summaryrefslogtreecommitdiff
path: root/Kernel/FileSystem/Ext2FileSystem.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-08-14 13:32:35 +0200
committerAndreas Kling <kling@serenityos.org>2021-08-14 13:34:59 +0200
commitef2720bcad5840a6e174492eb55046e9edacc782 (patch)
tree81b8bdaf03b1ec32fae5b648f864d4f703077eed /Kernel/FileSystem/Ext2FileSystem.cpp
parent459115a59c05ef478b2f99f4089343ef64d65a1c (diff)
downloadserenity-ef2720bcad5840a6e174492eb55046e9edacc782.zip
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.
Diffstat (limited to 'Kernel/FileSystem/Ext2FileSystem.cpp')
-rw-r--r--Kernel/FileSystem/Ext2FileSystem.cpp14
1 files changed, 9 insertions, 5 deletions
diff --git a/Kernel/FileSystem/Ext2FileSystem.cpp b/Kernel/FileSystem/Ext2FileSystem.cpp
index 20876dc21d..b34582c934 100644
--- a/Kernel/FileSystem/Ext2FileSystem.cpp
+++ b/Kernel/FileSystem/Ext2FileSystem.cpp
@@ -1630,12 +1630,12 @@ KResult Ext2FSInode::populate_lookup_cache() const
return KSuccess;
}
-RefPtr<Inode> Ext2FSInode::lookup(StringView name)
+KResultOr<NonnullRefPtr<Inode>> Ext2FSInode::lookup(StringView name)
{
VERIFY(is_directory());
dbgln_if(EXT2_DEBUG, "Ext2FSInode[{}]:lookup(): Looking up '{}'", identifier(), name);
- if (populate_lookup_cache().is_error())
- return {};
+ if (auto result = populate_lookup_cache(); result.is_error())
+ return result;
InodeIndex inode_index;
{
@@ -1643,11 +1643,15 @@ RefPtr<Inode> Ext2FSInode::lookup(StringView name)
auto it = m_lookup_cache.find(name.hash(), [&](auto& entry) { return entry.key == name; });
if (it == m_lookup_cache.end()) {
dbgln_if(EXT2_DEBUG, "Ext2FSInode[{}]:lookup(): '{}' not found", identifier(), name);
- return {};
+ return ENOENT;
}
inode_index = it->value;
}
- return fs().get_inode({ fsid(), inode_index });
+
+ auto inode = fs().get_inode({ fsid(), inode_index });
+ if (!inode)
+ return ENOENT;
+ return inode.release_nonnull();
}
void Ext2FSInode::one_ref_left()