chmod.cpp 908 B

123456789101112131415161718192021222324252627282930313233
  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$chmod(Userspace<const char*> user_path, size_t path_length, mode_t mode)
  11. {
  12. VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this);
  13. REQUIRE_PROMISE(fattr);
  14. auto path = get_syscall_path_argument(user_path, path_length);
  15. if (path.is_error())
  16. return path.error();
  17. return VirtualFileSystem::the().chmod(path.value()->view(), mode, current_directory());
  18. }
  19. KResultOr<FlatPtr> Process::sys$fchmod(int fd, mode_t mode)
  20. {
  21. VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this);
  22. REQUIRE_PROMISE(fattr);
  23. auto description = fds().file_description(fd);
  24. if (!description)
  25. return EBADF;
  26. return description->chmod(mode);
  27. }
  28. }