From 4d2eaa4c55790820f9e258a2251299a3fa4388dd Mon Sep 17 00:00:00 2001 From: Seok Hong Date: Tue, 24 Jan 2017 08:49:14 +0900 Subject: [PATCH] Fix wrong bitmap space size calculation Change-Id: I4e971bb251697a08fea79b58b780214912ea02b9 Signed-off-by: Seok Hong --- server/ext4-tool.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/server/ext4-tool.cpp b/server/ext4-tool.cpp index 783c084..d319483 100644 --- a/server/ext4-tool.cpp +++ b/server/ext4-tool.cpp @@ -76,9 +76,6 @@ Ext4Tool::Ext4Tool(const std::string &src) : device.lseek(ODE_SUPERBLOCK_OFFSET + 36, SEEK_SET); device.read(&clustersPerGroup, 4); - // read bitmap - bitmap.resize(totalBlockCount + 1); - unsigned int groupDescCount = divCeilSafely(totalBlockCount - firstDataBlock, blocksPerGroup); int blockNbytes = clustersPerGroup / 8; @@ -100,6 +97,15 @@ Ext4Tool::Ext4Tool(const std::string &src) : /* skip other member */ }; + // read bitmap + { + unsigned int start = firstDataBlock; + unsigned int real_end = blocksPerGroup * groupDescCount - 1 + start; + size_t size = (size_t) (((real_end - start) / 8) + 1); + size = (size + 7) & ~3; + bitmap.resize(size); + } + for (unsigned int i = 0; i < groupDescCount; i++) { data block_bitmap(blockSize); -- 2.34.1