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 | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 4 | * Copyright (C) 1994, 1995, 1996, 1997 Theodore Ts'o. |
| 5 | * |
| 6 | * %Begin-Header% |
| 7 | * This file may be redistributed under the terms of the GNU Public |
| 8 | * License. |
| 9 | * %End-Header% |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | /* Usage: mke2fs [options] device |
| 13 | * |
| 14 | * The device may be a block device or a image of one, but this isn't |
| 15 | * enforced (but it's not much fun on a character device :-). |
| 16 | */ |
| 17 | |
Theodore Ts'o | a418d3a | 1997-04-26 14:00:26 +0000 | [diff] [blame] | 18 | #include <stdio.h> |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 19 | #include <string.h> |
| 20 | #include <fcntl.h> |
| 21 | #include <ctype.h> |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 22 | #include <time.h> |
Theodore Ts'o | 756df35 | 2002-03-07 20:52:12 -0500 | [diff] [blame] | 23 | #ifdef __linux__ |
Theodore Ts'o | 2740156 | 1999-09-14 20:11:19 +0000 | [diff] [blame] | 24 | #include <sys/utsname.h> |
| 25 | #endif |
Theodore Ts'o | a418d3a | 1997-04-26 14:00:26 +0000 | [diff] [blame] | 26 | #ifdef HAVE_GETOPT_H |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 27 | #include <getopt.h> |
Theodore Ts'o | 373b833 | 2000-04-03 16:22:35 +0000 | [diff] [blame] | 28 | #else |
| 29 | extern char *optarg; |
| 30 | extern int optind; |
Theodore Ts'o | a418d3a | 1997-04-26 14:00:26 +0000 | [diff] [blame] | 31 | #endif |
| 32 | #ifdef HAVE_UNISTD_H |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 33 | #include <unistd.h> |
Theodore Ts'o | a418d3a | 1997-04-26 14:00:26 +0000 | [diff] [blame] | 34 | #endif |
| 35 | #ifdef HAVE_STDLIB_H |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 36 | #include <stdlib.h> |
Theodore Ts'o | a418d3a | 1997-04-26 14:00:26 +0000 | [diff] [blame] | 37 | #endif |
| 38 | #ifdef HAVE_ERRNO_H |
| 39 | #include <errno.h> |
| 40 | #endif |
| 41 | #ifdef HAVE_MNTENT_H |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 42 | #include <mntent.h> |
Theodore Ts'o | a418d3a | 1997-04-26 14:00:26 +0000 | [diff] [blame] | 43 | #endif |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 44 | #include <sys/ioctl.h> |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 45 | #include <sys/types.h> |
| 46 | |
Theodore Ts'o | 54c637d | 2001-05-14 11:45:38 +0000 | [diff] [blame] | 47 | #include "ext2fs/ext2_fs.h" |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 48 | #include "et/com_err.h" |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 49 | #include "uuid/uuid.h" |
Theodore Ts'o | 896938d | 1999-10-23 01:04:50 +0000 | [diff] [blame] | 50 | #include "e2p/e2p.h" |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 51 | #include "ext2fs/ext2fs.h" |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 52 | #include "util.h" |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 53 | #include "../version.h" |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 54 | #include "nls-enable.h" |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 55 | |
| 56 | #define STRIDE_LENGTH 8 |
| 57 | |
Theodore Ts'o | 6733c2f | 1999-11-23 02:23:30 +0000 | [diff] [blame] | 58 | #ifndef __sparc__ |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 59 | #define ZAP_BOOTBLOCK |
| 60 | #endif |
| 61 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 62 | extern int isatty(int); |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 63 | extern FILE *fpopen(const char *cmd, const char *mode); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 64 | |
| 65 | const char * program_name = "mke2fs"; |
Theodore Ts'o | d48755e | 2000-12-09 14:36:04 +0000 | [diff] [blame] | 66 | const char * device_name /* = NULL */; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 67 | |
| 68 | /* Command line options */ |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 69 | int cflag; |
| 70 | int verbose; |
| 71 | int quiet; |
| 72 | int super_only; |
| 73 | int force; |
| 74 | int noaction; |
| 75 | int journal_size; |
| 76 | int journal_flags; |
| 77 | char *bad_blocks_filename; |
| 78 | __u32 fs_stride; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 79 | |
| 80 | struct ext2_super_block param; |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 81 | char *creator_os; |
| 82 | char *volume_label; |
| 83 | char *mount_dir; |
| 84 | char *journal_device; |
| 85 | int sync_kludge; /* Set using the MKE2FS_SYNC env. option */ |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 86 | |
Theodore Ts'o | 31e29a1 | 2002-05-17 10:53:07 -0400 | [diff] [blame] | 87 | int sys_page_size = 4096; |
| 88 | |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 89 | static void usage(void) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 90 | { |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 91 | fprintf(stderr, _("Usage: %s [-c|-t|-l filename] [-b block-size] " |
Theodore Ts'o | dc2ec52 | 2001-01-18 01:51:15 +0000 | [diff] [blame] | 92 | "[-f fragment-size]\n\t[-i bytes-per-inode] [-j] [-J journal-options]" |
Theodore Ts'o | 5515e6b | 1999-01-05 07:25:06 +0000 | [diff] [blame] | 93 | " [-N number-of-inodes]\n\t[-m reserved-blocks-percentage] " |
| 94 | "[-o creator-os] [-g blocks-per-group]\n\t[-L volume-label] " |
Theodore Ts'o | 18160d2 | 1999-10-23 01:22:17 +0000 | [diff] [blame] | 95 | "[-M last-mounted-directory] [-O feature[,...]]\n\t" |
Theodore Ts'o | b10fd5e | 2001-04-22 03:47:23 +0000 | [diff] [blame] | 96 | "[-r fs-revision] [-R raid_opts] [-qvSV] device [blocks-count]\n"), |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 97 | program_name); |
| 98 | exit(1); |
| 99 | } |
| 100 | |
Theodore Ts'o | 6733c2f | 1999-11-23 02:23:30 +0000 | [diff] [blame] | 101 | static int int_log2(int arg) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 102 | { |
| 103 | int l = 0; |
| 104 | |
| 105 | arg >>= 1; |
| 106 | while (arg) { |
| 107 | l++; |
| 108 | arg >>= 1; |
| 109 | } |
| 110 | return l; |
| 111 | } |
| 112 | |
Theodore Ts'o | 6733c2f | 1999-11-23 02:23:30 +0000 | [diff] [blame] | 113 | static int int_log10(unsigned int arg) |
Theodore Ts'o | 1dde43f | 1998-11-14 04:18:28 +0000 | [diff] [blame] | 114 | { |
| 115 | int l; |
| 116 | |
| 117 | for (l=0; arg ; l++) |
| 118 | arg = arg / 10; |
| 119 | return l; |
| 120 | } |
| 121 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 122 | /* |
Theodore Ts'o | 50787ea | 1999-07-19 15:30:21 +0000 | [diff] [blame] | 123 | * This function sets the default parameters for a filesystem |
| 124 | * |
Theodore Ts'o | 2740156 | 1999-09-14 20:11:19 +0000 | [diff] [blame] | 125 | * The type is specified by the user. The size is the maximum size |
| 126 | * (in megabytes) for which a set of parameters applies, with a size |
| 127 | * of zero meaning that it is the default parameter for the type. |
| 128 | * Note that order is important in the table below. |
Theodore Ts'o | 50787ea | 1999-07-19 15:30:21 +0000 | [diff] [blame] | 129 | */ |
Theodore Ts'o | 31e29a1 | 2002-05-17 10:53:07 -0400 | [diff] [blame] | 130 | #define DEF_MAX_BLOCKSIZE -1 |
Theodore Ts'o | 50787ea | 1999-07-19 15:30:21 +0000 | [diff] [blame] | 131 | static char default_str[] = "default"; |
| 132 | struct mke2fs_defaults { |
Theodore Ts'o | 4a60056 | 1999-10-26 14:35:51 +0000 | [diff] [blame] | 133 | const char *type; |
| 134 | int size; |
| 135 | int blocksize; |
| 136 | int inode_ratio; |
Theodore Ts'o | 50787ea | 1999-07-19 15:30:21 +0000 | [diff] [blame] | 137 | } settings[] = { |
| 138 | { default_str, 0, 4096, 8192 }, |
| 139 | { default_str, 512, 1024, 4096 }, |
| 140 | { default_str, 3, 1024, 8192 }, |
Theodore Ts'o | dc2ec52 | 2001-01-18 01:51:15 +0000 | [diff] [blame] | 141 | { "journal", 0, 4096, 8192 }, |
Theodore Ts'o | 50787ea | 1999-07-19 15:30:21 +0000 | [diff] [blame] | 142 | { "news", 0, 4096, 4096 }, |
Theodore Ts'o | 31e29a1 | 2002-05-17 10:53:07 -0400 | [diff] [blame] | 143 | { "largefile", 0, DEF_MAX_BLOCKSIZE, 1024 * 1024 }, |
| 144 | { "largefile4", 0, DEF_MAX_BLOCKSIZE, 4096 * 1024 }, |
Theodore Ts'o | 50787ea | 1999-07-19 15:30:21 +0000 | [diff] [blame] | 145 | { 0, 0, 0, 0}, |
| 146 | }; |
| 147 | |
Theodore Ts'o | 4ea7bd0 | 2001-12-16 23:23:37 -0500 | [diff] [blame] | 148 | static void set_fs_defaults(const char *fs_type, |
| 149 | struct ext2_super_block *super, |
Theodore Ts'o | 93d5c38 | 2003-05-21 17:28:29 -0400 | [diff] [blame] | 150 | int blocksize, int sector_size, |
| 151 | int *inode_ratio) |
Theodore Ts'o | 50787ea | 1999-07-19 15:30:21 +0000 | [diff] [blame] | 152 | { |
| 153 | int megs; |
| 154 | int ratio = 0; |
| 155 | struct mke2fs_defaults *p; |
Theodore Ts'o | c5290fa | 2003-04-11 22:10:50 -0400 | [diff] [blame] | 156 | int use_bsize = 1024; |
Theodore Ts'o | 50787ea | 1999-07-19 15:30:21 +0000 | [diff] [blame] | 157 | |
Andreas Dilger | 932a489 | 2002-05-16 03:20:07 -0600 | [diff] [blame] | 158 | megs = super->s_blocks_count * (EXT2_BLOCK_SIZE(super) / 1024) / 1024; |
Theodore Ts'o | 50787ea | 1999-07-19 15:30:21 +0000 | [diff] [blame] | 159 | if (inode_ratio) |
| 160 | ratio = *inode_ratio; |
| 161 | if (!fs_type) |
| 162 | fs_type = default_str; |
| 163 | for (p = settings; p->type; p++) { |
| 164 | if ((strcmp(p->type, fs_type) != 0) && |
| 165 | (strcmp(p->type, default_str) != 0)) |
| 166 | continue; |
Theodore Ts'o | c5290fa | 2003-04-11 22:10:50 -0400 | [diff] [blame] | 167 | if ((p->size != 0) && (megs > p->size)) |
Theodore Ts'o | 50787ea | 1999-07-19 15:30:21 +0000 | [diff] [blame] | 168 | continue; |
| 169 | if (ratio == 0) |
Andreas Dilger | b21bf26 | 2002-06-10 11:05:56 -0600 | [diff] [blame] | 170 | *inode_ratio = p->inode_ratio < blocksize ? |
| 171 | blocksize : p->inode_ratio; |
Theodore Ts'o | c5290fa | 2003-04-11 22:10:50 -0400 | [diff] [blame] | 172 | use_bsize = p->blocksize; |
Theodore Ts'o | 50787ea | 1999-07-19 15:30:21 +0000 | [diff] [blame] | 173 | } |
Theodore Ts'o | 1139300 | 2003-07-12 01:58:12 -0400 | [diff] [blame] | 174 | if (sector_size && use_bsize < sector_size) |
Theodore Ts'o | 93d5c38 | 2003-05-21 17:28:29 -0400 | [diff] [blame] | 175 | use_bsize = sector_size; |
Theodore Ts'o | c5290fa | 2003-04-11 22:10:50 -0400 | [diff] [blame] | 176 | if (blocksize <= 0) { |
| 177 | if (use_bsize == DEF_MAX_BLOCKSIZE) |
| 178 | use_bsize = sys_page_size; |
| 179 | if ((blocksize < 0) && (use_bsize < (-blocksize))) |
| 180 | use_bsize = -blocksize; |
| 181 | blocksize = use_bsize; |
| 182 | super->s_blocks_count /= blocksize / 1024; |
| 183 | } |
| 184 | super->s_log_frag_size = super->s_log_block_size = |
| 185 | int_log2(blocksize >> EXT2_MIN_BLOCK_LOG_SIZE); |
Theodore Ts'o | 50787ea | 1999-07-19 15:30:21 +0000 | [diff] [blame] | 186 | } |
| 187 | |
Theodore Ts'o | c5290fa | 2003-04-11 22:10:50 -0400 | [diff] [blame] | 188 | |
Theodore Ts'o | 50787ea | 1999-07-19 15:30:21 +0000 | [diff] [blame] | 189 | /* |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 190 | * Helper function for read_bb_file and test_disk |
| 191 | */ |
| 192 | static void invalid_block(ext2_filsys fs, blk_t blk) |
| 193 | { |
Theodore Ts'o | 6693837 | 2002-03-08 00:14:46 -0500 | [diff] [blame] | 194 | fprintf(stderr, _("Bad block %u out of range; ignored.\n"), blk); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 195 | return; |
| 196 | } |
| 197 | |
| 198 | /* |
| 199 | * Reads the bad blocks list from a file |
| 200 | */ |
| 201 | static void read_bb_file(ext2_filsys fs, badblocks_list *bb_list, |
| 202 | const char *bad_blocks_file) |
| 203 | { |
| 204 | FILE *f; |
| 205 | errcode_t retval; |
| 206 | |
| 207 | f = fopen(bad_blocks_file, "r"); |
| 208 | if (!f) { |
| 209 | com_err("read_bad_blocks_file", errno, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 210 | _("while trying to open %s"), bad_blocks_file); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 211 | exit(1); |
| 212 | } |
| 213 | retval = ext2fs_read_bb_FILE(fs, f, bb_list, invalid_block); |
| 214 | fclose (f); |
| 215 | if (retval) { |
| 216 | com_err("ext2fs_read_bb_FILE", retval, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 217 | _("while reading in list of bad blocks from file")); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 218 | exit(1); |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | /* |
| 223 | * Runs the badblocks program to test the disk |
| 224 | */ |
| 225 | static void test_disk(ext2_filsys fs, badblocks_list *bb_list) |
| 226 | { |
| 227 | FILE *f; |
| 228 | errcode_t retval; |
| 229 | char buf[1024]; |
| 230 | |
Theodore Ts'o | 3ed57c2 | 2001-12-24 15:01:59 -0500 | [diff] [blame] | 231 | sprintf(buf, "badblocks -b %d %s%s%s %d", fs->blocksize, |
| 232 | quiet ? "" : "-s ", (cflag > 1) ? "-w " : "", |
| 233 | fs->device_name, fs->super->s_blocks_count); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 234 | if (verbose) |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 235 | printf(_("Running command: %s\n"), buf); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 236 | f = popen(buf, "r"); |
| 237 | if (!f) { |
| 238 | com_err("popen", errno, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 239 | _("while trying run '%s'"), buf); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 240 | exit(1); |
| 241 | } |
| 242 | retval = ext2fs_read_bb_FILE(fs, f, bb_list, invalid_block); |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 243 | pclose(f); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 244 | if (retval) { |
| 245 | com_err("ext2fs_read_bb_FILE", retval, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 246 | _("while processing list of bad blocks from program")); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 247 | exit(1); |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | static void handle_bad_blocks(ext2_filsys fs, badblocks_list bb_list) |
| 252 | { |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 253 | int i, j; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 254 | int must_be_good; |
| 255 | blk_t blk; |
| 256 | badblocks_iterate bb_iter; |
| 257 | errcode_t retval; |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 258 | blk_t group_block; |
| 259 | int group; |
| 260 | int group_bad; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 261 | |
| 262 | if (!bb_list) |
| 263 | return; |
| 264 | |
| 265 | /* |
| 266 | * The primary superblock and group descriptors *must* be |
| 267 | * good; if not, abort. |
| 268 | */ |
| 269 | must_be_good = fs->super->s_first_data_block + 1 + fs->desc_blocks; |
| 270 | 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] | 271 | if (ext2fs_badblocks_list_test(bb_list, i)) { |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 272 | fprintf(stderr, _("Block %d in primary " |
| 273 | "superblock/group descriptor area bad.\n"), i); |
| 274 | fprintf(stderr, _("Blocks %d through %d must be good " |
| 275 | "in order to build a filesystem.\n"), |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 276 | fs->super->s_first_data_block, must_be_good); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 277 | fprintf(stderr, _("Aborting....\n")); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 278 | exit(1); |
| 279 | } |
| 280 | } |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 281 | |
| 282 | /* |
| 283 | * See if any of the bad blocks are showing up in the backup |
| 284 | * superblocks and/or group descriptors. If so, issue a |
| 285 | * warning and adjust the block counts appropriately. |
| 286 | */ |
| 287 | group_block = fs->super->s_first_data_block + |
| 288 | fs->super->s_blocks_per_group; |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 289 | |
| 290 | for (i = 1; i < fs->group_desc_count; i++) { |
Theodore Ts'o | 92bcc59 | 1998-02-16 22:29:34 +0000 | [diff] [blame] | 291 | group_bad = 0; |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 292 | for (j=0; j < fs->desc_blocks+1; j++) { |
Theodore Ts'o | cbbf031 | 2001-06-13 00:12:04 +0000 | [diff] [blame] | 293 | if (ext2fs_badblocks_list_test(bb_list, |
| 294 | group_block + j)) { |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 295 | if (!group_bad) |
| 296 | fprintf(stderr, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 297 | _("Warning: the backup superblock/group descriptors at block %d contain\n" |
| 298 | " bad blocks.\n\n"), |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 299 | group_block); |
| 300 | group_bad++; |
| 301 | group = ext2fs_group_of_blk(fs, group_block+j); |
| 302 | fs->group_desc[group].bg_free_blocks_count++; |
| 303 | fs->super->s_free_blocks_count++; |
| 304 | } |
| 305 | } |
| 306 | group_block += fs->super->s_blocks_per_group; |
| 307 | } |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 308 | |
| 309 | /* |
| 310 | * Mark all the bad blocks as used... |
| 311 | */ |
Theodore Ts'o | cbbf031 | 2001-06-13 00:12:04 +0000 | [diff] [blame] | 312 | retval = ext2fs_badblocks_list_iterate_begin(bb_list, &bb_iter); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 313 | if (retval) { |
Theodore Ts'o | cbbf031 | 2001-06-13 00:12:04 +0000 | [diff] [blame] | 314 | com_err("ext2fs_badblocks_list_iterate_begin", retval, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 315 | _("while marking bad blocks as used")); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 316 | exit(1); |
| 317 | } |
Theodore Ts'o | cbbf031 | 2001-06-13 00:12:04 +0000 | [diff] [blame] | 318 | while (ext2fs_badblocks_list_iterate(bb_iter, &blk)) |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 319 | ext2fs_mark_block_bitmap(fs->block_map, blk); |
Theodore Ts'o | cbbf031 | 2001-06-13 00:12:04 +0000 | [diff] [blame] | 320 | ext2fs_badblocks_list_iterate_end(bb_iter); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 321 | } |
| 322 | |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 323 | /* |
| 324 | * These functions implement a generalized progress meter. |
| 325 | */ |
| 326 | struct progress_struct { |
| 327 | char format[20]; |
| 328 | char backup[80]; |
| 329 | __u32 max; |
| 330 | }; |
| 331 | |
| 332 | static void progress_init(struct progress_struct *progress, |
Theodore Ts'o | 4ea7bd0 | 2001-12-16 23:23:37 -0500 | [diff] [blame] | 333 | const char *label,__u32 max) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 334 | { |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 335 | int i; |
Theodore Ts'o | 7d5633c | 1999-02-09 08:14:28 +0000 | [diff] [blame] | 336 | |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 337 | memset(progress, 0, sizeof(struct progress_struct)); |
| 338 | if (quiet) |
| 339 | return; |
Theodore Ts'o | 1dde43f | 1998-11-14 04:18:28 +0000 | [diff] [blame] | 340 | |
| 341 | /* |
| 342 | * Figure out how many digits we need |
| 343 | */ |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 344 | i = int_log10(max); |
| 345 | sprintf(progress->format, "%%%dd/%%%dld", i, i); |
| 346 | memset(progress->backup, '\b', sizeof(progress->backup)-1); |
| 347 | progress->backup[sizeof(progress->backup)-1] = 0; |
| 348 | if ((2*i)+1 < sizeof(progress->backup)) |
| 349 | progress->backup[(2*i)+1] = 0; |
| 350 | progress->max = max; |
Theodore Ts'o | 1dde43f | 1998-11-14 04:18:28 +0000 | [diff] [blame] | 351 | |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 352 | fputs(label, stdout); |
| 353 | fflush(stdout); |
| 354 | } |
| 355 | |
| 356 | static void progress_update(struct progress_struct *progress, __u32 val) |
| 357 | { |
| 358 | if (progress->format[0] == 0) |
| 359 | return; |
| 360 | printf(progress->format, val, progress->max); |
| 361 | fputs(progress->backup, stdout); |
| 362 | } |
| 363 | |
| 364 | static void progress_close(struct progress_struct *progress) |
| 365 | { |
| 366 | if (progress->format[0] == 0) |
| 367 | return; |
| 368 | fputs(_("done \n"), stdout); |
| 369 | } |
| 370 | |
| 371 | |
| 372 | /* |
| 373 | * Helper function which zeros out _num_ blocks starting at _blk_. In |
| 374 | * case of an error, the details of the error is returned via _ret_blk_ |
| 375 | * and _ret_count_ if they are non-NULL pointers. Returns 0 on |
| 376 | * success, and an error code on an error. |
| 377 | * |
| 378 | * As a special case, if the first argument is NULL, then it will |
| 379 | * attempt to free the static zeroizing buffer. (This is to keep |
| 380 | * programs that check for memory leaks happy.) |
| 381 | */ |
| 382 | static errcode_t zero_blocks(ext2_filsys fs, blk_t blk, int num, |
| 383 | struct progress_struct *progress, |
| 384 | blk_t *ret_blk, int *ret_count) |
| 385 | { |
| 386 | int j, count, next_update, next_update_incr; |
| 387 | static char *buf; |
| 388 | errcode_t retval; |
| 389 | |
| 390 | /* If fs is null, clean up the static buffer and return */ |
| 391 | if (!fs) { |
| 392 | if (buf) { |
| 393 | free(buf); |
| 394 | buf = 0; |
| 395 | } |
| 396 | return 0; |
| 397 | } |
| 398 | /* Allocate the zeroizing buffer if necessary */ |
| 399 | if (!buf) { |
| 400 | buf = malloc(fs->blocksize * STRIDE_LENGTH); |
| 401 | if (!buf) { |
| 402 | com_err("malloc", ENOMEM, |
| 403 | _("while allocating zeroizing buffer")); |
| 404 | exit(1); |
| 405 | } |
| 406 | memset(buf, 0, fs->blocksize * STRIDE_LENGTH); |
| 407 | } |
| 408 | /* OK, do the write loop */ |
| 409 | next_update = 0; |
| 410 | next_update_incr = num / 100; |
| 411 | if (next_update_incr < 1) |
| 412 | next_update_incr = 1; |
| 413 | for (j=0; j < num; j += STRIDE_LENGTH, blk += STRIDE_LENGTH) { |
Theodore Ts'o | f044b4d | 2002-08-17 13:32:21 -0400 | [diff] [blame] | 414 | count = num - j; |
| 415 | if (count > STRIDE_LENGTH) |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 416 | count = STRIDE_LENGTH; |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 417 | retval = io_channel_write_blk(fs->io, blk, count, buf); |
| 418 | if (retval) { |
| 419 | if (ret_count) |
| 420 | *ret_count = count; |
| 421 | if (ret_blk) |
| 422 | *ret_blk = blk; |
| 423 | return retval; |
| 424 | } |
| 425 | if (progress && j > next_update) { |
| 426 | next_update += num / 100; |
| 427 | progress_update(progress, blk); |
| 428 | } |
| 429 | } |
| 430 | return 0; |
| 431 | } |
| 432 | |
| 433 | static void write_inode_tables(ext2_filsys fs) |
| 434 | { |
| 435 | errcode_t retval; |
| 436 | blk_t blk; |
| 437 | int i, num; |
| 438 | struct progress_struct progress; |
| 439 | |
| 440 | if (quiet) |
| 441 | memset(&progress, 0, sizeof(progress)); |
| 442 | else |
| 443 | progress_init(&progress, _("Writing inode tables: "), |
| 444 | fs->group_desc_count); |
| 445 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 446 | for (i = 0; i < fs->group_desc_count; i++) { |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 447 | progress_update(&progress, i); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 448 | |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 449 | blk = fs->group_desc[i].bg_inode_table; |
| 450 | num = fs->inode_blocks_per_group; |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 451 | |
| 452 | retval = zero_blocks(fs, blk, num, 0, &blk, &num); |
| 453 | if (retval) { |
Theodore Ts'o | 6693837 | 2002-03-08 00:14:46 -0500 | [diff] [blame] | 454 | fprintf(stderr, _("\nCould not write %d blocks " |
| 455 | "in inode table starting at %d: %s\n"), |
| 456 | num, blk, error_message(retval)); |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 457 | exit(1); |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 458 | } |
Theodore Ts'o | 7d5633c | 1999-02-09 08:14:28 +0000 | [diff] [blame] | 459 | if (sync_kludge) { |
| 460 | if (sync_kludge == 1) |
| 461 | sync(); |
| 462 | else if ((i % sync_kludge) == 0) |
| 463 | sync(); |
| 464 | } |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 465 | } |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 466 | zero_blocks(0, 0, 0, 0, 0, 0); |
| 467 | progress_close(&progress); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | static void create_root_dir(ext2_filsys fs) |
| 471 | { |
| 472 | errcode_t retval; |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 473 | struct ext2_inode inode; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 474 | |
| 475 | retval = ext2fs_mkdir(fs, EXT2_ROOT_INO, EXT2_ROOT_INO, 0); |
| 476 | if (retval) { |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 477 | com_err("ext2fs_mkdir", retval, _("while creating root dir")); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 478 | exit(1); |
| 479 | } |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 480 | if (geteuid()) { |
| 481 | retval = ext2fs_read_inode(fs, EXT2_ROOT_INO, &inode); |
| 482 | if (retval) { |
| 483 | com_err("ext2fs_read_inode", retval, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 484 | _("while reading root inode")); |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 485 | exit(1); |
| 486 | } |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 487 | inode.i_uid = getuid(); |
| 488 | if (inode.i_uid) |
| 489 | inode.i_gid = getgid(); |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 490 | retval = ext2fs_write_inode(fs, EXT2_ROOT_INO, &inode); |
| 491 | if (retval) { |
| 492 | com_err("ext2fs_write_inode", retval, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 493 | _("while setting root inode ownership")); |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 494 | exit(1); |
| 495 | } |
| 496 | } |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | static void create_lost_and_found(ext2_filsys fs) |
| 500 | { |
| 501 | errcode_t retval; |
Theodore Ts'o | dfcdc32 | 2001-01-11 15:38:00 +0000 | [diff] [blame] | 502 | ext2_ino_t ino; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 503 | const char *name = "lost+found"; |
| 504 | int i; |
Theodore Ts'o | 50787ea | 1999-07-19 15:30:21 +0000 | [diff] [blame] | 505 | int lpf_size = 0; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 506 | |
Theodore Ts'o | 6a52506 | 2001-12-24 09:40:00 -0500 | [diff] [blame] | 507 | fs->umask = 077; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 508 | retval = ext2fs_mkdir(fs, EXT2_ROOT_INO, 0, name); |
| 509 | if (retval) { |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 510 | com_err("ext2fs_mkdir", retval, |
| 511 | _("while creating /lost+found")); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 512 | exit(1); |
| 513 | } |
| 514 | |
| 515 | retval = ext2fs_lookup(fs, EXT2_ROOT_INO, name, strlen(name), 0, &ino); |
| 516 | if (retval) { |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 517 | com_err("ext2_lookup", retval, |
| 518 | _("while looking up /lost+found")); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 519 | exit(1); |
| 520 | } |
| 521 | |
| 522 | for (i=1; i < EXT2_NDIR_BLOCKS; i++) { |
Theodore Ts'o | 50787ea | 1999-07-19 15:30:21 +0000 | [diff] [blame] | 523 | if ((lpf_size += fs->blocksize) >= 16*1024) |
| 524 | break; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 525 | retval = ext2fs_expand_dir(fs, ino); |
| 526 | if (retval) { |
| 527 | com_err("ext2fs_expand_dir", retval, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 528 | _("while expanding /lost+found")); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 529 | exit(1); |
| 530 | } |
Theodore Ts'o | 6a52506 | 2001-12-24 09:40:00 -0500 | [diff] [blame] | 531 | } |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | static void create_bad_block_inode(ext2_filsys fs, badblocks_list bb_list) |
| 535 | { |
| 536 | errcode_t retval; |
| 537 | |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 538 | ext2fs_mark_inode_bitmap(fs->inode_map, EXT2_BAD_INO); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 539 | fs->group_desc[0].bg_free_inodes_count--; |
| 540 | fs->super->s_free_inodes_count--; |
| 541 | retval = ext2fs_update_bb_inode(fs, bb_list); |
| 542 | if (retval) { |
| 543 | com_err("ext2fs_update_bb_inode", retval, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 544 | _("while setting bad block inode")); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 545 | exit(1); |
| 546 | } |
| 547 | |
| 548 | } |
| 549 | |
| 550 | static void reserve_inodes(ext2_filsys fs) |
| 551 | { |
Theodore Ts'o | dfcdc32 | 2001-01-11 15:38:00 +0000 | [diff] [blame] | 552 | ext2_ino_t i; |
| 553 | int group; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 554 | |
Theodore Ts'o | 7f88b04 | 1997-04-26 14:48:50 +0000 | [diff] [blame] | 555 | for (i = EXT2_ROOT_INO + 1; i < EXT2_FIRST_INODE(fs->super); i++) { |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 556 | ext2fs_mark_inode_bitmap(fs->inode_map, i); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 557 | group = ext2fs_group_of_ino(fs, i); |
| 558 | fs->group_desc[group].bg_free_inodes_count--; |
| 559 | fs->super->s_free_inodes_count--; |
| 560 | } |
| 561 | ext2fs_mark_ib_dirty(fs); |
| 562 | } |
| 563 | |
Theodore Ts'o | 756df35 | 2002-03-07 20:52:12 -0500 | [diff] [blame] | 564 | #define BSD_DISKMAGIC (0x82564557UL) /* The disk magic number */ |
Theodore Ts'o | 7ef3bb8 | 2002-03-08 03:01:53 -0500 | [diff] [blame] | 565 | #define BSD_MAGICDISK (0x57455682UL) /* The disk magic number reversed */ |
Theodore Ts'o | 756df35 | 2002-03-07 20:52:12 -0500 | [diff] [blame] | 566 | #define BSD_LABEL_OFFSET 64 |
Theodore Ts'o | 756df35 | 2002-03-07 20:52:12 -0500 | [diff] [blame] | 567 | |
Theodore Ts'o | 04a9685 | 2001-08-30 21:55:26 -0400 | [diff] [blame] | 568 | static void zap_sector(ext2_filsys fs, int sect, int nsect) |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 569 | { |
Theodore Ts'o | 3f85f65 | 2001-09-17 10:38:06 -0400 | [diff] [blame] | 570 | char *buf; |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 571 | int retval; |
Theodore Ts'o | 756df35 | 2002-03-07 20:52:12 -0500 | [diff] [blame] | 572 | unsigned int *magic; |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 573 | |
Theodore Ts'o | 3f85f65 | 2001-09-17 10:38:06 -0400 | [diff] [blame] | 574 | buf = malloc(512*nsect); |
Andreas Dilger | 568101f | 2001-10-13 01:22:25 -0600 | [diff] [blame] | 575 | if (!buf) { |
Theodore Ts'o | 4ea7bd0 | 2001-12-16 23:23:37 -0500 | [diff] [blame] | 576 | printf(_("Out of memory erasing sectors %d-%d\n"), |
| 577 | sect, sect + nsect - 1); |
Andreas Dilger | 568101f | 2001-10-13 01:22:25 -0600 | [diff] [blame] | 578 | exit(1); |
| 579 | } |
Theodore Ts'o | 756df35 | 2002-03-07 20:52:12 -0500 | [diff] [blame] | 580 | |
Theodore Ts'o | 7ef3bb8 | 2002-03-08 03:01:53 -0500 | [diff] [blame] | 581 | if (sect == 0) { |
| 582 | /* Check for a BSD disklabel, and don't erase it if so */ |
| 583 | retval = io_channel_read_blk(fs->io, 0, -512, buf); |
| 584 | if (retval) |
| 585 | fprintf(stderr, |
| 586 | _("Warning: could not read block 0: %s\n"), |
| 587 | error_message(retval)); |
| 588 | else { |
| 589 | magic = (unsigned int *) (buf + BSD_LABEL_OFFSET); |
| 590 | if ((*magic == BSD_DISKMAGIC) || |
| 591 | (*magic == BSD_MAGICDISK)) |
| 592 | return; |
| 593 | } |
Theodore Ts'o | 756df35 | 2002-03-07 20:52:12 -0500 | [diff] [blame] | 594 | } |
Theodore Ts'o | 756df35 | 2002-03-07 20:52:12 -0500 | [diff] [blame] | 595 | |
Theodore Ts'o | 7098810 | 2002-07-14 08:00:00 -0400 | [diff] [blame] | 596 | memset(buf, 0, 512*nsect); |
Theodore Ts'o | e41784e | 2000-08-14 14:44:15 +0000 | [diff] [blame] | 597 | io_channel_set_blksize(fs->io, 512); |
Theodore Ts'o | 04a9685 | 2001-08-30 21:55:26 -0400 | [diff] [blame] | 598 | retval = io_channel_write_blk(fs->io, sect, -512*nsect, buf); |
Theodore Ts'o | e41784e | 2000-08-14 14:44:15 +0000 | [diff] [blame] | 599 | io_channel_set_blksize(fs->io, fs->blocksize); |
Theodore Ts'o | 3f85f65 | 2001-09-17 10:38:06 -0400 | [diff] [blame] | 600 | free(buf); |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 601 | if (retval) |
Theodore Ts'o | 6693837 | 2002-03-08 00:14:46 -0500 | [diff] [blame] | 602 | fprintf(stderr, _("Warning: could not erase sector %d: %s\n"), |
| 603 | sect, error_message(retval)); |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 604 | } |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 605 | |
| 606 | static void create_journal_dev(ext2_filsys fs) |
| 607 | { |
| 608 | struct progress_struct progress; |
| 609 | errcode_t retval; |
| 610 | char *buf; |
Theodore Ts'o | dc2ec52 | 2001-01-18 01:51:15 +0000 | [diff] [blame] | 611 | blk_t blk; |
| 612 | int count; |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 613 | |
Theodore Ts'o | d6a27e0 | 2001-04-17 02:34:41 +0000 | [diff] [blame] | 614 | retval = ext2fs_create_journal_superblock(fs, |
| 615 | fs->super->s_blocks_count, 0, &buf); |
| 616 | if (retval) { |
| 617 | com_err("create_journal_dev", retval, |
| 618 | _("while initializing journal superblock")); |
| 619 | exit(1); |
| 620 | } |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 621 | if (quiet) |
| 622 | memset(&progress, 0, sizeof(progress)); |
| 623 | else |
| 624 | progress_init(&progress, _("Zeroing journal device: "), |
| 625 | fs->super->s_blocks_count); |
| 626 | |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 627 | retval = zero_blocks(fs, 0, fs->super->s_blocks_count, |
| 628 | &progress, &blk, &count); |
| 629 | if (retval) { |
| 630 | com_err("create_journal_dev", retval, |
Theodore Ts'o | 14bbcbc | 2001-05-13 22:58:27 +0000 | [diff] [blame] | 631 | _("while zeroing journal device (block %u, count %d)"), |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 632 | blk, count); |
| 633 | exit(1); |
| 634 | } |
Theodore Ts'o | dc2ec52 | 2001-01-18 01:51:15 +0000 | [diff] [blame] | 635 | zero_blocks(0, 0, 0, 0, 0, 0); |
| 636 | |
Theodore Ts'o | dc2ec52 | 2001-01-18 01:51:15 +0000 | [diff] [blame] | 637 | retval = io_channel_write_blk(fs->io, |
| 638 | fs->super->s_first_data_block+1, |
| 639 | 1, buf); |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 640 | if (retval) { |
| 641 | com_err("create_journal_dev", retval, |
| 642 | _("while writing journal superblock")); |
| 643 | exit(1); |
| 644 | } |
| 645 | progress_close(&progress); |
| 646 | } |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 647 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 648 | static void show_stats(ext2_filsys fs) |
| 649 | { |
Theodore Ts'o | ef9abe5 | 2001-01-01 15:31:53 +0000 | [diff] [blame] | 650 | struct ext2_super_block *s = fs->super; |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 651 | char buf[80]; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 652 | blk_t group_block; |
Theodore Ts'o | 1dde43f | 1998-11-14 04:18:28 +0000 | [diff] [blame] | 653 | int i, need, col_left; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 654 | |
| 655 | if (param.s_blocks_count != s->s_blocks_count) |
Theodore Ts'o | 6693837 | 2002-03-08 00:14:46 -0500 | [diff] [blame] | 656 | fprintf(stderr, _("warning: %d blocks unused.\n\n"), |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 657 | param.s_blocks_count - s->s_blocks_count); |
Theodore Ts'o | 50787ea | 1999-07-19 15:30:21 +0000 | [diff] [blame] | 658 | |
| 659 | memset(buf, 0, sizeof(buf)); |
| 660 | strncpy(buf, s->s_volume_name, sizeof(s->s_volume_name)); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 661 | printf(_("Filesystem label=%s\n"), buf); |
| 662 | printf(_("OS type: ")); |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 663 | switch (fs->super->s_creator_os) { |
| 664 | case EXT2_OS_LINUX: printf ("Linux"); break; |
Theodore Ts'o | ad6783d | 1999-10-26 01:58:54 +0000 | [diff] [blame] | 665 | case EXT2_OS_HURD: printf ("GNU/Hurd"); break; |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 666 | case EXT2_OS_MASIX: printf ("Masix"); break; |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 667 | default: printf (_("(unknown os)")); |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 668 | } |
Theodore Ts'o | 50787ea | 1999-07-19 15:30:21 +0000 | [diff] [blame] | 669 | printf("\n"); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 670 | printf(_("Block size=%u (log=%u)\n"), fs->blocksize, |
Theodore Ts'o | 50787ea | 1999-07-19 15:30:21 +0000 | [diff] [blame] | 671 | s->s_log_block_size); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 672 | printf(_("Fragment size=%u (log=%u)\n"), fs->fragsize, |
Theodore Ts'o | 50787ea | 1999-07-19 15:30:21 +0000 | [diff] [blame] | 673 | s->s_log_frag_size); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 674 | printf(_("%u inodes, %u blocks\n"), s->s_inodes_count, |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 675 | s->s_blocks_count); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 676 | printf(_("%u blocks (%2.2f%%) reserved for the super user\n"), |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 677 | s->s_r_blocks_count, |
| 678 | 100.0 * s->s_r_blocks_count / s->s_blocks_count); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 679 | printf(_("First data block=%u\n"), s->s_first_data_block); |
| 680 | if (fs->group_desc_count > 1) |
Theodore Ts'o | c8c071a | 2001-01-11 16:08:23 +0000 | [diff] [blame] | 681 | printf(_("%u block groups\n"), fs->group_desc_count); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 682 | else |
Theodore Ts'o | c8c071a | 2001-01-11 16:08:23 +0000 | [diff] [blame] | 683 | printf(_("%u block group\n"), fs->group_desc_count); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 684 | printf(_("%u blocks per group, %u fragments per group\n"), |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 685 | s->s_blocks_per_group, s->s_frags_per_group); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 686 | printf(_("%u inodes per group\n"), s->s_inodes_per_group); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 687 | |
| 688 | if (fs->group_desc_count == 1) { |
| 689 | printf("\n"); |
| 690 | return; |
| 691 | } |
| 692 | |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 693 | printf(_("Superblock backups stored on blocks: ")); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 694 | group_block = s->s_first_data_block; |
| 695 | col_left = 0; |
| 696 | for (i = 1; i < fs->group_desc_count; i++) { |
| 697 | group_block += s->s_blocks_per_group; |
Theodore Ts'o | 521e368 | 1997-04-29 17:48:10 +0000 | [diff] [blame] | 698 | if (!ext2fs_bg_has_super(fs, i)) |
| 699 | continue; |
Theodore Ts'o | 7671433 | 1999-10-20 18:06:29 +0000 | [diff] [blame] | 700 | if (i != 1) |
| 701 | printf(", "); |
Theodore Ts'o | 6733c2f | 1999-11-23 02:23:30 +0000 | [diff] [blame] | 702 | need = int_log10(group_block) + 2; |
Theodore Ts'o | 1dde43f | 1998-11-14 04:18:28 +0000 | [diff] [blame] | 703 | if (need > col_left) { |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 704 | printf("\n\t"); |
Theodore Ts'o | 1dde43f | 1998-11-14 04:18:28 +0000 | [diff] [blame] | 705 | col_left = 72; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 706 | } |
Theodore Ts'o | 1dde43f | 1998-11-14 04:18:28 +0000 | [diff] [blame] | 707 | col_left -= need; |
Theodore Ts'o | a418d3a | 1997-04-26 14:00:26 +0000 | [diff] [blame] | 708 | printf("%u", group_block); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 709 | } |
| 710 | printf("\n\n"); |
| 711 | } |
| 712 | |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 713 | /* |
| 714 | * Set the S_CREATOR_OS field. Return true if OS is known, |
| 715 | * otherwise, 0. |
| 716 | */ |
| 717 | static int set_os(struct ext2_super_block *sb, char *os) |
| 718 | { |
| 719 | if (isdigit (*os)) |
| 720 | sb->s_creator_os = atoi (os); |
| 721 | else if (strcasecmp(os, "linux") == 0) |
| 722 | sb->s_creator_os = EXT2_OS_LINUX; |
| 723 | else if (strcasecmp(os, "GNU") == 0 || strcasecmp(os, "hurd") == 0) |
| 724 | sb->s_creator_os = EXT2_OS_HURD; |
| 725 | else if (strcasecmp(os, "masix") == 0) |
| 726 | sb->s_creator_os = EXT2_OS_MASIX; |
| 727 | else |
| 728 | return 0; |
| 729 | return 1; |
| 730 | } |
| 731 | |
Theodore Ts'o | a418d3a | 1997-04-26 14:00:26 +0000 | [diff] [blame] | 732 | #define PATH_SET "PATH=/sbin" |
| 733 | |
Theodore Ts'o | d163b09 | 1997-10-03 17:42:28 +0000 | [diff] [blame] | 734 | static void parse_raid_opts(const char *opts) |
Theodore Ts'o | a29f4d3 | 1997-04-29 21:26:48 +0000 | [diff] [blame] | 735 | { |
| 736 | char *buf, *token, *next, *p, *arg; |
| 737 | int len; |
| 738 | int raid_usage = 0; |
| 739 | |
| 740 | len = strlen(opts); |
| 741 | buf = malloc(len+1); |
| 742 | if (!buf) { |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 743 | fprintf(stderr, _("Couldn't allocate memory to parse " |
| 744 | "raid options!\n")); |
Theodore Ts'o | a29f4d3 | 1997-04-29 21:26:48 +0000 | [diff] [blame] | 745 | exit(1); |
| 746 | } |
| 747 | strcpy(buf, opts); |
| 748 | for (token = buf; token && *token; token = next) { |
| 749 | p = strchr(token, ','); |
| 750 | next = 0; |
| 751 | if (p) { |
| 752 | *p = 0; |
| 753 | next = p+1; |
| 754 | } |
| 755 | arg = strchr(token, '='); |
| 756 | if (arg) { |
| 757 | *arg = 0; |
| 758 | arg++; |
| 759 | } |
| 760 | if (strcmp(token, "stride") == 0) { |
| 761 | if (!arg) { |
| 762 | raid_usage++; |
| 763 | continue; |
| 764 | } |
| 765 | fs_stride = strtoul(arg, &p, 0); |
| 766 | if (*p || (fs_stride == 0)) { |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 767 | fprintf(stderr, |
| 768 | _("Invalid stride parameter.\n")); |
Theodore Ts'o | a29f4d3 | 1997-04-29 21:26:48 +0000 | [diff] [blame] | 769 | raid_usage++; |
| 770 | continue; |
| 771 | } |
| 772 | } else |
| 773 | raid_usage++; |
| 774 | } |
| 775 | if (raid_usage) { |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 776 | fprintf(stderr, _("\nBad raid options specified.\n\n" |
Theodore Ts'o | a29f4d3 | 1997-04-29 21:26:48 +0000 | [diff] [blame] | 777 | "Raid options are separated by commas, " |
| 778 | "and may take an argument which\n" |
| 779 | "\tis set off by an equals ('=') sign.\n\n" |
| 780 | "Valid raid options are:\n" |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 781 | "\tstride=<stride length in blocks>\n\n")); |
Theodore Ts'o | a29f4d3 | 1997-04-29 21:26:48 +0000 | [diff] [blame] | 782 | exit(1); |
| 783 | } |
| 784 | } |
| 785 | |
Theodore Ts'o | 896938d | 1999-10-23 01:04:50 +0000 | [diff] [blame] | 786 | static __u32 ok_features[3] = { |
Theodore Ts'o | 843049c | 2002-09-22 15:37:40 -0400 | [diff] [blame] | 787 | EXT3_FEATURE_COMPAT_HAS_JOURNAL | |
| 788 | EXT2_FEATURE_COMPAT_DIR_INDEX, /* Compat */ |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 789 | EXT2_FEATURE_INCOMPAT_FILETYPE| /* Incompat */ |
Theodore Ts'o | c046ac7 | 2002-10-20 00:38:57 -0400 | [diff] [blame] | 790 | EXT3_FEATURE_INCOMPAT_JOURNAL_DEV| |
| 791 | EXT2_FEATURE_INCOMPAT_META_BG, |
Theodore Ts'o | 896938d | 1999-10-23 01:04:50 +0000 | [diff] [blame] | 792 | EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER /* R/O compat */ |
| 793 | }; |
Theodore Ts'o | a29f4d3 | 1997-04-29 21:26:48 +0000 | [diff] [blame] | 794 | |
| 795 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 796 | static void PRS(int argc, char *argv[]) |
| 797 | { |
Theodore Ts'o | c5290fa | 2003-04-11 22:10:50 -0400 | [diff] [blame] | 798 | int b, c; |
Theodore Ts'o | 4a60056 | 1999-10-26 14:35:51 +0000 | [diff] [blame] | 799 | int size; |
| 800 | char * tmp; |
Theodore Ts'o | 4a60056 | 1999-10-26 14:35:51 +0000 | [diff] [blame] | 801 | int blocksize = 0; |
| 802 | int inode_ratio = 0; |
Andreas Dilger | 932a489 | 2002-05-16 03:20:07 -0600 | [diff] [blame] | 803 | int inode_size = 0; |
Theodore Ts'o | 4a60056 | 1999-10-26 14:35:51 +0000 | [diff] [blame] | 804 | int reserved_ratio = 5; |
Theodore Ts'o | 93d5c38 | 2003-05-21 17:28:29 -0400 | [diff] [blame] | 805 | int sector_size = 0; |
Theodore Ts'o | dfcdc32 | 2001-01-11 15:38:00 +0000 | [diff] [blame] | 806 | ext2_ino_t num_inodes = 0; |
Theodore Ts'o | a418d3a | 1997-04-26 14:00:26 +0000 | [diff] [blame] | 807 | errcode_t retval; |
Theodore Ts'o | 4a60056 | 1999-10-26 14:35:51 +0000 | [diff] [blame] | 808 | char * oldpath = getenv("PATH"); |
Theodore Ts'o | 4a60056 | 1999-10-26 14:35:51 +0000 | [diff] [blame] | 809 | char * raid_opts = 0; |
Theodore Ts'o | 4ea7bd0 | 2001-12-16 23:23:37 -0500 | [diff] [blame] | 810 | const char * fs_type = 0; |
Theodore Ts'o | f3561ed | 2001-08-15 11:58:16 -0400 | [diff] [blame] | 811 | int default_features = 1; |
Theodore Ts'o | 4a60056 | 1999-10-26 14:35:51 +0000 | [diff] [blame] | 812 | blk_t dev_size; |
Theodore Ts'o | 756df35 | 2002-03-07 20:52:12 -0500 | [diff] [blame] | 813 | #ifdef __linux__ |
Theodore Ts'o | 4a60056 | 1999-10-26 14:35:51 +0000 | [diff] [blame] | 814 | struct utsname ut; |
Theodore Ts'o | 2740156 | 1999-09-14 20:11:19 +0000 | [diff] [blame] | 815 | #endif |
Theodore Ts'o | 31e29a1 | 2002-05-17 10:53:07 -0400 | [diff] [blame] | 816 | long sysval; |
Theodore Ts'o | 14bbcbc | 2001-05-13 22:58:27 +0000 | [diff] [blame] | 817 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 818 | /* Update our PATH to include /sbin */ |
Theodore Ts'o | a418d3a | 1997-04-26 14:00:26 +0000 | [diff] [blame] | 819 | if (oldpath) { |
| 820 | char *newpath; |
| 821 | |
| 822 | newpath = malloc(sizeof (PATH_SET) + 1 + strlen (oldpath)); |
| 823 | strcpy (newpath, PATH_SET); |
| 824 | strcat (newpath, ":"); |
| 825 | strcat (newpath, oldpath); |
| 826 | putenv (newpath); |
| 827 | } else |
| 828 | putenv (PATH_SET); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 829 | |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 830 | tmp = getenv("MKE2FS_SYNC"); |
| 831 | if (tmp) |
| 832 | sync_kludge = atoi(tmp); |
Theodore Ts'o | 31e29a1 | 2002-05-17 10:53:07 -0400 | [diff] [blame] | 833 | |
| 834 | /* Determine the system page size if possible */ |
| 835 | #ifdef HAVE_SYSCONF |
| 836 | #if (!defined(_SC_PAGESIZE) && defined(_SC_PAGE_SIZE)) |
| 837 | #define _SC_PAGESIZE _SC_PAGE_SIZE |
| 838 | #endif |
| 839 | #ifdef _SC_PAGESIZE |
| 840 | sysval = sysconf(_SC_PAGESIZE); |
Andreas Dilger | aab6fe7 | 2002-05-18 13:27:33 -0600 | [diff] [blame] | 841 | if (sysval > 0) |
Theodore Ts'o | 31e29a1 | 2002-05-17 10:53:07 -0400 | [diff] [blame] | 842 | sys_page_size = sysval; |
| 843 | #endif /* _SC_PAGESIZE */ |
| 844 | #endif /* HAVE_SYSCONF */ |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 845 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 846 | setbuf(stdout, NULL); |
| 847 | setbuf(stderr, NULL); |
| 848 | initialize_ext2_error_table(); |
| 849 | memset(¶m, 0, sizeof(struct ext2_super_block)); |
Theodore Ts'o | 50787ea | 1999-07-19 15:30:21 +0000 | [diff] [blame] | 850 | param.s_rev_level = 1; /* Create revision 1 filesystems now */ |
Theodore Ts'o | f3561ed | 2001-08-15 11:58:16 -0400 | [diff] [blame] | 851 | param.s_feature_incompat |= EXT2_FEATURE_INCOMPAT_FILETYPE; |
| 852 | param.s_feature_ro_compat |= EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER; |
Theodore Ts'o | 54779c6 | 2002-11-13 07:00:16 -0500 | [diff] [blame] | 853 | #if 0 |
Theodore Ts'o | 843049c | 2002-09-22 15:37:40 -0400 | [diff] [blame] | 854 | param.s_feature_compat |= EXT2_FEATURE_COMPAT_DIR_INDEX; |
Theodore Ts'o | 54779c6 | 2002-11-13 07:00:16 -0500 | [diff] [blame] | 855 | #endif |
Theodore Ts'o | 843049c | 2002-09-22 15:37:40 -0400 | [diff] [blame] | 856 | |
Theodore Ts'o | 756df35 | 2002-03-07 20:52:12 -0500 | [diff] [blame] | 857 | #ifdef __linux__ |
Theodore Ts'o | 14bbcbc | 2001-05-13 22:58:27 +0000 | [diff] [blame] | 858 | if (uname(&ut)) { |
| 859 | perror("uname"); |
| 860 | exit(1); |
| 861 | } |
| 862 | if ((ut.release[0] == '1') || |
| 863 | (ut.release[0] == '2' && ut.release[1] == '.' && |
| 864 | ut.release[2] < '2' && ut.release[3] == '.')) { |
Theodore Ts'o | 14bbcbc | 2001-05-13 22:58:27 +0000 | [diff] [blame] | 865 | param.s_rev_level = 0; |
Theodore Ts'o | f3561ed | 2001-08-15 11:58:16 -0400 | [diff] [blame] | 866 | param.s_feature_incompat = 0; |
| 867 | param.s_feature_compat = 0; |
| 868 | param.s_feature_ro_compat = 0; |
Theodore Ts'o | 14bbcbc | 2001-05-13 22:58:27 +0000 | [diff] [blame] | 869 | } |
| 870 | #endif |
Andreas Dilger | 0072f8d | 2002-02-25 23:11:26 -0700 | [diff] [blame] | 871 | |
| 872 | if (argc && *argv) { |
| 873 | program_name = get_progname(*argv); |
| 874 | |
| 875 | /* If called as mkfs.ext3, create a journal inode */ |
| 876 | if (!strcmp(program_name, "mkfs.ext3")) |
| 877 | journal_size = -1; |
| 878 | } |
| 879 | |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 880 | while ((c = getopt (argc, argv, |
Theodore Ts'o | dc2ec52 | 2001-01-18 01:51:15 +0000 | [diff] [blame] | 881 | "b:cf:g:i:jl:m:no:qr:R:s:tvI:J:ST:FL:M:N:O:V")) != EOF) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 882 | switch (c) { |
| 883 | case 'b': |
Theodore Ts'o | c5290fa | 2003-04-11 22:10:50 -0400 | [diff] [blame] | 884 | blocksize = strtol(optarg, &tmp, 0); |
| 885 | b = (blocksize > 0) ? blocksize : -blocksize; |
| 886 | if (b < EXT2_MIN_BLOCK_SIZE || |
| 887 | b > EXT2_MAX_BLOCK_SIZE || *tmp) { |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 888 | com_err(program_name, 0, |
| 889 | _("bad block size - %s"), optarg); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 890 | exit(1); |
| 891 | } |
Andreas Dilger | 932a489 | 2002-05-16 03:20:07 -0600 | [diff] [blame] | 892 | if (blocksize > 4096) |
| 893 | fprintf(stderr, _("Warning: blocksize %d not " |
| 894 | "usable on most systems.\n"), |
| 895 | blocksize); |
Theodore Ts'o | c5290fa | 2003-04-11 22:10:50 -0400 | [diff] [blame] | 896 | if (blocksize > 0) |
| 897 | param.s_log_block_size = |
| 898 | int_log2(blocksize >> |
| 899 | EXT2_MIN_BLOCK_LOG_SIZE); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 900 | break; |
Theodore Ts'o | b10fd5e | 2001-04-22 03:47:23 +0000 | [diff] [blame] | 901 | case 'c': /* Check for bad blocks */ |
| 902 | case 't': /* deprecated */ |
Theodore Ts'o | 3ed57c2 | 2001-12-24 15:01:59 -0500 | [diff] [blame] | 903 | cflag++; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 904 | break; |
| 905 | case 'f': |
| 906 | size = strtoul(optarg, &tmp, 0); |
Andreas Dilger | 932a489 | 2002-05-16 03:20:07 -0600 | [diff] [blame] | 907 | if (size < EXT2_MIN_BLOCK_SIZE || |
| 908 | size > EXT2_MAX_BLOCK_SIZE || *tmp) { |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 909 | com_err(program_name, 0, |
| 910 | _("bad fragment size - %s"), |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 911 | optarg); |
| 912 | exit(1); |
| 913 | } |
| 914 | param.s_log_frag_size = |
Theodore Ts'o | 6733c2f | 1999-11-23 02:23:30 +0000 | [diff] [blame] | 915 | int_log2(size >> EXT2_MIN_BLOCK_LOG_SIZE); |
Theodore Ts'o | 6693837 | 2002-03-08 00:14:46 -0500 | [diff] [blame] | 916 | fprintf(stderr, _("Warning: fragments not supported. " |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 917 | "Ignoring -f option\n")); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 918 | break; |
| 919 | case 'g': |
| 920 | param.s_blocks_per_group = strtoul(optarg, &tmp, 0); |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 921 | if (*tmp) { |
| 922 | com_err(program_name, 0, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 923 | _("Illegal number for blocks per group")); |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 924 | exit(1); |
| 925 | } |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 926 | if ((param.s_blocks_per_group % 8) != 0) { |
| 927 | com_err(program_name, 0, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 928 | _("blocks per group must be multiple of 8")); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 929 | exit(1); |
| 930 | } |
| 931 | break; |
| 932 | case 'i': |
| 933 | inode_ratio = strtoul(optarg, &tmp, 0); |
Andreas Dilger | 932a489 | 2002-05-16 03:20:07 -0600 | [diff] [blame] | 934 | if (inode_ratio < EXT2_MIN_BLOCK_SIZE || |
| 935 | inode_ratio > EXT2_MAX_BLOCK_SIZE * 1024 || |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 936 | *tmp) { |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 937 | com_err(program_name, 0, |
Andreas Dilger | 932a489 | 2002-05-16 03:20:07 -0600 | [diff] [blame] | 938 | _("bad inode ratio %s (min %d/max %d"), |
| 939 | optarg, EXT2_MIN_BLOCK_SIZE, |
| 940 | EXT2_MAX_BLOCK_SIZE); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 941 | exit(1); |
| 942 | } |
| 943 | break; |
Theodore Ts'o | dc2ec52 | 2001-01-18 01:51:15 +0000 | [diff] [blame] | 944 | case 'J': |
| 945 | parse_journal_opts(optarg); |
| 946 | break; |
Theodore Ts'o | 85ef4ae | 2000-10-24 19:33:45 +0000 | [diff] [blame] | 947 | case 'j': |
Theodore Ts'o | 14bbcbc | 2001-05-13 22:58:27 +0000 | [diff] [blame] | 948 | param.s_feature_compat |= |
| 949 | EXT3_FEATURE_COMPAT_HAS_JOURNAL; |
Theodore Ts'o | dc2ec52 | 2001-01-18 01:51:15 +0000 | [diff] [blame] | 950 | if (!journal_size) |
| 951 | journal_size = -1; |
Theodore Ts'o | 8ddaa66 | 2000-11-17 04:55:24 +0000 | [diff] [blame] | 952 | break; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 953 | case 'l': |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 954 | bad_blocks_filename = malloc(strlen(optarg)+1); |
| 955 | if (!bad_blocks_filename) { |
| 956 | com_err(program_name, ENOMEM, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 957 | _("in malloc for bad_blocks_filename")); |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 958 | exit(1); |
| 959 | } |
| 960 | strcpy(bad_blocks_filename, optarg); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 961 | break; |
| 962 | case 'm': |
| 963 | reserved_ratio = strtoul(optarg, &tmp, 0); |
| 964 | if (reserved_ratio > 50 || *tmp) { |
| 965 | com_err(program_name, 0, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 966 | _("bad reserved blocks percent - %s"), |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 967 | optarg); |
| 968 | exit(1); |
| 969 | } |
| 970 | break; |
Theodore Ts'o | 50787ea | 1999-07-19 15:30:21 +0000 | [diff] [blame] | 971 | case 'n': |
| 972 | noaction++; |
| 973 | break; |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 974 | case 'o': |
| 975 | creator_os = optarg; |
| 976 | break; |
Theodore Ts'o | 7f88b04 | 1997-04-26 14:48:50 +0000 | [diff] [blame] | 977 | case 'r': |
| 978 | param.s_rev_level = atoi(optarg); |
Theodore Ts'o | 14bbcbc | 2001-05-13 22:58:27 +0000 | [diff] [blame] | 979 | if (param.s_rev_level == EXT2_GOOD_OLD_REV) { |
Theodore Ts'o | f3561ed | 2001-08-15 11:58:16 -0400 | [diff] [blame] | 980 | param.s_feature_incompat = 0; |
| 981 | param.s_feature_compat = 0; |
| 982 | param.s_feature_ro_compat = 0; |
Theodore Ts'o | 14bbcbc | 2001-05-13 22:58:27 +0000 | [diff] [blame] | 983 | } |
Theodore Ts'o | 7f88b04 | 1997-04-26 14:48:50 +0000 | [diff] [blame] | 984 | break; |
Theodore Ts'o | b10fd5e | 2001-04-22 03:47:23 +0000 | [diff] [blame] | 985 | case 's': /* deprecated */ |
Theodore Ts'o | f3561ed | 2001-08-15 11:58:16 -0400 | [diff] [blame] | 986 | if (atoi(optarg)) |
| 987 | param.s_feature_ro_compat |= |
| 988 | EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER; |
| 989 | else |
| 990 | param.s_feature_ro_compat &= |
| 991 | ~EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER; |
Theodore Ts'o | 521e368 | 1997-04-29 17:48:10 +0000 | [diff] [blame] | 992 | break; |
Theodore Ts'o | 7f88b04 | 1997-04-26 14:48:50 +0000 | [diff] [blame] | 993 | #ifdef EXT2_DYNAMIC_REV |
| 994 | case 'I': |
Andreas Dilger | 932a489 | 2002-05-16 03:20:07 -0600 | [diff] [blame] | 995 | inode_size = strtoul(optarg, &tmp, 0); |
| 996 | if (*tmp) { |
| 997 | com_err(program_name, 0, |
| 998 | _("bad inode size - %s"), optarg); |
| 999 | exit(1); |
| 1000 | } |
Theodore Ts'o | 7f88b04 | 1997-04-26 14:48:50 +0000 | [diff] [blame] | 1001 | break; |
| 1002 | #endif |
Theodore Ts'o | 5515e6b | 1999-01-05 07:25:06 +0000 | [diff] [blame] | 1003 | case 'N': |
| 1004 | num_inodes = atoi(optarg); |
| 1005 | break; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1006 | case 'v': |
| 1007 | verbose = 1; |
| 1008 | break; |
| 1009 | case 'q': |
| 1010 | quiet = 1; |
| 1011 | break; |
Theodore Ts'o | 74becf3 | 1997-04-26 14:37:06 +0000 | [diff] [blame] | 1012 | case 'F': |
| 1013 | force = 1; |
| 1014 | break; |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 1015 | case 'L': |
| 1016 | volume_label = optarg; |
| 1017 | break; |
| 1018 | case 'M': |
| 1019 | mount_dir = optarg; |
| 1020 | break; |
Theodore Ts'o | 896938d | 1999-10-23 01:04:50 +0000 | [diff] [blame] | 1021 | case 'O': |
Theodore Ts'o | f3561ed | 2001-08-15 11:58:16 -0400 | [diff] [blame] | 1022 | if (!strcmp(optarg, "none") || default_features) { |
| 1023 | param.s_feature_compat = 0; |
| 1024 | param.s_feature_incompat = 0; |
| 1025 | param.s_feature_ro_compat = 0; |
| 1026 | default_features = 0; |
| 1027 | } |
| 1028 | if (!strcmp(optarg, "none")) |
| 1029 | break; |
| 1030 | if (e2p_edit_feature(optarg, |
| 1031 | ¶m.s_feature_compat, |
| 1032 | ok_features)) { |
| 1033 | fprintf(stderr, |
| 1034 | _("Invalid filesystem option set: %s\n"), optarg); |
| 1035 | exit(1); |
| 1036 | } |
Theodore Ts'o | 896938d | 1999-10-23 01:04:50 +0000 | [diff] [blame] | 1037 | break; |
Theodore Ts'o | a29f4d3 | 1997-04-29 21:26:48 +0000 | [diff] [blame] | 1038 | case 'R': |
| 1039 | raid_opts = optarg; |
| 1040 | break; |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 1041 | case 'S': |
| 1042 | super_only = 1; |
| 1043 | break; |
Theodore Ts'o | 50787ea | 1999-07-19 15:30:21 +0000 | [diff] [blame] | 1044 | case 'T': |
| 1045 | fs_type = optarg; |
| 1046 | break; |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 1047 | case 'V': |
| 1048 | /* Print version number and exit */ |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 1049 | fprintf(stderr, _("\tUsing %s\n"), |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 1050 | error_message(EXT2_ET_BASE)); |
| 1051 | exit(0); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1052 | default: |
| 1053 | usage(); |
| 1054 | } |
| 1055 | if (optind == argc) |
| 1056 | usage(); |
| 1057 | device_name = argv[optind]; |
| 1058 | optind++; |
| 1059 | if (optind < argc) { |
Theodore Ts'o | e1a0a3e | 2000-02-11 05:00:19 +0000 | [diff] [blame] | 1060 | unsigned long tmp2 = strtoul(argv[optind++], &tmp, 0); |
| 1061 | |
| 1062 | if ((*tmp) || (tmp2 > 0xfffffffful)) { |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 1063 | com_err(program_name, 0, _("bad blocks count - %s"), |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1064 | argv[optind - 1]); |
| 1065 | exit(1); |
| 1066 | } |
Theodore Ts'o | e1a0a3e | 2000-02-11 05:00:19 +0000 | [diff] [blame] | 1067 | param.s_blocks_count = tmp2; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1068 | } |
| 1069 | if (optind < argc) |
| 1070 | usage(); |
Theodore Ts'o | a418d3a | 1997-04-26 14:00:26 +0000 | [diff] [blame] | 1071 | |
Theodore Ts'o | 3879857 | 2003-04-16 15:29:39 -0400 | [diff] [blame] | 1072 | if (!quiet) |
| 1073 | fprintf (stderr, "mke2fs %s (%s)\n", E2FSPROGS_VERSION, |
| 1074 | E2FSPROGS_DATE); |
| 1075 | |
Theodore Ts'o | a29f4d3 | 1997-04-29 21:26:48 +0000 | [diff] [blame] | 1076 | if (raid_opts) |
| 1077 | parse_raid_opts(raid_opts); |
| 1078 | |
Theodore Ts'o | 77dc4eb | 2001-07-27 22:00:18 -0400 | [diff] [blame] | 1079 | /* |
| 1080 | * If there's no blocksize specified and there is a journal |
| 1081 | * device, use it to figure out the blocksize |
| 1082 | */ |
Theodore Ts'o | c5290fa | 2003-04-11 22:10:50 -0400 | [diff] [blame] | 1083 | if (blocksize <= 0 && journal_device) { |
Theodore Ts'o | 77dc4eb | 2001-07-27 22:00:18 -0400 | [diff] [blame] | 1084 | ext2_filsys jfs; |
Theodore Ts'o | a7ccdff | 2003-07-08 18:03:48 -0400 | [diff] [blame] | 1085 | io_manager io_ptr; |
Theodore Ts'o | 77dc4eb | 2001-07-27 22:00:18 -0400 | [diff] [blame] | 1086 | |
Theodore Ts'o | a7ccdff | 2003-07-08 18:03:48 -0400 | [diff] [blame] | 1087 | #ifdef CONFIG_TESTIO_DEBUG |
| 1088 | io_ptr = test_io_manager; |
| 1089 | test_io_backing_manager = unix_io_manager; |
| 1090 | #else |
| 1091 | io_ptr = unix_io_manager; |
| 1092 | #endif |
Theodore Ts'o | 77dc4eb | 2001-07-27 22:00:18 -0400 | [diff] [blame] | 1093 | retval = ext2fs_open(journal_device, |
| 1094 | EXT2_FLAG_JOURNAL_DEV_OK, 0, |
Theodore Ts'o | a7ccdff | 2003-07-08 18:03:48 -0400 | [diff] [blame] | 1095 | 0, io_ptr, &jfs); |
Theodore Ts'o | 77dc4eb | 2001-07-27 22:00:18 -0400 | [diff] [blame] | 1096 | if (retval) { |
| 1097 | com_err(program_name, retval, |
| 1098 | _("while trying to open journal device %s\n"), |
| 1099 | journal_device); |
| 1100 | exit(1); |
| 1101 | } |
Theodore Ts'o | c5290fa | 2003-04-11 22:10:50 -0400 | [diff] [blame] | 1102 | if ((blocksize < 0) && (jfs->blocksize < -blocksize)) { |
| 1103 | com_err(program_name, 0, |
Theodore Ts'o | ddc32a0 | 2003-05-03 18:45:55 -0400 | [diff] [blame] | 1104 | _("Journal dev blocksize (%d) smaller than " |
Theodore Ts'o | c5290fa | 2003-04-11 22:10:50 -0400 | [diff] [blame] | 1105 | "minimum blocksize %d\n"), jfs->blocksize, |
| 1106 | -blocksize); |
| 1107 | exit(1); |
| 1108 | } |
Theodore Ts'o | 77dc4eb | 2001-07-27 22:00:18 -0400 | [diff] [blame] | 1109 | blocksize = jfs->blocksize; |
| 1110 | param.s_log_block_size = |
| 1111 | int_log2(blocksize >> EXT2_MIN_BLOCK_LOG_SIZE); |
| 1112 | ext2fs_close(jfs); |
| 1113 | } |
Theodore Ts'o | dc2ec52 | 2001-01-18 01:51:15 +0000 | [diff] [blame] | 1114 | |
Theodore Ts'o | 31e29a1 | 2002-05-17 10:53:07 -0400 | [diff] [blame] | 1115 | if (blocksize > sys_page_size) { |
Andreas Dilger | 932a489 | 2002-05-16 03:20:07 -0600 | [diff] [blame] | 1116 | if (!force) { |
| 1117 | com_err(program_name, 0, |
| 1118 | _("%d-byte blocks too big for system (max %d)"), |
Theodore Ts'o | 31e29a1 | 2002-05-17 10:53:07 -0400 | [diff] [blame] | 1119 | blocksize, sys_page_size); |
Andreas Dilger | 932a489 | 2002-05-16 03:20:07 -0600 | [diff] [blame] | 1120 | proceed_question(); |
| 1121 | } |
| 1122 | fprintf(stderr, _("Warning: %d-byte blocks too big for system " |
| 1123 | "(max %d), forced to continue\n"), |
Theodore Ts'o | 31e29a1 | 2002-05-17 10:53:07 -0400 | [diff] [blame] | 1124 | blocksize, sys_page_size); |
Andreas Dilger | 932a489 | 2002-05-16 03:20:07 -0600 | [diff] [blame] | 1125 | } |
Theodore Ts'o | cf7d5f1 | 2003-07-25 17:39:51 -0400 | [diff] [blame] | 1126 | if ((blocksize > 4096) && |
| 1127 | (param.s_feature_compat & EXT3_FEATURE_COMPAT_HAS_JOURNAL)) |
| 1128 | fprintf(stderr, "\nWarning: some 2.4 kernels do not support " |
| 1129 | "blocksizes greater than 4096 \n\tusing ext3." |
| 1130 | " Use -b 4096 if this is an issue for you.\n\n"); |
Andreas Dilger | 932a489 | 2002-05-16 03:20:07 -0600 | [diff] [blame] | 1131 | |
Andreas Dilger | fa72458 | 2001-08-04 01:18:34 -0600 | [diff] [blame] | 1132 | if (param.s_feature_incompat & EXT3_FEATURE_INCOMPAT_JOURNAL_DEV) { |
| 1133 | if (!fs_type) |
| 1134 | fs_type = "journal"; |
| 1135 | reserved_ratio = 0; |
Theodore Ts'o | f3561ed | 2001-08-15 11:58:16 -0400 | [diff] [blame] | 1136 | param.s_feature_incompat = EXT3_FEATURE_INCOMPAT_JOURNAL_DEV; |
| 1137 | param.s_feature_compat = 0; |
| 1138 | param.s_feature_ro_compat = 0; |
| 1139 | } |
Theodore Ts'o | 14bbcbc | 2001-05-13 22:58:27 +0000 | [diff] [blame] | 1140 | if (param.s_rev_level == EXT2_GOOD_OLD_REV && |
| 1141 | (param.s_feature_compat || param.s_feature_ro_compat || |
| 1142 | param.s_feature_incompat)) |
| 1143 | param.s_rev_level = 1; /* Create a revision 1 filesystem */ |
| 1144 | |
Theodore Ts'o | 74becf3 | 1997-04-26 14:37:06 +0000 | [diff] [blame] | 1145 | if (!force) |
Theodore Ts'o | 8ddaa66 | 2000-11-17 04:55:24 +0000 | [diff] [blame] | 1146 | check_plausibility(device_name); |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 1147 | check_mount(device_name, force, _("filesystem")); |
Theodore Ts'o | a418d3a | 1997-04-26 14:00:26 +0000 | [diff] [blame] | 1148 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1149 | param.s_log_frag_size = param.s_log_block_size; |
| 1150 | |
Theodore Ts'o | 50787ea | 1999-07-19 15:30:21 +0000 | [diff] [blame] | 1151 | if (noaction && param.s_blocks_count) { |
| 1152 | dev_size = param.s_blocks_count; |
| 1153 | retval = 0; |
| 1154 | } else |
| 1155 | retval = ext2fs_get_device_size(device_name, |
| 1156 | EXT2_BLOCK_SIZE(¶m), |
| 1157 | &dev_size); |
Theodore Ts'o | a789d84 | 1998-03-30 01:20:55 +0000 | [diff] [blame] | 1158 | if (retval && (retval != EXT2_ET_UNIMPLEMENTED)) { |
| 1159 | com_err(program_name, retval, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 1160 | _("while trying to determine filesystem size")); |
Theodore Ts'o | a789d84 | 1998-03-30 01:20:55 +0000 | [diff] [blame] | 1161 | exit(1); |
| 1162 | } |
Theodore Ts'o | a418d3a | 1997-04-26 14:00:26 +0000 | [diff] [blame] | 1163 | if (!param.s_blocks_count) { |
Theodore Ts'o | a789d84 | 1998-03-30 01:20:55 +0000 | [diff] [blame] | 1164 | if (retval == EXT2_ET_UNIMPLEMENTED) { |
| 1165 | com_err(program_name, 0, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 1166 | _("Couldn't determine device size; you " |
Theodore Ts'o | a789d84 | 1998-03-30 01:20:55 +0000 | [diff] [blame] | 1167 | "must specify\nthe size of the " |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 1168 | "filesystem\n")); |
Theodore Ts'o | a418d3a | 1997-04-26 14:00:26 +0000 | [diff] [blame] | 1169 | exit(1); |
Theodore Ts'o | 26ab531 | 2000-05-29 15:05:42 +0000 | [diff] [blame] | 1170 | } else { |
| 1171 | if (dev_size == 0) { |
| 1172 | com_err(program_name, 0, |
| 1173 | _("Device size reported to be zero. " |
| 1174 | "Invalid partition specified, or\n\t" |
| 1175 | "partition table wasn't reread " |
| 1176 | "after running fdisk, due to\n\t" |
| 1177 | "a modified partition being busy " |
| 1178 | "and in use. You may need to reboot\n\t" |
| 1179 | "to re-read your partition table.\n" |
| 1180 | )); |
| 1181 | exit(1); |
| 1182 | } |
Theodore Ts'o | a789d84 | 1998-03-30 01:20:55 +0000 | [diff] [blame] | 1183 | param.s_blocks_count = dev_size; |
Theodore Ts'o | a7ccdff | 2003-07-08 18:03:48 -0400 | [diff] [blame] | 1184 | if (sys_page_size > EXT2_BLOCK_SIZE(¶m)) |
| 1185 | param.s_blocks_count &= ~((sys_page_size / |
| 1186 | EXT2_BLOCK_SIZE(¶m))-1); |
Theodore Ts'o | 26ab531 | 2000-05-29 15:05:42 +0000 | [diff] [blame] | 1187 | } |
| 1188 | |
Theodore Ts'o | a789d84 | 1998-03-30 01:20:55 +0000 | [diff] [blame] | 1189 | } else if (!force && (param.s_blocks_count > dev_size)) { |
| 1190 | com_err(program_name, 0, |
Theodore Ts'o | c5290fa | 2003-04-11 22:10:50 -0400 | [diff] [blame] | 1191 | _("Filesystem larger than apparent device size.")); |
Theodore Ts'o | a789d84 | 1998-03-30 01:20:55 +0000 | [diff] [blame] | 1192 | proceed_question(); |
Theodore Ts'o | a418d3a | 1997-04-26 14:00:26 +0000 | [diff] [blame] | 1193 | } |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1194 | |
Theodore Ts'o | dc2ec52 | 2001-01-18 01:51:15 +0000 | [diff] [blame] | 1195 | /* |
| 1196 | * If the user asked for HAS_JOURNAL, then make sure a journal |
| 1197 | * gets created. |
| 1198 | */ |
| 1199 | if ((param.s_feature_compat & EXT3_FEATURE_COMPAT_HAS_JOURNAL) && |
| 1200 | !journal_size) |
| 1201 | journal_size = -1; |
Theodore Ts'o | 77dc4eb | 2001-07-27 22:00:18 -0400 | [diff] [blame] | 1202 | |
Theodore Ts'o | c046ac7 | 2002-10-20 00:38:57 -0400 | [diff] [blame] | 1203 | /* Set first meta blockgroup via an environment variable */ |
| 1204 | /* (this is mostly for debugging purposes) */ |
| 1205 | if ((param.s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG) && |
| 1206 | ((tmp = getenv("MKE2FS_FIRST_META_BG")))) |
| 1207 | param.s_first_meta_bg = atoi(tmp); |
| 1208 | |
Theodore Ts'o | 93d5c38 | 2003-05-21 17:28:29 -0400 | [diff] [blame] | 1209 | /* Get the hardware sector size, if available */ |
| 1210 | retval = ext2fs_get_device_sectsize(device_name, §or_size); |
| 1211 | if (retval) { |
| 1212 | com_err(program_name, retval, |
| 1213 | _("while trying to determine hardware sector size")); |
| 1214 | exit(1); |
| 1215 | } |
| 1216 | |
| 1217 | set_fs_defaults(fs_type, ¶m, blocksize, sector_size, &inode_ratio); |
Theodore Ts'o | c5290fa | 2003-04-11 22:10:50 -0400 | [diff] [blame] | 1218 | blocksize = EXT2_BLOCK_SIZE(¶m); |
| 1219 | |
Theodore Ts'o | 521e368 | 1997-04-29 17:48:10 +0000 | [diff] [blame] | 1220 | if (param.s_blocks_per_group) { |
| 1221 | if (param.s_blocks_per_group < 256 || |
Theodore Ts'o | c5290fa | 2003-04-11 22:10:50 -0400 | [diff] [blame] | 1222 | param.s_blocks_per_group > 8 * blocksize) { |
Theodore Ts'o | 521e368 | 1997-04-29 17:48:10 +0000 | [diff] [blame] | 1223 | com_err(program_name, 0, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 1224 | _("blocks per group count out of range")); |
Theodore Ts'o | 521e368 | 1997-04-29 17:48:10 +0000 | [diff] [blame] | 1225 | exit(1); |
| 1226 | } |
| 1227 | } |
| 1228 | |
Andreas Dilger | 932a489 | 2002-05-16 03:20:07 -0600 | [diff] [blame] | 1229 | if (inode_size) { |
| 1230 | if (inode_size < EXT2_GOOD_OLD_INODE_SIZE || |
| 1231 | inode_size > EXT2_BLOCK_SIZE(¶m) || |
| 1232 | inode_size & (inode_size - 1)) { |
| 1233 | com_err(program_name, 0, |
| 1234 | _("bad inode size %d (min %d/max %d)"), |
| 1235 | inode_size, EXT2_GOOD_OLD_INODE_SIZE, |
Theodore Ts'o | c5290fa | 2003-04-11 22:10:50 -0400 | [diff] [blame] | 1236 | blocksize); |
Andreas Dilger | 932a489 | 2002-05-16 03:20:07 -0600 | [diff] [blame] | 1237 | exit(1); |
| 1238 | } |
| 1239 | if (inode_size != EXT2_GOOD_OLD_INODE_SIZE) |
| 1240 | fprintf(stderr, _("Warning: %d-byte inodes not usable " |
| 1241 | "on most systems\n"), |
| 1242 | inode_size); |
| 1243 | param.s_inode_size = inode_size; |
| 1244 | } |
| 1245 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1246 | /* |
| 1247 | * Calculate number of inodes based on the inode ratio |
| 1248 | */ |
Theodore Ts'o | 5515e6b | 1999-01-05 07:25:06 +0000 | [diff] [blame] | 1249 | param.s_inodes_count = num_inodes ? num_inodes : |
Theodore Ts'o | c5290fa | 2003-04-11 22:10:50 -0400 | [diff] [blame] | 1250 | ((__u64) param.s_blocks_count * blocksize) |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 1251 | / inode_ratio; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1252 | |
| 1253 | /* |
| 1254 | * Calculate number of blocks to reserve |
| 1255 | */ |
| 1256 | param.s_r_blocks_count = (param.s_blocks_count * reserved_ratio) / 100; |
Theodore Ts'o | 521e368 | 1997-04-29 17:48:10 +0000 | [diff] [blame] | 1257 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1258 | } |
| 1259 | |
| 1260 | int main (int argc, char *argv[]) |
| 1261 | { |
| 1262 | errcode_t retval = 0; |
| 1263 | ext2_filsys fs; |
| 1264 | badblocks_list bb_list = 0; |
Theodore Ts'o | 85ef4ae | 2000-10-24 19:33:45 +0000 | [diff] [blame] | 1265 | int journal_blocks; |
Theodore Ts'o | 44c09c0 | 2001-01-14 17:02:09 +0000 | [diff] [blame] | 1266 | int i, val; |
Theodore Ts'o | a7ccdff | 2003-07-08 18:03:48 -0400 | [diff] [blame] | 1267 | io_manager io_ptr; |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 1268 | |
| 1269 | #ifdef ENABLE_NLS |
| 1270 | setlocale(LC_MESSAGES, ""); |
Theodore Ts'o | 14308a5 | 2002-03-05 03:26:52 -0500 | [diff] [blame] | 1271 | setlocale(LC_CTYPE, ""); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 1272 | bindtextdomain(NLS_CAT_NAME, LOCALEDIR); |
| 1273 | textdomain(NLS_CAT_NAME); |
| 1274 | #endif |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1275 | PRS(argc, argv); |
| 1276 | |
Theodore Ts'o | a7ccdff | 2003-07-08 18:03:48 -0400 | [diff] [blame] | 1277 | #ifdef CONFIG_TESTIO_DEBUG |
| 1278 | io_ptr = test_io_manager; |
| 1279 | test_io_backing_manager = unix_io_manager; |
| 1280 | #else |
| 1281 | io_ptr = unix_io_manager; |
| 1282 | #endif |
| 1283 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1284 | /* |
| 1285 | * Initialize the superblock.... |
| 1286 | */ |
| 1287 | retval = ext2fs_initialize(device_name, 0, ¶m, |
Theodore Ts'o | a7ccdff | 2003-07-08 18:03:48 -0400 | [diff] [blame] | 1288 | io_ptr, &fs); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1289 | if (retval) { |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 1290 | com_err(device_name, retval, _("while setting up superblock")); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1291 | exit(1); |
| 1292 | } |
| 1293 | |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 1294 | /* |
Theodore Ts'o | e41784e | 2000-08-14 14:44:15 +0000 | [diff] [blame] | 1295 | * Wipe out the old on-disk superblock |
| 1296 | */ |
Theodore Ts'o | 04a9685 | 2001-08-30 21:55:26 -0400 | [diff] [blame] | 1297 | if (!noaction) |
| 1298 | zap_sector(fs, 2, 6); |
Theodore Ts'o | e41784e | 2000-08-14 14:44:15 +0000 | [diff] [blame] | 1299 | |
| 1300 | /* |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 1301 | * Generate a UUID for it... |
| 1302 | */ |
Theodore Ts'o | ef9abe5 | 2001-01-01 15:31:53 +0000 | [diff] [blame] | 1303 | uuid_generate(fs->super->s_uuid); |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 1304 | |
| 1305 | /* |
Theodore Ts'o | 843049c | 2002-09-22 15:37:40 -0400 | [diff] [blame] | 1306 | * Initialize the directory index variables |
| 1307 | */ |
| 1308 | fs->super->s_def_hash_version = EXT2_HASH_TEA; |
| 1309 | uuid_generate((unsigned char *) fs->super->s_hash_seed); |
| 1310 | |
| 1311 | /* |
Theodore Ts'o | 44c09c0 | 2001-01-14 17:02:09 +0000 | [diff] [blame] | 1312 | * Add "jitter" to the superblock's check interval so that we |
| 1313 | * don't check all the filesystems at the same time. We use a |
| 1314 | * kludgy hack of using the UUID to derive a random jitter value. |
| 1315 | */ |
| 1316 | for (i = 0, val = 0 ; i < sizeof(fs->super->s_uuid); i++) |
| 1317 | val += fs->super->s_uuid[i]; |
| 1318 | fs->super->s_max_mnt_count += val % EXT2_DFL_MAX_MNT_COUNT; |
| 1319 | |
| 1320 | /* |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 1321 | * Override the creator OS, if applicable |
| 1322 | */ |
| 1323 | if (creator_os && !set_os(fs->super, creator_os)) { |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 1324 | com_err (program_name, 0, _("unknown os - %s"), creator_os); |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 1325 | exit(1); |
| 1326 | } |
| 1327 | |
| 1328 | /* |
Theodore Ts'o | 4ea0a11 | 2000-05-08 13:33:17 +0000 | [diff] [blame] | 1329 | * For the Hurd, we will turn off filetype since it doesn't |
| 1330 | * support it. |
| 1331 | */ |
| 1332 | if (fs->super->s_creator_os == EXT2_OS_HURD) |
| 1333 | fs->super->s_feature_incompat &= |
| 1334 | ~EXT2_FEATURE_INCOMPAT_FILETYPE; |
| 1335 | |
| 1336 | /* |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 1337 | * Set the volume label... |
| 1338 | */ |
| 1339 | if (volume_label) { |
Theodore Ts'o | ef9abe5 | 2001-01-01 15:31:53 +0000 | [diff] [blame] | 1340 | memset(fs->super->s_volume_name, 0, |
| 1341 | sizeof(fs->super->s_volume_name)); |
| 1342 | strncpy(fs->super->s_volume_name, volume_label, |
| 1343 | sizeof(fs->super->s_volume_name)); |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 1344 | } |
| 1345 | |
| 1346 | /* |
| 1347 | * Set the last mount directory |
| 1348 | */ |
| 1349 | if (mount_dir) { |
Theodore Ts'o | ef9abe5 | 2001-01-01 15:31:53 +0000 | [diff] [blame] | 1350 | memset(fs->super->s_last_mounted, 0, |
| 1351 | sizeof(fs->super->s_last_mounted)); |
| 1352 | strncpy(fs->super->s_last_mounted, mount_dir, |
| 1353 | sizeof(fs->super->s_last_mounted)); |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 1354 | } |
| 1355 | |
Theodore Ts'o | 50787ea | 1999-07-19 15:30:21 +0000 | [diff] [blame] | 1356 | if (!quiet || noaction) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1357 | show_stats(fs); |
| 1358 | |
Theodore Ts'o | 50787ea | 1999-07-19 15:30:21 +0000 | [diff] [blame] | 1359 | if (noaction) |
| 1360 | exit(0); |
| 1361 | |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 1362 | if (fs->super->s_feature_incompat & |
| 1363 | EXT3_FEATURE_INCOMPAT_JOURNAL_DEV) { |
| 1364 | create_journal_dev(fs); |
Andreas Dilger | 568101f | 2001-10-13 01:22:25 -0600 | [diff] [blame] | 1365 | exit(ext2fs_close(fs) ? 1 : 0); |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 1366 | } |
| 1367 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1368 | if (bad_blocks_filename) |
| 1369 | read_bb_file(fs, &bb_list, bad_blocks_filename); |
| 1370 | if (cflag) |
| 1371 | test_disk(fs, &bb_list); |
| 1372 | |
| 1373 | handle_bad_blocks(fs, bb_list); |
Theodore Ts'o | a29f4d3 | 1997-04-29 21:26:48 +0000 | [diff] [blame] | 1374 | fs->stride = fs_stride; |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 1375 | retval = ext2fs_allocate_tables(fs); |
| 1376 | if (retval) { |
| 1377 | com_err(program_name, retval, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 1378 | _("while trying to allocate filesystem tables")); |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 1379 | exit(1); |
| 1380 | } |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 1381 | if (super_only) { |
| 1382 | fs->super->s_state |= EXT2_ERROR_FS; |
| 1383 | fs->flags &= ~(EXT2_FLAG_IB_DIRTY|EXT2_FLAG_BB_DIRTY); |
| 1384 | } else { |
Andreas Dilger | 59f2724 | 2001-08-30 15:39:04 -0600 | [diff] [blame] | 1385 | /* rsv must be a power of two (64kB is MD RAID sb alignment) */ |
Theodore Ts'o | 04a9685 | 2001-08-30 21:55:26 -0400 | [diff] [blame] | 1386 | int rsv = 65536 / fs->blocksize; |
Theodore Ts'o | 1400bbb | 2001-05-14 04:19:25 +0000 | [diff] [blame] | 1387 | unsigned long blocks = fs->super->s_blocks_count; |
Andreas Dilger | 59f2724 | 2001-08-30 15:39:04 -0600 | [diff] [blame] | 1388 | unsigned long start; |
Theodore Ts'o | 1400bbb | 2001-05-14 04:19:25 +0000 | [diff] [blame] | 1389 | blk_t ret_blk; |
| 1390 | |
| 1391 | #ifdef ZAP_BOOTBLOCK |
Theodore Ts'o | 04a9685 | 2001-08-30 21:55:26 -0400 | [diff] [blame] | 1392 | zap_sector(fs, 0, 2); |
Theodore Ts'o | 1400bbb | 2001-05-14 04:19:25 +0000 | [diff] [blame] | 1393 | #endif |
Andreas Dilger | 59f2724 | 2001-08-30 15:39:04 -0600 | [diff] [blame] | 1394 | |
| 1395 | /* |
Theodore Ts'o | 1400bbb | 2001-05-14 04:19:25 +0000 | [diff] [blame] | 1396 | * Wipe out any old MD RAID (or other) metadata at the end |
| 1397 | * of the device. This will also verify that the device is |
Andreas Dilger | 59f2724 | 2001-08-30 15:39:04 -0600 | [diff] [blame] | 1398 | * as large as we think. Be careful with very small devices. |
Theodore Ts'o | 1400bbb | 2001-05-14 04:19:25 +0000 | [diff] [blame] | 1399 | */ |
Andreas Dilger | 59f2724 | 2001-08-30 15:39:04 -0600 | [diff] [blame] | 1400 | start = (blocks & ~(rsv - 1)); |
| 1401 | if (start > rsv) |
| 1402 | start -= rsv; |
| 1403 | if (start > 0) |
| 1404 | retval = zero_blocks(fs, start, blocks - start, |
| 1405 | NULL, &ret_blk, NULL); |
| 1406 | |
Theodore Ts'o | 1400bbb | 2001-05-14 04:19:25 +0000 | [diff] [blame] | 1407 | if (retval) { |
| 1408 | com_err(program_name, retval, |
Theodore Ts'o | f044b4d | 2002-08-17 13:32:21 -0400 | [diff] [blame] | 1409 | _("while zeroing block %u at end of filesystem"), |
Theodore Ts'o | 1400bbb | 2001-05-14 04:19:25 +0000 | [diff] [blame] | 1410 | ret_blk); |
Theodore Ts'o | 1400bbb | 2001-05-14 04:19:25 +0000 | [diff] [blame] | 1411 | } |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 1412 | write_inode_tables(fs); |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 1413 | create_root_dir(fs); |
| 1414 | create_lost_and_found(fs); |
| 1415 | reserve_inodes(fs); |
| 1416 | create_bad_block_inode(fs, bb_list); |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 1417 | } |
Theodore Ts'o | 8ddaa66 | 2000-11-17 04:55:24 +0000 | [diff] [blame] | 1418 | |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 1419 | if (journal_device) { |
| 1420 | ext2_filsys jfs; |
| 1421 | |
Theodore Ts'o | 8ddaa66 | 2000-11-17 04:55:24 +0000 | [diff] [blame] | 1422 | if (!force) |
| 1423 | check_plausibility(journal_device); |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 1424 | check_mount(journal_device, force, _("journal")); |
Theodore Ts'o | 8ddaa66 | 2000-11-17 04:55:24 +0000 | [diff] [blame] | 1425 | |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 1426 | retval = ext2fs_open(journal_device, EXT2_FLAG_RW| |
| 1427 | EXT2_FLAG_JOURNAL_DEV_OK, 0, |
| 1428 | fs->blocksize, unix_io_manager, &jfs); |
| 1429 | if (retval) { |
| 1430 | com_err(program_name, retval, |
| 1431 | _("while trying to open journal device %s\n"), |
| 1432 | journal_device); |
| 1433 | exit(1); |
| 1434 | } |
Theodore Ts'o | 93345d1 | 2001-02-17 06:09:50 +0000 | [diff] [blame] | 1435 | if (!quiet) { |
Theodore Ts'o | 77dc4eb | 2001-07-27 22:00:18 -0400 | [diff] [blame] | 1436 | printf(_("Adding journal to device %s: "), |
Theodore Ts'o | 8ddaa66 | 2000-11-17 04:55:24 +0000 | [diff] [blame] | 1437 | journal_device); |
Theodore Ts'o | 93345d1 | 2001-02-17 06:09:50 +0000 | [diff] [blame] | 1438 | fflush(stdout); |
| 1439 | } |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 1440 | retval = ext2fs_add_journal_device(fs, jfs); |
| 1441 | if(retval) { |
Theodore Ts'o | 8ddaa66 | 2000-11-17 04:55:24 +0000 | [diff] [blame] | 1442 | com_err (program_name, retval, |
Theodore Ts'o | 1d08d9b | 2001-04-17 01:01:49 +0000 | [diff] [blame] | 1443 | _("\n\twhile trying to add journal to device %s"), |
Theodore Ts'o | 8ddaa66 | 2000-11-17 04:55:24 +0000 | [diff] [blame] | 1444 | journal_device); |
| 1445 | exit(1); |
| 1446 | } |
| 1447 | if (!quiet) |
| 1448 | printf(_("done\n")); |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 1449 | ext2fs_close(jfs); |
Andreas Dilger | 2d15576 | 2001-08-17 03:48:11 -0600 | [diff] [blame] | 1450 | free(journal_device); |
Theodore Ts'o | 8ddaa66 | 2000-11-17 04:55:24 +0000 | [diff] [blame] | 1451 | } else if (journal_size) { |
Theodore Ts'o | 2537b6d | 2001-03-26 20:07:13 +0000 | [diff] [blame] | 1452 | journal_blocks = figure_journal_size(journal_size, fs); |
Theodore Ts'o | 93345d1 | 2001-02-17 06:09:50 +0000 | [diff] [blame] | 1453 | |
| 1454 | if (!journal_blocks) { |
| 1455 | fs->super->s_feature_compat &= |
| 1456 | ~EXT3_FEATURE_COMPAT_HAS_JOURNAL; |
| 1457 | goto no_journal; |
| 1458 | } |
| 1459 | if (!quiet) { |
Theodore Ts'o | 16ad333 | 2000-12-31 03:21:56 +0000 | [diff] [blame] | 1460 | printf(_("Creating journal (%d blocks): "), |
| 1461 | journal_blocks); |
Theodore Ts'o | 93345d1 | 2001-02-17 06:09:50 +0000 | [diff] [blame] | 1462 | fflush(stdout); |
| 1463 | } |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 1464 | retval = ext2fs_add_journal_inode(fs, journal_blocks, |
| 1465 | journal_flags); |
Theodore Ts'o | 85ef4ae | 2000-10-24 19:33:45 +0000 | [diff] [blame] | 1466 | if (retval) { |
| 1467 | com_err (program_name, retval, |
Theodore Ts'o | 1d08d9b | 2001-04-17 01:01:49 +0000 | [diff] [blame] | 1468 | _("\n\twhile trying to create journal")); |
Theodore Ts'o | 85ef4ae | 2000-10-24 19:33:45 +0000 | [diff] [blame] | 1469 | exit(1); |
| 1470 | } |
| 1471 | if (!quiet) |
| 1472 | printf(_("done\n")); |
| 1473 | } |
Theodore Ts'o | 93345d1 | 2001-02-17 06:09:50 +0000 | [diff] [blame] | 1474 | no_journal: |
| 1475 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1476 | if (!quiet) |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 1477 | printf(_("Writing superblocks and " |
| 1478 | "filesystem accounting information: ")); |
Theodore Ts'o | 5d45d80 | 1999-03-16 19:35:19 +0000 | [diff] [blame] | 1479 | retval = ext2fs_flush(fs); |
| 1480 | if (retval) { |
Theodore Ts'o | 6693837 | 2002-03-08 00:14:46 -0500 | [diff] [blame] | 1481 | fprintf(stderr, |
| 1482 | _("\nWarning, had trouble writing out superblocks.")); |
Theodore Ts'o | 5d45d80 | 1999-03-16 19:35:19 +0000 | [diff] [blame] | 1483 | } |
Theodore Ts'o | 93345d1 | 2001-02-17 06:09:50 +0000 | [diff] [blame] | 1484 | if (!quiet) { |
Theodore Ts'o | 2537b6d | 2001-03-26 20:07:13 +0000 | [diff] [blame] | 1485 | printf(_("done\n\n")); |
Theodore Ts'o | 66cf2f6 | 2001-06-14 06:42:44 +0000 | [diff] [blame] | 1486 | print_check_message(fs); |
Theodore Ts'o | 93345d1 | 2001-02-17 06:09:50 +0000 | [diff] [blame] | 1487 | } |
Andreas Dilger | 568101f | 2001-10-13 01:22:25 -0600 | [diff] [blame] | 1488 | val = ext2fs_close(fs); |
| 1489 | return (retval || val) ? 1 : 0; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1490 | } |