fat_fs: Add support for variable sector size

Add support for variable sector sizes by exposing _MAX_SS as
CONFIG_FS_FATFS_MAX_SS to Kconfig and adding the GET_SECTOR_SIZE IOCTL.

Signed-off-by: Markus Fuchs <markus.fuchs@de.sauter-bc.com>
This commit is contained in:
Markus Fuchs 2020-10-12 09:54:34 +02:00 committed by Kumar Gala
parent 1d1fcc725a
commit 237778d3f1
3 changed files with 22 additions and 2 deletions

1
README
View File

@ -23,3 +23,4 @@ _CODE_PAGE as CONFIG_FS_FATFS_CODEPAGE
_FS_READONLY as CONFIG_FS_FATFS_READ_ONLY
_USE_MKFS as CONFIG_FS_FATFS_MKFS
_VOLUMES as CONFIG_FS_FATFS_VOLUMES
_MAX_SS as CONFIG_FS_FATFS_MAX_SS

View File

@ -201,7 +201,11 @@
#define _MIN_SS 512
#if defined(CONFIG_FS_FATFS_MAX_SS)
#define _MAX_SS CONFIG_FS_FATFS_MAX_SS
#else
#define _MAX_SS 512
#endif /* defined(CONFIG_FS_FATFS_MAX_SS) */
/* 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

View File

@ -97,7 +97,8 @@ DRESULT disk_write(BYTE pdrv, const BYTE *buff, DWORD sector, UINT count)
DRESULT disk_ioctl(BYTE pdrv, BYTE cmd, void *buff)
{
int ret = RES_OK;
int ret = RES_OK;
uint32_t sector_size = 0;
__ASSERT(pdrv < ARRAY_SIZE(pdrv_str), "pdrv out-of-range\n");
@ -113,7 +114,21 @@ DRESULT disk_ioctl(BYTE pdrv, BYTE cmd, void *buff)
if (disk_access_ioctl(pdrv_str[pdrv],
DISK_IOCTL_GET_SECTOR_COUNT, buff) != 0) {
ret = RES_ERROR;
}
}
break;
case GET_SECTOR_SIZE:
/* Zephyr's DISK_IOCTL_GET_SECTOR_SIZE returns sector size as a
* 32-bit number while FatFS's GET_SECTOR_SIZE is supposed to
* return a 16-bit number.
*/
if ((disk_access_ioctl(pdrv_str[pdrv],
DISK_IOCTL_GET_SECTOR_SIZE, &sector_size) == 0) &&
(sector_size == (uint16_t)sector_size)) {
*(uint16_t *)buff = (uint16_t)sector_size;
} else {
ret = RES_ERROR;
}
break;
case GET_BLOCK_SIZE: