Skip to content

Commit d59bc27

Browse files
committed
fix msc multiple lun issue with windows
1 parent c47288a commit d59bc27

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

Diff for: supervisor/shared/usb/usb_msc_flash.c

+16-3
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,14 @@ int32_t tud_msc_scsi_cb(uint8_t lun, const uint8_t scsi_cmd[16], void *buffer, u
157157

158158
void tud_msc_capacity_cb(uint8_t lun, uint32_t *block_count, uint16_t *block_size) {
159159
fs_user_mount_t *vfs = get_vfs(lun);
160-
disk_ioctl(vfs, GET_SECTOR_COUNT, block_count);
161-
disk_ioctl(vfs, GET_SECTOR_SIZE, block_size);
160+
161+
if (vfs) {
162+
disk_ioctl(vfs, GET_SECTOR_COUNT, block_count);
163+
disk_ioctl(vfs, GET_SECTOR_SIZE, block_size);
164+
} else {
165+
*block_count = 0;
166+
*block_size = 0;
167+
}
162168
}
163169

164170
bool tud_msc_is_writable_cb(uint8_t lun) {
@@ -184,8 +190,11 @@ int32_t tud_msc_read10_cb(uint8_t lun, uint32_t lba, uint32_t offset, void *buff
184190
const uint32_t block_count = bufsize / MSC_FLASH_BLOCK_SIZE;
185191

186192
fs_user_mount_t *vfs = get_vfs(lun);
187-
disk_read(vfs, buffer, lba, block_count);
193+
if (vfs == NULL) {
194+
return -1;
195+
}
188196

197+
disk_read(vfs, buffer, lba, block_count);
189198
return block_count * MSC_FLASH_BLOCK_SIZE;
190199
}
191200

@@ -197,6 +206,10 @@ int32_t tud_msc_write10_cb(uint8_t lun, uint32_t lba, uint32_t offset, uint8_t *
197206
const uint32_t block_count = bufsize / MSC_FLASH_BLOCK_SIZE;
198207

199208
fs_user_mount_t *vfs = get_vfs(lun);
209+
if (vfs != NULL) {
210+
return -1;
211+
}
212+
200213
disk_write(vfs, buffer, lba, block_count);
201214
// Since by getting here we assume the mount is read-only to
202215
// MicroPython let's update the cached FatFs sector if it's the one

0 commit comments

Comments
 (0)