mirror of https://github.com/vitalif/e2fsprogs
mke2fs: optimize fix_cluster_bg_counts()
Instead of iterating over the allocation bitmap using ext2fs_test_block_bitmap2(), bit by bit, use ext2fs_find_first_set_block_bitmap2() instead. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>maint-test
parent
424de6e8e3
commit
6e49e6a3e5
|
@ -2332,30 +2332,43 @@ static int mke2fs_discard_device(ext2_filsys fs)
|
||||||
|
|
||||||
static void fix_cluster_bg_counts(ext2_filsys fs)
|
static void fix_cluster_bg_counts(ext2_filsys fs)
|
||||||
{
|
{
|
||||||
blk64_t cluster, num_clusters, tot_free;
|
blk64_t block, num_blocks, last_block, next;
|
||||||
unsigned num = 0;
|
blk64_t tot_free = 0;
|
||||||
int grp_free, num_free, group;
|
errcode_t retval;
|
||||||
|
dgrp_t group = 0;
|
||||||
|
int grp_free = 0;
|
||||||
|
|
||||||
num_clusters = EXT2FS_B2C(fs, ext2fs_blocks_count(fs->super));
|
num_blocks = ext2fs_blocks_count(fs->super);
|
||||||
tot_free = num_free = group = grp_free = 0;
|
last_block = ext2fs_group_last_block2(fs, group);
|
||||||
for (cluster = EXT2FS_B2C(fs, fs->super->s_first_data_block);
|
block = fs->super->s_first_data_block;
|
||||||
cluster < num_clusters; cluster++) {
|
while (block < num_blocks) {
|
||||||
if (!ext2fs_test_block_bitmap2(fs->block_map,
|
retval = ext2fs_find_first_zero_block_bitmap2(fs->block_map,
|
||||||
EXT2FS_C2B(fs, cluster))) {
|
block, last_block, &next);
|
||||||
grp_free++;
|
if (retval == 0)
|
||||||
tot_free++;
|
block = next;
|
||||||
|
else {
|
||||||
|
block = last_block + 1;
|
||||||
|
goto next_bg;
|
||||||
}
|
}
|
||||||
num++;
|
|
||||||
if ((num == fs->super->s_clusters_per_group) ||
|
retval = ext2fs_find_first_set_block_bitmap2(fs->block_map,
|
||||||
(cluster == num_clusters-1)) {
|
block, last_block, &next);
|
||||||
|
if (retval)
|
||||||
|
next = last_block + 1;
|
||||||
|
grp_free += EXT2FS_NUM_B2C(fs, next - block);
|
||||||
|
tot_free += next - block;
|
||||||
|
block = next;
|
||||||
|
|
||||||
|
if (block > last_block) {
|
||||||
|
next_bg:
|
||||||
ext2fs_bg_free_blocks_count_set(fs, group, grp_free);
|
ext2fs_bg_free_blocks_count_set(fs, group, grp_free);
|
||||||
ext2fs_group_desc_csum_set(fs, group);
|
ext2fs_group_desc_csum_set(fs, group);
|
||||||
num = 0;
|
|
||||||
grp_free = 0;
|
grp_free = 0;
|
||||||
group++;
|
group++;
|
||||||
|
last_block = ext2fs_group_last_block2(fs, group);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ext2fs_free_blocks_count_set(fs->super, EXT2FS_C2B(fs, tot_free));
|
ext2fs_free_blocks_count_set(fs->super, tot_free);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int create_quota_inodes(ext2_filsys fs)
|
static int create_quota_inodes(ext2_filsys fs)
|
||||||
|
|
Loading…
Reference in New Issue