All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mike Looijmans <mike.looijmans@topic.nl>
To: Khem Raj <raj.khem@gmail.com>
Cc: openembedded-core@lists.openembedded.org
Subject: Re: [PATCH v2 4/4] busybox-mdev: Support automatic mounting of block devices
Date: Thu, 01 Jan 2015 10:07:06 +0100	[thread overview]
Message-ID: <54A50E3A.5010707@topic.nl> (raw)
In-Reply-To: <AD47BDE1-4736-43B8-B901-ACDCFAD1665B@gmail.com>

On 01/01/2015 03:49 AM, Khem Raj wrote:
>
>> On Dec 18, 2014, at 6:17 AM, Mike Looijmans <mike.looijmans@topic.nl> wrote:
>>
>> 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>
>> ---
>> meta/recipes-core/busybox/busybox.inc         |    1 +
>> meta/recipes-core/busybox/busybox_1.22.1.bb   |    1 +
>> meta/recipes-core/busybox/busybox_git.bb      |    1 +
>> meta/recipes-core/busybox/files/mdev-mount.sh |   63 +++++++++++++++++++++++++
>> meta/recipes-core/busybox/files/mdev.conf     |    3 ++
>> 5 files changed, 69 insertions(+)
>> create mode 100644 meta/recipes-core/busybox/files/mdev-mount.sh
>>
>> diff --git a/meta/recipes-core/busybox/busybox.inc b/meta/recipes-core/busybox/busybox.inc
>> index deb2ee4..0769d92 100644
>> --- a/meta/recipes-core/busybox/busybox.inc
>> +++ b/meta/recipes-core/busybox/busybox.inc
>> @@ -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
>>
>> diff --git a/meta/recipes-core/busybox/busybox_1.22.1.bb b/meta/recipes-core/busybox/busybox_1.22.1.bb
>> index 82f7f68..f379bb6 100644
>> --- a/meta/recipes-core/busybox/busybox_1.22.1.bb
>> +++ b/meta/recipes-core/busybox/busybox_1.22.1.bb
>> @@ -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 \
>> diff --git a/meta/recipes-core/busybox/busybox_git.bb b/meta/recipes-core/busybox/busybox_git.bb
>> index f2cc119..f91b552 100644
>> --- a/meta/recipes-core/busybox/busybox_git.bb
>> +++ b/meta/recipes-core/busybox/busybox_git.bb
>> @@ -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
>> index 0000000..d5d66d6
>> --- /dev/null
>> +++ b/meta/recipes-core/busybox/files/mdev-mount.sh
>> @@ -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
>
> bashism, get rid of it.

please explain?

>
>> +			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
>> diff --git a/meta/recipes-core/busybox/files/mdev.conf b/meta/recipes-core/busybox/files/mdev.conf
>> index 6dfd161..17e93da 100644
>> --- a/meta/recipes-core/busybox/files/mdev.conf
>> +++ b/meta/recipes-core/busybox/files/mdev.conf
>> @@ -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
>> --
>> 1.7.9.5
>>
>> --
>> _______________________________________________
>> Openembedded-core mailing list
>> Openembedded-core@lists.openembedded.org
>> http://lists.openembedded.org/mailman/listinfo/openembedded-core
>


-- 
Mike Looijmans


  reply	other threads:[~2015-01-01  9:07 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-04 10:27 [PATCH 0/2] Busybox mdev improvements Mike Looijmans
2014-12-04 10:27 ` [PATCH 1/2] busybox-mdev: Install missing find-touchscreen.sh Mike Looijmans
2014-12-04 10:27 ` [PATCH 2/2] busybox/find-touchscreen.sh: Simplify script and recognize USB devices Mike Looijmans
2014-12-04 20:47 ` [PATCH 0/2] Busybox mdev improvements Otavio Salvador
2014-12-05  6:18   ` Mike Looijmans
2014-12-05 11:27     ` Otavio Salvador
2014-12-05 12:57       ` Mike Looijmans
2014-12-05 14:13         ` Otavio Salvador
2014-12-05  9:58 ` [PATCH 1/2] busybox-mdev: Support automatic mounting of block devices Mike Looijmans
2014-12-05  9:58   ` [PATCH 2/2] busybox-mdev: Add hotplug kernel module support to mdev.conf Mike Looijmans
2014-12-17 22:01   ` [PATCH 1/2] busybox-mdev: Support automatic mounting of block devices Burton, Ross
2014-12-18 13:14     ` Mike Looijmans
2014-12-17 22:03   ` Burton, Ross
2014-12-17 22:05     ` Burton, Ross
2014-12-17 22:08     ` Gary Thomas
2014-12-18  6:31       ` Mike Looijmans
2014-12-18 12:55         ` Otavio Salvador
2014-12-18 14:38           ` Mike Looijmans
2014-12-18  6:23     ` Mike Looijmans
2014-12-18 13:30       ` Burton, Ross
2014-12-18 13:54         ` Mike Looijmans
2014-12-18 14:17 ` [PATCH v2 0/4] Busybox mdev improvements Mike Looijmans
2014-12-18 14:17   ` [PATCH v2 1/4] busybox-mdev: Install missing find-touchscreen.sh Mike Looijmans
2014-12-18 14:43     ` Otavio Salvador
2014-12-18 14:17   ` [PATCH v2 2/4] busybox/find-touchscreen.sh: Simplify script and recognize USB devices Mike Looijmans
2014-12-18 14:17   ` [PATCH v2 4/4] busybox-mdev: Support automatic mounting of block devices Mike Looijmans
2015-01-01  2:49     ` Khem Raj
2015-01-01  9:07       ` Mike Looijmans [this message]
2015-01-01 13:08         ` Peter A. Bigot
2015-01-01 19:21           ` Mike Looijmans
2014-12-18 14:19   ` [PATCH v2 3/4] busybox-mdev: Add hotplug kernel module support to mdev.conf Mike Looijmans
2014-12-18 14:44     ` Otavio Salvador

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=54A50E3A.5010707@topic.nl \
    --to=mike.looijmans@topic.nl \
    --cc=openembedded-core@lists.openembedded.org \
    --cc=raj.khem@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.