I’m having trouble creating a file on the SD card from a Sandboxed App. Here is what works. I can manually create a file on the SD card from a command prompt, so I have mounted the SD card correctly. When I run my simple app, it executes successfully but no file is created on the SD card. From my research, I believe I need a SMACK setting of some type, but can’t figure out what to do.
I have attached my app code below and would appreciate any help.
fstest2.adef file
sandboxed: true
version: 1.0.0
maxFileSystemBytes: 512K
start: manual
executables:
{
fstest2 = ( fstest2Component )
}
processes:
{
envVars:
{
LE_LOG_LEVEL = DEBUG
}
run:
{
( fstest2 )
}
faultAction: restart
}
requires:
{
device:
{
// Request read and write access to the SD card.
[rw] /dev/mmcblk0p1 /dev/mmcblk0p1
}
dir:
{
/mnt/userrw/sdcard /
}
}
Component.cdef file
sources:
{
fstest2Component.c
}
fstest2Component.c file
#include “legato.h”
COMPONENT_INIT
{
LE_INFO(“Test File Creation.”);
uint8_t write_buffer_tx[] =
{
0x54, 0x45, 0x53, 0x54, 0x32
};
le_result_t res;
le_fs_FileRef_t fp;
size_t filesize;
res = le_fs_Open("/test2.txt", LE_FS_CREAT|LE_FS_RDWR|LE_FS_APPEND|LE_FS_SYNC , &fp);
if(res == LE_OK){
LE_INFO(“File Created Successfully.”);
} else {
LE_INFO(“File Creation Failed %d.”, res);
}
res = le_fs_Write(fp, write_buffer_tx, NUM_ARRAY_MEMBERS(write_buffer_tx));
if(res == LE_OK){
LE_INFO(“File Write Successful.”);
} else {
LE_INFO(“File Write Failed %d.”, res);
}
le_fs_Close(fp);
res = le_fs_GetSize("/test2.txt", &filesize);
if(res == LE_OK){
LE_INFO(“File Get Size Successful. size=%d”, filesize);
} else {
LE_INFO(“File Get Size Failed %d.”, res);
}
}
Log Output
Oct 8 22:37:14 | fstest2[16521]/fstest2_exe T=main | _main.c main() 61 | == Starting Event Processing Loop ==
Oct 8 22:37:14 | fstest2[16521]/fstest2Component T=main | fstest2Component.c _fstest2Component_COMPONENT_INIT() 5 | Test File Creation.
Oct 8 22:37:14 | fstest2[16521]/fstest2Component T=main | fstest2Component.c _fstest2Component_COMPONENT_INIT() 15 | File Created Successfully.
Oct 8 22:37:14 | fstest2[16521]/fstest2Component T=main | fstest2Component.c _fstest2Component_COMPONENT_INIT() 21 | File Write Successful.
Oct 8 22:37:14 | fstest2[16521]/fstest2Component T=main | fstest2Component.c _fstest2Component_COMPONENT_INIT() 28 | File Get Size Successful. size=5