From 51255b864c09390a96f49ed14a70916eb75b6456 Mon Sep 17 00:00:00 2001 From: David Zeuthen Date: Thu, 11 Aug 2011 18:05:11 -0400 Subject: [PATCH] Use -T for eject(1) on optical drives This enables the "eject" button in palimpsest to close the tray if it's opened already. Signed-off-by: David Zeuthen --- data/org.freedesktop.UDisks2.xml | 4 +++- src/udiskslinuxdrive.c | 27 ++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/data/org.freedesktop.UDisks2.xml b/data/org.freedesktop.UDisks2.xml index 4a5b21c..be71e0a 100644 --- a/data/org.freedesktop.UDisks2.xml +++ b/data/org.freedesktop.UDisks2.xml @@ -175,7 +175,9 @@ other hardware may simply eject the disc. On some hardware it may not do anything physical but it may cause e.g. a display on the hardware to show e.g. It is now safe to remove - the device. + the device. If called on a drive with an open tray, + the "tray close" command may be sent if the hardware supports + it. --> diff --git a/src/udiskslinuxdrive.c b/src/udiskslinuxdrive.c index 16c54d3..4671fe1 100644 --- a/src/udiskslinuxdrive.c +++ b/src/udiskslinuxdrive.c @@ -654,10 +654,14 @@ on_eject (UDisksDrive *drive_iface, UDisksDaemon *daemon; const gchar *action_id; gchar *error_message; + gboolean is_cdrom; + const gchar *const *media_compat; + guint n; daemon = NULL; block = NULL; error_message = NULL; + is_cdrom = FALSE; daemon = udisks_linux_drive_get_daemon (drive); block_object = find_block_object (drive); @@ -685,12 +689,33 @@ on_eject (UDisksDrive *drive_iface, invocation)) goto out; + /* Check if CD drive and, if so, use -T to support opening/closing + * the tray + * + * From the eject(1) man page + * + * With this option the drive is given a CD-ROM tray close command + * if it's opened, and a CD-ROM tray eject command if it's + * closed. Not all devices support this command, because it uses + * the above CD-ROM tray close command. + */ + media_compat = udisks_drive_get_media_compatibility (drive_iface); + for (n = 0; media_compat != NULL && media_compat[n] != NULL; n++) + { + if (g_str_has_prefix (media_compat[n], "optical")) + { + is_cdrom = TRUE; + break; + } + } + if (!udisks_daemon_launch_spawned_job_sync (daemon, NULL, /* GCancellable */ 0, /* uid_t run_as */ &error_message, NULL, /* input_string */ - "eject \"%s\"", + "eject %s\"%s\"", + is_cdrom ? "-T " : "", udisks_block_device_get_device (block))) { g_dbus_method_invocation_return_error (invocation, -- 2.7.4