Skip to content

Commit 0d88b59

Browse files
committed
Merge remote-tracking branch 'origin/main'
2 parents f85766b + 358a334 commit 0d88b59

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

supervisor/shared/usb/usb_msc_flash.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,20 +204,25 @@ uint8_t tud_msc_get_maxlun_cb(void) {
204204
return LUN_COUNT;
205205
}
206206

207+
// PREVENT ALLOW MEDIUM REMOVAL: TinyUSB routes this to its own dedicated callback,
208+
// NOT tud_msc_scsi_cb. Reply unsupported on all LUNs so the host keeps TUR polling
209+
// on every LUN — eject/storage.remount() works uniformly across CIRCUITPY, SAVES, SD.
210+
bool tud_msc_prevent_allow_medium_removal_cb(uint8_t lun, uint8_t prohibit_removal, uint8_t control) {
211+
(void)prohibit_removal;
212+
(void)control;
213+
tud_msc_set_sense(lun, SCSI_SENSE_ILLEGAL_REQUEST, 0x20, 0x00);
214+
return false;
215+
}
216+
207217
// Callback invoked when received an SCSI command not in built-in list below
208218
// - READ_CAPACITY10, READ_FORMAT_CAPACITY, INQUIRY, TEST_UNIT_READY, START_STOP_UNIT, MODE_SENSE6, REQUEST_SENSE
209-
// - READ10 and WRITE10 have their own callbacks
219+
// - PREVENT_ALLOW_MEDIUM_REMOVAL, READ10, WRITE10 have their own callbacks
210220
int32_t tud_msc_scsi_cb(uint8_t lun, const uint8_t scsi_cmd[16], void *buffer, uint16_t bufsize) {
211221
// Note that no command uses a response right now.
212222
const void *response = NULL;
213223
int32_t resplen = 0;
214224

215225
switch (scsi_cmd[0]) {
216-
case SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL:
217-
// Host is about to read/write etc ... better not to disconnect disk
218-
resplen = 0;
219-
break;
220-
221226
default:
222227
// Set Sense = Invalid Command Operation
223228
tud_msc_set_sense(lun, SCSI_SENSE_ILLEGAL_REQUEST, 0x20, 0x00);

0 commit comments

Comments
 (0)