fix(libkernel): report lookup errors when creating through a trailing slash #10319

Merged
MarrasFederico merged 4 commits from upstream-pr/10319 into main 2026-11-02 22:34:53 +00:00
MarrasFederico commented 2026-10-23 17:34:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarrasFederico on 2026-10-23T17:34:25Z.


What

open and sceKernelOpen with O_CREAT on a missing final name followed by / reported the host error (EISDIR on Linux; the existing debt records EINVAL on Windows). FreeBSD 11.4 lookup rejects this case with ENOENT, because only a directory can be created through a trailing slash.

After a native open fails with EISDIR or EINVAL, a trailing-separator creation request now checks the path's status. A missing path reports guest ENOENT; metadata errors are mapped explicitly, including ELOOP. Other requests and existing directories keep their original result. This applies to ordinary and aliased guest paths, with both plain and exclusive creation covered. Failed requests create no file. The resolved debt item is removed; a concise replacement records the non-atomic host lookup/open sequence and that this has not been measured on a PS5.

#8544, which edited the neighbouring fcntl debt line, is merged, and the branch is rebased onto current main as one commit. #8658 adds a macOS existing-directory check at the native-open call; this correction is placed after the Windows directory fallback to avoid the insertion conflict.

Tested

Ubuntu 26.04.1, kernel 7.0.0-38, GCC 15.2.0, Release, BUILD_TESTING=ON. Windows was not compiled here; BunnyFl's Windows run is below. No title was run.

  • Full build succeeds after rebasing onto current main (7b0f1b6809).
  • Ten path, filesystem and application-archive guest tests pass: ctest --test-dir build -R 'guest_(path|filesystem|app_archive)' --output-on-failure -j12.
  • With the new assertions and main's Open.cpp, guest_path_errors and guest_filesystem fail (checked again on the rebased head). Removing the lookup correction fails again; losing explicit metadata-error propagation fails the symlink-loop regression. The restored implementation passes.
  • Windows (BunnyFl's run, Windows 11, WinLibs GCC 15.2.0, head merged onto main c8d34aa8f4):
    • guest_filesystem passes 3 of 3, and fails 3 of 3 at the new aliased check with only the test lines applied.
    • A local probe turns _wopen's EINVAL into ENOENT for plain and aliased paths, with and without O_EXCL, and creates no file.
    • Existing directories, an existing file and non-create opens keep main's results.
    • guest_path_errors is built only under if(UNIX) (it uses ::symlink), and the symlink-loop case was not run on Windows: that account cannot create symlinks.
  • python3 tools/check_conventions.py --base origin/main and whitespace checks pass.
  • Open and closed function/file searches, related issues and main history were checked. No PR implements this missing-name correction; #9109 covers an existing non-directory path instead.
  • The local pr_overlap --branch scan flagged only the adjacent fcntl debt line of #8544, now merged. It finds no code conflict. Its not-compared PRs were inspected manually: #4630, #5021, #6044, #6149, #6740, #6830, #6936, #7049, #7088, #7105, #7121, #7149, #7201, #7202, #7464, #7509, #7565, #7653, #8010, #8520, #8553, #9074, #9133, #9256, #9284, #9293, #9297, #9302, #9557, #9561, #9566, #9575, #9669 and #9693. The macOS patches concern existing directories, the other Open.cpp edits concern notifications, archives, argument copying or seek/write, and the test edits cover other scenarios. The debt edits concern other behaviors; #9256/#9557/#9561/#9566 also edit the neighboring long fcntl paragraph and may need a documentation rebase after the declared order. #6044 deletes an obsolete whole test file and requires rebasing independently.

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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4986800058 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10319). Originally posted by [MarrasFederico](https://github.com/MarrasFederico) on 2026-10-23T17:34:25Z. --- ### What `open` and `sceKernelOpen` with `O_CREAT` on a missing final name followed by `/` reported the host error (`EISDIR` on Linux; the existing debt records `EINVAL` on Windows). [FreeBSD 11.4 lookup](https://github.com/freebsd/freebsd-src/blob/8c639945a44588f6cfdddfb057bb5aad88735da0/sys/kern/vfs_lookup.c#L947-L951) rejects this case with `ENOENT`, because only a directory can be created through a trailing slash. After a native open fails with `EISDIR` or `EINVAL`, a trailing-separator creation request now checks the path's status. A missing path reports guest `ENOENT`; metadata errors are mapped explicitly, including `ELOOP`. Other requests and existing directories keep their original result. This applies to ordinary and aliased guest paths, with both plain and exclusive creation covered. Failed requests create no file. The resolved debt item is removed; a concise replacement records the non-atomic host lookup/open sequence and that this has not been measured on a PS5. #8544, which edited the neighbouring `fcntl` debt line, is merged, and the branch is rebased onto current `main` as one commit. #8658 adds a macOS existing-directory check at the native-open call; this correction is placed after the Windows directory fallback to avoid the insertion conflict. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Ubuntu 26.04.1, kernel 7.0.0-38, GCC 15.2.0, Release, `BUILD_TESTING=ON`. Windows was not compiled here; BunnyFl's Windows run is below. No title was run. - Full build succeeds after rebasing onto current `main` (7b0f1b6809). - Ten path, filesystem and application-archive guest tests pass: `ctest --test-dir build -R 'guest_(path|filesystem|app_archive)' --output-on-failure -j12`. - With the new assertions and `main`'s `Open.cpp`, `guest_path_errors` and `guest_filesystem` fail (checked again on the rebased head). Removing the lookup correction fails again; losing explicit metadata-error propagation fails the symlink-loop regression. The restored implementation passes. - **Windows** ([BunnyFl's run](https://github.com/boykopovar/AnyPS5/pull/10319#issuecomment-6390145418), Windows 11, WinLibs GCC 15.2.0, head merged onto `main` `c8d34aa8f4`): - `guest_filesystem` passes 3 of 3, and fails 3 of 3 at the new aliased check with only the test lines applied. - A local probe turns `_wopen`'s `EINVAL` into `ENOENT` for plain and aliased paths, with and without `O_EXCL`, and creates no file. - Existing directories, an existing file and non-create opens keep `main`'s results. - `guest_path_errors` is built only under `if(UNIX)` (it uses `::symlink`), and the symlink-loop case was not run on Windows: that account cannot create symlinks. - `python3 tools/check_conventions.py --base origin/main` and whitespace checks pass. - Open and closed function/file searches, related issues and main history were checked. No PR implements this missing-name correction; #9109 covers an existing non-directory path instead. - The local `pr_overlap --branch` scan flagged only the adjacent `fcntl` debt line of #8544, now merged. It finds no code conflict. Its not-compared PRs were inspected manually: #4630, #5021, #6044, #6149, #6740, #6830, #6936, #7049, #7088, #7105, #7121, #7149, #7201, #7202, #7464, #7509, #7565, #7653, #8010, #8520, #8553, #9074, #9133, #9256, #9284, #9293, #9297, #9302, #9557, #9561, #9566, #9575, #9669 and #9693. The macOS patches concern existing directories, the other `Open.cpp` edits concern notifications, archives, argument copying or seek/write, and the test edits cover other scenarios. The debt edits concern other behaviors; #9256/#9557/#9561/#9566 also edit the neighboring long `fcntl` paragraph and may need a documentation rebase after the declared order. #6044 deletes an obsolete whole test file and requires rebasing independently. ### 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 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 <!-- #PR, or none --> - [x] Fixes: none <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: none <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: n/a <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes <!-- yes / no -->
harisibrar1 commented 2026-10-24 01:05:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-24T01:05:21Z.

Review: COMMENTED


Checked against main 11d6efa06c and FreeBSD 11.4 lookup() (vfs_lookup.c, the TRAILINGSLASH/WILLBEDIR → ENOENT block and the TRAILINGSLASH on a non-directory → ENOTDIR block):

  • The behaviour matches lookup(): a missing final name with a trailing slash gives ENOENT, existing directories keep EISDIR/EEXIST, and an existing file with a trailing slash still takes the host's ENOTDIR path. Open.cpp is unchanged on main since your base, so the fix is still needed.
  • git merge-tree against current main now conflicts in docs/dev/debt/libkernel.md, where main rewrote the neighbouring fcntl line. #8544 is already merged (85f2f2d478), so the declared merge order is satisfied and only a rebase is needed.
  • The new /parent-test-mount/missing-create/ check in GuestFilesystem.cpp also runs on Windows, and the PR says Windows wasn't compiled. A Windows CI or local run of guest_filesystem would confirm that _wopen's EINVAL is corrected there as intended; I couldn't run it myself.

Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5635991803 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10319#pullrequestreview-5635991803). Originally posted by [harisibrar1](https://github.com/harisibrar1) on 2026-10-24T01:05:21Z. **Review:** COMMENTED --- Checked against main 11d6efa06c and FreeBSD 11.4 `lookup()` (vfs_lookup.c, the `TRAILINGSLASH`/`WILLBEDIR` → `ENOENT` block and the `TRAILINGSLASH` on a non-directory → `ENOTDIR` block): - The behaviour matches `lookup()`: a missing final name with a trailing slash gives `ENOENT`, existing directories keep `EISDIR`/`EEXIST`, and an existing file with a trailing slash still takes the host's `ENOTDIR` path. Open.cpp is unchanged on main since your base, so the fix is still needed. - `git merge-tree` against current main now conflicts in `docs/dev/debt/libkernel.md`, where main rewrote the neighbouring `fcntl` line. #8544 is already merged (85f2f2d478), so the declared merge order is satisfied and only a rebase is needed. - The new `/parent-test-mount/missing-create/` check in `GuestFilesystem.cpp` also runs on Windows, and the PR says Windows wasn't compiled. A Windows CI or local run of `guest_filesystem` would confirm that `_wopen`'s `EINVAL` is corrected there as intended; I couldn't run it myself. Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
MarcZX10 commented 2026-10-24 21:11:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T21:11:38Z.

Review: CHANGES_REQUESTED


The Linux tests exercise the missing-name, exclusive-create, no-file-created, and symlink-loop cases, and the lookup correction is appropriately limited to O_CREAT after EISDIR/EINVAL. Two integration checks remain before approval:

  • Rebase onto current main, as required by CONTRIBUTING.md. This branch is based on aeeaefa, 6,761 commits behind current main; the nearby fcntl debt history and the existing GuestFilesystem test code have since moved.
  • Please run guest_filesystem and guest_path_errors on Windows. The change specifically maps Windows _wopen's EINVAL, but Windows was not compiled for the reported runs and the hosted Windows product job is skipped for this path. Confirm both aliased and plain paths, including the symlink-loop case where the platform permits it, on the rebased head.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5640045047 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10319#pullrequestreview-5640045047). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T21:11:38Z. **Review:** CHANGES_REQUESTED --- The Linux tests exercise the missing-name, exclusive-create, no-file-created, and symlink-loop cases, and the lookup correction is appropriately limited to `O_CREAT` after `EISDIR`/`EINVAL`. Two integration checks remain before approval: - Rebase onto current `main`, as required by CONTRIBUTING.md. This branch is based on `aeeaefa`, 6,761 commits behind current `main`; the nearby `fcntl` debt history and the existing `GuestFilesystem` test code have since moved. - Please run `guest_filesystem` and `guest_path_errors` on Windows. The change specifically maps Windows `_wopen`'s `EINVAL`, but Windows was not compiled for the reported runs and the hosted Windows product job is skipped for this path. Confirm both aliased and plain paths, including the symlink-loop case where the platform permits it, on the rebased head.
MarcZX10 commented 2026-10-29 08:39:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T08:39:06Z.

Review: APPROVED


Reviewed the updated head 182c8be21791edf8acac4dcb0868163e6eeb54a4. It now includes current base 10bec5c322eb581b3e959e6c7e18bcf09e068e96, resolving the requested rebase/conflict. The Windows workflow passes on this exact head; the earlier Linux build and focused guest path/filesystem/archive tests passed on the immediately preceding rebased tree, and the latest merge is reported as main plus the debt-file conflict resolution. The Windows report also covers plain and aliased missing paths, both create modes, no-file-created behavior, and unchanged existing-path behavior. guest_path_errors and the symlink-loop case were not run on Windows because the target requires Unix symlinks. I did not rerun Linux locally on the final merge commit.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5694910363 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10319#pullrequestreview-5694910363). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-29T08:39:06Z. **Review:** APPROVED --- Reviewed the updated head `182c8be21791edf8acac4dcb0868163e6eeb54a4`. It now includes current base `10bec5c322eb581b3e959e6c7e18bcf09e068e96`, resolving the requested rebase/conflict. The Windows workflow passes on this exact head; the earlier Linux build and focused guest path/filesystem/archive tests passed on the immediately preceding rebased tree, and the latest merge is reported as main plus the debt-file conflict resolution. The Windows report also covers plain and aliased missing paths, both create modes, no-file-created behavior, and unchanged existing-path behavior. `guest_path_errors` and the symlink-loop case were not run on Windows because the target requires Unix symlinks. I did not rerun Linux locally on the final merge commit.
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!10319
No description provided.