fix(libkernel): report lookup errors from truncate instead of ENOENT #4817

Closed
Gashrod1 wants to merge 1 commit from upstream-pr/4817 into main
Gashrod1 commented 2026-10-12 22:51:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Gashrod1 on 2026-10-12T22:51:34Z.


What

sceKernelTruncate_nid_postfix (and truncate_nid_postfix, which goes through it) reported every failed lookup as ENOENT: file/, file/inner and a symbolic link loop all failed with ENOENT, and guest_filesystem asserted ENOENT for sized.txt/missing. FreeBSD's kern_truncate looks the path up with namei(LOOKUP | FOLLOW) and returns the lookup error: ENOTDIR for a trailing slash on a non-directory or for a component that is not a directory (sys/kern/vfs_lookup.c), ELOOP for a link loop.

When the path does not resolve, sceKernelTruncate now returns ENOTDIR if a prefix is a non-directory (HasNonDirectoryPrefix, as sceKernelMkdir and sceKernelRmdir already do) or if the path has a trailing separator and names an existing file; otherwise the status error goes through FilesystemError (ENOENT for a missing path, ELOOP for a loop). A path with a trailing separator that resolves to a file also fails with ENOTDIR instead of being truncated. The ENOTDIR decision does not depend on what the host's lookup reports.

guest_truncate checks sized.txt/ and sized.txt/inner (ENOTDIR through truncate and sceKernelTruncate) on every platform and a link to itself (ELOOP) in the existing non-Windows block; guest_filesystem now expects ENOTDIR for sized.txt/missing. Both fail on main and pass with the change.

Tested

Linux (Arch, GCC), Release, BUILD_TESTING=ON, based on main ee4962190: guest_truncate and guest_filesystem abort on main and pass with the change (3 runs); full build and full ctest pass. Windows (WinLibs MinGW-w64 GCC 15.2.0 r7, NVIDIA RTX 5060), Release, BUILD_TESTING=ON: full build and full ctest pass (1018 tests, the same 7 skipped as on main). No title or homebrew run.

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:4835922949 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4817). Originally posted by [Gashrod1](https://github.com/Gashrod1) on 2026-10-12T22:51:34Z. --- ### What `sceKernelTruncate_nid_postfix` (and `truncate_nid_postfix`, which goes through it) reported every failed lookup as ENOENT: `file/`, `file/inner` and a symbolic link loop all failed with ENOENT, and `guest_filesystem` asserted ENOENT for `sized.txt/missing`. FreeBSD's `kern_truncate` looks the path up with `namei(LOOKUP | FOLLOW)` and returns the lookup error: ENOTDIR for a trailing slash on a non-directory or for a component that is not a directory (`sys/kern/vfs_lookup.c`), ELOOP for a link loop. When the path does not resolve, `sceKernelTruncate` now returns ENOTDIR if a prefix is a non-directory (`HasNonDirectoryPrefix`, as `sceKernelMkdir` and `sceKernelRmdir` already do) or if the path has a trailing separator and names an existing file; otherwise the status error goes through `FilesystemError` (ENOENT for a missing path, ELOOP for a loop). A path with a trailing separator that resolves to a file also fails with ENOTDIR instead of being truncated. The ENOTDIR decision does not depend on what the host's lookup reports. `guest_truncate` checks `sized.txt/` and `sized.txt/inner` (ENOTDIR through `truncate` and `sceKernelTruncate`) on every platform and a link to itself (ELOOP) in the existing non-Windows block; `guest_filesystem` now expects ENOTDIR for `sized.txt/missing`. Both fail on `main` and pass with the change. ### Tested Linux (Arch, GCC), Release, `BUILD_TESTING=ON`, based on `main` `ee4962190`: `guest_truncate` and `guest_filesystem` abort on `main` and pass with the change (3 runs); full build and full `ctest` pass. Windows (WinLibs MinGW-w64 GCC 15.2.0 r7, NVIDIA RTX 5060), Release, `BUILD_TESTING=ON`: full build and full `ctest` pass (1018 tests, the same 7 skipped as on `main`). No title or homebrew run. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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
oneandonlydean commented 2026-10-14 02:37:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T02:37:43Z.


Closing: no title is known to reach this. With the queue at 700+ open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6159643624 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4817#issuecomment-6159643624). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-14T02:37:43Z. --- Closing: no title is known to reach this. With the queue at 700+ open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.

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!4817
No description provided.