extmod/vfs: Return mount table from no-args vfs.mount call.

This extends the existing `vfs.mount()` function to accept zero arguments,
in which case it returns a list of tuples of mounted filesystem objects
and their mount location.

Signed-off-by: Anson Mansfield <amansfield@mantaro.com>
This commit is contained in:
Anson Mansfield
2025-03-14 13:19:06 -04:00
committed by Damien George
parent 458a8f2e15
commit 1487a13079

View File

@@ -206,6 +206,18 @@ static mp_obj_t mp_vfs_autodetect(mp_obj_t bdev_obj) {
}
mp_obj_t mp_vfs_mount(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
if (n_args == 0) {
// zero-args, output a table of all current mountpoints
mp_obj_t mount_list = mp_obj_new_list(0, NULL);
mp_vfs_mount_t *vfsp = MP_STATE_VM(vfs_mount_table);
while (vfsp != NULL) {
mp_obj_t items[] = { vfsp->obj, mp_obj_new_str(vfsp->str, vfsp->len) };
mp_obj_list_append(mount_list, mp_obj_new_tuple(MP_ARRAY_SIZE(items), items));
vfsp = vfsp->next;
}
return mount_list;
}
enum { ARG_fsobj, ARG_mount_point, ARG_readonly, ARG_mkfs };
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },