Bug 130427 - USB stick cannot be unmounted using context menu
Summary: USB stick cannot be unmounted using context menu
Status: RESOLVED WORKSFORME
Alias: None
Product: kio
Classification: Frameworks and Libraries
Component: media (show other bugs)
Version: unspecified
Platform: Mandriva RPMs Linux
: NOR normal
Target Milestone: ---
Assignee: Kevin Ottens
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-07-07 18:30 UTC by FACORAT Fabrice
Modified: 2010-11-04 06:53 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
HAL support for kdeeject (1.51 KB, patch)
2006-08-31 19:22 UTC, FACORAT Fabrice
Details
New version of HAL support for kdeeject (2.12 KB, patch)
2006-09-04 15:51 UTC, FACORAT Fabrice
Details
Updated patch for post 2010 hal (1.43 KB, patch)
2010-11-04 06:48 UTC, Artem S. Tashkinov
Details

Note You need to log in before you can comment on or make changes to this bug.
Description FACORAT Fabrice 2006-07-07 18:30:36 UTC
Version:            (using KDE KDE 3.5.3)
Installed from:    Mandriva RPMs
OS:                Linux

Insert USB stick, it is correctly mounted, icon appears in kicker applet 
indicating device and status.

Use context menu on applet -> Safely remove. Nothing happens. Adding echo to HAL umount script shows that it is never called.

Please fix, it makes it impossible to safely remove mounted media.

The problem is, for mounted removable drives KDE calls "kio_mount_helper -s" (media_safelyremove.desktop). It directly calls kdeeject which apparently does not support halbackend (or better, it apparently does not go via media manager to umount devices). Either kdeeject has to be fixed or  media_safelyremove.desktop should simply call "kio_mount_helper -u" - that does work correctly.


Mandriva bug report link : http://qa.mandriva.com/show_bug.cgi?id=23278
Comment 1 Daniel Eklöf 2006-07-29 13:55:19 UTC
This started to happening to me in kde-3.5.4, with the new mount/unmount code in the media manager. Editing media_safelyremove.desktop as suggested above solved the problem for me.
Comment 2 FACORAT Fabrice 2006-08-31 18:02:13 UTC
kdeeject needs to use HAL method to ject the devices.
See :

error() {
	kdialog --title "Safely Remove" --error "$1"
	exit 1
}

BLOCK_UDI=$(dcop kded mediamanager properties "$1" | head -1)
[ -n "$BLOCK_UDI" ] || error "Can't find UDI for URL $1"

STORAGE_UDI=$(hal-get-property --udi $BLOCK_UDI --key block.storage_device)
[ -n "$STORAGE_UDI" ] || error "Can't find device for volume $BLOCK_UDI"

for TMP in $(hal-find-by-property --key block.storage_device --string $STORAGE_UDI); do
	[ $(hal-get-property --udi $TMP --key block.is_volume) = true ] || continue
	[ $(hal-get-property --udi $TMP --key volume.is_mounted) = true ] || continue
	ERROR=$(dcop kded mediamanager unmount $TMP)
	[ -n "$ERROR" ] && error "$ERROR"
done

dbus-send --system --dest=org.freedesktop.Hal "$BLOCK_UDI" org.freedesktop.Hal.Device.Volume.Eject array:string:""
Comment 3 Kevin Ottens 2006-08-31 18:13:13 UTC
Can you still reproduce this bug with 3.5.4? If yes what is the version of the "eject" command on your system?
Comment 4 FACORAT Fabrice 2006-08-31 18:26:26 UTC
yes
[admin@info1 Mandriva 2007]$ eject -V
eject version 2.1.5 par Jeff Tranter (tranter@pobox.com)


Ok the issue is the following :
- removable media entries are no longer in /etc/fstab by HAL since version 0.5.4 IIRC
- So eject can't eject media which are not in fstab ( unless you are root ).
- Thus we need to use Hal method to eject the media, and if this fail, then we could try eject command as a fallback
Comment 5 FACORAT Fabrice 2006-08-31 18:46:06 UTC
kdeeject needs to be modified in the following way :

if HAL version > 0.5.4 Then
   if device volume.is_disc == FALSE Then
        for all block in volume
               if  block.is_volume  && volume.is_mounted Then
                     dcop kded mediamanager unmount
        done
   Else
       dcop kded mediamanager unmount
   fi
   dbus-send --system --dest=org.freedesktop.Hal blockdevice_udi org.freedesktop.Hal.Device.Volume.Eject array:string:""
else
   eject $1
fi
          
Comment 6 FACORAT Fabrice 2006-08-31 19:22:49 UTC
Created attachment 17589 [details]
HAL support for kdeeject

HAL support for kdeeject.
I modified only the Linux part ( I hope ) and check for HAL version as for HAL
< 0.5 entries was written in fstab and the eject method may not exist.
Comment 7 FACORAT Fabrice 2006-09-04 15:51:52 UTC
Created attachment 17634 [details]
New version of HAL support for kdeeject

Ok this new patch version :
- check for HAL userland tools presence before trying to use them
- doesn't try to get UDI from mediamanager to avoid bug #130424 side effects
- use mediamanager to umount the volume, and if this failed, try to use HAL
method
- if HAL is not available fallback to the old eject method
Comment 8 Daniel Eklöf 2006-09-25 18:14:11 UTC
Works for me. Thanks!
Comment 9 FACORAT Fabrice 2007-01-12 18:43:15 UTC
this is fixed in kde 3.5.5
Comment 10 Julien Etienne 2008-02-19 23:12:27 UTC
The issue is still present in kdebase-3.5.8 (for example see gentoo bug report http://bugs.gentoo.org/show_bug.cgi?id=186028 ).

I have fixed the problem using the dbus-send to send the eject command to HAL as other reporters have suggested.
Comment 11 Aron Parsons 2008-03-04 23:34:58 UTC
This is still present in KDE 3.5.9 on Gentoo x86_64.  I am following the same bug as reported in comment #10.
Comment 12 Artem S. Tashkinov 2010-11-04 06:48:08 UTC
Created attachment 53118 [details]
Updated patch for post 2010 hal

The previous patch doesn't work cleanly, because hal wants --print-reply option. Besides on my own PC eject command needs to be issued twice, otherwise HAL doesn't want to play by my rules:

The first invocation yields:

method return sender=:1.1 -> dest=:1.103 reply_serial=2
   int32 0

The second (which actually ejects the device) yields:

Error org.freedesktop.Hal.Device.UnknownError: An unknown error occured

- but this error message actually means that HAL succeeded. So, on the next line I check if the device still exists.
Comment 13 Artem S. Tashkinov 2010-11-04 06:53:49 UTC
And the original proposed patch has never been pushed upstream, so this bug cannot be "solved".

Here's this file from KDE 3.5 branch: http://websvn.kde.org/branches/KDE/3.5/kdebase/kdeeject/kdeeject?revision=568272&view=markup