mirror of
https://github.com/KytyPS5/KytyPS5.git
synced 2026-10-22 20:06:54 +02:00
kernel: implement POSIX fsync through the shared file API
This commit is contained in:
@@ -483,6 +483,27 @@ void TestSaveOpenVisibility() {
|
||||
Check(FileSystem::KernelClose(truncated) == OK, "close truncated save file");
|
||||
}
|
||||
|
||||
void TestFsync() {
|
||||
Loader::SymbolDatabase symbols;
|
||||
Libs::InitLibKernel_1(&symbols);
|
||||
const auto* symbol = symbols.Find(
|
||||
{"juWbTNM+8hw", "Posix", 1, "libkernel", 1, 1, Loader::SymbolType::Func});
|
||||
Check(symbol != nullptr, "POSIX fsync export resolves");
|
||||
const auto fsync = reinterpret_cast<int (KYTY_SYSV_ABI *)(int)>(symbol->vaddr);
|
||||
Check(fsync(std::numeric_limits<int>::min()) == -1 &&
|
||||
*Libs::Posix::GetErrorAddr() == Libs::Posix::POSIX_EBADF,
|
||||
"invalid fsync descriptor reports POSIX EBADF");
|
||||
|
||||
constexpr char Path[] = "/savedata0/fsync.dat";
|
||||
const int fd = FileSystem::KernelOpen(Path, 0x602, 0777);
|
||||
Check(fd >= 3 && FileSystem::KernelWrite(fd, "save", 4) == 4 && fsync(fd) == OK &&
|
||||
FileSystem::KernelLseek(fd, 0, 1) == 4,
|
||||
"fsync flushes a writable file without changing its offset");
|
||||
Check(FileSystem::KernelClose(fd) == OK && fsync(fd) == -1 &&
|
||||
*Libs::Posix::GetErrorAddr() == Libs::Posix::POSIX_EBADF,
|
||||
"closed fsync descriptor reports POSIX EBADF");
|
||||
}
|
||||
|
||||
void TestSaveTruncate() {
|
||||
namespace Kernel = Libs::LibKernel;
|
||||
Loader::SymbolDatabase symbols;
|
||||
@@ -973,6 +994,9 @@ void CheckArchiveMount(const std::filesystem::path &root) {
|
||||
std::equal(bytes.begin(), bytes.begin() + 9, payload.end() - 9) &&
|
||||
FileSystem::KernelRead(fd, bytes.data(), bytes.size()) == 0,
|
||||
"archive reads stop at the member boundary");
|
||||
Check(FileSystem::KernelFsync(fd) == OK &&
|
||||
FileSystem::KernelLseek(fd, 0, 1) == payload.size(),
|
||||
"fsync succeeds on an immutable archive member without changing its offset");
|
||||
Check(FileSystem::KernelWrite(fd, bytes.data(), 1) ==
|
||||
Libs::LibKernel::KERNEL_ERROR_EBADF &&
|
||||
FileSystem::KernelPwrite(fd, bytes.data(), 1, 0) ==
|
||||
@@ -2271,6 +2295,7 @@ int main(int, char**) {
|
||||
CheckAprPaths(temporary.Path());
|
||||
FileSystem::Mount(temporary.Path(), "/savedata0");
|
||||
TestSaveOpenVisibility();
|
||||
TestFsync();
|
||||
TestSaveTruncate();
|
||||
TestSaveWritev();
|
||||
TestAioBatches();
|
||||
|
||||
Reference in New Issue
Block a user