summaryrefslogtreecommitdiff
path: root/extmod
diff options
context:
space:
mode:
Diffstat (limited to 'extmod')
-rw-r--r--extmod/fsusermount.c11
-rw-r--r--extmod/fsusermount.h11
2 files changed, 18 insertions, 4 deletions
diff --git a/extmod/fsusermount.c b/extmod/fsusermount.c
index 74525ef74..441711ae2 100644
--- a/extmod/fsusermount.c
+++ b/extmod/fsusermount.c
@@ -76,8 +76,15 @@ STATIC mp_obj_t fatfs_mount_mkfs(mp_uint_t n_args, const mp_obj_t *pos_args, mp_
// 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_sync, vfs->sync);
- mp_load_method(device, MP_QSTR_count, vfs->count);
+ 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->u.old.count[1] = MP_OBJ_SENTINEL;
+ } 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:
diff --git a/extmod/fsusermount.h b/extmod/fsusermount.h
index c141ecb99..53442a368 100644
--- a/extmod/fsusermount.h
+++ b/extmod/fsusermount.h
@@ -29,8 +29,15 @@ typedef struct _fs_user_mount_t {
mp_uint_t len;
mp_obj_t readblocks[4];
mp_obj_t writeblocks[4];
- mp_obj_t sync[2];
- mp_obj_t count[2];
+ // new protocol uses just ioctl, old uses sync (optional) and count
+ // if ioctl[3]=count[1]=MP_OBJ_SENTINEL then we have the new protocol, else old
+ 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;