Kernel: Fix ext2 small link deallocation

Also fix deallocation bug
This commit is contained in:
Bananymous 2023-10-30 15:34:25 +02:00
parent 26c7aee327
commit 4e785a133c
1 changed files with 5 additions and 1 deletions

View File

@ -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));