Skip to content

Commit 3625afa

Browse files
committed
extmod/vfs: Allow to stat the root directory.
os.stat('/') now works and returns a mostly-empty tuple. Really all that is useful is the mode which tells that it's a directory.
1 parent 2f76c3c commit 3625afa

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

extmod/vfs.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,14 @@ MP_DEFINE_CONST_FUN_OBJ_1(mp_vfs_rmdir_obj, mp_vfs_rmdir);
311311
mp_obj_t mp_vfs_stat(mp_obj_t path_in) {
312312
mp_obj_t path_out;
313313
mp_vfs_mount_t *vfs = lookup_path(path_in, &path_out);
314+
if (vfs == MP_VFS_ROOT) {
315+
mp_obj_tuple_t *t = MP_OBJ_TO_PTR(mp_obj_new_tuple(10, NULL));
316+
t->items[0] = MP_OBJ_NEW_SMALL_INT(0x4000); // st_mode = stat.S_IFDIR
317+
for (int i = 1; i <= 9; ++i) {
318+
t->items[i] = MP_OBJ_NEW_SMALL_INT(0); // dev, nlink, uid, gid, size, atime, mtime, ctime
319+
}
320+
return MP_OBJ_FROM_PTR(t);
321+
}
314322
return mp_vfs_proxy_call(vfs, MP_QSTR_stat, 1, &path_out);
315323
}
316324
MP_DEFINE_CONST_FUN_OBJ_1(mp_vfs_stat_obj, mp_vfs_stat);

0 commit comments

Comments
 (0)