SD card access, path/directory

Oh ok, sorry I’m a beginner in linux environment!

It gives an error:

Feb 26 15:59:39 | hellovincent2[1446]/HelloVincent2Component T=main | HelloVincent2Component.c _HelloVincent2Component_COMPONENT_INIT() 7 | Hello Vincent2!
Feb 26 15:59:39 | hellovincent2[1446] | | mount: mounting /dev/mmcblk0p1 on “/tmp/sdcard” failed: No such file or directory
Feb 26 15:59:39 | hellovincent2[1446] | | PROCESS: 1446 ,TID 1446
Feb 26 15:59:39 | hellovincent2[1446] | | SIGNAL: 11, ADDR (nil), AT 0xb6d069e8 SI_CODE 0x00000001
Feb 26 15:59:39 | hellovincent2[1446] | | ILLEGAL ADDRESS (nil)

Here’s the c code:

#include “legato.h”
#include<stdio.h>
#include<stdlib.h>

COMPONENT_INIT
{
LE_INFO(“Hello Vincent2!”);

system("/bin/mount -t auto -o sync /dev/mmcblk0p1 “/tmp/sdcard”");

FILE* demo;
char str[] = "Hello!";

// Creates a file "demo_file"
// with file acccess as write-plus mode
demo = fopen("/tmp/sdcard/demo3.txt", "w+");

fwrite(str , 1 , sizeof(str) , demo);

// closes the file pointed by demo
fclose(demo);

if(demo == NULL)
{
	LE_INFO("File Creation Failed");
}
else
{
	LE_INFO("File Created Successfully");
}

}

How about
system(“/bin/mount -t auto -o sync /dev/mmcblk0p1 /tmp/sdcard”);

Please note that this mounting operation only need to be run once after power on.

I get the same error with:

system(“/bin/mount -t auto -o sync /dev/mmcblk0p1 /tmp/sdcard”);

do you have the folder /tmp/sdcard?

Hello jyijyi,

No I don’t! The demo.txt file is actually created at the root of the SD card. (when doing the mount with the console terminal)

It seems the “mkdir -p /tmp/sdcard” command did not create the folders

then please create the folder before you run the app.

I did create the /tmp/sdcard folders on SD card and tested the app, it gave the same error.

I tested both of:

system(“/bin/mount -t auto -o sync /dev/mmcblk0p1 “/tmp/sdcard””);
system(“/bin/mount -t auto -o sync /dev/mmcblk0p1 /tmp/sdcard”);

Then I retried to make the the mount with console terminal (without system() command), it works but demo.txt file is again created at the SD root and not in /tmp/sdcard folder. :no_mouth:

It really seems the app does not recognize the /tmp/sdcard folder.
I you look at the commands below you’ll see at line 4 it fails to detect the folders.

I have to execute the mkdir -p /tmp/sdcard command to make the mount work.

Then I run the app and the demo3.txt is created. When I serach it with the find command it lists it under the /tmp/sdcard/demo.txt

But actually test.txt and demo3.txt are created at the SD root. See below

legato console6

then what is the problem?
You can create file now in SD card.

Yes of course (and with your great help), but we didn’t succeed in doing the mount in the app!

For the moment I still have to do the console terminal commands to make it work.

Did you create the folder /tmp/sdcard before running the app?
Can you tell more what are you doing now?

Yes I created it manually (with my windows explorer) before running the app.

What I don’t understand is why the “/bin/mount -t auto -o sync /dev/mmcblk0p1 “/tmp/sdcard”” command does not succeed (/tmp/sdcard failed: no such file or directory), unless I (Re)create it with
mkdir -p /tmp/sdcard.
(Cf my previous post in SSH terminal)

It seems that for the app /tmp/sdcard doesn’t exist, which explains why system() function crashes.

I do really need to access this SD card (read and write) in my application, and I’m completely stuck at the moment :expressionless:

Then you can do one more system() to create the folder in your app.

system(“mkdir /tmp/sdcard”);

Ok, it works now, even if I still don’t understand why the created file is in the root instead of /tmp/sdcard.

But no matters for the moment, I can continue develop the app from now :grinning: