feat(libkernel_sys): implement getfsstat #12695

Closed
xdCloudy wants to merge 1 commit from upstream-pr/12695 into main
xdCloudy commented 2026-10-29 02:40:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xdCloudy on 2026-10-29T02:40:09Z.


What

Implements getfsstat (EARPL-r8jf0) for the AnyPS5 guest mount model. Firmware 13.60 Ghidra analysis of libkernel_sys.sprx (SHA-256 60921322b155ba649cfa29ea5e6d358ca0229424b4f73fd5c30ae7f7ce7c304c) identifies the wrapper at 0x1a70 invoking syscall 395. The implementation follows the FreeBSD 11.4 buffer-size, mode, count-query and bounded-copy contract; it reports the guest root and registered guest path aliases and fills each f_mntonname with the guest path. Filesystem statistics use the shared host-backed path-statistics provider introduced by #9161, so this PR depends on #9161. The enumerated mounts and host-specific fields do not reproduce the PS5 mount table; limitations are recorded in docs/dev/debt/libkernel_sys.md.

Tested

  • Windows: built guest_kernel_sys_tests; focused guest_kernel_sys CTest passed (1/1).
  • Linux/WSL: built guest_kernel_sys_tests; focused test executable passed when launched from /tmp.
  • Public-header audit passed (373 libraries / 13,414 exports); conventions check passed; git diff --check passed.
  • The implementation was initially validated against the local host-statfs helper before the shared-provider dependency was added. I am rerunning the focused test with #9161 integrated before claiming this exact version passes.

Checklist

  • Based on current main; no other open PR implements the same function
  • 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: #9161
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5061151231 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12695). Originally posted by [xdCloudy](https://github.com/xdCloudy) on 2026-10-29T02:40:09Z. --- ### What Implements `getfsstat` (`EARPL-r8jf0`) for the AnyPS5 guest mount model. Firmware 13.60 Ghidra analysis of `libkernel_sys.sprx` (SHA-256 `60921322b155ba649cfa29ea5e6d358ca0229424b4f73fd5c30ae7f7ce7c304c`) identifies the wrapper at `0x1a70` invoking syscall 395. The implementation follows the FreeBSD 11.4 buffer-size, mode, count-query and bounded-copy contract; it reports the guest root and registered guest path aliases and fills each `f_mntonname` with the guest path. Filesystem statistics use the shared host-backed path-statistics provider introduced by [#9161](https://github.com/boykopovar/AnyPS5/pull/9161), so this PR depends on #9161. The enumerated mounts and host-specific fields do not reproduce the PS5 mount table; limitations are recorded in `docs/dev/debt/libkernel_sys.md`. ### Tested - Windows: built `guest_kernel_sys_tests`; focused `guest_kernel_sys` CTest passed (1/1). - Linux/WSL: built `guest_kernel_sys_tests`; focused test executable passed when launched from `/tmp`. - Public-header audit passed (373 libraries / 13,414 exports); conventions check passed; `git diff --check` passed. - The implementation was initially validated against the local host-statfs helper before the shared-provider dependency was added. I am rerunning the focused test with #9161 integrated before claiming this exact version passes. ### Checklist - [x] Based on current `main`; no other open PR implements the same function - [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: #9161 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
rooklz commented 2026-10-29 03:01:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-29T03:01:42Z.

Review: COMMENTED


Reviewed at 806b7bd3e3, host-side only. I did no console runs and have no firmware access.

Duplicate export. The checklist says no other open PR implements the same function, but #9161 (yabanana, last updated today, head d2f98f3910, MERGEABLE) implements statfs with the same (const char*, KernelStatfs*) signature. A local python3 tools/pr_overlap.py --branch on this head reports it:

Pull request Conflicting files (lines on main) Same exports
#9161 core/libs/prx/libkernel_sys/Export.Discovery.cpp L2146-2150 statfs

git merge-tree against 3a2b919816 is clean for this PR on its own, but it conflicts with #9161 in that hunk. Whichever merges second has to be rebased or dropped. This is the same situation as #12687, where futimesat/symlinkat were also in #9161.

#9161's statfs test covers more than this PR's 10 rows:

  • errno stays unchanged on success
  • canary words around the output show it is written exactly sizeof(KernelStatfs) wide
  • the output is left untouched on ENOENT
  • an unreadable path pointer (1) gives EFAULT
  • an output buffer that straddles a read-only page gives EFAULT

Every row here already has an equivalent in #9161; the only difference is that this PR uses 0x10 as the bad output pointer where #9161 uses 1. Archive-only paths throw in both PRs: here through ResolvePath's "reading" refusal, in #9161 through an explicit "statfs" refusal. So I'd suggest folding anything unique into #9161 instead of landing a second statfs.

The POSIX branch was never run. Per the body, the Linux run stopped before the new rows, and the PR's linux CI lane was skipped. I took NativeStatfsPath verbatim, along with main's NativeFstatfs, DeviceFilesystem, SceErrorFromErrno, the GUEST_* constants and NotFoundError_nid_no_patch. I built it with -fsanitize=address,undefined on Ubuntu 24.04 x86_64 (glibc 2.39, ext4/overlay tmp, non-root). Result: 0 mismatches and no sanitizer reports.

Path Result
file / directory 0, and the record matches _fstatfs on the same file byte for byte up to f_owner
missing 2
file/child 20
dangling symlink 2
2-link symlink loop 62
256-char component 63
named FIFO 0
bound AF_UNIX socket path 0
/dev/null 0, giving DeviceFilesystem 512/2/255
component without search permission 13

So the Linux path is correct as written. These results should also hold for #9161's equivalent NativeStatfs if it keeps the same stat→statvfs order. Unlike _fstatfs, a FIFO or socket path returns 0 instead of EINVAL. That is consistent with FreeBSD resolving the vnode's mount, but it is worth one debt sentence in whichever PR lands.

Conventions pass at this head.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5692349638 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12695#pullrequestreview-5692349638). Originally posted by [rooklz](https://github.com/rooklz) on 2026-10-29T03:01:42Z. **Review:** COMMENTED --- Reviewed at 806b7bd3e3, host-side only. I did no console runs and have no firmware access. **Duplicate export.** The checklist says no other open PR implements the same function, but #9161 (yabanana, last updated today, head d2f98f3910, MERGEABLE) implements `statfs` with the same `(const char*, KernelStatfs*)` signature. A local `python3 tools/pr_overlap.py --branch` on this head reports it: | Pull request | Conflicting files (lines on `main`) | Same exports | |---|---|---| | #9161 | `core/libs/prx/libkernel_sys/Export.Discovery.cpp` L2146-2150 | `statfs` | `git merge-tree` against 3a2b919816 is clean for this PR on its own, but it conflicts with #9161 in that hunk. Whichever merges second has to be rebased or dropped. This is the same situation as #12687, where `futimesat`/`symlinkat` were also in #9161. #9161's statfs test covers more than this PR's 10 rows: - errno stays unchanged on success - canary words around the output show it is written exactly `sizeof(KernelStatfs)` wide - the output is left untouched on ENOENT - an unreadable path pointer (`1`) gives EFAULT - an output buffer that straddles a read-only page gives EFAULT Every row here already has an equivalent in #9161; the only difference is that this PR uses `0x10` as the bad output pointer where #9161 uses `1`. Archive-only paths throw in both PRs: here through `ResolvePath`'s "reading" refusal, in #9161 through an explicit `"statfs"` refusal. So I'd suggest folding anything unique into #9161 instead of landing a second `statfs`. **The POSIX branch was never run.** Per the body, the Linux run stopped before the new rows, and the PR's `linux` CI lane was skipped. I took `NativeStatfsPath` verbatim, along with main's `NativeFstatfs`, `DeviceFilesystem`, `SceErrorFromErrno`, the `GUEST_*` constants and `NotFoundError_nid_no_patch`. I built it with `-fsanitize=address,undefined` on Ubuntu 24.04 x86_64 (glibc 2.39, ext4/overlay tmp, non-root). Result: 0 mismatches and no sanitizer reports. | Path | Result | |---|---| | file / directory | 0, and the record matches `_fstatfs` on the same file byte for byte up to `f_owner` | | missing | 2 | | `file/child` | 20 | | dangling symlink | 2 | | 2-link symlink loop | 62 | | 256-char component | 63 | | named FIFO | 0 | | bound AF_UNIX socket path | 0 | | `/dev/null` | 0, giving `DeviceFilesystem` 512/2/255 | | component without search permission | 13 | So the Linux path is correct as written. These results should also hold for #9161's equivalent `NativeStatfs` if it keeps the same `stat`→`statvfs` order. Unlike `_fstatfs`, a FIFO or socket *path* returns 0 instead of EINVAL. That is consistent with FreeBSD resolving the vnode's mount, but it is worth one debt sentence in whichever PR lands. Conventions pass at this head.

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