feat(libkernel_sys): implement renameat #4877

Merged
jagrat04 merged 1 commit from upstream-pr/4877 into main 2026-10-13 08:23:02 +00:00
jagrat04 commented 2026-10-13 01:23:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jagrat04 on 2026-10-13T01:23:14Z.


What

Implements FreeBSD/POSIX renameat in libkernel_sys.prx (NID 3P7i3vxeZ18).

  • Argument validation: returns EFAULT on null pointer paths and ENOENT on empty paths.
  • Path length validation: returns ENAMETOOLONG for path lengths >= 1024 or components > 255.
  • Delegation: passes AT_FDCWD (-100) and absolute paths directly to rename.
  • Descriptor resolution: resolves relative paths against directory file descriptors via GetDirectoryDescriptorPath_nid_no_patch, returning EBADF for closed descriptors and ENOTDIR for non-directory descriptors.
  • File system semantics: validates trailing slashes, rejects renaming . or .. with EINVAL, prevents moving a directory into a subdirectory of itself (EINVAL), moving directory onto non-empty directory (ENOTEMPTY), moving file onto directory (EISDIR), and moving directory onto file (ENOTDIR).
  • Preserves written path tracking via RecordWrittenPath_nid_no_patch.
  • Documents technical debt in docs/dev/debt/libkernel_sys.md.

Tested

  • Added unit tests in core/libs/tests/GuestKernelSys.cpp covering:
    • Null paths (EFAULT) and empty paths (ENOENT)
    • Bad file descriptors (EBADF) and regular file descriptors (ENOTDIR)
    • Long path component (ENAMETOOLONG)
    • Dot and dot-dot path components (EINVAL)
    • Non-existent source file (ENOENT)
    • Renaming file to file and verifying contents
    • Renaming identical file path (no-op success)
    • Renaming file onto existing directory (EISDIR)
    • Renaming directory onto existing file (ENOTDIR)
    • Renaming directory into a child subdirectory (EINVAL)
    • Renaming directory onto non-empty directory (ENOTEMPTY)
    • Renaming directory onto empty directory (success)
    • Renaming across two separate directory descriptors
    • Trailing slash validations on source and target (ENOTDIR)
    • Delegation for AT_FDCWD (-100)
  • Verified with guest_kernel_sys test suite (100% tests passed).
  • Verified with 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:4837011988 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4877). Originally posted by [jagrat04](https://github.com/jagrat04) on 2026-10-13T01:23:14Z. --- ### What Implements FreeBSD/POSIX `renameat` in `libkernel_sys.prx` (NID `3P7i3vxeZ18`). - Argument validation: returns `EFAULT` on null pointer paths and `ENOENT` on empty paths. - Path length validation: returns `ENAMETOOLONG` for path lengths >= 1024 or components > 255. - Delegation: passes `AT_FDCWD` (-100) and absolute paths directly to `rename`. - Descriptor resolution: resolves relative paths against directory file descriptors via `GetDirectoryDescriptorPath_nid_no_patch`, returning `EBADF` for closed descriptors and `ENOTDIR` for non-directory descriptors. - File system semantics: validates trailing slashes, rejects renaming `.` or `..` with `EINVAL`, prevents moving a directory into a subdirectory of itself (`EINVAL`), moving directory onto non-empty directory (`ENOTEMPTY`), moving file onto directory (`EISDIR`), and moving directory onto file (`ENOTDIR`). - Preserves written path tracking via `RecordWrittenPath_nid_no_patch`. - Documents technical debt in `docs/dev/debt/libkernel_sys.md`. ### Tested - Added unit tests in `core/libs/tests/GuestKernelSys.cpp` covering: - Null paths (`EFAULT`) and empty paths (`ENOENT`) - Bad file descriptors (`EBADF`) and regular file descriptors (`ENOTDIR`) - Long path component (`ENAMETOOLONG`) - Dot and dot-dot path components (`EINVAL`) - Non-existent source file (`ENOENT`) - Renaming file to file and verifying contents - Renaming identical file path (no-op success) - Renaming file onto existing directory (`EISDIR`) - Renaming directory onto existing file (`ENOTDIR`) - Renaming directory into a child subdirectory (`EINVAL`) - Renaming directory onto non-empty directory (`ENOTEMPTY`) - Renaming directory onto empty directory (success) - Renaming across two separate directory descriptors - Trailing slash validations on source and target (`ENOTDIR`) - Delegation for `AT_FDCWD` (-100) - Verified with `guest_kernel_sys` test suite (100% tests passed). - Verified with `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-13 01:23:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T01:23:34Z.


Progress report (4899658 → 2a8e745)

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

✅ 1 implemented
Library Name
libkernel_sys renameat_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6136030689 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4877#issuecomment-6136030689). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-13T01:23:34Z. --- <!-- progress-report --> ### Progress report (4899658 → 2a8e745) 📈 **System libraries**: 88.28% (+0.01%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libkernel_sys | `renameat_nid_postfix` | </details>
nicolasfalesy commented 2026-10-13 07:24:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by nicolasfalesy on 2026-10-13T07:24:54Z.


Linux test (Arch, GCC 16.2.1, glibc, Release), this PR merged onto main 7e181fcc3 together with #4927, #4903, #4877, #4822 and #4823 (no conflicts): guest_kernel_sys passes. With this PR's source change reverted (test kept), guest_kernel_sys fails on Linux, so the check guards the change on Linux too.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6140512776 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4877#issuecomment-6140512776). Originally posted by [nicolasfalesy](https://github.com/nicolasfalesy) on 2026-10-13T07:24:54Z. --- Linux test (Arch, GCC 16.2.1, glibc, Release), this PR merged onto `main` 7e181fcc3 together with #4927, #4903, #4877, #4822 and #4823 (no conflicts): `guest_kernel_sys` passes. With this PR's source change reverted (test kept), `guest_kernel_sys` fails on Linux, so the check guards the change on Linux too.
adriadam10 commented 2026-10-13 08:18:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T08:18:38Z.


Rebased onto current main (only adjacency conflicts with the mkdirat block, the error constants and the test declarations); build and the 24 core/libs tests pass locally, including guest_kernel_sys. The new test fails to link without the change. Confirmed on Linux by @nicolasfalesy. The Windows-only branch (removing an empty destination directory before rename) is covered by code review only. Merging once CI is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6141353000 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4877#issuecomment-6141353000). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-13T08:18:38Z. --- Rebased onto current `main` (only adjacency conflicts with the `mkdirat` block, the error constants and the test declarations); build and the 24 `core/libs` tests pass locally, including `guest_kernel_sys`. The new test fails to link without the change. Confirmed on Linux by @nicolasfalesy. The Windows-only branch (removing an empty destination directory before `rename`) is covered by code review only. Merging once CI is green.
adriadam10 commented 2026-10-13 08:20:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T08:20:41Z.


Rebased onto current main again (adjacency conflicts with the new unlinkat block in Export.cpp and in docs/dev/debt/libkernel_sys.md; both are kept). Build and the 24 core/libs tests pass locally, including guest_kernel_sys. The Windows-only branch is covered by code review only. Merging once CI is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6141386128 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4877#issuecomment-6141386128). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-13T08:20:41Z. --- Rebased onto current `main` again (adjacency conflicts with the new `unlinkat` block in `Export.cpp` and in `docs/dev/debt/libkernel_sys.md`; both are kept). Build and the 24 `core/libs` tests pass locally, including `guest_kernel_sys`. The Windows-only branch is covered by code review only. Merging once CI is green.
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!4877
No description provided.