diff options
Diffstat (limited to 'resize')
-rw-r--r-- | resize/Makefile.in | 3 | ||||
-rw-r--r-- | resize/extent.c | 11 | ||||
-rw-r--r-- | resize/main.c | 33 | ||||
-rw-r--r-- | resize/online.c | 3 | ||||
-rw-r--r-- | resize/resize2fs.c | 75 | ||||
-rw-r--r-- | resize/test_extent.c | 7 |
6 files changed, 89 insertions, 43 deletions
diff --git a/resize/Makefile.in b/resize/Makefile.in index f7f836a2..27f72130 100644 --- a/resize/Makefile.in +++ b/resize/Makefile.in @@ -8,6 +8,7 @@ VPATH = @srcdir@ top_builddir = .. my_dir = resize INSTALL = @INSTALL@ +MKDIR_P = @MKDIR_P@ @MCONFIG@ @@ -42,6 +43,8 @@ DEPSTATIC_LIBS= $(STATIC_LIBE2P) $(STATIC_LIBEXT2FS) $(DEPSTATIC_LIBCOM_ERR) all:: $(PROGS) $(TEST_PROGS) $(MANPAGES) +all-static:: resize2fs.static + resize2fs: $(RESIZE_OBJS) $(DEPLIBS) $(E) " LD $@" $(Q) $(CC) $(ALL_LDFLAGS) -o resize2fs $(RESIZE_OBJS) $(LIBS) diff --git a/resize/extent.c b/resize/extent.c index e5ca16c0..4177c6f7 100644 --- a/resize/extent.c +++ b/resize/extent.c @@ -201,10 +201,15 @@ void ext2fs_extent_dump(ext2_extent extent, FILE *out) fputs(_("# Extent dump:\n"), out); fprintf(out, _("#\tNum=%llu, Size=%llu, Cursor=%llu, Sorted=%llu\n"), - extent->num, extent->size, extent->cursor, extent->sorted); + (unsigned long long) extent->num, + (unsigned long long) extent->size, + (unsigned long long) extent->cursor, + (unsigned long long) extent->sorted); for (i=0, ent=extent->list; i < extent->num; i++, ent++) { - fprintf(out, "#\t\t %llu -> %llu (%llu)\n", ent->old_loc, - ent->new_loc, ent->size); + fprintf(out, "#\t\t %llu -> %llu (%llu)\n", + (unsigned long long) ent->old_loc, + (unsigned long long) ent->new_loc, + (unsigned long long) ent->size); } } diff --git a/resize/main.c b/resize/main.c index cb0bf6a0..ccfd2896 100644 --- a/resize/main.c +++ b/resize/main.c @@ -269,6 +269,8 @@ int main (int argc, char ** argv) long sysval; int len, mount_flags; char *mtpt, *undo_file = NULL; + dgrp_t new_group_desc_count; + unsigned long new_desc_blocks; #ifdef ENABLE_NLS setlocale(LC_MESSAGES, ""); @@ -402,7 +404,7 @@ int main (int argc, char ** argv) if (!(mount_flags & EXT2_MF_MOUNTED)) io_flags = EXT2_FLAG_RW | EXT2_FLAG_EXCLUSIVE; - io_flags |= EXT2_FLAG_64BITS; + io_flags |= EXT2_FLAG_64BITS | EXT2_FLAG_THREADS; if (undo_file) { retval = resize2fs_setup_tdb(device_name, undo_file, &io_ptr); if (retval) @@ -468,7 +470,7 @@ int main (int argc, char ** argv) if (print_min_size) { printf(_("Estimated minimum size of the filesystem: %llu\n"), - min_size); + (unsigned long long) min_size); exit(0); } @@ -528,10 +530,23 @@ int main (int argc, char ** argv) exit(1); } } + new_group_desc_count = ext2fs_div64_ceil(new_size - + fs->super->s_first_data_block, + EXT2_BLOCKS_PER_GROUP(fs->super)); + new_desc_blocks = ext2fs_div_ceil(new_group_desc_count, + EXT2_DESC_PER_BLOCK(fs->super)); + if ((new_desc_blocks + fs->super->s_first_data_block) > + EXT2_BLOCKS_PER_GROUP(fs->super)) { + com_err(program_name, 0, + _("New size results in too many block group " + "descriptors.\n")); + exit(1); + } if (!force && new_size < min_size) { com_err(program_name, 0, - _("New size smaller than minimum (%llu)\n"), min_size); + _("New size smaller than minimum (%llu)\n"), + (unsigned long long) min_size); exit(1); } if (use_stride >= 0) { @@ -563,8 +578,8 @@ int main (int argc, char ** argv) if (!force && (new_size > max_size)) { fprintf(stderr, _("The containing partition (or device)" " is only %llu (%dk) blocks.\nYou requested a new size" - " of %llu blocks.\n\n"), max_size, - blocksize / 1024, new_size); + " of %llu blocks.\n\n"), (unsigned long long) max_size, + blocksize / 1024, (unsigned long long) new_size); exit(1); } if ((flags & RESIZE_DISABLE_64BIT) && (flags & RESIZE_ENABLE_64BIT)) { @@ -591,7 +606,8 @@ int main (int argc, char ** argv) } } else if (new_size == ext2fs_blocks_count(fs->super)) { fprintf(stderr, _("The filesystem is already %llu (%dk) " - "blocks long. Nothing to do!\n\n"), new_size, + "blocks long. Nothing to do!\n\n"), + (unsigned long long) new_size, blocksize / 1024); exit(0); } @@ -622,7 +638,8 @@ int main (int argc, char ** argv) else printf(_("Resizing the filesystem on " "%s to %llu (%dk) blocks.\n"), - device_name, new_size, blocksize / 1024); + device_name, (unsigned long long) new_size, + blocksize / 1024); retval = resize_fs(fs, &new_size, flags, ((flags & RESIZE_PERCENT_COMPLETE) ? resize_progress_func : 0)); @@ -639,7 +656,7 @@ int main (int argc, char ** argv) exit(1); } printf(_("The filesystem on %s is now %llu (%dk) blocks long.\n\n"), - device_name, new_size, blocksize / 1024); + device_name, (unsigned long long) new_size, blocksize / 1024); if ((st_buf.st_size > new_file_size) && (fd > 0)) { diff --git a/resize/online.c b/resize/online.c index 2caf946a..eef7c0bf 100644 --- a/resize/online.c +++ b/resize/online.c @@ -218,7 +218,8 @@ errcode_t online_resize_fs(ext2_filsys fs, const char *mtpt, } printf(_("Performing an on-line resize of %s to %llu (%dk) blocks.\n"), - fs->device_name, *new_size, fs->blocksize / 1024); + fs->device_name, (unsigned long long) *new_size, + fs->blocksize / 1024); size = fs->group_desc_count * sb->s_blocks_per_group + sb->s_first_data_block; diff --git a/resize/resize2fs.c b/resize/resize2fs.c index c2e10471..a0d08e5b 100644 --- a/resize/resize2fs.c +++ b/resize/resize2fs.c @@ -49,7 +49,7 @@ static errcode_t inode_scan_and_fix(ext2_resize_t rfs); static errcode_t inode_ref_fix(ext2_resize_t rfs); static errcode_t move_itables(ext2_resize_t rfs); static errcode_t fix_resize_inode(ext2_filsys fs); -static errcode_t ext2fs_calculate_summary_stats(ext2_filsys fs); +static errcode_t resize2fs_calculate_summary_stats(ext2_filsys fs); static errcode_t fix_sb_journal_backup(ext2_filsys fs); static errcode_t mark_table_blocks(ext2_filsys fs, ext2fs_block_bitmap bmap); @@ -177,9 +177,9 @@ errcode_t resize_fs(ext2_filsys fs, blk64_t *new_size, int flags, #ifdef RESIZE2FS_DEBUG if (rfs->flags & RESIZE_DEBUG_BMOVE) printf("Number of free blocks: %llu/%llu, Needed: %llu\n", - ext2fs_free_blocks_count(rfs->old_fs->super), - ext2fs_free_blocks_count(rfs->new_fs->super), - rfs->needed_blocks); + (unsigned long long) ext2fs_free_blocks_count(rfs->old_fs->super), + (unsigned long long) ext2fs_free_blocks_count(rfs->new_fs->super), + (unsigned long long) rfs->needed_blocks); #endif init_resource_track(&rtrack, "block_mover", fs->io); @@ -211,7 +211,7 @@ errcode_t resize_fs(ext2_filsys fs, blk64_t *new_size, int flags, goto errout; init_resource_track(&rtrack, "calculate_summary_stats", fs->io); - retval = ext2fs_calculate_summary_stats(rfs->new_fs); + retval = resize2fs_calculate_summary_stats(rfs->new_fs); if (retval) goto errout; print_resource_track(rfs, &rtrack, fs->io); @@ -703,6 +703,7 @@ errcode_t adjust_fs_info(ext2_filsys fs, ext2_filsys old_fs, double percent; ext2fs_blocks_count_set(fs->super, new_size); + fs->super->s_overhead_clusters = 0; retry: fs->group_desc_count = ext2fs_div64_ceil(ext2fs_blocks_count(fs->super) - @@ -757,7 +758,7 @@ retry: new_inodes =(unsigned long long) fs->super->s_inodes_per_group * fs->group_desc_count; if (new_inodes > ~0U) { fprintf(stderr, _("inodes (%llu) must be less than %u\n"), - new_inodes, ~0U); + (unsigned long long) new_inodes, ~0U); return EXT2_ET_TOO_MANY_INODES; } fs->super->s_inodes_count = fs->super->s_inodes_per_group * @@ -1242,7 +1243,8 @@ static void mark_fs_metablock(ext2_resize_t rfs, * nothing other than standard metadata in use. */ return; - } else if (ext2fs_test_block_bitmap2(rfs->old_fs->block_map, blk) && + } else if (blk < ext2fs_blocks_count(rfs->old_fs->super) && + ext2fs_test_block_bitmap2(rfs->old_fs->block_map, blk) && !ext2fs_test_block_bitmap2(meta_bmap, blk)) { ext2fs_mark_block_bitmap2(rfs->move_blocks, blk); rfs->needed_blocks++; @@ -1509,7 +1511,8 @@ static errcode_t blocks_to_move(ext2_resize_t rfs) if (ext2fs_block_bitmap_loc(old_fs, i) != (blk = ext2fs_block_bitmap_loc(fs, i))) { ext2fs_block_alloc_stats2(fs, blk, +1); - if (ext2fs_test_block_bitmap2(old_fs->block_map, blk) && + if (blk < ext2fs_blocks_count(old_fs->super) && + ext2fs_test_block_bitmap2(old_fs->block_map, blk) && !ext2fs_test_block_bitmap2(meta_bmap, blk)) ext2fs_mark_block_bitmap2(rfs->move_blocks, blk); @@ -1517,7 +1520,8 @@ static errcode_t blocks_to_move(ext2_resize_t rfs) if (ext2fs_inode_bitmap_loc(old_fs, i) != (blk = ext2fs_inode_bitmap_loc(fs, i))) { ext2fs_block_alloc_stats2(fs, blk, +1); - if (ext2fs_test_block_bitmap2(old_fs->block_map, blk) && + if (blk < ext2fs_blocks_count(old_fs->super) && + ext2fs_test_block_bitmap2(old_fs->block_map, blk) && !ext2fs_test_block_bitmap2(meta_bmap, blk)) ext2fs_mark_block_bitmap2(rfs->move_blocks, blk); @@ -1543,7 +1547,8 @@ static errcode_t blocks_to_move(ext2_resize_t rfs) for (blk = ext2fs_inode_table_loc(fs, i), j=0; j < fs->inode_blocks_per_group ; j++, blk++) { ext2fs_block_alloc_stats2(fs, blk, +1); - if (ext2fs_test_block_bitmap2(old_fs->block_map, blk) && + if (blk < ext2fs_blocks_count(old_fs->super) && + ext2fs_test_block_bitmap2(old_fs->block_map, blk) && !ext2fs_test_block_bitmap2(meta_bmap, blk)) ext2fs_mark_block_bitmap2(rfs->move_blocks, blk); @@ -1643,7 +1648,8 @@ static errcode_t resize2fs_get_alloc_block(ext2_filsys fs, #ifdef RESIZE2FS_DEBUG if (rfs->flags & 0xF) - printf("get_alloc_block allocating %llu\n", blk); + printf("get_alloc_block allocating %llu\n", + (unsigned long long) blk); #endif ext2fs_mark_block_bitmap2(rfs->old_fs->block_map, blk); @@ -1749,7 +1755,9 @@ static errcode_t block_mover(ext2_resize_t rfs) #ifdef RESIZE2FS_DEBUG if (rfs->flags & RESIZE_DEBUG_BMOVE) printf("Moving %llu blocks %llu->%llu\n", - size, old_blk, new_blk); + (unsigned long long) size, + (unsigned long long) old_blk, + (unsigned long long) new_blk); #endif do { c = size; @@ -1842,8 +1850,9 @@ static int process_block(ext2_filsys fs, blk64_t *block_nr, #ifdef RESIZE2FS_DEBUG if (pb->rfs->flags & RESIZE_DEBUG_BMOVE) printf("ino=%u, blockcnt=%lld, %llu->%llu\n", - pb->old_ino, blockcnt, block, - new_block); + pb->old_ino, (long long) blockcnt, + (unsigned long long) block, + (unsigned long long) new_block); #endif block = new_block; } @@ -2459,7 +2468,8 @@ static errcode_t move_itables(ext2_resize_t rfs) #ifdef RESIZE2FS_DEBUG if (rfs->flags & RESIZE_DEBUG_ITABLEMOVE) printf("Itable move group %d block %llu->%llu (diff %lld)\n", - i, old_blk, new_blk, diff); + i, (unsigned long long) old_blk, + (unsigned long long) new_blk, diff); #endif if (!diff) @@ -2739,7 +2749,7 @@ errout: /* * Finally, recalculate the summary information */ -static errcode_t ext2fs_calculate_summary_stats(ext2_filsys fs) +static errcode_t resize2fs_calculate_summary_stats(ext2_filsys fs) { blk64_t blk; ext2_ino_t ino; @@ -2926,14 +2936,15 @@ blk64_t calculate_minimum_resize_size(ext2_filsys fs, int flags) fs->super->s_reserved_gdt_blocks; /* calculate how many blocks are needed for data */ - data_needed = ext2fs_blocks_count(fs->super) - - ext2fs_free_blocks_count(fs->super); - - for (grp = 0; grp < fs->group_desc_count; grp++) + data_needed = ext2fs_blocks_count(fs->super); + for (grp = 0; grp < fs->group_desc_count; grp++) { data_needed -= calc_group_overhead(fs, grp, old_desc_blocks); + data_needed -= ext2fs_bg_free_blocks_count(fs, grp); + } #ifdef RESIZE2FS_DEBUG if (flags & RESIZE_DEBUG_MIN_CALC) - printf("fs requires %llu data blocks.\n", data_needed); + printf("fs requires %llu data blocks.\n", + (unsigned long long) data_needed); #endif /* @@ -2976,7 +2987,7 @@ blk64_t calculate_minimum_resize_size(ext2_filsys fs, int flags) #ifdef RESIZE2FS_DEBUG if (flags & RESIZE_DEBUG_MIN_CALC) printf("With %d group(s), we have %llu blocks available.\n", - groups, data_blocks); + groups, (unsigned long long) data_blocks); #endif /* @@ -3029,8 +3040,10 @@ blk64_t calculate_minimum_resize_size(ext2_filsys fs, int flags) if (flags & RESIZE_DEBUG_MIN_CALC) printf("Added %d extra group(s), " "blks_needed %llu, data_blocks %llu, " - "last_start %llu\n", extra_grps, blks_needed, - data_blocks, last_start); + "last_start %llu\n", extra_grps, + (unsigned long long) blks_needed, + (unsigned long long) data_blocks, + (unsigned long long) last_start); #endif } @@ -3045,7 +3058,8 @@ blk64_t calculate_minimum_resize_size(ext2_filsys fs, int flags) #ifdef RESIZE2FS_DEBUG if (flags & RESIZE_DEBUG_MIN_CALC) - printf("Last group's overhead is %llu\n", overhead); + printf("Last group's overhead is %llu\n", + (unsigned long long) overhead); #endif /* @@ -3058,7 +3072,7 @@ blk64_t calculate_minimum_resize_size(ext2_filsys fs, int flags) #ifdef RESIZE2FS_DEBUG if (flags & RESIZE_DEBUG_MIN_CALC) printf("Need %llu data blocks in last group\n", - remainder); + (unsigned long long) remainder); #endif /* * 50 is a magic number that mkfs/resize uses to see if its @@ -3076,7 +3090,8 @@ blk64_t calculate_minimum_resize_size(ext2_filsys fs, int flags) overhead += fs->super->s_first_data_block; #ifdef RESIZE2FS_DEBUG if (flags & RESIZE_DEBUG_MIN_CALC) - printf("Final size of last group is %lld\n", overhead); + printf("Final size of last group is %llu\n", + (unsigned long long) overhead); #endif /* Add extra slack for bigalloc file systems */ @@ -3103,7 +3118,8 @@ blk64_t calculate_minimum_resize_size(ext2_filsys fs, int flags) #ifdef RESIZE2FS_DEBUG if (flags & RESIZE_DEBUG_MIN_CALC) - printf("Estimated blocks needed: %llu\n", blks_needed); + printf("Estimated blocks needed: %llu\n", + (unsigned long long) blks_needed); #endif /* @@ -3138,7 +3154,8 @@ blk64_t calculate_minimum_resize_size(ext2_filsys fs, int flags) #ifdef RESIZE2FS_DEBUG if (flags & RESIZE_DEBUG_MIN_CALC) - printf("Extents safety margin: %llu\n", safe_margin); + printf("Extents safety margin: %llu\n", + (unsigned long long) safe_margin); #endif blks_needed += safe_margin; } diff --git a/resize/test_extent.c b/resize/test_extent.c index 5e9aed79..11ad1323 100644 --- a/resize/test_extent.c +++ b/resize/test_extent.c @@ -88,7 +88,8 @@ void do_test(FILE *in, FILE *out) goto handle_error; } else if (!strcmp(cmd, "lookup")) { num2 = ext2fs_extent_translate(extent, num1); - fprintf(out, "# Answer: %llu%s\n", num2, + fprintf(out, "# Answer: %llu%s\n", + (unsigned long long) num2, num2 ? "" : " (not found)"); } else if (!strcmp(cmd, "dump")) { ext2fs_extent_dump(extent, out); @@ -104,7 +105,9 @@ void do_test(FILE *in, FILE *out) if (!size) break; fprintf(out, "# %llu -> %llu (%llu)\n", - num1, num2, size); + (unsigned long long) num1, + (unsigned long long) num2, + (unsigned long long) size); } } else fputs("# Syntax error\n", out); |