]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
e2freefrag: Fix to work correctly for file systems with 1kb block sizes
authorTheodore Ts'o <tytso@mit.edu>
Mon, 10 Aug 2009 00:09:10 +0000 (20:09 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 10 Aug 2009 03:21:23 +0000 (23:21 -0400)
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" <tytso@mit.edu>
misc/e2freefrag.c

index 274bf55222459d01f702b127c97b0522a1772164..10a48ad0b110b630a6ffe238053403928bfce495 100644 (file)
@@ -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++;