Repository navigation
fix(libkernel): rewind Windows directory descriptors on lseek - #2680
Closed
husseinkad wants to merge 3 commits into
Closed
husseinkad wants to merge 3 commits into
husseinkad wants to merge 3 commits into
Conversation
lseek on a directory descriptor returned 0 without moving the listing, so getdents after lseek(fd, 0, SEEK_SET) reported nothing.
…ffset overflow lseek on a non-directory descriptor no longer takes the directory table lock when no directory is open, and a listing is read under the descriptor's own lock. SEEK_CUR with offset 0 only reports the position, and an overflowing SEEK_CUR offset reports EOVERFLOW.
|
Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes. |
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.
What
On Windows a guest directory descriptor sits on the NUL device, so
sceKernelLseekon it did nothing: afterlseek(fd, 0, SEEK_SET)a secondgetdentsreturned 0 entries instead of listing the directory again. FreeBSDgetdirentries(2)documents that the position "may be set and retrieved by lseek(2)", and offset 0 is the standard rewind.File::SeekDirectoryDescriptornow handleslseekon directory descriptors (hook insceKernelLseek):SEEK_SETrewinds; the next read lists the live directory againSEEK_CURreturns the entry index (offset 0 is a pure query that does not touch the snapshot)SEEK_SET/SEEK_CURoffsets are entry indexes; a negative result throws like any otherlseekfailure (EINVAL), an offset overflow reportsEOVERFLOWSEEK_ENDthrows viaNotImplemented_nid_no_patch(FreeBSD defines it relative to the directory size, which is not modelled; it used to return 0 from the NUL descriptor)Per-descriptor state has its own lock, so a slow listing does not block
lseekon other descriptors, andlseek/closeon non-directory descriptors return before taking any lock while no directory is open. The limits (O(entries) re-listing per rewind,getdirentriesstill reporting 0 throughbasep) are recorded in TechnicalDebt.Tested
Windows 11 (10.0.26200), WinLibs GCC 15.2.0 r7, Release:
guest_directory_rewind: rewind after a partial and a full read, a file added between listings,SEEK_CURexactly 2 after.and.., a seek past the end, negative and overflowing seeks,SEEK_CUR0 not disturbing a listing, rewind aftergetdentsfailed on a too-small buffer, and a reused descriptor that was a directory behaving as a file. It fails without the change.ctest -R "guest_directory|guest_filesystem|guest_file_timestamps": 6 of 6 pass.getdents+ directorylseek+ regular-filelseek(about 12.6M operations) had 0 errors and no crash; separate probes with 0, 1, 5 and 10,000 entries relisted correctly.tools/check_conventions.py --base origin/mainpasses;tools/pr_overlap.py --branchreports no overlap. Open PR fix(kernel): return guest errors from scalar file operations #2144 also rewritessceKernelLseekinOpen.cpp(error returns instead of throws); the directory hook there would need to follow whichever style lands first.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository