|
| 1 | +============ |
| 2 | +Auto-Mounter |
| 3 | +============ |
| 4 | + |
| 5 | +General Description |
| 6 | +=================== |
| 7 | +NuttX implements an auto-mounter than can make working with SD cards or other |
| 8 | +removable media easier. With the auto-mounter, the file system will be |
| 9 | +automatically mounted when media is inserted and automatically unmounted when |
| 10 | +the media is removed. |
| 11 | + |
| 12 | +The auto is enable by selecting in the NuttX configuration:: |
| 13 | + |
| 14 | + CONFIG_FS_AUTOMOUNTER=y |
| 15 | + |
| 16 | + |
| 17 | +WARNING: SD cards should never be removed without first unmounting them. This |
| 18 | +is to avoid data and possible corruption of the file system. Certainly this is |
| 19 | +the case if you are writing to the SD card at the time of the removal. If you |
| 20 | +use the SD card for read-only access, however, then I cannot think of any |
| 21 | +reason why removing the card without mounting would be harmful. |
| 22 | + |
| 23 | +For applications that write to the removable media, the automatic unmount is |
| 24 | +still beneficial (as opposed to leaving a broken mount in place) although |
| 25 | +should not be relied upon for a proper solution. |
| 26 | + |
| 27 | +Board-Specific Support |
| 28 | +====================== |
| 29 | + |
| 30 | +Like many components of NuttX, the auto-mounter has a upper-half/lower-half |
| 31 | +architecture: |
| 32 | + |
| 33 | +* **Upper half** The upper half is the file ``fs/fs_automount.c``. This upper |
| 34 | + half performs the basic automount activities. It responds to media |
| 35 | + insertion and removal events by mounting and unmounting the file system on |
| 36 | + the media. This includes logic to handle unmount retries: The unmount cannot |
| 37 | + be performed while applications have open files on the media. In this case, |
| 38 | + the auto-mounter will periodically retry the unmount until all of the |
| 39 | + applications close there references to files on the non-existent media. |
| 40 | + |
| 41 | +* **Lower Half** The lower half is defined by a standard interface. That |
| 42 | + interface definition is in the header file ``include/nuttx/fs/automount.h``. |
| 43 | + The lower half interface provides: (1) mount information including file |
| 44 | + system type, block driver path, and mount point path, (2) mount and unmount |
| 45 | + retry delays, and (3) and callbacks to attach to and management the media |
| 46 | + insertion / removal interrupts. |
| 47 | + |
| 48 | +Example Implementation |
| 49 | +====================== |
| 50 | + |
| 51 | +There is an example implementation of this lower half interface at |
| 52 | +``boards/arm/sama5/sama5d4-ek/src/sam_automount.c``. The ``boards/arm/sama5/sama5d4-ek/Kconfig`` |
| 53 | +as the board-specific configuration for the auto-mounter. You can see |
| 54 | +the configuration settings in the ``boards/arm/sama5/sama5d4-ek/configs/nsh/defconfig`` |
| 55 | +and ``boards/arm/sama5/sama5d4-ek/configs/nxwm/defconfig`` configuration files:: |
| 56 | + |
| 57 | + CONFIG_SAMA5D4EK_HSMCI0_AUTOMOUNT=y |
| 58 | + CONFIG_SAMA5D4EK_HSMCI0_AUTOMOUNT_FSTYPE="vfat" |
| 59 | + CONFIG_SAMA5D4EK_HSMCI0_AUTOMOUNT_BLKDEV="/dev/mmcsd0" |
| 60 | + CONFIG_SAMA5D4EK_HSMCI0_AUTOMOUNT_MOUNTPOINT="/mnt/sdcard" |
| 61 | + CONFIG_SAMA5D4EK_HSMCI0_AUTOMOUNT_DDELAY=1000 |
| 62 | + CONFIG_SAMA5D4EK_HSMCI0_AUTOMOUNT_UDELAY=2000 |
| 63 | + |
| 64 | +These setting determine the values in the lower half interface. The interrupt is |
| 65 | +provided by a PIO pin defined in ``boards/arm/sama5/sama5d4-ek/src/sama5e4-ek.h`` and |
| 66 | +the implementation of the interface and callbacks is in |
| 67 | +``boards/arm/sama5/sama5d4-ek/src/sam_automount.c``. |
| 68 | + |
| 69 | + |
0 commit comments