mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 13:18:13 +00:00
Ext2FS: Block #0 can terminate an inode block list early.
We were already handling this for the indirect blocks, but the direct ones would happily consider #0 to be a valid block list entry.
This commit is contained in:
parent
e1f922ded2
commit
75b0e5cce5
1 changed files with 9 additions and 1 deletions
|
@ -269,6 +269,11 @@ Vector<Ext2FS::BlockIndex> Ext2FS::block_list_for_inode(const ext2_inode& e2inod
|
||||||
|
|
||||||
// NOTE: i_blocks is number of 512-byte blocks, not number of fs-blocks.
|
// NOTE: i_blocks is number of 512-byte blocks, not number of fs-blocks.
|
||||||
unsigned block_count = e2inode.i_blocks / (block_size() / 512);
|
unsigned block_count = e2inode.i_blocks / (block_size() / 512);
|
||||||
|
|
||||||
|
#ifdef EXT2_DEBUG
|
||||||
|
dbgprintf("Ext2FS::block_list_for_inode(): i_size=%u, i_blocks=%u, block_count=%u\n", e2inode.i_size, block_count);
|
||||||
|
#endif
|
||||||
|
|
||||||
unsigned blocks_remaining = block_count;
|
unsigned blocks_remaining = block_count;
|
||||||
Vector<BlockIndex> list;
|
Vector<BlockIndex> list;
|
||||||
if (include_block_list_blocks) {
|
if (include_block_list_blocks) {
|
||||||
|
@ -280,7 +285,10 @@ Vector<Ext2FS::BlockIndex> Ext2FS::block_list_for_inode(const ext2_inode& e2inod
|
||||||
|
|
||||||
unsigned direct_count = min(block_count, (unsigned)EXT2_NDIR_BLOCKS);
|
unsigned direct_count = min(block_count, (unsigned)EXT2_NDIR_BLOCKS);
|
||||||
for (unsigned i = 0; i < direct_count; ++i) {
|
for (unsigned i = 0; i < direct_count; ++i) {
|
||||||
list.unchecked_append(e2inode.i_block[i]);
|
auto block_index = e2inode.i_block[i];
|
||||||
|
if (!block_index)
|
||||||
|
return list;
|
||||||
|
list.unchecked_append(block_index);
|
||||||
--blocks_remaining;
|
--blocks_remaining;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue