mirror of https://github.com/vitalif/e2fsprogs
libext2fs: clean up ext2fs_bg_flags_ interfaces
The ext2fs_bg_flag* functions were confusing. Currently we have this: void ext2fs_bg_flags_set(ext2_filsys fs, dgrp_t group, __u16 bg_flags); void ext2fs_bg_flags_clear(ext2_filsys fs, dgrp_t group,__u16 bg_flags); (_set (unused) sets exactly bg_flags; _clear clears all and ignores bg_flags) and these, which can twiddle individual bits in bg_flags: void ext2fs_bg_flag_set(ext2_filsys fs, dgrp_t group, __u16 bg_flag); void ext2fs_bg_flag_clear(ext2_filsys fs, dgrp_t group, __u16 bg_flag); A better interface, after the patch below, is just: ext2fs_bg_flags_zap(fs, group) /* zeros bg_flags */ ext2fs_bg_flags_set(fs, group, flags) /* adds flags to bg_flags */ ext2fs_bg_flags_clear(fs, group, flags) /* clears flags in bg_flags */ and remove the original ext2fs_bg_flags_set / ext2fs_bg_flags_clear. Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>bitmap-optimize
parent
03b9dca63a
commit
e633b58ac7
|
@ -991,7 +991,7 @@ out_htree:
|
|||
pctx.num = dirent->inode;
|
||||
if (fix_problem(ctx, PR_2_INOREF_BG_INO_UNINIT,
|
||||
&cd->pctx)){
|
||||
ext2fs_bg_flag_clear(fs, group,
|
||||
ext2fs_bg_flags_clear(fs, group,
|
||||
EXT2_BG_INODE_UNINIT);
|
||||
ext2fs_mark_super_dirty(fs);
|
||||
ctx->flags |= E2F_FLAG_RESTART_LATER;
|
||||
|
|
|
@ -260,8 +260,7 @@ redo_counts:
|
|||
pctx2.blk = i;
|
||||
pctx2.group = group;
|
||||
if (fix_problem(ctx, PR_5_BLOCK_UNINIT,&pctx2)){
|
||||
ext2fs_bg_flag_clear(fs, group, EXT2_BG_BLOCK_UNINIT)
|
||||
;
|
||||
ext2fs_bg_flags_clear(fs, group, EXT2_BG_BLOCK_UNINIT);
|
||||
skip_group = 0;
|
||||
}
|
||||
}
|
||||
|
@ -343,8 +342,7 @@ redo_counts:
|
|||
|
||||
if (fix_problem(ctx, PR_5_FREE_BLOCK_COUNT_GROUP,
|
||||
&pctx)) {
|
||||
fs->group_desc[i].bg_free_blocks_count =
|
||||
free_array[i];
|
||||
ext2fs_bg_free_blocks_count_set(fs, i, free_array[i]);
|
||||
ext2fs_mark_super_dirty(fs);
|
||||
} else
|
||||
ext2fs_unmark_valid(fs);
|
||||
|
@ -482,8 +480,7 @@ redo_counts:
|
|||
pctx2.blk = i;
|
||||
pctx2.group = group;
|
||||
if (fix_problem(ctx, PR_5_INODE_UNINIT,&pctx2)){
|
||||
ext2fs_bg_flag_clear(fs, group, EXT2_BG_INODE_UNINIT)
|
||||
;
|
||||
ext2fs_bg_flags_clear(fs, group, EXT2_BG_INODE_UNINIT);
|
||||
skip_group = 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -638,8 +638,8 @@ void check_super_block(e2fsck_t ctx)
|
|||
should_be = 0;
|
||||
if (!ext2fs_group_desc_csum_verify(fs, i)) {
|
||||
if (fix_problem(ctx, PR_0_GDT_CSUM, &pctx)) {
|
||||
ext2fs_bg_flag_clear (fs, i, EXT2_BG_BLOCK_UNINIT);
|
||||
ext2fs_bg_flag_clear (fs, i, EXT2_BG_INODE_UNINIT);
|
||||
ext2fs_bg_flags_clear(fs, i, EXT2_BG_BLOCK_UNINIT);
|
||||
ext2fs_bg_flags_clear(fs, i, EXT2_BG_INODE_UNINIT);
|
||||
gd->bg_itable_unused = 0;
|
||||
should_be = 1;
|
||||
}
|
||||
|
@ -651,8 +651,8 @@ void check_super_block(e2fsck_t ctx)
|
|||
ext2fs_bg_flag_test(fs, i, EXT2_BG_INODE_UNINIT) ||
|
||||
gd->bg_itable_unused != 0)){
|
||||
if (fix_problem(ctx, PR_0_GDT_UNINIT, &pctx)) {
|
||||
ext2fs_bg_flag_clear (fs, i, EXT2_BG_BLOCK_UNINIT);
|
||||
ext2fs_bg_flag_clear (fs, i, EXT2_BG_INODE_UNINIT);
|
||||
ext2fs_bg_flags_clear(fs, i, EXT2_BG_BLOCK_UNINIT);
|
||||
ext2fs_bg_flags_clear(fs, i, EXT2_BG_INODE_UNINIT);
|
||||
gd->bg_itable_unused = 0;
|
||||
should_be = 1;
|
||||
}
|
||||
|
@ -662,7 +662,7 @@ void check_super_block(e2fsck_t ctx)
|
|||
if (i == fs->group_desc_count - 1 &&
|
||||
ext2fs_bg_flag_test(fs, i, EXT2_BG_BLOCK_UNINIT)) {
|
||||
if (fix_problem(ctx, PR_0_BB_UNINIT_LAST, &pctx)) {
|
||||
ext2fs_bg_flag_clear (fs, i, EXT2_BG_BLOCK_UNINIT);
|
||||
ext2fs_bg_flags_clear(fs, i, EXT2_BG_BLOCK_UNINIT);
|
||||
should_be = 1;
|
||||
}
|
||||
ext2fs_unmark_valid(fs);
|
||||
|
@ -671,7 +671,7 @@ void check_super_block(e2fsck_t ctx)
|
|||
if (ext2fs_bg_flag_test(fs, i, EXT2_BG_BLOCK_UNINIT) &&
|
||||
!ext2fs_bg_flag_test(fs, i, EXT2_BG_INODE_UNINIT)) {
|
||||
if (fix_problem(ctx, PR_0_BB_UNINIT_IB_INIT, &pctx)) {
|
||||
ext2fs_bg_flag_clear (fs, i, EXT2_BG_BLOCK_UNINIT);
|
||||
ext2fs_bg_flags_clear(fs, i, EXT2_BG_BLOCK_UNINIT);
|
||||
should_be = 1;
|
||||
}
|
||||
ext2fs_unmark_valid(fs);
|
||||
|
|
|
@ -68,7 +68,7 @@ static void check_block_uninit(ext2_filsys fs, ext2fs_block_bitmap map,
|
|||
else
|
||||
ext2fs_fast_unmark_block_bitmap2(map, blk);
|
||||
}
|
||||
ext2fs_bg_flag_clear(fs, group, EXT2_BG_BLOCK_UNINIT);
|
||||
ext2fs_bg_flags_clear(fs, group, EXT2_BG_BLOCK_UNINIT);
|
||||
ext2fs_group_desc_csum_set(fs, group);
|
||||
}
|
||||
|
||||
|
@ -89,7 +89,7 @@ static void check_inode_uninit(ext2_filsys fs, ext2fs_inode_bitmap map,
|
|||
for (i=0; i < fs->super->s_inodes_per_group; i++, ino++)
|
||||
ext2fs_fast_unmark_inode_bitmap2(map, ino);
|
||||
|
||||
ext2fs_bg_flag_clear(fs, group, EXT2_BG_INODE_UNINIT);
|
||||
ext2fs_bg_flags_clear(fs, group, EXT2_BG_INODE_UNINIT);
|
||||
check_block_uninit(fs, fs->block_map, group);
|
||||
}
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ int ext2fs_reserve_super_and_bgd(ext2_filsys fs,
|
|||
|
||||
if (old_desc_blk) {
|
||||
if (fs->super->s_reserved_gdt_blocks && fs->block_map == bmap)
|
||||
ext2fs_bg_flag_clear(fs, group, EXT2_BG_BLOCK_UNINIT);
|
||||
ext2fs_bg_flags_clear(fs, group, EXT2_BG_BLOCK_UNINIT);
|
||||
for (j=0; j < old_desc_blocks; j++)
|
||||
if (old_desc_blk + j < ext2fs_blocks_count(fs->super))
|
||||
ext2fs_mark_block_bitmap2(bmap,
|
||||
|
|
|
@ -37,7 +37,7 @@ void ext2fs_inode_alloc_stats2(ext2_filsys fs, ext2_ino_t ino,
|
|||
|
||||
/* We don't strictly need to be clearing the uninit flag if inuse < 0
|
||||
* (i.e. freeing inodes) but it also means something is bad. */
|
||||
ext2fs_bg_flag_clear(fs, group, EXT2_BG_INODE_UNINIT);
|
||||
ext2fs_bg_flags_clear(fs, group, EXT2_BG_INODE_UNINIT);
|
||||
if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
|
||||
EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) {
|
||||
ext2_ino_t first_unused_inode = fs->super->s_inodes_per_group -
|
||||
|
@ -77,7 +77,7 @@ void ext2fs_block_alloc_stats2(ext2_filsys fs, blk64_t blk, int inuse)
|
|||
else
|
||||
ext2fs_unmark_block_bitmap2(fs->block_map, blk);
|
||||
fs->group_desc[group].bg_free_blocks_count -= inuse;
|
||||
ext2fs_bg_flag_clear(fs, group, EXT2_BG_BLOCK_UNINIT);
|
||||
ext2fs_bg_flags_clear(fs, group, EXT2_BG_BLOCK_UNINIT);
|
||||
ext2fs_group_desc_csum_set(fs, group);
|
||||
|
||||
ext2fs_free_blocks_count_add(fs->super, -inuse);
|
||||
|
|
|
@ -143,7 +143,7 @@ errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group,
|
|||
dgrp_t gr = ext2fs_group_of_blk(fs, new_blk);
|
||||
fs->group_desc[gr].bg_free_blocks_count--;
|
||||
ext2fs_free_blocks_count_add(fs->super, -1);
|
||||
ext2fs_bg_flag_clear(fs, gr, EXT2_BG_BLOCK_UNINIT);
|
||||
ext2fs_bg_flags_clear(fs, gr, EXT2_BG_BLOCK_UNINIT);
|
||||
ext2fs_group_desc_csum_set(fs, gr);
|
||||
}
|
||||
}
|
||||
|
@ -171,7 +171,7 @@ errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group,
|
|||
dgrp_t gr = ext2fs_group_of_blk(fs, new_blk);
|
||||
fs->group_desc[gr].bg_free_blocks_count--;
|
||||
ext2fs_free_blocks_count_add(fs->super, -1);
|
||||
ext2fs_bg_flag_clear(fs, gr, EXT2_BG_BLOCK_UNINIT);
|
||||
ext2fs_bg_flags_clear(fs, gr, EXT2_BG_BLOCK_UNINIT);
|
||||
ext2fs_group_desc_csum_set(fs, gr);
|
||||
}
|
||||
}
|
||||
|
@ -205,7 +205,7 @@ errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group,
|
|||
dgrp_t gr = ext2fs_group_of_blk(fs, blk);
|
||||
fs->group_desc[gr].bg_free_blocks_count--;
|
||||
ext2fs_free_blocks_count_add(fs->super, -1);
|
||||
ext2fs_bg_flag_clear(fs, gr,
|
||||
ext2fs_bg_flags_clear(fs, gr,
|
||||
EXT2_BG_BLOCK_UNINIT);
|
||||
ext2fs_group_desc_csum_set(fs, gr);
|
||||
}
|
||||
|
|
|
@ -421,25 +421,9 @@ __u16 ext2fs_bg_flags(ext2_filsys fs, dgrp_t group)
|
|||
}
|
||||
|
||||
/*
|
||||
* Set the flags for this block group
|
||||
* Zero out the flags for this block group
|
||||
*/
|
||||
void ext2fs_bg_flags_set(ext2_filsys fs, dgrp_t group, __u16 bg_flags)
|
||||
{
|
||||
if (fs->super->s_desc_size >= EXT2_MIN_DESC_SIZE_64BIT) {
|
||||
struct ext4_group_desc *gdp;
|
||||
gdp = (struct ext4_group_desc *) (fs->group_desc) + group;
|
||||
|
||||
gdp->bg_flags = bg_flags;
|
||||
return;
|
||||
}
|
||||
|
||||
fs->group_desc[group].bg_flags = bg_flags;
|
||||
}
|
||||
|
||||
/*
|
||||
* Clear the flags for this block group
|
||||
*/
|
||||
void ext2fs_bg_flags_clear(ext2_filsys fs, dgrp_t group, __u16 bg_flags)
|
||||
void ext2fs_bg_flags_zap(ext2_filsys fs, dgrp_t group)
|
||||
{
|
||||
if (fs->super->s_desc_size >= EXT2_MIN_DESC_SIZE_64BIT) {
|
||||
struct ext4_group_desc *gdp;
|
||||
|
@ -468,35 +452,35 @@ int ext2fs_bg_flag_test(ext2_filsys fs, dgrp_t group, __u16 bg_flag)
|
|||
}
|
||||
|
||||
/*
|
||||
* Set a particular flag for this block group
|
||||
* Set a flag or set of flags for this block group
|
||||
*/
|
||||
void ext2fs_bg_flag_set(ext2_filsys fs, dgrp_t group, __u16 bg_flag)
|
||||
void ext2fs_bg_flags_set(ext2_filsys fs, dgrp_t group, __u16 bg_flags)
|
||||
{
|
||||
if (fs->super->s_desc_size >= EXT2_MIN_DESC_SIZE_64BIT) {
|
||||
struct ext4_group_desc *gdp;
|
||||
gdp = (struct ext4_group_desc *) (fs->group_desc) + group;
|
||||
|
||||
gdp->bg_flags |= bg_flag;
|
||||
gdp->bg_flags |= bg_flags;
|
||||
return;
|
||||
}
|
||||
|
||||
fs->group_desc[group].bg_flags |= bg_flag;
|
||||
fs->group_desc[group].bg_flags |= bg_flags;
|
||||
}
|
||||
|
||||
/*
|
||||
* Clear a particular flag for this block group
|
||||
* Clear a flag or set of flags for this block group
|
||||
*/
|
||||
void ext2fs_bg_flag_clear(ext2_filsys fs, dgrp_t group, __u16 bg_flag)
|
||||
void ext2fs_bg_flags_clear(ext2_filsys fs, dgrp_t group, __u16 bg_flags)
|
||||
{
|
||||
if (fs->super->s_desc_size >= EXT2_MIN_DESC_SIZE_64BIT) {
|
||||
struct ext4_group_desc *gdp;
|
||||
gdp = (struct ext4_group_desc *) (fs->group_desc) + group;
|
||||
|
||||
gdp->bg_flags &= ~bg_flag;
|
||||
gdp->bg_flags &= ~bg_flags;
|
||||
return;
|
||||
}
|
||||
|
||||
fs->group_desc[group].bg_flags &= ~bg_flag;
|
||||
fs->group_desc[group].bg_flags &= ~bg_flags;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -202,7 +202,7 @@ int main(int argc, char **argv)
|
|||
fs->group_desc[i].bg_free_blocks_count = 31119;
|
||||
fs->group_desc[i].bg_free_inodes_count = 15701;
|
||||
fs->group_desc[i].bg_used_dirs_count = 2;
|
||||
fs->group_desc[i].bg_flags = 0;
|
||||
ext2fs_bg_flags_zap(fs, i);
|
||||
};
|
||||
|
||||
csum1 = ext2fs_group_desc_csum(fs, 0);
|
||||
|
|
|
@ -762,12 +762,10 @@ extern __u32 ext2fs_bg_itable_unused(ext2_filsys fs, dgrp_t group);
|
|||
extern void ext2fs_bg_itable_unused_set(ext2_filsys fs, dgrp_t group,
|
||||
__u32 n);
|
||||
extern __u16 ext2fs_bg_flags(ext2_filsys fs, dgrp_t group);
|
||||
extern void ext2fs_bg_flags_set(ext2_filsys fs, dgrp_t group, __u16 bg_flags);
|
||||
extern void ext2fs_bg_flags_clear(ext2_filsys fs, dgrp_t group,
|
||||
__u16 bg_flags);
|
||||
extern void ext2fs_bg_flags_zap(ext2_filsys fs, dgrp_t group);
|
||||
extern int ext2fs_bg_flag_test(ext2_filsys fs, dgrp_t group, __u16 bg_flag);
|
||||
extern void ext2fs_bg_flag_set(ext2_filsys fs, dgrp_t group, __u16 bg_flag);
|
||||
extern void ext2fs_bg_flag_clear(ext2_filsys fs, dgrp_t group, __u16 bg_flag);
|
||||
extern void ext2fs_bg_flags_set(ext2_filsys fs, dgrp_t group, __u16 bg_flags);
|
||||
extern void ext2fs_bg_flags_clear(ext2_filsys fs, dgrp_t group, __u16 bg_flags);
|
||||
extern __u16 ext2fs_bg_checksum(ext2_filsys fs, dgrp_t group);
|
||||
extern void ext2fs_bg_checksum_set(ext2_filsys fs, dgrp_t group, __u16 checksum);
|
||||
extern blk64_t ext2fs_file_acl_block(const struct ext2_inode *inode);
|
||||
|
|
|
@ -404,9 +404,9 @@ ipg_retry:
|
|||
*/
|
||||
if (csum_flag) {
|
||||
if (i != fs->group_desc_count - 1)
|
||||
ext2fs_bg_flag_set(fs, i, EXT2_BG_BLOCK_UNINIT)
|
||||
;
|
||||
ext2fs_bg_flag_set(fs, i, EXT2_BG_INODE_UNINIT);
|
||||
ext2fs_bg_flags_set(fs, i,
|
||||
EXT2_BG_BLOCK_UNINIT);
|
||||
ext2fs_bg_flags_set(fs, i, EXT2_BG_INODE_UNINIT);
|
||||
numblocks = super->s_inodes_per_group;
|
||||
if (i == 0)
|
||||
numblocks -= super->s_first_ino;
|
||||
|
|
|
@ -351,8 +351,8 @@ errcode_t ext2fs_open2(const char *name, const char *io_options,
|
|||
dgrp_t group;
|
||||
|
||||
for (group = 0; group < fs->group_desc_count; group++) {
|
||||
ext2fs_bg_flag_clear(fs, group, EXT2_BG_BLOCK_UNINIT);
|
||||
ext2fs_bg_flag_clear(fs, group, EXT2_BG_INODE_UNINIT);
|
||||
ext2fs_bg_flags_clear(fs, group, EXT2_BG_BLOCK_UNINIT);
|
||||
ext2fs_bg_flags_clear(fs, group, EXT2_BG_INODE_UNINIT);
|
||||
fs->group_desc[group].bg_itable_unused = 0;
|
||||
}
|
||||
ext2fs_mark_super_dirty(fs);
|
||||
|
|
|
@ -323,7 +323,7 @@ static void write_inode_tables(ext2_filsys fs, int lazy_flag)
|
|||
EXT2_BLOCK_SIZE(fs->super));
|
||||
} else {
|
||||
/* The kernel doesn't need to zero the itable blocks */
|
||||
ext2fs_bg_flag_set(fs, i, EXT2_BG_INODE_ZEROED);
|
||||
ext2fs_bg_flags_set(fs, i, EXT2_BG_INODE_ZEROED);
|
||||
ext2fs_group_desc_csum_set(fs, i);
|
||||
}
|
||||
retval = ext2fs_zero_blocks(fs, blk, num, &blk, &num);
|
||||
|
|
|
@ -112,7 +112,7 @@ errcode_t resize_fs(ext2_filsys fs, blk_t *new_size, int flags,
|
|||
|
||||
fix_uninit_block_bitmaps(rfs->new_fs);
|
||||
/* Clear the block bitmap uninit flag for the last block group */
|
||||
ext2fs_bg_flag_clear(rfs->new_fs, rfs->new_fs->group_desc_count - 1,
|
||||
ext2fs_bg_flags_clear(rfs->new_fs, rfs->new_fs->group_desc_count - 1,
|
||||
EXT2_BG_BLOCK_UNINIT);
|
||||
|
||||
*new_size = ext2fs_blocks_count(rfs->new_fs->super);
|
||||
|
@ -499,10 +499,9 @@ retry:
|
|||
sizeof(struct ext2_group_desc));
|
||||
adjblocks = 0;
|
||||
|
||||
ext2fs_bg_flags_clear(fs, i, 0);
|
||||
ext2fs_bg_flags_zap(fs, i);
|
||||
if (csum_flag)
|
||||
ext2fs_bg_flag_set(fs, i, EXT2_BG_INODE_UNINIT | EXT2_BG_INODE_ZEROED)
|
||||
;
|
||||
ext2fs_bg_flags_set(fs, i, EXT2_BG_INODE_UNINIT | EXT2_BG_INODE_ZEROED);
|
||||
if (i == fs->group_desc_count-1) {
|
||||
numblocks = (ext2fs_blocks_count(fs->super) -
|
||||
fs->super->s_first_data_block) %
|
||||
|
@ -512,8 +511,8 @@ retry:
|
|||
} else {
|
||||
numblocks = fs->super->s_blocks_per_group;
|
||||
if (csum_flag)
|
||||
ext2fs_bg_flag_set(fs, i, EXT2_BG_BLOCK_UNINIT)
|
||||
;
|
||||
ext2fs_bg_flags_set(fs, i,
|
||||
EXT2_BG_BLOCK_UNINIT);
|
||||
}
|
||||
|
||||
has_super = ext2fs_bg_has_super(fs, i);
|
||||
|
|
Loading…
Reference in New Issue