Repository navigation
libfatx: Grow directories past their first cluster - #106
Merged
Merged
Conversation
This was referenced Oct 18, 2026
Closed
There was a problem hiding this comment.
🟡 Changes recommended
An allocation failure during directory growth leaks an allocated cluster, and the tests neither exercise marker-free full-chain termination and growth nor verify the intended low-level statuses.
2 open issues
What changed in this PR
This PR addresses #56 by enabling FATX directories to grow beyond one cluster without writing into neighboring clusters. It also treats the end of a full directory chain as normal directory termination.
Changes:
- Walk directory cluster chains and initialize new clusters with end markers before attaching them.
- Handle marker-free directory termination in library operations and FUSE directory listing.
- Add tests for multi-cluster growth, neighboring-file integrity, slot reuse, and cluster-boundary behavior.
| File | Description |
|---|---|
pyfatx/tests/test.py |
Adds directory-growth and cluster-boundary regression tests. |
libfatx/fatx_dir.c |
Implements directory growth and updates chain-end handling. |
libfatx/fatx_attr.c |
Maps directory chain exhaustion to file-not-found. |
fatxfs/fatxfs_fuse.c |
Treats directory chain exhaustion as successful listing completion. |
Review effort: Balanced
Member
|
Thanks for the PR! Please rebase and check out the copilot reported issues |
Adding an entry to a directory never extended it correctly once its first cluster was full: - With the end-of-directory marker in the last slot of a cluster, the marker was moved to the slot after it, which is the first entry of the next cluster on disk, not the next cluster of the directory. - With every slot in use, a new cluster was attached but the entry was written one slot past the end of the old cluster, again landing in whatever cluster follows it on disk. Both cases overwrite another file or directory, and the new entry is never found, so creating the file then fails with EPERM (XboxDev#56). Reading a directory whose last cluster is completely full also failed, because reaching the end of its chain was treated as an error. Allocation now walks the directory's cluster chain, moves the end marker into the next cluster of the chain, and appends a cluster filled with end markers when the chain is full. Reaching the end of the chain after a full cluster is reported as the end of the directory. Fixes XboxDev#56
xmutantson
force-pushed
the
libfatx-grow-directories
branch
from
October 29, 2026 21:07
65b9ab3 to
3394639
Compare
Member
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Fixes #56.
fatx_alloc_dir_entry()never extended a directory correctly once its first cluster was full, and in both failing cases it writes outside the directory:entry + 1, which is past the end of the cluster.fatx_dev_seek_cluster()doesn't bound the offset, so this rewrites the first byte of whatever cluster follows on disk.entries_per_clusterof the old cluster, which is the first 64 bytes of the next cluster on disk.In both cases the new entry is never found afterwards, so creating the file fails with
EPERM. That is the error in #56, which shows up withrsync/cpinto game folders with more than 256 entries (16 KiB clusters) or 512 entries (32 KiB clusters). What #56 doesn't show is the write outside the directory: because clusters are allocated sequentially, the cluster after a directory's first cluster is usually the first file or subdirectory created inside it. In a scratch image, the corrupted neighbor was a sibling directory created right after the full one, and the file inside it no longer read back correctly.Reading a directory whose last cluster is completely full (no end marker) also failed, because
fatx_next_dir_entry()treated reaching the end of the chain as an error.Changes
fatx_alloc_dir_entry()walks the cluster chain instead of stepping past the end of a cluster. When the end marker is in the last slot, it moves into the next cluster of the chain; if there is none, a new one is appended. When every slot is used, the entry goes in the first slot of a new cluster.0xFFend markers (asfatx_init_root()does) before being attached, and are released again if they can't be initialized or attached.fatx_next_dir_entry()returnsFATX_STATUS_END_OF_DIRat the end of the chain after a full cluster;fatx_open_dir(),fatx_get_attr_dir(),fatx_unlink(),fatx_rmdir()andfatxfsread_dirtreat that as the end of the directory.fatx_open_dir()this also stops a lookup that runs off the end of a directory from continuing with the next path component in the wrong directory.Testing
Two tests in
pyfatx/tests/test.py:test_directory_grows_past_one_cluster: 600 files in one directory (three 16 KiB clusters) plus a canary file in a sibling directory created right after it; checks the listing, every file's content, the canary, slot reuse after unlink, andrmdir.test_directory_with_full_last_cluster: builds a directory whose only cluster is full with no end marker (255 files, then the end marker in the last slot is overwritten with a 256th entry throughfatx_write_dir()), then checks the raw statuses: walking the directory ends withFATX_STATUS_END_OF_DIRand a missing name givesFATX_STATUS_FILE_NOT_FOUND, wheremasterreturnsFATX_STATUS_ERRORfor both. It then checks that the directory grows from that state.On
masterboth new tests fail (the other 17 pass); with this change all 19 pass. I also ran afatxfsmount test with 1,200 files in one directory on a 32 KiB-cluster F: image, checked before and after a remount, and used the patchedfatxfsto copy ~430 GB of game folders (some directories with up to 4,000 entries) to a real 500 GB drive; a checksum comparison against the source afterwards matched every file.Rebased onto
masterafter #107.Separately, the same copy hit the prefix match in
fatx_open_dir()that #99 fixes (BloodRayne/resolving to an earlierBloodRayne 2/). This PR doesn't touch that comparison, so the two shouldn't conflict.