Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
micropython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
micropython
Commits
f6ef8e3f
Commit
f6ef8e3f
authored
Jun 07, 2017
by
Damien George
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
extmod/vfs: Allow to statvfs the root directory.
parent
551a7317
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
0 deletions
+35
-0
extmod/vfs.c
extmod/vfs.c
+26
-0
tests/extmod/vfs_basic.py
tests/extmod/vfs_basic.py
+5
-0
tests/extmod/vfs_basic.py.exp
tests/extmod/vfs_basic.py.exp
+4
-0
No files found.
extmod/vfs.c
View file @
f6ef8e3f
...
...
@@ -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
);
...
...
tests/extmod/vfs_basic.py
View file @
f6ef8e3f
...
...
@@ -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'
)
...
...
tests/extmod/vfs_basic.py.exp
View file @
f6ef8e3f
(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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment