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 | ed1b33e | 2003-03-01 19:29:01 -0500 | [diff] [blame] | 51 | #include "blkid/blkid.h" |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 52 | |
| 53 | #include "../version.h" |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 54 | #include "nls-enable.h" |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 55 | |
| 56 | const char * program_name = "tune2fs"; |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 57 | char * device_name; |
Theodore Ts'o | c8c071a | 2001-01-11 16:08:23 +0000 | [diff] [blame] | 58 | char * new_label, *new_last_mounted, *new_UUID; |
Theodore Ts'o | 4d0f228 | 2001-04-23 20:58:03 +0000 | [diff] [blame] | 59 | static int c_flag, C_flag, e_flag, f_flag, g_flag, i_flag, l_flag, L_flag; |
Theodore Ts'o | d4de4aa | 2001-12-26 08:58:01 -0500 | [diff] [blame] | 60 | static int m_flag, M_flag, r_flag, s_flag = -1, u_flag, U_flag, T_flag; |
| 61 | static time_t last_check_time; |
Theodore Ts'o | 8323815 | 2001-01-09 00:16:26 +0000 | [diff] [blame] | 62 | static int print_label; |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 63 | static int max_mount_count, mount_count, mount_flags; |
| 64 | static unsigned long interval, reserved_ratio, reserved_blocks; |
| 65 | static unsigned long resgid, resuid; |
| 66 | static unsigned short errors; |
Theodore Ts'o | 8323815 | 2001-01-09 00:16:26 +0000 | [diff] [blame] | 67 | static int open_flag; |
| 68 | static char *features_cmd; |
Theodore Ts'o | a0c3fd5 | 2002-10-15 17:43:43 -0400 | [diff] [blame] | 69 | static char *mntopts_cmd; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 70 | |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 71 | int journal_size, journal_flags; |
| 72 | char *journal_device; |
| 73 | |
| 74 | 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] | 75 | |
Theodore Ts'o | 3e69906 | 2002-10-13 23:56:28 -0400 | [diff] [blame] | 76 | void do_findfs(int argc, char **argv); |
| 77 | |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 78 | static void usage(void) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 79 | { |
Theodore Ts'o | b21e38a | 2001-01-01 15:26:58 +0000 | [diff] [blame] | 80 | fprintf(stderr, |
| 81 | _("Usage: %s [-c max-mounts-count] [-e errors-behavior] " |
| 82 | "[-g group]\n" |
Theodore Ts'o | a0c3fd5 | 2002-10-15 17:43:43 -0400 | [diff] [blame] | 83 | "\t[-i interval[d|m|w]] [-j] [-J journal-options]\n" |
| 84 | "\t[-l] [-s sparse-flag] [-m reserved-blocks-percent]\n" |
| 85 | "\t[-o [^]mount-options[,...]] [-r reserved-blocks-count]\n" |
| 86 | "\t[-u user] [-C mount-count] [-L volume-label] " |
| 87 | "[-M last-mounted-dir]\n" |
Theodore Ts'o | d4de4aa | 2001-12-26 08:58:01 -0500 | [diff] [blame] | 88 | "\t[-O [^]feature[,...]] [-T last-check-time] [-U UUID]" |
| 89 | " device\n"), program_name); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 90 | exit (1); |
| 91 | } |
| 92 | |
Theodore Ts'o | 896938d | 1999-10-23 01:04:50 +0000 | [diff] [blame] | 93 | static __u32 ok_features[3] = { |
Theodore Ts'o | 843049c | 2002-09-22 15:37:40 -0400 | [diff] [blame] | 94 | EXT3_FEATURE_COMPAT_HAS_JOURNAL | |
| 95 | EXT2_FEATURE_COMPAT_DIR_INDEX, /* Compat */ |
Theodore Ts'o | 896938d | 1999-10-23 01:04:50 +0000 | [diff] [blame] | 96 | EXT2_FEATURE_INCOMPAT_FILETYPE, /* Incompat */ |
| 97 | EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER /* R/O compat */ |
| 98 | }; |
| 99 | |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 100 | /* |
Theodore Ts'o | dc2ec52 | 2001-01-18 01:51:15 +0000 | [diff] [blame] | 101 | * Remove an external journal from the filesystem |
| 102 | */ |
| 103 | static void remove_journal_device(ext2_filsys fs) |
| 104 | { |
Theodore Ts'o | 4ea7bd0 | 2001-12-16 23:23:37 -0500 | [diff] [blame] | 105 | char *journal_path; |
Theodore Ts'o | dc2ec52 | 2001-01-18 01:51:15 +0000 | [diff] [blame] | 106 | ext2_filsys jfs; |
| 107 | char buf[1024]; |
| 108 | journal_superblock_t *jsb; |
| 109 | int i, nr_users; |
| 110 | errcode_t retval; |
Theodore Ts'o | 4d0f228 | 2001-04-23 20:58:03 +0000 | [diff] [blame] | 111 | int commit_remove_journal = 0; |
Theodore Ts'o | 2a29f13 | 2003-05-05 12:08:47 -0400 | [diff] [blame^] | 112 | io_manager io_ptr; |
Theodore Ts'o | 4d0f228 | 2001-04-23 20:58:03 +0000 | [diff] [blame] | 113 | |
| 114 | if (f_flag) |
| 115 | commit_remove_journal = 1; /* force removal even if error */ |
Theodore Ts'o | dc2ec52 | 2001-01-18 01:51:15 +0000 | [diff] [blame] | 116 | |
Andreas Dilger | 2d15576 | 2001-08-17 03:48:11 -0600 | [diff] [blame] | 117 | uuid_unparse(fs->super->s_journal_uuid, buf); |
Theodore Ts'o | ed1b33e | 2003-03-01 19:29:01 -0500 | [diff] [blame] | 118 | journal_path = blkid_get_devname(NULL, "UUID", buf); |
Andreas Dilger | 2d15576 | 2001-08-17 03:48:11 -0600 | [diff] [blame] | 119 | |
Theodore Ts'o | 4ea7bd0 | 2001-12-16 23:23:37 -0500 | [diff] [blame] | 120 | if (!journal_path) { |
| 121 | journal_path = |
Andreas Dilger | 2d15576 | 2001-08-17 03:48:11 -0600 | [diff] [blame] | 122 | ext2fs_find_block_device(fs->super->s_journal_dev); |
Theodore Ts'o | 4ea7bd0 | 2001-12-16 23:23:37 -0500 | [diff] [blame] | 123 | if (!journal_path) |
Andreas Dilger | 2d15576 | 2001-08-17 03:48:11 -0600 | [diff] [blame] | 124 | return; |
| 125 | } |
Theodore Ts'o | dc2ec52 | 2001-01-18 01:51:15 +0000 | [diff] [blame] | 126 | |
Theodore Ts'o | 2a29f13 | 2003-05-05 12:08:47 -0400 | [diff] [blame^] | 127 | #ifdef CONFIG_TESTIO_DEBUG |
| 128 | io_ptr = test_io_manager; |
| 129 | test_io_backing_manager = unix_io_manager; |
| 130 | #else |
| 131 | io_ptr = unix_io_manager; |
| 132 | #endif |
Theodore Ts'o | 4ea7bd0 | 2001-12-16 23:23:37 -0500 | [diff] [blame] | 133 | retval = ext2fs_open(journal_path, EXT2_FLAG_RW| |
Theodore Ts'o | dc2ec52 | 2001-01-18 01:51:15 +0000 | [diff] [blame] | 134 | EXT2_FLAG_JOURNAL_DEV_OK, 0, |
Theodore Ts'o | 2a29f13 | 2003-05-05 12:08:47 -0400 | [diff] [blame^] | 135 | fs->blocksize, io_ptr, &jfs); |
Theodore Ts'o | dc2ec52 | 2001-01-18 01:51:15 +0000 | [diff] [blame] | 136 | if (retval) { |
| 137 | com_err(program_name, retval, |
| 138 | _("while trying to open external journal")); |
Theodore Ts'o | 4d0f228 | 2001-04-23 20:58:03 +0000 | [diff] [blame] | 139 | goto no_valid_journal; |
Theodore Ts'o | dc2ec52 | 2001-01-18 01:51:15 +0000 | [diff] [blame] | 140 | } |
| 141 | if (!(jfs->super->s_feature_incompat & EXT3_FEATURE_INCOMPAT_JOURNAL_DEV)) { |
Theodore Ts'o | 7141b54 | 2001-08-15 19:17:37 -0400 | [diff] [blame] | 142 | fprintf(stderr, _("%s is not a journal device.\n"), |
Theodore Ts'o | 4ea7bd0 | 2001-12-16 23:23:37 -0500 | [diff] [blame] | 143 | journal_path); |
Theodore Ts'o | 4d0f228 | 2001-04-23 20:58:03 +0000 | [diff] [blame] | 144 | goto no_valid_journal; |
Theodore Ts'o | dc2ec52 | 2001-01-18 01:51:15 +0000 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | /* Get the journal superblock */ |
| 148 | if ((retval = io_channel_read_blk(jfs->io, 1, -1024, buf))) { |
| 149 | com_err(program_name, retval, |
| 150 | _("while reading journal superblock")); |
Theodore Ts'o | 4d0f228 | 2001-04-23 20:58:03 +0000 | [diff] [blame] | 151 | goto no_valid_journal; |
Theodore Ts'o | dc2ec52 | 2001-01-18 01:51:15 +0000 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | jsb = (journal_superblock_t *) buf; |
| 155 | if ((jsb->s_header.h_magic != (unsigned) ntohl(JFS_MAGIC_NUMBER)) || |
| 156 | (jsb->s_header.h_blocktype != (unsigned) ntohl(JFS_SUPERBLOCK_V2))) { |
| 157 | fprintf(stderr, _("Journal superblock not found!\n")); |
Theodore Ts'o | 4d0f228 | 2001-04-23 20:58:03 +0000 | [diff] [blame] | 158 | goto no_valid_journal; |
Theodore Ts'o | dc2ec52 | 2001-01-18 01:51:15 +0000 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | /* Find the filesystem UUID */ |
| 162 | nr_users = ntohl(jsb->s_nr_users); |
| 163 | for (i=0; i < nr_users; i++) { |
| 164 | if (memcmp(fs->super->s_uuid, |
| 165 | &jsb->s_users[i*16], 16) == 0) |
| 166 | break; |
| 167 | } |
| 168 | if (i >= nr_users) { |
Theodore Ts'o | 7141b54 | 2001-08-15 19:17:37 -0400 | [diff] [blame] | 169 | fprintf(stderr, |
| 170 | _("Filesystem's UUID not found on journal device.\n")); |
Theodore Ts'o | 4d0f228 | 2001-04-23 20:58:03 +0000 | [diff] [blame] | 171 | commit_remove_journal = 1; |
| 172 | goto no_valid_journal; |
Theodore Ts'o | dc2ec52 | 2001-01-18 01:51:15 +0000 | [diff] [blame] | 173 | } |
| 174 | nr_users--; |
| 175 | for (i=0; i < nr_users; i++) |
| 176 | memcpy(&jsb->s_users[i*16], &jsb->s_users[(i+1)*16], 16); |
| 177 | jsb->s_nr_users = htonl(nr_users); |
| 178 | |
| 179 | /* Write back the journal superblock */ |
| 180 | if ((retval = io_channel_write_blk(jfs->io, 1, -1024, buf))) { |
| 181 | com_err(program_name, retval, |
| 182 | "while writing journal superblock."); |
Theodore Ts'o | 4d0f228 | 2001-04-23 20:58:03 +0000 | [diff] [blame] | 183 | goto no_valid_journal; |
Theodore Ts'o | dc2ec52 | 2001-01-18 01:51:15 +0000 | [diff] [blame] | 184 | } |
| 185 | |
Theodore Ts'o | 4d0f228 | 2001-04-23 20:58:03 +0000 | [diff] [blame] | 186 | commit_remove_journal = 1; |
| 187 | |
| 188 | no_valid_journal: |
| 189 | if (commit_remove_journal == 0) { |
Theodore Ts'o | 7141b54 | 2001-08-15 19:17:37 -0400 | [diff] [blame] | 190 | fprintf(stderr, _("Journal NOT removed\n")); |
Theodore Ts'o | 4d0f228 | 2001-04-23 20:58:03 +0000 | [diff] [blame] | 191 | exit(1); |
| 192 | } |
Theodore Ts'o | dc2ec52 | 2001-01-18 01:51:15 +0000 | [diff] [blame] | 193 | fs->super->s_journal_dev = 0; |
Theodore Ts'o | ed1b33e | 2003-03-01 19:29:01 -0500 | [diff] [blame] | 194 | uuid_clear(fs->super->s_journal_uuid); |
Theodore Ts'o | dc2ec52 | 2001-01-18 01:51:15 +0000 | [diff] [blame] | 195 | ext2fs_mark_super_dirty(fs); |
Theodore Ts'o | 4d0f228 | 2001-04-23 20:58:03 +0000 | [diff] [blame] | 196 | printf(_("Journal removed\n")); |
Theodore Ts'o | 4ea7bd0 | 2001-12-16 23:23:37 -0500 | [diff] [blame] | 197 | free(journal_path); |
Theodore Ts'o | dc2ec52 | 2001-01-18 01:51:15 +0000 | [diff] [blame] | 198 | } |
| 199 | |
Theodore Ts'o | 194686b | 2001-07-31 12:03:23 -0400 | [diff] [blame] | 200 | /* Helper function for remove_journal_inode */ |
| 201 | static int release_blocks_proc(ext2_filsys fs, blk_t *blocknr, |
| 202 | int blockcnt, void *private) |
| 203 | { |
| 204 | blk_t block; |
| 205 | int group; |
| 206 | |
| 207 | block = *blocknr; |
| 208 | ext2fs_unmark_block_bitmap(fs->block_map,block); |
| 209 | group = ext2fs_group_of_blk(fs, block); |
| 210 | fs->group_desc[group].bg_free_blocks_count++; |
| 211 | fs->super->s_free_blocks_count++; |
| 212 | return 0; |
| 213 | } |
| 214 | |
| 215 | /* |
| 216 | * Remove the journal inode from the filesystem |
| 217 | */ |
| 218 | static void remove_journal_inode(ext2_filsys fs) |
| 219 | { |
| 220 | struct ext2_inode inode; |
| 221 | errcode_t retval; |
| 222 | ino_t ino = fs->super->s_journal_inum; |
Theodore Ts'o | 194686b | 2001-07-31 12:03:23 -0400 | [diff] [blame] | 223 | |
| 224 | retval = ext2fs_read_inode(fs, ino, &inode); |
| 225 | if (retval) { |
| 226 | com_err(program_name, retval, |
| 227 | _("while reading journal inode")); |
| 228 | exit(1); |
| 229 | } |
| 230 | if (ino == EXT2_JOURNAL_INO) { |
| 231 | retval = ext2fs_read_bitmaps(fs); |
| 232 | if (retval) { |
| 233 | com_err(program_name, retval, |
| 234 | _("while reading bitmaps")); |
| 235 | exit(1); |
| 236 | } |
| 237 | retval = ext2fs_block_iterate(fs, ino, 0, NULL, |
| 238 | release_blocks_proc, NULL); |
| 239 | if (retval) { |
| 240 | com_err(program_name, retval, |
| 241 | _("while clearing journal inode")); |
| 242 | exit(1); |
| 243 | } |
| 244 | memset(&inode, 0, sizeof(inode)); |
| 245 | ext2fs_mark_bb_dirty(fs); |
Theodore Ts'o | 194686b | 2001-07-31 12:03:23 -0400 | [diff] [blame] | 246 | fs->flags &= ~EXT2_FLAG_SUPER_ONLY; |
| 247 | } else |
| 248 | inode.i_flags &= ~EXT2_IMMUTABLE_FL; |
| 249 | retval = ext2fs_write_inode(fs, ino, &inode); |
| 250 | if (retval) { |
| 251 | com_err(program_name, retval, |
| 252 | _("while writing journal inode")); |
| 253 | exit(1); |
| 254 | } |
| 255 | fs->super->s_journal_inum = 0; |
| 256 | ext2fs_mark_super_dirty(fs); |
| 257 | } |
Theodore Ts'o | dc2ec52 | 2001-01-18 01:51:15 +0000 | [diff] [blame] | 258 | |
| 259 | /* |
Theodore Ts'o | a0c3fd5 | 2002-10-15 17:43:43 -0400 | [diff] [blame] | 260 | * Update the default mount options |
| 261 | */ |
| 262 | static void update_mntopts(ext2_filsys fs, char *mntopts) |
| 263 | { |
| 264 | struct ext2_super_block *sb= fs->super; |
| 265 | |
| 266 | if (e2p_edit_mntopts(mntopts, &sb->s_default_mount_opts, ~0)) { |
| 267 | fprintf(stderr, _("Invalid mount option set: %s\n"), |
| 268 | mntopts); |
| 269 | exit(1); |
| 270 | } |
| 271 | ext2fs_mark_super_dirty(fs); |
| 272 | } |
| 273 | |
| 274 | /* |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 275 | * Update the feature set as provided by the user. |
| 276 | */ |
Theodore Ts'o | c8c071a | 2001-01-11 16:08:23 +0000 | [diff] [blame] | 277 | static void update_feature_set(ext2_filsys fs, char *features) |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 278 | { |
| 279 | int sparse, old_sparse, filetype, old_filetype; |
Theodore Ts'o | 843049c | 2002-09-22 15:37:40 -0400 | [diff] [blame] | 280 | int journal, old_journal, dxdir, old_dxdir; |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 281 | struct ext2_super_block *sb= fs->super; |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 282 | |
| 283 | old_sparse = sb->s_feature_ro_compat & |
| 284 | EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER; |
| 285 | old_filetype = sb->s_feature_incompat & |
| 286 | EXT2_FEATURE_INCOMPAT_FILETYPE; |
| 287 | old_journal = sb->s_feature_compat & |
| 288 | EXT3_FEATURE_COMPAT_HAS_JOURNAL; |
Theodore Ts'o | 843049c | 2002-09-22 15:37:40 -0400 | [diff] [blame] | 289 | old_dxdir = sb->s_feature_compat & |
| 290 | EXT2_FEATURE_COMPAT_DIR_INDEX; |
Theodore Ts'o | c8c071a | 2001-01-11 16:08:23 +0000 | [diff] [blame] | 291 | if (e2p_edit_feature(features, &sb->s_feature_compat, |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 292 | ok_features)) { |
| 293 | fprintf(stderr, _("Invalid filesystem option set: %s\n"), |
Theodore Ts'o | c8c071a | 2001-01-11 16:08:23 +0000 | [diff] [blame] | 294 | features); |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 295 | exit(1); |
| 296 | } |
| 297 | sparse = sb->s_feature_ro_compat & |
| 298 | EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER; |
| 299 | filetype = sb->s_feature_incompat & |
| 300 | EXT2_FEATURE_INCOMPAT_FILETYPE; |
| 301 | journal = sb->s_feature_compat & |
| 302 | EXT3_FEATURE_COMPAT_HAS_JOURNAL; |
Theodore Ts'o | 843049c | 2002-09-22 15:37:40 -0400 | [diff] [blame] | 303 | dxdir = sb->s_feature_compat & |
| 304 | EXT2_FEATURE_COMPAT_DIR_INDEX; |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 305 | if (old_journal && !journal) { |
| 306 | if ((mount_flags & EXT2_MF_MOUNTED) && |
| 307 | !(mount_flags & EXT2_MF_READONLY)) { |
| 308 | fprintf(stderr, |
Theodore Ts'o | 8d64174 | 2001-05-14 04:12:27 +0000 | [diff] [blame] | 309 | _("The has_journal flag may only be " |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 310 | "cleared when the filesystem is\n" |
| 311 | "unmounted or mounted " |
| 312 | "read-only.\n")); |
| 313 | exit(1); |
| 314 | } |
| 315 | if (sb->s_feature_incompat & |
| 316 | EXT3_FEATURE_INCOMPAT_RECOVER) { |
| 317 | fprintf(stderr, |
Theodore Ts'o | 8d64174 | 2001-05-14 04:12:27 +0000 | [diff] [blame] | 318 | _("The needs_recovery flag is set. " |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 319 | "Please run e2fsck before clearing\n" |
Theodore Ts'o | e549d0a | 2001-05-25 16:38:48 +0000 | [diff] [blame] | 320 | "the has_journal flag.\n")); |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 321 | exit(1); |
| 322 | } |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 323 | if (sb->s_journal_inum) { |
Theodore Ts'o | 194686b | 2001-07-31 12:03:23 -0400 | [diff] [blame] | 324 | remove_journal_inode(fs); |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 325 | } |
Theodore Ts'o | de49f01 | 2001-07-30 16:31:30 -0400 | [diff] [blame] | 326 | if (sb->s_journal_dev) { |
Theodore Ts'o | dc2ec52 | 2001-01-18 01:51:15 +0000 | [diff] [blame] | 327 | remove_journal_device(fs); |
Theodore Ts'o | de49f01 | 2001-07-30 16:31:30 -0400 | [diff] [blame] | 328 | } |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 329 | } |
| 330 | if (journal && !old_journal) { |
| 331 | /* |
| 332 | * If adding a journal flag, let the create journal |
| 333 | * code below handle creating setting the flag and |
| 334 | * creating the journal. We supply a default size if |
| 335 | * necessary. |
| 336 | */ |
Theodore Ts'o | dc2ec52 | 2001-01-18 01:51:15 +0000 | [diff] [blame] | 337 | if (!journal_size) |
| 338 | journal_size = -1; |
Theodore Ts'o | 08dd830 | 2001-01-14 16:25:58 +0000 | [diff] [blame] | 339 | sb->s_feature_compat &= ~EXT3_FEATURE_COMPAT_HAS_JOURNAL; |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 340 | } |
Theodore Ts'o | 843049c | 2002-09-22 15:37:40 -0400 | [diff] [blame] | 341 | if (dxdir && !old_dxdir) { |
| 342 | if (!sb->s_def_hash_version) |
| 343 | sb->s_def_hash_version = EXT2_HASH_TEA; |
| 344 | if (uuid_is_null((unsigned char *) sb->s_hash_seed)) |
| 345 | uuid_generate((unsigned char *) sb->s_hash_seed); |
| 346 | } |
Theodore Ts'o | dc2ec52 | 2001-01-18 01:51:15 +0000 | [diff] [blame] | 347 | |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 348 | if (sb->s_rev_level == EXT2_GOOD_OLD_REV && |
| 349 | (sb->s_feature_compat || sb->s_feature_ro_compat || |
| 350 | sb->s_feature_incompat)) |
| 351 | ext2fs_update_dynamic_rev(fs); |
| 352 | if ((sparse != old_sparse) || |
Theodore Ts'o | 194686b | 2001-07-31 12:03:23 -0400 | [diff] [blame] | 353 | (filetype != old_filetype)) { |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 354 | sb->s_state &= ~EXT2_VALID_FS; |
| 355 | printf("\n%s\n", _(please_fsck)); |
| 356 | } |
| 357 | ext2fs_mark_super_dirty(fs); |
| 358 | } |
| 359 | |
| 360 | /* |
| 361 | * Add a journal to the filesystem. |
| 362 | */ |
| 363 | static void add_journal(ext2_filsys fs) |
| 364 | { |
| 365 | unsigned long journal_blocks; |
| 366 | errcode_t retval; |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 367 | ext2_filsys jfs; |
Theodore Ts'o | 2a29f13 | 2003-05-05 12:08:47 -0400 | [diff] [blame^] | 368 | io_manager io_ptr; |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 369 | |
| 370 | if (fs->super->s_feature_compat & |
| 371 | EXT3_FEATURE_COMPAT_HAS_JOURNAL) { |
| 372 | fprintf(stderr, _("The filesystem already has a journal.\n")); |
Andreas Dilger | 2d15576 | 2001-08-17 03:48:11 -0600 | [diff] [blame] | 373 | goto err; |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 374 | } |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 375 | if (journal_device) { |
| 376 | check_plausibility(journal_device); |
| 377 | check_mount(journal_device, 0, _("journal")); |
Theodore Ts'o | 2a29f13 | 2003-05-05 12:08:47 -0400 | [diff] [blame^] | 378 | #ifdef CONFIG_TESTIO_DEBUG |
| 379 | io_ptr = test_io_manager; |
| 380 | test_io_backing_manager = unix_io_manager; |
| 381 | #else |
| 382 | io_ptr = unix_io_manager; |
| 383 | #endif |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 384 | retval = ext2fs_open(journal_device, EXT2_FLAG_RW| |
| 385 | EXT2_FLAG_JOURNAL_DEV_OK, 0, |
Theodore Ts'o | 2a29f13 | 2003-05-05 12:08:47 -0400 | [diff] [blame^] | 386 | fs->blocksize, io_ptr, &jfs); |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 387 | if (retval) { |
| 388 | com_err(program_name, retval, |
Theodore Ts'o | 1d08d9b | 2001-04-17 01:01:49 +0000 | [diff] [blame] | 389 | _("\n\twhile trying to open journal on %s\n"), |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 390 | journal_device); |
Andreas Dilger | 2d15576 | 2001-08-17 03:48:11 -0600 | [diff] [blame] | 391 | goto err; |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 392 | } |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 393 | printf(_("Creating journal on device %s: "), |
| 394 | journal_device); |
Theodore Ts'o | 4055ef7 | 2001-01-14 16:11:14 +0000 | [diff] [blame] | 395 | fflush(stdout); |
Andreas Dilger | 2d15576 | 2001-08-17 03:48:11 -0600 | [diff] [blame] | 396 | |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 397 | retval = ext2fs_add_journal_device(fs, jfs); |
Andreas Dilger | 2d15576 | 2001-08-17 03:48:11 -0600 | [diff] [blame] | 398 | ext2fs_close(jfs); |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 399 | if (retval) { |
| 400 | com_err (program_name, retval, |
Theodore Ts'o | 8d64174 | 2001-05-14 04:12:27 +0000 | [diff] [blame] | 401 | _("while adding filesystem to journal on %s"), |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 402 | journal_device); |
Andreas Dilger | 2d15576 | 2001-08-17 03:48:11 -0600 | [diff] [blame] | 403 | goto err; |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 404 | } |
| 405 | printf(_("done\n")); |
| 406 | } else if (journal_size) { |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 407 | printf(_("Creating journal inode: ")); |
| 408 | fflush(stdout); |
Theodore Ts'o | 2537b6d | 2001-03-26 20:07:13 +0000 | [diff] [blame] | 409 | journal_blocks = figure_journal_size(journal_size, fs); |
| 410 | |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 411 | retval = ext2fs_add_journal_inode(fs, journal_blocks, |
| 412 | journal_flags); |
| 413 | if (retval) { |
Theodore Ts'o | 7141b54 | 2001-08-15 19:17:37 -0400 | [diff] [blame] | 414 | fprintf(stderr, "\n"); |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 415 | com_err(program_name, retval, |
Theodore Ts'o | 1d08d9b | 2001-04-17 01:01:49 +0000 | [diff] [blame] | 416 | _("\n\twhile trying to create journal file")); |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 417 | exit(1); |
Theodore Ts'o | 1d08d9b | 2001-04-17 01:01:49 +0000 | [diff] [blame] | 418 | } else |
| 419 | printf(_("done\n")); |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 420 | /* |
| 421 | * If the filesystem wasn't mounted, we need to force |
| 422 | * the block group descriptors out. |
| 423 | */ |
| 424 | if ((mount_flags & EXT2_MF_MOUNTED) == 0) |
| 425 | fs->flags &= ~EXT2_FLAG_SUPER_ONLY; |
| 426 | } |
Theodore Ts'o | 66cf2f6 | 2001-06-14 06:42:44 +0000 | [diff] [blame] | 427 | print_check_message(fs); |
Andreas Dilger | 2d15576 | 2001-08-17 03:48:11 -0600 | [diff] [blame] | 428 | return; |
| 429 | |
| 430 | err: |
| 431 | if (journal_device) |
| 432 | free(journal_device); |
| 433 | exit(1); |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 434 | } |
| 435 | |
Theodore Ts'o | 896938d | 1999-10-23 01:04:50 +0000 | [diff] [blame] | 436 | |
Theodore Ts'o | c8c071a | 2001-01-11 16:08:23 +0000 | [diff] [blame] | 437 | static void parse_e2label_options(int argc, char ** argv) |
Theodore Ts'o | 8323815 | 2001-01-09 00:16:26 +0000 | [diff] [blame] | 438 | { |
| 439 | if ((argc < 2) || (argc > 3)) { |
| 440 | fprintf(stderr, _("Usage: e2label device [newlabel]\n")); |
| 441 | exit(1); |
| 442 | } |
Theodore Ts'o | 332f2c2 | 2003-03-06 12:58:33 -0500 | [diff] [blame] | 443 | device_name = blkid_get_devname(NULL, argv[1], NULL); |
Theodore Ts'o | 8323815 | 2001-01-09 00:16:26 +0000 | [diff] [blame] | 444 | if (argc == 3) { |
Andreas Dilger | 2d15576 | 2001-08-17 03:48:11 -0600 | [diff] [blame] | 445 | open_flag = EXT2_FLAG_RW | EXT2_FLAG_JOURNAL_DEV_OK; |
Theodore Ts'o | 8323815 | 2001-01-09 00:16:26 +0000 | [diff] [blame] | 446 | L_flag = 1; |
| 447 | new_label = argv[2]; |
| 448 | } else |
| 449 | print_label++; |
| 450 | } |
| 451 | |
Theodore Ts'o | d4de4aa | 2001-12-26 08:58:01 -0500 | [diff] [blame] | 452 | static time_t parse_time(char *str) |
| 453 | { |
| 454 | struct tm ts; |
| 455 | |
| 456 | if (strcmp(str, "now") == 0) { |
| 457 | return (time(0)); |
| 458 | } |
| 459 | memset(&ts, 0, sizeof(ts)); |
Theodore Ts'o | bc7c14e | 2003-05-03 16:40:09 -0400 | [diff] [blame] | 460 | #ifdef HAVE_STRPTIME |
Theodore Ts'o | d4de4aa | 2001-12-26 08:58:01 -0500 | [diff] [blame] | 461 | strptime(optarg, "%Y%m%d%H%M%S", &ts); |
Theodore Ts'o | bc7c14e | 2003-05-03 16:40:09 -0400 | [diff] [blame] | 462 | #else |
| 463 | sscanf(optarg, "%4d%2d%2d%2d%2d%2d", &ts.tm_year, &ts.tm_mon, |
| 464 | &ts.tm_mday, &ts.tm_hour, &ts.tm_min, &ts.tm_sec); |
| 465 | ts.tm_year -= 1900; |
| 466 | ts.tm_mon -= 1; |
| 467 | if (ts.tm_year < 0 || ts.tm_mon < 0 || ts.tm_mon > 11 || |
| 468 | ts.tm_mday < 0 || ts.tm_mday > 31 || ts.tm_hour > 23 || |
| 469 | ts.tm_min > 59 || ts.tm_sec > 61) |
| 470 | ts.tm_mday = 0; |
| 471 | #endif |
Theodore Ts'o | d4de4aa | 2001-12-26 08:58:01 -0500 | [diff] [blame] | 472 | if (ts.tm_mday == 0) { |
| 473 | com_err(program_name, 0, |
| 474 | _("Couldn't parse date/time specifier: %s"), |
| 475 | str); |
| 476 | usage(); |
| 477 | } |
| 478 | return (mktime(&ts)); |
| 479 | } |
Theodore Ts'o | 8323815 | 2001-01-09 00:16:26 +0000 | [diff] [blame] | 480 | |
Theodore Ts'o | c8c071a | 2001-01-11 16:08:23 +0000 | [diff] [blame] | 481 | static void parse_tune2fs_options(int argc, char **argv) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 482 | { |
Theodore Ts'o | 519149f | 1997-10-25 03:49:49 +0000 | [diff] [blame] | 483 | int c; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 484 | char * tmp; |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 485 | struct group * gr; |
| 486 | struct passwd * pw; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 487 | |
Theodore Ts'o | 0f8973f | 2001-08-27 12:44:23 -0400 | [diff] [blame] | 488 | printf("tune2fs %s (%s)\n", E2FSPROGS_VERSION, E2FSPROGS_DATE); |
Theodore Ts'o | a0c3fd5 | 2002-10-15 17:43:43 -0400 | [diff] [blame] | 489 | while ((c = getopt(argc, argv, "c:e:fg:i:jlm:o:r:s:u:C:J:L:M:O:T:U:")) != EOF) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 490 | switch (c) |
| 491 | { |
| 492 | case 'c': |
Theodore Ts'o | 45d9e2f | 2000-07-07 03:12:54 +0000 | [diff] [blame] | 493 | max_mount_count = strtol (optarg, &tmp, 0); |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 494 | if (*tmp || max_mount_count > 16000) { |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 495 | com_err (program_name, 0, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 496 | _("bad mounts count - %s"), |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 497 | optarg); |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 498 | usage(); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 499 | } |
Theodore Ts'o | ce57f14 | 2001-04-26 04:25:39 +0000 | [diff] [blame] | 500 | if (max_mount_count == 0) |
| 501 | max_mount_count = -1; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 502 | c_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 'C': |
| 506 | mount_count = strtoul (optarg, &tmp, 0); |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 507 | if (*tmp || mount_count > 16000) { |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 508 | com_err (program_name, 0, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 509 | _("bad mounts count - %s"), |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 510 | optarg); |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 511 | usage(); |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 512 | } |
| 513 | C_flag = 1; |
| 514 | open_flag = EXT2_FLAG_RW; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 515 | break; |
| 516 | case 'e': |
| 517 | if (strcmp (optarg, "continue") == 0) |
| 518 | errors = EXT2_ERRORS_CONTINUE; |
| 519 | else if (strcmp (optarg, "remount-ro") == 0) |
| 520 | errors = EXT2_ERRORS_RO; |
| 521 | else if (strcmp (optarg, "panic") == 0) |
| 522 | errors = EXT2_ERRORS_PANIC; |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 523 | else { |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 524 | com_err (program_name, 0, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 525 | _("bad error behavior - %s"), |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 526 | optarg); |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 527 | usage(); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 528 | } |
| 529 | e_flag = 1; |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 530 | open_flag = EXT2_FLAG_RW; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 531 | break; |
Theodore Ts'o | 4d0f228 | 2001-04-23 20:58:03 +0000 | [diff] [blame] | 532 | case 'f': /* Force */ |
| 533 | f_flag = 1; |
| 534 | break; |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 535 | case 'g': |
| 536 | resgid = strtoul (optarg, &tmp, 0); |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 537 | if (*tmp) { |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 538 | gr = getgrnam (optarg); |
| 539 | if (gr == NULL) |
| 540 | tmp = optarg; |
Theodore Ts'o | a418d3a | 1997-04-26 14:00:26 +0000 | [diff] [blame] | 541 | else { |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 542 | resgid = gr->gr_gid; |
Theodore Ts'o | a418d3a | 1997-04-26 14:00:26 +0000 | [diff] [blame] | 543 | *tmp =0; |
| 544 | } |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 545 | } |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 546 | if (*tmp) { |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 547 | com_err (program_name, 0, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 548 | _("bad gid/group name - %s"), |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 549 | optarg); |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 550 | usage(); |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 551 | } |
| 552 | g_flag = 1; |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 553 | open_flag = EXT2_FLAG_RW; |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 554 | break; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 555 | case 'i': |
| 556 | interval = strtoul (optarg, &tmp, 0); |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 557 | switch (*tmp) { |
| 558 | case 's': |
| 559 | tmp++; |
| 560 | break; |
| 561 | case '\0': |
| 562 | case 'd': |
| 563 | case 'D': /* days */ |
| 564 | interval *= 86400; |
| 565 | if (*tmp != '\0') |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 566 | tmp++; |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 567 | break; |
| 568 | case 'm': |
| 569 | case 'M': /* months! */ |
| 570 | interval *= 86400 * 30; |
| 571 | tmp++; |
| 572 | break; |
| 573 | case 'w': |
| 574 | case 'W': /* weeks */ |
| 575 | interval *= 86400 * 7; |
| 576 | tmp++; |
| 577 | break; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 578 | } |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 579 | if (*tmp || interval > (365 * 86400)) { |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 580 | com_err (program_name, 0, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 581 | _("bad interval - %s"), optarg); |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 582 | usage(); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 583 | } |
| 584 | i_flag = 1; |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 585 | open_flag = EXT2_FLAG_RW; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 586 | break; |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 587 | case 'j': |
Theodore Ts'o | dc2ec52 | 2001-01-18 01:51:15 +0000 | [diff] [blame] | 588 | if (!journal_size) |
| 589 | journal_size = -1; |
Theodore Ts'o | 4d0f228 | 2001-04-23 20:58:03 +0000 | [diff] [blame] | 590 | open_flag = EXT2_FLAG_RW; |
Theodore Ts'o | dc2ec52 | 2001-01-18 01:51:15 +0000 | [diff] [blame] | 591 | break; |
| 592 | case 'J': |
| 593 | parse_journal_opts(optarg); |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 594 | open_flag = EXT2_FLAG_RW; |
| 595 | break; |
Theodore Ts'o | 08dd830 | 2001-01-14 16:25:58 +0000 | [diff] [blame] | 596 | case 'l': |
| 597 | l_flag = 1; |
| 598 | break; |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 599 | case 'L': |
| 600 | new_label = optarg; |
| 601 | L_flag = 1; |
Andreas Dilger | 2d15576 | 2001-08-17 03:48:11 -0600 | [diff] [blame] | 602 | open_flag = EXT2_FLAG_RW | |
| 603 | EXT2_FLAG_JOURNAL_DEV_OK; |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 604 | break; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 605 | case 'm': |
| 606 | reserved_ratio = strtoul (optarg, &tmp, 0); |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 607 | if (*tmp || reserved_ratio > 50) { |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 608 | com_err (program_name, 0, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 609 | _("bad reserved block ratio - %s"), |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 610 | optarg); |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 611 | usage(); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 612 | } |
| 613 | m_flag = 1; |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 614 | open_flag = EXT2_FLAG_RW; |
| 615 | break; |
| 616 | case 'M': |
| 617 | new_last_mounted = optarg; |
| 618 | M_flag = 1; |
| 619 | open_flag = EXT2_FLAG_RW; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 620 | break; |
Theodore Ts'o | a0c3fd5 | 2002-10-15 17:43:43 -0400 | [diff] [blame] | 621 | case 'o': |
| 622 | if (mntopts_cmd) { |
| 623 | com_err (program_name, 0, |
| 624 | _("-o may only be specified once")); |
| 625 | usage(); |
| 626 | } |
| 627 | mntopts_cmd = optarg; |
| 628 | open_flag = EXT2_FLAG_RW; |
| 629 | break; |
| 630 | |
Theodore Ts'o | 896938d | 1999-10-23 01:04:50 +0000 | [diff] [blame] | 631 | case 'O': |
Theodore Ts'o | d258668 | 2001-08-15 11:03:58 -0400 | [diff] [blame] | 632 | if (features_cmd) { |
| 633 | com_err (program_name, 0, |
| 634 | _("-O may only be specified once")); |
| 635 | usage(); |
| 636 | } |
Theodore Ts'o | 896938d | 1999-10-23 01:04:50 +0000 | [diff] [blame] | 637 | features_cmd = optarg; |
| 638 | open_flag = EXT2_FLAG_RW; |
| 639 | break; |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 640 | case 'r': |
| 641 | reserved_blocks = strtoul (optarg, &tmp, 0); |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 642 | if (*tmp) { |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 643 | com_err (program_name, 0, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 644 | _("bad reserved blocks count - %s"), |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 645 | optarg); |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 646 | usage(); |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 647 | } |
| 648 | r_flag = 1; |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 649 | open_flag = EXT2_FLAG_RW; |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 650 | break; |
Theodore Ts'o | 521e368 | 1997-04-29 17:48:10 +0000 | [diff] [blame] | 651 | case 's': |
| 652 | s_flag = atoi(optarg); |
| 653 | open_flag = EXT2_FLAG_RW; |
| 654 | break; |
Theodore Ts'o | d4de4aa | 2001-12-26 08:58:01 -0500 | [diff] [blame] | 655 | case 'T': |
| 656 | T_flag = 1; |
| 657 | last_check_time = parse_time(optarg); |
| 658 | open_flag = EXT2_FLAG_RW; |
| 659 | break; |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 660 | case 'u': |
| 661 | resuid = strtoul (optarg, &tmp, 0); |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 662 | if (*tmp) { |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 663 | pw = getpwnam (optarg); |
| 664 | if (pw == NULL) |
| 665 | tmp = optarg; |
Theodore Ts'o | a418d3a | 1997-04-26 14:00:26 +0000 | [diff] [blame] | 666 | else { |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 667 | resuid = pw->pw_uid; |
Theodore Ts'o | a418d3a | 1997-04-26 14:00:26 +0000 | [diff] [blame] | 668 | *tmp = 0; |
| 669 | } |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 670 | } |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 671 | if (*tmp) { |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 672 | com_err (program_name, 0, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 673 | _("bad uid/user name - %s"), |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 674 | optarg); |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 675 | usage(); |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 676 | } |
| 677 | u_flag = 1; |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 678 | open_flag = EXT2_FLAG_RW; |
| 679 | break; |
| 680 | case 'U': |
| 681 | new_UUID = optarg; |
| 682 | U_flag = 1; |
Andreas Dilger | 2d15576 | 2001-08-17 03:48:11 -0600 | [diff] [blame] | 683 | open_flag = EXT2_FLAG_RW | |
| 684 | EXT2_FLAG_JOURNAL_DEV_OK; |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 685 | break; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 686 | default: |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 687 | usage(); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 688 | } |
| 689 | if (optind < argc - 1 || optind == argc) |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 690 | usage(); |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 691 | if (!open_flag && !l_flag) |
| 692 | usage(); |
Theodore Ts'o | 332f2c2 | 2003-03-06 12:58:33 -0500 | [diff] [blame] | 693 | device_name = blkid_get_devname(NULL, argv[optind], NULL); |
Theodore Ts'o | 118d7da | 2002-08-17 23:01:22 -0400 | [diff] [blame] | 694 | } |
Theodore Ts'o | 8323815 | 2001-01-09 00:16:26 +0000 | [diff] [blame] | 695 | |
Theodore Ts'o | 3e69906 | 2002-10-13 23:56:28 -0400 | [diff] [blame] | 696 | void do_findfs(int argc, char **argv) |
Theodore Ts'o | 118d7da | 2002-08-17 23:01:22 -0400 | [diff] [blame] | 697 | { |
| 698 | char *dev; |
| 699 | |
| 700 | if ((argc != 2) || |
| 701 | (strncmp(argv[1], "LABEL=", 6) && strncmp(argv[1], "UUID=", 5))) { |
| 702 | fprintf(stderr, "Usage: findfs LABEL=<label>|UUID=<uuid>\n"); |
| 703 | exit(2); |
| 704 | } |
Theodore Ts'o | ed1b33e | 2003-03-01 19:29:01 -0500 | [diff] [blame] | 705 | dev = blkid_get_devname(NULL, argv[1], NULL); |
Theodore Ts'o | 118d7da | 2002-08-17 23:01:22 -0400 | [diff] [blame] | 706 | if (!dev) { |
| 707 | fprintf(stderr, "Filesystem matching %s not found\n", |
| 708 | argv[1]); |
| 709 | exit(1); |
| 710 | } |
| 711 | puts(dev); |
| 712 | exit(0); |
| 713 | } |
Theodore Ts'o | 8323815 | 2001-01-09 00:16:26 +0000 | [diff] [blame] | 714 | |
| 715 | |
| 716 | int main (int argc, char ** argv) |
| 717 | { |
| 718 | errcode_t retval; |
| 719 | ext2_filsys fs; |
| 720 | struct ext2_super_block *sb; |
Theodore Ts'o | 2a29f13 | 2003-05-05 12:08:47 -0400 | [diff] [blame^] | 721 | io_manager io_ptr; |
Theodore Ts'o | 8323815 | 2001-01-09 00:16:26 +0000 | [diff] [blame] | 722 | |
| 723 | #ifdef ENABLE_NLS |
| 724 | setlocale(LC_MESSAGES, ""); |
Theodore Ts'o | 14308a5 | 2002-03-05 03:26:52 -0500 | [diff] [blame] | 725 | setlocale(LC_CTYPE, ""); |
Theodore Ts'o | 8323815 | 2001-01-09 00:16:26 +0000 | [diff] [blame] | 726 | bindtextdomain(NLS_CAT_NAME, LOCALEDIR); |
| 727 | textdomain(NLS_CAT_NAME); |
| 728 | #endif |
| 729 | if (argc && *argv) |
| 730 | program_name = *argv; |
| 731 | initialize_ext2_error_table(); |
| 732 | |
Theodore Ts'o | 118d7da | 2002-08-17 23:01:22 -0400 | [diff] [blame] | 733 | if (strcmp(get_progname(argv[0]), "findfs") == 0) |
| 734 | do_findfs(argc, argv); |
Theodore Ts'o | 8323815 | 2001-01-09 00:16:26 +0000 | [diff] [blame] | 735 | if (strcmp(get_progname(argv[0]), "e2label") == 0) |
| 736 | parse_e2label_options(argc, argv); |
| 737 | else |
| 738 | parse_tune2fs_options(argc, argv); |
| 739 | |
Theodore Ts'o | 2a29f13 | 2003-05-05 12:08:47 -0400 | [diff] [blame^] | 740 | #ifdef CONFIG_TESTIO_DEBUG |
| 741 | io_ptr = test_io_manager; |
| 742 | test_io_backing_manager = unix_io_manager; |
| 743 | #else |
| 744 | io_ptr = unix_io_manager; |
| 745 | #endif |
| 746 | retval = ext2fs_open (device_name, open_flag, 0, 0, io_ptr, &fs); |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 747 | if (retval) { |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 748 | com_err (program_name, retval, _("while trying to open %s"), |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 749 | device_name); |
Theodore Ts'o | 7141b54 | 2001-08-15 19:17:37 -0400 | [diff] [blame] | 750 | fprintf(stderr, |
| 751 | _("Couldn't find valid filesystem superblock.\n")); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 752 | exit(1); |
| 753 | } |
Theodore Ts'o | 8323815 | 2001-01-09 00:16:26 +0000 | [diff] [blame] | 754 | sb = fs->super; |
| 755 | if (print_label) { |
| 756 | /* For e2label emulation */ |
Theodore Ts'o | c8c071a | 2001-01-11 16:08:23 +0000 | [diff] [blame] | 757 | printf("%.*s\n", (int) sizeof(sb->s_volume_name), |
| 758 | sb->s_volume_name); |
Theodore Ts'o | 8323815 | 2001-01-09 00:16:26 +0000 | [diff] [blame] | 759 | exit(0); |
| 760 | } |
Theodore Ts'o | b21e38a | 2001-01-01 15:26:58 +0000 | [diff] [blame] | 761 | retval = ext2fs_check_if_mounted(device_name, &mount_flags); |
| 762 | if (retval) { |
| 763 | com_err("ext2fs_check_if_mount", retval, |
| 764 | _("while determining whether %s is mounted."), |
| 765 | device_name); |
Theodore Ts'o | 4055ef7 | 2001-01-14 16:11:14 +0000 | [diff] [blame] | 766 | exit(1); |
Theodore Ts'o | b21e38a | 2001-01-01 15:26:58 +0000 | [diff] [blame] | 767 | } |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 768 | /* Normally we only need to write out the superblock */ |
| 769 | fs->flags |= EXT2_FLAG_SUPER_ONLY; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 770 | |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 771 | if (c_flag) { |
Theodore Ts'o | b21e38a | 2001-01-01 15:26:58 +0000 | [diff] [blame] | 772 | sb->s_max_mnt_count = max_mount_count; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 773 | ext2fs_mark_super_dirty(fs); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 774 | printf (_("Setting maximal mount count to %d\n"), |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 775 | max_mount_count); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 776 | } |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 777 | if (C_flag) { |
Theodore Ts'o | b21e38a | 2001-01-01 15:26:58 +0000 | [diff] [blame] | 778 | sb->s_mnt_count = mount_count; |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 779 | ext2fs_mark_super_dirty(fs); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 780 | printf (_("Setting current mount count to %d\n"), mount_count); |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 781 | } |
| 782 | if (e_flag) { |
Theodore Ts'o | b21e38a | 2001-01-01 15:26:58 +0000 | [diff] [blame] | 783 | sb->s_errors = errors; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 784 | ext2fs_mark_super_dirty(fs); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 785 | printf (_("Setting error behavior to %d\n"), errors); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 786 | } |
Theodore Ts'o | b21e38a | 2001-01-01 15:26:58 +0000 | [diff] [blame] | 787 | if (g_flag) { |
| 788 | sb->s_def_resgid = resgid; |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 789 | ext2fs_mark_super_dirty(fs); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 790 | printf (_("Setting reserved blocks gid to %lu\n"), resgid); |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 791 | } |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 792 | if (i_flag) { |
Theodore Ts'o | b21e38a | 2001-01-01 15:26:58 +0000 | [diff] [blame] | 793 | sb->s_checkinterval = interval; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 794 | ext2fs_mark_super_dirty(fs); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 795 | printf (_("Setting interval between check %lu seconds\n"), interval); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 796 | } |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 797 | if (m_flag) { |
Theodore Ts'o | b21e38a | 2001-01-01 15:26:58 +0000 | [diff] [blame] | 798 | sb->s_r_blocks_count = (sb->s_blocks_count / 100) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 799 | * reserved_ratio; |
| 800 | ext2fs_mark_super_dirty(fs); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 801 | printf (_("Setting reserved blocks percentage to %lu (%u blocks)\n"), |
Theodore Ts'o | b21e38a | 2001-01-01 15:26:58 +0000 | [diff] [blame] | 802 | reserved_ratio, sb->s_r_blocks_count); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 803 | } |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 804 | if (r_flag) { |
Theodore Ts'o | b21e38a | 2001-01-01 15:26:58 +0000 | [diff] [blame] | 805 | if (reserved_blocks >= sb->s_blocks_count) { |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 806 | com_err (program_name, 0, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 807 | _("reserved blocks count is too big (%ul)"), |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 808 | reserved_blocks); |
| 809 | exit (1); |
| 810 | } |
Theodore Ts'o | b21e38a | 2001-01-01 15:26:58 +0000 | [diff] [blame] | 811 | sb->s_r_blocks_count = reserved_blocks; |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 812 | ext2fs_mark_super_dirty(fs); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 813 | printf (_("Setting reserved blocks count to %lu\n"), |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 814 | reserved_blocks); |
| 815 | } |
Theodore Ts'o | 521e368 | 1997-04-29 17:48:10 +0000 | [diff] [blame] | 816 | if (s_flag == 1) { |
Theodore Ts'o | 521e368 | 1997-04-29 17:48:10 +0000 | [diff] [blame] | 817 | if (sb->s_feature_ro_compat & |
| 818 | EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER) |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 819 | fprintf(stderr, _("\nThe filesystem already" |
Theodore Ts'o | e1a0a3e | 2000-02-11 05:00:19 +0000 | [diff] [blame] | 820 | " has sparse superblocks.\n")); |
Theodore Ts'o | 521e368 | 1997-04-29 17:48:10 +0000 | [diff] [blame] | 821 | else { |
| 822 | sb->s_feature_ro_compat |= |
| 823 | EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER; |
Theodore Ts'o | b21e38a | 2001-01-01 15:26:58 +0000 | [diff] [blame] | 824 | sb->s_state &= ~EXT2_VALID_FS; |
Theodore Ts'o | 521e368 | 1997-04-29 17:48:10 +0000 | [diff] [blame] | 825 | ext2fs_mark_super_dirty(fs); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 826 | printf(_("\nSparse superblock flag set. %s"), |
Theodore Ts'o | a4fa100 | 2000-02-08 21:35:41 +0000 | [diff] [blame] | 827 | _(please_fsck)); |
Theodore Ts'o | 521e368 | 1997-04-29 17:48:10 +0000 | [diff] [blame] | 828 | } |
Theodore Ts'o | 521e368 | 1997-04-29 17:48:10 +0000 | [diff] [blame] | 829 | } |
| 830 | if (s_flag == 0) { |
Theodore Ts'o | 521e368 | 1997-04-29 17:48:10 +0000 | [diff] [blame] | 831 | if (!(sb->s_feature_ro_compat & |
| 832 | EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER)) |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 833 | fprintf(stderr, _("\nThe filesystem already" |
Theodore Ts'o | e1a0a3e | 2000-02-11 05:00:19 +0000 | [diff] [blame] | 834 | " has sparse superblocks disabled.\n")); |
Theodore Ts'o | 521e368 | 1997-04-29 17:48:10 +0000 | [diff] [blame] | 835 | else { |
| 836 | sb->s_feature_ro_compat &= |
| 837 | ~EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER; |
Theodore Ts'o | b21e38a | 2001-01-01 15:26:58 +0000 | [diff] [blame] | 838 | sb->s_state &= ~EXT2_VALID_FS; |
Theodore Ts'o | 521e368 | 1997-04-29 17:48:10 +0000 | [diff] [blame] | 839 | fs->flags |= EXT2_FLAG_MASTER_SB_ONLY; |
| 840 | ext2fs_mark_super_dirty(fs); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 841 | printf(_("\nSparse superblock flag cleared. %s"), |
Theodore Ts'o | a4fa100 | 2000-02-08 21:35:41 +0000 | [diff] [blame] | 842 | _(please_fsck)); |
Theodore Ts'o | 521e368 | 1997-04-29 17:48:10 +0000 | [diff] [blame] | 843 | } |
Theodore Ts'o | 521e368 | 1997-04-29 17:48:10 +0000 | [diff] [blame] | 844 | } |
Theodore Ts'o | d4de4aa | 2001-12-26 08:58:01 -0500 | [diff] [blame] | 845 | if (T_flag) { |
| 846 | sb->s_lastcheck = last_check_time; |
| 847 | ext2fs_mark_super_dirty(fs); |
| 848 | printf(_("Setting time filesystem last checked to %s\n"), |
| 849 | ctime(&last_check_time)); |
| 850 | } |
Theodore Ts'o | b21e38a | 2001-01-01 15:26:58 +0000 | [diff] [blame] | 851 | if (u_flag) { |
| 852 | sb->s_def_resuid = resuid; |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 853 | ext2fs_mark_super_dirty(fs); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 854 | printf (_("Setting reserved blocks uid to %lu\n"), resuid); |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 855 | } |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 856 | if (L_flag) { |
Theodore Ts'o | a789d84 | 1998-03-30 01:20:55 +0000 | [diff] [blame] | 857 | if (strlen(new_label) > sizeof(sb->s_volume_name)) |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 858 | fprintf(stderr, _("Warning: label too " |
| 859 | "long, truncating.\n")); |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 860 | memset(sb->s_volume_name, 0, sizeof(sb->s_volume_name)); |
| 861 | strncpy(sb->s_volume_name, new_label, |
| 862 | sizeof(sb->s_volume_name)); |
| 863 | ext2fs_mark_super_dirty(fs); |
| 864 | } |
| 865 | if (M_flag) { |
| 866 | memset(sb->s_last_mounted, 0, sizeof(sb->s_last_mounted)); |
| 867 | strncpy(sb->s_last_mounted, new_last_mounted, |
| 868 | sizeof(sb->s_last_mounted)); |
| 869 | ext2fs_mark_super_dirty(fs); |
| 870 | } |
Theodore Ts'o | a0c3fd5 | 2002-10-15 17:43:43 -0400 | [diff] [blame] | 871 | if (mntopts_cmd) |
| 872 | update_mntopts(fs, mntopts_cmd); |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 873 | if (features_cmd) |
| 874 | update_feature_set(fs, features_cmd); |
Theodore Ts'o | dc2ec52 | 2001-01-18 01:51:15 +0000 | [diff] [blame] | 875 | if (journal_size || journal_device) |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 876 | add_journal(fs); |
| 877 | |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 878 | if (U_flag) { |
Theodore Ts'o | 4d0f228 | 2001-04-23 20:58:03 +0000 | [diff] [blame] | 879 | if ((strcasecmp(new_UUID, "null") == 0) || |
| 880 | (strcasecmp(new_UUID, "clear") == 0)) { |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 881 | uuid_clear(sb->s_uuid); |
Theodore Ts'o | 6398532 | 2001-01-03 17:02:13 +0000 | [diff] [blame] | 882 | } else if (strcasecmp(new_UUID, "time") == 0) { |
| 883 | uuid_generate_time(sb->s_uuid); |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 884 | } else if (strcasecmp(new_UUID, "random") == 0) { |
| 885 | uuid_generate(sb->s_uuid); |
| 886 | } else if (uuid_parse(new_UUID, sb->s_uuid)) { |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 887 | com_err(program_name, 0, _("Invalid UUID format\n")); |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 888 | exit(1); |
| 889 | } |
| 890 | ext2fs_mark_super_dirty(fs); |
| 891 | } |
| 892 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 893 | if (l_flag) |
Theodore Ts'o | b21e38a | 2001-01-01 15:26:58 +0000 | [diff] [blame] | 894 | list_super (sb); |
Andreas Dilger | c007bc0 | 2001-12-25 23:10:40 -0700 | [diff] [blame] | 895 | return (ext2fs_close (fs) ? 1 : 0); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 896 | } |