fix(libkernel): rewind Windows directory descriptors on lseek #2680
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2680"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by husseinkad on 2026-10-10T10:50:04Z.
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 #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 repositoryImported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-10T10:50:19Z.
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.
Pull request closed