8000 Allow mounting '/' on '/' by dhalbert · Pull Request #953 · adafruit/circuitpython · GitHub
[go: up one dir, main page]

Skip to content

Allow mounting '/' on '/' #953

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions extmod/vfs_fat_diskio.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ DRESULT disk_read (
if (nlr_push(&nlr) == 0) {
mp_obj_t ret = mp_call_method_n_kw(2, 0, vfs->readblocks);
nlr_pop();
if (mp_obj_get_int(ret) != 0) {
if (ret != mp_const_none && MP_OBJ_SMALL_INT_VALUE(ret) != 0) {
return RES_ERROR;
}
} else {
Expand Down Expand Up @@ -180,7 +180,7 @@ DRESULT disk_write (
if (nlr_push(&nlr) == 0) {
mp_obj_t ret = mp_call_method_n_kw(2, 0, vfs->writeblocks);
nlr_pop();
if (mp_obj_get_int(ret) != 0) {
if (ret != mp_const_none && MP_OBJ_SMALL_INT_VALUE(ret) != 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!mp_obj_is_true(ret) will make it use the standard Python truthiness. https://github.com/adafruit/circuitpython/blob/master/py/obj.h#L681

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The particular test I used above was already used elsewhere in this file (see line 73, for example), so let's stick with the current test. The implicit contract is that the called routines either have a plain return (so returning None, meaning everything is fine, or return an error code, with 0 meaning OK. Other Falsiness (like empty lists) is not expected.

return RES_ERROR;
}
} else {
Expand Down
15 changes: 9 additions & 6 deletions shared-module/storage/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,15 @@ void common_hal_storage_mount(mp_obj_t vfs_obj, const char* mount_path, bool rea
args[1] = mp_const_false; // Don't make the file system automatically when mounting.

// Check that there's no file or directory with the same name as the mount point.
nlr_buf_t nlr;
if (nlr_push(&nlr) == 0) {
common_hal_os_stat(mount_path);
nlr_pop();
// Something with the same name exists.
mp_raise_OSError(MP_EEXIST);
// But it's ok to mount '/' in any case.
if (strcmp(vfs->str, "/") != 0) {
nlr_buf_t nlr;
if (nlr_push(&nlr) == 0) {
common_hal_os_stat(mount_path);
nlr_pop();
// Something with the same name exists.
mp_raise_OSError(MP_EEXIST);
}
}

// check that the destination mount point is unused
Expand Down
0