From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Zeuthen Date: Tue, 09 Jun 2009 00:45:57 +0000 Subject: Re: udev rule for unmount action Message-Id: <1244508357.18491.31.camel@localhost.localdomain> List-Id: References: <200906061702.10974.chris@ilovelinux.de> In-Reply-To: <200906061702.10974.chris@ilovelinux.de> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable To: linux-hotplug@vger.kernel.org Hi, On Sat, 2009-06-06 at 17:02 +0200, Christian Schmitt wrote: > Hi, >=20 > I am trying to write a udev rule for my external HD that needs some speci= al=20 > "care" when being unmounted (see here:=20 > 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 unmoun= t=20 > command and execute a script. The "ACTION=3Dremove" rule only works when = I=20 > unplug the device. Is there a way to execute a script when unmounting? I = guess=20 > 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.=20 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[7350df8b63= cf4178a2fe69ee740b5222130421 Then I added support for this in GVfs which is what Nautilus uses. http://git.gnome.org/cgit/gvfs/commit/?id'b14622b7fcc228ddd617ebd723751ccd8= dadaa http://git.gnome.org/cgit/gnome-disk-utility/commit/?id=F76001f6f6beca8b21f= f81e70f2633c60783479f (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