Skip to content

Commit 1487a13

Browse files
AJMansfielddpgeorge
authored andcommitted
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 <[email protected]>
1 parent 458a8f2 commit 1487a13

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

extmod/vfs.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,18 @@ static mp_obj_t mp_vfs_autodetect(mp_obj_t bdev_obj) {
206206
}
207207

208208
mp_obj_t mp_vfs_mount(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
209+
if (n_args == 0) {
210+
// zero-args, output a table of all current mountpoints
211+
mp_obj_t mount_list = mp_obj_new_list(0, NULL);
212+
mp_vfs_mount_t *vfsp = MP_STATE_VM(vfs_mount_table);
213+
while (vfsp != NULL) {
214+
mp_obj_t items[] = { vfsp->obj, mp_obj_new_str(vfsp->str, vfsp->len) };
215+
mp_obj_list_append(mount_list, mp_obj_new_tuple(MP_ARRAY_SIZE(items), items));
216+
vfsp = vfsp->next;
217+
}
218+
return mount_list;
219+
}
220+
209221
enum { ARG_fsobj, ARG_mount_point, ARG_readonly, ARG_mkfs };
210222
static const mp_arg_t allowed_args[] = {
211223
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },

0 commit comments

Comments
 (0)