aboutsummaryrefslogtreecommitdiff
path: root/extmod/vfs.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2017-06-07 15:17:45 +1000
committerDamien George <damien.p.george@gmail.com>2017-06-07 15:17:45 +1000
commitf6ef8e3f17222a397e02f93a8b0d283e0f6c9793 (patch)
tree05fe7ce2f89ee241251cef5a7f6ae820ad1737c9 /extmod/vfs.c
parent551a7317554b84651b0c3fd97f495753c17042ad (diff)
extmod/vfs: Allow to statvfs the root directory.
Diffstat (limited to 'extmod/vfs.c')
-rw-r--r--extmod/vfs.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/extmod/vfs.c b/extmod/vfs.c
index f158bd387..b75ec7516 100644
--- a/extmod/vfs.c
+++ b/extmod/vfs.c
@@ -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);