Skip to content

Commit c08f5a3

Browse files
committed
Add storage.getmount to retrieve the mount object associated with a path
1 parent 968763a commit c08f5a3

3 files changed

Lines changed: 15 additions & 0 deletions

File tree

‎shared-bindings/storage/__init__.c‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,22 @@ mp_obj_t storage_remount(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_a
122122
}
123123
MP_DEFINE_CONST_FUN_OBJ_KW(storage_remount_obj, 1, storage_remount);
124124

125+
//| .. function:: getmount(mount_path)
126+
//|
127+
//| Retrieves the mount object associated with the mount path
128+
//|
129+
mp_obj_t storage_getmount(const mp_obj_t mnt_in) {
130+
return common_hal_storage_getmount(mp_obj_str_get_str(mnt_in));
131+
}
132+
MP_DEFINE_CONST_FUN_OBJ_1(storage_getmount_obj, storage_getmount);
133+
125134
STATIC const mp_rom_map_elem_t storage_module_globals_table[] = {
126135
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_storage) },
127136

128137
{ MP_ROM_QSTR(MP_QSTR_mount), MP_ROM_PTR(&storage_mount_obj) },
129138
{ MP_ROM_QSTR(MP_QSTR_umount), MP_ROM_PTR(&storage_umount_obj) },
130139
{ MP_ROM_QSTR(MP_QSTR_remount), MP_ROM_PTR(&storage_remount_obj) },
140+
{ MP_ROM_QSTR(MP_QSTR_getmount), MP_ROM_PTR(&storage_getmount_obj) },
131141

132142
//| .. class:: VfsFat(block_device)
133143
//|

‎shared-bindings/storage/__init__.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,6 @@ void common_hal_storage_mount(mp_obj_t vfs_obj, const char* path, bool readonly)
3434
void common_hal_storage_umount_path(const char* path);
3535
void common_hal_storage_umount_object(mp_obj_t vfs_obj);
3636
void common_hal_storage_remount(const char* path, bool readonly);
37+
mp_obj_t common_hal_storage_getmount(const char* path);
3738

3839
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_STORAGE___INIT___H

‎shared-module/storage/__init__.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,7 @@ STATIC mp_obj_t storage_object_from_path(const char* mount_path) {
121121
void common_hal_storage_umount_path(const char* mount_path) {
122122
common_hal_storage_umount_object(storage_object_from_path(mount_path));
123123
}
124+
125+
mp_obj_t common_hal_storage_getmount(const char *mount_path) {
126+
return storage_object_from_path(mount_path);
127+
}

0 commit comments

Comments
 (0)