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.
This commit is contained in:
David committed 2026-10-16 07:24:08 +04:00
1 parent 5d9dcc42d2
commit ea7ea289d2
2 files changed
+36 -26

No files matched your search

@@ -1,26 +1,7 @@
#include "prx/libc/include/general/VabiMacros.hpp"
#include "prx/libkernel/File/include/KernelStatfs.hpp"
#include <cstddef>
#include <cstdint>
#include "prx/libSceLibcInternal/include/Statvfs.hpp"
#include <cstring>
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<std::uint64_t>(volume.f_bavail), volume.f_bfree, volume.f_blocks,
static_cast<std::uint64_t>(volume.f_ffree), static_cast<std::uint64_t>(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;
@@ -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 <cstddef>
#include <cstdint>
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<std::uint64_t>(volume.f_bavail), volume.f_bfree, volume.f_blocks,
static_cast<std::uint64_t>(volume.f_ffree), static_cast<std::uint64_t>(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