feat(libkernel): implement futimes

This commit is contained in:
Nahuel Genchi
2026-10-05 20:47:34 -03:00
parent eded1e010f
commit ec17b9811c
3 changed files with 35 additions and 5 deletions
@@ -65,6 +65,10 @@ static int NativeUtimes(const std::filesystem::path& path, const KernelTimeval*
struct _utimbuf values{static_cast<time_t>(times[0].tv_sec), static_cast<time_t>(times[1].tv_sec)};
return ::_wutime(path.wstring().c_str(), &values);
}
static int NativeFutimes(int descriptor, const KernelTimeval* times) {
const auto path = NativeDescriptorPath(descriptor);
return path ? NativeUtimes(*path, times) : -1;
}
static int NativeFlock(int descriptor, int operation) {
HANDLE handle = reinterpret_cast<HANDLE>(::_get_osfhandle(descriptor));
if (handle == INVALID_HANDLE_VALUE) {
@@ -136,6 +140,12 @@ static int NativeUtimes(const std::filesystem::path& path, const KernelTimeval*
{static_cast<time_t>(times[1].tv_sec), static_cast<suseconds_t>(times[1].tv_usec)}};
return ::utimes(path.c_str(), values);
}
static int NativeFutimes(int descriptor, const KernelTimeval* times) {
if (times == nullptr) return ::futimes(descriptor, nullptr);
struct timeval values[2]{{static_cast<time_t>(times[0].tv_sec), static_cast<suseconds_t>(times[0].tv_usec)},
{static_cast<time_t>(times[1].tv_sec), static_cast<suseconds_t>(times[1].tv_usec)}};
return ::futimes(descriptor, values);
}
static int NativeFlock(int descriptor, int operation) {
return ::flock(descriptor, operation);
}
@@ -531,6 +541,17 @@ int APS5_VABI utimes_nid_postfix(const char* path, const KernelTimeval* times) {
return PosixResult(sceKernelUtimes_nid_postfix(path, times));
}
int APS5_VABI futimes_nid_postfix(int d, const KernelTimeval* times) {
if (d >= GuestSockets::FirstDescriptor) return PosixFailure(GuestSockets::IsOpen(d) ? GUEST_EINVAL : GUEST_EBADF);
if (times != nullptr) {
for (int i = 0; i < 2; ++i) {
if (times[i].tv_usec < 0 || times[i].tv_usec >= 1000000) return PosixFailure(GUEST_EINVAL);
}
}
if (NativeFutimes(d, times) != 0) return PosixResult(SceErrorFromErrno(errno));
return 0;
}
int APS5_VABI fsync_nid_postfix(int fd) {
if (sceKernelFsync(fd) != 0) return PosixFailure(errno);
return 0;
@@ -27,11 +27,6 @@ int APS5_VABI pthread_cancel_nid_postfix(void) {
NotImplemented_nid_no_patch("0D4-FVvEikw");
return 0;
}
int APS5_VABI futimes_nid_postfix(void) {
NotImplemented_nid_no_patch(__func__);
return 0;
}
int APS5_VABI recvmsg_nid_postfix(void) {
NotImplemented_nid_no_patch(__func__);
return 0;
+14
View File
@@ -11,6 +11,7 @@ int APS5_VABI rename_nid_postfix(const char*, const char*);
int APS5_VABI sceKernelChmod_nid_postfix(const char*, unsigned short);
int APS5_VABI sceKernelFchmod(int, unsigned short);
int APS5_VABI fchmod_nid_postfix(int, int);
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 sceKernelFtruncate(int, long long);
@@ -83,18 +84,31 @@ int main() {
Require(sceKernelFchmod(descriptor, 0400) == 0 && !ownerWrite());
Require(fchmod_nid_postfix(descriptor, 0600) == 0 && ownerWrite());
Require(sceKernelFtruncate(descriptor, 3) == 0);
FileStat times{};
const KernelTimeval past[2]{{1000000000, 0}, {1000000000, 500000}};
Require(futimes_nid_postfix(descriptor, past) == 0);
Require(stat_nid_postfix(sized.string().c_str(), &times) == 0 && times.st_mtim.tv_sec == 1000000000);
Require(futimes_nid_postfix(descriptor, nullptr) == 0);
Require(stat_nid_postfix(sized.string().c_str(), &times) == 0 && times.st_mtim.tv_sec > 1000000000);
const KernelTimeval overflow[2]{{0, 0}, {0, 1000000}};
Require(futimes_nid_postfix(descriptor, overflow) == -1 && *__error_nid_postfix() == 22);
const KernelTimeval negative[2]{{0, -1}, {0, 0}};
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);
#endif
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(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(remove_nid_postfix(sized.string().c_str()) == 0);
const auto present = root / "present.txt";
const auto presentName = present.string();