Skip to contentSkip to conversation

Fix reading of bitmaps from filesystem image

PATCH RESEND In review Jan Kara 2 participants 3 messages Jan 9, 2008 – Jan 14, 2008

lore
Share & tools
lore

Jan Kara

author
#0 lore raw

PATCH RESEND 1/1 Fix reading of bitmaps from filesystem image

Hi Ted,

I've sent you the attached fix some time ago but it didn't seem to get
merged yet...
Honza

Signature · 11 lines
Jan Kara <[email protected]>
SUSE Labs, CR
---

Subject: Fix reading of bitmaps from filesystem image

Reading of bitmaps from image file could never work with more than one
group in a filesystem... Fix the loops so that we read appropriate number
of blocks.

Signed-off-by: Jan Kara <[email protected]>
lib/ext2fs/rw_bitmaps.c +6 -8
index 1897ec3..abbe5e8 100644
@@ -190,7 +190,7 @@ static errcode_t read_bitmaps(ext2_filsy
 	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) {
+		while (do_inode && ino_cnt > 0) {
 			retval = io_channel_read_blk(fs->image_io, blk++,
 						     1, inode_bitmap);
 			if (retval)
@@ -202,15 +202,14 @@ static errcode_t read_bitmaps(ext2_filsy
 					       ino_itr, cnt, inode_bitmap);
 			if (retval)
 				goto cleanup;
-			ino_itr += fs->blocksize << 3;
-			ino_cnt -= fs->blocksize << 3;
-			inode_nbytes -= fs->blocksize;
+			ino_itr += cnt;
+			ino_cnt -= cnt;
 		}
 		blk = (fs->image_header->offset_blockmap /
 		       fs->blocksize);
 		blk_cnt = EXT2_BLOCKS_PER_GROUP(fs->super) * 
 			fs->group_desc_count;
-		while (block_nbytes > 0) {
+		while (do_block && blk_cnt > 0) {
 			retval = io_channel_read_blk(fs->image_io, blk++,
 						     1, block_bitmap);
 			if (retval)
@@ -222,9 +221,8 @@ static errcode_t read_bitmaps(ext2_filsy
 				       blk_itr, cnt, block_bitmap);
 			if (retval)
 				goto cleanup;
-			blk_itr += fs->blocksize << 3;
-			blk_cnt -= fs->blocksize << 3;
-			block_nbytes -= fs->blocksize;
+			blk_itr += cnt;
+			blk_cnt -= cnt;
 		}
 		goto success_cleanup;
 	}
#1 lore raw
Quoted 4 lines · Jan Kara

Reading of bitmaps from image file could never work with more than one group in a filesystem... Fix the loops so that we read appropriate number of blocks.

OK, so I'm probably being dense, but.... what's the problem?

You changed the loop from counting in bytes to inodes, but either method should work.

- Ted

author
#2 lore raw
Quoted 10 lines · Theodore Tso
Quoted 4 lines · Jan Kara

Reading of bitmaps from image file could never work with more than one group in a filesystem... Fix the loops so that we read appropriate number of blocks.

OK, so I'm probably being dense, but.... what's the problem?

You changed the loop from counting in bytes to inodes, but either method should work.

At the beginning of read_bitmap() there is:

        unsigned int block_nbytes = EXT2_BLOCKS_PER_GROUP(fs->super) / 8;
        unsigned inode_nbytes = EXT2_INODES_PER_GROUP(fs->super) / 8;

Therefore in the loop:
while (inode_nbytes > 0)

we end up reading bitmap for just one group...

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR