Skip to content

Shrink root dir size for tiny (<=128K) FAT12 fs #8567

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/oofatfs/ff.c
Original file line number Diff line number Diff line change
Expand Up @@ -5422,7 +5422,8 @@ FRESULT f_mkfs (
)
{
const UINT n_fats = 1; /* Number of FATs for FAT/FAT32 volume (1 or 2) */
const UINT n_rootdir = 512; /* Number of root directory entries for FAT volume */
// CIRCUITPY-CHANGE: Make number of root directory entries changeable. See below.
UINT n_rootdir = 512; /* Default number of root directory entries for FAT volume */
static const WORD cst[] = {1, 4, 16, 64, 256, 512, 0}; /* Cluster size boundary for FAT volume (4Ks unit) */
#if FF_MKFS_FAT32
static const WORD cst32[] = {1, 2, 4, 8, 16, 32, 0}; /* Cluster size boundary for FAT32 volume (128Ks unit) */
Expand Down Expand Up @@ -5703,6 +5704,11 @@ FRESULT f_mkfs (
}
sz_fat = (n + ss - 1) / ss; /* FAT size [sector] */
sz_rsv = 1; /* Number of reserved sectors */
// CIRCUITPY-CHANGE: For fewer than 256 clusters (128kB filesystem),
// shrink the root directory size from 512 entries to 128 entries. Note that
// long filenames will use two entries. This change affects only the root directory,
// not subdirectories
n_rootdir = (sz_vol <= 256) ? 128 : n_rootdir;
sz_dir = (DWORD)n_rootdir * SZDIRE / ss; /* Rootdir size [sector] */
}
b_fat = b_vol + sz_rsv; /* FAT base */
Expand Down
2 changes: 1 addition & 1 deletion tests/extmod/vfs_blockdev.py.exp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
test <class 'VfsFat'>
(512, 512, 16, 16, 16, 0, 0, 0, 0, 255)
(512, 512, 40, 40, 40, 0, 0, 0, 0, 255)
[('test', 32768, 0, 90)]
some datasome datasome datasome datasome datasome datasome datasome datasome datasome data
test <class 'VfsLfs2'>
Expand Down
2 changes: 1 addition & 1 deletion tests/extmod/vfs_fat_ramdisk.py.exp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
True
True
label: LABEL TEST
statvfs: (512, 512, 16, 16, 16, 0, 0, 0, 0, 255)
statvfs: (512, 512, 40, 40, 40, 0, 0, 0, 0, 255)
getcwd: /
True
[('foo_file.txt', 32768, 0, 6)]
Expand Down