Serenity Operating System
1/*
2 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
3 *
4 * SPDX-License-Identifier: BSD-2-Clause
5 */
6
7#include <AK/StringView.h>
8#include <Kernel/FileSystem/VirtualFileSystem.h>
9#include <Kernel/Process.h>
10
11namespace Kernel {
12
13ErrorOr<FlatPtr> Process::sys$faccessat(Userspace<Syscall::SC_faccessat_params const*> user_params)
14{
15 VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this);
16 TRY(require_promise(Pledge::rpath));
17 auto params = TRY(copy_typed_from_user(user_params));
18 auto pathname = TRY(get_syscall_path_argument(params.pathname));
19
20 if ((params.flags & ~(AT_SYMLINK_NOFOLLOW | AT_EACCESS)) != 0)
21 return EINVAL;
22
23 auto flags = AccessFlags::None;
24 if (params.flags & AT_SYMLINK_NOFOLLOW)
25 flags |= AccessFlags::DoNotFollowSymlinks;
26 if (params.flags & AT_EACCESS)
27 flags |= AccessFlags::EffectiveAccess;
28
29 TRY(VirtualFileSystem::the().access(credentials(), pathname->view(), params.mode, TRY(custody_for_dirfd(params.dirfd)), flags));
30 return 0;
31}
32
33}