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

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

merged 5 commits into from
Nov 10, 2023

Conversation

eightycc
Copy link
Collaborator

@eightycc eightycc commented Nov 7, 2023

Reduce the size of the root directory for a FAT12 filesystem on a tiny (<=128KB) flash device.

When oofatfs creates a filesystem it uses a default root directory size of 512. For most flash devices this is a reasonable choice, but for tiny flash devices this can consume a large portion of the flash. For example, a Trinket M0 has a 64KB filesystem of which 16KB is consumed by the FAT12 root directory.

This pull causes f_mkfs() to automatically reduce the FAT12 root directory from 512 entries to 64 entries when it detects a device <= 128KB. For the Trinket M0 case, the root directory flash size usage is reduced from 16KB to 2KB.

This pull will reduce the number of files and sub-directories that can be placed in the root directory from 256 to 32. Files and sub-directories usually take 2 entries due to LFN (Long File Name) support. The number of files and sub-directories that can be stored in sub-directories are not limited by this change due to FAT12 allocating them dynamically from the filesystem's data space.

This pull will not affect an existing filesystem. Only when the device is reformatted will the root directory size be reduced.

For background, Linux's mkfs.msdos has a command line option that sets the root directory size.

This pull has been tested on Linux (Ubuntu 22.04), Windows 10, and MacOS Big Sur (11.7.8).

@dhalbert dhalbert requested a review from tannewt November 7, 2023 19:59
@dhalbert
Copy link
Collaborator

dhalbert commented Nov 7, 2023

How much space is saved if the limit is 64 entries rather than 32? I guess it uses 4kB for the root, so leaving 60kB, which I think would still be fine. @ladyada was concerned that 32 files (or 16 files if long files names) is really too low.

@dhalbert dhalbert removed the request for review from tannewt November 7, 2023 20:04
@eightycc
Copy link
Collaborator Author

eightycc commented Nov 7, 2023

It takes two entries per file or sub-directory, so I set it to 64 entries in the pull giving 32 files or sub-directories in the root directory. Each entry is 32 bytes, so every additional 16 entries takes another 512 byte sector.

As the pull is, root directory capacity is 32 long name files or sub-directories. I upped it to 64 entries because I had second thoughts, too.

I probably shouldn't overthink this, but modifying oofatfs/ff.c doesn't leave me completely comfortable. It's fragile code, so any changes are a risk. Also, changes complicate incorporating upstream fixes at a future date. On the other hand, this isn't the first CircuitPython mod to oofatfs.

Copy link
Collaborator

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I've annotated the changes more, and also increased the number of entries to 128, since we have use cases for more files in the root directory.

@dhalbert
Copy link
Collaborator

dhalbert commented Nov 7, 2023

probably shouldn't overthink this, but modifying oofatfs/ff.c doesn't leave me completely comfortable. It's fragile code, so any changes are a risk. Also, changes complicate incorporating upstream fixes at a future date. On the other hand, this isn't the first CircuitPython mod to oofatfs.

As long as the changes are clearly annotated as // CIRCUITPY-CHANGE (as I did in the review), I think it's OK. The main thing is to make it easy to spot and understand the changes from upstream.

@dhalbert
Copy link
Collaborator

dhalbert commented Nov 7, 2023

@tannewt I want to run this by you too.

@dhalbert dhalbert requested a review from tannewt November 7, 2023 21:58
@eightycc
Copy link
Collaborator Author

eightycc commented Nov 8, 2023

@dhalbert CI fail moved to another SiLabs board. It looks like timing:

Slcp parse warnings for /home/runner/work/circuitpython/circuitpython/ports/silabs/circuitpython_efr32.slcp
	Referenced SDK Extension 'cp_efr32:1.0.0' could not be found.
Warnings loading project: 
 - Referenced SDK Extension 'cp_efr32:1.0.0' could not be found.

This warning appears only for the failing targets.

Perhaps the silabs/cp_efr32_extension path isn't getting signed in time for another parallel make? Signing should happen in the slc-generate target in silabs/Makefile.

@tannewt
Copy link
Member

tannewt commented Nov 9, 2023

@dhalbert CI fail moved to another SiLabs board.

I just reran the test and it worked ok. Makefile race condition seems likely.

Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine with me! Thanks for the investigation!

Copy link
Collaborator

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this great work!

@dhalbert dhalbert merged commit ce6a5e3 into adafruit:main Nov 10, 2023
@eightycc eightycc deleted the tinyfs2 branch November 11, 2023 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants