fix(libkernel): return EPERM when unlinking a directory #2289

Merged
reyani-dev merged 1 commit from upstream-pr/2289 into main 2026-10-10 04:46:41 +00:00
reyani-dev commented 2026-10-09 14:44:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by reyani-dev on 2026-10-09T14:44:34Z.


What

FreeBSD's unlink(2) fails with EPERM when the path is a directory. sceKernelUnlink passed the host error through, so the guest got a different code on each host:

Host unlink("dir") on main FreeBSD
Windows (_wunlink) EACCES (13), measured EPERM (1)
Linux (unlink) EISDIR (21), per unlink(2) EPERM (1)

sceKernelUnlink now checks the path with symlink_status before unlinking and returns EPERM for a directory. A symbolic link to a directory is still unlinked, as on FreeBSD. If the path can't be inspected, the check doesn't match and the native unlink reports its own error as before. unlink (the POSIX wrapper) goes through sceKernelUnlink, so both are covered.

Tested

Windows 11, WinLibs GCC 15.2.0 r7, Release, -DBUILD_TESTING=ON:

  • Two checks in guest_filesystem_tests, next to the other unlink checks: unlink(dir) returns -1 with errno 1 and leaves the directory in place, and sceKernelUnlink(dir) returns 0x80020001. On main the first fails with guest errno 13.
  • ctest -R "guest_filesystem|guest_kernel_sync|guest_file": 3/3 passed.
  • tools/check_conventions.py passes, and tools/pr_overlap.py --branch reports no overlap. It also merges cleanly with #2144, #2170, #1628, #1777, #1755, #1764, #2193 and my #2260, which touch the same files (git merge-tree). #1727 already conflicts with main on its own (TechnicalDebt.md).

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

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4801977558 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2289). Originally posted by [reyani-dev](https://github.com/reyani-dev) on 2026-10-09T14:44:34Z. --- ### What FreeBSD's `unlink(2)` fails with `EPERM` when the path is a directory. `sceKernelUnlink` passed the host error through, so the guest got a different code on each host: | Host | `unlink("dir")` on `main` | FreeBSD | |---|---|---| | Windows (`_wunlink`) | `EACCES` (13), measured | `EPERM` (1) | | Linux (`unlink`) | `EISDIR` (21), per `unlink(2)` | `EPERM` (1) | `sceKernelUnlink` now checks the path with `symlink_status` before unlinking and returns `EPERM` for a directory. A symbolic link to a directory is still unlinked, as on FreeBSD. If the path can't be inspected, the check doesn't match and the native `unlink` reports its own error as before. `unlink` (the POSIX wrapper) goes through `sceKernelUnlink`, so both are covered. ### Tested Windows 11, WinLibs GCC 15.2.0 r7, Release, `-DBUILD_TESTING=ON`: - Two checks in `guest_filesystem_tests`, next to the other `unlink` checks: `unlink(dir)` returns -1 with errno 1 and leaves the directory in place, and `sceKernelUnlink(dir)` returns `0x80020001`. On `main` the first fails with `guest errno 13`. - `ctest -R "guest_filesystem|guest_kernel_sync|guest_file"`: 3/3 passed. - `tools/check_conventions.py` passes, and `tools/pr_overlap.py --branch` reports no overlap. It also merges cleanly with #2144, #2170, #1628, #1777, #1755, #1764, #2193 and my #2260, which touch the same files (`git merge-tree`). #1727 already conflicts with `main` on its own (`TechnicalDebt.md`). ### 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](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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 🤖 Generated with [Claude Code](https://claude.com/claude-code)
reyani-dev commented 2026-10-09 15:14:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by reyani-dev on 2026-10-09T15:14:19Z.


Full Linux and Windows builds and tests for this head (27516327), using the project's Build workflow. I can't start the upstream manual run, so I ran the same build.yml in my fork through a mirror PR. Like the upstream run, the jobs check out the PR head merged into current main (d70b8998):

Job Result
linux success; full build, ctest: 516/516 passed
windows success; full build, ctest: 507/507 passed
relinker (Linux, Windows, macOS) success

Run: https://github.com/AchrafReyani/AnyPS5/actions/runs/37946468349

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6083731638 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2289#issuecomment-6083731638). Originally posted by [reyani-dev](https://github.com/reyani-dev) on 2026-10-09T15:14:19Z. --- Full Linux and Windows builds and tests for this head (`27516327`), using the project's Build workflow. I can't start the upstream manual run, so I ran the same `build.yml` in my fork through a mirror PR. Like the upstream run, the jobs check out the PR head merged into current `main` (`d70b8998`): | Job | Result | |---|---| | [linux](https://github.com/AchrafReyani/AnyPS5/actions/runs/37946468349/job/113873947737) | success; full build, `ctest`: 516/516 passed | | [windows](https://github.com/AchrafReyani/AnyPS5/actions/runs/37946468349/job/113873947698) | success; full build, `ctest`: 507/507 passed | | relinker (Linux, Windows, macOS) | success | Run: https://github.com/AchrafReyani/AnyPS5/actions/runs/37946468349
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!2289
No description provided.