Skip to content
Snippets Groups Projects
Commit 92e9a5e0 authored by Damien George's avatar Damien George
Browse files

stmhal: Check if user block device is mounted before accessing it.

In particular this fixes a bug where pyb.sync (and os.sync) fail because
they try to sync the user mounted device even if it's not mounted.
parent 84d59c28
No related branches found
No related tags found
No related merge requests found
...@@ -151,6 +151,10 @@ DRESULT disk_read ( ...@@ -151,6 +151,10 @@ DRESULT disk_read (
#endif #endif
case PD_USER: case PD_USER:
if (fs_user_mount == NULL) {
// nothing mounted
return RES_ERROR;
}
fs_user_mount->readblocks[2] = MP_OBJ_NEW_SMALL_INT(sector); fs_user_mount->readblocks[2] = MP_OBJ_NEW_SMALL_INT(sector);
fs_user_mount->readblocks[3] = mp_obj_new_bytearray_by_ref(count * 512, buff); fs_user_mount->readblocks[3] = mp_obj_new_bytearray_by_ref(count * 512, buff);
mp_call_method_n_kw(2, 0, fs_user_mount->readblocks); mp_call_method_n_kw(2, 0, fs_user_mount->readblocks);
...@@ -190,6 +194,10 @@ DRESULT disk_write ( ...@@ -190,6 +194,10 @@ DRESULT disk_write (
#endif #endif
case PD_USER: case PD_USER:
if (fs_user_mount == NULL) {
// nothing mounted
return RES_ERROR;
}
if (fs_user_mount->writeblocks[0] == MP_OBJ_NULL) { if (fs_user_mount->writeblocks[0] == MP_OBJ_NULL) {
// read-only block device // read-only block device
return RES_ERROR; return RES_ERROR;
...@@ -243,6 +251,10 @@ DRESULT disk_ioctl ( ...@@ -243,6 +251,10 @@ DRESULT disk_ioctl (
#endif #endif
case PD_USER: case PD_USER:
if (fs_user_mount == NULL) {
// nothing mounted
return RES_ERROR;
}
switch (cmd) { switch (cmd) {
case CTRL_SYNC: case CTRL_SYNC:
if (fs_user_mount->sync[0] != MP_OBJ_NULL) { if (fs_user_mount->sync[0] != MP_OBJ_NULL) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment