feat(libkernel): support SEEK_DATA and SEEK_HOLE in lseek #6936
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6936"
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 AlexOfTheForest on 2026-10-16T20:06:05Z.
What
FreeBSD 11.4's
lseekacceptsSEEK_DATA(3) andSEEK_HOLE(4); AnyPS5 rejected them,sceKernelLseekthrew on any unknown whence, andlseekreturnedEINVALbefore looking at the descriptor. Three commits:fix(libkernel): an unknown whence fails as in FreeBSD'skern_lseek. The file is fetched first, so a closed descriptor isEBADFand a pipeESPIPEwhatever the whence.vn_seekrejects the unknown whence withEINVAL.sceKernelLseekno longer throws.feat(libkernel):SEEK_DATA/SEEK_HOLEasvn_seekandvn_bmap_seekholedefine them:ENXIO. Inside the file,SEEK_DATAfinds the next data andSEEK_HOLEthe next hole, with the end of the file counting as one.ENOTTY. Pipe:ESPIPE.SEEK_HOLEreturns the file size.feat(libkernel): the same onapp0.zardescriptors, which have no holes.The logic lives in
File/src/Seek.cpp. The console's filesystems are unknown (one withoutFIOSEEKDATAwould answerENOTTY), so this is recorded indocs/dev/debt/libkernel.md.GuestPosixScalarIoexpectedEINVALfor whence 3; it now checks an unknown whence (5) instead.Tested
Linux x86-64, GCC.
guest_lseek_whence:EINVAL,EBADFandESPIPE, through bothsceKernelLseekandlseek;SEEK_DATA/SEEK_HOLEinside a file, at its end and past it, and on an empty file, a directory and a pipe;guest_kernel_app_archivecovers archived files.guest_posix_scalar_io,guest_filesystemand the archive tests pass.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by cadenasynyster on 2026-10-17T01:19:45Z.
Windows run, since the PR lists Windows as untested and the Windows CI job is skipped on this head:
Windows 11 10.0.26200.9711 (NTFS), WinLibs GCC 15.2.0 posix UCRT r7, Release, BUILD_TESTING=ON, head 8392e0c97 merged onto main
f3263dfbf(clean merge, no new build errors).Not checked: sparse files with real holes on NTFS, or a title.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-11-01T19:59:00Z.
Review: COMMENTED
Correction (2026-11-01): the title-ID/log demand below is not a CONTRIBUTING requirement;
Unblocks: noneis allowed. The technical points below are unaffected.The PR names no title that calls
lseekwithSEEK_DATAorSEEK_HOLE("Unblocks: none") and shows no log line of a title reaching the change onmain. Without that the newSeek.cppsurface (about 250 changed lines) is unreachable from anything that runs, and this kind of PR gets closed. Please add the title ID and the log line.Two questions on the code:
sceKernelLseekused to throw on an unknown whence and now returnsEINVALfor anything outside 0 to 4. The description says this matcheskern_lseek; is that checked against a console trace or only against FreeBSD sources? The debt entry says the console's filesystems are unknown, and the same uncertainty applies to which errno the console returns here.SEEK_HOLEreturns the file size andSEEK_DATAreturns the offset, i.e. the whole file is data. That is correct for a filesystem without sparse reporting, but sparse files on NTFS do exist; if a title probes for holes it would see a different layout than on Linux. Is that recorded indocs/dev/debt/libkernel.md, or only the console side?Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T02:51:07Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge:
SeekArchivedFiletreats everySEEK_DATAoffset inside an archived file as data, even when the offset is beyond the current file position only because the implementation seeks directly to it; this bypasses the defined region lookup and can report data where none exists if archived files can contain sparse regions.What I ran
Reviewed head
f06949da78cf801f47702e27f0dd987f4b80e184. No commands or tests were run in this review; the author reports Linux x86-64/GCC tests in the PR description.Results
Findings
Blocking
core/libs/prx/libkernel/File/src/ArchivedFile.cpp:93: For any archived file offset belownode.Size,SEEK_DATAreturns that offset as data without checking the file's actual data regions. The implementation must establish that app0.zar files are always fully allocated or resolve the data region correctly; the current description's blanket claim that archived files have no holes does not establish that property.Non-blocking
None.
Not verified
core/libs/prx/libkernel/CMakeLists.txt,core/libs/prx/libkernel/File/include/Seek.hpp,core/libs/tests/GuestKernelAppArchive.cpp,core/libs/tests/GuestPosixScalarIo.cpp, anddocs/dev/debt/libkernel.mdwere listed in the prepared bundle but not read from their full file texts; relevant hunks were inspected indiff.patch.files.jsonwere not available through the review reader, so excluded files could not be enumerated. No claim is made about those files.To get this to a good state
Confirm app0.zar files are guaranteed to have no holes, with evidence, or implement region resolution that does not assume every in-range offset contains data. Then rerun the archived-file seek tests and the relevant filesystem tests on the new head.
Pull request closed