2020-07-31 00:38:15 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-07-31 00:38:15 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <AK/StringView.h>
|
|
|
|
#include <Kernel/FileSystem/Custody.h>
|
|
|
|
#include <Kernel/FileSystem/VirtualFileSystem.h>
|
|
|
|
#include <Kernel/Process.h>
|
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
2021-03-01 15:49:16 +03:00
|
|
|
KResultOr<int> Process::sys$realpath(Userspace<const Syscall::SC_realpath_params*> user_params)
|
2020-07-31 00:38:15 +03:00
|
|
|
{
|
|
|
|
REQUIRE_PROMISE(rpath);
|
|
|
|
|
|
|
|
Syscall::SC_realpath_params params;
|
2020-09-12 06:11:07 +03:00
|
|
|
if (!copy_from_user(¶ms, user_params))
|
2021-03-01 15:49:16 +03:00
|
|
|
return EFAULT;
|
2020-07-31 00:38:15 +03:00
|
|
|
|
|
|
|
auto path = get_syscall_path_argument(params.path);
|
|
|
|
if (path.is_error())
|
|
|
|
return path.error();
|
|
|
|
|
2021-05-29 17:59:40 +03:00
|
|
|
auto custody_or_error = VFS::the().resolve_path(path.value()->view(), current_directory());
|
2020-07-31 00:38:15 +03:00
|
|
|
if (custody_or_error.is_error())
|
|
|
|
return custody_or_error.error();
|
|
|
|
auto& custody = custody_or_error.value();
|
|
|
|
auto absolute_path = custody->absolute_path();
|
|
|
|
|
2021-01-16 00:29:40 +03:00
|
|
|
size_t ideal_size = absolute_path.length() + 1;
|
|
|
|
auto size_to_copy = min(ideal_size, params.buffer.size);
|
|
|
|
if (!copy_to_user(params.buffer.data, absolute_path.characters(), size_to_copy))
|
2021-03-01 15:49:16 +03:00
|
|
|
return EFAULT;
|
2021-01-16 00:29:40 +03:00
|
|
|
// Note: we return the whole size here, not the copied size.
|
|
|
|
return ideal_size;
|
2020-07-31 00:38:15 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|