int csum_flag;
int bigalloc_flag;
int io_flags;
+ int has_bg;
unsigned reserved_inos;
char *buf = 0;
char c;
super->s_magic = EXT2_SUPER_MAGIC;
super->s_state = EXT2_VALID_FS;
- bigalloc_flag = EXT2_HAS_RO_COMPAT_FEATURE(param,
- EXT4_FEATURE_RO_COMPAT_BIGALLOC);
+ bigalloc_flag = ext2fs_has_feature_bigalloc(param);
assign_field(s_log_block_size);
* If we're creating an external journal device, we don't need
* to bother with the rest.
*/
- if (super->s_feature_incompat & EXT3_FEATURE_INCOMPAT_JOURNAL_DEV) {
+ if (ext2fs_has_feature_journal_dev(super)) {
fs->group_desc_count = 0;
ext2fs_mark_super_dirty(fs);
*ret_fs = fs;
}
set_field(s_desc_size,
- super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT ?
+ ext2fs_has_feature_64bit(super) ?
EXT2_MIN_DESC_SIZE_64BIT : 0);
fs->desc_blocks = ext2fs_div_ceil(fs->group_desc_count,
i = fs->blocksize >= 4096 ? 1 : 4096 / fs->blocksize;
- if (super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT &&
+ if (ext2fs_has_feature_64bit(super) &&
(ext2fs_blocks_count(super) / i) > (1ULL << 32))
set_field(s_inodes_count, ~0U);
else
/*
* check the number of reserved group descriptor table blocks
*/
- if (super->s_feature_compat & EXT2_FEATURE_COMPAT_RESIZE_INODE)
+ if (ext2fs_has_feature_resize_inode(super))
rsv_gdt = calc_reserved_gdt_blocks(fs);
else
rsv_gdt = 0;
* table, and the reserved gdt blocks.
*/
overhead = (int) (3 + fs->inode_blocks_per_group +
- fs->desc_blocks + super->s_reserved_gdt_blocks);
+ super->s_reserved_gdt_blocks);
+
+ /* Enable meta_bg if we'd lose more than 3/4 of a BG to GDT blocks. */
+ if (super->s_reserved_gdt_blocks + fs->desc_blocks >
+ super->s_blocks_per_group * 3 / 4)
+ ext2fs_set_feature_meta_bg(fs->super);
+
+ if (ext2fs_has_feature_meta_bg(fs->super))
+ overhead++;
+ else
+ overhead += fs->desc_blocks;
/* This can only happen if the user requested too many inodes */
if (overhead > super->s_blocks_per_group) {
* backup.
*/
overhead = (int) (2 + fs->inode_blocks_per_group);
- if (ext2fs_bg_has_super(fs, fs->group_desc_count - 1))
+ has_bg = 0;
+ if (ext2fs_has_feature_sparse_super2(super)) {
+ /*
+ * We have to do this manually since
+ * super->s_backup_bgs hasn't been set up yet.
+ */
+ if (fs->group_desc_count == 2)
+ has_bg = param->s_backup_bgs[0] != 0;
+ else
+ has_bg = param->s_backup_bgs[1] != 0;
+ } else
+ has_bg = ext2fs_bg_has_super(fs, fs->group_desc_count - 1);
+ if (has_bg)
overhead += 1 + fs->desc_blocks + super->s_reserved_gdt_blocks;
rem = ((ext2fs_blocks_count(super) - super->s_first_data_block) %
super->s_blocks_per_group);
*/
/* Set up the locations of the backup superblocks */
- if (super->s_feature_compat & EXT4_FEATURE_COMPAT_SPARSE_SUPER2) {
+ if (ext2fs_has_feature_sparse_super2(super)) {
if (super->s_backup_bgs[0] >= fs->group_desc_count)
super->s_backup_bgs[0] = fs->group_desc_count - 1;
if (super->s_backup_bgs[1] >= fs->group_desc_count)