Skip to content

feat(libkernel): implement _fstatfs - #2858

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
babyhuey:feat/libkernel-fstatfs
Oct 10, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
babyhuey:feat/libkernel-fstatfs

Conversation

@babyhuey

@babyhuey babyhuey commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

What

Implements _fstatfs (17Mfe1B3X6U) in libkernel. The commit is @Recapi's (Recapi:feat/libkernel-fstatfs 756439c, rebased onto main with their authorship kept). They can't open a PR yet because of the intake check, and it handles more than my first version of this PR did.

It fills the FreeBSD 11 struct statfs (472 bytes, f_version 0x20030518) with the host volume that holds the file: block size, transfer size, total, free and available blocks, file counts and maximum name length, plus MNT_RDONLY, MNT_NOSUID and MNT_NOEXEC from fstatvfs on Linux. On Windows it uses GetVolumePathNameW, GetDiskFreeSpaceW/GetDiskFreeSpaceExW and GetVolumeInformationW, mapping only FILE_READ_ONLY_VOLUME.

  • Sockets and anonymous pipes return EINVAL, as FreeBSD's getvnode does. On Linux, named FIFOs still work.
  • Windows volume query failures, a zero cluster size, and a descriptor that is neither a disk file nor a pipe throw.
  • TechnicalDebt (Functional) lists the fields left 0 or empty and the Windows file counts.

Stremio Plus (PPSA74126) stops at it on main 57f96fd (catalog build, eboot.bin and sce_module/libc.prx unwrapped as #2605 requires; tracked in #1578):

Tested

Linux (Ubuntu 24.04, GCC 13, Release) on 57f96fd: guest_fstatfs passes 5/5 (--repeat until-fail:5), and the Stremio Plus line above. check_conventions.py passes. Windows 11 (MinGW-w64 GCC 15.2 from WinLibs, Release) on the same commit: guest_fstatfs 5/5, no warnings, and Stremio Plus stops at FAIL: unresolved ELF import 04AjkP0jO9U (_umtx_op) from libkernel.prx.

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 in TechnicalDebt
  • 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
  • AI-assisted: yes

@github-actions

github-actions Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Progress report (57f96fd → 9a3e55b)

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

✅ 1 implemented
Library Name
libkernel _fstatfs_nid_postfix

@Recapi

Recapi commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

Thanks for opening this and for linking my branch. I can't open a PR myself because of the intake check, so here are the differences between the two, in case you want to fold any of them in. Each piece is in Recapi:feat/libkernel-fstatfs (756439c), in NativeFstatfs and GuestFstatfs.cpp, and you're welcome to take it as is.

  1. Pipes. On FreeBSD, fstatfs on a pipe fails with EINVAL, because kern_fstatfs goes through getvnode and an anonymous pipe has no vnode. Linux fstatvfs succeeds on a pipe, so with this PR a guest pipe gets a successful statfs with 0 blocks:
    int p[2]; pipe(p); fstatvfs(p[0], &s);   // r=0, f_frsize=4096, f_blocks=0, f_namemax=255 (Ubuntu 24.04)
    
    On Windows the same case already returns EINVAL, but only because GetFinalPathNameByHandleW fails on a pipe handle. My branch rejects S_ISFIFO on pipefs (0x50495045) on Linux, so named FIFOs still work. On Windows it rejects FILE_TYPE_PIPE. Its test covers both ends of a pipe.
  2. Windows volume query failures become EIO here. In my branch they throw with the path and GetLastError(), following the rule that unmodelled paths throw. The same goes for a zero cluster size, which would otherwise divide by zero, and for a descriptor that is neither a disk file nor a pipe.
  3. Mount flags. f_flags stays 0 here. My branch maps ST_RDONLY, ST_NOSUID and ST_NOEXEC to MNT_RDONLY, MNT_NOSUID and MNT_NOEXEC. On Windows it maps only FILE_READ_ONLY_VOLUME.
  4. TechnicalDebt. f_type, f_fstypename, the mount names, f_owner, f_fsid and the I/O counters are left zero or empty, which a title can read. My branch adds an entry under "Functional" for those fields, the Windows f_files/f_ffree and the pipe behaviour.

None of this changes the Stremio Plus stop. With either version it moves on to _umtx_op.

@babyhuey
babyhuey force-pushed the feat/libkernel-fstatfs branch from 6012a43 to 9a3e55b Compare October 10, 2026 17:11
@babyhuey

Copy link
Copy Markdown
Contributor Author

@Recapi your version handles more, so this PR now carries your commit (756439c rebased onto main 57f96fd as 9a3e55b, with you as the author). The only rebase conflict was TechnicalDebt.md, where main had added lines next to yours; I kept both. On Linux guest_fstatfs passes 5/5 and Stremio Plus goes on to _umtx_op. The Windows run is in progress, and I've updated the description to match.

@github-actions

github-actions Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

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
#1619 docs/dev/TechnicalDebt.md L477
#1739 docs/dev/TechnicalDebt.md L477

@oneandonlydean
oneandonlydean merged commit b78ced2 into boykopovar:main Oct 10, 2026
13 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants