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 :-).
25 #include <sys/utsname.h>
45 #include <sys/ioctl.h>
46 #include <sys/types.h>
49 #include "ext2fs/ext2_fs.h"
50 #include "et/com_err.h"
51 #include "uuid/uuid.h"
53 #include "ext2fs/ext2fs.h"
57 #include "../version.h"
58 #include "nls-enable.h"
60 #define STRIDE_LENGTH 8
66 extern int isatty(int);
67 extern FILE *fpopen(const char *cmd, const char *mode);
69 const char * program_name = "mke2fs";
70 const char * device_name /* = NULL */;
72 /* Command line options */
82 char *bad_blocks_filename;
85 struct ext2_super_block fs_param;
90 int sync_kludge; /* Set using the MKE2FS_SYNC env. option */
95 int sys_page_size = 4096;
96 int linux_version_code = 0;
98 static void usage(void)
100 fprintf(stderr, _("Usage: %s [-c|-l filename] [-b block-size] "
101 "[-f fragment-size]\n\t[-i bytes-per-inode] [-I inode-size] "
102 "[-J journal-options]\n"
103 "\t[-N number-of-inodes] [-m reserved-blocks-percentage] "
104 "[-o creator-os]\n\t[-g blocks-per-group] [-L volume-label] "
105 "[-M last-mounted-directory]\n\t[-O feature[,...]] "
106 "[-r fs-revision] [-E extended-option[,...]]\n"
107 "\t[-T fs-type] [-jnqvFSV] device [blocks-count]\n"),
112 static int int_log2(int arg)
124 static int int_log10(unsigned int arg)
133 static int parse_version_number(const char *s)
135 int major, minor, rev;
141 major = strtol(cp, &endptr, 10);
142 if (cp == endptr || *endptr != '.')
145 minor = strtol(cp, &endptr, 10);
146 if (cp == endptr || *endptr != '.')
149 rev = strtol(cp, &endptr, 10);
152 return ((((major * 256) + minor) * 256) + rev);
156 * Helper function for read_bb_file and test_disk
158 static void invalid_block(ext2_filsys fs EXT2FS_ATTR((unused)), blk_t blk)
160 fprintf(stderr, _("Bad block %u out of range; ignored.\n"), blk);
165 * Reads the bad blocks list from a file
167 static void read_bb_file(ext2_filsys fs, badblocks_list *bb_list,
168 const char *bad_blocks_file)
173 f = fopen(bad_blocks_file, "r");
175 com_err("read_bad_blocks_file", errno,
176 _("while trying to open %s"), bad_blocks_file);
179 retval = ext2fs_read_bb_FILE(fs, f, bb_list, invalid_block);
182 com_err("ext2fs_read_bb_FILE", retval,
183 _("while reading in list of bad blocks from file"));
189 * Runs the badblocks program to test the disk
191 static void test_disk(ext2_filsys fs, badblocks_list *bb_list)
197 sprintf(buf, "badblocks -b %d -X %s%s%s %u", fs->blocksize,
198 quiet ? "" : "-s ", (cflag > 1) ? "-w " : "",
199 fs->device_name, fs->super->s_blocks_count-1);
201 printf(_("Running command: %s\n"), buf);
204 com_err("popen", errno,
205 _("while trying to run '%s'"), buf);
208 retval = ext2fs_read_bb_FILE(fs, f, bb_list, invalid_block);
211 com_err("ext2fs_read_bb_FILE", retval,
212 _("while processing list of bad blocks from program"));
217 static void handle_bad_blocks(ext2_filsys fs, badblocks_list bb_list)
221 unsigned must_be_good;
223 badblocks_iterate bb_iter;
233 * The primary superblock and group descriptors *must* be
234 * good; if not, abort.
236 must_be_good = fs->super->s_first_data_block + 1 + fs->desc_blocks;
237 for (i = fs->super->s_first_data_block; i <= must_be_good; i++) {
238 if (ext2fs_badblocks_list_test(bb_list, i)) {
239 fprintf(stderr, _("Block %d in primary "
240 "superblock/group descriptor area bad.\n"), i);
241 fprintf(stderr, _("Blocks %u through %u must be good "
242 "in order to build a filesystem.\n"),
243 fs->super->s_first_data_block, must_be_good);
244 fputs(_("Aborting....\n"), stderr);
250 * See if any of the bad blocks are showing up in the backup
251 * superblocks and/or group descriptors. If so, issue a
252 * warning and adjust the block counts appropriately.
254 group_block = fs->super->s_first_data_block +
255 fs->super->s_blocks_per_group;
257 for (i = 1; i < fs->group_desc_count; i++) {
259 for (j=0; j < fs->desc_blocks+1; j++) {
260 if (ext2fs_badblocks_list_test(bb_list,
264 _("Warning: the backup superblock/group descriptors at block %u contain\n"
268 group = ext2fs_group_of_blk(fs, group_block+j);
269 fs->group_desc[group].bg_free_blocks_count++;
270 ext2fs_group_desc_csum_set(fs, group);
271 fs->super->s_free_blocks_count++;
274 group_block += fs->super->s_blocks_per_group;
278 * Mark all the bad blocks as used...
280 retval = ext2fs_badblocks_list_iterate_begin(bb_list, &bb_iter);
282 com_err("ext2fs_badblocks_list_iterate_begin", retval,
283 _("while marking bad blocks as used"));
286 while (ext2fs_badblocks_list_iterate(bb_iter, &blk))
287 ext2fs_mark_block_bitmap(fs->block_map, blk);
288 ext2fs_badblocks_list_iterate_end(bb_iter);
292 * These functions implement a generalized progress meter.
294 struct progress_struct {
301 static void progress_init(struct progress_struct *progress,
302 const char *label,__u32 max)
306 memset(progress, 0, sizeof(struct progress_struct));
311 * Figure out how many digits we need
314 sprintf(progress->format, "%%%dd/%%%dld", i, i);
315 memset(progress->backup, '\b', sizeof(progress->backup)-1);
316 progress->backup[sizeof(progress->backup)-1] = 0;
317 if ((2*i)+1 < (int) sizeof(progress->backup))
318 progress->backup[(2*i)+1] = 0;
321 progress->skip_progress = 0;
322 if (getenv("MKE2FS_SKIP_PROGRESS"))
323 progress->skip_progress++;
325 fputs(label, stdout);
329 static void progress_update(struct progress_struct *progress, __u32 val)
331 if ((progress->format[0] == 0) || progress->skip_progress)
333 printf(progress->format, val, progress->max);
334 fputs(progress->backup, stdout);
337 static void progress_close(struct progress_struct *progress)
339 if (progress->format[0] == 0)
341 fputs(_("done \n"), stdout);
344 static void write_inode_tables(ext2_filsys fs, int lazy_flag)
350 struct progress_struct progress;
353 memset(&progress, 0, sizeof(progress));
355 progress_init(&progress, _("Writing inode tables: "),
356 fs->group_desc_count);
358 for (i = 0; i < fs->group_desc_count; i++) {
359 progress_update(&progress, i);
361 blk = fs->group_desc[i].bg_inode_table;
362 num = fs->inode_blocks_per_group;
365 ipb = fs->blocksize / EXT2_INODE_SIZE(fs->super);
366 num = ((((fs->super->s_inodes_per_group -
367 fs->group_desc[i].bg_itable_unused) *
368 EXT2_INODE_SIZE(fs->super)) +
369 EXT2_BLOCK_SIZE(fs->super) - 1) /
370 EXT2_BLOCK_SIZE(fs->super));
372 /* The kernel doesn't need to zero the itable blocks */
373 fs->group_desc[i].bg_flags |= EXT2_BG_INODE_ZEROED;
374 ext2fs_group_desc_csum_set(fs, i);
376 retval = ext2fs_zero_blocks(fs, blk, num, &blk, &num);
378 fprintf(stderr, _("\nCould not write %d "
379 "blocks in inode table starting at %u: %s\n"),
380 num, blk, error_message(retval));
384 if (sync_kludge == 1)
386 else if ((i % sync_kludge) == 0)
390 ext2fs_zero_blocks(0, 0, 0, 0, 0);
391 progress_close(&progress);
394 static void create_root_dir(ext2_filsys fs)
397 struct ext2_inode inode;
400 retval = ext2fs_mkdir(fs, EXT2_ROOT_INO, EXT2_ROOT_INO, 0);
402 com_err("ext2fs_mkdir", retval, _("while creating root dir"));
406 retval = ext2fs_read_inode(fs, EXT2_ROOT_INO, &inode);
408 com_err("ext2fs_read_inode", retval,
409 _("while reading root inode"));
414 ext2fs_set_i_uid_high(inode, uid >> 16);
418 ext2fs_set_i_gid_high(inode, gid >> 16);
420 retval = ext2fs_write_new_inode(fs, EXT2_ROOT_INO, &inode);
422 com_err("ext2fs_write_inode", retval,
423 _("while setting root inode ownership"));
429 static void create_lost_and_found(ext2_filsys fs)
431 unsigned int lpf_size = 0;
434 const char *name = "lost+found";
438 retval = ext2fs_mkdir(fs, EXT2_ROOT_INO, 0, name);
440 com_err("ext2fs_mkdir", retval,
441 _("while creating /lost+found"));
445 retval = ext2fs_lookup(fs, EXT2_ROOT_INO, name, strlen(name), 0, &ino);
447 com_err("ext2_lookup", retval,
448 _("while looking up /lost+found"));
452 for (i=1; i < EXT2_NDIR_BLOCKS; i++) {
453 /* Ensure that lost+found is at least 2 blocks, so we always
454 * test large empty blocks for big-block filesystems. */
455 if ((lpf_size += fs->blocksize) >= 16*1024 &&
456 lpf_size >= 2 * fs->blocksize)
458 retval = ext2fs_expand_dir(fs, ino);
460 com_err("ext2fs_expand_dir", retval,
461 _("while expanding /lost+found"));
467 static void create_bad_block_inode(ext2_filsys fs, badblocks_list bb_list)
471 ext2fs_mark_inode_bitmap(fs->inode_map, EXT2_BAD_INO);
472 ext2fs_inode_alloc_stats2(fs, EXT2_BAD_INO, +1, 0);
473 retval = ext2fs_update_bb_inode(fs, bb_list);
475 com_err("ext2fs_update_bb_inode", retval,
476 _("while setting bad block inode"));
482 static void reserve_inodes(ext2_filsys fs)
487 for (i = EXT2_ROOT_INO + 1; i < EXT2_FIRST_INODE(fs->super); i++)
488 ext2fs_inode_alloc_stats2(fs, i, +1, 0);
489 ext2fs_mark_ib_dirty(fs);
492 #define BSD_DISKMAGIC (0x82564557UL) /* The disk magic number */
493 #define BSD_MAGICDISK (0x57455682UL) /* The disk magic number reversed */
494 #define BSD_LABEL_OFFSET 64
496 static void zap_sector(ext2_filsys fs, int sect, int nsect)
502 buf = malloc(512*nsect);
504 printf(_("Out of memory erasing sectors %d-%d\n"),
505 sect, sect + nsect - 1);
510 /* Check for a BSD disklabel, and don't erase it if so */
511 retval = io_channel_read_blk(fs->io, 0, -512, buf);
514 _("Warning: could not read block 0: %s\n"),
515 error_message(retval));
517 magic = (unsigned int *) (buf + BSD_LABEL_OFFSET);
518 if ((*magic == BSD_DISKMAGIC) ||
519 (*magic == BSD_MAGICDISK))
524 memset(buf, 0, 512*nsect);
525 io_channel_set_blksize(fs->io, 512);
526 retval = io_channel_write_blk(fs->io, sect, -512*nsect, buf);
527 io_channel_set_blksize(fs->io, fs->blocksize);
530 fprintf(stderr, _("Warning: could not erase sector %d: %s\n"),
531 sect, error_message(retval));
534 static void create_journal_dev(ext2_filsys fs)
536 struct progress_struct progress;
540 int c, count, err_count;
542 retval = ext2fs_create_journal_superblock(fs,
543 fs->super->s_blocks_count, 0, &buf);
545 com_err("create_journal_dev", retval,
546 _("while initializing journal superblock"));
550 memset(&progress, 0, sizeof(progress));
552 progress_init(&progress, _("Zeroing journal device: "),
553 fs->super->s_blocks_count);
556 count = fs->super->s_blocks_count;
562 retval = ext2fs_zero_blocks(fs, blk, c, &err_blk, &err_count);
564 com_err("create_journal_dev", retval,
565 _("while zeroing journal device "
566 "(block %u, count %d)"),
572 progress_update(&progress, blk);
574 ext2fs_zero_blocks(0, 0, 0, 0, 0);
576 retval = io_channel_write_blk(fs->io,
577 fs->super->s_first_data_block+1,
580 com_err("create_journal_dev", retval,
581 _("while writing journal superblock"));
584 progress_close(&progress);
587 static void show_stats(ext2_filsys fs)
589 struct ext2_super_block *s = fs->super;
596 if (fs_param.s_blocks_count != s->s_blocks_count)
597 fprintf(stderr, _("warning: %u blocks unused.\n\n"),
598 fs_param.s_blocks_count - s->s_blocks_count);
600 memset(buf, 0, sizeof(buf));
601 strncpy(buf, s->s_volume_name, sizeof(s->s_volume_name));
602 printf(_("Filesystem label=%s\n"), buf);
603 fputs(_("OS type: "), stdout);
604 os = e2p_os2string(fs->super->s_creator_os);
608 printf(_("Block size=%u (log=%u)\n"), fs->blocksize,
609 s->s_log_block_size);
610 printf(_("Fragment size=%u (log=%u)\n"), fs->fragsize,
612 printf(_("%u inodes, %u blocks\n"), s->s_inodes_count,
614 printf(_("%u blocks (%2.2f%%) reserved for the super user\n"),
616 100.0 * s->s_r_blocks_count / s->s_blocks_count);
617 printf(_("First data block=%u\n"), s->s_first_data_block);
618 if (s->s_reserved_gdt_blocks)
619 printf(_("Maximum filesystem blocks=%lu\n"),
620 (s->s_reserved_gdt_blocks + fs->desc_blocks) *
621 EXT2_DESC_PER_BLOCK(s) * s->s_blocks_per_group);
622 if (fs->group_desc_count > 1)
623 printf(_("%u block groups\n"), fs->group_desc_count);
625 printf(_("%u block group\n"), fs->group_desc_count);
626 printf(_("%u blocks per group, %u fragments per group\n"),
627 s->s_blocks_per_group, s->s_frags_per_group);
628 printf(_("%u inodes per group\n"), s->s_inodes_per_group);
630 if (fs->group_desc_count == 1) {
635 printf(_("Superblock backups stored on blocks: "));
636 group_block = s->s_first_data_block;
638 for (i = 1; i < fs->group_desc_count; i++) {
639 group_block += s->s_blocks_per_group;
640 if (!ext2fs_bg_has_super(fs, i))
644 need = int_log10(group_block) + 2;
645 if (need > col_left) {
650 printf("%u", group_block);
656 * Set the S_CREATOR_OS field. Return true if OS is known,
659 static int set_os(struct ext2_super_block *sb, char *os)
662 sb->s_creator_os = atoi (os);
663 else if (strcasecmp(os, "linux") == 0)
664 sb->s_creator_os = EXT2_OS_LINUX;
665 else if (strcasecmp(os, "GNU") == 0 || strcasecmp(os, "hurd") == 0)
666 sb->s_creator_os = EXT2_OS_HURD;
667 else if (strcasecmp(os, "freebsd") == 0)
668 sb->s_creator_os = EXT2_OS_FREEBSD;
669 else if (strcasecmp(os, "lites") == 0)
670 sb->s_creator_os = EXT2_OS_LITES;
676 #define PATH_SET "PATH=/sbin"
678 static void parse_extended_opts(struct ext2_super_block *param,
681 char *buf, *token, *next, *p, *arg, *badopt = 0;
689 _("Couldn't allocate memory to parse options!\n"));
693 for (token = buf; token && *token; token = next) {
694 p = strchr(token, ',');
700 arg = strchr(token, '=');
705 if (strcmp(token, "stride") == 0) {
711 param->s_raid_stride = strtoul(arg, &p, 0);
712 if (*p || (param->s_raid_stride == 0)) {
714 _("Invalid stride parameter: %s\n"),
719 } else if (strcmp(token, "stripe-width") == 0 ||
720 strcmp(token, "stripe_width") == 0) {
726 param->s_raid_stripe_width = strtoul(arg, &p, 0);
727 if (*p || (param->s_raid_stripe_width == 0)) {
729 _("Invalid stripe-width parameter: %s\n"),
734 } else if (!strcmp(token, "resize")) {
735 unsigned long resize, bpg, rsv_groups;
736 unsigned long group_desc_count, desc_blocks;
737 unsigned int gdpb, blocksize;
746 resize = parse_num_blocks(arg,
747 param->s_log_block_size);
751 _("Invalid resize parameter: %s\n"),
756 if (resize <= param->s_blocks_count) {
758 _("The resize maximum must be greater "
759 "than the filesystem size.\n"));
764 blocksize = EXT2_BLOCK_SIZE(param);
765 bpg = param->s_blocks_per_group;
768 gdpb = EXT2_DESC_PER_BLOCK(param);
770 ext2fs_div_ceil(param->s_blocks_count, bpg);
771 desc_blocks = (group_desc_count +
773 rsv_groups = ext2fs_div_ceil(resize, bpg);
774 rsv_gdb = ext2fs_div_ceil(rsv_groups, gdpb) -
776 if (rsv_gdb > (int) EXT2_ADDR_PER_BLOCK(param))
777 rsv_gdb = EXT2_ADDR_PER_BLOCK(param);
780 if (param->s_rev_level == EXT2_GOOD_OLD_REV) {
782 _("On-line resizing not supported with revision 0 filesystems\n"));
786 param->s_feature_compat |=
787 EXT2_FEATURE_COMPAT_RESIZE_INODE;
789 param->s_reserved_gdt_blocks = rsv_gdb;
791 } else if (!strcmp(token, "test_fs")) {
792 param->s_flags |= EXT2_FLAGS_TEST_FILESYS;
793 } else if (!strcmp(token, "lazy_itable_init")) {
795 lazy_itable_init = strtoul(arg, &p, 0);
797 lazy_itable_init = 1;
804 fprintf(stderr, _("\nBad option(s) specified: %s\n\n"
805 "Extended options are separated by commas, "
806 "and may take an argument which\n"
807 "\tis set off by an equals ('=') sign.\n\n"
808 "Valid extended options are:\n"
809 "\tstride=<RAID per-disk data chunk in blocks>\n"
810 "\tstripe-width=<RAID stride * data disks in blocks>\n"
811 "\tresize=<resize maximum size in blocks>\n"
812 "\tlazy_itable_init=<0 to disable, 1 to enable>\n"
814 badopt ? badopt : "");
818 if (param->s_raid_stride &&
819 (param->s_raid_stripe_width % param->s_raid_stride) != 0)
820 fprintf(stderr, _("\nWarning: RAID stripe-width %u not an even "
821 "multiple of stride %u.\n\n"),
822 param->s_raid_stripe_width, param->s_raid_stride);
827 static __u32 ok_features[3] = {
829 EXT3_FEATURE_COMPAT_HAS_JOURNAL |
830 EXT2_FEATURE_COMPAT_RESIZE_INODE |
831 EXT2_FEATURE_COMPAT_DIR_INDEX |
832 EXT2_FEATURE_COMPAT_EXT_ATTR,
834 EXT2_FEATURE_INCOMPAT_FILETYPE|
835 EXT3_FEATURE_INCOMPAT_EXTENTS|
836 EXT3_FEATURE_INCOMPAT_JOURNAL_DEV|
837 EXT2_FEATURE_INCOMPAT_META_BG|
838 EXT4_FEATURE_INCOMPAT_FLEX_BG,
840 EXT2_FEATURE_RO_COMPAT_LARGE_FILE|
841 EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER|
842 EXT4_FEATURE_RO_COMPAT_GDT_CSUM
846 static void syntax_err_report(const char *filename, long err, int line_num)
849 _("Syntax error in mke2fs config file (%s, line #%d)\n\t%s\n"),
850 filename, line_num, error_message(err));
854 static const char *config_fn[] = { ROOT_SYSCONFDIR "/mke2fs.conf", 0 };
856 static void edit_feature(const char *str, __u32 *compat_array)
861 if (e2p_edit_feature(str, compat_array, ok_features)) {
862 fprintf(stderr, _("Invalid filesystem option set: %s\n"),
874 static errcode_t init_list(struct str_list *sl)
878 sl->list = malloc((sl->max+1) * sizeof(char *));
885 static errcode_t push_string(struct str_list *sl, const char *str)
889 if (sl->num >= sl->max) {
891 new_list = realloc(sl->list, (sl->max+1) * sizeof(char *));
896 sl->list[sl->num] = malloc(strlen(str)+1);
897 if (sl->list[sl->num] == 0)
899 strcpy(sl->list[sl->num], str);
901 sl->list[sl->num] = 0;
905 static void print_str_list(char **list)
909 for (cpp = list; *cpp; cpp++) {
910 printf("'%s'", *cpp);
917 static char **parse_fs_type(const char *fs_type,
918 const char *usage_types,
919 struct ext2_super_block *fs_param,
922 const char *ext_type = 0;
924 char *profile_type = 0;
926 const char *size_type;
927 struct str_list list;
931 if (init_list(&list))
937 ext_type = strrchr(progname, '/');
943 if (!strncmp(ext_type, "mkfs.", 5)) {
945 if (ext_type[0] == 0)
952 profile_get_string(profile, "defaults", "fs_type", 0,
953 "ext2", &profile_type);
954 ext_type = profile_type;
955 if (!strcmp(ext_type, "ext2") && (journal_size != 0))
959 meg = (1024 * 1024) / EXT2_BLOCK_SIZE(fs_param);
960 if (fs_param->s_blocks_count < 3 * meg)
961 size_type = "floppy";
962 else if (fs_param->s_blocks_count < 512 * meg)
965 size_type = "default";
968 usage_types = size_type;
970 parse_str = malloc(usage_types ? strlen(usage_types)+1 : 1);
976 strcpy(parse_str, usage_types);
981 push_string(&list, ext_type);
989 push_string(&list, cp);
1003 static char *get_string_from_profile(char **fs_types, const char *opt,
1004 const char *def_val)
1010 for (i=0; fs_types[i]; i++);
1011 for (i-=1; i >=0 ; i--) {
1012 profile_get_string(profile, "fs_types", fs_types[i],
1017 profile_get_string(profile, "defaults", opt, 0, def_val, &ret);
1021 static int get_int_from_profile(char **fs_types, const char *opt, int def_val)
1026 profile_get_integer(profile, "defaults", opt, 0, def_val, &ret);
1027 for (cpp = fs_types; *cpp; cpp++)
1028 profile_get_integer(profile, "fs_types", *cpp, opt, ret, &ret);
1032 static int get_bool_from_profile(char **fs_types, const char *opt, int def_val)
1037 profile_get_boolean(profile, "defaults", opt, 0, def_val, &ret);
1038 for (cpp = fs_types; *cpp; cpp++)
1039 profile_get_boolean(profile, "fs_types", *cpp, opt, ret, &ret);
1043 extern const char *mke2fs_default_profile;
1044 static const char *default_files[] = { "<default>", 0 };
1046 static void PRS(int argc, char *argv[])
1052 int inode_ratio = 0;
1054 double reserved_ratio = 5.0;
1055 int sector_size = 0;
1056 int show_version_only = 0;
1057 unsigned long long num_inodes = 0; /* unsigned long long to catch too-large input */
1059 char * oldpath = getenv("PATH");
1060 char * extended_opts = 0;
1061 const char * fs_type = 0;
1062 const char * usage_types = 0;
1068 int s_opt = -1, r_opt = -1;
1069 char *fs_features = 0;
1072 int pathlen = sizeof(PATH_SET) + 1;
1075 pathlen += strlen(oldpath);
1076 newpath = malloc(pathlen);
1077 strcpy(newpath, PATH_SET);
1079 /* Update our PATH to include /sbin */
1081 strcat (newpath, ":");
1082 strcat (newpath, oldpath);
1086 tmp = getenv("MKE2FS_SYNC");
1088 sync_kludge = atoi(tmp);
1090 /* Determine the system page size if possible */
1092 #if (!defined(_SC_PAGESIZE) && defined(_SC_PAGE_SIZE))
1093 #define _SC_PAGESIZE _SC_PAGE_SIZE
1096 sysval = sysconf(_SC_PAGESIZE);
1098 sys_page_size = sysval;
1099 #endif /* _SC_PAGESIZE */
1100 #endif /* HAVE_SYSCONF */
1102 if ((tmp = getenv("MKE2FS_CONFIG")) != NULL)
1104 profile_set_syntax_err_cb(syntax_err_report);
1105 retval = profile_init(config_fn, &profile);
1106 if (retval == ENOENT) {
1107 profile_init(default_files, &profile);
1108 profile_set_default(profile, mke2fs_default_profile);
1111 setbuf(stdout, NULL);
1112 setbuf(stderr, NULL);
1113 add_error_table(&et_ext2_error_table);
1114 add_error_table(&et_prof_error_table);
1115 memset(&fs_param, 0, sizeof(struct ext2_super_block));
1116 fs_param.s_rev_level = 1; /* Create revision 1 filesystems now */
1123 linux_version_code = parse_version_number(ut.release);
1124 if (linux_version_code && linux_version_code < (2*65536 + 2*256))
1125 fs_param.s_rev_level = 0;
1128 if (argc && *argv) {
1129 program_name = get_progname(*argv);
1131 /* If called as mkfs.ext3, create a journal inode */
1132 if (!strcmp(program_name, "mkfs.ext3"))
1136 while ((c = getopt (argc, argv,
1137 "b:cf:g:i:jl:m:no:qr:s:t:vE:FI:J:L:M:N:O:R:ST:V")) != EOF) {
1140 blocksize = strtol(optarg, &tmp, 0);
1141 b = (blocksize > 0) ? blocksize : -blocksize;
1142 if (b < EXT2_MIN_BLOCK_SIZE ||
1143 b > EXT2_MAX_BLOCK_SIZE || *tmp) {
1144 com_err(program_name, 0,
1145 _("invalid block size - %s"), optarg);
1148 if (blocksize > 4096)
1149 fprintf(stderr, _("Warning: blocksize %d not "
1150 "usable on most systems.\n"),
1153 fs_param.s_log_block_size =
1154 int_log2(blocksize >>
1155 EXT2_MIN_BLOCK_LOG_SIZE);
1157 case 'c': /* Check for bad blocks */
1161 size = strtoul(optarg, &tmp, 0);
1162 if (size < EXT2_MIN_BLOCK_SIZE ||
1163 size > EXT2_MAX_BLOCK_SIZE || *tmp) {
1164 com_err(program_name, 0,
1165 _("invalid fragment size - %s"),
1169 fs_param.s_log_frag_size =
1170 int_log2(size >> EXT2_MIN_BLOCK_LOG_SIZE);
1171 fprintf(stderr, _("Warning: fragments not supported. "
1172 "Ignoring -f option\n"));
1175 fs_param.s_blocks_per_group = strtoul(optarg, &tmp, 0);
1177 com_err(program_name, 0,
1178 _("Illegal number for blocks per group"));
1181 if ((fs_param.s_blocks_per_group % 8) != 0) {
1182 com_err(program_name, 0,
1183 _("blocks per group must be multiple of 8"));
1188 inode_ratio = strtoul(optarg, &tmp, 0);
1189 if (inode_ratio < EXT2_MIN_BLOCK_SIZE ||
1190 inode_ratio > EXT2_MAX_BLOCK_SIZE * 1024 ||
1192 com_err(program_name, 0,
1193 _("invalid inode ratio %s (min %d/max %d)"),
1194 optarg, EXT2_MIN_BLOCK_SIZE,
1195 EXT2_MAX_BLOCK_SIZE);
1200 parse_journal_opts(optarg);
1207 bad_blocks_filename = malloc(strlen(optarg)+1);
1208 if (!bad_blocks_filename) {
1209 com_err(program_name, ENOMEM,
1210 _("in malloc for bad_blocks_filename"));
1213 strcpy(bad_blocks_filename, optarg);
1216 reserved_ratio = strtod(optarg, &tmp);
1217 if (reserved_ratio > 50 || *tmp) {
1218 com_err(program_name, 0,
1219 _("invalid reserved blocks percent - %s"),
1228 creator_os = optarg;
1234 r_opt = strtoul(optarg, &tmp, 0);
1236 com_err(program_name, 0,
1237 _("bad revision level - %s"), optarg);
1240 fs_param.s_rev_level = r_opt;
1242 case 's': /* deprecated */
1243 s_opt = atoi(optarg);
1246 inode_size = strtoul(optarg, &tmp, 0);
1248 com_err(program_name, 0,
1249 _("invalid inode size - %s"), optarg);
1260 volume_label = optarg;
1266 num_inodes = strtoul(optarg, &tmp, 0);
1268 com_err(program_name, 0,
1269 _("bad num inodes - %s"), optarg);
1274 fs_features = optarg;
1278 extended_opts = optarg;
1287 usage_types = optarg;
1290 /* Print version number and exit */
1291 show_version_only++;
1297 if ((optind == argc) && !show_version_only)
1299 device_name = argv[optind++];
1301 if (!quiet || show_version_only)
1302 fprintf (stderr, "mke2fs %s (%s)\n", E2FSPROGS_VERSION,
1305 if (show_version_only) {
1306 fprintf(stderr, _("\tUsing %s\n"),
1307 error_message(EXT2_ET_BASE));
1312 * If there's no blocksize specified and there is a journal
1313 * device, use it to figure out the blocksize
1315 if (blocksize <= 0 && journal_device) {
1319 #ifdef CONFIG_TESTIO_DEBUG
1320 io_ptr = test_io_manager;
1321 test_io_backing_manager = unix_io_manager;
1323 io_ptr = unix_io_manager;
1325 retval = ext2fs_open(journal_device,
1326 EXT2_FLAG_JOURNAL_DEV_OK, 0,
1329 com_err(program_name, retval,
1330 _("while trying to open journal device %s\n"),
1334 if ((blocksize < 0) && (jfs->blocksize < (unsigned) (-blocksize))) {
1335 com_err(program_name, 0,
1336 _("Journal dev blocksize (%d) smaller than "
1337 "minimum blocksize %d\n"), jfs->blocksize,
1341 blocksize = jfs->blocksize;
1342 fs_param.s_log_block_size =
1343 int_log2(blocksize >> EXT2_MIN_BLOCK_LOG_SIZE);
1347 if (blocksize > sys_page_size) {
1349 com_err(program_name, 0,
1350 _("%d-byte blocks too big for system (max %d)"),
1351 blocksize, sys_page_size);
1354 fprintf(stderr, _("Warning: %d-byte blocks too big for system "
1355 "(max %d), forced to continue\n"),
1356 blocksize, sys_page_size);
1358 if (optind < argc) {
1359 fs_param.s_blocks_count = parse_num_blocks(argv[optind++],
1360 fs_param.s_log_block_size);
1361 if (!fs_param.s_blocks_count) {
1362 com_err(program_name, 0, _("invalid blocks count - %s"),
1371 check_plausibility(device_name);
1372 check_mount(device_name, force, _("filesystem"));
1374 fs_param.s_log_frag_size = fs_param.s_log_block_size;
1376 if (noaction && fs_param.s_blocks_count) {
1377 dev_size = fs_param.s_blocks_count;
1381 retval = ext2fs_get_device_size(device_name,
1382 EXT2_BLOCK_SIZE(&fs_param),
1384 if ((retval == EFBIG) &&
1386 (fs_param.s_log_block_size == 0)) {
1387 fs_param.s_log_block_size = 2;
1393 if (retval && (retval != EXT2_ET_UNIMPLEMENTED)) {
1394 com_err(program_name, retval,
1395 _("while trying to determine filesystem size"));
1398 if (!fs_param.s_blocks_count) {
1399 if (retval == EXT2_ET_UNIMPLEMENTED) {
1400 com_err(program_name, 0,
1401 _("Couldn't determine device size; you "
1402 "must specify\nthe size of the "
1406 if (dev_size == 0) {
1407 com_err(program_name, 0,
1408 _("Device size reported to be zero. "
1409 "Invalid partition specified, or\n\t"
1410 "partition table wasn't reread "
1411 "after running fdisk, due to\n\t"
1412 "a modified partition being busy "
1413 "and in use. You may need to reboot\n\t"
1414 "to re-read your partition table.\n"
1418 fs_param.s_blocks_count = dev_size;
1419 if (sys_page_size > EXT2_BLOCK_SIZE(&fs_param))
1420 fs_param.s_blocks_count &= ~((sys_page_size /
1421 EXT2_BLOCK_SIZE(&fs_param))-1);
1424 } else if (!force && (fs_param.s_blocks_count > dev_size)) {
1425 com_err(program_name, 0,
1426 _("Filesystem larger than apparent device size."));
1430 fs_types = parse_fs_type(fs_type, usage_types, &fs_param, argv[0]);
1432 fprintf(stderr, _("Failed to parse fs types list\n"));
1436 fputs("Fs_types for mke2fs.conf resolution: ", stdout);
1437 print_str_list(fs_types);
1441 int megs = (__u64)fs_param.s_blocks_count *
1442 (EXT2_BLOCK_SIZE(&fs_param) / 1024) / 1024;
1444 if (fs_param.s_feature_incompat &
1445 EXT3_FEATURE_INCOMPAT_JOURNAL_DEV)
1446 fs_type = "journal";
1449 else if (megs <= 512)
1452 fs_type = "default";
1455 /* Figure out what features should be enabled */
1458 if (fs_param.s_rev_level != EXT2_GOOD_OLD_REV) {
1461 tmp = get_string_from_profile(fs_types, "base_features",
1462 "sparse_super,filetype,resize_inode,dir_index");
1463 edit_feature(tmp, &fs_param.s_feature_compat);
1466 for (cpp = fs_types; *cpp; cpp++) {
1468 profile_get_string(profile, "fs_types", *cpp,
1469 "features", "", &tmp);
1471 edit_feature(tmp, &fs_param.s_feature_compat);
1475 tmp = get_string_from_profile(fs_types, "default_features",
1478 edit_feature(fs_features ? fs_features : tmp,
1479 &fs_param.s_feature_compat);
1483 if (r_opt == EXT2_GOOD_OLD_REV &&
1484 (fs_param.s_feature_compat || fs_param.s_feature_incompat ||
1485 fs_param.s_feature_incompat)) {
1486 fprintf(stderr, _("Filesystem features not supported "
1487 "with revision 0 filesystems\n"));
1492 if (r_opt == EXT2_GOOD_OLD_REV) {
1493 fprintf(stderr, _("Sparse superblocks not supported "
1494 "with revision 0 filesystems\n"));
1497 fs_param.s_feature_ro_compat |=
1498 EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER;
1499 } else if (s_opt == 0)
1500 fs_param.s_feature_ro_compat &=
1501 ~EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER;
1503 if (journal_size != 0) {
1504 if (r_opt == EXT2_GOOD_OLD_REV) {
1505 fprintf(stderr, _("Journals not supported "
1506 "with revision 0 filesystems\n"));
1509 fs_param.s_feature_compat |=
1510 EXT3_FEATURE_COMPAT_HAS_JOURNAL;
1513 if (fs_param.s_feature_incompat &
1514 EXT3_FEATURE_INCOMPAT_JOURNAL_DEV) {
1516 fs_param.s_feature_incompat = EXT3_FEATURE_INCOMPAT_JOURNAL_DEV;
1517 fs_param.s_feature_compat = 0;
1518 fs_param.s_feature_ro_compat = 0;
1521 if ((fs_param.s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG) &&
1522 (fs_param.s_feature_compat & EXT2_FEATURE_COMPAT_RESIZE_INODE)) {
1523 fprintf(stderr, _("The resize_inode and meta_bg features "
1524 "are not compatible.\n"
1525 "They can not be both enabled "
1526 "simultaneously.\n"));
1530 /* Set first meta blockgroup via an environment variable */
1531 /* (this is mostly for debugging purposes) */
1532 if ((fs_param.s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG) &&
1533 ((tmp = getenv("MKE2FS_FIRST_META_BG"))))
1534 fs_param.s_first_meta_bg = atoi(tmp);
1536 /* Get the hardware sector size, if available */
1537 retval = ext2fs_get_device_sectsize(device_name, §or_size);
1539 com_err(program_name, retval,
1540 _("while trying to determine hardware sector size"));
1544 if ((tmp = getenv("MKE2FS_DEVICE_SECTSIZE")) != NULL)
1545 sector_size = atoi(tmp);
1547 if (blocksize <= 0) {
1548 use_bsize = get_int_from_profile(fs_types, "blocksize", 4096);
1550 if (use_bsize == -1) {
1551 use_bsize = sys_page_size;
1552 if ((linux_version_code < (2*65536 + 6*256)) &&
1556 if (sector_size && use_bsize < sector_size)
1557 use_bsize = sector_size;
1558 if ((blocksize < 0) && (use_bsize < (-blocksize)))
1559 use_bsize = -blocksize;
1560 blocksize = use_bsize;
1561 fs_param.s_blocks_count /= blocksize / 1024;
1564 if (inode_ratio == 0) {
1565 inode_ratio = get_int_from_profile(fs_types, "inode_ratio",
1567 if (inode_ratio < blocksize)
1568 inode_ratio = blocksize;
1571 fs_param.s_log_frag_size = fs_param.s_log_block_size =
1572 int_log2(blocksize >> EXT2_MIN_BLOCK_LOG_SIZE);
1574 blocksize = EXT2_BLOCK_SIZE(&fs_param);
1576 lazy_itable_init = get_bool_from_profile(fs_types,
1577 "lazy_itable_init", 0);
1580 parse_extended_opts(&fs_param, extended_opts);
1582 /* Since sparse_super is the default, we would only have a problem
1583 * here if it was explicitly disabled.
1585 if ((fs_param.s_feature_compat & EXT2_FEATURE_COMPAT_RESIZE_INODE) &&
1586 !(fs_param.s_feature_ro_compat&EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER)) {
1587 com_err(program_name, 0,
1588 _("reserved online resize blocks not supported "
1589 "on non-sparse filesystem"));
1593 if (fs_param.s_blocks_per_group) {
1594 if (fs_param.s_blocks_per_group < 256 ||
1595 fs_param.s_blocks_per_group > 8 * (unsigned) blocksize) {
1596 com_err(program_name, 0,
1597 _("blocks per group count out of range"));
1602 if (inode_size == 0)
1603 inode_size = get_int_from_profile(fs_types, "inode_size", 0);
1605 if (inode_size && fs_param.s_rev_level >= EXT2_DYNAMIC_REV) {
1606 if (inode_size < EXT2_GOOD_OLD_INODE_SIZE ||
1607 inode_size > EXT2_BLOCK_SIZE(&fs_param) ||
1608 inode_size & (inode_size - 1)) {
1609 com_err(program_name, 0,
1610 _("invalid inode size %d (min %d/max %d)"),
1611 inode_size, EXT2_GOOD_OLD_INODE_SIZE,
1615 fs_param.s_inode_size = inode_size;
1618 /* Make sure number of inodes specified will fit in 32 bits */
1619 if (num_inodes == 0) {
1620 unsigned long long n;
1621 n = (unsigned long long) fs_param.s_blocks_count * blocksize / inode_ratio;
1623 com_err(program_name, 0,
1624 _("too many inodes (%llu), raise inode ratio?"), n);
1627 } else if (num_inodes > ~0U) {
1628 com_err(program_name, 0,
1629 _("too many inodes (%llu), specify < 2^32 inodes"),
1634 * Calculate number of inodes based on the inode ratio
1636 fs_param.s_inodes_count = num_inodes ? num_inodes :
1637 ((__u64) fs_param.s_blocks_count * blocksize)
1640 if ((((long long)fs_param.s_inodes_count) *
1641 (inode_size ? inode_size : EXT2_GOOD_OLD_INODE_SIZE)) >=
1642 (((long long)fs_param.s_blocks_count) *
1643 EXT2_BLOCK_SIZE(&fs_param))) {
1644 com_err(program_name, 0, _("inode_size (%u) * inodes_count "
1645 "(%u) too big for a\n\t"
1646 "filesystem with %lu blocks, "
1647 "specify higher inode_ratio (-i)\n\t"
1648 "or lower inode count (-N).\n"),
1649 inode_size ? inode_size : EXT2_GOOD_OLD_INODE_SIZE,
1650 fs_param.s_inodes_count,
1651 (unsigned long) fs_param.s_blocks_count);
1656 * Calculate number of blocks to reserve
1658 fs_param.s_r_blocks_count = e2p_percent(reserved_ratio,
1659 fs_param.s_blocks_count);
1662 static int should_do_undo(const char *name)
1667 struct ext2_super_block super;
1668 io_manager manager = unix_io_manager;
1669 int csum_flag, force_undo;
1671 csum_flag = EXT2_HAS_RO_COMPAT_FEATURE(&fs_param,
1672 EXT4_FEATURE_RO_COMPAT_GDT_CSUM);
1673 force_undo = get_int_from_profile(fs_types, "force_undo", 0);
1674 if (!force_undo && (!csum_flag || !lazy_itable_init))
1677 retval = manager->open(name, IO_FLAG_EXCLUSIVE, &channel);
1680 * We don't handle error cases instead we
1681 * declare that the file system doesn't exist
1682 * and let the rest of mke2fs take care of
1689 io_channel_set_blksize(channel, SUPERBLOCK_OFFSET);
1690 retval = io_channel_read_blk(channel, 1, -SUPERBLOCK_SIZE, &super);
1696 #if defined(WORDS_BIGENDIAN)
1697 s_magic = ext2fs_swab16(super.s_magic);
1699 s_magic = super.s_magic;
1702 if (s_magic == EXT2_SUPER_MAGIC)
1706 io_channel_close(channel);
1713 static int mke2fs_setup_tdb(const char *name, io_manager *io_ptr)
1715 errcode_t retval = 0;
1716 char *tdb_dir, tdb_file[PATH_MAX];
1717 char *device_name, *tmp_name;
1720 * Configuration via a conf file would be
1723 tdb_dir = getenv("E2FSPROGS_UNDO_DIR");
1725 profile_get_string(profile, "defaults",
1726 "undo_dir", 0, "/var/lib/e2fsprogs",
1729 if (!strcmp(tdb_dir, "none") || (tdb_dir[0] == 0) ||
1730 access(tdb_dir, W_OK))
1733 tmp_name = strdup(name);
1734 device_name = basename(tmp_name);
1735 sprintf(tdb_file, "%s/mke2fs-%s.e2undo", tdb_dir, device_name);
1737 if (!access(tdb_file, F_OK)) {
1738 if (unlink(tdb_file) < 0) {
1740 com_err(program_name, retval,
1741 _("while trying to delete %s"),
1747 set_undo_io_backing_manager(*io_ptr);
1748 *io_ptr = undo_io_manager;
1749 set_undo_io_backup_file(tdb_file);
1750 printf(_("Overwriting existing filesystem; this can be undone "
1751 "using the command:\n"
1752 " e2undo %s %s\n\n"), tdb_file, name);
1758 int main (int argc, char *argv[])
1760 errcode_t retval = 0;
1762 badblocks_list bb_list = 0;
1763 unsigned int journal_blocks;
1767 char tdb_string[40];
1770 setlocale(LC_MESSAGES, "");
1771 setlocale(LC_CTYPE, "");
1772 bindtextdomain(NLS_CAT_NAME, LOCALEDIR);
1773 textdomain(NLS_CAT_NAME);
1777 #ifdef CONFIG_TESTIO_DEBUG
1778 io_ptr = test_io_manager;
1779 test_io_backing_manager = unix_io_manager;
1781 io_ptr = unix_io_manager;
1784 if (should_do_undo(device_name)) {
1785 retval = mke2fs_setup_tdb(device_name, &io_ptr);
1791 * Initialize the superblock....
1793 retval = ext2fs_initialize(device_name, EXT2_FLAG_EXCLUSIVE, &fs_param,
1796 com_err(device_name, retval, _("while setting up superblock"));
1799 sprintf(tdb_string, "tdb_data_size=%d", fs->blocksize <= 4096 ?
1800 32768 : fs->blocksize * 8);
1801 io_channel_set_options(fs->io, tdb_string);
1803 if (fs_param.s_flags & EXT2_FLAGS_TEST_FILESYS)
1804 fs->super->s_flags |= EXT2_FLAGS_TEST_FILESYS;
1807 * Wipe out the old on-disk superblock
1810 zap_sector(fs, 2, 6);
1813 * Generate a UUID for it...
1815 uuid_generate(fs->super->s_uuid);
1818 * Initialize the directory index variables
1820 fs->super->s_def_hash_version = EXT2_HASH_TEA;
1821 uuid_generate((unsigned char *) fs->super->s_hash_seed);
1824 * Add "jitter" to the superblock's check interval so that we
1825 * don't check all the filesystems at the same time. We use a
1826 * kludgy hack of using the UUID to derive a random jitter value.
1828 for (i = 0, val = 0 ; i < sizeof(fs->super->s_uuid); i++)
1829 val += fs->super->s_uuid[i];
1830 fs->super->s_max_mnt_count += val % EXT2_DFL_MAX_MNT_COUNT;
1833 * Override the creator OS, if applicable
1835 if (creator_os && !set_os(fs->super, creator_os)) {
1836 com_err (program_name, 0, _("unknown os - %s"), creator_os);
1841 * For the Hurd, we will turn off filetype since it doesn't
1844 if (fs->super->s_creator_os == EXT2_OS_HURD)
1845 fs->super->s_feature_incompat &=
1846 ~EXT2_FEATURE_INCOMPAT_FILETYPE;
1849 * Set the volume label...
1852 memset(fs->super->s_volume_name, 0,
1853 sizeof(fs->super->s_volume_name));
1854 strncpy(fs->super->s_volume_name, volume_label,
1855 sizeof(fs->super->s_volume_name));
1859 * Set the last mount directory
1862 memset(fs->super->s_last_mounted, 0,
1863 sizeof(fs->super->s_last_mounted));
1864 strncpy(fs->super->s_last_mounted, mount_dir,
1865 sizeof(fs->super->s_last_mounted));
1868 if (!quiet || noaction)
1874 if (fs->super->s_feature_incompat &
1875 EXT3_FEATURE_INCOMPAT_JOURNAL_DEV) {
1876 create_journal_dev(fs);
1877 exit(ext2fs_close(fs) ? 1 : 0);
1880 if (bad_blocks_filename)
1881 read_bb_file(fs, &bb_list, bad_blocks_filename);
1883 test_disk(fs, &bb_list);
1885 handle_bad_blocks(fs, bb_list);
1886 fs->stride = fs_stride = fs->super->s_raid_stride;
1887 retval = ext2fs_allocate_tables(fs);
1889 com_err(program_name, retval,
1890 _("while trying to allocate filesystem tables"));
1894 fs->super->s_state |= EXT2_ERROR_FS;
1895 fs->flags &= ~(EXT2_FLAG_IB_DIRTY|EXT2_FLAG_BB_DIRTY);
1897 /* rsv must be a power of two (64kB is MD RAID sb alignment) */
1898 unsigned int rsv = 65536 / fs->blocksize;
1899 unsigned long blocks = fs->super->s_blocks_count;
1900 unsigned long start;
1903 #ifdef ZAP_BOOTBLOCK
1904 zap_sector(fs, 0, 2);
1908 * Wipe out any old MD RAID (or other) metadata at the end
1909 * of the device. This will also verify that the device is
1910 * as large as we think. Be careful with very small devices.
1912 start = (blocks & ~(rsv - 1));
1916 retval = ext2fs_zero_blocks(fs, start, blocks - start,
1920 com_err(program_name, retval,
1921 _("while zeroing block %u at end of filesystem"),
1924 write_inode_tables(fs, lazy_itable_init);
1925 create_root_dir(fs);
1926 create_lost_and_found(fs);
1928 create_bad_block_inode(fs, bb_list);
1929 if (fs->super->s_feature_compat &
1930 EXT2_FEATURE_COMPAT_RESIZE_INODE) {
1931 retval = ext2fs_create_resize_inode(fs);
1933 com_err("ext2fs_create_resize_inode", retval,
1934 _("while reserving blocks for online resize"));
1940 if (journal_device) {
1944 check_plausibility(journal_device);
1945 check_mount(journal_device, force, _("journal"));
1947 retval = ext2fs_open(journal_device, EXT2_FLAG_RW|
1948 EXT2_FLAG_JOURNAL_DEV_OK, 0,
1949 fs->blocksize, unix_io_manager, &jfs);
1951 com_err(program_name, retval,
1952 _("while trying to open journal device %s\n"),
1957 printf(_("Adding journal to device %s: "),
1961 retval = ext2fs_add_journal_device(fs, jfs);
1963 com_err (program_name, retval,
1964 _("\n\twhile trying to add journal to device %s"),
1969 printf(_("done\n"));
1971 free(journal_device);
1972 } else if ((journal_size) ||
1973 (fs_param.s_feature_compat &
1974 EXT3_FEATURE_COMPAT_HAS_JOURNAL)) {
1975 journal_blocks = figure_journal_size(journal_size, fs);
1977 if (!journal_blocks) {
1978 fs->super->s_feature_compat &=
1979 ~EXT3_FEATURE_COMPAT_HAS_JOURNAL;
1983 printf(_("Creating journal (%u blocks): "),
1987 retval = ext2fs_add_journal_inode(fs, journal_blocks,
1990 com_err (program_name, retval,
1991 _("\n\twhile trying to create journal"));
1995 printf(_("done\n"));
2000 printf(_("Writing superblocks and "
2001 "filesystem accounting information: "));
2002 retval = ext2fs_flush(fs);
2005 _("\nWarning, had trouble writing out superblocks."));
2008 printf(_("done\n\n"));
2009 if (!getenv("MKE2FS_SKIP_CHECK_MSG"))
2010 print_check_message(fs);
2012 val = ext2fs_close(fs);
2013 remove_error_table(&et_ext2_error_table);
2014 remove_error_table(&et_prof_error_table);
2015 profile_release(profile);
2016 return (retval || val) ? 1 : 0;