Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Cam Hutchison <cam@camh.ch>
To: buildroot@busybox.net
Subject: [Buildroot] [Bug 3811] New: Added auto-mount for USB and SD Card (mdev) (for 2011.05)
Date: Thu, 02 Jun 2011 04:10:54 -0000	[thread overview]
Message-ID: <2b45.4de70d4e.b3842@getafix.xdna.net> (raw)
In-Reply-To: bug-3811-163@https.bugs.busybox.net/

Some comments on your automount.sh changes:

>+#! /bin/sh

No space after #!

>+mounted=`mount | grep $1 | wc -l`

mounted=$(grep -c "^/dev/$1 " /proc/mounts)

$() is clearer than ``.
Less processes is better than more.
Use a full pattern so you don't accidently match sda against /dev/sda1 or
other sub-matches (sda1 vs sda11).

>+# mounted, assume we umount
>+if [ $mounted -ge 1 ]; then
>+        if ! umount "/dev/$1"; then
>+                exit 1
>+        fi

If something is mounted more than once, you unmount it only once. So why
it it necessary to know how many times it is mounted?

if grep -qs "^/dev/$1 " /proc/mounts ; then

is simplier and more idiomatic. You can then get rid of mounted=...
above.

>+
>+        if ! rmdir "/media/$1"; then
>+                exit 1
>+        fi
>+# not mounted, lets mount under /media
>+else
>+        if ! mkdir -p "/media/$1"; then
>+                exit 1
>+        fi

Why remove the directory, only to re-create it again?

>+
>+        if ! mount -o sync "/dev/$1" "/media/$1"; then
>+                # failed to mount, clean up mountpoint
>+                if ! rmdir "/media/$1"; then
>+                        exit 1
>+                fi
>+                exit 1

Why test the result of rmdir if you are just going to exit 1 anyway?

rmdir "/media/$1"
exit 1

>+        fi
>+fi
>+
>+exit 0
>+
>diff --git a/package/busybox/busybox.mk b/package/busybox/busybox.mk
>index 711d11b..bbe5c39 100644
>--- a/package/busybox/busybox.mk
>+++ b/package/busybox/busybox.mk
>@@ -32,6 +32,8 @@ endif
> ifeq ($(BR2_ROOTFS_DEVICE_CREATION_DYNAMIC_MDEV),y)
> define BUSYBOX_INSTALL_MDEV_SCRIPT
>     install -m 0755 package/busybox/S10mdev $(TARGET_DIR)/etc/init.d
>+    install -m 0755 package/busybox/mdev.conf $(TARGET_DIR)/etc
>+    install -m 0755 package/busybox/automount.sh $(TARGET_DIR)/sbin

Since automount.sh is a helper program for mdev, not a general-purpose
program, it should probably live in /lib/mdev and not /sbin.

> endef
> define BUSYBOX_SET_MDEV
>     $(call KCONFIG_ENABLE_OPT,CONFIG_MDEV,$(BUSYBOX_BUILD_CONFIG))
>diff --git a/package/busybox/mdev.conf b/package/busybox/mdev.conf
>new file mode 100644
>index 0000000..08d915c
>--- /dev/null
>+++ b/package/busybox/mdev.conf
>@@ -0,0 +1,2 @@
>+sd[a-z][0-9]* 0:0 0660 *(/sbin/automount.sh $MDEV)
>+mmcblk[0-9]p[0-9] 0:0 0660 *(/sbin/automount.sh $MDEV)

  parent reply	other threads:[~2011-06-02  4:10 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-01 13:28 [Buildroot] [Bug 3811] New: Added auto-mount for USB and SD Card (mdev) (for 2011.05) bugzilla at busybox.net
2011-06-01 14:03 ` Patryk Benderz
2011-06-02  4:10 ` Cam Hutchison [this message]
2014-02-08 20:53 ` [Buildroot] [Bug 3811] " bugzilla at busybox.net
2014-02-10 17:56 ` bugzilla at busybox.net

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=2b45.4de70d4e.b3842@getafix.xdna.net \
    --to=cam@camh.ch \
    --cc=buildroot@busybox.net \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox