1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 08:58:11 +00:00

Kernel: Make Inode::lookup() return a KResultOr<NonnullRefPtr<Inode>>

This allows file systems to return arbitrary error codes instead of just
an Inode or not an Inode.
This commit is contained in:
Andreas Kling 2021-08-14 13:32:35 +02:00
parent 459115a59c
commit ef2720bcad
18 changed files with 83 additions and 72 deletions

View file

@ -136,21 +136,24 @@ KResult DevPtsFSInode::traverse_as_directory(Function<bool(FileSystem::Directory
return KSuccess;
}
RefPtr<Inode> DevPtsFSInode::lookup(StringView name)
KResultOr<NonnullRefPtr<Inode>> DevPtsFSInode::lookup(StringView name)
{
VERIFY(identifier().index() == 1);
if (name == "." || name == "..")
return this;
return *this;
auto& fs = static_cast<DevPtsFS&>(this->fs());
auto pty_index = name.to_uint();
if (pty_index.has_value() && s_ptys->contains(pty_index.value())) {
return fs.get_inode({ fsid(), pty_index_to_inode_index(pty_index.value()) });
auto inode = fs.get_inode({ fsid(), pty_index_to_inode_index(pty_index.value()) });
if (!inode)
return ENOENT;
return inode.release_nonnull();
}
return {};
return ENOENT;
}
void DevPtsFSInode::flush_metadata()