Skip to content

feat(libkernel_sys): implement getfsstat - #12695

Closed
xdCloudy wants to merge 1 commit into
boykopovar:mainfrom
xdCloudy:feat/libkernel-sys-statfs
Closed

xdCloudy wants to merge 1 commit into
boykopovar:mainfrom
xdCloudy:feat/libkernel-sys-statfs

Conversation

@xdCloudy

@xdCloudy xdCloudy commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

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 feat(libkernel_sys): implement statfs symlinkat and futimesat #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: feat(libkernel_sys): implement statfs symlinkat and futimesat #9161
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Progress report (3a2b919 → 496f97a)

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

✅ 1 implemented
Library Name
libkernel_sys getfsstat_nid_postfix

Changed libraries (implemented exports)

Library Before After Change
libkernel_sys 116/514 (22.57%) 117/514 (22.76%) +0.19 pp

@adriadam10 adriadam10 self-assigned this Oct 29, 2026
@xdCloudy xdCloudy changed the title feat(libkernel_sys): implement statfs feat(libkernel_sys): implement filesystem status calls Oct 29, 2026
@oneandonlydean

Copy link
Copy Markdown
Collaborator

@xdCloudy Thanks for the firmware work: the 0x1a90 wrapper forwarding the path and output pointer to syscall 396 is exactly the kind of evidence these entries need. One thing has to be sorted out before this can go in. #9161 (open, same area, assigned to oneandonlydean) also implements statfs (together with symlinkat and futimesat), removes the same statfs_nid_postfix stub from Export.Discovery.cpp and shares the host-volume code with _fstatfs, so the "no other open PR implements the same functions" box does not hold (the overlap tool did not flag it). A trial merge of this branch on top of #9161 conflicts in Export.Discovery.cpp. #12687 had the same problem and was closed for it.

The two take different routes: #9161 turns the Windows _fstatfs volume code into a path-based helper that both calls use and checks the guest write with process_vm_writev on Linux, where this PR adds a second copy of that Windows block and copies out with GuestCopyOut_nid_no_patch. Could you look at #9161 and either (a) add your firmware 13.60 evidence there as a comment so the maintainers can fold it into its debt entry (it has no function offset or syscall number), or (b) say what this PR does that #9161 does not. If there is nothing, please close this one; if #9161 lands first and something remains, a small follow-up on top would be welcome.

@xdCloudy xdCloudy changed the title feat(libkernel_sys): implement filesystem status calls feat(libkernel_sys): implement getfsstat Oct 29, 2026
@xdCloudy
xdCloudy force-pushed the feat/libkernel-sys-statfs branch from 471c5f5 to 496f97a Compare October 29, 2026 02:58
@xdCloudy

Copy link
Copy Markdown
Contributor Author

@oneandonlydean Thanks, you were right about the statfs duplicate and helper overlap. I removed statfs from this branch entirely. #12695 now implements only the distinct getfsstat export (EARPL-r8jf0): firmware 13.60 libkernel_sys.sprx places its wrapper at 0x1a70, invoking syscall 395. It uses the path-statistics provider from #9161 and is marked as depending on #9161; no statfs export or second host-volume implementation remains here. I’m validating the dependency-integrated build before updating the PR’s test report.

@rooklz rooklz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at 806b7bd, 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 d2f98f3, 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 3a2b919 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.

@xdCloudy

Copy link
Copy Markdown
Contributor Author

@rooklz Thanks for the independent Linux validation and the FIFO/socket path note. I removed statfs from #12695, but the refreshed overlap scan then found that open #11031 already implements getfsstat. My earlier reply that this PR was a distinct function was premature. I’m closing #12695 rather than maintain a duplicate; I’ve shared the firmware 13.60 wrapper evidence on #11031, and any guest-alias enumeration can be reconsidered as a follow-up after that PR lands.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

@adriadam10 we won't merge this while it duplicates #9161; if it turns out to add something #9161 lacks, we'll merge it once the requests above are addressed and exact-head CI is green, unless you'd rather handle it yourself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants