feat(libkernel_sys): implement mkdirat #4743

Merged
jagrat04 merged 1 commit from upstream-pr/4743 into main 2026-10-13 07:55:12 +00:00
jagrat04 commented 2026-10-12 20:29:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jagrat04 on 2026-10-12T20:29:33Z.


What

Implement mkdirat in libkernel_sys (PRX library).

  • Delegates to mkdir_nid_postfix when d == AT_FDCWD (-100) or path is absolute.
  • Resolves relative paths against directory descriptor using GetDirectoryDescriptorPath_nid_no_patch.
  • Validates descriptor (EBADF on invalid fd, ENOTDIR on non-directory fd).
  • Validates parent directory and prefix paths (EEXIST if destination exists, ENOTDIR if an ancestor path component is a file, ENOENT if parent directory is missing, EFAULT on null, ENOENT on empty).
  • Creates directory natively and logs written path via RecordWrittenPath_nid_no_patch.
  • Adds technical debt documentation entry to docs/dev/debt/libkernel_sys.md.

Tested

Built and verified locally with unit tests in core/libs/tests/GuestKernelSys.cpp:

  • Windows: guest_kernel_sys test passed (100% tests passed).
  • Ran python tools/check_conventions.py --base origin/main.

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
  • Unblocks: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4834646245 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4743). Originally posted by [jagrat04](https://github.com/jagrat04) on 2026-10-12T20:29:33Z. --- ### What Implement mkdirat in libkernel_sys (PRX library). - Delegates to mkdir_nid_postfix when d == AT_FDCWD (-100) or path is absolute. - Resolves relative paths against directory descriptor using GetDirectoryDescriptorPath_nid_no_patch. - Validates descriptor (EBADF on invalid fd, ENOTDIR on non-directory fd). - Validates parent directory and prefix paths (EEXIST if destination exists, ENOTDIR if an ancestor path component is a file, ENOENT if parent directory is missing, EFAULT on null, ENOENT on empty). - Creates directory natively and logs written path via RecordWrittenPath_nid_no_patch. - Adds technical debt documentation entry to docs/dev/debt/libkernel_sys.md. ### Tested Built and verified locally with unit tests in core/libs/tests/GuestKernelSys.cpp: - Windows: guest_kernel_sys test passed (100% tests passed). - Ran python tools/check_conventions.py --base origin/main. ### 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 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 - [x] Unblocks: none - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-12 20:29:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-12T20:29:56Z.


Progress report (758aca7 → ec0d61e)

📈 System libraries: 87.9% (+0.01%, +1 implemented functions)

✅ 1 implemented
Library Name
libkernel_sys mkdirat_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6132085790 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4743#issuecomment-6132085790). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-12T20:29:56Z. --- <!-- progress-report --> ### Progress report (758aca7 → ec0d61e) 📈 **System libraries**: 87.9% (+0.01%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libkernel_sys | `mkdirat_nid_postfix` | </details>
adriadam10 commented 2026-10-12 21:17:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-12T21:17:17Z.

Review: CHANGES_REQUESTED


Thanks for the PR. It also conflicts with main now (core/libs/tests/GuestKernelSys.cpp and docs/dev/debt/libkernel_sys.md, next to the new pathconf/readlinkat lines), so it needs a rebase. Points to fix:

  • core/libs/prx/libkernel_sys/Export.cpp:289: Fail(errno) stores the host Linux errno as the guest errno. Values above 34 differ from FreeBSD (e.g. ENAMETOOLONG is 36 on Linux, 63 on FreeBSD, see GuestEnametoolong above). Map it the way mkdir does (SceErrorFromErrno) or with GuestError.
  • Export.cpp:265-290 re-implements what mkdir_nid_postfix already does in core/libs/prx/libkernel/File/src/Stdio.cpp:668 (ResolvePathError_nid_no_patch, NativeMkdir, HasNonDirectoryPrefix). The hand-rolled checks drop ENAMETOOLONG and the invalid-name handling mkdir has. Resolve the joined path through the same helpers instead of duplicating them.
  • Windows branch (Export.cpp:281-287): mode is ignored (fine, but say so in the debt line) and every other GetLastError() becomes EIO; ERROR_PATH_NOT_FOUND should be ENOENT, as in symlink above.
  • Tests: add a name over 255 bytes (ENAMETOOLONG) and a .. component; they pin the two behaviours above.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5496027744 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4743#pullrequestreview-5496027744). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-12T21:17:17Z. **Review:** CHANGES_REQUESTED --- Thanks for the PR. It also conflicts with `main` now (`core/libs/tests/GuestKernelSys.cpp` and `docs/dev/debt/libkernel_sys.md`, next to the new `pathconf`/`readlinkat` lines), so it needs a rebase. Points to fix: - `core/libs/prx/libkernel_sys/Export.cpp:289`: `Fail(errno)` stores the host Linux errno as the guest errno. Values above 34 differ from FreeBSD (e.g. `ENAMETOOLONG` is 36 on Linux, 63 on FreeBSD, see `GuestEnametoolong` above). Map it the way `mkdir` does (`SceErrorFromErrno`) or with `GuestError`. - `Export.cpp:265-290` re-implements what `mkdir_nid_postfix` already does in `core/libs/prx/libkernel/File/src/Stdio.cpp:668` (`ResolvePathError_nid_no_patch`, `NativeMkdir`, `HasNonDirectoryPrefix`). The hand-rolled checks drop `ENAMETOOLONG` and the invalid-name handling `mkdir` has. Resolve the joined path through the same helpers instead of duplicating them. - Windows branch (`Export.cpp:281-287`): `mode` is ignored (fine, but say so in the debt line) and every other `GetLastError()` becomes `EIO`; `ERROR_PATH_NOT_FOUND` should be `ENOENT`, as in `symlink` above. - Tests: add a name over 255 bytes (`ENAMETOOLONG`) and a `..` component; they pin the two behaviours above.
github-actions[bot] commented 2026-10-12 23:06:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-12T23:06:57Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#4553 core/libs/prx/libkernel_sys/Export.cpp L355
core/libs/tests/GuestKernelSys.cpp L40
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6134331532 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4743#issuecomment-6134331532). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-12T23:06:57Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #4553 | `core/libs/prx/libkernel_sys/Export.cpp` [L355](https://github.com/boykopovar/AnyPS5/blob/fc1f063f51189be91a186fd943e809bab2ef1ea2/core/libs/prx/libkernel_sys/Export.cpp#L355)<br>`core/libs/tests/GuestKernelSys.cpp` [L40](https://github.com/boykopovar/AnyPS5/blob/fc1f063f51189be91a186fd943e809bab2ef1ea2/core/libs/tests/GuestKernelSys.cpp#L40) | | |
johnohhh1 commented 2026-10-13 00:37:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by johnohhh1 on 2026-10-13T00:37:47Z.


Independent Linux validation: the full build and all 18 selected runtime suites pass on Ubuntu 26.04.1 x86-64, GCC 15.2.0, Release, bundled dependencies, BUILD_TESTING=ON.

Tested upstream 1c5e62878ab01af05d5a75bd94146228f5dea9d4 plus PR commit 588657423eb2f730967456143e89927d8fb4a7e2 (local cherry-pick 43e91af02fead98effd85b0640e2ebab268d057f, same stable patch ID). The PR head still matches. guest_kernel_sys, patched_libraries, and 16 related filesystem suites passed without skips, serially with a 30-second per-test timeout. Conventions checks also pass.

A standalone probe passed 141 checks:

  • 90 combinations of ordinary permission modes, host umasks, descriptor-relative / AT_FDCWD / absolute paths, and trailing slashes. Access bits matched native Linux mkdirat.
  • 49 error cases covering existing destinations, missing/non-directory prefixes, invalid/non-directory/closed descriptors, null/empty paths, dangling links, symlink loops, overlong names and enforced permission denial. Host errno values were translated to guest numbers where needed.
  • Changed guest working directory and valid .. traversal.

No defect found in these cases. These are synthetic Linux checks; I did not test Windows, a console or a game, and this does not verify the documented guest-umask/path-alias limitations or additional mode bits.

AI-assisted validation/report: Codex. The tested implementation is your existing patch.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6135391439 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4743#issuecomment-6135391439). Originally posted by [johnohhh1](https://github.com/johnohhh1) on 2026-10-13T00:37:47Z. --- Independent Linux validation: the full build and all 18 selected runtime suites pass on Ubuntu 26.04.1 x86-64, GCC 15.2.0, Release, bundled dependencies, `BUILD_TESTING=ON`. Tested upstream `1c5e62878ab01af05d5a75bd94146228f5dea9d4` plus PR commit `588657423eb2f730967456143e89927d8fb4a7e2` (local cherry-pick `43e91af02fead98effd85b0640e2ebab268d057f`, same stable patch ID). The PR head still matches. `guest_kernel_sys`, `patched_libraries`, and 16 related filesystem suites passed without skips, serially with a 30-second per-test timeout. Conventions checks also pass. A standalone probe passed 141 checks: - 90 combinations of ordinary permission modes, host umasks, descriptor-relative / `AT_FDCWD` / absolute paths, and trailing slashes. Access bits matched native Linux `mkdirat`. - 49 error cases covering existing destinations, missing/non-directory prefixes, invalid/non-directory/closed descriptors, null/empty paths, dangling links, symlink loops, overlong names and enforced permission denial. Host errno values were translated to guest numbers where needed. - Changed guest working directory and valid `..` traversal. No defect found in these cases. These are synthetic Linux checks; I did not test Windows, a console or a game, and this does not verify the documented guest-umask/path-alias limitations or additional mode bits. AI-assisted validation/report: Codex. The tested implementation is your existing patch.
jagrat04 commented 2026-10-13 00:42:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jagrat04 on 2026-10-13T00:42:17Z.


@adriadam10 Thanks for the review! Updated as requested:

  • Rebased cleanly onto latest origin/main.
  • Linux error handling: Mapped native errno via GuestError(std::error_code(nativeError, std::generic_category())), correctly translating errors like ENAMETOOLONG (63) and checking non-directory prefix for ENOTDIR.
  • Windows branch: Handles ERROR_ALREADY_EXISTS and ERROR_FILE_EXISTS (EEXIST), and maps ERROR_PATH_NOT_FOUND to ENOTDIR (if non-directory prefix exists) or ENOENT. Recorded that mode is ignored on Windows in docs/dev/debt/libkernel_sys.md.
  • Tests: Added test cases in GuestKernelSys.cpp for a component name > 255 bytes (ENAMETOOLONG 63) and a relative path with .. (dir/../dotdot_dir).
  • Verified locally with guest_kernel_sys test (100% pass) and python tools/check_conventions.py --base origin/main.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6135454825 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4743#issuecomment-6135454825). Originally posted by [jagrat04](https://github.com/jagrat04) on 2026-10-13T00:42:17Z. --- @adriadam10 Thanks for the review! Updated as requested: - Rebased cleanly onto latest `origin/main`. - Linux error handling: Mapped native errno via `GuestError(std::error_code(nativeError, std::generic_category()))`, correctly translating errors like `ENAMETOOLONG` (63) and checking non-directory prefix for `ENOTDIR`. - Windows branch: Handles `ERROR_ALREADY_EXISTS` and `ERROR_FILE_EXISTS` (`EEXIST`), and maps `ERROR_PATH_NOT_FOUND` to `ENOTDIR` (if non-directory prefix exists) or `ENOENT`. Recorded that `mode` is ignored on Windows in `docs/dev/debt/libkernel_sys.md`. - Tests: Added test cases in `GuestKernelSys.cpp` for a component name > 255 bytes (`ENAMETOOLONG` 63) and a relative path with `..` (`dir/../dotdot_dir`). - Verified locally with `guest_kernel_sys` test (100% pass) and `python tools/check_conventions.py --base origin/main`.
adriadam10 commented 2026-10-13 07:55:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T07:55:09Z.

Review: APPROVED


Checked the rebuilt head on Linux (build, guest_kernel_sys and the rest of the libs tests green; the new test does not link without the change). Errno mapping, Windows error handling, the ../long-name tests and the debt line address the earlier review; merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5500427820 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4743#pullrequestreview-5500427820). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-13T07:55:09Z. **Review:** APPROVED --- Checked the rebuilt head on Linux (build, `guest_kernel_sys` and the rest of the libs tests green; the new test does not link without the change). Errno mapping, Windows error handling, the `..`/long-name tests and the debt line address the earlier review; merging.
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!4743
No description provided.