8000 allow '/' to be mounted on '/' from Python code · sparkfun/circuitpython@dbf1a2f · GitHub
[go: up one dir, main page]

Skip to content

Commit dbf1a2f

Browse files
committed
allow '/' to be mounted on '/' from Python code
1 parent de4cd1e commit dbf1a2f

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

extmod/vfs_fat_diskio.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ DRESULT disk_read (
135135
if (nlr_push(&nlr) == 0) {
136136
mp_obj_t ret = mp_call_method_n_kw(2, 0, vfs->readblocks);
137137
nlr_pop();
138-
if (mp_obj_get_int(ret) != 0) {
138+
if (ret != mp_const_none && MP_OBJ_SMALL_INT_VALUE(ret) != 0) {
139139
return RES_ERROR;
140140
}
141141
} else {
@@ -180,7 +180,7 @@ DRESULT disk_write (
180180
if (nlr_push(&nlr) == 0) {
181181
mp_obj_t ret = mp_call_method_n_kw(2, 0, vfs->writeblocks);
182182
nlr_pop();
183-
if (mp_obj_get_int(ret) != 0) {
183+
if (ret != mp_const_none && MP_OBJ_SMALL_INT_VALUE(ret) != 0) {
184184
return RES_ERROR;
185185
}
186186
} else {

shared-module/storage/__init__.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,15 @@ void common_hal_storage_mount(mp_obj_t vfs_obj, const char* mount_path, bool rea
6565
args[1] = mp_const_false; // Don't make the file system automatically when mounting.
6666

6767
// Check that there's no file or directory with the same name as the mount point.
68-
nlr_buf_t nlr;
69-
if (nlr_push(&nlr) == 0) {
70-
common_hal_os_stat(mount_path);
71-
nlr_pop();
72-
// Something with the same name exists.
73-
mp_raise_OSError(MP_EEXIST);
68 84FB +
// But it's ok to mount '/' in any case.
69+
if (strcmp(vfs->str, "/") != 0) {
70+
nlr_buf_t nlr;
71+
if (nlr_push(&nlr) == 0) {
72+
common_hal_os_stat(mount_path);
73+
nlr_pop();
74+
// Something with the same name exists.
75+
mp_raise_OSError(MP_EEXIST);
76+
}
7477
}
7578

7679
// check that the destination mount point is unused

0 commit comments

Comments
 (0)
0