Package: usbmount Version: 0.0.14 Severity: wishlist Just found it painful to have all the usbN directories, even when that many usb sticks may not be mounted. This patch adds an option MOUNTPOINT_GENERATE (off by default, so there is no change in the existing behaviour) which when set, reuses MOUNTPOINTS to be the prefix, and creates directories as and when needed, by suffixing them with an integer. The directory, if empty, is also unlinked on device removal (This however does not take effect in the current version, due to Bug #356227)
Here is the patch:
--- usbmount.distrib 2005-07-08 22:21:02.000000000 +0530 +++ usbmount 2006-04-09 20:30:01.000000000 +0530 @@ -15,7 +15,6 @@ set -e exec > /dev/null 2>&1 - # Log a string via the syslog facility. log() { @@ -35,6 +34,14 @@ return 1 } +test_mtpt() +{ + if test -d "$1" && ! grep -q "^[^ ][^ ]* *$1 " /proc/mounts; then + return 0 + else + return 1 + fi +} # Test if /sbin/vol_id is executable. test -x /sbin/vol_id || { log err "cannnot execute /sbin/vol_id"; exit 1; } @@ -51,7 +58,6 @@ . /etc/usbmount/usbmount.conf fi - umask 022 if test "$1" = add; then @@ -96,15 +102,27 @@ if in_list "$fstype" "$FILESYSTEMS"; then # Search an available mountpoint. - for v in $MOUNTPOINTS; do - if test -d "$v" \ - && ! grep -q "^[^ ][^ ]* *$v " /proc/mounts; then - mountpoint="$v" - log debug "mountpoint $mountpoint is available for $DEVNAME" - break - fi - done + if test "$MOUNTPOINT_GENERATE" = yes; then + ctr=0 + while true; do + v="$MOUNTPOINTS$ctr" + test -e "$v" || mkdir "$v" || break + if test_mtpt "$v"; then + mountpoint="$v" + break + fi + ctr=$(( $ctr + 1 )) + done + else + for v in $MOUNTPOINTS; do + if test_mtpt "$v"; then + mountpoint="$v" + break + fi + done + fi if test -n "$mountpoint"; then + log debug "mountpoint $mountpoint is available for $DEVNAME" # Determine mount options. options= for v in $FS_MOUNTOPTIONS; do @@ -172,11 +190,17 @@ if test "$DEVNAME" = "$device"; then # If the mountpoint and filesystem type are maintained by # this script, unmount the filesystem. - if in_list "$mountpoint" "$MOUNTPOINTS" \ - && in_list "$fstype" "$FILESYSTEMS"; then + if test "$MOUNTPOINT_GENERATE" = yes; then + test -z "${mountpoint##$MOUNTPOINTS[0-9]*}" && mttest=ok + else + in_list "$mountpoint" "$MOUNTPOINTS" && mttest=ok + fi + if test "$mttest" = ok && in_list "$fstype" "$FILESYSTEMS"; then log info "executing command: umount -l $mountpoint" umount -l "$mountpoint" - + if test "$MOUNTPOINT_GENERATE" = yes; then + rmdir "$mountpoint" 2> /dev/null + fi # Run hook scripts; ignore errors. export UM_DEVICE="$DEVNAME" export UM_MOUNTPOINT="$mountpoint"
Here is my config file. I have also documented the new option:
# Configuration file for the usbmount package, which mounts USB mass # storage devices when they are plugged in and unmounts them when they # are removed. # Set this to yes if you want mountpoints to be automatically generated based # on a given prefix followed by the smallest available positive integer. # MOUNTPOINTS specifies the prefix. For example, if /media/usb is specified, # the mountpoints used are usb0, usb1 etc. The directory is created if not # present. Further, if the directory is empty on device removal, it is removed # as well. MOUNTPOINT_GENERATE=yes # Mountpoints: When MOUNTPOINT_GENERATE is not set, these directories are # eligible as mointpoints for USB mass storage devices. A newly plugged in # device is mounted on the first directory in this list that exists and on # which nothing is mounted yet. When MOUNTPOINT_GENERATE is set, this option # specifies the prefix to be used. MOUNTPOINTS=/media/usb #MOUNTPOINTS="/media/usb0 /media/usb1 /media/usb2 /media/usb3 # /media/usb4 /media/usb5 /media/usb6 /media/usb7" # Filesystem types: USB mass storage devices are only mounted if they # contain a filesystem type which is in this list. ############################################################################# # WARNING! The vfat filesystem does not yet fully implement sync-mounting. # # If you include "vfat" in the list of filesystem types, you *MUST* make # # sure all data is written to the medium before you remove it (e.g. run the # # "sync" command in a terminal window). Otherwise, you *WILL* lose data! # ############################################################################# FILESYSTEMS="ext2 ext3 vfat" # Mount options: Options passed to the mount command with the -o flag. # WARNING! Removing "sync" from the options is a very bad idea and # might result in severe data loss. MOUNTOPTIONS="noexec,nodev,noatime,users" # Filesystem type specific mount options: This variable contains a space sepa- # rated list of strings, each of which has the form "-fstype=TYPE,OPTIONS". # If a filesystem with a type listed here is mounted, the corresponding # options are appended to those specificed in the MOUNTOPTIONS variable. # For example, "-fstype=vfat,gid=floppy,dmask=0007,fmask=0117" would add the # options "gid=floppy,dmask=0007,fmask=0117" when a vfat filesystem is mounted. FS_MOUNTOPTIONS="-fstype=vfat,dmask=000,fmask=111" # If set to "yes", more information will be logged via the syslog # facility. VERBOSE="yes"
Regards, Ramkumar. -- System Information: Debian Release: testing/unstable APT prefers testing APT policy: (101, 'testing') Architecture: i386 (i686) Shell: /bin/sh linked to /bin/dash Kernel: Linux 2.6.15-archck2 Locale: LANG=en_IN, LC_CTYPE=en_IN (charmap=UTF-8) Versions of packages usbmount depends on: ii lockfile-progs 0.1.10 Programs for locking and unlocking ii udev 0.088-2 /dev/ and hotplug management daemo usbmount recommends no packages. -- no debconf information -- WARN_(accel)("msg null; should hang here to be win compatible\n"); -- WINE source code