Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1 | /* |
| 2 | * mke2fs.c - Make a ext2fs filesystem. |
| 3 | * |
Theodore Ts'o | 55f4cbd | 2005-01-05 03:01:06 -0500 | [diff] [blame] | 4 | * Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, |
| 5 | * 2003, 2004, 2005 by Theodore Ts'o. |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 6 | * |
| 7 | * %Begin-Header% |
| 8 | * This file may be redistributed under the terms of the GNU Public |
| 9 | * License. |
| 10 | * %End-Header% |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 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 | |
Theodore Ts'o | ebabf2a | 2008-07-13 15:32:37 -0400 | [diff] [blame] | 19 | #define _XOPEN_SOURCE 600 /* for inclusion of PATH_MAX in Solaris */ |
| 20 | |
Theodore Ts'o | a418d3a | 1997-04-26 14:00:26 +0000 | [diff] [blame] | 21 | #include <stdio.h> |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 22 | #include <string.h> |
| 23 | #include <fcntl.h> |
| 24 | #include <ctype.h> |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 25 | #include <time.h> |
Theodore Ts'o | 756df35 | 2002-03-07 20:52:12 -0500 | [diff] [blame] | 26 | #ifdef __linux__ |
Theodore Ts'o | 2740156 | 1999-09-14 20:11:19 +0000 | [diff] [blame] | 27 | #include <sys/utsname.h> |
| 28 | #endif |
Theodore Ts'o | a418d3a | 1997-04-26 14:00:26 +0000 | [diff] [blame] | 29 | #ifdef HAVE_GETOPT_H |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 30 | #include <getopt.h> |
Theodore Ts'o | 373b833 | 2000-04-03 16:22:35 +0000 | [diff] [blame] | 31 | #else |
| 32 | extern char *optarg; |
| 33 | extern int optind; |
Theodore Ts'o | a418d3a | 1997-04-26 14:00:26 +0000 | [diff] [blame] | 34 | #endif |
| 35 | #ifdef HAVE_UNISTD_H |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 36 | #include <unistd.h> |
Theodore Ts'o | a418d3a | 1997-04-26 14:00:26 +0000 | [diff] [blame] | 37 | #endif |
| 38 | #ifdef HAVE_STDLIB_H |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 39 | #include <stdlib.h> |
Theodore Ts'o | a418d3a | 1997-04-26 14:00:26 +0000 | [diff] [blame] | 40 | #endif |
| 41 | #ifdef HAVE_ERRNO_H |
| 42 | #include <errno.h> |
| 43 | #endif |
| 44 | #ifdef HAVE_MNTENT_H |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 45 | #include <mntent.h> |
Theodore Ts'o | a418d3a | 1997-04-26 14:00:26 +0000 | [diff] [blame] | 46 | #endif |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 47 | #include <sys/ioctl.h> |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 48 | #include <sys/types.h> |
Aneesh Kumar K.V | b626b39 | 2007-08-13 15:56:26 +0530 | [diff] [blame] | 49 | #include <libgen.h> |
Theodore Ts'o | 3658579 | 2008-06-07 22:07:50 -0400 | [diff] [blame] | 50 | #include <limits.h> |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 51 | |
Theodore Ts'o | 54c637d | 2001-05-14 11:45:38 +0000 | [diff] [blame] | 52 | #include "ext2fs/ext2_fs.h" |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 53 | #include "et/com_err.h" |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 54 | #include "uuid/uuid.h" |
Theodore Ts'o | 896938d | 1999-10-23 01:04:50 +0000 | [diff] [blame] | 55 | #include "e2p/e2p.h" |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 56 | #include "ext2fs/ext2fs.h" |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 57 | #include "util.h" |
Theodore Ts'o | 9dc6ad1 | 2006-03-23 22:00:01 -0500 | [diff] [blame] | 58 | #include "profile.h" |
Theodore Ts'o | a6d8302 | 2006-12-26 03:38:07 -0500 | [diff] [blame] | 59 | #include "prof_err.h" |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 60 | #include "../version.h" |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 61 | #include "nls-enable.h" |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 62 | |
| 63 | #define STRIDE_LENGTH 8 |
| 64 | |
Theodore Ts'o | 6733c2f | 1999-11-23 02:23:30 +0000 | [diff] [blame] | 65 | #ifndef __sparc__ |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 66 | #define ZAP_BOOTBLOCK |
| 67 | #endif |
| 68 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 69 | extern int isatty(int); |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 70 | extern FILE *fpopen(const char *cmd, const char *mode); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 71 | |
| 72 | const char * program_name = "mke2fs"; |
Theodore Ts'o | d48755e | 2000-12-09 14:36:04 +0000 | [diff] [blame] | 73 | const char * device_name /* = NULL */; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 74 | |
| 75 | /* Command line options */ |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 76 | int cflag; |
| 77 | int verbose; |
| 78 | int quiet; |
| 79 | int super_only; |
| 80 | int force; |
| 81 | int noaction; |
| 82 | int journal_size; |
| 83 | int journal_flags; |
Theodore Ts'o | a4396e9 | 2008-04-18 10:19:27 -0400 | [diff] [blame] | 84 | int lazy_itable_init; |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 85 | char *bad_blocks_filename; |
| 86 | __u32 fs_stride; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 87 | |
Theodore Ts'o | 9b9a780 | 2005-12-10 21:50:30 -0500 | [diff] [blame] | 88 | struct ext2_super_block fs_param; |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 89 | char *creator_os; |
| 90 | char *volume_label; |
| 91 | char *mount_dir; |
| 92 | char *journal_device; |
| 93 | int sync_kludge; /* Set using the MKE2FS_SYNC env. option */ |
Aneesh Kumar K.V | b626b39 | 2007-08-13 15:56:26 +0530 | [diff] [blame] | 94 | char **fs_types; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 95 | |
Theodore Ts'o | 9dc6ad1 | 2006-03-23 22:00:01 -0500 | [diff] [blame] | 96 | profile_t profile; |
| 97 | |
Theodore Ts'o | 31e29a1 | 2002-05-17 10:53:07 -0400 | [diff] [blame] | 98 | int sys_page_size = 4096; |
Theodore Ts'o | d99225e | 2004-09-25 07:40:12 -0400 | [diff] [blame] | 99 | int linux_version_code = 0; |
Theodore Ts'o | 31e29a1 | 2002-05-17 10:53:07 -0400 | [diff] [blame] | 100 | |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 101 | static void usage(void) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 102 | { |
Theodore Ts'o | bdd80f2 | 2008-02-28 21:12:31 -0500 | [diff] [blame] | 103 | fprintf(stderr, _("Usage: %s [-c|-l filename] [-b block-size] " |
Andreas Dilger | 067911a | 2006-07-15 22:08:20 -0400 | [diff] [blame] | 104 | "[-f fragment-size]\n\t[-i bytes-per-inode] [-I inode-size] " |
Theodore Ts'o | bdd80f2 | 2008-02-28 21:12:31 -0500 | [diff] [blame] | 105 | "[-J journal-options]\n" |
Theodore Ts'o | 9ba4000 | 2008-04-22 08:27:01 -0400 | [diff] [blame] | 106 | "\t[-G meta group size] [-N number-of-inodes]\n" |
| 107 | "\t[-m reserved-blocks-percentage] [-o creator-os]\n" |
| 108 | "\t[-g blocks-per-group] [-L volume-label] " |
Andreas Dilger | 067911a | 2006-07-15 22:08:20 -0400 | [diff] [blame] | 109 | "[-M last-mounted-directory]\n\t[-O feature[,...]] " |
Theodore Ts'o | bdd80f2 | 2008-02-28 21:12:31 -0500 | [diff] [blame] | 110 | "[-r fs-revision] [-E extended-option[,...]]\n" |
| 111 | "\t[-T fs-type] [-jnqvFSV] device [blocks-count]\n"), |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 112 | program_name); |
| 113 | exit(1); |
| 114 | } |
| 115 | |
Theodore Ts'o | 6733c2f | 1999-11-23 02:23:30 +0000 | [diff] [blame] | 116 | static int int_log2(int arg) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 117 | { |
| 118 | int l = 0; |
| 119 | |
| 120 | arg >>= 1; |
| 121 | while (arg) { |
| 122 | l++; |
| 123 | arg >>= 1; |
| 124 | } |
| 125 | return l; |
| 126 | } |
| 127 | |
Theodore Ts'o | 6733c2f | 1999-11-23 02:23:30 +0000 | [diff] [blame] | 128 | static int int_log10(unsigned int arg) |
Theodore Ts'o | 1dde43f | 1998-11-14 04:18:28 +0000 | [diff] [blame] | 129 | { |
| 130 | int l; |
| 131 | |
| 132 | for (l=0; arg ; l++) |
| 133 | arg = arg / 10; |
| 134 | return l; |
| 135 | } |
| 136 | |
Theodore Ts'o | d99225e | 2004-09-25 07:40:12 -0400 | [diff] [blame] | 137 | static int parse_version_number(const char *s) |
| 138 | { |
| 139 | int major, minor, rev; |
| 140 | char *endptr; |
| 141 | const char *cp = s; |
| 142 | |
| 143 | if (!s) |
| 144 | return 0; |
| 145 | major = strtol(cp, &endptr, 10); |
| 146 | if (cp == endptr || *endptr != '.') |
| 147 | return 0; |
| 148 | cp = endptr + 1; |
| 149 | minor = strtol(cp, &endptr, 10); |
| 150 | if (cp == endptr || *endptr != '.') |
| 151 | return 0; |
| 152 | cp = endptr + 1; |
| 153 | rev = strtol(cp, &endptr, 10); |
| 154 | if (cp == endptr) |
| 155 | return 0; |
| 156 | return ((((major * 256) + minor) * 256) + rev); |
| 157 | } |
| 158 | |
Theodore Ts'o | 50787ea | 1999-07-19 15:30:21 +0000 | [diff] [blame] | 159 | /* |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 160 | * Helper function for read_bb_file and test_disk |
| 161 | */ |
Theodore Ts'o | 5443492 | 2003-12-07 01:28:50 -0500 | [diff] [blame] | 162 | static void invalid_block(ext2_filsys fs EXT2FS_ATTR((unused)), blk_t blk) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 163 | { |
Theodore Ts'o | 6693837 | 2002-03-08 00:14:46 -0500 | [diff] [blame] | 164 | fprintf(stderr, _("Bad block %u out of range; ignored.\n"), blk); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 165 | return; |
| 166 | } |
| 167 | |
| 168 | /* |
| 169 | * Reads the bad blocks list from a file |
| 170 | */ |
| 171 | static void read_bb_file(ext2_filsys fs, badblocks_list *bb_list, |
| 172 | const char *bad_blocks_file) |
| 173 | { |
| 174 | FILE *f; |
| 175 | errcode_t retval; |
| 176 | |
| 177 | f = fopen(bad_blocks_file, "r"); |
| 178 | if (!f) { |
| 179 | com_err("read_bad_blocks_file", errno, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 180 | _("while trying to open %s"), bad_blocks_file); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 181 | exit(1); |
| 182 | } |
| 183 | retval = ext2fs_read_bb_FILE(fs, f, bb_list, invalid_block); |
| 184 | fclose (f); |
| 185 | if (retval) { |
| 186 | com_err("ext2fs_read_bb_FILE", retval, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 187 | _("while reading in list of bad blocks from file")); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 188 | exit(1); |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | /* |
| 193 | * Runs the badblocks program to test the disk |
| 194 | */ |
| 195 | static void test_disk(ext2_filsys fs, badblocks_list *bb_list) |
| 196 | { |
| 197 | FILE *f; |
| 198 | errcode_t retval; |
| 199 | char buf[1024]; |
| 200 | |
Eric Sandeen | d0ff90d | 2006-09-12 14:56:15 -0400 | [diff] [blame] | 201 | sprintf(buf, "badblocks -b %d -X %s%s%s %u", fs->blocksize, |
Theodore Ts'o | 3ed57c2 | 2001-12-24 15:01:59 -0500 | [diff] [blame] | 202 | quiet ? "" : "-s ", (cflag > 1) ? "-w " : "", |
Theodore Ts'o | 8ade479 | 2006-11-08 00:41:50 -0500 | [diff] [blame] | 203 | fs->device_name, fs->super->s_blocks_count-1); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 204 | if (verbose) |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 205 | printf(_("Running command: %s\n"), buf); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 206 | f = popen(buf, "r"); |
| 207 | if (!f) { |
| 208 | com_err("popen", errno, |
Theodore Ts'o | f37ab68 | 2005-05-05 23:15:55 -0400 | [diff] [blame] | 209 | _("while trying to run '%s'"), buf); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 210 | exit(1); |
| 211 | } |
| 212 | retval = ext2fs_read_bb_FILE(fs, f, bb_list, invalid_block); |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 213 | pclose(f); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 214 | if (retval) { |
| 215 | com_err("ext2fs_read_bb_FILE", retval, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 216 | _("while processing list of bad blocks from program")); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 217 | exit(1); |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | static void handle_bad_blocks(ext2_filsys fs, badblocks_list bb_list) |
| 222 | { |
Theodore Ts'o | 5443492 | 2003-12-07 01:28:50 -0500 | [diff] [blame] | 223 | dgrp_t i; |
| 224 | blk_t j; |
| 225 | unsigned must_be_good; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 226 | blk_t blk; |
| 227 | badblocks_iterate bb_iter; |
| 228 | errcode_t retval; |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 229 | blk_t group_block; |
| 230 | int group; |
| 231 | int group_bad; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 232 | |
| 233 | if (!bb_list) |
| 234 | return; |
| 235 | |
| 236 | /* |
| 237 | * The primary superblock and group descriptors *must* be |
| 238 | * good; if not, abort. |
| 239 | */ |
| 240 | must_be_good = fs->super->s_first_data_block + 1 + fs->desc_blocks; |
| 241 | for (i = fs->super->s_first_data_block; i <= must_be_good; i++) { |
Theodore Ts'o | cbbf031 | 2001-06-13 00:12:04 +0000 | [diff] [blame] | 242 | if (ext2fs_badblocks_list_test(bb_list, i)) { |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 243 | fprintf(stderr, _("Block %d in primary " |
| 244 | "superblock/group descriptor area bad.\n"), i); |
Eric Sandeen | d0ff90d | 2006-09-12 14:56:15 -0400 | [diff] [blame] | 245 | fprintf(stderr, _("Blocks %u through %u must be good " |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 246 | "in order to build a filesystem.\n"), |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 247 | fs->super->s_first_data_block, must_be_good); |
Theodore Ts'o | 5443492 | 2003-12-07 01:28:50 -0500 | [diff] [blame] | 248 | fputs(_("Aborting....\n"), stderr); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 249 | exit(1); |
| 250 | } |
| 251 | } |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 252 | |
| 253 | /* |
| 254 | * See if any of the bad blocks are showing up in the backup |
| 255 | * superblocks and/or group descriptors. If so, issue a |
| 256 | * warning and adjust the block counts appropriately. |
| 257 | */ |
| 258 | group_block = fs->super->s_first_data_block + |
| 259 | fs->super->s_blocks_per_group; |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 260 | |
| 261 | for (i = 1; i < fs->group_desc_count; i++) { |
Theodore Ts'o | 92bcc59 | 1998-02-16 22:29:34 +0000 | [diff] [blame] | 262 | group_bad = 0; |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 263 | for (j=0; j < fs->desc_blocks+1; j++) { |
Theodore Ts'o | cbbf031 | 2001-06-13 00:12:04 +0000 | [diff] [blame] | 264 | if (ext2fs_badblocks_list_test(bb_list, |
| 265 | group_block + j)) { |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 266 | if (!group_bad) |
| 267 | fprintf(stderr, |
Takashi Sato | 8deb80a | 2006-03-18 21:43:46 -0500 | [diff] [blame] | 268 | _("Warning: the backup superblock/group descriptors at block %u contain\n" |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 269 | " bad blocks.\n\n"), |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 270 | group_block); |
| 271 | group_bad++; |
| 272 | group = ext2fs_group_of_blk(fs, group_block+j); |
| 273 | fs->group_desc[group].bg_free_blocks_count++; |
Theodore Ts'o | 5711ed2 | 2008-04-21 01:29:01 -0400 | [diff] [blame] | 274 | ext2fs_group_desc_csum_set(fs, group); |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 275 | fs->super->s_free_blocks_count++; |
| 276 | } |
| 277 | } |
| 278 | group_block += fs->super->s_blocks_per_group; |
| 279 | } |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 280 | |
| 281 | /* |
| 282 | * Mark all the bad blocks as used... |
| 283 | */ |
Theodore Ts'o | cbbf031 | 2001-06-13 00:12:04 +0000 | [diff] [blame] | 284 | retval = ext2fs_badblocks_list_iterate_begin(bb_list, &bb_iter); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 285 | if (retval) { |
Theodore Ts'o | cbbf031 | 2001-06-13 00:12:04 +0000 | [diff] [blame] | 286 | com_err("ext2fs_badblocks_list_iterate_begin", retval, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 287 | _("while marking bad blocks as used")); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 288 | exit(1); |
| 289 | } |
Theodore Ts'o | cbbf031 | 2001-06-13 00:12:04 +0000 | [diff] [blame] | 290 | while (ext2fs_badblocks_list_iterate(bb_iter, &blk)) |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 291 | ext2fs_mark_block_bitmap(fs->block_map, blk); |
Theodore Ts'o | cbbf031 | 2001-06-13 00:12:04 +0000 | [diff] [blame] | 292 | ext2fs_badblocks_list_iterate_end(bb_iter); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 293 | } |
| 294 | |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 295 | /* |
| 296 | * These functions implement a generalized progress meter. |
| 297 | */ |
| 298 | struct progress_struct { |
| 299 | char format[20]; |
| 300 | char backup[80]; |
| 301 | __u32 max; |
Theodore Ts'o | 1cca86f | 2003-09-01 09:28:18 -0400 | [diff] [blame] | 302 | int skip_progress; |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 303 | }; |
| 304 | |
| 305 | static void progress_init(struct progress_struct *progress, |
Theodore Ts'o | 4ea7bd0 | 2001-12-16 23:23:37 -0500 | [diff] [blame] | 306 | const char *label,__u32 max) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 307 | { |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 308 | int i; |
Theodore Ts'o | 7d5633c | 1999-02-09 08:14:28 +0000 | [diff] [blame] | 309 | |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 310 | memset(progress, 0, sizeof(struct progress_struct)); |
| 311 | if (quiet) |
| 312 | return; |
Theodore Ts'o | 1dde43f | 1998-11-14 04:18:28 +0000 | [diff] [blame] | 313 | |
| 314 | /* |
| 315 | * Figure out how many digits we need |
| 316 | */ |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 317 | i = int_log10(max); |
| 318 | sprintf(progress->format, "%%%dd/%%%dld", i, i); |
| 319 | memset(progress->backup, '\b', sizeof(progress->backup)-1); |
| 320 | progress->backup[sizeof(progress->backup)-1] = 0; |
Theodore Ts'o | 5443492 | 2003-12-07 01:28:50 -0500 | [diff] [blame] | 321 | if ((2*i)+1 < (int) sizeof(progress->backup)) |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 322 | progress->backup[(2*i)+1] = 0; |
| 323 | progress->max = max; |
Theodore Ts'o | 1dde43f | 1998-11-14 04:18:28 +0000 | [diff] [blame] | 324 | |
Theodore Ts'o | 1cca86f | 2003-09-01 09:28:18 -0400 | [diff] [blame] | 325 | progress->skip_progress = 0; |
| 326 | if (getenv("MKE2FS_SKIP_PROGRESS")) |
| 327 | progress->skip_progress++; |
| 328 | |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 329 | fputs(label, stdout); |
| 330 | fflush(stdout); |
| 331 | } |
| 332 | |
| 333 | static void progress_update(struct progress_struct *progress, __u32 val) |
| 334 | { |
Theodore Ts'o | 1cca86f | 2003-09-01 09:28:18 -0400 | [diff] [blame] | 335 | if ((progress->format[0] == 0) || progress->skip_progress) |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 336 | return; |
| 337 | printf(progress->format, val, progress->max); |
| 338 | fputs(progress->backup, stdout); |
| 339 | } |
| 340 | |
| 341 | static void progress_close(struct progress_struct *progress) |
| 342 | { |
| 343 | if (progress->format[0] == 0) |
| 344 | return; |
| 345 | fputs(_("done \n"), stdout); |
| 346 | } |
| 347 | |
Theodore Ts'o | a4396e9 | 2008-04-18 10:19:27 -0400 | [diff] [blame] | 348 | static void write_inode_tables(ext2_filsys fs, int lazy_flag) |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 349 | { |
| 350 | errcode_t retval; |
| 351 | blk_t blk; |
Theodore Ts'o | 5443492 | 2003-12-07 01:28:50 -0500 | [diff] [blame] | 352 | dgrp_t i; |
Theodore Ts'o | 0f2794c | 2008-04-22 23:18:37 -0400 | [diff] [blame] | 353 | int num, ipb; |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 354 | struct progress_struct progress; |
| 355 | |
| 356 | if (quiet) |
| 357 | memset(&progress, 0, sizeof(progress)); |
| 358 | else |
| 359 | progress_init(&progress, _("Writing inode tables: "), |
| 360 | fs->group_desc_count); |
| 361 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 362 | for (i = 0; i < fs->group_desc_count; i++) { |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 363 | progress_update(&progress, i); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 364 | |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 365 | blk = fs->group_desc[i].bg_inode_table; |
| 366 | num = fs->inode_blocks_per_group; |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 367 | |
Theodore Ts'o | 0f2794c | 2008-04-22 23:18:37 -0400 | [diff] [blame] | 368 | if (lazy_flag) { |
| 369 | ipb = fs->blocksize / EXT2_INODE_SIZE(fs->super); |
Theodore Ts'o | 0f2794c | 2008-04-22 23:18:37 -0400 | [diff] [blame] | 370 | num = ((((fs->super->s_inodes_per_group - |
| 371 | fs->group_desc[i].bg_itable_unused) * |
| 372 | EXT2_INODE_SIZE(fs->super)) + |
| 373 | EXT2_BLOCK_SIZE(fs->super) - 1) / |
| 374 | EXT2_BLOCK_SIZE(fs->super)); |
Theodore Ts'o | 0f2794c | 2008-04-22 23:18:37 -0400 | [diff] [blame] | 375 | } else { |
Jose R. Santos | d2d22a2 | 2007-10-21 21:03:36 -0500 | [diff] [blame] | 376 | /* The kernel doesn't need to zero the itable blocks */ |
| 377 | fs->group_desc[i].bg_flags |= EXT2_BG_INODE_ZEROED; |
Theodore Ts'o | 5711ed2 | 2008-04-21 01:29:01 -0400 | [diff] [blame] | 378 | ext2fs_group_desc_csum_set(fs, i); |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 379 | } |
Aneesh Kumar K.V | b626b39 | 2007-08-13 15:56:26 +0530 | [diff] [blame] | 380 | retval = ext2fs_zero_blocks(fs, blk, num, &blk, &num); |
Theodore Ts'o | 0f2794c | 2008-04-22 23:18:37 -0400 | [diff] [blame] | 381 | if (retval) { |
| 382 | fprintf(stderr, _("\nCould not write %d " |
| 383 | "blocks in inode table starting at %u: %s\n"), |
| 384 | num, blk, error_message(retval)); |
| 385 | exit(1); |
| 386 | } |
Theodore Ts'o | 7d5633c | 1999-02-09 08:14:28 +0000 | [diff] [blame] | 387 | if (sync_kludge) { |
| 388 | if (sync_kludge == 1) |
| 389 | sync(); |
| 390 | else if ((i % sync_kludge) == 0) |
| 391 | sync(); |
| 392 | } |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 393 | } |
Aneesh Kumar K.V | b626b39 | 2007-08-13 15:56:26 +0530 | [diff] [blame] | 394 | ext2fs_zero_blocks(0, 0, 0, 0, 0); |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 395 | progress_close(&progress); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | static void create_root_dir(ext2_filsys fs) |
| 399 | { |
Eric Sandeen | 5113a6e | 2007-05-08 00:10:54 -0400 | [diff] [blame] | 400 | errcode_t retval; |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 401 | struct ext2_inode inode; |
Eric Sandeen | 5113a6e | 2007-05-08 00:10:54 -0400 | [diff] [blame] | 402 | __u32 uid, gid; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 403 | |
| 404 | retval = ext2fs_mkdir(fs, EXT2_ROOT_INO, EXT2_ROOT_INO, 0); |
| 405 | if (retval) { |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 406 | com_err("ext2fs_mkdir", retval, _("while creating root dir")); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 407 | exit(1); |
| 408 | } |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 409 | if (geteuid()) { |
| 410 | retval = ext2fs_read_inode(fs, EXT2_ROOT_INO, &inode); |
| 411 | if (retval) { |
| 412 | com_err("ext2fs_read_inode", retval, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 413 | _("while reading root inode")); |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 414 | exit(1); |
| 415 | } |
Eric Sandeen | 5113a6e | 2007-05-08 00:10:54 -0400 | [diff] [blame] | 416 | uid = getuid(); |
| 417 | inode.i_uid = uid; |
Theodore Ts'o | 1534392 | 2008-01-21 09:45:25 -0500 | [diff] [blame] | 418 | ext2fs_set_i_uid_high(inode, uid >> 16); |
Eric Sandeen | 5113a6e | 2007-05-08 00:10:54 -0400 | [diff] [blame] | 419 | if (uid) { |
| 420 | gid = getgid(); |
| 421 | inode.i_gid = gid; |
Theodore Ts'o | 1534392 | 2008-01-21 09:45:25 -0500 | [diff] [blame] | 422 | ext2fs_set_i_gid_high(inode, gid >> 16); |
Eric Sandeen | 5113a6e | 2007-05-08 00:10:54 -0400 | [diff] [blame] | 423 | } |
Theodore Ts'o | e27b456 | 2005-03-21 01:02:53 -0500 | [diff] [blame] | 424 | retval = ext2fs_write_new_inode(fs, EXT2_ROOT_INO, &inode); |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 425 | if (retval) { |
| 426 | com_err("ext2fs_write_inode", retval, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 427 | _("while setting root inode ownership")); |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 428 | exit(1); |
| 429 | } |
| 430 | } |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | static void create_lost_and_found(ext2_filsys fs) |
| 434 | { |
Theodore Ts'o | 2d328bb | 2008-03-17 23:17:13 -0400 | [diff] [blame] | 435 | unsigned int lpf_size = 0; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 436 | errcode_t retval; |
Theodore Ts'o | dfcdc32 | 2001-01-11 15:38:00 +0000 | [diff] [blame] | 437 | ext2_ino_t ino; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 438 | const char *name = "lost+found"; |
| 439 | int i; |
| 440 | |
Theodore Ts'o | 6a52506 | 2001-12-24 09:40:00 -0500 | [diff] [blame] | 441 | fs->umask = 077; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 442 | retval = ext2fs_mkdir(fs, EXT2_ROOT_INO, 0, name); |
| 443 | if (retval) { |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 444 | com_err("ext2fs_mkdir", retval, |
| 445 | _("while creating /lost+found")); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 446 | exit(1); |
| 447 | } |
| 448 | |
| 449 | retval = ext2fs_lookup(fs, EXT2_ROOT_INO, name, strlen(name), 0, &ino); |
| 450 | if (retval) { |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 451 | com_err("ext2_lookup", retval, |
| 452 | _("while looking up /lost+found")); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 453 | exit(1); |
| 454 | } |
| 455 | |
| 456 | for (i=1; i < EXT2_NDIR_BLOCKS; i++) { |
Andreas Dilger | 8c7c6eb | 2008-01-09 20:59:47 +0100 | [diff] [blame] | 457 | /* Ensure that lost+found is at least 2 blocks, so we always |
| 458 | * test large empty blocks for big-block filesystems. */ |
| 459 | if ((lpf_size += fs->blocksize) >= 16*1024 && |
| 460 | lpf_size >= 2 * fs->blocksize) |
Theodore Ts'o | 50787ea | 1999-07-19 15:30:21 +0000 | [diff] [blame] | 461 | break; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 462 | retval = ext2fs_expand_dir(fs, ino); |
| 463 | if (retval) { |
| 464 | com_err("ext2fs_expand_dir", retval, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 465 | _("while expanding /lost+found")); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 466 | exit(1); |
| 467 | } |
Theodore Ts'o | 6a52506 | 2001-12-24 09:40:00 -0500 | [diff] [blame] | 468 | } |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | static void create_bad_block_inode(ext2_filsys fs, badblocks_list bb_list) |
| 472 | { |
| 473 | errcode_t retval; |
| 474 | |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 475 | ext2fs_mark_inode_bitmap(fs->inode_map, EXT2_BAD_INO); |
Theodore Ts'o | 5711ed2 | 2008-04-21 01:29:01 -0400 | [diff] [blame] | 476 | ext2fs_inode_alloc_stats2(fs, EXT2_BAD_INO, +1, 0); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 477 | retval = ext2fs_update_bb_inode(fs, bb_list); |
| 478 | if (retval) { |
| 479 | com_err("ext2fs_update_bb_inode", retval, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 480 | _("while setting bad block inode")); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 481 | exit(1); |
| 482 | } |
| 483 | |
| 484 | } |
| 485 | |
| 486 | static void reserve_inodes(ext2_filsys fs) |
| 487 | { |
Theodore Ts'o | dfcdc32 | 2001-01-11 15:38:00 +0000 | [diff] [blame] | 488 | ext2_ino_t i; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 489 | |
Theodore Ts'o | 5711ed2 | 2008-04-21 01:29:01 -0400 | [diff] [blame] | 490 | for (i = EXT2_ROOT_INO + 1; i < EXT2_FIRST_INODE(fs->super); i++) |
| 491 | ext2fs_inode_alloc_stats2(fs, i, +1, 0); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 492 | ext2fs_mark_ib_dirty(fs); |
| 493 | } |
| 494 | |
Theodore Ts'o | 756df35 | 2002-03-07 20:52:12 -0500 | [diff] [blame] | 495 | #define BSD_DISKMAGIC (0x82564557UL) /* The disk magic number */ |
Theodore Ts'o | 7ef3bb8 | 2002-03-08 03:01:53 -0500 | [diff] [blame] | 496 | #define BSD_MAGICDISK (0x57455682UL) /* The disk magic number reversed */ |
Theodore Ts'o | 756df35 | 2002-03-07 20:52:12 -0500 | [diff] [blame] | 497 | #define BSD_LABEL_OFFSET 64 |
Theodore Ts'o | 756df35 | 2002-03-07 20:52:12 -0500 | [diff] [blame] | 498 | |
Theodore Ts'o | 04a9685 | 2001-08-30 21:55:26 -0400 | [diff] [blame] | 499 | static void zap_sector(ext2_filsys fs, int sect, int nsect) |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 500 | { |
Theodore Ts'o | 3f85f65 | 2001-09-17 10:38:06 -0400 | [diff] [blame] | 501 | char *buf; |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 502 | int retval; |
Theodore Ts'o | 756df35 | 2002-03-07 20:52:12 -0500 | [diff] [blame] | 503 | unsigned int *magic; |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 504 | |
Theodore Ts'o | 3f85f65 | 2001-09-17 10:38:06 -0400 | [diff] [blame] | 505 | buf = malloc(512*nsect); |
Andreas Dilger | 568101f | 2001-10-13 01:22:25 -0600 | [diff] [blame] | 506 | if (!buf) { |
Theodore Ts'o | 4ea7bd0 | 2001-12-16 23:23:37 -0500 | [diff] [blame] | 507 | printf(_("Out of memory erasing sectors %d-%d\n"), |
| 508 | sect, sect + nsect - 1); |
Andreas Dilger | 568101f | 2001-10-13 01:22:25 -0600 | [diff] [blame] | 509 | exit(1); |
| 510 | } |
Theodore Ts'o | 756df35 | 2002-03-07 20:52:12 -0500 | [diff] [blame] | 511 | |
Theodore Ts'o | 7ef3bb8 | 2002-03-08 03:01:53 -0500 | [diff] [blame] | 512 | if (sect == 0) { |
| 513 | /* Check for a BSD disklabel, and don't erase it if so */ |
| 514 | retval = io_channel_read_blk(fs->io, 0, -512, buf); |
| 515 | if (retval) |
| 516 | fprintf(stderr, |
| 517 | _("Warning: could not read block 0: %s\n"), |
| 518 | error_message(retval)); |
| 519 | else { |
| 520 | magic = (unsigned int *) (buf + BSD_LABEL_OFFSET); |
| 521 | if ((*magic == BSD_DISKMAGIC) || |
| 522 | (*magic == BSD_MAGICDISK)) |
| 523 | return; |
| 524 | } |
Theodore Ts'o | 756df35 | 2002-03-07 20:52:12 -0500 | [diff] [blame] | 525 | } |
Theodore Ts'o | 756df35 | 2002-03-07 20:52:12 -0500 | [diff] [blame] | 526 | |
Theodore Ts'o | 7098810 | 2002-07-14 08:00:00 -0400 | [diff] [blame] | 527 | memset(buf, 0, 512*nsect); |
Theodore Ts'o | e41784e | 2000-08-14 14:44:15 +0000 | [diff] [blame] | 528 | io_channel_set_blksize(fs->io, 512); |
Theodore Ts'o | 04a9685 | 2001-08-30 21:55:26 -0400 | [diff] [blame] | 529 | retval = io_channel_write_blk(fs->io, sect, -512*nsect, buf); |
Theodore Ts'o | e41784e | 2000-08-14 14:44:15 +0000 | [diff] [blame] | 530 | io_channel_set_blksize(fs->io, fs->blocksize); |
Theodore Ts'o | 3f85f65 | 2001-09-17 10:38:06 -0400 | [diff] [blame] | 531 | free(buf); |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 532 | if (retval) |
Theodore Ts'o | 6693837 | 2002-03-08 00:14:46 -0500 | [diff] [blame] | 533 | fprintf(stderr, _("Warning: could not erase sector %d: %s\n"), |
| 534 | sect, error_message(retval)); |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 535 | } |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 536 | |
| 537 | static void create_journal_dev(ext2_filsys fs) |
| 538 | { |
| 539 | struct progress_struct progress; |
| 540 | errcode_t retval; |
| 541 | char *buf; |
Aneesh Kumar K.V | b626b39 | 2007-08-13 15:56:26 +0530 | [diff] [blame] | 542 | blk_t blk, err_blk; |
| 543 | int c, count, err_count; |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 544 | |
Theodore Ts'o | d6a27e0 | 2001-04-17 02:34:41 +0000 | [diff] [blame] | 545 | retval = ext2fs_create_journal_superblock(fs, |
| 546 | fs->super->s_blocks_count, 0, &buf); |
| 547 | if (retval) { |
| 548 | com_err("create_journal_dev", retval, |
| 549 | _("while initializing journal superblock")); |
| 550 | exit(1); |
| 551 | } |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 552 | if (quiet) |
| 553 | memset(&progress, 0, sizeof(progress)); |
| 554 | else |
| 555 | progress_init(&progress, _("Zeroing journal device: "), |
| 556 | fs->super->s_blocks_count); |
| 557 | |
Aneesh Kumar K.V | b626b39 | 2007-08-13 15:56:26 +0530 | [diff] [blame] | 558 | blk = 0; |
| 559 | count = fs->super->s_blocks_count; |
| 560 | while (count > 0) { |
| 561 | if (count > 1024) |
| 562 | c = 1024; |
| 563 | else |
| 564 | c = count; |
| 565 | retval = ext2fs_zero_blocks(fs, blk, c, &err_blk, &err_count); |
| 566 | if (retval) { |
| 567 | com_err("create_journal_dev", retval, |
| 568 | _("while zeroing journal device " |
| 569 | "(block %u, count %d)"), |
| 570 | err_blk, err_count); |
| 571 | exit(1); |
| 572 | } |
| 573 | blk += c; |
| 574 | count -= c; |
| 575 | progress_update(&progress, blk); |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 576 | } |
Aneesh Kumar K.V | b626b39 | 2007-08-13 15:56:26 +0530 | [diff] [blame] | 577 | ext2fs_zero_blocks(0, 0, 0, 0, 0); |
Theodore Ts'o | dc2ec52 | 2001-01-18 01:51:15 +0000 | [diff] [blame] | 578 | |
Theodore Ts'o | dc2ec52 | 2001-01-18 01:51:15 +0000 | [diff] [blame] | 579 | retval = io_channel_write_blk(fs->io, |
| 580 | fs->super->s_first_data_block+1, |
| 581 | 1, buf); |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 582 | if (retval) { |
| 583 | com_err("create_journal_dev", retval, |
| 584 | _("while writing journal superblock")); |
| 585 | exit(1); |
| 586 | } |
| 587 | progress_close(&progress); |
| 588 | } |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 589 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 590 | static void show_stats(ext2_filsys fs) |
| 591 | { |
Theodore Ts'o | ef9abe5 | 2001-01-01 15:31:53 +0000 | [diff] [blame] | 592 | struct ext2_super_block *s = fs->super; |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 593 | char buf[80]; |
Theodore Ts'o | 6325394 | 2005-03-19 01:13:22 -0500 | [diff] [blame] | 594 | char *os; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 595 | blk_t group_block; |
Theodore Ts'o | 5443492 | 2003-12-07 01:28:50 -0500 | [diff] [blame] | 596 | dgrp_t i; |
| 597 | int need, col_left; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 598 | |
Theodore Ts'o | 9b9a780 | 2005-12-10 21:50:30 -0500 | [diff] [blame] | 599 | if (fs_param.s_blocks_count != s->s_blocks_count) |
Takashi Sato | 8deb80a | 2006-03-18 21:43:46 -0500 | [diff] [blame] | 600 | fprintf(stderr, _("warning: %u blocks unused.\n\n"), |
Theodore Ts'o | 9b9a780 | 2005-12-10 21:50:30 -0500 | [diff] [blame] | 601 | fs_param.s_blocks_count - s->s_blocks_count); |
Theodore Ts'o | 50787ea | 1999-07-19 15:30:21 +0000 | [diff] [blame] | 602 | |
| 603 | memset(buf, 0, sizeof(buf)); |
| 604 | strncpy(buf, s->s_volume_name, sizeof(s->s_volume_name)); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 605 | printf(_("Filesystem label=%s\n"), buf); |
Theodore Ts'o | 5443492 | 2003-12-07 01:28:50 -0500 | [diff] [blame] | 606 | fputs(_("OS type: "), stdout); |
Theodore Ts'o | 6325394 | 2005-03-19 01:13:22 -0500 | [diff] [blame] | 607 | os = e2p_os2string(fs->super->s_creator_os); |
| 608 | fputs(os, stdout); |
| 609 | free(os); |
Theodore Ts'o | 50787ea | 1999-07-19 15:30:21 +0000 | [diff] [blame] | 610 | printf("\n"); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 611 | printf(_("Block size=%u (log=%u)\n"), fs->blocksize, |
Theodore Ts'o | 50787ea | 1999-07-19 15:30:21 +0000 | [diff] [blame] | 612 | s->s_log_block_size); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 613 | printf(_("Fragment size=%u (log=%u)\n"), fs->fragsize, |
Theodore Ts'o | 50787ea | 1999-07-19 15:30:21 +0000 | [diff] [blame] | 614 | s->s_log_frag_size); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 615 | printf(_("%u inodes, %u blocks\n"), s->s_inodes_count, |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 616 | s->s_blocks_count); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 617 | printf(_("%u blocks (%2.2f%%) reserved for the super user\n"), |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 618 | s->s_r_blocks_count, |
| 619 | 100.0 * s->s_r_blocks_count / s->s_blocks_count); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 620 | printf(_("First data block=%u\n"), s->s_first_data_block); |
Theodore Ts'o | d323f8f | 2004-12-15 14:39:16 -0500 | [diff] [blame] | 621 | if (s->s_reserved_gdt_blocks) |
| 622 | printf(_("Maximum filesystem blocks=%lu\n"), |
| 623 | (s->s_reserved_gdt_blocks + fs->desc_blocks) * |
Valerie Clement | f2de1d3 | 2007-08-30 17:38:13 +0200 | [diff] [blame] | 624 | EXT2_DESC_PER_BLOCK(s) * s->s_blocks_per_group); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 625 | if (fs->group_desc_count > 1) |
Theodore Ts'o | c8c071a | 2001-01-11 16:08:23 +0000 | [diff] [blame] | 626 | printf(_("%u block groups\n"), fs->group_desc_count); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 627 | else |
Theodore Ts'o | c8c071a | 2001-01-11 16:08:23 +0000 | [diff] [blame] | 628 | printf(_("%u block group\n"), fs->group_desc_count); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 629 | printf(_("%u blocks per group, %u fragments per group\n"), |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 630 | s->s_blocks_per_group, s->s_frags_per_group); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 631 | printf(_("%u inodes per group\n"), s->s_inodes_per_group); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 632 | |
| 633 | if (fs->group_desc_count == 1) { |
| 634 | printf("\n"); |
| 635 | return; |
| 636 | } |
Theodore Ts'o | d323f8f | 2004-12-15 14:39:16 -0500 | [diff] [blame] | 637 | |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 638 | printf(_("Superblock backups stored on blocks: ")); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 639 | group_block = s->s_first_data_block; |
| 640 | col_left = 0; |
| 641 | for (i = 1; i < fs->group_desc_count; i++) { |
| 642 | group_block += s->s_blocks_per_group; |
Theodore Ts'o | 521e368 | 1997-04-29 17:48:10 +0000 | [diff] [blame] | 643 | if (!ext2fs_bg_has_super(fs, i)) |
| 644 | continue; |
Theodore Ts'o | 7671433 | 1999-10-20 18:06:29 +0000 | [diff] [blame] | 645 | if (i != 1) |
| 646 | printf(", "); |
Theodore Ts'o | 6733c2f | 1999-11-23 02:23:30 +0000 | [diff] [blame] | 647 | need = int_log10(group_block) + 2; |
Theodore Ts'o | 1dde43f | 1998-11-14 04:18:28 +0000 | [diff] [blame] | 648 | if (need > col_left) { |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 649 | printf("\n\t"); |
Theodore Ts'o | 1dde43f | 1998-11-14 04:18:28 +0000 | [diff] [blame] | 650 | col_left = 72; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 651 | } |
Theodore Ts'o | 1dde43f | 1998-11-14 04:18:28 +0000 | [diff] [blame] | 652 | col_left -= need; |
Theodore Ts'o | a418d3a | 1997-04-26 14:00:26 +0000 | [diff] [blame] | 653 | printf("%u", group_block); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 654 | } |
| 655 | printf("\n\n"); |
| 656 | } |
| 657 | |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 658 | /* |
| 659 | * Set the S_CREATOR_OS field. Return true if OS is known, |
| 660 | * otherwise, 0. |
| 661 | */ |
| 662 | static int set_os(struct ext2_super_block *sb, char *os) |
| 663 | { |
| 664 | if (isdigit (*os)) |
| 665 | sb->s_creator_os = atoi (os); |
| 666 | else if (strcasecmp(os, "linux") == 0) |
| 667 | sb->s_creator_os = EXT2_OS_LINUX; |
| 668 | else if (strcasecmp(os, "GNU") == 0 || strcasecmp(os, "hurd") == 0) |
| 669 | sb->s_creator_os = EXT2_OS_HURD; |
Theodore Ts'o | ea1e8f4 | 2005-01-19 18:18:44 -0500 | [diff] [blame] | 670 | else if (strcasecmp(os, "freebsd") == 0) |
| 671 | sb->s_creator_os = EXT2_OS_FREEBSD; |
| 672 | else if (strcasecmp(os, "lites") == 0) |
| 673 | sb->s_creator_os = EXT2_OS_LITES; |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 674 | else |
| 675 | return 0; |
| 676 | return 1; |
| 677 | } |
| 678 | |
Theodore Ts'o | a418d3a | 1997-04-26 14:00:26 +0000 | [diff] [blame] | 679 | #define PATH_SET "PATH=/sbin" |
| 680 | |
Theodore Ts'o | c6a4413 | 2005-01-05 11:12:20 -0500 | [diff] [blame] | 681 | static void parse_extended_opts(struct ext2_super_block *param, |
| 682 | const char *opts) |
Theodore Ts'o | a29f4d3 | 1997-04-29 21:26:48 +0000 | [diff] [blame] | 683 | { |
Theodore Ts'o | 2d328bb | 2008-03-17 23:17:13 -0400 | [diff] [blame] | 684 | char *buf, *token, *next, *p, *arg, *badopt = 0; |
Theodore Ts'o | a29f4d3 | 1997-04-29 21:26:48 +0000 | [diff] [blame] | 685 | int len; |
Theodore Ts'o | d323f8f | 2004-12-15 14:39:16 -0500 | [diff] [blame] | 686 | int r_usage = 0; |
Theodore Ts'o | a29f4d3 | 1997-04-29 21:26:48 +0000 | [diff] [blame] | 687 | |
| 688 | len = strlen(opts); |
| 689 | buf = malloc(len+1); |
| 690 | if (!buf) { |
Theodore Ts'o | d323f8f | 2004-12-15 14:39:16 -0500 | [diff] [blame] | 691 | fprintf(stderr, |
| 692 | _("Couldn't allocate memory to parse options!\n")); |
Theodore Ts'o | a29f4d3 | 1997-04-29 21:26:48 +0000 | [diff] [blame] | 693 | exit(1); |
| 694 | } |
| 695 | strcpy(buf, opts); |
| 696 | for (token = buf; token && *token; token = next) { |
| 697 | p = strchr(token, ','); |
| 698 | next = 0; |
| 699 | if (p) { |
| 700 | *p = 0; |
| 701 | next = p+1; |
Theodore Ts'o | d323f8f | 2004-12-15 14:39:16 -0500 | [diff] [blame] | 702 | } |
Theodore Ts'o | a29f4d3 | 1997-04-29 21:26:48 +0000 | [diff] [blame] | 703 | arg = strchr(token, '='); |
| 704 | if (arg) { |
| 705 | *arg = 0; |
| 706 | arg++; |
| 707 | } |
| 708 | if (strcmp(token, "stride") == 0) { |
| 709 | if (!arg) { |
Theodore Ts'o | d323f8f | 2004-12-15 14:39:16 -0500 | [diff] [blame] | 710 | r_usage++; |
Theodore Ts'o | 0c17cb2 | 2008-02-18 22:56:25 -0500 | [diff] [blame] | 711 | badopt = token; |
Theodore Ts'o | a29f4d3 | 1997-04-29 21:26:48 +0000 | [diff] [blame] | 712 | continue; |
| 713 | } |
Theodore Ts'o | 0c17cb2 | 2008-02-18 22:56:25 -0500 | [diff] [blame] | 714 | param->s_raid_stride = strtoul(arg, &p, 0); |
| 715 | if (*p || (param->s_raid_stride == 0)) { |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 716 | fprintf(stderr, |
Theodore Ts'o | f37ab68 | 2005-05-05 23:15:55 -0400 | [diff] [blame] | 717 | _("Invalid stride parameter: %s\n"), |
| 718 | arg); |
Theodore Ts'o | d323f8f | 2004-12-15 14:39:16 -0500 | [diff] [blame] | 719 | r_usage++; |
Theodore Ts'o | a29f4d3 | 1997-04-29 21:26:48 +0000 | [diff] [blame] | 720 | continue; |
| 721 | } |
Theodore Ts'o | 0c17cb2 | 2008-02-18 22:56:25 -0500 | [diff] [blame] | 722 | } else if (strcmp(token, "stripe-width") == 0 || |
| 723 | strcmp(token, "stripe_width") == 0) { |
| 724 | if (!arg) { |
| 725 | r_usage++; |
| 726 | badopt = token; |
| 727 | continue; |
| 728 | } |
| 729 | param->s_raid_stripe_width = strtoul(arg, &p, 0); |
| 730 | if (*p || (param->s_raid_stripe_width == 0)) { |
| 731 | fprintf(stderr, |
| 732 | _("Invalid stripe-width parameter: %s\n"), |
| 733 | arg); |
| 734 | r_usage++; |
| 735 | continue; |
| 736 | } |
Theodore Ts'o | d323f8f | 2004-12-15 14:39:16 -0500 | [diff] [blame] | 737 | } else if (!strcmp(token, "resize")) { |
Theodore Ts'o | c6a4413 | 2005-01-05 11:12:20 -0500 | [diff] [blame] | 738 | unsigned long resize, bpg, rsv_groups; |
| 739 | unsigned long group_desc_count, desc_blocks; |
| 740 | unsigned int gdpb, blocksize; |
| 741 | int rsv_gdb; |
Theodore Ts'o | d323f8f | 2004-12-15 14:39:16 -0500 | [diff] [blame] | 742 | |
| 743 | if (!arg) { |
| 744 | r_usage++; |
Theodore Ts'o | 0c17cb2 | 2008-02-18 22:56:25 -0500 | [diff] [blame] | 745 | badopt = token; |
Theodore Ts'o | d323f8f | 2004-12-15 14:39:16 -0500 | [diff] [blame] | 746 | continue; |
| 747 | } |
| 748 | |
Theodore Ts'o | 55f4cbd | 2005-01-05 03:01:06 -0500 | [diff] [blame] | 749 | resize = parse_num_blocks(arg, |
| 750 | param->s_log_block_size); |
Theodore Ts'o | d323f8f | 2004-12-15 14:39:16 -0500 | [diff] [blame] | 751 | |
| 752 | if (resize == 0) { |
Theodore Ts'o | 55f4cbd | 2005-01-05 03:01:06 -0500 | [diff] [blame] | 753 | fprintf(stderr, |
| 754 | _("Invalid resize parameter: %s\n"), |
| 755 | arg); |
Theodore Ts'o | d323f8f | 2004-12-15 14:39:16 -0500 | [diff] [blame] | 756 | r_usage++; |
| 757 | continue; |
| 758 | } |
Theodore Ts'o | c6a4413 | 2005-01-05 11:12:20 -0500 | [diff] [blame] | 759 | if (resize <= param->s_blocks_count) { |
| 760 | fprintf(stderr, |
Theodore Ts'o | f37ab68 | 2005-05-05 23:15:55 -0400 | [diff] [blame] | 761 | _("The resize maximum must be greater " |
| 762 | "than the filesystem size.\n")); |
Theodore Ts'o | c6a4413 | 2005-01-05 11:12:20 -0500 | [diff] [blame] | 763 | r_usage++; |
| 764 | continue; |
| 765 | } |
Theodore Ts'o | d323f8f | 2004-12-15 14:39:16 -0500 | [diff] [blame] | 766 | |
Theodore Ts'o | c6a4413 | 2005-01-05 11:12:20 -0500 | [diff] [blame] | 767 | blocksize = EXT2_BLOCK_SIZE(param); |
| 768 | bpg = param->s_blocks_per_group; |
| 769 | if (!bpg) |
| 770 | bpg = blocksize * 8; |
Valerie Clement | f2de1d3 | 2007-08-30 17:38:13 +0200 | [diff] [blame] | 771 | gdpb = EXT2_DESC_PER_BLOCK(param); |
Theodore Ts'o | 69022e0 | 2006-08-30 01:57:00 -0400 | [diff] [blame] | 772 | group_desc_count = |
| 773 | ext2fs_div_ceil(param->s_blocks_count, bpg); |
Theodore Ts'o | c6a4413 | 2005-01-05 11:12:20 -0500 | [diff] [blame] | 774 | desc_blocks = (group_desc_count + |
| 775 | gdpb - 1) / gdpb; |
Theodore Ts'o | 69022e0 | 2006-08-30 01:57:00 -0400 | [diff] [blame] | 776 | rsv_groups = ext2fs_div_ceil(resize, bpg); |
| 777 | rsv_gdb = ext2fs_div_ceil(rsv_groups, gdpb) - |
Theodore Ts'o | c6a4413 | 2005-01-05 11:12:20 -0500 | [diff] [blame] | 778 | desc_blocks; |
Theodore Ts'o | 9b9a780 | 2005-12-10 21:50:30 -0500 | [diff] [blame] | 779 | if (rsv_gdb > (int) EXT2_ADDR_PER_BLOCK(param)) |
Theodore Ts'o | c6a4413 | 2005-01-05 11:12:20 -0500 | [diff] [blame] | 780 | rsv_gdb = EXT2_ADDR_PER_BLOCK(param); |
| 781 | |
| 782 | if (rsv_gdb > 0) { |
Theodore Ts'o | b290d2d | 2006-10-18 00:31:11 -0400 | [diff] [blame] | 783 | if (param->s_rev_level == EXT2_GOOD_OLD_REV) { |
| 784 | fprintf(stderr, |
| 785 | _("On-line resizing not supported with revision 0 filesystems\n")); |
Brian Behlendorf | 2140038 | 2007-05-31 11:30:47 -0400 | [diff] [blame] | 786 | free(buf); |
Theodore Ts'o | b290d2d | 2006-10-18 00:31:11 -0400 | [diff] [blame] | 787 | exit(1); |
| 788 | } |
Theodore Ts'o | c6a4413 | 2005-01-05 11:12:20 -0500 | [diff] [blame] | 789 | param->s_feature_compat |= |
| 790 | EXT2_FEATURE_COMPAT_RESIZE_INODE; |
| 791 | |
| 792 | param->s_reserved_gdt_blocks = rsv_gdb; |
| 793 | } |
Theodore Ts'o | 6cb2740 | 2008-01-26 19:06:35 -0500 | [diff] [blame] | 794 | } else if (!strcmp(token, "test_fs")) { |
| 795 | param->s_flags |= EXT2_FLAGS_TEST_FILESYS; |
Theodore Ts'o | a4396e9 | 2008-04-18 10:19:27 -0400 | [diff] [blame] | 796 | } else if (!strcmp(token, "lazy_itable_init")) { |
Theodore Ts'o | 43781b9 | 2008-04-27 19:38:02 -0400 | [diff] [blame] | 797 | if (arg) |
| 798 | lazy_itable_init = strtoul(arg, &p, 0); |
| 799 | else |
| 800 | lazy_itable_init = 1; |
Theodore Ts'o | 0c17cb2 | 2008-02-18 22:56:25 -0500 | [diff] [blame] | 801 | } else { |
Theodore Ts'o | d323f8f | 2004-12-15 14:39:16 -0500 | [diff] [blame] | 802 | r_usage++; |
Theodore Ts'o | 0c17cb2 | 2008-02-18 22:56:25 -0500 | [diff] [blame] | 803 | badopt = token; |
| 804 | } |
Theodore Ts'o | a29f4d3 | 1997-04-29 21:26:48 +0000 | [diff] [blame] | 805 | } |
Theodore Ts'o | d323f8f | 2004-12-15 14:39:16 -0500 | [diff] [blame] | 806 | if (r_usage) { |
Theodore Ts'o | 0c17cb2 | 2008-02-18 22:56:25 -0500 | [diff] [blame] | 807 | fprintf(stderr, _("\nBad option(s) specified: %s\n\n" |
Theodore Ts'o | bb145b0 | 2005-06-20 08:35:27 -0400 | [diff] [blame] | 808 | "Extended options are separated by commas, " |
Theodore Ts'o | a29f4d3 | 1997-04-29 21:26:48 +0000 | [diff] [blame] | 809 | "and may take an argument which\n" |
| 810 | "\tis set off by an equals ('=') sign.\n\n" |
Theodore Ts'o | bb145b0 | 2005-06-20 08:35:27 -0400 | [diff] [blame] | 811 | "Valid extended options are:\n" |
Theodore Ts'o | 0c17cb2 | 2008-02-18 22:56:25 -0500 | [diff] [blame] | 812 | "\tstride=<RAID per-disk data chunk in blocks>\n" |
| 813 | "\tstripe-width=<RAID stride * data disks in blocks>\n" |
Theodore Ts'o | a4396e9 | 2008-04-18 10:19:27 -0400 | [diff] [blame] | 814 | "\tresize=<resize maximum size in blocks>\n" |
| 815 | "\tlazy_itable_init=<0 to disable, 1 to enable>\n" |
| 816 | "\ttest_fs\n\n"), |
Theodore Ts'o | 2d328bb | 2008-03-17 23:17:13 -0400 | [diff] [blame] | 817 | badopt ? badopt : ""); |
Brian Behlendorf | 2140038 | 2007-05-31 11:30:47 -0400 | [diff] [blame] | 818 | free(buf); |
Theodore Ts'o | a29f4d3 | 1997-04-29 21:26:48 +0000 | [diff] [blame] | 819 | exit(1); |
| 820 | } |
Theodore Ts'o | 0c17cb2 | 2008-02-18 22:56:25 -0500 | [diff] [blame] | 821 | if (param->s_raid_stride && |
| 822 | (param->s_raid_stripe_width % param->s_raid_stride) != 0) |
| 823 | fprintf(stderr, _("\nWarning: RAID stripe-width %u not an even " |
| 824 | "multiple of stride %u.\n\n"), |
| 825 | param->s_raid_stripe_width, param->s_raid_stride); |
| 826 | |
Brian Behlendorf | 2140038 | 2007-05-31 11:30:47 -0400 | [diff] [blame] | 827 | free(buf); |
Theodore Ts'o | a29f4d3 | 1997-04-29 21:26:48 +0000 | [diff] [blame] | 828 | } |
| 829 | |
Theodore Ts'o | 896938d | 1999-10-23 01:04:50 +0000 | [diff] [blame] | 830 | static __u32 ok_features[3] = { |
Theodore Ts'o | 558df54 | 2008-02-27 15:01:19 -0500 | [diff] [blame] | 831 | /* Compat */ |
Theodore Ts'o | 843049c | 2002-09-22 15:37:40 -0400 | [diff] [blame] | 832 | EXT3_FEATURE_COMPAT_HAS_JOURNAL | |
Theodore Ts'o | d323f8f | 2004-12-15 14:39:16 -0500 | [diff] [blame] | 833 | EXT2_FEATURE_COMPAT_RESIZE_INODE | |
Theodore Ts'o | f5fa200 | 2006-05-08 20:17:26 -0400 | [diff] [blame] | 834 | EXT2_FEATURE_COMPAT_DIR_INDEX | |
Theodore Ts'o | 558df54 | 2008-02-27 15:01:19 -0500 | [diff] [blame] | 835 | EXT2_FEATURE_COMPAT_EXT_ATTR, |
| 836 | /* Incompat */ |
| 837 | EXT2_FEATURE_INCOMPAT_FILETYPE| |
Theodore Ts'o | bf6b848 | 2008-02-20 08:13:19 -0500 | [diff] [blame] | 838 | EXT3_FEATURE_INCOMPAT_EXTENTS| |
Theodore Ts'o | c046ac7 | 2002-10-20 00:38:57 -0400 | [diff] [blame] | 839 | EXT3_FEATURE_INCOMPAT_JOURNAL_DEV| |
Jose R. Santos | c2d4300 | 2007-08-13 23:32:57 -0500 | [diff] [blame] | 840 | EXT2_FEATURE_INCOMPAT_META_BG| |
| 841 | EXT4_FEATURE_INCOMPAT_FLEX_BG, |
Theodore Ts'o | 558df54 | 2008-02-27 15:01:19 -0500 | [diff] [blame] | 842 | /* R/O compat */ |
| 843 | EXT2_FEATURE_RO_COMPAT_LARGE_FILE| |
Theodore Ts'o | 2be8fe4 | 2008-07-10 10:49:59 -0400 | [diff] [blame] | 844 | EXT4_FEATURE_RO_COMPAT_HUGE_FILE| |
| 845 | EXT4_FEATURE_RO_COMPAT_DIR_NLINK| |
| 846 | EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE| |
Jose R. Santos | d2d22a2 | 2007-10-21 21:03:36 -0500 | [diff] [blame] | 847 | EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER| |
| 848 | EXT4_FEATURE_RO_COMPAT_GDT_CSUM |
Theodore Ts'o | 896938d | 1999-10-23 01:04:50 +0000 | [diff] [blame] | 849 | }; |
Theodore Ts'o | a29f4d3 | 1997-04-29 21:26:48 +0000 | [diff] [blame] | 850 | |
| 851 | |
Theodore Ts'o | 9dc6ad1 | 2006-03-23 22:00:01 -0500 | [diff] [blame] | 852 | static void syntax_err_report(const char *filename, long err, int line_num) |
| 853 | { |
| 854 | fprintf(stderr, |
| 855 | _("Syntax error in mke2fs config file (%s, line #%d)\n\t%s\n"), |
| 856 | filename, line_num, error_message(err)); |
| 857 | exit(1); |
| 858 | } |
| 859 | |
Matthias Andree | abcfdfd | 2006-06-10 16:08:18 +0200 | [diff] [blame] | 860 | static const char *config_fn[] = { ROOT_SYSCONFDIR "/mke2fs.conf", 0 }; |
Theodore Ts'o | 9dc6ad1 | 2006-03-23 22:00:01 -0500 | [diff] [blame] | 861 | |
| 862 | static void edit_feature(const char *str, __u32 *compat_array) |
| 863 | { |
| 864 | if (!str) |
| 865 | return; |
| 866 | |
| 867 | if (e2p_edit_feature(str, compat_array, ok_features)) { |
| 868 | fprintf(stderr, _("Invalid filesystem option set: %s\n"), |
| 869 | str); |
| 870 | exit(1); |
| 871 | } |
| 872 | } |
| 873 | |
Theodore Ts'o | 3d43836 | 2008-02-19 08:32:58 -0500 | [diff] [blame] | 874 | struct str_list { |
| 875 | char **list; |
| 876 | int num; |
| 877 | int max; |
| 878 | }; |
| 879 | |
| 880 | static errcode_t init_list(struct str_list *sl) |
| 881 | { |
| 882 | sl->num = 0; |
| 883 | sl->max = 0; |
| 884 | sl->list = malloc((sl->max+1) * sizeof(char *)); |
| 885 | if (!sl->list) |
| 886 | return ENOMEM; |
| 887 | sl->list[0] = 0; |
| 888 | return 0; |
| 889 | } |
| 890 | |
| 891 | static errcode_t push_string(struct str_list *sl, const char *str) |
| 892 | { |
| 893 | char **new_list; |
| 894 | |
| 895 | if (sl->num >= sl->max) { |
| 896 | sl->max += 2; |
| 897 | new_list = realloc(sl->list, (sl->max+1) * sizeof(char *)); |
| 898 | if (!new_list) |
| 899 | return ENOMEM; |
| 900 | sl->list = new_list; |
| 901 | } |
| 902 | sl->list[sl->num] = malloc(strlen(str)+1); |
| 903 | if (sl->list[sl->num] == 0) |
| 904 | return ENOMEM; |
| 905 | strcpy(sl->list[sl->num], str); |
| 906 | sl->num++; |
| 907 | sl->list[sl->num] = 0; |
| 908 | return 0; |
| 909 | } |
| 910 | |
| 911 | static void print_str_list(char **list) |
| 912 | { |
| 913 | char **cpp; |
| 914 | |
| 915 | for (cpp = list; *cpp; cpp++) { |
| 916 | printf("'%s'", *cpp); |
| 917 | if (cpp[1]) |
| 918 | fputs(", ", stdout); |
| 919 | } |
| 920 | fputc('\n', stdout); |
| 921 | } |
| 922 | |
| 923 | static char **parse_fs_type(const char *fs_type, |
| 924 | const char *usage_types, |
| 925 | struct ext2_super_block *fs_param, |
| 926 | char *progname) |
| 927 | { |
| 928 | const char *ext_type = 0; |
| 929 | char *parse_str; |
| 930 | char *profile_type = 0; |
| 931 | char *cp, *t; |
| 932 | const char *size_type; |
| 933 | struct str_list list; |
Theodore Ts'o | 3d43836 | 2008-02-19 08:32:58 -0500 | [diff] [blame] | 934 | unsigned long meg; |
Theodore Ts'o | 7f5601e | 2008-07-10 09:24:25 -0400 | [diff] [blame] | 935 | int is_hurd = 0; |
Theodore Ts'o | 3d43836 | 2008-02-19 08:32:58 -0500 | [diff] [blame] | 936 | |
| 937 | if (init_list(&list)) |
| 938 | return 0; |
| 939 | |
Theodore Ts'o | 7f5601e | 2008-07-10 09:24:25 -0400 | [diff] [blame] | 940 | if (creator_os && (!strcasecmp(creator_os, "GNU") || |
| 941 | !strcasecmp(creator_os, "hurd"))) |
| 942 | is_hurd = 1; |
| 943 | |
Theodore Ts'o | 3d43836 | 2008-02-19 08:32:58 -0500 | [diff] [blame] | 944 | if (fs_type) |
| 945 | ext_type = fs_type; |
Theodore Ts'o | 7f5601e | 2008-07-10 09:24:25 -0400 | [diff] [blame] | 946 | else if (is_hurd) |
| 947 | ext_type = "ext2"; |
Theodore Ts'o | 3d43836 | 2008-02-19 08:32:58 -0500 | [diff] [blame] | 948 | else if (progname) { |
| 949 | ext_type = strrchr(progname, '/'); |
| 950 | if (ext_type) |
| 951 | ext_type++; |
| 952 | else |
| 953 | ext_type = progname; |
| 954 | |
| 955 | if (!strncmp(ext_type, "mkfs.", 5)) { |
| 956 | ext_type += 5; |
| 957 | if (ext_type[0] == 0) |
| 958 | ext_type = 0; |
| 959 | } else |
| 960 | ext_type = 0; |
| 961 | } |
| 962 | |
| 963 | if (!ext_type) { |
| 964 | profile_get_string(profile, "defaults", "fs_type", 0, |
| 965 | "ext2", &profile_type); |
| 966 | ext_type = profile_type; |
| 967 | if (!strcmp(ext_type, "ext2") && (journal_size != 0)) |
| 968 | ext_type = "ext3"; |
| 969 | } |
| 970 | |
Theodore Ts'o | bad89b2 | 2008-08-22 21:57:29 -0400 | [diff] [blame^] | 971 | if (!strcmp(ext_type, "ext3") || !strcmp(ext_type, "ext4") || |
| 972 | !strcmp(ext_type, "ext4dev")) { |
| 973 | profile_get_string(profile, "fs_types", ext_type, "features", |
| 974 | 0, &t); |
| 975 | if (!t) { |
| 976 | printf(_("\nWarning! Your mke2fs.conf file does " |
| 977 | "not define the %s filesystem type.\n"), |
| 978 | ext_type); |
| 979 | printf(_("You probably need to install an updated " |
| 980 | "mke2fs.conf file.\n\n")); |
| 981 | sleep(5); |
| 982 | } |
| 983 | } |
| 984 | |
Theodore Ts'o | 3d43836 | 2008-02-19 08:32:58 -0500 | [diff] [blame] | 985 | meg = (1024 * 1024) / EXT2_BLOCK_SIZE(fs_param); |
| 986 | if (fs_param->s_blocks_count < 3 * meg) |
| 987 | size_type = "floppy"; |
| 988 | else if (fs_param->s_blocks_count < 512 * meg) |
| 989 | size_type = "small"; |
| 990 | else |
| 991 | size_type = "default"; |
| 992 | |
| 993 | if (!usage_types) |
| 994 | usage_types = size_type; |
| 995 | |
| 996 | parse_str = malloc(usage_types ? strlen(usage_types)+1 : 1); |
| 997 | if (!parse_str) { |
| 998 | free(list.list); |
| 999 | return 0; |
| 1000 | } |
| 1001 | if (usage_types) |
| 1002 | strcpy(parse_str, usage_types); |
| 1003 | else |
| 1004 | *parse_str = '\0'; |
| 1005 | |
| 1006 | if (ext_type) |
| 1007 | push_string(&list, ext_type); |
| 1008 | cp = parse_str; |
| 1009 | while (1) { |
| 1010 | t = strchr(cp, ','); |
| 1011 | if (t) |
| 1012 | *t = '\0'; |
| 1013 | |
| 1014 | if (*cp) |
| 1015 | push_string(&list, cp); |
| 1016 | if (t) |
| 1017 | cp = t+1; |
| 1018 | else { |
| 1019 | cp = ""; |
| 1020 | break; |
| 1021 | } |
| 1022 | } |
| 1023 | free(parse_str); |
| 1024 | if (profile_type) |
| 1025 | free(profile_type); |
Theodore Ts'o | 7f5601e | 2008-07-10 09:24:25 -0400 | [diff] [blame] | 1026 | if (is_hurd) |
| 1027 | push_string(&list, "hurd"); |
Theodore Ts'o | 3d43836 | 2008-02-19 08:32:58 -0500 | [diff] [blame] | 1028 | return (list.list); |
| 1029 | } |
| 1030 | |
| 1031 | static char *get_string_from_profile(char **fs_types, const char *opt, |
| 1032 | const char *def_val) |
| 1033 | { |
| 1034 | char *ret = 0; |
Theodore Ts'o | 3d43836 | 2008-02-19 08:32:58 -0500 | [diff] [blame] | 1035 | int i; |
| 1036 | |
| 1037 | for (i=0; fs_types[i]; i++); |
| 1038 | for (i-=1; i >=0 ; i--) { |
| 1039 | profile_get_string(profile, "fs_types", fs_types[i], |
| 1040 | opt, 0, &ret); |
| 1041 | if (ret) |
| 1042 | return ret; |
| 1043 | } |
| 1044 | profile_get_string(profile, "defaults", opt, 0, def_val, &ret); |
| 1045 | return (ret); |
| 1046 | } |
| 1047 | |
| 1048 | static int get_int_from_profile(char **fs_types, const char *opt, int def_val) |
| 1049 | { |
| 1050 | int ret; |
| 1051 | char **cpp; |
| 1052 | |
| 1053 | profile_get_integer(profile, "defaults", opt, 0, def_val, &ret); |
| 1054 | for (cpp = fs_types; *cpp; cpp++) |
| 1055 | profile_get_integer(profile, "fs_types", *cpp, opt, ret, &ret); |
| 1056 | return ret; |
| 1057 | } |
| 1058 | |
Theodore Ts'o | a4396e9 | 2008-04-18 10:19:27 -0400 | [diff] [blame] | 1059 | static int get_bool_from_profile(char **fs_types, const char *opt, int def_val) |
| 1060 | { |
| 1061 | int ret; |
| 1062 | char **cpp; |
| 1063 | |
| 1064 | profile_get_boolean(profile, "defaults", opt, 0, def_val, &ret); |
| 1065 | for (cpp = fs_types; *cpp; cpp++) |
| 1066 | profile_get_boolean(profile, "fs_types", *cpp, opt, ret, &ret); |
| 1067 | return ret; |
| 1068 | } |
Theodore Ts'o | 3d43836 | 2008-02-19 08:32:58 -0500 | [diff] [blame] | 1069 | |
Theodore Ts'o | d48bc60 | 2007-07-04 14:10:46 -0400 | [diff] [blame] | 1070 | extern const char *mke2fs_default_profile; |
| 1071 | static const char *default_files[] = { "<default>", 0 }; |
| 1072 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1073 | static void PRS(int argc, char *argv[]) |
| 1074 | { |
Theodore Ts'o | c5290fa | 2003-04-11 22:10:50 -0400 | [diff] [blame] | 1075 | int b, c; |
Theodore Ts'o | 4a60056 | 1999-10-26 14:35:51 +0000 | [diff] [blame] | 1076 | int size; |
Eric Sandeen | 79e6240 | 2008-07-06 18:36:56 -0400 | [diff] [blame] | 1077 | char *tmp, **cpp; |
Theodore Ts'o | 4a60056 | 1999-10-26 14:35:51 +0000 | [diff] [blame] | 1078 | int blocksize = 0; |
| 1079 | int inode_ratio = 0; |
Andreas Dilger | 932a489 | 2002-05-16 03:20:07 -0600 | [diff] [blame] | 1080 | int inode_size = 0; |
Theodore Ts'o | 9ba4000 | 2008-04-22 08:27:01 -0400 | [diff] [blame] | 1081 | unsigned long flex_bg_size = 0; |
Andreas Dilger | ce91114 | 2005-07-06 11:50:08 -0500 | [diff] [blame] | 1082 | double reserved_ratio = 5.0; |
Theodore Ts'o | 93d5c38 | 2003-05-21 17:28:29 -0400 | [diff] [blame] | 1083 | int sector_size = 0; |
Theodore Ts'o | 1e6e4c5 | 2003-12-07 02:28:24 -0500 | [diff] [blame] | 1084 | int show_version_only = 0; |
Andreas Dilger | de8f3a7 | 2007-05-25 11:18:11 -0400 | [diff] [blame] | 1085 | unsigned long long num_inodes = 0; /* unsigned long long to catch too-large input */ |
Theodore Ts'o | a418d3a | 1997-04-26 14:00:26 +0000 | [diff] [blame] | 1086 | errcode_t retval; |
Theodore Ts'o | 4a60056 | 1999-10-26 14:35:51 +0000 | [diff] [blame] | 1087 | char * oldpath = getenv("PATH"); |
Theodore Ts'o | c6a4413 | 2005-01-05 11:12:20 -0500 | [diff] [blame] | 1088 | char * extended_opts = 0; |
Theodore Ts'o | 4ea7bd0 | 2001-12-16 23:23:37 -0500 | [diff] [blame] | 1089 | const char * fs_type = 0; |
Theodore Ts'o | 3d43836 | 2008-02-19 08:32:58 -0500 | [diff] [blame] | 1090 | const char * usage_types = 0; |
Theodore Ts'o | 4a60056 | 1999-10-26 14:35:51 +0000 | [diff] [blame] | 1091 | blk_t dev_size; |
Theodore Ts'o | 756df35 | 2002-03-07 20:52:12 -0500 | [diff] [blame] | 1092 | #ifdef __linux__ |
Theodore Ts'o | 4a60056 | 1999-10-26 14:35:51 +0000 | [diff] [blame] | 1093 | struct utsname ut; |
Theodore Ts'o | 2740156 | 1999-09-14 20:11:19 +0000 | [diff] [blame] | 1094 | #endif |
Theodore Ts'o | 31e29a1 | 2002-05-17 10:53:07 -0400 | [diff] [blame] | 1095 | long sysval; |
Theodore Ts'o | 9dc6ad1 | 2006-03-23 22:00:01 -0500 | [diff] [blame] | 1096 | int s_opt = -1, r_opt = -1; |
| 1097 | char *fs_features = 0; |
| 1098 | int use_bsize; |
Theodore Ts'o | 642935c | 2006-11-14 23:38:17 -0500 | [diff] [blame] | 1099 | char *newpath; |
| 1100 | int pathlen = sizeof(PATH_SET) + 1; |
| 1101 | |
| 1102 | if (oldpath) |
| 1103 | pathlen += strlen(oldpath); |
| 1104 | newpath = malloc(pathlen); |
| 1105 | strcpy(newpath, PATH_SET); |
Theodore Ts'o | 14bbcbc | 2001-05-13 22:58:27 +0000 | [diff] [blame] | 1106 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1107 | /* Update our PATH to include /sbin */ |
Theodore Ts'o | a418d3a | 1997-04-26 14:00:26 +0000 | [diff] [blame] | 1108 | if (oldpath) { |
Theodore Ts'o | a418d3a | 1997-04-26 14:00:26 +0000 | [diff] [blame] | 1109 | strcat (newpath, ":"); |
| 1110 | strcat (newpath, oldpath); |
Theodore Ts'o | 642935c | 2006-11-14 23:38:17 -0500 | [diff] [blame] | 1111 | } |
| 1112 | putenv (newpath); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1113 | |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 1114 | tmp = getenv("MKE2FS_SYNC"); |
| 1115 | if (tmp) |
| 1116 | sync_kludge = atoi(tmp); |
Theodore Ts'o | 31e29a1 | 2002-05-17 10:53:07 -0400 | [diff] [blame] | 1117 | |
| 1118 | /* Determine the system page size if possible */ |
| 1119 | #ifdef HAVE_SYSCONF |
| 1120 | #if (!defined(_SC_PAGESIZE) && defined(_SC_PAGE_SIZE)) |
| 1121 | #define _SC_PAGESIZE _SC_PAGE_SIZE |
| 1122 | #endif |
| 1123 | #ifdef _SC_PAGESIZE |
| 1124 | sysval = sysconf(_SC_PAGESIZE); |
Andreas Dilger | aab6fe7 | 2002-05-18 13:27:33 -0600 | [diff] [blame] | 1125 | if (sysval > 0) |
Theodore Ts'o | 31e29a1 | 2002-05-17 10:53:07 -0400 | [diff] [blame] | 1126 | sys_page_size = sysval; |
| 1127 | #endif /* _SC_PAGESIZE */ |
| 1128 | #endif /* HAVE_SYSCONF */ |
Theodore Ts'o | 9dc6ad1 | 2006-03-23 22:00:01 -0500 | [diff] [blame] | 1129 | |
| 1130 | if ((tmp = getenv("MKE2FS_CONFIG")) != NULL) |
| 1131 | config_fn[0] = tmp; |
| 1132 | profile_set_syntax_err_cb(syntax_err_report); |
Theodore Ts'o | d48bc60 | 2007-07-04 14:10:46 -0400 | [diff] [blame] | 1133 | retval = profile_init(config_fn, &profile); |
| 1134 | if (retval == ENOENT) { |
| 1135 | profile_init(default_files, &profile); |
| 1136 | profile_set_default(profile, mke2fs_default_profile); |
| 1137 | } |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 1138 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1139 | setbuf(stdout, NULL); |
| 1140 | setbuf(stderr, NULL); |
Theodore Ts'o | a6d8302 | 2006-12-26 03:38:07 -0500 | [diff] [blame] | 1141 | add_error_table(&et_ext2_error_table); |
| 1142 | add_error_table(&et_prof_error_table); |
Theodore Ts'o | 9b9a780 | 2005-12-10 21:50:30 -0500 | [diff] [blame] | 1143 | memset(&fs_param, 0, sizeof(struct ext2_super_block)); |
| 1144 | fs_param.s_rev_level = 1; /* Create revision 1 filesystems now */ |
Theodore Ts'o | 843049c | 2002-09-22 15:37:40 -0400 | [diff] [blame] | 1145 | |
Theodore Ts'o | 756df35 | 2002-03-07 20:52:12 -0500 | [diff] [blame] | 1146 | #ifdef __linux__ |
Theodore Ts'o | 14bbcbc | 2001-05-13 22:58:27 +0000 | [diff] [blame] | 1147 | if (uname(&ut)) { |
| 1148 | perror("uname"); |
| 1149 | exit(1); |
| 1150 | } |
Theodore Ts'o | d99225e | 2004-09-25 07:40:12 -0400 | [diff] [blame] | 1151 | linux_version_code = parse_version_number(ut.release); |
Theodore Ts'o | 9dc6ad1 | 2006-03-23 22:00:01 -0500 | [diff] [blame] | 1152 | if (linux_version_code && linux_version_code < (2*65536 + 2*256)) |
Theodore Ts'o | 9b9a780 | 2005-12-10 21:50:30 -0500 | [diff] [blame] | 1153 | fs_param.s_rev_level = 0; |
Theodore Ts'o | 14bbcbc | 2001-05-13 22:58:27 +0000 | [diff] [blame] | 1154 | #endif |
Andreas Dilger | 0072f8d | 2002-02-25 23:11:26 -0700 | [diff] [blame] | 1155 | |
| 1156 | if (argc && *argv) { |
| 1157 | program_name = get_progname(*argv); |
| 1158 | |
| 1159 | /* If called as mkfs.ext3, create a journal inode */ |
| 1160 | if (!strcmp(program_name, "mkfs.ext3")) |
| 1161 | journal_size = -1; |
| 1162 | } |
| 1163 | |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 1164 | while ((c = getopt (argc, argv, |
Theodore Ts'o | 9ba4000 | 2008-04-22 08:27:01 -0400 | [diff] [blame] | 1165 | "b:cf:g:G:i:jl:m:no:qr:s:t:vE:FI:J:L:M:N:O:R:ST:V")) != EOF) { |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1166 | switch (c) { |
| 1167 | case 'b': |
Theodore Ts'o | c5290fa | 2003-04-11 22:10:50 -0400 | [diff] [blame] | 1168 | blocksize = strtol(optarg, &tmp, 0); |
| 1169 | b = (blocksize > 0) ? blocksize : -blocksize; |
| 1170 | if (b < EXT2_MIN_BLOCK_SIZE || |
| 1171 | b > EXT2_MAX_BLOCK_SIZE || *tmp) { |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 1172 | com_err(program_name, 0, |
Theodore Ts'o | f37ab68 | 2005-05-05 23:15:55 -0400 | [diff] [blame] | 1173 | _("invalid block size - %s"), optarg); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1174 | exit(1); |
| 1175 | } |
Andreas Dilger | 932a489 | 2002-05-16 03:20:07 -0600 | [diff] [blame] | 1176 | if (blocksize > 4096) |
| 1177 | fprintf(stderr, _("Warning: blocksize %d not " |
| 1178 | "usable on most systems.\n"), |
| 1179 | blocksize); |
Theodore Ts'o | c5290fa | 2003-04-11 22:10:50 -0400 | [diff] [blame] | 1180 | if (blocksize > 0) |
Theodore Ts'o | 9b9a780 | 2005-12-10 21:50:30 -0500 | [diff] [blame] | 1181 | fs_param.s_log_block_size = |
Theodore Ts'o | c5290fa | 2003-04-11 22:10:50 -0400 | [diff] [blame] | 1182 | int_log2(blocksize >> |
| 1183 | EXT2_MIN_BLOCK_LOG_SIZE); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1184 | break; |
Theodore Ts'o | b10fd5e | 2001-04-22 03:47:23 +0000 | [diff] [blame] | 1185 | case 'c': /* Check for bad blocks */ |
Theodore Ts'o | 3ed57c2 | 2001-12-24 15:01:59 -0500 | [diff] [blame] | 1186 | cflag++; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1187 | break; |
| 1188 | case 'f': |
| 1189 | size = strtoul(optarg, &tmp, 0); |
Andreas Dilger | 932a489 | 2002-05-16 03:20:07 -0600 | [diff] [blame] | 1190 | if (size < EXT2_MIN_BLOCK_SIZE || |
| 1191 | size > EXT2_MAX_BLOCK_SIZE || *tmp) { |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 1192 | com_err(program_name, 0, |
Theodore Ts'o | bb145b0 | 2005-06-20 08:35:27 -0400 | [diff] [blame] | 1193 | _("invalid fragment size - %s"), |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1194 | optarg); |
| 1195 | exit(1); |
| 1196 | } |
Theodore Ts'o | 9b9a780 | 2005-12-10 21:50:30 -0500 | [diff] [blame] | 1197 | fs_param.s_log_frag_size = |
Theodore Ts'o | 6733c2f | 1999-11-23 02:23:30 +0000 | [diff] [blame] | 1198 | int_log2(size >> EXT2_MIN_BLOCK_LOG_SIZE); |
Theodore Ts'o | 6693837 | 2002-03-08 00:14:46 -0500 | [diff] [blame] | 1199 | fprintf(stderr, _("Warning: fragments not supported. " |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 1200 | "Ignoring -f option\n")); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1201 | break; |
| 1202 | case 'g': |
Theodore Ts'o | 9b9a780 | 2005-12-10 21:50:30 -0500 | [diff] [blame] | 1203 | fs_param.s_blocks_per_group = strtoul(optarg, &tmp, 0); |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 1204 | if (*tmp) { |
| 1205 | com_err(program_name, 0, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 1206 | _("Illegal number for blocks per group")); |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 1207 | exit(1); |
| 1208 | } |
Theodore Ts'o | 9b9a780 | 2005-12-10 21:50:30 -0500 | [diff] [blame] | 1209 | if ((fs_param.s_blocks_per_group % 8) != 0) { |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 1210 | com_err(program_name, 0, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 1211 | _("blocks per group must be multiple of 8")); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1212 | exit(1); |
| 1213 | } |
| 1214 | break; |
Theodore Ts'o | 9ba4000 | 2008-04-22 08:27:01 -0400 | [diff] [blame] | 1215 | case 'G': |
| 1216 | flex_bg_size = strtoul(optarg, &tmp, 0); |
| 1217 | if (*tmp) { |
| 1218 | com_err(program_name, 0, |
| 1219 | _("Illegal number for flex_bg size")); |
| 1220 | exit(1); |
| 1221 | } |
| 1222 | if (flex_bg_size < 2 || |
| 1223 | (flex_bg_size & (flex_bg_size-1)) != 0) { |
| 1224 | com_err(program_name, 0, |
| 1225 | _("flex_bg size must be a power of 2")); |
| 1226 | exit(1); |
| 1227 | } |
| 1228 | break; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1229 | case 'i': |
| 1230 | inode_ratio = strtoul(optarg, &tmp, 0); |
Andreas Dilger | 932a489 | 2002-05-16 03:20:07 -0600 | [diff] [blame] | 1231 | if (inode_ratio < EXT2_MIN_BLOCK_SIZE || |
| 1232 | inode_ratio > EXT2_MAX_BLOCK_SIZE * 1024 || |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1233 | *tmp) { |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 1234 | com_err(program_name, 0, |
Theodore Ts'o | bb145b0 | 2005-06-20 08:35:27 -0400 | [diff] [blame] | 1235 | _("invalid inode ratio %s (min %d/max %d)"), |
Andreas Dilger | 932a489 | 2002-05-16 03:20:07 -0600 | [diff] [blame] | 1236 | optarg, EXT2_MIN_BLOCK_SIZE, |
| 1237 | EXT2_MAX_BLOCK_SIZE); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1238 | exit(1); |
| 1239 | } |
| 1240 | break; |
Theodore Ts'o | dc2ec52 | 2001-01-18 01:51:15 +0000 | [diff] [blame] | 1241 | case 'J': |
| 1242 | parse_journal_opts(optarg); |
| 1243 | break; |
Theodore Ts'o | 85ef4ae | 2000-10-24 19:33:45 +0000 | [diff] [blame] | 1244 | case 'j': |
Theodore Ts'o | dc2ec52 | 2001-01-18 01:51:15 +0000 | [diff] [blame] | 1245 | if (!journal_size) |
| 1246 | journal_size = -1; |
Theodore Ts'o | 8ddaa66 | 2000-11-17 04:55:24 +0000 | [diff] [blame] | 1247 | break; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1248 | case 'l': |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 1249 | bad_blocks_filename = malloc(strlen(optarg)+1); |
| 1250 | if (!bad_blocks_filename) { |
| 1251 | com_err(program_name, ENOMEM, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 1252 | _("in malloc for bad_blocks_filename")); |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 1253 | exit(1); |
| 1254 | } |
| 1255 | strcpy(bad_blocks_filename, optarg); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1256 | break; |
| 1257 | case 'm': |
Andreas Dilger | ce91114 | 2005-07-06 11:50:08 -0500 | [diff] [blame] | 1258 | reserved_ratio = strtod(optarg, &tmp); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1259 | if (reserved_ratio > 50 || *tmp) { |
| 1260 | com_err(program_name, 0, |
Theodore Ts'o | bb145b0 | 2005-06-20 08:35:27 -0400 | [diff] [blame] | 1261 | _("invalid reserved blocks percent - %s"), |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1262 | optarg); |
| 1263 | exit(1); |
| 1264 | } |
| 1265 | break; |
Theodore Ts'o | 50787ea | 1999-07-19 15:30:21 +0000 | [diff] [blame] | 1266 | case 'n': |
| 1267 | noaction++; |
| 1268 | break; |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 1269 | case 'o': |
| 1270 | creator_os = optarg; |
| 1271 | break; |
Andreas Dilger | 2524785 | 2005-07-06 12:58:15 -0500 | [diff] [blame] | 1272 | case 'q': |
| 1273 | quiet = 1; |
| 1274 | break; |
Theodore Ts'o | 7f88b04 | 1997-04-26 14:48:50 +0000 | [diff] [blame] | 1275 | case 'r': |
Theodore Ts'o | 9dc6ad1 | 2006-03-23 22:00:01 -0500 | [diff] [blame] | 1276 | r_opt = strtoul(optarg, &tmp, 0); |
Andreas Dilger | 2524785 | 2005-07-06 12:58:15 -0500 | [diff] [blame] | 1277 | if (*tmp) { |
| 1278 | com_err(program_name, 0, |
| 1279 | _("bad revision level - %s"), optarg); |
| 1280 | exit(1); |
| 1281 | } |
Theodore Ts'o | 9dc6ad1 | 2006-03-23 22:00:01 -0500 | [diff] [blame] | 1282 | fs_param.s_rev_level = r_opt; |
Theodore Ts'o | 7f88b04 | 1997-04-26 14:48:50 +0000 | [diff] [blame] | 1283 | break; |
Theodore Ts'o | b10fd5e | 2001-04-22 03:47:23 +0000 | [diff] [blame] | 1284 | case 's': /* deprecated */ |
Theodore Ts'o | 9dc6ad1 | 2006-03-23 22:00:01 -0500 | [diff] [blame] | 1285 | s_opt = atoi(optarg); |
Theodore Ts'o | 521e368 | 1997-04-29 17:48:10 +0000 | [diff] [blame] | 1286 | break; |
Theodore Ts'o | 7f88b04 | 1997-04-26 14:48:50 +0000 | [diff] [blame] | 1287 | case 'I': |
Andreas Dilger | 932a489 | 2002-05-16 03:20:07 -0600 | [diff] [blame] | 1288 | inode_size = strtoul(optarg, &tmp, 0); |
| 1289 | if (*tmp) { |
| 1290 | com_err(program_name, 0, |
Theodore Ts'o | bb145b0 | 2005-06-20 08:35:27 -0400 | [diff] [blame] | 1291 | _("invalid inode size - %s"), optarg); |
Andreas Dilger | 932a489 | 2002-05-16 03:20:07 -0600 | [diff] [blame] | 1292 | exit(1); |
| 1293 | } |
Theodore Ts'o | 7f88b04 | 1997-04-26 14:48:50 +0000 | [diff] [blame] | 1294 | break; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1295 | case 'v': |
| 1296 | verbose = 1; |
| 1297 | break; |
Theodore Ts'o | 74becf3 | 1997-04-26 14:37:06 +0000 | [diff] [blame] | 1298 | case 'F': |
Andreas Dilger | c16e610 | 2006-08-05 19:05:53 -0400 | [diff] [blame] | 1299 | force++; |
Theodore Ts'o | 74becf3 | 1997-04-26 14:37:06 +0000 | [diff] [blame] | 1300 | break; |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 1301 | case 'L': |
| 1302 | volume_label = optarg; |
| 1303 | break; |
| 1304 | case 'M': |
| 1305 | mount_dir = optarg; |
| 1306 | break; |
Andreas Dilger | 2524785 | 2005-07-06 12:58:15 -0500 | [diff] [blame] | 1307 | case 'N': |
| 1308 | num_inodes = strtoul(optarg, &tmp, 0); |
| 1309 | if (*tmp) { |
| 1310 | com_err(program_name, 0, |
| 1311 | _("bad num inodes - %s"), optarg); |
| 1312 | exit(1); |
| 1313 | } |
| 1314 | break; |
Theodore Ts'o | 896938d | 1999-10-23 01:04:50 +0000 | [diff] [blame] | 1315 | case 'O': |
Theodore Ts'o | 9dc6ad1 | 2006-03-23 22:00:01 -0500 | [diff] [blame] | 1316 | fs_features = optarg; |
Theodore Ts'o | 896938d | 1999-10-23 01:04:50 +0000 | [diff] [blame] | 1317 | break; |
Theodore Ts'o | c6a4413 | 2005-01-05 11:12:20 -0500 | [diff] [blame] | 1318 | case 'E': |
Theodore Ts'o | a29f4d3 | 1997-04-29 21:26:48 +0000 | [diff] [blame] | 1319 | case 'R': |
Theodore Ts'o | c6a4413 | 2005-01-05 11:12:20 -0500 | [diff] [blame] | 1320 | extended_opts = optarg; |
Theodore Ts'o | a29f4d3 | 1997-04-29 21:26:48 +0000 | [diff] [blame] | 1321 | break; |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 1322 | case 'S': |
| 1323 | super_only = 1; |
| 1324 | break; |
Theodore Ts'o | 3d43836 | 2008-02-19 08:32:58 -0500 | [diff] [blame] | 1325 | case 't': |
Theodore Ts'o | 50787ea | 1999-07-19 15:30:21 +0000 | [diff] [blame] | 1326 | fs_type = optarg; |
| 1327 | break; |
Theodore Ts'o | 3d43836 | 2008-02-19 08:32:58 -0500 | [diff] [blame] | 1328 | case 'T': |
| 1329 | usage_types = optarg; |
| 1330 | break; |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 1331 | case 'V': |
| 1332 | /* Print version number and exit */ |
Theodore Ts'o | 1e6e4c5 | 2003-12-07 02:28:24 -0500 | [diff] [blame] | 1333 | show_version_only++; |
| 1334 | break; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1335 | default: |
| 1336 | usage(); |
| 1337 | } |
Theodore Ts'o | 55f4cbd | 2005-01-05 03:01:06 -0500 | [diff] [blame] | 1338 | } |
Theodore Ts'o | 1e6e4c5 | 2003-12-07 02:28:24 -0500 | [diff] [blame] | 1339 | if ((optind == argc) && !show_version_only) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1340 | usage(); |
Theodore Ts'o | 55f4cbd | 2005-01-05 03:01:06 -0500 | [diff] [blame] | 1341 | device_name = argv[optind++]; |
Theodore Ts'o | a418d3a | 1997-04-26 14:00:26 +0000 | [diff] [blame] | 1342 | |
Theodore Ts'o | 1e6e4c5 | 2003-12-07 02:28:24 -0500 | [diff] [blame] | 1343 | if (!quiet || show_version_only) |
Theodore Ts'o | 3879857 | 2003-04-16 15:29:39 -0400 | [diff] [blame] | 1344 | fprintf (stderr, "mke2fs %s (%s)\n", E2FSPROGS_VERSION, |
| 1345 | E2FSPROGS_DATE); |
| 1346 | |
Theodore Ts'o | 1e6e4c5 | 2003-12-07 02:28:24 -0500 | [diff] [blame] | 1347 | if (show_version_only) { |
| 1348 | fprintf(stderr, _("\tUsing %s\n"), |
| 1349 | error_message(EXT2_ET_BASE)); |
| 1350 | exit(0); |
| 1351 | } |
| 1352 | |
Theodore Ts'o | 77dc4eb | 2001-07-27 22:00:18 -0400 | [diff] [blame] | 1353 | /* |
| 1354 | * If there's no blocksize specified and there is a journal |
| 1355 | * device, use it to figure out the blocksize |
| 1356 | */ |
Theodore Ts'o | c5290fa | 2003-04-11 22:10:50 -0400 | [diff] [blame] | 1357 | if (blocksize <= 0 && journal_device) { |
Theodore Ts'o | 77dc4eb | 2001-07-27 22:00:18 -0400 | [diff] [blame] | 1358 | ext2_filsys jfs; |
Theodore Ts'o | a7ccdff | 2003-07-08 18:03:48 -0400 | [diff] [blame] | 1359 | io_manager io_ptr; |
Theodore Ts'o | 77dc4eb | 2001-07-27 22:00:18 -0400 | [diff] [blame] | 1360 | |
Theodore Ts'o | a7ccdff | 2003-07-08 18:03:48 -0400 | [diff] [blame] | 1361 | #ifdef CONFIG_TESTIO_DEBUG |
| 1362 | io_ptr = test_io_manager; |
| 1363 | test_io_backing_manager = unix_io_manager; |
| 1364 | #else |
| 1365 | io_ptr = unix_io_manager; |
| 1366 | #endif |
Theodore Ts'o | 77dc4eb | 2001-07-27 22:00:18 -0400 | [diff] [blame] | 1367 | retval = ext2fs_open(journal_device, |
| 1368 | EXT2_FLAG_JOURNAL_DEV_OK, 0, |
Theodore Ts'o | a7ccdff | 2003-07-08 18:03:48 -0400 | [diff] [blame] | 1369 | 0, io_ptr, &jfs); |
Theodore Ts'o | 77dc4eb | 2001-07-27 22:00:18 -0400 | [diff] [blame] | 1370 | if (retval) { |
| 1371 | com_err(program_name, retval, |
| 1372 | _("while trying to open journal device %s\n"), |
| 1373 | journal_device); |
| 1374 | exit(1); |
| 1375 | } |
Theodore Ts'o | 5443492 | 2003-12-07 01:28:50 -0500 | [diff] [blame] | 1376 | if ((blocksize < 0) && (jfs->blocksize < (unsigned) (-blocksize))) { |
Theodore Ts'o | c5290fa | 2003-04-11 22:10:50 -0400 | [diff] [blame] | 1377 | com_err(program_name, 0, |
Theodore Ts'o | ddc32a0 | 2003-05-03 18:45:55 -0400 | [diff] [blame] | 1378 | _("Journal dev blocksize (%d) smaller than " |
Theodore Ts'o | c5290fa | 2003-04-11 22:10:50 -0400 | [diff] [blame] | 1379 | "minimum blocksize %d\n"), jfs->blocksize, |
| 1380 | -blocksize); |
| 1381 | exit(1); |
| 1382 | } |
Theodore Ts'o | 77dc4eb | 2001-07-27 22:00:18 -0400 | [diff] [blame] | 1383 | blocksize = jfs->blocksize; |
Theodore Ts'o | f8df04b | 2008-07-06 20:57:17 -0400 | [diff] [blame] | 1384 | printf(_("Using journal device's blocksize: %d\n"), blocksize); |
Theodore Ts'o | 9b9a780 | 2005-12-10 21:50:30 -0500 | [diff] [blame] | 1385 | fs_param.s_log_block_size = |
Theodore Ts'o | 77dc4eb | 2001-07-27 22:00:18 -0400 | [diff] [blame] | 1386 | int_log2(blocksize >> EXT2_MIN_BLOCK_LOG_SIZE); |
| 1387 | ext2fs_close(jfs); |
| 1388 | } |
Theodore Ts'o | dc2ec52 | 2001-01-18 01:51:15 +0000 | [diff] [blame] | 1389 | |
Theodore Ts'o | 31e29a1 | 2002-05-17 10:53:07 -0400 | [diff] [blame] | 1390 | if (blocksize > sys_page_size) { |
Andreas Dilger | 932a489 | 2002-05-16 03:20:07 -0600 | [diff] [blame] | 1391 | if (!force) { |
| 1392 | com_err(program_name, 0, |
| 1393 | _("%d-byte blocks too big for system (max %d)"), |
Theodore Ts'o | 31e29a1 | 2002-05-17 10:53:07 -0400 | [diff] [blame] | 1394 | blocksize, sys_page_size); |
Andreas Dilger | 932a489 | 2002-05-16 03:20:07 -0600 | [diff] [blame] | 1395 | proceed_question(); |
| 1396 | } |
| 1397 | fprintf(stderr, _("Warning: %d-byte blocks too big for system " |
| 1398 | "(max %d), forced to continue\n"), |
Theodore Ts'o | 31e29a1 | 2002-05-17 10:53:07 -0400 | [diff] [blame] | 1399 | blocksize, sys_page_size); |
Andreas Dilger | 932a489 | 2002-05-16 03:20:07 -0600 | [diff] [blame] | 1400 | } |
Theodore Ts'o | 55f4cbd | 2005-01-05 03:01:06 -0500 | [diff] [blame] | 1401 | if (optind < argc) { |
Theodore Ts'o | 9b9a780 | 2005-12-10 21:50:30 -0500 | [diff] [blame] | 1402 | fs_param.s_blocks_count = parse_num_blocks(argv[optind++], |
| 1403 | fs_param.s_log_block_size); |
| 1404 | if (!fs_param.s_blocks_count) { |
Theodore Ts'o | f37ab68 | 2005-05-05 23:15:55 -0400 | [diff] [blame] | 1405 | com_err(program_name, 0, _("invalid blocks count - %s"), |
Theodore Ts'o | 55f4cbd | 2005-01-05 03:01:06 -0500 | [diff] [blame] | 1406 | argv[optind - 1]); |
| 1407 | exit(1); |
| 1408 | } |
| 1409 | } |
| 1410 | if (optind < argc) |
| 1411 | usage(); |
| 1412 | |
Theodore Ts'o | 74becf3 | 1997-04-26 14:37:06 +0000 | [diff] [blame] | 1413 | if (!force) |
Theodore Ts'o | 8ddaa66 | 2000-11-17 04:55:24 +0000 | [diff] [blame] | 1414 | check_plausibility(device_name); |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 1415 | check_mount(device_name, force, _("filesystem")); |
Theodore Ts'o | a418d3a | 1997-04-26 14:00:26 +0000 | [diff] [blame] | 1416 | |
Theodore Ts'o | 9b9a780 | 2005-12-10 21:50:30 -0500 | [diff] [blame] | 1417 | fs_param.s_log_frag_size = fs_param.s_log_block_size; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1418 | |
Theodore Ts'o | 9b9a780 | 2005-12-10 21:50:30 -0500 | [diff] [blame] | 1419 | if (noaction && fs_param.s_blocks_count) { |
| 1420 | dev_size = fs_param.s_blocks_count; |
Theodore Ts'o | 50787ea | 1999-07-19 15:30:21 +0000 | [diff] [blame] | 1421 | retval = 0; |
Theodore Ts'o | 2095312 | 2005-01-27 19:07:26 -0500 | [diff] [blame] | 1422 | } else { |
| 1423 | retry: |
Theodore Ts'o | 50787ea | 1999-07-19 15:30:21 +0000 | [diff] [blame] | 1424 | retval = ext2fs_get_device_size(device_name, |
Theodore Ts'o | 9b9a780 | 2005-12-10 21:50:30 -0500 | [diff] [blame] | 1425 | EXT2_BLOCK_SIZE(&fs_param), |
Theodore Ts'o | 50787ea | 1999-07-19 15:30:21 +0000 | [diff] [blame] | 1426 | &dev_size); |
Theodore Ts'o | 2095312 | 2005-01-27 19:07:26 -0500 | [diff] [blame] | 1427 | if ((retval == EFBIG) && |
| 1428 | (blocksize == 0) && |
Theodore Ts'o | 9b9a780 | 2005-12-10 21:50:30 -0500 | [diff] [blame] | 1429 | (fs_param.s_log_block_size == 0)) { |
| 1430 | fs_param.s_log_block_size = 2; |
Theodore Ts'o | 2095312 | 2005-01-27 19:07:26 -0500 | [diff] [blame] | 1431 | blocksize = 4096; |
| 1432 | goto retry; |
| 1433 | } |
| 1434 | } |
| 1435 | |
Theodore Ts'o | f8df04b | 2008-07-06 20:57:17 -0400 | [diff] [blame] | 1436 | if (retval == EFBIG) { |
| 1437 | fprintf(stderr, _("%s: Size of device %s too big " |
| 1438 | "to be expressed in 32 bits\n\t" |
| 1439 | "using a blocksize of %d.\n"), |
| 1440 | program_name, device_name, EXT2_BLOCK_SIZE(&fs_param)); |
| 1441 | exit(1); |
| 1442 | } |
Theodore Ts'o | a789d84 | 1998-03-30 01:20:55 +0000 | [diff] [blame] | 1443 | if (retval && (retval != EXT2_ET_UNIMPLEMENTED)) { |
| 1444 | com_err(program_name, retval, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 1445 | _("while trying to determine filesystem size")); |
Theodore Ts'o | a789d84 | 1998-03-30 01:20:55 +0000 | [diff] [blame] | 1446 | exit(1); |
| 1447 | } |
Theodore Ts'o | 9b9a780 | 2005-12-10 21:50:30 -0500 | [diff] [blame] | 1448 | if (!fs_param.s_blocks_count) { |
Theodore Ts'o | a789d84 | 1998-03-30 01:20:55 +0000 | [diff] [blame] | 1449 | if (retval == EXT2_ET_UNIMPLEMENTED) { |
| 1450 | com_err(program_name, 0, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 1451 | _("Couldn't determine device size; you " |
Theodore Ts'o | a789d84 | 1998-03-30 01:20:55 +0000 | [diff] [blame] | 1452 | "must specify\nthe size of the " |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 1453 | "filesystem\n")); |
Theodore Ts'o | a418d3a | 1997-04-26 14:00:26 +0000 | [diff] [blame] | 1454 | exit(1); |
Theodore Ts'o | 26ab531 | 2000-05-29 15:05:42 +0000 | [diff] [blame] | 1455 | } else { |
| 1456 | if (dev_size == 0) { |
| 1457 | com_err(program_name, 0, |
| 1458 | _("Device size reported to be zero. " |
| 1459 | "Invalid partition specified, or\n\t" |
| 1460 | "partition table wasn't reread " |
| 1461 | "after running fdisk, due to\n\t" |
| 1462 | "a modified partition being busy " |
| 1463 | "and in use. You may need to reboot\n\t" |
| 1464 | "to re-read your partition table.\n" |
| 1465 | )); |
| 1466 | exit(1); |
| 1467 | } |
Theodore Ts'o | 9b9a780 | 2005-12-10 21:50:30 -0500 | [diff] [blame] | 1468 | fs_param.s_blocks_count = dev_size; |
| 1469 | if (sys_page_size > EXT2_BLOCK_SIZE(&fs_param)) |
| 1470 | fs_param.s_blocks_count &= ~((sys_page_size / |
| 1471 | EXT2_BLOCK_SIZE(&fs_param))-1); |
Theodore Ts'o | 26ab531 | 2000-05-29 15:05:42 +0000 | [diff] [blame] | 1472 | } |
| 1473 | |
Theodore Ts'o | 9b9a780 | 2005-12-10 21:50:30 -0500 | [diff] [blame] | 1474 | } else if (!force && (fs_param.s_blocks_count > dev_size)) { |
Theodore Ts'o | a789d84 | 1998-03-30 01:20:55 +0000 | [diff] [blame] | 1475 | com_err(program_name, 0, |
Theodore Ts'o | c5290fa | 2003-04-11 22:10:50 -0400 | [diff] [blame] | 1476 | _("Filesystem larger than apparent device size.")); |
Theodore Ts'o | a789d84 | 1998-03-30 01:20:55 +0000 | [diff] [blame] | 1477 | proceed_question(); |
Theodore Ts'o | a418d3a | 1997-04-26 14:00:26 +0000 | [diff] [blame] | 1478 | } |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1479 | |
Theodore Ts'o | 3d43836 | 2008-02-19 08:32:58 -0500 | [diff] [blame] | 1480 | fs_types = parse_fs_type(fs_type, usage_types, &fs_param, argv[0]); |
| 1481 | if (!fs_types) { |
| 1482 | fprintf(stderr, _("Failed to parse fs types list\n")); |
| 1483 | exit(1); |
| 1484 | } |
Theodore Ts'o | 9dc6ad1 | 2006-03-23 22:00:01 -0500 | [diff] [blame] | 1485 | |
| 1486 | /* Figure out what features should be enabled */ |
| 1487 | |
Theodore Ts'o | 3d43836 | 2008-02-19 08:32:58 -0500 | [diff] [blame] | 1488 | tmp = NULL; |
Theodore Ts'o | b290d2d | 2006-10-18 00:31:11 -0400 | [diff] [blame] | 1489 | if (fs_param.s_rev_level != EXT2_GOOD_OLD_REV) { |
Theodore Ts'o | 3d43836 | 2008-02-19 08:32:58 -0500 | [diff] [blame] | 1490 | tmp = get_string_from_profile(fs_types, "base_features", |
| 1491 | "sparse_super,filetype,resize_inode,dir_index"); |
| 1492 | edit_feature(tmp, &fs_param.s_feature_compat); |
| 1493 | free(tmp); |
| 1494 | |
| 1495 | for (cpp = fs_types; *cpp; cpp++) { |
| 1496 | tmp = NULL; |
| 1497 | profile_get_string(profile, "fs_types", *cpp, |
| 1498 | "features", "", &tmp); |
| 1499 | if (tmp && *tmp) |
| 1500 | edit_feature(tmp, &fs_param.s_feature_compat); |
| 1501 | if (tmp) |
| 1502 | free(tmp); |
| 1503 | } |
| 1504 | tmp = get_string_from_profile(fs_types, "default_features", |
| 1505 | ""); |
Theodore Ts'o | b290d2d | 2006-10-18 00:31:11 -0400 | [diff] [blame] | 1506 | } |
Theodore Ts'o | 3d43836 | 2008-02-19 08:32:58 -0500 | [diff] [blame] | 1507 | edit_feature(fs_features ? fs_features : tmp, |
Theodore Ts'o | b290d2d | 2006-10-18 00:31:11 -0400 | [diff] [blame] | 1508 | &fs_param.s_feature_compat); |
| 1509 | if (tmp) |
| 1510 | free(tmp); |
Theodore Ts'o | b290d2d | 2006-10-18 00:31:11 -0400 | [diff] [blame] | 1511 | |
Theodore Ts'o | b4d5105 | 2008-07-06 20:24:29 -0400 | [diff] [blame] | 1512 | if (fs_param.s_feature_incompat & EXT3_FEATURE_INCOMPAT_JOURNAL_DEV) { |
| 1513 | fs_types[0] = strdup("journal"); |
| 1514 | fs_types[1] = 0; |
| 1515 | } |
| 1516 | |
| 1517 | if (verbose) { |
| 1518 | fputs(_("fs_types for mke2fs.conf resolution: "), stdout); |
| 1519 | print_str_list(fs_types); |
| 1520 | } |
| 1521 | |
Theodore Ts'o | b290d2d | 2006-10-18 00:31:11 -0400 | [diff] [blame] | 1522 | if (r_opt == EXT2_GOOD_OLD_REV && |
| 1523 | (fs_param.s_feature_compat || fs_param.s_feature_incompat || |
Theodore Ts'o | 92fb854 | 2008-07-18 21:08:56 -0400 | [diff] [blame] | 1524 | fs_param.s_feature_ro_compat)) { |
Theodore Ts'o | 9dc6ad1 | 2006-03-23 22:00:01 -0500 | [diff] [blame] | 1525 | fprintf(stderr, _("Filesystem features not supported " |
| 1526 | "with revision 0 filesystems\n")); |
| 1527 | exit(1); |
| 1528 | } |
| 1529 | |
Theodore Ts'o | b290d2d | 2006-10-18 00:31:11 -0400 | [diff] [blame] | 1530 | if (s_opt > 0) { |
| 1531 | if (r_opt == EXT2_GOOD_OLD_REV) { |
| 1532 | fprintf(stderr, _("Sparse superblocks not supported " |
| 1533 | "with revision 0 filesystems\n")); |
| 1534 | exit(1); |
| 1535 | } |
Theodore Ts'o | 9dc6ad1 | 2006-03-23 22:00:01 -0500 | [diff] [blame] | 1536 | fs_param.s_feature_ro_compat |= |
| 1537 | EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER; |
Theodore Ts'o | b290d2d | 2006-10-18 00:31:11 -0400 | [diff] [blame] | 1538 | } else if (s_opt == 0) |
Theodore Ts'o | 9dc6ad1 | 2006-03-23 22:00:01 -0500 | [diff] [blame] | 1539 | fs_param.s_feature_ro_compat &= |
| 1540 | ~EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER; |
| 1541 | |
Theodore Ts'o | b290d2d | 2006-10-18 00:31:11 -0400 | [diff] [blame] | 1542 | if (journal_size != 0) { |
| 1543 | if (r_opt == EXT2_GOOD_OLD_REV) { |
| 1544 | fprintf(stderr, _("Journals not supported " |
| 1545 | "with revision 0 filesystems\n")); |
| 1546 | exit(1); |
| 1547 | } |
Theodore Ts'o | 9dc6ad1 | 2006-03-23 22:00:01 -0500 | [diff] [blame] | 1548 | fs_param.s_feature_compat |= |
| 1549 | EXT3_FEATURE_COMPAT_HAS_JOURNAL; |
Theodore Ts'o | b290d2d | 2006-10-18 00:31:11 -0400 | [diff] [blame] | 1550 | } |
Theodore Ts'o | 9dc6ad1 | 2006-03-23 22:00:01 -0500 | [diff] [blame] | 1551 | |
| 1552 | if (fs_param.s_feature_incompat & |
| 1553 | EXT3_FEATURE_INCOMPAT_JOURNAL_DEV) { |
Theodore Ts'o | 9dc6ad1 | 2006-03-23 22:00:01 -0500 | [diff] [blame] | 1554 | reserved_ratio = 0; |
| 1555 | fs_param.s_feature_incompat = EXT3_FEATURE_INCOMPAT_JOURNAL_DEV; |
| 1556 | fs_param.s_feature_compat = 0; |
| 1557 | fs_param.s_feature_ro_compat = 0; |
| 1558 | } |
Theodore Ts'o | d94cc2e | 2008-04-27 00:08:14 -0400 | [diff] [blame] | 1559 | |
| 1560 | if ((fs_param.s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG) && |
| 1561 | (fs_param.s_feature_compat & EXT2_FEATURE_COMPAT_RESIZE_INODE)) { |
| 1562 | fprintf(stderr, _("The resize_inode and meta_bg features " |
| 1563 | "are not compatible.\n" |
| 1564 | "They can not be both enabled " |
| 1565 | "simultaneously.\n")); |
| 1566 | exit(1); |
| 1567 | } |
| 1568 | |
Theodore Ts'o | c046ac7 | 2002-10-20 00:38:57 -0400 | [diff] [blame] | 1569 | /* Set first meta blockgroup via an environment variable */ |
| 1570 | /* (this is mostly for debugging purposes) */ |
Theodore Ts'o | 9b9a780 | 2005-12-10 21:50:30 -0500 | [diff] [blame] | 1571 | if ((fs_param.s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG) && |
Theodore Ts'o | c046ac7 | 2002-10-20 00:38:57 -0400 | [diff] [blame] | 1572 | ((tmp = getenv("MKE2FS_FIRST_META_BG")))) |
Theodore Ts'o | 9b9a780 | 2005-12-10 21:50:30 -0500 | [diff] [blame] | 1573 | fs_param.s_first_meta_bg = atoi(tmp); |
Theodore Ts'o | c046ac7 | 2002-10-20 00:38:57 -0400 | [diff] [blame] | 1574 | |
Theodore Ts'o | 93d5c38 | 2003-05-21 17:28:29 -0400 | [diff] [blame] | 1575 | /* Get the hardware sector size, if available */ |
| 1576 | retval = ext2fs_get_device_sectsize(device_name, §or_size); |
| 1577 | if (retval) { |
| 1578 | com_err(program_name, retval, |
| 1579 | _("while trying to determine hardware sector size")); |
| 1580 | exit(1); |
| 1581 | } |
Theodore Ts'o | 1cca86f | 2003-09-01 09:28:18 -0400 | [diff] [blame] | 1582 | |
Theodore Ts'o | 5443492 | 2003-12-07 01:28:50 -0500 | [diff] [blame] | 1583 | if ((tmp = getenv("MKE2FS_DEVICE_SECTSIZE")) != NULL) |
Theodore Ts'o | 1cca86f | 2003-09-01 09:28:18 -0400 | [diff] [blame] | 1584 | sector_size = atoi(tmp); |
Theodore Ts'o | 93d5c38 | 2003-05-21 17:28:29 -0400 | [diff] [blame] | 1585 | |
Theodore Ts'o | 9dc6ad1 | 2006-03-23 22:00:01 -0500 | [diff] [blame] | 1586 | if (blocksize <= 0) { |
Theodore Ts'o | 3d43836 | 2008-02-19 08:32:58 -0500 | [diff] [blame] | 1587 | use_bsize = get_int_from_profile(fs_types, "blocksize", 4096); |
Theodore Ts'o | 9dc6ad1 | 2006-03-23 22:00:01 -0500 | [diff] [blame] | 1588 | |
| 1589 | if (use_bsize == -1) { |
| 1590 | use_bsize = sys_page_size; |
| 1591 | if ((linux_version_code < (2*65536 + 6*256)) && |
| 1592 | (use_bsize > 4096)) |
| 1593 | use_bsize = 4096; |
| 1594 | } |
| 1595 | if (sector_size && use_bsize < sector_size) |
| 1596 | use_bsize = sector_size; |
| 1597 | if ((blocksize < 0) && (use_bsize < (-blocksize))) |
| 1598 | use_bsize = -blocksize; |
| 1599 | blocksize = use_bsize; |
| 1600 | fs_param.s_blocks_count /= blocksize / 1024; |
| 1601 | } |
| 1602 | |
| 1603 | if (inode_ratio == 0) { |
Theodore Ts'o | 3d43836 | 2008-02-19 08:32:58 -0500 | [diff] [blame] | 1604 | inode_ratio = get_int_from_profile(fs_types, "inode_ratio", |
| 1605 | 8192); |
Theodore Ts'o | 9dc6ad1 | 2006-03-23 22:00:01 -0500 | [diff] [blame] | 1606 | if (inode_ratio < blocksize) |
| 1607 | inode_ratio = blocksize; |
| 1608 | } |
| 1609 | |
| 1610 | fs_param.s_log_frag_size = fs_param.s_log_block_size = |
| 1611 | int_log2(blocksize >> EXT2_MIN_BLOCK_LOG_SIZE); |
| 1612 | |
Theodore Ts'o | 9b9a780 | 2005-12-10 21:50:30 -0500 | [diff] [blame] | 1613 | blocksize = EXT2_BLOCK_SIZE(&fs_param); |
Theodore Ts'o | a4396e9 | 2008-04-18 10:19:27 -0400 | [diff] [blame] | 1614 | |
| 1615 | lazy_itable_init = get_bool_from_profile(fs_types, |
| 1616 | "lazy_itable_init", 0); |
Theodore Ts'o | c5290fa | 2003-04-11 22:10:50 -0400 | [diff] [blame] | 1617 | |
Theodore Ts'o | 2d36358 | 2008-05-14 18:09:37 -0400 | [diff] [blame] | 1618 | /* Get options from profile */ |
| 1619 | for (cpp = fs_types; *cpp; cpp++) { |
| 1620 | tmp = NULL; |
| 1621 | profile_get_string(profile, "fs_types", *cpp, "options", "", &tmp); |
| 1622 | if (tmp && *tmp) |
| 1623 | parse_extended_opts(&fs_param, tmp); |
| 1624 | if (tmp) |
| 1625 | free(tmp); |
| 1626 | } |
| 1627 | |
Theodore Ts'o | c6a4413 | 2005-01-05 11:12:20 -0500 | [diff] [blame] | 1628 | if (extended_opts) |
Theodore Ts'o | 9b9a780 | 2005-12-10 21:50:30 -0500 | [diff] [blame] | 1629 | parse_extended_opts(&fs_param, extended_opts); |
Theodore Ts'o | d323f8f | 2004-12-15 14:39:16 -0500 | [diff] [blame] | 1630 | |
| 1631 | /* Since sparse_super is the default, we would only have a problem |
| 1632 | * here if it was explicitly disabled. |
| 1633 | */ |
Theodore Ts'o | 9b9a780 | 2005-12-10 21:50:30 -0500 | [diff] [blame] | 1634 | if ((fs_param.s_feature_compat & EXT2_FEATURE_COMPAT_RESIZE_INODE) && |
| 1635 | !(fs_param.s_feature_ro_compat&EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER)) { |
Theodore Ts'o | d323f8f | 2004-12-15 14:39:16 -0500 | [diff] [blame] | 1636 | com_err(program_name, 0, |
| 1637 | _("reserved online resize blocks not supported " |
| 1638 | "on non-sparse filesystem")); |
| 1639 | exit(1); |
| 1640 | } |
| 1641 | |
Theodore Ts'o | 9b9a780 | 2005-12-10 21:50:30 -0500 | [diff] [blame] | 1642 | if (fs_param.s_blocks_per_group) { |
| 1643 | if (fs_param.s_blocks_per_group < 256 || |
| 1644 | fs_param.s_blocks_per_group > 8 * (unsigned) blocksize) { |
Theodore Ts'o | 521e368 | 1997-04-29 17:48:10 +0000 | [diff] [blame] | 1645 | com_err(program_name, 0, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 1646 | _("blocks per group count out of range")); |
Theodore Ts'o | 521e368 | 1997-04-29 17:48:10 +0000 | [diff] [blame] | 1647 | exit(1); |
| 1648 | } |
| 1649 | } |
| 1650 | |
Theodore Ts'o | 3d43836 | 2008-02-19 08:32:58 -0500 | [diff] [blame] | 1651 | if (inode_size == 0) |
| 1652 | inode_size = get_int_from_profile(fs_types, "inode_size", 0); |
Theodore Ts'o | 9ba4000 | 2008-04-22 08:27:01 -0400 | [diff] [blame] | 1653 | if (!flex_bg_size && (fs_param.s_feature_incompat & |
| 1654 | EXT4_FEATURE_INCOMPAT_FLEX_BG)) |
| 1655 | flex_bg_size = get_int_from_profile(fs_types, |
| 1656 | "flex_bg_size", 16); |
| 1657 | if (flex_bg_size) { |
| 1658 | if (!(fs_param.s_feature_incompat & |
| 1659 | EXT4_FEATURE_INCOMPAT_FLEX_BG)) { |
| 1660 | com_err(program_name, 0, |
| 1661 | _("Flex_bg feature not enabled, so " |
| 1662 | "flex_bg size may not be specified")); |
| 1663 | exit(1); |
| 1664 | } |
| 1665 | fs_param.s_log_groups_per_flex = int_log2(flex_bg_size); |
| 1666 | } |
Andreas Dilger | 067911a | 2006-07-15 22:08:20 -0400 | [diff] [blame] | 1667 | |
| 1668 | if (inode_size && fs_param.s_rev_level >= EXT2_DYNAMIC_REV) { |
Andreas Dilger | 932a489 | 2002-05-16 03:20:07 -0600 | [diff] [blame] | 1669 | if (inode_size < EXT2_GOOD_OLD_INODE_SIZE || |
Theodore Ts'o | 9b9a780 | 2005-12-10 21:50:30 -0500 | [diff] [blame] | 1670 | inode_size > EXT2_BLOCK_SIZE(&fs_param) || |
Andreas Dilger | 932a489 | 2002-05-16 03:20:07 -0600 | [diff] [blame] | 1671 | inode_size & (inode_size - 1)) { |
| 1672 | com_err(program_name, 0, |
Theodore Ts'o | bb145b0 | 2005-06-20 08:35:27 -0400 | [diff] [blame] | 1673 | _("invalid inode size %d (min %d/max %d)"), |
Andreas Dilger | 932a489 | 2002-05-16 03:20:07 -0600 | [diff] [blame] | 1674 | inode_size, EXT2_GOOD_OLD_INODE_SIZE, |
Theodore Ts'o | c5290fa | 2003-04-11 22:10:50 -0400 | [diff] [blame] | 1675 | blocksize); |
Andreas Dilger | 932a489 | 2002-05-16 03:20:07 -0600 | [diff] [blame] | 1676 | exit(1); |
| 1677 | } |
Theodore Ts'o | 9b9a780 | 2005-12-10 21:50:30 -0500 | [diff] [blame] | 1678 | fs_param.s_inode_size = inode_size; |
Andreas Dilger | 932a489 | 2002-05-16 03:20:07 -0600 | [diff] [blame] | 1679 | } |
| 1680 | |
Eric Sandeen | f335864 | 2006-09-12 14:56:17 -0400 | [diff] [blame] | 1681 | /* Make sure number of inodes specified will fit in 32 bits */ |
| 1682 | if (num_inodes == 0) { |
Andreas Dilger | de8f3a7 | 2007-05-25 11:18:11 -0400 | [diff] [blame] | 1683 | unsigned long long n; |
| 1684 | n = (unsigned long long) fs_param.s_blocks_count * blocksize / inode_ratio; |
Eric Sandeen | f335864 | 2006-09-12 14:56:17 -0400 | [diff] [blame] | 1685 | if (n > ~0U) { |
| 1686 | com_err(program_name, 0, |
| 1687 | _("too many inodes (%llu), raise inode ratio?"), n); |
| 1688 | exit(1); |
| 1689 | } |
| 1690 | } else if (num_inodes > ~0U) { |
| 1691 | com_err(program_name, 0, |
| 1692 | _("too many inodes (%llu), specify < 2^32 inodes"), |
Andreas Dilger | de8f3a7 | 2007-05-25 11:18:11 -0400 | [diff] [blame] | 1693 | num_inodes); |
Eric Sandeen | f335864 | 2006-09-12 14:56:17 -0400 | [diff] [blame] | 1694 | exit(1); |
| 1695 | } |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1696 | /* |
| 1697 | * Calculate number of inodes based on the inode ratio |
| 1698 | */ |
Theodore Ts'o | 9b9a780 | 2005-12-10 21:50:30 -0500 | [diff] [blame] | 1699 | fs_param.s_inodes_count = num_inodes ? num_inodes : |
| 1700 | ((__u64) fs_param.s_blocks_count * blocksize) |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 1701 | / inode_ratio; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1702 | |
Andreas Dilger | dcf7b09 | 2007-05-22 16:04:51 -0400 | [diff] [blame] | 1703 | if ((((long long)fs_param.s_inodes_count) * |
| 1704 | (inode_size ? inode_size : EXT2_GOOD_OLD_INODE_SIZE)) >= |
| 1705 | (((long long)fs_param.s_blocks_count) * |
| 1706 | EXT2_BLOCK_SIZE(&fs_param))) { |
| 1707 | com_err(program_name, 0, _("inode_size (%u) * inodes_count " |
| 1708 | "(%u) too big for a\n\t" |
| 1709 | "filesystem with %lu blocks, " |
| 1710 | "specify higher inode_ratio (-i)\n\t" |
| 1711 | "or lower inode count (-N).\n"), |
| 1712 | inode_size ? inode_size : EXT2_GOOD_OLD_INODE_SIZE, |
Andreas Dilger | de8f3a7 | 2007-05-25 11:18:11 -0400 | [diff] [blame] | 1713 | fs_param.s_inodes_count, |
| 1714 | (unsigned long) fs_param.s_blocks_count); |
Andreas Dilger | dcf7b09 | 2007-05-22 16:04:51 -0400 | [diff] [blame] | 1715 | exit(1); |
| 1716 | } |
| 1717 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1718 | /* |
| 1719 | * Calculate number of blocks to reserve |
| 1720 | */ |
Theodore Ts'o | 9ff8ece | 2008-06-17 19:58:29 -0400 | [diff] [blame] | 1721 | fs_param.s_r_blocks_count = (unsigned int) (reserved_ratio * |
| 1722 | fs_param.s_blocks_count / 100.0); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1723 | } |
Theodore Ts'o | d323f8f | 2004-12-15 14:39:16 -0500 | [diff] [blame] | 1724 | |
Aneesh Kumar K.V | b626b39 | 2007-08-13 15:56:26 +0530 | [diff] [blame] | 1725 | static int should_do_undo(const char *name) |
| 1726 | { |
| 1727 | errcode_t retval; |
| 1728 | io_channel channel; |
| 1729 | __u16 s_magic; |
| 1730 | struct ext2_super_block super; |
| 1731 | io_manager manager = unix_io_manager; |
| 1732 | int csum_flag, force_undo; |
| 1733 | |
| 1734 | csum_flag = EXT2_HAS_RO_COMPAT_FEATURE(&fs_param, |
| 1735 | EXT4_FEATURE_RO_COMPAT_GDT_CSUM); |
| 1736 | force_undo = get_int_from_profile(fs_types, "force_undo", 0); |
| 1737 | if (!force_undo && (!csum_flag || !lazy_itable_init)) |
| 1738 | return 0; |
| 1739 | |
| 1740 | retval = manager->open(name, IO_FLAG_EXCLUSIVE, &channel); |
| 1741 | if (retval) { |
| 1742 | /* |
| 1743 | * We don't handle error cases instead we |
| 1744 | * declare that the file system doesn't exist |
| 1745 | * and let the rest of mke2fs take care of |
| 1746 | * error |
| 1747 | */ |
| 1748 | retval = 0; |
| 1749 | goto open_err_out; |
| 1750 | } |
| 1751 | |
| 1752 | io_channel_set_blksize(channel, SUPERBLOCK_OFFSET); |
| 1753 | retval = io_channel_read_blk(channel, 1, -SUPERBLOCK_SIZE, &super); |
| 1754 | if (retval) { |
| 1755 | retval = 0; |
| 1756 | goto err_out; |
| 1757 | } |
| 1758 | |
| 1759 | #if defined(WORDS_BIGENDIAN) |
| 1760 | s_magic = ext2fs_swab16(super.s_magic); |
| 1761 | #else |
| 1762 | s_magic = super.s_magic; |
| 1763 | #endif |
| 1764 | |
| 1765 | if (s_magic == EXT2_SUPER_MAGIC) |
| 1766 | retval = 1; |
| 1767 | |
| 1768 | err_out: |
| 1769 | io_channel_close(channel); |
| 1770 | |
| 1771 | open_err_out: |
| 1772 | |
| 1773 | return retval; |
| 1774 | } |
| 1775 | |
| 1776 | static int mke2fs_setup_tdb(const char *name, io_manager *io_ptr) |
| 1777 | { |
| 1778 | errcode_t retval = 0; |
| 1779 | char *tdb_dir, tdb_file[PATH_MAX]; |
| 1780 | char *device_name, *tmp_name; |
| 1781 | |
| 1782 | /* |
| 1783 | * Configuration via a conf file would be |
| 1784 | * nice |
| 1785 | */ |
| 1786 | tdb_dir = getenv("E2FSPROGS_UNDO_DIR"); |
| 1787 | if (!tdb_dir) |
| 1788 | profile_get_string(profile, "defaults", |
| 1789 | "undo_dir", 0, "/var/lib/e2fsprogs", |
| 1790 | &tdb_dir); |
| 1791 | |
| 1792 | if (!strcmp(tdb_dir, "none") || (tdb_dir[0] == 0) || |
| 1793 | access(tdb_dir, W_OK)) |
| 1794 | return 0; |
| 1795 | |
| 1796 | tmp_name = strdup(name); |
| 1797 | device_name = basename(tmp_name); |
| 1798 | sprintf(tdb_file, "%s/mke2fs-%s.e2undo", tdb_dir, device_name); |
| 1799 | |
| 1800 | if (!access(tdb_file, F_OK)) { |
| 1801 | if (unlink(tdb_file) < 0) { |
| 1802 | retval = errno; |
| 1803 | com_err(program_name, retval, |
| 1804 | _("while trying to delete %s"), |
| 1805 | tdb_file); |
| 1806 | return retval; |
| 1807 | } |
| 1808 | } |
| 1809 | |
| 1810 | set_undo_io_backing_manager(*io_ptr); |
| 1811 | *io_ptr = undo_io_manager; |
| 1812 | set_undo_io_backup_file(tdb_file); |
| 1813 | printf(_("Overwriting existing filesystem; this can be undone " |
| 1814 | "using the command:\n" |
| 1815 | " e2undo %s %s\n\n"), tdb_file, name); |
Eric Sandeen | 79e6240 | 2008-07-06 18:36:56 -0400 | [diff] [blame] | 1816 | |
Aneesh Kumar K.V | b626b39 | 2007-08-13 15:56:26 +0530 | [diff] [blame] | 1817 | free(tmp_name); |
| 1818 | return retval; |
| 1819 | } |
| 1820 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1821 | int main (int argc, char *argv[]) |
| 1822 | { |
| 1823 | errcode_t retval = 0; |
| 1824 | ext2_filsys fs; |
| 1825 | badblocks_list bb_list = 0; |
Theodore Ts'o | d4e0b1c | 2007-08-03 18:56:01 -0400 | [diff] [blame] | 1826 | unsigned int journal_blocks; |
Theodore Ts'o | 5443492 | 2003-12-07 01:28:50 -0500 | [diff] [blame] | 1827 | unsigned int i; |
| 1828 | int val; |
Theodore Ts'o | a7ccdff | 2003-07-08 18:03:48 -0400 | [diff] [blame] | 1829 | io_manager io_ptr; |
Aneesh Kumar K.V | b626b39 | 2007-08-13 15:56:26 +0530 | [diff] [blame] | 1830 | char tdb_string[40]; |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 1831 | |
| 1832 | #ifdef ENABLE_NLS |
| 1833 | setlocale(LC_MESSAGES, ""); |
Theodore Ts'o | 14308a5 | 2002-03-05 03:26:52 -0500 | [diff] [blame] | 1834 | setlocale(LC_CTYPE, ""); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 1835 | bindtextdomain(NLS_CAT_NAME, LOCALEDIR); |
| 1836 | textdomain(NLS_CAT_NAME); |
| 1837 | #endif |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1838 | PRS(argc, argv); |
| 1839 | |
Theodore Ts'o | a7ccdff | 2003-07-08 18:03:48 -0400 | [diff] [blame] | 1840 | #ifdef CONFIG_TESTIO_DEBUG |
| 1841 | io_ptr = test_io_manager; |
| 1842 | test_io_backing_manager = unix_io_manager; |
| 1843 | #else |
| 1844 | io_ptr = unix_io_manager; |
| 1845 | #endif |
| 1846 | |
Aneesh Kumar K.V | b626b39 | 2007-08-13 15:56:26 +0530 | [diff] [blame] | 1847 | if (should_do_undo(device_name)) { |
| 1848 | retval = mke2fs_setup_tdb(device_name, &io_ptr); |
| 1849 | if (retval) |
| 1850 | exit(1); |
| 1851 | } |
| 1852 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1853 | /* |
| 1854 | * Initialize the superblock.... |
| 1855 | */ |
Theodore Ts'o | 616059b | 2006-03-18 20:02:05 -0500 | [diff] [blame] | 1856 | retval = ext2fs_initialize(device_name, EXT2_FLAG_EXCLUSIVE, &fs_param, |
Theodore Ts'o | a7ccdff | 2003-07-08 18:03:48 -0400 | [diff] [blame] | 1857 | io_ptr, &fs); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1858 | if (retval) { |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 1859 | com_err(device_name, retval, _("while setting up superblock")); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1860 | exit(1); |
| 1861 | } |
Aneesh Kumar K.V | b626b39 | 2007-08-13 15:56:26 +0530 | [diff] [blame] | 1862 | sprintf(tdb_string, "tdb_data_size=%d", fs->blocksize <= 4096 ? |
| 1863 | 32768 : fs->blocksize * 8); |
| 1864 | io_channel_set_options(fs->io, tdb_string); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1865 | |
Theodore Ts'o | 6cb2740 | 2008-01-26 19:06:35 -0500 | [diff] [blame] | 1866 | if (fs_param.s_flags & EXT2_FLAGS_TEST_FILESYS) |
| 1867 | fs->super->s_flags |= EXT2_FLAGS_TEST_FILESYS; |
| 1868 | |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 1869 | /* |
Theodore Ts'o | e41784e | 2000-08-14 14:44:15 +0000 | [diff] [blame] | 1870 | * Wipe out the old on-disk superblock |
| 1871 | */ |
Theodore Ts'o | 04a9685 | 2001-08-30 21:55:26 -0400 | [diff] [blame] | 1872 | if (!noaction) |
| 1873 | zap_sector(fs, 2, 6); |
Theodore Ts'o | e41784e | 2000-08-14 14:44:15 +0000 | [diff] [blame] | 1874 | |
| 1875 | /* |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 1876 | * Generate a UUID for it... |
| 1877 | */ |
Theodore Ts'o | ef9abe5 | 2001-01-01 15:31:53 +0000 | [diff] [blame] | 1878 | uuid_generate(fs->super->s_uuid); |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 1879 | |
| 1880 | /* |
Theodore Ts'o | 843049c | 2002-09-22 15:37:40 -0400 | [diff] [blame] | 1881 | * Initialize the directory index variables |
| 1882 | */ |
| 1883 | fs->super->s_def_hash_version = EXT2_HASH_TEA; |
| 1884 | uuid_generate((unsigned char *) fs->super->s_hash_seed); |
| 1885 | |
| 1886 | /* |
Theodore Ts'o | 44c09c0 | 2001-01-14 17:02:09 +0000 | [diff] [blame] | 1887 | * Add "jitter" to the superblock's check interval so that we |
| 1888 | * don't check all the filesystems at the same time. We use a |
| 1889 | * kludgy hack of using the UUID to derive a random jitter value. |
| 1890 | */ |
| 1891 | for (i = 0, val = 0 ; i < sizeof(fs->super->s_uuid); i++) |
| 1892 | val += fs->super->s_uuid[i]; |
| 1893 | fs->super->s_max_mnt_count += val % EXT2_DFL_MAX_MNT_COUNT; |
| 1894 | |
| 1895 | /* |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 1896 | * Override the creator OS, if applicable |
| 1897 | */ |
| 1898 | if (creator_os && !set_os(fs->super, creator_os)) { |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 1899 | com_err (program_name, 0, _("unknown os - %s"), creator_os); |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 1900 | exit(1); |
| 1901 | } |
| 1902 | |
| 1903 | /* |
Theodore Ts'o | 4ea0a11 | 2000-05-08 13:33:17 +0000 | [diff] [blame] | 1904 | * For the Hurd, we will turn off filetype since it doesn't |
| 1905 | * support it. |
| 1906 | */ |
| 1907 | if (fs->super->s_creator_os == EXT2_OS_HURD) |
| 1908 | fs->super->s_feature_incompat &= |
| 1909 | ~EXT2_FEATURE_INCOMPAT_FILETYPE; |
| 1910 | |
| 1911 | /* |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 1912 | * Set the volume label... |
| 1913 | */ |
| 1914 | if (volume_label) { |
Theodore Ts'o | ef9abe5 | 2001-01-01 15:31:53 +0000 | [diff] [blame] | 1915 | memset(fs->super->s_volume_name, 0, |
| 1916 | sizeof(fs->super->s_volume_name)); |
| 1917 | strncpy(fs->super->s_volume_name, volume_label, |
| 1918 | sizeof(fs->super->s_volume_name)); |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 1919 | } |
| 1920 | |
| 1921 | /* |
| 1922 | * Set the last mount directory |
| 1923 | */ |
| 1924 | if (mount_dir) { |
Theodore Ts'o | ef9abe5 | 2001-01-01 15:31:53 +0000 | [diff] [blame] | 1925 | memset(fs->super->s_last_mounted, 0, |
| 1926 | sizeof(fs->super->s_last_mounted)); |
| 1927 | strncpy(fs->super->s_last_mounted, mount_dir, |
| 1928 | sizeof(fs->super->s_last_mounted)); |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 1929 | } |
| 1930 | |
Theodore Ts'o | 50787ea | 1999-07-19 15:30:21 +0000 | [diff] [blame] | 1931 | if (!quiet || noaction) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1932 | show_stats(fs); |
| 1933 | |
Theodore Ts'o | 50787ea | 1999-07-19 15:30:21 +0000 | [diff] [blame] | 1934 | if (noaction) |
| 1935 | exit(0); |
| 1936 | |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 1937 | if (fs->super->s_feature_incompat & |
| 1938 | EXT3_FEATURE_INCOMPAT_JOURNAL_DEV) { |
| 1939 | create_journal_dev(fs); |
Andreas Dilger | 568101f | 2001-10-13 01:22:25 -0600 | [diff] [blame] | 1940 | exit(ext2fs_close(fs) ? 1 : 0); |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 1941 | } |
| 1942 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1943 | if (bad_blocks_filename) |
| 1944 | read_bb_file(fs, &bb_list, bad_blocks_filename); |
| 1945 | if (cflag) |
| 1946 | test_disk(fs, &bb_list); |
| 1947 | |
| 1948 | handle_bad_blocks(fs, bb_list); |
Theodore Ts'o | 0c17cb2 | 2008-02-18 22:56:25 -0500 | [diff] [blame] | 1949 | fs->stride = fs_stride = fs->super->s_raid_stride; |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 1950 | retval = ext2fs_allocate_tables(fs); |
| 1951 | if (retval) { |
| 1952 | com_err(program_name, retval, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 1953 | _("while trying to allocate filesystem tables")); |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 1954 | exit(1); |
| 1955 | } |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 1956 | if (super_only) { |
| 1957 | fs->super->s_state |= EXT2_ERROR_FS; |
| 1958 | fs->flags &= ~(EXT2_FLAG_IB_DIRTY|EXT2_FLAG_BB_DIRTY); |
| 1959 | } else { |
Andreas Dilger | 59f2724 | 2001-08-30 15:39:04 -0600 | [diff] [blame] | 1960 | /* rsv must be a power of two (64kB is MD RAID sb alignment) */ |
Theodore Ts'o | 5443492 | 2003-12-07 01:28:50 -0500 | [diff] [blame] | 1961 | unsigned int rsv = 65536 / fs->blocksize; |
Theodore Ts'o | 1400bbb | 2001-05-14 04:19:25 +0000 | [diff] [blame] | 1962 | unsigned long blocks = fs->super->s_blocks_count; |
Andreas Dilger | 59f2724 | 2001-08-30 15:39:04 -0600 | [diff] [blame] | 1963 | unsigned long start; |
Theodore Ts'o | 1400bbb | 2001-05-14 04:19:25 +0000 | [diff] [blame] | 1964 | blk_t ret_blk; |
| 1965 | |
| 1966 | #ifdef ZAP_BOOTBLOCK |
Theodore Ts'o | 04a9685 | 2001-08-30 21:55:26 -0400 | [diff] [blame] | 1967 | zap_sector(fs, 0, 2); |
Theodore Ts'o | 1400bbb | 2001-05-14 04:19:25 +0000 | [diff] [blame] | 1968 | #endif |
Andreas Dilger | 59f2724 | 2001-08-30 15:39:04 -0600 | [diff] [blame] | 1969 | |
| 1970 | /* |
Theodore Ts'o | 1400bbb | 2001-05-14 04:19:25 +0000 | [diff] [blame] | 1971 | * Wipe out any old MD RAID (or other) metadata at the end |
| 1972 | * of the device. This will also verify that the device is |
Andreas Dilger | 59f2724 | 2001-08-30 15:39:04 -0600 | [diff] [blame] | 1973 | * as large as we think. Be careful with very small devices. |
Theodore Ts'o | 1400bbb | 2001-05-14 04:19:25 +0000 | [diff] [blame] | 1974 | */ |
Andreas Dilger | 59f2724 | 2001-08-30 15:39:04 -0600 | [diff] [blame] | 1975 | start = (blocks & ~(rsv - 1)); |
| 1976 | if (start > rsv) |
| 1977 | start -= rsv; |
| 1978 | if (start > 0) |
Aneesh Kumar K.V | b626b39 | 2007-08-13 15:56:26 +0530 | [diff] [blame] | 1979 | retval = ext2fs_zero_blocks(fs, start, blocks - start, |
| 1980 | &ret_blk, NULL); |
Andreas Dilger | 59f2724 | 2001-08-30 15:39:04 -0600 | [diff] [blame] | 1981 | |
Theodore Ts'o | 1400bbb | 2001-05-14 04:19:25 +0000 | [diff] [blame] | 1982 | if (retval) { |
| 1983 | com_err(program_name, retval, |
Theodore Ts'o | f044b4d | 2002-08-17 13:32:21 -0400 | [diff] [blame] | 1984 | _("while zeroing block %u at end of filesystem"), |
Theodore Ts'o | 1400bbb | 2001-05-14 04:19:25 +0000 | [diff] [blame] | 1985 | ret_blk); |
Theodore Ts'o | 1400bbb | 2001-05-14 04:19:25 +0000 | [diff] [blame] | 1986 | } |
Theodore Ts'o | a4396e9 | 2008-04-18 10:19:27 -0400 | [diff] [blame] | 1987 | write_inode_tables(fs, lazy_itable_init); |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 1988 | create_root_dir(fs); |
| 1989 | create_lost_and_found(fs); |
| 1990 | reserve_inodes(fs); |
| 1991 | create_bad_block_inode(fs, bb_list); |
Theodore Ts'o | ea77431 | 2005-01-28 11:45:28 -0500 | [diff] [blame] | 1992 | if (fs->super->s_feature_compat & |
| 1993 | EXT2_FEATURE_COMPAT_RESIZE_INODE) { |
| 1994 | retval = ext2fs_create_resize_inode(fs); |
| 1995 | if (retval) { |
| 1996 | com_err("ext2fs_create_resize_inode", retval, |
Theodore Ts'o | d323f8f | 2004-12-15 14:39:16 -0500 | [diff] [blame] | 1997 | _("while reserving blocks for online resize")); |
Theodore Ts'o | ea77431 | 2005-01-28 11:45:28 -0500 | [diff] [blame] | 1998 | exit(1); |
| 1999 | } |
Theodore Ts'o | d323f8f | 2004-12-15 14:39:16 -0500 | [diff] [blame] | 2000 | } |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 2001 | } |
Theodore Ts'o | 8ddaa66 | 2000-11-17 04:55:24 +0000 | [diff] [blame] | 2002 | |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 2003 | if (journal_device) { |
| 2004 | ext2_filsys jfs; |
| 2005 | |
Theodore Ts'o | 8ddaa66 | 2000-11-17 04:55:24 +0000 | [diff] [blame] | 2006 | if (!force) |
| 2007 | check_plausibility(journal_device); |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 2008 | check_mount(journal_device, force, _("journal")); |
Theodore Ts'o | 8ddaa66 | 2000-11-17 04:55:24 +0000 | [diff] [blame] | 2009 | |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 2010 | retval = ext2fs_open(journal_device, EXT2_FLAG_RW| |
| 2011 | EXT2_FLAG_JOURNAL_DEV_OK, 0, |
| 2012 | fs->blocksize, unix_io_manager, &jfs); |
| 2013 | if (retval) { |
| 2014 | com_err(program_name, retval, |
| 2015 | _("while trying to open journal device %s\n"), |
| 2016 | journal_device); |
| 2017 | exit(1); |
| 2018 | } |
Theodore Ts'o | 93345d1 | 2001-02-17 06:09:50 +0000 | [diff] [blame] | 2019 | if (!quiet) { |
Theodore Ts'o | 77dc4eb | 2001-07-27 22:00:18 -0400 | [diff] [blame] | 2020 | printf(_("Adding journal to device %s: "), |
Theodore Ts'o | 8ddaa66 | 2000-11-17 04:55:24 +0000 | [diff] [blame] | 2021 | journal_device); |
Theodore Ts'o | 93345d1 | 2001-02-17 06:09:50 +0000 | [diff] [blame] | 2022 | fflush(stdout); |
| 2023 | } |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 2024 | retval = ext2fs_add_journal_device(fs, jfs); |
| 2025 | if(retval) { |
Theodore Ts'o | 8ddaa66 | 2000-11-17 04:55:24 +0000 | [diff] [blame] | 2026 | com_err (program_name, retval, |
Theodore Ts'o | 1d08d9b | 2001-04-17 01:01:49 +0000 | [diff] [blame] | 2027 | _("\n\twhile trying to add journal to device %s"), |
Theodore Ts'o | 8ddaa66 | 2000-11-17 04:55:24 +0000 | [diff] [blame] | 2028 | journal_device); |
| 2029 | exit(1); |
| 2030 | } |
| 2031 | if (!quiet) |
| 2032 | printf(_("done\n")); |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 2033 | ext2fs_close(jfs); |
Andreas Dilger | 2d15576 | 2001-08-17 03:48:11 -0600 | [diff] [blame] | 2034 | free(journal_device); |
Theodore Ts'o | 9dc6ad1 | 2006-03-23 22:00:01 -0500 | [diff] [blame] | 2035 | } else if ((journal_size) || |
| 2036 | (fs_param.s_feature_compat & |
| 2037 | EXT3_FEATURE_COMPAT_HAS_JOURNAL)) { |
Theodore Ts'o | 2537b6d | 2001-03-26 20:07:13 +0000 | [diff] [blame] | 2038 | journal_blocks = figure_journal_size(journal_size, fs); |
Theodore Ts'o | 93345d1 | 2001-02-17 06:09:50 +0000 | [diff] [blame] | 2039 | |
| 2040 | if (!journal_blocks) { |
| 2041 | fs->super->s_feature_compat &= |
| 2042 | ~EXT3_FEATURE_COMPAT_HAS_JOURNAL; |
| 2043 | goto no_journal; |
| 2044 | } |
| 2045 | if (!quiet) { |
Theodore Ts'o | d4e0b1c | 2007-08-03 18:56:01 -0400 | [diff] [blame] | 2046 | printf(_("Creating journal (%u blocks): "), |
Theodore Ts'o | 16ad333 | 2000-12-31 03:21:56 +0000 | [diff] [blame] | 2047 | journal_blocks); |
Theodore Ts'o | 93345d1 | 2001-02-17 06:09:50 +0000 | [diff] [blame] | 2048 | fflush(stdout); |
| 2049 | } |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 2050 | retval = ext2fs_add_journal_inode(fs, journal_blocks, |
| 2051 | journal_flags); |
Theodore Ts'o | 85ef4ae | 2000-10-24 19:33:45 +0000 | [diff] [blame] | 2052 | if (retval) { |
| 2053 | com_err (program_name, retval, |
Theodore Ts'o | 1d08d9b | 2001-04-17 01:01:49 +0000 | [diff] [blame] | 2054 | _("\n\twhile trying to create journal")); |
Theodore Ts'o | 85ef4ae | 2000-10-24 19:33:45 +0000 | [diff] [blame] | 2055 | exit(1); |
| 2056 | } |
| 2057 | if (!quiet) |
| 2058 | printf(_("done\n")); |
| 2059 | } |
Theodore Ts'o | 93345d1 | 2001-02-17 06:09:50 +0000 | [diff] [blame] | 2060 | no_journal: |
| 2061 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 2062 | if (!quiet) |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 2063 | printf(_("Writing superblocks and " |
| 2064 | "filesystem accounting information: ")); |
Theodore Ts'o | 5d45d80 | 1999-03-16 19:35:19 +0000 | [diff] [blame] | 2065 | retval = ext2fs_flush(fs); |
| 2066 | if (retval) { |
Theodore Ts'o | 6693837 | 2002-03-08 00:14:46 -0500 | [diff] [blame] | 2067 | fprintf(stderr, |
| 2068 | _("\nWarning, had trouble writing out superblocks.")); |
Theodore Ts'o | 5d45d80 | 1999-03-16 19:35:19 +0000 | [diff] [blame] | 2069 | } |
Theodore Ts'o | 93345d1 | 2001-02-17 06:09:50 +0000 | [diff] [blame] | 2070 | if (!quiet) { |
Theodore Ts'o | 2537b6d | 2001-03-26 20:07:13 +0000 | [diff] [blame] | 2071 | printf(_("done\n\n")); |
Theodore Ts'o | 1cca86f | 2003-09-01 09:28:18 -0400 | [diff] [blame] | 2072 | if (!getenv("MKE2FS_SKIP_CHECK_MSG")) |
| 2073 | print_check_message(fs); |
Theodore Ts'o | 93345d1 | 2001-02-17 06:09:50 +0000 | [diff] [blame] | 2074 | } |
Andreas Dilger | 568101f | 2001-10-13 01:22:25 -0600 | [diff] [blame] | 2075 | val = ext2fs_close(fs); |
Theodore Ts'o | a6d8302 | 2006-12-26 03:38:07 -0500 | [diff] [blame] | 2076 | remove_error_table(&et_ext2_error_table); |
| 2077 | remove_error_table(&et_prof_error_table); |
Theodore Ts'o | 3d43836 | 2008-02-19 08:32:58 -0500 | [diff] [blame] | 2078 | profile_release(profile); |
Andreas Dilger | 568101f | 2001-10-13 01:22:25 -0600 | [diff] [blame] | 2079 | return (retval || val) ? 1 : 0; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 2080 | } |