Fix missing entries in simplefs_lookup#83
Open
ibat10clw wants to merge 1 commit intosysprog21:masterfrom
Open
Conversation
simplefs_lookup must scan all entries in a directory before it can determine whether a file exists. The current implementation stops early when it encounters a hole in the directory, which can cause later files to be missed. In addition, fi is used as the index into dblock, so the loop should be bounded by SIMPLEFS_FILES_PER_BLOCK rather than dblock->nr_files. If a file is located near the end of the directory block, the loop may terminate early when fi >= dblock->nr_files, resulting in an incomplete scan. Fix this by skipping holes during filename comparison and continuing to advance fi until all live directory entries have been examined.
Collaborator
|
I defer to @RoyWFHuang for confirmation. |
Collaborator
|
I agree. The early exit on holes is exactly what causes files to be missed in the scan. |
RoyWFHuang
approved these changes
Apr 3, 2026
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.
simplefs_lookup must scan all entries in a directory before it can determine whether a file exists.
The current implementation stops early when it encounters a hole in the directory, which can cause later files to be missed. In addition, fi is used as the index into dblock, so the loop should be bounded by SIMPLEFS_FILES_PER_BLOCK rather than dblock->nr_files. If a file is located near the end of the directory block, the loop may terminate early when fi >= dblock->nr_files, resulting in an incomplete scan.
Fix this by skipping holes during filename comparison and continuing to advance fi until all live directory entries have been examined.
This issue can be reproduced with a freshly formatted simplefs image using
the following steps.
Before this patch
$ sudo touch test/{1..10}.txt $ sudo rm test/1.txt $ echo 3 | sudo tee /proc/sys/vm/drop_caches $ sudo touch test/9.txt $ ls test/ 10.txt 2.txt 3.txt 4.txt 5.txt 6.txt 7.txt 8.txt 9.txt 9.txtAfter this patch
$ sudo touch test/{1..10}.txt $ sudo rm test/1.txt $ echo 3 | sudo tee /proc/sys/vm/drop_caches $ sudo touch test/9.txt $ ls test/ 10.txt 2.txt 3.txt 4.txt 5.txt 6.txt 7.txt 8.txt 9.txtSummary by cubic
Ensure
simplefs_lookupscans the whole directory block and skips holes so files aren’t missed, including entries near the end. This fixes false “not found” results and eliminates duplicate-looking listings after deletions.f->inodeis set.SIMPLEFS_FILES_PER_BLOCKand track live entries with a localnr_files.fi += f->nr_blkto correctly traverse sparse directory blocks.Written for commit f85250a. Summary will update on new commits.