2 * mke2fs.c - Make a ext2fs filesystem.
4 * Copyright (C) 1994, 1995, 1996, 1997 Theodore Ts'o.
7 * This file may be redistributed under the terms of the GNU Public
12 /* Usage: mke2fs [options] device
14 * The device may be a block device or a image of one, but this isn't
15 * enforced (but it's not much fun on a character device :-).
24 #include <sys/utsname.h>
44 #include <sys/ioctl.h>
45 #include <sys/types.h>
47 #include <linux/ext2_fs.h>
48 #ifdef HAVE_LINUX_MAJOR_H
49 #include <linux/major.h>
50 #include <sys/stat.h> /* Only need sys/stat.h for major nr test */
53 #include "et/com_err.h"
54 #include "uuid/uuid.h"
56 #include "ext2fs/ext2fs.h"
57 #include "../version.h"
58 #include "nls-enable.h"
60 /* Everything is STDC, these days */
63 #define STRIDE_LENGTH 8
69 extern int isatty(int);
70 extern FILE *fpopen(const char *cmd, const char *mode);
72 const char * program_name = "mke2fs";
73 const char * device_name /* = NULL */;
75 /* Command line options */
77 int verbose /* = 0 */ ;
79 int super_only /* = 0 */ ;
81 int noaction /* = 0 */ ;
82 int journal_size /* = 0 */ ;
83 int journal_flags /* = 0 */ ;
84 char *bad_blocks_filename /* = 0 */ ;
85 __u32 fs_stride /* = 0 */ ;
87 struct ext2_super_block param;
88 char *creator_os /* = NULL */ ;
89 char *volume_label /* = NULL */ ;
90 char *mount_dir /* = NULL */ ;
91 char *journal_device /* = NULL */ ;
93 static void usage(NOARGS);
94 static void check_plausibility(const char *device);
95 static void check_mount(const char *device);
97 static void usage(NOARGS)
99 fprintf(stderr, _("Usage: %s [-c|-t|-l filename] [-b block-size] "
100 "[-f fragment-size]\n\t[-i bytes-per-inode] [-j journal-options]"
101 " [-N number-of-inodes]\n\t[-m reserved-blocks-percentage] "
102 "[-o creator-os] [-g blocks-per-group]\n\t[-L volume-label] "
103 "[-M last-mounted-directory] [-O feature[,...]]\n\t"
104 "[-r fs-revision] [-R raid_opts] [-s sparse-super-flag]\n\t"
105 "[-qvSV] device [blocks-count]\n"),
110 static int int_log2(int arg)
122 static int int_log10(unsigned int arg)
131 static void proceed_question(NOARGS)
134 char *short_yes = _("yY");
138 printf(_("Proceed anyway? (y,n) "));
140 fgets(buf, sizeof(buf), stdin);
141 if (strchr(short_yes, buf[0]) == 0)
145 #ifndef SCSI_BLK_MAJOR
146 #define SCSI_BLK_MAJOR(M) ((M) == SCSI_DISK_MAJOR || (M) == SCSI_CDROM_MAJOR)
149 static void check_plausibility(const char *device)
151 #ifdef HAVE_LINUX_MAJOR_H
153 #define MAJOR(dev) ((dev)>>8)
154 #define MINOR(dev) ((dev) & 0xff)
160 val = stat(device, &s);
163 fprintf(stderr, _("Could not stat %s --- %s\n"),
164 device, error_message(errno));
166 fprintf(stderr, _("\nThe device apparently does "
167 "not exist; did you specify it correctly?\n"));
170 if(!S_ISBLK(s.st_mode)) {
171 printf(_("%s is not a block special device.\n"), device);
174 } else if ((MAJOR(s.st_rdev) == HD_MAJOR &&
175 MINOR(s.st_rdev)%64 == 0) ||
176 (SCSI_BLK_MAJOR(MAJOR(s.st_rdev)) &&
177 MINOR(s.st_rdev)%16 == 0)) {
178 printf(_("%s is entire device, not just one partition!\n"),
185 static void check_mount(const char *device)
190 retval = ext2fs_check_if_mounted(device, &mount_flags);
192 com_err("ext2fs_check_if_mount", retval,
193 _("while determining whether %s is mounted."),
197 if (!(mount_flags & EXT2_MF_MOUNTED))
200 fprintf(stderr, _("%s is mounted; "), device);
202 fprintf(stderr, _("mke2fs forced anyway. "
203 "Hope /etc/mtab is incorrect.\n"));
205 fprintf(stderr, _("will not make a filesystem here!\n"));
211 * This function sets the default parameters for a filesystem
213 * The type is specified by the user. The size is the maximum size
214 * (in megabytes) for which a set of parameters applies, with a size
215 * of zero meaning that it is the default parameter for the type.
216 * Note that order is important in the table below.
218 static char default_str[] = "default";
219 struct mke2fs_defaults {
225 { default_str, 0, 4096, 8192 },
226 { default_str, 512, 1024, 4096 },
227 { default_str, 3, 1024, 8192 },
228 { "news", 0, 4096, 4096 },
232 static void set_fs_defaults(char *fs_type, struct ext2fs_sb *super,
233 int blocksize, int *inode_ratio)
237 struct mke2fs_defaults *p;
239 megs = (super->s_blocks_count * (EXT2_BLOCK_SIZE(super) / 1024) /
242 ratio = *inode_ratio;
244 fs_type = default_str;
245 for (p = settings; p->type; p++) {
246 if ((strcmp(p->type, fs_type) != 0) &&
247 (strcmp(p->type, default_str) != 0))
249 if ((p->size != 0) &&
253 *inode_ratio = p->inode_ratio;
254 if (blocksize == 0) {
255 super->s_log_frag_size = super->s_log_block_size =
256 int_log2(p->blocksize >> EXT2_MIN_BLOCK_LOG_SIZE);
260 super->s_blocks_count /= EXT2_BLOCK_SIZE(super) / 1024;
264 * Helper function for read_bb_file and test_disk
266 static void invalid_block(ext2_filsys fs, blk_t blk)
268 printf(_("Bad block %u out of range; ignored.\n"), blk);
273 * Reads the bad blocks list from a file
275 static void read_bb_file(ext2_filsys fs, badblocks_list *bb_list,
276 const char *bad_blocks_file)
281 f = fopen(bad_blocks_file, "r");
283 com_err("read_bad_blocks_file", errno,
284 _("while trying to open %s"), bad_blocks_file);
287 retval = ext2fs_read_bb_FILE(fs, f, bb_list, invalid_block);
290 com_err("ext2fs_read_bb_FILE", retval,
291 _("while reading in list of bad blocks from file"));
297 * Runs the badblocks program to test the disk
299 static void test_disk(ext2_filsys fs, badblocks_list *bb_list)
305 sprintf(buf, "badblocks -b %d %s%s %d", fs->blocksize,
306 quiet ? "" : "-s ", fs->device_name,
307 fs->super->s_blocks_count);
309 printf(_("Running command: %s\n"), buf);
312 com_err("popen", errno,
313 _("while trying run '%s'"), buf);
316 retval = ext2fs_read_bb_FILE(fs, f, bb_list, invalid_block);
319 com_err("ext2fs_read_bb_FILE", retval,
320 _("while processing list of bad blocks from program"));
325 static void handle_bad_blocks(ext2_filsys fs, badblocks_list bb_list)
330 badblocks_iterate bb_iter;
340 * The primary superblock and group descriptors *must* be
341 * good; if not, abort.
343 must_be_good = fs->super->s_first_data_block + 1 + fs->desc_blocks;
344 for (i = fs->super->s_first_data_block; i <= must_be_good; i++) {
345 if (badblocks_list_test(bb_list, i)) {
346 fprintf(stderr, _("Block %d in primary "
347 "superblock/group descriptor area bad.\n"), i);
348 fprintf(stderr, _("Blocks %d through %d must be good "
349 "in order to build a filesystem.\n"),
350 fs->super->s_first_data_block, must_be_good);
351 fprintf(stderr, _("Aborting....\n"));
357 * See if any of the bad blocks are showing up in the backup
358 * superblocks and/or group descriptors. If so, issue a
359 * warning and adjust the block counts appropriately.
361 group_block = fs->super->s_first_data_block +
362 fs->super->s_blocks_per_group;
364 for (i = 1; i < fs->group_desc_count; i++) {
366 for (j=0; j < fs->desc_blocks+1; j++) {
367 if (badblocks_list_test(bb_list, group_block +
371 _("Warning: the backup superblock/group descriptors at block %d contain\n"
375 group = ext2fs_group_of_blk(fs, group_block+j);
376 fs->group_desc[group].bg_free_blocks_count++;
377 fs->super->s_free_blocks_count++;
380 group_block += fs->super->s_blocks_per_group;
384 * Mark all the bad blocks as used...
386 retval = badblocks_list_iterate_begin(bb_list, &bb_iter);
388 com_err("badblocks_list_iterate_begin", retval,
389 _("while marking bad blocks as used"));
392 while (badblocks_list_iterate(bb_iter, &blk))
393 ext2fs_mark_block_bitmap(fs->block_map, blk);
394 badblocks_list_iterate_end(bb_iter);
397 static void write_inode_tables(ext2_filsys fs)
401 int i, j, num, count;
403 char format[20], backup[80];
407 mke2fs_sync = getenv("MKE2FS_SYNC");
409 sync_kludge = atoi(mke2fs_sync);
411 buf = malloc(fs->blocksize * STRIDE_LENGTH);
413 com_err("malloc", ENOMEM,
414 _("while allocating zeroizing buffer"));
417 memset(buf, 0, fs->blocksize * STRIDE_LENGTH);
420 * Figure out how many digits we need
422 i = int_log10(fs->group_desc_count);
423 sprintf(format, "%%%dd/%%%dld", i, i);
424 memset(backup, '\b', sizeof(backup)-1);
425 backup[sizeof(backup)-1] = 0;
426 if ((2*i)+1 < sizeof(backup))
430 printf(_("Writing inode tables: "));
431 for (i = 0; i < fs->group_desc_count; i++) {
433 printf(format, i, fs->group_desc_count);
435 blk = fs->group_desc[i].bg_inode_table;
436 num = fs->inode_blocks_per_group;
438 for (j=0; j < num; j += STRIDE_LENGTH, blk += STRIDE_LENGTH) {
439 if (num-j > STRIDE_LENGTH)
440 count = STRIDE_LENGTH;
443 retval = io_channel_write_blk(fs->io, blk, count, buf);
445 printf(_("Warning: could not write %d blocks "
446 "in inode table starting at %d: %s\n"),
447 count, blk, error_message(retval));
450 fputs(backup, stdout);
452 if (sync_kludge == 1)
454 else if ((i % sync_kludge) == 0)
460 fputs(_("done \n"), stdout);
463 static void create_root_dir(ext2_filsys fs)
466 struct ext2_inode inode;
468 retval = ext2fs_mkdir(fs, EXT2_ROOT_INO, EXT2_ROOT_INO, 0);
470 com_err("ext2fs_mkdir", retval, _("while creating root dir"));
474 retval = ext2fs_read_inode(fs, EXT2_ROOT_INO, &inode);
476 com_err("ext2fs_read_inode", retval,
477 _("while reading root inode"));
480 inode.i_uid = getuid();
482 inode.i_gid = getgid();
483 retval = ext2fs_write_inode(fs, EXT2_ROOT_INO, &inode);
485 com_err("ext2fs_write_inode", retval,
486 _("while setting root inode ownership"));
492 static void create_lost_and_found(ext2_filsys fs)
496 const char *name = "lost+found";
500 retval = ext2fs_mkdir(fs, EXT2_ROOT_INO, 0, name);
502 com_err("ext2fs_mkdir", retval,
503 _("while creating /lost+found"));
507 retval = ext2fs_lookup(fs, EXT2_ROOT_INO, name, strlen(name), 0, &ino);
509 com_err("ext2_lookup", retval,
510 _("while looking up /lost+found"));
514 for (i=1; i < EXT2_NDIR_BLOCKS; i++) {
515 if ((lpf_size += fs->blocksize) >= 16*1024)
517 retval = ext2fs_expand_dir(fs, ino);
519 com_err("ext2fs_expand_dir", retval,
520 _("while expanding /lost+found"));
526 static void create_bad_block_inode(ext2_filsys fs, badblocks_list bb_list)
530 ext2fs_mark_inode_bitmap(fs->inode_map, EXT2_BAD_INO);
531 fs->group_desc[0].bg_free_inodes_count--;
532 fs->super->s_free_inodes_count--;
533 retval = ext2fs_update_bb_inode(fs, bb_list);
535 com_err("ext2fs_update_bb_inode", retval,
536 _("while setting bad block inode"));
542 static void reserve_inodes(ext2_filsys fs)
547 for (i = EXT2_ROOT_INO + 1; i < EXT2_FIRST_INODE(fs->super); i++) {
548 ext2fs_mark_inode_bitmap(fs->inode_map, i);
549 group = ext2fs_group_of_ino(fs, i);
550 fs->group_desc[group].bg_free_inodes_count--;
551 fs->super->s_free_inodes_count--;
553 ext2fs_mark_ib_dirty(fs);
556 static void zap_sector(ext2_filsys fs, int sect)
563 io_channel_set_blksize(fs->io, 512);
564 retval = io_channel_write_blk(fs->io, sect, -512, buf);
565 io_channel_set_blksize(fs->io, fs->blocksize);
567 printf(_("Warning: could not erase sector %d: %s\n"), sect,
568 error_message(retval));
572 static void show_stats(ext2_filsys fs)
574 struct ext2fs_sb *s = (struct ext2fs_sb *) fs->super;
577 int i, need, col_left;
579 if (param.s_blocks_count != s->s_blocks_count)
580 printf(_("warning: %d blocks unused.\n\n"),
581 param.s_blocks_count - s->s_blocks_count);
583 memset(buf, 0, sizeof(buf));
584 strncpy(buf, s->s_volume_name, sizeof(s->s_volume_name));
585 printf(_("Filesystem label=%s\n"), buf);
586 printf(_("OS type: "));
587 switch (fs->super->s_creator_os) {
588 case EXT2_OS_LINUX: printf ("Linux"); break;
589 case EXT2_OS_HURD: printf ("GNU/Hurd"); break;
590 case EXT2_OS_MASIX: printf ("Masix"); break;
591 default: printf (_("(unknown os)"));
594 printf(_("Block size=%u (log=%u)\n"), fs->blocksize,
595 s->s_log_block_size);
596 printf(_("Fragment size=%u (log=%u)\n"), fs->fragsize,
598 printf(_("%u inodes, %u blocks\n"), s->s_inodes_count,
600 printf(_("%u blocks (%2.2f%%) reserved for the super user\n"),
602 100.0 * s->s_r_blocks_count / s->s_blocks_count);
603 printf(_("First data block=%u\n"), s->s_first_data_block);
604 if (fs->group_desc_count > 1)
605 printf(_("%lu block groups\n"), fs->group_desc_count);
607 printf(_("%lu block group\n"), fs->group_desc_count);
608 printf(_("%u blocks per group, %u fragments per group\n"),
609 s->s_blocks_per_group, s->s_frags_per_group);
610 printf(_("%u inodes per group\n"), s->s_inodes_per_group);
612 if (fs->group_desc_count == 1) {
617 printf(_("Superblock backups stored on blocks: "));
618 group_block = s->s_first_data_block;
620 for (i = 1; i < fs->group_desc_count; i++) {
621 group_block += s->s_blocks_per_group;
622 if (!ext2fs_bg_has_super(fs, i))
626 need = int_log10(group_block) + 2;
627 if (need > col_left) {
632 printf("%u", group_block);
637 #ifndef HAVE_STRCASECMP
638 static int strcasecmp (char *s1, char *s2)
641 int ch1 = *s1++, ch2 = *s2++;
649 return *s1 ? 1 : *s2 ? -1 : 0;
654 * Set the S_CREATOR_OS field. Return true if OS is known,
657 static int set_os(struct ext2_super_block *sb, char *os)
660 sb->s_creator_os = atoi (os);
661 else if (strcasecmp(os, "linux") == 0)
662 sb->s_creator_os = EXT2_OS_LINUX;
663 else if (strcasecmp(os, "GNU") == 0 || strcasecmp(os, "hurd") == 0)
664 sb->s_creator_os = EXT2_OS_HURD;
665 else if (strcasecmp(os, "masix") == 0)
666 sb->s_creator_os = EXT2_OS_MASIX;
672 #define PATH_SET "PATH=/sbin"
674 static void parse_raid_opts(const char *opts)
676 char *buf, *token, *next, *p, *arg;
683 fprintf(stderr, _("Couldn't allocate memory to parse "
688 for (token = buf; token && *token; token = next) {
689 p = strchr(token, ',');
695 arg = strchr(token, '=');
700 if (strcmp(token, "stride") == 0) {
705 fs_stride = strtoul(arg, &p, 0);
706 if (*p || (fs_stride == 0)) {
708 _("Invalid stride parameter.\n"));
716 fprintf(stderr, _("\nBad raid options specified.\n\n"
717 "Raid options are separated by commas, "
718 "and may take an argument which\n"
719 "\tis set off by an equals ('=') sign.\n\n"
720 "Valid raid options are:\n"
721 "\tstride=<stride length in blocks>\n\n"));
726 static void parse_journal_opts(const char *opts)
728 char *buf, *token, *next, *p, *arg;
730 int journal_usage = 0;
735 fprintf(stderr, _("Couldn't allocate memory to parse "
736 "journal options!\n"));
740 for (token = buf; token && *token; token = next) {
741 p = strchr(token, ',');
747 arg = strchr(token, '=');
752 printf("Journal option=%s, argument=%s\n", token,
754 if (strcmp(token, "device") == 0) {
759 journal_device = arg;
760 } else if (strcmp(token, "size") == 0) {
765 journal_size = strtoul(arg, &p, 0);
767 if (*p || (journal_size < 4 || journal_size > 100)) {
769 _("Invalid journal size parameter - %s.\n"),
774 } else if (strcmp(token, "v1_superblock") == 0) {
775 journal_flags |= EXT2_MKJOURNAL_V1_SUPER;
778 journal_size = strtoul(token, &p, 0);
782 goto journal_size_check;
786 fprintf(stderr, _("\nBad journal options specified.\n\n"
787 "Journal options are separated by commas, "
788 "and may take an argument which\n"
789 "\tis set off by an equals ('=') sign.\n\n"
790 "Valid raid options are:\n"
791 "\tsize=<journal size in megabytes>\n"
792 "\tdevice=<journal device>\n\n"
793 "Journal size must be between "
794 "4 and 100 megabytes.\n\n" ));
799 static __u32 ok_features[3] = {
801 EXT2_FEATURE_INCOMPAT_FILETYPE, /* Incompat */
802 EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER /* R/O compat */
806 static void PRS(int argc, char *argv[])
811 blk_t group_blk_max = 8192;
814 int reserved_ratio = 5;
815 ino_t num_inodes = 0;
817 int sparse_option = 1;
818 char * oldpath = getenv("PATH");
819 struct ext2fs_sb *param_ext2 = (struct ext2fs_sb *) ¶m;
820 char * raid_opts = 0;
821 char * journal_opts = 0;
823 const char * feature_set = "filetype";
832 if ((ut.release[0] == '1') ||
833 (ut.release[0] == '2' && ut.release[1] == '.' &&
834 ut.release[2] < '2' && ut.release[3] == '.'))
837 /* Update our PATH to include /sbin */
841 newpath = malloc(sizeof (PATH_SET) + 1 + strlen (oldpath));
842 strcpy (newpath, PATH_SET);
843 strcat (newpath, ":");
844 strcat (newpath, oldpath);
849 setbuf(stdout, NULL);
850 setbuf(stderr, NULL);
851 initialize_ext2_error_table();
852 memset(¶m, 0, sizeof(struct ext2_super_block));
853 param.s_rev_level = 1; /* Create revision 1 filesystems now */
855 fprintf (stderr, _("mke2fs %s, %s for EXT2 FS %s, %s\n"),
856 E2FSPROGS_VERSION, E2FSPROGS_DATE,
857 EXT2FS_VERSION, EXT2FS_DATE);
859 program_name = *argv;
860 while ((c = getopt (argc, argv,
861 "b:cf:g:i:j:l:m:no:qr:R:s:tvI:ST:FL:M:N:O:V")) != EOF)
864 blocksize = strtoul(optarg, &tmp, 0);
865 if (blocksize < 1024 || blocksize > 4096 || *tmp) {
866 com_err(program_name, 0,
867 _("bad block size - %s"), optarg);
870 param.s_log_block_size =
871 int_log2(blocksize >> EXT2_MIN_BLOCK_LOG_SIZE);
872 group_blk_max = blocksize * 8;
875 case 't': /* Check for bad blocks */
879 size = strtoul(optarg, &tmp, 0);
880 if (size < 1024 || size > 4096 || *tmp) {
881 com_err(program_name, 0,
882 _("bad fragment size - %s"),
886 param.s_log_frag_size =
887 int_log2(size >> EXT2_MIN_BLOCK_LOG_SIZE);
888 printf(_("Warning: fragments not supported. "
889 "Ignoring -f option\n"));
892 param.s_blocks_per_group = strtoul(optarg, &tmp, 0);
894 com_err(program_name, 0,
895 _("Illegal number for blocks per group"));
898 if ((param.s_blocks_per_group % 8) != 0) {
899 com_err(program_name, 0,
900 _("blocks per group must be multiple of 8"));
905 inode_ratio = strtoul(optarg, &tmp, 0);
906 if (inode_ratio < 1024 || inode_ratio > 256 * 1024 ||
908 com_err(program_name, 0,
909 _("bad inode ratio - %s"), optarg);
914 journal_opts = optarg;
917 bad_blocks_filename = malloc(strlen(optarg)+1);
918 if (!bad_blocks_filename) {
919 com_err(program_name, ENOMEM,
920 _("in malloc for bad_blocks_filename"));
923 strcpy(bad_blocks_filename, optarg);
926 reserved_ratio = strtoul(optarg, &tmp, 0);
927 if (reserved_ratio > 50 || *tmp) {
928 com_err(program_name, 0,
929 _("bad reserved blocks percent - %s"),
941 param.s_rev_level = atoi(optarg);
944 sparse_option = atoi(optarg);
946 #ifdef EXT2_DYNAMIC_REV
948 param.s_inode_size = atoi(optarg);
952 num_inodes = atoi(optarg);
964 volume_label = optarg;
970 feature_set = optarg;
982 /* Print version number and exit */
983 fprintf(stderr, _("\tUsing %s\n"),
984 error_message(EXT2_ET_BASE));
991 device_name = argv[optind];
994 unsigned long tmp2 = strtoul(argv[optind++], &tmp, 0);
996 if ((*tmp) || (tmp2 > 0xfffffffful)) {
997 com_err(program_name, 0, _("bad blocks count - %s"),
1001 param.s_blocks_count = tmp2;
1007 parse_raid_opts(raid_opts);
1010 parse_journal_opts(journal_opts);
1013 check_plausibility(device_name);
1014 check_mount(device_name);
1016 param.s_log_frag_size = param.s_log_block_size;
1018 if (noaction && param.s_blocks_count) {
1019 dev_size = param.s_blocks_count;
1022 retval = ext2fs_get_device_size(device_name,
1023 EXT2_BLOCK_SIZE(¶m),
1025 if (retval && (retval != EXT2_ET_UNIMPLEMENTED)) {
1026 com_err(program_name, retval,
1027 _("while trying to determine filesystem size"));
1030 if (!param.s_blocks_count) {
1031 if (retval == EXT2_ET_UNIMPLEMENTED) {
1032 com_err(program_name, 0,
1033 _("Couldn't determine device size; you "
1034 "must specify\nthe size of the "
1038 if (dev_size == 0) {
1039 com_err(program_name, 0,
1040 _("Device size reported to be zero. "
1041 "Invalid partition specified, or\n\t"
1042 "partition table wasn't reread "
1043 "after running fdisk, due to\n\t"
1044 "a modified partition being busy "
1045 "and in use. You may need to reboot\n\t"
1046 "to re-read your partition table.\n"
1050 param.s_blocks_count = dev_size;
1053 } else if (!force && (param.s_blocks_count > dev_size)) {
1054 com_err(program_name, 0,
1055 _("Filesystem larger than apparent filesystem size."));
1059 set_fs_defaults(fs_type, param_ext2, blocksize, &inode_ratio);
1061 if (param.s_blocks_per_group) {
1062 if (param.s_blocks_per_group < 256 ||
1063 param.s_blocks_per_group > group_blk_max || *tmp) {
1064 com_err(program_name, 0,
1065 _("blocks per group count out of range"));
1071 * Calculate number of inodes based on the inode ratio
1073 param.s_inodes_count = num_inodes ? num_inodes :
1074 ((__u64) param.s_blocks_count * EXT2_BLOCK_SIZE(¶m))
1078 * Calculate number of blocks to reserve
1080 param.s_r_blocks_count = (param.s_blocks_count * reserved_ratio) / 100;
1082 /* Turn off features not supported by the earlier filesystem version */
1083 if (param.s_rev_level == 0) {
1088 param_ext2->s_feature_ro_compat |=
1089 EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER;
1091 if (feature_set && !strncasecmp(feature_set, "none", 4))
1093 if (feature_set && e2p_edit_feature(feature_set,
1094 ¶m_ext2->s_feature_compat,
1096 fprintf(stderr, _("Invalid filesystem option set: %s\n"),
1102 int main (int argc, char *argv[])
1104 errcode_t retval = 0;
1106 badblocks_list bb_list = 0;
1108 struct ext2fs_sb *s;
1111 setlocale(LC_MESSAGES, "");
1112 bindtextdomain(NLS_CAT_NAME, LOCALEDIR);
1113 textdomain(NLS_CAT_NAME);
1118 * Initialize the superblock....
1120 retval = ext2fs_initialize(device_name, 0, ¶m,
1121 unix_io_manager, &fs);
1123 com_err(device_name, retval, _("while setting up superblock"));
1128 * Wipe out the old on-disk superblock
1133 * Generate a UUID for it...
1135 s = (struct ext2fs_sb *) fs->super;
1136 uuid_generate(s->s_uuid);
1139 * Override the creator OS, if applicable
1141 if (creator_os && !set_os(fs->super, creator_os)) {
1142 com_err (program_name, 0, _("unknown os - %s"), creator_os);
1147 * For the Hurd, we will turn off filetype since it doesn't
1150 if (fs->super->s_creator_os == EXT2_OS_HURD)
1151 fs->super->s_feature_incompat &=
1152 ~EXT2_FEATURE_INCOMPAT_FILETYPE;
1155 * Set the volume label...
1158 memset(s->s_volume_name, 0, sizeof(s->s_volume_name));
1159 strncpy(s->s_volume_name, volume_label,
1160 sizeof(s->s_volume_name));
1164 * Set the last mount directory
1167 memset(s->s_last_mounted, 0, sizeof(s->s_last_mounted));
1168 strncpy(s->s_last_mounted, mount_dir,
1169 sizeof(s->s_last_mounted));
1172 if (!quiet || noaction)
1178 if (bad_blocks_filename)
1179 read_bb_file(fs, &bb_list, bad_blocks_filename);
1181 test_disk(fs, &bb_list);
1183 handle_bad_blocks(fs, bb_list);
1184 fs->stride = fs_stride;
1185 retval = ext2fs_allocate_tables(fs);
1187 com_err(program_name, retval,
1188 _("while trying to allocate filesystem tables"));
1192 fs->super->s_state |= EXT2_ERROR_FS;
1193 fs->flags &= ~(EXT2_FLAG_IB_DIRTY|EXT2_FLAG_BB_DIRTY);
1195 write_inode_tables(fs);
1196 create_root_dir(fs);
1197 create_lost_and_found(fs);
1199 create_bad_block_inode(fs, bb_list);
1200 #ifdef ZAP_BOOTBLOCK
1205 journal_blocks = journal_size * 1024 / (fs->blocksize / 1024);
1206 if (journal_device) {
1208 check_plausibility(journal_device);
1209 check_mount(journal_device);
1212 printf(_("Creating journal on device %s: "),
1214 retval = ext2fs_add_journal_device(fs, journal_device,
1218 com_err (program_name, retval,
1219 _("while trying to create journal on device %s"),
1224 printf(_("done\n"));
1225 } else if (journal_size) {
1227 printf(_("Creating journal (%d blocks): "),
1229 retval = ext2fs_add_journal_fs(fs, journal_blocks,
1232 com_err (program_name, retval,
1233 _("while trying to create journal"));
1237 printf(_("done\n"));
1241 printf(_("Writing superblocks and "
1242 "filesystem accounting information: "));
1243 retval = ext2fs_flush(fs);
1245 printf(_("\nWarning, had trouble writing out superblocks."));
1248 printf(_("done\n"));