How Check Sd Inserted Or Not


since you're french (cocorico ;) )

man mount :
mount [-t type]
fournit la liste des systèmes de fichiers actuellement
montés (éventuellement ceux du type indiqué uniquement)

I don't know if that is what you are looking for :ph34r:
 
ok donc pour "demonter" le sd:
umount /mnt/sd
et pour la "remonter"
mount /dev/mmcsd/disc0/part1 /mnt/sd

J'ai bon ?

Edit: j'ai testé, "device busy" :(

I ask that because I would like to change the SD with gp2x ON and with a program launched from this SD
 
In a shell script you can do:

Code:
if mount | grep -q disc0; then
	# SD is mounted
else
	# Not mounted
fi
 
JyCet posted on Sep 13 2006 at 08:09 PM said:
Edit: j'ai testé at "device busy" :(
That means some process is using the SD, e.g. you are in a directory under /mnt/sd in the shell. If so just "cd /" before you unmount it.

Your program will have to close any files on the SD too and chdir() off the SD.
 
Last edited by a moderator:
Hi,

I found and will test that:
Code:
// all files already closed
//change dir to the root
chdir("/");
// umount the sd
umount ("/mnt/sd");
// CHANGE SD HERE
// mount the new sd
mount ("/dev/mmcsd/disc0/part1","/mnt/sd",...),
// return to the sd
chdir("/mnt/sd/");
// now DO MY STUFF
...
 
Test complete but always impossible :(

If I launch any program from SD, it's impossible to umount /mnt/sd
If I add chdir("/"); in a program without any sd call inside this program, it's always impossible to umount /mnt/sd
Now if I copy a program in the NAND, this program do some call to the SD (like opendir() ) and close these call (closedir() ), I can umount /mnt/sd

:(
 
JyCet posted on Sep 16 2006 at 01:02 AM said:
Test complete but always impossible :(

If I launch any program from SD, it's impossible to umount /mnt/sd
If I add chdir("/"); in a program without any sd call inside this program, it's always impossible to umount /mnt/sd
Now if I copy a program in the NAND, this program do some call to the SD (like opendir() ) and close these call (closedir() ), I can umount /mnt/sd

:(
Copy your 'SD switcher' to /tmp (which is tmpfs), run it from there, then you can unmount /mnt/sd. Without hurting the NAND :)
 
Last edited by a moderator:
Daid posted on Sep 16 2006 at 11:28 AM said:
Copy your 'SD switcher' to /tmp (which is tmpfs), run it from there, then you can unmount /mnt/sd. Without hurting the NAND :)

Sorry I dont understand what you mean by SD switcher and tmpfs.
I'm very beginer with linux and I would to create a RAMdisk (I can use around 15MB of free ram to create this RAMdisk) to copy some file from one SD to another.
That's why I search how to umount the sd and mount a new one :)
 
Last edited by a moderator:
JyCet posted on Sep 13 2006 at 07:18 PM said:
Hi all,
Does someone know under linux how to check if a sd is inserted or not ?
Thanks :)

3 ways from the top of my head:
1) stat the /mnt/sd and /mnt if both have the same device id, the sdcard is not mounted
2) open /proc/mounts and if you find any mention of sd there, it's mounted
3) open a pipe to the mount command and parse the output, if you see any mention of sd there, it's mounted
 
Last edited by a moderator:
Ok, i've looked inside fstab and understand now this line :
Code:
none /tmp /tmpfs Size=5M 0 0
It mean that we alway have 5MB allocated for a virtual /tmp folder in RAM.
Very good to know that, I'll investigate and do some test we this virtual folder :)

Thanks a lot
 
Back
Top