rename.cpp 807 B

123456789101112131415161718192021222324
  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. ErrorOr<FlatPtr> Process::sys$rename(Userspace<Syscall::SC_rename_params const*> user_params)
  11. {
  12. VERIFY_NO_PROCESS_BIG_LOCK(this);
  13. TRY(require_promise(Pledge::cpath));
  14. auto params = TRY(copy_typed_from_user(user_params));
  15. auto old_path = TRY(get_syscall_path_argument(params.old_path));
  16. auto new_path = TRY(get_syscall_path_argument(params.new_path));
  17. TRY(VirtualFileSystem::the().rename(credentials(), TRY(custody_for_dirfd(params.olddirfd)), old_path->view(), TRY(custody_for_dirfd(params.newdirfd)), new_path->view()));
  18. return 0;
  19. }
  20. }