fix(libkernel): change O_APPEND on a Windows file through fcntl #9256
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9256"
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 Dom3005 on 2026-10-21T16:40:12Z.
What
On Windows,
fcntl(F_SETFL)threwfcntl: changing O_APPEND on a file is not implementedwhenever it set or clearedO_APPENDon a regular file. FreeBSD 11.4'skern_fcntlchangesO_APPENDlike any otherF_SETFLflag.The guest flag already decides whether
writegoes throughWriteAtEnd. A descriptor opened withO_APPENDalso carries the CRT's append flag, though (NativeOpenpasses_O_APPENDto_open_osfhandle), so after the guest clearedO_APPEND,::_writewould still seek to the end. The CRT flag has to stay set whileO_APPENDis on, becausefdopen(fd, "w")on such a descriptor writes through the CRT and must keep appending.When
O_APPENDchanges on a Windows file,F_SETFLnow duplicates the descriptor's handle, opens it with or without_O_APPENDthrough_open_osfhandle, and_dup2s it onto the same number. This is the same patternMoveAppendingHandlein libc uses forfdopenin append mode. On FreeBSDO_APPENDbelongs to the open file, so this is done for every descriptor that shares the status (the descriptorsdupandF_DUPFDcreate). The duplicated handle keeps the same file object, so file position andflocklocks carry over.The "Changing
O_APPENDon a Windows file" clause is removed from thefcntlentry indocs/dev/debt/libkernel.md.Tested
Windows 11 10.0.26200, WinLibs GCC 15.2.0 r7 UCRT, Release,
BUILD_TESTING=ON, onmaincecb540a6.guest_kernel_fcntlnow runs the sameO_APPENDchecks on every host, where it used to expect the throw on Windows: append, clearO_APPENDand write at offset 0, set it again through aF_DUPFDduplicate and check that the original descriptor appends, clear it through the duplicate and check that the original no longer appends, then read the file back (Ybcdeabc).fcntl: changing O_APPEND on a file is not implemented, fd=3.ctest -E '^agc_driver': 1230/1230 passed.python tools/check_conventions.py: passed.O_APPENDsemantics, which the host's ownF_SETFLprovides.Overlap:
tools/pr_overlap.pyshows #8544 and #9109 editing the same paragraph ofdocs/dev/debt/libkernel.md(#8544 changes the pipeF_GETFLpart of thefcntlentry), so whichever merges second needs a one-line rebase. #6044, #6977 and #8520 share files, but their diffs don't touchO_APPEND.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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by cadenasynyster on 2026-10-21T21:28:16Z.
Independent Windows run of this PR (head da61bf7c1).
Environment: Windows 11 10.0.26300, Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7 (MinGW), Release, BUILD_TESTING=ON.
Results:
guest_kernel_fcntlpasses 3/3 (--repeat until-fail:3).core/libs/prx/libkernel/File/src/DescriptorControl.cppwith the merge-base version (cecb540a6). The test fails withfcntl: changing O_APPEND on a file is not implemented, fd=3, the same as the description. I restored the PR's file afterwards.Note for anyone repeating the baseline: that failing run aborts after writing
abcdeandab, sokernel_fcntl_probe.binstays behind inbuild/core/libs/prx/libkernelwith 7 bytes.FileFlagsRoundTripopens it withoutO_TRUNC, so every later run, onmainas well, fails earlier at theFIONREADcheck (readable == 3, line 241) until the file is deleted. My first runs of this PR hit that. With the file deleted,main(0c6a5bd59) and this PR both pass. This is in the existing test, not in this PR's change.Not run: Linux/macOS,
fdopen(fd, "w")on a descriptor whoseO_APPENDwas changed (the description mentions it, but the test does not cover it), the full repository CTest, and any title.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by Dom3005 on 2026-10-21T21:55:59Z.
Thanks for the independent run and the baseline. Before this PR, Windows only expected the throw at that point, so the test could not stop partway and leave the probe file behind. Now it can, so ddcb41a9a removes
kernel_fcntl_probe.binat the start ofFileFlagsRoundTrip. I checked it by writing a 7-byteabcdeabprobe file intobuild/core/libs/prx/libkernel: the previous binary fails, and the new one passes--repeat until-fail:3and removes the file afterwards.The
fdopen(fd, "w")case is still covered only by the reasoning in the description. It goes through libc, so this kernel test does not exercise it.Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-22T08:50:01Z.
Hi @Dom3005, a merge-order note for two of mine:
O_FSYNC) changes theO_FSYNCexpectation incore/libs/tests/GuestKernelFcntl.cppnext to your lines there, and both edit thefcntlrow ofdocs/dev/debt/libkernel.md.SIGIOowner) touches the samefcntldebt row.None of the code meets. Proposal: no dependency either way; whichever merges second keeps both test changes and all the debt sentences. Does that work for you? I'll record it in both checklists.
AI-assisted: yes