From ea7ea289d2e0a4333dbcb57189d4d7c434c180af Mon Sep 17 00:00:00 2001 From: David Date: Fri, 16 Oct 2026 07:24:08 +0400 Subject: [PATCH] refactor(libSceLibcInternal): share the statvfs layout and its conversion fstatvfs kept the guest struct statvfs and the sfs2svfs conversion from the kernel's statfs to itself. Both move to include/Statvfs.hpp so that statvfs can convert a volume the same way without opening the path. Nothing changes for fstatvfs. --- .../FilesystemStatistics.cpp | 28 ++------------- .../libSceLibcInternal/include/Statvfs.hpp | 34 +++++++++++++++++++ 2 files changed, 36 insertions(+), 26 deletions(-) create mode 100644 core/libs/prx/libSceLibcInternal/include/Statvfs.hpp diff --git a/core/libs/prx/libSceLibcInternal/FilesystemStatistics.cpp b/core/libs/prx/libSceLibcInternal/FilesystemStatistics.cpp index 083431cef6..8cb50f1eca 100644 --- a/core/libs/prx/libSceLibcInternal/FilesystemStatistics.cpp +++ b/core/libs/prx/libSceLibcInternal/FilesystemStatistics.cpp @@ -1,26 +1,7 @@ #include "prx/libc/include/general/VabiMacros.hpp" -#include "prx/libkernel/File/include/KernelStatfs.hpp" -#include -#include +#include "prx/libSceLibcInternal/include/Statvfs.hpp" #include -struct LibcStatvfs { - std::uint64_t f_bavail; - std::uint64_t f_bfree; - std::uint64_t f_blocks; - std::uint64_t f_favail; - std::uint64_t f_ffree; - std::uint64_t f_files; - std::uint64_t f_bsize; - std::uint64_t f_flag; - std::uint64_t f_frsize; - std::uint64_t f_fsid; - std::uint64_t f_namemax; -}; -static_assert(sizeof(LibcStatvfs) == 88); -static_assert(offsetof(LibcStatvfs, f_bsize) == 48); -static_assert(offsetof(LibcStatvfs, f_namemax) == 80); - extern "C" int APS5_VABI _fstatfs_nid_postfix(int, KernelStatfs*); extern "C" int* APS5_VABI __error_nid_postfix(); @@ -34,12 +15,7 @@ extern "C" int APS5_VABI fstatvfs_nid_postfix(int descriptor, LibcStatvfs* outpu *error = 14; return -1; } - const LibcStatvfs result{ - static_cast(volume.f_bavail), volume.f_bfree, volume.f_blocks, - static_cast(volume.f_ffree), static_cast(volume.f_ffree), volume.f_files, - volume.f_iosize, (volume.f_flags & 1) | ((volume.f_flags & 8) >> 2), volume.f_bsize, - 0, volume.f_namemax - }; + const LibcStatvfs result = StatvfsFromStatfs(volume); std::memcpy(output, &result, sizeof(result)); *error = saved; return 0; diff --git a/core/libs/prx/libSceLibcInternal/include/Statvfs.hpp b/core/libs/prx/libSceLibcInternal/include/Statvfs.hpp new file mode 100644 index 0000000000..4d6b238770 --- /dev/null +++ b/core/libs/prx/libSceLibcInternal/include/Statvfs.hpp @@ -0,0 +1,34 @@ +#ifndef CORE_LIBS_PRX_LIBSCELIBCINTERNAL_INCLUDE_STATVFS_HPP +#define CORE_LIBS_PRX_LIBSCELIBCINTERNAL_INCLUDE_STATVFS_HPP + +#include "prx/libkernel/File/include/KernelStatfs.hpp" +#include +#include + +struct LibcStatvfs { + std::uint64_t f_bavail; + std::uint64_t f_bfree; + std::uint64_t f_blocks; + std::uint64_t f_favail; + std::uint64_t f_ffree; + std::uint64_t f_files; + std::uint64_t f_bsize; + std::uint64_t f_flag; + std::uint64_t f_frsize; + std::uint64_t f_fsid; + std::uint64_t f_namemax; +}; +static_assert(sizeof(LibcStatvfs) == 88); +static_assert(offsetof(LibcStatvfs, f_bsize) == 48); +static_assert(offsetof(LibcStatvfs, f_namemax) == 80); + +inline LibcStatvfs StatvfsFromStatfs(const KernelStatfs& volume) { + return LibcStatvfs{ + static_cast(volume.f_bavail), volume.f_bfree, volume.f_blocks, + static_cast(volume.f_ffree), static_cast(volume.f_ffree), volume.f_files, + volume.f_iosize, (volume.f_flags & 1) | ((volume.f_flags & 8) >> 2), volume.f_bsize, + 0, volume.f_namemax + }; +} + +#endif