summaryrefslogtreecommitdiff
path: root/Kernel/FileSystem
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-02-21 19:07:23 +0100
committerAndreas Kling <kling@serenityos.org>2020-02-21 19:07:23 +0100
commitb6887bd9cdcd876a7bfcfbd9893b260dc14000aa (patch)
tree4135de1a42c5e80ca342f22f032fbfb9569bbead /Kernel/FileSystem
parentb298c01e9291caa10ebf8c6e3bdff293cb2d692b (diff)
downloadserenity-b6887bd9cdcd876a7bfcfbd9893b260dc14000aa.zip
Ext2FS: The max current block count of a file is size/block_size
Turns out that i_blocks does not take block list holes into account.
Diffstat (limited to 'Kernel/FileSystem')
-rw-r--r--Kernel/FileSystem/Ext2FileSystem.cpp11
-rw-r--r--Kernel/FileSystem/Ext2FileSystem.h1
2 files changed, 7 insertions, 5 deletions
diff --git a/Kernel/FileSystem/Ext2FileSystem.cpp b/Kernel/FileSystem/Ext2FileSystem.cpp
index 5e25dde67e..5873fa6052 100644
--- a/Kernel/FileSystem/Ext2FileSystem.cpp
+++ b/Kernel/FileSystem/Ext2FileSystem.cpp
@@ -407,11 +407,10 @@ Vector<Ext2FS::BlockIndex> Ext2FS::block_list_for_inode_impl(const ext2_inode& e
LOCKER(m_lock);
unsigned entries_per_block = EXT2_ADDR_PER_BLOCK(&super_block());
- // 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 = ceil_div(e2inode.i_size, block_size());
#ifdef EXT2_DEBUG
- dbgprintf("Ext2FS::block_list_for_inode(): i_size=%u, i_blocks=%u, block_count=%u\n", e2inode.i_size, block_count);
+ dbgprintf("Ext2FS::block_list_for_inode(): i_size=%u, i_blocks=%u, block_count=%u\n", e2inode.i_size, e2inode.i_blocks, block_count);
#endif
unsigned blocks_remaining = block_count;
@@ -687,9 +686,11 @@ ssize_t Ext2FSInode::read_bytes(off_t offset, ssize_t count, u8* buffer, FileDes
u8 block[max_block_size];
for (int bi = first_block_logical_index; remaining_count && bi <= last_block_logical_index; ++bi) {
- bool success = fs().read_block(m_block_list[bi], block, description);
+ auto block_index = m_block_list[bi];
+ ASSERT(block_index);
+ bool success = fs().read_block(block_index, block, description);
if (!success) {
- kprintf("ext2fs: read_bytes: read_block(%u) failed (lbi: %u)\n", m_block_list[bi], bi);
+ kprintf("ext2fs: read_bytes: read_block(%u) failed (lbi: %u)\n", block_index, bi);
return -EIO;
}
diff --git a/Kernel/FileSystem/Ext2FileSystem.h b/Kernel/FileSystem/Ext2FileSystem.h
index fd4b32b79d..4d0a888df7 100644
--- a/Kernel/FileSystem/Ext2FileSystem.h
+++ b/Kernel/FileSystem/Ext2FileSystem.h
@@ -139,6 +139,7 @@ private:
GroupIndex group_index_from_inode(InodeIndex) const;
GroupIndex group_index_from_block_index(BlockIndex) const;
+ Vector<BlockIndex> block_list_for_inode_impl(const ext2_inode&, bool include_block_list_blocks = false) const;
Vector<BlockIndex> block_list_for_inode(const ext2_inode&, bool include_block_list_blocks = false) const;
bool write_block_list_for_inode(InodeIndex, ext2_inode&, const Vector<BlockIndex>&);