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$link(Userspace<Syscall::SC_link_params const*> user_params)
14{
15 VERIFY_NO_PROCESS_BIG_LOCK(this);
16 TRY(require_promise(Pledge::cpath));
17 auto params = TRY(copy_typed_from_user(user_params));
18 auto old_path = TRY(try_copy_kstring_from_user(params.old_path));
19 auto new_path = TRY(try_copy_kstring_from_user(params.new_path));
20 TRY(VirtualFileSystem::the().link(credentials(), old_path->view(), new_path->view(), current_directory()));
21 return 0;
22}
23
24ErrorOr<FlatPtr> Process::sys$symlink(Userspace<Syscall::SC_symlink_params const*> user_params)
25{
26 VERIFY_NO_PROCESS_BIG_LOCK(this);
27 TRY(require_promise(Pledge::cpath));
28 auto params = TRY(copy_typed_from_user(user_params));
29
30 auto target = TRY(get_syscall_path_argument(params.target));
31 auto linkpath = TRY(get_syscall_path_argument(params.linkpath));
32 TRY(VirtualFileSystem::the().symlink(credentials(), target->view(), linkpath->view(), TRY(custody_for_dirfd(params.dirfd))));
33 return 0;
34}
35
36}