mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 09:51:57 -05:00
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:
parent
c7e4d1b575
commit
a32b9c903b
1 changed files with 11 additions and 0 deletions
|
@ -233,6 +233,17 @@ auto Ext2FS::allocate_blocks(GroupIndex preferred_group_index, size_t count) ->
|
||||||
TRY(blocks.try_ensure_capacity(count));
|
TRY(blocks.try_ensure_capacity(count));
|
||||||
|
|
||||||
MutexLocker locker(m_lock);
|
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;
|
auto group_index = preferred_group_index;
|
||||||
|
|
||||||
if (!group_descriptor(preferred_group_index).bg_free_blocks_count) {
|
if (!group_descriptor(preferred_group_index).bg_free_blocks_count) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue