fix(libkernel): open directories whose host path ends in a separator on Windows #4513

Merged
winstrex merged 1 commit from upstream-pr/4513 into main 2026-10-12 18:30:27 +00:00
winstrex commented 2026-10-12 14:00:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by winstrex on 2026-10-12T14:00:48Z.


What

On Windows, sceKernelOpen with O_DIRECTORY fails with 0x80020002 (ENOENT) on an existing directory when the resolved host path ends in a separator. That covers the guest root /, ., <dir>/ and <dir>/... Only <dir> without a trailing separator opens.

Found with The Pathless (PPSA01825). At boot, Unreal calls sceKernelOpen("/app0/..", O_DIRECTORY) to list the parent of the content root. On Windows the call returned ENOENT and getdents was never reached:

[src/Open.cpp sceKernelOpen] path=/app0/.. flags=0x20000 nativeFlags=0x8000 mode=0555
-> 0x80020002

Cause: in OpenNative (core/libs/prx/libkernel/File/src/Open.cpp), the CRT _wopen fails on a path ending in \ with ENOENT, and the fallback to File::OpenDirectoryDescriptor only runs when errno != ENOENT. A directory whose host path ends in a separator never reaches it.

Fix: when the host path has no filename, the fallback runs regardless of the errno. Trailing separators are stripped with the same loop sceKernelMkdir uses since #2819 (while (!path.has_filename() && path.has_relative_path()) path = path.parent_path()), so a host drive root such as C:\ is kept as is. The directory descriptor is then opened on the stripped path. A missing path without a trailing separator still returns ENOENT without an extra stat, and the EEXIST/EISDIR checks are unchanged. Linux is unaffected because open(2) accepts a trailing slash on a directory.

This follows the earlier trailing-separator fixes in libkernel: #2743/#2819 (sceKernelMkdir) and #2300 (sceKernelStat).

Tested

Windows 11, WinLibs GCC 15.2.

  • guest_filesystem now opens /, ., <dir>/ and <dir>/.. with O_DIRECTORY and calls sceKernelGetdents until it returns 0. Without the change in Open.cpp the test fails at the first open (guest errno 2); with it, it passes.
  • ctest -R "guest_|file|kernel": 346 tests passed.
  • Linux and Windows: full CI on my fork, green: https://github.com/winstrex/AnyPS5/actions/runs/38255891314
  • The Pathless (PPSA01825, own dump), Windows: open("/app0/..", O_DIRECTORY) now returns a descriptor and the listing completes (getdents returns 88 bytes, then 0). The title still stops right after it, in the same place as before: Project file not found: ../../../Pathless/Pathless.uproject, then PS5 Out of Memory / LowLevelFatalError ... Ran out of memory allocating 5565054976 bytes. That stop has a different cause and is not addressed here: it is the PlayGo chunk enumeration described for Sifu on #3209 and #3238 (the dump has no chunk table, the title queries ever-increasing chunk ids, and the request size is the same).

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
  • Unblocks: none (PPSA01825 gets past this open but stops right after it, see Tested)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4830501841 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4513). Originally posted by [winstrex](https://github.com/winstrex) on 2026-10-12T14:00:48Z. --- ### What On Windows, `sceKernelOpen` with `O_DIRECTORY` fails with `0x80020002` (ENOENT) on an existing directory when the resolved host path ends in a separator. That covers the guest root `/`, `.`, `<dir>/` and `<dir>/..`. Only `<dir>` without a trailing separator opens. Found with The Pathless (PPSA01825). At boot, Unreal calls `sceKernelOpen("/app0/..", O_DIRECTORY)` to list the parent of the content root. On Windows the call returned ENOENT and `getdents` was never reached: ``` [src/Open.cpp sceKernelOpen] path=/app0/.. flags=0x20000 nativeFlags=0x8000 mode=0555 -> 0x80020002 ``` Cause: in `OpenNative` (`core/libs/prx/libkernel/File/src/Open.cpp`), the CRT `_wopen` fails on a path ending in `\` with ENOENT, and the fallback to `File::OpenDirectoryDescriptor` only runs when `errno != ENOENT`. A directory whose host path ends in a separator never reaches it. Fix: when the host path has no filename, the fallback runs regardless of the errno. Trailing separators are stripped with the same loop `sceKernelMkdir` uses since #2819 (`while (!path.has_filename() && path.has_relative_path()) path = path.parent_path()`), so a host drive root such as `C:\` is kept as is. The directory descriptor is then opened on the stripped path. A missing path without a trailing separator still returns ENOENT without an extra `stat`, and the `EEXIST`/`EISDIR` checks are unchanged. Linux is unaffected because `open(2)` accepts a trailing slash on a directory. This follows the earlier trailing-separator fixes in libkernel: #2743/#2819 (`sceKernelMkdir`) and #2300 (`sceKernelStat`). ### Tested Windows 11, WinLibs GCC 15.2. - `guest_filesystem` now opens `/`, `.`, `<dir>/` and `<dir>/..` with `O_DIRECTORY` and calls `sceKernelGetdents` until it returns 0. Without the change in `Open.cpp` the test fails at the first open (guest errno 2); with it, it passes. - `ctest -R "guest_|file|kernel"`: 346 tests passed. - Linux and Windows: full CI on my fork, green: https://github.com/winstrex/AnyPS5/actions/runs/38255891314 - The Pathless (PPSA01825, own dump), Windows: `open("/app0/..", O_DIRECTORY)` now returns a descriptor and the listing completes (`getdents` returns 88 bytes, then 0). The title still stops right after it, in the same place as before: `Project file not found: ../../../Pathless/Pathless.uproject`, then `PS5 Out of Memory` / `LowLevelFatalError ... Ran out of memory allocating 5565054976 bytes`. That stop has a different cause and is not addressed here: it is the PlayGo chunk enumeration described for Sifu on #3209 and #3238 (the dump has no chunk table, the title queries ever-increasing chunk ids, and the request size is the same). ### 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] Unblocks: none (PPSA01825 gets past this open but stops right after it, see Tested) - [x] AI-assisted: yes
xXPBSXx commented 2026-10-12 16:31:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-12T16:31:33Z.


Windows test: head a47178b86 merged onto current main d592d54e1 (clean merge, no conflicts). Windows 10, MinGW GCC (WinLibs), Ninja Release, -j2: full build 0 errors; ctest with the filter guest_filesystem: guest_filesystem passed (1 test(s), 0 failed); python tools/check_conventions.py --base upstream/main passed. I did not run the new tests against main without the change.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6128391921 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4513#issuecomment-6128391921). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-12T16:31:33Z. --- Windows test: head `a47178b86` merged onto current `main` `d592d54e1` (clean merge, no conflicts). Windows 10, MinGW GCC (WinLibs), Ninja Release, `-j2`: full build 0 errors; ctest with the filter `guest_filesystem`: guest_filesystem passed (1 test(s), 0 failed); `python tools/check_conventions.py --base upstream/main` passed. I did not run the new tests against `main` without the change. AI-assisted (Claude Code).
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!4513
No description provided.