Skip to content

Commit

Permalink
Kernel: Make Ext2FS::write_ext2_inode() return KResult
Browse files Browse the repository at this point in the history
This allows us to use TRY() in more places.
  • Loading branch information
awesomekling committed Oct 21, 2021
1 parent 6f69d52 commit 98b865f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
18 changes: 7 additions & 11 deletions Kernel/FileSystem/Ext2FileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,8 @@ void Ext2FS::free_inode(Ext2FSInode& inode)
// NOTE: After this point, the inode metadata is wiped.
memset(&inode.m_raw_inode, 0, sizeof(ext2_inode));
inode.m_raw_inode.i_dtime = kgettimeofday().to_truncated_seconds();
write_ext2_inode(inode.index(), inode.m_raw_inode);
if (auto result = write_ext2_inode(inode.index(), inode.m_raw_inode); result.is_error())
dbgln("Ext2FS[{}]::free_inode(): Failed to write inode {}: {}", fsid(), inode.index(), result.error());

// Mark the inode as free.
if (auto result = set_inode_allocation_state(inode.index(), false); result.is_error())
Expand Down Expand Up @@ -777,7 +778,7 @@ KResult Ext2FSInode::flush_metadata()
{
MutexLocker locker(m_inode_lock);
dbgln_if(EXT2_DEBUG, "Ext2FSInode[{}]::flush_metadata(): Flushing inode", identifier());
fs().write_ext2_inode(index(), m_raw_inode);
TRY(fs().write_ext2_inode(index(), m_raw_inode));
if (is_directory()) {
// Unless we're about to go away permanently, invalidate the lookup cache.
if (m_raw_inode.i_links_count != 0) {
Expand Down Expand Up @@ -1247,18 +1248,14 @@ u64 Ext2FS::blocks_per_group() const
return EXT2_BLOCKS_PER_GROUP(&super_block());
}

bool Ext2FS::write_ext2_inode(InodeIndex inode, const ext2_inode& e2inode)
KResult Ext2FS::write_ext2_inode(InodeIndex inode, ext2_inode const& e2inode)
{
BlockIndex block_index;
unsigned offset;
if (!find_block_containing_inode(inode, block_index, offset))
return false;
return EINVAL;
auto buffer = UserOrKernelBuffer::for_kernel_buffer(const_cast<u8*>((const u8*)&e2inode));
if (auto result = write_block(block_index, buffer, inode_size(), offset); result.is_error()) {
// FIXME: Propagate errors.
return false;
}
return true;
return write_block(block_index, buffer, inode_size(), offset);
}

auto Ext2FS::allocate_blocks(GroupIndex preferred_group_index, size_t count) -> KResultOr<Vector<BlockIndex>>
Expand Down Expand Up @@ -1537,8 +1534,7 @@ KResultOr<NonnullRefPtr<Inode>> Ext2FS::create_inode(Ext2FSInode& parent_inode,
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, e2inode);
VERIFY(success);
TRY(write_ext2_inode(inode_id, e2inode));

auto new_inode = TRY(get_inode({ fsid(), inode_id }));

Expand Down
2 changes: 1 addition & 1 deletion Kernel/FileSystem/Ext2FileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class Ext2FS final : public BlockBasedFileSystem {
u64 blocks_per_group() const;
u64 inode_size() const;

bool write_ext2_inode(InodeIndex, const ext2_inode&);
KResult write_ext2_inode(InodeIndex, ext2_inode const&);
bool find_block_containing_inode(InodeIndex, BlockIndex& block_index, unsigned& offset) const;

bool flush_super_block();
Expand Down

0 comments on commit 98b865f

Please sign in to comment.