diff options
| author | Damien George <damien@micropython.org> | 2025-03-04 22:46:33 +1100 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2025-03-06 12:52:35 +1100 |
| commit | be0fce942996af576acd2ac639a4be92f6c4eeb7 (patch) | |
| tree | 9dc20dbfd7b88889ec60825655d418bc8995c283 /ports/unix/main.c | |
| parent | 6bec36a4eec999eccc6aadf0de782ebf69454ced (diff) | |
unix/main: Add coverage test for mounting ROMFS filesystem at startup.
Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'ports/unix/main.c')
| -rw-r--r-- | ports/unix/main.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/ports/unix/main.c b/ports/unix/main.c index 58fa3ff58..0d137fe1b 100644 --- a/ports/unix/main.c +++ b/ports/unix/main.c @@ -45,6 +45,7 @@ #include "py/gc.h" #include "py/objstr.h" #include "py/cstack.h" +#include "py/mperrno.h" #include "py/mphal.h" #include "py/mpthread.h" #include "extmod/misc.h" @@ -548,7 +549,14 @@ MP_NOINLINE int main_(int argc, char **argv) { MP_OBJ_NEW_QSTR(MP_QSTR__slash_), }; mp_vfs_mount(2, args, (mp_map_t *)&mp_const_empty_map); + + // Make sure the root that was just mounted is the current VFS (it's always at + // the end of the linked list). Can't use chdir('/') because that will change + // the current path within the VfsPosix object. MP_STATE_VM(vfs_cur) = MP_STATE_VM(vfs_mount_table); + while (MP_STATE_VM(vfs_cur)->next != NULL) { + MP_STATE_VM(vfs_cur) = MP_STATE_VM(vfs_cur)->next; + } } #endif @@ -803,3 +811,22 @@ void nlr_jump_fail(void *val) { fprintf(stderr, "FATAL: uncaught NLR %p\n", val); exit(1); } + +#if MICROPY_VFS_ROM_IOCTL + +static uint8_t romfs_buf[4] = { 0xd2, 0xcd, 0x31, 0x00 }; // empty ROMFS +static const MP_DEFINE_MEMORYVIEW_OBJ(romfs_obj, 'B', 0, sizeof(romfs_buf), romfs_buf); + +mp_obj_t mp_vfs_rom_ioctl(size_t n_args, const mp_obj_t *args) { + switch (mp_obj_get_int(args[0])) { + case MP_VFS_ROM_IOCTL_GET_NUMBER_OF_SEGMENTS: + return MP_OBJ_NEW_SMALL_INT(1); + + case MP_VFS_ROM_IOCTL_GET_SEGMENT: + return MP_OBJ_FROM_PTR(&romfs_obj); + } + + return MP_OBJ_NEW_SMALL_INT(-MP_EINVAL); +} + +#endif |
