fix(libkernel): report ENOTDIR from mkdir and rmdir when a path component is a file #2707

Closed
husseinkad wants to merge 2 commits from upstream-pr/2707 into main
husseinkad commented 2026-10-10 11:44:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by husseinkad on 2026-10-10T11:44:22Z.


What

On Windows, mkdir, sceKernelMkdir, rmdir and sceKernelRmdir with a regular file as a path component returned ENOENT (or a raw Windows code that maps to EIO). FreeBSD returns ENOTDIR: mkdir(2) "[ENOTDIR] A component of the path prefix is not a directory", rmdir(2) "[ENOTDIR] A component of the path is not a directory".

A new helper HasNonDirectoryPrefix walks up to the nearest existing ancestor and reports whether it is not a directory (a trailing separator is ignored). It runs only on the failure path: the POSIX mkdir remaps a native ENOENT or EINVAL to ENOTDIR when it is true (EINVAL because _wmkdir rejects file/a:b/x before it looks at the prefix), sceKernelMkdir and sceKernelRmdir use it the same way, and sceKernelRmdir("file/") is ENOTDIR. errno is captured before the helper runs. sceKernelMkdir("new/") used to take native.parent_path(), which is new itself, and failed with ENOENT while mkdir("new/") succeeded; both now strip the trailing separator and succeed. The Linux host already returns ENOTDIR for these paths and is unchanged. Out of scope and unchanged: mkdir("file/") and mkdir("file/.") (EEXIST), and the other path-taking calls (sceKernelTruncate, sceKernelRename, ...), which have the same defect and need their own changes.

Tested

Windows 11 (10.0.26200), WinLibs GCC 15.2.0 r7, Release:

  • guest_filesystem gains file/child and file/child/leaf for the four functions, rmdir("file/"), <file>/a:b/x, dir/missing/leaf (stays ENOENT), rmdir("missing/") and trailing-separator mkdir for both variants; it fails without the change (exit 0xc0000409) and passes with it. ctest -R "guest_filesystem|guest_directory" passes.
  • Outside the repo, a guest-API probe of 124 paths x 4 entry points (496 comparisons) against main's Stdio.cpp built into a second libkernel.prx: 371 identical; 104 changed ENOENT/EINVAL to ENOTDIR, all with a regular file as a path prefix (including junctions, case differences, non-ASCII names, NUL/x, 400 nested components, a file under a read-only directory); 20 trailing-separator sceKernelMkdir forms now create the directory like mkdir; none changed from success to failure; a 3-thread create/delete race against a flipping ancestor showed no hang or stale errno.
  • tools/check_conventions.py --base origin/main passes; tools/pr_overlap.py --branch reports no overlap.
  • Linux not run (unchanged by reading the code).

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
  • 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:4810945887 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2707). Originally posted by [husseinkad](https://github.com/husseinkad) on 2026-10-10T11:44:22Z. --- ### What On Windows, `mkdir`, `sceKernelMkdir`, `rmdir` and `sceKernelRmdir` with a regular file as a path component returned ENOENT (or a raw Windows code that maps to EIO). FreeBSD returns ENOTDIR: mkdir(2) "[ENOTDIR] A component of the path prefix is not a directory", rmdir(2) "[ENOTDIR] A component of the path is not a directory". A new helper `HasNonDirectoryPrefix` walks up to the nearest existing ancestor and reports whether it is not a directory (a trailing separator is ignored). It runs only on the failure path: the POSIX `mkdir` remaps a native ENOENT or EINVAL to ENOTDIR when it is true (EINVAL because `_wmkdir` rejects `file/a:b/x` before it looks at the prefix), `sceKernelMkdir` and `sceKernelRmdir` use it the same way, and `sceKernelRmdir("file/")` is ENOTDIR. `errno` is captured before the helper runs. `sceKernelMkdir("new/")` used to take `native.parent_path()`, which is `new` itself, and failed with ENOENT while `mkdir("new/")` succeeded; both now strip the trailing separator and succeed. The Linux host already returns ENOTDIR for these paths and is unchanged. Out of scope and unchanged: `mkdir("file/")` and `mkdir("file/.")` (EEXIST), and the other path-taking calls (`sceKernelTruncate`, `sceKernelRename`, ...), which have the same defect and need their own changes. ### Tested Windows 11 (10.0.26200), WinLibs GCC 15.2.0 r7, Release: - `guest_filesystem` gains `file/child` and `file/child/leaf` for the four functions, `rmdir("file/")`, `<file>/a:b/x`, `dir/missing/leaf` (stays ENOENT), `rmdir("missing/")` and trailing-separator mkdir for both variants; it fails without the change (exit `0xc0000409`) and passes with it. `ctest -R "guest_filesystem|guest_directory"` passes. - Outside the repo, a guest-API probe of 124 paths x 4 entry points (496 comparisons) against `main`'s `Stdio.cpp` built into a second `libkernel.prx`: 371 identical; 104 changed ENOENT/EINVAL to ENOTDIR, all with a regular file as a path prefix (including junctions, case differences, non-ASCII names, `NUL/x`, 400 nested components, a file under a read-only directory); 20 trailing-separator `sceKernelMkdir` forms now create the directory like `mkdir`; none changed from success to failure; a 3-thread create/delete race against a flipping ancestor showed no hang or stale errno. - `tools/check_conventions.py --base origin/main` passes; `tools/pr_overlap.py --branch` reports no overlap. - Linux not run (unchanged by reading the code). ### 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 (`NotImplemented_nid_no_patch`); silent stubs are listed in TechnicalDebt - [x] No notes, investigation `.md` files or images added to the repository - [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
github-actions[bot] commented 2026-10-10 11:44:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-10T11:44:33Z.


Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6097146626 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2707#issuecomment-6097146626). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-10T11:44:33Z. --- Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes.

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