utime.cpp 867 B

12345678910111213141516171819202122232425262728293031
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/StringView.h>
  7. #include <Kernel/FileSystem/VirtualFileSystem.h>
  8. #include <Kernel/Process.h>
  9. namespace Kernel {
  10. KResultOr<FlatPtr> Process::sys$utime(Userspace<const char*> user_path, size_t path_length, Userspace<const struct utimbuf*> user_buf)
  11. {
  12. REQUIRE_PROMISE(fattr);
  13. auto path = get_syscall_path_argument(user_path, path_length);
  14. if (path.is_error())
  15. return path.error();
  16. utimbuf buf;
  17. if (user_buf) {
  18. if (!copy_from_user(&buf, user_buf))
  19. return EFAULT;
  20. } else {
  21. auto now = kgettimeofday().to_truncated_seconds();
  22. // Not a bug!
  23. buf = { now, now };
  24. }
  25. return VFS::the().utime(path.value()->view(), current_directory(), buf.actime, buf.modtime);
  26. }
  27. }