mke2fs.c revision 80a1806d617fdb14421ac6ac50a640ac1fd303b3
1/* 2 * mke2fs.c - Make a ext2fs filesystem. 3 * 4 * Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 5 * 2003, 2004, 2005 by Theodore Ts'o. 6 * 7 * %Begin-Header% 8 * This file may be redistributed under the terms of the GNU Public 9 * License. 10 * %End-Header% 11 */ 12 13/* Usage: mke2fs [options] device 14 * 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 :-). 17 */ 18 19#define _XOPEN_SOURCE 600 /* for inclusion of PATH_MAX in Solaris */ 20 21#include "config.h" 22#include <stdio.h> 23#include <string.h> 24#include <strings.h> 25#include <fcntl.h> 26#include <ctype.h> 27#include <time.h> 28#ifdef __linux__ 29#include <sys/utsname.h> 30#endif 31#ifdef HAVE_GETOPT_H 32#include <getopt.h> 33#else 34extern char *optarg; 35extern int optind; 36#endif 37#ifdef HAVE_UNISTD_H 38#include <unistd.h> 39#endif 40#ifdef HAVE_STDLIB_H 41#include <stdlib.h> 42#endif 43#ifdef HAVE_ERRNO_H 44#include <errno.h> 45#endif 46#include <sys/ioctl.h> 47#include <sys/types.h> 48#include <sys/stat.h> 49#include <libgen.h> 50#include <limits.h> 51#include <blkid/blkid.h> 52 53#include "ext2fs/ext2_fs.h" 54#include "ext2fs/ext2fsP.h" 55#include "et/com_err.h" 56#include "uuid/uuid.h" 57#include "e2p/e2p.h" 58#include "ext2fs/ext2fs.h" 59#include "util.h" 60#include "profile.h" 61#include "prof_err.h" 62#include "../version.h" 63#include "nls-enable.h" 64#include "quota/mkquota.h" 65 66#define STRIDE_LENGTH 8 67 68#define MAX_32_NUM ((((unsigned long long) 1) << 32) - 1) 69 70#ifndef __sparc__ 71#define ZAP_BOOTBLOCK 72#endif 73 74#define DISCARD_STEP_MB (2048) 75 76extern int isatty(int); 77extern FILE *fpopen(const char *cmd, const char *mode); 78 79const char * program_name = "mke2fs"; 80const char * device_name /* = NULL */; 81 82/* Command line options */ 83int cflag; 84int verbose; 85int quiet; 86int super_only; 87int discard = 1; /* attempt to discard device before fs creation */ 88int direct_io; 89int force; 90int noaction; 91uid_t root_uid; 92gid_t root_gid; 93int journal_size; 94int journal_flags; 95int lazy_itable_init; 96char *bad_blocks_filename = NULL; 97__u32 fs_stride; 98int quotatype = -1; /* Initialize both user and group quotas by default */ 99 100struct ext2_super_block fs_param; 101char *fs_uuid = NULL; 102char *creator_os; 103char *volume_label; 104char *mount_dir; 105char *journal_device; 106int sync_kludge; /* Set using the MKE2FS_SYNC env. option */ 107char **fs_types; 108 109profile_t profile; 110 111int sys_page_size = 4096; 112int linux_version_code = 0; 113 114static void usage(void) 115{ 116 fprintf(stderr, _("Usage: %s [-c|-l filename] [-b block-size] " 117 "[-C cluster-size]\n\t[-i bytes-per-inode] [-I inode-size] " 118 "[-J journal-options]\n" 119 "\t[-G flex-group-size] [-N number-of-inodes]\n" 120 "\t[-m reserved-blocks-percentage] [-o creator-os]\n" 121 "\t[-g blocks-per-group] [-L volume-label] " 122 "[-M last-mounted-directory]\n\t[-O feature[,...]] " 123 "[-r fs-revision] [-E extended-option[,...]]\n" 124 "\t[-t fs-type] [-T usage-type ] [-U UUID] " 125 "[-jnqvDFKSV] device [blocks-count]\n"), 126 program_name); 127 exit(1); 128} 129 130static int int_log2(unsigned long long arg) 131{ 132 int l = 0; 133 134 arg >>= 1; 135 while (arg) { 136 l++; 137 arg >>= 1; 138 } 139 return l; 140} 141 142static int int_log10(unsigned long long arg) 143{ 144 int l; 145 146 for (l=0; arg ; l++) 147 arg = arg / 10; 148 return l; 149} 150 151#ifdef __linux__ 152static int parse_version_number(const char *s) 153{ 154 int major, minor, rev; 155 char *endptr; 156 const char *cp = s; 157 158 if (!s) 159 return 0; 160 major = strtol(cp, &endptr, 10); 161 if (cp == endptr || *endptr != '.') 162 return 0; 163 cp = endptr + 1; 164 minor = strtol(cp, &endptr, 10); 165 if (cp == endptr || *endptr != '.') 166 return 0; 167 cp = endptr + 1; 168 rev = strtol(cp, &endptr, 10); 169 if (cp == endptr) 170 return 0; 171 return ((((major * 256) + minor) * 256) + rev); 172} 173#endif 174 175/* 176 * Helper function for read_bb_file and test_disk 177 */ 178static void invalid_block(ext2_filsys fs EXT2FS_ATTR((unused)), blk_t blk) 179{ 180 fprintf(stderr, _("Bad block %u out of range; ignored.\n"), blk); 181 return; 182} 183 184/* 185 * Reads the bad blocks list from a file 186 */ 187static void read_bb_file(ext2_filsys fs, badblocks_list *bb_list, 188 const char *bad_blocks_file) 189{ 190 FILE *f; 191 errcode_t retval; 192 193 f = fopen(bad_blocks_file, "r"); 194 if (!f) { 195 com_err("read_bad_blocks_file", errno, 196 _("while trying to open %s"), bad_blocks_file); 197 exit(1); 198 } 199 retval = ext2fs_read_bb_FILE(fs, f, bb_list, invalid_block); 200 fclose (f); 201 if (retval) { 202 com_err("ext2fs_read_bb_FILE", retval, 203 _("while reading in list of bad blocks from file")); 204 exit(1); 205 } 206} 207 208/* 209 * Runs the badblocks program to test the disk 210 */ 211static void test_disk(ext2_filsys fs, badblocks_list *bb_list) 212{ 213 FILE *f; 214 errcode_t retval; 215 char buf[1024]; 216 217 sprintf(buf, "badblocks -b %d -X %s%s%s %llu", fs->blocksize, 218 quiet ? "" : "-s ", (cflag > 1) ? "-w " : "", 219 fs->device_name, ext2fs_blocks_count(fs->super)-1); 220 if (verbose) 221 printf(_("Running command: %s\n"), buf); 222 f = popen(buf, "r"); 223 if (!f) { 224 com_err("popen", errno, 225 _("while trying to run '%s'"), buf); 226 exit(1); 227 } 228 retval = ext2fs_read_bb_FILE(fs, f, bb_list, invalid_block); 229 pclose(f); 230 if (retval) { 231 com_err("ext2fs_read_bb_FILE", retval, 232 _("while processing list of bad blocks from program")); 233 exit(1); 234 } 235} 236 237static void handle_bad_blocks(ext2_filsys fs, badblocks_list bb_list) 238{ 239 dgrp_t i; 240 blk_t j; 241 unsigned must_be_good; 242 blk_t blk; 243 badblocks_iterate bb_iter; 244 errcode_t retval; 245 blk_t group_block; 246 int group; 247 int group_bad; 248 249 if (!bb_list) 250 return; 251 252 /* 253 * The primary superblock and group descriptors *must* be 254 * good; if not, abort. 255 */ 256 must_be_good = fs->super->s_first_data_block + 1 + fs->desc_blocks; 257 for (i = fs->super->s_first_data_block; i <= must_be_good; i++) { 258 if (ext2fs_badblocks_list_test(bb_list, i)) { 259 fprintf(stderr, _("Block %d in primary " 260 "superblock/group descriptor area bad.\n"), i); 261 fprintf(stderr, _("Blocks %u through %u must be good " 262 "in order to build a filesystem.\n"), 263 fs->super->s_first_data_block, must_be_good); 264 fputs(_("Aborting....\n"), stderr); 265 exit(1); 266 } 267 } 268 269 /* 270 * See if any of the bad blocks are showing up in the backup 271 * superblocks and/or group descriptors. If so, issue a 272 * warning and adjust the block counts appropriately. 273 */ 274 group_block = fs->super->s_first_data_block + 275 fs->super->s_blocks_per_group; 276 277 for (i = 1; i < fs->group_desc_count; i++) { 278 group_bad = 0; 279 for (j=0; j < fs->desc_blocks+1; j++) { 280 if (ext2fs_badblocks_list_test(bb_list, 281 group_block + j)) { 282 if (!group_bad) 283 fprintf(stderr, 284_("Warning: the backup superblock/group descriptors at block %u contain\n" 285" bad blocks.\n\n"), 286 group_block); 287 group_bad++; 288 group = ext2fs_group_of_blk2(fs, group_block+j); 289 ext2fs_bg_free_blocks_count_set(fs, group, ext2fs_bg_free_blocks_count(fs, group) + 1); 290 ext2fs_group_desc_csum_set(fs, group); 291 ext2fs_free_blocks_count_add(fs->super, 1); 292 } 293 } 294 group_block += fs->super->s_blocks_per_group; 295 } 296 297 /* 298 * Mark all the bad blocks as used... 299 */ 300 retval = ext2fs_badblocks_list_iterate_begin(bb_list, &bb_iter); 301 if (retval) { 302 com_err("ext2fs_badblocks_list_iterate_begin", retval, 303 _("while marking bad blocks as used")); 304 exit(1); 305 } 306 while (ext2fs_badblocks_list_iterate(bb_iter, &blk)) 307 ext2fs_mark_block_bitmap2(fs->block_map, EXT2FS_B2C(fs, blk)); 308 ext2fs_badblocks_list_iterate_end(bb_iter); 309} 310 311static void write_inode_tables(ext2_filsys fs, int lazy_flag, int itable_zeroed) 312{ 313 errcode_t retval; 314 blk64_t blk; 315 dgrp_t i; 316 int num; 317 struct ext2fs_numeric_progress_struct progress; 318 319 ext2fs_numeric_progress_init(fs, &progress, 320 _("Writing inode tables: "), 321 fs->group_desc_count); 322 323 for (i = 0; i < fs->group_desc_count; i++) { 324 ext2fs_numeric_progress_update(fs, &progress, i); 325 326 blk = ext2fs_inode_table_loc(fs, i); 327 num = fs->inode_blocks_per_group; 328 329 if (lazy_flag) 330 num = ext2fs_div_ceil((fs->super->s_inodes_per_group - 331 ext2fs_bg_itable_unused(fs, i)) * 332 EXT2_INODE_SIZE(fs->super), 333 EXT2_BLOCK_SIZE(fs->super)); 334 if (!lazy_flag || itable_zeroed) { 335 /* The kernel doesn't need to zero the itable blocks */ 336 ext2fs_bg_flags_set(fs, i, EXT2_BG_INODE_ZEROED); 337 ext2fs_group_desc_csum_set(fs, i); 338 } 339 retval = ext2fs_zero_blocks2(fs, blk, num, &blk, &num); 340 if (retval) { 341 fprintf(stderr, _("\nCould not write %d " 342 "blocks in inode table starting at %llu: %s\n"), 343 num, blk, error_message(retval)); 344 exit(1); 345 } 346 if (sync_kludge) { 347 if (sync_kludge == 1) 348 sync(); 349 else if ((i % sync_kludge) == 0) 350 sync(); 351 } 352 } 353 ext2fs_zero_blocks2(0, 0, 0, 0, 0); 354 ext2fs_numeric_progress_close(fs, &progress, 355 _("done \n")); 356} 357 358static void create_root_dir(ext2_filsys fs) 359{ 360 errcode_t retval; 361 struct ext2_inode inode; 362 __u32 uid, gid; 363 364 retval = ext2fs_mkdir(fs, EXT2_ROOT_INO, EXT2_ROOT_INO, 0); 365 if (retval) { 366 com_err("ext2fs_mkdir", retval, _("while creating root dir")); 367 exit(1); 368 } 369 if (root_uid != 0 || root_gid != 0) { 370 retval = ext2fs_read_inode(fs, EXT2_ROOT_INO, &inode); 371 if (retval) { 372 com_err("ext2fs_read_inode", retval, 373 _("while reading root inode")); 374 exit(1); 375 } 376 377 inode.i_uid = root_uid; 378 ext2fs_set_i_uid_high(inode, root_uid >> 16); 379 inode.i_gid = root_gid; 380 ext2fs_set_i_gid_high(inode, root_gid >> 16); 381 382 retval = ext2fs_write_new_inode(fs, EXT2_ROOT_INO, &inode); 383 if (retval) { 384 com_err("ext2fs_write_inode", retval, 385 _("while setting root inode ownership")); 386 exit(1); 387 } 388 } 389} 390 391static void create_lost_and_found(ext2_filsys fs) 392{ 393 unsigned int lpf_size = 0; 394 errcode_t retval; 395 ext2_ino_t ino; 396 const char *name = "lost+found"; 397 int i; 398 399 fs->umask = 077; 400 retval = ext2fs_mkdir(fs, EXT2_ROOT_INO, 0, name); 401 if (retval) { 402 com_err("ext2fs_mkdir", retval, 403 _("while creating /lost+found")); 404 exit(1); 405 } 406 407 retval = ext2fs_lookup(fs, EXT2_ROOT_INO, name, strlen(name), 0, &ino); 408 if (retval) { 409 com_err("ext2_lookup", retval, 410 _("while looking up /lost+found")); 411 exit(1); 412 } 413 414 for (i=1; i < EXT2_NDIR_BLOCKS; i++) { 415 /* Ensure that lost+found is at least 2 blocks, so we always 416 * test large empty blocks for big-block filesystems. */ 417 if ((lpf_size += fs->blocksize) >= 16*1024 && 418 lpf_size >= 2 * fs->blocksize) 419 break; 420 retval = ext2fs_expand_dir(fs, ino); 421 if (retval) { 422 com_err("ext2fs_expand_dir", retval, 423 _("while expanding /lost+found")); 424 exit(1); 425 } 426 } 427} 428 429static void create_bad_block_inode(ext2_filsys fs, badblocks_list bb_list) 430{ 431 errcode_t retval; 432 433 ext2fs_mark_inode_bitmap2(fs->inode_map, EXT2_BAD_INO); 434 ext2fs_inode_alloc_stats2(fs, EXT2_BAD_INO, +1, 0); 435 retval = ext2fs_update_bb_inode(fs, bb_list); 436 if (retval) { 437 com_err("ext2fs_update_bb_inode", retval, 438 _("while setting bad block inode")); 439 exit(1); 440 } 441 442} 443 444static void reserve_inodes(ext2_filsys fs) 445{ 446 ext2_ino_t i; 447 448 for (i = EXT2_ROOT_INO + 1; i < EXT2_FIRST_INODE(fs->super); i++) 449 ext2fs_inode_alloc_stats2(fs, i, +1, 0); 450 ext2fs_mark_ib_dirty(fs); 451} 452 453#define BSD_DISKMAGIC (0x82564557UL) /* The disk magic number */ 454#define BSD_MAGICDISK (0x57455682UL) /* The disk magic number reversed */ 455#define BSD_LABEL_OFFSET 64 456 457static void zap_sector(ext2_filsys fs, int sect, int nsect) 458{ 459 char *buf; 460 int retval; 461 unsigned int *magic; 462 463 buf = malloc(512*nsect); 464 if (!buf) { 465 printf(_("Out of memory erasing sectors %d-%d\n"), 466 sect, sect + nsect - 1); 467 exit(1); 468 } 469 470 if (sect == 0) { 471 /* Check for a BSD disklabel, and don't erase it if so */ 472 retval = io_channel_read_blk64(fs->io, 0, -512, buf); 473 if (retval) 474 fprintf(stderr, 475 _("Warning: could not read block 0: %s\n"), 476 error_message(retval)); 477 else { 478 magic = (unsigned int *) (buf + BSD_LABEL_OFFSET); 479 if ((*magic == BSD_DISKMAGIC) || 480 (*magic == BSD_MAGICDISK)) 481 return; 482 } 483 } 484 485 memset(buf, 0, 512*nsect); 486 io_channel_set_blksize(fs->io, 512); 487 retval = io_channel_write_blk64(fs->io, sect, -512*nsect, buf); 488 io_channel_set_blksize(fs->io, fs->blocksize); 489 free(buf); 490 if (retval) 491 fprintf(stderr, _("Warning: could not erase sector %d: %s\n"), 492 sect, error_message(retval)); 493} 494 495static void create_journal_dev(ext2_filsys fs) 496{ 497 struct ext2fs_numeric_progress_struct progress; 498 errcode_t retval; 499 char *buf; 500 blk64_t blk, err_blk; 501 int c, count, err_count; 502 503 retval = ext2fs_create_journal_superblock(fs, 504 ext2fs_blocks_count(fs->super), 0, &buf); 505 if (retval) { 506 com_err("create_journal_dev", retval, 507 _("while initializing journal superblock")); 508 exit(1); 509 } 510 511 if (journal_flags & EXT2_MKJOURNAL_LAZYINIT) 512 goto write_superblock; 513 514 ext2fs_numeric_progress_init(fs, &progress, 515 _("Zeroing journal device: "), 516 ext2fs_blocks_count(fs->super)); 517 blk = 0; 518 count = ext2fs_blocks_count(fs->super); 519 while (count > 0) { 520 if (count > 1024) 521 c = 1024; 522 else 523 c = count; 524 retval = ext2fs_zero_blocks2(fs, blk, c, &err_blk, &err_count); 525 if (retval) { 526 com_err("create_journal_dev", retval, 527 _("while zeroing journal device " 528 "(block %llu, count %d)"), 529 err_blk, err_count); 530 exit(1); 531 } 532 blk += c; 533 count -= c; 534 ext2fs_numeric_progress_update(fs, &progress, blk); 535 } 536 ext2fs_zero_blocks2(0, 0, 0, 0, 0); 537 538 ext2fs_numeric_progress_close(fs, &progress, NULL); 539write_superblock: 540 retval = io_channel_write_blk64(fs->io, 541 fs->super->s_first_data_block+1, 542 1, buf); 543 if (retval) { 544 com_err("create_journal_dev", retval, 545 _("while writing journal superblock")); 546 exit(1); 547 } 548} 549 550static void show_stats(ext2_filsys fs) 551{ 552 struct ext2_super_block *s = fs->super; 553 char buf[80]; 554 char *os; 555 blk64_t group_block; 556 dgrp_t i; 557 int need, col_left; 558 559 if (ext2fs_blocks_count(&fs_param) != ext2fs_blocks_count(s)) 560 fprintf(stderr, _("warning: %llu blocks unused.\n\n"), 561 ext2fs_blocks_count(&fs_param) - ext2fs_blocks_count(s)); 562 563 memset(buf, 0, sizeof(buf)); 564 strncpy(buf, s->s_volume_name, sizeof(s->s_volume_name)); 565 printf(_("Filesystem label=%s\n"), buf); 566 os = e2p_os2string(fs->super->s_creator_os); 567 if (os) 568 printf(_("OS type: %s\n"), os); 569 free(os); 570 printf(_("Block size=%u (log=%u)\n"), fs->blocksize, 571 s->s_log_block_size); 572 if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super, 573 EXT4_FEATURE_RO_COMPAT_BIGALLOC)) 574 printf(_("Cluster size=%u (log=%u)\n"), 575 fs->blocksize << fs->cluster_ratio_bits, 576 s->s_log_cluster_size); 577 else 578 printf(_("Fragment size=%u (log=%u)\n"), EXT2_CLUSTER_SIZE(s), 579 s->s_log_cluster_size); 580 printf(_("Stride=%u blocks, Stripe width=%u blocks\n"), 581 s->s_raid_stride, s->s_raid_stripe_width); 582 printf(_("%u inodes, %llu blocks\n"), s->s_inodes_count, 583 ext2fs_blocks_count(s)); 584 printf(_("%llu blocks (%2.2f%%) reserved for the super user\n"), 585 ext2fs_r_blocks_count(s), 586 100.0 * ext2fs_r_blocks_count(s) / ext2fs_blocks_count(s)); 587 printf(_("First data block=%u\n"), s->s_first_data_block); 588 if (root_uid != 0 || root_gid != 0) 589 printf(_("Root directory owner=%u:%u\n"), root_uid, root_gid); 590 if (s->s_reserved_gdt_blocks) 591 printf(_("Maximum filesystem blocks=%lu\n"), 592 (s->s_reserved_gdt_blocks + fs->desc_blocks) * 593 EXT2_DESC_PER_BLOCK(s) * s->s_blocks_per_group); 594 if (fs->group_desc_count > 1) 595 printf(_("%u block groups\n"), fs->group_desc_count); 596 else 597 printf(_("%u block group\n"), fs->group_desc_count); 598 if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super, 599 EXT4_FEATURE_RO_COMPAT_BIGALLOC)) 600 printf(_("%u blocks per group, %u clusters per group\n"), 601 s->s_blocks_per_group, s->s_clusters_per_group); 602 else 603 printf(_("%u blocks per group, %u fragments per group\n"), 604 s->s_blocks_per_group, s->s_clusters_per_group); 605 printf(_("%u inodes per group\n"), s->s_inodes_per_group); 606 607 if (fs->group_desc_count == 1) { 608 printf("\n"); 609 return; 610 } 611 612 printf(_("Superblock backups stored on blocks: ")); 613 group_block = s->s_first_data_block; 614 col_left = 0; 615 for (i = 1; i < fs->group_desc_count; i++) { 616 group_block += s->s_blocks_per_group; 617 if (!ext2fs_bg_has_super(fs, i)) 618 continue; 619 if (i != 1) 620 printf(", "); 621 need = int_log10(group_block) + 2; 622 if (need > col_left) { 623 printf("\n\t"); 624 col_left = 72; 625 } 626 col_left -= need; 627 printf("%llu", group_block); 628 } 629 printf("\n\n"); 630} 631 632/* 633 * Set the S_CREATOR_OS field. Return true if OS is known, 634 * otherwise, 0. 635 */ 636static int set_os(struct ext2_super_block *sb, char *os) 637{ 638 if (isdigit (*os)) 639 sb->s_creator_os = atoi (os); 640 else if (strcasecmp(os, "linux") == 0) 641 sb->s_creator_os = EXT2_OS_LINUX; 642 else if (strcasecmp(os, "GNU") == 0 || strcasecmp(os, "hurd") == 0) 643 sb->s_creator_os = EXT2_OS_HURD; 644 else if (strcasecmp(os, "freebsd") == 0) 645 sb->s_creator_os = EXT2_OS_FREEBSD; 646 else if (strcasecmp(os, "lites") == 0) 647 sb->s_creator_os = EXT2_OS_LITES; 648 else 649 return 0; 650 return 1; 651} 652 653#define PATH_SET "PATH=/sbin" 654 655static void parse_extended_opts(struct ext2_super_block *param, 656 const char *opts) 657{ 658 char *buf, *token, *next, *p, *arg, *badopt = 0; 659 int len; 660 int r_usage = 0; 661 662 len = strlen(opts); 663 buf = malloc(len+1); 664 if (!buf) { 665 fprintf(stderr, 666 _("Couldn't allocate memory to parse options!\n")); 667 exit(1); 668 } 669 strcpy(buf, opts); 670 for (token = buf; token && *token; token = next) { 671 p = strchr(token, ','); 672 next = 0; 673 if (p) { 674 *p = 0; 675 next = p+1; 676 } 677 arg = strchr(token, '='); 678 if (arg) { 679 *arg = 0; 680 arg++; 681 } 682 if (strcmp(token, "mmp_update_interval") == 0) { 683 if (!arg) { 684 r_usage++; 685 badopt = token; 686 continue; 687 } 688 param->s_mmp_update_interval = strtoul(arg, &p, 0); 689 if (*p) { 690 fprintf(stderr, 691 _("Invalid mmp_update_interval: %s\n"), 692 arg); 693 r_usage++; 694 continue; 695 } 696 } else if (strcmp(token, "stride") == 0) { 697 if (!arg) { 698 r_usage++; 699 badopt = token; 700 continue; 701 } 702 param->s_raid_stride = strtoul(arg, &p, 0); 703 if (*p) { 704 fprintf(stderr, 705 _("Invalid stride parameter: %s\n"), 706 arg); 707 r_usage++; 708 continue; 709 } 710 } else if (strcmp(token, "stripe-width") == 0 || 711 strcmp(token, "stripe_width") == 0) { 712 if (!arg) { 713 r_usage++; 714 badopt = token; 715 continue; 716 } 717 param->s_raid_stripe_width = strtoul(arg, &p, 0); 718 if (*p) { 719 fprintf(stderr, 720 _("Invalid stripe-width parameter: %s\n"), 721 arg); 722 r_usage++; 723 continue; 724 } 725 } else if (!strcmp(token, "resize")) { 726 blk64_t resize; 727 unsigned long bpg, rsv_groups; 728 unsigned long group_desc_count, desc_blocks; 729 unsigned int gdpb, blocksize; 730 int rsv_gdb; 731 732 if (!arg) { 733 r_usage++; 734 badopt = token; 735 continue; 736 } 737 738 resize = parse_num_blocks2(arg, 739 param->s_log_block_size); 740 741 if (resize == 0) { 742 fprintf(stderr, 743 _("Invalid resize parameter: %s\n"), 744 arg); 745 r_usage++; 746 continue; 747 } 748 if (resize <= ext2fs_blocks_count(param)) { 749 fprintf(stderr, 750 _("The resize maximum must be greater " 751 "than the filesystem size.\n")); 752 r_usage++; 753 continue; 754 } 755 756 blocksize = EXT2_BLOCK_SIZE(param); 757 bpg = param->s_blocks_per_group; 758 if (!bpg) 759 bpg = blocksize * 8; 760 gdpb = EXT2_DESC_PER_BLOCK(param); 761 group_desc_count = (__u32) ext2fs_div64_ceil( 762 ext2fs_blocks_count(param), bpg); 763 desc_blocks = (group_desc_count + 764 gdpb - 1) / gdpb; 765 rsv_groups = ext2fs_div64_ceil(resize, bpg); 766 rsv_gdb = ext2fs_div_ceil(rsv_groups, gdpb) - 767 desc_blocks; 768 if (rsv_gdb > (int) EXT2_ADDR_PER_BLOCK(param)) 769 rsv_gdb = EXT2_ADDR_PER_BLOCK(param); 770 771 if (rsv_gdb > 0) { 772 if (param->s_rev_level == EXT2_GOOD_OLD_REV) { 773 fprintf(stderr, 774 _("On-line resizing not supported with revision 0 filesystems\n")); 775 free(buf); 776 exit(1); 777 } 778 param->s_feature_compat |= 779 EXT2_FEATURE_COMPAT_RESIZE_INODE; 780 781 param->s_reserved_gdt_blocks = rsv_gdb; 782 } 783 } else if (!strcmp(token, "test_fs")) { 784 param->s_flags |= EXT2_FLAGS_TEST_FILESYS; 785 } else if (!strcmp(token, "lazy_itable_init")) { 786 if (arg) 787 lazy_itable_init = strtoul(arg, &p, 0); 788 else 789 lazy_itable_init = 1; 790 } else if (!strcmp(token, "lazy_journal_init")) { 791 if (arg) 792 journal_flags |= strtoul(arg, &p, 0) ? 793 EXT2_MKJOURNAL_LAZYINIT : 0; 794 else 795 journal_flags |= EXT2_MKJOURNAL_LAZYINIT; 796 } else if (!strcmp(token, "root_owner")) { 797 if (arg) { 798 root_uid = strtoul(arg, &p, 0); 799 if (*p != ':') { 800 fprintf(stderr, 801 _("Invalid root_owner: '%s'\n"), 802 arg); 803 r_usage++; 804 continue; 805 } 806 p++; 807 root_gid = strtoul(p, &p, 0); 808 if (*p) { 809 fprintf(stderr, 810 _("Invalid root_owner: '%s'\n"), 811 arg); 812 r_usage++; 813 continue; 814 } 815 } else { 816 root_uid = getuid(); 817 root_gid = getgid(); 818 } 819 } else if (!strcmp(token, "discard")) { 820 discard = 1; 821 } else if (!strcmp(token, "nodiscard")) { 822 discard = 0; 823 } else if (!strcmp(token, "quotatype")) { 824 if (!arg) { 825 r_usage++; 826 badopt = token; 827 continue; 828 } 829 if (!strncmp(arg, "usr", 3)) { 830 quotatype = 0; 831 } else if (!strncmp(arg, "grp", 3)) { 832 quotatype = 1; 833 } else { 834 fprintf(stderr, 835 _("Invalid quotatype parameter: %s\n"), 836 arg); 837 r_usage++; 838 continue; 839 } 840 } else { 841 r_usage++; 842 badopt = token; 843 } 844 } 845 if (r_usage) { 846 fprintf(stderr, _("\nBad option(s) specified: %s\n\n" 847 "Extended options are separated by commas, " 848 "and may take an argument which\n" 849 "\tis set off by an equals ('=') sign.\n\n" 850 "Valid extended options are:\n" 851 "\tstride=<RAID per-disk data chunk in blocks>\n" 852 "\tstripe-width=<RAID stride * data disks in blocks>\n" 853 "\tresize=<resize maximum size in blocks>\n" 854 "\tlazy_itable_init=<0 to disable, 1 to enable>\n" 855 "\tlazy_journal_init=<0 to disable, 1 to enable>\n" 856 "\troot_uid=<uid of root directory>\n" 857 "\troot_gid=<gid of root directory>\n" 858 "\ttest_fs\n" 859 "\tdiscard\n" 860 "\tnodiscard\n" 861 "\tquotatype=<usr OR grp>\n\n"), 862 badopt ? badopt : ""); 863 free(buf); 864 exit(1); 865 } 866 if (param->s_raid_stride && 867 (param->s_raid_stripe_width % param->s_raid_stride) != 0) 868 fprintf(stderr, _("\nWarning: RAID stripe-width %u not an even " 869 "multiple of stride %u.\n\n"), 870 param->s_raid_stripe_width, param->s_raid_stride); 871 872 free(buf); 873} 874 875static __u32 ok_features[3] = { 876 /* Compat */ 877 EXT3_FEATURE_COMPAT_HAS_JOURNAL | 878 EXT2_FEATURE_COMPAT_RESIZE_INODE | 879 EXT2_FEATURE_COMPAT_DIR_INDEX | 880 EXT2_FEATURE_COMPAT_EXT_ATTR, 881 /* Incompat */ 882 EXT2_FEATURE_INCOMPAT_FILETYPE| 883 EXT3_FEATURE_INCOMPAT_EXTENTS| 884 EXT3_FEATURE_INCOMPAT_JOURNAL_DEV| 885 EXT2_FEATURE_INCOMPAT_META_BG| 886 EXT4_FEATURE_INCOMPAT_FLEX_BG| 887 EXT4_FEATURE_INCOMPAT_MMP | 888 EXT4_FEATURE_INCOMPAT_64BIT, 889 /* R/O compat */ 890 EXT2_FEATURE_RO_COMPAT_LARGE_FILE| 891 EXT4_FEATURE_RO_COMPAT_HUGE_FILE| 892 EXT4_FEATURE_RO_COMPAT_DIR_NLINK| 893 EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE| 894 EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER| 895 EXT4_FEATURE_RO_COMPAT_GDT_CSUM| 896 EXT4_FEATURE_RO_COMPAT_BIGALLOC| 897#ifdef CONFIG_QUOTA 898 EXT4_FEATURE_RO_COMPAT_QUOTA| 899#endif 900 0 901}; 902 903 904static void syntax_err_report(const char *filename, long err, int line_num) 905{ 906 fprintf(stderr, 907 _("Syntax error in mke2fs config file (%s, line #%d)\n\t%s\n"), 908 filename, line_num, error_message(err)); 909 exit(1); 910} 911 912static const char *config_fn[] = { ROOT_SYSCONFDIR "/mke2fs.conf", 0 }; 913 914static void edit_feature(const char *str, __u32 *compat_array) 915{ 916 if (!str) 917 return; 918 919 if (e2p_edit_feature(str, compat_array, ok_features)) { 920 fprintf(stderr, _("Invalid filesystem option set: %s\n"), 921 str); 922 exit(1); 923 } 924} 925 926static void edit_mntopts(const char *str, __u32 *mntopts) 927{ 928 if (!str) 929 return; 930 931 if (e2p_edit_mntopts(str, mntopts, ~0)) { 932 fprintf(stderr, _("Invalid mount option set: %s\n"), 933 str); 934 exit(1); 935 } 936} 937 938struct str_list { 939 char **list; 940 int num; 941 int max; 942}; 943 944static errcode_t init_list(struct str_list *sl) 945{ 946 sl->num = 0; 947 sl->max = 0; 948 sl->list = malloc((sl->max+1) * sizeof(char *)); 949 if (!sl->list) 950 return ENOMEM; 951 sl->list[0] = 0; 952 return 0; 953} 954 955static errcode_t push_string(struct str_list *sl, const char *str) 956{ 957 char **new_list; 958 959 if (sl->num >= sl->max) { 960 sl->max += 2; 961 new_list = realloc(sl->list, (sl->max+1) * sizeof(char *)); 962 if (!new_list) 963 return ENOMEM; 964 sl->list = new_list; 965 } 966 sl->list[sl->num] = malloc(strlen(str)+1); 967 if (sl->list[sl->num] == 0) 968 return ENOMEM; 969 strcpy(sl->list[sl->num], str); 970 sl->num++; 971 sl->list[sl->num] = 0; 972 return 0; 973} 974 975static void print_str_list(char **list) 976{ 977 char **cpp; 978 979 for (cpp = list; *cpp; cpp++) { 980 printf("'%s'", *cpp); 981 if (cpp[1]) 982 fputs(", ", stdout); 983 } 984 fputc('\n', stdout); 985} 986 987/* 988 * Return TRUE if the profile has the given subsection 989 */ 990static int profile_has_subsection(profile_t prof, const char *section, 991 const char *subsection) 992{ 993 void *state; 994 const char *names[4]; 995 char *name; 996 int ret = 0; 997 998 names[0] = section; 999 names[1] = subsection; 1000 names[2] = 0; 1001 1002 if (profile_iterator_create(prof, names, 1003 PROFILE_ITER_LIST_SECTION | 1004 PROFILE_ITER_RELATIONS_ONLY, &state)) 1005 return 0; 1006 1007 if ((profile_iterator(&state, &name, 0) == 0) && name) { 1008 free(name); 1009 ret = 1; 1010 } 1011 1012 profile_iterator_free(&state); 1013 return ret; 1014} 1015 1016static char **parse_fs_type(const char *fs_type, 1017 const char *usage_types, 1018 struct ext2_super_block *sb, 1019 blk64_t fs_blocks_count, 1020 char *progname) 1021{ 1022 const char *ext_type = 0; 1023 char *parse_str; 1024 char *profile_type = 0; 1025 char *cp, *t; 1026 const char *size_type; 1027 struct str_list list; 1028 unsigned long long meg; 1029 int is_hurd = 0; 1030 1031 if (init_list(&list)) 1032 return 0; 1033 1034 if (creator_os && (!strcasecmp(creator_os, "GNU") || 1035 !strcasecmp(creator_os, "hurd"))) 1036 is_hurd = 1; 1037 1038 if (fs_type) 1039 ext_type = fs_type; 1040 else if (is_hurd) 1041 ext_type = "ext2"; 1042 else if (!strcmp(program_name, "mke3fs")) 1043 ext_type = "ext3"; 1044 else if (!strcmp(program_name, "mke4fs")) 1045 ext_type = "ext4"; 1046 else if (progname) { 1047 ext_type = strrchr(progname, '/'); 1048 if (ext_type) 1049 ext_type++; 1050 else 1051 ext_type = progname; 1052 1053 if (!strncmp(ext_type, "mkfs.", 5)) { 1054 ext_type += 5; 1055 if (ext_type[0] == 0) 1056 ext_type = 0; 1057 } else 1058 ext_type = 0; 1059 } 1060 1061 if (!ext_type) { 1062 profile_get_string(profile, "defaults", "fs_type", 0, 1063 "ext2", &profile_type); 1064 ext_type = profile_type; 1065 if (!strcmp(ext_type, "ext2") && (journal_size != 0)) 1066 ext_type = "ext3"; 1067 } 1068 1069 1070 if (!profile_has_subsection(profile, "fs_types", ext_type) && 1071 strcmp(ext_type, "ext2")) { 1072 printf(_("\nYour mke2fs.conf file does not define the " 1073 "%s filesystem type.\n"), ext_type); 1074 if (!strcmp(ext_type, "ext3") || !strcmp(ext_type, "ext4") || 1075 !strcmp(ext_type, "ext4dev")) { 1076 printf(_("You probably need to install an updated " 1077 "mke2fs.conf file.\n\n")); 1078 } 1079 if (!force) { 1080 printf(_("Aborting...\n")); 1081 exit(1); 1082 } 1083 } 1084 1085 meg = (1024 * 1024) / EXT2_BLOCK_SIZE(sb); 1086 if (fs_blocks_count < 3 * meg) 1087 size_type = "floppy"; 1088 else if (fs_blocks_count < 512 * meg) 1089 size_type = "small"; 1090 else if (fs_blocks_count < 4 * 1024 * 1024 * meg) 1091 size_type = "default"; 1092 else if (fs_blocks_count < 16 * 1024 * 1024 * meg) 1093 size_type = "big"; 1094 else 1095 size_type = "huge"; 1096 1097 if (!usage_types) 1098 usage_types = size_type; 1099 1100 parse_str = malloc(strlen(usage_types)+1); 1101 if (!parse_str) { 1102 free(profile_type); 1103 free(list.list); 1104 return 0; 1105 } 1106 strcpy(parse_str, usage_types); 1107 1108 if (ext_type) 1109 push_string(&list, ext_type); 1110 cp = parse_str; 1111 while (1) { 1112 t = strchr(cp, ','); 1113 if (t) 1114 *t = '\0'; 1115 1116 if (*cp) { 1117 if (profile_has_subsection(profile, "fs_types", cp)) 1118 push_string(&list, cp); 1119 else if (strcmp(cp, "default") != 0) 1120 fprintf(stderr, 1121 _("\nWarning: the fs_type %s is not " 1122 "defined in mke2fs.conf\n\n"), 1123 cp); 1124 } 1125 if (t) 1126 cp = t+1; 1127 else 1128 break; 1129 } 1130 free(parse_str); 1131 free(profile_type); 1132 if (is_hurd) 1133 push_string(&list, "hurd"); 1134 return (list.list); 1135} 1136 1137static char *get_string_from_profile(char **types, const char *opt, 1138 const char *def_val) 1139{ 1140 char *ret = 0; 1141 int i; 1142 1143 for (i=0; types[i]; i++); 1144 for (i-=1; i >=0 ; i--) { 1145 profile_get_string(profile, "fs_types", types[i], 1146 opt, 0, &ret); 1147 if (ret) 1148 return ret; 1149 } 1150 profile_get_string(profile, "defaults", opt, 0, def_val, &ret); 1151 return (ret); 1152} 1153 1154static int get_int_from_profile(char **types, const char *opt, int def_val) 1155{ 1156 int ret; 1157 char **cpp; 1158 1159 profile_get_integer(profile, "defaults", opt, 0, def_val, &ret); 1160 for (cpp = types; *cpp; cpp++) 1161 profile_get_integer(profile, "fs_types", *cpp, opt, ret, &ret); 1162 return ret; 1163} 1164 1165static double get_double_from_profile(char **types, const char *opt, 1166 double def_val) 1167{ 1168 double ret; 1169 char **cpp; 1170 1171 profile_get_double(profile, "defaults", opt, 0, def_val, &ret); 1172 for (cpp = types; *cpp; cpp++) 1173 profile_get_double(profile, "fs_types", *cpp, opt, ret, &ret); 1174 return ret; 1175} 1176 1177static int get_bool_from_profile(char **types, const char *opt, int def_val) 1178{ 1179 int ret; 1180 char **cpp; 1181 1182 profile_get_boolean(profile, "defaults", opt, 0, def_val, &ret); 1183 for (cpp = types; *cpp; cpp++) 1184 profile_get_boolean(profile, "fs_types", *cpp, opt, ret, &ret); 1185 return ret; 1186} 1187 1188extern const char *mke2fs_default_profile; 1189static const char *default_files[] = { "<default>", 0 }; 1190 1191#ifdef HAVE_BLKID_PROBE_GET_TOPOLOGY 1192/* 1193 * Sets the geometry of a device (stripe/stride), and returns the 1194 * device's alignment offset, if any, or a negative error. 1195 */ 1196static int get_device_geometry(const char *file, 1197 struct ext2_super_block *fs_param, 1198 int psector_size) 1199{ 1200 int rc = -1; 1201 int blocksize; 1202 blkid_probe pr; 1203 blkid_topology tp; 1204 unsigned long min_io; 1205 unsigned long opt_io; 1206 struct stat statbuf; 1207 1208 /* Nothing to do for a regular file */ 1209 if (!stat(file, &statbuf) && S_ISREG(statbuf.st_mode)) 1210 return 0; 1211 1212 pr = blkid_new_probe_from_filename(file); 1213 if (!pr) 1214 goto out; 1215 1216 tp = blkid_probe_get_topology(pr); 1217 if (!tp) 1218 goto out; 1219 1220 min_io = blkid_topology_get_minimum_io_size(tp); 1221 opt_io = blkid_topology_get_optimal_io_size(tp); 1222 blocksize = EXT2_BLOCK_SIZE(fs_param); 1223 if ((min_io == 0) && (psector_size > blocksize)) 1224 min_io = psector_size; 1225 if ((opt_io == 0) && min_io) 1226 opt_io = min_io; 1227 if ((opt_io == 0) && (psector_size > blocksize)) 1228 opt_io = psector_size; 1229 1230 /* setting stripe/stride to blocksize is pointless */ 1231 if (min_io > blocksize) 1232 fs_param->s_raid_stride = min_io / blocksize; 1233 if (opt_io > blocksize) 1234 fs_param->s_raid_stripe_width = opt_io / blocksize; 1235 1236 rc = blkid_topology_get_alignment_offset(tp); 1237out: 1238 blkid_free_probe(pr); 1239 return rc; 1240} 1241#endif 1242 1243static void PRS(int argc, char *argv[]) 1244{ 1245 int b, c; 1246 int cluster_size = 0; 1247 char *tmp, **cpp; 1248 int blocksize = 0; 1249 int inode_ratio = 0; 1250 int inode_size = 0; 1251 unsigned long flex_bg_size = 0; 1252 double reserved_ratio = -1.0; 1253 int lsector_size = 0, psector_size = 0; 1254 int show_version_only = 0; 1255 unsigned long long num_inodes = 0; /* unsigned long long to catch too-large input */ 1256 errcode_t retval; 1257 char * oldpath = getenv("PATH"); 1258 char * extended_opts = 0; 1259 char * fs_type = 0; 1260 char * usage_types = 0; 1261 blk64_t dev_size; 1262 /* 1263 * NOTE: A few words about fs_blocks_count and blocksize: 1264 * 1265 * Initially, blocksize is set to zero, which implies 1024. 1266 * If -b is specified, blocksize is updated to the user's value. 1267 * 1268 * Next, the device size or the user's "blocks" command line argument 1269 * is used to set fs_blocks_count; the units are blocksize. 1270 * 1271 * Later, if blocksize hasn't been set and the profile specifies a 1272 * blocksize, then blocksize is updated and fs_blocks_count is scaled 1273 * appropriately. Note the change in units! 1274 * 1275 * Finally, we complain about fs_blocks_count > 2^32 on a non-64bit fs. 1276 */ 1277 blk64_t fs_blocks_count = 0; 1278#ifdef __linux__ 1279 struct utsname ut; 1280#endif 1281 long sysval; 1282 int s_opt = -1, r_opt = -1; 1283 char *fs_features = 0; 1284 int use_bsize; 1285 char *newpath; 1286 int pathlen = sizeof(PATH_SET) + 1; 1287 1288 if (oldpath) 1289 pathlen += strlen(oldpath); 1290 newpath = malloc(pathlen); 1291 if (!newpath) { 1292 fprintf(stderr, _("Couldn't allocate memory for new PATH.\n")); 1293 exit(1); 1294 } 1295 strcpy(newpath, PATH_SET); 1296 1297 /* Update our PATH to include /sbin */ 1298 if (oldpath) { 1299 strcat (newpath, ":"); 1300 strcat (newpath, oldpath); 1301 } 1302 putenv (newpath); 1303 1304 tmp = getenv("MKE2FS_SYNC"); 1305 if (tmp) 1306 sync_kludge = atoi(tmp); 1307 1308 /* Determine the system page size if possible */ 1309#ifdef HAVE_SYSCONF 1310#if (!defined(_SC_PAGESIZE) && defined(_SC_PAGE_SIZE)) 1311#define _SC_PAGESIZE _SC_PAGE_SIZE 1312#endif 1313#ifdef _SC_PAGESIZE 1314 sysval = sysconf(_SC_PAGESIZE); 1315 if (sysval > 0) 1316 sys_page_size = sysval; 1317#endif /* _SC_PAGESIZE */ 1318#endif /* HAVE_SYSCONF */ 1319 1320 if ((tmp = getenv("MKE2FS_CONFIG")) != NULL) 1321 config_fn[0] = tmp; 1322 profile_set_syntax_err_cb(syntax_err_report); 1323 retval = profile_init(config_fn, &profile); 1324 if (retval == ENOENT) { 1325 retval = profile_init(default_files, &profile); 1326 if (retval) 1327 goto profile_error; 1328 retval = profile_set_default(profile, mke2fs_default_profile); 1329 if (retval) 1330 goto profile_error; 1331 } else if (retval) { 1332profile_error: 1333 fprintf(stderr, _("Couldn't init profile successfully" 1334 " (error: %ld).\n"), retval); 1335 exit(1); 1336 } 1337 1338 setbuf(stdout, NULL); 1339 setbuf(stderr, NULL); 1340 add_error_table(&et_ext2_error_table); 1341 add_error_table(&et_prof_error_table); 1342 memset(&fs_param, 0, sizeof(struct ext2_super_block)); 1343 fs_param.s_rev_level = 1; /* Create revision 1 filesystems now */ 1344 1345#ifdef __linux__ 1346 if (uname(&ut)) { 1347 perror("uname"); 1348 exit(1); 1349 } 1350 linux_version_code = parse_version_number(ut.release); 1351 if (linux_version_code && linux_version_code < (2*65536 + 2*256)) 1352 fs_param.s_rev_level = 0; 1353#endif 1354 1355 if (argc && *argv) { 1356 program_name = get_progname(*argv); 1357 1358 /* If called as mkfs.ext3, create a journal inode */ 1359 if (!strcmp(program_name, "mkfs.ext3") || 1360 !strcmp(program_name, "mke3fs")) 1361 journal_size = -1; 1362 } 1363 1364 while ((c = getopt (argc, argv, 1365 "b:cg:i:jl:m:no:qr:s:t:vC:DE:FG:I:J:KL:M:N:O:R:ST:U:V")) != EOF) { 1366 switch (c) { 1367 case 'b': 1368 blocksize = parse_num_blocks2(optarg, -1); 1369 b = (blocksize > 0) ? blocksize : -blocksize; 1370 if (b < EXT2_MIN_BLOCK_SIZE || 1371 b > EXT2_MAX_BLOCK_SIZE) { 1372 com_err(program_name, 0, 1373 _("invalid block size - %s"), optarg); 1374 exit(1); 1375 } 1376 if (blocksize > 4096) 1377 fprintf(stderr, _("Warning: blocksize %d not " 1378 "usable on most systems.\n"), 1379 blocksize); 1380 if (blocksize > 0) 1381 fs_param.s_log_block_size = 1382 int_log2(blocksize >> 1383 EXT2_MIN_BLOCK_LOG_SIZE); 1384 break; 1385 case 'c': /* Check for bad blocks */ 1386 cflag++; 1387 break; 1388 case 'C': 1389 cluster_size = parse_num_blocks2(optarg, -1); 1390 if (cluster_size <= EXT2_MIN_CLUSTER_SIZE || 1391 cluster_size > EXT2_MAX_CLUSTER_SIZE) { 1392 com_err(program_name, 0, 1393 _("invalid cluster size - %s"), 1394 optarg); 1395 exit(1); 1396 } 1397 break; 1398 case 'D': 1399 direct_io = 1; 1400 break; 1401 case 'R': 1402 com_err(program_name, 0, 1403 _("'-R' is deprecated, use '-E' instead")); 1404 /* fallthrough */ 1405 case 'E': 1406 extended_opts = optarg; 1407 break; 1408 case 'F': 1409 force++; 1410 break; 1411 case 'g': 1412 fs_param.s_blocks_per_group = strtoul(optarg, &tmp, 0); 1413 if (*tmp) { 1414 com_err(program_name, 0, 1415 _("Illegal number for blocks per group")); 1416 exit(1); 1417 } 1418 if ((fs_param.s_blocks_per_group % 8) != 0) { 1419 com_err(program_name, 0, 1420 _("blocks per group must be multiple of 8")); 1421 exit(1); 1422 } 1423 break; 1424 case 'G': 1425 flex_bg_size = strtoul(optarg, &tmp, 0); 1426 if (*tmp) { 1427 com_err(program_name, 0, 1428 _("Illegal number for flex_bg size")); 1429 exit(1); 1430 } 1431 if (flex_bg_size < 1 || 1432 (flex_bg_size & (flex_bg_size-1)) != 0) { 1433 com_err(program_name, 0, 1434 _("flex_bg size must be a power of 2")); 1435 exit(1); 1436 } 1437 break; 1438 case 'i': 1439 inode_ratio = strtoul(optarg, &tmp, 0); 1440 if (inode_ratio < EXT2_MIN_BLOCK_SIZE || 1441 inode_ratio > EXT2_MAX_BLOCK_SIZE * 1024 || 1442 *tmp) { 1443 com_err(program_name, 0, 1444 _("invalid inode ratio %s (min %d/max %d)"), 1445 optarg, EXT2_MIN_BLOCK_SIZE, 1446 EXT2_MAX_BLOCK_SIZE * 1024); 1447 exit(1); 1448 } 1449 break; 1450 case 'I': 1451 inode_size = strtoul(optarg, &tmp, 0); 1452 if (*tmp) { 1453 com_err(program_name, 0, 1454 _("invalid inode size - %s"), optarg); 1455 exit(1); 1456 } 1457 break; 1458 case 'j': 1459 if (!journal_size) 1460 journal_size = -1; 1461 break; 1462 case 'J': 1463 parse_journal_opts(optarg); 1464 break; 1465 case 'K': 1466 fprintf(stderr, _("Warning: -K option is deprecated and " 1467 "should not be used anymore. Use " 1468 "\'-E nodiscard\' extended option " 1469 "instead!\n")); 1470 discard = 0; 1471 break; 1472 case 'l': 1473 bad_blocks_filename = realloc(bad_blocks_filename, 1474 strlen(optarg) + 1); 1475 if (!bad_blocks_filename) { 1476 com_err(program_name, ENOMEM, 1477 _("in malloc for bad_blocks_filename")); 1478 exit(1); 1479 } 1480 strcpy(bad_blocks_filename, optarg); 1481 break; 1482 case 'L': 1483 volume_label = optarg; 1484 break; 1485 case 'm': 1486 reserved_ratio = strtod(optarg, &tmp); 1487 if ( *tmp || reserved_ratio > 50 || 1488 reserved_ratio < 0) { 1489 com_err(program_name, 0, 1490 _("invalid reserved blocks percent - %s"), 1491 optarg); 1492 exit(1); 1493 } 1494 break; 1495 case 'M': 1496 mount_dir = optarg; 1497 break; 1498 case 'n': 1499 noaction++; 1500 break; 1501 case 'N': 1502 num_inodes = strtoul(optarg, &tmp, 0); 1503 if (*tmp) { 1504 com_err(program_name, 0, 1505 _("bad num inodes - %s"), optarg); 1506 exit(1); 1507 } 1508 break; 1509 case 'o': 1510 creator_os = optarg; 1511 break; 1512 case 'O': 1513 fs_features = optarg; 1514 break; 1515 case 'q': 1516 quiet = 1; 1517 break; 1518 case 'r': 1519 r_opt = strtoul(optarg, &tmp, 0); 1520 if (*tmp) { 1521 com_err(program_name, 0, 1522 _("bad revision level - %s"), optarg); 1523 exit(1); 1524 } 1525 fs_param.s_rev_level = r_opt; 1526 break; 1527 case 's': /* deprecated */ 1528 s_opt = atoi(optarg); 1529 break; 1530 case 'S': 1531 super_only = 1; 1532 break; 1533 case 't': 1534 if (fs_type) { 1535 com_err(program_name, 0, 1536 _("The -t option may only be used once")); 1537 exit(1); 1538 } 1539 fs_type = strdup(optarg); 1540 break; 1541 case 'T': 1542 if (usage_types) { 1543 com_err(program_name, 0, 1544 _("The -T option may only be used once")); 1545 exit(1); 1546 } 1547 usage_types = strdup(optarg); 1548 break; 1549 case 'U': 1550 fs_uuid = optarg; 1551 break; 1552 case 'v': 1553 verbose = 1; 1554 break; 1555 case 'V': 1556 /* Print version number and exit */ 1557 show_version_only++; 1558 break; 1559 default: 1560 usage(); 1561 } 1562 } 1563 if ((optind == argc) && !show_version_only) 1564 usage(); 1565 device_name = argv[optind++]; 1566 1567 if (!quiet || show_version_only) 1568 fprintf (stderr, "mke2fs %s (%s)\n", E2FSPROGS_VERSION, 1569 E2FSPROGS_DATE); 1570 1571 if (show_version_only) { 1572 fprintf(stderr, _("\tUsing %s\n"), 1573 error_message(EXT2_ET_BASE)); 1574 exit(0); 1575 } 1576 1577 /* 1578 * If there's no blocksize specified and there is a journal 1579 * device, use it to figure out the blocksize 1580 */ 1581 if (blocksize <= 0 && journal_device) { 1582 ext2_filsys jfs; 1583 io_manager io_ptr; 1584 1585#ifdef CONFIG_TESTIO_DEBUG 1586 if (getenv("TEST_IO_FLAGS") || getenv("TEST_IO_BLOCK")) { 1587 io_ptr = test_io_manager; 1588 test_io_backing_manager = unix_io_manager; 1589 } else 1590#endif 1591 io_ptr = unix_io_manager; 1592 retval = ext2fs_open(journal_device, 1593 EXT2_FLAG_JOURNAL_DEV_OK, 0, 1594 0, io_ptr, &jfs); 1595 if (retval) { 1596 com_err(program_name, retval, 1597 _("while trying to open journal device %s\n"), 1598 journal_device); 1599 exit(1); 1600 } 1601 if ((blocksize < 0) && (jfs->blocksize < (unsigned) (-blocksize))) { 1602 com_err(program_name, 0, 1603 _("Journal dev blocksize (%d) smaller than " 1604 "minimum blocksize %d\n"), jfs->blocksize, 1605 -blocksize); 1606 exit(1); 1607 } 1608 blocksize = jfs->blocksize; 1609 printf(_("Using journal device's blocksize: %d\n"), blocksize); 1610 fs_param.s_log_block_size = 1611 int_log2(blocksize >> EXT2_MIN_BLOCK_LOG_SIZE); 1612 ext2fs_close(jfs); 1613 } 1614 1615 if (optind < argc) { 1616 fs_blocks_count = parse_num_blocks2(argv[optind++], 1617 fs_param.s_log_block_size); 1618 if (!fs_blocks_count) { 1619 com_err(program_name, 0, 1620 _("invalid blocks '%s' on device '%s'"), 1621 argv[optind - 1], device_name); 1622 exit(1); 1623 } 1624 } 1625 if (optind < argc) 1626 usage(); 1627 1628 if (!force) 1629 check_plausibility(device_name); 1630 check_mount(device_name, force, _("filesystem")); 1631 1632 /* Determine the size of the device (if possible) */ 1633 if (noaction && fs_blocks_count) { 1634 dev_size = fs_blocks_count; 1635 retval = 0; 1636 } else 1637 retval = ext2fs_get_device_size2(device_name, 1638 EXT2_BLOCK_SIZE(&fs_param), 1639 &dev_size); 1640 1641 if (retval && (retval != EXT2_ET_UNIMPLEMENTED)) { 1642 com_err(program_name, retval, 1643 _("while trying to determine filesystem size")); 1644 exit(1); 1645 } 1646 if (!fs_blocks_count) { 1647 if (retval == EXT2_ET_UNIMPLEMENTED) { 1648 com_err(program_name, 0, 1649 _("Couldn't determine device size; you " 1650 "must specify\nthe size of the " 1651 "filesystem\n")); 1652 exit(1); 1653 } else { 1654 if (dev_size == 0) { 1655 com_err(program_name, 0, 1656 _("Device size reported to be zero. " 1657 "Invalid partition specified, or\n\t" 1658 "partition table wasn't reread " 1659 "after running fdisk, due to\n\t" 1660 "a modified partition being busy " 1661 "and in use. You may need to reboot\n\t" 1662 "to re-read your partition table.\n" 1663 )); 1664 exit(1); 1665 } 1666 fs_blocks_count = dev_size; 1667 if (sys_page_size > EXT2_BLOCK_SIZE(&fs_param)) 1668 fs_blocks_count &= ~((blk64_t) ((sys_page_size / 1669 EXT2_BLOCK_SIZE(&fs_param))-1)); 1670 } 1671 } else if (!force && (fs_blocks_count > dev_size)) { 1672 com_err(program_name, 0, 1673 _("Filesystem larger than apparent device size.")); 1674 proceed_question(); 1675 } 1676 1677 if (!fs_type) 1678 profile_get_string(profile, "devices", device_name, 1679 "fs_type", 0, &fs_type); 1680 if (!usage_types) 1681 profile_get_string(profile, "devices", device_name, 1682 "usage_types", 0, &usage_types); 1683 1684 /* 1685 * We have the file system (or device) size, so we can now 1686 * determine the appropriate file system types so the fs can 1687 * be appropriately configured. 1688 */ 1689 fs_types = parse_fs_type(fs_type, usage_types, &fs_param, 1690 fs_blocks_count ? fs_blocks_count : dev_size, 1691 argv[0]); 1692 if (!fs_types) { 1693 fprintf(stderr, _("Failed to parse fs types list\n")); 1694 exit(1); 1695 } 1696 1697 /* Figure out what features should be enabled */ 1698 1699 tmp = NULL; 1700 if (fs_param.s_rev_level != EXT2_GOOD_OLD_REV) { 1701 tmp = get_string_from_profile(fs_types, "base_features", 1702 "sparse_super,filetype,resize_inode,dir_index"); 1703 edit_feature(tmp, &fs_param.s_feature_compat); 1704 free(tmp); 1705 1706 /* And which mount options as well */ 1707 tmp = get_string_from_profile(fs_types, "default_mntopts", 1708 "acl,user_xattr"); 1709 edit_mntopts(tmp, &fs_param.s_default_mount_opts); 1710 if (tmp) 1711 free(tmp); 1712 1713 for (cpp = fs_types; *cpp; cpp++) { 1714 tmp = NULL; 1715 profile_get_string(profile, "fs_types", *cpp, 1716 "features", "", &tmp); 1717 if (tmp && *tmp) 1718 edit_feature(tmp, &fs_param.s_feature_compat); 1719 if (tmp) 1720 free(tmp); 1721 } 1722 tmp = get_string_from_profile(fs_types, "default_features", 1723 ""); 1724 } 1725 edit_feature(fs_features ? fs_features : tmp, 1726 &fs_param.s_feature_compat); 1727 if (tmp) 1728 free(tmp); 1729 1730 /* Get the hardware sector sizes, if available */ 1731 retval = ext2fs_get_device_sectsize(device_name, &lsector_size); 1732 if (retval) { 1733 com_err(program_name, retval, 1734 _("while trying to determine hardware sector size")); 1735 exit(1); 1736 } 1737 retval = ext2fs_get_device_phys_sectsize(device_name, &psector_size); 1738 if (retval) { 1739 com_err(program_name, retval, 1740 _("while trying to determine physical sector size")); 1741 exit(1); 1742 } 1743 1744 tmp = getenv("MKE2FS_DEVICE_SECTSIZE"); 1745 if (tmp != NULL) 1746 lsector_size = atoi(tmp); 1747 tmp = getenv("MKE2FS_DEVICE_PHYS_SECTSIZE"); 1748 if (tmp != NULL) 1749 psector_size = atoi(tmp); 1750 1751 /* Older kernels may not have physical/logical distinction */ 1752 if (!psector_size) 1753 psector_size = lsector_size; 1754 1755 if (blocksize <= 0) { 1756 use_bsize = get_int_from_profile(fs_types, "blocksize", 4096); 1757 1758 if (use_bsize == -1) { 1759 use_bsize = sys_page_size; 1760 if ((linux_version_code < (2*65536 + 6*256)) && 1761 (use_bsize > 4096)) 1762 use_bsize = 4096; 1763 } 1764 if (lsector_size && use_bsize < lsector_size) 1765 use_bsize = lsector_size; 1766 if ((blocksize < 0) && (use_bsize < (-blocksize))) 1767 use_bsize = -blocksize; 1768 blocksize = use_bsize; 1769 fs_blocks_count /= (blocksize / 1024); 1770 } else { 1771 if (blocksize < lsector_size) { /* Impossible */ 1772 com_err(program_name, EINVAL, 1773 _("while setting blocksize; too small " 1774 "for device\n")); 1775 exit(1); 1776 } else if ((blocksize < psector_size) && 1777 (psector_size <= sys_page_size)) { /* Suboptimal */ 1778 fprintf(stderr, _("Warning: specified blocksize %d is " 1779 "less than device physical sectorsize %d\n"), 1780 blocksize, psector_size); 1781 } 1782 } 1783 1784 fs_param.s_log_block_size = 1785 int_log2(blocksize >> EXT2_MIN_BLOCK_LOG_SIZE); 1786 1787 /* 1788 * We now need to do a sanity check of fs_blocks_count for 1789 * 32-bit vs 64-bit block number support. 1790 */ 1791 if ((fs_blocks_count > MAX_32_NUM) && 1792 !(fs_param.s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT) && 1793 get_bool_from_profile(fs_types, "auto_64-bit_support", 0)) { 1794 fs_param.s_feature_incompat |= EXT4_FEATURE_INCOMPAT_64BIT; 1795 fs_param.s_feature_compat &= ~EXT2_FEATURE_COMPAT_RESIZE_INODE; 1796 } 1797 if ((fs_blocks_count > MAX_32_NUM) && 1798 !(fs_param.s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT)) { 1799 fprintf(stderr, _("%s: Size of device (0x%llx blocks) %s " 1800 "too big to be expressed\n\t" 1801 "in 32 bits using a blocksize of %d.\n"), 1802 program_name, fs_blocks_count, device_name, 1803 EXT2_BLOCK_SIZE(&fs_param)); 1804 exit(1); 1805 } 1806 1807 ext2fs_blocks_count_set(&fs_param, fs_blocks_count); 1808 1809 if (fs_param.s_feature_incompat & EXT3_FEATURE_INCOMPAT_JOURNAL_DEV) { 1810 fs_types[0] = strdup("journal"); 1811 fs_types[1] = 0; 1812 } 1813 1814 if (verbose) { 1815 fputs(_("fs_types for mke2fs.conf resolution: "), stdout); 1816 print_str_list(fs_types); 1817 } 1818 1819 if (r_opt == EXT2_GOOD_OLD_REV && 1820 (fs_param.s_feature_compat || fs_param.s_feature_incompat || 1821 fs_param.s_feature_ro_compat)) { 1822 fprintf(stderr, _("Filesystem features not supported " 1823 "with revision 0 filesystems\n")); 1824 exit(1); 1825 } 1826 1827 if (s_opt > 0) { 1828 if (r_opt == EXT2_GOOD_OLD_REV) { 1829 fprintf(stderr, _("Sparse superblocks not supported " 1830 "with revision 0 filesystems\n")); 1831 exit(1); 1832 } 1833 fs_param.s_feature_ro_compat |= 1834 EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER; 1835 } else if (s_opt == 0) 1836 fs_param.s_feature_ro_compat &= 1837 ~EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER; 1838 1839 if (journal_size != 0) { 1840 if (r_opt == EXT2_GOOD_OLD_REV) { 1841 fprintf(stderr, _("Journals not supported " 1842 "with revision 0 filesystems\n")); 1843 exit(1); 1844 } 1845 fs_param.s_feature_compat |= 1846 EXT3_FEATURE_COMPAT_HAS_JOURNAL; 1847 } 1848 1849 /* Get reserved_ratio from profile if not specified on cmd line. */ 1850 if (reserved_ratio < 0.0) { 1851 reserved_ratio = get_double_from_profile( 1852 fs_types, "reserved_ratio", 5.0); 1853 if (reserved_ratio > 50 || reserved_ratio < 0) { 1854 com_err(program_name, 0, 1855 _("invalid reserved blocks percent - %lf"), 1856 reserved_ratio); 1857 exit(1); 1858 } 1859 } 1860 1861 if (fs_param.s_feature_incompat & 1862 EXT3_FEATURE_INCOMPAT_JOURNAL_DEV) { 1863 reserved_ratio = 0; 1864 fs_param.s_feature_incompat = EXT3_FEATURE_INCOMPAT_JOURNAL_DEV; 1865 fs_param.s_feature_compat = 0; 1866 fs_param.s_feature_ro_compat = 0; 1867 } 1868 1869 /* Check the user's mkfs options for 64bit */ 1870 if ((fs_param.s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT) && 1871 !(fs_param.s_feature_incompat & EXT3_FEATURE_INCOMPAT_EXTENTS)) { 1872 printf(_("Extents MUST be enabled for a 64-bit filesystem. " 1873 "Pass -O extents to rectify.\n")); 1874 exit(1); 1875 } 1876 1877 /* Set first meta blockgroup via an environment variable */ 1878 /* (this is mostly for debugging purposes) */ 1879 if ((fs_param.s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG) && 1880 ((tmp = getenv("MKE2FS_FIRST_META_BG")))) 1881 fs_param.s_first_meta_bg = atoi(tmp); 1882 if (fs_param.s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_BIGALLOC) { 1883 if (!cluster_size) 1884 cluster_size = get_int_from_profile(fs_types, 1885 "cluster_size", 1886 blocksize*16); 1887 fs_param.s_log_cluster_size = 1888 int_log2(cluster_size >> EXT2_MIN_CLUSTER_LOG_SIZE); 1889 if (fs_param.s_log_cluster_size && 1890 fs_param.s_log_cluster_size < fs_param.s_log_block_size) { 1891 com_err(program_name, 0, 1892 _("The cluster size may not be " 1893 "smaller than the block size.\n")); 1894 exit(1); 1895 } 1896 } else if (cluster_size) { 1897 com_err(program_name, 0, 1898 _("specifying a cluster size requires the " 1899 "bigalloc feature")); 1900 exit(1); 1901 } else 1902 fs_param.s_log_cluster_size = fs_param.s_log_block_size; 1903 1904 if (inode_ratio == 0) { 1905 inode_ratio = get_int_from_profile(fs_types, "inode_ratio", 1906 8192); 1907 if (inode_ratio < blocksize) 1908 inode_ratio = blocksize; 1909 if (inode_ratio < EXT2_CLUSTER_SIZE(&fs_param)) 1910 inode_ratio = EXT2_CLUSTER_SIZE(&fs_param); 1911 } 1912 1913#ifdef HAVE_BLKID_PROBE_GET_TOPOLOGY 1914 retval = get_device_geometry(device_name, &fs_param, psector_size); 1915 if (retval < 0) { 1916 fprintf(stderr, 1917 _("warning: Unable to get device geometry for %s\n"), 1918 device_name); 1919 } else if (retval) { 1920 printf(_("%s alignment is offset by %lu bytes.\n"), 1921 device_name, retval); 1922 printf(_("This may result in very poor performance, " 1923 "(re)-partitioning suggested.\n")); 1924 } 1925#endif 1926 1927 blocksize = EXT2_BLOCK_SIZE(&fs_param); 1928 1929 /* 1930 * Initialize s_desc_size so that the parse_extended_opts() 1931 * can correctly handle "-E resize=NNN" if the 64-bit option 1932 * is set. 1933 */ 1934 if (fs_param.s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT) 1935 fs_param.s_desc_size = EXT2_MIN_DESC_SIZE_64BIT; 1936 1937 /* This check should happen beyond the last assignment to blocksize */ 1938 if (blocksize > sys_page_size) { 1939 if (!force) { 1940 com_err(program_name, 0, 1941 _("%d-byte blocks too big for system (max %d)"), 1942 blocksize, sys_page_size); 1943 proceed_question(); 1944 } 1945 fprintf(stderr, _("Warning: %d-byte blocks too big for system " 1946 "(max %d), forced to continue\n"), 1947 blocksize, sys_page_size); 1948 } 1949 1950 lazy_itable_init = 0; 1951 if (access("/sys/fs/ext4/features/lazy_itable_init", R_OK) == 0) 1952 lazy_itable_init = 1; 1953 1954 lazy_itable_init = get_bool_from_profile(fs_types, 1955 "lazy_itable_init", 1956 lazy_itable_init); 1957 discard = get_bool_from_profile(fs_types, "discard" , discard); 1958 journal_flags |= get_bool_from_profile(fs_types, 1959 "lazy_journal_init", 0) ? 1960 EXT2_MKJOURNAL_LAZYINIT : 0; 1961 journal_flags |= EXT2_MKJOURNAL_NO_MNT_CHECK; 1962 1963 /* Get options from profile */ 1964 for (cpp = fs_types; *cpp; cpp++) { 1965 tmp = NULL; 1966 profile_get_string(profile, "fs_types", *cpp, "options", "", &tmp); 1967 if (tmp && *tmp) 1968 parse_extended_opts(&fs_param, tmp); 1969 free(tmp); 1970 } 1971 1972 if (extended_opts) 1973 parse_extended_opts(&fs_param, extended_opts); 1974 1975 /* Can't support bigalloc feature without extents feature */ 1976 if ((fs_param.s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_BIGALLOC) && 1977 !(fs_param.s_feature_incompat & EXT3_FEATURE_INCOMPAT_EXTENTS)) { 1978 com_err(program_name, 0, 1979 _("Can't support bigalloc feature without " 1980 "extents feature")); 1981 exit(1); 1982 } 1983 1984 if ((fs_param.s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG) && 1985 (fs_param.s_feature_compat & EXT2_FEATURE_COMPAT_RESIZE_INODE)) { 1986 fprintf(stderr, _("The resize_inode and meta_bg features " 1987 "are not compatible.\n" 1988 "They can not be both enabled " 1989 "simultaneously.\n")); 1990 exit(1); 1991 } 1992 1993 if (!quiet && 1994 (fs_param.s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_BIGALLOC)) 1995 fprintf(stderr, _("\nWarning: the bigalloc feature is still " 1996 "under development\n" 1997 "See https://ext4.wiki.kernel.org/" 1998 "index.php/Bigalloc for more information\n\n")); 1999 2000 if (!quiet && 2001 (fs_param.s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_QUOTA)) 2002 fprintf(stderr, _("\nWarning: the quota feature is still " 2003 "under development\n" 2004 "See https://ext4.wiki.kernel.org/" 2005 "index.php/Quota for more information\n\n")); 2006 2007 /* Since sparse_super is the default, we would only have a problem 2008 * here if it was explicitly disabled. 2009 */ 2010 if ((fs_param.s_feature_compat & EXT2_FEATURE_COMPAT_RESIZE_INODE) && 2011 !(fs_param.s_feature_ro_compat&EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER)) { 2012 com_err(program_name, 0, 2013 _("reserved online resize blocks not supported " 2014 "on non-sparse filesystem")); 2015 exit(1); 2016 } 2017 2018 if (fs_param.s_blocks_per_group) { 2019 if (fs_param.s_blocks_per_group < 256 || 2020 fs_param.s_blocks_per_group > 8 * (unsigned) blocksize) { 2021 com_err(program_name, 0, 2022 _("blocks per group count out of range")); 2023 exit(1); 2024 } 2025 } 2026 2027 /* 2028 * If the bigalloc feature is enabled, then the -g option will 2029 * specify the number of clusters per group. 2030 */ 2031 if (fs_param.s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_BIGALLOC) { 2032 fs_param.s_clusters_per_group = fs_param.s_blocks_per_group; 2033 fs_param.s_blocks_per_group = 0; 2034 } 2035 2036 if (inode_size == 0) 2037 inode_size = get_int_from_profile(fs_types, "inode_size", 0); 2038 if (!flex_bg_size && (fs_param.s_feature_incompat & 2039 EXT4_FEATURE_INCOMPAT_FLEX_BG)) 2040 flex_bg_size = get_int_from_profile(fs_types, 2041 "flex_bg_size", 16); 2042 if (flex_bg_size) { 2043 if (!(fs_param.s_feature_incompat & 2044 EXT4_FEATURE_INCOMPAT_FLEX_BG)) { 2045 com_err(program_name, 0, 2046 _("Flex_bg feature not enabled, so " 2047 "flex_bg size may not be specified")); 2048 exit(1); 2049 } 2050 fs_param.s_log_groups_per_flex = int_log2(flex_bg_size); 2051 } 2052 2053 if (inode_size && fs_param.s_rev_level >= EXT2_DYNAMIC_REV) { 2054 if (inode_size < EXT2_GOOD_OLD_INODE_SIZE || 2055 inode_size > EXT2_BLOCK_SIZE(&fs_param) || 2056 inode_size & (inode_size - 1)) { 2057 com_err(program_name, 0, 2058 _("invalid inode size %d (min %d/max %d)"), 2059 inode_size, EXT2_GOOD_OLD_INODE_SIZE, 2060 blocksize); 2061 exit(1); 2062 } 2063 fs_param.s_inode_size = inode_size; 2064 } 2065 2066 /* Make sure number of inodes specified will fit in 32 bits */ 2067 if (num_inodes == 0) { 2068 unsigned long long n; 2069 n = ext2fs_blocks_count(&fs_param) * blocksize / inode_ratio; 2070 if (n > MAX_32_NUM) { 2071 if (fs_param.s_feature_incompat & 2072 EXT4_FEATURE_INCOMPAT_64BIT) 2073 num_inodes = MAX_32_NUM; 2074 else { 2075 com_err(program_name, 0, 2076 _("too many inodes (%llu), raise " 2077 "inode ratio?"), n); 2078 exit(1); 2079 } 2080 } 2081 } else if (num_inodes > MAX_32_NUM) { 2082 com_err(program_name, 0, 2083 _("too many inodes (%llu), specify < 2^32 inodes"), 2084 num_inodes); 2085 exit(1); 2086 } 2087 /* 2088 * Calculate number of inodes based on the inode ratio 2089 */ 2090 fs_param.s_inodes_count = num_inodes ? num_inodes : 2091 (ext2fs_blocks_count(&fs_param) * blocksize) / inode_ratio; 2092 2093 if ((((unsigned long long)fs_param.s_inodes_count) * 2094 (inode_size ? inode_size : EXT2_GOOD_OLD_INODE_SIZE)) >= 2095 ((ext2fs_blocks_count(&fs_param)) * 2096 EXT2_BLOCK_SIZE(&fs_param))) { 2097 com_err(program_name, 0, _("inode_size (%u) * inodes_count " 2098 "(%u) too big for a\n\t" 2099 "filesystem with %llu blocks, " 2100 "specify higher inode_ratio (-i)\n\t" 2101 "or lower inode count (-N).\n"), 2102 inode_size ? inode_size : EXT2_GOOD_OLD_INODE_SIZE, 2103 fs_param.s_inodes_count, 2104 (unsigned long long) ext2fs_blocks_count(&fs_param)); 2105 exit(1); 2106 } 2107 2108 /* 2109 * Calculate number of blocks to reserve 2110 */ 2111 ext2fs_r_blocks_count_set(&fs_param, reserved_ratio * 2112 ext2fs_blocks_count(&fs_param) / 100.0); 2113 2114 free(fs_type); 2115 free(usage_types); 2116} 2117 2118static int should_do_undo(const char *name) 2119{ 2120 errcode_t retval; 2121 io_channel channel; 2122 __u16 s_magic; 2123 struct ext2_super_block super; 2124 io_manager manager = unix_io_manager; 2125 int csum_flag, force_undo; 2126 2127 csum_flag = EXT2_HAS_RO_COMPAT_FEATURE(&fs_param, 2128 EXT4_FEATURE_RO_COMPAT_GDT_CSUM); 2129 force_undo = get_int_from_profile(fs_types, "force_undo", 0); 2130 if (!force_undo && (!csum_flag || !lazy_itable_init)) 2131 return 0; 2132 2133 retval = manager->open(name, IO_FLAG_EXCLUSIVE, &channel); 2134 if (retval) { 2135 /* 2136 * We don't handle error cases instead we 2137 * declare that the file system doesn't exist 2138 * and let the rest of mke2fs take care of 2139 * error 2140 */ 2141 retval = 0; 2142 goto open_err_out; 2143 } 2144 2145 io_channel_set_blksize(channel, SUPERBLOCK_OFFSET); 2146 retval = io_channel_read_blk64(channel, 1, -SUPERBLOCK_SIZE, &super); 2147 if (retval) { 2148 retval = 0; 2149 goto err_out; 2150 } 2151 2152#if defined(WORDS_BIGENDIAN) 2153 s_magic = ext2fs_swab16(super.s_magic); 2154#else 2155 s_magic = super.s_magic; 2156#endif 2157 2158 if (s_magic == EXT2_SUPER_MAGIC) 2159 retval = 1; 2160 2161err_out: 2162 io_channel_close(channel); 2163 2164open_err_out: 2165 2166 return retval; 2167} 2168 2169static int mke2fs_setup_tdb(const char *name, io_manager *io_ptr) 2170{ 2171 errcode_t retval = ENOMEM; 2172 char *tdb_dir = NULL, *tdb_file = NULL; 2173 char *dev_name, *tmp_name; 2174 int free_tdb_dir = 0; 2175 2176 /* 2177 * Configuration via a conf file would be 2178 * nice 2179 */ 2180 tdb_dir = getenv("E2FSPROGS_UNDO_DIR"); 2181 if (!tdb_dir) { 2182 profile_get_string(profile, "defaults", 2183 "undo_dir", 0, "/var/lib/e2fsprogs", 2184 &tdb_dir); 2185 free_tdb_dir = 1; 2186 } 2187 2188 if (!strcmp(tdb_dir, "none") || (tdb_dir[0] == 0) || 2189 access(tdb_dir, W_OK)) { 2190 if (free_tdb_dir) 2191 free(tdb_dir); 2192 return 0; 2193 } 2194 2195 tmp_name = strdup(name); 2196 if (!tmp_name) 2197 goto errout; 2198 dev_name = basename(tmp_name); 2199 tdb_file = malloc(strlen(tdb_dir) + 8 + strlen(dev_name) + 7 + 1); 2200 if (!tdb_file) { 2201 free(tmp_name); 2202 goto errout; 2203 } 2204 sprintf(tdb_file, "%s/mke2fs-%s.e2undo", tdb_dir, dev_name); 2205 free(tmp_name); 2206 2207 if (!access(tdb_file, F_OK)) { 2208 if (unlink(tdb_file) < 0) { 2209 retval = errno; 2210 goto errout; 2211 } 2212 } 2213 2214 set_undo_io_backing_manager(*io_ptr); 2215 *io_ptr = undo_io_manager; 2216 retval = set_undo_io_backup_file(tdb_file); 2217 if (retval) 2218 goto errout; 2219 printf(_("Overwriting existing filesystem; this can be undone " 2220 "using the command:\n" 2221 " e2undo %s %s\n\n"), tdb_file, name); 2222 2223 if (free_tdb_dir) 2224 free(tdb_dir); 2225 free(tdb_file); 2226 return 0; 2227 2228errout: 2229 if (free_tdb_dir) 2230 free(tdb_dir); 2231 free(tdb_file); 2232 com_err(program_name, retval, 2233 _("while trying to setup undo file\n")); 2234 return retval; 2235} 2236 2237static int mke2fs_discard_device(ext2_filsys fs) 2238{ 2239 struct ext2fs_numeric_progress_struct progress; 2240 blk64_t blocks = ext2fs_blocks_count(fs->super); 2241 blk64_t count = DISCARD_STEP_MB; 2242 blk64_t cur; 2243 int retval = 0; 2244 2245 /* 2246 * Let's try if discard really works on the device, so 2247 * we do not print numeric progress resulting in failure 2248 * afterwards. 2249 */ 2250 retval = io_channel_discard(fs->io, 0, fs->blocksize); 2251 if (retval) 2252 return retval; 2253 cur = fs->blocksize; 2254 2255 count *= (1024 * 1024); 2256 count /= fs->blocksize; 2257 2258 ext2fs_numeric_progress_init(fs, &progress, 2259 _("Discarding device blocks: "), 2260 blocks); 2261 while (cur < blocks) { 2262 ext2fs_numeric_progress_update(fs, &progress, cur); 2263 2264 if (cur + count > blocks) 2265 count = blocks - cur; 2266 2267 retval = io_channel_discard(fs->io, cur, count); 2268 if (retval) 2269 break; 2270 cur += count; 2271 } 2272 2273 if (retval) { 2274 ext2fs_numeric_progress_close(fs, &progress, 2275 _("failed - ")); 2276 if (!quiet) 2277 printf("%s\n",error_message(retval)); 2278 } else 2279 ext2fs_numeric_progress_close(fs, &progress, 2280 _("done \n")); 2281 2282 return retval; 2283} 2284 2285static void fix_cluster_bg_counts(ext2_filsys fs) 2286{ 2287 blk64_t cluster, num_clusters, tot_free; 2288 unsigned num = 0; 2289 int grp_free, num_free, group; 2290 2291 num_clusters = EXT2FS_B2C(fs, ext2fs_blocks_count(fs->super)); 2292 tot_free = num_free = group = grp_free = 0; 2293 for (cluster = EXT2FS_B2C(fs, fs->super->s_first_data_block); 2294 cluster < num_clusters; cluster++) { 2295 if (!ext2fs_test_block_bitmap2(fs->block_map, 2296 EXT2FS_C2B(fs, cluster))) { 2297 grp_free++; 2298 tot_free++; 2299 } 2300 num++; 2301 if ((num == fs->super->s_clusters_per_group) || 2302 (cluster == num_clusters-1)) { 2303 ext2fs_bg_free_blocks_count_set(fs, group, grp_free); 2304 ext2fs_group_desc_csum_set(fs, group); 2305 num = 0; 2306 grp_free = 0; 2307 group++; 2308 } 2309 } 2310 ext2fs_free_blocks_count_set(fs->super, EXT2FS_C2B(fs, tot_free)); 2311} 2312 2313static int create_quota_inodes(ext2_filsys fs) 2314{ 2315 quota_ctx_t qctx; 2316 2317 quota_init_context(&qctx, fs, -1); 2318 quota_compute_usage(qctx); 2319 quota_write_inode(qctx, quotatype); 2320 quota_release_context(&qctx); 2321 2322 return 0; 2323} 2324 2325int main (int argc, char *argv[]) 2326{ 2327 errcode_t retval = 0; 2328 ext2_filsys fs; 2329 badblocks_list bb_list = 0; 2330 unsigned int journal_blocks; 2331 unsigned int i, checkinterval; 2332 int max_mnt_count; 2333 int val, hash_alg; 2334 int flags; 2335 int old_bitmaps; 2336 io_manager io_ptr; 2337 char tdb_string[40]; 2338 char *hash_alg_str; 2339 int itable_zeroed = 0; 2340 2341#ifdef ENABLE_NLS 2342 setlocale(LC_MESSAGES, ""); 2343 setlocale(LC_CTYPE, ""); 2344 bindtextdomain(NLS_CAT_NAME, LOCALEDIR); 2345 textdomain(NLS_CAT_NAME); 2346 set_com_err_gettext(gettext); 2347#endif 2348 PRS(argc, argv); 2349 2350#ifdef CONFIG_TESTIO_DEBUG 2351 if (getenv("TEST_IO_FLAGS") || getenv("TEST_IO_BLOCK")) { 2352 io_ptr = test_io_manager; 2353 test_io_backing_manager = unix_io_manager; 2354 } else 2355#endif 2356 io_ptr = unix_io_manager; 2357 2358 if (should_do_undo(device_name)) { 2359 retval = mke2fs_setup_tdb(device_name, &io_ptr); 2360 if (retval) 2361 exit(1); 2362 } 2363 2364 /* 2365 * Initialize the superblock.... 2366 */ 2367 flags = EXT2_FLAG_EXCLUSIVE; 2368 if (direct_io) 2369 flags |= EXT2_FLAG_DIRECT_IO; 2370 profile_get_boolean(profile, "options", "old_bitmaps", 0, 0, 2371 &old_bitmaps); 2372 if (!old_bitmaps) 2373 flags |= EXT2_FLAG_64BITS; 2374 /* 2375 * By default, we print how many inode tables or block groups 2376 * or whatever we've written so far. The quiet flag disables 2377 * this, along with a lot of other output. 2378 */ 2379 if (!quiet) 2380 flags |= EXT2_FLAG_PRINT_PROGRESS; 2381 retval = ext2fs_initialize(device_name, flags, &fs_param, io_ptr, &fs); 2382 if (retval) { 2383 com_err(device_name, retval, _("while setting up superblock")); 2384 exit(1); 2385 } 2386 2387 /* Calculate journal blocks */ 2388 if (!journal_device && ((journal_size) || 2389 (fs_param.s_feature_compat & 2390 EXT3_FEATURE_COMPAT_HAS_JOURNAL))) 2391 journal_blocks = figure_journal_size(journal_size, fs); 2392 2393 /* Can't undo discard ... */ 2394 if (!noaction && discard && (io_ptr != undo_io_manager)) { 2395 retval = mke2fs_discard_device(fs); 2396 if (!retval && io_channel_discard_zeroes_data(fs->io)) { 2397 if (verbose) 2398 printf(_("Discard succeeded and will return 0s " 2399 " - skipping inode table wipe\n")); 2400 lazy_itable_init = 1; 2401 itable_zeroed = 1; 2402 } 2403 } 2404 2405 sprintf(tdb_string, "tdb_data_size=%d", fs->blocksize <= 4096 ? 2406 32768 : fs->blocksize * 8); 2407 io_channel_set_options(fs->io, tdb_string); 2408 2409 if (fs_param.s_flags & EXT2_FLAGS_TEST_FILESYS) 2410 fs->super->s_flags |= EXT2_FLAGS_TEST_FILESYS; 2411 2412 if ((fs_param.s_feature_incompat & 2413 (EXT3_FEATURE_INCOMPAT_EXTENTS|EXT4_FEATURE_INCOMPAT_FLEX_BG)) || 2414 (fs_param.s_feature_ro_compat & 2415 (EXT4_FEATURE_RO_COMPAT_HUGE_FILE|EXT4_FEATURE_RO_COMPAT_GDT_CSUM| 2416 EXT4_FEATURE_RO_COMPAT_DIR_NLINK| 2417 EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE))) 2418 fs->super->s_kbytes_written = 1; 2419 2420 /* 2421 * Wipe out the old on-disk superblock 2422 */ 2423 if (!noaction) 2424 zap_sector(fs, 2, 6); 2425 2426 /* 2427 * Parse or generate a UUID for the filesystem 2428 */ 2429 if (fs_uuid) { 2430 if (uuid_parse(fs_uuid, fs->super->s_uuid) !=0) { 2431 com_err(device_name, 0, "could not parse UUID: %s\n", 2432 fs_uuid); 2433 exit(1); 2434 } 2435 } else 2436 uuid_generate(fs->super->s_uuid); 2437 2438 /* 2439 * Initialize the directory index variables 2440 */ 2441 hash_alg_str = get_string_from_profile(fs_types, "hash_alg", 2442 "half_md4"); 2443 hash_alg = e2p_string2hash(hash_alg_str); 2444 free(hash_alg_str); 2445 fs->super->s_def_hash_version = (hash_alg >= 0) ? hash_alg : 2446 EXT2_HASH_HALF_MD4; 2447 uuid_generate((unsigned char *) fs->super->s_hash_seed); 2448 2449 /* 2450 * Periodic checks can be enabled/disabled via config file. 2451 * Note we override the kernel include file's idea of what the default 2452 * check interval (never) should be. It's a good idea to check at 2453 * least *occasionally*, specially since servers will never rarely get 2454 * to reboot, since Linux is so robust these days. :-) 2455 * 2456 * 180 days (six months) seems like a good value. 2457 */ 2458#ifdef EXT2_DFL_CHECKINTERVAL 2459#undef EXT2_DFL_CHECKINTERVAL 2460#endif 2461#define EXT2_DFL_CHECKINTERVAL (86400L * 180L) 2462 2463 if (get_bool_from_profile(fs_types, "enable_periodic_fsck", 0)) { 2464 fs->super->s_checkinterval = EXT2_DFL_CHECKINTERVAL; 2465 fs->super->s_max_mnt_count = EXT2_DFL_MAX_MNT_COUNT; 2466 /* 2467 * Add "jitter" to the superblock's check interval so that we 2468 * don't check all the filesystems at the same time. We use a 2469 * kludgy hack of using the UUID to derive a random jitter value 2470 */ 2471 for (i = 0, val = 0 ; i < sizeof(fs->super->s_uuid); i++) 2472 val += fs->super->s_uuid[i]; 2473 fs->super->s_max_mnt_count += val % EXT2_DFL_MAX_MNT_COUNT; 2474 } else 2475 fs->super->s_max_mnt_count = -1; 2476 2477 /* 2478 * Override the creator OS, if applicable 2479 */ 2480 if (creator_os && !set_os(fs->super, creator_os)) { 2481 com_err (program_name, 0, _("unknown os - %s"), creator_os); 2482 exit(1); 2483 } 2484 2485 /* 2486 * For the Hurd, we will turn off filetype since it doesn't 2487 * support it. 2488 */ 2489 if (fs->super->s_creator_os == EXT2_OS_HURD) 2490 fs->super->s_feature_incompat &= 2491 ~EXT2_FEATURE_INCOMPAT_FILETYPE; 2492 2493 /* 2494 * Set the volume label... 2495 */ 2496 if (volume_label) { 2497 memset(fs->super->s_volume_name, 0, 2498 sizeof(fs->super->s_volume_name)); 2499 strncpy(fs->super->s_volume_name, volume_label, 2500 sizeof(fs->super->s_volume_name)); 2501 } 2502 2503 /* 2504 * Set the last mount directory 2505 */ 2506 if (mount_dir) { 2507 memset(fs->super->s_last_mounted, 0, 2508 sizeof(fs->super->s_last_mounted)); 2509 strncpy(fs->super->s_last_mounted, mount_dir, 2510 sizeof(fs->super->s_last_mounted)); 2511 } 2512 2513 if (!quiet || noaction) 2514 show_stats(fs); 2515 2516 if (noaction) 2517 exit(0); 2518 2519 if (fs->super->s_feature_incompat & 2520 EXT3_FEATURE_INCOMPAT_JOURNAL_DEV) { 2521 create_journal_dev(fs); 2522 exit(ext2fs_close(fs) ? 1 : 0); 2523 } 2524 2525 if (bad_blocks_filename) 2526 read_bb_file(fs, &bb_list, bad_blocks_filename); 2527 if (cflag) 2528 test_disk(fs, &bb_list); 2529 2530 handle_bad_blocks(fs, bb_list); 2531 fs->stride = fs_stride = fs->super->s_raid_stride; 2532 if (!quiet) 2533 printf(_("Allocating group tables: ")); 2534 retval = ext2fs_allocate_tables(fs); 2535 if (retval) { 2536 com_err(program_name, retval, 2537 _("while trying to allocate filesystem tables")); 2538 exit(1); 2539 } 2540 if (!quiet) 2541 printf(_("done \n")); 2542 2543 retval = ext2fs_convert_subcluster_bitmap(fs, &fs->block_map); 2544 if (retval) { 2545 com_err(program_name, retval, 2546 _("\n\twhile converting subcluster bitmap")); 2547 exit(1); 2548 } 2549 2550 if (super_only) { 2551 fs->super->s_state |= EXT2_ERROR_FS; 2552 fs->flags &= ~(EXT2_FLAG_IB_DIRTY|EXT2_FLAG_BB_DIRTY); 2553 /* 2554 * The command "mke2fs -S" is used to recover 2555 * corrupted file systems, so do not mark any of the 2556 * inodes as unused; we want e2fsck to consider all 2557 * inodes as potentially containing recoverable data. 2558 */ 2559 if (fs->super->s_feature_ro_compat & 2560 EXT4_FEATURE_RO_COMPAT_GDT_CSUM) { 2561 for (i = 0; i < fs->group_desc_count; i++) 2562 ext2fs_bg_itable_unused_set(fs, i, 0); 2563 } 2564 } else { 2565 /* rsv must be a power of two (64kB is MD RAID sb alignment) */ 2566 blk64_t rsv = 65536 / fs->blocksize; 2567 blk64_t blocks = ext2fs_blocks_count(fs->super); 2568 blk64_t start; 2569 blk64_t ret_blk; 2570 2571#ifdef ZAP_BOOTBLOCK 2572 zap_sector(fs, 0, 2); 2573#endif 2574 2575 /* 2576 * Wipe out any old MD RAID (or other) metadata at the end 2577 * of the device. This will also verify that the device is 2578 * as large as we think. Be careful with very small devices. 2579 */ 2580 start = (blocks & ~(rsv - 1)); 2581 if (start > rsv) 2582 start -= rsv; 2583 if (start > 0) 2584 retval = ext2fs_zero_blocks2(fs, start, blocks - start, 2585 &ret_blk, NULL); 2586 2587 if (retval) { 2588 com_err(program_name, retval, 2589 _("while zeroing block %llu at end of filesystem"), 2590 ret_blk); 2591 } 2592 write_inode_tables(fs, lazy_itable_init, itable_zeroed); 2593 create_root_dir(fs); 2594 create_lost_and_found(fs); 2595 reserve_inodes(fs); 2596 create_bad_block_inode(fs, bb_list); 2597 if (fs->super->s_feature_compat & 2598 EXT2_FEATURE_COMPAT_RESIZE_INODE) { 2599 retval = ext2fs_create_resize_inode(fs); 2600 if (retval) { 2601 com_err("ext2fs_create_resize_inode", retval, 2602 _("while reserving blocks for online resize")); 2603 exit(1); 2604 } 2605 } 2606 } 2607 2608 if (journal_device) { 2609 ext2_filsys jfs; 2610 2611 if (!force) 2612 check_plausibility(journal_device); 2613 check_mount(journal_device, force, _("journal")); 2614 2615 retval = ext2fs_open(journal_device, EXT2_FLAG_RW| 2616 EXT2_FLAG_JOURNAL_DEV_OK, 0, 2617 fs->blocksize, unix_io_manager, &jfs); 2618 if (retval) { 2619 com_err(program_name, retval, 2620 _("while trying to open journal device %s\n"), 2621 journal_device); 2622 exit(1); 2623 } 2624 if (!quiet) { 2625 printf(_("Adding journal to device %s: "), 2626 journal_device); 2627 fflush(stdout); 2628 } 2629 retval = ext2fs_add_journal_device(fs, jfs); 2630 if(retval) { 2631 com_err (program_name, retval, 2632 _("\n\twhile trying to add journal to device %s"), 2633 journal_device); 2634 exit(1); 2635 } 2636 if (!quiet) 2637 printf(_("done\n")); 2638 ext2fs_close(jfs); 2639 free(journal_device); 2640 } else if ((journal_size) || 2641 (fs_param.s_feature_compat & 2642 EXT3_FEATURE_COMPAT_HAS_JOURNAL)) { 2643 if (super_only) { 2644 printf(_("Skipping journal creation in super-only mode\n")); 2645 fs->super->s_journal_inum = EXT2_JOURNAL_INO; 2646 goto no_journal; 2647 } 2648 2649 if (!journal_blocks) { 2650 fs->super->s_feature_compat &= 2651 ~EXT3_FEATURE_COMPAT_HAS_JOURNAL; 2652 goto no_journal; 2653 } 2654 if (!quiet) { 2655 printf(_("Creating journal (%u blocks): "), 2656 journal_blocks); 2657 fflush(stdout); 2658 } 2659 retval = ext2fs_add_journal_inode(fs, journal_blocks, 2660 journal_flags); 2661 if (retval) { 2662 com_err (program_name, retval, 2663 _("\n\twhile trying to create journal")); 2664 exit(1); 2665 } 2666 if (!quiet) 2667 printf(_("done\n")); 2668 } 2669no_journal: 2670 if (!super_only && 2671 fs->super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_MMP) { 2672 retval = ext2fs_mmp_init(fs); 2673 if (retval) { 2674 fprintf(stderr, _("\nError while enabling multiple " 2675 "mount protection feature.")); 2676 exit(1); 2677 } 2678 if (!quiet) 2679 printf(_("Multiple mount protection is enabled " 2680 "with update interval %d seconds.\n"), 2681 fs->super->s_mmp_update_interval); 2682 } 2683 2684 if (EXT2_HAS_RO_COMPAT_FEATURE(&fs_param, 2685 EXT4_FEATURE_RO_COMPAT_BIGALLOC)) 2686 fix_cluster_bg_counts(fs); 2687 if (EXT2_HAS_RO_COMPAT_FEATURE(&fs_param, 2688 EXT4_FEATURE_RO_COMPAT_QUOTA)) 2689 create_quota_inodes(fs); 2690 2691 if (!quiet) 2692 printf(_("Writing superblocks and " 2693 "filesystem accounting information: ")); 2694 checkinterval = fs->super->s_checkinterval; 2695 max_mnt_count = fs->super->s_max_mnt_count; 2696 retval = ext2fs_close(fs); 2697 if (retval) { 2698 fprintf(stderr, 2699 _("\nWarning, had trouble writing out superblocks.")); 2700 } else if (!quiet) { 2701 printf(_("done\n\n")); 2702 if (!getenv("MKE2FS_SKIP_CHECK_MSG")) 2703 print_check_message(max_mnt_count, checkinterval); 2704 } 2705 2706 remove_error_table(&et_ext2_error_table); 2707 remove_error_table(&et_prof_error_table); 2708 profile_release(profile); 2709 for (i=0; fs_types[i]; i++) 2710 free(fs_types[i]); 2711 free(fs_types); 2712 return retval; 2713} 2714