Re: udev rule for unmount action

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

On Sat, 2009-06-06 at 17:02 +0200, Christian Schmitt wrote:
> Hi,
> 
> I am trying to write a udev rule for my external HD that needs some special 
> "care" when being unmounted (see here: 
> http://elliotli.blogspot.com/2009/01/safely-remove-usb-hard-drive-in-
> linux.html).

That's a very interesting blog entry, thanks for sharing. My experience
dealing with the storage stack in GNOME is that people keep asking for
this feature.

> The problem is that I can not find a way to make udev react on the unmount 
> command and execute a script. The "ACTION==remove" rule only works when I 
> unplug the device. Is there a way to execute a script when unmounting? I guess 
> doing this on the DE level is not the best way to go.

Actually I think doing this on the desktop level is the way forward.
There are two problems here.

First, consider a USB optical drive attached to the system. A typical
thing you want to do here is to eject the disc so you can insert another
one. Now, to eject media you first have to unmount it before you can
send the eject ioctl to the device. But if you hook into the unmount
process then you unbind the device before it is mounted and you never
get to send the eject ioctl.

The other example is when the user manually wants to unmount a partition
instead of ejecting it. Now, in the Nautilus file manager we do default
to ejecting stuff (the eject icon in the sidebar) but the user can also
right-click and click on Unmount in the context menu. If you hook into
the unmount process then the device(s) actually disappears, much against
what the user wanted.

Anyway, it's not a problem to do all this from the desktop level and I
just added support for this. 

First, I wrote a patch to DeviceKit-disks (the successor to HAL for
handling storage devices) that offers a DriveDetach() method and also
a :drive-can-detach property. Right now we only set :drive-can-detach
for USB devices but we can add support for other connection fabrics as
needed. The patch is here

http://cgit.freedesktop.org/DeviceKit/DeviceKit-disks/commit/?id=5b7350df8b63cf4178a2fe69ee740b5222130421

Then I added support for this in GVfs which is what Nautilus uses.

http://git.gnome.org/cgit/gvfs/commit/?id=27b14622b7fcc228ddd617ebd723751ccd8dadaa
http://git.gnome.org/cgit/gnome-disk-utility/commit/?id=f76001f6f6beca8b21ff81e70f2633c60783479f
(actually GVfs uses gnome-disk-utility which is a "binding" of some sort
of DeviceKit-disks. But that's unimportant for this discussion.)

So, in a nutshell, GNOME 2.28 will support powering down USB enclosures
out of the box.

Btw, another change I made is to only unbind the usb-storage driver to
better handle multifunction devices. E.g. you don't want to unbind
drivers from all the USB interfaces.

Cheers,
David


--
To unsubscribe from this list: send the line "unsubscribe linux-hotplug" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel]     [Linux DVB]     [Asterisk Internet PBX]     [DCCP]     [Netdev]     [X.org]     [Util Linux NG]     [Fedora Women]     [ALSA Devel]     [Linux USB]

  Powered by Linux