@@ -194,6 +194,7 @@ uint8_t tud_msc_get_maxlun_cb(void) {
194
194
// - READ_CAPACITY10, READ_FORMAT_CAPACITY, INQUIRY, TEST_UNIT_READY, START_STOP_UNIT, MODE_SENSE6, REQUEST_SENSE
195
195
// - READ10 and WRITE10 have their own callbacks
196
196
int32_t tud_msc_scsi_cb (uint8_t lun , const uint8_t scsi_cmd [16 ], void * buffer , uint16_t bufsize ) {
197
+ // Note that no command uses a response right now.
197
198
const void * response = NULL ;
198
199
int32_t resplen = 0 ;
199
200
@@ -227,8 +228,10 @@ int32_t tud_msc_scsi_cb(uint8_t lun, const uint8_t scsi_cmd[16], void *buffer, u
227
228
228
229
void tud_msc_capacity_cb (uint8_t lun , uint32_t * block_count , uint16_t * block_size ) {
229
230
fs_user_mount_t * vfs = get_vfs (lun );
230
- disk_ioctl (vfs , GET_SECTOR_COUNT , block_count );
231
- disk_ioctl (vfs , GET_SECTOR_SIZE , block_size );
231
+ if (vfs != NULL ) {
232
+ disk_ioctl (vfs , GET_SECTOR_COUNT , block_count );
233
+ disk_ioctl (vfs , GET_SECTOR_SIZE , block_size );
234
+ }
232
235
}
233
236
234
237
bool tud_msc_is_writable_cb (uint8_t lun ) {
@@ -259,6 +262,9 @@ int32_t tud_msc_read10_cb(uint8_t lun, uint32_t lba, uint32_t offset, void *buff
259
262
const uint32_t block_count = bufsize / MSC_FLASH_BLOCK_SIZE ;
260
263
261
264
fs_user_mount_t * vfs = get_vfs (lun );
265
+ if (vfs == NULL ) {
266
+ return -1 ;
267
+ }
262
268
uint32_t disk_block_count ;
263
269
disk_ioctl (vfs , GET_SECTOR_COUNT , & disk_block_count );
264
270
@@ -281,6 +287,9 @@ int32_t tud_msc_write10_cb(uint8_t lun, uint32_t lba, uint32_t offset, uint8_t *
281
287
const uint32_t block_count = bufsize / MSC_FLASH_BLOCK_SIZE ;
282
288
283
289
fs_user_mount_t * vfs = get_vfs (lun );
290
+ if (vfs == NULL ) {
291
+ return -1 ;
292
+ }
284
293
disk_write (vfs , buffer , lba , block_count );
285
294
// Since by getting here we assume the mount is read-only to
286
295
// MicroPython let's update the cached FatFs sector if it's the one
0 commit comments