feat(libkernel_sys): implement unlinkat #4870

Merged
jagrat04 merged 1 commit from upstream-pr/4870 into main 2026-10-13 08:16:19 +00:00
jagrat04 commented 2026-10-13 00:56:39 +00:00 (Migrated from github.com)

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


What

Implements FreeBSD/POSIX unlinkat in libkernel_sys.prx (NID tCFbw1wGrqk, imported by 2 Ship 2 Harkinian / PPSA99621).

  • Flags validation: verifies flag & ~0x800 fails with EINVAL (FreeBSD AT_REMOVEDIR).
  • Path validation: fails null paths with EFAULT and empty strings with ENOENT.
  • Delegation: passes AT_FDCWD (-100) and absolute paths to rmdir (if AT_REMOVEDIR) or unlink.
  • Directory descriptor resolution: gets base directory from file descriptor, failing invalid descriptors with EBADF and non-directory descriptors with ENOTDIR.
  • Directory removal (AT_REMOVEDIR): forbids . and .. with EINVAL, symlinks and regular files with ENOTDIR, non-empty directories with ENOTEMPTY, and removes empty directories.
  • File unlinking: fails directories with EPERM, trailing slashes on non-directories with ENOTDIR, and unlinks regular files and symlinks.
  • Documents technical debt in docs/dev/debt/libkernel_sys.md.

Tested

  • Added unit tests in core/libs/tests/GuestKernelSys.cpp covering:
    • Valid and invalid flags (EINVAL)
    • Null (EFAULT) and empty (ENOENT) paths
    • Invalid descriptor (EBADF) and file descriptor (ENOTDIR)
    • Non-directory prefix and trailing slashes (ENOTDIR)
    • Long path component (ENAMETOOLONG)
    • Missing file / directory lookup (ENOENT)
    • Directory without AT_REMOVEDIR (EPERM)
    • File with AT_REMOVEDIR (ENOTDIR)
    • Dot and dot-dot paths with AT_REMOVEDIR (EINVAL)
    • Non-empty directory removal (ENOTEMPTY)
    • Relative file unlink and directory removal
    • Absolute path and AT_FDCWD delegation
  • Verified with guest_kernel_sys and guest_filesystem test targets (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: PPSA99621
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4836827906 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4870). Originally posted by [jagrat04](https://github.com/jagrat04) on 2026-10-13T00:56:39Z. --- ### What Implements FreeBSD/POSIX `unlinkat` in `libkernel_sys.prx` (NID `tCFbw1wGrqk`, imported by 2 Ship 2 Harkinian / PPSA99621). - Flags validation: verifies `flag & ~0x800` fails with `EINVAL` (FreeBSD `AT_REMOVEDIR`). - Path validation: fails null paths with `EFAULT` and empty strings with `ENOENT`. - Delegation: passes `AT_FDCWD` (-100) and absolute paths to `rmdir` (if `AT_REMOVEDIR`) or `unlink`. - Directory descriptor resolution: gets base directory from file descriptor, failing invalid descriptors with `EBADF` and non-directory descriptors with `ENOTDIR`. - Directory removal (`AT_REMOVEDIR`): forbids `.` and `..` with `EINVAL`, symlinks and regular files with `ENOTDIR`, non-empty directories with `ENOTEMPTY`, and removes empty directories. - File unlinking: fails directories with `EPERM`, trailing slashes on non-directories with `ENOTDIR`, and unlinks regular files and symlinks. - Documents technical debt in `docs/dev/debt/libkernel_sys.md`. ### Tested - Added unit tests in `core/libs/tests/GuestKernelSys.cpp` covering: - Valid and invalid flags (`EINVAL`) - Null (`EFAULT`) and empty (`ENOENT`) paths - Invalid descriptor (`EBADF`) and file descriptor (`ENOTDIR`) - Non-directory prefix and trailing slashes (`ENOTDIR`) - Long path component (`ENAMETOOLONG`) - Missing file / directory lookup (`ENOENT`) - Directory without `AT_REMOVEDIR` (`EPERM`) - File with `AT_REMOVEDIR` (`ENOTDIR`) - Dot and dot-dot paths with `AT_REMOVEDIR` (`EINVAL`) - Non-empty directory removal (`ENOTEMPTY`) - Relative file unlink and directory removal - Absolute path and `AT_FDCWD` delegation - Verified with `guest_kernel_sys` and `guest_filesystem` test targets (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: PPSA99621 - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-13 00:57:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T00:57:05Z.


Progress report (5344514 → 55ddffe)

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

✅ 1 implemented
Library Name
libkernel_sys unlinkat_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6135709573 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4870#issuecomment-6135709573). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-13T00:57:05Z. --- <!-- progress-report --> ### Progress report (5344514 → 55ddffe) 📈 **System libraries**: 88.25% (+0.01%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libkernel_sys | `unlinkat_nid_postfix` | </details>
nicolasfalesy commented 2026-10-13 07:25:20 +00:00 (Migrated from github.com)

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


Linux test (Arch, GCC 16.2.1, glibc, Release), this PR merged onto main 7e181fcc3: guest_kernel_sys passes. With this PR's Export.cpp change reverted (test kept), it fails on Linux, so the check guards the change on Linux too. Note: it conflicts with #4877 (renameat) in libkernel_sys/Export.cpp and GuestKernelSys.cpp; whichever lands second needs a small rebase.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6140519347 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4870#issuecomment-6140519347). Originally posted by [nicolasfalesy](https://github.com/nicolasfalesy) on 2026-10-13T07:25:20Z. --- Linux test (Arch, GCC 16.2.1, glibc, Release), this PR merged onto `main` 7e181fcc3: `guest_kernel_sys` passes. With this PR's `Export.cpp` change reverted (test kept), it fails on Linux, so the check guards the change on Linux too. Note: it conflicts with #4877 (`renameat`) in `libkernel_sys/Export.cpp` and `GuestKernelSys.cpp`; whichever lands second needs a small rebase.
adriadam10 commented 2026-10-13 08:13:55 +00:00 (Migrated from github.com)

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


Rebased onto current main (only adjacency conflict with mkdirat in Export.cpp and GuestKernelSys.cpp; both kept, and the new tests use their own directory names so they don't collide with mkdirat's). Build and the libs ctest scope pass (44/44), and guest_kernel_sys no longer links without the unlinkat change. Flag value, errno choices (EPERM for a directory without AT_REMOVEDIR, EINVAL for ./.., ENOTEMPTY, ENOTDIR) match FreeBSD's kern_unlinkat; confirmed on Linux by @nicolasfalesy. Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6141277776 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4870#issuecomment-6141277776). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-13T08:13:55Z. --- Rebased onto current `main` (only adjacency conflict with `mkdirat` in `Export.cpp` and `GuestKernelSys.cpp`; both kept, and the new tests use their own directory names so they don't collide with `mkdirat`'s). Build and the libs ctest scope pass (44/44), and `guest_kernel_sys` no longer links without the `unlinkat` change. Flag value, errno choices (`EPERM` for a directory without `AT_REMOVEDIR`, `EINVAL` for `.`/`..`, `ENOTEMPTY`, `ENOTDIR`) match FreeBSD's `kern_unlinkat`; confirmed on Linux by @nicolasfalesy. 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!4870
No description provided.