fix(libkernel): chmod read-only files before unlink on Windows #2651

Closed
sridhar777911 wants to merge 70 commits from upstream-pr/2651 into main
sridhar777911 commented 2026-10-10 09:59:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by sridhar777911 on 2026-10-10T09:59:44Z.


What

Fixes Issue #2601. Unlink and sceKernelUnlink previously failed with EACCES on read-only files natively on Windows due to strict POSIX vs WIN32 semantic differences.

Tested

  • Rechecked locally. Passed check_conventions.py
  • Passed ctest suite
  • Built on Windows 11

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4810366767 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2651). Originally posted by [sridhar777911](https://github.com/sridhar777911) on 2026-10-10T09:59:44Z. --- ### What Fixes Issue #2601. Unlink and sceKernelUnlink previously failed with EACCES on read-only files natively on Windows due to strict POSIX vs WIN32 semantic differences. ### Tested - Rechecked locally. Passed `check_conventions.py` - Passed `ctest` suite - Built on Windows 11 ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in TechnicalDebt - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
Mouhand-Kaddo commented 2026-10-10 10:19:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Mouhand-Kaddo on 2026-10-10T10:19:21Z.


Additional platform validation on standalone PR head e80f6982f5d303f2fe2abfd52939cb5057aa9bf5:

Linux: blocked or failed — Arch Linux in WSL2 (kernel 6.6.87.2), GCC 16.2.1 20260810; CMake 4.3.1 / Ninja.

Release / BUILD_TESTING=ON: the selected-target build failed before CTest could run. No passing runtime-test claim.

Reproduce: cmake --build <build> --target guest_filesystem_tests.

Tests: guest_filesystem.

Blocker: Command exited 1: cmake.

GCC reports a conflicting declaration of readOnly in core/libs/tests/GuestFilesystem.cpp:288; the same variable is already declared at line 107 in main(). The PR adds the second declaration in the same scope, so guest_filesystem_tests does not compile. Rename or reuse the new variable before this test can run.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6096499898 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2651#issuecomment-6096499898). Originally posted by [Mouhand-Kaddo](https://github.com/Mouhand-Kaddo) on 2026-10-10T10:19:21Z. --- <!-- anyps5-platform-validation:e80f6982f5d303f2fe2abfd52939cb5057aa9bf5 --> Additional platform validation on standalone PR head `e80f6982f5d303f2fe2abfd52939cb5057aa9bf5`: **Linux: blocked or failed** — Arch Linux in WSL2 (kernel 6.6.87.2), GCC 16.2.1 20260810; CMake 4.3.1 / Ninja. Release / `BUILD_TESTING=ON`: the selected-target build failed before CTest could run. No passing runtime-test claim. Reproduce: `cmake --build <build> --target guest_filesystem_tests`. Tests: `guest_filesystem`. Blocker: Command exited 1: cmake. GCC reports a conflicting declaration of readOnly in core/libs/tests/GuestFilesystem.cpp:288; the same variable is already declared at line 107 in main(). The PR adds the second declaration in the same scope, so guest_filesystem_tests does not compile. Rename or reuse the new variable before this test can run.
MarcZX10 commented 2026-10-10 10:29:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-10T10:29:57Z.


Follow-up on the current PR head

This updates my earlier review because the PR head changed to f42420e7. The current diff needs another cleanup pass before it can be reviewed as a one-topic pull request:

Finding Current evidence Needed before merge
The PR includes unrelated work GitHub reports 70 commits, 234 changed files, +6,050/−448, with merge base 85d16bcc while current main is b0cccf20. The title is only about Windows read-only unlink. Rebase onto current main and retain only the unlink change and its regression tests.
The Linux test target still has a same-scope redeclaration GuestFilesystem.cpp declares readOnly at lines 108 and 310 in main(). Put the new cases in a scope or use different names, then build guest_filesystem_tests.
Failed retry leaves the file writable NativeUnlink adds owner_write before retrying _wunlink, then returns on a second failure without restoring the original permissions. Restore the original attribute when retry fails, and retain a held-open-file regression case.

The PR overlaps issue #2601, where Achraf has Windows 11 evidence for both successful unlink and restoring read-only state when an open handle prevents deletion. Please coordinate on one canonical implementation and preserve that test evidence.

The latest automatic check shown here is Conventions only; it does not validate this broad diff or compile the failing Linux target. The focused test and the collaborator-triggered Linux/Windows Build plus relinker matrix required by CONTRIBUTING.md remain outstanding.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6096577352 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2651#issuecomment-6096577352). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-10T10:29:57Z. --- ### Follow-up on the current PR head This updates my earlier review because the PR head changed to `f42420e7`. The current diff needs another cleanup pass before it can be reviewed as a one-topic pull request: | Finding | Current evidence | Needed before merge | |---|---|---| | The PR includes unrelated work | GitHub reports 70 commits, 234 changed files, +6,050/−448, with merge base `85d16bcc` while current `main` is `b0cccf20`. The title is only about Windows read-only unlink. | Rebase onto current `main` and retain only the unlink change and its regression tests. | | The Linux test target still has a same-scope redeclaration | `GuestFilesystem.cpp` declares `readOnly` at lines 108 and 310 in `main()`. | Put the new cases in a scope or use different names, then build `guest_filesystem_tests`. | | Failed retry leaves the file writable | `NativeUnlink` adds `owner_write` before retrying `_wunlink`, then returns on a second failure without restoring the original permissions. | Restore the original attribute when retry fails, and retain a held-open-file regression case. | The PR overlaps issue [#2601](https://github.com/boykopovar/AnyPS5/issues/2601), where Achraf has Windows 11 evidence for both successful unlink and restoring read-only state when an open handle prevents deletion. Please coordinate on one canonical implementation and preserve that test evidence. The latest automatic check shown here is Conventions only; it does not validate this broad diff or compile the failing Linux target. The focused test and the collaborator-triggered Linux/Windows Build plus relinker matrix required by `CONTRIBUTING.md` remain outstanding.
MarcZX10 commented 2026-10-10 11:06:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-10T11:06:34Z.

Review: CHANGES_REQUESTED


I cannot approve the current head f42420e7 yet. The merge-base diff is far broader than the titled unlink change, and the focused files still have correctness and build blockers:

Blocker Evidence Required follow-up
Unrelated PR scope The current PR has 70 commits and changes 234 files (+6,050/−448) from merge base 85d16bcc, while the title is only about Windows read-only unlink. Rebase onto current main and keep only this topic's source and tests.
Test target does not compile GuestFilesystem.cpp declares readOnly at lines 108 and 310 in the same main() scope. Rename or scope the added test variables and build guest_filesystem_tests.
Read-only state is not restored after retry failure NativeUnlink adds owner_write before the retry; if the retry also fails, it returns without restoring the prior permissions. Restore the original read-only state on failure and retain coverage for a held-open file.

This overlaps issue #2601. Please coordinate with Achraf so the canonical patch retains their Windows evidence for both successful deletion and restoring the read-only attribute when deletion fails. The current automatic checks show Conventions only; focused tests and the repository-required collaborator-triggered Linux/Windows Build and Linux/Windows/macOS relinker matrix are still outstanding.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5478722938 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2651#pullrequestreview-5478722938). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-10T11:06:34Z. **Review:** CHANGES_REQUESTED --- I cannot approve the current head `f42420e7` yet. The merge-base diff is far broader than the titled unlink change, and the focused files still have correctness and build blockers: | Blocker | Evidence | Required follow-up | |---|---|---| | Unrelated PR scope | The current PR has 70 commits and changes 234 files (+6,050/−448) from merge base `85d16bcc`, while the title is only about Windows read-only unlink. | Rebase onto current `main` and keep only this topic's source and tests. | | Test target does not compile | `GuestFilesystem.cpp` declares `readOnly` at lines 108 and 310 in the same `main()` scope. | Rename or scope the added test variables and build `guest_filesystem_tests`. | | Read-only state is not restored after retry failure | `NativeUnlink` adds `owner_write` before the retry; if the retry also fails, it returns without restoring the prior permissions. | Restore the original read-only state on failure and retain coverage for a held-open file. | This overlaps issue #2601. Please coordinate with Achraf so the canonical patch retains their Windows evidence for both successful deletion and restoring the read-only attribute when deletion fails. The current automatic checks show Conventions only; focused tests and the repository-required collaborator-triggered Linux/Windows Build and Linux/Windows/macOS relinker matrix are still outstanding.
MarcZX10 commented 2026-10-10 12:00:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-10T12:00:59Z.


Windows validation update from issue #2601

A new native Windows report is available on issue #2601. It tested Achraf's narrow fix/unlink-readonly commit fbf0ec0a on main b5f5362d:

Run Build guest_filesystem
Full two-file patch Passed Passed (1/1)
Test-only change, Open.cpp reverted Passed Failed with 0xc0000409

This confirms the regression and implementation on that branch under Windows; it is not validation of this PR's head.

PR #2651 remains at f42420e7 with 70 commits, 234 changed files (+6,050/−448), and Conventions as its only passing check. Current upstream main is 197ffac9. The scope, same-scope redeclaration, retry permission restoration, and required Build/relinker checks from my prior review still need resolution. Please coordinate with Achraf on one narrow carrier and preserve the new Windows evidence there.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6097270246 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2651#issuecomment-6097270246). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-10T12:00:59Z. --- ### Windows validation update from issue #2601 A new native Windows report is available on [issue #2601](https://github.com/boykopovar/AnyPS5/issues/2601). It tested Achraf's narrow `fix/unlink-readonly` commit `fbf0ec0a` on `main` `b5f5362d`: | Run | Build | `guest_filesystem` | |---|---|---| | Full two-file patch | Passed | Passed (1/1) | | Test-only change, `Open.cpp` reverted | Passed | Failed with `0xc0000409` | This confirms the regression and implementation on that branch under Windows; it is not validation of this PR's head. PR #2651 remains at `f42420e7` with 70 commits, 234 changed files (+6,050/−448), and Conventions as its only passing check. Current upstream `main` is `197ffac9`. The scope, same-scope redeclaration, retry permission restoration, and required Build/relinker checks from my prior review still need resolution. Please coordinate with Achraf on one narrow carrier and preserve the new Windows evidence there.
reyani-dev commented 2026-10-10 12:13:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by reyani-dev on 2026-10-10T12:13:56Z.


Hi @sridhar777911, I reported this as #2601. It has a one-commit fix, AchrafReyani:fix/unlink-readonly (fbf0ec0a, +19/−1 in Open.cpp and GuestFilesystem.cpp), which I can't open as a PR because of the intake check. Rather than have two versions, feel free to take that commit into this PR, or reset this branch onto it, so there's one scoped change.

It already addresses the points from the review above:

  • No retry: it makes the file writable before the single _wunlink, the shape the maintainer asked for on #2342.
  • It restores the read-only attribute when the unlink fails, for example on a file held open without delete sharing.
  • Its test variables (lockedPosix, lockedKernel) don't clash with readOnly.

Validation so far on #2601:

  • Linux: MarcZX100 on b5f5362d.
  • Windows: @harmsluis on b5f5362d. The new checks fail without the Open.cpp change and pass with it.
  • Windows: my own run with the held-open-file case.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6097368837 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2651#issuecomment-6097368837). Originally posted by [reyani-dev](https://github.com/reyani-dev) on 2026-10-10T12:13:56Z. --- Hi @sridhar777911, I reported this as #2601. It has a one-commit fix, [`AchrafReyani:fix/unlink-readonly`](https://github.com/AchrafReyani/AnyPS5/tree/fix/unlink-readonly) (fbf0ec0a, +19/−1 in `Open.cpp` and `GuestFilesystem.cpp`), which I can't open as a PR because of the intake check. Rather than have two versions, feel free to take that commit into this PR, or reset this branch onto it, so there's one scoped change. It already addresses the points from the review above: - No retry: it makes the file writable before the single `_wunlink`, the shape the maintainer asked for on #2342. - It restores the read-only attribute when the unlink fails, for example on a file held open without delete sharing. - Its test variables (`lockedPosix`, `lockedKernel`) don't clash with `readOnly`. Validation so far on #2601: - Linux: MarcZX100 on `b5f5362d`. - Windows: @harmsluis on `b5f5362d`. The new checks fail without the `Open.cpp` change and pass with it. - Windows: my own run with the held-open-file case.
oneandonlydean commented 2026-10-10 19:17:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-10T19:17:54Z.


Please reset this branch onto fbf0ec0a from #2601. As it is, it carries 70 unrelated commits, guest_filesystem_tests doesn't build (readOnly is declared twice in main()), and NativeUnlink retries _wunlink after EACCES, which isn't allowed (see #2342). Otherwise I'll close it.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6101234906 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2651#issuecomment-6101234906). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-10T19:17:54Z. --- Please reset this branch onto fbf0ec0a from #2601. As it is, it carries 70 unrelated commits, `guest_filesystem_tests` doesn't build (`readOnly` is declared twice in `main()`), and `NativeUnlink` retries `_wunlink` after `EACCES`, which isn't allowed (see #2342). Otherwise I'll close it.
adriadam10 commented 2026-10-11 09:58:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T09:58:05Z.


Closing: the fix for #2601 has already landed via #2910 (single commit, rebased on main).

This branch also can't be merged as is:

  • It carries 70 unrelated commits / 234 files (+6,050/−448) for a one-topic unlink fix (CONTRIBUTING: one topic per PR).
  • It conflicts with main.
  • guest_filesystem_tests doesn't build (readOnly is declared twice in main() of GuestFilesystem.cpp).
  • NativeUnlink retries _wunlink after EACCES, which was ruled out in #2342.

@oneandonlydean asked for a reset onto fbf0ec0a and there was no update. Welcome to open a new PR from a clean branch for anything else.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6107809417 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2651#issuecomment-6107809417). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T09:58:05Z. --- Closing: the fix for #2601 has already landed via #2910 (single commit, rebased on `main`). This branch also can't be merged as is: - It carries 70 unrelated commits / 234 files (+6,050/−448) for a one-topic unlink fix (CONTRIBUTING: one topic per PR). - It conflicts with `main`. - `guest_filesystem_tests` doesn't build (`readOnly` is declared twice in `main()` of `GuestFilesystem.cpp`). - `NativeUnlink` retries `_wunlink` after `EACCES`, which was ruled out in #2342. @oneandonlydean asked for a reset onto fbf0ec0a and there was no update. Welcome to open a new PR from a clean branch for anything else.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!2651
No description provided.