summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-01-22 20:48:48 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-01-22 20:49:23 +0100
commit6fb403370974470c95deedbd16126e64d0fcc89e (patch)
tree503a3986160e9dcbe159590266d28d3ca58ca9de
parent05f18febb6cd21fb15ab7a3af7ea715c6b653e08 (diff)
downloadserenity-6fb403370974470c95deedbd16126e64d0fcc89e.zip
Ext2FS: Move inode freeing logic from ~Ext2FSInode() to Ext2FS::free_inode().
-rw-r--r--VirtualFileSystem/Ext2FileSystem.cpp34
-rw-r--r--VirtualFileSystem/Ext2FileSystem.h1
2 files changed, 20 insertions, 15 deletions
diff --git a/VirtualFileSystem/Ext2FileSystem.cpp b/VirtualFileSystem/Ext2FileSystem.cpp
index 6fca4bae7e..c2ee3a75ed 100644
--- a/VirtualFileSystem/Ext2FileSystem.cpp
+++ b/VirtualFileSystem/Ext2FileSystem.cpp
@@ -219,6 +219,23 @@ Vector<unsigned> Ext2FS::block_list_for_inode(const ext2_inode& e2inode, bool in
return list;
}
+void Ext2FS::free_inode(Ext2FSInode& inode)
+{
+ ASSERT(inode.m_raw_inode.i_links_count == 0);
+ dbgprintf("Ext2FS: inode %u has no more links, time to delete!\n", inode.index());
+
+ inode.m_raw_inode.i_dtime = RTC::now();
+ write_ext2_inode(inode.index(), inode.m_raw_inode);
+
+ auto block_list = block_list_for_inode(inode.m_raw_inode, true);
+
+ auto group_index = group_index_from_inode(inode.index());
+ for (auto block_index : block_list)
+ set_block_allocation_state(group_index, block_index, false);
+
+ set_inode_allocation_state(inode.index(), false);
+}
+
Ext2FSInode::Ext2FSInode(Ext2FS& fs, unsigned index, const ext2_inode& raw_inode)
: Inode(fs, index)
, m_raw_inode(raw_inode)
@@ -227,21 +244,8 @@ Ext2FSInode::Ext2FSInode(Ext2FS& fs, unsigned index, const ext2_inode& raw_inode
Ext2FSInode::~Ext2FSInode()
{
- if (m_raw_inode.i_links_count != 0)
- return;
-
- dbgprintf("Ext2FS: inode %u has no more links, time to delete!\n", index());
-
- m_raw_inode.i_dtime = RTC::now();
- fs().write_ext2_inode(index(), m_raw_inode);
-
- auto block_list = fs().block_list_for_inode(m_raw_inode, true);
-
- auto group_index = fs().group_index_from_inode(index());
- for (auto block_index : block_list)
- fs().set_block_allocation_state(group_index, block_index, false);
-
- fs().set_inode_allocation_state(index(), false);
+ if (m_raw_inode.i_links_count == 0)
+ fs().free_inode(*this);
}
InodeMetadata Ext2FSInode::metadata() const
diff --git a/VirtualFileSystem/Ext2FileSystem.h b/VirtualFileSystem/Ext2FileSystem.h
index 49ee9dab80..f32a31904a 100644
--- a/VirtualFileSystem/Ext2FileSystem.h
+++ b/VirtualFileSystem/Ext2FileSystem.h
@@ -107,6 +107,7 @@ private:
bool set_block_allocation_state(GroupIndex, BlockIndex, bool);
void uncache_inode(InodeIndex);
+ void free_inode(Ext2FSInode&);
unsigned m_blockGroupCount { 0 };