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 */
83 char *bad_blocks_filename = 0;
86 struct ext2_super_block param;
87 char *creator_os = NULL;
88 char *volume_label = NULL;
89 char *mount_dir = NULL;
91 static void usage(NOARGS), check_plausibility(NOARGS), check_mount(NOARGS);
93 static void usage(NOARGS)
95 fprintf(stderr, _("Usage: %s [-c|-t|-l filename] [-b block-size] "
96 "[-f fragment-size]\n\t[-i bytes-per-inode] "
97 " [-N number-of-inodes]\n\t[-m reserved-blocks-percentage] "
98 "[-o creator-os] [-g blocks-per-group]\n\t[-L volume-label] "
99 "[-M last-mounted-directory] [-O feature[,...]]\n\t"
100 "[-r fs-revision] [-R raid_opts] [-s sparse-super-flag]\n\t"
101 "[-qvSV] device [blocks-count]\n"),
106 static int int_log2(int arg)
118 static int int_log10(unsigned int arg)
127 static void proceed_question(NOARGS)
130 char *short_yes = _("yY");
134 printf(_("Proceed anyway? (y,n) "));
136 fgets(buf, sizeof(buf), stdin);
137 if (strchr(short_yes, buf[0]) == 0)
141 #ifndef SCSI_BLK_MAJOR
142 #define SCSI_BLK_MAJOR(M) ((M) == SCSI_DISK_MAJOR || (M) == SCSI_CDROM_MAJOR)
145 static void check_plausibility(NOARGS)
147 #ifdef HAVE_LINUX_MAJOR_H
149 #define MAJOR(dev) ((dev)>>8)
150 #define MINOR(dev) ((dev) & 0xff)
156 val = stat(device_name, &s);
159 fprintf(stderr, _("Could not stat %s --- %s\n"),
160 device_name, error_message(errno));
162 fprintf(stderr, _("\nThe device apparently does "
163 "not exist; did you specify it correctly?\n"));
166 if(!S_ISBLK(s.st_mode)) {
167 printf(_("%s is not a block special device.\n"), device_name);
170 } else if ((MAJOR(s.st_rdev) == HD_MAJOR &&
171 MINOR(s.st_rdev)%64 == 0) ||
172 (SCSI_BLK_MAJOR(MAJOR(s.st_rdev)) &&
173 MINOR(s.st_rdev)%16 == 0)) {
174 printf(_("%s is entire device, not just one partition!\n"),
181 static void check_mount(NOARGS)
186 retval = ext2fs_check_if_mounted(device_name, &mount_flags);
188 com_err("ext2fs_check_if_mount", retval,
189 _("while determining whether %s is mounted."),
193 if (!(mount_flags & EXT2_MF_MOUNTED))
196 fprintf(stderr, _("%s is mounted; "), device_name);
198 fprintf(stderr, _("mke2fs forced anyway. "
199 "Hope /etc/mtab is incorrect.\n"));
201 fprintf(stderr, _("will not make a filesystem here!\n"));
207 * This function sets the default parameters for a filesystem
209 * The type is specified by the user. The size is the maximum size
210 * (in megabytes) for which a set of parameters applies, with a size
211 * of zero meaning that it is the default parameter for the type.
212 * Note that order is important in the table below.
214 static char default_str[] = "default";
215 struct mke2fs_defaults {
221 { default_str, 0, 4096, 8192 },
222 { default_str, 512, 1024, 4096 },
223 { default_str, 3, 1024, 8192 },
224 { "news", 0, 4096, 4096 },
228 static void set_fs_defaults(char *fs_type, struct ext2fs_sb *super,
229 int blocksize, int *inode_ratio)
233 struct mke2fs_defaults *p;
235 megs = (super->s_blocks_count * (EXT2_BLOCK_SIZE(super) / 1024) /
238 ratio = *inode_ratio;
240 fs_type = default_str;
241 for (p = settings; p->type; p++) {
242 if ((strcmp(p->type, fs_type) != 0) &&
243 (strcmp(p->type, default_str) != 0))
245 if ((p->size != 0) &&
249 *inode_ratio = p->inode_ratio;
250 if (blocksize == 0) {
251 super->s_log_frag_size = super->s_log_block_size =
252 int_log2(p->blocksize >> EXT2_MIN_BLOCK_LOG_SIZE);
256 super->s_blocks_count /= EXT2_BLOCK_SIZE(super) / 1024;
260 * Helper function for read_bb_file and test_disk
262 static void invalid_block(ext2_filsys fs, blk_t blk)
264 printf(_("Bad block %u out of range; ignored.\n"), blk);
269 * Reads the bad blocks list from a file
271 static void read_bb_file(ext2_filsys fs, badblocks_list *bb_list,
272 const char *bad_blocks_file)
277 f = fopen(bad_blocks_file, "r");
279 com_err("read_bad_blocks_file", errno,
280 _("while trying to open %s"), bad_blocks_file);
283 retval = ext2fs_read_bb_FILE(fs, f, bb_list, invalid_block);
286 com_err("ext2fs_read_bb_FILE", retval,
287 _("while reading in list of bad blocks from file"));
293 * Runs the badblocks program to test the disk
295 static void test_disk(ext2_filsys fs, badblocks_list *bb_list)
301 sprintf(buf, "badblocks -b %d %s%s %d", fs->blocksize,
302 quiet ? "" : "-s ", fs->device_name,
303 fs->super->s_blocks_count);
305 printf(_("Running command: %s\n"), buf);
308 com_err("popen", errno,
309 _("while trying run '%s'"), buf);
312 retval = ext2fs_read_bb_FILE(fs, f, bb_list, invalid_block);
315 com_err("ext2fs_read_bb_FILE", retval,
316 _("while processing list of bad blocks from program"));
321 static void handle_bad_blocks(ext2_filsys fs, badblocks_list bb_list)
326 badblocks_iterate bb_iter;
336 * The primary superblock and group descriptors *must* be
337 * good; if not, abort.
339 must_be_good = fs->super->s_first_data_block + 1 + fs->desc_blocks;
340 for (i = fs->super->s_first_data_block; i <= must_be_good; i++) {
341 if (badblocks_list_test(bb_list, i)) {
342 fprintf(stderr, _("Block %d in primary "
343 "superblock/group descriptor area bad.\n"), i);
344 fprintf(stderr, _("Blocks %d through %d must be good "
345 "in order to build a filesystem.\n"),
346 fs->super->s_first_data_block, must_be_good);
347 fprintf(stderr, _("Aborting....\n"));
353 * See if any of the bad blocks are showing up in the backup
354 * superblocks and/or group descriptors. If so, issue a
355 * warning and adjust the block counts appropriately.
357 group_block = fs->super->s_first_data_block +
358 fs->super->s_blocks_per_group;
360 for (i = 1; i < fs->group_desc_count; i++) {
362 for (j=0; j < fs->desc_blocks+1; j++) {
363 if (badblocks_list_test(bb_list, group_block +
367 _("Warning: the backup superblock/group descriptors at block %d contain\n"
371 group = ext2fs_group_of_blk(fs, group_block+j);
372 fs->group_desc[group].bg_free_blocks_count++;
373 fs->super->s_free_blocks_count++;
376 group_block += fs->super->s_blocks_per_group;
380 * Mark all the bad blocks as used...
382 retval = badblocks_list_iterate_begin(bb_list, &bb_iter);
384 com_err("badblocks_list_iterate_begin", retval,
385 _("while marking bad blocks as used"));
388 while (badblocks_list_iterate(bb_iter, &blk))
389 ext2fs_mark_block_bitmap(fs->block_map, blk);
390 badblocks_list_iterate_end(bb_iter);
393 static void write_inode_tables(ext2_filsys fs)
397 int i, j, num, count;
399 char format[20], backup[80];
403 mke2fs_sync = getenv("MKE2FS_SYNC");
405 sync_kludge = atoi(mke2fs_sync);
407 buf = malloc(fs->blocksize * STRIDE_LENGTH);
409 com_err("malloc", ENOMEM,
410 _("while allocating zeroizing buffer"));
413 memset(buf, 0, fs->blocksize * STRIDE_LENGTH);
416 * Figure out how many digits we need
418 i = int_log10(fs->group_desc_count);
419 sprintf(format, "%%%dd/%%%dld", i, i);
420 memset(backup, '\b', sizeof(backup)-1);
421 backup[sizeof(backup)-1] = 0;
422 if ((2*i)+1 < sizeof(backup))
426 printf(_("Writing inode tables: "));
427 for (i = 0; i < fs->group_desc_count; i++) {
429 printf(format, i, fs->group_desc_count);
431 blk = fs->group_desc[i].bg_inode_table;
432 num = fs->inode_blocks_per_group;
434 for (j=0; j < num; j += STRIDE_LENGTH, blk += STRIDE_LENGTH) {
435 if (num-j > STRIDE_LENGTH)
436 count = STRIDE_LENGTH;
439 retval = io_channel_write_blk(fs->io, blk, count, buf);
441 printf(_("Warning: could not write %d blocks "
442 "in inode table starting at %d: %s\n"),
443 count, blk, error_message(retval));
446 fputs(backup, stdout);
448 if (sync_kludge == 1)
450 else if ((i % sync_kludge) == 0)
456 fputs(_("done \n"), stdout);
459 static void create_root_dir(ext2_filsys fs)
462 struct ext2_inode inode;
464 retval = ext2fs_mkdir(fs, EXT2_ROOT_INO, EXT2_ROOT_INO, 0);
466 com_err("ext2fs_mkdir", retval, _("while creating root dir"));
470 retval = ext2fs_read_inode(fs, EXT2_ROOT_INO, &inode);
472 com_err("ext2fs_read_inode", retval,
473 _("while reading root inode"));
476 inode.i_uid = getuid();
478 inode.i_gid = getgid();
479 retval = ext2fs_write_inode(fs, EXT2_ROOT_INO, &inode);
481 com_err("ext2fs_write_inode", retval,
482 _("while setting root inode ownership"));
488 static void create_lost_and_found(ext2_filsys fs)
492 const char *name = "lost+found";
496 retval = ext2fs_mkdir(fs, EXT2_ROOT_INO, 0, name);
498 com_err("ext2fs_mkdir", retval,
499 _("while creating /lost+found"));
503 retval = ext2fs_lookup(fs, EXT2_ROOT_INO, name, strlen(name), 0, &ino);
505 com_err("ext2_lookup", retval,
506 _("while looking up /lost+found"));
510 for (i=1; i < EXT2_NDIR_BLOCKS; i++) {
511 if ((lpf_size += fs->blocksize) >= 16*1024)
513 retval = ext2fs_expand_dir(fs, ino);
515 com_err("ext2fs_expand_dir", retval,
516 _("while expanding /lost+found"));
522 static void create_bad_block_inode(ext2_filsys fs, badblocks_list bb_list)
526 ext2fs_mark_inode_bitmap(fs->inode_map, EXT2_BAD_INO);
527 fs->group_desc[0].bg_free_inodes_count--;
528 fs->super->s_free_inodes_count--;
529 retval = ext2fs_update_bb_inode(fs, bb_list);
531 com_err("ext2fs_update_bb_inode", retval,
532 _("while setting bad block inode"));
538 static void reserve_inodes(ext2_filsys fs)
543 for (i = EXT2_ROOT_INO + 1; i < EXT2_FIRST_INODE(fs->super); i++) {
544 ext2fs_mark_inode_bitmap(fs->inode_map, i);
545 group = ext2fs_group_of_ino(fs, i);
546 fs->group_desc[group].bg_free_inodes_count--;
547 fs->super->s_free_inodes_count--;
549 ext2fs_mark_ib_dirty(fs);
552 static void zap_sector(ext2_filsys fs, int sect)
559 io_channel_set_blksize(fs->io, 512);
560 retval = io_channel_write_blk(fs->io, sect, -512, buf);
561 io_channel_set_blksize(fs->io, fs->blocksize);
563 printf(_("Warning: could not erase sector %d: %s\n"), sect,
564 error_message(retval));
568 static void show_stats(ext2_filsys fs)
570 struct ext2fs_sb *s = (struct ext2fs_sb *) fs->super;
573 int i, need, col_left;
575 if (param.s_blocks_count != s->s_blocks_count)
576 printf(_("warning: %d blocks unused.\n\n"),
577 param.s_blocks_count - s->s_blocks_count);
579 memset(buf, 0, sizeof(buf));
580 strncpy(buf, s->s_volume_name, sizeof(s->s_volume_name));
581 printf(_("Filesystem label=%s\n"), buf);
582 printf(_("OS type: "));
583 switch (fs->super->s_creator_os) {
584 case EXT2_OS_LINUX: printf ("Linux"); break;
585 case EXT2_OS_HURD: printf ("GNU/Hurd"); break;
586 case EXT2_OS_MASIX: printf ("Masix"); break;
587 default: printf (_("(unknown os)"));
590 printf(_("Block size=%u (log=%u)\n"), fs->blocksize,
591 s->s_log_block_size);
592 printf(_("Fragment size=%u (log=%u)\n"), fs->fragsize,
594 printf(_("%u inodes, %u blocks\n"), s->s_inodes_count,
596 printf(_("%u blocks (%2.2f%%) reserved for the super user\n"),
598 100.0 * s->s_r_blocks_count / s->s_blocks_count);
599 printf(_("First data block=%u\n"), s->s_first_data_block);
600 if (fs->group_desc_count > 1)
601 printf(_("%lu block groups\n"), fs->group_desc_count);
603 printf(_("%lu block group\n"), fs->group_desc_count);
604 printf(_("%u blocks per group, %u fragments per group\n"),
605 s->s_blocks_per_group, s->s_frags_per_group);
606 printf(_("%u inodes per group\n"), s->s_inodes_per_group);
608 if (fs->group_desc_count == 1) {
613 printf(_("Superblock backups stored on blocks: "));
614 group_block = s->s_first_data_block;
616 for (i = 1; i < fs->group_desc_count; i++) {
617 group_block += s->s_blocks_per_group;
618 if (!ext2fs_bg_has_super(fs, i))
622 need = int_log10(group_block) + 2;
623 if (need > col_left) {
628 printf("%u", group_block);
633 #ifndef HAVE_STRCASECMP
634 static int strcasecmp (char *s1, char *s2)
637 int ch1 = *s1++, ch2 = *s2++;
645 return *s1 ? 1 : *s2 ? -1 : 0;
650 * Set the S_CREATOR_OS field. Return true if OS is known,
653 static int set_os(struct ext2_super_block *sb, char *os)
656 sb->s_creator_os = atoi (os);
657 else if (strcasecmp(os, "linux") == 0)
658 sb->s_creator_os = EXT2_OS_LINUX;
659 else if (strcasecmp(os, "GNU") == 0 || strcasecmp(os, "hurd") == 0)
660 sb->s_creator_os = EXT2_OS_HURD;
661 else if (strcasecmp(os, "masix") == 0)
662 sb->s_creator_os = EXT2_OS_MASIX;
668 #define PATH_SET "PATH=/sbin"
670 static void parse_raid_opts(const char *opts)
672 char *buf, *token, *next, *p, *arg;
679 fprintf(stderr, _("Couldn't allocate memory to parse "
684 for (token = buf; token && *token; token = next) {
685 p = strchr(token, ',');
691 arg = strchr(token, '=');
696 if (strcmp(token, "stride") == 0) {
701 fs_stride = strtoul(arg, &p, 0);
702 if (*p || (fs_stride == 0)) {
704 _("Invalid stride parameter.\n"));
712 fprintf(stderr, _("\nBad raid options specified.\n\n"
713 "Raid options are separated by commas, "
714 "and may take an argument which\n"
715 "\tis set off by an equals ('=') sign.\n\n"
716 "Valid raid options are:\n"
717 "\tstride=<stride length in blocks>\n\n"));
722 static __u32 ok_features[3] = {
724 EXT2_FEATURE_INCOMPAT_FILETYPE, /* Incompat */
725 EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER /* R/O compat */
729 static void PRS(int argc, char *argv[])
734 blk_t group_blk_max = 8192;
737 int reserved_ratio = 5;
738 ino_t num_inodes = 0;
740 int sparse_option = 0;
741 char * oldpath = getenv("PATH");
742 struct ext2fs_sb *param_ext2 = (struct ext2fs_sb *) ¶m;
743 char * raid_opts = 0;
745 const char * feature_set = "filetype,sparse_super";
754 if ((ut.release[0] == '1') ||
755 (ut.release[0] == '2' && ut.release[1] == '.' &&
756 ut.release[2] < '2' && ut.release[3] == '.'))
759 /* Update our PATH to include /sbin */
763 newpath = malloc(sizeof (PATH_SET) + 1 + strlen (oldpath));
764 strcpy (newpath, PATH_SET);
765 strcat (newpath, ":");
766 strcat (newpath, oldpath);
771 setbuf(stdout, NULL);
772 setbuf(stderr, NULL);
773 initialize_ext2_error_table();
774 memset(¶m, 0, sizeof(struct ext2_super_block));
775 param.s_rev_level = 1; /* Create revision 1 filesystems now */
777 fprintf (stderr, _("mke2fs %s, %s for EXT2 FS %s, %s\n"),
778 E2FSPROGS_VERSION, E2FSPROGS_DATE,
779 EXT2FS_VERSION, EXT2FS_DATE);
781 program_name = *argv;
782 while ((c = getopt (argc, argv,
783 "b:cf:g:i:j:l:m:no:qr:R:s:tvI:ST:FL:M:N:O:V")) != EOF)
786 blocksize = strtoul(optarg, &tmp, 0);
787 if (blocksize < 1024 || blocksize > 4096 || *tmp) {
788 com_err(program_name, 0,
789 _("bad block size - %s"), optarg);
792 param.s_log_block_size =
793 int_log2(blocksize >> EXT2_MIN_BLOCK_LOG_SIZE);
794 group_blk_max = blocksize * 8;
797 case 't': /* Check for bad blocks */
801 size = strtoul(optarg, &tmp, 0);
802 if (size < 1024 || size > 4096 || *tmp) {
803 com_err(program_name, 0,
804 _("bad fragment size - %s"),
808 param.s_log_frag_size =
809 int_log2(size >> EXT2_MIN_BLOCK_LOG_SIZE);
810 printf(_("Warning: fragments not supported. "
811 "Ignoring -f option\n"));
814 param.s_blocks_per_group = strtoul(optarg, &tmp, 0);
816 com_err(program_name, 0,
817 _("Illegal number for blocks per group"));
820 if ((param.s_blocks_per_group % 8) != 0) {
821 com_err(program_name, 0,
822 _("blocks per group must be multiple of 8"));
827 inode_ratio = strtoul(optarg, &tmp, 0);
828 if (inode_ratio < 1024 || inode_ratio > 256 * 1024 ||
830 com_err(program_name, 0,
831 _("bad inode ratio - %s"), optarg);
836 journal_size = strtoul(optarg, &tmp, 0);
837 if (journal_size < 4 || journal_size > 100 || *tmp) {
838 com_err(program_name, 0,
839 _("bad journal size - %s"), optarg);
844 bad_blocks_filename = malloc(strlen(optarg)+1);
845 if (!bad_blocks_filename) {
846 com_err(program_name, ENOMEM,
847 _("in malloc for bad_blocks_filename"));
850 strcpy(bad_blocks_filename, optarg);
853 reserved_ratio = strtoul(optarg, &tmp, 0);
854 if (reserved_ratio > 50 || *tmp) {
855 com_err(program_name, 0,
856 _("bad reserved blocks percent - %s"),
868 param.s_rev_level = atoi(optarg);
871 sparse_option = atoi(optarg);
873 #ifdef EXT2_DYNAMIC_REV
875 param.s_inode_size = atoi(optarg);
879 num_inodes = atoi(optarg);
891 volume_label = optarg;
897 feature_set = optarg;
909 /* Print version number and exit */
910 fprintf(stderr, _("\tUsing %s\n"),
911 error_message(EXT2_ET_BASE));
918 device_name = argv[optind];
921 unsigned long tmp2 = strtoul(argv[optind++], &tmp, 0);
923 if ((*tmp) || (tmp2 > 0xfffffffful)) {
924 com_err(program_name, 0, _("bad blocks count - %s"),
928 param.s_blocks_count = tmp2;
934 parse_raid_opts(raid_opts);
937 check_plausibility();
940 param.s_log_frag_size = param.s_log_block_size;
942 if (noaction && param.s_blocks_count) {
943 dev_size = param.s_blocks_count;
946 retval = ext2fs_get_device_size(device_name,
947 EXT2_BLOCK_SIZE(¶m),
949 if (retval && (retval != EXT2_ET_UNIMPLEMENTED)) {
950 com_err(program_name, retval,
951 _("while trying to determine filesystem size"));
954 if (!param.s_blocks_count) {
955 if (retval == EXT2_ET_UNIMPLEMENTED) {
956 com_err(program_name, 0,
957 _("Couldn't determine device size; you "
958 "must specify\nthe size of the "
963 com_err(program_name, 0,
964 _("Device size reported to be zero. "
965 "Invalid partition specified, or\n\t"
966 "partition table wasn't reread "
967 "after running fdisk, due to\n\t"
968 "a modified partition being busy "
969 "and in use. You may need to reboot\n\t"
970 "to re-read your partition table.\n"
974 param.s_blocks_count = dev_size;
977 } else if (!force && (param.s_blocks_count > dev_size)) {
978 com_err(program_name, 0,
979 _("Filesystem larger than apparent filesystem size."));
983 set_fs_defaults(fs_type, param_ext2, blocksize, &inode_ratio);
985 if (param.s_blocks_per_group) {
986 if (param.s_blocks_per_group < 256 ||
987 param.s_blocks_per_group > group_blk_max || *tmp) {
988 com_err(program_name, 0,
989 _("blocks per group count out of range"));
995 * Calculate number of inodes based on the inode ratio
997 param.s_inodes_count = num_inodes ? num_inodes :
998 ((__u64) param.s_blocks_count * EXT2_BLOCK_SIZE(¶m))
1002 * Calculate number of blocks to reserve
1004 param.s_r_blocks_count = (param.s_blocks_count * reserved_ratio) / 100;
1006 #ifdef EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER
1008 param_ext2->s_feature_ro_compat |=
1009 EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER;
1011 if (feature_set && !strncasecmp(feature_set, "none", 4))
1013 if (feature_set && e2p_edit_feature(feature_set,
1014 ¶m_ext2->s_feature_compat,
1016 fprintf(stderr, _("Invalid filesystem option set: %s\n"),
1022 int main (int argc, char *argv[])
1024 errcode_t retval = 0;
1026 badblocks_list bb_list = 0;
1028 struct ext2fs_sb *s;
1031 setlocale(LC_MESSAGES, "");
1032 bindtextdomain(NLS_CAT_NAME, LOCALEDIR);
1033 textdomain(NLS_CAT_NAME);
1038 * Initialize the superblock....
1040 retval = ext2fs_initialize(device_name, 0, ¶m,
1041 unix_io_manager, &fs);
1043 com_err(device_name, retval, _("while setting up superblock"));
1048 * Wipe out the old on-disk superblock
1053 * Generate a UUID for it...
1055 s = (struct ext2fs_sb *) fs->super;
1056 uuid_generate(s->s_uuid);
1059 * Override the creator OS, if applicable
1061 if (creator_os && !set_os(fs->super, creator_os)) {
1062 com_err (program_name, 0, _("unknown os - %s"), creator_os);
1067 * For the Hurd, we will turn off filetype since it doesn't
1070 if (fs->super->s_creator_os == EXT2_OS_HURD)
1071 fs->super->s_feature_incompat &=
1072 ~EXT2_FEATURE_INCOMPAT_FILETYPE;
1075 * Set the volume label...
1078 memset(s->s_volume_name, 0, sizeof(s->s_volume_name));
1079 strncpy(s->s_volume_name, volume_label,
1080 sizeof(s->s_volume_name));
1084 * Set the last mount directory
1087 memset(s->s_last_mounted, 0, sizeof(s->s_last_mounted));
1088 strncpy(s->s_last_mounted, mount_dir,
1089 sizeof(s->s_last_mounted));
1092 if (!quiet || noaction)
1098 if (bad_blocks_filename)
1099 read_bb_file(fs, &bb_list, bad_blocks_filename);
1101 test_disk(fs, &bb_list);
1103 handle_bad_blocks(fs, bb_list);
1104 fs->stride = fs_stride;
1105 retval = ext2fs_allocate_tables(fs);
1107 com_err(program_name, retval,
1108 _("while trying to allocate filesystem tables"));
1112 fs->super->s_state |= EXT2_ERROR_FS;
1113 fs->flags &= ~(EXT2_FLAG_IB_DIRTY|EXT2_FLAG_BB_DIRTY);
1115 write_inode_tables(fs);
1116 create_root_dir(fs);
1117 create_lost_and_found(fs);
1119 create_bad_block_inode(fs, bb_list);
1120 #ifdef ZAP_BOOTBLOCK
1126 printf(_("Creating journal: "));
1127 journal_blocks = journal_size * 1024 /
1128 (fs->blocksize / 1024);
1129 retval = ext2fs_add_journal_fs(fs, journal_blocks);
1131 com_err (program_name, retval,
1132 _("while trying to create journal"));
1136 printf(_("done\n"));
1140 printf(_("Writing superblocks and "
1141 "filesystem accounting information: "));
1142 retval = ext2fs_flush(fs);
1144 printf(_("\nWarning, had trouble writing out superblocks."));
1147 printf(_("done\n"));