[PLEASE TEST] emit "EjectPressed" signal on optical drive

Kay Sievers kay.sievers at vrfy.org
Mon Oct 24 16:04:58 PDT 2005


Hi,
we had something like this in the old version of HAL. That time a lot
of drives did not support the eject event properly.

Let's try if it works with our current boxes. "dbus-monitor --system"
should show the event if you press the button of your optical drive.

Please guys test and report back if it works or not, to see if it's
worth to put that back.

Thanks,
Kay


-------------- next part --------------
Index: hald/linux2/addons/addon-storage.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux2/addons/addon-storage.c,v
retrieving revision 1.12
diff -u -r1.12 addon-storage.c
--- hald/linux2/addons/addon-storage.c	27 Sep 2005 09:42:13 -0000	1.12
+++ hald/linux2/addons/addon-storage.c	24 Oct 2005 22:59:37 -0000
@@ -268,6 +268,36 @@
 			default:
 				break;
 			}
+
+			/* check if eject button was pressed */
+			if (got_media) {
+				struct cdrom_generic_command cgc;
+				struct request_sense sense;
+				unsigned char buffer[8];
+				int ret;
+
+				memset (&cgc, 0, sizeof(struct cdrom_generic_command));
+				memset (buffer, 0, sizeof(buffer));
+				cgc.cmd[0] = GPCMD_GET_EVENT_STATUS_NOTIFICATION;
+				cgc.cmd[1] = 1;
+				cgc.cmd[4] = 16;
+				cgc.cmd[8] = sizeof (buffer);
+				memset (&sense, 0, sizeof (sense));
+				cgc.timeout = 600;
+				cgc.buffer = buffer;
+				cgc.buflen = sizeof (buffer);
+				cgc.data_direction = CGC_DATA_READ;
+				cgc.sense = &sense;
+				cgc.quiet = 1;
+				ret = ioctl (fd, CDROM_SEND_PACKET, &cgc);
+				if (ret == 0 && (buffer[4] & 0x0f) == 0x01) {
+					DBusError error;
+
+					dbus_error_init (&error);
+					libhal_device_emit_condition ( ctx, udi, "EjectPressed", "", &error);
+				}
+			}
+
 			close (fd);
 		} else {
 


More information about the hal mailing list