hal/tools hal-system-storage-mount, 1.18, 1.19 hal-system-storage-unmount, 1.4, 1.5

David Zeuthen david at freedesktop.org
Thu Feb 9 18:40:03 PST 2006


Update of /cvs/hal/hal/tools
In directory gabe:/tmp/cvs-serv14635/tools

Modified Files:
	hal-system-storage-mount hal-system-storage-unmount 
Log Message:
2006-02-09  David Zeuthen  <davidz at redhat.com>

        * tools/hal-system-storage-unmount: Use new property on the hal
        device object to figure out where hal mounted the device. This
        also ensures we only unmount stuff that we mounted ourselves
        ... where we = the hal mount/unmount methods. Also only allow the
        user who mounted the volume to unmount it (also allow uid 0).

        * tools/hal-system-storage-mount: Allow mounting of drives we
        don't poll. Export mount point and what uid mounted it as
        properties on the hal device object

        * fdi/policy/10osvendor/20-storage-methods.fdi: Fix up detection
        of blank and audio discs for the purpose of adding Eject methods.
        Export Mount, Unmount and Eject methods on drives we don't poll.
        Give some leeway with what mount options we support.



Index: hal-system-storage-mount
===================================================================
RCS file: /cvs/hal/hal/tools/hal-system-storage-mount,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- hal-system-storage-mount	26 Jan 2006 15:15:07 -0000	1.18
+++ hal-system-storage-mount	10 Feb 2006 02:40:01 -0000	1.19
@@ -59,7 +59,11 @@
 
 # if no mountpoint is given, use default name
 if [ "$GIVEN_MOUNTPOINT" == "" ]; then
-    GIVEN_MOUNTPOINT="disk"
+    if [ "$HAL_PROP_STORAGE_MEDIA_CHECK_ENABLED" == "false" ]; then
+	GIVEN_MOUNTPOINT="$HAL_PROP_STORAGE_DRIVE_TYPE"
+    else
+	GIVEN_MOUNTPOINT="disk"
+    fi
 fi
 
 # last check, we've replaced invalid characters in requested mountpoint
@@ -150,8 +154,14 @@
     exit 1
 fi
 
+if [ "$MOUNTTYPE" != "" ]; then
+    MOUNTTYPE_EXPANDED="-t \"$MOUNTTYPE\""
+else
+    MOUNTTYPE_EXPANDED=""
+fi
+
 # mount and return status
-RESULT=$(mount -o "noexec,nosuid,nodev$MOUNTOPTIONS" -t "$MOUNTTYPE" "$HAL_PROP_BLOCK_DEVICE" "$MOUNT_ROOT/$MOUNTPOINT" 2>&1)
+RESULT=$(mount -o "noexec,nosuid,nodev$MOUNTOPTIONS" $MOUNTTYPE_EXPANDED "$HAL_PROP_BLOCK_DEVICE" "$MOUNT_ROOT/$MOUNTPOINT" 2>&1)
 if [ $? -ne 0 ]; then
     case "$RESULT" in
 	*"unknown filesystem"*)
@@ -169,4 +179,7 @@
     exit 1
 fi
 
+hal-set-property --udi $UDI --key info.hal_mount.created_mount_point --string "$MOUNT_ROOT/$MOUNTPOINT" > /dev/null 2>&1
+hal-set-property --udi $UDI --key info.hal_mount.mounted_by_uid --int "$HAL_METHOD_INVOKED_BY_UID" > /dev/null 2>&1
+
 exit 0

Index: hal-system-storage-unmount
===================================================================
RCS file: /cvs/hal/hal/tools/hal-system-storage-unmount,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- hal-system-storage-unmount	11 Jan 2006 17:00:21 -0000	1.4
+++ hal-system-storage-unmount	10 Feb 2006 02:40:01 -0000	1.5
@@ -1,6 +1,7 @@
 #!/bin/bash
 
 # Copyright (C) 2005, Kay Sievers <kay.sievers at vrfy.org>
+# Copyright (C) 2006, David Zeuthen <david at fubar.dk>
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License version 2.
@@ -12,12 +13,29 @@
     exit 1
 fi
 
-if [ "$HAL_PROP_VOLUME_IS_MOUNTED" != "true" ]; then
+MOUNT_POINT="$HAL_PROP_INFO_HAL_MOUNT_CREATED_MOUNT_POINT"
+if [ "$MOUNT_POINT" == "" ]; then
     echo "org.freedesktop.Hal.Device.Volume.NotMounted" >&2
-    echo "Device is not mounted." >&2
+    echo "Cannot figure out where device is mounted." >&2
     exit 1
 fi
 
+if [ "$HAL_PROP_STORAGE_MEDIA_CHECK_ENABLED" != "false" ]; then
+    if [ "$HAL_PROP_VOLUME_IS_MOUNTED" != "true" ]; then
+	echo "org.freedesktop.Hal.Device.Volume.NotMounted" >&2
+	echo "Device is not mounted." >&2
+	exit 1
+    fi
+fi
+
+if [ "$HAL_METHOD_INVOKED_BY_UID" != "0" ]; then
+    if [ "$HAL_METHOD_INVOKED_BY_UID" != "$HAL_PROP_INFO_HAL_MOUNT_MOUNTED_BY_UID" ]; then
+	echo "org.freedesktop.Hal.Device.Volume.PermissionDenied" >&2
+	echo "Volume mounted by uid $HAL_PROP_INFO_HAL_MOUNT_MOUNTED_BY_UID cannot be unmounted by uid $HAL_METHOD_INVOKED_BY_UID." >&2
+	exit 1
+    fi
+fi
+
 # read parameters
 # "lazy\tforce\n"
 # Only allow ^a-zA-Z0-9_= in the string because otherwise someone may
@@ -59,7 +77,7 @@
     done
 fi
 
-RESULT=$(umount $UNMOUNTOPTIONS "$HAL_PROP_VOLUME_MOUNT_POINT" 2>&1)
+RESULT=$(umount $UNMOUNTOPTIONS "$MOUNT_POINT"  2>&1)
 if [ $? -ne 0 ]; then
     case "$RESULT" in
 	*busy*)
@@ -78,9 +96,12 @@
 fi
 
 # remove directory only if HAL has created it
-if [ -e $HAL_PROP_VOLUME_MOUNT_POINT/.created-by-hal ]; then
-  rm -f $HAL_PROP_VOLUME_MOUNT_POINT/.created-by-hal
-  rmdir --ignore-fail-on-non-empty "$HAL_PROP_VOLUME_MOUNT_POINT"
+if [ -e $MOUNT_POINT/.created-by-hal ]; then
+  rm -f $MOUNT_POINT/.created-by-hal
+  rmdir --ignore-fail-on-non-empty "$MOUNT_POINT"
 fi
 
+hal-set-property --udi $UDI --key info.hal_mount.created_mount_point --remove > /dev/null 2>&1
+hal-set-property --udi $UDI --key info.hal_mount.mounted_by_uid --remove > /dev/null 2>&1
+
 exit 0




More information about the hal-commit mailing list