feat(libkernel_sys): implement fstatat #7563

Merged
babyhuey merged 1 commit from upstream-pr/7563 into main 2026-10-20 14:08:27 +00:00
babyhuey commented 2026-10-18 14:10:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-18T14:10:32Z.


What

Implements fstatat (t6haf4s-eE0) in libkernel_sys, next to openat, mkdirat, fchmodat and unlinkat, and following them:

  • AT_FDCWD (-100) and absolute paths go to stat, or to lstat with AT_SYMLINK_NOFOLLOW (0x200).
  • Any other relative path is joined to the descriptor's host directory through a new libkernel helper, StatInDirectory_nid_no_patch, the same way OpenInDirectory_nid_no_patch does for openat. It returns EBADF for a descriptor that is not open and ENOTDIR for one that is not a directory. Following links, it uses sceKernelStat's native-path code, moved into StatNative unchanged, so a trailing / on a non-directory gives ENOTDIR as in stat. Without following, it uses File::FillLinkStat like lstat.
  • Flags other than AT_SYMLINK_NOFOLLOW return EINVAL; a null path EFAULT; an empty one ENOENT.

The technical debt entry follows the other *at functions (no guest path aliases or case-insensitive matching below a descriptor, .. not kept inside the guest root).

Tested

On 15649b70 (rebased onto main a373e85e5 after #6411 merged), Linux (Ubuntu 24.04, GCC 13) and Windows 11 (MinGW-w64 GCC 15.2 from WinLibs), Release:

  • guest_kernel_sys passes 5/5 (--repeat until-fail:5) on both. The new cases cover a file and a directory below a descriptor, a trailing /, AT_SYMLINK_NOFOLLOW, AT_FDCWD, an absolute guest path, ENOENT, EFAULT, EINVAL, EBADF and ENOTDIR for a file descriptor, plus a symbolic link followed and not followed (not on Windows, like the existing fchmodat link cases).
  • No new warnings in the files this PR touches on either OS.

Stremio Plus (PPSA74126, catalog release 0.5.11) stops on main with symbol lookup error: ... undefined symbol: t6haf4s-eE0 (fstatat); nothing open provides it (checked all 851 open PR diffs). With this PR:

  • Linux (headless): it gets past fstatat, starts its threads and stops at the headless DisplayWindow Vulkan check, like the other UI titles in a headless run.
  • Windows 11, 60 s, on main 5bf2e139e it fails to load (unresolved ELF import t6haf4s-eE0 (fstatat) from libkernel_sys.prx, exit 0xC0000139, no window). With this PR it runs the full 60 s at 59.94 fps with no UCRT reports and draws its "Link your account" page (QR code, link code, countdown and the "Request a new link" button). Rechecked on the rebased head: 59.93 FPS, same page; Morrowind (PPSA99630) still reaches its own Archive 'Morrowind.bsa' not found exit through #6411's fchown.

The stat consumers (ctest -R "filesystem|fstat|timestamp|app_archive|kernel_sys|stat", 39 tests on the rebased head) also pass 5/5 on both after sceKernelStat moved to StatNative, as they do on main.

check_conventions.py passes.

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. #6411 (fchown) merged first; this is rebased onto it, keeping both functions and both test blocks in libkernel_sys/Export.cpp and GuestKernelSys.cpp.
  • Unblocks: PPSA74126
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4909771504 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7563). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-18T14:10:32Z. --- ### What Implements `fstatat` (`t6haf4s-eE0`) in libkernel_sys, next to `openat`, `mkdirat`, `fchmodat` and `unlinkat`, and following them: - `AT_FDCWD` (-100) and absolute paths go to `stat`, or to `lstat` with `AT_SYMLINK_NOFOLLOW` (0x200). - Any other relative path is joined to the descriptor's host directory through a new libkernel helper, `StatInDirectory_nid_no_patch`, the same way `OpenInDirectory_nid_no_patch` does for `openat`. It returns `EBADF` for a descriptor that is not open and `ENOTDIR` for one that is not a directory. Following links, it uses `sceKernelStat`'s native-path code, moved into `StatNative` unchanged, so a trailing `/` on a non-directory gives `ENOTDIR` as in `stat`. Without following, it uses `File::FillLinkStat` like `lstat`. - Flags other than `AT_SYMLINK_NOFOLLOW` return `EINVAL`; a null path `EFAULT`; an empty one `ENOENT`. The technical debt entry follows the other `*at` functions (no guest path aliases or case-insensitive matching below a descriptor, `..` not kept inside the guest root). ### Tested On 15649b70 (rebased onto `main` a373e85e5 after #6411 merged), Linux (Ubuntu 24.04, GCC 13) and Windows 11 (MinGW-w64 GCC 15.2 from WinLibs), Release: - `guest_kernel_sys` passes 5/5 (`--repeat until-fail:5`) on both. The new cases cover a file and a directory below a descriptor, a trailing `/`, `AT_SYMLINK_NOFOLLOW`, `AT_FDCWD`, an absolute guest path, `ENOENT`, `EFAULT`, `EINVAL`, `EBADF` and `ENOTDIR` for a file descriptor, plus a symbolic link followed and not followed (not on Windows, like the existing `fchmodat` link cases). - No new warnings in the files this PR touches on either OS. Stremio Plus (PPSA74126, catalog release 0.5.11) stops on `main` with `symbol lookup error: ... undefined symbol: t6haf4s-eE0 (fstatat)`; nothing open provides it (checked all 851 open PR diffs). With this PR: - Linux (headless): it gets past `fstatat`, starts its threads and stops at the headless `DisplayWindow` Vulkan check, like the other UI titles in a headless run. - Windows 11, 60 s, on `main` 5bf2e139e it fails to load (`unresolved ELF import t6haf4s-eE0 (fstatat) from libkernel_sys.prx`, exit `0xC0000139`, no window). With this PR it runs the full 60 s at 59.94 fps with no UCRT reports and draws its "Link your account" page (QR code, link code, countdown and the "Request a new link" button). Rechecked on the rebased head: 59.93 FPS, same page; Morrowind (PPSA99630) still reaches its own `Archive 'Morrowind.bsa' not found` exit through #6411's `fchown`. The stat consumers (`ctest -R "filesystem|fstat|timestamp|app_archive|kernel_sys|stat"`, 39 tests on the rebased head) also pass 5/5 on both after `sceKernelStat` moved to `StatNative`, as they do on `main`. `check_conventions.py` passes. ### 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. #6411 (`fchown`) merged first; this is rebased onto it, keeping both functions and both test blocks in `libkernel_sys/Export.cpp` and `GuestKernelSys.cpp`. - [x] Unblocks: PPSA74126 - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-18 14:11:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-18T14:11:05Z.


Progress report (c22eb87 → 15649b7)

➖ System libraries: 91.56% (+0.0%, +1 implemented functions)

✅ 1 implemented
Library Name
libkernel_sys fstatat_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6250905189 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7563#issuecomment-6250905189). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-18T14:11:05Z. --- <!-- progress-report --> ### Progress report (c22eb87 → 15649b7) ➖ **System libraries**: 91.56% (+0.0%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libkernel_sys | `fstatat_nid_postfix` | </details>
github-actions[bot] commented 2026-10-18 14:35:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-18T14:35:58Z.


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
PR 8457 core/libs/tests/GuestKernelSys.cpp L632-637

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/libkernel/File/src/Open.cpp
core/libs/prx/libkernel_sys/Export.cpp
PR 6044 core/libs/tests/GuestKernelSys.cpp
PR 6936 core/libs/prx/libkernel/File/src/Open.cpp
PR 7201 core/libs/prx/libkernel/File/src/Open.cpp
core/libs/prx/libkernel_sys/Export.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6251157855 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7563#issuecomment-6251157855). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-18T14:35:58Z. --- <!-- 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 | |---|---|---|---| | [PR 8457](https://www.github.com/boykopovar/AnyPS5/pull/8457) | `core/libs/tests/GuestKernelSys.cpp` [L632-637](https://github.com/boykopovar/AnyPS5/blob/30fda0a03a43339037677d3a9f4a021d5b078566/core/libs/tests/GuestKernelSys.cpp#L632-L637) | | | 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/libkernel/File/src/Open.cpp`<br>`core/libs/prx/libkernel_sys/Export.cpp` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/tests/GuestKernelSys.cpp` | | [PR 6936](https://www.github.com/boykopovar/AnyPS5/pull/6936) | `core/libs/prx/libkernel/File/src/Open.cpp` | | [PR 7201](https://www.github.com/boykopovar/AnyPS5/pull/7201) | `core/libs/prx/libkernel/File/src/Open.cpp`<br>`core/libs/prx/libkernel_sys/Export.cpp` |
LeandroLP23 commented 2026-10-18 18:06:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-18T18:06:20Z.


Windows run. Radeon 860M (RDNA 3.5, driver 32.0.13058.8001), Windows 11 26300, WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON. Build: main c3591adf9 with #7623, #7612, #7611, #7603, #7579, #7563 and #7541 merged together (each merge clean, built once).

The build is clean and guest_kernel_sys passes 3 runs of 3.

AI-assisted

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6253308229 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7563#issuecomment-6253308229). Originally posted by [LeandroLP23](https://github.com/LeandroLP23) on 2026-10-18T18:06:20Z. --- Windows run. Radeon 860M (RDNA 3.5, driver 32.0.13058.8001), Windows 11 26300, WinLibs GCC 15.2.0 r7, Release, `BUILD_TESTING=ON`. Build: `main` `c3591adf9` with #7623, #7612, #7611, #7603, #7579, #7563 and #7541 merged together (each merge clean, built once). The build is clean and `guest_kernel_sys` passes 3 runs of 3. AI-assisted
adriadam10 commented 2026-10-20 14:08:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-20T14:08:38Z.


Rechecked against current main: the StatNative refactor keeps the NotFoundError_nid_no_patch and Windows ELOOP changes, the error paths match openat/unlinkat/readlinkat, and the tests and technical debt entry are in order; merged.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6292813417 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7563#issuecomment-6292813417). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-20T14:08:38Z. --- Rechecked against current main: the `StatNative` refactor keeps the `NotFoundError_nid_no_patch` and Windows ELOOP changes, the error paths match `openat`/`unlinkat`/`readlinkat`, and the tests and technical debt entry are in order; merged.
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!7563
No description provided.