I’m using Udisks via dbus in python to unmount a usb device (in this case a Kindle), but I’d like to send the eject signal to it, as this kicks the Kindle back from USB mode into its usual interface.
Udisks won’t let me DriveEject, as it’s not an actual drive, and I gather this is a feature. The error given is:
dbus.exceptions.DBusException: org.freedesktop.UDisks.Error.Failed: Device is not a drive
The Udisks documentation mentions the ejectable property:
ID_DRIVE_EJECTABLE
Whether the media in the drive is
physically ejectable. Only set this to
1 (or 0) if the drive truly uses (or
doesn’t) ejectable media. In
particular, it is not necessary to set
this for e.g. iPod or Kindle devices
where it is necessary to send a
command via eject(1) since the desktop
user session will offer this option
for removable devices regardless of
whether they are ejectable. If this
property is not set, a heuristic will
be used to determine if the media is
ejectable (drives using optical, Zip
or Jaz media are considered
ejectable).
but doesn’t explain how to do this from the desktop user session.
(Nautilus lets me eject just fine from the desktop shell. The ‘eject’ shell command will unmount but won’t send the eject signal to the device without sudo)
Is there any legitimate way to do this with Udisks, and if not, how does nautlius go about doing it?
So it turns out I was trying to eject the partition, not the drive itself, hence the “Device is not a drive error”. (Which is to say, calling udisks eject on /dev/sdc1 rather than /dev/sdc)
The solution was to first unmount the partition using FilesystemUnmount(), then find the parent drive using the “PartitionSlave” property, and call DriveEject() on this.
In python with dbus, assuming you already have a device object from Udisks for the parition, this looks something like: