From 88861a88884727091c9ffbd30030a6e31d061dde Mon Sep 17 00:00:00 2001 From: Michael Lotz Date: Mon, 31 Aug 2009 15:08:38 +0000 Subject: [PATCH] Also test for the "no medium persent" case and don't tell B_DEV_MEDIA_CHANGED in such a case as that would try to read info about a non-present medium. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32862 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../drivers/disk/usb/usb_disk/usb_disk.cpp | 30 +++++++++++-------- .../drivers/disk/usb/usb_disk/usb_disk_scsi.h | 3 ++ 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/add-ons/kernel/drivers/disk/usb/usb_disk/usb_disk.cpp b/src/add-ons/kernel/drivers/disk/usb/usb_disk/usb_disk.cpp index 42ea333fca..dcf4be1a50 100644 --- a/src/add-ons/kernel/drivers/disk/usb/usb_disk/usb_disk.cpp +++ b/src/add-ons/kernel/drivers/disk/usb/usb_disk/usb_disk.cpp @@ -426,7 +426,8 @@ usb_disk_request_sense(device_lun *lun) return result; } - if (parameter.sense_key > SCSI_SENSE_KEY_NOT_READY) { + if (parameter.sense_key > SCSI_SENSE_KEY_NOT_READY + && parameter.sense_key != SCSI_SENSE_KEY_UNIT_ATTENTION) { TRACE_ALWAYS("request_sense: key: 0x%02x; asc: 0x%02x; ascq: 0x%02x;\n", parameter.sense_key, parameter.additional_sense_code, parameter.additional_sense_code_qualifier); @@ -437,14 +438,6 @@ usb_disk_request_sense(device_lun *lun) case SCSI_SENSE_KEY_RECOVERED_ERROR: return B_OK; - case SCSI_SENSE_KEY_NOT_READY: - TRACE("request_sense: device not ready (asc 0x%02x ascq 0x%02x)\n", - parameter.additional_sense_code, - parameter.additional_sense_code_qualifier); - lun->media_present = false; - usb_disk_reset_capacity(lun); - return B_DEV_NO_MEDIA; - case SCSI_SENSE_KEY_HARDWARE_ERROR: case SCSI_SENSE_KEY_MEDIUM_ERROR: TRACE_ALWAYS("request_sense: media or hardware error\n"); @@ -455,10 +448,21 @@ usb_disk_request_sense(device_lun *lun) return B_DEV_INVALID_IOCTL; case SCSI_SENSE_KEY_UNIT_ATTENTION: - TRACE_ALWAYS("request_sense: media changed\n"); - lun->media_changed = true; - lun->media_present = true; - return B_DEV_MEDIA_CHANGED; + if (parameter.additional_sense_code != SCSI_ASC_MEDIUM_NOT_PRESENT) { + TRACE_ALWAYS("request_sense: media changed\n"); + lun->media_changed = true; + lun->media_present = true; + return B_DEV_MEDIA_CHANGED; + } + // fall through + + case SCSI_SENSE_KEY_NOT_READY: + TRACE("request_sense: device not ready (asc 0x%02x ascq 0x%02x)\n", + parameter.additional_sense_code, + parameter.additional_sense_code_qualifier); + lun->media_present = false; + usb_disk_reset_capacity(lun); + return B_DEV_NO_MEDIA; case SCSI_SENSE_KEY_DATA_PROTECT: TRACE_ALWAYS("request_sense: write protected\n"); diff --git a/src/add-ons/kernel/drivers/disk/usb/usb_disk/usb_disk_scsi.h b/src/add-ons/kernel/drivers/disk/usb/usb_disk/usb_disk_scsi.h index c204468025..f5306a89ff 100644 --- a/src/add-ons/kernel/drivers/disk/usb/usb_disk/usb_disk_scsi.h +++ b/src/add-ons/kernel/drivers/disk/usb/usb_disk/usb_disk_scsi.h @@ -99,6 +99,9 @@ typedef enum { SCSI_SENSE_KEY_ABORTED_COMMAND = 0x0b, } scsi_sense_key; +// request sense additional sense codes +#define SCSI_ASC_MEDIUM_NOT_PRESENT 0x3a + // mode sense page code/parameter #define SCSI_MODE_PAGE_DEVICE_CONFIGURATION 0x10 #define SCSI_DEVICE_SPECIFIC_WRITE_PROTECT 0x80