on 24/12/2007 16:32 Andriy Gapon said the following: > on 21/12/2007 15:33 Joe Marcus Clarke said the following: >> Disc media is treated differently than USB media. USB umass devices are >> assumed to have media. This is part of the issue with the card reader >> (floppy drives behave the same way). > > Isn't this a bad assumption?
Attached is a patch that attempts to address removable storage devices (that are not CD-ROMs) attached either via SCSI or via USB. The purpose is to do "gentler" probing of media presence than that done by OS in response to open(2). I employed one hack in the code to avoid device being open()-ed if cam_open_device() fails, but this was "just in case", not sure if it was really needed. The patch works very well for me, especially in tandem with the patch for SCSI verboseness that I posted to -stable and -scsi. -- Andriy Gapon
--- addons/addon-storage.c.orig Mon Dec 24 16:45:04 2007 +++ addons/addon-storage.c Mon Dec 24 18:22:19 2007 @@ -42,6 +42,7 @@ static struct char *device_file; char *parent; boolean is_cdrom; + boolean is_scsi_removable; boolean had_media; struct timeval next_update; } addon = { { 2, 0 } }; @@ -71,6 +72,18 @@ hf_addon_storage_cdrom_eject_pressed (HF } static boolean +hf_addon_storage_scsi_read_capacity (HFPCDROM *cdrom) +{ + unsigned char buf[8]; + static char ccb[16] = { /*HFP_CDROM_READ_CAPACITY*/ 0x25 }; + + assert(cdrom != NULL); + + /* we check only success/error and discard the data */ + return hfp_cdrom_send_ccb(cdrom, ccb, 10, HFP_CDROM_DIRECTION_IN, buf, sizeof(buf), NULL); +} + +static boolean hf_addon_storage_update (void) { boolean has_media = FALSE; @@ -94,6 +107,31 @@ hf_addon_storage_update (void) hfp_cdrom_free(cdrom); } } + else if (addon.is_scsi_removable) + { + /* (ab)use cdrom-specific routines: + * for what we are doing here there is no difference between + * a SCSI CD-ROM and any other disk-like SCSI device + * with removable media. + * This is a gentler check than trying to open the device. + */ + HFPCDROM *cdrom; + + /* XXX hfp_cdrom_new_from_fd(-1) below is an ugly hack to prevent + * regular open() in the case cam_open_device() fails. + */ + cdrom = hfp_cdrom_new_from_fd(-1, addon.device_file, addon.parent); + if (cdrom) + { + /* some umass devices may lie in TEST UNIT READY, + * so doing READ CAPACITY to be sure. + */ + if (hfp_cdrom_test_unit_ready(cdrom) && hf_addon_storage_scsi_read_capacity(cdrom)) + has_media = TRUE; + + hfp_cdrom_free(cdrom); + } + } else { int fd; @@ -115,7 +153,9 @@ hf_addon_storage_update (void) int main (int argc, char **argv) { - char *drive_type; + const char *drive_type; + const char *removable; + const char *bus; DBusConnection *connection; if (! hfp_init(argc, argv)) @@ -129,6 +169,14 @@ main (int argc, char **argv) if (! drive_type) goto end; + removable = getenv("HAL_PROP_STORAGE_REMOVABLE"); + if (! removable) + goto end; + + bus = getenv("HAL_PROP_STORAGE_BUS"); + if (! bus) + goto end; + addon.parent = getenv("HAL_PROP_INFO_PARENT"); if (! addon.parent) goto end; @@ -137,6 +185,7 @@ main (int argc, char **argv) setproctitle("%s", addon.device_file); addon.is_cdrom = ! strcmp(drive_type, "cdrom"); + addon.is_scsi_removable = (! strcmp(bus, "scsi") || ! strcmp(bus, "usb")) && ! strcmp(removable, "true"); addon.had_media = hf_addon_storage_update(); connection = libhal_ctx_get_dbus_connection(hfp_ctx);
_______________________________________________ kde-freebsd mailing list kde-freebsd@kde.org https://mail.kde.org/mailman/listinfo/kde-freebsd