#include "resize2fs.h"
struct ext2_extent_entry {
- __u32 old_loc, new_loc;
- int size;
+ __u64 old_loc, new_loc;
+ __u64 size;
};
struct _ext2_extent {
struct ext2_extent_entry *list;
- int cursor;
- int size;
- int num;
- int sorted;
+ __u64 cursor;
+ __u64 size;
+ __u64 num;
+ __u64 sorted;
};
/*
* Create an extent table
*/
-errcode_t ext2fs_create_extent_table(ext2_extent *ret_extent, int size)
+errcode_t ext2fs_create_extent_table(ext2_extent *ret_extent, __u64 size)
{
ext2_extent extent;
errcode_t retval;
/*
* Add an entry to the extent table
*/
-errcode_t ext2fs_add_extent_entry(ext2_extent extent, __u32 old_loc, __u32 new_loc)
+errcode_t ext2fs_add_extent_entry(ext2_extent extent, __u64 old_loc, __u64 new_loc)
{
struct ext2_extent_entry *ent;
errcode_t retval;
- int newsize;
- int curr;
+ __u64 newsize;
+ __u64 curr;
if (extent->num >= extent->size) {
newsize = extent->size + 100;
* Given an inode map and inode number, look up the old inode number
* and return the new inode number.
*/
-__u32 ext2fs_extent_translate(ext2_extent extent, __u32 old_loc)
+__u64 ext2fs_extent_translate(ext2_extent extent, __u64 old_loc)
{
- int low, high, mid;
- __u32 lowval, highval;
+ __s64 low, high, mid;
+ __u64 lowval, highval;
float range;
if (!extent->sorted) {
else
range = ((float) (old_loc - lowval)) /
(highval - lowval);
- mid = low + ((int) (range * (high-low)));
+ mid = low + ((__u64) (range * (high-low)));
}
#endif
if ((old_loc >= extent->list[mid].old_loc) &&
*/
void ext2fs_extent_dump(ext2_extent extent, FILE *out)
{
- int i;
+ __u64 i;
struct ext2_extent_entry *ent;
fputs(_("# Extent dump:\n"), out);
- fprintf(out, _("#\tNum=%d, Size=%d, Cursor=%d, Sorted=%d\n"),
+ fprintf(out, _("#\tNum=%llu, Size=%llu, Cursor=%llu, Sorted=%llu\n"),
extent->num, extent->size, extent->cursor, extent->sorted);
for (i=0, ent=extent->list; i < extent->num; i++, ent++) {
- fprintf(out, _("#\t\t %u -> %u (%d)\n"), ent->old_loc,
+ fprintf(out, _("#\t\t %llu -> %llu (%llu)\n"), ent->old_loc,
ent->new_loc, ent->size);
}
}
/*
* Iterate over the contents of the extent table
*/
-errcode_t ext2fs_iterate_extent(ext2_extent extent, __u32 *old_loc,
- __u32 *new_loc, int *size)
+errcode_t ext2fs_iterate_extent(ext2_extent extent, __u64 *old_loc,
+ __u64 *new_loc, __u64 *size)
{
struct ext2_extent_entry *ent;
int force_min_size = 0;
int print_min_size = 0;
int fd, ret;
- blk_t new_size = 0;
- blk_t max_size = 0;
- blk_t min_size = 0;
+ blk64_t new_size = 0;
+ blk64_t max_size = 0;
+ blk64_t min_size = 0;
io_manager io_ptr;
char *new_size_str = 0;
int use_stride = -1;
device_name);
exit(1);
}
- printf(_("Estimated minimum size of the filesystem: %u\n"),
+ printf(_("Estimated minimum size of the filesystem: %llu\n"),
min_size);
exit(0);
}
* defaults and for making sure the new filesystem doesn't
* exceed the partition size.
*/
- retval = ext2fs_get_device_size(device_name, fs->blocksize,
- &max_size);
+ retval = ext2fs_get_device_size2(device_name, fs->blocksize,
+ &max_size);
if (retval) {
com_err(program_name, retval,
_("while trying to determine filesystem size"));
if (force_min_size)
new_size = min_size;
else if (new_size_str) {
- new_size = parse_num_blocks(new_size_str,
- fs->super->s_log_block_size);
+ new_size = parse_num_blocks2(new_size_str,
+ fs->super->s_log_block_size);
if (new_size == 0) {
com_err(program_name, 0,
_("Invalid new size: %s\n"), new_size_str);
if (!force && new_size < min_size) {
com_err(program_name, 0,
- _("New size smaller than minimum (%u)\n"), min_size);
+ _("New size smaller than minimum (%llu)\n"), min_size);
exit(1);
}
if (use_stride >= 0) {
}
if (!force && (new_size > max_size)) {
fprintf(stderr, _("The containing partition (or device)"
- " is only %u (%dk) blocks.\nYou requested a new size"
- " of %u blocks.\n\n"), max_size,
+ " is only %llu (%dk) blocks.\nYou requested a new size"
+ " of %llu blocks.\n\n"), max_size,
fs->blocksize / 1024, new_size);
exit(1);
}
if (new_size == ext2fs_blocks_count(fs->super)) {
- fprintf(stderr, _("The filesystem is already %u blocks "
+ fprintf(stderr, _("The filesystem is already %llu blocks "
"long. Nothing to do!\n\n"), new_size);
exit(0);
}
exit(1);
}
printf(_("Resizing the filesystem on "
- "%s to %u (%dk) blocks.\n"),
+ "%s to %llu (%dk) blocks.\n"),
device_name, new_size, fs->blocksize / 1024);
retval = resize_fs(fs, &new_size, flags,
((flags & RESIZE_PERCENT_COMPLETE) ?
ext2fs_close(fs);
exit(1);
}
- printf(_("The filesystem on %s is now %u blocks long.\n\n"),
+ printf(_("The filesystem on %s is now %llu blocks long.\n\n"),
device_name, new_size);
if ((st_buf.st_size > new_file_size) &&
#endif
static void fix_uninit_block_bitmaps(ext2_filsys fs);
-static errcode_t adjust_superblock(ext2_resize_t rfs, blk_t new_size);
+static errcode_t adjust_superblock(ext2_resize_t rfs, blk64_t new_size);
static errcode_t blocks_to_move(ext2_resize_t rfs);
static errcode_t block_mover(ext2_resize_t rfs);
static errcode_t inode_scan_and_fix(ext2_resize_t rfs);
/*
* This is the top-level routine which does the dirty deed....
*/
-errcode_t resize_fs(ext2_filsys fs, blk_t *new_size, int flags,
+errcode_t resize_fs(ext2_filsys fs, blk64_t *new_size, int flags,
errcode_t (*progress)(ext2_resize_t rfs, int pass,
unsigned long cur,
unsigned long max_val))
#ifdef RESIZE2FS_DEBUG
if (rfs->flags & RESIZE_DEBUG_BMOVE)
- printf("Number of free blocks: %llu/%llu, Needed: %d\n",
+ 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);
*/
static void fix_uninit_block_bitmaps(ext2_filsys fs)
{
- blk_t i, blk, super_blk, old_desc_blk, new_desc_blk;
+ blk64_t i, blk, super_blk, old_desc_blk, new_desc_blk;
int old_desc_blocks;
dgrp_t g;
blk = (g * fs->super->s_blocks_per_group) +
fs->super->s_first_data_block;
- ext2fs_super_and_bgd_loc(fs, g, &super_blk,
- &old_desc_blk, &new_desc_blk, 0);
+ ext2fs_super_and_bgd_loc2(fs, g, &super_blk,
+ &old_desc_blk, &new_desc_blk, 0);
if (fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG)
old_desc_blocks = fs->super->s_first_meta_bg;
* filesystem.
*/
errcode_t adjust_fs_info(ext2_filsys fs, ext2_filsys old_fs,
- ext2fs_block_bitmap reserve_blocks, blk_t new_size)
+ ext2fs_block_bitmap reserve_blocks, blk64_t new_size)
{
errcode_t retval;
- int overhead = 0;
- int rem;
- blk_t blk, group_block;
+ blk64_t overhead = 0;
+ blk64_t rem;
+ blk64_t blk, group_block;
ext2_ino_t real_end;
- int adj, old_numblocks, numblocks, adjblocks;
+ blk64_t adj, old_numblocks, numblocks, adjblocks;
unsigned long i, j, old_desc_blocks, max_group;
unsigned int meta_bg, meta_bg_size;
int has_super, csum_flag;
* This routine adjusts the superblock and other data structures, both
* in disk as well as in memory...
*/
-static errcode_t adjust_superblock(ext2_resize_t rfs, blk_t new_size)
+static errcode_t adjust_superblock(ext2_resize_t rfs, blk64_t new_size)
{
ext2_filsys fs;
int adj = 0;
errcode_t retval;
- blk_t group_block;
+ blk64_t group_block;
unsigned long i;
unsigned long max_group;
static errcode_t mark_table_blocks(ext2_filsys fs,
ext2fs_block_bitmap bmap)
{
- blk_t b;
+ blk64_t b;
unsigned int j;
dgrp_t i;
unsigned long meta_bg_size;
*/
static void mark_fs_metablock(ext2_resize_t rfs,
ext2fs_block_bitmap meta_bmap,
- int group, blk_t blk)
+ int group, blk64_t blk)
{
ext2_filsys fs = rfs->new_fs;
{
int j, has_super;
dgrp_t i, max_groups, g;
- blk_t blk, group_blk;
- unsigned long old_blocks, new_blocks;
+ blk64_t blk, group_blk;
+ blk64_t old_blocks, new_blocks;
unsigned int meta_bg, meta_bg_size;
errcode_t retval;
ext2_filsys fs, old_fs;
#endif
}
-static blk_t get_new_block(ext2_resize_t rfs)
+static blk64_t get_new_block(ext2_resize_t rfs)
{
ext2_filsys fs = rfs->new_fs;
blk64_t *ret)
{
ext2_resize_t rfs = (ext2_resize_t) fs->priv_data;
- blk_t blk;
+ blk64_t blk;
blk = get_new_block(rfs);
if (!blk)
#ifdef RESIZE2FS_DEBUG
if (rfs->flags & 0xF)
- printf("get_alloc_block allocating %u\n", blk);
+ printf("get_alloc_block allocating %llu\n", blk);
#endif
ext2fs_mark_block_bitmap2(rfs->old_fs->block_map, blk);
static errcode_t block_mover(ext2_resize_t rfs)
{
- blk_t blk, old_blk, new_blk;
+ blk64_t blk, old_blk, new_blk;
ext2_filsys fs = rfs->new_fs;
ext2_filsys old_fs = rfs->old_fs;
errcode_t retval;
- int size, c;
+ __u64 size;
+ int c;
int to_move, moved;
ext2_badblocks_list badblock_list = 0;
int bb_modified = 0;
break;
#ifdef RESIZE2FS_DEBUG
if (rfs->flags & RESIZE_DEBUG_BMOVE)
- printf("Moving %d blocks %u->%u\n",
+ printf("Moving %llu blocks %llu->%llu\n",
size, old_blk, new_blk);
#endif
do {
int changed;
};
-static int process_block(ext2_filsys fs, blk_t *block_nr,
+static int process_block(ext2_filsys fs, blk64_t *block_nr,
e2_blkcnt_t blockcnt,
- blk_t ref_block EXT2FS_ATTR((unused)),
+ blk64_t ref_block EXT2FS_ATTR((unused)),
int ref_offset EXT2FS_ATTR((unused)), void *priv_data)
{
struct process_block_struct *pb;
errcode_t retval;
- blk_t block, new_block;
+ blk64_t block, new_block;
int ret = 0;
pb = (struct process_block_struct *) priv_data;
pb->changed = 1;
#ifdef RESIZE2FS_DEBUG
if (pb->rfs->flags & RESIZE_DEBUG_BMOVE)
- printf("ino=%u, blockcnt=%lld, %u->%u\n",
+ printf("ino=%u, blockcnt=%lld, %llu->%llu\n",
pb->ino, blockcnt, block, new_block);
#endif
block = new_block;
}
}
if (pb->is_dir) {
- retval = ext2fs_add_dir_block(fs->dblist, pb->ino,
- block, (int) blockcnt);
+ retval = ext2fs_add_dir_block2(fs->dblist, pb->ino,
+ block, (int) blockcnt);
if (retval) {
pb->error = retval;
ret |= BLOCK_ABORT;
errcode_t retval;
char *block_buf = 0;
ext2_ino_t start_to_move;
- blk_t orig_size, new_block;
+ blk64_t orig_size;
+ blk64_t new_block;
int inode_size;
if ((rfs->old_fs->group_desc_count <=
if (ext2fs_inode_has_valid_blocks(inode) &&
(rfs->bmap || pb.is_dir)) {
pb.ino = ino;
- retval = ext2fs_block_iterate2(rfs->old_fs,
+ retval = ext2fs_block_iterate3(rfs->old_fs,
ino, 0, block_buf,
process_block, &pb);
if (retval)
* inode references
*/
is.num = 0;
- is.max_dirs = ext2fs_dblist_count(rfs->old_fs->dblist);
+ is.max_dirs = ext2fs_dblist_count2(rfs->old_fs->dblist);
is.rfs = rfs;
is.err = 0;
*/
static errcode_t move_itables(ext2_resize_t rfs)
{
- int n, num, size, diff;
+ int n, num, size;
+ long long diff;
dgrp_t i, max_groups;
ext2_filsys fs = rfs->new_fs;
char *cp;
- blk_t old_blk, new_blk, blk;
+ blk64_t old_blk, new_blk, blk;
errcode_t retval;
int j, to_move, moved;
#ifdef RESIZE2FS_DEBUG
if (rfs->flags & RESIZE_DEBUG_ITABLEMOVE)
- printf("Itable move group %d block %u->%u (diff %d)\n",
+ printf("Itable move group %d block %llu->%llu (diff %lld)\n",
i, old_blk, new_blk, diff);
#endif
struct ext2_inode inode;
errcode_t retval;
char * block_buf;
- blk_t blk;
+ blk64_t blk;
if (!(fs->super->s_feature_compat &
EXT2_FEATURE_COMPAT_RESIZE_INODE))
*/
static errcode_t ext2fs_calculate_summary_stats(ext2_filsys fs)
{
- blk_t blk;
+ blk64_t blk;
ext2_ino_t ino;
unsigned int group = 0;
unsigned int count = 0;
int total_free = 0;
int group_free = 0;
int uninit = 0;
- blk_t super_blk, old_desc_blk, new_desc_blk;
+ blk64_t super_blk, old_desc_blk, new_desc_blk;
int old_desc_blocks;
/*
* First calculate the block statistics
*/
uninit = ext2fs_bg_flags_test(fs, group, EXT2_BG_BLOCK_UNINIT);
- ext2fs_super_and_bgd_loc(fs, group, &super_blk, &old_desc_blk,
- &new_desc_blk, 0);
+ ext2fs_super_and_bgd_loc2(fs, group, &super_blk, &old_desc_blk,
+ &new_desc_blk, 0);
if (fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG)
old_desc_blocks = fs->super->s_first_meta_bg;
else
break;
count = 0;
group_free = 0;
- uninit = (ext2fs_bg_flags_test(fs, group, EXT2_BG_BLOCK_UNINIT)
- );
- ext2fs_super_and_bgd_loc(fs, group, &super_blk,
- &old_desc_blk,
- &new_desc_blk, 0);
+ uninit = ext2fs_bg_flags_test(fs, group, EXT2_BG_BLOCK_UNINIT);
+ ext2fs_super_and_bgd_loc2(fs, group, &super_blk,
+ &old_desc_blk,
+ &new_desc_blk, 0);
if (fs->super->s_feature_incompat &
EXT2_FEATURE_INCOMPAT_META_BG)
old_desc_blocks = fs->super->s_first_meta_bg;
/*
* calcluate the minimum number of blocks the given fs can be resized to
*/
-blk_t calculate_minimum_resize_size(ext2_filsys fs)
+blk64_t calculate_minimum_resize_size(ext2_filsys fs)
{
- blk_t inode_count, blks_needed, groups, data_blocks;
- blk_t grp, data_needed, last_start;
- int overhead = 0, num_of_superblocks = 0;
+ ext2_ino_t inode_count;
+ blk64_t blks_needed, groups, data_blocks;
+ blk64_t grp, data_needed, last_start;
+ blk64_t overhead = 0;
+ int num_of_superblocks = 0;
int extra_groups = 0;
int flexbg_size = 1 << fs->super->s_log_groups_per_flex;
blks_needed = ext2fs_div_ceil(inode_count,
fs->super->s_inodes_per_group) *
EXT2_BLOCKS_PER_GROUP(fs->super);
- groups = ext2fs_div_ceil(blks_needed,
- EXT2_BLOCKS_PER_GROUP(fs->super));
+ groups = ext2fs_div64_ceil(blks_needed,
+ EXT2_BLOCKS_PER_GROUP(fs->super));
/*
* we need to figure out how many backup superblocks we have so we can
* then we need to add them here
*/
while (data_needed > data_blocks) {
- blk_t remainder = data_needed - data_blocks;
- blk_t extra_grps;
+ blk64_t remainder = data_needed - data_blocks;
+ blk64_t extra_grps;
/* figure out how many more groups we need for the data */
- extra_grps = ext2fs_div_ceil(remainder,
- EXT2_BLOCKS_PER_GROUP(fs->super));
+ extra_grps = ext2fs_div64_ceil(remainder,
+ EXT2_BLOCKS_PER_GROUP(fs->super));
data_blocks += extra_grps * EXT2_BLOCKS_PER_GROUP(fs->super);
* so we need to adjust the size of the last group accordingly
*/
if (last_start < data_needed) {
- blk_t remainder = data_needed - last_start;
+ blk64_t remainder = data_needed - last_start;
/*
* 50 is a magic number that mkfs/resize uses to see if its