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_fat.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_fat.c')
-rw-r--r-- | extmod/vfs_fat.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/extmod/vfs_fat.c b/extmod/vfs_fat.c index 5666a6b0c..4af836b2d 100644 --- a/extmod/vfs_fat.c +++ b/extmod/vfs_fat.c @@ -47,7 +47,8 @@ #define mp_obj_fat_vfs_t fs_user_mount_t -mp_import_stat_t fat_vfs_import_stat(fs_user_mount_t *vfs, const char *path) { +STATIC mp_import_stat_t fat_vfs_import_stat(void *vfs_in, const char *path) { + fs_user_mount_t *vfs = vfs_in; FILINFO fno; assert(vfs != NULL); FRESULT res = f_stat(&vfs->fatfs, path, &fno); @@ -421,11 +422,17 @@ STATIC const mp_rom_map_elem_t fat_vfs_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(fat_vfs_locals_dict, fat_vfs_locals_dict_table); +STATIC const mp_vfs_proto_t fat_vfs_proto = { + .import_stat = fat_vfs_import_stat, +}; + const mp_obj_type_t mp_fat_vfs_type = { { &mp_type_type }, .name = MP_QSTR_VfsFat, .make_new = fat_vfs_make_new, + .protocol = &fat_vfs_proto, .locals_dict = (mp_obj_dict_t*)&fat_vfs_locals_dict, + }; #endif // MICROPY_VFS_FAT |