Commit f6ef8e3f authored by Damien George's avatar Damien George

extmod/vfs: Allow to statvfs the root directory.

parent 551a7317
......@@ -421,6 +421,32 @@ MP_DEFINE_CONST_FUN_OBJ_1(mp_vfs_stat_obj, mp_vfs_stat);
mp_obj_t mp_vfs_statvfs(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) {
// statvfs called on the root directory, see if there's anything mounted there
for (vfs = MP_STATE_VM(vfs_mount_table); vfs != NULL; vfs = vfs->next) {
if (vfs->len == 1) {
break;
}
}
// If there's nothing mounted at root then return a mostly-empty tuple
if (vfs == NULL) {
mp_obj_tuple_t *t = MP_OBJ_TO_PTR(mp_obj_new_tuple(10, NULL));
// fill in: bsize, frsize, blocks, bfree, bavail, files, ffree, favail, flags
for (int i = 0; i <= 8; ++i) {
t->items[i] = MP_OBJ_NEW_SMALL_INT(0);
}
// Put something sensible in f_namemax
t->items[9] = MP_OBJ_NEW_SMALL_INT(MICROPY_ALLOC_PATH_MAX);
return MP_OBJ_FROM_PTR(t);
}
// VFS mounted at root so delegate the call to it
path_out = MP_OBJ_NEW_QSTR(MP_QSTR__slash_);
}
return mp_vfs_proxy_call(vfs, MP_QSTR_statvfs, 1, &path_out);
}
MP_DEFINE_CONST_FUN_OBJ_1(mp_vfs_statvfs_obj, mp_vfs_statvfs);
......
......@@ -57,6 +57,9 @@ for path in uos.listdir('/'):
# stat root dir
print(uos.stat('/'))
# statvfs root dir
print(uos.statvfs('/'))
# getcwd when in root dir
print(uos.getcwd())
......@@ -128,6 +131,8 @@ except OSError:
# root dir
uos.mount(Filesystem(3), '/')
print(uos.stat('/'))
print(uos.statvfs('/'))
print(uos.listdir())
open('test')
......
(16384, 0, 0, 0, 0, 0, 0, 0, 0, 0)
(0, 0, 0, 0, 0, 0, 0, 0, 0, 4096)
/
1 mount False False
['test_mnt']
......@@ -36,6 +37,9 @@ OSError
2 umount
OSError
3 mount False False
(16384, 0, 0, 0, 0, 0, 0, 0, 0, 0)
3 statvfs /
(3,)
3 ilistdir /
['a3']
3 open test r
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment