mirror of
https://github.com/micropython/micropython.git
synced 2025-07-21 04:51:12 +02:00
extmod/vfs: Add mp_vfs_mount_romfs_protected() helper.
This function will attempt to create a `VfsRom` instance and mount it at location "/rom" in the filesystem. Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
30
extmod/vfs.c
30
extmod/vfs.c
@@ -46,6 +46,10 @@
|
||||
#include "extmod/vfs_posix.h"
|
||||
#endif
|
||||
|
||||
#if MICROPY_VFS_ROM && MICROPY_VFS_ROM_IOCTL
|
||||
#include "extmod/vfs_rom.h"
|
||||
#endif
|
||||
|
||||
// For mp_vfs_proxy_call, the maximum number of additional args that can be passed.
|
||||
// A fixed maximum size is used to avoid the need for a costly variable array.
|
||||
#define PROXY_MAX_ARGS (2)
|
||||
@@ -552,6 +556,32 @@ int mp_vfs_mount_and_chdir_protected(mp_obj_t bdev, mp_obj_t mount_point) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if MICROPY_VFS_ROM && MICROPY_VFS_ROM_IOCTL
|
||||
|
||||
int mp_vfs_mount_romfs_protected(void) {
|
||||
int ret;
|
||||
nlr_buf_t nlr;
|
||||
if (nlr_push(&nlr) == 0) {
|
||||
mp_obj_t args[2] = { MP_OBJ_NEW_SMALL_INT(MP_VFS_ROM_IOCTL_GET_SEGMENT), MP_OBJ_NEW_SMALL_INT(0) };
|
||||
mp_obj_t rom = mp_vfs_rom_ioctl(2, args);
|
||||
mp_obj_t romfs = mp_call_function_1(MP_OBJ_FROM_PTR(&mp_type_vfs_rom), rom);
|
||||
mp_obj_t mount_point = MP_OBJ_NEW_QSTR(MP_QSTR__slash_rom);
|
||||
mp_call_function_2(MP_OBJ_FROM_PTR(&mp_vfs_mount_obj), romfs, mount_point);
|
||||
#if MICROPY_PY_SYS_PATH_ARGV_DEFAULTS
|
||||
// Add "/rom" and "/rom/lib" to `sys.path`.
|
||||
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_rom));
|
||||
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_rom_slash_lib));
|
||||
#endif
|
||||
ret = 0; // success
|
||||
nlr_pop();
|
||||
} else {
|
||||
ret = -MP_EIO;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
MP_REGISTER_ROOT_POINTER(struct _mp_vfs_mount_t *vfs_cur);
|
||||
MP_REGISTER_ROOT_POINTER(struct _mp_vfs_mount_t *vfs_mount_table);
|
||||
|
||||
|
@@ -112,6 +112,9 @@ mp_obj_t mp_vfs_stat(mp_obj_t path_in);
|
||||
mp_obj_t mp_vfs_statvfs(mp_obj_t path_in);
|
||||
|
||||
int mp_vfs_mount_and_chdir_protected(mp_obj_t bdev, mp_obj_t mount_point);
|
||||
#if MICROPY_VFS_ROM && MICROPY_VFS_ROM_IOCTL
|
||||
int mp_vfs_mount_romfs_protected(void);
|
||||
#endif
|
||||
|
||||
MP_DECLARE_CONST_FUN_OBJ_KW(mp_vfs_mount_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ_1(mp_vfs_umount_obj);
|
||||
|
@@ -68,6 +68,11 @@ Q(utf-8)
|
||||
Q(.frozen)
|
||||
#endif
|
||||
|
||||
#if MICROPY_VFS_ROM && MICROPY_VFS_ROM_IOCTL
|
||||
Q(/rom)
|
||||
Q(/rom/lib)
|
||||
#endif
|
||||
|
||||
#if MICROPY_ENABLE_PYSTACK
|
||||
Q(pystack exhausted)
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user