mknod.cpp 828 B

123456789101112131415161718192021222324252627
  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$mknod(Userspace<const Syscall::SC_mknod_params*> user_params)
  11. {
  12. REQUIRE_PROMISE(dpath);
  13. Syscall::SC_mknod_params params;
  14. if (!copy_from_user(&params, user_params))
  15. return EFAULT;
  16. if (!is_superuser() && !is_regular_file(params.mode) && !is_fifo(params.mode) && !is_socket(params.mode))
  17. return EPERM;
  18. auto path = get_syscall_path_argument(params.path);
  19. if (path.is_error())
  20. return path.error();
  21. return VFS::the().mknod(path.value()->view(), params.mode & ~umask(), params.dev, current_directory());
  22. }
  23. }