[Pkg-utopia-commits] r194 - packages/hal/trunk/debian

Sjoerd Simons sjoerd@costa.debian.org
Mon, 11 Apr 2005 14:38:08 +0000


Author: sjoerd
Date: 2005-04-11 14:38:07 +0000 (Mon, 11 Apr 2005)
New Revision: 194

Modified:
   packages/hal/trunk/debian/changelog
   packages/hal/trunk/debian/hal.udev.device-removable.sh
   packages/hal/trunk/debian/hal.udev.rules
Log:
Improved removable drives detection script

Modified: packages/hal/trunk/debian/changelog
===================================================================
--- packages/hal/trunk/debian/changelog	2005-04-11 13:26:14 UTC (rev 193)
+++ packages/hal/trunk/debian/changelog	2005-04-11 14:38:07 UTC (rev 194)
@@ -1,6 +1,7 @@
 hal (0.4.7-4) UNRELEASED; urgency=low
 
   * Add fdi file to recognize Apple Ipods
+  * Improved udev script for removable drives detection (Thanks to Marco d'Itri)
 
  -- Sjoerd Simons <sjoerd@debian.org>  Mon, 11 Apr 2005 15:24:03 +0200
 

Modified: packages/hal/trunk/debian/hal.udev.device-removable.sh
===================================================================
--- packages/hal/trunk/debian/hal.udev.device-removable.sh	2005-04-11 13:26:14 UTC (rev 193)
+++ packages/hal/trunk/debian/hal.udev.device-removable.sh	2005-04-11 14:38:07 UTC (rev 194)
@@ -1,39 +1,52 @@
 #!/bin/sh -e
-# print "1" if device $1 is either removable, on the ieee1394 or on the usb bus,
-# and "0" otherwise.
+# print "1" if device $1 is either removable or attached to a bus listed
+# in $2 (e.g. 'ieee1394 usb') and "0" otherwise.
 
-check_bus() {
-  # check if the DEVICE is on the given bus 
-  # This is done by checking if any of the devices on the bus is a prefix 
-  # of the device
-  BUSDEVP="/sys/bus/$1/devices"
-  for x in $BUSDEVP/*; do
-    [ -L "$x" ] || continue
-    if echo "$DEVICE" | grep -q "^$(readlink -f $x)"; then 
+# check if the device $1 is on the bus $2
+# this is done by checking if any of the devices on the bus is a prefix
+# of the device
+on_bus() {
+  local BUSDEVP="/sys/bus/$2/devices"
+  for link in $BUSDEVP/*; do
+    [ -L "$link" ] || continue
+    if echo "$1" | grep -q "^$(readlink -f $link)/"; then
       return 0
     fi
   done
   return 1
 }
 
+# read the first line of the file $1
+read_value() {
+  local value
+  read -r value < $1 || true
+  echo $value
+}
+
+# strip the partition number, if present
 DEV="${1%[0-9]*}"
+SCAN_BUS="$2"
+
 BLOCKPATH="/sys/block/$DEV"
 
-if [ ! -d "${BLOCKPATH}" ]; then 
-  exit 1
-fi
+[ -d $BLOCKPATH ] || exit 1
 
-REMOVABLE="${BLOCKPATH}/removable"
-DEVICE="$(readlink -f "${BLOCKPATH}/device")"
-IS_REMOVABLE="0"
+IS_REMOVABLE=$(read_value $BLOCKPATH/removable)
 
-if [ -e "$REMOVABLE" ]; then
-  IS_REMOVABLE="$(cat $REMOVABLE)"
+if [ "$IS_REMOVABLE" != 1 -a "$SCAN_BUS" ]; then
+  DEVICE="$(readlink -f "${BLOCKPATH}/device")"
+  for bus in "$SCAN_BUS"; do
+    if on_bus $DEVICE $bus; then
+      IS_REMOVABLE=1
+      break
+    fi
+  done
 fi
 
-if [ "$IS_REMOVABLE" = "1" ] || check_bus "usb" || check_bus "ieee1394" ; then 
+if [ "$IS_REMOVABLE" = "1" ]; then
   echo 1
-else 
+else
   echo 0
 fi
+
 exit 0

Modified: packages/hal/trunk/debian/hal.udev.rules
===================================================================
--- packages/hal/trunk/debian/hal.udev.rules	2005-04-11 13:26:14 UTC (rev 193)
+++ packages/hal/trunk/debian/hal.udev.rules	2005-04-11 14:38:07 UTC (rev 194)
@@ -1,4 +1,4 @@
 # put removable IDE/SCSI devices into the hal group instead of 'disk'
-BUS="scsi",KERNEL="sd[a-z]*", PROGRAM="/etc/udev/scripts/device-removable.sh %k", RESULT="1", NAME="%k", MODE="0640", GROUP="hal"
-# BUS="ide", KERNEL="hd[a-z]*", PROGRAM="/etc/udev/scripts/device-removable.sh %k", RESULT="1", NAME="%k", MODE="0640", GROUP="hal"
-BUS="usb", KERNEL="ub[a-z]*", NAME="%k", MODE="0640", GROUP="hal"
+BUS="scsi",KERNEL="sd[a-z]*", PROGRAM="/etc/udev/scripts/device-removable.sh %k 'usb ieee1394'", RESULT="1", MODE="0640", GROUP="hal"
+# BUS="ide", KERNEL="hd[a-z]*", PROGRAM="/etc/udev/scripts/device-removable.sh  %k 'usb ieee1394'", RESULT="1", MODE="0640", GROUP="hal"
+BUS="usb", KERNEL="ub[a-z]*", MODE="0640", GROUP="hal"