rename.cpp 893 B

1234567891011121314151617181920212223242526272829
  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$rename(Userspace<const Syscall::SC_rename_params*> user_params)
  11. {
  12. VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
  13. REQUIRE_PROMISE(cpath);
  14. Syscall::SC_rename_params params;
  15. if (!copy_from_user(&params, user_params))
  16. return EFAULT;
  17. auto old_path = get_syscall_path_argument(params.old_path);
  18. if (old_path.is_error())
  19. return old_path.error();
  20. auto new_path = get_syscall_path_argument(params.new_path);
  21. if (new_path.is_error())
  22. return new_path.error();
  23. return VirtualFileSystem::the().rename(old_path.value()->view(), new_path.value()->view(), current_directory());
  24. }
  25. }