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