aboutsummaryrefslogtreecommitdiff
path: root/extmod/vfs.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2018-06-06 14:24:23 +1000
committerDamien George <damien.p.george@gmail.com>2018-06-06 14:33:42 +1000
commitc117effddd1f9ffd902a9712cf0ae7413696dc66 (patch)
treeb14d54474360c11580a55fe4ea28a11efb2646cc /extmod/vfs.c
parentfadd6bbe436df73a8a0d15fa9b7e743707ee7c36 (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.c')
-rw-r--r--extmod/vfs.c17
1 files changed, 4 insertions, 13 deletions
diff --git a/extmod/vfs.c b/extmod/vfs.c
index 96d5019b3..77531b874 100644
--- a/extmod/vfs.c
+++ b/extmod/vfs.c
@@ -34,9 +34,6 @@
#if MICROPY_VFS
-#if MICROPY_VFS_POSIX
-#include "extmod/vfs_posix.h"
-#endif
#if MICROPY_VFS_FAT
#include "extmod/vfs_fat.h"
#endif
@@ -128,17 +125,11 @@ mp_import_stat_t mp_vfs_import_stat(const char *path) {
return MP_IMPORT_STAT_NO_EXIST;
}
- // Fast paths for known VFS types
- #if MICROPY_VFS_POSIX
- if (mp_obj_get_type(vfs->obj) == &mp_type_vfs_posix) {
- return mp_vfs_posix_import_stat(MP_OBJ_TO_PTR(vfs->obj), path_out);
- }
- #endif
- #if MICROPY_VFS_FAT
- if (mp_obj_get_type(vfs->obj) == &mp_fat_vfs_type) {
- return fat_vfs_import_stat(MP_OBJ_TO_PTR(vfs->obj), path_out);
+ // If the mounted object has the VFS protocol, call its import_stat helper
+ const mp_vfs_proto_t *proto = mp_obj_get_type(vfs->obj)->protocol;
+ if (proto != NULL) {
+ return proto->import_stat(MP_OBJ_TO_PTR(vfs->obj), path_out);
}
- #endif
// delegate to vfs.stat() method
mp_obj_t path_o = mp_obj_new_str(path_out, strlen(path_out));