feat(libkernel_sys): implement lchflags #9442
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9442"
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 Gruzzberry on 2026-10-21T22:15:50Z.
What
lchflagswas a throwing stub in libkernel_sys. FreeBSD 11.4 implements it aschflagswithout following a symbolic link in the last component:sys_lchflagscallskern_chflagsatwithAT_SYMLINK_NOFOLLOW, andkern_chflagsatonly switchesnameifromFOLLOWtoNOFOLLOW.chflagsinStdio.cppnow goes throughChangeFileFlags_nid_no_patch, which takes the same follow choice. When not following, a symbolic link in the last component is the target, so a dangling link is accepted instead of failing the lookup. The link is recognised withFile::FillLinkStat, the guestlstat, because under MinGWstd::filesystem::symlink_statusreports a Windows symbolic link as the file or directory it names. A trailing slash still follows, as in FreeBSD. The flag checks are the existing ones, unchanged: unknown bitsEOPNOTSUPP,SF_SNAPSHOTEPERM, any other non-zero flag throws because the host keeps no BSD file flags.chflagsitself behaves as before.Tested
Windows 11 (10.0.26200), WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release,
-DBUILD_TESTING=ON, onmaind6eafa54d0(rebased), Developer Mode on so the link cases run.guest_kernel_sys: the newlchflagschecks (a regular file,EFAULT,ENOENTfor empty and missing paths,ENOTDIRthrough a file,EOPNOTSUPP,EPERM, a dangling link and a working link with flags 0,EOPNOTSUPPandEPERMon the link, the throw forUF_IMMUTABLE) abort onmainwithlchflags_nid_postfix not implementedand pass with this PR.guest_filesystem(the existingchflagsandfchflagschecks) andguest_file_timestamps: pass.maind6eafa54d0and onmainwith #9442, #9469, #9474, #9487 and #9496 merged together, same machine: 1890 tests each, identical results (1869 passed, 18 skipped; on both, the 3agc_driver_sample_order*tests fail andagc_driver_image_array_window_past_layer_limitis not built, as its 64 KiBalignasis rejected by this MinGW toolchain).python tools/check_conventions.py --base upstream/main: passes.guest_kernel_syspasses, and fails withlchflags_nid_postfix not implementedwithout the change); see the review.Overlaps
PathErrorcopy the guest path; this PR is rebased onto it, soChangeFileFlags_nid_no_patchtakes the copied path for bothchflagsandlchflags.GuestKernelSys.cppblock; agreed on #9442: this PR goes first and #10625 rebases, keeping both.lchmod) removes the stub next tolchflagsinExport.Discovery.cpp, and #9097 and #9103 add code next to these lines inGuestKernelSys.cppandlibkernel_sys/Export.cpp: text-only, whichever lands second rebases.GuestKernelSys.cpptotests/process/; if it lands first, the new cases move with the file in the rebase.tools/pr_overlap.py --branchon the rebased head lists no other direct overlap; of the 22 pull requests it could not compare, none changeschflags,LookupErrororlchflags.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); no silent stubs added.mdfiles or images added to the repositoryAI-assisted (Claude Code).
🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by Gruzzberry on 2026-10-21T22:52:14Z.
Updated: the link check now uses
File::FillLinkStat(the guestlstat) instead ofstd::filesystem::symlink_status. Measured on Windows 11 with MinGW-w64 GCC 15.2.0 r7:symlink_statusandstatusboth report a symbolic link, dangling or not, as the regular file or directory it names, so the earlier check was never true on Windows and the dangling-link test only passed becausechflagsdoes not follow links there either. Withchflagsfixed to follow links (separate PR), the earlier version fails the dangling-link check and this one passes.guest_kernel_sysandguest_filesystempass.Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-22T00:06:44Z.
Review: COMMENTED
Linux run of the current change, since the description lists only Windows ("Not tested: Linux").
Machine: Linux x86_64, i7-8700 (6 cores / 12 threads), Ubuntu 26.04, GCC 15.2, Release,
BUILD_TESTING=ON. Heade5d6ec946merged ontomaina6dcea927(the merge touchesStdio.cpp,libkernel_sys/Export.Discovery.cpp,libkernel_sys/Export.cppandGuestKernelSys.cpp).guest_kernel_syspasses with the change, including the newlchflagscases (regular file,EFAULT,ENOENT,ENOTDIR,EOPNOTSUPP,EPERM, the dangling and working link cases and theUF_IMMUTABLEthrow).mainand keeping the test abortsguest_kernel_sys:terminate called after throwing an instance of 'std::runtime_error'what(): lchflags_nid_postfix not implementedso the regression reproduces on Linux as well and the test covers the change.
Export.Discovery.cpp) to a real entry inExport.cpp; the patched/unpatchedlibkernel_syslibraries build and the NID/convention tests pass, so the NID patching stays intact.Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T01:36:09Z.
Review: DISMISSED
I reviewed the
lchflagsimplementation and its source/test context. The cited FreeBSD syscall usesAT_SYMLINK_NOFOLLOW; the helper uses guestlstatso a dangling final-component link is recognized on MinGW, whilechflagsretains follow behavior. The existing unsupported-flag results are preserved. The author reports Windows tests and an independent reviewer reports Linux build/regression results; hosted eligibility, conventions, labels and report pass, while product/relinker jobs were skipped. I did not run local tests.The current overlap results need author coordination before merge:
PathErrorcontract and thechflagscode inStdio.cpp; this PR refactors that samechflagsimplementation and calls the oldPathErrorsignature. The branches must be reconciled so checked guest-path copying and the new no-follow helper both remain.chown/lchown/fchownatexports inlibkernel_sys/Export.cppat the samefstatat/unlinkinsertion area where this PR addslchflags.GuestKernelSys.cpptotests/process/GuestKernelSys.cpp, while this PR adds the regression cases to the old path. Coordinate so the final registered test target includes the new coverage after the move.Please agree the order with these authors, rebase/compose the changes, and record
Depends onfor any prerequisite. The presentnoneentries do not document these direct overlaps. The scan also listed #9040, #9097 and #6525 at nearby test lines; I manually compared their hunks and found their helper/call insertions separate from the lchflags additions, so I am not requesting changes for those.Imported from boykopovar/AnyPS5. Originally posted by Gruzzberry on 2026-10-22T06:48:59Z.
Rebased onto
maind6eafa54d0.guest_kernel_sysandguest_filesystempass on the new head, the new checks fail on thatmainwithout the change, andcheck_conventions.pypasses. Full suite onmaind6eafa54d0and onmainwith #9442, #9469, #9474, #9487 and #9496 merged together: 1890 tests each, identical results.Overlaps, now listed in the description under Overlaps: I asked on #9423 to land it first and will then rebase this PR so
ChangeFileFlags_nid_no_patchtakes the copied path forchflagsandlchflags. #9200, #9097 and #9103 are adjacent text only, and the new cases followGuestKernelSys.cppif #6044 moves it first. Thanks @jotitadev for the Linux run; it is credited in the description.Imported from boykopovar/AnyPS5. Originally posted by Gruzzberry on 2026-10-22T11:40:53Z.
Holding this as a draft, following the direction on #5239: the open queue is above 700 and no named title needs this change on current
main. I will only mark it ready again with a current-main title ID, its Game bring-up discussion and the log line where it stops on this, or once the queue is below 700. Thanks for the reviews so far; the requested fixes are being made on the branch in the meantime.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T18:43:17Z.
Review: COMMENTED
The implementation and reported Windows/Linux checks look well-supported. One documentation follow-up: please update the existing
chflagsdebt entry indocs/dev/debt/libkernel.mdto includelchflagsand its no-follow behavior, including that this behavior and the console filesystem/flag handling have not been measured on a PS5. The entry currently documents the same shared flag limitations forchflags/fchflags, but does not name the newly implemented API or its symlink-specific path behavior. No blocking code issue found in this review.