1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:27:35 +00:00

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
parent 2d2ea05c97
commit a9204510a4
24 changed files with 62 additions and 155 deletions

View file

@ -34,13 +34,9 @@ KResultOr<FlatPtr> Process::sys$readv(int fd, Userspace<const struct iovec*> iov
return EINVAL;
}
auto description = fds().file_description(fd);
if (!description)
return EBADF;
auto description = TRY(fds().file_description(fd));
if (!description->is_readable())
return EBADF;
if (description->is_directory())
return EISDIR;
@ -75,9 +71,7 @@ KResultOr<FlatPtr> Process::sys$read(int fd, Userspace<u8*> buffer, size_t size)
if (size > NumericLimits<ssize_t>::max())
return EINVAL;
dbgln_if(IO_DEBUG, "sys$read({}, {}, {})", fd, buffer.ptr(), size);
auto description = fds().file_description(fd);
if (!description)
return EBADF;
auto description = TRY(fds().file_description(fd));
if (!description->is_readable())
return EBADF;
if (description->is_directory())