HAL methods at storage device level,
to mount/unmount/eject volumes
Kay Sievers
kay.sievers at vrfy.org
Thu Dec 8 14:06:19 PST 2005
On Thu, Dec 08, 2005 at 01:36:09PM -0500, David Zeuthen wrote:
> On Thu, 2005-12-08 at 16:49 +0100, Kay Sievers wrote:
> > HAL volume method interface to request privileged operations like mount, umount, eject
> >
> > Every storage device which contains a recognized filesystem exposes the
> > methods, which can be invoked over the usual HAL D-BUS interface:
> > Mount(string:path, string:options)
> > UnMount()
> > Eject()
> >
> > In the future, this interface could be extended to provide SetLabel(),
> > Format() or any other useful action.
>
> Awesome stuff! Suggest s/UnMount/Unmount/
Done.
> and to pass options as an array of strings.
Yeah, comitted the needed support for this to CVS now.
> Do we want to allow passing the filesystem to use? Thinking ppl want to
> mount use fs msdos instead of vfat to get true 8.3 filenames. Deny
> everything but this. Can this be done through mount options?
We have an additional parameter now:
Mount(string:directory, string:fstype stringlist:options)
The dbus call look like this:
$ dbus-send --system --print-reply --dest=org.freedesktop.Hal \
/org/freedesktop/Hal/devices/volume_uuid_a5ea6ca9_485c_4e0f_95b3_ea85324403e2
org.freedesktop.Hal.Device.Volume.Mount string: string: array:string:sync,ro
method return sender=:1.10102 -> dest=:1.10403
uint32 0
$ dbus-send --system --print-reply --dest=org.freedesktop.Hal \
/org/freedesktop/Hal/devices/volume_uuid_a5ea6ca9_485c_4e0f_95b3_ea85324403e2 \
org.freedesktop.Hal.Device.Volume.Mount string: string: array:string:sync,ro,myopt
Error org.freedesktop.Hal.Device.Volume.InvalidMountOption:
> addition to ro, sync, quiet (we do we allow quiet btw?)
>
> - noatime
> - nodiratime
> - noexec
> - dirsync
Added.
Should work for a very first cut. The scripts need to be extended, sure,
but we should be able to start using it now.
Thanks,
Kay
-------------- next part --------------
<?xml version="1.0" encoding="UTF-8"?>
<deviceinfo version="0.2">
<device>
<match key="volume.fsusage" string="filesystem">
<append key="info.interfaces" type="strlist">org.freedesktop.Hal.Device.Volume</append>
<append key="org.freedesktop.Hal.Device.Volume.method_names" type="strlist">Mount</append>
<append key="org.freedesktop.Hal.Device.Volume.method_signatures" type="strlist">ssas</append>
<append key="org.freedesktop.Hal.Device.Volume.method_execpaths" type="strlist">hal-system-storage-mount</append>
<append key="org.freedesktop.Hal.Device.Volume.method_names" type="strlist">Unmount</append>
<append key="org.freedesktop.Hal.Device.Volume.method_signatures" type="strlist"></append>
<append key="org.freedesktop.Hal.Device.Volume.method_execpaths" type="strlist">hal-system-storage-unmount</append>
<append key="org.freedesktop.Hal.Device.Volume.method_names" type="strlist">Eject</append>
<append key="org.freedesktop.Hal.Device.Volume.method_signatures" type="strlist"></append>
<append key="org.freedesktop.Hal.Device.Volume.method_execpaths" type="strlist">hal-system-storage-eject</append>
</match>
</device>
</deviceinfo>
-------------- next part --------------
#!/bin/sh -e
# Copyright (C) 2005, Kay Sievers <kay.sievers at vrfy.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2.
MOUNT_ROOT="/media"
# Check for environment variables
if [ "$HAL_PROP_BLOCK_DEVICE" == "" ] || [ "$HAL_PROP_INFO_UDI" == "" ] ; then
echo "Missing or empty environment variable(s)." >&2
echo "This script should be started by hald." >&2
exit 1
fi
# check if device is already mounted
if [ "$HAL_PROP_VOLUME_IS_MOUNTED" = "true" ]; then
echo "org.freedesktop.Hal.Device.Volume.AlreadyMounted" >&2
echo "$HAL_PROP_VOLUME_MOUNT_POINT" >&2
exit 1
fi
# read parameters
# "MyDisk\n"
# "fuse\n"
# "ro\tsync\n"
read GIVEN_MOUNTPOINT
read GIVEN_MOUNTTYPE
read GIVEN_MOUNTOPTIONS
# if no mountpoint, get mountpoint from label
if [ "$GIVEN_MOUNTPOINT" == "" ]; then
case "$HAL_PROP_VOLUME_LABEL" in
*[!A-Za-z0-9_\-\+:]*)
break
;;
esac
GIVEN_MOUNTPOINT="$HAL_PROP_VOLUME_LABEL"
fi
# if no mountpoint, use default name
if [ "$GIVEN_MOUNTPOINT" == "" ]; then
GIVEN_MOUNTPOINT="disk"
fi
# validate characters in mountpoint
case "$GIVEN_MOUNTPOINT" in
*[!A-Za-z0-9_\-\+:]*)
echo "org.freedesktop.Hal.Device.Volume.InvalidMountpoint" >&2
echo "" >&2
exit 1
;;
esac
MOUNTPOINT="$GIVEN_MOUNTPOINT"
# pass only whitelisted mount options
if [ "$GIVEN_MOUNTOPTIONS" != "" ]; then
for OPTION in $GIVEN_MOUNTOPTIONS; do
case "$OPTION" in
ro)
MOUNTOPTIONS="$MOUNTOPTIONS,ro"
;;
sync)
MOUNTOPTIONS="$MOUNTOPTIONS,sync"
;;
dirsync)
MOUNTOPTIONS="$MOUNTOPTIONS,dirsync"
;;
noatime)
MOUNTOPTIONS="$MOUNTOPTIONS,noatime"
;;
nodiratime)
MOUNTOPTIONS="$MOUNTOPTIONS,nodiratime"
;;
noexec)
MOUNTOPTIONS="$MOUNTOPTIONS,noexec"
;;
quiet)
MOUNTOPTIONS="$MOUNTOPTIONS,quiet"
;;
*)
echo "org.freedesktop.Hal.Device.Volume.InvalidMountOption" >&2
echo "" >&2
exit 1
esac
done
fi
# append number to mountpoint if it already exists
if [ -e "$MOUNT_ROOT/$MOUNTPOINT" ]; then
NUM=1;
while [ -e "$MOUNT_ROOT/$MOUNTPOINT-$NUM" ]; do
NUM=$(($NUM + 1))
done
MOUNTPOINT="$MOUNTPOINT-$NUM"
fi
# create directory and mark it for cleanup with an extended attribute
if [ ! -e "$MOUNT_ROOT/$MOUNTPOINT" ]; then
MOUNTPOINT_CREATED=1
mkdir "$MOUNT_ROOT/$MOUNTPOINT"
attr -s HAL_MOUNTPOINT -V "$HAL_PROP_INFO_UDI" "$MOUNT_ROOT/$MOUNTPOINT" > /dev/null 2>&1
fi
if [ ! -e "$MOUNT_ROOT/$MOUNTPOINT" ]; then
echo "org.freedesktop.Hal.Device.Volume.FailedToCreateMountpoint" >&2
echo "$MOUNT_ROOT/$MOUNTPOINT" >&2
exit 1
fi
# mount and return status
mount -o "nosuid,nodev$MOUNTOPTIONS" -t "$HAL_PROP_VOLUME_FSTYPE" "$HAL_PROP_BLOCK_DEVICE" "$MOUNT_ROOT/$MOUNTPOINT" > /dev/null 2>&1
logger O="nosuid,nodev$MOUNTOPTIONS" T="$HAL_PROP_VOLUME_FSTYPE" "$HAL_PROP_BLOCK_DEVICE" "$MOUNT_ROOT/$MOUNTPOINT"
if [ $? -ne 0 ]; then
if [ -n "$MOUNTPOINT_CREATED" ]; then
rmdir "$MOUNT_ROOT/$MOUNTPOINT"
fi
echo "org.freedesktop.Hal.Device.Volume.MountFailed" >&2
echo "$MOUNT_ROOT/$MOUNTPOINT" >&2
exit 1
fi
exit 0
-------------- next part --------------
#!/bin/sh -e
# Copyright (C) 2005, Kay Sievers <kay.sievers at vrfy.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2.
# Check for environment variables
if [ "$HAL_PROP_BLOCK_DEVICE" == "" ] || [ "$HAL_PROP_INFO_UDI" == "" ] ; then
echo "Missing or empty environment variable(s)." >&2
echo "This script should be started by hald." >&2
exit 1
fi
if [ "$HAL_PROP_VOLUME_IS_MOUNTED" != "true" ]; then
echo "org.freedesktop.Hal.Device.Volume.NotMounted" >&2
echo "$HAL_PROP_VOLUME_MOUNT_POINT" >&2
exit 1
fi
umount "$HAL_PROP_VOLUME_MOUNT_POINT" > /dev/null 2>&1 || true
if [ $? -ne 0 ]; then
echo "org.freedesktop.Hal.Device.Volume.UnmountFailed" >&2
echo "$HAL_PROP_VOLUME_MOUNT_POINT" >&2
exit 1
fi
# remove directory only if HAL has created it
attr -q -g HAL_MOUNTPOINT "$HAL_PROP_VOLUME_MOUNT_POINT" > /dev/null 2>&1 || exit 0
rmdir --ignore-fail-on-non-empty "$HAL_PROP_VOLUME_MOUNT_POINT"
exit 0
-------------- next part --------------
#!/bin/sh
# Copyright (C) 2005, Kay Sievers <kay.sievers at vrfy.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2.
#
# Check for environment variables
if [ "$HAL_PROP_BLOCK_DEVICE" == "" ] || [ "$HAL_PROP_INFO_UDI" == "" ] ; then
echo "Missing or empty environment variable(s)." >&2
echo "This script should be started by hald." >&2
exit 1
fi
eject "$HAL_PROP_BLOCK_DEVICE" > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "org.freedesktop.Hal.Device.Volume.EjectFailed" >&2
echo "$HAL_PROP_BLOCK_DEVICE" >&2
exit 1
fi
exit 0
More information about the hal
mailing list