I. Soil EIGHT practices:
Once the SD card is plugged into the system, the kernel will automatically create the device file under/dev/: SDcard. But sometimes the user in the dial out before the card and no umount, the second card in the system created is not sdcard device files, but mmcblk0, MMCBLK1P1, MMCBLK2P1, or MMCBLK3P1.
So just use if (fopen ("/dev/sdcard", "r") = = NULL) to detect if the SD card has been captured by the kernel. Then you can mount .... And the things you want to do.
How do you know that you already have mount?
After the cat/proc/mounts, there will be:
Rootfs/rootfs RW 0 0
/dev/root/yaffs rw,relatime 0 0
NONE/PROC proc Rw,relatime 0 0
None/sys Sysfs rw,relatime 0 0
None/dev Ramfs rw,relatime 0 0
None/dev/pts devpts rw,relatime,mode=622 0 0
Tmpfs/dev/shm Tmpfs rw,relatime 0 0
None/tmp Ramfs rw,relatime 0 0
None/var Ramfs rw,relatime 0 0
/dev/sdcard/mnt VFAT Rw,relatime,fmask=0022,dmask=0000,allow_utime=0022,codepag
E=cp437,iocharset=iso8859-1 0 0
/dev/mmcblk1p1/mnt VFAT Rw,relatime,fmask=0022,dmask=0000,allow_utime=0022,code
Page=cp437,iocharset=iso8859-1 0 0
Ha ha... The last two are the one I just mount.
Ii. Professional Mdev Method (and Udev): Http://www.embedu.org/Column/Column167.htm Mdev is a lite version of the Udev management program in BusyBox, He can also realize the automatic creation of the device node and the automatic installation of the device, but in the implementation of the process is a little different, in the hot Plug time when the Mdev is hotplug direct call, then mdev through the environment variable ACTION and DEVPATH, To determine the action of this hot plug event and to affect the directory in the/sys. You will then see if there is a "dev" property file in this directory, and if so, use this information to create a device node file for this device in/dev.
1. When making the root file system using BusyBox, select Support Mdev
Linux System Utilities--->
[*] Mdev
[*] Support/etc/mdev.conf
[*] Support command execution at device Addition/removal
2. Add the following to the file system
Vim/etc/init.d/rcs
Mount-t Tmpfs Mdev/dev
Mount-t Sysfs Sysfs/sys
Mkdir/dev/pts
Mount-t devpts devpts/dev/pts
Echo/sbin/mdev>/proc/sys/kernel/hotplug
Mdev–s
The addition of these statements can be found in the Mdev manual.
3. Add the response to the hot-swap event to automatically mount the USB flash drive and SD card.
Vim/etc/mdev.conf
MMCBLK[0-9]P[0-9] 0:0 666 @/etc/sd_card_inserting
MMCBLK[0-9] 0:0 666 $/etc/sd_card_removing
SD[A-Z] [0-9] 0:0 666 @/etc/usb/usb_inserting
SD[A-Z] 0:0 666 $/etc/usb/usb_removing
The gray part, is a script, the script content can be customized according to our needs, can implement mount, uninstall or some other functions.
The following is a script that automatically mounts and unloads:
/etc/sd_card_inserting
#!/bin/sh
Mount-t VFAT/DEV/MMCBLK0P1/MNT/SD
/etc/sd_card_removing
#!/bin/sh
Sync
Umount/mnt/sd
How arm Linux automatically detects and mount SD cards, and how to know that already mount