Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1 | /* |
| 2 | * tune2fs.c - Change the file system parameters on |
| 3 | * an unmounted second extended file system |
| 4 | * |
| 5 | * Copyright (C) 1992, 1993, 1994 Remy Card <card@masi.ibp.fr> |
| 6 | * Laboratoire MASI, Institut Blaise Pascal |
| 7 | * Universite Pierre et Marie Curie (Paris VI) |
| 8 | * |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 9 | * Copyright 1995, 1996, 1997 by Theodore Ts'o. |
| 10 | * |
| 11 | * %Begin-Header% |
| 12 | * This file may be redistributed under the terms of the GNU Public |
| 13 | * License. |
| 14 | * %End-Header% |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | /* |
| 18 | * History: |
| 19 | * 93/06/01 - Creation |
| 20 | * 93/10/31 - Added the -c option to change the maximal mount counts |
| 21 | * 93/12/14 - Added -l flag to list contents of superblock |
| 22 | * M.J.E. Mol (marcel@duteca.et.tudelft.nl) |
| 23 | * F.W. ten Wolde (franky@duteca.et.tudelft.nl) |
| 24 | * 93/12/29 - Added the -e option to change errors behavior |
| 25 | * 94/02/27 - Ported to use the ext2fs library |
| 26 | * 94/03/06 - Added the checks interval from Uwe Ohse (uwe@tirka.gun.de) |
| 27 | */ |
| 28 | |
| 29 | #include <fcntl.h> |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 30 | #include <grp.h> |
Theodore Ts'o | a418d3a | 1997-04-26 14:00:26 +0000 | [diff] [blame] | 31 | #ifdef HAVE_GETOPT_H |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 32 | #include <getopt.h> |
Theodore Ts'o | a418d3a | 1997-04-26 14:00:26 +0000 | [diff] [blame] | 33 | #endif |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 34 | #include <pwd.h> |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 35 | #include <stdio.h> |
| 36 | #include <stdlib.h> |
| 37 | #include <string.h> |
| 38 | #include <time.h> |
| 39 | #include <unistd.h> |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 40 | #include <sys/types.h> |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 41 | |
| 42 | #include <linux/ext2_fs.h> |
| 43 | |
| 44 | #include "ext2fs/ext2fs.h" |
| 45 | #include "et/com_err.h" |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 46 | #include "uuid/uuid.h" |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 47 | #include "e2p/e2p.h" |
| 48 | |
| 49 | #include "../version.h" |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 50 | #include "nls-enable.h" |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 51 | |
| 52 | const char * program_name = "tune2fs"; |
| 53 | char * device_name = NULL; |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 54 | char * new_label = NULL; |
| 55 | char * new_last_mounted = NULL; |
| 56 | char * new_UUID = NULL; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 57 | int c_flag = 0; |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 58 | int C_flag = 0; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 59 | int e_flag = 0; |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 60 | int g_flag = 0; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 61 | int i_flag = 0; |
| 62 | int l_flag = 0; |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 63 | int L_flag = 0; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 64 | int m_flag = 0; |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 65 | int M_flag = 0; |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 66 | int r_flag = 0; |
Theodore Ts'o | 521e368 | 1997-04-29 17:48:10 +0000 | [diff] [blame] | 67 | int s_flag = -1; |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 68 | int u_flag = 0; |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 69 | int U_flag = 0; |
| 70 | int max_mount_count, mount_count; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 71 | unsigned long interval; |
| 72 | unsigned long reserved_ratio = 0; |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 73 | unsigned long reserved_blocks = 0; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 74 | unsigned short errors; |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 75 | unsigned long resgid = 0; |
| 76 | unsigned long resuid = 0; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 77 | |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 78 | #ifndef HAVE_STRCASECMP |
| 79 | static int strcasecmp (char *s1, char *s2) |
| 80 | { |
| 81 | while (*s1 && *s2) { |
| 82 | int ch1 = *s1++, ch2 = *s2++; |
| 83 | if (isupper (ch1)) |
| 84 | ch1 = tolower (ch1); |
| 85 | if (isupper (ch2)) |
| 86 | ch2 = tolower (ch2); |
| 87 | if (ch1 != ch2) |
| 88 | return ch1 - ch2; |
| 89 | } |
| 90 | return *s1 ? 1 : *s2 ? -1 : 0; |
| 91 | } |
| 92 | #endif |
| 93 | |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 94 | static void usage(void) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 95 | { |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 96 | fprintf(stderr, _("Usage: %s [-c max-mounts-count] [-e errors-behavior] " |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 97 | "[-g group]\n" |
Theodore Ts'o | 582134c | 2000-01-19 13:26:23 +0000 | [diff] [blame] | 98 | "\t[-i interval[d|m|w]] [-l] [-s sparse-flag] " |
| 99 | "[-m reserved-blocks-percent]\n" |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 100 | "\t[-r reserved-blocks-count] [-u user] [-C mount-count]\n" |
Theodore Ts'o | 896938d | 1999-10-23 01:04:50 +0000 | [diff] [blame] | 101 | "\t[-L volume-label] [-M last-mounted-dir] [-U UUID]\n" |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 102 | "\t[-O [^]feature[,...]] device\n"), program_name); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 103 | exit (1); |
| 104 | } |
| 105 | |
Theodore Ts'o | 896938d | 1999-10-23 01:04:50 +0000 | [diff] [blame] | 106 | static __u32 ok_features[3] = { |
| 107 | 0, /* Compat */ |
| 108 | EXT2_FEATURE_INCOMPAT_FILETYPE, /* Incompat */ |
| 109 | EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER /* R/O compat */ |
| 110 | }; |
| 111 | |
Theodore Ts'o | a4fa100 | 2000-02-08 21:35:41 +0000 | [diff] [blame] | 112 | static const char *please_fsck = N_("Please run e2fsck on the filesystem.\n"); |
Theodore Ts'o | 896938d | 1999-10-23 01:04:50 +0000 | [diff] [blame] | 113 | |
Theodore Ts'o | 00e5433 | 1997-09-16 02:13:52 +0000 | [diff] [blame] | 114 | int main (int argc, char ** argv) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 115 | { |
Theodore Ts'o | 519149f | 1997-10-25 03:49:49 +0000 | [diff] [blame] | 116 | int c; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 117 | char * tmp; |
| 118 | errcode_t retval; |
| 119 | ext2_filsys fs; |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 120 | struct ext2fs_sb *sb; |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 121 | struct group * gr; |
| 122 | struct passwd * pw; |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 123 | int open_flag = 0; |
Theodore Ts'o | 896938d | 1999-10-23 01:04:50 +0000 | [diff] [blame] | 124 | char *features_cmd = 0; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 125 | |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 126 | #ifdef ENABLE_NLS |
| 127 | setlocale(LC_MESSAGES, ""); |
| 128 | bindtextdomain(NLS_CAT_NAME, LOCALEDIR); |
| 129 | textdomain(NLS_CAT_NAME); |
| 130 | #endif |
| 131 | fprintf (stderr, _("tune2fs %s, %s for EXT2 FS %s, %s\n"), |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 132 | E2FSPROGS_VERSION, E2FSPROGS_DATE, |
| 133 | EXT2FS_VERSION, EXT2FS_DATE); |
| 134 | if (argc && *argv) |
| 135 | program_name = *argv; |
| 136 | initialize_ext2_error_table(); |
Theodore Ts'o | 896938d | 1999-10-23 01:04:50 +0000 | [diff] [blame] | 137 | while ((c = getopt (argc, argv, "c:e:g:i:lm:r:s:u:C:L:M:O:U:")) != EOF) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 138 | switch (c) |
| 139 | { |
| 140 | case 'c': |
| 141 | max_mount_count = strtoul (optarg, &tmp, 0); |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 142 | if (*tmp || max_mount_count > 16000) { |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 143 | com_err (program_name, 0, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 144 | _("bad mounts count - %s"), |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 145 | optarg); |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 146 | usage(); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 147 | } |
| 148 | c_flag = 1; |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 149 | open_flag = EXT2_FLAG_RW; |
| 150 | break; |
| 151 | case 'C': |
| 152 | mount_count = strtoul (optarg, &tmp, 0); |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 153 | if (*tmp || mount_count > 16000) { |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 154 | com_err (program_name, 0, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 155 | _("bad mounts count - %s"), |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 156 | optarg); |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 157 | usage(); |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 158 | } |
| 159 | C_flag = 1; |
| 160 | open_flag = EXT2_FLAG_RW; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 161 | break; |
| 162 | case 'e': |
| 163 | if (strcmp (optarg, "continue") == 0) |
| 164 | errors = EXT2_ERRORS_CONTINUE; |
| 165 | else if (strcmp (optarg, "remount-ro") == 0) |
| 166 | errors = EXT2_ERRORS_RO; |
| 167 | else if (strcmp (optarg, "panic") == 0) |
| 168 | errors = EXT2_ERRORS_PANIC; |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 169 | else { |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 170 | com_err (program_name, 0, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 171 | _("bad error behavior - %s"), |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 172 | optarg); |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 173 | usage(); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 174 | } |
| 175 | e_flag = 1; |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 176 | open_flag = EXT2_FLAG_RW; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 177 | break; |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 178 | case 'g': |
| 179 | resgid = strtoul (optarg, &tmp, 0); |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 180 | if (*tmp) { |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 181 | gr = getgrnam (optarg); |
| 182 | if (gr == NULL) |
| 183 | tmp = optarg; |
Theodore Ts'o | a418d3a | 1997-04-26 14:00:26 +0000 | [diff] [blame] | 184 | else { |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 185 | resgid = gr->gr_gid; |
Theodore Ts'o | a418d3a | 1997-04-26 14:00:26 +0000 | [diff] [blame] | 186 | *tmp =0; |
| 187 | } |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 188 | } |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 189 | if (*tmp) { |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 190 | com_err (program_name, 0, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 191 | _("bad gid/group name - %s"), |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 192 | optarg); |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 193 | usage(); |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 194 | } |
| 195 | g_flag = 1; |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 196 | open_flag = EXT2_FLAG_RW; |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 197 | break; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 198 | case 'i': |
| 199 | interval = strtoul (optarg, &tmp, 0); |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 200 | switch (*tmp) { |
| 201 | case 's': |
| 202 | tmp++; |
| 203 | break; |
| 204 | case '\0': |
| 205 | case 'd': |
| 206 | case 'D': /* days */ |
| 207 | interval *= 86400; |
| 208 | if (*tmp != '\0') |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 209 | tmp++; |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 210 | break; |
| 211 | case 'm': |
| 212 | case 'M': /* months! */ |
| 213 | interval *= 86400 * 30; |
| 214 | tmp++; |
| 215 | break; |
| 216 | case 'w': |
| 217 | case 'W': /* weeks */ |
| 218 | interval *= 86400 * 7; |
| 219 | tmp++; |
| 220 | break; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 221 | } |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 222 | if (*tmp || interval > (365 * 86400)) { |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 223 | com_err (program_name, 0, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 224 | _("bad interval - %s"), optarg); |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 225 | usage(); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 226 | } |
| 227 | i_flag = 1; |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 228 | open_flag = EXT2_FLAG_RW; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 229 | break; |
| 230 | case 'l': |
| 231 | l_flag = 1; |
| 232 | break; |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 233 | case 'L': |
| 234 | new_label = optarg; |
| 235 | L_flag = 1; |
| 236 | open_flag = EXT2_FLAG_RW; |
| 237 | break; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 238 | case 'm': |
| 239 | reserved_ratio = strtoul (optarg, &tmp, 0); |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 240 | if (*tmp || reserved_ratio > 50) { |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 241 | com_err (program_name, 0, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 242 | _("bad reserved block ratio - %s"), |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 243 | optarg); |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 244 | usage(); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 245 | } |
| 246 | m_flag = 1; |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 247 | open_flag = EXT2_FLAG_RW; |
| 248 | break; |
| 249 | case 'M': |
| 250 | new_last_mounted = optarg; |
| 251 | M_flag = 1; |
| 252 | open_flag = EXT2_FLAG_RW; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 253 | break; |
Theodore Ts'o | 896938d | 1999-10-23 01:04:50 +0000 | [diff] [blame] | 254 | case 'O': |
| 255 | features_cmd = optarg; |
| 256 | open_flag = EXT2_FLAG_RW; |
| 257 | break; |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 258 | case 'r': |
| 259 | reserved_blocks = strtoul (optarg, &tmp, 0); |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 260 | if (*tmp) { |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 261 | com_err (program_name, 0, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 262 | _("bad reserved blocks count - %s"), |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 263 | optarg); |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 264 | usage(); |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 265 | } |
| 266 | r_flag = 1; |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 267 | open_flag = EXT2_FLAG_RW; |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 268 | break; |
Theodore Ts'o | 521e368 | 1997-04-29 17:48:10 +0000 | [diff] [blame] | 269 | case 's': |
| 270 | s_flag = atoi(optarg); |
| 271 | open_flag = EXT2_FLAG_RW; |
| 272 | break; |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 273 | case 'u': |
| 274 | resuid = strtoul (optarg, &tmp, 0); |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 275 | if (*tmp) { |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 276 | pw = getpwnam (optarg); |
| 277 | if (pw == NULL) |
| 278 | tmp = optarg; |
Theodore Ts'o | a418d3a | 1997-04-26 14:00:26 +0000 | [diff] [blame] | 279 | else { |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 280 | resuid = pw->pw_uid; |
Theodore Ts'o | a418d3a | 1997-04-26 14:00:26 +0000 | [diff] [blame] | 281 | *tmp = 0; |
| 282 | } |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 283 | } |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 284 | if (*tmp) { |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 285 | com_err (program_name, 0, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 286 | _("bad uid/user name - %s"), |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 287 | optarg); |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 288 | usage(); |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 289 | } |
| 290 | u_flag = 1; |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 291 | open_flag = EXT2_FLAG_RW; |
| 292 | break; |
| 293 | case 'U': |
| 294 | new_UUID = optarg; |
| 295 | U_flag = 1; |
| 296 | open_flag = EXT2_FLAG_RW; |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 297 | break; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 298 | default: |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 299 | usage(); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 300 | } |
| 301 | if (optind < argc - 1 || optind == argc) |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 302 | usage(); |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 303 | if (!open_flag && !l_flag) |
| 304 | usage(); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 305 | device_name = argv[optind]; |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 306 | retval = ext2fs_open (device_name, open_flag, 0, 0, |
| 307 | unix_io_manager, &fs); |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 308 | if (retval) { |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 309 | com_err (program_name, retval, _("while trying to open %s"), |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 310 | device_name); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 311 | printf(_("Couldn't find valid filesystem superblock.\n")); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 312 | exit(1); |
| 313 | } |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 314 | sb = (struct ext2fs_sb *) fs->super; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 315 | |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 316 | if (c_flag) { |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 317 | fs->super->s_max_mnt_count = max_mount_count; |
| 318 | ext2fs_mark_super_dirty(fs); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 319 | printf (_("Setting maximal mount count to %d\n"), |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 320 | max_mount_count); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 321 | } |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 322 | if (C_flag) { |
| 323 | fs->super->s_mnt_count = mount_count; |
| 324 | ext2fs_mark_super_dirty(fs); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 325 | printf (_("Setting current mount count to %d\n"), mount_count); |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 326 | } |
| 327 | if (e_flag) { |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 328 | fs->super->s_errors = errors; |
| 329 | ext2fs_mark_super_dirty(fs); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 330 | printf (_("Setting error behavior to %d\n"), errors); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 331 | } |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 332 | if (g_flag) |
| 333 | #ifdef EXT2_DEF_RESGID |
| 334 | { |
| 335 | fs->super->s_def_resgid = resgid; |
| 336 | ext2fs_mark_super_dirty(fs); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 337 | printf (_("Setting reserved blocks gid to %lu\n"), resgid); |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 338 | } |
| 339 | #else |
| 340 | com_err (program_name, 0, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 341 | _("The -g option is not supported by this version -- " |
| 342 | "Recompile with a newer kernel")); |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 343 | #endif |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 344 | if (i_flag) { |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 345 | fs->super->s_checkinterval = interval; |
| 346 | ext2fs_mark_super_dirty(fs); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 347 | printf (_("Setting interval between check %lu seconds\n"), interval); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 348 | } |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 349 | if (m_flag) { |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 350 | fs->super->s_r_blocks_count = (fs->super->s_blocks_count / 100) |
| 351 | * reserved_ratio; |
| 352 | ext2fs_mark_super_dirty(fs); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 353 | printf (_("Setting reserved blocks percentage to %lu (%u blocks)\n"), |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 354 | reserved_ratio, fs->super->s_r_blocks_count); |
| 355 | } |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 356 | if (r_flag) { |
| 357 | if (reserved_blocks >= fs->super->s_blocks_count) { |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 358 | com_err (program_name, 0, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 359 | _("reserved blocks count is too big (%ul)"), |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 360 | reserved_blocks); |
| 361 | exit (1); |
| 362 | } |
| 363 | fs->super->s_r_blocks_count = reserved_blocks; |
| 364 | ext2fs_mark_super_dirty(fs); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 365 | printf (_("Setting reserved blocks count to %lu\n"), |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 366 | reserved_blocks); |
| 367 | } |
Theodore Ts'o | 521e368 | 1997-04-29 17:48:10 +0000 | [diff] [blame] | 368 | if (s_flag == 1) { |
| 369 | #ifdef EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER |
| 370 | if (sb->s_feature_ro_compat & |
| 371 | EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER) |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 372 | fprintf(stderr, _("\nThe filesystem already" |
Theodore Ts'o | e1a0a3e | 2000-02-11 05:00:19 +0000 | [diff] [blame^] | 373 | " has sparse superblocks.\n")); |
Theodore Ts'o | 521e368 | 1997-04-29 17:48:10 +0000 | [diff] [blame] | 374 | else { |
| 375 | sb->s_feature_ro_compat |= |
| 376 | EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER; |
| 377 | fs->super->s_state &= ~EXT2_VALID_FS; |
| 378 | ext2fs_mark_super_dirty(fs); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 379 | printf(_("\nSparse superblock flag set. %s"), |
Theodore Ts'o | a4fa100 | 2000-02-08 21:35:41 +0000 | [diff] [blame] | 380 | _(please_fsck)); |
Theodore Ts'o | 521e368 | 1997-04-29 17:48:10 +0000 | [diff] [blame] | 381 | } |
| 382 | #else /* !EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER */ |
| 383 | com_err (program_name, 0, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 384 | _("The -s option is not supported by this version -- " |
| 385 | "Recompile with a newer kernel")); |
Theodore Ts'o | 521e368 | 1997-04-29 17:48:10 +0000 | [diff] [blame] | 386 | #endif /* EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER */ |
| 387 | } |
| 388 | if (s_flag == 0) { |
| 389 | #ifdef EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER |
| 390 | if (!(sb->s_feature_ro_compat & |
| 391 | EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER)) |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 392 | fprintf(stderr, _("\nThe filesystem already" |
Theodore Ts'o | e1a0a3e | 2000-02-11 05:00:19 +0000 | [diff] [blame^] | 393 | " has sparse superblocks disabled.\n")); |
Theodore Ts'o | 521e368 | 1997-04-29 17:48:10 +0000 | [diff] [blame] | 394 | else { |
| 395 | sb->s_feature_ro_compat &= |
| 396 | ~EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER; |
| 397 | fs->super->s_state &= ~EXT2_VALID_FS; |
| 398 | fs->flags |= EXT2_FLAG_MASTER_SB_ONLY; |
| 399 | ext2fs_mark_super_dirty(fs); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 400 | printf(_("\nSparse superblock flag cleared. %s"), |
Theodore Ts'o | a4fa100 | 2000-02-08 21:35:41 +0000 | [diff] [blame] | 401 | _(please_fsck)); |
Theodore Ts'o | 521e368 | 1997-04-29 17:48:10 +0000 | [diff] [blame] | 402 | } |
| 403 | #else /* !EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER */ |
| 404 | com_err (program_name, 0, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 405 | _("The -s option is not supported by this version -- " |
| 406 | "Recompile with a newer kernel")); |
Theodore Ts'o | 521e368 | 1997-04-29 17:48:10 +0000 | [diff] [blame] | 407 | #endif /* EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER */ |
| 408 | } |
| 409 | |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 410 | if (u_flag) |
| 411 | #ifdef EXT2_DEF_RESUID |
| 412 | { |
| 413 | fs->super->s_def_resuid = resuid; |
| 414 | ext2fs_mark_super_dirty(fs); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 415 | printf (_("Setting reserved blocks uid to %lu\n"), resuid); |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 416 | } |
| 417 | #else |
| 418 | com_err (program_name, 0, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 419 | _("The -u option is not supported by this version -- " |
| 420 | "Recompile with a newer kernel")); |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 421 | #endif |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 422 | if (L_flag) { |
Theodore Ts'o | a789d84 | 1998-03-30 01:20:55 +0000 | [diff] [blame] | 423 | if (strlen(new_label) > sizeof(sb->s_volume_name)) |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 424 | fprintf(stderr, _("Warning: label too " |
| 425 | "long, truncating.\n")); |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 426 | memset(sb->s_volume_name, 0, sizeof(sb->s_volume_name)); |
| 427 | strncpy(sb->s_volume_name, new_label, |
| 428 | sizeof(sb->s_volume_name)); |
| 429 | ext2fs_mark_super_dirty(fs); |
| 430 | } |
| 431 | if (M_flag) { |
| 432 | memset(sb->s_last_mounted, 0, sizeof(sb->s_last_mounted)); |
| 433 | strncpy(sb->s_last_mounted, new_last_mounted, |
| 434 | sizeof(sb->s_last_mounted)); |
| 435 | ext2fs_mark_super_dirty(fs); |
| 436 | } |
Theodore Ts'o | 896938d | 1999-10-23 01:04:50 +0000 | [diff] [blame] | 437 | if (features_cmd) { |
| 438 | int sparse, old_sparse, filetype, old_filetype; |
| 439 | |
| 440 | old_sparse = sb->s_feature_ro_compat & |
| 441 | EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER; |
| 442 | old_filetype = sb->s_feature_incompat & |
| 443 | EXT2_FEATURE_INCOMPAT_FILETYPE; |
| 444 | if (e2p_edit_feature(features_cmd, |
| 445 | &sb->s_feature_compat, |
| 446 | ok_features)) { |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 447 | fprintf(stderr, _("Invalid filesystem option set: %s\n"), |
Theodore Ts'o | 896938d | 1999-10-23 01:04:50 +0000 | [diff] [blame] | 448 | features_cmd); |
| 449 | exit(1); |
| 450 | } |
| 451 | sparse = sb->s_feature_ro_compat & |
| 452 | EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER; |
| 453 | filetype = sb->s_feature_incompat & |
| 454 | EXT2_FEATURE_INCOMPAT_FILETYPE; |
| 455 | if ((sparse != old_sparse) || |
| 456 | (filetype != old_filetype)) { |
| 457 | fs->super->s_state &= ~EXT2_VALID_FS; |
Theodore Ts'o | a4fa100 | 2000-02-08 21:35:41 +0000 | [diff] [blame] | 458 | printf("\n%s\n", _(please_fsck)); |
Theodore Ts'o | 896938d | 1999-10-23 01:04:50 +0000 | [diff] [blame] | 459 | } |
| 460 | ext2fs_mark_super_dirty(fs); |
| 461 | } |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 462 | if (U_flag) { |
| 463 | if (strcasecmp(new_UUID, "null") == 0) { |
| 464 | uuid_clear(sb->s_uuid); |
| 465 | } else if (strcasecmp(new_UUID, "random") == 0) { |
| 466 | uuid_generate(sb->s_uuid); |
| 467 | } else if (uuid_parse(new_UUID, sb->s_uuid)) { |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 468 | com_err(program_name, 0, _("Invalid UUID format\n")); |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 469 | exit(1); |
| 470 | } |
| 471 | ext2fs_mark_super_dirty(fs); |
| 472 | } |
| 473 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 474 | if (l_flag) |
| 475 | list_super (fs->super); |
| 476 | ext2fs_close (fs); |
| 477 | exit (0); |
| 478 | } |