Repository navigation
feat(libkernel): support SEEK_DATA and SEEK_HOLE in lseek - #6936
AlexOfTheForest wants to merge 3 commits into
Conversation
|
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
|
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 8392e0c merged onto main f3263df (clean merge, no new build errors).
Not checked: sparse files with real holes on NTFS, or a title. AI-assisted: yes |
8392e0c to
b173bb7
Compare
b173bb7 to
1de206c
Compare
…of throwing sceKernelLseek threw on a whence other than SET, CUR and END, and lseek returned EINVAL before looking at the descriptor. FreeBSD 11.4's kern_lseek fetches the file first and dispatches to its fo_seek: a closed descriptor is EBADF, a pipe ESPIPE whatever the whence, and vn_seek rejects the unknown whence with EINVAL. Both calls now resolve the descriptor before the whence.
FreeBSD 11.4 accepts whence 3 and 4: vn_seek forwards them to FIOSEEKDATA and FIOSEEKHOLE, which UFS answers through vn_bmap_seekhole. An offset at or past the end of a regular file is ENXIO, a directory ENOTTY and a pipe ESPIPE; inside the file SEEK_DATA finds the next data and SEEK_HOLE the next hole, the end of the file counting as one. Linux and macOS ask the host for the same regions; Windows has no holes to report, so SEEK_DATA keeps the offset and SEEK_HOLE moves to the size. A negative offset, shared memory and devices throw, as the source does not settle them.
An archived descriptor fell through to AppArchiveDescriptorSeek, which throws on any whence but SET, CUR and END. An archived file has no holes: SEEK_DATA keeps an offset inside the file, SEEK_HOLE moves to its size and an offset at or past the end is ENXIO, as for a regular file.
|
@AlexOfTheForest this needs a rebase onto main: the branch conflicts in Stdio.cpp, CMakeLists and the debt doc. Please push the rebased head so CI can run on it, since no test job has run on this head. The whence values (3 and 4) and the Windows emulation read correctly to me: DATA returns the offset, HOLE returns the file size, and an offset at or past EOF gives ENXIO. One thing to check while you are in there: on an archived fd with an unknown whence, a failed stat with errno 0 looks like it could return 0 instead of an error. |
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — changes requested
Changes are required before merge: SeekArchivedFile treats every SEEK_DATA offset 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
| Check | Result | Note |
|---|---|---|
| Prepared diff and changed code | passed | Changed implementation and tests read |
| Programmatic checks | not run | No build or tests run |
| Windows and macOS behavior | not run | Author reports these were not tested |
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.- The contents of
files.jsonwere not available through the review reader, so excluded files could not be enumerated. No claim is made about those files. - No build, tests, or console behavior were independently verified.
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.
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)