From 35f8f44510e8a9307f8eb0fb3b14b444eb226404 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Mon, 30 Oct 2023 15:34:25 +0200 Subject: [PATCH] Kernel: Fix ext2 small link deallocation Also fix deallocation bug --- kernel/kernel/FS/Ext2/Inode.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/kernel/kernel/FS/Ext2/Inode.cpp b/kernel/kernel/FS/Ext2/Inode.cpp index 0729ec8509..0103a6e9ec 100644 --- a/kernel/kernel/FS/Ext2/Inode.cpp +++ b/kernel/kernel/FS/Ext2/Inode.cpp @@ -274,6 +274,9 @@ namespace Kernel { ASSERT(m_inode.links_count == 0); + if (mode().iflnk() && (size_t)size() < sizeof(m_inode.block)) + goto done; + // cleanup direct blocks for (uint32_t i = 0; i < 12; i++) if (m_inode.block[i]) @@ -287,6 +290,7 @@ namespace Kernel if (m_inode.block[14]) cleanup_indirect_block(m_inode.block[14], 3); +done: // mark blocks as deleted memset(m_inode.block, 0x00, sizeof(m_inode.block)); @@ -759,7 +763,7 @@ needs_new_block: if (data_block_index < indices_per_fs_block * indices_per_fs_block) return TRY(allocate_new_block_to_indirect_block(m_inode.block[13], data_block_index, 2)); - data_block_index -= indices_per_fs_block; + data_block_index -= indices_per_fs_block * indices_per_fs_block; if (data_block_index < indices_per_fs_block * indices_per_fs_block * indices_per_fs_block) return TRY(allocate_new_block_to_indirect_block(m_inode.block[14], data_block_index, 3));