diff options
Diffstat (limited to 'extmod/vfs_fat_file.c')
-rw-r--r-- | extmod/vfs_fat_file.c | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/extmod/vfs_fat_file.c b/extmod/vfs_fat_file.c index 77848b5a5..edffa37c7 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_FSUSERMOUNT || MICROPY_FSUSERMOUNT_ADHOC +#if MICROPY_VFS && MICROPY_VFS_FAT #include <stdio.h> #include <errno.h> @@ -36,13 +34,11 @@ #include "py/runtime.h" #include "py/stream.h" #include "py/mperrno.h" -#include "lib/fatfs/ff.h" -#include "extmod/vfs_fat_file.h" +#include "lib/oofatfs/ff.h" +#include "extmod/vfs_fat.h" -#if MICROPY_VFS_FAT #define mp_type_fileio fatfs_type_fileio #define mp_type_textio fatfs_type_textio -#endif extern const mp_obj_type_t mp_type_fileio; extern const mp_obj_type_t mp_type_textio; @@ -112,7 +108,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 (self->fp.fs != NULL) { + if (self->fp.obj.fs != NULL) { FRESULT res = f_close(&self->fp); if (res != FR_OK) { mp_raise_OSError(fresult_to_errno_table[res]); @@ -178,7 +174,7 @@ STATIC const mp_arg_t file_open_args[] = { }; #define FILE_OPEN_NUM_ARGS MP_ARRAY_SIZE(file_open_args) -STATIC mp_obj_t file_open(const mp_obj_type_t *type, mp_arg_val_t *args) { +STATIC mp_obj_t file_open(fs_user_mount_t *vfs, const mp_obj_type_t *type, mp_arg_val_t *args) { int mode = 0; const char *mode_s = mp_obj_str_get_str(args[1].u_obj); // TODO make sure only one of r, w, x, a, and b, t are specified @@ -214,7 +210,8 @@ STATIC mp_obj_t file_open(const mp_obj_type_t *type, mp_arg_val_t *args) { o->base.type = type; const char *fname = mp_obj_str_get_str(args[0].u_obj); - FRESULT res = f_open(&o->fp, fname, mode); + assert(vfs != NULL); + FRESULT res = f_open(&vfs->fatfs, &o->fp, fname, mode); if (res != FR_OK) { m_del_obj(pyb_file_obj_t, o); mp_raise_OSError(fresult_to_errno_table[res]); @@ -231,7 +228,7 @@ STATIC mp_obj_t file_open(const mp_obj_type_t *type, mp_arg_val_t *args) { STATIC mp_obj_t file_obj_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_val_t arg_vals[FILE_OPEN_NUM_ARGS]; mp_arg_parse_all_kw_array(n_args, n_kw, args, FILE_OPEN_NUM_ARGS, file_open_args, arg_vals); - return file_open(type, arg_vals); + return file_open(NULL, type, arg_vals); } // TODO gc hook to close the file if not already closed @@ -265,7 +262,7 @@ const mp_obj_type_t mp_type_fileio = { .name = MP_QSTR_FileIO, .print = file_obj_print, .make_new = file_obj_make_new, - .getiter = mp_identity, + .getiter = mp_identity_getiter, .iternext = mp_stream_unbuffered_iter, .protocol = &fileio_stream_p, .locals_dict = (mp_obj_dict_t*)&rawfile_locals_dict, @@ -284,18 +281,21 @@ const mp_obj_type_t mp_type_textio = { .name = MP_QSTR_TextIOWrapper, .print = file_obj_print, .make_new = file_obj_make_new, - .getiter = mp_identity, + .getiter = mp_identity_getiter, .iternext = mp_stream_unbuffered_iter, .protocol = &textio_stream_p, .locals_dict = (mp_obj_dict_t*)&rawfile_locals_dict, }; // Factory function for I/O stream classes -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) { // TODO: analyze buffering args and instantiate appropriate type + fs_user_mount_t *self = MP_OBJ_TO_PTR(self_in); mp_arg_val_t arg_vals[FILE_OPEN_NUM_ARGS]; - mp_arg_parse_all(n_args, args, kwargs, FILE_OPEN_NUM_ARGS, file_open_args, arg_vals); - return file_open(&mp_type_textio, arg_vals); + 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); } -#endif // MICROPY_FSUSERMOUNT +#endif // MICROPY_VFS && MICROPY_VFS_FAT |