[parted-devel] [PATCH] Fix block number used when checking for state

Flavio Leitner flavio.leitner at gmail.com
Tue Jun 12 17:53:20 UTC 2007


Hi there,

The ext2_bread() returns a descriptor containing a
pointer ->data representing the contents of 1 block.

In ext2_block_relocate_grow(), it reads the block bitmap from
a group descriptor representing a range of blocks:
   bh = ext2_bread(fs, EXT2_GROUP_BLOCK_BITMAP(fs->gd[i]));

Then it does:
   k = EXT2_GROUP_INODE_TABLE(fs->gd[i]) + fs->inodeblocks + j;
k is the absolute block number and then checks the state doing:
if (bh->data[k>>3] & _bitmap[k&7])

The k should be the offset inside of group descriptor and not
the absolute block number. Example:
. Block bitmap represents 512 blocks
. Block absolute number is 1023.

GrpDesc = Block absolute number / block bitmap size = 1
bh = ext2_bread(fs, EXT2_GROUP_BLOCK_BITMAP(fs->gd[GrpDesc]))
bh->data[] contains a bitmap of 512 blocks from 512-1024
relative = absolute block number % block bitmap size
relative = 1023/512 = 511

The block state is in bitmap bh->data[relative>>3] & ...

Signed-off-by: Flavio Leitner <flavio.leitner at gmail.com>

diff --git a/libparted/fs/ext2/ext2_block_relocator.c b/libparted/fs/ext2/ext2_block_relocator.c
index 1f71d10..7b1dc72 100644
--- a/libparted/fs/ext2/ext2_block_relocator.c
+++ b/libparted/fs/ext2/ext2_block_relocator.c
@@ -797,17 +797,21 @@ static int ext2_block_relocate_grow(struct ext2_fs *fs, struct ext2_block_reloca
 
 			for (j=0;j<diff;j++)
 			{
+				blk_t block;
 				blk_t k;
 
 				k = EXT2_GROUP_INODE_TABLE(fs->gd[i])
                                         + fs->inodeblocks + j;
-				if (bh->data[k>>3] & _bitmap[k&7])
+				block = k % EXT2_SUPER_BLOCKS_PER_GROUP(fs->sb);
+				if (bh->data[block>>3] & _bitmap[block&7]) {
+					k += EXT2_SUPER_FIRST_DATA_BLOCK(fs->sb);
 					if (!ext2_block_relocator_mark(fs,
-							    state, start + k))
+							    state, k))
 					{
 						ext2_brelse(bh, 0);
 						return 0;
 					}
+				}
 			}
 		}
 
-- 
1.5.0.6

-- 
Flavio



More information about the parted-devel mailing list