From e09710e3eb04c062d0943e76608c3b50eeef6a1a Mon Sep 17 00:00:00 2001 From: CTCaer Date: Mon, 16 May 2022 13:33:38 +0300 Subject: [PATCH] bdk: fatfs: mkfs alignment changes - Default data alignment is now 1MB **when it's not set** - Default volume alignment is now based on data alignment and not hardcoded to 16MB. - Change max allowed alignment to 64MB. The above changes allow selecting alignments for volume and data between 1MB and 64MB. (From the previous 1 to 16MB for data and 16MB for volume). --- bdk/libs/fatfs/ff.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bdk/libs/fatfs/ff.c b/bdk/libs/fatfs/ff.c index 5ea2eee..b61fa7d 100644 --- a/bdk/libs/fatfs/ff.c +++ b/bdk/libs/fatfs/ff.c @@ -5879,7 +5879,7 @@ FRESULT f_mkfs ( stat = disk_initialize(pdrv); if (stat & STA_NOINIT) return FR_NOT_READY; if (stat & STA_PROTECT) return FR_WRITE_PROTECTED; - if (disk_ioctl(pdrv, GET_BLOCK_SIZE, &sz_blk) != RES_OK || !sz_blk || sz_blk > 32768 || (sz_blk & (sz_blk - 1))) sz_blk = 1; /* Erase block to align data area */ + if (disk_ioctl(pdrv, GET_BLOCK_SIZE, &sz_blk) != RES_OK || !sz_blk || sz_blk > 131072 || (sz_blk & (sz_blk - 1))) sz_blk = 2048; /* Erase block to align data area. 1MB minimum */ #if FF_MAX_SS != FF_MIN_SS /* Get sector size of the medium if variable sector size cfg. */ if (disk_ioctl(pdrv, GET_SECTOR_SIZE, &ss) != RES_OK) return FR_DISK_ERR; if (ss > FF_MAX_SS || ss < FF_MIN_SS || (ss & (ss - 1))) return FR_DISK_ERR; @@ -5915,7 +5915,7 @@ FRESULT f_mkfs ( } else { /* Create a single-partition in this function */ if (disk_ioctl(pdrv, GET_SECTOR_COUNT, &sz_vol) != RES_OK) LEAVE_MKFS(FR_DISK_ERR); - b_vol = (opt & FM_SFD) ? 0 : 32768; /* Volume start sector. Align to 16MB */ + b_vol = (opt & FM_SFD) ? 0 : sz_blk; /* Volume start sector */ if (sz_vol < b_vol) LEAVE_MKFS(FR_MKFS_ABORTED); sz_vol -= b_vol; /* Volume size */ }