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_misc.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'extmod/vfs_fat_misc.c') diff --git a/extmod/vfs_fat_misc.c b/extmod/vfs_fat_misc.c index d3507a85f..5e89009cd 100644 --- a/extmod/vfs_fat_misc.c +++ b/extmod/vfs_fat_misc.c @@ -32,27 +32,39 @@ #include #include "py/nlr.h" #include "py/runtime.h" +#if MICROPY_FATFS_OO +#include "lib/oofatfs/ff.h" +#else #include "lib/fatfs/ff.h" -#include "lib/fatfs/diskio.h" +#endif #include "extmod/vfs_fat_file.h" #include "extmod/fsusermount.h" #include "py/lexer.h" -#if _USE_LFN +#if !MICROPY_FATFS_OO && _USE_LFN STATIC char lfn[_MAX_LFN + 1]; /* Buffer to store the LFN */ #endif // TODO: actually, the core function should be ilistdir() + mp_obj_t fat_vfs_listdir(const char *path, bool is_str_type) { + return fat_vfs_listdir2(NULL, path, is_str_type); +} + +mp_obj_t fat_vfs_listdir2(fs_user_mount_t *vfs, const char *path, bool is_str_type) { FRESULT res; FILINFO fno; DIR dir; -#if _USE_LFN +#if !MICROPY_FATFS_OO && _USE_LFN fno.lfname = lfn; fno.lfsize = sizeof lfn; #endif + #if MICROPY_FATFS_OO + res = f_opendir(&vfs->fatfs, &dir, path); + #else res = f_opendir(&dir, path); /* Open the directory */ + #endif if (res != FR_OK) { mp_raise_OSError(fresult_to_errno_table[res]); } @@ -65,7 +77,7 @@ mp_obj_t fat_vfs_listdir(const char *path, bool is_str_type) { if (fno.fname[0] == '.' && fno.fname[1] == 0) continue; /* Ignore . entry */ if (fno.fname[0] == '.' && fno.fname[1] == '.' && fno.fname[2] == 0) continue; /* Ignore .. entry */ -#if _USE_LFN +#if !MICROPY_FATFS_OO && _USE_LFN char *fn = *fno.lfname ? fno.lfname : fno.fname; #else char *fn = fno.fname; @@ -100,11 +112,19 @@ mp_import_stat_t fat_vfs_import_stat(const char *path); mp_import_stat_t fat_vfs_import_stat(const char *path) { FILINFO fno; -#if _USE_LFN +#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; + } + FRESULT res = f_stat(&vfs->fatfs, path, &fno); + #else FRESULT res = f_stat(path, &fno); + #endif if (res == FR_OK) { if ((fno.fattrib & AM_DIR) != 0) { return MP_IMPORT_STAT_DIR; -- cgit v1.2.3 From 32a1138b9f66b76808906064a76c5f9533cc825c Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 27 Jan 2017 15:04:17 +1100 Subject: extmod: Rename vfs_fat_file.h to vfs_fat.h. And move declaration of mp_fat_vfs_type to this file. --- cc3200/mods/moduos.c | 2 +- esp8266/moduos.c | 3 +-- extmod/vfs_fat.c | 2 +- extmod/vfs_fat.h | 39 +++++++++++++++++++++++++++++++++++++++ extmod/vfs_fat_ffconf.c | 2 +- extmod/vfs_fat_file.c | 2 +- extmod/vfs_fat_file.h | 38 -------------------------------------- extmod/vfs_fat_misc.c | 2 +- extmod/vfs_fat_reader.c | 2 +- stmhal/builtin_open.c | 2 +- stmhal/moduos.c | 2 +- unix/modos.c | 2 +- 12 files changed, 49 insertions(+), 49 deletions(-) create mode 100644 extmod/vfs_fat.h delete mode 100644 extmod/vfs_fat_file.h (limited to 'extmod/vfs_fat_misc.c') diff --git a/cc3200/mods/moduos.c b/cc3200/mods/moduos.c index d5b29336a..1c9932b8e 100644 --- a/cc3200/mods/moduos.c +++ b/cc3200/mods/moduos.c @@ -37,7 +37,7 @@ #include "moduos.h" #include "diskio.h" #include "sflash_diskio.h" -#include "extmod/vfs_fat_file.h" +#include "extmod/vfs_fat.h" #include "random.h" #include "mpexception.h" #include "version.h" diff --git a/esp8266/moduos.c b/esp8266/moduos.c index e9c4c3e8c..5f5aab166 100644 --- a/esp8266/moduos.c +++ b/esp8266/moduos.c @@ -34,12 +34,11 @@ #include "py/runtime.h" #include "py/mperrno.h" #include "extmod/misc.h" +#include "extmod/vfs_fat.h" #include "genhdr/mpversion.h" #include "esp_mphal.h" #include "user_interface.h" -extern const mp_obj_type_t mp_fat_vfs_type; - STATIC const qstr os_uname_info_fields[] = { MP_QSTR_sysname, MP_QSTR_nodename, MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine diff --git a/extmod/vfs_fat.c b/extmod/vfs_fat.c index 36bdb5dbd..36e5031a8 100644 --- a/extmod/vfs_fat.c +++ b/extmod/vfs_fat.c @@ -37,7 +37,7 @@ #include "py/runtime.h" #include "py/mperrno.h" #include "lib/oofatfs/ff.h" -#include "extmod/vfs_fat_file.h" +#include "extmod/vfs_fat.h" #include "extmod/fsusermount.h" #include "timeutils.h" diff --git a/extmod/vfs_fat.h b/extmod/vfs_fat.h new file mode 100644 index 000000000..441b35c04 --- /dev/null +++ b/extmod/vfs_fat.h @@ -0,0 +1,39 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2013, 2014 Damien P. George + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +struct _fs_user_mount_t; + +extern const byte fresult_to_errno_table[20]; +extern const mp_obj_type_t mp_fat_vfs_type; + +struct _fs_user_mount_t *ff_get_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(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs); +MP_DECLARE_CONST_FUN_OBJ_KW(mp_builtin_open_obj); + +mp_obj_t fat_vfs_listdir(const char *path, bool is_str_type); +mp_obj_t fat_vfs_listdir2(struct _fs_user_mount_t *vfs, const char *path, bool is_str_type); diff --git a/extmod/vfs_fat_ffconf.c b/extmod/vfs_fat_ffconf.c index ddcdd8844..89081380e 100644 --- a/extmod/vfs_fat_ffconf.c +++ b/extmod/vfs_fat_ffconf.c @@ -36,7 +36,7 @@ #include "lib/fatfs/ff.h" #endif #include "extmod/fsusermount.h" -#include "extmod/vfs_fat_file.h" +#include "extmod/vfs_fat.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) { diff --git a/extmod/vfs_fat_file.c b/extmod/vfs_fat_file.c index 6651d70d0..ea332709e 100644 --- a/extmod/vfs_fat_file.c +++ b/extmod/vfs_fat_file.c @@ -42,7 +42,7 @@ #include "lib/fatfs/ff.h" #endif #include "extmod/fsusermount.h" -#include "extmod/vfs_fat_file.h" +#include "extmod/vfs_fat.h" #if MICROPY_VFS_FAT #define mp_type_fileio fatfs_type_fileio diff --git a/extmod/vfs_fat_file.h b/extmod/vfs_fat_file.h deleted file mode 100644 index 9693aa04a..000000000 --- a/extmod/vfs_fat_file.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2013, 2014 Damien P. George - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -struct _fs_user_mount_t; - -extern const byte fresult_to_errno_table[20]; - -struct _fs_user_mount_t *ff_get_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(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs); -MP_DECLARE_CONST_FUN_OBJ_KW(mp_builtin_open_obj); - -mp_obj_t fat_vfs_listdir(const char *path, bool is_str_type); -mp_obj_t fat_vfs_listdir2(struct _fs_user_mount_t *vfs, const char *path, bool is_str_type); diff --git a/extmod/vfs_fat_misc.c b/extmod/vfs_fat_misc.c index 5e89009cd..ea267a15f 100644 --- a/extmod/vfs_fat_misc.c +++ b/extmod/vfs_fat_misc.c @@ -37,7 +37,7 @@ #else #include "lib/fatfs/ff.h" #endif -#include "extmod/vfs_fat_file.h" +#include "extmod/vfs_fat.h" #include "extmod/fsusermount.h" #include "py/lexer.h" diff --git a/extmod/vfs_fat_reader.c b/extmod/vfs_fat_reader.c index efd2de0c1..b9abf3ad7 100644 --- a/extmod/vfs_fat_reader.c +++ b/extmod/vfs_fat_reader.c @@ -38,7 +38,7 @@ #include "lib/fatfs/ff.h" #endif #include "extmod/fsusermount.h" -#include "extmod/vfs_fat_file.h" +#include "extmod/vfs_fat.h" typedef struct _mp_reader_fatfs_t { FIL fp; diff --git a/stmhal/builtin_open.c b/stmhal/builtin_open.c index 697eec8ea..56b98ea61 100644 --- a/stmhal/builtin_open.c +++ b/stmhal/builtin_open.c @@ -25,6 +25,6 @@ */ #include "py/runtime.h" -#include "extmod/vfs_fat_file.h" +#include "extmod/vfs_fat.h" MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, fatfs_builtin_open); diff --git a/stmhal/moduos.c b/stmhal/moduos.c index b3c6570a5..158e530ff 100644 --- a/stmhal/moduos.c +++ b/stmhal/moduos.c @@ -37,7 +37,7 @@ #include "timeutils.h" #include "rng.h" #include "uart.h" -#include "extmod/vfs_fat_file.h" +#include "extmod/vfs_fat.h" #include "sdcard.h" #include "extmod/fsusermount.h" #include "portmodules.h" diff --git a/unix/modos.c b/unix/modos.c index 72f5d872e..c35b246dd 100644 --- a/unix/modos.c +++ b/unix/modos.c @@ -39,6 +39,7 @@ #include "py/objtuple.h" #include "py/mphal.h" #include "extmod/misc.h" +#include "extmod/vfs_fat.h" // Can't include this, as FATFS structure definition is required, // and FatFs header defining it conflicts with POSIX. @@ -46,7 +47,6 @@ MP_DECLARE_CONST_FUN_OBJ_KW(fsuser_mount_obj); MP_DECLARE_CONST_FUN_OBJ_1(fsuser_umount_obj); MP_DECLARE_CONST_FUN_OBJ_KW(fsuser_mkfs_obj); -extern const mp_obj_type_t mp_fat_vfs_type; #ifdef __ANDROID__ #define USE_STATFS 1 -- cgit v1.2.3 From 6c23c7587f1c02f58e9246ec59fe4f6544728b50 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 27 Jan 2017 17:17:54 +1100 Subject: extmod/vfs: Add ability for VFS sub-system to import using VfsFat. --- extmod/vfs.c | 7 +++++++ extmod/vfs_fat.h | 3 +++ extmod/vfs_fat_misc.c | 10 +++------- stmhal/import.c | 5 ++--- 4 files changed, 15 insertions(+), 10 deletions(-) (limited to 'extmod/vfs_fat_misc.c') diff --git a/extmod/vfs.c b/extmod/vfs.c index 2880271c6..0cba0bc58 100644 --- a/extmod/vfs.c +++ b/extmod/vfs.c @@ -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; } diff --git a/extmod/vfs_fat.h b/extmod/vfs_fat.h index 52674eb6e..1ea8a9637 100644 --- a/extmod/vfs_fat.h +++ b/extmod/vfs_fat.h @@ -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); diff --git a/extmod/vfs_fat_misc.c b/extmod/vfs_fat_misc.c index ea267a15f..489e53586 100644 --- a/extmod/vfs_fat_misc.c +++ b/extmod/vfs_fat_misc.c @@ -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) { diff --git a/stmhal/import.c b/stmhal/import.c index 1edbe2caa..2bc282e7b 100644 --- a/stmhal/import.c +++ b/stmhal/import.c @@ -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); } -- cgit v1.2.3 From ec3274324b0f7460f0276957184dc4b9f33a9bc7 Mon Sep 17 00:00:00 2001 From: Damien George Date: Sun, 29 Jan 2017 23:05:33 +1100 Subject: extmod/vfs_fat: Update to use FF_DIR instead of DIR. --- extmod/vfs_fat_misc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'extmod/vfs_fat_misc.c') diff --git a/extmod/vfs_fat_misc.c b/extmod/vfs_fat_misc.c index 489e53586..2f06d9f63 100644 --- a/extmod/vfs_fat_misc.c +++ b/extmod/vfs_fat_misc.c @@ -54,7 +54,7 @@ mp_obj_t fat_vfs_listdir(const char *path, bool is_str_type) { mp_obj_t fat_vfs_listdir2(fs_user_mount_t *vfs, const char *path, bool is_str_type) { FRESULT res; FILINFO fno; - DIR dir; + FF_DIR dir; #if !MICROPY_FATFS_OO && _USE_LFN fno.lfname = lfn; fno.lfsize = sizeof lfn; -- cgit v1.2.3 From 3d6f9572084a8bcba762899ee4f8ea15ddf010ab Mon Sep 17 00:00:00 2001 From: Damien George Date: Sun, 29 Jan 2017 15:17:55 +1100 Subject: extmod/vfs_fat: Remove MICROPY_FSUSERMOUNT_ADHOC config option. --- extmod/vfs_fat_file.c | 4 +--- extmod/vfs_fat_misc.c | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) (limited to 'extmod/vfs_fat_misc.c') diff --git a/extmod/vfs_fat_file.c b/extmod/vfs_fat_file.c index f5a188036..d3d437823 100644 --- a/extmod/vfs_fat_file.c +++ b/extmod/vfs_fat_file.c @@ -25,9 +25,7 @@ */ #include "py/mpconfig.h" -// *_ADHOC part is for cc3200 port which doesn't use general uPy -// infrastructure and instead duplicates code. TODO: Resolve. -#if MICROPY_VFS || MICROPY_FSUSERMOUNT || MICROPY_FSUSERMOUNT_ADHOC +#if MICROPY_VFS || MICROPY_FSUSERMOUNT #include #include diff --git a/extmod/vfs_fat_misc.c b/extmod/vfs_fat_misc.c index 2f06d9f63..7e7576398 100644 --- a/extmod/vfs_fat_misc.c +++ b/extmod/vfs_fat_misc.c @@ -25,9 +25,7 @@ */ #include "py/mpconfig.h" -// *_ADHOC part is for cc3200 port which doesn't use general uPy -// infrastructure and instead duplicates code. TODO: Resolve. -#if MICROPY_VFS_FAT || MICROPY_FSUSERMOUNT || MICROPY_FSUSERMOUNT_ADHOC +#if MICROPY_VFS_FAT || MICROPY_FSUSERMOUNT #include #include "py/nlr.h" -- cgit v1.2.3 From 1808b2e8d5c9fff8020628a7849a537ffa9790e3 Mon Sep 17 00:00:00 2001 From: Damien George Date: Sun, 29 Jan 2017 15:21:46 +1100 Subject: extmod: Remove MICROPY_FSUSERMOUNT and related files. Replaced by MICROPY_VFS and the VFS sub-system. --- extmod/fsusermount.c | 244 ------------------------------------------------ extmod/vfs_fat.h | 2 - extmod/vfs_fat_diskio.c | 4 +- extmod/vfs_fat_ffconf.c | 118 ----------------------- extmod/vfs_fat_file.c | 4 +- extmod/vfs_fat_misc.c | 2 +- py/mpconfig.h | 5 - py/mpstate.h | 5 - py/py.mk | 2 - unix/modos.c | 12 --- unix/mpconfigport.h | 1 - 11 files changed, 5 insertions(+), 394 deletions(-) delete mode 100644 extmod/fsusermount.c delete mode 100644 extmod/vfs_fat_ffconf.c (limited to 'extmod/vfs_fat_misc.c') diff --git a/extmod/fsusermount.c b/extmod/fsusermount.c deleted file mode 100644 index 4ca9b80a6..000000000 --- a/extmod/fsusermount.c +++ /dev/null @@ -1,244 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2014 Damien P. George - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "py/mpconfig.h" -#if MICROPY_FSUSERMOUNT -#include -#include - -#include "py/nlr.h" -#include "py/runtime.h" -#include "py/mperrno.h" -#if MICROPY_FATFS_OO -#include "lib/oofatfs/ff.h" -#else -#include "lib/fatfs/ff.h" -#endif -#include "extmod/fsusermount.h" - -fs_user_mount_t *fatfs_mount_mkfs(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args, bool mkfs) { - static const mp_arg_t allowed_args[] = { - { MP_QSTR_readonly, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} }, - { MP_QSTR_mkfs, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} }, - }; - - // parse args - mp_obj_t device = pos_args[0]; - mp_obj_t mount_point = pos_args[1]; - mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args - 2, pos_args + 2, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - - // get the mount point - mp_uint_t mnt_len; - const char *mnt_str = mp_obj_str_get_data(mount_point, &mnt_len); - - if (device == mp_const_none) { - // umount - FRESULT res = FR_NO_FILESYSTEM; - 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 && !memcmp(mnt_str, vfs->str, mnt_len + 1)) { - #if MICROPY_FATFS_OO - res = f_umount(&vfs->fatfs); - #else - res = f_mount(NULL, vfs->str, 0); - #endif - if (vfs->flags & FSUSER_FREE_OBJ) { - m_del_obj(fs_user_mount_t, vfs); - } - MP_STATE_PORT(fs_user_mount)[i] = NULL; - break; - } - } - if (res != FR_OK) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "can't umount")); - } - return NULL; - } else { - // mount - size_t i = 0; - for (; i < MP_ARRAY_SIZE(MP_STATE_PORT(fs_user_mount)); ++i) { - if (MP_STATE_PORT(fs_user_mount)[i] == NULL) { - break; - } - } - if (i == MP_ARRAY_SIZE(MP_STATE_PORT(fs_user_mount))) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "too many devices mounted")); - } - - // create new object - fs_user_mount_t *vfs = m_new_obj(fs_user_mount_t); - vfs->str = mnt_str; - vfs->len = mnt_len; - vfs->flags = FSUSER_FREE_OBJ; - #if MICROPY_FATFS_OO - vfs->fatfs.drv = vfs; - #endif - - // load block protocol methods - mp_load_method(device, MP_QSTR_readblocks, vfs->readblocks); - mp_load_method_maybe(device, MP_QSTR_writeblocks, vfs->writeblocks); - mp_load_method_maybe(device, MP_QSTR_ioctl, vfs->u.ioctl); - if (vfs->u.ioctl[0] != MP_OBJ_NULL) { - // device supports new block protocol, so indicate it - vfs->flags |= FSUSER_HAVE_IOCTL; - } else { - // no ioctl method, so assume the device uses the old block protocol - mp_load_method_maybe(device, MP_QSTR_sync, vfs->u.old.sync); - mp_load_method(device, MP_QSTR_count, vfs->u.old.count); - } - - // Read-only device indicated by writeblocks[0] == MP_OBJ_NULL. - // User can specify read-only device by: - // 1. readonly=True keyword argument - // 2. nonexistent writeblocks method (then writeblocks[0] == MP_OBJ_NULL already) - if (args[0].u_bool) { - vfs->writeblocks[0] = MP_OBJ_NULL; - } - - // Register the vfs object so that it can be found by the FatFS driver using - // ff_get_ldnumber. We don't register it any earlier than this point in case there - // is an exception, in which case there would remain a partially mounted device. - MP_STATE_PORT(fs_user_mount)[i] = vfs; - - // mount the block device (if mkfs, only pre-mount) - FRESULT res; - #if MICROPY_FATFS_OO - if (mkfs) { - res = FR_OK; - } else { - res = f_mount(&vfs->fatfs); - } - #else - res = f_mount(&vfs->fatfs, vfs->str, !mkfs); - #endif - - // check the result - if (res == FR_OK) { - if (mkfs) { - goto mkfs; - } - } else if (res == FR_NO_FILESYSTEM && args[1].u_bool) { -mkfs:; - #if MICROPY_FATFS_OO - uint8_t working_buf[_MAX_SS]; - res = f_mkfs(&vfs->fatfs, FM_FAT | FM_SFD, 0, working_buf, sizeof(working_buf)); - #else - res = f_mkfs(vfs->str, 1, 0); - #endif - if (res != FR_OK) { -mkfs_error: - MP_STATE_PORT(fs_user_mount)[i] = NULL; - nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "can't mkfs")); - } - if (mkfs) { - // If requested to only mkfs, unmount pre-mounted device - #if MICROPY_FATFS_OO - res = FR_OK; - #else - res = f_mount(NULL, vfs->str, 0); - #endif - if (res != FR_OK) { - goto mkfs_error; - } - MP_STATE_PORT(fs_user_mount)[i] = NULL; - return NULL; - } - } else { - MP_STATE_PORT(fs_user_mount)[i] = NULL; - nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "can't mount")); - } - - /* - if (vfs->writeblocks[0] == MP_OBJ_NULL) { - printf("mounted read-only"); - } else { - printf("mounted read-write"); - } - DWORD nclst; - FATFS *fatfs; - f_getfree(vfs->str, &nclst, &fatfs); - printf(" on %s with %u bytes free\n", vfs->str, (uint)(nclst * fatfs->csize * 512)); - */ - return vfs; - } -} - -STATIC mp_obj_t fatfs_mount(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - fatfs_mount_mkfs(n_args, pos_args, kw_args, false); - return mp_const_none; -} -MP_DEFINE_CONST_FUN_OBJ_KW(fsuser_mount_obj, 2, fatfs_mount); - -mp_obj_t fatfs_umount(mp_obj_t bdev_or_path_in) { - size_t i = 0; - if (MP_OBJ_IS_STR(bdev_or_path_in)) { - mp_uint_t mnt_len; - const char *mnt_str = mp_obj_str_get_data(bdev_or_path_in, &mnt_len); - for (; 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 && !memcmp(mnt_str, vfs->str, mnt_len + 1)) { - break; - } - } - } else { - for (; 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 && bdev_or_path_in == vfs->readblocks[1]) { - break; - } - } - } - - if (i == MP_ARRAY_SIZE(MP_STATE_PORT(fs_user_mount))) { - mp_raise_OSError(MP_EINVAL); - } - - fs_user_mount_t *vfs = MP_STATE_PORT(fs_user_mount)[i]; - FRESULT res; - #if MICROPY_FATFS_OO - res = f_umount(&vfs->fatfs); - #else - res = f_mount(NULL, vfs->str, 0); - #endif - if (vfs->flags & FSUSER_FREE_OBJ) { - m_del_obj(fs_user_mount_t, vfs); - } - MP_STATE_PORT(fs_user_mount)[i] = NULL; - if (res != FR_OK) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "can't umount")); - } - return mp_const_none; -} -MP_DEFINE_CONST_FUN_OBJ_1(fsuser_umount_obj, fatfs_umount); - -STATIC mp_obj_t fatfs_mkfs(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - fatfs_mount_mkfs(n_args, pos_args, kw_args, true); - return mp_const_none; -} -MP_DEFINE_CONST_FUN_OBJ_KW(fsuser_mkfs_obj, 2, fatfs_mkfs); - -#endif // MICROPY_FSUSERMOUNT diff --git a/extmod/vfs_fat.h b/extmod/vfs_fat.h index 1ea8a9637..bc5be0c67 100644 --- a/extmod/vfs_fat.h +++ b/extmod/vfs_fat.h @@ -31,8 +31,6 @@ struct _fs_user_mount_t; extern const byte fresult_to_errno_table[20]; 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); diff --git a/extmod/vfs_fat_diskio.c b/extmod/vfs_fat_diskio.c index 3bbd37435..c8a6e1533 100644 --- a/extmod/vfs_fat_diskio.c +++ b/extmod/vfs_fat_diskio.c @@ -28,7 +28,7 @@ */ #include "py/mpconfig.h" -#if MICROPY_VFS || MICROPY_FSUSERMOUNT +#if MICROPY_VFS #include #include @@ -305,4 +305,4 @@ DRESULT disk_ioctl ( } #endif -#endif // MICROPY_VFS || MICROPY_FSUSERMOUNT +#endif // MICROPY_VFS diff --git a/extmod/vfs_fat_ffconf.c b/extmod/vfs_fat_ffconf.c deleted file mode 100644 index 89081380e..000000000 --- a/extmod/vfs_fat_ffconf.c +++ /dev/null @@ -1,118 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2013, 2014 Damien P. George - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "py/mpconfig.h" -#if MICROPY_FSUSERMOUNT - -#include - -#include "py/mpstate.h" -#if MICROPY_FATFS_OO -#include "lib/oofatfs/ff.h" -#else -#include "lib/fatfs/ff.h" -#endif -#include "extmod/fsusermount.h" -#include "extmod/vfs_fat.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) { - if ((*path)[mount_point_len] == '/') { - *path += mount_point_len; - return true; - } else if ((*path)[mount_point_len] == '\0') { - *path = "/"; - return true; - } - } - 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) { - if (!(*path)) { - return -1; - } - - if (**path != '/') { - #if _FS_RPATH - return ff_CurrVol; - #else - return -1; - #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 i; - } - } - - return -1; -} - -void ff_get_volname(BYTE vol, TCHAR **dest) { - fs_user_mount_t *vfs = MP_STATE_PORT(fs_user_mount)[vol]; - memcpy(*dest, vfs->str, vfs->len); - *dest += vfs->len; -} - -#endif - -#endif // MICROPY_FSUSERMOUNT diff --git a/extmod/vfs_fat_file.c b/extmod/vfs_fat_file.c index d3d437823..dccd12035 100644 --- a/extmod/vfs_fat_file.c +++ b/extmod/vfs_fat_file.c @@ -25,7 +25,7 @@ */ #include "py/mpconfig.h" -#if MICROPY_VFS || MICROPY_FSUSERMOUNT +#if MICROPY_VFS #include #include @@ -322,4 +322,4 @@ mp_obj_t fatfs_builtin_open_self(mp_obj_t self_in, mp_obj_t path, mp_obj_t mode) return file_open(self, &mp_type_textio, arg_vals); } -#endif // MICROPY_VFS || MICROPY_FSUSERMOUNT +#endif // MICROPY_VFS diff --git a/extmod/vfs_fat_misc.c b/extmod/vfs_fat_misc.c index 7e7576398..82ef91a1f 100644 --- a/extmod/vfs_fat_misc.c +++ b/extmod/vfs_fat_misc.c @@ -25,7 +25,7 @@ */ #include "py/mpconfig.h" -#if MICROPY_VFS_FAT || MICROPY_FSUSERMOUNT +#if MICROPY_VFS_FAT #include #include "py/nlr.h" diff --git a/py/mpconfig.h b/py/mpconfig.h index d078e9301..993ad1db8 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -616,11 +616,6 @@ typedef double mp_float_t; #define MICROPY_USE_INTERNAL_PRINTF (1) #endif -// Support for user-space VFS mount (selected ports) -#ifndef MICROPY_FSUSERMOUNT -#define MICROPY_FSUSERMOUNT (0) -#endif - // Support for generic VFS sub-system #ifndef MICROPY_VFS #define MICROPY_VFS (0) diff --git a/py/mpstate.h b/py/mpstate.h index daf085a06..54392a994 100644 --- a/py/mpstate.h +++ b/py/mpstate.h @@ -160,11 +160,6 @@ typedef struct _mp_state_vm_t { mp_obj_t lwip_slip_stream; #endif - #if MICROPY_FSUSERMOUNT - // for user-mountable block device (max fixed at compile time) - struct _fs_user_mount_t *fs_user_mount[MICROPY_FATFS_VOLUMES]; - #endif - #if MICROPY_VFS struct _mp_vfs_mount_t *vfs_cur; struct _mp_vfs_mount_t *vfs_mount_table; diff --git a/py/py.mk b/py/py.mk index 0e5a9667d..01a802674 100644 --- a/py/py.mk +++ b/py/py.mk @@ -233,11 +233,9 @@ PY_O_BASENAME = \ ../extmod/modwebsocket.o \ ../extmod/modwebrepl.o \ ../extmod/modframebuf.o \ - ../extmod/fsusermount.o \ ../extmod/vfs.o \ ../extmod/vfs_reader.o \ ../extmod/vfs_fat.o \ - ../extmod/vfs_fat_ffconf.o \ ../extmod/vfs_fat_diskio.o \ ../extmod/vfs_fat_file.o \ ../extmod/vfs_fat_misc.o \ diff --git a/unix/modos.c b/unix/modos.c index c35b246dd..1584b0d20 100644 --- a/unix/modos.c +++ b/unix/modos.c @@ -41,13 +41,6 @@ #include "extmod/misc.h" #include "extmod/vfs_fat.h" -// Can't include this, as FATFS structure definition is required, -// and FatFs header defining it conflicts with POSIX. -//#include "extmod/fsusermount.h" -MP_DECLARE_CONST_FUN_OBJ_KW(fsuser_mount_obj); -MP_DECLARE_CONST_FUN_OBJ_1(fsuser_umount_obj); -MP_DECLARE_CONST_FUN_OBJ_KW(fsuser_mkfs_obj); - #ifdef __ANDROID__ #define USE_STATFS 1 #endif @@ -233,11 +226,6 @@ STATIC const mp_rom_map_elem_t mp_module_os_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_getenv), MP_ROM_PTR(&mod_os_getenv_obj) }, { MP_ROM_QSTR(MP_QSTR_mkdir), MP_ROM_PTR(&mod_os_mkdir_obj) }, { MP_ROM_QSTR(MP_QSTR_ilistdir), MP_ROM_PTR(&mod_os_ilistdir_obj) }, - #if MICROPY_FSUSERMOUNT - { MP_ROM_QSTR(MP_QSTR_vfs_mount), MP_ROM_PTR(&fsuser_mount_obj) }, - { MP_ROM_QSTR(MP_QSTR_vfs_umount), MP_ROM_PTR(&fsuser_umount_obj) }, - { MP_ROM_QSTR(MP_QSTR_vfs_mkfs), MP_ROM_PTR(&fsuser_mkfs_obj) }, - #endif #if MICROPY_VFS_FAT { MP_ROM_QSTR(MP_QSTR_VfsFat), MP_ROM_PTR(&mp_fat_vfs_type) }, #endif diff --git a/unix/mpconfigport.h b/unix/mpconfigport.h index f61a381a3..3aff893d6 100644 --- a/unix/mpconfigport.h +++ b/unix/mpconfigport.h @@ -139,7 +139,6 @@ #define MICROPY_FATFS_VOLUMES (3) #define MICROPY_FATFS_MAX_SS (4096) #define MICROPY_FATFS_LFN_CODE_PAGE (437) /* 1=SFN/ANSI 437=LFN/U.S.(OEM) */ -#define MICROPY_FSUSERMOUNT (0) #define MICROPY_VFS_FAT (0) // Define to MICROPY_ERROR_REPORTING_DETAILED to get function, etc. -- cgit v1.2.3 From 0bd61d23b9b21819da9d10290dfccd4ae4a69e1a Mon Sep 17 00:00:00 2001 From: Damien George Date: Sun, 29 Jan 2017 15:26:24 +1100 Subject: extmod/vfs_fat: Remove MICROPY_FATFS_OO config option. Everyone should now be using the new ooFatFs library. The old one is no longer supported and will be removed. --- cc3200/mpconfigport.h | 1 - esp8266/mpconfigport.h | 1 - extmod/vfs_fat.c | 4 ---- extmod/vfs_fat_diskio.c | 32 ++------------------------------ extmod/vfs_fat_file.c | 13 ------------- extmod/vfs_fat_misc.c | 29 ----------------------------- stmhal/mpconfigport.h | 1 - unix/mpconfigport.h | 1 - 8 files changed, 2 insertions(+), 80 deletions(-) (limited to 'extmod/vfs_fat_misc.c') diff --git a/cc3200/mpconfigport.h b/cc3200/mpconfigport.h index 939d9f62b..49ea64403 100644 --- a/cc3200/mpconfigport.h +++ b/cc3200/mpconfigport.h @@ -64,7 +64,6 @@ #define MICROPY_QSTR_BYTES_IN_HASH (1) // fatfs configuration used in ffconf.h -#define MICROPY_FATFS_OO (1) #define MICROPY_FATFS_ENABLE_LFN (2) #define MICROPY_FATFS_MAX_LFN (MICROPY_ALLOC_PATH_MAX) #define MICROPY_FATFS_LFN_CODE_PAGE (437) // 1=SFN/ANSI 437=LFN/U.S.(OEM) diff --git a/esp8266/mpconfigport.h b/esp8266/mpconfigport.h index 89d9dae76..04b9792eb 100644 --- a/esp8266/mpconfigport.h +++ b/esp8266/mpconfigport.h @@ -95,7 +95,6 @@ #define MICROPY_QSTR_EXTRA_POOL mp_qstr_frozen_const_pool #define MICROPY_VFS (1) -#define MICROPY_FATFS_OO (1) #define MICROPY_FATFS_ENABLE_LFN (1) #define MICROPY_FATFS_RPATH (2) #define MICROPY_FATFS_MAX_SS (4096) diff --git a/extmod/vfs_fat.c b/extmod/vfs_fat.c index a6f2ae806..ecbbdb59a 100644 --- a/extmod/vfs_fat.c +++ b/extmod/vfs_fat.c @@ -32,10 +32,6 @@ #error "with MICROPY_VFS_FAT enabled, must also enable MICROPY_VFS" #endif -#if !MICROPY_FATFS_OO -#error "with MICROPY_VFS_FAT enabled, must also enable MICROPY_FATFS_OO" -#endif - #include #include "py/nlr.h" #include "py/runtime.h" diff --git a/extmod/vfs_fat_diskio.c b/extmod/vfs_fat_diskio.c index c8a6e1533..e12c4597e 100644 --- a/extmod/vfs_fat_diskio.c +++ b/extmod/vfs_fat_diskio.c @@ -36,13 +36,8 @@ #include "py/mphal.h" #include "py/runtime.h" -#if MICROPY_FATFS_OO #include "lib/oofatfs/ff.h" #include "lib/oofatfs/diskio.h" -#else -#include "lib/fatfs/ff.h" /* FatFs lower layer API */ -#include "lib/fatfs/diskio.h" /* FatFs lower layer API */ -#endif #include "extmod/fsusermount.h" #if _MAX_SS == _MIN_SS @@ -51,29 +46,16 @@ #define SECSIZE(fs) ((fs)->ssize) #endif -#if MICROPY_FATFS_OO typedef void *bdev_t; STATIC fs_user_mount_t *disk_get_device(void *bdev) { return (fs_user_mount_t*)bdev; } -#else -typedef BYTE bdev_t; -STATIC fs_user_mount_t *disk_get_device(uint id) { - if (id < MP_ARRAY_SIZE(MP_STATE_PORT(fs_user_mount))) { - return MP_STATE_PORT(fs_user_mount)[id]; - } else { - return NULL; - } -} -#endif /*-----------------------------------------------------------------------*/ /* Initialize a Drive */ /*-----------------------------------------------------------------------*/ -#if MICROPY_FATFS_OO STATIC -#endif DSTATUS disk_initialize ( bdev_t pdrv /* Physical drive nmuber (0..) */ ) @@ -105,9 +87,7 @@ DSTATUS disk_initialize ( /* Get Disk Status */ /*-----------------------------------------------------------------------*/ -#if MICROPY_FATFS_OO STATIC -#endif DSTATUS disk_status ( bdev_t pdrv /* Physical drive nmuber (0..) */ ) @@ -159,7 +139,6 @@ DRESULT disk_read ( /* Write Sector(s) */ /*-----------------------------------------------------------------------*/ -#if MICROPY_FATFS_OO || _USE_WRITE DRESULT disk_write ( bdev_t pdrv, /* Physical drive nmuber (0..) */ const BYTE *buff, /* Data to be written */ @@ -191,14 +170,12 @@ DRESULT disk_write ( return RES_OK; } -#endif /*-----------------------------------------------------------------------*/ /* Miscellaneous Functions */ /*-----------------------------------------------------------------------*/ -#if MICROPY_FATFS_OO || _USE_IOCTL DRESULT disk_ioctl ( bdev_t pdrv, /* Physical drive nmuber (0..) */ BYTE cmd, /* Control code */ @@ -237,7 +214,7 @@ DRESULT disk_ioctl ( } else { *((WORD*)buff) = mp_obj_get_int(ret); } - #if MICROPY_FATFS_OO && _MAX_SS != _MIN_SS + #if _MAX_SS != _MIN_SS // need to store ssize because we use it in disk_read/disk_write vfs->fatfs.ssize = *((WORD*)buff); #endif @@ -248,7 +225,6 @@ DRESULT disk_ioctl ( *((DWORD*)buff) = 1; // erase block size in units of sector size return RES_OK; - #if MICROPY_FATFS_OO case IOCTL_INIT: *((DSTATUS*)buff) = disk_initialize(pdrv); return RES_OK; @@ -256,7 +232,6 @@ DRESULT disk_ioctl ( case IOCTL_STATUS: *((DSTATUS*)buff) = disk_status(pdrv); return RES_OK; - #endif default: return RES_PARERR; @@ -278,7 +253,7 @@ DRESULT disk_ioctl ( case GET_SECTOR_SIZE: *((WORD*)buff) = 512; // old protocol had fixed sector size - #if MICROPY_FATFS_OO && _MAX_SS != _MIN_SS + #if _MAX_SS != _MIN_SS // need to store ssize because we use it in disk_read/disk_write vfs->fatfs.ssize = 512; #endif @@ -288,7 +263,6 @@ DRESULT disk_ioctl ( *((DWORD*)buff) = 1; // erase block size in units of sector size return RES_OK; - #if MICROPY_FATFS_OO case IOCTL_INIT: *((DSTATUS*)buff) = disk_initialize(pdrv); return RES_OK; @@ -296,13 +270,11 @@ DRESULT disk_ioctl ( case IOCTL_STATUS: *((DSTATUS*)buff) = disk_status(pdrv); return RES_OK; - #endif default: return RES_PARERR; } } } -#endif #endif // MICROPY_VFS diff --git a/extmod/vfs_fat_file.c b/extmod/vfs_fat_file.c index dccd12035..bb5903575 100644 --- a/extmod/vfs_fat_file.c +++ b/extmod/vfs_fat_file.c @@ -34,11 +34,7 @@ #include "py/runtime.h" #include "py/stream.h" #include "py/mperrno.h" -#if MICROPY_FATFS_OO #include "lib/oofatfs/ff.h" -#else -#include "lib/fatfs/ff.h" -#endif #include "extmod/fsusermount.h" #include "extmod/vfs_fat.h" @@ -115,11 +111,7 @@ STATIC mp_uint_t file_obj_write(mp_obj_t self_in, const void *buf, mp_uint_t siz STATIC mp_obj_t file_obj_close(mp_obj_t self_in) { pyb_file_obj_t *self = MP_OBJ_TO_PTR(self_in); // if fs==NULL then the file is closed and in that case this method is a no-op - #if MICROPY_FATFS_OO if (self->fp.obj.fs != NULL) { - #else - if (self->fp.fs != NULL) { - #endif FRESULT res = f_close(&self->fp); if (res != FR_OK) { mp_raise_OSError(fresult_to_errno_table[res]); @@ -221,13 +213,8 @@ STATIC mp_obj_t file_open(fs_user_mount_t *vfs, const mp_obj_type_t *type, mp_ar o->base.type = type; const char *fname = mp_obj_str_get_str(args[0].u_obj); - #if MICROPY_FATFS_OO assert(vfs != NULL); FRESULT res = f_open(&vfs->fatfs, &o->fp, fname, mode); - #else - (void)vfs; - FRESULT res = f_open(&o->fp, fname, mode); - #endif if (res != FR_OK) { m_del_obj(pyb_file_obj_t, o); mp_raise_OSError(fresult_to_errno_table[res]); diff --git a/extmod/vfs_fat_misc.c b/extmod/vfs_fat_misc.c index 82ef91a1f..ba513ef92 100644 --- a/extmod/vfs_fat_misc.c +++ b/extmod/vfs_fat_misc.c @@ -30,19 +30,11 @@ #include #include "py/nlr.h" #include "py/runtime.h" -#if MICROPY_FATFS_OO #include "lib/oofatfs/ff.h" -#else -#include "lib/fatfs/ff.h" -#endif #include "extmod/vfs_fat.h" #include "extmod/fsusermount.h" #include "py/lexer.h" -#if !MICROPY_FATFS_OO && _USE_LFN -STATIC char lfn[_MAX_LFN + 1]; /* Buffer to store the LFN */ -#endif - // TODO: actually, the core function should be ilistdir() mp_obj_t fat_vfs_listdir(const char *path, bool is_str_type) { @@ -53,16 +45,8 @@ mp_obj_t fat_vfs_listdir2(fs_user_mount_t *vfs, const char *path, bool is_str_ty FRESULT res; FILINFO fno; FF_DIR dir; -#if !MICROPY_FATFS_OO && _USE_LFN - fno.lfname = lfn; - fno.lfsize = sizeof lfn; -#endif - #if MICROPY_FATFS_OO res = f_opendir(&vfs->fatfs, &dir, path); - #else - res = f_opendir(&dir, path); /* Open the directory */ - #endif if (res != FR_OK) { mp_raise_OSError(fresult_to_errno_table[res]); } @@ -75,11 +59,7 @@ mp_obj_t fat_vfs_listdir2(fs_user_mount_t *vfs, const char *path, bool is_str_ty if (fno.fname[0] == '.' && fno.fname[1] == 0) continue; /* Ignore . entry */ if (fno.fname[0] == '.' && fno.fname[1] == '.' && fno.fname[2] == 0) continue; /* Ignore .. entry */ -#if !MICROPY_FATFS_OO && _USE_LFN - char *fn = *fno.lfname ? fno.lfname : fno.fname; -#else char *fn = fno.fname; -#endif /* if (fno.fattrib & AM_DIR) { @@ -108,17 +88,8 @@ mp_obj_t fat_vfs_listdir2(fs_user_mount_t *vfs, const char *path, bool is_str_ty 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 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) { if ((fno.fattrib & AM_DIR) != 0) { return MP_IMPORT_STAT_DIR; diff --git a/stmhal/mpconfigport.h b/stmhal/mpconfigport.h index 53369a182..873215458 100644 --- a/stmhal/mpconfigport.h +++ b/stmhal/mpconfigport.h @@ -135,7 +135,6 @@ #endif // fatfs configuration used in ffconf.h -#define MICROPY_FATFS_OO (1) #define MICROPY_FATFS_ENABLE_LFN (1) #define MICROPY_FATFS_LFN_CODE_PAGE (437) /* 1=SFN/ANSI 437=LFN/U.S.(OEM) */ #define MICROPY_FATFS_USE_LABEL (1) diff --git a/unix/mpconfigport.h b/unix/mpconfigport.h index 9e418fe0a..ba2b5ce98 100644 --- a/unix/mpconfigport.h +++ b/unix/mpconfigport.h @@ -131,7 +131,6 @@ #define MICROPY_MACHINE_MEM_GET_READ_ADDR mod_machine_mem_get_addr #define MICROPY_MACHINE_MEM_GET_WRITE_ADDR mod_machine_mem_get_addr -#define MICROPY_FATFS_OO (1) #define MICROPY_FATFS_ENABLE_LFN (1) #define MICROPY_FATFS_RPATH (2) #define MICROPY_FATFS_MAX_SS (4096) -- cgit v1.2.3 From b697c890096805d9ccaf7553dbff5b82f5332609 Mon Sep 17 00:00:00 2001 From: Damien George Date: Sun, 29 Jan 2017 19:20:27 +1100 Subject: extmod: Merge old fsusermount.h header into vfs.h and vfs_fat.h. vfs.h is for generic VFS declarations, and vfs_fat.h is for VfsFat specific things. --- cc3200/ftp/ftp.c | 2 +- cc3200/mods/pybflash.c | 1 - cc3200/mods/pybsd.c | 2 +- cc3200/mptask.c | 2 +- extmod/fsusermount.h | 62 ------------------------------------------------- extmod/vfs.c | 5 +++- extmod/vfs.h | 7 ++++++ extmod/vfs_fat.c | 1 - extmod/vfs_fat.h | 26 ++++++++++++++++++++- extmod/vfs_fat_diskio.c | 2 +- extmod/vfs_fat_file.c | 1 - extmod/vfs_fat_misc.c | 1 - stmhal/main.c | 2 +- stmhal/modmachine.c | 2 +- stmhal/sdcard.c | 1 - stmhal/storage.c | 1 - 16 files changed, 42 insertions(+), 76 deletions(-) delete mode 100644 extmod/fsusermount.h (limited to 'extmod/vfs_fat_misc.c') diff --git a/cc3200/ftp/ftp.c b/cc3200/ftp/ftp.c index c8a52149c..679c32561 100644 --- a/cc3200/ftp/ftp.c +++ b/cc3200/ftp/ftp.c @@ -32,7 +32,7 @@ #include "py/obj.h" #include "lib/oofatfs/ff.h" #include "extmod/vfs.h" -#include "extmod/fsusermount.h" +#include "extmod/vfs_fat.h" #include "inc/hw_types.h" #include "inc/hw_ints.h" #include "inc/hw_memmap.h" diff --git a/cc3200/mods/pybflash.c b/cc3200/mods/pybflash.c index 0779f4a05..f5af79dbf 100644 --- a/cc3200/mods/pybflash.c +++ b/cc3200/mods/pybflash.c @@ -31,7 +31,6 @@ #include "lib/oofatfs/ff.h" #include "lib/oofatfs/diskio.h" #include "extmod/vfs_fat.h" -#include "extmod/fsusermount.h" #include "fatfs/src/drivers/sflash_diskio.h" #include "mods/pybflash.h" diff --git a/cc3200/mods/pybsd.c b/cc3200/mods/pybsd.c index bac5a270c..937b8599d 100644 --- a/cc3200/mods/pybsd.c +++ b/cc3200/mods/pybsd.c @@ -29,7 +29,7 @@ #include "py/runtime.h" #include "lib/oofatfs/ff.h" #include "lib/oofatfs/diskio.h" -#include "extmod/fsusermount.h" +#include "extmod/vfs_fat.h" #include "inc/hw_types.h" #include "inc/hw_gpio.h" #include "inc/hw_ints.h" diff --git a/cc3200/mptask.c b/cc3200/mptask.c index 476561c6d..c7c1832ed 100644 --- a/cc3200/mptask.c +++ b/cc3200/mptask.c @@ -36,7 +36,7 @@ #include "lib/oofatfs/ff.h" #include "lib/oofatfs/diskio.h" #include "extmod/vfs.h" -#include "extmod/fsusermount.h" +#include "extmod/vfs_fat.h" #include "inc/hw_memmap.h" #include "inc/hw_types.h" #include "inc/hw_ints.h" diff --git a/extmod/fsusermount.h b/extmod/fsusermount.h deleted file mode 100644 index af6867d23..000000000 --- a/extmod/fsusermount.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2014 Damien P. George - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -// these are the values for fs_user_mount_t.flags -#define FSUSER_NATIVE (0x0001) // readblocks[2]/writeblocks[2] contain native func -#define FSUSER_FREE_OBJ (0x0002) // fs_user_mount_t obj should be freed on umount -#define FSUSER_HAVE_IOCTL (0x0004) // new protocol with ioctl - -// constants for block protocol ioctl -#define BP_IOCTL_INIT (1) -#define BP_IOCTL_DEINIT (2) -#define BP_IOCTL_SYNC (3) -#define BP_IOCTL_SEC_COUNT (4) -#define BP_IOCTL_SEC_SIZE (5) - -typedef struct _fs_user_mount_t { - mp_obj_base_t base; - const char *str; - uint16_t len; // length of str - uint16_t flags; - mp_obj_t readblocks[4]; - mp_obj_t writeblocks[4]; - // new protocol uses just ioctl, old uses sync (optional) and count - union { - mp_obj_t ioctl[4]; - struct { - mp_obj_t sync[2]; - mp_obj_t count[2]; - } old; - } u; - FATFS fatfs; -} fs_user_mount_t; - -fs_user_mount_t *fatfs_mount_mkfs(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args, bool mkfs); -mp_obj_t fatfs_umount(mp_obj_t bdev_or_path_in); - -MP_DECLARE_CONST_FUN_OBJ_KW(fsuser_mount_obj); -MP_DECLARE_CONST_FUN_OBJ_1(fsuser_umount_obj); -MP_DECLARE_CONST_FUN_OBJ_KW(fsuser_mkfs_obj); diff --git a/extmod/vfs.c b/extmod/vfs.c index 97c9077a2..1eb26acf1 100644 --- a/extmod/vfs.c +++ b/extmod/vfs.c @@ -31,10 +31,13 @@ #include "py/objstr.h" #include "py/mperrno.h" #include "extmod/vfs.h" -#include "extmod/vfs_fat.h" #if MICROPY_VFS +#if MICROPY_VFS_FAT +#include "extmod/vfs_fat.h" +#endif + // path is the path to lookup and *path_out holds the path within the VFS // object (starts with / if an absolute path). // Returns MP_VFS_ROOT for root dir (and then path_out is undefined) and diff --git a/extmod/vfs.h b/extmod/vfs.h index 92e53b305..4a1c225a0 100644 --- a/extmod/vfs.h +++ b/extmod/vfs.h @@ -35,6 +35,13 @@ #define MP_VFS_NONE ((mp_vfs_mount_t*)1) #define MP_VFS_ROOT ((mp_vfs_mount_t*)0) +// constants for block protocol ioctl +#define BP_IOCTL_INIT (1) +#define BP_IOCTL_DEINIT (2) +#define BP_IOCTL_SYNC (3) +#define BP_IOCTL_SEC_COUNT (4) +#define BP_IOCTL_SEC_SIZE (5) + typedef struct _mp_vfs_mount_t { const char *str; // mount point with leading / size_t len; diff --git a/extmod/vfs_fat.c b/extmod/vfs_fat.c index ecbbdb59a..b32bf7ad9 100644 --- a/extmod/vfs_fat.c +++ b/extmod/vfs_fat.c @@ -38,7 +38,6 @@ #include "py/mperrno.h" #include "lib/oofatfs/ff.h" #include "extmod/vfs_fat.h" -#include "extmod/fsusermount.h" #include "timeutils.h" #if _MAX_SS == _MIN_SS diff --git a/extmod/vfs_fat.h b/extmod/vfs_fat.h index bc5be0c67..fefae776c 100644 --- a/extmod/vfs_fat.h +++ b/extmod/vfs_fat.h @@ -25,8 +25,32 @@ */ #include "py/lexer.h" +#include "py/obj.h" +#include "lib/oofatfs/ff.h" +#include "extmod/vfs.h" -struct _fs_user_mount_t; +// these are the values for fs_user_mount_t.flags +#define FSUSER_NATIVE (0x0001) // readblocks[2]/writeblocks[2] contain native func +#define FSUSER_FREE_OBJ (0x0002) // fs_user_mount_t obj should be freed on umount +#define FSUSER_HAVE_IOCTL (0x0004) // new protocol with ioctl + +typedef struct _fs_user_mount_t { + mp_obj_base_t base; + const char *str; + uint16_t len; // length of str + uint16_t flags; + mp_obj_t readblocks[4]; + mp_obj_t writeblocks[4]; + // new protocol uses just ioctl, old uses sync (optional) and count + union { + mp_obj_t ioctl[4]; + struct { + mp_obj_t sync[2]; + mp_obj_t count[2]; + } old; + } u; + FATFS fatfs; +} fs_user_mount_t; extern const byte fresult_to_errno_table[20]; extern const mp_obj_type_t mp_fat_vfs_type; diff --git a/extmod/vfs_fat_diskio.c b/extmod/vfs_fat_diskio.c index e12c4597e..7efcc22f2 100644 --- a/extmod/vfs_fat_diskio.c +++ b/extmod/vfs_fat_diskio.c @@ -38,7 +38,7 @@ #include "py/runtime.h" #include "lib/oofatfs/ff.h" #include "lib/oofatfs/diskio.h" -#include "extmod/fsusermount.h" +#include "extmod/vfs_fat.h" #if _MAX_SS == _MIN_SS #define SECSIZE(fs) (_MIN_SS) diff --git a/extmod/vfs_fat_file.c b/extmod/vfs_fat_file.c index bb5903575..0f2a7a1aa 100644 --- a/extmod/vfs_fat_file.c +++ b/extmod/vfs_fat_file.c @@ -35,7 +35,6 @@ #include "py/stream.h" #include "py/mperrno.h" #include "lib/oofatfs/ff.h" -#include "extmod/fsusermount.h" #include "extmod/vfs_fat.h" #if MICROPY_VFS_FAT diff --git a/extmod/vfs_fat_misc.c b/extmod/vfs_fat_misc.c index ba513ef92..97d2675cd 100644 --- a/extmod/vfs_fat_misc.c +++ b/extmod/vfs_fat_misc.c @@ -32,7 +32,6 @@ #include "py/runtime.h" #include "lib/oofatfs/ff.h" #include "extmod/vfs_fat.h" -#include "extmod/fsusermount.h" #include "py/lexer.h" // TODO: actually, the core function should be ilistdir() diff --git a/stmhal/main.c b/stmhal/main.c index 9eab50061..3a0bd7a6b 100644 --- a/stmhal/main.c +++ b/stmhal/main.c @@ -39,7 +39,7 @@ #include "lib/utils/pyexec.h" #include "lib/oofatfs/ff.h" #include "extmod/vfs.h" -#include "extmod/fsusermount.h" +#include "extmod/vfs_fat.h" #include "systick.h" #include "pendsv.h" diff --git a/stmhal/modmachine.c b/stmhal/modmachine.c index aec8e29c5..b10bca819 100644 --- a/stmhal/modmachine.c +++ b/stmhal/modmachine.c @@ -37,7 +37,7 @@ #include "lib/utils/pyexec.h" #include "lib/oofatfs/ff.h" #include "extmod/vfs.h" -#include "extmod/fsusermount.h" +#include "extmod/vfs_fat.h" #include "gccollect.h" #include "irq.h" #include "rng.h" diff --git a/stmhal/sdcard.c b/stmhal/sdcard.c index 52ede492b..b1d67f62a 100644 --- a/stmhal/sdcard.c +++ b/stmhal/sdcard.c @@ -30,7 +30,6 @@ #include "py/runtime.h" #include "lib/oofatfs/ff.h" #include "extmod/vfs_fat.h" -#include "extmod/fsusermount.h" #include "mphalport.h" #include "sdcard.h" diff --git a/stmhal/storage.c b/stmhal/storage.c index 6130d6fb8..c1daad4c2 100644 --- a/stmhal/storage.c +++ b/stmhal/storage.c @@ -31,7 +31,6 @@ #include "py/runtime.h" #include "lib/oofatfs/ff.h" #include "extmod/vfs_fat.h" -#include "extmod/fsusermount.h" #include "systick.h" #include "led.h" -- cgit v1.2.3 From 0fb27888fc805e4b39f74153d8543fe7348eb886 Mon Sep 17 00:00:00 2001 From: Damien George Date: Sun, 29 Jan 2017 19:50:32 +1100 Subject: extmod/vfs_fat: Remove unused function fat_vfs_listdir. --- extmod/vfs_fat.h | 1 - extmod/vfs_fat_misc.c | 4 ---- 2 files changed, 5 deletions(-) (limited to 'extmod/vfs_fat_misc.c') diff --git a/extmod/vfs_fat.h b/extmod/vfs_fat.h index 0eb963d16..a5e3c604b 100644 --- a/extmod/vfs_fat.h +++ b/extmod/vfs_fat.h @@ -59,5 +59,4 @@ mp_import_stat_t fat_vfs_import_stat(struct _fs_user_mount_t *vfs, const char *p 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); -mp_obj_t fat_vfs_listdir(const char *path, bool is_str_type); mp_obj_t fat_vfs_listdir2(struct _fs_user_mount_t *vfs, const char *path, bool is_str_type); diff --git a/extmod/vfs_fat_misc.c b/extmod/vfs_fat_misc.c index 97d2675cd..19db99c7f 100644 --- a/extmod/vfs_fat_misc.c +++ b/extmod/vfs_fat_misc.c @@ -36,10 +36,6 @@ // TODO: actually, the core function should be ilistdir() -mp_obj_t fat_vfs_listdir(const char *path, bool is_str_type) { - return fat_vfs_listdir2(NULL, path, is_str_type); -} - mp_obj_t fat_vfs_listdir2(fs_user_mount_t *vfs, const char *path, bool is_str_type) { FRESULT res; FILINFO fno; -- cgit v1.2.3 From d4cd4831b01ff87b4a9f84bb88b165e3b156b3b4 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 5 May 2017 23:32:44 +1000 Subject: extmod/vfs_fat: Replace listdir() with implementation of ilistdir(). VfsFat no longer has the listdir() method. Rather, if listdir() functionality is needed then one should use uos.listdir() which will call VfsFat.ilistdir(). --- extmod/vfs_fat.c | 8 +++--- extmod/vfs_fat.h | 2 +- extmod/vfs_fat_misc.c | 73 ++++++++++++++++++++++++++++++--------------------- 3 files changed, 48 insertions(+), 35 deletions(-) (limited to 'extmod/vfs_fat_misc.c') diff --git a/extmod/vfs_fat.c b/extmod/vfs_fat.c index dee4f9298..41c32c6b6 100644 --- a/extmod/vfs_fat.c +++ b/extmod/vfs_fat.c @@ -91,7 +91,7 @@ STATIC MP_DEFINE_CONST_STATICMETHOD_OBJ(fat_vfs_mkfs_obj, MP_ROM_PTR(&fat_vfs_mk STATIC MP_DEFINE_CONST_FUN_OBJ_3(fat_vfs_open_obj, fatfs_builtin_open_self); -STATIC mp_obj_t fat_vfs_listdir_func(size_t n_args, const mp_obj_t *args) { +STATIC mp_obj_t fat_vfs_ilistdir_func(size_t n_args, const mp_obj_t *args) { mp_obj_fat_vfs_t *self = MP_OBJ_TO_PTR(args[0]); bool is_str_type = true; const char *path; @@ -104,9 +104,9 @@ STATIC mp_obj_t fat_vfs_listdir_func(size_t n_args, const mp_obj_t *args) { path = ""; } - return fat_vfs_listdir2(self, path, is_str_type); + return fat_vfs_ilistdir2(self, path, is_str_type); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(fat_vfs_listdir_obj, 1, 2, fat_vfs_listdir_func); +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(fat_vfs_ilistdir_obj, 1, 2, fat_vfs_ilistdir_func); STATIC mp_obj_t fat_vfs_remove_internal(mp_obj_t vfs_in, mp_obj_t path_in, mp_int_t attr) { mp_obj_fat_vfs_t *self = MP_OBJ_TO_PTR(vfs_in); @@ -321,7 +321,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(fat_vfs_umount_obj, vfs_fat_umount); STATIC const mp_rom_map_elem_t fat_vfs_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_mkfs), MP_ROM_PTR(&fat_vfs_mkfs_obj) }, { MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&fat_vfs_open_obj) }, - { MP_ROM_QSTR(MP_QSTR_listdir), MP_ROM_PTR(&fat_vfs_listdir_obj) }, + { MP_ROM_QSTR(MP_QSTR_ilistdir), MP_ROM_PTR(&fat_vfs_ilistdir_obj) }, { MP_ROM_QSTR(MP_QSTR_mkdir), MP_ROM_PTR(&fat_vfs_mkdir_obj) }, { MP_ROM_QSTR(MP_QSTR_rmdir), MP_ROM_PTR(&fat_vfs_rmdir_obj) }, { MP_ROM_QSTR(MP_QSTR_chdir), MP_ROM_PTR(&fat_vfs_chdir_obj) }, diff --git a/extmod/vfs_fat.h b/extmod/vfs_fat.h index 7eb865254..6c7c05a9a 100644 --- a/extmod/vfs_fat.h +++ b/extmod/vfs_fat.h @@ -57,4 +57,4 @@ mp_import_stat_t fat_vfs_import_stat(struct _fs_user_mount_t *vfs, const char *p 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); -mp_obj_t fat_vfs_listdir2(struct _fs_user_mount_t *vfs, const char *path, bool is_str_type); +mp_obj_t fat_vfs_ilistdir2(struct _fs_user_mount_t *vfs, const char *path, bool is_str_type); diff --git a/extmod/vfs_fat_misc.c b/extmod/vfs_fat_misc.c index 19db99c7f..5b906189f 100644 --- a/extmod/vfs_fat_misc.c +++ b/extmod/vfs_fat_misc.c @@ -34,51 +34,64 @@ #include "extmod/vfs_fat.h" #include "py/lexer.h" -// TODO: actually, the core function should be ilistdir() - -mp_obj_t fat_vfs_listdir2(fs_user_mount_t *vfs, const char *path, bool is_str_type) { - FRESULT res; - FILINFO fno; +typedef struct _mp_vfs_fat_ilistdir_it_t { + mp_obj_base_t base; + mp_fun_1_t iternext; + bool is_str; FF_DIR dir; +} mp_vfs_fat_ilistdir_it_t; - res = f_opendir(&vfs->fatfs, &dir, path); - if (res != FR_OK) { - mp_raise_OSError(fresult_to_errno_table[res]); - } - - mp_obj_t dir_list = mp_obj_new_list(0, NULL); +STATIC mp_obj_t mp_vfs_fat_ilistdir_it_iternext(mp_obj_t self_in) { + mp_vfs_fat_ilistdir_it_t *self = MP_OBJ_TO_PTR(self_in); for (;;) { - res = f_readdir(&dir, &fno); /* Read a directory item */ - if (res != FR_OK || fno.fname[0] == 0) break; /* Break on error or end of dir */ - if (fno.fname[0] == '.' && fno.fname[1] == 0) continue; /* Ignore . entry */ - if (fno.fname[0] == '.' && fno.fname[1] == '.' && fno.fname[2] == 0) continue; /* Ignore .. entry */ - + FILINFO fno; + FRESULT res = f_readdir(&self->dir, &fno); char *fn = fno.fname; + if (res != FR_OK || fn[0] == 0) { + // stop on error or end of dir + break; + } + if (fn[0] == '.' && (fn[1] == 0 || (fn[1] == '.' && fn[2] == 0))) { + // skip . and .. + continue; + } - /* + // make 3-tuple with info about this entry + mp_obj_tuple_t *t = MP_OBJ_TO_PTR(mp_obj_new_tuple(3, NULL)); + if (self->is_str) { + t->items[0] = mp_obj_new_str(fn, strlen(fn), false); + } else { + t->items[0] = mp_obj_new_bytes((const byte*)fn, strlen(fn)); + } if (fno.fattrib & AM_DIR) { // dir + t->items[1] = MP_OBJ_NEW_SMALL_INT(MP_S_IFDIR); } else { // file + t->items[1] = MP_OBJ_NEW_SMALL_INT(MP_S_IFREG); } - */ + t->items[2] = MP_OBJ_NEW_SMALL_INT(0); // no inode number - // make a string object for this entry - mp_obj_t entry_o; - if (is_str_type) { - entry_o = mp_obj_new_str(fn, strlen(fn), false); - } else { - entry_o = mp_obj_new_bytes((const byte*)fn, strlen(fn)); - } - - // add the entry to the list - mp_obj_list_append(dir_list, entry_o); + return MP_OBJ_FROM_PTR(t); } - f_closedir(&dir); + // ignore error because we may be closing a second time + f_closedir(&self->dir); - return dir_list; + return MP_OBJ_STOP_ITERATION; +} + +mp_obj_t fat_vfs_ilistdir2(fs_user_mount_t *vfs, const char *path, bool is_str_type) { + mp_vfs_fat_ilistdir_it_t *iter = m_new_obj(mp_vfs_fat_ilistdir_it_t); + iter->base.type = &mp_type_polymorph_iter; + iter->iternext = mp_vfs_fat_ilistdir_it_iternext; + iter->is_str = is_str_type; + FRESULT res = f_opendir(&vfs->fatfs, &iter->dir, path); + if (res != FR_OK) { + mp_raise_OSError(fresult_to_errno_table[res]); + } + return MP_OBJ_FROM_PTR(iter); } mp_import_stat_t fat_vfs_import_stat(fs_user_mount_t *vfs, const char *path) { -- cgit v1.2.3 From f95e4e77823919dfe82b6711f1d25d2d8c5008fc Mon Sep 17 00:00:00 2001 From: Damien George Date: Sat, 13 May 2017 18:58:46 +1000 Subject: extmod/vfs_fat_misc: Remove dot-dirs filter since FatFS already does it. --- extmod/vfs_fat_misc.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'extmod/vfs_fat_misc.c') diff --git a/extmod/vfs_fat_misc.c b/extmod/vfs_fat_misc.c index 5b906189f..7c16db7e5 100644 --- a/extmod/vfs_fat_misc.c +++ b/extmod/vfs_fat_misc.c @@ -52,10 +52,8 @@ STATIC mp_obj_t mp_vfs_fat_ilistdir_it_iternext(mp_obj_t self_in) { // stop on error or end of dir break; } - if (fn[0] == '.' && (fn[1] == 0 || (fn[1] == '.' && fn[2] == 0))) { - // skip . and .. - continue; - } + + // Note that FatFS already filters . and .., so we don't need to // make 3-tuple with info about this entry mp_obj_tuple_t *t = MP_OBJ_TO_PTR(mp_obj_new_tuple(3, NULL)); -- cgit v1.2.3