@@ -157,8 +157,14 @@ int32_t tud_msc_scsi_cb(uint8_t lun, const uint8_t scsi_cmd[16], void *buffer, u
157
157
158
158
void tud_msc_capacity_cb (uint8_t lun , uint32_t * block_count , uint16_t * block_size ) {
159
159
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
+ }
162
168
}
163
169
164
170
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
184
190
const uint32_t block_count = bufsize / MSC_FLASH_BLOCK_SIZE ;
185
191
186
192
fs_user_mount_t * vfs = get_vfs (lun );
187
- disk_read (vfs , buffer , lba , block_count );
193
+ if (vfs == NULL ) {
194
+ return -1 ;
195
+ }
188
196
197
+ disk_read (vfs , buffer , lba , block_count );
189
198
return block_count * MSC_FLASH_BLOCK_SIZE ;
190
199
}
191
200
@@ -197,6 +206,10 @@ int32_t tud_msc_write10_cb(uint8_t lun, uint32_t lba, uint32_t offset, uint8_t *
197
206
const uint32_t block_count = bufsize / MSC_FLASH_BLOCK_SIZE ;
198
207
199
208
fs_user_mount_t * vfs = get_vfs (lun );
209
+ if (vfs != NULL ) {
210
+ return -1 ;
211
+ }
212
+
200
213
disk_write (vfs , buffer , lba , block_count );
201
214
// Since by getting here we assume the mount is read-only to
202
215
// MicroPython let's update the cached FatFs sector if it's the one
0 commit comments