mke2fs.c revision fd73a1d254556fce65d03e74ee5a97304f496caa
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; 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(list.list); 1103 return 0; 1104 } 1105 strcpy(parse_str, usage_types); 1106 1107 if (ext_type) 1108 push_string(&list, ext_type); 1109 cp = parse_str; 1110 while (1) { 1111 t = strchr(cp, ','); 1112 if (t) 1113 *t = '\0'; 1114 1115 if (*cp) { 1116 if (profile_has_subsection(profile, "fs_types", cp)) 1117 push_string(&list, cp); 1118 else if (strcmp(cp, "default") != 0) 1119 fprintf(stderr, 1120 _("\nWarning: the fs_type %s is not " 1121 "defined in mke2fs.conf\n\n"), 1122 cp); 1123 } 1124 if (t) 1125 cp = t+1; 1126 else 1127 break; 1128 } 1129 free(parse_str); 1130 free(profile_type); 1131 if (is_hurd) 1132 push_string(&list, "hurd"); 1133 return (list.list); 1134} 1135 1136static char *get_string_from_profile(char **types, const char *opt, 1137 const char *def_val) 1138{ 1139 char *ret = 0; 1140 int i; 1141 1142 for (i=0; types[i]; i++); 1143 for (i-=1; i >=0 ; i--) { 1144 profile_get_string(profile, "fs_types", types[i], 1145 opt, 0, &ret); 1146 if (ret) 1147 return ret; 1148 } 1149 profile_get_string(profile, "defaults", opt, 0, def_val, &ret); 1150 return (ret); 1151} 1152 1153static int get_int_from_profile(char **types, const char *opt, int def_val) 1154{ 1155 int ret; 1156 char **cpp; 1157 1158 profile_get_integer(profile, "defaults", opt, 0, def_val, &ret); 1159 for (cpp = types; *cpp; cpp++) 1160 profile_get_integer(profile, "fs_types", *cpp, opt, ret, &ret); 1161 return ret; 1162} 1163 1164static double get_double_from_profile(char **types, const char *opt, 1165 double def_val) 1166{ 1167 double ret; 1168 char **cpp; 1169 1170 profile_get_double(profile, "defaults", opt, 0, def_val, &ret); 1171 for (cpp = types; *cpp; cpp++) 1172 profile_get_double(profile, "fs_types", *cpp, opt, ret, &ret); 1173 return ret; 1174} 1175 1176static int get_bool_from_profile(char **types, const char *opt, int def_val) 1177{ 1178 int ret; 1179 char **cpp; 1180 1181 profile_get_boolean(profile, "defaults", opt, 0, def_val, &ret); 1182 for (cpp = types; *cpp; cpp++) 1183 profile_get_boolean(profile, "fs_types", *cpp, opt, ret, &ret); 1184 return ret; 1185} 1186 1187extern const char *mke2fs_default_profile; 1188static const char *default_files[] = { "<default>", 0 }; 1189 1190#ifdef HAVE_BLKID_PROBE_GET_TOPOLOGY 1191/* 1192 * Sets the geometry of a device (stripe/stride), and returns the 1193 * device's alignment offset, if any, or a negative error. 1194 */ 1195static int get_device_geometry(const char *file, 1196 struct ext2_super_block *fs_param, 1197 int psector_size) 1198{ 1199 int rc = -1; 1200 int blocksize; 1201 blkid_probe pr; 1202 blkid_topology tp; 1203 unsigned long min_io; 1204 unsigned long opt_io; 1205 struct stat statbuf; 1206 1207 /* Nothing to do for a regular file */ 1208 if (!stat(file, &statbuf) && S_ISREG(statbuf.st_mode)) 1209 return 0; 1210 1211 pr = blkid_new_probe_from_filename(file); 1212 if (!pr) 1213 goto out; 1214 1215 tp = blkid_probe_get_topology(pr); 1216 if (!tp) 1217 goto out; 1218 1219 min_io = blkid_topology_get_minimum_io_size(tp); 1220 opt_io = blkid_topology_get_optimal_io_size(tp); 1221 blocksize = EXT2_BLOCK_SIZE(fs_param); 1222 if ((min_io == 0) && (psector_size > blocksize)) 1223 min_io = psector_size; 1224 if ((opt_io == 0) && min_io) 1225 opt_io = min_io; 1226 if ((opt_io == 0) && (psector_size > blocksize)) 1227 opt_io = psector_size; 1228 1229 /* setting stripe/stride to blocksize is pointless */ 1230 if (min_io > blocksize) 1231 fs_param->s_raid_stride = min_io / blocksize; 1232 if (opt_io > blocksize) 1233 fs_param->s_raid_stripe_width = opt_io / blocksize; 1234 1235 rc = blkid_topology_get_alignment_offset(tp); 1236out: 1237 blkid_free_probe(pr); 1238 return rc; 1239} 1240#endif 1241 1242static void PRS(int argc, char *argv[]) 1243{ 1244 int b, c; 1245 int cluster_size = 0; 1246 char *tmp, **cpp; 1247 int blocksize = 0; 1248 int inode_ratio = 0; 1249 int inode_size = 0; 1250 unsigned long flex_bg_size = 0; 1251 double reserved_ratio = -1.0; 1252 int lsector_size = 0, psector_size = 0; 1253 int show_version_only = 0; 1254 unsigned long long num_inodes = 0; /* unsigned long long to catch too-large input */ 1255 errcode_t retval; 1256 char * oldpath = getenv("PATH"); 1257 char * extended_opts = 0; 1258 char * fs_type = 0; 1259 char * usage_types = 0; 1260 blk64_t dev_size; 1261 blk64_t fs_blocks_count = 0; 1262#ifdef __linux__ 1263 struct utsname ut; 1264#endif 1265 long sysval; 1266 int s_opt = -1, r_opt = -1; 1267 char *fs_features = 0; 1268 int use_bsize; 1269 char *newpath; 1270 int pathlen = sizeof(PATH_SET) + 1; 1271 1272 if (oldpath) 1273 pathlen += strlen(oldpath); 1274 newpath = malloc(pathlen); 1275 if (!newpath) { 1276 fprintf(stderr, _("Couldn't allocate memory for new PATH.\n")); 1277 exit(1); 1278 } 1279 strcpy(newpath, PATH_SET); 1280 1281 /* Update our PATH to include /sbin */ 1282 if (oldpath) { 1283 strcat (newpath, ":"); 1284 strcat (newpath, oldpath); 1285 } 1286 putenv (newpath); 1287 1288 tmp = getenv("MKE2FS_SYNC"); 1289 if (tmp) 1290 sync_kludge = atoi(tmp); 1291 1292 /* Determine the system page size if possible */ 1293#ifdef HAVE_SYSCONF 1294#if (!defined(_SC_PAGESIZE) && defined(_SC_PAGE_SIZE)) 1295#define _SC_PAGESIZE _SC_PAGE_SIZE 1296#endif 1297#ifdef _SC_PAGESIZE 1298 sysval = sysconf(_SC_PAGESIZE); 1299 if (sysval > 0) 1300 sys_page_size = sysval; 1301#endif /* _SC_PAGESIZE */ 1302#endif /* HAVE_SYSCONF */ 1303 1304 if ((tmp = getenv("MKE2FS_CONFIG")) != NULL) 1305 config_fn[0] = tmp; 1306 profile_set_syntax_err_cb(syntax_err_report); 1307 retval = profile_init(config_fn, &profile); 1308 if (retval == ENOENT) { 1309 retval = profile_init(default_files, &profile); 1310 if (retval) 1311 goto profile_error; 1312 retval = profile_set_default(profile, mke2fs_default_profile); 1313 if (retval) 1314 goto profile_error; 1315 } else if (retval) { 1316profile_error: 1317 fprintf(stderr, _("Couldn't init profile successfully" 1318 " (error: %ld).\n"), retval); 1319 exit(1); 1320 } 1321 1322 setbuf(stdout, NULL); 1323 setbuf(stderr, NULL); 1324 add_error_table(&et_ext2_error_table); 1325 add_error_table(&et_prof_error_table); 1326 memset(&fs_param, 0, sizeof(struct ext2_super_block)); 1327 fs_param.s_rev_level = 1; /* Create revision 1 filesystems now */ 1328 1329#ifdef __linux__ 1330 if (uname(&ut)) { 1331 perror("uname"); 1332 exit(1); 1333 } 1334 linux_version_code = parse_version_number(ut.release); 1335 if (linux_version_code && linux_version_code < (2*65536 + 2*256)) 1336 fs_param.s_rev_level = 0; 1337#endif 1338 1339 if (argc && *argv) { 1340 program_name = get_progname(*argv); 1341 1342 /* If called as mkfs.ext3, create a journal inode */ 1343 if (!strcmp(program_name, "mkfs.ext3") || 1344 !strcmp(program_name, "mke3fs")) 1345 journal_size = -1; 1346 } 1347 1348 while ((c = getopt (argc, argv, 1349 "b:cg:i:jl:m:no:qr:s:t:vC:DE:FG:I:J:KL:M:N:O:R:ST:U:V")) != EOF) { 1350 switch (c) { 1351 case 'b': 1352 blocksize = parse_num_blocks2(optarg, -1); 1353 b = (blocksize > 0) ? blocksize : -blocksize; 1354 if (b < EXT2_MIN_BLOCK_SIZE || 1355 b > EXT2_MAX_BLOCK_SIZE) { 1356 com_err(program_name, 0, 1357 _("invalid block size - %s"), optarg); 1358 exit(1); 1359 } 1360 if (blocksize > 4096) 1361 fprintf(stderr, _("Warning: blocksize %d not " 1362 "usable on most systems.\n"), 1363 blocksize); 1364 if (blocksize > 0) 1365 fs_param.s_log_block_size = 1366 int_log2(blocksize >> 1367 EXT2_MIN_BLOCK_LOG_SIZE); 1368 break; 1369 case 'c': /* Check for bad blocks */ 1370 cflag++; 1371 break; 1372 case 'C': 1373 cluster_size = parse_num_blocks2(optarg, -1); 1374 if (cluster_size <= EXT2_MIN_CLUSTER_SIZE || 1375 cluster_size > EXT2_MAX_CLUSTER_SIZE) { 1376 com_err(program_name, 0, 1377 _("invalid cluster size - %s"), 1378 optarg); 1379 exit(1); 1380 } 1381 break; 1382 case 'D': 1383 direct_io = 1; 1384 break; 1385 case 'R': 1386 com_err(program_name, 0, 1387 _("'-R' is deprecated, use '-E' instead")); 1388 /* fallthrough */ 1389 case 'E': 1390 extended_opts = optarg; 1391 break; 1392 case 'F': 1393 force++; 1394 break; 1395 case 'g': 1396 fs_param.s_blocks_per_group = strtoul(optarg, &tmp, 0); 1397 if (*tmp) { 1398 com_err(program_name, 0, 1399 _("Illegal number for blocks per group")); 1400 exit(1); 1401 } 1402 if ((fs_param.s_blocks_per_group % 8) != 0) { 1403 com_err(program_name, 0, 1404 _("blocks per group must be multiple of 8")); 1405 exit(1); 1406 } 1407 break; 1408 case 'G': 1409 flex_bg_size = strtoul(optarg, &tmp, 0); 1410 if (*tmp) { 1411 com_err(program_name, 0, 1412 _("Illegal number for flex_bg size")); 1413 exit(1); 1414 } 1415 if (flex_bg_size < 1 || 1416 (flex_bg_size & (flex_bg_size-1)) != 0) { 1417 com_err(program_name, 0, 1418 _("flex_bg size must be a power of 2")); 1419 exit(1); 1420 } 1421 break; 1422 case 'i': 1423 inode_ratio = strtoul(optarg, &tmp, 0); 1424 if (inode_ratio < EXT2_MIN_BLOCK_SIZE || 1425 inode_ratio > EXT2_MAX_BLOCK_SIZE * 1024 || 1426 *tmp) { 1427 com_err(program_name, 0, 1428 _("invalid inode ratio %s (min %d/max %d)"), 1429 optarg, EXT2_MIN_BLOCK_SIZE, 1430 EXT2_MAX_BLOCK_SIZE * 1024); 1431 exit(1); 1432 } 1433 break; 1434 case 'I': 1435 inode_size = strtoul(optarg, &tmp, 0); 1436 if (*tmp) { 1437 com_err(program_name, 0, 1438 _("invalid inode size - %s"), optarg); 1439 exit(1); 1440 } 1441 break; 1442 case 'j': 1443 if (!journal_size) 1444 journal_size = -1; 1445 break; 1446 case 'J': 1447 parse_journal_opts(optarg); 1448 break; 1449 case 'K': 1450 fprintf(stderr, _("Warning: -K option is deprecated and " 1451 "should not be used anymore. Use " 1452 "\'-E nodiscard\' extended option " 1453 "instead!\n")); 1454 discard = 0; 1455 break; 1456 case 'l': 1457 bad_blocks_filename = malloc(strlen(optarg)+1); 1458 if (!bad_blocks_filename) { 1459 com_err(program_name, ENOMEM, 1460 _("in malloc for bad_blocks_filename")); 1461 exit(1); 1462 } 1463 strcpy(bad_blocks_filename, optarg); 1464 break; 1465 case 'L': 1466 volume_label = optarg; 1467 break; 1468 case 'm': 1469 reserved_ratio = strtod(optarg, &tmp); 1470 if ( *tmp || reserved_ratio > 50 || 1471 reserved_ratio < 0) { 1472 com_err(program_name, 0, 1473 _("invalid reserved blocks percent - %s"), 1474 optarg); 1475 exit(1); 1476 } 1477 break; 1478 case 'M': 1479 mount_dir = optarg; 1480 break; 1481 case 'n': 1482 noaction++; 1483 break; 1484 case 'N': 1485 num_inodes = strtoul(optarg, &tmp, 0); 1486 if (*tmp) { 1487 com_err(program_name, 0, 1488 _("bad num inodes - %s"), optarg); 1489 exit(1); 1490 } 1491 break; 1492 case 'o': 1493 creator_os = optarg; 1494 break; 1495 case 'O': 1496 fs_features = optarg; 1497 break; 1498 case 'q': 1499 quiet = 1; 1500 break; 1501 case 'r': 1502 r_opt = strtoul(optarg, &tmp, 0); 1503 if (*tmp) { 1504 com_err(program_name, 0, 1505 _("bad revision level - %s"), optarg); 1506 exit(1); 1507 } 1508 fs_param.s_rev_level = r_opt; 1509 break; 1510 case 's': /* deprecated */ 1511 s_opt = atoi(optarg); 1512 break; 1513 case 'S': 1514 super_only = 1; 1515 break; 1516 case 't': 1517 if (fs_type) { 1518 com_err(program_name, 0, 1519 _("The -t option may only be used once")); 1520 exit(1); 1521 } 1522 fs_type = strdup(optarg); 1523 break; 1524 case 'T': 1525 if (usage_types) { 1526 com_err(program_name, 0, 1527 _("The -T option may only be used once")); 1528 exit(1); 1529 } 1530 usage_types = strdup(optarg); 1531 break; 1532 case 'U': 1533 fs_uuid = optarg; 1534 break; 1535 case 'v': 1536 verbose = 1; 1537 break; 1538 case 'V': 1539 /* Print version number and exit */ 1540 show_version_only++; 1541 break; 1542 default: 1543 usage(); 1544 } 1545 } 1546 if ((optind == argc) && !show_version_only) 1547 usage(); 1548 device_name = argv[optind++]; 1549 1550 if (!quiet || show_version_only) 1551 fprintf (stderr, "mke2fs %s (%s)\n", E2FSPROGS_VERSION, 1552 E2FSPROGS_DATE); 1553 1554 if (show_version_only) { 1555 fprintf(stderr, _("\tUsing %s\n"), 1556 error_message(EXT2_ET_BASE)); 1557 exit(0); 1558 } 1559 1560 /* 1561 * If there's no blocksize specified and there is a journal 1562 * device, use it to figure out the blocksize 1563 */ 1564 if (blocksize <= 0 && journal_device) { 1565 ext2_filsys jfs; 1566 io_manager io_ptr; 1567 1568#ifdef CONFIG_TESTIO_DEBUG 1569 if (getenv("TEST_IO_FLAGS") || getenv("TEST_IO_BLOCK")) { 1570 io_ptr = test_io_manager; 1571 test_io_backing_manager = unix_io_manager; 1572 } else 1573#endif 1574 io_ptr = unix_io_manager; 1575 retval = ext2fs_open(journal_device, 1576 EXT2_FLAG_JOURNAL_DEV_OK, 0, 1577 0, io_ptr, &jfs); 1578 if (retval) { 1579 com_err(program_name, retval, 1580 _("while trying to open journal device %s\n"), 1581 journal_device); 1582 exit(1); 1583 } 1584 if ((blocksize < 0) && (jfs->blocksize < (unsigned) (-blocksize))) { 1585 com_err(program_name, 0, 1586 _("Journal dev blocksize (%d) smaller than " 1587 "minimum blocksize %d\n"), jfs->blocksize, 1588 -blocksize); 1589 exit(1); 1590 } 1591 blocksize = jfs->blocksize; 1592 printf(_("Using journal device's blocksize: %d\n"), blocksize); 1593 fs_param.s_log_block_size = 1594 int_log2(blocksize >> EXT2_MIN_BLOCK_LOG_SIZE); 1595 ext2fs_close(jfs); 1596 } 1597 1598 if (optind < argc) { 1599 fs_blocks_count = parse_num_blocks2(argv[optind++], 1600 fs_param.s_log_block_size); 1601 if (!fs_blocks_count) { 1602 com_err(program_name, 0, 1603 _("invalid blocks '%s' on device '%s'"), 1604 argv[optind - 1], device_name); 1605 exit(1); 1606 } 1607 } 1608 if (optind < argc) 1609 usage(); 1610 1611 if (!force) 1612 check_plausibility(device_name); 1613 check_mount(device_name, force, _("filesystem")); 1614 1615 /* Determine the size of the device (if possible) */ 1616 if (noaction && fs_blocks_count) { 1617 dev_size = fs_blocks_count; 1618 retval = 0; 1619 } else 1620 retval = ext2fs_get_device_size2(device_name, 1621 EXT2_BLOCK_SIZE(&fs_param), 1622 &dev_size); 1623 1624 if (retval && (retval != EXT2_ET_UNIMPLEMENTED)) { 1625 com_err(program_name, retval, 1626 _("while trying to determine filesystem size")); 1627 exit(1); 1628 } 1629 if (!fs_blocks_count) { 1630 if (retval == EXT2_ET_UNIMPLEMENTED) { 1631 com_err(program_name, 0, 1632 _("Couldn't determine device size; you " 1633 "must specify\nthe size of the " 1634 "filesystem\n")); 1635 exit(1); 1636 } else { 1637 if (dev_size == 0) { 1638 com_err(program_name, 0, 1639 _("Device size reported to be zero. " 1640 "Invalid partition specified, or\n\t" 1641 "partition table wasn't reread " 1642 "after running fdisk, due to\n\t" 1643 "a modified partition being busy " 1644 "and in use. You may need to reboot\n\t" 1645 "to re-read your partition table.\n" 1646 )); 1647 exit(1); 1648 } 1649 fs_blocks_count = dev_size; 1650 if (sys_page_size > EXT2_BLOCK_SIZE(&fs_param)) 1651 fs_blocks_count &= ~((blk64_t) ((sys_page_size / 1652 EXT2_BLOCK_SIZE(&fs_param))-1)); 1653 } 1654 } else if (!force && (fs_blocks_count > dev_size)) { 1655 com_err(program_name, 0, 1656 _("Filesystem larger than apparent device size.")); 1657 proceed_question(); 1658 } 1659 1660 if (!fs_type) 1661 profile_get_string(profile, "devices", device_name, 1662 "fs_type", 0, &fs_type); 1663 if (!usage_types) 1664 profile_get_string(profile, "devices", device_name, 1665 "usage_types", 0, &usage_types); 1666 1667 /* 1668 * We have the file system (or device) size, so we can now 1669 * determine the appropriate file system types so the fs can 1670 * be appropriately configured. 1671 */ 1672 fs_types = parse_fs_type(fs_type, usage_types, &fs_param, 1673 fs_blocks_count ? fs_blocks_count : dev_size, 1674 argv[0]); 1675 if (!fs_types) { 1676 fprintf(stderr, _("Failed to parse fs types list\n")); 1677 exit(1); 1678 } 1679 1680 /* Figure out what features should be enabled */ 1681 1682 tmp = NULL; 1683 if (fs_param.s_rev_level != EXT2_GOOD_OLD_REV) { 1684 tmp = get_string_from_profile(fs_types, "base_features", 1685 "sparse_super,filetype,resize_inode,dir_index"); 1686 edit_feature(tmp, &fs_param.s_feature_compat); 1687 free(tmp); 1688 1689 /* And which mount options as well */ 1690 tmp = get_string_from_profile(fs_types, "default_mntopts", 1691 "acl,user_xattr"); 1692 edit_mntopts(tmp, &fs_param.s_default_mount_opts); 1693 if (tmp) 1694 free(tmp); 1695 1696 for (cpp = fs_types; *cpp; cpp++) { 1697 tmp = NULL; 1698 profile_get_string(profile, "fs_types", *cpp, 1699 "features", "", &tmp); 1700 if (tmp && *tmp) 1701 edit_feature(tmp, &fs_param.s_feature_compat); 1702 if (tmp) 1703 free(tmp); 1704 } 1705 tmp = get_string_from_profile(fs_types, "default_features", 1706 ""); 1707 } 1708 edit_feature(fs_features ? fs_features : tmp, 1709 &fs_param.s_feature_compat); 1710 if (tmp) 1711 free(tmp); 1712 1713 /* 1714 * We now need to do a sanity check of fs_blocks_count for 1715 * 32-bit vs 64-bit block number support. 1716 */ 1717 if ((fs_blocks_count > MAX_32_NUM) && (blocksize == 0)) { 1718 fs_blocks_count /= 4; /* Try using a 4k blocksize */ 1719 blocksize = 4096; 1720 fs_param.s_log_block_size = 2; 1721 } 1722 if ((fs_blocks_count > MAX_32_NUM) && 1723 !(fs_param.s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT) && 1724 get_bool_from_profile(fs_types, "auto_64-bit_support", 0)) { 1725 fs_param.s_feature_incompat |= EXT4_FEATURE_INCOMPAT_64BIT; 1726 fs_param.s_feature_compat &= ~EXT2_FEATURE_COMPAT_RESIZE_INODE; 1727 } 1728 if ((fs_blocks_count > MAX_32_NUM) && 1729 !(fs_param.s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT)) { 1730 fprintf(stderr, _("%s: Size of device (0x%llx blocks) %s " 1731 "too big to be expressed\n\t" 1732 "in 32 bits using a blocksize of %d.\n"), 1733 program_name, fs_blocks_count, device_name, 1734 EXT2_BLOCK_SIZE(&fs_param)); 1735 exit(1); 1736 } 1737 1738 ext2fs_blocks_count_set(&fs_param, fs_blocks_count); 1739 1740 if (fs_param.s_feature_incompat & EXT3_FEATURE_INCOMPAT_JOURNAL_DEV) { 1741 fs_types[0] = strdup("journal"); 1742 fs_types[1] = 0; 1743 } 1744 1745 if (verbose) { 1746 fputs(_("fs_types for mke2fs.conf resolution: "), stdout); 1747 print_str_list(fs_types); 1748 } 1749 1750 if (r_opt == EXT2_GOOD_OLD_REV && 1751 (fs_param.s_feature_compat || fs_param.s_feature_incompat || 1752 fs_param.s_feature_ro_compat)) { 1753 fprintf(stderr, _("Filesystem features not supported " 1754 "with revision 0 filesystems\n")); 1755 exit(1); 1756 } 1757 1758 if (s_opt > 0) { 1759 if (r_opt == EXT2_GOOD_OLD_REV) { 1760 fprintf(stderr, _("Sparse superblocks not supported " 1761 "with revision 0 filesystems\n")); 1762 exit(1); 1763 } 1764 fs_param.s_feature_ro_compat |= 1765 EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER; 1766 } else if (s_opt == 0) 1767 fs_param.s_feature_ro_compat &= 1768 ~EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER; 1769 1770 if (journal_size != 0) { 1771 if (r_opt == EXT2_GOOD_OLD_REV) { 1772 fprintf(stderr, _("Journals not supported " 1773 "with revision 0 filesystems\n")); 1774 exit(1); 1775 } 1776 fs_param.s_feature_compat |= 1777 EXT3_FEATURE_COMPAT_HAS_JOURNAL; 1778 } 1779 1780 /* Get reserved_ratio from profile if not specified on cmd line. */ 1781 if (reserved_ratio < 0.0) { 1782 reserved_ratio = get_double_from_profile( 1783 fs_types, "reserved_ratio", 5.0); 1784 if (reserved_ratio > 50 || reserved_ratio < 0) { 1785 com_err(program_name, 0, 1786 _("invalid reserved blocks percent - %lf"), 1787 reserved_ratio); 1788 exit(1); 1789 } 1790 } 1791 1792 if (fs_param.s_feature_incompat & 1793 EXT3_FEATURE_INCOMPAT_JOURNAL_DEV) { 1794 reserved_ratio = 0; 1795 fs_param.s_feature_incompat = EXT3_FEATURE_INCOMPAT_JOURNAL_DEV; 1796 fs_param.s_feature_compat = 0; 1797 fs_param.s_feature_ro_compat = 0; 1798 } 1799 1800 if ((fs_param.s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG) && 1801 (fs_param.s_feature_compat & EXT2_FEATURE_COMPAT_RESIZE_INODE)) { 1802 fprintf(stderr, _("The resize_inode and meta_bg features " 1803 "are not compatible.\n" 1804 "They can not be both enabled " 1805 "simultaneously.\n")); 1806 exit(1); 1807 } 1808 1809 /* Set first meta blockgroup via an environment variable */ 1810 /* (this is mostly for debugging purposes) */ 1811 if ((fs_param.s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG) && 1812 ((tmp = getenv("MKE2FS_FIRST_META_BG")))) 1813 fs_param.s_first_meta_bg = atoi(tmp); 1814 1815 /* Get the hardware sector sizes, if available */ 1816 retval = ext2fs_get_device_sectsize(device_name, &lsector_size); 1817 if (retval) { 1818 com_err(program_name, retval, 1819 _("while trying to determine hardware sector size")); 1820 exit(1); 1821 } 1822 retval = ext2fs_get_device_phys_sectsize(device_name, &psector_size); 1823 if (retval) { 1824 com_err(program_name, retval, 1825 _("while trying to determine physical sector size")); 1826 exit(1); 1827 } 1828 1829 if ((tmp = getenv("MKE2FS_DEVICE_SECTSIZE")) != NULL) 1830 lsector_size = atoi(tmp); 1831 if ((tmp = getenv("MKE2FS_DEVICE_PHYS_SECTSIZE")) != NULL) 1832 psector_size = atoi(tmp); 1833 1834 /* Older kernels may not have physical/logical distinction */ 1835 if (!psector_size) 1836 psector_size = lsector_size; 1837 1838 if (blocksize <= 0) { 1839 use_bsize = get_int_from_profile(fs_types, "blocksize", 4096); 1840 1841 if (use_bsize == -1) { 1842 use_bsize = sys_page_size; 1843 if ((linux_version_code < (2*65536 + 6*256)) && 1844 (use_bsize > 4096)) 1845 use_bsize = 4096; 1846 } 1847 if (lsector_size && use_bsize < lsector_size) 1848 use_bsize = lsector_size; 1849 if ((blocksize < 0) && (use_bsize < (-blocksize))) 1850 use_bsize = -blocksize; 1851 blocksize = use_bsize; 1852 ext2fs_blocks_count_set(&fs_param, 1853 ext2fs_blocks_count(&fs_param) / 1854 (blocksize / 1024)); 1855 } else { 1856 if (blocksize < lsector_size) { /* Impossible */ 1857 com_err(program_name, EINVAL, 1858 _("while setting blocksize; too small " 1859 "for device\n")); 1860 exit(1); 1861 } else if ((blocksize < psector_size) && 1862 (psector_size <= sys_page_size)) { /* Suboptimal */ 1863 fprintf(stderr, _("Warning: specified blocksize %d is " 1864 "less than device physical sectorsize %d\n"), 1865 blocksize, psector_size); 1866 } 1867 } 1868 1869 fs_param.s_log_block_size = 1870 int_log2(blocksize >> EXT2_MIN_BLOCK_LOG_SIZE); 1871 if (fs_param.s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_BIGALLOC) { 1872 if (!cluster_size) 1873 cluster_size = get_int_from_profile(fs_types, 1874 "cluster_size", 1875 blocksize*16); 1876 fs_param.s_log_cluster_size = 1877 int_log2(cluster_size >> EXT2_MIN_CLUSTER_LOG_SIZE); 1878 if (fs_param.s_log_cluster_size && 1879 fs_param.s_log_cluster_size < fs_param.s_log_block_size) { 1880 com_err(program_name, 0, 1881 _("The cluster size may not be " 1882 "smaller than the block size.\n")); 1883 exit(1); 1884 } 1885 } else if (cluster_size) { 1886 com_err(program_name, 0, 1887 _("specifying a cluster size requires the " 1888 "bigalloc feature")); 1889 exit(1); 1890 } else 1891 fs_param.s_log_cluster_size = fs_param.s_log_block_size; 1892 1893 if (inode_ratio == 0) { 1894 inode_ratio = get_int_from_profile(fs_types, "inode_ratio", 1895 8192); 1896 if (inode_ratio < blocksize) 1897 inode_ratio = blocksize; 1898 if (inode_ratio < EXT2_CLUSTER_SIZE(&fs_param)) 1899 inode_ratio = EXT2_CLUSTER_SIZE(&fs_param); 1900 } 1901 1902#ifdef HAVE_BLKID_PROBE_GET_TOPOLOGY 1903 retval = get_device_geometry(device_name, &fs_param, psector_size); 1904 if (retval < 0) { 1905 fprintf(stderr, 1906 _("warning: Unable to get device geometry for %s\n"), 1907 device_name); 1908 } else if (retval) { 1909 printf(_("%s alignment is offset by %lu bytes.\n"), 1910 device_name, retval); 1911 printf(_("This may result in very poor performance, " 1912 "(re)-partitioning suggested.\n")); 1913 } 1914#endif 1915 1916 blocksize = EXT2_BLOCK_SIZE(&fs_param); 1917 1918 /* 1919 * Initialize s_desc_size so that the parse_extended_opts() 1920 * can correctly handle "-E resize=NNN" if the 64-bit option 1921 * is set. 1922 */ 1923 if (fs_param.s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT) 1924 fs_param.s_desc_size = EXT2_MIN_DESC_SIZE_64BIT; 1925 1926 /* This check should happen beyond the last assignment to blocksize */ 1927 if (blocksize > sys_page_size) { 1928 if (!force) { 1929 com_err(program_name, 0, 1930 _("%d-byte blocks too big for system (max %d)"), 1931 blocksize, sys_page_size); 1932 proceed_question(); 1933 } 1934 fprintf(stderr, _("Warning: %d-byte blocks too big for system " 1935 "(max %d), forced to continue\n"), 1936 blocksize, sys_page_size); 1937 } 1938 1939 lazy_itable_init = 0; 1940 if (access("/sys/fs/ext4/features/lazy_itable_init", R_OK) == 0) 1941 lazy_itable_init = 1; 1942 1943 lazy_itable_init = get_bool_from_profile(fs_types, 1944 "lazy_itable_init", 1945 lazy_itable_init); 1946 discard = get_bool_from_profile(fs_types, "discard" , discard); 1947 journal_flags |= get_bool_from_profile(fs_types, 1948 "lazy_journal_init", 0) ? 1949 EXT2_MKJOURNAL_LAZYINIT : 0; 1950 journal_flags |= EXT2_MKJOURNAL_NO_MNT_CHECK; 1951 1952 /* Get options from profile */ 1953 for (cpp = fs_types; *cpp; cpp++) { 1954 tmp = NULL; 1955 profile_get_string(profile, "fs_types", *cpp, "options", "", &tmp); 1956 if (tmp && *tmp) 1957 parse_extended_opts(&fs_param, tmp); 1958 free(tmp); 1959 } 1960 1961 if (extended_opts) 1962 parse_extended_opts(&fs_param, extended_opts); 1963 1964 /* Can't support bigalloc feature without extents feature */ 1965 if ((fs_param.s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_BIGALLOC) && 1966 !(fs_param.s_feature_incompat & EXT3_FEATURE_INCOMPAT_EXTENTS)) { 1967 com_err(program_name, 0, 1968 _("Can't support bigalloc feature without " 1969 "extents feature")); 1970 exit(1); 1971 } 1972 1973 if (!quiet && 1974 (fs_param.s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_BIGALLOC)) 1975 fprintf(stderr, _("\nWarning: the bigalloc feature is still " 1976 "under development\n" 1977 "See https://ext4.wiki.kernel.org/" 1978 "index.php/Bigalloc for more information\n\n")); 1979 1980 if (!quiet && 1981 (fs_param.s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_QUOTA)) 1982 fprintf(stderr, _("\nWarning: the quota feature is still " 1983 "under development\n" 1984 "See https://ext4.wiki.kernel.org/" 1985 "index.php/Quota for more information\n\n")); 1986 1987 /* Since sparse_super is the default, we would only have a problem 1988 * here if it was explicitly disabled. 1989 */ 1990 if ((fs_param.s_feature_compat & EXT2_FEATURE_COMPAT_RESIZE_INODE) && 1991 !(fs_param.s_feature_ro_compat&EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER)) { 1992 com_err(program_name, 0, 1993 _("reserved online resize blocks not supported " 1994 "on non-sparse filesystem")); 1995 exit(1); 1996 } 1997 1998 if (fs_param.s_blocks_per_group) { 1999 if (fs_param.s_blocks_per_group < 256 || 2000 fs_param.s_blocks_per_group > 8 * (unsigned) blocksize) { 2001 com_err(program_name, 0, 2002 _("blocks per group count out of range")); 2003 exit(1); 2004 } 2005 } 2006 2007 /* 2008 * If the bigalloc feature is enabled, then the -g option will 2009 * specify the number of clusters per group. 2010 */ 2011 if (fs_param.s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_BIGALLOC) { 2012 fs_param.s_clusters_per_group = fs_param.s_blocks_per_group; 2013 fs_param.s_blocks_per_group = 0; 2014 } 2015 2016 if (inode_size == 0) 2017 inode_size = get_int_from_profile(fs_types, "inode_size", 0); 2018 if (!flex_bg_size && (fs_param.s_feature_incompat & 2019 EXT4_FEATURE_INCOMPAT_FLEX_BG)) 2020 flex_bg_size = get_int_from_profile(fs_types, 2021 "flex_bg_size", 16); 2022 if (flex_bg_size) { 2023 if (!(fs_param.s_feature_incompat & 2024 EXT4_FEATURE_INCOMPAT_FLEX_BG)) { 2025 com_err(program_name, 0, 2026 _("Flex_bg feature not enabled, so " 2027 "flex_bg size may not be specified")); 2028 exit(1); 2029 } 2030 fs_param.s_log_groups_per_flex = int_log2(flex_bg_size); 2031 } 2032 2033 if (inode_size && fs_param.s_rev_level >= EXT2_DYNAMIC_REV) { 2034 if (inode_size < EXT2_GOOD_OLD_INODE_SIZE || 2035 inode_size > EXT2_BLOCK_SIZE(&fs_param) || 2036 inode_size & (inode_size - 1)) { 2037 com_err(program_name, 0, 2038 _("invalid inode size %d (min %d/max %d)"), 2039 inode_size, EXT2_GOOD_OLD_INODE_SIZE, 2040 blocksize); 2041 exit(1); 2042 } 2043 fs_param.s_inode_size = inode_size; 2044 } 2045 2046 /* Make sure number of inodes specified will fit in 32 bits */ 2047 if (num_inodes == 0) { 2048 unsigned long long n; 2049 n = ext2fs_blocks_count(&fs_param) * blocksize / inode_ratio; 2050 if (n > MAX_32_NUM) { 2051 if (fs_param.s_feature_incompat & 2052 EXT4_FEATURE_INCOMPAT_64BIT) 2053 num_inodes = MAX_32_NUM; 2054 else { 2055 com_err(program_name, 0, 2056 _("too many inodes (%llu), raise " 2057 "inode ratio?"), n); 2058 exit(1); 2059 } 2060 } 2061 } else if (num_inodes > MAX_32_NUM) { 2062 com_err(program_name, 0, 2063 _("too many inodes (%llu), specify < 2^32 inodes"), 2064 num_inodes); 2065 exit(1); 2066 } 2067 /* 2068 * Calculate number of inodes based on the inode ratio 2069 */ 2070 fs_param.s_inodes_count = num_inodes ? num_inodes : 2071 (ext2fs_blocks_count(&fs_param) * blocksize) / inode_ratio; 2072 2073 if ((((unsigned long long)fs_param.s_inodes_count) * 2074 (inode_size ? inode_size : EXT2_GOOD_OLD_INODE_SIZE)) >= 2075 ((ext2fs_blocks_count(&fs_param)) * 2076 EXT2_BLOCK_SIZE(&fs_param))) { 2077 com_err(program_name, 0, _("inode_size (%u) * inodes_count " 2078 "(%u) too big for a\n\t" 2079 "filesystem with %llu blocks, " 2080 "specify higher inode_ratio (-i)\n\t" 2081 "or lower inode count (-N).\n"), 2082 inode_size ? inode_size : EXT2_GOOD_OLD_INODE_SIZE, 2083 fs_param.s_inodes_count, 2084 (unsigned long long) ext2fs_blocks_count(&fs_param)); 2085 exit(1); 2086 } 2087 2088 /* 2089 * Calculate number of blocks to reserve 2090 */ 2091 ext2fs_r_blocks_count_set(&fs_param, reserved_ratio * 2092 ext2fs_blocks_count(&fs_param) / 100.0); 2093 2094 free(fs_type); 2095 free(usage_types); 2096} 2097 2098static int should_do_undo(const char *name) 2099{ 2100 errcode_t retval; 2101 io_channel channel; 2102 __u16 s_magic; 2103 struct ext2_super_block super; 2104 io_manager manager = unix_io_manager; 2105 int csum_flag, force_undo; 2106 2107 csum_flag = EXT2_HAS_RO_COMPAT_FEATURE(&fs_param, 2108 EXT4_FEATURE_RO_COMPAT_GDT_CSUM); 2109 force_undo = get_int_from_profile(fs_types, "force_undo", 0); 2110 if (!force_undo && (!csum_flag || !lazy_itable_init)) 2111 return 0; 2112 2113 retval = manager->open(name, IO_FLAG_EXCLUSIVE, &channel); 2114 if (retval) { 2115 /* 2116 * We don't handle error cases instead we 2117 * declare that the file system doesn't exist 2118 * and let the rest of mke2fs take care of 2119 * error 2120 */ 2121 retval = 0; 2122 goto open_err_out; 2123 } 2124 2125 io_channel_set_blksize(channel, SUPERBLOCK_OFFSET); 2126 retval = io_channel_read_blk64(channel, 1, -SUPERBLOCK_SIZE, &super); 2127 if (retval) { 2128 retval = 0; 2129 goto err_out; 2130 } 2131 2132#if defined(WORDS_BIGENDIAN) 2133 s_magic = ext2fs_swab16(super.s_magic); 2134#else 2135 s_magic = super.s_magic; 2136#endif 2137 2138 if (s_magic == EXT2_SUPER_MAGIC) 2139 retval = 1; 2140 2141err_out: 2142 io_channel_close(channel); 2143 2144open_err_out: 2145 2146 return retval; 2147} 2148 2149static int mke2fs_setup_tdb(const char *name, io_manager *io_ptr) 2150{ 2151 errcode_t retval = ENOMEM; 2152 char *tdb_dir = NULL, *tdb_file = NULL; 2153 char *dev_name, *tmp_name; 2154 int free_tdb_dir = 0; 2155 2156 /* 2157 * Configuration via a conf file would be 2158 * nice 2159 */ 2160 tdb_dir = getenv("E2FSPROGS_UNDO_DIR"); 2161 if (!tdb_dir) { 2162 profile_get_string(profile, "defaults", 2163 "undo_dir", 0, "/var/lib/e2fsprogs", 2164 &tdb_dir); 2165 free_tdb_dir = 1; 2166 } 2167 2168 if (!strcmp(tdb_dir, "none") || (tdb_dir[0] == 0) || 2169 access(tdb_dir, W_OK)) 2170 return 0; 2171 2172 tmp_name = strdup(name); 2173 if (!tmp_name) 2174 goto errout; 2175 dev_name = basename(tmp_name); 2176 tdb_file = malloc(strlen(tdb_dir) + 8 + strlen(dev_name) + 7 + 1); 2177 if (!tdb_file) { 2178 free(tmp_name); 2179 goto errout; 2180 } 2181 sprintf(tdb_file, "%s/mke2fs-%s.e2undo", tdb_dir, dev_name); 2182 free(tmp_name); 2183 2184 if (!access(tdb_file, F_OK)) { 2185 if (unlink(tdb_file) < 0) { 2186 retval = errno; 2187 goto errout; 2188 } 2189 } 2190 2191 set_undo_io_backing_manager(*io_ptr); 2192 *io_ptr = undo_io_manager; 2193 retval = set_undo_io_backup_file(tdb_file); 2194 if (retval) 2195 goto errout; 2196 printf(_("Overwriting existing filesystem; this can be undone " 2197 "using the command:\n" 2198 " e2undo %s %s\n\n"), tdb_file, name); 2199 2200 if (free_tdb_dir) 2201 free(tdb_dir); 2202 free(tdb_file); 2203 return 0; 2204 2205errout: 2206 if (free_tdb_dir) 2207 free(tdb_dir); 2208 free(tdb_file); 2209 com_err(program_name, retval, 2210 _("while trying to setup undo file\n")); 2211 return retval; 2212} 2213 2214static int mke2fs_discard_device(ext2_filsys fs) 2215{ 2216 struct ext2fs_numeric_progress_struct progress; 2217 blk64_t blocks = ext2fs_blocks_count(fs->super); 2218 blk64_t count = DISCARD_STEP_MB; 2219 blk64_t cur; 2220 int retval = 0; 2221 2222 /* 2223 * Let's try if discard really works on the device, so 2224 * we do not print numeric progress resulting in failure 2225 * afterwards. 2226 */ 2227 retval = io_channel_discard(fs->io, 0, fs->blocksize); 2228 if (retval) 2229 return retval; 2230 cur = fs->blocksize; 2231 2232 count *= (1024 * 1024); 2233 count /= fs->blocksize; 2234 2235 ext2fs_numeric_progress_init(fs, &progress, 2236 _("Discarding device blocks: "), 2237 blocks); 2238 while (cur < blocks) { 2239 ext2fs_numeric_progress_update(fs, &progress, cur); 2240 2241 if (cur + count > blocks) 2242 count = blocks - cur; 2243 2244 retval = io_channel_discard(fs->io, cur, count); 2245 if (retval) 2246 break; 2247 cur += count; 2248 } 2249 2250 if (retval) { 2251 ext2fs_numeric_progress_close(fs, &progress, 2252 _("failed - ")); 2253 if (!quiet) 2254 printf("%s\n",error_message(retval)); 2255 } else 2256 ext2fs_numeric_progress_close(fs, &progress, 2257 _("done \n")); 2258 2259 return retval; 2260} 2261 2262static void fix_cluster_bg_counts(ext2_filsys fs) 2263{ 2264 blk64_t cluster, num_clusters, tot_free; 2265 unsigned num = 0; 2266 int grp_free, num_free, group; 2267 2268 num_clusters = EXT2FS_B2C(fs, ext2fs_blocks_count(fs->super)); 2269 tot_free = num_free = group = grp_free = 0; 2270 for (cluster = EXT2FS_B2C(fs, fs->super->s_first_data_block); 2271 cluster < num_clusters; cluster++) { 2272 if (!ext2fs_test_block_bitmap2(fs->block_map, 2273 EXT2FS_C2B(fs, cluster))) { 2274 grp_free++; 2275 tot_free++; 2276 } 2277 num++; 2278 if ((num == fs->super->s_clusters_per_group) || 2279 (cluster == num_clusters-1)) { 2280 ext2fs_bg_free_blocks_count_set(fs, group, grp_free); 2281 ext2fs_group_desc_csum_set(fs, group); 2282 num = 0; 2283 grp_free = 0; 2284 group++; 2285 } 2286 } 2287 ext2fs_free_blocks_count_set(fs->super, EXT2FS_C2B(fs, tot_free)); 2288} 2289 2290static int create_quota_inodes(ext2_filsys fs) 2291{ 2292 quota_ctx_t qctx; 2293 2294 quota_init_context(&qctx, fs, -1); 2295 quota_compute_usage(qctx); 2296 quota_write_inode(qctx, quotatype); 2297 quota_release_context(&qctx); 2298 2299 return 0; 2300} 2301 2302int main (int argc, char *argv[]) 2303{ 2304 errcode_t retval = 0; 2305 ext2_filsys fs; 2306 badblocks_list bb_list = 0; 2307 unsigned int journal_blocks; 2308 unsigned int i, checkinterval; 2309 int max_mnt_count; 2310 int val, hash_alg; 2311 int flags; 2312 int old_bitmaps; 2313 io_manager io_ptr; 2314 char tdb_string[40]; 2315 char *hash_alg_str; 2316 int itable_zeroed = 0; 2317 2318#ifdef ENABLE_NLS 2319 setlocale(LC_MESSAGES, ""); 2320 setlocale(LC_CTYPE, ""); 2321 bindtextdomain(NLS_CAT_NAME, LOCALEDIR); 2322 textdomain(NLS_CAT_NAME); 2323 set_com_err_gettext(gettext); 2324#endif 2325 PRS(argc, argv); 2326 2327#ifdef CONFIG_TESTIO_DEBUG 2328 if (getenv("TEST_IO_FLAGS") || getenv("TEST_IO_BLOCK")) { 2329 io_ptr = test_io_manager; 2330 test_io_backing_manager = unix_io_manager; 2331 } else 2332#endif 2333 io_ptr = unix_io_manager; 2334 2335 if (should_do_undo(device_name)) { 2336 retval = mke2fs_setup_tdb(device_name, &io_ptr); 2337 if (retval) 2338 exit(1); 2339 } 2340 2341 /* 2342 * Initialize the superblock.... 2343 */ 2344 flags = EXT2_FLAG_EXCLUSIVE; 2345 if (direct_io) 2346 flags |= EXT2_FLAG_DIRECT_IO; 2347 profile_get_boolean(profile, "options", "old_bitmaps", 0, 0, 2348 &old_bitmaps); 2349 if (!old_bitmaps) 2350 flags |= EXT2_FLAG_64BITS; 2351 /* 2352 * By default, we print how many inode tables or block groups 2353 * or whatever we've written so far. The quiet flag disables 2354 * this, along with a lot of other output. 2355 */ 2356 if (!quiet) 2357 flags |= EXT2_FLAG_PRINT_PROGRESS; 2358 retval = ext2fs_initialize(device_name, flags, &fs_param, io_ptr, &fs); 2359 if (retval) { 2360 com_err(device_name, retval, _("while setting up superblock")); 2361 exit(1); 2362 } 2363 2364 /* Calculate journal blocks */ 2365 if (!journal_device && ((journal_size) || 2366 (fs_param.s_feature_compat & 2367 EXT3_FEATURE_COMPAT_HAS_JOURNAL))) 2368 journal_blocks = figure_journal_size(journal_size, fs); 2369 2370 /* Can't undo discard ... */ 2371 if (!noaction && discard && (io_ptr != undo_io_manager)) { 2372 retval = mke2fs_discard_device(fs); 2373 if (!retval && io_channel_discard_zeroes_data(fs->io)) { 2374 if (verbose) 2375 printf(_("Discard succeeded and will return 0s " 2376 " - skipping inode table wipe\n")); 2377 lazy_itable_init = 1; 2378 itable_zeroed = 1; 2379 } 2380 } 2381 2382 sprintf(tdb_string, "tdb_data_size=%d", fs->blocksize <= 4096 ? 2383 32768 : fs->blocksize * 8); 2384 io_channel_set_options(fs->io, tdb_string); 2385 2386 if (fs_param.s_flags & EXT2_FLAGS_TEST_FILESYS) 2387 fs->super->s_flags |= EXT2_FLAGS_TEST_FILESYS; 2388 2389 if ((fs_param.s_feature_incompat & 2390 (EXT3_FEATURE_INCOMPAT_EXTENTS|EXT4_FEATURE_INCOMPAT_FLEX_BG)) || 2391 (fs_param.s_feature_ro_compat & 2392 (EXT4_FEATURE_RO_COMPAT_HUGE_FILE|EXT4_FEATURE_RO_COMPAT_GDT_CSUM| 2393 EXT4_FEATURE_RO_COMPAT_DIR_NLINK| 2394 EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE))) 2395 fs->super->s_kbytes_written = 1; 2396 2397 /* 2398 * Wipe out the old on-disk superblock 2399 */ 2400 if (!noaction) 2401 zap_sector(fs, 2, 6); 2402 2403 /* 2404 * Parse or generate a UUID for the filesystem 2405 */ 2406 if (fs_uuid) { 2407 if (uuid_parse(fs_uuid, fs->super->s_uuid) !=0) { 2408 com_err(device_name, 0, "could not parse UUID: %s\n", 2409 fs_uuid); 2410 exit(1); 2411 } 2412 } else 2413 uuid_generate(fs->super->s_uuid); 2414 2415 /* 2416 * Initialize the directory index variables 2417 */ 2418 hash_alg_str = get_string_from_profile(fs_types, "hash_alg", 2419 "half_md4"); 2420 hash_alg = e2p_string2hash(hash_alg_str); 2421 free(hash_alg_str); 2422 fs->super->s_def_hash_version = (hash_alg >= 0) ? hash_alg : 2423 EXT2_HASH_HALF_MD4; 2424 uuid_generate((unsigned char *) fs->super->s_hash_seed); 2425 2426 /* 2427 * Periodic checks can be enabled/disabled via config file. 2428 * Note we override the kernel include file's idea of what the default 2429 * check interval (never) should be. It's a good idea to check at 2430 * least *occasionally*, specially since servers will never rarely get 2431 * to reboot, since Linux is so robust these days. :-) 2432 * 2433 * 180 days (six months) seems like a good value. 2434 */ 2435#ifdef EXT2_DFL_CHECKINTERVAL 2436#undef EXT2_DFL_CHECKINTERVAL 2437#endif 2438#define EXT2_DFL_CHECKINTERVAL (86400L * 180L) 2439 2440 if (get_bool_from_profile(fs_types, "enable_periodic_fsck", 0)) { 2441 fs->super->s_checkinterval = EXT2_DFL_CHECKINTERVAL; 2442 fs->super->s_max_mnt_count = EXT2_DFL_MAX_MNT_COUNT; 2443 /* 2444 * Add "jitter" to the superblock's check interval so that we 2445 * don't check all the filesystems at the same time. We use a 2446 * kludgy hack of using the UUID to derive a random jitter value 2447 */ 2448 for (i = 0, val = 0 ; i < sizeof(fs->super->s_uuid); i++) 2449 val += fs->super->s_uuid[i]; 2450 fs->super->s_max_mnt_count += val % EXT2_DFL_MAX_MNT_COUNT; 2451 } else 2452 fs->super->s_max_mnt_count = -1; 2453 2454 /* 2455 * Override the creator OS, if applicable 2456 */ 2457 if (creator_os && !set_os(fs->super, creator_os)) { 2458 com_err (program_name, 0, _("unknown os - %s"), creator_os); 2459 exit(1); 2460 } 2461 2462 /* 2463 * For the Hurd, we will turn off filetype since it doesn't 2464 * support it. 2465 */ 2466 if (fs->super->s_creator_os == EXT2_OS_HURD) 2467 fs->super->s_feature_incompat &= 2468 ~EXT2_FEATURE_INCOMPAT_FILETYPE; 2469 2470 /* 2471 * Set the volume label... 2472 */ 2473 if (volume_label) { 2474 memset(fs->super->s_volume_name, 0, 2475 sizeof(fs->super->s_volume_name)); 2476 strncpy(fs->super->s_volume_name, volume_label, 2477 sizeof(fs->super->s_volume_name)); 2478 } 2479 2480 /* 2481 * Set the last mount directory 2482 */ 2483 if (mount_dir) { 2484 memset(fs->super->s_last_mounted, 0, 2485 sizeof(fs->super->s_last_mounted)); 2486 strncpy(fs->super->s_last_mounted, mount_dir, 2487 sizeof(fs->super->s_last_mounted)); 2488 } 2489 2490 if (!quiet || noaction) 2491 show_stats(fs); 2492 2493 if (noaction) 2494 exit(0); 2495 2496 if (fs->super->s_feature_incompat & 2497 EXT3_FEATURE_INCOMPAT_JOURNAL_DEV) { 2498 create_journal_dev(fs); 2499 exit(ext2fs_close(fs) ? 1 : 0); 2500 } 2501 2502 if (bad_blocks_filename) 2503 read_bb_file(fs, &bb_list, bad_blocks_filename); 2504 if (cflag) 2505 test_disk(fs, &bb_list); 2506 2507 handle_bad_blocks(fs, bb_list); 2508 fs->stride = fs_stride = fs->super->s_raid_stride; 2509 if (!quiet) 2510 printf(_("Allocating group tables: ")); 2511 retval = ext2fs_allocate_tables(fs); 2512 if (retval) { 2513 com_err(program_name, retval, 2514 _("while trying to allocate filesystem tables")); 2515 exit(1); 2516 } 2517 if (!quiet) 2518 printf(_("done \n")); 2519 2520 retval = ext2fs_convert_subcluster_bitmap(fs, &fs->block_map); 2521 if (retval) { 2522 com_err(program_name, retval, 2523 _("\n\twhile converting subcluster bitmap")); 2524 exit(1); 2525 } 2526 2527 if (super_only) { 2528 fs->super->s_state |= EXT2_ERROR_FS; 2529 fs->flags &= ~(EXT2_FLAG_IB_DIRTY|EXT2_FLAG_BB_DIRTY); 2530 /* 2531 * The command "mke2fs -S" is used to recover 2532 * corrupted file systems, so do not mark any of the 2533 * inodes as unused; we want e2fsck to consider all 2534 * inodes as potentially containing recoverable data. 2535 */ 2536 if (fs->super->s_feature_ro_compat & 2537 EXT4_FEATURE_RO_COMPAT_GDT_CSUM) { 2538 for (i = 0; i < fs->group_desc_count; i++) 2539 ext2fs_bg_itable_unused_set(fs, i, 0); 2540 } 2541 } else { 2542 /* rsv must be a power of two (64kB is MD RAID sb alignment) */ 2543 blk64_t rsv = 65536 / fs->blocksize; 2544 blk64_t blocks = ext2fs_blocks_count(fs->super); 2545 blk64_t start; 2546 blk64_t ret_blk; 2547 2548#ifdef ZAP_BOOTBLOCK 2549 zap_sector(fs, 0, 2); 2550#endif 2551 2552 /* 2553 * Wipe out any old MD RAID (or other) metadata at the end 2554 * of the device. This will also verify that the device is 2555 * as large as we think. Be careful with very small devices. 2556 */ 2557 start = (blocks & ~(rsv - 1)); 2558 if (start > rsv) 2559 start -= rsv; 2560 if (start > 0) 2561 retval = ext2fs_zero_blocks2(fs, start, blocks - start, 2562 &ret_blk, NULL); 2563 2564 if (retval) { 2565 com_err(program_name, retval, 2566 _("while zeroing block %llu at end of filesystem"), 2567 ret_blk); 2568 } 2569 write_inode_tables(fs, lazy_itable_init, itable_zeroed); 2570 create_root_dir(fs); 2571 create_lost_and_found(fs); 2572 reserve_inodes(fs); 2573 create_bad_block_inode(fs, bb_list); 2574 if (fs->super->s_feature_compat & 2575 EXT2_FEATURE_COMPAT_RESIZE_INODE) { 2576 retval = ext2fs_create_resize_inode(fs); 2577 if (retval) { 2578 com_err("ext2fs_create_resize_inode", retval, 2579 _("while reserving blocks for online resize")); 2580 exit(1); 2581 } 2582 } 2583 } 2584 2585 if (journal_device) { 2586 ext2_filsys jfs; 2587 2588 if (!force) 2589 check_plausibility(journal_device); 2590 check_mount(journal_device, force, _("journal")); 2591 2592 retval = ext2fs_open(journal_device, EXT2_FLAG_RW| 2593 EXT2_FLAG_JOURNAL_DEV_OK, 0, 2594 fs->blocksize, unix_io_manager, &jfs); 2595 if (retval) { 2596 com_err(program_name, retval, 2597 _("while trying to open journal device %s\n"), 2598 journal_device); 2599 exit(1); 2600 } 2601 if (!quiet) { 2602 printf(_("Adding journal to device %s: "), 2603 journal_device); 2604 fflush(stdout); 2605 } 2606 retval = ext2fs_add_journal_device(fs, jfs); 2607 if(retval) { 2608 com_err (program_name, retval, 2609 _("\n\twhile trying to add journal to device %s"), 2610 journal_device); 2611 exit(1); 2612 } 2613 if (!quiet) 2614 printf(_("done\n")); 2615 ext2fs_close(jfs); 2616 free(journal_device); 2617 } else if ((journal_size) || 2618 (fs_param.s_feature_compat & 2619 EXT3_FEATURE_COMPAT_HAS_JOURNAL)) { 2620 if (super_only) { 2621 printf(_("Skipping journal creation in super-only mode\n")); 2622 fs->super->s_journal_inum = EXT2_JOURNAL_INO; 2623 goto no_journal; 2624 } 2625 2626 if (!journal_blocks) { 2627 fs->super->s_feature_compat &= 2628 ~EXT3_FEATURE_COMPAT_HAS_JOURNAL; 2629 goto no_journal; 2630 } 2631 if (!quiet) { 2632 printf(_("Creating journal (%u blocks): "), 2633 journal_blocks); 2634 fflush(stdout); 2635 } 2636 retval = ext2fs_add_journal_inode(fs, journal_blocks, 2637 journal_flags); 2638 if (retval) { 2639 com_err (program_name, retval, 2640 _("\n\twhile trying to create journal")); 2641 exit(1); 2642 } 2643 if (!quiet) 2644 printf(_("done\n")); 2645 } 2646no_journal: 2647 if (!super_only && 2648 fs->super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_MMP) { 2649 retval = ext2fs_mmp_init(fs); 2650 if (retval) { 2651 fprintf(stderr, _("\nError while enabling multiple " 2652 "mount protection feature.")); 2653 exit(1); 2654 } 2655 if (!quiet) 2656 printf(_("Multiple mount protection is enabled " 2657 "with update interval %d seconds.\n"), 2658 fs->super->s_mmp_update_interval); 2659 } 2660 2661 if (EXT2_HAS_RO_COMPAT_FEATURE(&fs_param, 2662 EXT4_FEATURE_RO_COMPAT_BIGALLOC)) 2663 fix_cluster_bg_counts(fs); 2664 if (EXT2_HAS_RO_COMPAT_FEATURE(&fs_param, 2665 EXT4_FEATURE_RO_COMPAT_QUOTA)) 2666 create_quota_inodes(fs); 2667 2668 if (!quiet) 2669 printf(_("Writing superblocks and " 2670 "filesystem accounting information: ")); 2671 checkinterval = fs->super->s_checkinterval; 2672 max_mnt_count = fs->super->s_max_mnt_count; 2673 retval = ext2fs_close(fs); 2674 if (retval) { 2675 fprintf(stderr, 2676 _("\nWarning, had trouble writing out superblocks.")); 2677 } else if (!quiet) { 2678 printf(_("done\n\n")); 2679 if (!getenv("MKE2FS_SKIP_CHECK_MSG")) 2680 print_check_message(max_mnt_count, checkinterval); 2681 } 2682 2683 remove_error_table(&et_ext2_error_table); 2684 remove_error_table(&et_prof_error_table); 2685 profile_release(profile); 2686 for (i=0; fs_types[i]; i++) 2687 free(fs_types[i]); 2688 free(fs_types); 2689 return retval; 2690} 2691