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
39a380b6
Commit
39a380b6
authored
Oct 19, 2015
by
Paul Sokolovsky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
unix/modos: Android Bionic lacks statvfs(), has BSD statfs().
parent
e0f5df57
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
8 deletions
+28
-8
unix/modos.c
unix/modos.c
+28
-8
No files found.
unix/modos.c
View file @
39a380b6
...
...
@@ -31,14 +31,15 @@
#include <errno.h>
#include <stdlib.h>
#include "py/mpconfig.h"
#if MICROPY_PY_OS_STATVFS
#include <sys/statvfs.h>
#endif
#include "py/nlr.h"
#include "py/runtime.h"
#include "py/objtuple.h"
#ifdef __ANDROID__
#define USE_STATFS 1
#endif
#define RAISE_ERRNO(err_flag, error_val) \
{ if (err_flag == -1) \
{ nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(error_val))); } }
...
...
@@ -67,12 +68,31 @@ STATIC mp_obj_t mod_os_stat(mp_obj_t path_in) {
STATIC
MP_DEFINE_CONST_FUN_OBJ_1
(
mod_os_stat_obj
,
mod_os_stat
);
#if MICROPY_PY_OS_STATVFS
#if MICROPY_PY_OS_STATVFS
#if USE_STATFS
#include <sys/vfs.h>
#define STRUCT_STATVFS struct statfs
#define STATVFS statfs
#define F_FAVAIL sb.f_ffree
#define F_NAMEMAX sb.f_namelen
#define F_FLAG sb.f_flags
#else
#include <sys/statvfs.h>
#define STRUCT_STATVFS struct statvfs
#define STATVFS statvfs
#define F_FAVAIL sb.f_favail
#define F_NAMEMAX sb.f_namemax
#define F_FLAG sb.f_flag
#endif
#endif
STATIC
mp_obj_t
mod_os_statvfs
(
mp_obj_t
path_in
)
{
struct
statvfs
sb
;
STRUCT_STATVFS
sb
;
mp_uint_t
len
;
const
char
*
path
=
mp_obj_str_get_data
(
path_in
,
&
len
);
int
res
=
statvfs
(
path
,
&
sb
);
int
res
=
STATVFS
(
path
,
&
sb
);
RAISE_ERRNO
(
res
,
errno
);
mp_obj_tuple_t
*
t
=
mp_obj_new_tuple
(
10
,
NULL
);
...
...
@@ -83,9 +103,9 @@ STATIC mp_obj_t mod_os_statvfs(mp_obj_t path_in) {
t
->
items
[
4
]
=
MP_OBJ_NEW_SMALL_INT
(
sb
.
f_bavail
);
t
->
items
[
5
]
=
MP_OBJ_NEW_SMALL_INT
(
sb
.
f_files
);
t
->
items
[
6
]
=
MP_OBJ_NEW_SMALL_INT
(
sb
.
f_ffree
);
t
->
items
[
7
]
=
MP_OBJ_NEW_SMALL_INT
(
sb
.
f_favail
);
t
->
items
[
8
]
=
MP_OBJ_NEW_SMALL_INT
(
sb
.
f_flag
);
t
->
items
[
9
]
=
MP_OBJ_NEW_SMALL_INT
(
sb
.
f_namemax
);
t
->
items
[
7
]
=
MP_OBJ_NEW_SMALL_INT
(
F_FAVAIL
);
t
->
items
[
8
]
=
MP_OBJ_NEW_SMALL_INT
(
F_FLAG
);
t
->
items
[
9
]
=
MP_OBJ_NEW_SMALL_INT
(
F_NAMEMAX
);
return
t
;
}
STATIC
MP_DEFINE_CONST_FUN_OBJ_1
(
mod_os_statvfs_obj
,
mod_os_statvfs
);
...
...
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