diff options
author | Andreas Kling <kling@serenityos.org> | 2021-09-05 15:30:15 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-05 15:30:15 +0200 |
commit | 865eb54f75ca893ab118a83c9b7a80c767d4231a (patch) | |
tree | 31bad586955d3d8b87054b5ffeacff43aae7514b /Kernel/FileSystem | |
parent | 83fed5b2de58e7ad9dc2da1f15dd5cf0e052cadd (diff) | |
download | serenity-865eb54f75ca893ab118a83c9b7a80c767d4231a.zip |
Kernel/Ext2FS: Use TRY() in the Ext2FS
This class was just *full* of great opportunities for TRY(). :^)
Diffstat (limited to 'Kernel/FileSystem')
-rw-r--r-- | Kernel/FileSystem/Ext2FileSystem.cpp | 183 |
1 files changed, 58 insertions, 125 deletions
diff --git a/Kernel/FileSystem/Ext2FileSystem.cpp b/Kernel/FileSystem/Ext2FileSystem.cpp index ce2fca0173..869cad637f 100644 --- a/Kernel/FileSystem/Ext2FileSystem.cpp +++ b/Kernel/FileSystem/Ext2FileSystem.cpp @@ -119,8 +119,7 @@ KResult Ext2FS::initialize() set_fragment_size(EXT2_FRAG_SIZE(&super_block)); // Note: This depends on the block size being available. - if (auto result = BlockBasedFileSystem::initialize(); result.is_error()) - return result; + TRY(BlockBasedFileSystem::initialize()); VERIFY(block_size() <= (int)max_block_size); @@ -139,10 +138,7 @@ KResult Ext2FS::initialize() return ENOMEM; } auto buffer = UserOrKernelBuffer::for_kernel_buffer(m_cached_group_descriptor_table->data()); - if (auto result = read_blocks(first_block_of_bgdt, blocks_to_read, buffer); result.is_error()) { - dbgln("Ext2FS: initialize had error: {}", result.error()); - return result; - } + TRY(read_blocks(first_block_of_bgdt, blocks_to_read, buffer)); if constexpr (EXT2_DEBUG) { for (unsigned i = 1; i <= m_block_group_count; ++i) { @@ -250,8 +246,7 @@ KResult Ext2FSInode::grow_doubly_indirect_block(BlockBasedFileSystem::BlockIndex auto buffer = UserOrKernelBuffer::for_kernel_buffer(stream.data()); if (old_blocks_length > 0) { - if (auto result = fs().read_block(block, &buffer, fs().block_size()); result.is_error()) - return result; + TRY(fs().read_block(block, &buffer, fs().block_size())); } // Grow the doubly indirect block. @@ -268,8 +263,7 @@ KResult Ext2FSInode::grow_doubly_indirect_block(BlockBasedFileSystem::BlockIndex // Write out the indirect blocks. for (unsigned i = old_blocks_length / entries_per_block; i < new_indirect_blocks_length; i++) { const auto offset_block = i * entries_per_block; - if (auto result = write_indirect_block(block_as_pointers[i], blocks_indices.slice(offset_block, min(blocks_indices.size() - offset_block, entries_per_block))); result.is_error()) - return result; + TRY(write_indirect_block(block_as_pointers[i], blocks_indices.slice(offset_block, min(blocks_indices.size() - offset_block, entries_per_block)))); } // Write out the doubly indirect block. @@ -289,22 +283,19 @@ KResult Ext2FSInode::shrink_doubly_indirect_block(BlockBasedFileSystem::BlockInd auto block_contents = ByteBuffer::create_uninitialized(fs().block_size()); auto* block_as_pointers = (unsigned*)block_contents.data(); auto buffer = UserOrKernelBuffer::for_kernel_buffer(reinterpret_cast<u8*>(block_as_pointers)); - if (auto result = fs().read_block(block, &buffer, fs().block_size()); result.is_error()) - return result; + TRY(fs().read_block(block, &buffer, fs().block_size())); // Free the unused indirect blocks. for (unsigned i = new_indirect_blocks_length; i < old_indirect_blocks_length; i++) { dbgln_if(EXT2_BLOCKLIST_DEBUG, "Ext2FSInode[{}]::shrink_doubly_indirect_block(): Freeing indirect block {} at index {}", identifier(), block_as_pointers[i], i); - if (auto result = fs().set_block_allocation_state(block_as_pointers[i], false); result.is_error()) - return result; + TRY(fs().set_block_allocation_state(block_as_pointers[i], false)); meta_blocks--; } // Free the doubly indirect block if no longer needed. if (new_blocks_length == 0) { dbgln_if(EXT2_BLOCKLIST_DEBUG, "Ext2FSInode[{}]::shrink_doubly_indirect_block(): Freeing doubly indirect block {}", identifier(), block); - if (auto result = fs().set_block_allocation_state(block, false); result.is_error()) - return result; + TRY(fs().set_block_allocation_state(block, false)); meta_blocks--; } @@ -328,8 +319,7 @@ KResult Ext2FSInode::grow_triply_indirect_block(BlockBasedFileSystem::BlockIndex auto buffer = UserOrKernelBuffer::for_kernel_buffer(stream.data()); if (old_blocks_length > 0) { - if (auto result = fs().read_block(block, &buffer, fs().block_size()); result.is_error()) - return result; + TRY(fs().read_block(block, &buffer, fs().block_size())); } // Grow the triply indirect block. @@ -348,8 +338,7 @@ KResult Ext2FSInode::grow_triply_indirect_block(BlockBasedFileSystem::BlockIndex const auto processed_blocks = i * entries_per_doubly_indirect_block; const auto old_doubly_indirect_blocks_length = min(old_blocks_length > processed_blocks ? old_blocks_length - processed_blocks : 0, entries_per_doubly_indirect_block); const auto new_doubly_indirect_blocks_length = min(blocks_indices.size() > processed_blocks ? blocks_indices.size() - processed_blocks : 0, entries_per_doubly_indirect_block); - if (auto result = grow_doubly_indirect_block(block_as_pointers[i], old_doubly_indirect_blocks_length, blocks_indices.slice(processed_blocks, new_doubly_indirect_blocks_length), new_meta_blocks, meta_blocks); result.is_error()) - return result; + TRY(grow_doubly_indirect_block(block_as_pointers[i], old_doubly_indirect_blocks_length, blocks_indices.slice(processed_blocks, new_doubly_indirect_blocks_length), new_meta_blocks, meta_blocks)); } // Write out the triply indirect block. @@ -370,8 +359,7 @@ KResult Ext2FSInode::shrink_triply_indirect_block(BlockBasedFileSystem::BlockInd auto block_contents = ByteBuffer::create_uninitialized(fs().block_size()); auto* block_as_pointers = (unsigned*)block_contents.data(); auto buffer = UserOrKernelBuffer::for_kernel_buffer(reinterpret_cast<u8*>(block_as_pointers)); - if (auto result = fs().read_block(block, &buffer, fs().block_size()); result.is_error()) - return result; + TRY(fs().read_block(block, &buffer, fs().block_size())); // Shrink the doubly indirect blocks. for (unsigned i = new_triply_indirect_blocks_length; i < old_triply_indirect_blocks_length; i++) { @@ -379,15 +367,13 @@ KResult Ext2FSInode::shrink_triply_indirect_block(BlockBasedFileSystem::BlockInd const auto old_doubly_indirect_blocks_length = min(old_blocks_length > processed_blocks ? old_blocks_length - processed_blocks : 0, entries_per_doubly_indirect_block); const auto new_doubly_indirect_blocks_length = min(new_blocks_length > processed_blocks ? new_blocks_length - processed_blocks : 0, entries_per_doubly_indirect_block); dbgln_if(EXT2_BLOCKLIST_DEBUG, "Ext2FSInode[{}]::shrink_triply_indirect_block(): Shrinking doubly indirect block {} at index {}", identifier(), block_as_pointers[i], i); - if (auto result = shrink_doubly_indirect_block(block_as_pointers[i], old_doubly_indirect_blocks_length, new_doubly_indirect_blocks_length, meta_blocks); result.is_error()) - return result; + TRY(shrink_doubly_indirect_block(block_as_pointers[i], old_doubly_indirect_blocks_length, new_doubly_indirect_blocks_length, meta_blocks)); } // Free the triply indirect block if no longer needed. if (new_blocks_length == 0) { dbgln_if(EXT2_BLOCKLIST_DEBUG, "Ext2FSInode[{}]::shrink_triply_indirect_block(): Freeing triply indirect block {}", identifier(), block); - if (auto result = fs().set_block_allocation_state(block, false); result.is_error()) - return result; + TRY(fs().set_block_allocation_state(block, false)); meta_blocks--; } @@ -413,10 +399,7 @@ KResult Ext2FSInode::flush_block_list() Vector<Ext2FS::BlockIndex> new_meta_blocks; if (new_shape.meta_blocks > old_shape.meta_blocks) { - auto blocks_or_error = fs().allocate_blocks(fs().group_index_from_inode(index()), new_shape.meta_blocks - old_shape.meta_blocks); - if (blocks_or_error.is_error()) - return blocks_or_error.error(); - new_meta_blocks = blocks_or_error.release_value(); + new_meta_blocks = TRY(fs().allocate_blocks(fs().group_index_from_inode(index()), new_shape.meta_blocks - old_shape.meta_blocks)); } m_raw_inode.i_blocks = (m_block_list.size() + new_shape.meta_blocks) * (fs().block_size() / 512); @@ -465,12 +448,10 @@ KResult Ext2FSInode::flush_block_list() old_shape.meta_blocks++; } - if (auto result = write_indirect_block(m_raw_inode.i_block[EXT2_IND_BLOCK], m_block_list.span().slice(output_block_index, new_shape.indirect_blocks)); result.is_error()) - return result; + TRY(write_indirect_block(m_raw_inode.i_block[EXT2_IND_BLOCK], m_block_list.span().slice(output_block_index, new_shape.indirect_blocks))); } else if ((new_shape.indirect_blocks == 0) && (old_shape.indirect_blocks != 0)) { dbgln_if(EXT2_BLOCKLIST_DEBUG, "Ext2FSInode[{}]::flush_block_list(): Freeing indirect block: {}", identifier(), m_raw_inode.i_block[EXT2_IND_BLOCK]); - if (auto result = fs().set_block_allocation_state(m_raw_inode.i_block[EXT2_IND_BLOCK], false); result.is_error()) - return result; + TRY(fs().set_block_allocation_state(m_raw_inode.i_block[EXT2_IND_BLOCK], false)); old_shape.meta_blocks--; m_raw_inode.i_block[EXT2_IND_BLOCK] = 0; } @@ -489,11 +470,9 @@ KResult Ext2FSInode::flush_block_list() set_metadata_dirty(true); old_shape.meta_blocks++; } - if (auto result = grow_doubly_indirect_block(m_raw_inode.i_block[EXT2_DIND_BLOCK], old_shape.doubly_indirect_blocks, m_block_list.span().slice(output_block_index, new_shape.doubly_indirect_blocks), new_meta_blocks, old_shape.meta_blocks); result.is_error()) - return result; + TRY(grow_doubly_indirect_block(m_raw_inode.i_block[EXT2_DIND_BLOCK], old_shape.doubly_indirect_blocks, m_block_list.span().slice(output_block_index, new_shape.doubly_indirect_blocks), new_meta_blocks, old_shape.meta_blocks)); } else { - if (auto result = shrink_doubly_indirect_block(m_raw_inode.i_block[EXT2_DIND_BLOCK], old_shape.doubly_indirect_blocks, new_shape.doubly_indirect_blocks, old_shape.meta_blocks); result.is_error()) - return result; + TRY(shrink_doubly_indirect_block(m_raw_inode.i_block[EXT2_DIND_BLOCK], old_shape.doubly_indirect_blocks, new_shape.doubly_indirect_blocks, old_shape.meta_blocks)); if (new_shape.doubly_indirect_blocks == 0) m_raw_inode.i_block[EXT2_DIND_BLOCK] = 0; } @@ -512,11 +491,9 @@ KResult Ext2FSInode::flush_block_list() set_metadata_dirty(true); old_shape.meta_blocks++; } - if (auto result = grow_triply_indirect_block(m_raw_inode.i_block[EXT2_TIND_BLOCK], old_shape.triply_indirect_blocks, m_block_list.span().slice(output_block_index, new_shape.triply_indirect_blocks), new_meta_blocks, old_shape.meta_blocks); result.is_error()) - return result; + TRY(grow_triply_indirect_block(m_raw_inode.i_block[EXT2_TIND_BLOCK], old_shape.triply_indirect_blocks, m_block_list.span().slice(output_block_index, new_shape.triply_indirect_blocks), new_meta_blocks, old_shape.meta_blocks)); } else { - if (auto result = shrink_triply_indirect_block(m_raw_inode.i_block[EXT2_TIND_BLOCK], old_shape.triply_indirect_blocks, new_shape.triply_indirect_blocks, old_shape.meta_blocks); result.is_error()) - return result; + TRY(shrink_triply_indirect_block(m_raw_inode.i_block[EXT2_TIND_BLOCK], old_shape.triply_indirect_blocks, new_shape.triply_indirect_blocks, old_shape.meta_blocks)); if (new_shape.triply_indirect_blocks == 0) m_raw_inode.i_block[EXT2_TIND_BLOCK] = 0; } @@ -933,10 +910,8 @@ KResult Ext2FSInode::resize(u64 new_size) m_block_list = this->compute_block_list(); if (blocks_needed_after > blocks_needed_before) { - auto blocks_or_error = fs().allocate_blocks(fs().group_index_from_inode(index()), blocks_needed_after - blocks_needed_before); - if (blocks_or_error.is_error()) - return blocks_or_error.error(); - if (!m_block_list.try_extend(blocks_or_error.release_value())) + auto blocks = TRY(fs().allocate_blocks(fs().group_index_from_inode(index()), blocks_needed_after - blocks_needed_before)); + if (!m_block_list.try_extend(move(blocks))) return ENOMEM; } else if (blocks_needed_after < blocks_needed_before) { if constexpr (EXT2_VERY_DEBUG) { @@ -956,8 +931,7 @@ KResult Ext2FSInode::resize(u64 new_size) } } - if (auto result = flush_block_list(); result.is_error()) - return result; + TRY(flush_block_list()); m_raw_inode.i_size = new_size; if (Kernel::is_regular_file(m_raw_inode.i_mode)) @@ -972,12 +946,10 @@ KResult Ext2FSInode::resize(u64 new_size) auto clear_from = old_size; u8 zero_buffer[PAGE_SIZE] {}; while (bytes_to_clear) { - auto result = write_bytes(clear_from, min(static_cast<u64>(sizeof(zero_buffer)), bytes_to_clear), UserOrKernelBuffer::for_kernel_buffer(zero_buffer), nullptr); - if (result.is_error()) - return result.error(); - VERIFY(result.value() != 0); - bytes_to_clear -= result.value(); - clear_from += result.value(); + auto nwritten = TRY(write_bytes(clear_from, min(static_cast<u64>(sizeof(zero_buffer)), bytes_to_clear), UserOrKernelBuffer::for_kernel_buffer(zero_buffer), nullptr)); + VERIFY(nwritten != 0); + bytes_to_clear -= nwritten; + clear_from += nwritten; } } @@ -993,8 +965,7 @@ KResultOr<size_t> Ext2FSInode::write_bytes(off_t offset, size_t count, const Use MutexLocker inode_locker(m_inode_lock); - if (auto result = prepare_to_write_data(); result.is_error()) - return result; + TRY(prepare_to_write_data()); if (is_symlink()) { VERIFY(offset == 0); @@ -1014,8 +985,7 @@ KResultOr<size_t> Ext2FSInode::write_bytes(off_t offset, size_t count, const Use const auto block_size = fs().block_size(); auto new_size = max(static_cast<u64>(offset) + count, size()); - if (auto result = resize(new_size); result.is_error()) - return result; + TRY(resize(new_size)); if (m_block_list.is_empty()) m_block_list = compute_block_list(); @@ -1098,8 +1068,7 @@ KResult Ext2FSInode::traverse_as_directory(Function<bool(FileSystem::DirectoryEn // so we can iterate over blocks separately. for (u64 offset = 0; offset < file_size; offset += block_size) { - if (auto result = read_bytes(offset, block_size, buf, nullptr); result.is_error()) - return result.error(); + TRY(read_bytes(offset, block_size, buf, nullptr)); auto* entry = reinterpret_cast<ext2_dir_entry_2*>(buffer); auto* entries_end = reinterpret_cast<ext2_dir_entry_2*>(buffer + block_size); @@ -1163,15 +1132,12 @@ KResult Ext2FSInode::write_directory(Vector<Ext2FSDirectoryEntry>& entries) VERIFY(stream.is_end()); - if (auto result = resize(stream.size()); result.is_error()) - return result; + TRY(resize(stream.size())); auto buffer = UserOrKernelBuffer::for_kernel_buffer(stream.data()); - auto result = write_bytes(0, stream.size(), buffer, nullptr); - if (result.is_error()) - return result.error(); + auto nwritten = TRY(write_bytes(0, stream.size(), buffer, nullptr)); set_metadata_dirty(true); - if (static_cast<size_t>(result.value()) != directory_data.size()) + if (nwritten != directory_data.size()) return EIO; return KSuccess; } @@ -1212,17 +1178,12 @@ KResult Ext2FSInode::add_child(Inode& child, const StringView& name, mode_t mode return EEXIST; } - result = child.increment_link_count(); - if (result.is_error()) - return result; + TRY(child.increment_link_count()); entries.empend(name, child.index(), to_ext2_file_type(mode)); - result = write_directory(entries); - if (result.is_error()) - return result; - if (auto populate_result = populate_lookup_cache(); populate_result.is_error()) - return populate_result; + TRY(write_directory(entries)); + TRY(populate_lookup_cache()); m_lookup_cache.set(name, child.index()); did_add_child(child.identifier(), name); @@ -1235,8 +1196,7 @@ KResult Ext2FSInode::remove_child(const StringView& name) dbgln_if(EXT2_DEBUG, "Ext2FSInode[{}]::remove_child(): Removing '{}'", identifier(), name); VERIFY(is_directory()); - if (auto populate_result = populate_lookup_cache(); populate_result.is_error()) - return populate_result; + TRY(populate_lookup_cache()); auto it = m_lookup_cache.find(name); if (it == m_lookup_cache.end()) @@ -1254,16 +1214,12 @@ KResult Ext2FSInode::remove_child(const StringView& name) if (result.is_error()) return result; - result = write_directory(entries); - if (result.is_error()) - return result; + TRY(write_directory(entries)); m_lookup_cache.remove(name); auto child_inode = fs().get_inode(child_id); - result = child_inode->decrement_link_count(); - if (result.is_error()) - return result; + TRY(child_inode->decrement_link_count()); did_remove_child(child_id, name); return KSuccess; @@ -1337,13 +1293,10 @@ auto Ext2FS::allocate_blocks(GroupIndex preferred_group_index, size_t count) -> VERIFY(found_a_group); auto& bgd = group_descriptor(group_index); - auto cached_bitmap_or_error = get_bitmap_block(bgd.bg_block_bitmap); - if (cached_bitmap_or_error.is_error()) - return cached_bitmap_or_error.error(); - auto& cached_bitmap = *cached_bitmap_or_error.value(); + auto* cached_bitmap = TRY(get_bitmap_block(bgd.bg_block_bitmap)); int blocks_in_group = min(blocks_per_group(), super_block().s_blocks_count); - auto block_bitmap = cached_bitmap.bitmap(blocks_in_group); + auto block_bitmap = cached_bitmap->bitmap(blocks_in_group); BlockIndex first_block_in_group = (group_index.value() - 1) * blocks_per_group() + first_block_index().value(); size_t free_region_size = 0; @@ -1400,11 +1353,8 @@ KResultOr<InodeIndex> Ext2FS::allocate_inode(GroupIndex preferred_group) unsigned inodes_in_group = min(inodes_per_group(), super_block().s_inodes_count); InodeIndex first_inode_in_group = (group_index.value() - 1) * inodes_per_group() + 1; - auto cached_bitmap_or_error = get_bitmap_block(bgd.bg_inode_bitmap); - if (cached_bitmap_or_error.is_error()) - return cached_bitmap_or_error.error(); - auto& cached_bitmap = *cached_bitmap_or_error.value(); - auto inode_bitmap = cached_bitmap.bitmap(inodes_in_group); + auto* cached_bitmap = TRY(get_bitmap_block(bgd.bg_inode_bitmap)); + auto inode_bitmap = cached_bitmap->bitmap(inodes_in_group); for (size_t i = 0; i < inode_bitmap.size(); ++i) { if (inode_bitmap.get(i)) continue; @@ -1412,7 +1362,7 @@ KResultOr<InodeIndex> Ext2FS::allocate_inode(GroupIndex preferred_group) auto inode_index = InodeIndex(first_inode_in_group.value() + i); - cached_bitmap.dirty = true; + cached_bitmap->dirty = true; m_super_block.s_free_inodes_count--; m_super_block_dirty = true; const_cast<ext2_group_desc&>(bgd).bg_free_inodes_count--; @@ -1452,25 +1402,20 @@ KResultOr<bool> Ext2FS::get_inode_allocation_state(InodeIndex index) const unsigned index_in_group = index.value() - ((group_index.value() - 1) * inodes_per_group()); unsigned bit_index = (index_in_group - 1) % inodes_per_group(); - auto cached_bitmap_or_error = const_cast<Ext2FS&>(*this).get_bitmap_block(bgd.bg_inode_bitmap); - if (cached_bitmap_or_error.is_error()) - return cached_bitmap_or_error.error(); - return cached_bitmap_or_error.value()->bitmap(inodes_per_group()).get(bit_index); + auto* cached_bitmap = TRY(const_cast<Ext2FS&>(*this).get_bitmap_block(bgd.bg_inode_bitmap)); + return cached_bitmap->bitmap(inodes_per_group()).get(bit_index); } KResult Ext2FS::update_bitmap_block(BlockIndex bitmap_block, size_t bit_index, bool new_state, u32& super_block_counter, u16& group_descriptor_counter) { - auto cached_bitmap_or_error = get_bitmap_block(bitmap_block); - if (cached_bitmap_or_error.is_error()) - return cached_bitmap_or_error.error(); - auto& cached_bitmap = *cached_bitmap_or_error.value(); - bool current_state = cached_bitmap.bitmap(blocks_per_group()).get(bit_index); + auto* cached_bitmap = TRY(get_bitmap_block(bitmap_block)); + bool current_state = cached_bitmap->bitmap(blocks_per_group()).get(bit_index); if (current_state == new_state) { dbgln("Ext2FS: Bit {} in bitmap block {} had unexpected state {}", bit_index, bitmap_block, current_state); return EIO; } - cached_bitmap.bitmap(blocks_per_group()).set(bit_index, new_state); - cached_bitmap.dirty = true; + cached_bitmap->bitmap(blocks_per_group()).set(bit_index, new_state); + cached_bitmap->dirty = true; if (new_state) { --super_block_counter; @@ -1544,11 +1489,7 @@ KResult Ext2FS::create_directory(Ext2FSInode& parent_inode, StringView name, mod MutexLocker locker(m_lock); VERIFY(is_directory(mode)); - auto inode_or_error = create_inode(parent_inode, name, mode, 0, uid, gid); - if (inode_or_error.is_error()) - return inode_or_error.error(); - - auto& inode = inode_or_error.value(); + auto inode = TRY(create_inode(parent_inode, name, mode, 0, uid, gid)); dbgln_if(EXT2_DEBUG, "Ext2FS: create_directory: created new directory named '{} with inode {}", name, inode->index()); @@ -1556,11 +1497,8 @@ KResult Ext2FS::create_directory(Ext2FSInode& parent_inode, StringView name, mod entries.empend(".", inode->index(), static_cast<u8>(EXT2_FT_DIR)); entries.empend("..", parent_inode.index(), static_cast<u8>(EXT2_FT_DIR)); - if (auto result = static_cast<Ext2FSInode&>(*inode).write_directory(entries); result.is_error()) - return result; - - if (auto result = parent_inode.increment_link_count(); result.is_error()) - return result; + TRY(static_cast<Ext2FSInode&>(*inode).write_directory(entries)); + TRY(parent_inode.increment_link_count()); auto& bgd = const_cast<ext2_group_desc&>(group_descriptor(group_index_from_inode(inode->identifier().index()))); ++bgd.bg_used_dirs_count; @@ -1597,20 +1535,17 @@ KResultOr<NonnullRefPtr<Inode>> Ext2FS::create_inode(Ext2FSInode& parent_inode, else if (is_block_device(mode)) e2inode.i_block[1] = dev; - auto inode_id = allocate_inode(); - if (inode_id.is_error()) - return inode_id.error(); + auto inode_id = TRY(allocate_inode()); dbgln_if(EXT2_DEBUG, "Ext2FS: writing initial metadata for inode {}", inode_id.value()); - auto success = write_ext2_inode(inode_id.value(), e2inode); + auto success = write_ext2_inode(inode_id, e2inode); VERIFY(success); - auto new_inode = get_inode({ fsid(), inode_id.value() }); + auto new_inode = get_inode({ fsid(), inode_id }); VERIFY(new_inode); dbgln_if(EXT2_DEBUG, "Ext2FS: Adding inode '{}' (mode {:o}) to parent directory {}", name, mode, parent_inode.index()); - if (auto result = parent_inode.add_child(*new_inode, name, mode); result.is_error()) - return result; + TRY(parent_inode.add_child(*new_inode, name, mode)); return new_inode.release_nonnull(); } @@ -1638,8 +1573,7 @@ KResultOr<NonnullRefPtr<Inode>> Ext2FSInode::lookup(StringView name) { VERIFY(is_directory()); dbgln_if(EXT2_DEBUG, "Ext2FSInode[{}]:lookup(): Looking up '{}'", identifier(), name); - if (auto result = populate_lookup_cache(); result.is_error()) - return result; + TRY(populate_lookup_cache()); InodeIndex inode_index; { @@ -1756,8 +1690,7 @@ KResult Ext2FSInode::truncate(u64 size) MutexLocker locker(m_inode_lock); if (static_cast<u64>(m_raw_inode.i_size) == size) return KSuccess; - if (auto result = resize(size); result.is_error()) - return result; + TRY(resize(size)); set_metadata_dirty(true); return KSuccess; } |