unsigned long i, j, old_desc_blocks, max_group;
unsigned int meta_bg, meta_bg_size;
int has_super;
+ __u64 new_inodes; /* u64 to check for overflow */
fs->super->s_blocks_count = new_size;
/*
* Adjust the number of inodes
*/
+ new_inodes =(__u64)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
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;
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;
}
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++;