feat(libkernel): implement _fstatfs #2858

Merged
babyhuey merged 1 commit from upstream-pr/2858 into main 2026-10-10 18:26:56 +00:00
babyhuey commented 2026-10-10 16:48:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-10T16:48:23Z.


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 57f96fd2 (catalog build, eboot.bin and sce_module/libc.prx unwrapped as #2605 requires; tracked in #1578):

  • main, Linux: app.elf: symbol lookup error: app.elf: undefined symbol: 17Mfe1B3X6U
  • with this PR, Linux: app.elf: symbol lookup error: app.elf: undefined symbol: 04AjkP0jO9U (_umtx_op, #1482)

Tested

Linux (Ubuntu 24.04, GCC 13, Release) on 57f96fd2: 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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4812851380 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2858). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-10T16:48:23Z. --- ### 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` 57f96fd2 (catalog build, `eboot.bin` and `sce_module/libc.prx` unwrapped as #2605 requires; tracked in #1578): - `main`, Linux: `app.elf: symbol lookup error: app.elf: undefined symbol: 17Mfe1B3X6U` - with this PR, Linux: `app.elf: symbol lookup error: app.elf: undefined symbol: 04AjkP0jO9U` (`_umtx_op`, #1482) ### Tested Linux (Ubuntu 24.04, GCC 13, Release) on 57f96fd2: `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 - [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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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] AI-assisted: yes
github-actions[bot] commented 2026-10-10 16:48:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-10T16:48:46Z.


Progress report (57f96fd → 9a3e55b)

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

✅ 1 implemented
Library Name
libkernel _fstatfs_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6099875278 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2858#issuecomment-6099875278). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-10T16:48:46Z. --- <!-- progress-report --> ### Progress report (57f96fd → 9a3e55b) ➖ **System libraries**: 84.52% (+0.0%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libkernel | `_fstatfs_nid_postfix` | </details>
Recapi commented 2026-10-10 17:00:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Recapi on 2026-10-10T17:00:53Z.


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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6099988338 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2858#issuecomment-6099988338). Originally posted by [Recapi](https://github.com/Recapi) on 2026-10-10T17:00:53Z. --- 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`](https://github.com/Recapi/AnyPS5/tree/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 commented 2026-10-10 17:12:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-10T17:12:04Z.


@Recapi your version handles more, so this PR now carries your commit (756439c rebased onto main 57f96fd2 as 9a3e55b8, 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6100094347 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2858#issuecomment-6100094347). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-10T17:12:04Z. --- @Recapi your version handles more, so this PR now carries your commit (756439c rebased onto `main` 57f96fd2 as 9a3e55b8, 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[bot] commented 2026-10-10 17:25:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-10T17:25:24Z.


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
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6100223664 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2858#issuecomment-6100223664). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-10T17:25:24Z. --- <!-- 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 | |---|---|---|---| | #1619 | `docs/dev/TechnicalDebt.md` [L477](https://github.com/boykopovar/AnyPS5/blob/9c5d67fbe27518bb5485c34f2fdcfbcb249bd800/docs/dev/TechnicalDebt.md#L477) | | | | #1739 | `docs/dev/TechnicalDebt.md` [L477](https://github.com/boykopovar/AnyPS5/blob/9c5d67fbe27518bb5485c34f2fdcfbcb249bd800/docs/dev/TechnicalDebt.md#L477) | | |
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!2858
No description provided.