+ if (!fs_type) {
+ int megs = fs_param.s_blocks_count *
+ (EXT2_BLOCK_SIZE(&fs_param) / 1024) / 1024;
+
+ if (megs <= 3)
+ fs_type = "floppy";
+ else if (megs <= 512)
+ fs_type = "small";
+ else
+ fs_type = "default";
+ }
+
+ /* Figure out what features should be enabled */
+
+ if (r_opt == EXT2_GOOD_OLD_REV && fs_features) {
+ fprintf(stderr, _("Filesystem features not supported "
+ "with revision 0 filesystems\n"));
+ exit(1);
+ }
+
+ profile_get_string(profile, "defaults", "base_features", 0,
+ "filetype,sparse_super", &tmp);
+ profile_get_string(profile, "fs_types", fs_type, "base_features",
+ tmp, &tmp2);
+ edit_feature(tmp2, &fs_param.s_feature_compat);
+ free(tmp);
+ free(tmp2);
+
+ profile_get_string(profile, "defaults", "default_features", 0,
+ "", &tmp);
+ profile_get_string(profile, "fs_types", fs_type,
+ "default_features", tmp, &tmp2);
+ edit_feature(fs_features ? fs_features : tmp2,
+ &fs_param.s_feature_compat);
+ free(tmp);
+ free(tmp2);
+
+ if (s_opt > 0)
+ fs_param.s_feature_ro_compat |=
+ EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER;
+ else if (s_opt == 0)
+ fs_param.s_feature_ro_compat &=
+ ~EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER;
+
+ if (journal_size != 0)
+ fs_param.s_feature_compat |=
+ EXT3_FEATURE_COMPAT_HAS_JOURNAL;
+
+ if (fs_param.s_feature_incompat &
+ EXT3_FEATURE_INCOMPAT_JOURNAL_DEV) {
+ if (!fs_type)
+ fs_type = "journal";
+ reserved_ratio = 0;
+ fs_param.s_feature_incompat = EXT3_FEATURE_INCOMPAT_JOURNAL_DEV;
+ fs_param.s_feature_compat = 0;
+ fs_param.s_feature_ro_compat = 0;
+ }
+
+ if (fs_param.s_rev_level == EXT2_GOOD_OLD_REV) {
+ fs_param.s_feature_incompat = 0;
+ fs_param.s_feature_compat = 0;
+ fs_param.s_feature_ro_compat = 0;
+ }
+
+ /* Set first meta blockgroup via an environment variable */
+ /* (this is mostly for debugging purposes) */
+ if ((fs_param.s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG) &&
+ ((tmp = getenv("MKE2FS_FIRST_META_BG"))))
+ fs_param.s_first_meta_bg = atoi(tmp);
+
+ /* Get the hardware sector size, if available */
+ retval = ext2fs_get_device_sectsize(device_name, §or_size);
+ if (retval) {
+ com_err(program_name, retval,
+ _("while trying to determine hardware sector size"));
+ exit(1);
+ }
+
+ if ((tmp = getenv("MKE2FS_DEVICE_SECTSIZE")) != NULL)
+ sector_size = atoi(tmp);
+
+ if (blocksize <= 0) {
+ profile_get_integer(profile, "defaults", "blocksize", 0,
+ 1024, &use_bsize);
+ profile_get_integer(profile, "fs_types", fs_type,
+ "blocksize", use_bsize, &use_bsize);
+
+ if (use_bsize == -1) {
+ use_bsize = sys_page_size;
+ if ((linux_version_code < (2*65536 + 6*256)) &&
+ (use_bsize > 4096))
+ use_bsize = 4096;
+ }
+ if (sector_size && use_bsize < sector_size)
+ use_bsize = sector_size;
+ if ((blocksize < 0) && (use_bsize < (-blocksize)))
+ use_bsize = -blocksize;
+ blocksize = use_bsize;
+ fs_param.s_blocks_count /= blocksize / 1024;
+ }
+
+ if (inode_ratio == 0) {
+ profile_get_integer(profile, "defaults", "inode_ratio", 0,
+ 8192, &inode_ratio);
+ profile_get_integer(profile, "fs_types", fs_type,
+ "inode_ratio", inode_ratio,
+ &inode_ratio);
+
+ if (inode_ratio < blocksize)
+ inode_ratio = blocksize;
+ }
+
+ fs_param.s_log_frag_size = fs_param.s_log_block_size =
+ int_log2(blocksize >> EXT2_MIN_BLOCK_LOG_SIZE);
+
+ blocksize = EXT2_BLOCK_SIZE(&fs_param);
+
+ if (extended_opts)
+ parse_extended_opts(&fs_param, extended_opts);
+
+ /* Since sparse_super is the default, we would only have a problem
+ * here if it was explicitly disabled.