fix(libkernel): report ENAMETOOLONG and ELOOP from open, unlink and stat #6648

Merged
NevesHenry merged 1 commit from upstream-pr/6648 into main 2026-10-19 08:15:07 +00:00
NevesHenry commented 2026-10-16 01:44:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by NevesHenry on 2026-10-16T01:44:20Z.


What

SceErrorFromErrno in File/src/Open.cpp passed host errno values 1 to 34 through unchanged and turned every other value into EIO. On Linux, ENAMETOOLONG is 36 and ELOOP is 40, so both became EIO (0x80020005). FreeBSD returns ENAMETOOLONG = 63 (0x8002003F) and ELOOP = 62 (0x8002003E). sceKernelStat returned ENOENT for both, because a failed std::filesystem::status reads as "doesn't exist".

sceKernelMkdir already gets these right because Stdio.cpp has its own copy of the mapping. The existing test shows the mismatch: sceKernelMkdir on a 300-character name returns 0x8002003F, and sceKernelOpen on the same path returns 0x80020005.

Values on main and with this change (Linux; a 300-character leaf and a symlink that points to itself):

Call main This PR
sceKernelOpen (read, and O_CREAT), too-long name 0x80020005 0x8002003F
open, too-long name -1, errno 5 -1, errno 63
sceKernelUnlink / unlink, too-long name 0x80020005 / errno 5 0x8002003F / errno 63
sceKernelStat / stat, too-long name 0x80020002 / errno 2 0x8002003F / errno 63
sceKernelOpen / open, symlink loop 0x80020005 / errno 5 0x8002003E / errno 62
sceKernelStat / stat, symlink loop 0x80020002 / errno 2 0x8002003E / errno 62
sceKernelUnlink / unlink, loop/leaf 0x80020005 / errno 5 0x8002003E / errno 62

Change (File/src/Open.cpp, 2 lines):

  • SceErrorFromErrno still passes 1 to 34 through. Other values now go through FilesystemError (libc/include/FilesystemError.hpp), the std::errc mapping that ResolvePathError_nid_no_patch already uses for path errors. That maps name-too-long to 63, loop to 62 and not-empty to 66, and everything else to EIO as before. This affects sceKernelOpen, OpenInDirectory_nid_no_patch (openat), sceKernelUnlink and SceIoErrorFromErrno. SceIoErrorFromErrno keeps its own EAGAIN, EDEADLK, EDQUOT and EOVERFLOW cases, and read, write and lseek can't fail with the three newly mapped values, so their results don't change.
  • sceKernelStat returns ENAMETOOLONG and ELOOP when the status query fails with them. Other failures still return ENOENT. I kept this narrow so that host-only errors, such as an invalid-name error on Windows, don't start reaching titles.
  • The POSIX open, creat, unlink and stat wrappers in Stdio.cpp convert the sceKernel* results, so they get the same errno values. lstat and mkdir already used the correct mapping.

I didn't merge the two SceErrorFromErrno copies into one. That would mean editing Stdio.cpp, which 11 open PRs change, and reusing FilesystemError avoids adding a third copy of these values.

Tested

Linux: WSL2, Ubuntu 22.04, glibc 2.35, GCC 13.4, Release. No title run.

  • guest_filesystem: the new checks are next to the existing 300-character mkdir check, inside its #ifndef _WIN32 block (the symlinks and the long name are tested only off Windows). They cover each row of the table and end by removing the loop link with unlink.
    • On main: fails at the first new check (sceKernelOpen on the long name returns 0x80020005).
    • With this change: passes.
  • The 50 ctest tests whose executables call sceKernelOpen/Unlink/Stat, open, unlink, stat, openat or fopen (guest_*, file_streams), run with -j8 6 times: 5 runs passed 50/50. In 1 run guest_kernel_fcntl aborted after 6.3 s while other builds were loading the machine. It passed alone and in the next 5 full runs. It only expects error codes below 35, so I don't think this change caused it.
  • Windows: not built. FilesystemError and SceKernelError were already in scope in Open.cpp. With MinGW's errno values, ENAMETOOLONG (38) and ENOTEMPTY (41) now map to 63 and 66 instead of EIO. That is untested.
  • tools/check_conventions.py --base origin/main passes, and git diff --check is clean.

Overlap: tools/pr_overlap.py needs git merge-tree --write-tree (git 2.38+), so I checked by hand with git merge-tree against the open PRs that change Open.cpp, GuestFilesystem.cpp or FilesystemError.hpp: #5831, #5835, #5938, #6132, #6228, #6234, #6484 and #6541. None of them changes this mapping, and this PR adds no conflicts. #5835 adds code above the status call in sceKernelStat, and the two merge cleanly.

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 under Silent stubs in their library's technical debt file
  • 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
  • Unblocks: none
  • GPUs tested: n/a (libkernel file errors)
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4882210653 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6648). Originally posted by [NevesHenry](https://github.com/NevesHenry) on 2026-10-16T01:44:20Z. --- ### What `SceErrorFromErrno` in `File/src/Open.cpp` passed host errno values 1 to 34 through unchanged and turned every other value into `EIO`. On Linux, `ENAMETOOLONG` is 36 and `ELOOP` is 40, so both became `EIO` (0x80020005). FreeBSD returns `ENAMETOOLONG` = 63 (0x8002003F) and `ELOOP` = 62 (0x8002003E). `sceKernelStat` returned `ENOENT` for both, because a failed `std::filesystem::status` reads as "doesn't exist". `sceKernelMkdir` already gets these right because `Stdio.cpp` has its own copy of the mapping. The existing test shows the mismatch: `sceKernelMkdir` on a 300-character name returns 0x8002003F, and `sceKernelOpen` on the same path returns 0x80020005. Values on `main` and with this change (Linux; a 300-character leaf and a symlink that points to itself): | Call | `main` | This PR | |---|---|---| | `sceKernelOpen` (read, and `O_CREAT`), too-long name | 0x80020005 | 0x8002003F | | `open`, too-long name | -1, errno 5 | -1, errno 63 | | `sceKernelUnlink` / `unlink`, too-long name | 0x80020005 / errno 5 | 0x8002003F / errno 63 | | `sceKernelStat` / `stat`, too-long name | 0x80020002 / errno 2 | 0x8002003F / errno 63 | | `sceKernelOpen` / `open`, symlink loop | 0x80020005 / errno 5 | 0x8002003E / errno 62 | | `sceKernelStat` / `stat`, symlink loop | 0x80020002 / errno 2 | 0x8002003E / errno 62 | | `sceKernelUnlink` / `unlink`, `loop/leaf` | 0x80020005 / errno 5 | 0x8002003E / errno 62 | Change (`File/src/Open.cpp`, 2 lines): - `SceErrorFromErrno` still passes 1 to 34 through. Other values now go through `FilesystemError` (`libc/include/FilesystemError.hpp`), the `std::errc` mapping that `ResolvePathError_nid_no_patch` already uses for path errors. That maps name-too-long to 63, loop to 62 and not-empty to 66, and everything else to `EIO` as before. This affects `sceKernelOpen`, `OpenInDirectory_nid_no_patch` (`openat`), `sceKernelUnlink` and `SceIoErrorFromErrno`. `SceIoErrorFromErrno` keeps its own `EAGAIN`, `EDEADLK`, `EDQUOT` and `EOVERFLOW` cases, and read, write and lseek can't fail with the three newly mapped values, so their results don't change. - `sceKernelStat` returns `ENAMETOOLONG` and `ELOOP` when the status query fails with them. Other failures still return `ENOENT`. I kept this narrow so that host-only errors, such as an invalid-name error on Windows, don't start reaching titles. - The POSIX `open`, `creat`, `unlink` and `stat` wrappers in `Stdio.cpp` convert the `sceKernel*` results, so they get the same errno values. `lstat` and `mkdir` already used the correct mapping. I didn't merge the two `SceErrorFromErrno` copies into one. That would mean editing `Stdio.cpp`, which 11 open PRs change, and reusing `FilesystemError` avoids adding a third copy of these values. ### Tested Linux: WSL2, Ubuntu 22.04, glibc 2.35, GCC 13.4, Release. No title run. - `guest_filesystem`: the new checks are next to the existing 300-character `mkdir` check, inside its `#ifndef _WIN32` block (the symlinks and the long name are tested only off Windows). They cover each row of the table and end by removing the loop link with `unlink`. - **On `main`:** fails at the first new check (`sceKernelOpen` on the long name returns 0x80020005). - **With this change:** passes. - The 50 ctest tests whose executables call `sceKernelOpen`/`Unlink`/`Stat`, `open`, `unlink`, `stat`, `openat` or `fopen` (`guest_*`, `file_streams`), run with `-j8` 6 times: 5 runs passed 50/50. In 1 run `guest_kernel_fcntl` aborted after 6.3 s while other builds were loading the machine. It passed alone and in the next 5 full runs. It only expects error codes below 35, so I don't think this change caused it. - Windows: not built. `FilesystemError` and `SceKernelError` were already in scope in `Open.cpp`. With MinGW's errno values, `ENAMETOOLONG` (38) and `ENOTEMPTY` (41) now map to 63 and 66 instead of `EIO`. That is untested. - `tools/check_conventions.py --base origin/main` passes, and `git diff --check` is clean. Overlap: `tools/pr_overlap.py` needs `git merge-tree --write-tree` (git 2.38+), so I checked by hand with `git merge-tree` against the open PRs that change `Open.cpp`, `GuestFilesystem.cpp` or `FilesystemError.hpp`: #5831, #5835, #5938, #6132, #6228, #6234, #6484 and #6541. None of them changes this mapping, and this PR adds no conflicts. #5835 adds code above the `status` call in `sceKernelStat`, and the two merge cleanly. ### 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 under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [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] Unblocks: none - [x] GPUs tested: n/a (libkernel file errors) - [x] AI-assisted: yes (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-16 02:38:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-16T02:38:31Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 6992 core/libs/prx/libkernel/File/src/Open.cpp L362

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 5021 core/libs/prx/libkernel/File/src/Open.cpp
PR 6044 core/libs/tests/GuestFilesystem.cpp
PR 6897 core/libs/tests/GuestFilesystem.cpp
PR 6936 core/libs/prx/libkernel/File/src/Open.cpp
PR 6942 core/libs/prx/libkernel/File/src/Open.cpp
PR 7121 core/libs/prx/libkernel/File/src/Open.cpp
PR 7201 core/libs/prx/libkernel/File/src/Open.cpp
PR 7299 core/libs/prx/libkernel/File/src/Open.cpp
PR 7332 core/libs/prx/libkernel/File/src/Open.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6206797669 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6648#issuecomment-6206797669). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-16T02:38:31Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | [PR 6992](https://www.github.com/boykopovar/AnyPS5/pull/6992) | `core/libs/prx/libkernel/File/src/Open.cpp` [L362](https://github.com/boykopovar/AnyPS5/blob/22e59888ce1a7a232537f68dadb02814811af3b8/core/libs/prx/libkernel/File/src/Open.cpp#L362) | | | Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/libs/prx/libkernel/File/src/Open.cpp` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/tests/GuestFilesystem.cpp` | | [PR 6897](https://www.github.com/boykopovar/AnyPS5/pull/6897) | `core/libs/tests/GuestFilesystem.cpp` | | [PR 6936](https://www.github.com/boykopovar/AnyPS5/pull/6936) | `core/libs/prx/libkernel/File/src/Open.cpp` | | [PR 6942](https://www.github.com/boykopovar/AnyPS5/pull/6942) | `core/libs/prx/libkernel/File/src/Open.cpp` | | [PR 7121](https://www.github.com/boykopovar/AnyPS5/pull/7121) | `core/libs/prx/libkernel/File/src/Open.cpp` | | [PR 7201](https://www.github.com/boykopovar/AnyPS5/pull/7201) | `core/libs/prx/libkernel/File/src/Open.cpp` | | [PR 7299](https://www.github.com/boykopovar/AnyPS5/pull/7299) | `core/libs/prx/libkernel/File/src/Open.cpp` | | [PR 7332](https://www.github.com/boykopovar/AnyPS5/pull/7332) | `core/libs/prx/libkernel/File/src/Open.cpp` |
Dextroid17 commented 2026-10-17 00:35:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-17T00:35:04Z.


Linux run of this head. Only the overlap bot has commented so far, so here is a second run on a different host.

Setup: head c6aeb7002 (merge-base with main 31cbb55d7), BUILD_TESTING=ON, Ninja, CachyOS (kernel 7.2.9), i9-11900K, GCC 16.2.1. Tests ran under env -i with only HOME and PATH set. Each arm ran ctest -V --no-tests=error -R '^guest_filesystem$' 3 times.

  • Head: passes 3 of 3.
  • Revert arm: with Open.cpp as on 31cbb55d7 and the PR's test kept, guest_filesystem fails 3 of 3 (subprocess aborted). The last call logged before the abort is sceKernelOpen on the 300-character name with flags 0, which is the first new check. The check's own failure message is not in the ctest log, so which check fired is inferred from that.
  • Merged with main at e751dd205: clean merge, passes 3 of 3. tools/check_conventions.py passes. main has since moved to f3263dfbf; it does not touch this PR's files and the PR still merges cleanly.

By reading, the expected values match FreeBSD 11.4 errno.h: ELOOP 62, ENAMETOOLONG 63, ENOTEMPTY 66.

Not checked: Windows (the new checks are inside #ifndef _WIN32, so the Windows open, unlink and stat paths for a name that is too long or a symlink loop are not tested), macOS, and PS5 hardware.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6227406279 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6648#issuecomment-6227406279). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-17T00:35:04Z. --- Linux run of this head. Only the overlap bot has commented so far, so here is a second run on a different host. **Setup:** head `c6aeb7002` (merge-base with `main` `31cbb55d7`), `BUILD_TESTING=ON`, Ninja, CachyOS (kernel 7.2.9), i9-11900K, GCC 16.2.1. Tests ran under `env -i` with only `HOME` and `PATH` set. Each arm ran `ctest -V --no-tests=error -R '^guest_filesystem$'` 3 times. - **Head:** passes 3 of 3. - **Revert arm:** with `Open.cpp` as on `31cbb55d7` and the PR's test kept, `guest_filesystem` fails 3 of 3 (subprocess aborted). The last call logged before the abort is `sceKernelOpen` on the 300-character name with flags 0, which is the first new check. The check's own failure message is not in the ctest log, so which check fired is inferred from that. - **Merged with `main` at `e751dd205`:** clean merge, passes 3 of 3. `tools/check_conventions.py` passes. `main` has since moved to `f3263dfbf`; it does not touch this PR's files and the PR still merges cleanly. By reading, the expected values match FreeBSD 11.4 [`errno.h`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/sys/errno.h#L127-L136): `ELOOP` 62, `ENAMETOOLONG` 63, `ENOTEMPTY` 66. Not checked: Windows (the new checks are inside `#ifndef _WIN32`, so the Windows open, unlink and stat paths for a name that is too long or a symlink loop are not tested), macOS, and PS5 hardware. Written with AI assistance (Claude Code). I ran the builds and tests above on my machine. AI-assisted: yes
MarcZX10 commented 2026-10-17 01:40:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T01:40:13Z.


The new Windows repro in #6983 exposes a platform gap in the stat portion of this change: on Windows, std::filesystem::status does not return the loop error on this path, so execution reaches FillFileStat and the failing _wstat64 throws an uncaught std::runtime_error. The added symlink-loop assertions are under #ifndef _WIN32, so this path is not exercised on Windows. Could you clarify whether you intend this PR to cover the self-referencing-link sceKernelStat case? If not, I can keep the platform-specific follow-up separate and make the dependency explicit.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6228063343 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6648#issuecomment-6228063343). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-17T01:40:13Z. --- The new Windows repro in #6983 exposes a platform gap in the stat portion of this change: on Windows, `std::filesystem::status` does not return the loop error on this path, so execution reaches `FillFileStat` and the failing `_wstat64` throws an uncaught `std::runtime_error`. The added symlink-loop assertions are under `#ifndef _WIN32`, so this path is not exercised on Windows. Could you clarify whether you intend this PR to cover the self-referencing-link `sceKernelStat` case? If not, I can keep the platform-specific follow-up separate and make the dependency explicit.
NevesHenry commented 2026-10-17 02:00:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by NevesHenry on 2026-10-17T02:00:45Z.


No, #6648 doesn't cover it. The abort is on main too (the control run in #6983 shows that), and the stat change here only handles the case where std::filesystem::status itself reports ENAMETOOLONG/ELOOP, which Windows doesn't reach for the self-link. Please go ahead with the follow-up as a separate PR; no ownership concern from me. The change here is the status error check just above the FillFileStat call in sceKernelStat, so it should merge with yours in either order.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6228244909 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6648#issuecomment-6228244909). Originally posted by [NevesHenry](https://github.com/NevesHenry) on 2026-10-17T02:00:45Z. --- No, #6648 doesn't cover it. The abort is on main too (the control run in #6983 shows that), and the stat change here only handles the case where std::filesystem::status itself reports ENAMETOOLONG/ELOOP, which Windows doesn't reach for the self-link. Please go ahead with the follow-up as a separate PR; no ownership concern from me. The change here is the status error check just above the FillFileStat call in sceKernelStat, so it should merge with yours in either order.
LeandroLP23 commented 2026-10-18 16:44:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-18T16:44:29Z.


Windows run, since the description lists Windows as not built. Windows 11 26300, Ryzen AI 7 350, WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON. Build: main 6efb7261b with #6648, #7559, #7496, #7497 and #7498 merged together (each merge clean, built once).

  • The build is clean, and guest_filesystem and guest_kernel_fcntl pass 3 runs of 3.
  • The new ENAMETOOLONG and ELOOP checks in GuestFilesystem.cpp sit inside #ifndef _WIN32, so on Windows this covers the build and no regression in the existing checks, not the new error paths.

AI-assisted

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6252461103 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6648#issuecomment-6252461103). Originally posted by [LeandroLP23](https://github.com/LeandroLP23) on 2026-10-18T16:44:29Z. --- Windows run, since the description lists Windows as not built. Windows 11 26300, Ryzen AI 7 350, WinLibs GCC 15.2.0 r7, Release, `BUILD_TESTING=ON`. Build: `main` `6efb7261b` with #6648, #7559, #7496, #7497 and #7498 merged together (each merge clean, built once). - The build is clean, and `guest_filesystem` and `guest_kernel_fcntl` pass 3 runs of 3. - The new `ENAMETOOLONG` and `ELOOP` checks in `GuestFilesystem.cpp` sit inside `#ifndef _WIN32`, so on Windows this covers the build and no regression in the existing checks, not the new error paths. AI-assisted
adriadam10 commented 2026-10-19 08:15:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T08:15:49Z.


Checked the SceErrorFromErrno change and the sceKernelStat error check against FilesystemError, and the new guest_filesystem checks (they fail on main at the first sceKernelOpen check, as the Linux revert run above also showed). Merging through the queue.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6262785779 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6648#issuecomment-6262785779). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-19T08:15:49Z. --- Checked the `SceErrorFromErrno` change and the `sceKernelStat` error check against `FilesystemError`, and the new `guest_filesystem` checks (they fail on `main` at the first `sceKernelOpen` check, as the Linux revert run above also showed). Merging through the queue.
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!6648
No description provided.