2 * mke2fs.c - Make a ext2fs filesystem.
4 * Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
5 * 2003, 2004, 2005 by Theodore Ts'o.
8 * This file may be redistributed under the terms of the GNU Public
13 /* Usage: mke2fs [options] device
15 * The device may be a block device or a image of one, but this isn't
16 * enforced (but it's not much fun on a character device :-).
19 #define _XOPEN_SOURCE 600 /* for inclusion of PATH_MAX in Solaris */
28 #include <sys/utsname.h>
45 #include <sys/ioctl.h>
46 #include <sys/types.h>
50 #include <blkid/blkid.h>
52 #include "ext2fs/ext2_fs.h"
53 #include "ext2fs/ext2fsP.h"
54 #include "et/com_err.h"
55 #include "uuid/uuid.h"
57 #include "ext2fs/ext2fs.h"
61 #include "../version.h"
62 #include "nls-enable.h"
63 #include "quota/mkquota.h"
65 #define STRIDE_LENGTH 8
67 #define MAX_32_NUM ((((unsigned long long) 1) << 32) - 1)
73 #ifndef ROOT_SYSCONFDIR
74 #define ROOT_SYSCONFDIR "/etc"
77 #define DISCARD_STEP_MB (2048)
79 extern int isatty(int);
80 extern FILE *fpopen(const char *cmd, const char *mode);
82 static const char * program_name = "mke2fs";
83 static const char * device_name /* = NULL */;
85 /* Command line options */
89 static int super_only;
90 static int discard = 1; /* attempt to discard device before fs creation */
94 static uid_t root_uid;
95 static gid_t root_gid;
98 static int lazy_itable_init;
99 static char *bad_blocks_filename = NULL;
100 static __u32 fs_stride;
101 static int quotatype = -1; /* Initialize both user and group quotas by default */
103 static struct ext2_super_block fs_param;
104 static char *fs_uuid = NULL;
105 static char *creator_os;
106 static char *volume_label;
107 static char *mount_dir;
108 char *journal_device;
109 static int sync_kludge; /* Set using the MKE2FS_SYNC env. option */
110 static char **fs_types;
112 static profile_t profile;
114 static int sys_page_size = 4096;
115 static int linux_version_code = 0;
117 static void usage(void)
119 fprintf(stderr, _("Usage: %s [-c|-l filename] [-b block-size] "
120 "[-C cluster-size]\n\t[-i bytes-per-inode] [-I inode-size] "
121 "[-J journal-options]\n"
122 "\t[-G flex-group-size] [-N number-of-inodes]\n"
123 "\t[-m reserved-blocks-percentage] [-o creator-os]\n"
124 "\t[-g blocks-per-group] [-L volume-label] "
125 "[-M last-mounted-directory]\n\t[-O feature[,...]] "
126 "[-r fs-revision] [-E extended-option[,...]]\n"
127 "\t[-t fs-type] [-T usage-type ] [-U UUID] "
128 "[-jnqvDFKSV] device [blocks-count]\n"),
133 static int int_log2(unsigned long long arg)
145 static int int_log10(unsigned long long arg)
155 static int parse_version_number(const char *s)
157 int major, minor, rev;
163 major = strtol(cp, &endptr, 10);
164 if (cp == endptr || *endptr != '.')
167 minor = strtol(cp, &endptr, 10);
168 if (cp == endptr || *endptr != '.')
171 rev = strtol(cp, &endptr, 10);
174 return ((((major * 256) + minor) * 256) + rev);
179 * Helper function for read_bb_file and test_disk
181 static void invalid_block(ext2_filsys fs EXT2FS_ATTR((unused)), blk_t blk)
183 fprintf(stderr, _("Bad block %u out of range; ignored.\n"), blk);
188 * Reads the bad blocks list from a file
190 static void read_bb_file(ext2_filsys fs, badblocks_list *bb_list,
191 const char *bad_blocks_file)
196 f = fopen(bad_blocks_file, "r");
198 com_err("read_bad_blocks_file", errno,
199 _("while trying to open %s"), bad_blocks_file);
202 retval = ext2fs_read_bb_FILE(fs, f, bb_list, invalid_block);
205 com_err("ext2fs_read_bb_FILE", retval, "%s",
206 _("while reading in list of bad blocks from file"));
212 * Runs the badblocks program to test the disk
214 static void test_disk(ext2_filsys fs, badblocks_list *bb_list)
220 sprintf(buf, "badblocks -b %d -X %s%s%s %llu", fs->blocksize,
221 quiet ? "" : "-s ", (cflag > 1) ? "-w " : "",
222 fs->device_name, ext2fs_blocks_count(fs->super)-1);
224 printf(_("Running command: %s\n"), buf);
227 com_err("popen", errno,
228 _("while trying to run '%s'"), buf);
231 retval = ext2fs_read_bb_FILE(fs, f, bb_list, invalid_block);
234 com_err("ext2fs_read_bb_FILE", retval, "%s",
235 _("while processing list of bad blocks from program"));
240 static void handle_bad_blocks(ext2_filsys fs, badblocks_list bb_list)
244 unsigned must_be_good;
246 badblocks_iterate bb_iter;
256 * The primary superblock and group descriptors *must* be
257 * good; if not, abort.
259 must_be_good = fs->super->s_first_data_block + 1 + fs->desc_blocks;
260 for (i = fs->super->s_first_data_block; i <= must_be_good; i++) {
261 if (ext2fs_badblocks_list_test(bb_list, i)) {
262 fprintf(stderr, _("Block %d in primary "
263 "superblock/group descriptor area bad.\n"), i);
264 fprintf(stderr, _("Blocks %u through %u must be good "
265 "in order to build a filesystem.\n"),
266 fs->super->s_first_data_block, must_be_good);
267 fputs(_("Aborting....\n"), stderr);
273 * See if any of the bad blocks are showing up in the backup
274 * superblocks and/or group descriptors. If so, issue a
275 * warning and adjust the block counts appropriately.
277 group_block = fs->super->s_first_data_block +
278 fs->super->s_blocks_per_group;
280 for (i = 1; i < fs->group_desc_count; i++) {
282 for (j=0; j < fs->desc_blocks+1; j++) {
283 if (ext2fs_badblocks_list_test(bb_list,
287 _("Warning: the backup superblock/group descriptors at block %u contain\n"
291 group = ext2fs_group_of_blk2(fs, group_block+j);
292 ext2fs_bg_free_blocks_count_set(fs, group, ext2fs_bg_free_blocks_count(fs, group) + 1);
293 ext2fs_group_desc_csum_set(fs, group);
294 ext2fs_free_blocks_count_add(fs->super, 1);
297 group_block += fs->super->s_blocks_per_group;
301 * Mark all the bad blocks as used...
303 retval = ext2fs_badblocks_list_iterate_begin(bb_list, &bb_iter);
305 com_err("ext2fs_badblocks_list_iterate_begin", retval, "%s",
306 _("while marking bad blocks as used"));
309 while (ext2fs_badblocks_list_iterate(bb_iter, &blk))
310 ext2fs_mark_block_bitmap2(fs->block_map, EXT2FS_B2C(fs, blk));
311 ext2fs_badblocks_list_iterate_end(bb_iter);
314 static void write_inode_tables(ext2_filsys fs, int lazy_flag, int itable_zeroed)
320 struct ext2fs_numeric_progress_struct progress;
322 ext2fs_numeric_progress_init(fs, &progress,
323 _("Writing inode tables: "),
324 fs->group_desc_count);
326 for (i = 0; i < fs->group_desc_count; i++) {
327 ext2fs_numeric_progress_update(fs, &progress, i);
329 blk = ext2fs_inode_table_loc(fs, i);
330 num = fs->inode_blocks_per_group;
333 num = ext2fs_div_ceil((fs->super->s_inodes_per_group -
334 ext2fs_bg_itable_unused(fs, i)) *
335 EXT2_INODE_SIZE(fs->super),
336 EXT2_BLOCK_SIZE(fs->super));
337 if (!lazy_flag || itable_zeroed) {
338 /* The kernel doesn't need to zero the itable blocks */
339 ext2fs_bg_flags_set(fs, i, EXT2_BG_INODE_ZEROED);
340 ext2fs_group_desc_csum_set(fs, i);
342 retval = ext2fs_zero_blocks2(fs, blk, num, &blk, &num);
344 fprintf(stderr, _("\nCould not write %d "
345 "blocks in inode table starting at %llu: %s\n"),
346 num, blk, error_message(retval));
350 if (sync_kludge == 1)
352 else if ((i % sync_kludge) == 0)
356 ext2fs_zero_blocks2(0, 0, 0, 0, 0);
357 ext2fs_numeric_progress_close(fs, &progress,
361 static void create_root_dir(ext2_filsys fs)
364 struct ext2_inode inode;
366 retval = ext2fs_mkdir(fs, EXT2_ROOT_INO, EXT2_ROOT_INO, 0);
368 com_err("ext2fs_mkdir", retval, "%s",
369 _("while creating root dir"));
372 if (root_uid != 0 || root_gid != 0) {
373 retval = ext2fs_read_inode(fs, EXT2_ROOT_INO, &inode);
375 com_err("ext2fs_read_inode", retval, "%s",
376 _("while reading root inode"));
380 inode.i_uid = root_uid;
381 ext2fs_set_i_uid_high(inode, root_uid >> 16);
382 inode.i_gid = root_gid;
383 ext2fs_set_i_gid_high(inode, root_gid >> 16);
385 retval = ext2fs_write_new_inode(fs, EXT2_ROOT_INO, &inode);
387 com_err("ext2fs_write_inode", retval, "%s",
388 _("while setting root inode ownership"));
394 static void create_lost_and_found(ext2_filsys fs)
396 unsigned int lpf_size = 0;
399 const char *name = "lost+found";
403 retval = ext2fs_mkdir(fs, EXT2_ROOT_INO, 0, name);
405 com_err("ext2fs_mkdir", retval, "%s",
406 _("while creating /lost+found"));
410 retval = ext2fs_lookup(fs, EXT2_ROOT_INO, name, strlen(name), 0, &ino);
412 com_err("ext2_lookup", retval, "%s",
413 _("while looking up /lost+found"));
417 for (i=1; i < EXT2_NDIR_BLOCKS; i++) {
418 /* Ensure that lost+found is at least 2 blocks, so we always
419 * test large empty blocks for big-block filesystems. */
420 if ((lpf_size += fs->blocksize) >= 16*1024 &&
421 lpf_size >= 2 * fs->blocksize)
423 retval = ext2fs_expand_dir(fs, ino);
425 com_err("ext2fs_expand_dir", retval, "%s",
426 _("while expanding /lost+found"));
432 static void create_bad_block_inode(ext2_filsys fs, badblocks_list bb_list)
436 ext2fs_mark_inode_bitmap2(fs->inode_map, EXT2_BAD_INO);
437 ext2fs_inode_alloc_stats2(fs, EXT2_BAD_INO, +1, 0);
438 retval = ext2fs_update_bb_inode(fs, bb_list);
440 com_err("ext2fs_update_bb_inode", retval, "%s",
441 _("while setting bad block inode"));
447 static void reserve_inodes(ext2_filsys fs)
451 for (i = EXT2_ROOT_INO + 1; i < EXT2_FIRST_INODE(fs->super); i++)
452 ext2fs_inode_alloc_stats2(fs, i, +1, 0);
453 ext2fs_mark_ib_dirty(fs);
456 #define BSD_DISKMAGIC (0x82564557UL) /* The disk magic number */
457 #define BSD_MAGICDISK (0x57455682UL) /* The disk magic number reversed */
458 #define BSD_LABEL_OFFSET 64
460 static void zap_sector(ext2_filsys fs, int sect, int nsect)
466 buf = malloc(512*nsect);
468 printf(_("Out of memory erasing sectors %d-%d\n"),
469 sect, sect + nsect - 1);
474 /* Check for a BSD disklabel, and don't erase it if so */
475 retval = io_channel_read_blk64(fs->io, 0, -512, buf);
478 _("Warning: could not read block 0: %s\n"),
479 error_message(retval));
481 magic = (unsigned int *) (buf + BSD_LABEL_OFFSET);
482 if ((*magic == BSD_DISKMAGIC) ||
483 (*magic == BSD_MAGICDISK))
488 memset(buf, 0, 512*nsect);
489 io_channel_set_blksize(fs->io, 512);
490 retval = io_channel_write_blk64(fs->io, sect, -512*nsect, buf);
491 io_channel_set_blksize(fs->io, fs->blocksize);
494 fprintf(stderr, _("Warning: could not erase sector %d: %s\n"),
495 sect, error_message(retval));
498 static void create_journal_dev(ext2_filsys fs)
500 struct ext2fs_numeric_progress_struct progress;
503 blk64_t blk, err_blk;
504 int c, count, err_count;
506 retval = ext2fs_create_journal_superblock(fs,
507 ext2fs_blocks_count(fs->super), 0, &buf);
509 com_err("create_journal_dev", retval, "%s",
510 _("while initializing journal superblock"));
514 if (journal_flags & EXT2_MKJOURNAL_LAZYINIT)
515 goto write_superblock;
517 ext2fs_numeric_progress_init(fs, &progress,
518 _("Zeroing journal device: "),
519 ext2fs_blocks_count(fs->super));
521 count = ext2fs_blocks_count(fs->super);
527 retval = ext2fs_zero_blocks2(fs, blk, c, &err_blk, &err_count);
529 com_err("create_journal_dev", retval,
530 _("while zeroing journal device "
531 "(block %llu, count %d)"),
537 ext2fs_numeric_progress_update(fs, &progress, blk);
539 ext2fs_zero_blocks2(0, 0, 0, 0, 0);
541 ext2fs_numeric_progress_close(fs, &progress, NULL);
543 retval = io_channel_write_blk64(fs->io,
544 fs->super->s_first_data_block+1,
547 com_err("create_journal_dev", retval, "%s",
548 _("while writing journal superblock"));
553 static void show_stats(ext2_filsys fs)
555 struct ext2_super_block *s = fs->super;
562 if (ext2fs_blocks_count(&fs_param) != ext2fs_blocks_count(s))
563 fprintf(stderr, _("warning: %llu blocks unused.\n\n"),
564 ext2fs_blocks_count(&fs_param) - ext2fs_blocks_count(s));
566 memset(buf, 0, sizeof(buf));
567 strncpy(buf, s->s_volume_name, sizeof(s->s_volume_name));
568 printf(_("Filesystem label=%s\n"), buf);
569 os = e2p_os2string(fs->super->s_creator_os);
571 printf(_("OS type: %s\n"), os);
573 printf(_("Block size=%u (log=%u)\n"), fs->blocksize,
574 s->s_log_block_size);
575 if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
576 EXT4_FEATURE_RO_COMPAT_BIGALLOC))
577 printf(_("Cluster size=%u (log=%u)\n"),
578 fs->blocksize << fs->cluster_ratio_bits,
579 s->s_log_cluster_size);
581 printf(_("Fragment size=%u (log=%u)\n"), EXT2_CLUSTER_SIZE(s),
582 s->s_log_cluster_size);
583 printf(_("Stride=%u blocks, Stripe width=%u blocks\n"),
584 s->s_raid_stride, s->s_raid_stripe_width);
585 printf(_("%u inodes, %llu blocks\n"), s->s_inodes_count,
586 ext2fs_blocks_count(s));
587 printf(_("%llu blocks (%2.2f%%) reserved for the super user\n"),
588 ext2fs_r_blocks_count(s),
589 100.0 * ext2fs_r_blocks_count(s) / ext2fs_blocks_count(s));
590 printf(_("First data block=%u\n"), s->s_first_data_block);
591 if (root_uid != 0 || root_gid != 0)
592 printf(_("Root directory owner=%u:%u\n"), root_uid, root_gid);
593 if (s->s_reserved_gdt_blocks)
594 printf(_("Maximum filesystem blocks=%lu\n"),
595 (s->s_reserved_gdt_blocks + fs->desc_blocks) *
596 EXT2_DESC_PER_BLOCK(s) * s->s_blocks_per_group);
597 if (fs->group_desc_count > 1)
598 printf(_("%u block groups\n"), fs->group_desc_count);
600 printf(_("%u block group\n"), fs->group_desc_count);
601 if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
602 EXT4_FEATURE_RO_COMPAT_BIGALLOC))
603 printf(_("%u blocks per group, %u clusters per group\n"),
604 s->s_blocks_per_group, s->s_clusters_per_group);
606 printf(_("%u blocks per group, %u fragments per group\n"),
607 s->s_blocks_per_group, s->s_clusters_per_group);
608 printf(_("%u inodes per group\n"), s->s_inodes_per_group);
610 if (fs->group_desc_count == 1) {
615 printf("%s", _("Superblock backups stored on blocks: "));
616 group_block = s->s_first_data_block;
618 for (i = 1; i < fs->group_desc_count; i++) {
619 group_block += s->s_blocks_per_group;
620 if (!ext2fs_bg_has_super(fs, i))
624 need = int_log10(group_block) + 2;
625 if (need > col_left) {
630 printf("%llu", group_block);
636 * Set the S_CREATOR_OS field. Return true if OS is known,
639 static int set_os(struct ext2_super_block *sb, char *os)
642 sb->s_creator_os = atoi (os);
643 else if (strcasecmp(os, "linux") == 0)
644 sb->s_creator_os = EXT2_OS_LINUX;
645 else if (strcasecmp(os, "GNU") == 0 || strcasecmp(os, "hurd") == 0)
646 sb->s_creator_os = EXT2_OS_HURD;
647 else if (strcasecmp(os, "freebsd") == 0)
648 sb->s_creator_os = EXT2_OS_FREEBSD;
649 else if (strcasecmp(os, "lites") == 0)
650 sb->s_creator_os = EXT2_OS_LITES;
656 #define PATH_SET "PATH=/sbin"
658 static void parse_extended_opts(struct ext2_super_block *param,
661 char *buf, *token, *next, *p, *arg, *badopt = 0;
668 fprintf(stderr, "%s",
669 _("Couldn't allocate memory to parse options!\n"));
673 for (token = buf; token && *token; token = next) {
674 p = strchr(token, ',');
680 arg = strchr(token, '=');
685 if (strcmp(token, "desc-size") == 0 ||
686 strcmp(token, "desc_size") == 0) {
689 if (!(fs_param.s_feature_incompat &
690 EXT4_FEATURE_INCOMPAT_64BIT)) {
692 _("%s requires '-O 64bit'\n"), token);
696 if (param->s_reserved_gdt_blocks != 0) {
698 _("'%s' must be before 'resize=%u'\n"),
699 token, param->s_reserved_gdt_blocks);
708 desc_size = strtoul(arg, &p, 0);
709 if (*p || (desc_size & (desc_size - 1))) {
711 _("Invalid desc_size: '%s'\n"), arg);
715 param->s_desc_size = desc_size;
716 } else if (strcmp(token, "mmp_update_interval") == 0) {
722 param->s_mmp_update_interval = strtoul(arg, &p, 0);
725 _("Invalid mmp_update_interval: %s\n"),
730 } else if (strcmp(token, "stride") == 0) {
736 param->s_raid_stride = strtoul(arg, &p, 0);
739 _("Invalid stride parameter: %s\n"),
744 } else if (strcmp(token, "stripe-width") == 0 ||
745 strcmp(token, "stripe_width") == 0) {
751 param->s_raid_stripe_width = strtoul(arg, &p, 0);
754 _("Invalid stripe-width parameter: %s\n"),
759 } else if (!strcmp(token, "resize")) {
761 unsigned long bpg, rsv_groups;
762 unsigned long group_desc_count, desc_blocks;
763 unsigned int gdpb, blocksize;
772 resize = parse_num_blocks2(arg,
773 param->s_log_block_size);
777 _("Invalid resize parameter: %s\n"),
782 if (resize <= ext2fs_blocks_count(param)) {
783 fprintf(stderr, "%s",
784 _("The resize maximum must be greater "
785 "than the filesystem size.\n"));
790 blocksize = EXT2_BLOCK_SIZE(param);
791 bpg = param->s_blocks_per_group;
794 gdpb = EXT2_DESC_PER_BLOCK(param);
795 group_desc_count = (__u32) ext2fs_div64_ceil(
796 ext2fs_blocks_count(param), bpg);
797 desc_blocks = (group_desc_count +
799 rsv_groups = ext2fs_div64_ceil(resize, bpg);
800 rsv_gdb = ext2fs_div_ceil(rsv_groups, gdpb) -
802 if (rsv_gdb > (int) EXT2_ADDR_PER_BLOCK(param))
803 rsv_gdb = EXT2_ADDR_PER_BLOCK(param);
806 if (param->s_rev_level == EXT2_GOOD_OLD_REV) {
807 fprintf(stderr, "%s",
808 _("On-line resizing not supported with revision 0 filesystems\n"));
812 param->s_feature_compat |=
813 EXT2_FEATURE_COMPAT_RESIZE_INODE;
815 param->s_reserved_gdt_blocks = rsv_gdb;
817 } else if (!strcmp(token, "test_fs")) {
818 param->s_flags |= EXT2_FLAGS_TEST_FILESYS;
819 } else if (!strcmp(token, "lazy_itable_init")) {
821 lazy_itable_init = strtoul(arg, &p, 0);
823 lazy_itable_init = 1;
824 } else if (!strcmp(token, "lazy_journal_init")) {
826 journal_flags |= strtoul(arg, &p, 0) ?
827 EXT2_MKJOURNAL_LAZYINIT : 0;
829 journal_flags |= EXT2_MKJOURNAL_LAZYINIT;
830 } else if (!strcmp(token, "root_owner")) {
832 root_uid = strtoul(arg, &p, 0);
835 _("Invalid root_owner: '%s'\n"),
841 root_gid = strtoul(p, &p, 0);
844 _("Invalid root_owner: '%s'\n"),
853 } else if (!strcmp(token, "discard")) {
855 } else if (!strcmp(token, "nodiscard")) {
857 } else if (!strcmp(token, "quotatype")) {
863 if (!strncmp(arg, "usr", 3)) {
865 } else if (!strncmp(arg, "grp", 3)) {
869 _("Invalid quotatype parameter: %s\n"),
880 fprintf(stderr, _("\nBad option(s) specified: %s\n\n"
881 "Extended options are separated by commas, "
882 "and may take an argument which\n"
883 "\tis set off by an equals ('=') sign.\n\n"
884 "Valid extended options are:\n"
885 "\tstride=<RAID per-disk data chunk in blocks>\n"
886 "\tstripe-width=<RAID stride * data disks in blocks>\n"
887 "\tresize=<resize maximum size in blocks>\n"
888 "\tlazy_itable_init=<0 to disable, 1 to enable>\n"
889 "\tlazy_journal_init=<0 to disable, 1 to enable>\n"
890 "\troot_uid=<uid of root directory>\n"
891 "\troot_gid=<gid of root directory>\n"
895 "\tquotatype=<usr OR grp>\n\n"),
896 badopt ? badopt : "");
900 if (param->s_raid_stride &&
901 (param->s_raid_stripe_width % param->s_raid_stride) != 0)
902 fprintf(stderr, _("\nWarning: RAID stripe-width %u not an even "
903 "multiple of stride %u.\n\n"),
904 param->s_raid_stripe_width, param->s_raid_stride);
909 static __u32 ok_features[3] = {
911 EXT3_FEATURE_COMPAT_HAS_JOURNAL |
912 EXT2_FEATURE_COMPAT_RESIZE_INODE |
913 EXT2_FEATURE_COMPAT_DIR_INDEX |
914 EXT2_FEATURE_COMPAT_EXT_ATTR,
916 EXT2_FEATURE_INCOMPAT_FILETYPE|
917 EXT3_FEATURE_INCOMPAT_EXTENTS|
918 EXT3_FEATURE_INCOMPAT_JOURNAL_DEV|
919 EXT2_FEATURE_INCOMPAT_META_BG|
920 EXT4_FEATURE_INCOMPAT_FLEX_BG|
921 EXT4_FEATURE_INCOMPAT_MMP |
922 EXT4_FEATURE_INCOMPAT_64BIT,
924 EXT2_FEATURE_RO_COMPAT_LARGE_FILE|
925 EXT4_FEATURE_RO_COMPAT_HUGE_FILE|
926 EXT4_FEATURE_RO_COMPAT_DIR_NLINK|
927 EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE|
928 EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER|
929 EXT4_FEATURE_RO_COMPAT_GDT_CSUM|
930 EXT4_FEATURE_RO_COMPAT_BIGALLOC|
932 EXT4_FEATURE_RO_COMPAT_QUOTA|
938 static void syntax_err_report(const char *filename, long err, int line_num)
941 _("Syntax error in mke2fs config file (%s, line #%d)\n\t%s\n"),
942 filename, line_num, error_message(err));
946 static const char *config_fn[] = { ROOT_SYSCONFDIR "/mke2fs.conf", 0 };
948 static void edit_feature(const char *str, __u32 *compat_array)
953 if (e2p_edit_feature(str, compat_array, ok_features)) {
954 fprintf(stderr, _("Invalid filesystem option set: %s\n"),
960 static void edit_mntopts(const char *str, __u32 *mntopts)
965 if (e2p_edit_mntopts(str, mntopts, ~0)) {
966 fprintf(stderr, _("Invalid mount option set: %s\n"),
978 static errcode_t init_list(struct str_list *sl)
982 sl->list = malloc((sl->max+1) * sizeof(char *));
989 static errcode_t push_string(struct str_list *sl, const char *str)
993 if (sl->num >= sl->max) {
995 new_list = realloc(sl->list, (sl->max+1) * sizeof(char *));
1000 sl->list[sl->num] = malloc(strlen(str)+1);
1001 if (sl->list[sl->num] == 0)
1003 strcpy(sl->list[sl->num], str);
1005 sl->list[sl->num] = 0;
1009 static void print_str_list(char **list)
1013 for (cpp = list; *cpp; cpp++) {
1014 printf("'%s'", *cpp);
1016 fputs(", ", stdout);
1018 fputc('\n', stdout);
1022 * Return TRUE if the profile has the given subsection
1024 static int profile_has_subsection(profile_t prof, const char *section,
1025 const char *subsection)
1028 const char *names[4];
1033 names[1] = subsection;
1036 if (profile_iterator_create(prof, names,
1037 PROFILE_ITER_LIST_SECTION |
1038 PROFILE_ITER_RELATIONS_ONLY, &state))
1041 if ((profile_iterator(&state, &name, 0) == 0) && name) {
1046 profile_iterator_free(&state);
1050 static char **parse_fs_type(const char *fs_type,
1051 const char *usage_types,
1052 struct ext2_super_block *sb,
1053 blk64_t fs_blocks_count,
1056 const char *ext_type = 0;
1058 char *profile_type = 0;
1060 const char *size_type;
1061 struct str_list list;
1062 unsigned long long meg;
1065 if (init_list(&list))
1068 if (creator_os && (!strcasecmp(creator_os, "GNU") ||
1069 !strcasecmp(creator_os, "hurd")))
1076 else if (!strcmp(program_name, "mke3fs"))
1078 else if (!strcmp(program_name, "mke4fs"))
1080 else if (progname) {
1081 ext_type = strrchr(progname, '/');
1085 ext_type = progname;
1087 if (!strncmp(ext_type, "mkfs.", 5)) {
1089 if (ext_type[0] == 0)
1096 profile_get_string(profile, "defaults", "fs_type", 0,
1097 "ext2", &profile_type);
1098 ext_type = profile_type;
1099 if (!strcmp(ext_type, "ext2") && (journal_size != 0))
1104 if (!profile_has_subsection(profile, "fs_types", ext_type) &&
1105 strcmp(ext_type, "ext2")) {
1106 printf(_("\nYour mke2fs.conf file does not define the "
1107 "%s filesystem type.\n"), ext_type);
1108 if (!strcmp(ext_type, "ext3") || !strcmp(ext_type, "ext4") ||
1109 !strcmp(ext_type, "ext4dev")) {
1110 printf("%s", _("You probably need to install an "
1111 "updated mke2fs.conf file.\n\n"));
1114 printf("%s", _("Aborting...\n"));
1119 meg = (1024 * 1024) / EXT2_BLOCK_SIZE(sb);
1120 if (fs_blocks_count < 3 * meg)
1121 size_type = "floppy";
1122 else if (fs_blocks_count < 512 * meg)
1123 size_type = "small";
1124 else if (fs_blocks_count < 4 * 1024 * 1024 * meg)
1125 size_type = "default";
1126 else if (fs_blocks_count < 16 * 1024 * 1024 * meg)
1132 usage_types = size_type;
1134 parse_str = malloc(strlen(usage_types)+1);
1140 strcpy(parse_str, usage_types);
1143 push_string(&list, ext_type);
1146 t = strchr(cp, ',');
1151 if (profile_has_subsection(profile, "fs_types", cp))
1152 push_string(&list, cp);
1153 else if (strcmp(cp, "default") != 0)
1155 _("\nWarning: the fs_type %s is not "
1156 "defined in mke2fs.conf\n\n"),
1167 push_string(&list, "hurd");
1171 static char *get_string_from_profile(char **types, const char *opt,
1172 const char *def_val)
1177 for (i=0; types[i]; i++);
1178 for (i-=1; i >=0 ; i--) {
1179 profile_get_string(profile, "fs_types", types[i],
1184 profile_get_string(profile, "defaults", opt, 0, def_val, &ret);
1188 static int get_int_from_profile(char **types, const char *opt, int def_val)
1193 profile_get_integer(profile, "defaults", opt, 0, def_val, &ret);
1194 for (cpp = types; *cpp; cpp++)
1195 profile_get_integer(profile, "fs_types", *cpp, opt, ret, &ret);
1199 static double get_double_from_profile(char **types, const char *opt,
1205 profile_get_double(profile, "defaults", opt, 0, def_val, &ret);
1206 for (cpp = types; *cpp; cpp++)
1207 profile_get_double(profile, "fs_types", *cpp, opt, ret, &ret);
1211 static int get_bool_from_profile(char **types, const char *opt, int def_val)
1216 profile_get_boolean(profile, "defaults", opt, 0, def_val, &ret);
1217 for (cpp = types; *cpp; cpp++)
1218 profile_get_boolean(profile, "fs_types", *cpp, opt, ret, &ret);
1222 extern const char *mke2fs_default_profile;
1223 static const char *default_files[] = { "<default>", 0 };
1225 #ifdef HAVE_BLKID_PROBE_GET_TOPOLOGY
1227 * Sets the geometry of a device (stripe/stride), and returns the
1228 * device's alignment offset, if any, or a negative error.
1230 static int get_device_geometry(const char *file,
1231 struct ext2_super_block *fs_param,
1238 unsigned long min_io;
1239 unsigned long opt_io;
1240 struct stat statbuf;
1242 /* Nothing to do for a regular file */
1243 if (!stat(file, &statbuf) && S_ISREG(statbuf.st_mode))
1246 pr = blkid_new_probe_from_filename(file);
1250 tp = blkid_probe_get_topology(pr);
1254 min_io = blkid_topology_get_minimum_io_size(tp);
1255 opt_io = blkid_topology_get_optimal_io_size(tp);
1256 blocksize = EXT2_BLOCK_SIZE(fs_param);
1257 if ((min_io == 0) && (psector_size > blocksize))
1258 min_io = psector_size;
1259 if ((opt_io == 0) && min_io)
1261 if ((opt_io == 0) && (psector_size > blocksize))
1262 opt_io = psector_size;
1264 /* setting stripe/stride to blocksize is pointless */
1265 if (min_io > blocksize)
1266 fs_param->s_raid_stride = min_io / blocksize;
1267 if (opt_io > blocksize)
1268 fs_param->s_raid_stripe_width = opt_io / blocksize;
1270 rc = blkid_topology_get_alignment_offset(tp);
1272 blkid_free_probe(pr);
1277 static void PRS(int argc, char *argv[])
1280 int cluster_size = 0;
1283 int inode_ratio = 0;
1285 unsigned long flex_bg_size = 0;
1286 double reserved_ratio = -1.0;
1287 int lsector_size = 0, psector_size = 0;
1288 int show_version_only = 0;
1289 unsigned long long num_inodes = 0; /* unsigned long long to catch too-large input */
1291 char * oldpath = getenv("PATH");
1292 char * extended_opts = 0;
1294 char * usage_types = 0;
1297 * NOTE: A few words about fs_blocks_count and blocksize:
1299 * Initially, blocksize is set to zero, which implies 1024.
1300 * If -b is specified, blocksize is updated to the user's value.
1302 * Next, the device size or the user's "blocks" command line argument
1303 * is used to set fs_blocks_count; the units are blocksize.
1305 * Later, if blocksize hasn't been set and the profile specifies a
1306 * blocksize, then blocksize is updated and fs_blocks_count is scaled
1307 * appropriately. Note the change in units!
1309 * Finally, we complain about fs_blocks_count > 2^32 on a non-64bit fs.
1311 blk64_t fs_blocks_count = 0;
1316 int s_opt = -1, r_opt = -1;
1317 char *fs_features = 0;
1320 int pathlen = sizeof(PATH_SET) + 1;
1323 pathlen += strlen(oldpath);
1324 newpath = malloc(pathlen);
1326 fprintf(stderr, "%s",
1327 _("Couldn't allocate memory for new PATH.\n"));
1330 strcpy(newpath, PATH_SET);
1332 /* Update our PATH to include /sbin */
1334 strcat (newpath, ":");
1335 strcat (newpath, oldpath);
1339 tmp = getenv("MKE2FS_SYNC");
1341 sync_kludge = atoi(tmp);
1343 /* Determine the system page size if possible */
1345 #if (!defined(_SC_PAGESIZE) && defined(_SC_PAGE_SIZE))
1346 #define _SC_PAGESIZE _SC_PAGE_SIZE
1349 sysval = sysconf(_SC_PAGESIZE);
1351 sys_page_size = sysval;
1352 #endif /* _SC_PAGESIZE */
1353 #endif /* HAVE_SYSCONF */
1355 if ((tmp = getenv("MKE2FS_CONFIG")) != NULL)
1357 profile_set_syntax_err_cb(syntax_err_report);
1358 retval = profile_init(config_fn, &profile);
1359 if (retval == ENOENT) {
1360 retval = profile_init(default_files, &profile);
1363 retval = profile_set_default(profile, mke2fs_default_profile);
1366 } else if (retval) {
1368 fprintf(stderr, _("Couldn't init profile successfully"
1369 " (error: %ld).\n"), retval);
1373 setbuf(stdout, NULL);
1374 setbuf(stderr, NULL);
1375 add_error_table(&et_ext2_error_table);
1376 add_error_table(&et_prof_error_table);
1377 memset(&fs_param, 0, sizeof(struct ext2_super_block));
1378 fs_param.s_rev_level = 1; /* Create revision 1 filesystems now */
1385 linux_version_code = parse_version_number(ut.release);
1386 if (linux_version_code && linux_version_code < (2*65536 + 2*256))
1387 fs_param.s_rev_level = 0;
1390 if (argc && *argv) {
1391 program_name = get_progname(*argv);
1393 /* If called as mkfs.ext3, create a journal inode */
1394 if (!strcmp(program_name, "mkfs.ext3") ||
1395 !strcmp(program_name, "mke3fs"))
1399 while ((c = getopt (argc, argv,
1400 "b:cg:i:jl:m:no:qr:s:t:vC:DE:FG:I:J:KL:M:N:O:R:ST:U:V")) != EOF) {
1403 blocksize = parse_num_blocks2(optarg, -1);
1404 b = (blocksize > 0) ? blocksize : -blocksize;
1405 if (b < EXT2_MIN_BLOCK_SIZE ||
1406 b > EXT2_MAX_BLOCK_SIZE) {
1407 com_err(program_name, 0,
1408 _("invalid block size - %s"), optarg);
1411 if (blocksize > 4096)
1412 fprintf(stderr, _("Warning: blocksize %d not "
1413 "usable on most systems.\n"),
1416 fs_param.s_log_block_size =
1417 int_log2(blocksize >>
1418 EXT2_MIN_BLOCK_LOG_SIZE);
1420 case 'c': /* Check for bad blocks */
1424 cluster_size = parse_num_blocks2(optarg, -1);
1425 if (cluster_size <= EXT2_MIN_CLUSTER_SIZE ||
1426 cluster_size > EXT2_MAX_CLUSTER_SIZE) {
1427 com_err(program_name, 0,
1428 _("invalid cluster size - %s"),
1437 com_err(program_name, 0, "%s",
1438 _("'-R' is deprecated, use '-E' instead"));
1441 extended_opts = optarg;
1447 fs_param.s_blocks_per_group = strtoul(optarg, &tmp, 0);
1449 com_err(program_name, 0, "%s",
1450 _("Illegal number for blocks per group"));
1453 if ((fs_param.s_blocks_per_group % 8) != 0) {
1454 com_err(program_name, 0, "%s",
1455 _("blocks per group must be multiple of 8"));
1460 flex_bg_size = strtoul(optarg, &tmp, 0);
1462 com_err(program_name, 0, "%s",
1463 _("Illegal number for flex_bg size"));
1466 if (flex_bg_size < 1 ||
1467 (flex_bg_size & (flex_bg_size-1)) != 0) {
1468 com_err(program_name, 0, "%s",
1469 _("flex_bg size must be a power of 2"));
1474 inode_ratio = strtoul(optarg, &tmp, 0);
1475 if (inode_ratio < EXT2_MIN_BLOCK_SIZE ||
1476 inode_ratio > EXT2_MAX_BLOCK_SIZE * 1024 ||
1478 com_err(program_name, 0,
1479 _("invalid inode ratio %s (min %d/max %d)"),
1480 optarg, EXT2_MIN_BLOCK_SIZE,
1481 EXT2_MAX_BLOCK_SIZE * 1024);
1486 inode_size = strtoul(optarg, &tmp, 0);
1488 com_err(program_name, 0,
1489 _("invalid inode size - %s"), optarg);
1498 parse_journal_opts(optarg);
1501 fprintf(stderr, "%s",
1502 _("Warning: -K option is deprecated and "
1503 "should not be used anymore. Use "
1504 "\'-E nodiscard\' extended option "
1509 bad_blocks_filename = realloc(bad_blocks_filename,
1510 strlen(optarg) + 1);
1511 if (!bad_blocks_filename) {
1512 com_err(program_name, ENOMEM, "%s",
1513 _("in malloc for bad_blocks_filename"));
1516 strcpy(bad_blocks_filename, optarg);
1519 volume_label = optarg;
1522 reserved_ratio = strtod(optarg, &tmp);
1523 if ( *tmp || reserved_ratio > 50 ||
1524 reserved_ratio < 0) {
1525 com_err(program_name, 0,
1526 _("invalid reserved blocks percent - %s"),
1538 num_inodes = strtoul(optarg, &tmp, 0);
1540 com_err(program_name, 0,
1541 _("bad num inodes - %s"), optarg);
1546 creator_os = optarg;
1549 fs_features = optarg;
1555 r_opt = strtoul(optarg, &tmp, 0);
1557 com_err(program_name, 0,
1558 _("bad revision level - %s"), optarg);
1561 fs_param.s_rev_level = r_opt;
1563 case 's': /* deprecated */
1564 s_opt = atoi(optarg);
1571 com_err(program_name, 0, "%s",
1572 _("The -t option may only be used once"));
1575 fs_type = strdup(optarg);
1579 com_err(program_name, 0, "%s",
1580 _("The -T option may only be used once"));
1583 usage_types = strdup(optarg);
1592 /* Print version number and exit */
1593 show_version_only++;
1599 if ((optind == argc) && !show_version_only)
1601 device_name = argv[optind++];
1603 if (!quiet || show_version_only)
1604 fprintf (stderr, "mke2fs %s (%s)\n", E2FSPROGS_VERSION,
1607 if (show_version_only) {
1608 fprintf(stderr, _("\tUsing %s\n"),
1609 error_message(EXT2_ET_BASE));
1614 * If there's no blocksize specified and there is a journal
1615 * device, use it to figure out the blocksize
1617 if (blocksize <= 0 && journal_device) {
1621 #ifdef CONFIG_TESTIO_DEBUG
1622 if (getenv("TEST_IO_FLAGS") || getenv("TEST_IO_BLOCK")) {
1623 io_ptr = test_io_manager;
1624 test_io_backing_manager = unix_io_manager;
1627 io_ptr = unix_io_manager;
1628 retval = ext2fs_open(journal_device,
1629 EXT2_FLAG_JOURNAL_DEV_OK, 0,
1632 com_err(program_name, retval,
1633 _("while trying to open journal device %s\n"),
1637 if ((blocksize < 0) && (jfs->blocksize < (unsigned) (-blocksize))) {
1638 com_err(program_name, 0,
1639 _("Journal dev blocksize (%d) smaller than "
1640 "minimum blocksize %d\n"), jfs->blocksize,
1644 blocksize = jfs->blocksize;
1645 printf(_("Using journal device's blocksize: %d\n"), blocksize);
1646 fs_param.s_log_block_size =
1647 int_log2(blocksize >> EXT2_MIN_BLOCK_LOG_SIZE);
1651 if (optind < argc) {
1652 fs_blocks_count = parse_num_blocks2(argv[optind++],
1653 fs_param.s_log_block_size);
1654 if (!fs_blocks_count) {
1655 com_err(program_name, 0,
1656 _("invalid blocks '%s' on device '%s'"),
1657 argv[optind - 1], device_name);
1665 check_plausibility(device_name);
1666 check_mount(device_name, force, _("filesystem"));
1668 /* Determine the size of the device (if possible) */
1669 if (noaction && fs_blocks_count) {
1670 dev_size = fs_blocks_count;
1673 retval = ext2fs_get_device_size2(device_name,
1674 EXT2_BLOCK_SIZE(&fs_param),
1677 if (retval && (retval != EXT2_ET_UNIMPLEMENTED)) {
1678 com_err(program_name, retval, "%s",
1679 _("while trying to determine filesystem size"));
1682 if (!fs_blocks_count) {
1683 if (retval == EXT2_ET_UNIMPLEMENTED) {
1684 com_err(program_name, 0, "%s",
1685 _("Couldn't determine device size; you "
1686 "must specify\nthe size of the "
1690 if (dev_size == 0) {
1691 com_err(program_name, 0, "%s",
1692 _("Device size reported to be zero. "
1693 "Invalid partition specified, or\n\t"
1694 "partition table wasn't reread "
1695 "after running fdisk, due to\n\t"
1696 "a modified partition being busy "
1697 "and in use. You may need to reboot\n\t"
1698 "to re-read your partition table.\n"
1702 fs_blocks_count = dev_size;
1703 if (sys_page_size > EXT2_BLOCK_SIZE(&fs_param))
1704 fs_blocks_count &= ~((blk64_t) ((sys_page_size /
1705 EXT2_BLOCK_SIZE(&fs_param))-1));
1707 } else if (!force && (fs_blocks_count > dev_size)) {
1708 com_err(program_name, 0, "%s",
1709 _("Filesystem larger than apparent device size."));
1714 profile_get_string(profile, "devices", device_name,
1715 "fs_type", 0, &fs_type);
1717 profile_get_string(profile, "devices", device_name,
1718 "usage_types", 0, &usage_types);
1721 * We have the file system (or device) size, so we can now
1722 * determine the appropriate file system types so the fs can
1723 * be appropriately configured.
1725 fs_types = parse_fs_type(fs_type, usage_types, &fs_param,
1726 fs_blocks_count ? fs_blocks_count : dev_size,
1729 fprintf(stderr, "%s", _("Failed to parse fs types list\n"));
1733 /* Figure out what features should be enabled */
1736 if (fs_param.s_rev_level != EXT2_GOOD_OLD_REV) {
1737 tmp = get_string_from_profile(fs_types, "base_features",
1738 "sparse_super,filetype,resize_inode,dir_index");
1739 edit_feature(tmp, &fs_param.s_feature_compat);
1742 /* And which mount options as well */
1743 tmp = get_string_from_profile(fs_types, "default_mntopts",
1745 edit_mntopts(tmp, &fs_param.s_default_mount_opts);
1749 for (cpp = fs_types; *cpp; cpp++) {
1751 profile_get_string(profile, "fs_types", *cpp,
1752 "features", "", &tmp);
1754 edit_feature(tmp, &fs_param.s_feature_compat);
1758 tmp = get_string_from_profile(fs_types, "default_features",
1761 edit_feature(fs_features ? fs_features : tmp,
1762 &fs_param.s_feature_compat);
1766 /* Get the hardware sector sizes, if available */
1767 retval = ext2fs_get_device_sectsize(device_name, &lsector_size);
1769 com_err(program_name, retval, "%s",
1770 _("while trying to determine hardware sector size"));
1773 retval = ext2fs_get_device_phys_sectsize(device_name, &psector_size);
1775 com_err(program_name, retval, "%s",
1776 _("while trying to determine physical sector size"));
1780 tmp = getenv("MKE2FS_DEVICE_SECTSIZE");
1782 lsector_size = atoi(tmp);
1783 tmp = getenv("MKE2FS_DEVICE_PHYS_SECTSIZE");
1785 psector_size = atoi(tmp);
1787 /* Older kernels may not have physical/logical distinction */
1789 psector_size = lsector_size;
1791 if (blocksize <= 0) {
1792 use_bsize = get_int_from_profile(fs_types, "blocksize", 4096);
1794 if (use_bsize == -1) {
1795 use_bsize = sys_page_size;
1796 if ((linux_version_code < (2*65536 + 6*256)) &&
1800 if (lsector_size && use_bsize < lsector_size)
1801 use_bsize = lsector_size;
1802 if ((blocksize < 0) && (use_bsize < (-blocksize)))
1803 use_bsize = -blocksize;
1804 blocksize = use_bsize;
1805 fs_blocks_count /= (blocksize / 1024);
1807 if (blocksize < lsector_size) { /* Impossible */
1808 com_err(program_name, EINVAL, "%s",
1809 _("while setting blocksize; too small "
1812 } else if ((blocksize < psector_size) &&
1813 (psector_size <= sys_page_size)) { /* Suboptimal */
1814 fprintf(stderr, _("Warning: specified blocksize %d is "
1815 "less than device physical sectorsize %d\n"),
1816 blocksize, psector_size);
1820 fs_param.s_log_block_size =
1821 int_log2(blocksize >> EXT2_MIN_BLOCK_LOG_SIZE);
1824 * We now need to do a sanity check of fs_blocks_count for
1825 * 32-bit vs 64-bit block number support.
1827 if ((fs_blocks_count > MAX_32_NUM) &&
1828 !(fs_param.s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT) &&
1829 get_bool_from_profile(fs_types, "auto_64-bit_support", 0)) {
1830 fs_param.s_feature_incompat |= EXT4_FEATURE_INCOMPAT_64BIT;
1831 fs_param.s_feature_compat &= ~EXT2_FEATURE_COMPAT_RESIZE_INODE;
1833 if ((fs_blocks_count > MAX_32_NUM) &&
1834 !(fs_param.s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT)) {
1835 fprintf(stderr, _("%s: Size of device (0x%llx blocks) %s "
1836 "too big to be expressed\n\t"
1837 "in 32 bits using a blocksize of %d.\n"),
1838 program_name, fs_blocks_count, device_name,
1839 EXT2_BLOCK_SIZE(&fs_param));
1843 ext2fs_blocks_count_set(&fs_param, fs_blocks_count);
1845 if (fs_param.s_feature_incompat & EXT3_FEATURE_INCOMPAT_JOURNAL_DEV) {
1846 fs_types[0] = strdup("journal");
1851 fputs(_("fs_types for mke2fs.conf resolution: "), stdout);
1852 print_str_list(fs_types);
1855 if (r_opt == EXT2_GOOD_OLD_REV &&
1856 (fs_param.s_feature_compat || fs_param.s_feature_incompat ||
1857 fs_param.s_feature_ro_compat)) {
1858 fprintf(stderr, "%s", _("Filesystem features not supported "
1859 "with revision 0 filesystems\n"));
1864 if (r_opt == EXT2_GOOD_OLD_REV) {
1865 fprintf(stderr, "%s",
1866 _("Sparse superblocks not supported "
1867 "with revision 0 filesystems\n"));
1870 fs_param.s_feature_ro_compat |=
1871 EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER;
1872 } else if (s_opt == 0)
1873 fs_param.s_feature_ro_compat &=
1874 ~EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER;
1876 if (journal_size != 0) {
1877 if (r_opt == EXT2_GOOD_OLD_REV) {
1878 fprintf(stderr, "%s", _("Journals not supported with "
1879 "revision 0 filesystems\n"));
1882 fs_param.s_feature_compat |=
1883 EXT3_FEATURE_COMPAT_HAS_JOURNAL;
1886 /* Get reserved_ratio from profile if not specified on cmd line. */
1887 if (reserved_ratio < 0.0) {
1888 reserved_ratio = get_double_from_profile(
1889 fs_types, "reserved_ratio", 5.0);
1890 if (reserved_ratio > 50 || reserved_ratio < 0) {
1891 com_err(program_name, 0,
1892 _("invalid reserved blocks percent - %lf"),
1898 if (fs_param.s_feature_incompat &
1899 EXT3_FEATURE_INCOMPAT_JOURNAL_DEV) {
1901 fs_param.s_feature_incompat = EXT3_FEATURE_INCOMPAT_JOURNAL_DEV;
1902 fs_param.s_feature_compat = 0;
1903 fs_param.s_feature_ro_compat = 0;
1906 /* Check the user's mkfs options for 64bit */
1907 if ((fs_param.s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT) &&
1908 !(fs_param.s_feature_incompat & EXT3_FEATURE_INCOMPAT_EXTENTS)) {
1909 printf("%s", _("Extents MUST be enabled for a 64-bit "
1910 "filesystem. Pass -O extents to rectify.\n"));
1914 /* Set first meta blockgroup via an environment variable */
1915 /* (this is mostly for debugging purposes) */
1916 if ((fs_param.s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG) &&
1917 ((tmp = getenv("MKE2FS_FIRST_META_BG"))))
1918 fs_param.s_first_meta_bg = atoi(tmp);
1919 if (fs_param.s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_BIGALLOC) {
1921 cluster_size = get_int_from_profile(fs_types,
1924 fs_param.s_log_cluster_size =
1925 int_log2(cluster_size >> EXT2_MIN_CLUSTER_LOG_SIZE);
1926 if (fs_param.s_log_cluster_size &&
1927 fs_param.s_log_cluster_size < fs_param.s_log_block_size) {
1928 com_err(program_name, 0, "%s",
1929 _("The cluster size may not be "
1930 "smaller than the block size.\n"));
1933 } else if (cluster_size) {
1934 com_err(program_name, 0, "%s",
1935 _("specifying a cluster size requires the "
1936 "bigalloc feature"));
1939 fs_param.s_log_cluster_size = fs_param.s_log_block_size;
1941 if (inode_ratio == 0) {
1942 inode_ratio = get_int_from_profile(fs_types, "inode_ratio",
1944 if (inode_ratio < blocksize)
1945 inode_ratio = blocksize;
1946 if (inode_ratio < EXT2_CLUSTER_SIZE(&fs_param))
1947 inode_ratio = EXT2_CLUSTER_SIZE(&fs_param);
1950 #ifdef HAVE_BLKID_PROBE_GET_TOPOLOGY
1951 retval = get_device_geometry(device_name, &fs_param, psector_size);
1954 _("warning: Unable to get device geometry for %s\n"),
1956 } else if (retval) {
1957 printf(_("%s alignment is offset by %lu bytes.\n"),
1958 device_name, retval);
1959 printf(_("This may result in very poor performance, "
1960 "(re)-partitioning suggested.\n"));
1964 blocksize = EXT2_BLOCK_SIZE(&fs_param);
1967 * Initialize s_desc_size so that the parse_extended_opts()
1968 * can correctly handle "-E resize=NNN" if the 64-bit option
1971 if (fs_param.s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT)
1972 fs_param.s_desc_size = EXT2_MIN_DESC_SIZE_64BIT;
1974 /* This check should happen beyond the last assignment to blocksize */
1975 if (blocksize > sys_page_size) {
1977 com_err(program_name, 0,
1978 _("%d-byte blocks too big for system (max %d)"),
1979 blocksize, sys_page_size);
1982 fprintf(stderr, _("Warning: %d-byte blocks too big for system "
1983 "(max %d), forced to continue\n"),
1984 blocksize, sys_page_size);
1987 lazy_itable_init = 0;
1988 if (access("/sys/fs/ext4/features/lazy_itable_init", R_OK) == 0)
1989 lazy_itable_init = 1;
1991 lazy_itable_init = get_bool_from_profile(fs_types,
1994 discard = get_bool_from_profile(fs_types, "discard" , discard);
1995 journal_flags |= get_bool_from_profile(fs_types,
1996 "lazy_journal_init", 0) ?
1997 EXT2_MKJOURNAL_LAZYINIT : 0;
1998 journal_flags |= EXT2_MKJOURNAL_NO_MNT_CHECK;
2000 /* Get options from profile */
2001 for (cpp = fs_types; *cpp; cpp++) {
2003 profile_get_string(profile, "fs_types", *cpp, "options", "", &tmp);
2005 parse_extended_opts(&fs_param, tmp);
2010 parse_extended_opts(&fs_param, extended_opts);
2012 /* Can't support bigalloc feature without extents feature */
2013 if ((fs_param.s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_BIGALLOC) &&
2014 !(fs_param.s_feature_incompat & EXT3_FEATURE_INCOMPAT_EXTENTS)) {
2015 com_err(program_name, 0, "%s",
2016 _("Can't support bigalloc feature without "
2017 "extents feature"));
2021 if ((fs_param.s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG) &&
2022 (fs_param.s_feature_compat & EXT2_FEATURE_COMPAT_RESIZE_INODE)) {
2023 fprintf(stderr, "%s", _("The resize_inode and meta_bg "
2024 "features are not compatible.\n"
2025 "They can not be both enabled "
2026 "simultaneously.\n"));
2031 (fs_param.s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_BIGALLOC))
2032 fprintf(stderr, "%s", _("\nWarning: the bigalloc feature is "
2033 "still under development\n"
2034 "See https://ext4.wiki.kernel.org/"
2035 "index.php/Bigalloc for more information\n\n"));
2038 (fs_param.s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_QUOTA))
2039 fprintf(stderr, "%s", _("\nWarning: the quota feature is "
2040 "still under development\n"
2041 "See https://ext4.wiki.kernel.org/"
2042 "index.php/Quota for more information\n\n"));
2044 /* Since sparse_super is the default, we would only have a problem
2045 * here if it was explicitly disabled.
2047 if ((fs_param.s_feature_compat & EXT2_FEATURE_COMPAT_RESIZE_INODE) &&
2048 !(fs_param.s_feature_ro_compat&EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER)) {
2049 com_err(program_name, 0, "%s",
2050 _("reserved online resize blocks not supported "
2051 "on non-sparse filesystem"));
2055 if (fs_param.s_blocks_per_group) {
2056 if (fs_param.s_blocks_per_group < 256 ||
2057 fs_param.s_blocks_per_group > 8 * (unsigned) blocksize) {
2058 com_err(program_name, 0, "%s",
2059 _("blocks per group count out of range"));
2065 * If the bigalloc feature is enabled, then the -g option will
2066 * specify the number of clusters per group.
2068 if (fs_param.s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_BIGALLOC) {
2069 fs_param.s_clusters_per_group = fs_param.s_blocks_per_group;
2070 fs_param.s_blocks_per_group = 0;
2073 if (inode_size == 0)
2074 inode_size = get_int_from_profile(fs_types, "inode_size", 0);
2075 if (!flex_bg_size && (fs_param.s_feature_incompat &
2076 EXT4_FEATURE_INCOMPAT_FLEX_BG))
2077 flex_bg_size = get_int_from_profile(fs_types,
2078 "flex_bg_size", 16);
2080 if (!(fs_param.s_feature_incompat &
2081 EXT4_FEATURE_INCOMPAT_FLEX_BG)) {
2082 com_err(program_name, 0, "%s",
2083 _("Flex_bg feature not enabled, so "
2084 "flex_bg size may not be specified"));
2087 fs_param.s_log_groups_per_flex = int_log2(flex_bg_size);
2090 if (inode_size && fs_param.s_rev_level >= EXT2_DYNAMIC_REV) {
2091 if (inode_size < EXT2_GOOD_OLD_INODE_SIZE ||
2092 inode_size > EXT2_BLOCK_SIZE(&fs_param) ||
2093 inode_size & (inode_size - 1)) {
2094 com_err(program_name, 0,
2095 _("invalid inode size %d (min %d/max %d)"),
2096 inode_size, EXT2_GOOD_OLD_INODE_SIZE,
2100 fs_param.s_inode_size = inode_size;
2103 /* Make sure number of inodes specified will fit in 32 bits */
2104 if (num_inodes == 0) {
2105 unsigned long long n;
2106 n = ext2fs_blocks_count(&fs_param) * blocksize / inode_ratio;
2107 if (n > MAX_32_NUM) {
2108 if (fs_param.s_feature_incompat &
2109 EXT4_FEATURE_INCOMPAT_64BIT)
2110 num_inodes = MAX_32_NUM;
2112 com_err(program_name, 0,
2113 _("too many inodes (%llu), raise "
2114 "inode ratio?"), n);
2118 } else if (num_inodes > MAX_32_NUM) {
2119 com_err(program_name, 0,
2120 _("too many inodes (%llu), specify < 2^32 inodes"),
2125 * Calculate number of inodes based on the inode ratio
2127 fs_param.s_inodes_count = num_inodes ? num_inodes :
2128 (ext2fs_blocks_count(&fs_param) * blocksize) / inode_ratio;
2130 if ((((unsigned long long)fs_param.s_inodes_count) *
2131 (inode_size ? inode_size : EXT2_GOOD_OLD_INODE_SIZE)) >=
2132 ((ext2fs_blocks_count(&fs_param)) *
2133 EXT2_BLOCK_SIZE(&fs_param))) {
2134 com_err(program_name, 0, _("inode_size (%u) * inodes_count "
2135 "(%u) too big for a\n\t"
2136 "filesystem with %llu blocks, "
2137 "specify higher inode_ratio (-i)\n\t"
2138 "or lower inode count (-N).\n"),
2139 inode_size ? inode_size : EXT2_GOOD_OLD_INODE_SIZE,
2140 fs_param.s_inodes_count,
2141 (unsigned long long) ext2fs_blocks_count(&fs_param));
2146 * Calculate number of blocks to reserve
2148 ext2fs_r_blocks_count_set(&fs_param, reserved_ratio *
2149 ext2fs_blocks_count(&fs_param) / 100.0);
2155 static int should_do_undo(const char *name)
2160 struct ext2_super_block super;
2161 io_manager manager = unix_io_manager;
2162 int csum_flag, force_undo;
2164 csum_flag = EXT2_HAS_RO_COMPAT_FEATURE(&fs_param,
2165 EXT4_FEATURE_RO_COMPAT_GDT_CSUM);
2166 force_undo = get_int_from_profile(fs_types, "force_undo", 0);
2167 if (!force_undo && (!csum_flag || !lazy_itable_init))
2170 retval = manager->open(name, IO_FLAG_EXCLUSIVE, &channel);
2173 * We don't handle error cases instead we
2174 * declare that the file system doesn't exist
2175 * and let the rest of mke2fs take care of
2182 io_channel_set_blksize(channel, SUPERBLOCK_OFFSET);
2183 retval = io_channel_read_blk64(channel, 1, -SUPERBLOCK_SIZE, &super);
2189 #if defined(WORDS_BIGENDIAN)
2190 s_magic = ext2fs_swab16(super.s_magic);
2192 s_magic = super.s_magic;
2195 if (s_magic == EXT2_SUPER_MAGIC)
2199 io_channel_close(channel);
2206 static int mke2fs_setup_tdb(const char *name, io_manager *io_ptr)
2208 errcode_t retval = ENOMEM;
2209 char *tdb_dir = NULL, *tdb_file = NULL;
2210 char *dev_name, *tmp_name;
2211 int free_tdb_dir = 0;
2214 * Configuration via a conf file would be
2217 tdb_dir = getenv("E2FSPROGS_UNDO_DIR");
2219 profile_get_string(profile, "defaults",
2220 "undo_dir", 0, "/var/lib/e2fsprogs",
2225 if (!strcmp(tdb_dir, "none") || (tdb_dir[0] == 0) ||
2226 access(tdb_dir, W_OK)) {
2232 tmp_name = strdup(name);
2235 dev_name = basename(tmp_name);
2236 tdb_file = malloc(strlen(tdb_dir) + 8 + strlen(dev_name) + 7 + 1);
2241 sprintf(tdb_file, "%s/mke2fs-%s.e2undo", tdb_dir, dev_name);
2244 if (!access(tdb_file, F_OK)) {
2245 if (unlink(tdb_file) < 0) {
2251 set_undo_io_backing_manager(*io_ptr);
2252 *io_ptr = undo_io_manager;
2253 retval = set_undo_io_backup_file(tdb_file);
2256 printf(_("Overwriting existing filesystem; this can be undone "
2257 "using the command:\n"
2258 " e2undo %s %s\n\n"), tdb_file, name);
2269 com_err(program_name, retval, "%s",
2270 _("while trying to setup undo file\n"));
2274 static int mke2fs_discard_device(ext2_filsys fs)
2276 struct ext2fs_numeric_progress_struct progress;
2277 blk64_t blocks = ext2fs_blocks_count(fs->super);
2278 blk64_t count = DISCARD_STEP_MB;
2283 * Let's try if discard really works on the device, so
2284 * we do not print numeric progress resulting in failure
2287 retval = io_channel_discard(fs->io, 0, fs->blocksize);
2290 cur = fs->blocksize;
2292 count *= (1024 * 1024);
2293 count /= fs->blocksize;
2295 ext2fs_numeric_progress_init(fs, &progress,
2296 _("Discarding device blocks: "),
2298 while (cur < blocks) {
2299 ext2fs_numeric_progress_update(fs, &progress, cur);
2301 if (cur + count > blocks)
2302 count = blocks - cur;
2304 retval = io_channel_discard(fs->io, cur, count);
2311 ext2fs_numeric_progress_close(fs, &progress,
2314 printf("%s\n",error_message(retval));
2316 ext2fs_numeric_progress_close(fs, &progress,
2322 static void fix_cluster_bg_counts(ext2_filsys fs)
2324 blk64_t cluster, num_clusters, tot_free;
2326 int grp_free, num_free, group;
2328 num_clusters = EXT2FS_B2C(fs, ext2fs_blocks_count(fs->super));
2329 tot_free = num_free = group = grp_free = 0;
2330 for (cluster = EXT2FS_B2C(fs, fs->super->s_first_data_block);
2331 cluster < num_clusters; cluster++) {
2332 if (!ext2fs_test_block_bitmap2(fs->block_map,
2333 EXT2FS_C2B(fs, cluster))) {
2338 if ((num == fs->super->s_clusters_per_group) ||
2339 (cluster == num_clusters-1)) {
2340 ext2fs_bg_free_blocks_count_set(fs, group, grp_free);
2341 ext2fs_group_desc_csum_set(fs, group);
2347 ext2fs_free_blocks_count_set(fs->super, EXT2FS_C2B(fs, tot_free));
2350 static int create_quota_inodes(ext2_filsys fs)
2354 quota_init_context(&qctx, fs, -1);
2355 quota_compute_usage(qctx);
2356 quota_write_inode(qctx, quotatype);
2357 quota_release_context(&qctx);
2362 int main (int argc, char *argv[])
2364 errcode_t retval = 0;
2366 badblocks_list bb_list = 0;
2367 unsigned int journal_blocks;
2368 unsigned int i, checkinterval;
2374 char tdb_string[40];
2376 int itable_zeroed = 0;
2379 setlocale(LC_MESSAGES, "");
2380 setlocale(LC_CTYPE, "");
2381 bindtextdomain(NLS_CAT_NAME, LOCALEDIR);
2382 textdomain(NLS_CAT_NAME);
2383 set_com_err_gettext(gettext);
2387 #ifdef CONFIG_TESTIO_DEBUG
2388 if (getenv("TEST_IO_FLAGS") || getenv("TEST_IO_BLOCK")) {
2389 io_ptr = test_io_manager;
2390 test_io_backing_manager = unix_io_manager;
2393 io_ptr = unix_io_manager;
2395 if (should_do_undo(device_name)) {
2396 retval = mke2fs_setup_tdb(device_name, &io_ptr);
2402 * Initialize the superblock....
2404 flags = EXT2_FLAG_EXCLUSIVE;
2406 flags |= EXT2_FLAG_DIRECT_IO;
2407 profile_get_boolean(profile, "options", "old_bitmaps", 0, 0,
2410 flags |= EXT2_FLAG_64BITS;
2412 * By default, we print how many inode tables or block groups
2413 * or whatever we've written so far. The quiet flag disables
2414 * this, along with a lot of other output.
2417 flags |= EXT2_FLAG_PRINT_PROGRESS;
2418 retval = ext2fs_initialize(device_name, flags, &fs_param, io_ptr, &fs);
2420 com_err(device_name, retval, "%s",
2421 _("while setting up superblock"));
2425 /* Calculate journal blocks */
2426 if (!journal_device && ((journal_size) ||
2427 (fs_param.s_feature_compat &
2428 EXT3_FEATURE_COMPAT_HAS_JOURNAL)))
2429 journal_blocks = figure_journal_size(journal_size, fs);
2431 /* Can't undo discard ... */
2432 if (!noaction && discard && (io_ptr != undo_io_manager)) {
2433 retval = mke2fs_discard_device(fs);
2434 if (!retval && io_channel_discard_zeroes_data(fs->io)) {
2437 _("Discard succeeded and will return "
2438 "0s - skipping inode table wipe\n"));
2439 lazy_itable_init = 1;
2444 sprintf(tdb_string, "tdb_data_size=%d", fs->blocksize <= 4096 ?
2445 32768 : fs->blocksize * 8);
2446 io_channel_set_options(fs->io, tdb_string);
2448 if (fs_param.s_flags & EXT2_FLAGS_TEST_FILESYS)
2449 fs->super->s_flags |= EXT2_FLAGS_TEST_FILESYS;
2451 if ((fs_param.s_feature_incompat &
2452 (EXT3_FEATURE_INCOMPAT_EXTENTS|EXT4_FEATURE_INCOMPAT_FLEX_BG)) ||
2453 (fs_param.s_feature_ro_compat &
2454 (EXT4_FEATURE_RO_COMPAT_HUGE_FILE|EXT4_FEATURE_RO_COMPAT_GDT_CSUM|
2455 EXT4_FEATURE_RO_COMPAT_DIR_NLINK|
2456 EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE)))
2457 fs->super->s_kbytes_written = 1;
2460 * Wipe out the old on-disk superblock
2463 zap_sector(fs, 2, 6);
2466 * Parse or generate a UUID for the filesystem
2469 if (uuid_parse(fs_uuid, fs->super->s_uuid) !=0) {
2470 com_err(device_name, 0, "could not parse UUID: %s\n",
2475 uuid_generate(fs->super->s_uuid);
2478 * Initialize the directory index variables
2480 hash_alg_str = get_string_from_profile(fs_types, "hash_alg",
2482 hash_alg = e2p_string2hash(hash_alg_str);
2484 fs->super->s_def_hash_version = (hash_alg >= 0) ? hash_alg :
2486 uuid_generate((unsigned char *) fs->super->s_hash_seed);
2489 * Periodic checks can be enabled/disabled via config file.
2490 * Note we override the kernel include file's idea of what the default
2491 * check interval (never) should be. It's a good idea to check at
2492 * least *occasionally*, specially since servers will never rarely get
2493 * to reboot, since Linux is so robust these days. :-)
2495 * 180 days (six months) seems like a good value.
2497 #ifdef EXT2_DFL_CHECKINTERVAL
2498 #undef EXT2_DFL_CHECKINTERVAL
2500 #define EXT2_DFL_CHECKINTERVAL (86400L * 180L)
2502 if (get_bool_from_profile(fs_types, "enable_periodic_fsck", 0)) {
2503 fs->super->s_checkinterval = EXT2_DFL_CHECKINTERVAL;
2504 fs->super->s_max_mnt_count = EXT2_DFL_MAX_MNT_COUNT;
2506 * Add "jitter" to the superblock's check interval so that we
2507 * don't check all the filesystems at the same time. We use a
2508 * kludgy hack of using the UUID to derive a random jitter value
2510 for (i = 0, val = 0 ; i < sizeof(fs->super->s_uuid); i++)
2511 val += fs->super->s_uuid[i];
2512 fs->super->s_max_mnt_count += val % EXT2_DFL_MAX_MNT_COUNT;
2514 fs->super->s_max_mnt_count = -1;
2517 * Override the creator OS, if applicable
2519 if (creator_os && !set_os(fs->super, creator_os)) {
2520 com_err (program_name, 0, _("unknown os - %s"), creator_os);
2525 * For the Hurd, we will turn off filetype since it doesn't
2528 if (fs->super->s_creator_os == EXT2_OS_HURD)
2529 fs->super->s_feature_incompat &=
2530 ~EXT2_FEATURE_INCOMPAT_FILETYPE;
2533 * Set the volume label...
2536 memset(fs->super->s_volume_name, 0,
2537 sizeof(fs->super->s_volume_name));
2538 strncpy(fs->super->s_volume_name, volume_label,
2539 sizeof(fs->super->s_volume_name));
2543 * Set the last mount directory
2546 memset(fs->super->s_last_mounted, 0,
2547 sizeof(fs->super->s_last_mounted));
2548 strncpy(fs->super->s_last_mounted, mount_dir,
2549 sizeof(fs->super->s_last_mounted));
2552 if (!quiet || noaction)
2558 if (fs->super->s_feature_incompat &
2559 EXT3_FEATURE_INCOMPAT_JOURNAL_DEV) {
2560 create_journal_dev(fs);
2561 exit(ext2fs_close(fs) ? 1 : 0);
2564 if (bad_blocks_filename)
2565 read_bb_file(fs, &bb_list, bad_blocks_filename);
2567 test_disk(fs, &bb_list);
2569 handle_bad_blocks(fs, bb_list);
2570 fs->stride = fs_stride = fs->super->s_raid_stride;
2572 printf("%s", _("Allocating group tables: "));
2573 retval = ext2fs_allocate_tables(fs);
2575 com_err(program_name, retval, "%s",
2576 _("while trying to allocate filesystem tables"));
2580 printf("%s", _("done \n"));
2582 retval = ext2fs_convert_subcluster_bitmap(fs, &fs->block_map);
2584 com_err(program_name, retval, "%s",
2585 _("\n\twhile converting subcluster bitmap"));
2590 fs->super->s_state |= EXT2_ERROR_FS;
2591 fs->flags &= ~(EXT2_FLAG_IB_DIRTY|EXT2_FLAG_BB_DIRTY);
2593 * The command "mke2fs -S" is used to recover
2594 * corrupted file systems, so do not mark any of the
2595 * inodes as unused; we want e2fsck to consider all
2596 * inodes as potentially containing recoverable data.
2598 if (fs->super->s_feature_ro_compat &
2599 EXT4_FEATURE_RO_COMPAT_GDT_CSUM) {
2600 for (i = 0; i < fs->group_desc_count; i++)
2601 ext2fs_bg_itable_unused_set(fs, i, 0);
2604 /* rsv must be a power of two (64kB is MD RAID sb alignment) */
2605 blk64_t rsv = 65536 / fs->blocksize;
2606 blk64_t blocks = ext2fs_blocks_count(fs->super);
2610 #ifdef ZAP_BOOTBLOCK
2611 zap_sector(fs, 0, 2);
2615 * Wipe out any old MD RAID (or other) metadata at the end
2616 * of the device. This will also verify that the device is
2617 * as large as we think. Be careful with very small devices.
2619 start = (blocks & ~(rsv - 1));
2623 retval = ext2fs_zero_blocks2(fs, start, blocks - start,
2627 com_err(program_name, retval,
2628 _("while zeroing block %llu at end of filesystem"),
2631 write_inode_tables(fs, lazy_itable_init, itable_zeroed);
2632 create_root_dir(fs);
2633 create_lost_and_found(fs);
2635 create_bad_block_inode(fs, bb_list);
2636 if (fs->super->s_feature_compat &
2637 EXT2_FEATURE_COMPAT_RESIZE_INODE) {
2638 retval = ext2fs_create_resize_inode(fs);
2640 com_err("ext2fs_create_resize_inode", retval,
2642 _("while reserving blocks for online resize"));
2648 if (journal_device) {
2652 check_plausibility(journal_device);
2653 check_mount(journal_device, force, _("journal"));
2655 retval = ext2fs_open(journal_device, EXT2_FLAG_RW|
2656 EXT2_FLAG_JOURNAL_DEV_OK, 0,
2657 fs->blocksize, unix_io_manager, &jfs);
2659 com_err(program_name, retval,
2660 _("while trying to open journal device %s\n"),
2665 printf(_("Adding journal to device %s: "),
2669 retval = ext2fs_add_journal_device(fs, jfs);
2671 com_err (program_name, retval,
2672 _("\n\twhile trying to add journal to device %s"),
2677 printf("%s", _("done\n"));
2679 free(journal_device);
2680 } else if ((journal_size) ||
2681 (fs_param.s_feature_compat &
2682 EXT3_FEATURE_COMPAT_HAS_JOURNAL)) {
2684 printf("%s", _("Skipping journal creation in super-only mode\n"));
2685 fs->super->s_journal_inum = EXT2_JOURNAL_INO;
2689 if (!journal_blocks) {
2690 fs->super->s_feature_compat &=
2691 ~EXT3_FEATURE_COMPAT_HAS_JOURNAL;
2695 printf(_("Creating journal (%u blocks): "),
2699 retval = ext2fs_add_journal_inode(fs, journal_blocks,
2702 com_err(program_name, retval, "%s",
2703 _("\n\twhile trying to create journal"));
2707 printf("%s", _("done\n"));
2711 fs->super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_MMP) {
2712 retval = ext2fs_mmp_init(fs);
2714 fprintf(stderr, "%s",
2715 _("\nError while enabling multiple "
2716 "mount protection feature."));
2720 printf(_("Multiple mount protection is enabled "
2721 "with update interval %d seconds.\n"),
2722 fs->super->s_mmp_update_interval);
2725 if (EXT2_HAS_RO_COMPAT_FEATURE(&fs_param,
2726 EXT4_FEATURE_RO_COMPAT_BIGALLOC))
2727 fix_cluster_bg_counts(fs);
2728 if (EXT2_HAS_RO_COMPAT_FEATURE(&fs_param,
2729 EXT4_FEATURE_RO_COMPAT_QUOTA))
2730 create_quota_inodes(fs);
2733 printf("%s", _("Writing superblocks and "
2734 "filesystem accounting information: "));
2735 checkinterval = fs->super->s_checkinterval;
2736 max_mnt_count = fs->super->s_max_mnt_count;
2737 retval = ext2fs_close(fs);
2739 fprintf(stderr, "%s",
2740 _("\nWarning, had trouble writing out superblocks."));
2741 } else if (!quiet) {
2742 printf("%s", _("done\n\n"));
2743 if (!getenv("MKE2FS_SKIP_CHECK_MSG"))
2744 print_check_message(max_mnt_count, checkinterval);
2747 remove_error_table(&et_ext2_error_table);
2748 remove_error_table(&et_prof_error_table);
2749 profile_release(profile);
2750 for (i=0; fs_types[i]; i++)