From: Theodore Ts'o Date: Mon, 10 Aug 2009 00:09:10 +0000 (-0400) Subject: e2freefrag: Fix to work correctly for file systems with 1kb block sizes X-Git-Tag: v1.41.9~15 X-Git-Url: https://git.whamcloud.com/gitweb?a=commitdiff_plain;h=3e343b8d9af349301a2acd6b4328fb5663deb60c;p=tools%2Fe2fsprogs.git e2freefrag: Fix to work correctly for file systems with 1kb block sizes If the file system has a non-zero s_first_data_block, as is the case when the block size is 1kb, e2freefrag would incorrectly try to reference invalid data blocks in the block allocation bitmap. Signed-off-by: "Theodore Ts'o" --- diff --git a/misc/e2freefrag.c b/misc/e2freefrag.c index 274bf55..10a48ad 100644 --- a/misc/e2freefrag.c +++ b/misc/e2freefrag.c @@ -79,6 +79,7 @@ void scan_block_bitmap(ext2_filsys fs, struct chunk_info *info) unsigned long long chunk_num; unsigned long last_chunk_size = 0; unsigned long long chunk_start_blk = 0; + int used; for (chunk_num = 0; chunk_num < chunks; chunk_num++) { unsigned long long blk, num_blks; @@ -95,10 +96,13 @@ void scan_block_bitmap(ext2_filsys fs, struct chunk_info *info) /* Initialize starting block for first chunk correctly else * there is a segfault when blocksize = 1024 in which case * block_map->start = 1 */ - for (blk = (chunk_num == 0 ? fs->super->s_first_data_block : 0); - blk < num_blks; blk++, chunk_start_blk++) { - int used = ext2fs_fast_test_block_bitmap(fs->block_map, - chunk_start_blk); + for (blk = 0; blk < num_blks; blk++, chunk_start_blk++) { + if (chunk_num == 0 && blk == 0) { + blk = fs->super->s_first_data_block; + chunk_start_blk = blk; + } + used = ext2fs_fast_test_block_bitmap(fs->block_map, + chunk_start_blk); if (!used) { last_chunk_size++; chunk_free++;