Hello:

As I said in other bug reports, I'm testing usbmount, and I think that
it is a so useful app. for lightweight systems.

But I missed the lack of an on-demand mountpoint create and delete. With this
feature, I think that the system is friendly for a normal user (where is the
newly plugged usbstick?, ah! in the newly created dir under /media :-D).

For that, I tryed the pach in
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=361693. I apply it by hand
to /usr/share/usbmount/usbmount and add the new options
to /etc/usbmount/usbmount.conf. The pach still runs OK: it creates the
mountpoint at usb plugg, but don't removes it, as saids in the bugreport
#361693.

For this issue I create a workaround that:

1. At usb-plugg stores some variables in /tmp/usbbmount. For identify the usb
number, I get the info from /var/log/syslog, so this package should be
installed and running.

2. At usb-detach reads the variables from /tmp/usbbmount and deletes the
corresponding mountpoint. I need to get the info about what usb-stick was
detached from syslog, because I don't find any other place, all udev apps
are useless now that device is removed !!.

As you can see, the workaround is so weak, as it depends in syslog. But is
working OK for me. I attached it.

I see that usbmout need to be changed as result of some changes in udev, so I
see that this pach will be changed in the future. It is so weak too. But you
can use it as a first point for a stronger one :-DD

Greetings. Martintxo.

-- 
Tu que no puedes, llévame a cuestas 
--- usbmount-ORIG	2009-09-27 12:30:27.000000000 +0200
+++ usbmount	2009-10-02 17:27:35.000000000 +0200
@@ -36,6 +36,14 @@
     return 1
 }
 
+test_mtpt()
+{
+    if test -d "$1" && ! grep -q "^[^ ][^ ]*  *$1 " /proc/mounts; then
+       return 0
+    else
+       return 1
+    fi
+}
 
 # Test if /lib/udev/vol_id is executable.
 test -x /lib/udev/vol_id || { log err "cannot execute /lib/udev/vol_id"; exit 1; }
@@ -116,15 +124,28 @@
 	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
+	       log info "Creating mountpoint dir: $v"
+           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
@@ -141,6 +162,17 @@
 		log info "executing command: mount -t$fstype ${options:+-o$options} $DEVNAME $mountpoint"
 		mount "-t$fstype" "${options:+-o$options}" "$DEVNAME" "$mountpoint"
 
+		  #MARTINTXO: workaround for the dir deletion on device removal ...
+		  # Search for a single number for the usb device (in syslog, because with udevadm is so hard)
+		  devaddress=`tail -n 30 /var/log/syslog | grep " and address " |  awk '{ print $NF }'`
+		  devusbbus=`tail -n 30 /var/log/syslog | grep " and address " |  awk '{ print $7 }'`
+
+		  # Save the needed variables for device in a text file (in /tmp that is deleted at session end).
+		  # We will use them when we detach the device, for delete the dir.
+		  echo "DEVNAME$devusbbus$devaddress $DEVNAME" >> /tmp/usbbmount
+		  echo "mountpoint$devusbbus$devaddress $mountpoint" >> /tmp/usbbmount
+		  echo "fstype$devusbbus$devaddress $fstype" >> /tmp/usbbmount
+
 		# Determine vendor and model.
 		vendor=
 		if test -r "/sys$DEVPATH/device/vendor"; then
@@ -186,17 +218,51 @@
 
 elif test "$1" = remove; then
 
+    #MARTINTXO: workaround for the bug http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=356227
+    # that produces the no dir deletion created in /media by the patch in:
+    #  http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=361693 
+    
+    # Gets the detached device number for find it in the /tmp file:
+    #  (in syslog, because I don't find any other place, all udev apps are useless now that device is removed)
+    devaddress=`tail -n 1 /var/log/syslog | grep "USB disconnect, address" |  awk '{ print $NF }'`
+    devusbbus=`tail -n 1 /var/log/syslog | grep "USB disconnect, address" |  awk '{ print $7 }'`
+    
+    # Gets the adecuate variable from the /tmp file
+     if [ $devaddress != "" ] && [ $devusbbus != "" ]; then
+      DEVNAME=`grep "DEVNAME$devusbbus$devaddress" /tmp/usbbmount |  awk '{ print $2 }'`
+      mountpoint=`grep "mountpoint$devusbbus$devaddress" /tmp/usbbmount |  awk '{ print $2 }'`
+      fstype=`grep "fstype$devusbbus$devaddress" /tmp/usbbmount |  awk '{ print $2 }'`
+    else
+      log debug "I can't find any disconected usb device"
+      exit 1
+    fi
+
     # A block or partition device has been removed.
     # Test if it is mounted.
-    while read device mountpoint fstype remainder; do
-	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
-		log info "executing command: umount -l $mountpoint"
-		umount -l "$mountpoint"
-
+           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" \
+	     && [ `grep "^$DEVNAME" /etc/mtab |  awk '{ print $1 }'` = $DEVNAME ]; then
+		log info "executing command: umount $mountpoint"
+		umount "$mountpoint" && 
+                  if test "$MOUNTPOINT_GENERATE" = yes; then
+                      log info "Deleting mountpoint dir: $mountpoint"
+		      rmdir "$mountpoint" 2> /dev/null
+	          fi
+		# Run hook scripts; ignore errors.
+		export UM_DEVICE="$DEVNAME"
+		export UM_MOUNTPOINT="$mountpoint"
+		export UM_FILESYSTEM="$fstype"
+		log info "executing command: run-parts /etc/usbmount/umount.d"
+		run-parts /etc/usbmount/umount.d || :
+	    elif test "$MOUNTPOINT_GENERATE" = yes; then
+                log info "Deleting mountpoint dir: $mountpoint"
+		rmdir "$mountpoint" 2> /dev/null
 		# Run hook scripts; ignore errors.
 		export UM_DEVICE="$DEVNAME"
 		export UM_MOUNTPOINT="$mountpoint"
@@ -204,9 +270,6 @@
 		log info "executing command: run-parts /etc/usbmount/umount.d"
 		run-parts /etc/usbmount/umount.d || :
 	    fi
-	    break
-	fi
-    done < /proc/mounts
 
 fi
 

Reply via email to