filesystem: return st_mtim in posix_stat (fixes RB4 / CUSA02901 DLC crash) (#3781)

* filesystem: return st_mtim in posix_stat

* filesystem: stat - remove reliance on clock_cast

* filesystem: stat - remove reliance on to_time_t
This commit is contained in:
Emma
2025-11-06 20:47:40 +00:00
committed by GitHub
parent f5505daaca
commit 2f022a462d

View File

@@ -640,17 +640,29 @@ s32 PS4_SYSV_ABI posix_stat(const char* path, OrbisKernelStat* sb) {
*__Error() = POSIX_ENOENT;
return -1;
}
// get the difference between file clock and system clock
const auto now_sys = std::chrono::system_clock::now();
const auto now_file = std::filesystem::file_time_type::clock::now();
// calculate the file modified time
const auto mtime = std::filesystem::last_write_time(path_name);
const auto mtimestamp = now_sys + (mtime - now_file);
if (std::filesystem::is_directory(path_name)) {
sb->st_mode = 0000777u | 0040000u;
sb->st_size = 65536;
sb->st_blksize = 65536;
sb->st_blocks = 128;
sb->st_mtim.tv_sec =
std::chrono::duration_cast<std::chrono::seconds>(mtimestamp.time_since_epoch()).count();
// TODO incomplete
} else {
sb->st_mode = 0000777u | 0100000u;
sb->st_size = static_cast<s64>(std::filesystem::file_size(path_name));
sb->st_blksize = 512;
sb->st_blocks = (sb->st_size + 511) / 512;
sb->st_mtim.tv_sec =
std::chrono::duration_cast<std::chrono::seconds>(mtimestamp.time_since_epoch()).count();
// TODO incomplete
}