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>
diff --git a/lib/ext2fs/alloc.c b/lib/ext2fs/alloc.c
index 24ab05b..a711d45 100644
--- a/lib/ext2fs/alloc.c
+++ b/lib/ext2fs/alloc.c
@@ -68,7 +68,7 @@
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 @@
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);
}
diff --git a/lib/ext2fs/alloc_sb.c b/lib/ext2fs/alloc_sb.c
index 37f2140..b2e1969 100644
--- a/lib/ext2fs/alloc_sb.c
+++ b/lib/ext2fs/alloc_sb.c
@@ -62,7 +62,7 @@
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,
diff --git a/lib/ext2fs/alloc_stats.c b/lib/ext2fs/alloc_stats.c
index 0ea06ab..7229385 100644
--- a/lib/ext2fs/alloc_stats.c
+++ b/lib/ext2fs/alloc_stats.c
@@ -37,7 +37,7 @@
/* 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 @@
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);
diff --git a/lib/ext2fs/alloc_tables.c b/lib/ext2fs/alloc_tables.c
index 94aeeda..8141ec3 100644
--- a/lib/ext2fs/alloc_tables.c
+++ b/lib/ext2fs/alloc_tables.c
@@ -143,7 +143,7 @@
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 @@
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 @@
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);
}
diff --git a/lib/ext2fs/blknum.c b/lib/ext2fs/blknum.c
index 9b25ec7..6ebe47e 100644
--- a/lib/ext2fs/blknum.c
+++ b/lib/ext2fs/blknum.c
@@ -421,25 +421,9 @@
}
/*
- * 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 @@
}
/*
- * 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;
}
/*
diff --git a/lib/ext2fs/csum.c b/lib/ext2fs/csum.c
index dca42a0..c2a177d 100644
--- a/lib/ext2fs/csum.c
+++ b/lib/ext2fs/csum.c
@@ -202,7 +202,7 @@
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);
diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h
index 488fb6d..eb655b5 100644
--- a/lib/ext2fs/ext2fs.h
+++ b/lib/ext2fs/ext2fs.h
@@ -762,12 +762,10 @@
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);
diff --git a/lib/ext2fs/initialize.c b/lib/ext2fs/initialize.c
index edcdd72..986dd28 100644
--- a/lib/ext2fs/initialize.c
+++ b/lib/ext2fs/initialize.c
@@ -404,9 +404,9 @@
*/
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;
diff --git a/lib/ext2fs/openfs.c b/lib/ext2fs/openfs.c
index 8b48617..8b24619 100644
--- a/lib/ext2fs/openfs.c
+++ b/lib/ext2fs/openfs.c
@@ -351,8 +351,8 @@
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);