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 */
29 #include <sys/utsname.h>
46 #include <sys/ioctl.h>
47 #include <sys/types.h>
51 #include <blkid/blkid.h>
53 #include "ext2fs/ext2_fs.h"
54 #include "ext2fs/ext2fsP.h"
55 #include "et/com_err.h"
56 #include "uuid/uuid.h"
58 #include "ext2fs/ext2fs.h"
62 #include "../version.h"
63 #include "nls-enable.h"
64 #include "quota/mkquota.h"
66 #define STRIDE_LENGTH 8
68 #define MAX_32_NUM ((((unsigned long long) 1) << 32) - 1)
74 #define DISCARD_STEP_MB (2048)
76 extern int isatty(int);
77 extern FILE *fpopen(const char *cmd, const char *mode);
79 const char * program_name = "mke2fs";
80 const char * device_name /* = NULL */;
82 /* Command line options */
87 int discard = 1; /* attempt to discard device before fs creation */
94 char *bad_blocks_filename;
96 int quotatype = -1; /* Initialize both user and group quotas by default */
98 struct ext2_super_block fs_param;
103 char *journal_device;
104 int sync_kludge; /* Set using the MKE2FS_SYNC env. option */
109 int sys_page_size = 4096;
110 int linux_version_code = 0;
112 static void usage(void)
114 fprintf(stderr, _("Usage: %s [-c|-l filename] [-b block-size] "
115 "[-C cluster-size]\n\t[-i bytes-per-inode] [-I inode-size] "
116 "[-J journal-options]\n"
117 "\t[-G flex-group-size] [-N number-of-inodes]\n"
118 "\t[-m reserved-blocks-percentage] [-o creator-os]\n"
119 "\t[-g blocks-per-group] [-L volume-label] "
120 "[-M last-mounted-directory]\n\t[-O feature[,...]] "
121 "[-r fs-revision] [-E extended-option[,...]]\n"
122 "\t[-t fs-type] [-T usage-type ] [-U UUID] "
123 "[-jnqvDFKSV] device [blocks-count]\n"),
128 static int int_log2(unsigned long long arg)
140 static int int_log10(unsigned long long arg)
150 static int parse_version_number(const char *s)
152 int major, minor, rev;
158 major = strtol(cp, &endptr, 10);
159 if (cp == endptr || *endptr != '.')
162 minor = strtol(cp, &endptr, 10);
163 if (cp == endptr || *endptr != '.')
166 rev = strtol(cp, &endptr, 10);
169 return ((((major * 256) + minor) * 256) + rev);
174 * Helper function for read_bb_file and test_disk
176 static void invalid_block(ext2_filsys fs EXT2FS_ATTR((unused)), blk_t blk)
178 fprintf(stderr, _("Bad block %u out of range; ignored.\n"), blk);
183 * Reads the bad blocks list from a file
185 static void read_bb_file(ext2_filsys fs, badblocks_list *bb_list,
186 const char *bad_blocks_file)
191 f = fopen(bad_blocks_file, "r");
193 com_err("read_bad_blocks_file", errno,
194 _("while trying to open %s"), bad_blocks_file);
197 retval = ext2fs_read_bb_FILE(fs, f, bb_list, invalid_block);
200 com_err("ext2fs_read_bb_FILE", retval,
201 _("while reading in list of bad blocks from file"));
207 * Runs the badblocks program to test the disk
209 static void test_disk(ext2_filsys fs, badblocks_list *bb_list)
215 sprintf(buf, "badblocks -b %d -X %s%s%s %llu", fs->blocksize,
216 quiet ? "" : "-s ", (cflag > 1) ? "-w " : "",
217 fs->device_name, ext2fs_blocks_count(fs->super)-1);
219 printf(_("Running command: %s\n"), buf);
222 com_err("popen", errno,
223 _("while trying to run '%s'"), buf);
226 retval = ext2fs_read_bb_FILE(fs, f, bb_list, invalid_block);
229 com_err("ext2fs_read_bb_FILE", retval,
230 _("while processing list of bad blocks from program"));
235 static void handle_bad_blocks(ext2_filsys fs, badblocks_list bb_list)
239 unsigned must_be_good;
241 badblocks_iterate bb_iter;
251 * The primary superblock and group descriptors *must* be
252 * good; if not, abort.
254 must_be_good = fs->super->s_first_data_block + 1 + fs->desc_blocks;
255 for (i = fs->super->s_first_data_block; i <= must_be_good; i++) {
256 if (ext2fs_badblocks_list_test(bb_list, i)) {
257 fprintf(stderr, _("Block %d in primary "
258 "superblock/group descriptor area bad.\n"), i);
259 fprintf(stderr, _("Blocks %u through %u must be good "
260 "in order to build a filesystem.\n"),
261 fs->super->s_first_data_block, must_be_good);
262 fputs(_("Aborting....\n"), stderr);
268 * See if any of the bad blocks are showing up in the backup
269 * superblocks and/or group descriptors. If so, issue a
270 * warning and adjust the block counts appropriately.
272 group_block = fs->super->s_first_data_block +
273 fs->super->s_blocks_per_group;
275 for (i = 1; i < fs->group_desc_count; i++) {
277 for (j=0; j < fs->desc_blocks+1; j++) {
278 if (ext2fs_badblocks_list_test(bb_list,
282 _("Warning: the backup superblock/group descriptors at block %u contain\n"
286 group = ext2fs_group_of_blk2(fs, group_block+j);
287 ext2fs_bg_free_blocks_count_set(fs, group, ext2fs_bg_free_blocks_count(fs, group) + 1);
288 ext2fs_group_desc_csum_set(fs, group);
289 ext2fs_free_blocks_count_add(fs->super, 1);
292 group_block += fs->super->s_blocks_per_group;
296 * Mark all the bad blocks as used...
298 retval = ext2fs_badblocks_list_iterate_begin(bb_list, &bb_iter);
300 com_err("ext2fs_badblocks_list_iterate_begin", retval,
301 _("while marking bad blocks as used"));
304 while (ext2fs_badblocks_list_iterate(bb_iter, &blk))
305 ext2fs_mark_block_bitmap2(fs->block_map, EXT2FS_B2C(fs, blk));
306 ext2fs_badblocks_list_iterate_end(bb_iter);
309 static void write_reserved_inodes(ext2_filsys fs)
313 struct ext2_inode *inode;
315 retval = ext2fs_get_mem(EXT2_INODE_SIZE(fs->super), &inode);
317 com_err("inode_init", retval,
318 "while allocating memory");
321 bzero(inode, EXT2_INODE_SIZE(fs->super));
323 for (ino = 1; ino < EXT2_FIRST_INO(fs->super); ino++)
324 ext2fs_write_inode_full(fs, ino, inode,
325 EXT2_INODE_SIZE(fs->super));
327 ext2fs_free_mem(&inode);
330 static void write_inode_tables(ext2_filsys fs, int lazy_flag, int itable_zeroed)
336 struct ext2fs_numeric_progress_struct progress;
338 ext2fs_numeric_progress_init(fs, &progress,
339 _("Writing inode tables: "),
340 fs->group_desc_count);
342 for (i = 0; i < fs->group_desc_count; i++) {
343 ext2fs_numeric_progress_update(fs, &progress, i);
345 blk = ext2fs_inode_table_loc(fs, i);
346 num = fs->inode_blocks_per_group;
349 num = ext2fs_div_ceil((fs->super->s_inodes_per_group -
350 ext2fs_bg_itable_unused(fs, i)) *
351 EXT2_INODE_SIZE(fs->super),
352 EXT2_BLOCK_SIZE(fs->super));
353 if (!lazy_flag || itable_zeroed) {
354 /* The kernel doesn't need to zero the itable blocks */
355 ext2fs_bg_flags_set(fs, i, EXT2_BG_INODE_ZEROED);
356 ext2fs_group_desc_csum_set(fs, i);
358 retval = ext2fs_zero_blocks2(fs, blk, num, &blk, &num);
360 fprintf(stderr, _("\nCould not write %d "
361 "blocks in inode table starting at %llu: %s\n"),
362 num, blk, error_message(retval));
366 if (sync_kludge == 1)
368 else if ((i % sync_kludge) == 0)
372 ext2fs_zero_blocks2(0, 0, 0, 0, 0);
373 ext2fs_numeric_progress_close(fs, &progress,
376 /* Reserved inodes must always have correct checksums */
377 if (fs->super->s_creator_os == EXT2_OS_LINUX &&
378 fs->super->s_feature_ro_compat &
379 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)
380 write_reserved_inodes(fs);
383 static void create_root_dir(ext2_filsys fs)
386 struct ext2_inode inode;
389 retval = ext2fs_mkdir(fs, EXT2_ROOT_INO, EXT2_ROOT_INO, 0);
391 com_err("ext2fs_mkdir", retval, _("while creating root dir"));
395 retval = ext2fs_read_inode(fs, EXT2_ROOT_INO, &inode);
397 com_err("ext2fs_read_inode", retval,
398 _("while reading root inode"));
403 ext2fs_set_i_uid_high(inode, uid >> 16);
407 ext2fs_set_i_gid_high(inode, gid >> 16);
409 retval = ext2fs_write_new_inode(fs, EXT2_ROOT_INO, &inode);
411 com_err("ext2fs_write_inode", retval,
412 _("while setting root inode ownership"));
418 static void create_lost_and_found(ext2_filsys fs)
420 unsigned int lpf_size = 0;
423 const char *name = "lost+found";
427 retval = ext2fs_mkdir(fs, EXT2_ROOT_INO, 0, name);
429 com_err("ext2fs_mkdir", retval,
430 _("while creating /lost+found"));
434 retval = ext2fs_lookup(fs, EXT2_ROOT_INO, name, strlen(name), 0, &ino);
436 com_err("ext2_lookup", retval,
437 _("while looking up /lost+found"));
441 for (i=1; i < EXT2_NDIR_BLOCKS; i++) {
442 /* Ensure that lost+found is at least 2 blocks, so we always
443 * test large empty blocks for big-block filesystems. */
444 if ((lpf_size += fs->blocksize) >= 16*1024 &&
445 lpf_size >= 2 * fs->blocksize)
447 retval = ext2fs_expand_dir(fs, ino);
449 com_err("ext2fs_expand_dir", retval,
450 _("while expanding /lost+found"));
456 static void create_bad_block_inode(ext2_filsys fs, badblocks_list bb_list)
460 ext2fs_mark_inode_bitmap2(fs->inode_map, EXT2_BAD_INO);
461 ext2fs_inode_alloc_stats2(fs, EXT2_BAD_INO, +1, 0);
462 retval = ext2fs_update_bb_inode(fs, bb_list);
464 com_err("ext2fs_update_bb_inode", retval,
465 _("while setting bad block inode"));
471 static void reserve_inodes(ext2_filsys fs)
475 for (i = EXT2_ROOT_INO + 1; i < EXT2_FIRST_INODE(fs->super); i++)
476 ext2fs_inode_alloc_stats2(fs, i, +1, 0);
477 ext2fs_mark_ib_dirty(fs);
480 #define BSD_DISKMAGIC (0x82564557UL) /* The disk magic number */
481 #define BSD_MAGICDISK (0x57455682UL) /* The disk magic number reversed */
482 #define BSD_LABEL_OFFSET 64
484 static void zap_sector(ext2_filsys fs, int sect, int nsect)
490 buf = malloc(512*nsect);
492 printf(_("Out of memory erasing sectors %d-%d\n"),
493 sect, sect + nsect - 1);
498 /* Check for a BSD disklabel, and don't erase it if so */
499 retval = io_channel_read_blk64(fs->io, 0, -512, buf);
502 _("Warning: could not read block 0: %s\n"),
503 error_message(retval));
505 magic = (unsigned int *) (buf + BSD_LABEL_OFFSET);
506 if ((*magic == BSD_DISKMAGIC) ||
507 (*magic == BSD_MAGICDISK))
512 memset(buf, 0, 512*nsect);
513 io_channel_set_blksize(fs->io, 512);
514 retval = io_channel_write_blk64(fs->io, sect, -512*nsect, buf);
515 io_channel_set_blksize(fs->io, fs->blocksize);
518 fprintf(stderr, _("Warning: could not erase sector %d: %s\n"),
519 sect, error_message(retval));
522 static void create_journal_dev(ext2_filsys fs)
524 struct ext2fs_numeric_progress_struct progress;
527 blk64_t blk, err_blk;
528 int c, count, err_count;
530 retval = ext2fs_create_journal_superblock(fs,
531 ext2fs_blocks_count(fs->super), 0, &buf);
533 com_err("create_journal_dev", retval,
534 _("while initializing journal superblock"));
538 if (journal_flags & EXT2_MKJOURNAL_LAZYINIT)
539 goto write_superblock;
541 ext2fs_numeric_progress_init(fs, &progress,
542 _("Zeroing journal device: "),
543 ext2fs_blocks_count(fs->super));
545 count = ext2fs_blocks_count(fs->super);
551 retval = ext2fs_zero_blocks2(fs, blk, c, &err_blk, &err_count);
553 com_err("create_journal_dev", retval,
554 _("while zeroing journal device "
555 "(block %llu, count %d)"),
561 ext2fs_numeric_progress_update(fs, &progress, blk);
563 ext2fs_zero_blocks2(0, 0, 0, 0, 0);
565 ext2fs_numeric_progress_close(fs, &progress, NULL);
567 retval = io_channel_write_blk64(fs->io,
568 fs->super->s_first_data_block+1,
571 com_err("create_journal_dev", retval,
572 _("while writing journal superblock"));
577 static void show_stats(ext2_filsys fs)
579 struct ext2_super_block *s = fs->super;
586 if (ext2fs_blocks_count(&fs_param) != ext2fs_blocks_count(s))
587 fprintf(stderr, _("warning: %llu blocks unused.\n\n"),
588 ext2fs_blocks_count(&fs_param) - ext2fs_blocks_count(s));
590 memset(buf, 0, sizeof(buf));
591 strncpy(buf, s->s_volume_name, sizeof(s->s_volume_name));
592 printf(_("Filesystem label=%s\n"), buf);
593 os = e2p_os2string(fs->super->s_creator_os);
595 printf(_("OS type: %s\n"), os);
597 printf(_("Block size=%u (log=%u)\n"), fs->blocksize,
598 s->s_log_block_size);
599 if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
600 EXT4_FEATURE_RO_COMPAT_BIGALLOC))
601 printf(_("Cluster size=%u (log=%u)\n"),
602 fs->blocksize << fs->cluster_ratio_bits,
603 s->s_log_cluster_size);
605 printf(_("Fragment size=%u (log=%u)\n"), EXT2_CLUSTER_SIZE(s),
606 s->s_log_cluster_size);
607 printf(_("Stride=%u blocks, Stripe width=%u blocks\n"),
608 s->s_raid_stride, s->s_raid_stripe_width);
609 printf(_("%u inodes, %llu blocks\n"), s->s_inodes_count,
610 ext2fs_blocks_count(s));
611 printf(_("%llu blocks (%2.2f%%) reserved for the super user\n"),
612 ext2fs_r_blocks_count(s),
613 100.0 * ext2fs_r_blocks_count(s) / ext2fs_blocks_count(s));
614 printf(_("First data block=%u\n"), s->s_first_data_block);
615 if (s->s_reserved_gdt_blocks)
616 printf(_("Maximum filesystem blocks=%lu\n"),
617 (s->s_reserved_gdt_blocks + fs->desc_blocks) *
618 EXT2_DESC_PER_BLOCK(s) * s->s_blocks_per_group);
619 if (fs->group_desc_count > 1)
620 printf(_("%u block groups\n"), fs->group_desc_count);
622 printf(_("%u block group\n"), fs->group_desc_count);
623 if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
624 EXT4_FEATURE_RO_COMPAT_BIGALLOC))
625 printf(_("%u blocks per group, %u clusters per group\n"),
626 s->s_blocks_per_group, s->s_clusters_per_group);
628 printf(_("%u blocks per group, %u fragments per group\n"),
629 s->s_blocks_per_group, s->s_clusters_per_group);
630 printf(_("%u inodes per group\n"), s->s_inodes_per_group);
632 if (fs->group_desc_count == 1) {
637 printf(_("Superblock backups stored on blocks: "));
638 group_block = s->s_first_data_block;
640 for (i = 1; i < fs->group_desc_count; i++) {
641 group_block += s->s_blocks_per_group;
642 if (!ext2fs_bg_has_super(fs, i))
646 need = int_log10(group_block) + 2;
647 if (need > col_left) {
652 printf("%llu", group_block);
658 * Returns true if making a file system for the Hurd, else 0
660 static int for_hurd(const char *os)
670 return (atoi(os) == EXT2_OS_HURD);
671 return (strcasecmp(os, "GNU") == 0 || strcasecmp(os, "hurd") == 0);
675 * Set the S_CREATOR_OS field. Return true if OS is known,
678 static int set_os(struct ext2_super_block *sb, char *os)
681 sb->s_creator_os = atoi (os);
682 else if (strcasecmp(os, "linux") == 0)
683 sb->s_creator_os = EXT2_OS_LINUX;
684 else if (strcasecmp(os, "GNU") == 0 || strcasecmp(os, "hurd") == 0)
685 sb->s_creator_os = EXT2_OS_HURD;
686 else if (strcasecmp(os, "freebsd") == 0)
687 sb->s_creator_os = EXT2_OS_FREEBSD;
688 else if (strcasecmp(os, "lites") == 0)
689 sb->s_creator_os = EXT2_OS_LITES;
695 #define PATH_SET "PATH=/sbin"
697 static void parse_extended_opts(struct ext2_super_block *param,
700 char *buf, *token, *next, *p, *arg, *badopt = 0;
708 _("Couldn't allocate memory to parse options!\n"));
712 for (token = buf; token && *token; token = next) {
713 p = strchr(token, ',');
719 arg = strchr(token, '=');
724 if (strcmp(token, "mmp_update_interval") == 0) {
730 param->s_mmp_update_interval = strtoul(arg, &p, 0);
733 _("Invalid mmp_update_interval: %s\n"),
738 } else if (strcmp(token, "stride") == 0) {
744 param->s_raid_stride = strtoul(arg, &p, 0);
747 _("Invalid stride parameter: %s\n"),
752 } else if (strcmp(token, "stripe-width") == 0 ||
753 strcmp(token, "stripe_width") == 0) {
759 param->s_raid_stripe_width = strtoul(arg, &p, 0);
762 _("Invalid stripe-width parameter: %s\n"),
767 } else if (!strcmp(token, "resize")) {
769 unsigned long bpg, rsv_groups;
770 unsigned long group_desc_count, desc_blocks;
771 unsigned int gdpb, blocksize;
780 resize = parse_num_blocks2(arg,
781 param->s_log_block_size);
785 _("Invalid resize parameter: %s\n"),
790 if (resize <= ext2fs_blocks_count(param)) {
792 _("The resize maximum must be greater "
793 "than the filesystem size.\n"));
798 blocksize = EXT2_BLOCK_SIZE(param);
799 bpg = param->s_blocks_per_group;
802 gdpb = EXT2_DESC_PER_BLOCK(param);
803 group_desc_count = (__u32) ext2fs_div64_ceil(
804 ext2fs_blocks_count(param), bpg);
805 desc_blocks = (group_desc_count +
807 rsv_groups = ext2fs_div64_ceil(resize, bpg);
808 rsv_gdb = ext2fs_div_ceil(rsv_groups, gdpb) -
810 if (rsv_gdb > (int) EXT2_ADDR_PER_BLOCK(param))
811 rsv_gdb = EXT2_ADDR_PER_BLOCK(param);
814 if (param->s_rev_level == EXT2_GOOD_OLD_REV) {
816 _("On-line resizing not supported with revision 0 filesystems\n"));
820 param->s_feature_compat |=
821 EXT2_FEATURE_COMPAT_RESIZE_INODE;
823 param->s_reserved_gdt_blocks = rsv_gdb;
825 } else if (!strcmp(token, "test_fs")) {
826 param->s_flags |= EXT2_FLAGS_TEST_FILESYS;
827 } else if (!strcmp(token, "lazy_itable_init")) {
829 lazy_itable_init = strtoul(arg, &p, 0);
831 lazy_itable_init = 1;
832 } else if (!strcmp(token, "lazy_journal_init")) {
834 journal_flags |= strtoul(arg, &p, 0) ?
835 EXT2_MKJOURNAL_LAZYINIT : 0;
837 journal_flags |= EXT2_MKJOURNAL_LAZYINIT;
838 } else if (!strcmp(token, "discard")) {
840 } else if (!strcmp(token, "nodiscard")) {
842 } else if (!strcmp(token, "quotatype")) {
848 if (!strncmp(arg, "usr", 3)) {
850 } else if (!strncmp(arg, "grp", 3)) {
854 _("Invalid quotatype parameter: %s\n"),
865 fprintf(stderr, _("\nBad option(s) specified: %s\n\n"
866 "Extended options are separated by commas, "
867 "and may take an argument which\n"
868 "\tis set off by an equals ('=') sign.\n\n"
869 "Valid extended options are:\n"
870 "\tstride=<RAID per-disk data chunk in blocks>\n"
871 "\tstripe-width=<RAID stride * data disks in blocks>\n"
872 "\tresize=<resize maximum size in blocks>\n"
873 "\tlazy_itable_init=<0 to disable, 1 to enable>\n"
874 "\tlazy_journal_init=<0 to disable, 1 to enable>\n"
878 "\tquotatype=<usr OR grp>\n\n"),
879 badopt ? badopt : "");
883 if (param->s_raid_stride &&
884 (param->s_raid_stripe_width % param->s_raid_stride) != 0)
885 fprintf(stderr, _("\nWarning: RAID stripe-width %u not an even "
886 "multiple of stride %u.\n\n"),
887 param->s_raid_stripe_width, param->s_raid_stride);
892 static __u32 ok_features[3] = {
894 EXT3_FEATURE_COMPAT_HAS_JOURNAL |
895 EXT2_FEATURE_COMPAT_RESIZE_INODE |
896 EXT2_FEATURE_COMPAT_DIR_INDEX |
897 EXT2_FEATURE_COMPAT_EXT_ATTR,
899 EXT2_FEATURE_INCOMPAT_FILETYPE|
900 EXT3_FEATURE_INCOMPAT_EXTENTS|
901 EXT3_FEATURE_INCOMPAT_JOURNAL_DEV|
902 EXT2_FEATURE_INCOMPAT_META_BG|
903 EXT4_FEATURE_INCOMPAT_FLEX_BG|
904 EXT4_FEATURE_INCOMPAT_MMP |
905 EXT4_FEATURE_INCOMPAT_64BIT,
907 EXT2_FEATURE_RO_COMPAT_LARGE_FILE|
908 EXT4_FEATURE_RO_COMPAT_HUGE_FILE|
909 EXT4_FEATURE_RO_COMPAT_DIR_NLINK|
910 EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE|
911 EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER|
912 EXT4_FEATURE_RO_COMPAT_GDT_CSUM|
913 EXT4_FEATURE_RO_COMPAT_BIGALLOC|
915 EXT4_FEATURE_RO_COMPAT_QUOTA|
917 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM
921 static void syntax_err_report(const char *filename, long err, int line_num)
924 _("Syntax error in mke2fs config file (%s, line #%d)\n\t%s\n"),
925 filename, line_num, error_message(err));
929 static const char *config_fn[] = { ROOT_SYSCONFDIR "/mke2fs.conf", 0 };
931 static void edit_feature(const char *str, __u32 *compat_array)
936 if (e2p_edit_feature(str, compat_array, ok_features)) {
937 fprintf(stderr, _("Invalid filesystem option set: %s\n"),
943 static void edit_mntopts(const char *str, __u32 *mntopts)
948 if (e2p_edit_mntopts(str, mntopts, ~0)) {
949 fprintf(stderr, _("Invalid mount option set: %s\n"),
961 static errcode_t init_list(struct str_list *sl)
965 sl->list = malloc((sl->max+1) * sizeof(char *));
972 static errcode_t push_string(struct str_list *sl, const char *str)
976 if (sl->num >= sl->max) {
978 new_list = realloc(sl->list, (sl->max+1) * sizeof(char *));
983 sl->list[sl->num] = malloc(strlen(str)+1);
984 if (sl->list[sl->num] == 0)
986 strcpy(sl->list[sl->num], str);
988 sl->list[sl->num] = 0;
992 static void print_str_list(char **list)
996 for (cpp = list; *cpp; cpp++) {
997 printf("'%s'", *cpp);
1001 fputc('\n', stdout);
1005 * Return TRUE if the profile has the given subsection
1007 static int profile_has_subsection(profile_t prof, const char *section,
1008 const char *subsection)
1011 const char *names[4];
1016 names[1] = subsection;
1019 if (profile_iterator_create(prof, names,
1020 PROFILE_ITER_LIST_SECTION |
1021 PROFILE_ITER_RELATIONS_ONLY, &state))
1024 if ((profile_iterator(&state, &name, 0) == 0) && name) {
1029 profile_iterator_free(&state);
1033 static char **parse_fs_type(const char *fs_type,
1034 const char *usage_types,
1035 struct ext2_super_block *sb,
1036 blk64_t fs_blocks_count,
1039 const char *ext_type = 0;
1041 char *profile_type = 0;
1043 const char *size_type;
1044 struct str_list list;
1045 unsigned long long meg;
1046 int is_hurd = for_hurd(creator_os);
1048 if (init_list(&list))
1055 else if (!strcmp(program_name, "mke3fs"))
1057 else if (!strcmp(program_name, "mke4fs"))
1059 else if (progname) {
1060 ext_type = strrchr(progname, '/');
1064 ext_type = progname;
1066 if (!strncmp(ext_type, "mkfs.", 5)) {
1068 if (ext_type[0] == 0)
1075 profile_get_string(profile, "defaults", "fs_type", 0,
1076 "ext2", &profile_type);
1077 ext_type = profile_type;
1078 if (!strcmp(ext_type, "ext2") && (journal_size != 0))
1083 if (!profile_has_subsection(profile, "fs_types", ext_type) &&
1084 strcmp(ext_type, "ext2")) {
1085 printf(_("\nYour mke2fs.conf file does not define the "
1086 "%s filesystem type.\n"), ext_type);
1087 if (!strcmp(ext_type, "ext3") || !strcmp(ext_type, "ext4") ||
1088 !strcmp(ext_type, "ext4dev")) {
1089 printf(_("You probably need to install an updated "
1090 "mke2fs.conf file.\n\n"));
1093 printf(_("Aborting...\n"));
1098 meg = (1024 * 1024) / EXT2_BLOCK_SIZE(sb);
1099 if (fs_blocks_count < 3 * meg)
1100 size_type = "floppy";
1101 else if (fs_blocks_count < 512 * meg)
1102 size_type = "small";
1103 else if (fs_blocks_count < 4 * 1024 * 1024 * meg)
1104 size_type = "default";
1105 else if (fs_blocks_count < 16 * 1024 * 1024 * meg)
1111 usage_types = size_type;
1113 parse_str = malloc(strlen(usage_types)+1);
1118 strcpy(parse_str, usage_types);
1121 push_string(&list, ext_type);
1124 t = strchr(cp, ',');
1129 if (profile_has_subsection(profile, "fs_types", cp))
1130 push_string(&list, cp);
1131 else if (strcmp(cp, "default") != 0)
1133 _("\nWarning: the fs_type %s is not "
1134 "defined in mke2fs.conf\n\n"),
1145 push_string(&list, "hurd");
1149 static char *get_string_from_profile(char **types, const char *opt,
1150 const char *def_val)
1155 for (i=0; types[i]; i++);
1156 for (i-=1; i >=0 ; i--) {
1157 profile_get_string(profile, "fs_types", types[i],
1162 profile_get_string(profile, "defaults", opt, 0, def_val, &ret);
1166 static int get_int_from_profile(char **types, const char *opt, int def_val)
1171 profile_get_integer(profile, "defaults", opt, 0, def_val, &ret);
1172 for (cpp = types; *cpp; cpp++)
1173 profile_get_integer(profile, "fs_types", *cpp, opt, ret, &ret);
1177 static double get_double_from_profile(char **types, const char *opt,
1183 profile_get_double(profile, "defaults", opt, 0, def_val, &ret);
1184 for (cpp = types; *cpp; cpp++)
1185 profile_get_double(profile, "fs_types", *cpp, opt, ret, &ret);
1189 static int get_bool_from_profile(char **types, const char *opt, int def_val)
1194 profile_get_boolean(profile, "defaults", opt, 0, def_val, &ret);
1195 for (cpp = types; *cpp; cpp++)
1196 profile_get_boolean(profile, "fs_types", *cpp, opt, ret, &ret);
1200 extern const char *mke2fs_default_profile;
1201 static const char *default_files[] = { "<default>", 0 };
1203 #ifdef HAVE_BLKID_PROBE_GET_TOPOLOGY
1205 * Sets the geometry of a device (stripe/stride), and returns the
1206 * device's alignment offset, if any, or a negative error.
1208 static int get_device_geometry(const char *file,
1209 struct ext2_super_block *fs_param,
1216 unsigned long min_io;
1217 unsigned long opt_io;
1218 struct stat statbuf;
1220 /* Nothing to do for a regular file */
1221 if (!stat(file, &statbuf) && S_ISREG(statbuf.st_mode))
1224 pr = blkid_new_probe_from_filename(file);
1228 tp = blkid_probe_get_topology(pr);
1232 min_io = blkid_topology_get_minimum_io_size(tp);
1233 opt_io = blkid_topology_get_optimal_io_size(tp);
1234 blocksize = EXT2_BLOCK_SIZE(fs_param);
1235 if ((min_io == 0) && (psector_size > blocksize))
1236 min_io = psector_size;
1237 if ((opt_io == 0) && min_io)
1239 if ((opt_io == 0) && (psector_size > blocksize))
1240 opt_io = psector_size;
1242 /* setting stripe/stride to blocksize is pointless */
1243 if (min_io > blocksize)
1244 fs_param->s_raid_stride = min_io / blocksize;
1245 if (opt_io > blocksize)
1246 fs_param->s_raid_stripe_width = opt_io / blocksize;
1248 rc = blkid_topology_get_alignment_offset(tp);
1250 blkid_free_probe(pr);
1255 static void PRS(int argc, char *argv[])
1258 int cluster_size = 0;
1261 int inode_ratio = 0;
1263 unsigned long flex_bg_size = 0;
1264 double reserved_ratio = -1.0;
1265 int lsector_size = 0, psector_size = 0;
1266 int show_version_only = 0;
1267 unsigned long long num_inodes = 0; /* unsigned long long to catch too-large input */
1269 char * oldpath = getenv("PATH");
1270 char * extended_opts = 0;
1272 char * usage_types = 0;
1274 blk64_t fs_blocks_count = 0;
1279 int s_opt = -1, r_opt = -1;
1280 char *fs_features = 0;
1283 int pathlen = sizeof(PATH_SET) + 1;
1286 pathlen += strlen(oldpath);
1287 newpath = malloc(pathlen);
1289 fprintf(stderr, _("Couldn't allocate memory for new PATH.\n"));
1292 strcpy(newpath, PATH_SET);
1294 /* Update our PATH to include /sbin */
1296 strcat (newpath, ":");
1297 strcat (newpath, oldpath);
1301 tmp = getenv("MKE2FS_SYNC");
1303 sync_kludge = atoi(tmp);
1305 /* Determine the system page size if possible */
1307 #if (!defined(_SC_PAGESIZE) && defined(_SC_PAGE_SIZE))
1308 #define _SC_PAGESIZE _SC_PAGE_SIZE
1311 sysval = sysconf(_SC_PAGESIZE);
1313 sys_page_size = sysval;
1314 #endif /* _SC_PAGESIZE */
1315 #endif /* HAVE_SYSCONF */
1317 if ((tmp = getenv("MKE2FS_CONFIG")) != NULL)
1319 profile_set_syntax_err_cb(syntax_err_report);
1320 retval = profile_init(config_fn, &profile);
1321 if (retval == ENOENT) {
1322 retval = profile_init(default_files, &profile);
1325 retval = profile_set_default(profile, mke2fs_default_profile);
1328 } else if (retval) {
1330 fprintf(stderr, _("Couldn't init profile successfully"
1331 " (error: %ld).\n"), retval);
1335 setbuf(stdout, NULL);
1336 setbuf(stderr, NULL);
1337 add_error_table(&et_ext2_error_table);
1338 add_error_table(&et_prof_error_table);
1339 memset(&fs_param, 0, sizeof(struct ext2_super_block));
1340 fs_param.s_rev_level = 1; /* Create revision 1 filesystems now */
1347 linux_version_code = parse_version_number(ut.release);
1348 if (linux_version_code && linux_version_code < (2*65536 + 2*256))
1349 fs_param.s_rev_level = 0;
1352 if (argc && *argv) {
1353 program_name = get_progname(*argv);
1355 /* If called as mkfs.ext3, create a journal inode */
1356 if (!strcmp(program_name, "mkfs.ext3") ||
1357 !strcmp(program_name, "mke3fs"))
1361 while ((c = getopt (argc, argv,
1362 "b:cg:i:jl:m:no:qr:s:t:vC:DE:FG:I:J:KL:M:N:O:R:ST:U:V")) != EOF) {
1365 blocksize = parse_num_blocks2(optarg, -1);
1366 b = (blocksize > 0) ? blocksize : -blocksize;
1367 if (b < EXT2_MIN_BLOCK_SIZE ||
1368 b > EXT2_MAX_BLOCK_SIZE) {
1369 com_err(program_name, 0,
1370 _("invalid block size - %s"), optarg);
1373 if (blocksize > 4096)
1374 fprintf(stderr, _("Warning: blocksize %d not "
1375 "usable on most systems.\n"),
1378 fs_param.s_log_block_size =
1379 int_log2(blocksize >>
1380 EXT2_MIN_BLOCK_LOG_SIZE);
1382 case 'c': /* Check for bad blocks */
1386 cluster_size = parse_num_blocks2(optarg, -1);
1387 if (cluster_size <= EXT2_MIN_CLUSTER_SIZE ||
1388 cluster_size > EXT2_MAX_CLUSTER_SIZE) {
1389 com_err(program_name, 0,
1390 _("invalid cluster size - %s"),
1399 fs_param.s_blocks_per_group = strtoul(optarg, &tmp, 0);
1401 com_err(program_name, 0,
1402 _("Illegal number for blocks per group"));
1405 if ((fs_param.s_blocks_per_group % 8) != 0) {
1406 com_err(program_name, 0,
1407 _("blocks per group must be multiple of 8"));
1412 flex_bg_size = strtoul(optarg, &tmp, 0);
1414 com_err(program_name, 0,
1415 _("Illegal number for flex_bg size"));
1418 if (flex_bg_size < 1 ||
1419 (flex_bg_size & (flex_bg_size-1)) != 0) {
1420 com_err(program_name, 0,
1421 _("flex_bg size must be a power of 2"));
1426 inode_ratio = strtoul(optarg, &tmp, 0);
1427 if (inode_ratio < EXT2_MIN_BLOCK_SIZE ||
1428 inode_ratio > EXT2_MAX_BLOCK_SIZE * 1024 ||
1430 com_err(program_name, 0,
1431 _("invalid inode ratio %s (min %d/max %d)"),
1432 optarg, EXT2_MIN_BLOCK_SIZE,
1433 EXT2_MAX_BLOCK_SIZE * 1024);
1438 parse_journal_opts(optarg);
1441 fprintf(stderr, _("Warning: -K option is deprecated and "
1442 "should not be used anymore. Use "
1443 "\'-E nodiscard\' extended option "
1452 bad_blocks_filename = malloc(strlen(optarg)+1);
1453 if (!bad_blocks_filename) {
1454 com_err(program_name, ENOMEM,
1455 _("in malloc for bad_blocks_filename"));
1458 strcpy(bad_blocks_filename, optarg);
1461 reserved_ratio = strtod(optarg, &tmp);
1462 if ( *tmp || reserved_ratio > 50 ||
1463 reserved_ratio < 0) {
1464 com_err(program_name, 0,
1465 _("invalid reserved blocks percent - %s"),
1474 creator_os = optarg;
1480 r_opt = strtoul(optarg, &tmp, 0);
1482 com_err(program_name, 0,
1483 _("bad revision level - %s"), optarg);
1486 fs_param.s_rev_level = r_opt;
1488 case 's': /* deprecated */
1489 s_opt = atoi(optarg);
1492 inode_size = strtoul(optarg, &tmp, 0);
1494 com_err(program_name, 0,
1495 _("invalid inode size - %s"), optarg);
1506 volume_label = optarg;
1512 num_inodes = strtoul(optarg, &tmp, 0);
1514 com_err(program_name, 0,
1515 _("bad num inodes - %s"), optarg);
1520 fs_features = optarg;
1524 extended_opts = optarg;
1531 com_err(program_name, 0,
1532 _("The -t option may only be used once"));
1535 fs_type = strdup(optarg);
1539 com_err(program_name, 0,
1540 _("The -T option may only be used once"));
1543 usage_types = strdup(optarg);
1549 /* Print version number and exit */
1550 show_version_only++;
1556 if ((optind == argc) && !show_version_only)
1558 device_name = argv[optind++];
1560 if (!quiet || show_version_only)
1561 fprintf (stderr, "mke2fs %s (%s)\n", E2FSPROGS_VERSION,
1564 if (show_version_only) {
1565 fprintf(stderr, _("\tUsing %s\n"),
1566 error_message(EXT2_ET_BASE));
1571 * If there's no blocksize specified and there is a journal
1572 * device, use it to figure out the blocksize
1574 if (blocksize <= 0 && journal_device) {
1578 #ifdef CONFIG_TESTIO_DEBUG
1579 if (getenv("TEST_IO_FLAGS") || getenv("TEST_IO_BLOCK")) {
1580 io_ptr = test_io_manager;
1581 test_io_backing_manager = unix_io_manager;
1584 io_ptr = unix_io_manager;
1585 retval = ext2fs_open(journal_device,
1586 EXT2_FLAG_JOURNAL_DEV_OK, 0,
1589 com_err(program_name, retval,
1590 _("while trying to open journal device %s\n"),
1594 if ((blocksize < 0) && (jfs->blocksize < (unsigned) (-blocksize))) {
1595 com_err(program_name, 0,
1596 _("Journal dev blocksize (%d) smaller than "
1597 "minimum blocksize %d\n"), jfs->blocksize,
1601 blocksize = jfs->blocksize;
1602 printf(_("Using journal device's blocksize: %d\n"), blocksize);
1603 fs_param.s_log_block_size =
1604 int_log2(blocksize >> EXT2_MIN_BLOCK_LOG_SIZE);
1608 if (optind < argc) {
1609 fs_blocks_count = parse_num_blocks2(argv[optind++],
1610 fs_param.s_log_block_size);
1611 if (!fs_blocks_count) {
1612 com_err(program_name, 0,
1613 _("invalid blocks '%s' on device '%s'"),
1614 argv[optind - 1], device_name);
1622 check_plausibility(device_name);
1623 check_mount(device_name, force, _("filesystem"));
1625 /* Determine the size of the device (if possible) */
1626 if (noaction && fs_blocks_count) {
1627 dev_size = fs_blocks_count;
1630 retval = ext2fs_get_device_size2(device_name,
1631 EXT2_BLOCK_SIZE(&fs_param),
1634 if (retval && (retval != EXT2_ET_UNIMPLEMENTED)) {
1635 com_err(program_name, retval,
1636 _("while trying to determine filesystem size"));
1639 if (!fs_blocks_count) {
1640 if (retval == EXT2_ET_UNIMPLEMENTED) {
1641 com_err(program_name, 0,
1642 _("Couldn't determine device size; you "
1643 "must specify\nthe size of the "
1647 if (dev_size == 0) {
1648 com_err(program_name, 0,
1649 _("Device size reported to be zero. "
1650 "Invalid partition specified, or\n\t"
1651 "partition table wasn't reread "
1652 "after running fdisk, due to\n\t"
1653 "a modified partition being busy "
1654 "and in use. You may need to reboot\n\t"
1655 "to re-read your partition table.\n"
1659 fs_blocks_count = dev_size;
1660 if (sys_page_size > EXT2_BLOCK_SIZE(&fs_param))
1661 fs_blocks_count &= ~((blk64_t) ((sys_page_size /
1662 EXT2_BLOCK_SIZE(&fs_param))-1));
1664 } else if (!force && (fs_blocks_count > dev_size)) {
1665 com_err(program_name, 0,
1666 _("Filesystem larger than apparent device size."));
1671 profile_get_string(profile, "devices", device_name,
1672 "fs_type", 0, &fs_type);
1674 profile_get_string(profile, "devices", device_name,
1675 "usage_types", 0, &usage_types);
1678 * We have the file system (or device) size, so we can now
1679 * determine the appropriate file system types so the fs can
1680 * be appropriately configured.
1682 fs_types = parse_fs_type(fs_type, usage_types, &fs_param,
1683 fs_blocks_count ? fs_blocks_count : dev_size,
1686 fprintf(stderr, _("Failed to parse fs types list\n"));
1690 /* Figure out what features should be enabled */
1693 if (fs_param.s_rev_level != EXT2_GOOD_OLD_REV) {
1694 tmp = get_string_from_profile(fs_types, "base_features",
1695 "sparse_super,filetype,resize_inode,dir_index");
1696 edit_feature(tmp, &fs_param.s_feature_compat);
1699 /* And which mount options as well */
1700 tmp = get_string_from_profile(fs_types, "default_mntopts",
1702 edit_mntopts(tmp, &fs_param.s_default_mount_opts);
1706 for (cpp = fs_types; *cpp; cpp++) {
1708 profile_get_string(profile, "fs_types", *cpp,
1709 "features", "", &tmp);
1711 edit_feature(tmp, &fs_param.s_feature_compat);
1715 tmp = get_string_from_profile(fs_types, "default_features",
1718 /* Mask off features which aren't supported by the Hurd */
1719 if (for_hurd(creator_os)) {
1720 fs_param.s_feature_incompat &= ~EXT2_FEATURE_INCOMPAT_FILETYPE;
1721 fs_param.s_feature_ro_compat &=
1722 ~(EXT4_FEATURE_RO_COMPAT_HUGE_FILE |
1723 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM);
1725 edit_feature(fs_features ? fs_features : tmp,
1726 &fs_param.s_feature_compat);
1730 * If the user specified features incompatible with the Hurd, complain
1732 if (for_hurd(creator_os)) {
1733 if (fs_param.s_feature_incompat &
1734 EXT2_FEATURE_INCOMPAT_FILETYPE) {
1735 fprintf(stderr, _("The HURD does not support the "
1736 "filetype feature.\n"));
1739 if (fs_param.s_feature_ro_compat &
1740 EXT4_FEATURE_RO_COMPAT_HUGE_FILE) {
1741 fprintf(stderr, _("The HURD does not support the "
1742 "huge_file feature.\n"));
1745 if (fs_param.s_feature_ro_compat &
1746 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM) {
1747 fprintf(stderr, _("The HURD does not support the "
1748 "metadata_csum feature.\n"));
1754 * We now need to do a sanity check of fs_blocks_count for
1755 * 32-bit vs 64-bit block number support.
1757 if ((fs_blocks_count > MAX_32_NUM) && (blocksize == 0)) {
1758 fs_blocks_count /= 4; /* Try using a 4k blocksize */
1760 fs_param.s_log_block_size = 2;
1762 if ((fs_blocks_count > MAX_32_NUM) &&
1763 !(fs_param.s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT) &&
1764 get_bool_from_profile(fs_types, "auto_64-bit_support", 0)) {
1765 fs_param.s_feature_incompat |= EXT4_FEATURE_INCOMPAT_64BIT;
1766 fs_param.s_feature_compat &= ~EXT2_FEATURE_COMPAT_RESIZE_INODE;
1768 if ((fs_blocks_count > MAX_32_NUM) &&
1769 !(fs_param.s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT)) {
1770 fprintf(stderr, _("%s: Size of device (0x%llx blocks) %s "
1771 "too big to be expressed\n\t"
1772 "in 32 bits using a blocksize of %d.\n"),
1773 program_name, fs_blocks_count, device_name,
1774 EXT2_BLOCK_SIZE(&fs_param));
1778 ext2fs_blocks_count_set(&fs_param, fs_blocks_count);
1780 if (fs_param.s_feature_incompat & EXT3_FEATURE_INCOMPAT_JOURNAL_DEV) {
1781 fs_types[0] = strdup("journal");
1786 fputs(_("fs_types for mke2fs.conf resolution: "), stdout);
1787 print_str_list(fs_types);
1790 if (r_opt == EXT2_GOOD_OLD_REV &&
1791 (fs_param.s_feature_compat || fs_param.s_feature_incompat ||
1792 fs_param.s_feature_ro_compat)) {
1793 fprintf(stderr, _("Filesystem features not supported "
1794 "with revision 0 filesystems\n"));
1799 if (r_opt == EXT2_GOOD_OLD_REV) {
1800 fprintf(stderr, _("Sparse superblocks not supported "
1801 "with revision 0 filesystems\n"));
1804 fs_param.s_feature_ro_compat |=
1805 EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER;
1806 } else if (s_opt == 0)
1807 fs_param.s_feature_ro_compat &=
1808 ~EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER;
1810 if (journal_size != 0) {
1811 if (r_opt == EXT2_GOOD_OLD_REV) {
1812 fprintf(stderr, _("Journals not supported "
1813 "with revision 0 filesystems\n"));
1816 fs_param.s_feature_compat |=
1817 EXT3_FEATURE_COMPAT_HAS_JOURNAL;
1820 /* Get reserved_ratio from profile if not specified on cmd line. */
1821 if (reserved_ratio < 0.0) {
1822 reserved_ratio = get_double_from_profile(
1823 fs_types, "reserved_ratio", 5.0);
1824 if (reserved_ratio > 50 || reserved_ratio < 0) {
1825 com_err(program_name, 0,
1826 _("invalid reserved blocks percent - %lf"),
1832 if (fs_param.s_feature_incompat &
1833 EXT3_FEATURE_INCOMPAT_JOURNAL_DEV) {
1835 fs_param.s_feature_incompat = EXT3_FEATURE_INCOMPAT_JOURNAL_DEV;
1836 fs_param.s_feature_compat = 0;
1837 fs_param.s_feature_ro_compat = 0;
1840 if ((fs_param.s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG) &&
1841 (fs_param.s_feature_compat & EXT2_FEATURE_COMPAT_RESIZE_INODE)) {
1842 fprintf(stderr, _("The resize_inode and meta_bg features "
1843 "are not compatible.\n"
1844 "They can not be both enabled "
1845 "simultaneously.\n"));
1849 /* Set first meta blockgroup via an environment variable */
1850 /* (this is mostly for debugging purposes) */
1851 if ((fs_param.s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG) &&
1852 ((tmp = getenv("MKE2FS_FIRST_META_BG"))))
1853 fs_param.s_first_meta_bg = atoi(tmp);
1855 /* Get the hardware sector sizes, if available */
1856 retval = ext2fs_get_device_sectsize(device_name, &lsector_size);
1858 com_err(program_name, retval,
1859 _("while trying to determine hardware sector size"));
1862 retval = ext2fs_get_device_phys_sectsize(device_name, &psector_size);
1864 com_err(program_name, retval,
1865 _("while trying to determine physical sector size"));
1869 if ((tmp = getenv("MKE2FS_DEVICE_SECTSIZE")) != NULL)
1870 lsector_size = atoi(tmp);
1871 if ((tmp = getenv("MKE2FS_DEVICE_PHYS_SECTSIZE")) != NULL)
1872 psector_size = atoi(tmp);
1874 /* Older kernels may not have physical/logical distinction */
1876 psector_size = lsector_size;
1878 if (blocksize <= 0) {
1879 use_bsize = get_int_from_profile(fs_types, "blocksize", 4096);
1881 if (use_bsize == -1) {
1882 use_bsize = sys_page_size;
1883 if ((linux_version_code < (2*65536 + 6*256)) &&
1887 if (lsector_size && use_bsize < lsector_size)
1888 use_bsize = lsector_size;
1889 if ((blocksize < 0) && (use_bsize < (-blocksize)))
1890 use_bsize = -blocksize;
1891 blocksize = use_bsize;
1892 ext2fs_blocks_count_set(&fs_param,
1893 ext2fs_blocks_count(&fs_param) /
1894 (blocksize / 1024));
1896 if (blocksize < lsector_size) { /* Impossible */
1897 com_err(program_name, EINVAL,
1898 _("while setting blocksize; too small "
1901 } else if ((blocksize < psector_size) &&
1902 (psector_size <= sys_page_size)) { /* Suboptimal */
1903 fprintf(stderr, _("Warning: specified blocksize %d is "
1904 "less than device physical sectorsize %d\n"),
1905 blocksize, psector_size);
1909 fs_param.s_log_block_size =
1910 int_log2(blocksize >> EXT2_MIN_BLOCK_LOG_SIZE);
1911 if (fs_param.s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_BIGALLOC) {
1913 cluster_size = get_int_from_profile(fs_types,
1916 fs_param.s_log_cluster_size =
1917 int_log2(cluster_size >> EXT2_MIN_CLUSTER_LOG_SIZE);
1918 if (fs_param.s_log_cluster_size &&
1919 fs_param.s_log_cluster_size < fs_param.s_log_block_size) {
1920 com_err(program_name, 0,
1921 _("The cluster size may not be "
1922 "smaller than the block size.\n"));
1925 } else if (cluster_size) {
1926 com_err(program_name, 0,
1927 _("specifying a cluster size requires the "
1928 "bigalloc feature"));
1931 fs_param.s_log_cluster_size = fs_param.s_log_block_size;
1933 if (inode_ratio == 0) {
1934 inode_ratio = get_int_from_profile(fs_types, "inode_ratio",
1936 if (inode_ratio < blocksize)
1937 inode_ratio = blocksize;
1938 if (inode_ratio < EXT2_CLUSTER_SIZE(&fs_param))
1939 inode_ratio = EXT2_CLUSTER_SIZE(&fs_param);
1942 #ifdef HAVE_BLKID_PROBE_GET_TOPOLOGY
1943 retval = get_device_geometry(device_name, &fs_param, psector_size);
1946 _("warning: Unable to get device geometry for %s\n"),
1948 } else if (retval) {
1949 printf(_("%s alignment is offset by %lu bytes.\n"),
1950 device_name, retval);
1951 printf(_("This may result in very poor performance, "
1952 "(re)-partitioning suggested.\n"));
1956 blocksize = EXT2_BLOCK_SIZE(&fs_param);
1959 * Initialize s_desc_size so that the parse_extended_opts()
1960 * can correctly handle "-E resize=NNN" if the 64-bit option
1963 if (fs_param.s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT)
1964 fs_param.s_desc_size = EXT2_MIN_DESC_SIZE_64BIT;
1966 /* This check should happen beyond the last assignment to blocksize */
1967 if (blocksize > sys_page_size) {
1969 com_err(program_name, 0,
1970 _("%d-byte blocks too big for system (max %d)"),
1971 blocksize, sys_page_size);
1974 fprintf(stderr, _("Warning: %d-byte blocks too big for system "
1975 "(max %d), forced to continue\n"),
1976 blocksize, sys_page_size);
1979 lazy_itable_init = 0;
1980 if (access("/sys/fs/ext4/features/lazy_itable_init", R_OK) == 0)
1981 lazy_itable_init = 1;
1983 lazy_itable_init = get_bool_from_profile(fs_types,
1986 discard = get_bool_from_profile(fs_types, "discard" , discard);
1987 journal_flags |= get_bool_from_profile(fs_types,
1988 "lazy_journal_init", 0) ?
1989 EXT2_MKJOURNAL_LAZYINIT : 0;
1990 journal_flags |= EXT2_MKJOURNAL_NO_MNT_CHECK;
1992 /* Get options from profile */
1993 for (cpp = fs_types; *cpp; cpp++) {
1995 profile_get_string(profile, "fs_types", *cpp, "options", "", &tmp);
1997 parse_extended_opts(&fs_param, tmp);
2002 parse_extended_opts(&fs_param, extended_opts);
2004 /* Don't allow user to set both metadata_csum and uninit_bg bits. */
2005 if ((fs_param.s_feature_ro_compat &
2006 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM) &&
2007 (fs_param.s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_GDT_CSUM))
2008 fs_param.s_feature_ro_compat &=
2009 ~EXT4_FEATURE_RO_COMPAT_GDT_CSUM;
2011 /* Can't support bigalloc feature without extents feature */
2012 if ((fs_param.s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_BIGALLOC) &&
2013 !(fs_param.s_feature_incompat & EXT3_FEATURE_INCOMPAT_EXTENTS)) {
2014 com_err(program_name, 0,
2015 _("Can't support bigalloc feature without "
2016 "extents feature"));
2021 (fs_param.s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_BIGALLOC))
2022 fprintf(stderr, _("\nWarning: the bigalloc feature is still "
2023 "under development\n"
2024 "See https://ext4.wiki.kernel.org/"
2025 "index.php/Bigalloc for more information\n\n"));
2028 (fs_param.s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_QUOTA))
2029 fprintf(stderr, _("\nWarning: the quota feature is still "
2030 "under development\n"
2031 "See https://ext4.wiki.kernel.org/"
2032 "index.php/Quota for more information\n\n"));
2034 /* Since sparse_super is the default, we would only have a problem
2035 * here if it was explicitly disabled.
2037 if ((fs_param.s_feature_compat & EXT2_FEATURE_COMPAT_RESIZE_INODE) &&
2038 !(fs_param.s_feature_ro_compat&EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER)) {
2039 com_err(program_name, 0,
2040 _("reserved online resize blocks not supported "
2041 "on non-sparse filesystem"));
2045 if (fs_param.s_blocks_per_group) {
2046 if (fs_param.s_blocks_per_group < 256 ||
2047 fs_param.s_blocks_per_group > 8 * (unsigned) blocksize) {
2048 com_err(program_name, 0,
2049 _("blocks per group count out of range"));
2055 * If the bigalloc feature is enabled, then the -g option will
2056 * specify the number of clusters per group.
2058 if (fs_param.s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_BIGALLOC) {
2059 fs_param.s_clusters_per_group = fs_param.s_blocks_per_group;
2060 fs_param.s_blocks_per_group = 0;
2063 if (inode_size == 0)
2064 inode_size = get_int_from_profile(fs_types, "inode_size", 0);
2065 if (!flex_bg_size && (fs_param.s_feature_incompat &
2066 EXT4_FEATURE_INCOMPAT_FLEX_BG))
2067 flex_bg_size = get_int_from_profile(fs_types,
2068 "flex_bg_size", 16);
2070 if (!(fs_param.s_feature_incompat &
2071 EXT4_FEATURE_INCOMPAT_FLEX_BG)) {
2072 com_err(program_name, 0,
2073 _("Flex_bg feature not enabled, so "
2074 "flex_bg size may not be specified"));
2077 fs_param.s_log_groups_per_flex = int_log2(flex_bg_size);
2080 if (inode_size && fs_param.s_rev_level >= EXT2_DYNAMIC_REV) {
2081 if (inode_size < EXT2_GOOD_OLD_INODE_SIZE ||
2082 inode_size > EXT2_BLOCK_SIZE(&fs_param) ||
2083 inode_size & (inode_size - 1)) {
2084 com_err(program_name, 0,
2085 _("invalid inode size %d (min %d/max %d)"),
2086 inode_size, EXT2_GOOD_OLD_INODE_SIZE,
2090 fs_param.s_inode_size = inode_size;
2093 /* Make sure number of inodes specified will fit in 32 bits */
2094 if (num_inodes == 0) {
2095 unsigned long long n;
2096 n = ext2fs_blocks_count(&fs_param) * blocksize / inode_ratio;
2097 if (n > MAX_32_NUM) {
2098 if (fs_param.s_feature_incompat &
2099 EXT4_FEATURE_INCOMPAT_64BIT)
2100 num_inodes = MAX_32_NUM;
2102 com_err(program_name, 0,
2103 _("too many inodes (%llu), raise "
2104 "inode ratio?"), n);
2108 } else if (num_inodes > MAX_32_NUM) {
2109 com_err(program_name, 0,
2110 _("too many inodes (%llu), specify < 2^32 inodes"),
2115 * Calculate number of inodes based on the inode ratio
2117 fs_param.s_inodes_count = num_inodes ? num_inodes :
2118 (ext2fs_blocks_count(&fs_param) * blocksize) / inode_ratio;
2120 if ((((unsigned long long)fs_param.s_inodes_count) *
2121 (inode_size ? inode_size : EXT2_GOOD_OLD_INODE_SIZE)) >=
2122 ((ext2fs_blocks_count(&fs_param)) *
2123 EXT2_BLOCK_SIZE(&fs_param))) {
2124 com_err(program_name, 0, _("inode_size (%u) * inodes_count "
2125 "(%u) too big for a\n\t"
2126 "filesystem with %llu blocks, "
2127 "specify higher inode_ratio (-i)\n\t"
2128 "or lower inode count (-N).\n"),
2129 inode_size ? inode_size : EXT2_GOOD_OLD_INODE_SIZE,
2130 fs_param.s_inodes_count,
2131 (unsigned long long) ext2fs_blocks_count(&fs_param));
2136 * Calculate number of blocks to reserve
2138 ext2fs_r_blocks_count_set(&fs_param, reserved_ratio *
2139 ext2fs_blocks_count(&fs_param) / 100.0);
2145 static int should_do_undo(const char *name)
2150 struct ext2_super_block super;
2151 io_manager manager = unix_io_manager;
2152 int csum_flag, force_undo;
2154 csum_flag = EXT2_HAS_RO_COMPAT_FEATURE(&fs_param,
2155 EXT4_FEATURE_RO_COMPAT_GDT_CSUM |
2156 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM);
2157 force_undo = get_int_from_profile(fs_types, "force_undo", 0);
2158 if (!force_undo && (!csum_flag || !lazy_itable_init))
2161 retval = manager->open(name, IO_FLAG_EXCLUSIVE, &channel);
2164 * We don't handle error cases instead we
2165 * declare that the file system doesn't exist
2166 * and let the rest of mke2fs take care of
2173 io_channel_set_blksize(channel, SUPERBLOCK_OFFSET);
2174 retval = io_channel_read_blk64(channel, 1, -SUPERBLOCK_SIZE, &super);
2180 #if defined(WORDS_BIGENDIAN)
2181 s_magic = ext2fs_swab16(super.s_magic);
2183 s_magic = super.s_magic;
2186 if (s_magic == EXT2_SUPER_MAGIC)
2190 io_channel_close(channel);
2197 static int mke2fs_setup_tdb(const char *name, io_manager *io_ptr)
2199 errcode_t retval = ENOMEM;
2200 char *tdb_dir = NULL, *tdb_file = NULL;
2201 char *dev_name, *tmp_name;
2202 int free_tdb_dir = 0;
2205 * Configuration via a conf file would be
2208 tdb_dir = getenv("E2FSPROGS_UNDO_DIR");
2210 profile_get_string(profile, "defaults",
2211 "undo_dir", 0, "/var/lib/e2fsprogs",
2216 if (!strcmp(tdb_dir, "none") || (tdb_dir[0] == 0) ||
2217 access(tdb_dir, W_OK))
2220 tmp_name = strdup(name);
2223 dev_name = basename(tmp_name);
2224 tdb_file = malloc(strlen(tdb_dir) + 8 + strlen(dev_name) + 7 + 1);
2229 sprintf(tdb_file, "%s/mke2fs-%s.e2undo", tdb_dir, dev_name);
2232 if (!access(tdb_file, F_OK)) {
2233 if (unlink(tdb_file) < 0) {
2239 set_undo_io_backing_manager(*io_ptr);
2240 *io_ptr = undo_io_manager;
2241 retval = set_undo_io_backup_file(tdb_file);
2244 printf(_("Overwriting existing filesystem; this can be undone "
2245 "using the command:\n"
2246 " e2undo %s %s\n\n"), tdb_file, name);
2257 com_err(program_name, retval,
2258 _("while trying to setup undo file\n"));
2262 static int mke2fs_discard_device(ext2_filsys fs)
2264 struct ext2fs_numeric_progress_struct progress;
2265 blk64_t blocks = ext2fs_blocks_count(fs->super);
2266 blk64_t count = DISCARD_STEP_MB;
2271 * Let's try if discard really works on the device, so
2272 * we do not print numeric progress resulting in failure
2275 retval = io_channel_discard(fs->io, 0, fs->blocksize);
2278 cur = fs->blocksize;
2280 count *= (1024 * 1024);
2281 count /= fs->blocksize;
2283 ext2fs_numeric_progress_init(fs, &progress,
2284 _("Discarding device blocks: "),
2286 while (cur < blocks) {
2287 ext2fs_numeric_progress_update(fs, &progress, cur);
2289 if (cur + count > blocks)
2290 count = blocks - cur;
2292 retval = io_channel_discard(fs->io, cur, count);
2299 ext2fs_numeric_progress_close(fs, &progress,
2302 printf("%s\n",error_message(retval));
2304 ext2fs_numeric_progress_close(fs, &progress,
2310 static void fix_cluster_bg_counts(ext2_filsys fs)
2312 blk64_t cluster, num_clusters, tot_free;
2314 int grp_free, num_free, group;
2316 num_clusters = EXT2FS_B2C(fs, ext2fs_blocks_count(fs->super));
2317 tot_free = num_free = group = grp_free = 0;
2318 for (cluster = EXT2FS_B2C(fs, fs->super->s_first_data_block);
2319 cluster < num_clusters; cluster++) {
2320 if (!ext2fs_test_block_bitmap2(fs->block_map,
2321 EXT2FS_C2B(fs, cluster))) {
2326 if ((num == fs->super->s_clusters_per_group) ||
2327 (cluster == num_clusters-1)) {
2328 ext2fs_bg_free_blocks_count_set(fs, group, grp_free);
2329 ext2fs_group_desc_csum_set(fs, group);
2335 ext2fs_free_blocks_count_set(fs->super, EXT2FS_C2B(fs, tot_free));
2338 static int create_quota_inodes(ext2_filsys fs)
2342 quota_init_context(&qctx, fs, -1);
2343 quota_compute_usage(qctx);
2344 quota_write_inode(qctx, quotatype);
2345 quota_release_context(&qctx);
2350 int main (int argc, char *argv[])
2352 errcode_t retval = 0;
2354 badblocks_list bb_list = 0;
2355 unsigned int journal_blocks;
2356 unsigned int i, checkinterval;
2362 char tdb_string[40];
2364 int itable_zeroed = 0;
2367 setlocale(LC_MESSAGES, "");
2368 setlocale(LC_CTYPE, "");
2369 bindtextdomain(NLS_CAT_NAME, LOCALEDIR);
2370 textdomain(NLS_CAT_NAME);
2371 set_com_err_gettext(gettext);
2375 #ifdef CONFIG_TESTIO_DEBUG
2376 if (getenv("TEST_IO_FLAGS") || getenv("TEST_IO_BLOCK")) {
2377 io_ptr = test_io_manager;
2378 test_io_backing_manager = unix_io_manager;
2381 io_ptr = unix_io_manager;
2383 if (should_do_undo(device_name)) {
2384 retval = mke2fs_setup_tdb(device_name, &io_ptr);
2390 * Initialize the superblock....
2392 flags = EXT2_FLAG_EXCLUSIVE;
2394 flags |= EXT2_FLAG_DIRECT_IO;
2395 profile_get_boolean(profile, "options", "old_bitmaps", 0, 0,
2398 flags |= EXT2_FLAG_64BITS;
2400 * By default, we print how many inode tables or block groups
2401 * or whatever we've written so far. The quiet flag disables
2402 * this, along with a lot of other output.
2405 flags |= EXT2_FLAG_PRINT_PROGRESS;
2406 retval = ext2fs_initialize(device_name, flags, &fs_param, io_ptr, &fs);
2408 com_err(device_name, retval, _("while setting up superblock"));
2411 fs->progress_ops = &ext2fs_numeric_progress_ops;
2413 /* Check the user's mkfs options for metadata checksumming */
2415 EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
2416 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)) {
2417 if (!EXT2_HAS_INCOMPAT_FEATURE(fs->super,
2418 EXT3_FEATURE_INCOMPAT_EXTENTS))
2419 printf(_("Extents are not enabled. The file extent "
2420 "tree can be checksummed, whereas block maps "
2421 "cannot. Not enabling extents reduces the "
2422 "coverage of metadata checksumming. "
2423 "Pass -O extents to rectify.\n"));
2424 if (!EXT2_HAS_INCOMPAT_FEATURE(fs->super,
2425 EXT4_FEATURE_INCOMPAT_64BIT))
2426 printf(_("64-bit filesystem support is not "
2427 "enabled. The larger fields afforded by "
2428 "this feature enable full-strength "
2429 "checksumming. Pass -O 64bit to rectify.\n"));
2432 /* Can't undo discard ... */
2433 if (!noaction && discard && (io_ptr != undo_io_manager)) {
2434 retval = mke2fs_discard_device(fs);
2435 if (!retval && io_channel_discard_zeroes_data(fs->io)) {
2437 printf(_("Discard succeeded and will return 0s "
2438 " - 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_METADATA_CSUM|
2457 EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE)))
2458 fs->super->s_kbytes_written = 1;
2461 * Wipe out the old on-disk superblock
2464 zap_sector(fs, 2, 6);
2467 * Parse or generate a UUID for the filesystem
2470 if (uuid_parse(fs_uuid, fs->super->s_uuid) !=0) {
2471 com_err(device_name, 0, "could not parse UUID: %s\n",
2476 uuid_generate(fs->super->s_uuid);
2477 ext2fs_init_csum_seed(fs);
2480 * Initialize the directory index variables
2482 hash_alg_str = get_string_from_profile(fs_types, "hash_alg",
2484 hash_alg = e2p_string2hash(hash_alg_str);
2486 fs->super->s_def_hash_version = (hash_alg >= 0) ? hash_alg :
2488 uuid_generate((unsigned char *) fs->super->s_hash_seed);
2491 * Periodic checks can be enabled/disabled via config file.
2492 * Note we override the kernel include file's idea of what the default
2493 * check interval (never) should be. It's a good idea to check at
2494 * least *occasionally*, specially since servers will never rarely get
2495 * to reboot, since Linux is so robust these days. :-)
2497 * 180 days (six months) seems like a good value.
2499 #ifdef EXT2_DFL_CHECKINTERVAL
2500 #undef EXT2_DFL_CHECKINTERVAL
2502 #define EXT2_DFL_CHECKINTERVAL (86400L * 180L)
2504 if (get_bool_from_profile(fs_types, "enable_periodic_fsck", 0)) {
2505 fs->super->s_checkinterval = EXT2_DFL_CHECKINTERVAL;
2506 fs->super->s_max_mnt_count = EXT2_DFL_MAX_MNT_COUNT;
2508 * Add "jitter" to the superblock's check interval so that we
2509 * don't check all the filesystems at the same time. We use a
2510 * kludgy hack of using the UUID to derive a random jitter value
2512 for (i = 0, val = 0 ; i < sizeof(fs->super->s_uuid); i++)
2513 val += fs->super->s_uuid[i];
2514 fs->super->s_max_mnt_count += val % EXT2_DFL_MAX_MNT_COUNT;
2516 fs->super->s_max_mnt_count = -1;
2519 * Override the creator OS, if applicable
2521 if (creator_os && !set_os(fs->super, creator_os)) {
2522 com_err (program_name, 0, _("unknown os - %s"), creator_os);
2527 * For the Hurd, we will turn off filetype since it doesn't
2530 if (fs->super->s_creator_os == EXT2_OS_HURD)
2531 fs->super->s_feature_incompat &=
2532 ~EXT2_FEATURE_INCOMPAT_FILETYPE;
2535 * Set the volume label...
2538 memset(fs->super->s_volume_name, 0,
2539 sizeof(fs->super->s_volume_name));
2540 strncpy(fs->super->s_volume_name, volume_label,
2541 sizeof(fs->super->s_volume_name));
2545 * Set the last mount directory
2548 memset(fs->super->s_last_mounted, 0,
2549 sizeof(fs->super->s_last_mounted));
2550 strncpy(fs->super->s_last_mounted, mount_dir,
2551 sizeof(fs->super->s_last_mounted));
2554 if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
2555 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
2556 fs->super->s_checksum_type = EXT2_CRC32C_CHKSUM;
2558 if (!quiet || noaction)
2564 if (fs->super->s_feature_incompat &
2565 EXT3_FEATURE_INCOMPAT_JOURNAL_DEV) {
2566 create_journal_dev(fs);
2567 exit(ext2fs_close(fs) ? 1 : 0);
2570 if (bad_blocks_filename)
2571 read_bb_file(fs, &bb_list, bad_blocks_filename);
2573 test_disk(fs, &bb_list);
2575 handle_bad_blocks(fs, bb_list);
2576 fs->stride = fs_stride = fs->super->s_raid_stride;
2578 printf(_("Allocating group tables: "));
2579 retval = ext2fs_allocate_tables(fs);
2581 com_err(program_name, retval,
2582 _("while trying to allocate filesystem tables"));
2586 printf(_("done \n"));
2588 retval = ext2fs_convert_subcluster_bitmap(fs, &fs->block_map);
2590 com_err(program_name, retval,
2591 _("\n\twhile converting subcluster bitmap"));
2596 fs->super->s_state |= EXT2_ERROR_FS;
2597 fs->flags &= ~(EXT2_FLAG_IB_DIRTY|EXT2_FLAG_BB_DIRTY);
2599 * The command "mke2fs -S" is used to recover
2600 * corrupted file systems, so do not mark any of the
2601 * inodes as unused; we want e2fsck to consider all
2602 * inodes as potentially containing recoverable data.
2604 if (ext2fs_has_group_desc_csum(fs)) {
2605 for (i = 0; i < fs->group_desc_count; i++)
2606 ext2fs_bg_itable_unused_set(fs, i, 0);
2609 /* rsv must be a power of two (64kB is MD RAID sb alignment) */
2610 blk64_t rsv = 65536 / fs->blocksize;
2611 blk64_t blocks = ext2fs_blocks_count(fs->super);
2615 #ifdef ZAP_BOOTBLOCK
2616 zap_sector(fs, 0, 2);
2620 * Wipe out any old MD RAID (or other) metadata at the end
2621 * of the device. This will also verify that the device is
2622 * as large as we think. Be careful with very small devices.
2624 start = (blocks & ~(rsv - 1));
2628 retval = ext2fs_zero_blocks2(fs, start, blocks - start,
2632 com_err(program_name, retval,
2633 _("while zeroing block %llu at end of filesystem"),
2636 write_inode_tables(fs, lazy_itable_init, itable_zeroed);
2637 create_root_dir(fs);
2638 create_lost_and_found(fs);
2640 create_bad_block_inode(fs, bb_list);
2641 if (fs->super->s_feature_compat &
2642 EXT2_FEATURE_COMPAT_RESIZE_INODE) {
2643 retval = ext2fs_create_resize_inode(fs);
2645 com_err("ext2fs_create_resize_inode", retval,
2646 _("while reserving blocks for online resize"));
2652 if (journal_device) {
2656 check_plausibility(journal_device);
2657 check_mount(journal_device, force, _("journal"));
2659 retval = ext2fs_open(journal_device, EXT2_FLAG_RW|
2660 EXT2_FLAG_JOURNAL_DEV_OK, 0,
2661 fs->blocksize, unix_io_manager, &jfs);
2663 com_err(program_name, retval,
2664 _("while trying to open journal device %s\n"),
2669 printf(_("Adding journal to device %s: "),
2673 retval = ext2fs_add_journal_device(fs, jfs);
2675 com_err (program_name, retval,
2676 _("\n\twhile trying to add journal to device %s"),
2681 printf(_("done\n"));
2683 free(journal_device);
2684 } else if ((journal_size) ||
2685 (fs_param.s_feature_compat &
2686 EXT3_FEATURE_COMPAT_HAS_JOURNAL)) {
2687 journal_blocks = figure_journal_size(journal_size, fs);
2690 printf(_("Skipping journal creation in super-only mode\n"));
2691 fs->super->s_journal_inum = EXT2_JOURNAL_INO;
2695 if (!journal_blocks) {
2696 fs->super->s_feature_compat &=
2697 ~EXT3_FEATURE_COMPAT_HAS_JOURNAL;
2701 printf(_("Creating journal (%u blocks): "),
2705 retval = ext2fs_add_journal_inode(fs, journal_blocks,
2708 com_err (program_name, retval,
2709 _("\n\twhile trying to create journal"));
2713 printf(_("done\n"));
2717 fs->super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_MMP) {
2718 retval = ext2fs_mmp_init(fs);
2720 fprintf(stderr, _("\nError while enabling multiple "
2721 "mount protection feature."));
2725 printf(_("Multiple mount protection is enabled "
2726 "with update interval %d seconds.\n"),
2727 fs->super->s_mmp_update_interval);
2730 if (EXT2_HAS_RO_COMPAT_FEATURE(&fs_param,
2731 EXT4_FEATURE_RO_COMPAT_BIGALLOC))
2732 fix_cluster_bg_counts(fs);
2733 if (EXT2_HAS_RO_COMPAT_FEATURE(&fs_param,
2734 EXT4_FEATURE_RO_COMPAT_QUOTA))
2735 create_quota_inodes(fs);
2738 printf(_("Writing superblocks and "
2739 "filesystem accounting information: "));
2740 checkinterval = fs->super->s_checkinterval;
2741 max_mnt_count = fs->super->s_max_mnt_count;
2742 retval = ext2fs_close(fs);
2745 _("\nWarning, had trouble writing out superblocks."));
2746 } else if (!quiet) {
2747 printf(_("done\n\n"));
2748 if (!getenv("MKE2FS_SKIP_CHECK_MSG"))
2749 print_check_message(max_mnt_count, checkinterval);
2752 remove_error_table(&et_ext2_error_table);
2753 remove_error_table(&et_prof_error_table);
2754 profile_release(profile);
2755 for (i=0; fs_types[i]; i++)