Skip to content

Commit 237778d

Browse files
mrfuchsgalak
authored andcommitted
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 <[email protected]>
1 parent 1d1fcc7 commit 237778d

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

README

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ _CODE_PAGE as CONFIG_FS_FATFS_CODEPAGE
2323
_FS_READONLY as CONFIG_FS_FATFS_READ_ONLY
2424
_USE_MKFS as CONFIG_FS_FATFS_MKFS
2525
_VOLUMES as CONFIG_FS_FATFS_VOLUMES
26+
_MAX_SS as CONFIG_FS_FATFS_MAX_SS

include/ffconf.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,11 @@
201201

202202

203203
#define _MIN_SS 512
204+
#if defined(CONFIG_FS_FATFS_MAX_SS)
205+
#define _MAX_SS CONFIG_FS_FATFS_MAX_SS
206+
#else
204207
#define _MAX_SS 512
208+
#endif /* defined(CONFIG_FS_FATFS_MAX_SS) */
205209
/* These options configure the range of sector size to be supported. (512, 1024,
206210
/ 2048 or 4096) Always set both 512 for most systems, all type of memory cards and
207211
/ harddisk. But a larger value may be required for on-board flash memory and some

zfs_diskio.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ DRESULT disk_write(BYTE pdrv, const BYTE *buff, DWORD sector, UINT count)
9797

9898
DRESULT disk_ioctl(BYTE pdrv, BYTE cmd, void *buff)
9999
{
100-
int ret = RES_OK;
100+
int ret = RES_OK;
101+
uint32_t sector_size = 0;
101102

102103
__ASSERT(pdrv < ARRAY_SIZE(pdrv_str), "pdrv out-of-range\n");
103104

@@ -113,7 +114,21 @@ DRESULT disk_ioctl(BYTE pdrv, BYTE cmd, void *buff)
113114
if (disk_access_ioctl(pdrv_str[pdrv],
114115
DISK_IOCTL_GET_SECTOR_COUNT, buff) != 0) {
115116
ret = RES_ERROR;
116-
}
117+
}
118+
break;
119+
120+
case GET_SECTOR_SIZE:
121+
/* Zephyr's DISK_IOCTL_GET_SECTOR_SIZE returns sector size as a
122+
* 32-bit number while FatFS's GET_SECTOR_SIZE is supposed to
123+
* return a 16-bit number.
124+
*/
125+
if ((disk_access_ioctl(pdrv_str[pdrv],
126+
DISK_IOCTL_GET_SECTOR_SIZE, &sector_size) == 0) &&
127+
(sector_size == (uint16_t)sector_size)) {
128+
*(uint16_t *)buff = (uint16_t)sector_size;
129+
} else {
130+
ret = RES_ERROR;
131+
}
117132
break;
118133

119134
case GET_BLOCK_SIZE:

0 commit comments

Comments
 (0)