diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-05-25 19:19:43 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-05-25 19:19:43 +0200 |
commit | 75b0e5cce50b1cf126ea83f1de78fe1a03c5d425 (patch) | |
tree | 5bb5465f296be406e41a7d88b07055045c6f1e58 /Kernel | |
parent | e1f922ded2ce3cfdf7f292cefb2e416fdc3932aa (diff) | |
download | serenity-75b0e5cce50b1cf126ea83f1de78fe1a03c5d425.zip |
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.
Diffstat (limited to 'Kernel')
-rw-r--r-- | Kernel/FileSystem/Ext2FileSystem.cpp | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/Kernel/FileSystem/Ext2FileSystem.cpp b/Kernel/FileSystem/Ext2FileSystem.cpp index 838ac88793..13e3b93fd1 100644 --- a/Kernel/FileSystem/Ext2FileSystem.cpp +++ b/Kernel/FileSystem/Ext2FileSystem.cpp @@ -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) { @@ -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; } |