Update the ".." entry when a directory is moved to a new parent - #99
Open
schnitst wants to merge 1 commit into
Open
Conversation
When a directory is renamed into a different parent directory, fx_directory_rename relinks the entry in both parents but never updates the ".." entry inside the moved directory, which keeps pointing at the old parent's starting cluster. A ".." path component inside the moved directory then resolves to the old parent and, once that cluster is reused, to an unrelated place. fx_media_check does not detect this, as it skips the first two entries of every sub-directory. Read the moved directory's ".." entry after the relink and rewrite its starting cluster in place when the parent changed (0 when the new parent is the root). The write happens inside the existing fault tolerant transaction; a rename within one parent ends without the additional write. The regression test extension covers every parent transition - between sub-directories, into and out of the root - and pins the write count: one additional directory entry write for a move, none for a rename within one parent. Fixes Issue eclipse-threadx#98 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
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.
Problem
When fx_directory_rename moves a directory to a different parent directory, it relinks the entry in both parents but never updates the '..' entry inside the moved directory itself. '..' keeps the starting cluster of the old parent, so any '..' path component inside the moved directory resolves to the old parent - and, once that cluster is reused, to unrelated data. fx_media_check cannot detect this because it skips the first two entries of every sub-directory.
Details and reproduction: #98.
Fix
After the relink completes, read the moved directory's '..' entry (entry 1 of its first cluster) and rewrite its starting cluster in place when the parent changed - cluster 0 when the new parent is the root, matching the convention fx_directory_create writes. Design points:
Tests
filex_directory_rename_test.c gains a section covering every parent transition - between sub-directories, into the root, out of the root, and renames within one parent - verifying both path resolution through '..' and the on-media entry itself, and pinning the directory-entry write count (one additional write for a move, none for an in-place rename). The section runs on a freshly formatted media after the existing flow, so the error-injection steps calibrated against the original directory layout are unaffected.