Serenity Operating System
at master 31 lines 1.1 kB view raw
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/Custody.h> 9#include <Kernel/FileSystem/VirtualFileSystem.h> 10#include <Kernel/Process.h> 11 12namespace Kernel { 13 14ErrorOr<FlatPtr> Process::sys$realpath(Userspace<Syscall::SC_realpath_params const*> user_params) 15{ 16 VERIFY_NO_PROCESS_BIG_LOCK(this); 17 TRY(require_promise(Pledge::rpath)); 18 auto params = TRY(copy_typed_from_user(user_params)); 19 20 auto path = TRY(get_syscall_path_argument(params.path)); 21 auto custody = TRY(VirtualFileSystem::the().resolve_path(credentials(), path->view(), current_directory())); 22 auto absolute_path = TRY(custody->try_serialize_absolute_path()); 23 24 size_t ideal_size = absolute_path->length() + 1; 25 auto size_to_copy = min(ideal_size, params.buffer.size); 26 TRY(copy_to_user(params.buffer.data, absolute_path->characters(), size_to_copy)); 27 // Note: we return the whole size here, not the copied size. 28 return ideal_size; 29}; 30 31}