Kernel: Use TRY() in ISO9660FileSystem

This commit is contained in:
Andreas Kling 2021-09-06 02:06:49 +02:00
parent a994f11f10
commit 7a8061ba0c
Notes: sideshowbarker 2024-07-18 04:38:43 +09:00

View File

@ -63,12 +63,7 @@ public:
dbgln_if(ISO9660_VERY_DEBUG, "next(): Pushed into directory stack"); dbgln_if(ISO9660_VERY_DEBUG, "next(): Pushed into directory stack");
{ TRY(read_directory_contents());
auto result = read_directory_contents();
if (result.is_error()) {
return result;
}
}
dbgln_if(ISO9660_VERY_DEBUG, "next(): Read directory contents"); dbgln_if(ISO9660_VERY_DEBUG, "next(): Read directory contents");
@ -155,12 +150,7 @@ public:
private: private:
KResult read_directory_contents() KResult read_directory_contents()
{ {
auto result = m_fs.directory_entry_for_record({}, m_current_header); m_current_directory.entry = TRY(m_fs.directory_entry_for_record({}, m_current_header));
if (result.is_error()) {
return result.error();
}
m_current_directory.entry = result.value();
return KSuccess; return KSuccess;
} }
@ -199,12 +189,9 @@ ISO9660FS::~ISO9660FS()
KResult ISO9660FS::initialize() KResult ISO9660FS::initialize()
{ {
if (auto result = BlockBasedFileSystem::initialize(); result.is_error()) TRY(BlockBasedFileSystem::initialize());
return result; TRY(parse_volume_set());
if (auto result = parse_volume_set(); result.is_error()) TRY(create_root_inode());
return result;
if (auto result = create_root_inode(); result.is_error())
return result;
return KSuccess; return KSuccess;
} }
@ -305,12 +292,7 @@ KResult ISO9660FS::create_root_inode()
return EIO; return EIO;
} }
auto maybe_inode = ISO9660Inode::try_create_from_directory_record(*this, m_primary_volume->root_directory_record_header, {}); m_root_inode = TRY(ISO9660Inode::try_create_from_directory_record(*this, m_primary_volume->root_directory_record_header, {}));
if (maybe_inode.is_error()) {
return ENOMEM;
}
m_root_inode = maybe_inode.release_value();
return KSuccess; return KSuccess;
} }
@ -362,19 +344,11 @@ KResult ISO9660FS::visit_directory_record(ISO::DirectoryRecordHeader const& reco
ISO9660DirectoryIterator iterator { const_cast<ISO9660FS&>(*this), record }; ISO9660DirectoryIterator iterator { const_cast<ISO9660FS&>(*this), record };
while (!iterator.done()) { while (!iterator.done()) {
auto maybe_result = visitor(*iterator); auto decision = TRY(visitor(*iterator));
if (maybe_result.is_error()) { switch (decision) {
return maybe_result.error();
}
switch (maybe_result.value()) {
case RecursionDecision::Recurse: { case RecursionDecision::Recurse: {
auto maybe_has_moved = iterator.next(); auto has_moved = TRY(iterator.next());
if (maybe_has_moved.is_error()) { if (!has_moved) {
return maybe_has_moved.error();
}
if (!maybe_has_moved.value()) {
// If next() hasn't moved then we have read through all the // If next() hasn't moved then we have read through all the
// directories, and can exit. // directories, and can exit.
return KSuccess; return KSuccess;
@ -434,14 +408,11 @@ KResultOr<NonnullRefPtr<ISO9660FS::DirectoryEntry>> ISO9660FS::directory_entry_f
return EIO; return EIO;
} }
auto maybe_entry = DirectoryEntry::try_create(extent_location, data_length, move(blocks)); auto entry = TRY(DirectoryEntry::try_create(extent_location, data_length, move(blocks)));
if (maybe_entry.is_error()) { m_directory_entry_cache.set(key, entry);
return maybe_entry.error();
}
m_directory_entry_cache.set(key, maybe_entry.value());
dbgln_if(ISO9660_DEBUG, "Cached dirent @ {}", extent_location); dbgln_if(ISO9660_DEBUG, "Cached dirent @ {}", extent_location);
return maybe_entry.release_value(); return entry;
} }
u32 ISO9660FS::calculate_directory_entry_cache_key(ISO::DirectoryRecordHeader const& record) u32 ISO9660FS::calculate_directory_entry_cache_key(ISO::DirectoryRecordHeader const& record)