Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mtl1979/1ccf367729ed3c43287f1383637a38ef to your computer and use it in GitHub Desktop.
Save mtl1979/1ccf367729ed3c43287f1383637a38ef to your computer and use it in GitHub Desktop.
Fix removable USB drive support in Haiku
From a92b332589eda8cf391ab8dd308fd1ee670c596f Mon Sep 17 00:00:00 2001
From: "Mika T. Lindqvist" <[email protected]>
Date: Mon, 16 Dec 2024 22:44:00 +0200
Subject: [PATCH] usb_disk: Don't synchronize cache or read if no media
present.
---
.../kernel/drivers/disk/usb/usb_disk/usb_disk.cpp | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
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 3f53fbd8ec..92635ef5b8 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
@@ -691,7 +691,7 @@ usb_disk_request_sense(device_lun *lun, err_act *_action)
} else if (parameter.sense_key == SCSI_SENSE_KEY_UNIT_ATTENTION
&& status != B_DEV_NO_MEDIA) {
lun->media_present = true;
- } else if (status == B_DEV_NOT_READY) {
+ } else if (status == B_DEV_NOT_READY || status == B_DEV_NO_MEDIA) {
lun->media_present = false;
usb_disk_reset_capacity(lun);
}
@@ -985,6 +985,9 @@ usb_disk_synchronize(device_lun *lun, bool force)
if (!lun->should_sync && !force)
return B_OK;
+ if (!lun->media_present)
+ return B_DEV_NO_MEDIA;
+
uint8 commandBlock[12];
memset(commandBlock, 0, sizeof(commandBlock));
@@ -1279,6 +1282,10 @@ usb_disk_block_read(device_lun *lun, uint64 blockPosition, size_t blockCount,
{
uint8 commandBlock[16];
memset(commandBlock, 0, sizeof(commandBlock));
+
+ if (!lun->media_present)
+ return B_DEV_NO_MEDIA;
+
if (lun->device->is_ufi) {
commandBlock[0] = SCSI_READ_12;
commandBlock[1] = lun->logical_unit_number << 5;
--
2.43.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment