Skip to content

Commit ce6a5e3

Browse files
authored
Merge pull request #8567 from eightycc/tinyfs2
Shrink root dir size for tiny (<=128K) FAT12 fs
2 parents 25525f0 + a4c4c16 commit ce6a5e3

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

lib/oofatfs/ff.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5422,7 +5422,8 @@ FRESULT f_mkfs (
54225422
)
54235423
{
54245424
const UINT n_fats = 1; /* Number of FATs for FAT/FAT32 volume (1 or 2) */
5425-
const UINT n_rootdir = 512; /* Number of root directory entries for FAT volume */
5425+
// CIRCUITPY-CHANGE: Make number of root directory entries changeable. See below.
5426+
UINT n_rootdir = 512; /* Default number of root directory entries for FAT volume */
54265427
static const WORD cst[] = {1, 4, 16, 64, 256, 512, 0}; /* Cluster size boundary for FAT volume (4Ks unit) */
54275428
#if FF_MKFS_FAT32
54285429
static const WORD cst32[] = {1, 2, 4, 8, 16, 32, 0}; /* Cluster size boundary for FAT32 volume (128Ks unit) */
@@ -5703,6 +5704,11 @@ FRESULT f_mkfs (
57035704
}
57045705
sz_fat = (n + ss - 1) / ss; /* FAT size [sector] */
57055706
sz_rsv = 1; /* Number of reserved sectors */
5707+
// CIRCUITPY-CHANGE: For fewer than 256 clusters (128kB filesystem),
5708+
// shrink the root directory size from 512 entries to 128 entries. Note that
5709+
// long filenames will use two entries. This change affects only the root directory,
5710+
// not subdirectories
5711+
n_rootdir = (sz_vol <= 256) ? 128 : n_rootdir;
57065712
sz_dir = (DWORD)n_rootdir * SZDIRE / ss; /* Rootdir size [sector] */
57075713
}
57085714
b_fat = b_vol + sz_rsv; /* FAT base */

tests/extmod/vfs_blockdev.py.exp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
test <class 'VfsFat'>
2-
(512, 512, 16, 16, 16, 0, 0, 0, 0, 255)
2+
(512, 512, 40, 40, 40, 0, 0, 0, 0, 255)
33
[('test', 32768, 0, 90)]
44
some datasome datasome datasome datasome datasome datasome datasome datasome datasome data
55
test <class 'VfsLfs2'>

tests/extmod/vfs_fat_ramdisk.py.exp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
True
22
True
33
label: LABEL TEST
4-
statvfs: (512, 512, 16, 16, 16, 0, 0, 0, 0, 255)
4+
statvfs: (512, 512, 40, 40, 40, 0, 0, 0, 0, 255)
55
getcwd: /
66
True
77
[('foo_file.txt', 32768, 0, 6)]

0 commit comments

Comments
 (0)