Skip to content

Commit 651a188

Browse files
committed
extmod/vfs_fat_diskio: Actually support sectors != 512 with Python blockdevs.
1 parent 13394a6 commit 651a188

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

extmod/vfs_fat_diskio.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@
4040
#include "lib/fatfs/diskio.h" /* FatFs lower layer API */
4141
#include "extmod/fsusermount.h"
4242

43+
#if _MAX_SS == _MIN_SS
44+
#define SECSIZE(fs) (_MIN_SS)
45+
#else
46+
#define SECSIZE(fs) ((fs)->ssize)
47+
#endif
48+
4349
STATIC fs_user_mount_t *disk_get_device(uint id) {
4450
if (id < MP_ARRAY_SIZE(MP_STATE_PORT(fs_user_mount))) {
4551
return MP_STATE_PORT(fs_user_mount)[id];
@@ -122,7 +128,7 @@ DRESULT disk_read (
122128
}
123129
} else {
124130
vfs->readblocks[2] = MP_OBJ_NEW_SMALL_INT(sector);
125-
vfs->readblocks[3] = mp_obj_new_bytearray_by_ref(count * 512, buff);
131+
vfs->readblocks[3] = mp_obj_new_bytearray_by_ref(count * SECSIZE(&vfs->fatfs), buff);
126132
mp_call_method_n_kw(2, 0, vfs->readblocks);
127133
// TODO handle error return
128134
}
@@ -159,7 +165,7 @@ DRESULT disk_write (
159165
}
160166
} else {
161167
vfs->writeblocks[2] = MP_OBJ_NEW_SMALL_INT(sector);
162-
vfs->writeblocks[3] = mp_obj_new_bytearray_by_ref(count * 512, (void*)buff);
168+
vfs->writeblocks[3] = mp_obj_new_bytearray_by_ref(count * SECSIZE(&vfs->fatfs), (void*)buff);
163169
mp_call_method_n_kw(2, 0, vfs->writeblocks);
164170
// TODO handle error return
165171
}

0 commit comments

Comments
 (0)