Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1 | /* |
Theodore Ts'o | 4d0f228 | 2001-04-23 20:58:03 +0000 | [diff] [blame] | 2 | * tune2fs.c - Change the file system parameters on an ext2 file system |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 1992, 1993, 1994 Remy Card <card@masi.ibp.fr> |
| 5 | * Laboratoire MASI, Institut Blaise Pascal |
| 6 | * Universite Pierre et Marie Curie (Paris VI) |
| 7 | * |
Theodore Ts'o | 4d0f228 | 2001-04-23 20:58:03 +0000 | [diff] [blame] | 8 | * Copyright 1995, 1996, 1997, 1998, 1999, 2000 by Theodore Ts'o. |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 9 | * |
| 10 | * %Begin-Header% |
| 11 | * This file may be redistributed under the terms of the GNU Public |
| 12 | * License. |
| 13 | * %End-Header% |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | /* |
| 17 | * History: |
| 18 | * 93/06/01 - Creation |
| 19 | * 93/10/31 - Added the -c option to change the maximal mount counts |
| 20 | * 93/12/14 - Added -l flag to list contents of superblock |
| 21 | * M.J.E. Mol (marcel@duteca.et.tudelft.nl) |
| 22 | * F.W. ten Wolde (franky@duteca.et.tudelft.nl) |
| 23 | * 93/12/29 - Added the -e option to change errors behavior |
| 24 | * 94/02/27 - Ported to use the ext2fs library |
| 25 | * 94/03/06 - Added the checks interval from Uwe Ohse (uwe@tirka.gun.de) |
| 26 | */ |
| 27 | |
| 28 | #include <fcntl.h> |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 29 | #include <grp.h> |
Theodore Ts'o | a418d3a | 1997-04-26 14:00:26 +0000 | [diff] [blame] | 30 | #ifdef HAVE_GETOPT_H |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 31 | #include <getopt.h> |
Theodore Ts'o | 373b833 | 2000-04-03 16:22:35 +0000 | [diff] [blame] | 32 | #else |
| 33 | extern char *optarg; |
| 34 | extern int optind; |
Theodore Ts'o | a418d3a | 1997-04-26 14:00:26 +0000 | [diff] [blame] | 35 | #endif |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 36 | #include <pwd.h> |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 37 | #include <stdio.h> |
| 38 | #include <stdlib.h> |
| 39 | #include <string.h> |
| 40 | #include <time.h> |
| 41 | #include <unistd.h> |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 42 | #include <sys/types.h> |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 43 | |
Theodore Ts'o | 54c637d | 2001-05-14 11:45:38 +0000 | [diff] [blame] | 44 | #include "ext2fs/ext2_fs.h" |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 45 | #include "ext2fs/ext2fs.h" |
| 46 | #include "et/com_err.h" |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 47 | #include "uuid/uuid.h" |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 48 | #include "e2p/e2p.h" |
Theodore Ts'o | dc2ec52 | 2001-01-18 01:51:15 +0000 | [diff] [blame] | 49 | #include "jfs_user.h" |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 50 | #include "util.h" |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 51 | |
| 52 | #include "../version.h" |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 53 | #include "nls-enable.h" |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 54 | |
| 55 | const char * program_name = "tune2fs"; |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 56 | char * device_name; |
Theodore Ts'o | c8c071a | 2001-01-11 16:08:23 +0000 | [diff] [blame] | 57 | char * new_label, *new_last_mounted, *new_UUID; |
Theodore Ts'o | 4d0f228 | 2001-04-23 20:58:03 +0000 | [diff] [blame] | 58 | static int c_flag, C_flag, e_flag, f_flag, g_flag, i_flag, l_flag, L_flag; |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 59 | static int m_flag, M_flag, r_flag, s_flag = -1, u_flag, U_flag; |
Theodore Ts'o | 8323815 | 2001-01-09 00:16:26 +0000 | [diff] [blame] | 60 | static int print_label; |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 61 | static int max_mount_count, mount_count, mount_flags; |
| 62 | static unsigned long interval, reserved_ratio, reserved_blocks; |
| 63 | static unsigned long resgid, resuid; |
| 64 | static unsigned short errors; |
Theodore Ts'o | 8323815 | 2001-01-09 00:16:26 +0000 | [diff] [blame] | 65 | static int open_flag; |
| 66 | static char *features_cmd; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 67 | |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 68 | int journal_size, journal_flags; |
| 69 | char *journal_device; |
| 70 | |
| 71 | static const char *please_fsck = N_("Please run e2fsck on the filesystem.\n"); |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 72 | |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 73 | static void usage(void) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 74 | { |
Theodore Ts'o | b21e38a | 2001-01-01 15:26:58 +0000 | [diff] [blame] | 75 | fprintf(stderr, |
| 76 | _("Usage: %s [-c max-mounts-count] [-e errors-behavior] " |
| 77 | "[-g group]\n" |
Theodore Ts'o | dc2ec52 | 2001-01-18 01:51:15 +0000 | [diff] [blame] | 78 | "\t[-i interval[d|m|w]] [-j] [-J journal-options]\n" |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 79 | "\t[-l] [-s sparse-flag] [-m reserved-blocks-percent]\n" |
Theodore Ts'o | b21e38a | 2001-01-01 15:26:58 +0000 | [diff] [blame] | 80 | "\t[-r reserved-blocks-count] [-u user] [-C mount-count]\n" |
| 81 | "\t[-L volume-label] [-M last-mounted-dir] [-U UUID]\n" |
| 82 | "\t[-O [^]feature[,...]] device\n"), program_name); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 83 | exit (1); |
| 84 | } |
| 85 | |
Theodore Ts'o | 896938d | 1999-10-23 01:04:50 +0000 | [diff] [blame] | 86 | static __u32 ok_features[3] = { |
Theodore Ts'o | b21e38a | 2001-01-01 15:26:58 +0000 | [diff] [blame] | 87 | EXT3_FEATURE_COMPAT_HAS_JOURNAL, /* Compat */ |
Theodore Ts'o | 896938d | 1999-10-23 01:04:50 +0000 | [diff] [blame] | 88 | EXT2_FEATURE_INCOMPAT_FILETYPE, /* Incompat */ |
| 89 | EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER /* R/O compat */ |
| 90 | }; |
| 91 | |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 92 | /* |
Theodore Ts'o | dc2ec52 | 2001-01-18 01:51:15 +0000 | [diff] [blame] | 93 | * Remove an external journal from the filesystem |
| 94 | */ |
| 95 | static void remove_journal_device(ext2_filsys fs) |
| 96 | { |
| 97 | char *journal_device; |
| 98 | ext2_filsys jfs; |
| 99 | char buf[1024]; |
| 100 | journal_superblock_t *jsb; |
| 101 | int i, nr_users; |
| 102 | errcode_t retval; |
Theodore Ts'o | 4d0f228 | 2001-04-23 20:58:03 +0000 | [diff] [blame] | 103 | int commit_remove_journal = 0; |
| 104 | |
| 105 | if (f_flag) |
| 106 | commit_remove_journal = 1; /* force removal even if error */ |
Theodore Ts'o | dc2ec52 | 2001-01-18 01:51:15 +0000 | [diff] [blame] | 107 | |
| 108 | journal_device = ext2fs_find_block_device(fs->super->s_journal_dev); |
| 109 | if (!journal_device) |
| 110 | return; |
| 111 | |
| 112 | retval = ext2fs_open(journal_device, EXT2_FLAG_RW| |
| 113 | EXT2_FLAG_JOURNAL_DEV_OK, 0, |
| 114 | fs->blocksize, unix_io_manager, &jfs); |
| 115 | if (retval) { |
| 116 | com_err(program_name, retval, |
| 117 | _("while trying to open external journal")); |
Theodore Ts'o | 4d0f228 | 2001-04-23 20:58:03 +0000 | [diff] [blame] | 118 | goto no_valid_journal; |
Theodore Ts'o | dc2ec52 | 2001-01-18 01:51:15 +0000 | [diff] [blame] | 119 | } |
| 120 | if (!(jfs->super->s_feature_incompat & EXT3_FEATURE_INCOMPAT_JOURNAL_DEV)) { |
| 121 | fprintf(stderr, "%s is not a journal device.\n", |
| 122 | journal_device); |
Theodore Ts'o | 4d0f228 | 2001-04-23 20:58:03 +0000 | [diff] [blame] | 123 | goto no_valid_journal; |
Theodore Ts'o | dc2ec52 | 2001-01-18 01:51:15 +0000 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | /* Get the journal superblock */ |
| 127 | if ((retval = io_channel_read_blk(jfs->io, 1, -1024, buf))) { |
| 128 | com_err(program_name, retval, |
| 129 | _("while reading journal superblock")); |
Theodore Ts'o | 4d0f228 | 2001-04-23 20:58:03 +0000 | [diff] [blame] | 130 | goto no_valid_journal; |
Theodore Ts'o | dc2ec52 | 2001-01-18 01:51:15 +0000 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | jsb = (journal_superblock_t *) buf; |
| 134 | if ((jsb->s_header.h_magic != (unsigned) ntohl(JFS_MAGIC_NUMBER)) || |
| 135 | (jsb->s_header.h_blocktype != (unsigned) ntohl(JFS_SUPERBLOCK_V2))) { |
| 136 | fprintf(stderr, _("Journal superblock not found!\n")); |
Theodore Ts'o | 4d0f228 | 2001-04-23 20:58:03 +0000 | [diff] [blame] | 137 | goto no_valid_journal; |
Theodore Ts'o | dc2ec52 | 2001-01-18 01:51:15 +0000 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | /* Find the filesystem UUID */ |
| 141 | nr_users = ntohl(jsb->s_nr_users); |
| 142 | for (i=0; i < nr_users; i++) { |
| 143 | if (memcmp(fs->super->s_uuid, |
| 144 | &jsb->s_users[i*16], 16) == 0) |
| 145 | break; |
| 146 | } |
| 147 | if (i >= nr_users) { |
| 148 | fprintf(stderr, "Filesystem's UUID not found on journal device.\n"); |
Theodore Ts'o | 4d0f228 | 2001-04-23 20:58:03 +0000 | [diff] [blame] | 149 | commit_remove_journal = 1; |
| 150 | goto no_valid_journal; |
Theodore Ts'o | dc2ec52 | 2001-01-18 01:51:15 +0000 | [diff] [blame] | 151 | } |
| 152 | nr_users--; |
| 153 | for (i=0; i < nr_users; i++) |
| 154 | memcpy(&jsb->s_users[i*16], &jsb->s_users[(i+1)*16], 16); |
| 155 | jsb->s_nr_users = htonl(nr_users); |
| 156 | |
| 157 | /* Write back the journal superblock */ |
| 158 | if ((retval = io_channel_write_blk(jfs->io, 1, -1024, buf))) { |
| 159 | com_err(program_name, retval, |
| 160 | "while writing journal superblock."); |
Theodore Ts'o | 4d0f228 | 2001-04-23 20:58:03 +0000 | [diff] [blame] | 161 | goto no_valid_journal; |
Theodore Ts'o | dc2ec52 | 2001-01-18 01:51:15 +0000 | [diff] [blame] | 162 | } |
| 163 | |
Theodore Ts'o | 4d0f228 | 2001-04-23 20:58:03 +0000 | [diff] [blame] | 164 | commit_remove_journal = 1; |
| 165 | |
| 166 | no_valid_journal: |
| 167 | if (commit_remove_journal == 0) { |
| 168 | printf(_("Journal NOT removed\n")); |
| 169 | exit(1); |
| 170 | } |
Theodore Ts'o | dc2ec52 | 2001-01-18 01:51:15 +0000 | [diff] [blame] | 171 | fs->super->s_journal_dev = 0; |
| 172 | memset(fs->super->s_journal_uuid, 0, |
| 173 | sizeof(fs->super->s_journal_uuid)); |
| 174 | ext2fs_mark_super_dirty(fs); |
Theodore Ts'o | 4d0f228 | 2001-04-23 20:58:03 +0000 | [diff] [blame] | 175 | printf(_("Journal removed\n")); |
Theodore Ts'o | dc2ec52 | 2001-01-18 01:51:15 +0000 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | |
| 179 | /* |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 180 | * Update the feature set as provided by the user. |
| 181 | */ |
Theodore Ts'o | c8c071a | 2001-01-11 16:08:23 +0000 | [diff] [blame] | 182 | static void update_feature_set(ext2_filsys fs, char *features) |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 183 | { |
| 184 | int sparse, old_sparse, filetype, old_filetype; |
| 185 | int journal, old_journal; |
| 186 | struct ext2_inode inode; |
| 187 | struct ext2_super_block *sb= fs->super; |
| 188 | errcode_t retval; |
| 189 | |
| 190 | old_sparse = sb->s_feature_ro_compat & |
| 191 | EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER; |
| 192 | old_filetype = sb->s_feature_incompat & |
| 193 | EXT2_FEATURE_INCOMPAT_FILETYPE; |
| 194 | old_journal = sb->s_feature_compat & |
| 195 | EXT3_FEATURE_COMPAT_HAS_JOURNAL; |
Theodore Ts'o | c8c071a | 2001-01-11 16:08:23 +0000 | [diff] [blame] | 196 | if (e2p_edit_feature(features, &sb->s_feature_compat, |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 197 | ok_features)) { |
| 198 | fprintf(stderr, _("Invalid filesystem option set: %s\n"), |
Theodore Ts'o | c8c071a | 2001-01-11 16:08:23 +0000 | [diff] [blame] | 199 | features); |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 200 | exit(1); |
| 201 | } |
| 202 | sparse = sb->s_feature_ro_compat & |
| 203 | EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER; |
| 204 | filetype = sb->s_feature_incompat & |
| 205 | EXT2_FEATURE_INCOMPAT_FILETYPE; |
| 206 | journal = sb->s_feature_compat & |
| 207 | EXT3_FEATURE_COMPAT_HAS_JOURNAL; |
| 208 | if (old_journal && !journal) { |
| 209 | if ((mount_flags & EXT2_MF_MOUNTED) && |
| 210 | !(mount_flags & EXT2_MF_READONLY)) { |
| 211 | fprintf(stderr, |
Theodore Ts'o | 8d64174 | 2001-05-14 04:12:27 +0000 | [diff] [blame] | 212 | _("The has_journal flag may only be " |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 213 | "cleared when the filesystem is\n" |
| 214 | "unmounted or mounted " |
| 215 | "read-only.\n")); |
| 216 | exit(1); |
| 217 | } |
| 218 | if (sb->s_feature_incompat & |
| 219 | EXT3_FEATURE_INCOMPAT_RECOVER) { |
| 220 | fprintf(stderr, |
Theodore Ts'o | 8d64174 | 2001-05-14 04:12:27 +0000 | [diff] [blame] | 221 | _("The needs_recovery flag is set. " |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 222 | "Please run e2fsck before clearing\n" |
Theodore Ts'o | e549d0a | 2001-05-25 16:38:48 +0000 | [diff] [blame] | 223 | "the has_journal flag.\n")); |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 224 | exit(1); |
| 225 | } |
| 226 | /* |
| 227 | * Remove the immutable flag on the journal inode |
| 228 | */ |
| 229 | if (sb->s_journal_inum) { |
| 230 | retval = ext2fs_read_inode(fs, sb->s_journal_inum, |
| 231 | &inode); |
| 232 | if (retval) { |
| 233 | com_err(program_name, retval, |
| 234 | "while reading journal inode"); |
| 235 | exit(1); |
| 236 | } |
| 237 | inode.i_flags &= ~EXT2_IMMUTABLE_FL; |
| 238 | retval = ext2fs_write_inode(fs, sb->s_journal_inum, |
| 239 | &inode); |
| 240 | if (retval) { |
| 241 | com_err(program_name, retval, |
Theodore Ts'o | 4d0f228 | 2001-04-23 20:58:03 +0000 | [diff] [blame] | 242 | "while writing journal inode"); |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 243 | exit(1); |
| 244 | } |
| 245 | } |
Theodore Ts'o | dc2ec52 | 2001-01-18 01:51:15 +0000 | [diff] [blame] | 246 | if (sb->s_journal_dev) |
| 247 | remove_journal_device(fs); |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 248 | } |
| 249 | if (journal && !old_journal) { |
| 250 | /* |
| 251 | * If adding a journal flag, let the create journal |
| 252 | * code below handle creating setting the flag and |
| 253 | * creating the journal. We supply a default size if |
| 254 | * necessary. |
| 255 | */ |
Theodore Ts'o | dc2ec52 | 2001-01-18 01:51:15 +0000 | [diff] [blame] | 256 | if (!journal_size) |
| 257 | journal_size = -1; |
Theodore Ts'o | 08dd830 | 2001-01-14 16:25:58 +0000 | [diff] [blame] | 258 | sb->s_feature_compat &= ~EXT3_FEATURE_COMPAT_HAS_JOURNAL; |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 259 | journal = old_journal; |
| 260 | } |
Theodore Ts'o | dc2ec52 | 2001-01-18 01:51:15 +0000 | [diff] [blame] | 261 | |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 262 | if (sb->s_rev_level == EXT2_GOOD_OLD_REV && |
| 263 | (sb->s_feature_compat || sb->s_feature_ro_compat || |
| 264 | sb->s_feature_incompat)) |
| 265 | ext2fs_update_dynamic_rev(fs); |
| 266 | if ((sparse != old_sparse) || |
| 267 | (filetype != old_filetype) || |
| 268 | (journal != old_journal)) { |
| 269 | sb->s_state &= ~EXT2_VALID_FS; |
| 270 | printf("\n%s\n", _(please_fsck)); |
| 271 | } |
| 272 | ext2fs_mark_super_dirty(fs); |
| 273 | } |
| 274 | |
| 275 | /* |
| 276 | * Add a journal to the filesystem. |
| 277 | */ |
| 278 | static void add_journal(ext2_filsys fs) |
| 279 | { |
| 280 | unsigned long journal_blocks; |
| 281 | errcode_t retval; |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 282 | ext2_filsys jfs; |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 283 | |
| 284 | if (fs->super->s_feature_compat & |
| 285 | EXT3_FEATURE_COMPAT_HAS_JOURNAL) { |
| 286 | fprintf(stderr, _("The filesystem already has a journal.\n")); |
| 287 | exit(1); |
| 288 | } |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 289 | if (journal_device) { |
| 290 | check_plausibility(journal_device); |
| 291 | check_mount(journal_device, 0, _("journal")); |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 292 | retval = ext2fs_open(journal_device, EXT2_FLAG_RW| |
| 293 | EXT2_FLAG_JOURNAL_DEV_OK, 0, |
| 294 | fs->blocksize, unix_io_manager, &jfs); |
| 295 | if (retval) { |
| 296 | com_err(program_name, retval, |
Theodore Ts'o | 1d08d9b | 2001-04-17 01:01:49 +0000 | [diff] [blame] | 297 | _("\n\twhile trying to open journal on %s\n"), |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 298 | journal_device); |
| 299 | exit(1); |
| 300 | } |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 301 | printf(_("Creating journal on device %s: "), |
| 302 | journal_device); |
Theodore Ts'o | 4055ef7 | 2001-01-14 16:11:14 +0000 | [diff] [blame] | 303 | fflush(stdout); |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 304 | |
| 305 | retval = ext2fs_add_journal_device(fs, jfs); |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 306 | if (retval) { |
| 307 | com_err (program_name, retval, |
Theodore Ts'o | 8d64174 | 2001-05-14 04:12:27 +0000 | [diff] [blame] | 308 | _("while adding filesystem to journal on %s"), |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 309 | journal_device); |
| 310 | exit(1); |
| 311 | } |
| 312 | printf(_("done\n")); |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 313 | ext2fs_close(jfs); |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 314 | } else if (journal_size) { |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 315 | printf(_("Creating journal inode: ")); |
| 316 | fflush(stdout); |
Theodore Ts'o | 2537b6d | 2001-03-26 20:07:13 +0000 | [diff] [blame] | 317 | journal_blocks = figure_journal_size(journal_size, fs); |
| 318 | |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 319 | retval = ext2fs_add_journal_inode(fs, journal_blocks, |
| 320 | journal_flags); |
| 321 | if (retval) { |
| 322 | printf("\n"); |
| 323 | com_err(program_name, retval, |
Theodore Ts'o | 1d08d9b | 2001-04-17 01:01:49 +0000 | [diff] [blame] | 324 | _("\n\twhile trying to create journal file")); |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 325 | exit(1); |
Theodore Ts'o | 1d08d9b | 2001-04-17 01:01:49 +0000 | [diff] [blame] | 326 | } else |
| 327 | printf(_("done\n")); |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 328 | /* |
| 329 | * If the filesystem wasn't mounted, we need to force |
| 330 | * the block group descriptors out. |
| 331 | */ |
| 332 | if ((mount_flags & EXT2_MF_MOUNTED) == 0) |
| 333 | fs->flags &= ~EXT2_FLAG_SUPER_ONLY; |
| 334 | } |
Theodore Ts'o | 66cf2f6 | 2001-06-14 06:42:44 +0000 | [diff] [blame^] | 335 | print_check_message(fs); |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 336 | } |
| 337 | |
Theodore Ts'o | 8323815 | 2001-01-09 00:16:26 +0000 | [diff] [blame] | 338 | /* |
| 339 | * Given argv[0], return the program name. |
| 340 | */ |
Theodore Ts'o | c8c071a | 2001-01-11 16:08:23 +0000 | [diff] [blame] | 341 | static char *get_progname(char *argv_zero) |
Theodore Ts'o | 8323815 | 2001-01-09 00:16:26 +0000 | [diff] [blame] | 342 | { |
| 343 | char *cp; |
| 344 | |
| 345 | cp = strrchr(argv_zero, '/'); |
| 346 | if (!cp ) |
| 347 | return argv_zero; |
| 348 | else |
| 349 | return cp+1; |
| 350 | } |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 351 | |
Theodore Ts'o | 896938d | 1999-10-23 01:04:50 +0000 | [diff] [blame] | 352 | |
Theodore Ts'o | c8c071a | 2001-01-11 16:08:23 +0000 | [diff] [blame] | 353 | static void parse_e2label_options(int argc, char ** argv) |
Theodore Ts'o | 8323815 | 2001-01-09 00:16:26 +0000 | [diff] [blame] | 354 | { |
| 355 | if ((argc < 2) || (argc > 3)) { |
| 356 | fprintf(stderr, _("Usage: e2label device [newlabel]\n")); |
| 357 | exit(1); |
| 358 | } |
| 359 | device_name = argv[1]; |
| 360 | if (argc == 3) { |
| 361 | open_flag = EXT2_FLAG_RW; |
| 362 | L_flag = 1; |
| 363 | new_label = argv[2]; |
| 364 | } else |
| 365 | print_label++; |
| 366 | } |
| 367 | |
| 368 | |
Theodore Ts'o | c8c071a | 2001-01-11 16:08:23 +0000 | [diff] [blame] | 369 | static void parse_tune2fs_options(int argc, char **argv) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 370 | { |
Theodore Ts'o | 519149f | 1997-10-25 03:49:49 +0000 | [diff] [blame] | 371 | int c; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 372 | char * tmp; |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 373 | struct group * gr; |
| 374 | struct passwd * pw; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 375 | |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 376 | fprintf (stderr, _("tune2fs %s, %s for EXT2 FS %s, %s\n"), |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 377 | E2FSPROGS_VERSION, E2FSPROGS_DATE, |
| 378 | EXT2FS_VERSION, EXT2FS_DATE); |
Theodore Ts'o | 4d0f228 | 2001-04-23 20:58:03 +0000 | [diff] [blame] | 379 | while ((c = getopt (argc, argv, "c:e:fg:i:jlm:r:s:u:C:J:L:M:O:U:")) != EOF) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 380 | switch (c) |
| 381 | { |
| 382 | case 'c': |
Theodore Ts'o | 45d9e2f | 2000-07-07 03:12:54 +0000 | [diff] [blame] | 383 | max_mount_count = strtol (optarg, &tmp, 0); |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 384 | if (*tmp || max_mount_count > 16000) { |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 385 | com_err (program_name, 0, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 386 | _("bad mounts count - %s"), |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 387 | optarg); |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 388 | usage(); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 389 | } |
Theodore Ts'o | ce57f14 | 2001-04-26 04:25:39 +0000 | [diff] [blame] | 390 | if (max_mount_count == 0) |
| 391 | max_mount_count = -1; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 392 | c_flag = 1; |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 393 | open_flag = EXT2_FLAG_RW; |
| 394 | break; |
| 395 | case 'C': |
| 396 | mount_count = strtoul (optarg, &tmp, 0); |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 397 | if (*tmp || mount_count > 16000) { |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 398 | com_err (program_name, 0, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 399 | _("bad mounts count - %s"), |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 400 | optarg); |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 401 | usage(); |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 402 | } |
| 403 | C_flag = 1; |
| 404 | open_flag = EXT2_FLAG_RW; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 405 | break; |
| 406 | case 'e': |
| 407 | if (strcmp (optarg, "continue") == 0) |
| 408 | errors = EXT2_ERRORS_CONTINUE; |
| 409 | else if (strcmp (optarg, "remount-ro") == 0) |
| 410 | errors = EXT2_ERRORS_RO; |
| 411 | else if (strcmp (optarg, "panic") == 0) |
| 412 | errors = EXT2_ERRORS_PANIC; |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 413 | else { |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 414 | com_err (program_name, 0, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 415 | _("bad error behavior - %s"), |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 416 | optarg); |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 417 | usage(); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 418 | } |
| 419 | e_flag = 1; |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 420 | open_flag = EXT2_FLAG_RW; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 421 | break; |
Theodore Ts'o | 4d0f228 | 2001-04-23 20:58:03 +0000 | [diff] [blame] | 422 | case 'f': /* Force */ |
| 423 | f_flag = 1; |
| 424 | break; |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 425 | case 'g': |
| 426 | resgid = strtoul (optarg, &tmp, 0); |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 427 | if (*tmp) { |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 428 | gr = getgrnam (optarg); |
| 429 | if (gr == NULL) |
| 430 | tmp = optarg; |
Theodore Ts'o | a418d3a | 1997-04-26 14:00:26 +0000 | [diff] [blame] | 431 | else { |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 432 | resgid = gr->gr_gid; |
Theodore Ts'o | a418d3a | 1997-04-26 14:00:26 +0000 | [diff] [blame] | 433 | *tmp =0; |
| 434 | } |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 435 | } |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 436 | if (*tmp) { |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 437 | com_err (program_name, 0, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 438 | _("bad gid/group name - %s"), |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 439 | optarg); |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 440 | usage(); |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 441 | } |
| 442 | g_flag = 1; |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 443 | open_flag = EXT2_FLAG_RW; |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 444 | break; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 445 | case 'i': |
| 446 | interval = strtoul (optarg, &tmp, 0); |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 447 | switch (*tmp) { |
| 448 | case 's': |
| 449 | tmp++; |
| 450 | break; |
| 451 | case '\0': |
| 452 | case 'd': |
| 453 | case 'D': /* days */ |
| 454 | interval *= 86400; |
| 455 | if (*tmp != '\0') |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 456 | tmp++; |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 457 | break; |
| 458 | case 'm': |
| 459 | case 'M': /* months! */ |
| 460 | interval *= 86400 * 30; |
| 461 | tmp++; |
| 462 | break; |
| 463 | case 'w': |
| 464 | case 'W': /* weeks */ |
| 465 | interval *= 86400 * 7; |
| 466 | tmp++; |
| 467 | break; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 468 | } |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 469 | if (*tmp || interval > (365 * 86400)) { |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 470 | com_err (program_name, 0, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 471 | _("bad interval - %s"), optarg); |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 472 | usage(); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 473 | } |
| 474 | i_flag = 1; |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 475 | open_flag = EXT2_FLAG_RW; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 476 | break; |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 477 | case 'j': |
Theodore Ts'o | dc2ec52 | 2001-01-18 01:51:15 +0000 | [diff] [blame] | 478 | if (!journal_size) |
| 479 | journal_size = -1; |
Theodore Ts'o | 4d0f228 | 2001-04-23 20:58:03 +0000 | [diff] [blame] | 480 | open_flag = EXT2_FLAG_RW; |
Theodore Ts'o | dc2ec52 | 2001-01-18 01:51:15 +0000 | [diff] [blame] | 481 | break; |
| 482 | case 'J': |
| 483 | parse_journal_opts(optarg); |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 484 | open_flag = EXT2_FLAG_RW; |
| 485 | break; |
Theodore Ts'o | 08dd830 | 2001-01-14 16:25:58 +0000 | [diff] [blame] | 486 | case 'l': |
| 487 | l_flag = 1; |
| 488 | break; |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 489 | case 'L': |
| 490 | new_label = optarg; |
| 491 | L_flag = 1; |
| 492 | open_flag = EXT2_FLAG_RW; |
| 493 | break; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 494 | case 'm': |
| 495 | reserved_ratio = strtoul (optarg, &tmp, 0); |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 496 | if (*tmp || reserved_ratio > 50) { |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 497 | com_err (program_name, 0, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 498 | _("bad reserved block ratio - %s"), |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 499 | optarg); |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 500 | usage(); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 501 | } |
| 502 | m_flag = 1; |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 503 | open_flag = EXT2_FLAG_RW; |
| 504 | break; |
| 505 | case 'M': |
| 506 | new_last_mounted = optarg; |
| 507 | M_flag = 1; |
| 508 | open_flag = EXT2_FLAG_RW; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 509 | break; |
Theodore Ts'o | 896938d | 1999-10-23 01:04:50 +0000 | [diff] [blame] | 510 | case 'O': |
| 511 | features_cmd = optarg; |
| 512 | open_flag = EXT2_FLAG_RW; |
| 513 | break; |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 514 | case 'r': |
| 515 | reserved_blocks = strtoul (optarg, &tmp, 0); |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 516 | if (*tmp) { |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 517 | com_err (program_name, 0, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 518 | _("bad reserved blocks count - %s"), |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 519 | optarg); |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 520 | usage(); |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 521 | } |
| 522 | r_flag = 1; |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 523 | open_flag = EXT2_FLAG_RW; |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 524 | break; |
Theodore Ts'o | 521e368 | 1997-04-29 17:48:10 +0000 | [diff] [blame] | 525 | case 's': |
| 526 | s_flag = atoi(optarg); |
| 527 | open_flag = EXT2_FLAG_RW; |
| 528 | break; |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 529 | case 'u': |
| 530 | resuid = strtoul (optarg, &tmp, 0); |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 531 | if (*tmp) { |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 532 | pw = getpwnam (optarg); |
| 533 | if (pw == NULL) |
| 534 | tmp = optarg; |
Theodore Ts'o | a418d3a | 1997-04-26 14:00:26 +0000 | [diff] [blame] | 535 | else { |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 536 | resuid = pw->pw_uid; |
Theodore Ts'o | a418d3a | 1997-04-26 14:00:26 +0000 | [diff] [blame] | 537 | *tmp = 0; |
| 538 | } |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 539 | } |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 540 | if (*tmp) { |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 541 | com_err (program_name, 0, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 542 | _("bad uid/user name - %s"), |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 543 | optarg); |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 544 | usage(); |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 545 | } |
| 546 | u_flag = 1; |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 547 | open_flag = EXT2_FLAG_RW; |
| 548 | break; |
| 549 | case 'U': |
| 550 | new_UUID = optarg; |
| 551 | U_flag = 1; |
| 552 | open_flag = EXT2_FLAG_RW; |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 553 | break; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 554 | default: |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 555 | usage(); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 556 | } |
| 557 | if (optind < argc - 1 || optind == argc) |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 558 | usage(); |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 559 | if (!open_flag && !l_flag) |
| 560 | usage(); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 561 | device_name = argv[optind]; |
Theodore Ts'o | 8323815 | 2001-01-09 00:16:26 +0000 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | |
| 565 | |
| 566 | int main (int argc, char ** argv) |
| 567 | { |
| 568 | errcode_t retval; |
| 569 | ext2_filsys fs; |
| 570 | struct ext2_super_block *sb; |
| 571 | |
| 572 | #ifdef ENABLE_NLS |
| 573 | setlocale(LC_MESSAGES, ""); |
| 574 | bindtextdomain(NLS_CAT_NAME, LOCALEDIR); |
| 575 | textdomain(NLS_CAT_NAME); |
| 576 | #endif |
| 577 | if (argc && *argv) |
| 578 | program_name = *argv; |
| 579 | initialize_ext2_error_table(); |
| 580 | |
| 581 | if (strcmp(get_progname(argv[0]), "e2label") == 0) |
| 582 | parse_e2label_options(argc, argv); |
| 583 | else |
| 584 | parse_tune2fs_options(argc, argv); |
| 585 | |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 586 | retval = ext2fs_open (device_name, open_flag, 0, 0, |
| 587 | unix_io_manager, &fs); |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 588 | if (retval) { |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 589 | com_err (program_name, retval, _("while trying to open %s"), |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 590 | device_name); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 591 | printf(_("Couldn't find valid filesystem superblock.\n")); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 592 | exit(1); |
| 593 | } |
Theodore Ts'o | 8323815 | 2001-01-09 00:16:26 +0000 | [diff] [blame] | 594 | sb = fs->super; |
| 595 | if (print_label) { |
| 596 | /* For e2label emulation */ |
Theodore Ts'o | c8c071a | 2001-01-11 16:08:23 +0000 | [diff] [blame] | 597 | printf("%.*s\n", (int) sizeof(sb->s_volume_name), |
| 598 | sb->s_volume_name); |
Theodore Ts'o | 8323815 | 2001-01-09 00:16:26 +0000 | [diff] [blame] | 599 | exit(0); |
| 600 | } |
Theodore Ts'o | b21e38a | 2001-01-01 15:26:58 +0000 | [diff] [blame] | 601 | retval = ext2fs_check_if_mounted(device_name, &mount_flags); |
| 602 | if (retval) { |
| 603 | com_err("ext2fs_check_if_mount", retval, |
| 604 | _("while determining whether %s is mounted."), |
| 605 | device_name); |
Theodore Ts'o | 4055ef7 | 2001-01-14 16:11:14 +0000 | [diff] [blame] | 606 | exit(1); |
Theodore Ts'o | b21e38a | 2001-01-01 15:26:58 +0000 | [diff] [blame] | 607 | } |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 608 | /* Normally we only need to write out the superblock */ |
| 609 | fs->flags |= EXT2_FLAG_SUPER_ONLY; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 610 | |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 611 | if (c_flag) { |
Theodore Ts'o | b21e38a | 2001-01-01 15:26:58 +0000 | [diff] [blame] | 612 | sb->s_max_mnt_count = max_mount_count; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 613 | ext2fs_mark_super_dirty(fs); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 614 | printf (_("Setting maximal mount count to %d\n"), |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 615 | max_mount_count); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 616 | } |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 617 | if (C_flag) { |
Theodore Ts'o | b21e38a | 2001-01-01 15:26:58 +0000 | [diff] [blame] | 618 | sb->s_mnt_count = mount_count; |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 619 | ext2fs_mark_super_dirty(fs); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 620 | printf (_("Setting current mount count to %d\n"), mount_count); |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 621 | } |
| 622 | if (e_flag) { |
Theodore Ts'o | b21e38a | 2001-01-01 15:26:58 +0000 | [diff] [blame] | 623 | sb->s_errors = errors; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 624 | ext2fs_mark_super_dirty(fs); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 625 | printf (_("Setting error behavior to %d\n"), errors); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 626 | } |
Theodore Ts'o | b21e38a | 2001-01-01 15:26:58 +0000 | [diff] [blame] | 627 | if (g_flag) { |
| 628 | sb->s_def_resgid = resgid; |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 629 | ext2fs_mark_super_dirty(fs); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 630 | printf (_("Setting reserved blocks gid to %lu\n"), resgid); |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 631 | } |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 632 | if (i_flag) { |
Theodore Ts'o | b21e38a | 2001-01-01 15:26:58 +0000 | [diff] [blame] | 633 | sb->s_checkinterval = interval; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 634 | ext2fs_mark_super_dirty(fs); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 635 | printf (_("Setting interval between check %lu seconds\n"), interval); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 636 | } |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 637 | if (m_flag) { |
Theodore Ts'o | b21e38a | 2001-01-01 15:26:58 +0000 | [diff] [blame] | 638 | sb->s_r_blocks_count = (sb->s_blocks_count / 100) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 639 | * reserved_ratio; |
| 640 | ext2fs_mark_super_dirty(fs); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 641 | printf (_("Setting reserved blocks percentage to %lu (%u blocks)\n"), |
Theodore Ts'o | b21e38a | 2001-01-01 15:26:58 +0000 | [diff] [blame] | 642 | reserved_ratio, sb->s_r_blocks_count); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 643 | } |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 644 | if (r_flag) { |
Theodore Ts'o | b21e38a | 2001-01-01 15:26:58 +0000 | [diff] [blame] | 645 | if (reserved_blocks >= sb->s_blocks_count) { |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 646 | com_err (program_name, 0, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 647 | _("reserved blocks count is too big (%ul)"), |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 648 | reserved_blocks); |
| 649 | exit (1); |
| 650 | } |
Theodore Ts'o | b21e38a | 2001-01-01 15:26:58 +0000 | [diff] [blame] | 651 | sb->s_r_blocks_count = reserved_blocks; |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 652 | ext2fs_mark_super_dirty(fs); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 653 | printf (_("Setting reserved blocks count to %lu\n"), |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 654 | reserved_blocks); |
| 655 | } |
Theodore Ts'o | 521e368 | 1997-04-29 17:48:10 +0000 | [diff] [blame] | 656 | if (s_flag == 1) { |
Theodore Ts'o | 521e368 | 1997-04-29 17:48:10 +0000 | [diff] [blame] | 657 | if (sb->s_feature_ro_compat & |
| 658 | EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER) |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 659 | fprintf(stderr, _("\nThe filesystem already" |
Theodore Ts'o | e1a0a3e | 2000-02-11 05:00:19 +0000 | [diff] [blame] | 660 | " has sparse superblocks.\n")); |
Theodore Ts'o | 521e368 | 1997-04-29 17:48:10 +0000 | [diff] [blame] | 661 | else { |
| 662 | sb->s_feature_ro_compat |= |
| 663 | EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER; |
Theodore Ts'o | b21e38a | 2001-01-01 15:26:58 +0000 | [diff] [blame] | 664 | sb->s_state &= ~EXT2_VALID_FS; |
Theodore Ts'o | 521e368 | 1997-04-29 17:48:10 +0000 | [diff] [blame] | 665 | ext2fs_mark_super_dirty(fs); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 666 | printf(_("\nSparse superblock flag set. %s"), |
Theodore Ts'o | a4fa100 | 2000-02-08 21:35:41 +0000 | [diff] [blame] | 667 | _(please_fsck)); |
Theodore Ts'o | 521e368 | 1997-04-29 17:48:10 +0000 | [diff] [blame] | 668 | } |
Theodore Ts'o | 521e368 | 1997-04-29 17:48:10 +0000 | [diff] [blame] | 669 | } |
| 670 | if (s_flag == 0) { |
Theodore Ts'o | 521e368 | 1997-04-29 17:48:10 +0000 | [diff] [blame] | 671 | if (!(sb->s_feature_ro_compat & |
| 672 | EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER)) |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 673 | fprintf(stderr, _("\nThe filesystem already" |
Theodore Ts'o | e1a0a3e | 2000-02-11 05:00:19 +0000 | [diff] [blame] | 674 | " has sparse superblocks disabled.\n")); |
Theodore Ts'o | 521e368 | 1997-04-29 17:48:10 +0000 | [diff] [blame] | 675 | else { |
| 676 | sb->s_feature_ro_compat &= |
| 677 | ~EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER; |
Theodore Ts'o | b21e38a | 2001-01-01 15:26:58 +0000 | [diff] [blame] | 678 | sb->s_state &= ~EXT2_VALID_FS; |
Theodore Ts'o | 521e368 | 1997-04-29 17:48:10 +0000 | [diff] [blame] | 679 | fs->flags |= EXT2_FLAG_MASTER_SB_ONLY; |
| 680 | ext2fs_mark_super_dirty(fs); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 681 | printf(_("\nSparse superblock flag cleared. %s"), |
Theodore Ts'o | a4fa100 | 2000-02-08 21:35:41 +0000 | [diff] [blame] | 682 | _(please_fsck)); |
Theodore Ts'o | 521e368 | 1997-04-29 17:48:10 +0000 | [diff] [blame] | 683 | } |
Theodore Ts'o | 521e368 | 1997-04-29 17:48:10 +0000 | [diff] [blame] | 684 | } |
Theodore Ts'o | b21e38a | 2001-01-01 15:26:58 +0000 | [diff] [blame] | 685 | if (u_flag) { |
| 686 | sb->s_def_resuid = resuid; |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 687 | ext2fs_mark_super_dirty(fs); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 688 | printf (_("Setting reserved blocks uid to %lu\n"), resuid); |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 689 | } |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 690 | if (L_flag) { |
Theodore Ts'o | a789d84 | 1998-03-30 01:20:55 +0000 | [diff] [blame] | 691 | if (strlen(new_label) > sizeof(sb->s_volume_name)) |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 692 | fprintf(stderr, _("Warning: label too " |
| 693 | "long, truncating.\n")); |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 694 | memset(sb->s_volume_name, 0, sizeof(sb->s_volume_name)); |
| 695 | strncpy(sb->s_volume_name, new_label, |
| 696 | sizeof(sb->s_volume_name)); |
| 697 | ext2fs_mark_super_dirty(fs); |
| 698 | } |
| 699 | if (M_flag) { |
| 700 | memset(sb->s_last_mounted, 0, sizeof(sb->s_last_mounted)); |
| 701 | strncpy(sb->s_last_mounted, new_last_mounted, |
| 702 | sizeof(sb->s_last_mounted)); |
| 703 | ext2fs_mark_super_dirty(fs); |
| 704 | } |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 705 | if (features_cmd) |
| 706 | update_feature_set(fs, features_cmd); |
Theodore Ts'o | dc2ec52 | 2001-01-18 01:51:15 +0000 | [diff] [blame] | 707 | if (journal_size || journal_device) |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 708 | add_journal(fs); |
| 709 | |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 710 | if (U_flag) { |
Theodore Ts'o | 4d0f228 | 2001-04-23 20:58:03 +0000 | [diff] [blame] | 711 | if ((strcasecmp(new_UUID, "null") == 0) || |
| 712 | (strcasecmp(new_UUID, "clear") == 0)) { |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 713 | uuid_clear(sb->s_uuid); |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 714 | } else if (strcasecmp(new_UUID, "time") == 0) { |
| 715 | uuid_generate_time(sb->s_uuid); |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 716 | } else if (strcasecmp(new_UUID, "random") == 0) { |
| 717 | uuid_generate(sb->s_uuid); |
| 718 | } else if (uuid_parse(new_UUID, sb->s_uuid)) { |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 719 | com_err(program_name, 0, _("Invalid UUID format\n")); |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 720 | exit(1); |
| 721 | } |
| 722 | ext2fs_mark_super_dirty(fs); |
| 723 | } |
| 724 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 725 | if (l_flag) |
Theodore Ts'o | b21e38a | 2001-01-01 15:26:58 +0000 | [diff] [blame] | 726 | list_super (sb); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 727 | ext2fs_close (fs); |
| 728 | exit (0); |
| 729 | } |