if (retval)
goto errout;
+ rfs->new_fs->flags &= ~EXT2_FLAG_MASTER_SB_ONLY;
retval = ext2fs_close(rfs->new_fs);
if (retval)
goto errout;
unsigned long i, j, old_desc_blocks, max_group;
unsigned int meta_bg, meta_bg_size;
int has_super;
+ unsigned long long new_inodes; /* u64 to check for overflow */
fs->super->s_blocks_count = new_size;
/*
* Adjust the number of inodes
*/
+ 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"),
+ new_inodes, ~0U);
+ return EXT2_ET_TOO_MANY_INODES;
+ }
fs->super->s_inodes_count = fs->super->s_inodes_per_group *
fs->group_desc_count;
/*
* Adjust the number of reserved blocks
*/
- blk = old_fs->super->s_r_blocks_count * 100 /
+ blk = (__u64)old_fs->super->s_r_blocks_count * 100 /
old_fs->super->s_blocks_count;
- fs->super->s_r_blocks_count = ((fs->super->s_blocks_count * blk)
- / 100);
+ fs->super->s_r_blocks_count = e2p_percent(blk,
+ fs->super->s_blocks_count);
/*
* Adjust the bitmaps for size
(old_fs->desc_blocks - fs->desc_blocks);
if (new < 0)
new = 0;
- if (new > fs->blocksize/4)
+ if (new > (int) fs->blocksize/4)
new = fs->blocksize/4;
fs->super->s_reserved_gdt_blocks = new;
if (new == 0)
ext2fs_mark_block_bitmap(fs->block_map, group_block);
adjblocks++;
}
- meta_bg_size = (fs->blocksize /
- sizeof (struct ext2_group_desc));
+ meta_bg_size = EXT2_DESC_PER_BLOCK(fs->super);
meta_bg = i / meta_bg_size;
if (!(fs->super->s_feature_incompat &
EXT2_FEATURE_INCOMPAT_META_BG) ||
/*
* Initialize the new block group descriptors
*/
- retval = ext2fs_get_mem(fs->blocksize * fs->inode_blocks_per_group,
+ retval = ext2fs_get_array(fs->blocksize, fs->inode_blocks_per_group,
&rfs->itable_buf);
if (retval)
goto errout;
static errcode_t mark_table_blocks(ext2_filsys fs,
ext2fs_block_bitmap bmap)
{
- blk_t block, b;
+ blk_t b;
unsigned int j;
dgrp_t i;
unsigned long meta_bg_size;
unsigned int old_desc_blocks;
- meta_bg_size = (fs->blocksize / sizeof (struct ext2_group_desc));
- block = fs->super->s_first_data_block;
+ meta_bg_size = EXT2_DESC_PER_BLOCK(fs->super);
if (fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG)
old_desc_blocks = fs->super->s_first_meta_bg;
else
*/
ext2fs_mark_block_bitmap(bmap,
fs->group_desc[i].bg_inode_bitmap);
- block += fs->super->s_blocks_per_group;
}
return 0;
}
* If we're increasing the number of descriptor blocks, life
* gets interesting....
*/
- meta_bg_size = (fs->blocksize / sizeof (struct ext2_group_desc));
+ meta_bg_size = EXT2_DESC_PER_BLOCK(fs->super);
for (i = 0; i < max_groups; i++) {
has_super = ext2fs_bg_has_super(fs, i);
if (has_super)
new_blk = fs->super->s_first_data_block;
if (!rfs->itable_buf) {
- retval = ext2fs_get_mem(fs->blocksize *
+ retval = ext2fs_get_array(fs->blocksize,
fs->inode_blocks_per_group,
&rfs->itable_buf);
if (retval)
retval = ext2fs_init_dblist(rfs->old_fs, 0);
if (retval) goto errout;
- retval = ext2fs_get_mem(rfs->old_fs->blocksize * 3, &block_buf);
+ retval = ext2fs_get_array(rfs->old_fs->blocksize, 3, &block_buf);
if (retval) goto errout;
start_to_move = (rfs->new_fs->group_desc_count *
retval = ext2fs_read_inode(is->rfs->old_fs, dir, &inode);
if (retval == 0) {
inode.i_mtime = inode.i_ctime = time(0);
- ext2fs_write_inode(is->rfs->old_fs, dir, &inode);
+ is->err = ext2fs_write_inode(is->rfs->old_fs, dir, &inode);
+ if (is->err)
+ return DIRENT_ABORT;
}
return DIRENT_CHANGED;
total_free = 0;
count = 0;
group = 0;
- for (ino = 1; ino <= fs->super->s_inodes_count; ino++) {
+
+ /* Protect loop from wrap-around if s_inodes_count maxed */
+ for (ino = 1; ino <= fs->super->s_inodes_count && ino > 0; ino++) {
if (!ext2fs_fast_test_inode_bitmap(fs->inode_map, ino)) {
group_free++;
total_free++;