lib/fatfs: Add support for sector sizes larger than 512 bytes.
If MICROPY_FATFS_MAX_SS is defined to power of 2 value between 1024 and 4096, support for dynamic sector size in FatFs will be enabled. Note that FatFs reserves static buffer of MICROPY_FATFS_MAX_SS size for each filesystem in use, so that value should be set sparingly. Initial patch provided by @pfalcon.
This commit is contained in:
parent
c33ad60a67
commit
13a4c120ce
@ -217,7 +217,11 @@
|
||||
|
||||
|
||||
#define _MIN_SS 512
|
||||
#ifdef MICROPY_FATFS_MAX_SS
|
||||
#define _MAX_SS (MICROPY_FATFS_MAX_SS)
|
||||
#else
|
||||
#define _MAX_SS 512
|
||||
#endif
|
||||
/* These options configure the range of sector size to be supported. (512, 1024,
|
||||
/ 2048 or 4096) Always set both 512 for most systems, all type of memory cards and
|
||||
/ harddisk. But a larger value may be required for on-board flash memory and some
|
||||
|
@ -44,6 +44,7 @@
|
||||
//#define BP_IOCTL_DEINIT (2) // unused
|
||||
#define BP_IOCTL_SYNC (3)
|
||||
#define BP_IOCTL_SEC_COUNT (4)
|
||||
#define BP_IOCTL_SEC_SIZE (5)
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Initialize a Drive */
|
||||
@ -273,6 +274,15 @@ DRESULT disk_ioctl (
|
||||
return RES_OK;
|
||||
}
|
||||
|
||||
case GET_SECTOR_SIZE: {
|
||||
vfs->u.ioctl[2] = MP_OBJ_NEW_SMALL_INT(BP_IOCTL_SEC_SIZE);
|
||||
vfs->u.ioctl[3] = MP_OBJ_NEW_SMALL_INT(0); // unused
|
||||
mp_obj_t ret = mp_call_method_n_kw(2, 0, vfs->u.ioctl);
|
||||
*((WORD*)buff) = mp_obj_get_int(ret);
|
||||
vfs->u.ioctl[3] = MP_OBJ_SENTINEL; // indicate new protocol
|
||||
return RES_OK;
|
||||
}
|
||||
|
||||
case GET_BLOCK_SIZE:
|
||||
*((DWORD*)buff) = 1; // erase block size in units of sector size
|
||||
return RES_OK;
|
||||
@ -292,6 +302,10 @@ DRESULT disk_ioctl (
|
||||
return RES_OK;
|
||||
}
|
||||
|
||||
case GET_SECTOR_SIZE:
|
||||
*((WORD*)buff) = 512; // old protocol had fixed sector size
|
||||
return RES_OK;
|
||||
|
||||
case GET_BLOCK_SIZE:
|
||||
*((DWORD*)buff) = 1; // erase block size in units of sector size
|
||||
return RES_OK;
|
||||
|
Loading…
x
Reference in New Issue
Block a user