fix(libkernel): fail unlink, remove, rename and open of a file named with a trailing slash with ENOTDIR on Windows #8680

Closed
xXPBSXx wants to merge 2 commits from upstream-pr/8680 into main
xXPBSXx commented 2026-10-20 20:53:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-20T20:53:17Z.


What

A name that ends in / must be a directory. FreeBSD 11.4 fails the lookup with ENOTDIR otherwise (vfs_cache_lookup, sys/kern/vfs_cache.c:2104-2105). On Windows ResolveAlias dropped the slash for paths under a mount alias (it kept it only off Windows, #4681), and unlink/sceKernelUnlink, remove, rename and open/sceKernelOpen never asked whether a name with a slash is a non-directory, so they failed with ENOENT, EINVAL or EIO. ResolveAlias now keeps the slash on every host, and a shared helper (NamesNonDirectoryWithSlash_nid_no_patch) makes the four calls answer ENOTDIR (the source, and an existing source's destination, in rename). The trailing-slash block of guest_filesystem, which was compiled only off Windows, now runs on Windows.
Fixes #8679

Scope note: this changes the guest path resolver (General.cpp, ResolveAlias) and the kernel-style lookup of unlink, remove, rename and open, not the stdio/printf formatting that the console implements with Dinkumware; remove and rename follow the kernel lookup like the merged #8200 and #8199. git merge-tree against upstream/main, #8626, #8522, #8603, #8663, #8312 and #5528 is clean; pr_overlap was not run.

Tested

Windows 10 (19045), MinGW-w64 GCC 15.2.0, Release, -j4, on upstream/main 26740077bd + this commit:

  • guest_filesystem: fails at the first trailing-slash check (guest errno 2) with the code taken back to main and the block enabled, passes with the change (3 of 3 runs).
  • The tests whose sources call the path resolver, unlink, remove, rename or open (65 test targets, 87 ctest entries): 85 pass, 2 were not run (guest_memory_pool_stats, guest_fstatvfs_conversion; their executables were not built, unrelated).
  • python tools/check_conventions.py --base upstream/main: passes.
  • Not tested: Linux, macOS, a console, a title run. lstat, access, chmod, truncate, utimes, readlink, fopen and opendir still answer ENOENT or EINVAL for file/ on Windows; they are left for follow-ups. Earlier attempts: #5165, #5266 (closed).

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; no silent stubs added
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • AI-assisted: yes

AI-assisted (Claude Code).

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4942347307 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8680). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-20T20:53:17Z. --- ### What A name that ends in `/` must be a directory. FreeBSD 11.4 fails the lookup with `ENOTDIR` otherwise (`vfs_cache_lookup`, sys/kern/vfs_cache.c:2104-2105). On Windows `ResolveAlias` dropped the slash for paths under a mount alias (it kept it only off Windows, #4681), and `unlink`/`sceKernelUnlink`, `remove`, `rename` and `open`/`sceKernelOpen` never asked whether a name with a slash is a non-directory, so they failed with `ENOENT`, `EINVAL` or `EIO`. `ResolveAlias` now keeps the slash on every host, and a shared helper (`NamesNonDirectoryWithSlash_nid_no_patch`) makes the four calls answer `ENOTDIR` (the source, and an existing source's destination, in `rename`). The trailing-slash block of `guest_filesystem`, which was compiled only off Windows, now runs on Windows. Fixes #8679 Scope note: this changes the guest path resolver (`General.cpp`, `ResolveAlias`) and the kernel-style lookup of `unlink`, `remove`, `rename` and `open`, not the stdio/printf formatting that the console implements with Dinkumware; `remove` and `rename` follow the kernel lookup like the merged #8200 and #8199. `git merge-tree` against `upstream/main`, #8626, #8522, #8603, #8663, #8312 and #5528 is clean; `pr_overlap` was not run. ### Tested Windows 10 (19045), MinGW-w64 GCC 15.2.0, Release, `-j4`, on upstream/main 26740077bd + this commit: - `guest_filesystem`: fails at the first trailing-slash check (`guest errno 2`) with the code taken back to main and the block enabled, passes with the change (3 of 3 runs). - The tests whose sources call the path resolver, `unlink`, `remove`, `rename` or `open` (65 test targets, 87 ctest entries): 85 pass, 2 were not run (`guest_memory_pool_stats`, `guest_fstatvfs_conversion`; their executables were not built, unrelated). - `python tools/check_conventions.py --base upstream/main`: passes. - Not tested: Linux, macOS, a console, a title run. `lstat`, `access`, `chmod`, `truncate`, `utimes`, `readlink`, `fopen` and `opendir` still answer ENOENT or EINVAL for `file/` on Windows; they are left for follow-ups. Earlier attempts: #5165, #5266 (closed). ### 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 - [x] Unimplemented paths throw; no silent stubs added - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source (none added) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: none - [x] AI-assisted: yes AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-10-20 20:57:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-20T20:57:30Z.

Review: COMMENTED


One related trailing-slash case appears to fall through: with file a regular file, NamesNonDirectoryWithSlash_nid_no_patch("file/child/") strips the final slash to file/child, where std::filesystem::status reports not-found plus an error. exists(status) is false, so the helper returns false even though an earlier component is a regular file; the Windows operation may then map that to ENOENT instead of ENOTDIR. HasNonDirectoryPrefix_nid_no_patch(native) already walks existing parent components and looks suitable as the fallback when the named path itself is not found. Could you add a nested case (at least open and one removal path) and use that fallback?

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5591636623 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8680#pullrequestreview-5591636623). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-20T20:57:30Z. **Review:** COMMENTED --- One related trailing-slash case appears to fall through: with `file` a regular file, `NamesNonDirectoryWithSlash_nid_no_patch("file/child/")` strips the final slash to `file/child`, where `std::filesystem::status` reports not-found plus an error. `exists(status)` is false, so the helper returns false even though an earlier component is a regular file; the Windows operation may then map that to `ENOENT` instead of `ENOTDIR`. `HasNonDirectoryPrefix_nid_no_patch(native)` already walks existing parent components and looks suitable as the fallback when the named path itself is not found. Could you add a nested case (at least `open` and one removal path) and use that fallback?
github-actions[bot] commented 2026-10-20 21:03:16 +00:00 (Migrated from github.com)

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


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 5021 core/libs/prx/libc/src/General.cpp
core/libs/prx/libc/src/Rename.cpp
core/libs/prx/libkernel/File/src/Open.cpp
PR 6044 core/libs/tests/GuestFilesystem.cpp
PR 6226 core/libs/prx/libc/src/General.cpp
PR 6879 core/libs/prx/libc/src/General.cpp
PR 6936 core/libs/prx/libkernel/File/src/Open.cpp
PR 7121 core/libs/prx/libkernel/File/src/Open.cpp
PR 7201 core/libs/prx/libc/src/General.cpp
core/libs/prx/libc/src/Rename.cpp
core/libs/prx/libkernel/File/src/Open.cpp
PR 7530 core/libs/prx/libkernel/File/src/Open.cpp
core/libs/tests/GuestFilesystem.cpp
PR 8520 core/libs/prx/libkernel/File/src/Open.cpp
PR 8550 core/libs/tests/GuestFilesystem.cpp
PR 8658 core/libs/prx/libc/src/General.cpp
core/libs/prx/libc/src/Rename.cpp
core/libs/prx/libkernel/File/src/Open.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6301430007 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8680#issuecomment-6301430007). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-20T21:03:16Z. --- <!-- pr-overlap --> 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 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/libs/prx/libc/src/General.cpp`<br>`core/libs/prx/libc/src/Rename.cpp`<br>`core/libs/prx/libkernel/File/src/Open.cpp` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/tests/GuestFilesystem.cpp` | | [PR 6226](https://www.github.com/boykopovar/AnyPS5/pull/6226) | `core/libs/prx/libc/src/General.cpp` | | [PR 6879](https://www.github.com/boykopovar/AnyPS5/pull/6879) | `core/libs/prx/libc/src/General.cpp` | | [PR 6936](https://www.github.com/boykopovar/AnyPS5/pull/6936) | `core/libs/prx/libkernel/File/src/Open.cpp` | | [PR 7121](https://www.github.com/boykopovar/AnyPS5/pull/7121) | `core/libs/prx/libkernel/File/src/Open.cpp` | | [PR 7201](https://www.github.com/boykopovar/AnyPS5/pull/7201) | `core/libs/prx/libc/src/General.cpp`<br>`core/libs/prx/libc/src/Rename.cpp`<br>`core/libs/prx/libkernel/File/src/Open.cpp` | | [PR 7530](https://www.github.com/boykopovar/AnyPS5/pull/7530) | `core/libs/prx/libkernel/File/src/Open.cpp`<br>`core/libs/tests/GuestFilesystem.cpp` | | [PR 8520](https://www.github.com/boykopovar/AnyPS5/pull/8520) | `core/libs/prx/libkernel/File/src/Open.cpp` | | [PR 8550](https://www.github.com/boykopovar/AnyPS5/pull/8550) | `core/libs/tests/GuestFilesystem.cpp` | | [PR 8658](https://www.github.com/boykopovar/AnyPS5/pull/8658) | `core/libs/prx/libc/src/General.cpp`<br>`core/libs/prx/libc/src/Rename.cpp`<br>`core/libs/prx/libkernel/File/src/Open.cpp` |
xXPBSXx commented 2026-10-20 21:26:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-20T21:26:33Z.


Thanks for the review. I checked the nested case file/child/ (stripped to file/child, which does not exist). It already answers ENOTDIR for unlink, remove, open and sceKernelUnlink: the callers fall back to the non-directory-prefix check on ENOENT. I added these four cases to guest_filesystem (head 9eb680d17a). They pass on Windows (MinGW GCC 15.2, Release) with and without a HasNonDirectoryPrefix_nid_no_patch fallback inside NamesNonDirectoryWithSlash_nid_no_patch, so I did not add the fallback, since I could not show a failing case for it. If you have a call that still answers ENOENT for this shape, please name it and I will add it with a failing test. Not tested: rename with a nested name, Linux, macOS, a console.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6301843915 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8680#issuecomment-6301843915). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-20T21:26:33Z. --- Thanks for the review. I checked the nested case `file/child/` (stripped to `file/child`, which does not exist). It already answers ENOTDIR for `unlink`, `remove`, `open` and `sceKernelUnlink`: the callers fall back to the non-directory-prefix check on ENOENT. I added these four cases to `guest_filesystem` (head 9eb680d17a). They pass on Windows (MinGW GCC 15.2, Release) with and without a `HasNonDirectoryPrefix_nid_no_patch` fallback inside `NamesNonDirectoryWithSlash_nid_no_patch`, so I did not add the fallback, since I could not show a failing case for it. If you have a call that still answers ENOENT for this shape, please name it and I will add it with a failing test. Not tested: `rename` with a nested name, Linux, macOS, a console. AI-assisted (Claude Code).
oneandonlydean commented 2026-10-21 01:09:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-21T01:09:31Z.


Thanks for this. Since it changes Windows path resolution and we don't yet know of a title that needs it, I'm closing it for now, as with #5165/#5266. Please reopen with the title ID and the log line that shows the problem, and we'll pick it up.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6305467742 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8680#issuecomment-6305467742). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-21T01:09:31Z. --- Thanks for this. Since it changes Windows path resolution and we don't yet know of a title that needs it, I'm closing it for now, as with #5165/#5266. Please reopen with the title ID and the log line that shows the problem, and we'll pick it up.

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