summaryrefslogtreecommitdiff
path: root/extmod/vfs_fat_file.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2017-01-27 15:13:32 +1100
committerDamien George <damien.p.george@gmail.com>2017-01-27 17:19:06 +1100
commitfb3ae1784e1905709f82aadb7f1c8994682f9759 (patch)
treeaf7621f78dc2747dc4534903eb018c1745548b0d /extmod/vfs_fat_file.c
parentdcb9ea72157f1d9f3b0dc306c2c31cbd647f5ee1 (diff)
extmod/vfs_fat: Rework to support new generic VFS sub-system.
The VfsFat object can now be mounted by the generic VFS sub-system.
Diffstat (limited to 'extmod/vfs_fat_file.c')
-rw-r--r--extmod/vfs_fat_file.c20
1 files changed, 8 insertions, 12 deletions
diff --git a/extmod/vfs_fat_file.c b/extmod/vfs_fat_file.c
index ea332709e..f5a188036 100644
--- a/extmod/vfs_fat_file.c
+++ b/extmod/vfs_fat_file.c
@@ -27,7 +27,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_FSUSERMOUNT || MICROPY_FSUSERMOUNT_ADHOC
#include <stdio.h>
#include <errno.h>
@@ -224,13 +224,7 @@ STATIC mp_obj_t file_open(fs_user_mount_t *vfs, const mp_obj_type_t *type, mp_ar
const char *fname = mp_obj_str_get_str(args[0].u_obj);
#if MICROPY_FATFS_OO
- if (vfs == NULL) {
- vfs = ff_get_vfs(&fname);
- if (vfs == NULL) {
- m_del_obj(pyb_file_obj_t, o);
- mp_raise_OSError(MP_ENOENT);
- }
- }
+ assert(vfs != NULL);
FRESULT res = f_open(&vfs->fatfs, &o->fp, fname, mode);
#else
(void)vfs;
@@ -320,12 +314,14 @@ mp_obj_t fatfs_builtin_open(mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kw
}
// Factory function for I/O stream classes
-mp_obj_t fatfs_builtin_open_self(size_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(args[0]);
+ 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 - 1, args + 1, kwargs, FILE_OPEN_NUM_ARGS, file_open_args, 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_FSUSERMOUNT