diff options
Diffstat (limited to 'misc/tune2fs.c')
-rw-r--r-- | misc/tune2fs.c | 161 |
1 files changed, 82 insertions, 79 deletions
diff --git a/misc/tune2fs.c b/misc/tune2fs.c index 0d1b7518..5bf51870 100644 --- a/misc/tune2fs.c +++ b/misc/tune2fs.c @@ -69,7 +69,8 @@ static int I_flag; static time_t last_check_time; static int print_label; static int max_mount_count, mount_count, mount_flags; -static unsigned long interval, reserved_blocks; +static unsigned long interval; +static blk64_t reserved_blocks; static double reserved_ratio; static unsigned long resgid, resuid; static unsigned short errors; @@ -89,8 +90,8 @@ static struct list_head blk_move_list; struct blk_move { struct list_head list; - blk_t old_loc; - blk_t new_loc; + blk64_t old_loc; + blk64_t new_loc; }; @@ -198,7 +199,7 @@ static void remove_journal_device(ext2_filsys fs) } /* Get the journal superblock */ - if ((retval = io_channel_read_blk(jfs->io, 1, -1024, buf))) { + if ((retval = io_channel_read_blk64(jfs->io, 1, -1024, buf))) { com_err(program_name, retval, _("while reading journal superblock")); goto no_valid_journal; @@ -230,7 +231,7 @@ static void remove_journal_device(ext2_filsys fs) jsb->s_nr_users = htonl(nr_users); /* Write back the journal superblock */ - if ((retval = io_channel_write_blk(jfs->io, 1, -1024, buf))) { + if ((retval = io_channel_write_blk64(jfs->io, 1, -1024, buf))) { com_err(program_name, retval, "while writing journal superblock."); goto no_valid_journal; @@ -251,19 +252,21 @@ no_valid_journal: } /* Helper function for remove_journal_inode */ -static int release_blocks_proc(ext2_filsys fs, blk_t *blocknr, - int blockcnt EXT2FS_ATTR((unused)), +static int release_blocks_proc(ext2_filsys fs, blk64_t *blocknr, + e2_blkcnt_t blockcnt EXT2FS_ATTR((unused)), + blk64_t ref_block EXT2FS_ATTR((unused)), + int ref_offset EXT2FS_ATTR((unused)), void *private EXT2FS_ATTR((unused))) { - blk_t block; + blk64_t block; int group; block = *blocknr; - ext2fs_unmark_block_bitmap(fs->block_map, block); - group = ext2fs_group_of_blk(fs, block); - fs->group_desc[group].bg_free_blocks_count++; + ext2fs_unmark_block_bitmap2(fs->block_map, block); + group = ext2fs_group_of_blk2(fs, block); + ext2fs_bg_free_blocks_count_set(fs, group, ext2fs_bg_free_blocks_count(fs, group) + 1); ext2fs_group_desc_csum_set(fs, group); - fs->super->s_free_blocks_count++; + ext2fs_free_blocks_count_add(fs->super, EXT2FS_CLUSTER_RATIO(fs)); return 0; } @@ -289,9 +292,9 @@ static void remove_journal_inode(ext2_filsys fs) _("while reading bitmaps")); exit(1); } - retval = ext2fs_block_iterate(fs, ino, - BLOCK_FLAG_READ_ONLY, NULL, - release_blocks_proc, NULL); + retval = ext2fs_block_iterate3(fs, ino, + BLOCK_FLAG_READ_ONLY, NULL, + release_blocks_proc, NULL); if (retval) { com_err(program_name, retval, _("while clearing journal inode")); @@ -346,7 +349,6 @@ static void update_feature_set(ext2_filsys fs, char *features) { struct ext2_super_block *sb = fs->super; struct ext2_group_desc *gd; - errcode_t retval; __u32 old_features[3]; int i, type_err; unsigned int mask_err; @@ -447,8 +449,8 @@ static void update_feature_set(ext2_filsys fs, char *features) if (FEATURE_ON(E2P_FEATURE_RO_INCOMPAT, EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) { - gd = fs->group_desc; - for (i = 0; i < fs->group_desc_count; i++, gd++) { + for (i = 0; i < fs->group_desc_count; i++) { + gd = ext2fs_group_desc(fs, fs->group_desc, i); gd->bg_itable_unused = 0; gd->bg_flags = EXT2_BG_INODE_ZEROED; ext2fs_group_desc_csum_set(fs, i); @@ -458,8 +460,8 @@ static void update_feature_set(ext2_filsys fs, char *features) if (FEATURE_OFF(E2P_FEATURE_RO_INCOMPAT, EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) { - gd = fs->group_desc; - for (i = 0; i < fs->group_desc_count; i++, gd++) { + for (i = 0; i < fs->group_desc_count; i++) { + gd = ext2fs_group_desc(fs, fs->group_desc, i); if ((gd->bg_flags & EXT2_BG_INODE_ZEROED) == 0) { /* * XXX what we really should do is zap @@ -1022,22 +1024,22 @@ static int get_move_bitmaps(ext2_filsys fs, int new_ino_blks_per_grp, dgrp_t i; int retval; ext2_badblocks_list bb_list = 0; - blk_t j, needed_blocks = 0; - blk_t start_blk, end_blk; + blk64_t j, needed_blocks = 0; + blk64_t start_blk, end_blk; retval = ext2fs_read_bb_inode(fs, &bb_list); if (retval) return retval; for (i = 0; i < fs->group_desc_count; i++) { - start_blk = fs->group_desc[i].bg_inode_table + + start_blk = ext2fs_inode_table_loc(fs, i) + fs->inode_blocks_per_group; - end_blk = fs->group_desc[i].bg_inode_table + + end_blk = ext2fs_inode_table_loc(fs, i) + new_ino_blks_per_grp; for (j = start_blk; j < end_blk; j++) { - if (ext2fs_test_block_bitmap(fs->block_map, j)) { + if (ext2fs_test_block_bitmap2(fs->block_map, j)) { /* * IF the block is a bad block we fail */ @@ -1046,20 +1048,20 @@ static int get_move_bitmaps(ext2_filsys fs, int new_ino_blks_per_grp, return ENOSPC; } - ext2fs_mark_block_bitmap(bmap, j); + ext2fs_mark_block_bitmap2(bmap, j); } else { /* * We are going to use this block for * inode table. So mark them used. */ - ext2fs_mark_block_bitmap(fs->block_map, j); + ext2fs_mark_block_bitmap2(fs->block_map, j); } } needed_blocks += end_blk - start_blk; } ext2fs_badblocks_list_free(bb_list); - if (needed_blocks > fs->super->s_free_blocks_count) + if (needed_blocks > ext2fs_free_blocks_count(fs->super)) return ENOSPC; return 0; @@ -1069,9 +1071,9 @@ static int ext2fs_is_meta_block(ext2_filsys fs, blk_t blk) { dgrp_t group; group = ext2fs_group_of_blk(fs, blk); - if (fs->group_desc[group].bg_block_bitmap == blk) + if (ext2fs_block_bitmap_loc(fs, group) == blk) return 1; - if (fs->group_desc[group].bg_inode_bitmap == blk) + if (ext2fs_inode_bitmap_loc(fs, group) == blk) return 1; return 0; } @@ -1095,10 +1097,10 @@ static int move_block(ext2_filsys fs, ext2fs_block_bitmap bmap) { char *buf; - dgrp_t group; + dgrp_t group = 0; errcode_t retval; int meta_data = 0; - blk_t blk, new_blk, goal; + blk64_t blk, new_blk, goal; struct blk_move *bmv; retval = ext2fs_get_mem(fs->blocksize, &buf); @@ -1106,8 +1108,8 @@ static int move_block(ext2_filsys fs, ext2fs_block_bitmap bmap) return retval; for (new_blk = blk = fs->super->s_first_data_block; - blk < fs->super->s_blocks_count; blk++) { - if (!ext2fs_test_block_bitmap(bmap, blk)) + blk < ext2fs_blocks_count(fs->super); blk++) { + if (!ext2fs_test_block_bitmap2(bmap, blk)) continue; if (ext2fs_is_meta_block(fs, blk)) { @@ -1119,13 +1121,13 @@ static int move_block(ext2_filsys fs, ext2fs_block_bitmap bmap) * fail */ group = ext2fs_group_of_blk(fs, blk); - goal = ext2fs_group_first_block(fs, group); + goal = ext2fs_group_first_block2(fs, group); meta_data = 1; } else { goal = new_blk; } - retval = ext2fs_new_block(fs, goal, NULL, &new_blk); + retval = ext2fs_new_block2(fs, goal, NULL, &new_blk); if (retval) goto err_out; @@ -1136,7 +1138,7 @@ static int move_block(ext2_filsys fs, ext2fs_block_bitmap bmap) } /* Mark this block as allocated */ - ext2fs_mark_block_bitmap(fs->block_map, new_blk); + ext2fs_mark_block_bitmap2(fs->block_map, new_blk); /* Add it to block move list */ retval = ext2fs_get_mem(sizeof(struct blk_move), &bmv); @@ -1148,11 +1150,11 @@ static int move_block(ext2_filsys fs, ext2fs_block_bitmap bmap) list_add(&(bmv->list), &blk_move_list); - retval = io_channel_read_blk(fs->io, blk, 1, buf); + retval = io_channel_read_blk64(fs->io, blk, 1, buf); if (retval) goto err_out; - retval = io_channel_write_blk(fs->io, new_blk, 1, buf); + retval = io_channel_write_blk64(fs->io, new_blk, 1, buf); if (retval) goto err_out; } @@ -1162,7 +1164,7 @@ err_out: return retval; } -static blk_t translate_block(blk_t blk) +static blk64_t translate_block(blk64_t blk) { struct list_head *entry; struct blk_move *bmv; @@ -1177,17 +1179,17 @@ static blk_t translate_block(blk_t blk) } static int process_block(ext2_filsys fs EXT2FS_ATTR((unused)), - blk_t *block_nr, + blk64_t *block_nr, e2_blkcnt_t blockcnt EXT2FS_ATTR((unused)), - blk_t ref_block EXT2FS_ATTR((unused)), + blk64_t ref_block EXT2FS_ATTR((unused)), int ref_offset EXT2FS_ATTR((unused)), void *priv_data) { int ret = 0; - blk_t new_blk; + blk64_t new_blk; ext2fs_block_bitmap bmap = (ext2fs_block_bitmap) priv_data; - if (!ext2fs_test_block_bitmap(bmap, *block_nr)) + if (!ext2fs_test_block_bitmap2(bmap, *block_nr)) return 0; new_blk = translate_block(*block_nr); if (new_blk) { @@ -1205,7 +1207,7 @@ static int inode_scan_and_fix(ext2_filsys fs, ext2fs_block_bitmap bmap) { errcode_t retval = 0; ext2_ino_t ino; - blk_t blk; + blk64_t blk; char *block_buf = 0; struct ext2_inode inode; ext2_inode_scan scan = NULL; @@ -1236,13 +1238,14 @@ static int inode_scan_and_fix(ext2_filsys fs, ext2fs_block_bitmap bmap) * Do we need to fix this ?? */ - if (inode.i_file_acl && - ext2fs_test_block_bitmap(bmap, inode.i_file_acl)) { - blk = translate_block(inode.i_file_acl); + if (ext2fs_file_acl_block(&inode) && + ext2fs_test_block_bitmap2(bmap, + ext2fs_file_acl_block(&inode))) { + blk = translate_block(ext2fs_file_acl_block(&inode)); if (!blk) continue; - inode.i_file_acl = blk; + ext2fs_file_acl_block_set(&inode, blk); /* * Write the inode to disk so that inode table @@ -1256,7 +1259,7 @@ static int inode_scan_and_fix(ext2_filsys fs, ext2fs_block_bitmap bmap) if (!ext2fs_inode_has_valid_blocks(&inode)) continue; - retval = ext2fs_block_iterate2(fs, ino, 0, block_buf, + retval = ext2fs_block_iterate3(fs, ino, 0, block_buf, process_block, bmap); if (retval) goto err_out; @@ -1280,20 +1283,20 @@ static int group_desc_scan_and_fix(ext2_filsys fs, ext2fs_block_bitmap bmap) blk_t blk, new_blk; for (i = 0; i < fs->group_desc_count; i++) { - blk = fs->group_desc[i].bg_block_bitmap; - if (ext2fs_test_block_bitmap(bmap, blk)) { + blk = ext2fs_block_bitmap_loc(fs, i); + if (ext2fs_test_block_bitmap2(bmap, blk)) { new_blk = translate_block(blk); if (!new_blk) continue; - fs->group_desc[i].bg_block_bitmap = new_blk; + ext2fs_block_bitmap_loc_set(fs, i, new_blk); } - blk = fs->group_desc[i].bg_inode_bitmap; - if (ext2fs_test_block_bitmap(bmap, blk)) { + blk = ext2fs_inode_bitmap_loc(fs, i); + if (ext2fs_test_block_bitmap2(bmap, blk)) { new_blk = translate_block(blk); if (!new_blk) continue; - fs->group_desc[i].bg_inode_bitmap = new_blk; + ext2fs_inode_bitmap_loc_set(fs, i, new_blk); } } return 0; @@ -1302,7 +1305,7 @@ static int group_desc_scan_and_fix(ext2_filsys fs, ext2fs_block_bitmap bmap) static int expand_inode_table(ext2_filsys fs, unsigned long new_ino_size) { dgrp_t i; - blk_t blk; + blk64_t blk; errcode_t retval; int new_ino_blks_per_grp; unsigned int j; @@ -1333,8 +1336,8 @@ static int expand_inode_table(ext2_filsys fs, unsigned long new_ino_size) tmp_new_itable = new_itable; for (i = 0; i < fs->group_desc_count; i++) { - blk = fs->group_desc[i].bg_inode_table; - retval = io_channel_read_blk(fs->io, blk, + blk = ext2fs_inode_table_loc(fs, i); + retval = io_channel_read_blk64(fs->io, blk, fs->inode_blocks_per_group, old_itable); if (retval) goto err_out; @@ -1353,7 +1356,7 @@ static int expand_inode_table(ext2_filsys fs, unsigned long new_ino_size) old_itable = tmp_old_itable; new_itable = tmp_new_itable; - retval = io_channel_write_blk(fs->io, blk, + retval = io_channel_write_blk64(fs->io, blk, new_ino_blks_per_grp, new_itable); if (retval) goto err_out; @@ -1375,7 +1378,7 @@ err_out: 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; @@ -1386,21 +1389,22 @@ static errcode_t ext2fs_calculate_summary_stats(ext2_filsys fs) * First calculate the block statistics */ for (blk = fs->super->s_first_data_block; - blk < fs->super->s_blocks_count; blk++) { - if (!ext2fs_fast_test_block_bitmap(fs->block_map, blk)) { + blk < ext2fs_blocks_count(fs->super); blk++) { + if (!ext2fs_fast_test_block_bitmap2(fs->block_map, blk)) { group_free++; total_free++; } count++; if ((count == fs->super->s_blocks_per_group) || - (blk == fs->super->s_blocks_count-1)) { - fs->group_desc[group++].bg_free_blocks_count = - group_free; + (blk == ext2fs_blocks_count(fs->super)-1)) { + ext2fs_bg_free_blocks_count_set(fs, group++, + group_free); count = 0; group_free = 0; } } - fs->super->s_free_blocks_count = total_free; + total_free = EXT2FS_C2B(fs, total_free); + ext2fs_free_blocks_count_set(fs->super, total_free); /* * Next, calculate the inode statistics @@ -1412,15 +1416,15 @@ static errcode_t ext2fs_calculate_summary_stats(ext2_filsys fs) /* 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)) { + if (!ext2fs_fast_test_inode_bitmap2(fs->inode_map, ino)) { group_free++; total_free++; } count++; if ((count == fs->super->s_inodes_per_group) || (ino == fs->super->s_inodes_count)) { - fs->group_desc[group++].bg_free_inodes_count = - group_free; + ext2fs_bg_free_inodes_count_set(fs, group++, + group_free); count = 0; group_free = 0; } @@ -1714,23 +1718,22 @@ retry_open: interval); } if (m_flag) { - sb->s_r_blocks_count = (unsigned int) (reserved_ratio * - sb->s_blocks_count / 100.0); + ext2fs_r_blocks_count_set(sb, reserved_ratio * + ext2fs_blocks_count(sb) / 100.0); ext2fs_mark_super_dirty(fs); - printf(_("Setting reserved blocks percentage to %g%% " - "(%u blocks)\n"), - reserved_ratio, sb->s_r_blocks_count); + printf (_("Setting reserved blocks percentage to %g%% (%llu blocks)\n"), + reserved_ratio, ext2fs_r_blocks_count(sb)); } if (r_flag) { - if (reserved_blocks > sb->s_blocks_count/2) { + if (reserved_blocks > ext2fs_blocks_count(sb)/2) { com_err(program_name, 0, - _("reserved blocks count is too big (%lu)"), + _("reserved blocks count is too big (%llu)"), reserved_blocks); exit(1); } - sb->s_r_blocks_count = reserved_blocks; + ext2fs_r_blocks_count_set(sb, reserved_blocks); ext2fs_mark_super_dirty(fs); - printf(_("Setting reserved blocks count to %lu\n"), + printf(_("Setting reserved blocks count to %llu\n"), reserved_blocks); } if (s_flag == 1) { |