From: Sungbae Yoo Date: Tue, 28 Mar 2017 10:23:37 +0000 (+0900) Subject: Add to handle an exception that some blocks are missing in ext4tool X-Git-Tag: submit/tizen/20170329.022805~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=728431185bea4b224e7a0d9a5bf67b01a44e8094;p=platform%2Fcore%2Fsecurity%2Fode.git Add to handle an exception that some blocks are missing in ext4tool Signed-off-by: Sungbae Yoo Change-Id: I49c9f31b6bfe600fccdc493cf1ef3e984058cd79 --- diff --git a/server/ext4-tool.cpp b/server/ext4-tool.cpp index b194c04..a8412b0 100644 --- a/server/ext4-tool.cpp +++ b/server/ext4-tool.cpp @@ -87,7 +87,7 @@ Ext4Tool::Ext4Tool(const std::string &src) : device.lseek((firstDataBlock + 1) * blockSize, SEEK_SET); device.read(group_desc.data(), (descBlockCount * blockSize)); - unsigned int cnt = 0; + unsigned int cnt = blockNbytes << 3; unsigned int blkItr = firstDataBlock; // this structure just is used for easy type-casting. @@ -106,15 +106,19 @@ Ext4Tool::Ext4Tool(const std::string &src) : } for (unsigned int i = 0; i < groupDescCount; i++) { - data block_bitmap(blockSize); - unsigned int blk = (((struct odeExtGroupDesc *)(((unsigned char *)(group_desc.data())) + i * ODE_EXT2_MIN_DESC_SIZE))->blockBitmap); - device.lseek(blk * blockSize, SEEK_SET); - device.read(block_bitmap.data(), blockSize); - cnt = blockNbytes << 3; - memcpy(bitmap.data() + (blkItr >> 3), block_bitmap.data(), (cnt + 7) >> 3); - blkItr += blockNbytes << 3; + try { + data block_bitmap(blockSize); + device.lseek(blk * blockSize, SEEK_SET); + device.read(block_bitmap.data(), blockSize); + + memcpy(bitmap.data() + (blkItr >> 3), block_bitmap.data(), (cnt + 7) >> 3); + } catch (runtime::Exception &e) { + WARN("Block " + std::to_string(blk) + " is missing"); + memset(bitmap.data() + (blkItr >> 3), 0, (cnt + 7) >> 3); + } + blkItr += cnt; } device.close();