diff options
author | Damien George <damien.p.george@gmail.com> | 2018-06-06 14:24:23 +1000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2018-06-06 14:33:42 +1000 |
commit | c117effddd1f9ffd902a9712cf0ae7413696dc66 (patch) | |
tree | b14d54474360c11580a55fe4ea28a11efb2646cc /extmod/vfs_posix.c | |
parent | fadd6bbe436df73a8a0d15fa9b7e743707ee7c36 (diff) |
extmod/vfs: Introduce a C-level VFS protocol, with fast import_stat.
Following other C-level protocols, this VFS protocol is added to help
abstract away implementation details of the underlying VFS in an efficient
way. As a starting point, the import_stat function is put into this
protocol so that the VFS sub-system does not need to know about every VFS
implementation in order to do an efficient stat for importing files.
In the future it might be worth adding other functions to this protocol.
Diffstat (limited to 'extmod/vfs_posix.c')
-rw-r--r-- | extmod/vfs_posix.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/extmod/vfs_posix.c b/extmod/vfs_posix.c index 0db45a0c1..6e3bb2c5b 100644 --- a/extmod/vfs_posix.c +++ b/extmod/vfs_posix.c @@ -71,7 +71,8 @@ STATIC mp_obj_t vfs_posix_fun1_helper(mp_obj_t self_in, mp_obj_t path_in, int (* return mp_const_none; } -mp_import_stat_t mp_vfs_posix_import_stat(mp_obj_vfs_posix_t *self, const char *path) { +STATIC mp_import_stat_t mp_vfs_posix_import_stat(void *self_in, const char *path) { + mp_obj_vfs_posix_t *self = self_in; if (self->root_len != 0) { self->root.len = self->root_len; vstr_add_str(&self->root, path); @@ -347,10 +348,15 @@ STATIC const mp_rom_map_elem_t vfs_posix_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(vfs_posix_locals_dict, vfs_posix_locals_dict_table); +STATIC const mp_vfs_proto_t vfs_posix_proto = { + .import_stat = mp_vfs_posix_import_stat, +}; + const mp_obj_type_t mp_type_vfs_posix = { { &mp_type_type }, .name = MP_QSTR_VfsPosix, .make_new = vfs_posix_make_new, + .protocol = &vfs_posix_proto, .locals_dict = (mp_obj_dict_t*)&vfs_posix_locals_dict, }; |