summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--extmod/vfs.c26
-rw-r--r--tests/extmod/vfs_basic.py5
-rw-r--r--tests/extmod/vfs_basic.py.exp4
3 files changed, 35 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);
diff --git a/tests/extmod/vfs_basic.py b/tests/extmod/vfs_basic.py
index a3b2f3c29..fc016b8d5 100644
--- a/tests/extmod/vfs_basic.py
+++ b/tests/extmod/vfs_basic.py
@@ -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')
diff --git a/tests/extmod/vfs_basic.py.exp b/tests/extmod/vfs_basic.py.exp
index 8a23aa8ae..f8ecd07ea 100644
--- a/tests/extmod/vfs_basic.py.exp
+++ b/tests/extmod/vfs_basic.py.exp
@@ -1,4 +1,5 @@
(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