diff options
author | Damien George <damien.p.george@gmail.com> | 2017-02-13 12:25:43 +1100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2017-02-13 12:25:43 +1100 |
commit | 3625afa17362e8a2f873edeaa0856ae852c19beb (patch) | |
tree | 173f63d6c3eed18f63a0000f05299fa9872d095e | |
parent | 2f76c3ca0ad809e26f12722192e6fbdeab317566 (diff) | |
download | micropython-3625afa17362e8a2f873edeaa0856ae852c19beb.tar.gz micropython-3625afa17362e8a2f873edeaa0856ae852c19beb.zip |
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.
-rw-r--r-- | extmod/vfs.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/extmod/vfs.c b/extmod/vfs.c index 98d8711e4a..c968345b86 100644 --- a/extmod/vfs.c +++ b/extmod/vfs.c @@ -311,6 +311,14 @@ MP_DEFINE_CONST_FUN_OBJ_1(mp_vfs_rmdir_obj, mp_vfs_rmdir); mp_obj_t mp_vfs_stat(mp_obj_t path_in) { mp_obj_t path_out; mp_vfs_mount_t *vfs = lookup_path(path_in, &path_out); + if (vfs == MP_VFS_ROOT) { + mp_obj_tuple_t *t = MP_OBJ_TO_PTR(mp_obj_new_tuple(10, NULL)); + t->items[0] = MP_OBJ_NEW_SMALL_INT(0x4000); // st_mode = stat.S_IFDIR + for (int i = 1; i <= 9; ++i) { + t->items[i] = MP_OBJ_NEW_SMALL_INT(0); // dev, nlink, uid, gid, size, atime, mtime, ctime + } + return MP_OBJ_FROM_PTR(t); + } return mp_vfs_proxy_call(vfs, MP_QSTR_stat, 1, &path_out); } MP_DEFINE_CONST_FUN_OBJ_1(mp_vfs_stat_obj, mp_vfs_stat); |