Skip to content

Commit

Permalink
Ext2FS: Block #0 can terminate an inode block list early.
Browse files Browse the repository at this point in the history
We were already handling this for the indirect blocks, but the direct ones
would happily consider #0 to be a valid block list entry.
  • Loading branch information
awesomekling committed May 25, 2019
1 parent e1f922d commit 75b0e5c
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Kernel/FileSystem/Ext2FileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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;
Vector<BlockIndex> list;
if (include_block_list_blocks) {
Expand All @@ -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);
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;
}

Expand Down

0 comments on commit 75b0e5c

Please sign in to comment.