chmod.cpp 847 B

1234567891011121314151617181920212223242526272829303132
  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/FileDescription.h>
  8. #include <Kernel/FileSystem/VirtualFileSystem.h>
  9. #include <Kernel/Process.h>
  10. namespace Kernel {
  11. KResultOr<FlatPtr> Process::sys$chmod(Userspace<const char*> user_path, size_t path_length, mode_t mode)
  12. {
  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 VFS::the().chmod(path.value()->view(), mode, current_directory());
  18. }
  19. KResultOr<FlatPtr> Process::sys$fchmod(int fd, mode_t mode)
  20. {
  21. REQUIRE_PROMISE(fattr);
  22. auto description = file_description(fd);
  23. if (!description)
  24. return EBADF;
  25. return description->chmod(mode);
  26. }
  27. }