fix(libkernel): report ELOOP and ENAMETOOLONG from mkdir, rmdir and truncate #6942

Merged
AlexOfTheForest merged 2 commits from upstream-pr/6942 into main 2026-10-20 15:05:44 +00:00
AlexOfTheForest commented 2026-10-16 20:35:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AlexOfTheForest on 2026-10-16T20:35:40Z.


What

#6648 and #6992 made open, unlink and stat report a symbolic link loop (ELOOP, 62) and an over-long name (ENAMETOOLONG, 63). sceKernelMkdir, sceKernelRmdir and sceKernelTruncate still lost them. Their std::filesystem queries fail with filename_too_long or too_many_symbolic_link_levels, and the code went on to answer ENOENT, EIO or ENOTDIR. A PathLookupFailure check after those queries now returns the guest error, as FreeBSD's namei does. The POSIX mkdir, rmdir and truncate wrappers set the same errno.

Two commits:

  • fix(libkernel): report ELOOP and ENAMETOOLONG from mkdir and rmdir, which also adds guest_path_errors. The test covers open, unlink, stat, rename, mkdir and rmdir with a self-referencing link, a two-link cycle, a 300-byte name, and each of those as a path prefix. It is UNIX-only because it creates symbolic links.
  • fix(libkernel): report ELOOP and ENAMETOOLONG from truncate.

Tested

Linux x86_64: guest_path_errors, guest_filesystem, guest_posix_scalar_io, guest_kernel_fcntl and guest_record_lock_owners passed 3 of 3 runs. Run against unmodified main, guest_path_errors fails only at the mkdir, rmdir and truncate checks; open, unlink, stat and rename already pass there. tools/check_conventions.py --base upstream/main passes. Not run on Windows or macOS.

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
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4893969547 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6942). Originally posted by [AlexOfTheForest](https://github.com/AlexOfTheForest) on 2026-10-16T20:35:40Z. --- ### What #6648 and #6992 made open, unlink and stat report a symbolic link loop (`ELOOP`, 62) and an over-long name (`ENAMETOOLONG`, 63). `sceKernelMkdir`, `sceKernelRmdir` and `sceKernelTruncate` still lost them. Their `std::filesystem` queries fail with `filename_too_long` or `too_many_symbolic_link_levels`, and the code went on to answer `ENOENT`, `EIO` or `ENOTDIR`. A `PathLookupFailure` check after those queries now returns the guest error, as FreeBSD's `namei` does. The POSIX `mkdir`, `rmdir` and `truncate` wrappers set the same errno. Two commits: - `fix(libkernel): report ELOOP and ENAMETOOLONG from mkdir and rmdir`, which also adds `guest_path_errors`. The test covers open, unlink, stat, rename, mkdir and rmdir with a self-referencing link, a two-link cycle, a 300-byte name, and each of those as a path prefix. It is UNIX-only because it creates symbolic links. - `fix(libkernel): report ELOOP and ENAMETOOLONG from truncate`. ### Tested Linux x86_64: `guest_path_errors`, `guest_filesystem`, `guest_posix_scalar_io`, `guest_kernel_fcntl` and `guest_record_lock_owners` passed 3 of 3 runs. Run against unmodified `main`, `guest_path_errors` fails only at the mkdir, rmdir and truncate checks; open, unlink, stat and rename already pass there. `tools/check_conventions.py --base upstream/main` passes. Not run on Windows or macOS. ### 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 - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-16 20:44:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-16T20:44:03Z.


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 7530 core/libs/prx/libkernel/File/src/Stdio.cpp L1410

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 4972 core/libs/prx/libkernel/CMakeLists.txt
PR 5021 core/libs/prx/libkernel/CMakeLists.txt
core/libs/prx/libkernel/File/src/Stdio.cpp
PR 6044 core/libs/prx/libkernel/CMakeLists.txt
PR 6226 core/libs/prx/libkernel/CMakeLists.txt
PR 6469 core/libs/prx/libkernel/CMakeLists.txt
PR 6658 core/libs/prx/libkernel/CMakeLists.txt
PR 6893 core/libs/prx/libkernel/CMakeLists.txt
PR 6977 core/libs/prx/libkernel/CMakeLists.txt
core/libs/prx/libkernel/File/src/Stdio.cpp
PR 7201 core/libs/prx/libkernel/CMakeLists.txt
core/libs/prx/libkernel/File/src/Stdio.cpp
PR 7464 core/libs/prx/libkernel/CMakeLists.txt
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6224341625 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6942#issuecomment-6224341625). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-16T20:44:03Z. --- <!-- 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 7530](https://www.github.com/boykopovar/AnyPS5/pull/7530) | `core/libs/prx/libkernel/File/src/Stdio.cpp` [L1410](https://github.com/boykopovar/AnyPS5/blob/7526640c3c1c5ea236c33b43b854681e8d169745/core/libs/prx/libkernel/File/src/Stdio.cpp#L1410) | | | 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 4972](https://www.github.com/boykopovar/AnyPS5/pull/4972) | `core/libs/prx/libkernel/CMakeLists.txt` | | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/libs/prx/libkernel/CMakeLists.txt`<br>`core/libs/prx/libkernel/File/src/Stdio.cpp` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/prx/libkernel/CMakeLists.txt` | | [PR 6226](https://www.github.com/boykopovar/AnyPS5/pull/6226) | `core/libs/prx/libkernel/CMakeLists.txt` | | [PR 6469](https://www.github.com/boykopovar/AnyPS5/pull/6469) | `core/libs/prx/libkernel/CMakeLists.txt` | | [PR 6658](https://www.github.com/boykopovar/AnyPS5/pull/6658) | `core/libs/prx/libkernel/CMakeLists.txt` | | [PR 6893](https://www.github.com/boykopovar/AnyPS5/pull/6893) | `core/libs/prx/libkernel/CMakeLists.txt` | | [PR 6977](https://www.github.com/boykopovar/AnyPS5/pull/6977) | `core/libs/prx/libkernel/CMakeLists.txt`<br>`core/libs/prx/libkernel/File/src/Stdio.cpp` | | [PR 7201](https://www.github.com/boykopovar/AnyPS5/pull/7201) | `core/libs/prx/libkernel/CMakeLists.txt`<br>`core/libs/prx/libkernel/File/src/Stdio.cpp` | | [PR 7464](https://www.github.com/boykopovar/AnyPS5/pull/7464) | `core/libs/prx/libkernel/CMakeLists.txt` |
cadenasynyster commented 2026-10-17 01:21:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by cadenasynyster on 2026-10-17T01:21:43Z.


Windows check, since the PR lists Windows as untested and the Windows CI job is skipped on this head. guest_path_errors is UNIX-only, so this covers build and regressions, not the new error paths themselves:

Windows 11 10.0.26200.9711 (NTFS), WinLibs GCC 15.2.0 posix UCRT r7, Release, BUILD_TESTING=ON, head 4b979592d merged onto main f3263dfbf (clean merge, no new build errors).

  • guest_path_errors: not registered on Windows, as intended (ctest -N lists 0).
  • Existing file tests (filesystem, posix_scalar_io, directories, dup, aio, access, append, kernel_fcntl, kernel_app_archive): 11/11 pass with ctest --parallel 8.
  • On the guest_kernel_fcntl aborts you mentioned: 20/20 passes here (--repeat until-fail:20 --parallel 8), so I could not reproduce it on Windows.

Not checked: ELOOP/ENAMETOOLONG behaviour on Windows itself.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6227895075 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6942#issuecomment-6227895075). Originally posted by [cadenasynyster](https://github.com/cadenasynyster) on 2026-10-17T01:21:43Z. --- Windows check, since the PR lists Windows as untested and the Windows CI job is skipped on this head. guest_path_errors is UNIX-only, so this covers build and regressions, not the new error paths themselves: Windows 11 10.0.26200.9711 (NTFS), WinLibs GCC 15.2.0 posix UCRT r7, Release, BUILD_TESTING=ON, head 4b979592d merged onto main f3263dfbf (clean merge, no new build errors). - guest_path_errors: not registered on Windows, as intended (ctest -N lists 0). - Existing file tests (filesystem, posix_scalar_io, directories, dup, aio, access, append, kernel_fcntl, kernel_app_archive): 11/11 pass with ctest --parallel 8. - On the guest_kernel_fcntl aborts you mentioned: 20/20 passes here (--repeat until-fail:20 --parallel 8), so I could not reproduce it on Windows. Not checked: ELOOP/ENAMETOOLONG behaviour on Windows itself. AI-assisted: yes
cadenasynyster commented 2026-10-17 01:39:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by cadenasynyster on 2026-10-17T01:39:43Z.


Follow-up on Windows behaviour, since guest_path_errors does not run there: I ran GuestPathErrors.cpp on Windows locally, with its symlinks created through CreateSymbolicLinkA (MinGW has no symlink()). The new mapping is not reached on Windows, and the Windows results are the same on main, so this PR neither causes nor fixes them:

Call Windows (main and this PR) Expected
sceKernelStat("loop") process abort (FillFileStat throws) ELOOP
sceKernelOpen("loop") EINVAL ELOOP
sceKernelOpen("loop/inside") ENOENT ELOOP
open / stat / mkdir, 300-char name ENOENT ENAMETOOLONG

I filed the abort separately as #6983, with repro and details. Just noting it here so the Windows gap is visible next to this fix.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6228058896 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6942#issuecomment-6228058896). Originally posted by [cadenasynyster](https://github.com/cadenasynyster) on 2026-10-17T01:39:43Z. --- Follow-up on Windows behaviour, since guest_path_errors does not run there: I ran GuestPathErrors.cpp on Windows locally, with its symlinks created through CreateSymbolicLinkA (MinGW has no symlink()). The new mapping is not reached on Windows, and the Windows results are the same on main, so this PR neither causes nor fixes them: | Call | Windows (main and this PR) | Expected | |---|---|---| | `sceKernelStat("loop")` | process abort (FillFileStat throws) | `ELOOP` | | `sceKernelOpen("loop")` | `EINVAL` | `ELOOP` | | `sceKernelOpen("loop/inside")` | `ENOENT` | `ELOOP` | | open / stat / mkdir, 300-char name | `ENOENT` | `ENAMETOOLONG` | I filed the abort separately as #6983, with repro and details. Just noting it here so the Windows gap is visible next to this fix. AI-assisted: yes
MarcZX10 commented 2026-10-17 01:44:08 +00:00 (Migrated from github.com)

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


Issue #6983 reports that this abort persists even with this PR applied: Windows std::filesystem::status does not expose the self-link failure here, then _wstat64 fails inside FillFileStat and its exception escapes. This appears to be a separate native-stat failure path from the filesystem lookup errors handled here. I am evaluating a narrow TryFillFileStat follow-up for that case; please let me know if you see a merge-order or ownership concern, since both changes touch Open.cpp.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6228099147 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6942#issuecomment-6228099147). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-17T01:44:08Z. --- Issue #6983 reports that this abort persists even with this PR applied: Windows `std::filesystem::status` does not expose the self-link failure here, then `_wstat64` fails inside `FillFileStat` and its exception escapes. This appears to be a separate native-stat failure path from the filesystem lookup errors handled here. I am evaluating a narrow `TryFillFileStat` follow-up for that case; please let me know if you see a merge-order or ownership concern, since both changes touch `Open.cpp`.
MarcZX10 commented 2026-10-17 02:01:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T02:01:34Z.


NevesHenry, the author of #6648, confirmed on #6983 that this is a separate native-stat failure and should merge with the path-status change in either order. This follow-up adds TryFillFileStat for the later _wstat64 failure in sceKernelStat; it does not reuse code from either open PR. I propose Depends on: none because the change works on current main and should compose either way. AlexOfTheForest, could you confirm you have no ownership or merge-order concern with that follow-up?

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6228252884 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6942#issuecomment-6228252884). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-17T02:01:34Z. --- NevesHenry, the author of #6648, confirmed on #6983 that this is a separate native-stat failure and should merge with the path-status change in either order. This follow-up adds `TryFillFileStat` for the later `_wstat64` failure in `sceKernelStat`; it does not reuse code from either open PR. I propose `Depends on: none` because the change works on current main and should compose either way. AlexOfTheForest, could you confirm you have no ownership or merge-order concern with that follow-up?
AlexOfTheForest commented 2026-10-17 09:44:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AlexOfTheForest on 2026-10-17T09:44:27Z.


@MarcZX100 No ownership or merge-order concern from my side — go ahead with the TryFillFileStat follow-up for #6983. The two changes are independent (this PR only changes which errno the lookups report; #6983 is the native stat failure path on Windows), so either can merge first and the other rebases. Confirming: Depends on: none.

@cadenasynyster thanks for the Windows runs and the table. Windows returning EINVAL/ENOENT for loops and long names is unchanged by this PR; the guest_path_errors test is UNIX-only for that reason. Mapping those Windows cases is a separate follow-up.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6232432233 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6942#issuecomment-6232432233). Originally posted by [AlexOfTheForest](https://github.com/AlexOfTheForest) on 2026-10-17T09:44:27Z. --- @MarcZX100 No ownership or merge-order concern from my side — go ahead with the TryFillFileStat follow-up for #6983. The two changes are independent (this PR only changes which errno the lookups report; #6983 is the native stat failure path on Windows), so either can merge first and the other rebases. Confirming: Depends on: none. @cadenasynyster thanks for the Windows runs and the table. Windows returning EINVAL/ENOENT for loops and long names is unchanged by this PR; the guest_path_errors test is UNIX-only for that reason. Mapping those Windows cases is a separate follow-up.
AlexOfTheForest commented 2026-10-18 12:04:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AlexOfTheForest on 2026-10-18T12:04:53Z.


No ownership or merge-order concern from my side: the #6983 abort is a separate path, so your TryFillFileStat follow-up can merge before or after this one. "Depends on: none" is right. I also rebased this branch onto current main (a one-line CMakeLists.txt conflict with the record-lock test; both entries kept).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6249698816 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6942#issuecomment-6249698816). Originally posted by [AlexOfTheForest](https://github.com/AlexOfTheForest) on 2026-10-18T12:04:53Z. --- No ownership or merge-order concern from my side: the #6983 abort is a separate path, so your TryFillFileStat follow-up can merge before or after this one. "Depends on: none" is right. I also rebased this branch onto current main (a one-line CMakeLists.txt conflict with the record-lock test; both entries kept).
adriadam10 commented 2026-10-19 11:24:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T11:24:47Z.

Review: CHANGES_REQUESTED


Thanks for the measurements. This now conflicts with main in Open.cpp and Stdio.cpp, and not mechanically:

  • #6648 (merged today) already maps ELOOP/ENAMETOOLONG for open, unlink and stat through FilesystemError. The new File::SceErrorFromHostErrno / IsPathLookupError duplicates that, and the refactor + open/unlink + stat commits conflict with it (Open.cpp:172, Open.cpp:357).
  • sceKernelRename was rewritten on main (RenameGuestPath_nid_no_patch, Stdio.cpp:1326), so the rename commit no longer applies.
  • sceKernelMkdir, sceKernelRmdir and sceKernelTruncate on main still treat a failed std::filesystem lookup as ENOENT, so that part of the PR is still needed.

Could you rebase and reduce the PR to what main is still missing (mkdir/rmdir/truncate, using the existing FilesystemError mapping rather than a new helper), re-check rename against the new implementation, and trim guest_path_errors to the cases that fail on main? Please confirm which test rows fail without the change.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5570817275 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6942#pullrequestreview-5570817275). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-19T11:24:47Z. **Review:** CHANGES_REQUESTED --- Thanks for the measurements. This now conflicts with `main` in `Open.cpp` and `Stdio.cpp`, and not mechanically: - #6648 (merged today) already maps `ELOOP`/`ENAMETOOLONG` for open, unlink and stat through `FilesystemError`. The new `File::SceErrorFromHostErrno` / `IsPathLookupError` duplicates that, and the `refactor` + open/unlink + stat commits conflict with it (`Open.cpp:172`, `Open.cpp:357`). - `sceKernelRename` was rewritten on `main` (`RenameGuestPath_nid_no_patch`, `Stdio.cpp:1326`), so the rename commit no longer applies. - `sceKernelMkdir`, `sceKernelRmdir` and `sceKernelTruncate` on `main` still treat a failed `std::filesystem` lookup as `ENOENT`, so that part of the PR is still needed. Could you rebase and reduce the PR to what `main` is still missing (mkdir/rmdir/truncate, using the existing `FilesystemError` mapping rather than a new helper), re-check rename against the new implementation, and trim `guest_path_errors` to the cases that fail on `main`? Please confirm which test rows fail without the change.
AlexOfTheForest commented 2026-10-19 20:46:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AlexOfTheForest on 2026-10-19T20:46:40Z.


Rebased onto current main and narrowed: #6648 and #6992 already landed the open/unlink/stat part of this, so I dropped my refactor and those commits. What remains is mkdir, rmdir and truncate, which still answered ENOENT/EIO/ENOTDIR for a link loop or an over-long name on main (the test fails there exactly at those checks), plus the test that covers all of these paths. Depends on: none.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6276957333 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6942#issuecomment-6276957333). Originally posted by [AlexOfTheForest](https://github.com/AlexOfTheForest) on 2026-10-19T20:46:40Z. --- Rebased onto current main and narrowed: #6648 and #6992 already landed the open/unlink/stat part of this, so I dropped my refactor and those commits. What remains is mkdir, rmdir and truncate, which still answered ENOENT/EIO/ENOTDIR for a link loop or an over-long name on main (the test fails there exactly at those checks), plus the test that covers all of these paths. Depends on: none.
adriadam10 commented 2026-10-20 15:11:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-20T15:11:06Z.


Rebased onto current main; one conflict in sceKernelTruncate (it now uses NotFoundError_nid_no_patch), resolved by keeping that and placing the PathLookupFailure check before the exists check. guest_path_errors and the libkernel/libs ctest scope pass on the rebased head; merged.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6294161381 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6942#issuecomment-6294161381). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-20T15:11:06Z. --- Rebased onto current `main`; one conflict in `sceKernelTruncate` (it now uses `NotFoundError_nid_no_patch`), resolved by keeping that and placing the `PathLookupFailure` check before the `exists` check. `guest_path_errors` and the libkernel/libs ctest scope pass on the rebased head; merged.
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!6942
No description provided.