I'm just going to post my xfce auto-mounting code here because it's kind of semi-functional and I'm tired of working on it. Automounting works. It's unmounting that's more difficult. This should all be considered experimental.
First, a script to detect filesystem type and mount or unmount them:
/usr/local/libexec/xfce-mount
Code:
#!/bin/sh
# mount/unmount a removable storage device
# Warren Block, 2011-04-10
# modify /usr/local/etc/gamin/gaminrc, set to poll user Desktop directory
# poll /usr/home/wblock/Desktop/*
cmd=$1 # (mount/umount)
username=$2
devnode=$3
# $0 mount username /dev/da0s1
# $0 umount username
deskdev="/home/$username/Desktop/removable-storage"
# return a file type string for a devnode
fstype () {
case `file -s $1 | egrep -o 'FAT|NTFS|EXT2|ISO 9660|Unix Fast File system' | tr ' ' _` in
FAT*)
printf "msdosfs" ;;
NTFS*)
printf "ntfs" ;;
EXT2*)
printf "ext2fs" ;;
ISO_9660*)
printf "cd9660" ;;
Unix_Fast_File_system*)
printf "ufs" ;;
esac
}
mount_it () {
if [ ! -c "$devnode" ]; then
echo "$devnode does not exist"
return
fi
if [ ! -d "$deskdev" ]; then
mkdir $deskdev
chown $username:operator $deskdev
chmod 770 $deskdev
fi
fs=`fstype $devnode`
mount -t $fs $devnode $deskdev
}
umount_it () {
if `mount | grep -q $deskdev`; then
umount $deskdev
fi
# only remove mount directory if it exists and is empty
if [ -d $deskdev -a ! "`ls -A $deskdev`" ]; then
rm -rf "$deskdev"
fi
}
case $cmd in
mount*)
mount_it ;;
umount*)
umount_it ;;
esac
Configure
devd(8) to run that script:
/etc/devd.conf
Code:
...
# WB
# automount USB storage devices
notify 20 {
match "system" "DEVFS";
match "type" "CREATE";
match "cdev" "da[0-9]s1$";
action "su wblock -c '/usr/local/libexec/xfce-mount mount wblock /dev/$cdev'";
};
# WB
# unmount USB storage devices
notify 20 {
match "system" "DEVFS";
match "type" "DESTROY";
match "cdev" "da[0-9]s1$";
action "su wblock -c '/usr/local/libexec/xfce-mount umount wblock /dev/$cdev'";
};
As noted above,
devel/gamin has to be set to poll the mountpoint instead of opening it for read in an infuriating fashion that prevents unmounting.
/usr/local/etc/gamin/gaminrc
Code:
poll /usr/home/wblock/Desktop/*
User must be a member of wheel and usermount must be enabled:
/etc/sysctl.conf
Finally, add an "Unmount" menu option in Thunar so there will be a menu entry to unmount the device before unplugging it:
Start Thunar.
Edit/Configure custom actions...
Click + to add a new one.
Name: Unmount
Description: Unmount a volume
Command: /sbin/umount %f
(Note: do not quote that %f, it does not work. I don't know why, but hope xfce quotes or escapes arguments internally.)
Click the Appearance Conditions tab.
File Pattern: removable-storage
Select (check) Directories, Okay, Close.
To use:
Plug in the USB drive or memory card. An icon for "removable-storage" will appear on the desktop. Use as normal. When done, open the desktop in Thunar, right-click removable-storage and select Unmount. Disconnect the storage device and the icon will disappear.
Problems:
It only looks for the first slice. Disks with multiple slices or bsdlabels are not handled.
Despite the polling setting, I still see gam_server occasionally opening the removable-storage mountpoint for read, and preventing an unmount. Deinstalling gamin solves that, but icons aren't auto-redrawn on the desktop and probably elsewhere. Pressing F5 does that. Might be something that could be triggered with a dbus message from the mount script, don't know.
Trying to unmount from the desktop right-click context menu instead of within Thunar does not work. No idea why, maybe just to be annoying.