Commit 6c23c758 authored by Damien George's avatar Damien George
Browse files

extmod/vfs: Add ability for VFS sub-system to import using VfsFat.

parent fb3ae178
......@@ -31,6 +31,7 @@
#include "py/objstr.h"
#include "py/mperrno.h"
#include "extmod/vfs.h"
#include "extmod/vfs_fat.h"
#if MICROPY_VFS
......@@ -114,6 +115,12 @@ mp_import_stat_t mp_vfs_import_stat(const char *path) {
if (vfs == VFS_NONE || vfs == VFS_ROOT) {
return MP_IMPORT_STAT_NO_EXIST;
}
#if MICROPY_VFS_FAT
// fast paths for known VFS types
if (mp_obj_get_type(vfs->obj) == &mp_fat_vfs_type) {
return fat_vfs_import_stat(MP_OBJ_TO_PTR(vfs->obj), path_out);
}
#endif
// TODO delegate to vfs.stat() method
return MP_IMPORT_STAT_NO_EXIST;
}
......
......@@ -24,6 +24,8 @@
* THE SOFTWARE.
*/
#include "py/lexer.h"
struct _fs_user_mount_t;
extern const byte fresult_to_errno_table[20];
......@@ -31,6 +33,7 @@ extern const mp_obj_type_t mp_fat_vfs_type;
struct _fs_user_mount_t *ff_get_vfs(const char **path);
mp_import_stat_t fat_vfs_import_stat(struct _fs_user_mount_t *vfs, const char *path);
mp_obj_t fatfs_builtin_open(mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kwargs);
mp_obj_t fatfs_builtin_open_self(mp_obj_t self_in, mp_obj_t path, mp_obj_t mode);
MP_DECLARE_CONST_FUN_OBJ_KW(mp_builtin_open_obj);
......
......@@ -108,21 +108,17 @@ mp_obj_t fat_vfs_listdir2(fs_user_mount_t *vfs, const char *path, bool is_str_ty
return dir_list;
}
mp_import_stat_t fat_vfs_import_stat(const char *path);
mp_import_stat_t fat_vfs_import_stat(const char *path) {
mp_import_stat_t fat_vfs_import_stat(fs_user_mount_t *vfs, const char *path) {
FILINFO fno;
#if !MICROPY_FATFS_OO && _USE_LFN
fno.lfname = NULL;
fno.lfsize = 0;
#endif
#if MICROPY_FATFS_OO
fs_user_mount_t *vfs = ff_get_vfs(&path);
if (vfs == NULL) {
return MP_IMPORT_STAT_NO_EXIST;
}
assert(vfs != NULL);
FRESULT res = f_stat(&vfs->fatfs, path, &fno);
#else
(void)vfs;
FRESULT res = f_stat(path, &fno);
#endif
if (res == FR_OK) {
......
......@@ -28,9 +28,8 @@
#include "py/lexer.h"
#include "lib/fatfs/ff.h"
mp_import_stat_t fat_vfs_import_stat(const char *path);
#include "extmod/vfs_fat.h"
mp_import_stat_t mp_import_stat(const char *path) {
return fat_vfs_import_stat(path);
return fat_vfs_import_stat(NULL, path);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment