From 28d3405ac2e5f7631e10946d5eee4e22cad37d34 Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Tue, 6 Oct 2009 10:51:09 +0200 Subject: [PATCH] unlock CD trays after mounting Unlike in the hal world, we do not have a daemon polling CD drives for eject button presses. In order to make hardware tray eject buttons work, unlock the tray after mounting a CD. This is pretty much equivalent to yanking out USB sticks, which we already handle reasonably (detecting disappeared device, force-unmounting). https://bugs.freedesktop.org/show_bug.cgi?id=24052 --- src/devkit-disks-device.c | 19 +++++++++++++++++++ 1 files changed, 19 insertions(+), 0 deletions(-) diff --git a/src/devkit-disks-device.c b/src/devkit-disks-device.c index 60153d9..1b823af 100644 --- a/src/devkit-disks-device.c +++ b/src/devkit-disks-device.c @@ -38,6 +38,7 @@ #include #include #include +#include #include #include @@ -4395,6 +4396,23 @@ prepend_default_mount_options (const FSMountOptions *fsmo, uid_t caller_uid, cha } static void +unlock_cd_tray (DevkitDisksDevice *device) +{ + /* Unlock CD tray to keep the hardware eject button working */ + if (g_udev_device_has_property (device->priv->d, "ID_CDROM")) { + g_print ("**** Unlocking CD-ROM door for %s\n", device->priv->device_file); + int fd = open(device->priv->device_file, O_RDONLY); + if (fd > 0) { + if (ioctl (fd, CDROM_LOCKDOOR, 0) != 0) + g_warning ("Could not unlock CD-ROM door: %s", strerror (errno)); + close (fd); + } else { + g_warning ("Could not open CD-ROM device: %s", strerror (errno)); + } + } +} + +static void filesystem_mount_completed_cb (DBusGMethodInvocation *context, DevkitDisksDevice *device, gboolean job_was_cancelled, @@ -4412,6 +4430,7 @@ filesystem_mount_completed_cb (DBusGMethodInvocation *context, update_info (device); drain_pending_changes (device, FALSE); + unlock_cd_tray (device); dbus_g_method_return (context, data->mount_point); } else { -- 1.6.3.3