Kernel: Make file description lookup return KResultOr

Instead of checking it at every call site (to generate EBADF), we make
file_description(fd) return a KResultOr<NonnullRefPtr<FileDescription>>.

This allows us to wrap all the calls in TRY(). :^)

The only place that got a little bit messier from this is sys$mount(),
and there's a whole bunch of things there in need of cleanup.
This commit is contained in:
Andreas Kling 2021-09-05 18:34:28 +02:00
commit a9204510a4
Notes: sideshowbarker 2024-07-18 04:40:44 +09:00
24 changed files with 62 additions and 155 deletions

View file

@ -46,9 +46,7 @@ KResultOr<FlatPtr> Process::sys$open(Userspace<const Syscall::SC_open_params*> u
if (dirfd == AT_FDCWD) {
base = current_directory();
} else {
auto base_description = fds().file_description(dirfd);
if (!base_description)
return EBADF;
auto base_description = TRY(fds().file_description(dirfd));
if (!base_description->is_directory())
return ENOTDIR;
if (!base_description->custody())
@ -70,10 +68,7 @@ KResultOr<FlatPtr> Process::sys$close(int fd)
{
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
REQUIRE_PROMISE(stdio);
auto description = fds().file_description(fd);
dbgln_if(IO_DEBUG, "sys$close({}) {}", fd, description.ptr());
if (!description)
return EBADF;
auto description = TRY(fds().file_description(fd));
auto result = description->close();
m_fds[fd] = {};
return result;