Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cc3200/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@
X(ETIMEDOUT) \

// TODO these should be generic, not bound to fatfs
#define mp_type_fileio fatfs_type_fileio
#define mp_type_textio fatfs_type_textio
#define mp_type_fileio mp_vfs_fat_fileio_type
#define mp_type_textio mp_vfs_fat_textio_type

// use vfs's functions for import stat and builtin open
#define mp_import_stat mp_vfs_import_stat
Expand Down
4 changes: 2 additions & 2 deletions esp8266/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ typedef uint32_t sys_prot_t; // for modlwip
void *esp_native_code_commit(void*, size_t);
#define MP_PLAT_COMMIT_EXEC(buf, len) esp_native_code_commit(buf, len)

#define mp_type_fileio fatfs_type_fileio
#define mp_type_textio fatfs_type_textio
#define mp_type_fileio mp_vfs_fat_fileio_type
#define mp_type_textio mp_vfs_fat_textio_type

// use vfs's functions for import stat and builtin open
#define mp_import_stat mp_vfs_import_stat
Expand Down
1 change: 0 additions & 1 deletion examples/embedding/Makefile.upylib
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ SRC_C = $(addprefix $(MPTOP)/unix/,\
gccollect.c \
unix_mphal.c \
input.c \
file.c \
modmachine.c \
modos.c \
moduselect.c \
Expand Down
16 changes: 12 additions & 4 deletions extmod/vfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@

#if MICROPY_VFS

#if MICROPY_VFS_POSIX
#include "extmod/vfs_posix.h"
#endif
#if MICROPY_VFS_FAT
#include "extmod/vfs_fat.h"
#endif
Expand Down Expand Up @@ -120,8 +123,13 @@ mp_import_stat_t mp_vfs_import_stat(const char *path) {
if (vfs == MP_VFS_NONE || vfs == MP_VFS_ROOT) {
return MP_IMPORT_STAT_NO_EXIST;
}
#if MICROPY_VFS_FAT
// fast paths for known VFS types
#if MICROPY_VFS_POSIX
if (mp_obj_get_type(vfs->obj) == &mp_vfs_posix_type) {
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);
}
Expand All @@ -133,8 +141,8 @@ mp_import_stat_t mp_vfs_import_stat(const char *path) {
mp_obj_t mp_vfs_mount(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_readonly, ARG_mkfs };
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_readonly, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_false} },
{ MP_QSTR_mkfs, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_false} },
{ MP_QSTR_readonly, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_PTR(&mp_const_false_obj)} },
{ MP_QSTR_mkfs, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_PTR(&mp_const_false_obj)} },
};

// parse args
Expand Down Expand Up @@ -242,7 +250,7 @@ mp_obj_t mp_vfs_open(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args)
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);

mp_vfs_mount_t *vfs = lookup_path((mp_obj_t)args[ARG_file].u_rom_obj, &args[ARG_file].u_obj);
mp_vfs_mount_t *vfs = lookup_path(args[ARG_file].u_obj, &args[ARG_file].u_obj);
return mp_vfs_proxy_call(vfs, MP_QSTR_open, 2, (mp_obj_t*)&args);
}
MP_DEFINE_CONST_FUN_OBJ_KW(mp_vfs_open_obj, 0, mp_vfs_open);
Expand Down
2 changes: 2 additions & 0 deletions extmod/vfs_fat.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ typedef struct _fs_user_mount_t {

extern const byte fresult_to_errno_table[20];
extern const mp_obj_type_t mp_fat_vfs_type;
extern const mp_obj_type_t mp_vfs_fat_fileio_type;
extern const mp_obj_type_t mp_vfs_fat_textio_type;

mp_import_stat_t fat_vfs_import_stat(struct _fs_user_mount_t *vfs, const char *path);
mp_obj_t fatfs_builtin_open_self(mp_obj_t self_in, mp_obj_t path, mp_obj_t mode);
Expand Down
16 changes: 5 additions & 11 deletions extmod/vfs_fat_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@
#include "lib/oofatfs/ff.h"
#include "extmod/vfs_fat.h"

#define mp_type_fileio fatfs_type_fileio
#define mp_type_textio fatfs_type_textio

extern const mp_obj_type_t mp_type_fileio;
extern const mp_obj_type_t mp_type_textio;

// this table converts from FRESULT to POSIX errno
const byte fresult_to_errno_table[20] = {
[FR_OK] = 0,
Expand Down Expand Up @@ -197,11 +191,11 @@ STATIC mp_obj_t file_open(fs_user_mount_t *vfs, const mp_obj_type_t *type, mp_ar
break;
#if MICROPY_PY_IO_FILEIO
case 'b':
type = &mp_type_fileio;
type = &mp_vfs_fat_fileio_type;
break;
#endif
case 't':
type = &mp_type_textio;
type = &mp_vfs_fat_textio_type;
break;
}
}
Expand Down Expand Up @@ -257,7 +251,7 @@ STATIC const mp_stream_p_t fileio_stream_p = {
.ioctl = file_obj_ioctl,
};

const mp_obj_type_t mp_type_fileio = {
const mp_obj_type_t mp_vfs_fat_fileio_type = {
{ &mp_type_type },
.name = MP_QSTR_FileIO,
.print = file_obj_print,
Expand All @@ -276,7 +270,7 @@ STATIC const mp_stream_p_t textio_stream_p = {
.is_text = true,
};

const mp_obj_type_t mp_type_textio = {
const mp_obj_type_t mp_vfs_fat_textio_type = {
{ &mp_type_type },
.name = MP_QSTR_TextIOWrapper,
.print = file_obj_print,
Expand All @@ -295,7 +289,7 @@ mp_obj_t fatfs_builtin_open_self(mp_obj_t self_in, mp_obj_t path, mp_obj_t mode)
arg_vals[0].u_obj = path;
arg_vals[1].u_obj = mode;
arg_vals[2].u_obj = mp_const_none;
return file_open(self, &mp_type_textio, arg_vals);
return file_open(self, &mp_vfs_fat_textio_type, arg_vals);
}

#endif // MICROPY_VFS && MICROPY_VFS_FAT
Loading