Kernel: Update tv_nsec field when using utimensat() with UTIME_NOW

We were only updating the tv_sec field and leaving UTIME_NOW in tv_nsec.
This commit is contained in:
Andreas Kling 2022-11-22 23:22:35 +01:00
parent 376b3c95f7
commit 5556b27e38
Notes: sideshowbarker 2024-07-17 11:33:34 +09:00

View file

@ -18,7 +18,7 @@ ErrorOr<FlatPtr> Process::sys$utimensat(Userspace<Syscall::SC_utimensat_params c
TRY(require_promise(Pledge::fattr)); TRY(require_promise(Pledge::fattr));
auto params = TRY(copy_typed_from_user(user_params)); auto params = TRY(copy_typed_from_user(user_params));
auto now = kgettimeofday().to_truncated_seconds(); auto now = kgettimeofday().to_timespec();
int dirfd = params.dirfd; int dirfd = params.dirfd;
int follow_symlink = params.flag & AT_SYMLINK_NOFOLLOW ? O_NOFOLLOW_NOERROR : 0; int follow_symlink = params.flag & AT_SYMLINK_NOFOLLOW ? O_NOFOLLOW_NOERROR : 0;
@ -27,16 +27,14 @@ ErrorOr<FlatPtr> Process::sys$utimensat(Userspace<Syscall::SC_utimensat_params c
if (params.times) { if (params.times) {
TRY(copy_from_user(times, params.times, sizeof(times))); TRY(copy_from_user(times, params.times, sizeof(times)));
if (times[0].tv_nsec == UTIME_NOW) if (times[0].tv_nsec == UTIME_NOW)
times[0].tv_sec = now; times[0] = now;
if (times[1].tv_nsec == UTIME_NOW) if (times[1].tv_nsec == UTIME_NOW)
times[1].tv_sec = now; times[1] = now;
} else { } else {
// According to POSIX, both access and modification times are set to // According to POSIX, both access and modification times are set to
// the current time given a nullptr. // the current time given a nullptr.
times[0].tv_sec = now; times[0] = now;
times[0].tv_nsec = UTIME_NOW; times[1] = now;
times[1].tv_sec = now;
times[1].tv_nsec = UTIME_NOW;
} }
OwnPtr<KString> path; OwnPtr<KString> path;