Add storage.getmount to retrieve the mount object associated with a path

This commit is contained in:
Jeff Epler 2018-03-27 21:28:18 -05:00
parent 968763aa1d
commit c08f5a3a00
3 changed files with 15 additions and 0 deletions

View File

@ -122,12 +122,22 @@ mp_obj_t storage_remount(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_a
}
MP_DEFINE_CONST_FUN_OBJ_KW(storage_remount_obj, 1, storage_remount);
//| .. function:: getmount(mount_path)
//|
//| Retrieves the mount object associated with the mount path
//|
mp_obj_t storage_getmount(const mp_obj_t mnt_in) {
return common_hal_storage_getmount(mp_obj_str_get_str(mnt_in));
}
MP_DEFINE_CONST_FUN_OBJ_1(storage_getmount_obj, storage_getmount);
STATIC const mp_rom_map_elem_t storage_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_storage) },
{ MP_ROM_QSTR(MP_QSTR_mount), MP_ROM_PTR(&storage_mount_obj) },
{ MP_ROM_QSTR(MP_QSTR_umount), MP_ROM_PTR(&storage_umount_obj) },
{ MP_ROM_QSTR(MP_QSTR_remount), MP_ROM_PTR(&storage_remount_obj) },
{ MP_ROM_QSTR(MP_QSTR_getmount), MP_ROM_PTR(&storage_getmount_obj) },
//| .. class:: VfsFat(block_device)
//|

View File

@ -34,5 +34,6 @@ void common_hal_storage_mount(mp_obj_t vfs_obj, const char* path, bool readonly)
void common_hal_storage_umount_path(const char* path);
void common_hal_storage_umount_object(mp_obj_t vfs_obj);
void common_hal_storage_remount(const char* path, bool readonly);
mp_obj_t common_hal_storage_getmount(const char* path);
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_STORAGE___INIT___H

View File

@ -121,3 +121,7 @@ STATIC mp_obj_t storage_object_from_path(const char* mount_path) {
void common_hal_storage_umount_path(const char* mount_path) {
common_hal_storage_umount_object(storage_object_from_path(mount_path));
}
mp_obj_t common_hal_storage_getmount(const char *mount_path) {
return storage_object_from_path(mount_path);
}