Skip to content

Fix missing entries in simplefs_lookup#83

Open
ibat10clw wants to merge 1 commit intosysprog21:masterfrom
ibat10clw:fix-simplefs-lookup
Open

Fix missing entries in simplefs_lookup#83
ibat10clw wants to merge 1 commit intosysprog21:masterfrom
ibat10clw:fix-simplefs-lookup

Conversation

@ibat10clw
Copy link
Copy Markdown

@ibat10clw ibat10clw commented Mar 30, 2026

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.txt

After 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 

Summary by cubic

Ensure simplefs_lookup scans 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.

  • Bug Fixes
    • Continue scanning across holes; compare names only when f->inode is set.
    • Bound the loop by SIMPLEFS_FILES_PER_BLOCK and track live entries with a local nr_files.
    • Advance with fi += f->nr_blk to correctly traverse sparse directory blocks.

Written for commit f85250a. Summary will update on new commits.

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.
cubic-dev-ai[bot]

This comment was marked as resolved.

@jserv jserv requested a review from RoyWFHuang March 30, 2026 08:20
@jserv
Copy link
Copy Markdown
Collaborator

jserv commented Mar 30, 2026

I defer to @RoyWFHuang for confirmation.

@RoyWFHuang
Copy link
Copy Markdown
Collaborator

I agree. The early exit on holes is exactly what causes files to be missed in the scan.

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