hal/hald/linux2/addons addon-storage.c,1.14,1.15
Kay Sievers
kay at freedesktop.org
Fri Jan 27 07:44:00 PST 2006
Update of /cvs/hal/hal/hald/linux2/addons
In directory gabe:/tmp/cvs-serv30063/hald/linux2/addons
Modified Files:
addon-storage.c
Log Message:
2006-01-27 Kay Sievers <kay.sievers at vrfy.org>
* hald/linux2/addons/addon-storage.c: (main): Switch EjectButton
event detection to SG_IO interface. This should solve problems with
some SCSI drives and be the better interface anyway. For details see:
https://bugzilla.novell.com/show_bug.cgi?id=145147
Index: addon-storage.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux2/addons/addon-storage.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- addon-storage.c 2 Nov 2005 15:38:14 -0000 1.14
+++ addon-storage.c 27 Jan 2006 15:43:58 -0000 1.15
@@ -42,6 +42,7 @@
#include <linux/cdrom.h>
#include <linux/fs.h>
#include <mntent.h>
+#include <scsi/sg.h>
#include "libhal/libhal.h"
@@ -270,26 +271,22 @@
/* check if eject button was pressed */
if (got_media) {
- struct cdrom_generic_command cgc;
- struct request_sense sense;
+ unsigned char cdb[10] = { 0x4a, 1, 0, 0, 16, 0, 0, 0, 8, 0};
unsigned char buffer[8];
- int ret;
+ struct sg_io_hdr sg_h;
+ int retval;
- memset (&cgc, 0, sizeof (struct cdrom_generic_command));
- memset (&sense, 0, sizeof (struct request_sense));
- 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);
- 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) {
+ memset(buffer, 0, sizeof(buffer));
+ memset(&sg_h, 0, sizeof(struct sg_io_hdr));
+ sg_h.interface_id = 'S';
+ sg_h.cmd_len = sizeof(cdb);
+ sg_h.dxfer_direction = SG_DXFER_FROM_DEV;
+ sg_h.dxfer_len = sizeof(buffer);
+ sg_h.dxferp = buffer;
+ sg_h.cmdp = cdb;
+ sg_h.timeout = 5000;
+ retval = ioctl(fd, SG_IO, &sg_h);
+ if (retval == 0 && sg_h.status == 0 && (buffer[4] & 0x0f) == 0x01) {
DBusError error;
/* emit signal from drive device object */
@@ -297,7 +294,6 @@
libhal_device_emit_condition (ctx, udi, "EjectPressed", "", &error);
}
}
-
close (fd);
} else {
fd = open (device_file, O_RDONLY);
More information about the hal-commit
mailing list