feat(libkernel_sys): implement getfsstat #11031
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11031"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by Gruzzberry on 2026-10-25T14:32:58Z.
What
getfsstatwas a throwing stub in libkernel_sys. It now follows FreeBSD 11.4'ssys_getfsstatandkern_getfsstat: a negativebufsizeor a mode other thanMNT_WAIT(1) andMNT_NOWAIT(2) fails withEINVAL; a null buffer or abufsizeof 0 writes nothing and returns the filesystem count (1); a non-null buffer too small for onestruct statfs(472 bytes) writes nothing and returns 0, askern_getfsstatcaps the count atmaxcount; otherwise onestatfsis copied out and 1 returned, with an unwritable buffer failing withEFAULT.bufsizeis the guest's 64-bitlong, taken asstd::int64_tso the Windows build does not read it as 32 bits.The guest has one filesystem, the host volume of the guest root, filled in by the existing
_fstatfs. The debt entry records that this is not the console's mount table, thatMNT_NOWAITis not served from a cache, and that jail filtering is not modelled.Tested
Windows 11 (10.0.26200), WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release,
-DBUILD_TESTING=ON, onmain7a25f87620.guest_kernel_sys: newCheckGetfsstat: modes 0, 3, -1 and 4, and negative sizes, fail withEINVALand write nothing; size 0 returns 1 and writes nothing; sizes 1 and 471 with a buffer return 0 and write nothing; a null buffer returns 1 at sizes 471, 472 and2^32 + 472;-2^32 + 472fails withEINVAL(a 32-bit read would see 472); the unreadable0x10with a full-size buffer fails withEFAULT; with room for two structs, both modes return 1, the second slot stays untouched, and the first matches_fstatfson/. Onmainthe test does not compile (the stub has a(void)signature); on this branch it passes 3 runs out of 3.agc_host_import_cut_lifetime,agc_driver_depth_plane_partial_store,pr_overlap_encoding, which fail the same way on an unrelated checkout in the same environment;agc_driver_depth_clear_hleandguest_selectflaked in parallel and pass alone.python tools/check_conventions.py --base upstream/main: passes.Overlaps
kenv, mine) adds code at the same place inExport.cpp(L343) andGuestKernelSys.cpp(L524): #11032 goes first, then this PR rebases.GuestKernelSys.cppL524) and #10799 (libkernel_sys.mddebt L40) touch neighbouring lines: proposed on each that it goes first and this PR rebases.getfsstatorgetmntinfoor changes_fstatfs. #9161 (statfs) shares no lines.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); no silent stubs added.mdfiles or images added to the repositoryAI-assisted (Claude Code).
🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T14:34:48Z.
Review: CHANGES_REQUESTED
Requesting a correction to the short-buffer return value and its regression. For a non-null buffer with
0 < bufsize < sizeof(struct statfs), FreeBSD 11.4 returns 0 because no records fit. Inkern_getfsstat,maxcountis zero; the mount loop still counts the filesystem, but the finalif (sfsp != NULL && count > maxcount)caps the result tomaxcount(0). By contrast,bufsize == 0setssfspto null and returns the total count (1). The current implementation returns 1 for every size below one structure, and the test asserts 1 forSize - 1with a non-null buffer, so this case disagrees with the cited reference.Please distinguish zero capacity from a nonzero undersized buffer and update the tests for both. The reference is
kern_getfsstatat lines 2911–2919 and 3095–3115: https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/vfs_syscalls.c#L2911-L3115.Exact-head local checks:
git diff --check, conventions, and C++20 syntax checks forExport.cppandGuestKernelSys.cpppass. The hosted product jobs are skipped; the author reports the Windows focused suite, which I have not independently run.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T15:20:33Z.
Review: DISMISSED
One additional ABI issue to address alongside the existing short-buffer finding:
getfsstat_nid_postfixdeclaresbufsizeas C++longin bothApi.hppand its definition. On Windows x64 (LLP64),longis 32-bit, but the PS5/FreeBSD amd64 syscall ABI uses a 64-bitlongfor this argument. That makes this exported function decode the guest argument with the wrong width on the Windows host build and can truncate/misinterpret values aboveLONG_MAX(or a negative 64-bit value whose low 32 bits differ). Please use an explicit 64-bit guest ABI type consistently in the declaration/definition and add a regression covering the 64-bit boundary/sign-extension behavior on Windows. The repository’s Windows guest tests are a good place to validate this. The FreeBSD 11.4 syscall prototype also declareslong bufsize: https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/vfs_syscalls.c#L371-L378.