From f5f4cdae89ed040ae9209a380cf968254434e819 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 1 Jun 2016 17:00:28 +0100 Subject: extmod/vfs_fat: Rework so it can optionally use OO version of FatFS. If MICROPY_VFS_FAT is enabled by a port then the port must switch to using MICROPY_FATFS_OO. Otherwise a port can continue to use the FatFs code without any changes. --- extmod/vfs_fat_ffconf.c | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) (limited to 'extmod/vfs_fat_ffconf.c') diff --git a/extmod/vfs_fat_ffconf.c b/extmod/vfs_fat_ffconf.c index f8935af75..ddcdd8844 100644 --- a/extmod/vfs_fat_ffconf.c +++ b/extmod/vfs_fat_ffconf.c @@ -30,10 +30,13 @@ #include #include "py/mpstate.h" +#if MICROPY_FATFS_OO +#include "lib/oofatfs/ff.h" +#else #include "lib/fatfs/ff.h" -#include "lib/fatfs/ffconf.h" -#include "lib/fatfs/diskio.h" +#endif #include "extmod/fsusermount.h" +#include "extmod/vfs_fat_file.h" STATIC bool check_path(const TCHAR **path, const char *mount_point_str, mp_uint_t mount_point_len) { if (strncmp(*path, mount_point_str, mount_point_len) == 0) { @@ -48,6 +51,37 @@ STATIC bool check_path(const TCHAR **path, const char *mount_point_str, mp_uint_ return false; } +#if MICROPY_FATFS_OO + +STATIC fs_user_mount_t *vfs_cur_obj = NULL; + +// "path" is the path to lookup; will advance this pointer beyond the volume name. +// Returns a pointer to the VFS object, NULL means path not found. +fs_user_mount_t *ff_get_vfs(const char **path) { + if (!(*path)) { + return NULL; + } + + if (**path != '/') { + #if _FS_RPATH + return vfs_cur_obj; + #else + return NULL; + #endif + } + + for (size_t i = 0; i < MP_ARRAY_SIZE(MP_STATE_PORT(fs_user_mount)); ++i) { + fs_user_mount_t *vfs = MP_STATE_PORT(fs_user_mount)[i]; + if (vfs != NULL && check_path(path, vfs->str, vfs->len)) { + return vfs; + } + } + + return NULL; +} + +#else + // "path" is the path to lookup; will advance this pointer beyond the volume name. // Returns logical drive number (-1 means invalid path). int ff_get_ldnumber (const TCHAR **path) { @@ -79,4 +113,6 @@ void ff_get_volname(BYTE vol, TCHAR **dest) { *dest += vfs->len; } +#endif + #endif // MICROPY_FSUSERMOUNT -- cgit v1.2.3