mirror of
https://github.com/licsber/micropython.git
synced 2024-09-20 09:00:23 +08:00
extmod/vfs: Allow to statvfs the root directory.
This commit is contained in:
parent
551a731755
commit
f6ef8e3f17
26
extmod/vfs.c
26
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 mp_vfs_statvfs(mp_obj_t path_in) {
|
||||||
mp_obj_t path_out;
|
mp_obj_t path_out;
|
||||||
mp_vfs_mount_t *vfs = lookup_path(path_in, &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);
|
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);
|
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
|
# stat root dir
|
||||||
print(uos.stat('/'))
|
print(uos.stat('/'))
|
||||||
|
|
||||||
|
# statvfs root dir
|
||||||
|
print(uos.statvfs('/'))
|
||||||
|
|
||||||
# getcwd when in root dir
|
# getcwd when in root dir
|
||||||
print(uos.getcwd())
|
print(uos.getcwd())
|
||||||
|
|
||||||
@ -128,6 +131,8 @@ except OSError:
|
|||||||
|
|
||||||
# root dir
|
# root dir
|
||||||
uos.mount(Filesystem(3), '/')
|
uos.mount(Filesystem(3), '/')
|
||||||
|
print(uos.stat('/'))
|
||||||
|
print(uos.statvfs('/'))
|
||||||
print(uos.listdir())
|
print(uos.listdir())
|
||||||
open('test')
|
open('test')
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
(16384, 0, 0, 0, 0, 0, 0, 0, 0, 0)
|
(16384, 0, 0, 0, 0, 0, 0, 0, 0, 0)
|
||||||
|
(0, 0, 0, 0, 0, 0, 0, 0, 0, 4096)
|
||||||
/
|
/
|
||||||
1 mount False False
|
1 mount False False
|
||||||
['test_mnt']
|
['test_mnt']
|
||||||
@ -36,6 +37,9 @@ OSError
|
|||||||
2 umount
|
2 umount
|
||||||
OSError
|
OSError
|
||||||
3 mount False False
|
3 mount False False
|
||||||
|
(16384, 0, 0, 0, 0, 0, 0, 0, 0, 0)
|
||||||
|
3 statvfs /
|
||||||
|
(3,)
|
||||||
3 ilistdir /
|
3 ilistdir /
|
||||||
['a3']
|
['a3']
|
||||||
3 open test r
|
3 open test r
|
||||||
|
Loading…
Reference in New Issue
Block a user