diff options
Diffstat (limited to 'misc/mke2fs.c')
-rw-r--r-- | misc/mke2fs.c | 82 |
1 files changed, 78 insertions, 4 deletions
diff --git a/misc/mke2fs.c b/misc/mke2fs.c index ba5f179a..4a9c1b09 100644 --- a/misc/mke2fs.c +++ b/misc/mke2fs.c @@ -94,7 +94,9 @@ static gid_t root_gid; int journal_size; int journal_flags; int journal_fc_size; +static e2_blkcnt_t orphan_file_blocks; static int lazy_itable_init; +static int assume_storage_prezeroed; static int packed_meta_blocks; int no_copy_xattrs; static char *bad_blocks_filename = NULL; @@ -1012,6 +1014,11 @@ static void parse_extended_opts(struct ext2_super_block *param, lazy_itable_init = strtoul(arg, &p, 0); else lazy_itable_init = 1; + } else if (!strcmp(token, "assume_storage_prezeroed")) { + if (arg) + assume_storage_prezeroed = strtoul(arg, &p, 0); + else + assume_storage_prezeroed = 1; } else if (!strcmp(token, "lazy_journal_init")) { if (arg) journal_flags |= strtoul(arg, &p, 0) ? @@ -1089,6 +1096,21 @@ static void parse_extended_opts(struct ext2_super_block *param, continue; } encoding_flags = arg; + } else if (!strcmp(token, "orphan_file_size")) { + if (!arg) { + r_usage++; + badopt = token; + continue; + } + orphan_file_blocks = parse_num_blocks2(arg, + fs_param.s_log_block_size); + if (orphan_file_blocks == 0) { + fprintf(stderr, + _("Invalid size of orphan file %s\n"), + arg); + r_usage++; + continue; + } } else { r_usage++; badopt = token; @@ -1115,7 +1137,8 @@ static void parse_extended_opts(struct ext2_super_block *param, "\tnodiscard\n" "\tencoding=<encoding>\n" "\tencoding_flags=<flags>\n" - "\tquotatype=<quota type(s) to be enabled>\n\n"), + "\tquotatype=<quota type(s) to be enabled>\n" + "\tassume_storage_prezeroed=<0 to disable, 1 to enable>\n\n"), badopt ? badopt : ""); free(buf); exit(1); @@ -1156,7 +1179,8 @@ static __u32 ok_features[3] = { EXT2_FEATURE_COMPAT_EXT_ATTR | EXT4_FEATURE_COMPAT_SPARSE_SUPER2 | EXT4_FEATURE_COMPAT_FAST_COMMIT | - EXT4_FEATURE_COMPAT_STABLE_INODES, + EXT4_FEATURE_COMPAT_STABLE_INODES | + EXT4_FEATURE_COMPAT_ORPHAN_FILE, /* Incompat */ EXT2_FEATURE_INCOMPAT_FILETYPE| EXT3_FEATURE_INCOMPAT_EXTENTS| @@ -1551,6 +1575,8 @@ static void PRS(int argc, char *argv[]) int lsector_size = 0, psector_size = 0; int show_version_only = 0, is_device = 0; unsigned long long num_inodes = 0; /* unsigned long long to catch too-large input */ + int default_orphan_file = 0; + int default_csum_seed = 0; errcode_t retval; char * oldpath = getenv("PATH"); char * extended_opts = 0; @@ -2103,8 +2129,24 @@ profile_error: ext2fs_clear_feature_ea_inode(&fs_param); ext2fs_clear_feature_casefold(&fs_param); } - edit_feature(fs_features ? fs_features : tmp, - &fs_param.s_feature_compat); + if (!fs_features && tmp) + edit_feature(tmp, &fs_param.s_feature_compat); + /* + * Now all the defaults are incorporated in fs_param. Check the state + * of orphan_file feature so that we know whether we should silently + * disabled in case journal gets disabled. + */ + if (ext2fs_has_feature_orphan_file(&fs_param)) + default_orphan_file = 1; + if (ext2fs_has_feature_csum_seed(&fs_param)) + default_csum_seed = 1; + if (fs_features) + edit_feature(fs_features, &fs_param.s_feature_compat); + /* Silently disable orphan_file if user chose fs without journal */ + if (default_orphan_file && !ext2fs_has_feature_journal(&fs_param)) + ext2fs_clear_feature_orphan_file(&fs_param); + if (default_csum_seed && !ext2fs_has_feature_metadata_csum(&fs_param)) + ext2fs_clear_feature_csum_seed(&fs_param); if (tmp) free(tmp); (void) ext2fs_free_mem(&fs_features); @@ -3097,6 +3139,18 @@ int main (int argc, char *argv[]) io_channel_set_options(fs->io, opt_string); } + if (assume_storage_prezeroed) { + if (verbose) + printf("%s", + _("Assuming the storage device is prezeroed " + "- skipping inode table and journal wipe\n")); + + lazy_itable_init = 1; + itable_zeroed = 1; + zero_hugefile = 0; + journal_flags |= EXT2_MKJOURNAL_LAZYINIT; + } + /* Can't undo discard ... */ if (!noaction && discard && dev_size && (io_ptr != undo_io_manager)) { retval = mke2fs_discard_device(fs); @@ -3431,6 +3485,9 @@ int main (int argc, char *argv[]) if (!jparams.num_journal_blocks) { ext2fs_clear_feature_journal(fs->super); + ext2fs_clear_feature_orphan_file(fs->super); + ext2fs_clear_feature_journal(&fs_param); + ext2fs_clear_feature_orphan_file(&fs_param); goto no_journal; } if (!quiet) { @@ -3473,6 +3530,23 @@ no_journal: fix_cluster_bg_counts(fs); if (ext2fs_has_feature_quota(&fs_param)) create_quota_inodes(fs); + if (ext2fs_has_feature_orphan_file(&fs_param)) { + if (!ext2fs_has_feature_journal(&fs_param)) { + com_err(program_name, 0, _("cannot set orphan_file " + "feature without a journal.")); + exit(1); + } + if (!orphan_file_blocks) { + orphan_file_blocks = + ext2fs_default_orphan_file_blocks(fs); + } + retval = ext2fs_create_orphan_file(fs, orphan_file_blocks); + if (retval) { + com_err(program_name, retval, + _("while creating orphan file")); + exit(1); + } + } retval = mk_hugefiles(fs, device_name); if (retval) |