fix(libkernel): report ENOTDIR from stat for a file with a trailing slash #2300

Merged
reyani-dev merged 2 commits from upstream-pr/2300 into main 2026-10-10 06:27:28 +00:00
reyani-dev commented 2026-10-09 15:01:07 +00:00 (Migrated from github.com)

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


What

On FreeBSD, stat("file/") fails with ENOTDIR: a trailing slash asks for a directory. On main:

  • Windows: std::filesystem::exists("file/") is true (Win32 ignores the slash), then _wstat64("file/") fails, and File::FillFileStat throws FillFileStat: stat failed for ..., which aborts the title.
  • Linux: stat reports ENOTDIR, which std::filesystem::exists reads as "not found", so the guest got ENOENT.

sceKernelStat now takes the std::filesystem::status once and returns ENOTDIR if the host reports not_a_directory, or if the guest path ends in / and the target exists but isn't a directory. A missing path is still ENOENT, and stat("dir/") still succeeds. stat (the POSIX wrapper) goes through sceKernelStat, so both are covered.

The same trailing slash on other calls returns the wrong error without aborting: open("file/") and unlink("file/") give EINVAL instead of ENOTDIR on Windows. open is being reworked by several open PRs (#1628, #1777, #2144, #2170), and unlink is in my #2289, so I kept this to stat.

Tested

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

  • New checks in guest_filesystem_tests, next to the other stat checks:

    • stat("present.txt/") returns -1 with errno 20;
    • sceKernelStat("present.txt/") returns 0x80020014;
    • stat("<dir>/") succeeds and reports a directory.

    On main the test process aborts with FillFileStat: stat failed.

  • ctest -E "^agc_|video_out": 249/249 passed, including guest_path_case, which also uses sceKernelStat.

  • tools/check_conventions.py passes, and tools/pr_overlap.py --branch reports no overlap. It merges cleanly with the open PRs that touch Open.cpp and GuestFilesystem.cpp (#2144, #2170, #1628, #1777, #1755, #1764, #2193, #2115, #1624, #2086, #1620, #2129) and with my #2260 and #2289. #1616 already conflicts with main on its own.

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:4802169959 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2300). Originally posted by [reyani-dev](https://github.com/reyani-dev) on 2026-10-09T15:01:07Z. --- ### What On FreeBSD, `stat("file/")` fails with `ENOTDIR`: a trailing slash asks for a directory. On `main`: - **Windows:** `std::filesystem::exists("file/")` is true (Win32 ignores the slash), then `_wstat64("file/")` fails, and `File::FillFileStat` throws `FillFileStat: stat failed for ...`, which **aborts the title**. - **Linux:** `stat` reports `ENOTDIR`, which `std::filesystem::exists` reads as "not found", so the guest got `ENOENT`. `sceKernelStat` now takes the `std::filesystem::status` once and returns `ENOTDIR` if the host reports `not_a_directory`, or if the guest path ends in `/` and the target exists but isn't a directory. A missing path is still `ENOENT`, and `stat("dir/")` still succeeds. `stat` (the POSIX wrapper) goes through `sceKernelStat`, so both are covered. The same trailing slash on other calls returns the wrong error without aborting: `open("file/")` and `unlink("file/")` give `EINVAL` instead of `ENOTDIR` on Windows. `open` is being reworked by several open PRs (#1628, #1777, #2144, #2170), and `unlink` is in my #2289, so I kept this to `stat`. ### Tested Windows 11, WinLibs GCC 15.2.0 r7, Release, `-DBUILD_TESTING=ON`: - New checks in `guest_filesystem_tests`, next to the other `stat` checks: - `stat("present.txt/")` returns -1 with errno 20; - `sceKernelStat("present.txt/")` returns `0x80020014`; - `stat("<dir>/")` succeeds and reports a directory. On `main` the test process aborts with `FillFileStat: stat failed`. - `ctest -E "^agc_|video_out"`: 249/249 passed, including `guest_path_case`, which also uses `sceKernelStat`. - `tools/check_conventions.py` passes, and `tools/pr_overlap.py --branch` reports no overlap. It merges cleanly with the open PRs that touch `Open.cpp` and `GuestFilesystem.cpp` (#2144, #2170, #1628, #1777, #1755, #1764, #2193, #2115, #1624, #2086, #1620, #2129) and with my #2260 and #2289. #1616 already conflicts with `main` on its own. ### 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 16:30:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by reyani-dev on 2026-10-09T16:30:32Z.


Full Linux and Windows builds and tests for this head (d99a6ceb), 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/37948551554

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6085002788 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2300#issuecomment-6085002788). Originally posted by [reyani-dev](https://github.com/reyani-dev) on 2026-10-09T16:30:32Z. --- Full Linux and Windows builds and tests for this head (`d99a6ceb`), 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/37948551554/job/113881116571) | success; full build, `ctest`: 516/516 passed | | [windows](https://github.com/AchrafReyani/AnyPS5/actions/runs/37948551554/job/113881116556) | success; full build, `ctest`: 507/507 passed | | relinker (Linux, Windows, macOS) | success | Run: https://github.com/AchrafReyani/AnyPS5/actions/runs/37948551554
reyani-dev commented 2026-10-09 16:30:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by reyani-dev on 2026-10-09T16:30:40Z.


Full Linux and Windows builds and tests for this head (d99a6ceb), 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/37948551554

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6085004725 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2300#issuecomment-6085004725). Originally posted by [reyani-dev](https://github.com/reyani-dev) on 2026-10-09T16:30:40Z. --- Full Linux and Windows builds and tests for this head (`d99a6ceb`), 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/37948551554/job/113881116571) | success; full build, `ctest`: 516/516 passed | | [windows](https://github.com/AchrafReyani/AnyPS5/actions/runs/37948551554/job/113881116556) | success; full build, `ctest`: 507/507 passed | | relinker (Linux, Windows, macOS) | success | Run: https://github.com/AchrafReyani/AnyPS5/actions/runs/37948551554
adriadam10 commented 2026-10-10 06:15:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T06:15:45Z.


Checked on Linux merged onto current main: guest_filesystem aborted at the lstat checks, because the new directory check overwrote status, which the lstat checks (added by #1624) reuse. I pushed one commit that uses a separate FileStat dirStatus for it. After that, build and the scoped ctest (73 tests) are green, and the new stat checks fail when the Open.cpp change is reverted.

  • Windows path (_wstat64) not run here; relying on your fork run, which predates #1624.
    Merging once CI is green.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6094560332 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2300#issuecomment-6094560332). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T06:15:45Z. --- Checked on Linux merged onto current `main`: `guest_filesystem` aborted at the `lstat` checks, because the new directory check overwrote `status`, which the `lstat` checks (added by #1624) reuse. I pushed one commit that uses a separate `FileStat dirStatus` for it. After that, build and the scoped ctest (73 tests) are green, and the new `stat` checks fail when the `Open.cpp` change is reverted. - Windows path (`_wstat64`) not run here; relying on your fork run, which predates #1624. Merging once CI is green.
reyani-dev commented 2026-10-10 06:34:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by reyani-dev on 2026-10-10T06:34:43Z.


Thanks @adriadam10, the separate dirStatus is right.

I checked the Windows (_wstat64) side with your commit (c1b714f2) merged onto current main 03bf8ff3 (Windows 11, WinLibs GCC 15.2.0, Release):

  • guest_filesystem passes 3/3 (--repeat until-fail:3), including the new trailing-slash checks and the lstat ones;
  • ctest -E "^agc_|video_out" passes 335/335.

A fresh full Linux and Windows build of this head is running and will be posted here.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6094700523 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2300#issuecomment-6094700523). Originally posted by [reyani-dev](https://github.com/reyani-dev) on 2026-10-10T06:34:43Z. --- Thanks @adriadam10, the separate `dirStatus` is right. I checked the Windows (`_wstat64`) side with your commit (c1b714f2) merged onto current `main` 03bf8ff3 (Windows 11, WinLibs GCC 15.2.0, Release): - `guest_filesystem` passes 3/3 (`--repeat until-fail:3`), including the new trailing-slash checks and the `lstat` ones; - `ctest -E "^agc_|video_out"` passes 335/335. A fresh full Linux and Windows build of this head is running and will be posted here.
reyani-dev commented 2026-10-10 06:53:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by reyani-dev on 2026-10-10T06:53:49Z.


Full Linux and Windows builds and tests for this head (c1b714f2), 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 (03bf8ff3):

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

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

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6094851424 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2300#issuecomment-6094851424). Originally posted by [reyani-dev](https://github.com/reyani-dev) on 2026-10-10T06:53:49Z. --- Full Linux and Windows builds and tests for this head (`c1b714f2`), 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` (`03bf8ff3`): | Job | Result | |---|---| | [linux](https://github.com/AchrafReyani/AnyPS5/actions/runs/38031421856/job/114153023453) | success; full build, `ctest`: 628/628 passed | | [windows](https://github.com/AchrafReyani/AnyPS5/actions/runs/38031421856/job/114153023503) | success; full build, `ctest`: 636/636 passed | | relinker (Linux, Windows, macOS) | success | Run: https://github.com/AchrafReyani/AnyPS5/actions/runs/38031421856
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!2300
No description provided.