libkernel: unlink and sceKernelUnlink fail on read-only files on Windows (counterpart of #2342) #2601
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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 reyani-dev on 2026-10-10T08:19:22Z.
unlinkandsceKernelUnlinkfail on Windows for a file the guest made read-only. This is the libkernel counterpart of the libcremovecase fixed in #2342.FreeBSD's
unlinkignores the file's own permission bits; what matters is write access to the directory. Sochmod(path, 0400)followed byunlink(path)succeeds on the console. On Windows, the guestchmod(_wchmod) setsFILE_ATTRIBUTE_READONLYwhen the write bit is cleared.NativeUnlink's_wunlinkthen fails withEACCES, sounlinkreturns -1 with errno 13 andsceKernelUnlinkreturns0x8002000D, and the file stays. Linux is not affected.Fix, ready to cherry-pick.
AchrafReyani:fix/unlink-readonly(fbf0ec0a, one commit onmain89a1fb4e). I can't open it as a PR because of the intake check (it was #2405, closed by the bot).The fix follows the shape requested on #2342: decide up front, with no retry. When
_wstat64reports a regular file without_S_IWRITE,NativeUnlink(Windows only) makes it writable with_wchmodbefore the single_wunlink. If the unlink fails, for example because the file is open without delete sharing, it restores the read-only attribute and reports the unlink's error. The change uses only CRT calls already inOpen.cpp, with nowindows.h.guest_filesystemgains a case: two files made read-only withsceKernelChmod(0400)are removed, one byunlinkand one bysceKernelUnlink, and no longer exist.Checked on Windows (WinLibs GCC 15.2.0, Release, on
main89a1fb4e):sceKernelUnlinkreturns0x8002000D, the file stays, and the read-only attribute is restored. After the handle is closed,sceKernelUnlinkremoves it.ctest -E "^agc_|video_out"passes 341/341,check_conventions.pypasses, andpr_overlap.pyreports no overlap.No title is known to stop on this, unlike #2559. It is the same Windows behaviour gap that #2342 closed for
remove.Found with Claude Code.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-10T08:46:22Z.
Updated validation on current
mainI reapplied the one-commit patch from
AchrafReyani:fix/unlink-readonlyto upstreammainatb5f5362din a detached local worktree. The two-file patch applies cleanly.guest_filesystem_tests(Linux x86_64, GCC 12.2, Release)guest_filesystemmaingit diff --checkThe Windows evidence remains Achraf's Windows 11 / WinLibs GCC 15.2 run: read-only unlink succeeds, while a held-open file without delete sharing remains present and read-only after failure. That run and their fork CI were based on older commits (
3d1a7d90for CI); I have not repeated Windows validation onb5f5362d.Coordination with PR #2651
PR #2651 is still open, but its current head
f42420e7has 70 commits and changes 234 files (+6,050/−448) relative to its merge base. The unrelated diff needs to be removed before review. Its current unlink code also does not restore the read-only attribute after a failed retry, andGuestFilesystem.cppredeclaresreadOnlyin the same scope, so the Linux test target still cannot compile. I updated my review comment on #2651 with these current-head findings. Please coordinate with its author and the maintainers on one scoped implementation while preserving the Windows held-open-file evidence.The Achraf patch remains staged locally for review; I have not committed or pushed it. No PR was opened while intake requires 20 merged PRs and my count is 15. AI-assisted change.
Imported from boykopovar/AnyPS5. Originally posted by reyani-dev on 2026-10-10T09:26:08Z.
Thanks @MarcZX100. Here is the Windows side for the same commit:
main3d1a7d90(run 38040339170):guest_filesystemwith the new read-only checks. The two failures areguest_file_vectorandguest_memory, which fail identically on plainmainsince #2620 (details there), not this change.0x8002000D, stays in place and keeps its read-only attribute;Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-10T10:30:43Z.
Coordination with open PR #2651
There is now an open PR for the same Windows read-only
unlinkbehavior: #2651. I left a review comment there because its current head has a Linux test-build failure (readOnlyis redeclared inGuestFilesystem.cpp) and its retry path does not restore the read-only attribute if the second unlink attempt also fails.Your branch already has Windows 11 evidence for both successful deletion and the held-open-file case, including restoration of the read-only attribute after failure. Please coordinate with @sridhar777911 and the maintainers so the two implementations converge on one canonical change and your test/evidence is preserved.
Imported from boykopovar/AnyPS5. Originally posted by harmsluis on 2026-10-10T11:31:14Z.
Windows validation of
AchrafReyani:fix/unlink-readonly(fbf0ec0a) on currentmainb5f5362d, filling the gap noted above. Windows 11 (10.0.26300), WinLibs GCC 15.2.0, CMake 4.3.1 / Ninja, Release,BUILD_TESTING=ON.The commit cherry-picks cleanly onto
b5f5362d(two files, +19/−1).cmake --build build --target guest_filesystem_testsguest_filesystemb5f5362d+ full patchb5f5362d+ test change only (Open.cppreverted)0xc0000409So the new read-only checks fail on
mainand pass with theOpen.cppchange, natively on Windows. I did not repeat the held-open-file case; Achraf's earlier run covers it.AI-assisted: yes. An AI agent applied the patch, ran the builds and tests, and drafted this comment; I reviewed the results.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-10T12:38:45Z.
Current-main refresh of the narrow #2601 patch
I carried AchrafReyani's one-commit fix forward onto the latest upstream
main,b69270dd, preserving him as the commit author. The refreshed commit is1ba3c397on my fork branchcodex/fix-unlink-readonly-2601. The two touched files have not changed since the earlierb5f5362dvalidation base.libkernelandguest_filesystem_testsb69270dd+1ba3c397guest_filesystemmaingit diff --checkThis refresh is Linux evidence only. The Windows results remain those reported by Achraf and harmsluis on
b5f5362d/fbf0ec0a, including restoring the read-only attribute when a held-open file cannot be deleted; I did not repeat Windows onb69270dd.PR #2651 remains open at
f42420e7, markedDIRTY, with 234 changed files and only Conventions complete. Achraf offered the narrow tested change to that PR's author; there has been no author update since. I have not opened a replacement PR: the intake gate still requires 20 merged PRs, and my current count is 15.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-10T18:08:49Z.
@AchrafReyani the intake check needs 10 merged PRs now, so your branch (or MarcZX100's refresh, 1ba3c397) can go up as a PR.
Imported from boykopovar/AnyPS5. Originally posted by reyani-dev on 2026-10-10T18:24:15Z.
Thanks @oneandonlydean, it's up as #2910 (rebased onto current
main, same single commit).