chmod.cpp 863 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. ErrorOr<FlatPtr> Process::sys$chmod(Userspace<const char*> user_path, size_t path_length, mode_t mode)
  11. {
  12. VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this);
  13. TRY(require_promise(Pledge::fattr));
  14. auto path = TRY(get_syscall_path_argument(user_path, path_length));
  15. TRY(VirtualFileSystem::the().chmod(path->view(), mode, current_directory()));
  16. return 0;
  17. }
  18. ErrorOr<FlatPtr> Process::sys$fchmod(int fd, mode_t mode)
  19. {
  20. VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this);
  21. TRY(require_promise(Pledge::fattr));
  22. auto description = TRY(fds().open_file_description(fd));
  23. TRY(description->chmod(mode));
  24. return 0;
  25. }
  26. }