Serenity Operating System
at master 30 lines 873 B view raw
1/* 2 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7#include <AK/StringView.h> 8#include <Kernel/FileSystem/VirtualFileSystem.h> 9#include <Kernel/Process.h> 10 11namespace Kernel { 12 13ErrorOr<FlatPtr> Process::sys$utime(Userspace<char const*> user_path, size_t path_length, Userspace<const struct utimbuf*> user_buf) 14{ 15 VERIFY_NO_PROCESS_BIG_LOCK(this); 16 TRY(require_promise(Pledge::fattr)); 17 auto path = TRY(get_syscall_path_argument(user_path, path_length)); 18 utimbuf buf; 19 if (user_buf) { 20 TRY(copy_from_user(&buf, user_buf)); 21 } else { 22 auto now = kgettimeofday().to_truncated_seconds(); 23 // Not a bug! 24 buf = { now, now }; 25 } 26 TRY(VirtualFileSystem::the().utime(credentials(), path->view(), current_directory(), buf.actime, buf.modtime)); 27 return 0; 28} 29 30}