1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-30 19:42:13 +00:00

Ext2FS: Fix two bugs in block allocation:

1) Off-by-one in block allocation when block size != 1 KB

Due to a quirk in the on-disk layout of ext2, file systems with a block
size of 1 KB have block #1 as their first block, while all others start
on block #0.

2) We had no fallback mechanism when the preferred group was full

We now allocate blocks from the preferred block group as long as it's
possible, and fall back to a simple scan through all groups when the
preferred one is full.
This commit is contained in:
Andreas Kling 2019-09-22 18:34:52 +02:00
parent 9c549c178a
commit bff59eff4b
2 changed files with 56 additions and 35 deletions

View file

@ -98,8 +98,10 @@ private:
virtual RefPtr<Inode> create_directory(InodeIdentifier parentInode, const String& name, mode_t, int& error) override;
virtual RefPtr<Inode> get_inode(InodeIdentifier) const override;
BlockIndex first_block_index() const;
InodeIndex allocate_inode(GroupIndex preferred_group, off_t expected_size);
Vector<BlockIndex> allocate_blocks(GroupIndex, int count);
Vector<BlockIndex> allocate_blocks(GroupIndex preferred_group_index, int count);
BlockIndex allocate_block(GroupIndex preferred_group_index);
GroupIndex group_index_from_inode(InodeIndex) const;
GroupIndex group_index_from_block_index(BlockIndex) const;