[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <C26C67884C4B7A48980D57463559486403435BEA@BPXM20GP.gisp.nec.co.jp>
Date: Wed, 14 Mar 2018 05:47:00 +0000
From: Kazuya Mio <k-mio@...jp.nec.com>
To: "tytso@....edu" <tytso@....edu>,
"adilger.kernel@...ger.ca" <adilger.kernel@...ger.ca>
CC: "linux-ext4@...r.kernel.org" <linux-ext4@...r.kernel.org>
Subject: [PATCH] libext2fs: fix to read the bitmaps for image file correctly
When read_bitmaps() is called to read block/inode bitmap from the image file
created by e2image, it can read only one bitmap block due to the wrong
loop condition. read_bitmaps() doesn't need to split the code between
the filesystem and the image file, so remove EXT2_FLAG_IMAGE_FILE-specific code.
Signed-off-by: Kazuya Mio <k-mio@...jp.nec.com>
---
lib/ext2fs/rw_bitmaps.c | 57 ++++++++----------------------------------------
1 file changed, 10 insertions(+), 47 deletions(-)
diff --git a/lib/ext2fs/rw_bitmaps.c b/lib/ext2fs/rw_bitmaps.c
index 9db76eb..5f606b8 100644
--- a/lib/ext2fs/rw_bitmaps.c
+++ b/lib/ext2fs/rw_bitmaps.c
@@ -207,9 +207,7 @@ static errcode_t read_bitmaps(ext2_filsys fs, int do_inode, int do_block)
unsigned int cnt;
blk64_t blk;
blk64_t blk_itr = EXT2FS_B2C(fs, fs->super->s_first_data_block);
- blk64_t blk_cnt;
ext2_ino_t ino_itr = 1;
- ext2_ino_t ino_cnt;
EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
@@ -252,51 +250,13 @@ static errcode_t read_bitmaps(ext2_filsys fs, int do_inode, int do_block)
inode_nbytes = 0;
ext2fs_free_mem(&buf);
- if (fs->flags & EXT2_FLAG_IMAGE_FILE) {
- blk = (fs->image_header->offset_inodemap / fs->blocksize);
- ino_cnt = fs->super->s_inodes_count;
- while (inode_nbytes > 0) {
- retval = io_channel_read_blk64(fs->image_io, blk++,
- 1, inode_bitmap);
- if (retval)
- goto cleanup;
- cnt = fs->blocksize << 3;
- if (cnt > ino_cnt)
- cnt = ino_cnt;
- retval = ext2fs_set_inode_bitmap_range2(fs->inode_map,
- ino_itr, cnt, inode_bitmap);
- if (retval)
- goto cleanup;
- ino_itr += fs->blocksize << 3;
- ino_cnt -= fs->blocksize << 3;
- inode_nbytes -= fs->blocksize;
- }
- blk = (fs->image_header->offset_blockmap /
- fs->blocksize);
- blk_cnt = EXT2_GROUPS_TO_CLUSTERS(fs->super,
- fs->group_desc_count);
- while (block_nbytes > 0) {
- retval = io_channel_read_blk64(fs->image_io, blk++,
- 1, block_bitmap);
- if (retval)
- goto cleanup;
- cnt = fs->blocksize << 3;
- if (cnt > blk_cnt)
- cnt = blk_cnt;
- retval = ext2fs_set_block_bitmap_range2(fs->block_map,
- blk_itr, cnt, block_bitmap);
- if (retval)
- goto cleanup;
- blk_itr += fs->blocksize << 3;
- blk_cnt -= fs->blocksize << 3;
- block_nbytes -= fs->blocksize;
- }
- goto success_cleanup;
- }
-
for (i = 0; i < fs->group_desc_count; i++) {
if (block_bitmap) {
- blk = ext2fs_block_bitmap_loc(fs, i);
+ if (fs->flags & EXT2_FLAG_IMAGE_FILE) {
+ blk = (fs->image_header->offset_blockmap /
+ fs->blocksize) + i;
+ } else
+ blk = ext2fs_block_bitmap_loc(fs, i);
if (csum_flag &&
ext2fs_bg_flags_test(fs, i, EXT2_BG_BLOCK_UNINIT) &&
ext2fs_group_desc_csum_verify(fs, i))
@@ -327,7 +287,11 @@ static errcode_t read_bitmaps(ext2_filsys fs, int do_inode, int do_block)
blk_itr += block_nbytes << 3;
}
if (inode_bitmap) {
- blk = ext2fs_inode_bitmap_loc(fs, i);
+ if (fs->flags & EXT2_FLAG_IMAGE_FILE) {
+ blk = (fs->image_header->offset_inodemap /
+ fs->blocksize) + i;
+ } else
+ blk = ext2fs_inode_bitmap_loc(fs, i);
if (csum_flag &&
ext2fs_bg_flags_test(fs, i, EXT2_BG_INODE_UNINIT) &&
ext2fs_group_desc_csum_verify(fs, i))
@@ -367,7 +331,6 @@ static errcode_t read_bitmaps(ext2_filsys fs, int do_inode, int do_block)
goto cleanup;
}
-success_cleanup:
if (inode_bitmap)
ext2fs_free_mem(&inode_bitmap);
if (block_bitmap)
Powered by blists - more mailing lists