Kernel/Ext2FS: Make block allocation properly fallible

For some context, write_bytes_locked used to simply bail out before
writing any data if there weren't enough blocks to cover the entire size
of an inode before 1bf7f99a.

We're not actually restoring that behavior here, since computing the
amount of blocks to be allocated would get exceedingly complex,
considering that there could always be holes in between already
allocated blocks.

Instead, this simply makes allocate_blocks() bail out properly if there
aren't any free blocks left.

Fixes #24980
This commit is contained in:
implicitfield 2024-09-19 12:37:54 +03:00 committed by Tim Schumacher
parent c7e4d1b575
commit a32b9c903b

View file

@ -233,6 +233,17 @@ auto Ext2FS::allocate_blocks(GroupIndex preferred_group_index, size_t count) ->
TRY(blocks.try_ensure_capacity(count));
MutexLocker locker(m_lock);
size_t free_blocks = 0;
for (GroupIndex i = 1; i <= m_block_group_count; i = GroupIndex { i.value() + 1 }) {
free_blocks += group_descriptor(i).bg_free_blocks_count;
if (free_blocks >= count)
break;
}
if (free_blocks < count)
return Error::from_errno(ENOSPC);
auto group_index = preferred_group_index;
if (!group_descriptor(preferred_group_index).bg_free_blocks_count) {