mirror of
https://github.com/KytyPS5/KytyPS5.git
synced 2026-10-20 02:47:02 +02:00
kernel: implement POSIX fsync through the shared file API
This commit is contained in:
@@ -367,7 +367,7 @@ bool SysFileDeleteFile(const std::filesystem::path& name) {
|
||||
|
||||
bool SysFileFlush(sys_file_t& f) {
|
||||
if (f.type == SYS_FILE_FILE && f.f != nullptr) {
|
||||
return (fflush(f.f) == 0);
|
||||
return fflush(f.f) == 0 && fsync(fileno(f.f)) == 0;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -1326,6 +1326,27 @@ int KYTY_SYSV_ABI KernelFtruncate(int d, int64_t length) {
|
||||
return OK;
|
||||
}
|
||||
|
||||
int KYTY_SYSV_ABI KernelFsync(int d) {
|
||||
PRINT_NAME();
|
||||
|
||||
if (d < DESCRIPTOR_MIN) {
|
||||
return KERNEL_ERROR_EBADF;
|
||||
}
|
||||
|
||||
auto* file = g_files->GetFile(d);
|
||||
if (file == nullptr || !file->opened) {
|
||||
return KERNEL_ERROR_EBADF;
|
||||
}
|
||||
|
||||
Common::LockGuard lock(file->mutex);
|
||||
if (file->f.IsInvalid() || !file->f.Flush()) {
|
||||
return KERNEL_ERROR_EIO;
|
||||
}
|
||||
|
||||
LOGF("\tFsync: %s\n", Common::PathToString(file->real_name).c_str());
|
||||
return OK;
|
||||
}
|
||||
|
||||
int KYTY_SYSV_ABI KernelUnlink(const char* path) {
|
||||
PRINT_NAME();
|
||||
|
||||
|
||||
@@ -72,6 +72,7 @@ int KYTY_SYSV_ABI KernelStat(const char* path, FileStat* sb);
|
||||
int KYTY_SYSV_ABI KernelFstat(int d, FileStat* sb);
|
||||
int KYTY_SYSV_ABI KernelTruncate(const char* path, int64_t length);
|
||||
int KYTY_SYSV_ABI KernelFtruncate(int d, int64_t length);
|
||||
int KYTY_SYSV_ABI KernelFsync(int d);
|
||||
int KYTY_SYSV_ABI KernelUnlink(const char* path);
|
||||
int KYTY_SYSV_ABI KernelRename(const char* from, const char* to);
|
||||
int KYTY_SYSV_ABI KernelGetdirentries(int fd, char* buf, int nbytes, int64_t* basep);
|
||||
|
||||
@@ -1341,14 +1341,6 @@ static int KYTY_SYSV_ABI KernelGetOperationMode(int* mode, int* submode) {
|
||||
return OK;
|
||||
}
|
||||
|
||||
static int KYTY_SYSV_ABI KernelFsync(int fd) {
|
||||
PRINT_NAME();
|
||||
|
||||
LOGF("\t fd = %d\n", fd);
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
static void KYTY_SYSV_ABI KernelSync() {
|
||||
PRINT_NAME();
|
||||
}
|
||||
@@ -1986,6 +1978,12 @@ int KYTY_SYSV_ABI ftruncate(int d, int64_t length) {
|
||||
return POSIX_CALL(LibKernel::FileSystem::KernelFtruncate(d, length));
|
||||
}
|
||||
|
||||
int KYTY_SYSV_ABI fsync(int d) {
|
||||
PRINT_NAME();
|
||||
|
||||
return POSIX_CALL(LibKernel::FileSystem::KernelFsync(d));
|
||||
}
|
||||
|
||||
int KYTY_SYSV_ABI socket(int family, int type, int protocol) {
|
||||
PRINT_NAME();
|
||||
return Network::Net::Socket(family, type, protocol);
|
||||
@@ -2174,6 +2172,7 @@ LIB_DEFINE(InitLibKernel_1_Posix) {
|
||||
LIB_FUNC("E6ao34wPw+U", stat);
|
||||
LIB_FUNC("JGMio+21L4c", mkdir);
|
||||
LIB_FUNC("ih4CD9-gghM", Posix::ftruncate);
|
||||
LIB_FUNC("juWbTNM+8hw", Posix::fsync);
|
||||
LIB_FUNC("8nY19bKoiZk", Posix::fcntl);
|
||||
LIB_FUNC("pDuPEf3m4fI", Posix::sem_init);
|
||||
LIB_FUNC("cDW233RAwWo", Posix::sem_destroy);
|
||||
@@ -3394,7 +3393,7 @@ LIB_DEFINE(InitLibKernel_1) {
|
||||
LIB_FUNC("959qrazPIrg", LibKernel::KernelGetProcParam);
|
||||
LIB_FUNC("tU5e3f9gSiU", LibKernel::KernelIsTrinityMode);
|
||||
LIB_FUNC("NH6xARDOVv8", LibKernel::KernelGetOperationMode);
|
||||
LIB_FUNC("fTx66l5iWIA", LibKernel::KernelFsync);
|
||||
LIB_FUNC("fTx66l5iWIA", FileSystem::KernelFsync);
|
||||
LIB_FUNC("uvT2iYBBnkY", LibKernel::KernelSync);
|
||||
LIB_FUNC("HoLVWNanBBc", LibKernel::getpid);
|
||||
LIB_FUNC("9BcDykPmo1I", LibKernel::get_error_addr);
|
||||
|
||||
Reference in New Issue
Block a user