Bug 24052 – CDROM eject button is locked while CDROM is mounted
authorMartin Pitt <martin.pitt@ubuntu.com>
Tue, 6 Oct 2009 08:51:09 +0000 (10:51 +0200)
committerDavid Zeuthen <davidz@redhat.com>
Fri, 9 Oct 2009 13:40:09 +0000 (09:40 -0400)
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

Signed-off-by: David Zeuthen <davidz@redhat.com>
src/devkit-disks-device.c

index 60153d9..6460afd 100644 (file)
@@ -38,6 +38,7 @@
 #include <grp.h>
 #include <linux/fs.h>
 #include <sys/ioctl.h>
+#include <linux/cdrom.h>
 
 #include <glib.h>
 #include <glib/gstdio.h>
@@ -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 {