]> code.ossystems Code Review - openembedded-core.git/commitdiff
busybox-mdev: Support automatic mounting of block devices
authormike.looijmans@topic.nl <mike.looijmans@topic.nl>
Thu, 18 Dec 2014 14:17:31 +0000 (15:17 +0100)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Fri, 19 Dec 2014 18:06:46 +0000 (18:06 +0000)
Upon inserting a USB stick or similar device, mdev will run
an automounter script that mounts valid partitions on
/media/<device>. The script first checks /etc/fstab entries
so that mounting on UUID or LABEL or using custom mount options
is still possible. If /etc/fstab does not contain particular
mount options, the script will create (and remove) the mountpoint
automatically.
The script also supports full disk partitions (devices without
partition table).

The following environments can be set in /etc/default/mdev:
MDEV_AUTOMOUNT=n (Disables automounting completely)
MDEV_AUTOMOUNT_ROOT=/media (Change the mount root location)

Automatic mounting for a particular device can be disabled by
creating a file "/dev/<device>.nomount". This is helpful in
scripts that create partitions for example, and want to perform
specific actions which require the device to remain unmounted.

A more complex variation (using LABEL based mounts) on this script
has been in use in OpenPLi for many years now, and I've used this
one on many projects already, so it's about time to push this to
mainline.

Signed-off-by: Mike Looijmans <mike.looijmans@topic.nl>
Signed-off-by: Ross Burton <ross.burton@intel.com>
meta/recipes-core/busybox/busybox.inc
meta/recipes-core/busybox/busybox_1.22.1.bb
meta/recipes-core/busybox/busybox_git.bb
meta/recipes-core/busybox/files/mdev-mount.sh [new file with mode: 0644]
meta/recipes-core/busybox/files/mdev.conf

index deb2ee46069c0088a9b8528a195a5802bcba449a..0769d92c5089bccf01bbdf778e49775f2dffc731 100644 (file)
@@ -270,6 +270,7 @@ do_install () {
                        install -m 644 ${WORKDIR}/mdev.conf ${D}${sysconfdir}/mdev.conf
                        install -d ${D}${sysconfdir}/mdev
                        install -m 0755 ${WORKDIR}/find-touchscreen.sh ${D}${sysconfdir}/mdev
+                       install -m 0755 ${WORKDIR}/mdev-mount.sh ${D}${sysconfdir}/mdev
                fi
        fi
 
index 8879e529625f21eb93442a87ff6a39696f92c558..dd61a2680c4fb679ecd9596574e29c4f2338b91f 100644 (file)
@@ -20,6 +20,7 @@ SRC_URI = "http://www.busybox.net/downloads/busybox-${PV}.tar.bz2;name=tarball \
            file://busybox-syslog.default \
            file://mdev \
            file://mdev.conf \
+           file://mdev-mount.sh \
            file://umount.busybox \
            file://defconfig \
            file://busybox-syslog.service.in \
index f2cc119400eefabd3bd7d5fd47d78ec3140e3f11..f91b552f78b736a7c818d38b8acff828ebe2ba05 100644 (file)
@@ -24,6 +24,7 @@ SRC_URI = "git://busybox.net/busybox.git \
            file://busybox-syslog.default \
            file://mdev \
            file://mdev.conf \
+           file://mdev-mount.sh \
            file://umount.busybox \
            file://defconfig \
            file://busybox-syslog.service.in \
diff --git a/meta/recipes-core/busybox/files/mdev-mount.sh b/meta/recipes-core/busybox/files/mdev-mount.sh
new file mode 100644 (file)
index 0000000..d5d66d6
--- /dev/null
@@ -0,0 +1,63 @@
+#!/bin/sh
+MDEV_AUTOMOUNT=y
+MDEV_AUTOMOUNT_ROOT=/run/media
+[ -f /etc/default/mdev ] && . /etc/default/mdev
+if [ "${MDEV_AUTOMOUNT}" = "n" ] ; then
+       exit 0
+fi
+
+case "$ACTION" in
+       add|"")
+               ACTION="add"
+               # check if already mounted
+               if grep -q "^/dev/${MDEV} " /proc/mounts ; then
+                       # Already mounted
+                       exit 0
+               fi
+               DEVBASE=`expr substr $MDEV 1 3`
+               if [ "${DEVBASE}" == "mmc" ] ; then
+                       DEVBASE=`expr substr $MDEV 1 7`
+               fi
+               # check for "please don't mount it" file
+               if [ -f "/dev/nomount.${DEVBASE}" ] ; then
+                       # blocked
+                       exit 0
+               fi
+               # check for full-disk partition
+               if [ "${DEVBASE}" == "${MDEV}" ] ; then
+                       if [ -d /sys/block/${DEVBASE}/${DEVBASE}*1 ] ; then
+                               # Partition detected, just quit
+                               exit 0
+                       fi
+                       if [ ! -f /sys/block/${DEVBASE}/size ] ; then
+                               # No size at all
+                               exit 0
+                       fi
+                       if [ `cat /sys/block/${DEVBASE}/size` == 0 ] ; then
+                               # empty device, bail out
+                               exit 0
+                       fi
+               fi
+               # first allow fstab to determine the mountpoint
+               if ! mount /dev/$MDEV > /dev/null 2>&1
+               then
+                       MOUNTPOINT="${MDEV_AUTOMOUNT_ROOT}/$MDEV"
+                       mkdir "$MOUNTPOINT"
+                       mount -t auto /dev/$MDEV "$MOUNTPOINT"
+               fi
+               ;;
+       remove)
+               MOUNTPOINT=`grep "^/dev/$MDEV\s" /proc/mounts | cut -d' ' -f 2`
+               if [ ! -z "$MOUNTPOINT" ]
+               then
+                       umount "$MOUNTPOINT"
+                       rmdir "$MOUNTPOINT"
+               else
+                       umount /dev/$MDEV
+               fi
+               ;;
+       *)
+               # Unexpected keyword
+               exit 1
+               ;;
+esac
index 6dfd161fa0bf682d088a97f6c2ad38b1b8c388ff..17e93da7c3c60da803290af5b15a274a8bb2cea8 100644 (file)
@@ -37,3 +37,6 @@ input/mice 0:0 0660
 input/mouse.* 0:0 0660
 
 tun[0-9]* 0:0 0660 =net/
+
+[hs]d[a-z][0-9]? 0:0 660 */etc/mdev/mdev-mount.sh
+mmcblk[0-9].* 0:0 660 */etc/mdev/mdev-mount.sh