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

Kernel: Make FileSystem::get_inode() return KResultOr<NRP<Inode>>

This allows for natural error propagation in a bunch of new places.
This commit is contained in:
Andreas Kling 2021-09-05 18:55:55 +02:00
parent 12d9a6c1fa
commit caaeae9607
8 changed files with 33 additions and 49 deletions

View file

@ -55,15 +55,16 @@ Inode& DevPtsFS::root_inode()
return *m_root_inode;
}
RefPtr<Inode> DevPtsFS::get_inode(InodeIdentifier inode_id) const
KResultOr<NonnullRefPtr<Inode>> DevPtsFS::get_inode(InodeIdentifier inode_id) const
{
if (inode_id.index() == 1)
return m_root_inode;
return *m_root_inode;
unsigned pty_index = inode_index_to_pty_index(inode_id.index());
auto* device = Device::get_device(201, pty_index);
VERIFY(device);
// FIXME: Handle OOM
auto inode = adopt_ref(*new DevPtsFSInode(const_cast<DevPtsFS&>(*this), inode_id.index(), static_cast<SlavePTY*>(device)));
inode->m_metadata.inode = inode_id;
inode->m_metadata.size = 0;
@ -142,10 +143,7 @@ KResultOr<NonnullRefPtr<Inode>> DevPtsFSInode::lookup(StringView name)
for (SlavePTY& slave_pty : list) {
if (slave_pty.index() != pty_index.value())
continue;
auto inode = fs().get_inode({ fsid(), pty_index_to_inode_index(pty_index.value()) });
if (!inode)
return ENOENT;
return inode.release_nonnull();
return fs().get_inode({ fsid(), pty_index_to_inode_index(pty_index.value()) });
}
return ENOENT;
});