Merge pull request #2129 from sktharunbalaji13-cmd/contrib/scekernel-fdatasync

feat(libkernel): implement sceKernelFdatasync
This commit is contained in:
Dean 2026-10-11 07:19:45 +13:00 committed by GitHub
commit 2ece83f4dc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 9 deletions

View File

@ -463,6 +463,16 @@ int APS5_VABI sceKernelFsync(int fd) {
#endif
}
int APS5_VABI sceKernelFdatasync(int fd) {
if (fd >= GuestSockets::FirstDescriptor) return SceErrorFromErrno(GuestSockets::IsOpen(fd) ? GUEST_EINVAL : GUEST_EBADF);
#ifdef _WIN32
if (::_commit(fd) != 0) return SceErrorFromErrno(errno);
#else
if (::fdatasync(fd) != 0) return SceErrorFromErrno(errno);
#endif
return 0;
}
int APS5_VABI sceKernelWriteThrottlingStatus(std::uint64_t* status) {
if (status == nullptr) throw std::invalid_argument("sceKernelWriteThrottlingStatus: status is null");
status[0] = std::numeric_limits<std::uint32_t>::max();
@ -792,13 +802,7 @@ int APS5_VABI fsync_nid_postfix(int fd) {
}
int APS5_VABI fdatasync_nid_postfix(int fd) {
if (fd >= GuestSockets::FirstDescriptor) return PosixFailure(GuestSockets::IsOpen(fd) ? GUEST_EINVAL : GUEST_EBADF);
#ifdef _WIN32
if (::_commit(fd) != 0) return PosixResult(SceErrorFromErrno(errno));
#else
if (::fdatasync(fd) != 0) return PosixResult(SceErrorFromErrno(errno));
#endif
return 0;
return PosixResult(sceKernelFdatasync(fd));
}
}

View File

@ -21,6 +21,7 @@ int APS5_VABI futimes_nid_postfix(int, const KernelTimeval*);
int APS5_VABI socket_nid_postfix(int, int, int);
int APS5_VABI sceKernelFsync(int);
int APS5_VABI fdatasync_nid_postfix(int);
int APS5_VABI sceKernelFdatasync(int);
int APS5_VABI sceKernelWriteThrottlingStatus(std::uint64_t*);
int APS5_VABI sceKernelFtruncate(int, long long);
int APS5_VABI sceKernelTruncate_nid_postfix(const char*, long long);
@ -140,6 +141,7 @@ int main() {
#endif
Require(descriptor >= 0 && sceKernelFsync(descriptor) == 0);
Require(fdatasync_nid_postfix(descriptor) == 0);
Require(sceKernelFdatasync(descriptor) == 0);
const auto ownerWrite = [&] {
return (std::filesystem::status(sized).permissions() & std::filesystem::perms::owner_write) != std::filesystem::perms::none;
};
@ -158,22 +160,24 @@ int main() {
Require(futimes_nid_postfix(descriptor, negative) == -1 && *__error_nid_postfix() == 22);
Require(std::fclose(native) == 0);
Require(std::filesystem::file_size(sized) == 3);
#ifndef _WIN32
Require(sceKernelFchmod(descriptor, 0600) == static_cast<int>(0x80020009u));
Require(fchmod_nid_postfix(descriptor, 0600) == -1 && *__error_nid_postfix() == 9);
Require(futimes_nid_postfix(descriptor, nullptr) == -1 && *__error_nid_postfix() == 9);
Require(fdatasync_nid_postfix(descriptor) == -1 && *__error_nid_postfix() == 9);
#endif
Require(sceKernelFdatasync(descriptor) == static_cast<int>(0x80020009u));
const int socket = socket_nid_postfix(2, 2, 0);
Require(socket >= 0);
Require(sceKernelFchmod(socket, 0600) == static_cast<int>(0x80020016u));
Require(fchmod_nid_postfix(socket, 0600) == -1 && *__error_nid_postfix() == 22);
Require(futimes_nid_postfix(socket, nullptr) == -1 && *__error_nid_postfix() == 22);
Require(fdatasync_nid_postfix(socket) == -1 && *__error_nid_postfix() == 22);
Require(sceKernelFdatasync(socket) == static_cast<int>(0x80020016u));
Require(close_nid_postfix(socket) == 0);
Require(fchmod_nid_postfix(socket, 0600) == -1 && *__error_nid_postfix() == 9);
Require(futimes_nid_postfix(socket, nullptr) == -1 && *__error_nid_postfix() == 9);
Require(fdatasync_nid_postfix(socket) == -1 && *__error_nid_postfix() == 9);
Require(sceKernelFdatasync(socket) == static_cast<int>(0x80020009u));
Require(sceKernelFdatasync(0x7fffffff) == static_cast<int>(0x80020009u));
Require(remove_nid_postfix(sized.string().c_str()) == 0);
const auto present = root / "present.txt";
const auto presentName = present.string();