diff options
author | Damien George <damien.p.george@gmail.com> | 2015-07-27 23:40:19 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2015-07-27 23:40:19 +0100 |
commit | 92e9a5e0a7f2634c670ffe8056430b94d210a4c0 (patch) | |
tree | 212005e5d8ec3a771c4af2eb6a6ed5819303c607 | |
parent | 84d59c28738b8f84c0581de4f6bba01c1f1e40ef (diff) | |
download | micropython-92e9a5e0a7f2634c670ffe8056430b94d210a4c0.tar.gz micropython-92e9a5e0a7f2634c670ffe8056430b94d210a4c0.zip |
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.
-rw-r--r-- | stmhal/diskio.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/stmhal/diskio.c b/stmhal/diskio.c index 9cae46eb18..3b0c86d5b1 100644 --- a/stmhal/diskio.c +++ b/stmhal/diskio.c @@ -151,6 +151,10 @@ DRESULT disk_read ( #endif 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[3] = mp_obj_new_bytearray_by_ref(count * 512, buff); mp_call_method_n_kw(2, 0, fs_user_mount->readblocks); @@ -190,6 +194,10 @@ DRESULT disk_write ( #endif case PD_USER: + if (fs_user_mount == NULL) { + // nothing mounted + return RES_ERROR; + } if (fs_user_mount->writeblocks[0] == MP_OBJ_NULL) { // read-only block device return RES_ERROR; @@ -243,6 +251,10 @@ DRESULT disk_ioctl ( #endif case PD_USER: + if (fs_user_mount == NULL) { + // nothing mounted + return RES_ERROR; + } switch (cmd) { case CTRL_SYNC: if (fs_user_mount->sync[0] != MP_OBJ_NULL) { |