2020-07-30 21:38:15 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-07-30 21:38:15 +00:00
|
|
|
*/
|
|
|
|
|
2021-09-07 11:39:11 +00:00
|
|
|
#include <Kernel/FileSystem/OpenFileDescription.h>
|
2020-07-30 21:38:15 +00:00
|
|
|
#include <Kernel/Process.h>
|
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
2021-06-28 18:59:35 +00:00
|
|
|
KResultOr<FlatPtr> Process::sys$get_dir_entries(int fd, Userspace<void*> user_buffer, size_t user_size)
|
2020-07-30 21:38:15 +00:00
|
|
|
{
|
2021-07-18 18:20:12 +00:00
|
|
|
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this);
|
2020-07-30 21:38:15 +00:00
|
|
|
REQUIRE_PROMISE(stdio);
|
2021-06-16 14:44:15 +00:00
|
|
|
if (user_size > NumericLimits<ssize_t>::max())
|
2021-03-01 12:49:16 +00:00
|
|
|
return EINVAL;
|
2021-09-07 11:41:27 +00:00
|
|
|
auto description = TRY(fds().open_file_description(fd));
|
2021-03-01 14:04:31 +00:00
|
|
|
auto buffer = UserOrKernelBuffer::for_user_buffer(user_buffer, static_cast<size_t>(user_size));
|
|
|
|
if (!buffer.has_value())
|
2021-03-01 12:49:16 +00:00
|
|
|
return EFAULT;
|
2021-06-28 18:59:35 +00:00
|
|
|
auto result = description->get_dir_entries(buffer.value(), user_size);
|
|
|
|
if (result.is_error())
|
|
|
|
return result.error();
|
|
|
|
else
|
|
|
|
return result.release_value();
|
2020-07-30 21:38:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|