blob: 06e5c20ba6742b2901d7f60453fcc6245b232040 [file] [log] [blame]
Theodore Ts'o3839e651997-04-26 13:21:57 +00001/*
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'o19c78dc1997-04-29 16:17:09 +00009 * 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'o3839e651997-04-26 13:21:57 +000015 */
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'of3db3561997-04-26 13:34:30 +000030#include <grp.h>
Theodore Ts'oa418d3a1997-04-26 14:00:26 +000031#ifdef HAVE_GETOPT_H
Theodore Ts'o3839e651997-04-26 13:21:57 +000032#include <getopt.h>
Theodore Ts'o373b8332000-04-03 16:22:35 +000033#else
34extern char *optarg;
35extern int optind;
Theodore Ts'oa418d3a1997-04-26 14:00:26 +000036#endif
Theodore Ts'of3db3561997-04-26 13:34:30 +000037#include <pwd.h>
Theodore Ts'o3839e651997-04-26 13:21:57 +000038#include <stdio.h>
39#include <stdlib.h>
40#include <string.h>
41#include <time.h>
42#include <unistd.h>
Theodore Ts'of3db3561997-04-26 13:34:30 +000043#include <sys/types.h>
Theodore Ts'o3839e651997-04-26 13:21:57 +000044
45#include <linux/ext2_fs.h>
46
47#include "ext2fs/ext2fs.h"
48#include "et/com_err.h"
Theodore Ts'o1e3472c1997-04-29 14:53:37 +000049#include "uuid/uuid.h"
Theodore Ts'o3839e651997-04-26 13:21:57 +000050#include "e2p/e2p.h"
51
52#include "../version.h"
Theodore Ts'od9c56d32000-02-08 00:47:55 +000053#include "nls-enable.h"
Theodore Ts'o3839e651997-04-26 13:21:57 +000054
55const char * program_name = "tune2fs";
56char * device_name = NULL;
Theodore Ts'o1e3472c1997-04-29 14:53:37 +000057char * new_label = NULL;
58char * new_last_mounted = NULL;
59char * new_UUID = NULL;
Theodore Ts'o3839e651997-04-26 13:21:57 +000060int c_flag = 0;
Theodore Ts'o1e3472c1997-04-29 14:53:37 +000061int C_flag = 0;
Theodore Ts'o3839e651997-04-26 13:21:57 +000062int e_flag = 0;
Theodore Ts'of3db3561997-04-26 13:34:30 +000063int g_flag = 0;
Theodore Ts'o3839e651997-04-26 13:21:57 +000064int i_flag = 0;
65int l_flag = 0;
Theodore Ts'o1e3472c1997-04-29 14:53:37 +000066int L_flag = 0;
Theodore Ts'o3839e651997-04-26 13:21:57 +000067int m_flag = 0;
Theodore Ts'o1e3472c1997-04-29 14:53:37 +000068int M_flag = 0;
Theodore Ts'of3db3561997-04-26 13:34:30 +000069int r_flag = 0;
Theodore Ts'o521e3681997-04-29 17:48:10 +000070int s_flag = -1;
Theodore Ts'of3db3561997-04-26 13:34:30 +000071int u_flag = 0;
Theodore Ts'o1e3472c1997-04-29 14:53:37 +000072int U_flag = 0;
73int max_mount_count, mount_count;
Theodore Ts'o3839e651997-04-26 13:21:57 +000074unsigned long interval;
75unsigned long reserved_ratio = 0;
Theodore Ts'of3db3561997-04-26 13:34:30 +000076unsigned long reserved_blocks = 0;
Theodore Ts'o3839e651997-04-26 13:21:57 +000077unsigned short errors;
Theodore Ts'of3db3561997-04-26 13:34:30 +000078unsigned long resgid = 0;
79unsigned long resuid = 0;
Theodore Ts'o3839e651997-04-26 13:21:57 +000080
Theodore Ts'o1e3472c1997-04-29 14:53:37 +000081#ifndef HAVE_STRCASECMP
82static int strcasecmp (char *s1, char *s2)
83{
84 while (*s1 && *s2) {
85 int ch1 = *s1++, ch2 = *s2++;
86 if (isupper (ch1))
87 ch1 = tolower (ch1);
88 if (isupper (ch2))
89 ch2 = tolower (ch2);
90 if (ch1 != ch2)
91 return ch1 - ch2;
92 }
93 return *s1 ? 1 : *s2 ? -1 : 0;
94}
95#endif
96
Theodore Ts'o818180c1998-06-27 05:11:14 +000097static void usage(void)
Theodore Ts'o3839e651997-04-26 13:21:57 +000098{
Theodore Ts'od9c56d32000-02-08 00:47:55 +000099 fprintf(stderr, _("Usage: %s [-c max-mounts-count] [-e errors-behavior] "
Theodore Ts'of3db3561997-04-26 13:34:30 +0000100 "[-g group]\n"
Theodore Ts'o582134c2000-01-19 13:26:23 +0000101 "\t[-i interval[d|m|w]] [-l] [-s sparse-flag] "
102 "[-m reserved-blocks-percent]\n"
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000103 "\t[-r reserved-blocks-count] [-u user] [-C mount-count]\n"
Theodore Ts'o896938d1999-10-23 01:04:50 +0000104 "\t[-L volume-label] [-M last-mounted-dir] [-U UUID]\n"
Theodore Ts'od9c56d32000-02-08 00:47:55 +0000105 "\t[-O [^]feature[,...]] device\n"), program_name);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000106 exit (1);
107}
108
Theodore Ts'o896938d1999-10-23 01:04:50 +0000109static __u32 ok_features[3] = {
110 0, /* Compat */
111 EXT2_FEATURE_INCOMPAT_FILETYPE, /* Incompat */
112 EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER /* R/O compat */
113};
114
Theodore Ts'oa4fa1002000-02-08 21:35:41 +0000115static const char *please_fsck = N_("Please run e2fsck on the filesystem.\n");
Theodore Ts'o896938d1999-10-23 01:04:50 +0000116
Theodore Ts'o00e54331997-09-16 02:13:52 +0000117int main (int argc, char ** argv)
Theodore Ts'o3839e651997-04-26 13:21:57 +0000118{
Theodore Ts'o519149f1997-10-25 03:49:49 +0000119 int c;
Theodore Ts'o3839e651997-04-26 13:21:57 +0000120 char * tmp;
121 errcode_t retval;
122 ext2_filsys fs;
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000123 struct ext2fs_sb *sb;
Theodore Ts'of3db3561997-04-26 13:34:30 +0000124 struct group * gr;
125 struct passwd * pw;
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000126 int open_flag = 0;
Theodore Ts'o896938d1999-10-23 01:04:50 +0000127 char *features_cmd = 0;
Theodore Ts'o3839e651997-04-26 13:21:57 +0000128
Theodore Ts'od9c56d32000-02-08 00:47:55 +0000129#ifdef ENABLE_NLS
130 setlocale(LC_MESSAGES, "");
131 bindtextdomain(NLS_CAT_NAME, LOCALEDIR);
132 textdomain(NLS_CAT_NAME);
133#endif
134 fprintf (stderr, _("tune2fs %s, %s for EXT2 FS %s, %s\n"),
Theodore Ts'o3839e651997-04-26 13:21:57 +0000135 E2FSPROGS_VERSION, E2FSPROGS_DATE,
136 EXT2FS_VERSION, EXT2FS_DATE);
137 if (argc && *argv)
138 program_name = *argv;
139 initialize_ext2_error_table();
Theodore Ts'o896938d1999-10-23 01:04:50 +0000140 while ((c = getopt (argc, argv, "c:e:g:i:lm:r:s:u:C:L:M:O:U:")) != EOF)
Theodore Ts'o3839e651997-04-26 13:21:57 +0000141 switch (c)
142 {
143 case 'c':
144 max_mount_count = strtoul (optarg, &tmp, 0);
Theodore Ts'o818180c1998-06-27 05:11:14 +0000145 if (*tmp || max_mount_count > 16000) {
Theodore Ts'o3839e651997-04-26 13:21:57 +0000146 com_err (program_name, 0,
Theodore Ts'od9c56d32000-02-08 00:47:55 +0000147 _("bad mounts count - %s"),
Theodore Ts'o3839e651997-04-26 13:21:57 +0000148 optarg);
Theodore Ts'o818180c1998-06-27 05:11:14 +0000149 usage();
Theodore Ts'o3839e651997-04-26 13:21:57 +0000150 }
151 c_flag = 1;
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000152 open_flag = EXT2_FLAG_RW;
153 break;
154 case 'C':
155 mount_count = strtoul (optarg, &tmp, 0);
Theodore Ts'o818180c1998-06-27 05:11:14 +0000156 if (*tmp || mount_count > 16000) {
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000157 com_err (program_name, 0,
Theodore Ts'od9c56d32000-02-08 00:47:55 +0000158 _("bad mounts count - %s"),
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000159 optarg);
Theodore Ts'o818180c1998-06-27 05:11:14 +0000160 usage();
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000161 }
162 C_flag = 1;
163 open_flag = EXT2_FLAG_RW;
Theodore Ts'o3839e651997-04-26 13:21:57 +0000164 break;
165 case 'e':
166 if (strcmp (optarg, "continue") == 0)
167 errors = EXT2_ERRORS_CONTINUE;
168 else if (strcmp (optarg, "remount-ro") == 0)
169 errors = EXT2_ERRORS_RO;
170 else if (strcmp (optarg, "panic") == 0)
171 errors = EXT2_ERRORS_PANIC;
Theodore Ts'o818180c1998-06-27 05:11:14 +0000172 else {
Theodore Ts'o3839e651997-04-26 13:21:57 +0000173 com_err (program_name, 0,
Theodore Ts'od9c56d32000-02-08 00:47:55 +0000174 _("bad error behavior - %s"),
Theodore Ts'o3839e651997-04-26 13:21:57 +0000175 optarg);
Theodore Ts'o818180c1998-06-27 05:11:14 +0000176 usage();
Theodore Ts'o3839e651997-04-26 13:21:57 +0000177 }
178 e_flag = 1;
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000179 open_flag = EXT2_FLAG_RW;
Theodore Ts'o3839e651997-04-26 13:21:57 +0000180 break;
Theodore Ts'of3db3561997-04-26 13:34:30 +0000181 case 'g':
182 resgid = strtoul (optarg, &tmp, 0);
Theodore Ts'o818180c1998-06-27 05:11:14 +0000183 if (*tmp) {
Theodore Ts'of3db3561997-04-26 13:34:30 +0000184 gr = getgrnam (optarg);
185 if (gr == NULL)
186 tmp = optarg;
Theodore Ts'oa418d3a1997-04-26 14:00:26 +0000187 else {
Theodore Ts'of3db3561997-04-26 13:34:30 +0000188 resgid = gr->gr_gid;
Theodore Ts'oa418d3a1997-04-26 14:00:26 +0000189 *tmp =0;
190 }
Theodore Ts'of3db3561997-04-26 13:34:30 +0000191 }
Theodore Ts'o818180c1998-06-27 05:11:14 +0000192 if (*tmp) {
Theodore Ts'of3db3561997-04-26 13:34:30 +0000193 com_err (program_name, 0,
Theodore Ts'od9c56d32000-02-08 00:47:55 +0000194 _("bad gid/group name - %s"),
Theodore Ts'of3db3561997-04-26 13:34:30 +0000195 optarg);
Theodore Ts'o818180c1998-06-27 05:11:14 +0000196 usage();
Theodore Ts'of3db3561997-04-26 13:34:30 +0000197 }
198 g_flag = 1;
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000199 open_flag = EXT2_FLAG_RW;
Theodore Ts'of3db3561997-04-26 13:34:30 +0000200 break;
Theodore Ts'o3839e651997-04-26 13:21:57 +0000201 case 'i':
202 interval = strtoul (optarg, &tmp, 0);
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000203 switch (*tmp) {
204 case 's':
205 tmp++;
206 break;
207 case '\0':
208 case 'd':
209 case 'D': /* days */
210 interval *= 86400;
211 if (*tmp != '\0')
Theodore Ts'o3839e651997-04-26 13:21:57 +0000212 tmp++;
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000213 break;
214 case 'm':
215 case 'M': /* months! */
216 interval *= 86400 * 30;
217 tmp++;
218 break;
219 case 'w':
220 case 'W': /* weeks */
221 interval *= 86400 * 7;
222 tmp++;
223 break;
Theodore Ts'o3839e651997-04-26 13:21:57 +0000224 }
Theodore Ts'o818180c1998-06-27 05:11:14 +0000225 if (*tmp || interval > (365 * 86400)) {
Theodore Ts'o3839e651997-04-26 13:21:57 +0000226 com_err (program_name, 0,
Theodore Ts'od9c56d32000-02-08 00:47:55 +0000227 _("bad interval - %s"), optarg);
Theodore Ts'o818180c1998-06-27 05:11:14 +0000228 usage();
Theodore Ts'o3839e651997-04-26 13:21:57 +0000229 }
230 i_flag = 1;
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000231 open_flag = EXT2_FLAG_RW;
Theodore Ts'o3839e651997-04-26 13:21:57 +0000232 break;
233 case 'l':
234 l_flag = 1;
235 break;
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000236 case 'L':
237 new_label = optarg;
238 L_flag = 1;
239 open_flag = EXT2_FLAG_RW;
240 break;
Theodore Ts'o3839e651997-04-26 13:21:57 +0000241 case 'm':
242 reserved_ratio = strtoul (optarg, &tmp, 0);
Theodore Ts'o818180c1998-06-27 05:11:14 +0000243 if (*tmp || reserved_ratio > 50) {
Theodore Ts'o3839e651997-04-26 13:21:57 +0000244 com_err (program_name, 0,
Theodore Ts'od9c56d32000-02-08 00:47:55 +0000245 _("bad reserved block ratio - %s"),
Theodore Ts'o3839e651997-04-26 13:21:57 +0000246 optarg);
Theodore Ts'o818180c1998-06-27 05:11:14 +0000247 usage();
Theodore Ts'o3839e651997-04-26 13:21:57 +0000248 }
249 m_flag = 1;
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000250 open_flag = EXT2_FLAG_RW;
251 break;
252 case 'M':
253 new_last_mounted = optarg;
254 M_flag = 1;
255 open_flag = EXT2_FLAG_RW;
Theodore Ts'o3839e651997-04-26 13:21:57 +0000256 break;
Theodore Ts'o896938d1999-10-23 01:04:50 +0000257 case 'O':
258 features_cmd = optarg;
259 open_flag = EXT2_FLAG_RW;
260 break;
Theodore Ts'of3db3561997-04-26 13:34:30 +0000261 case 'r':
262 reserved_blocks = strtoul (optarg, &tmp, 0);
Theodore Ts'o818180c1998-06-27 05:11:14 +0000263 if (*tmp) {
Theodore Ts'of3db3561997-04-26 13:34:30 +0000264 com_err (program_name, 0,
Theodore Ts'od9c56d32000-02-08 00:47:55 +0000265 _("bad reserved blocks count - %s"),
Theodore Ts'of3db3561997-04-26 13:34:30 +0000266 optarg);
Theodore Ts'o818180c1998-06-27 05:11:14 +0000267 usage();
Theodore Ts'of3db3561997-04-26 13:34:30 +0000268 }
269 r_flag = 1;
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000270 open_flag = EXT2_FLAG_RW;
Theodore Ts'of3db3561997-04-26 13:34:30 +0000271 break;
Theodore Ts'o521e3681997-04-29 17:48:10 +0000272 case 's':
273 s_flag = atoi(optarg);
274 open_flag = EXT2_FLAG_RW;
275 break;
Theodore Ts'of3db3561997-04-26 13:34:30 +0000276 case 'u':
277 resuid = strtoul (optarg, &tmp, 0);
Theodore Ts'o818180c1998-06-27 05:11:14 +0000278 if (*tmp) {
Theodore Ts'of3db3561997-04-26 13:34:30 +0000279 pw = getpwnam (optarg);
280 if (pw == NULL)
281 tmp = optarg;
Theodore Ts'oa418d3a1997-04-26 14:00:26 +0000282 else {
Theodore Ts'of3db3561997-04-26 13:34:30 +0000283 resuid = pw->pw_uid;
Theodore Ts'oa418d3a1997-04-26 14:00:26 +0000284 *tmp = 0;
285 }
Theodore Ts'of3db3561997-04-26 13:34:30 +0000286 }
Theodore Ts'o818180c1998-06-27 05:11:14 +0000287 if (*tmp) {
Theodore Ts'of3db3561997-04-26 13:34:30 +0000288 com_err (program_name, 0,
Theodore Ts'od9c56d32000-02-08 00:47:55 +0000289 _("bad uid/user name - %s"),
Theodore Ts'of3db3561997-04-26 13:34:30 +0000290 optarg);
Theodore Ts'o818180c1998-06-27 05:11:14 +0000291 usage();
Theodore Ts'of3db3561997-04-26 13:34:30 +0000292 }
293 u_flag = 1;
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000294 open_flag = EXT2_FLAG_RW;
295 break;
296 case 'U':
297 new_UUID = optarg;
298 U_flag = 1;
299 open_flag = EXT2_FLAG_RW;
Theodore Ts'of3db3561997-04-26 13:34:30 +0000300 break;
Theodore Ts'o3839e651997-04-26 13:21:57 +0000301 default:
Theodore Ts'o818180c1998-06-27 05:11:14 +0000302 usage();
Theodore Ts'o3839e651997-04-26 13:21:57 +0000303 }
304 if (optind < argc - 1 || optind == argc)
Theodore Ts'o818180c1998-06-27 05:11:14 +0000305 usage();
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000306 if (!open_flag && !l_flag)
307 usage();
Theodore Ts'o3839e651997-04-26 13:21:57 +0000308 device_name = argv[optind];
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000309 retval = ext2fs_open (device_name, open_flag, 0, 0,
310 unix_io_manager, &fs);
Theodore Ts'o818180c1998-06-27 05:11:14 +0000311 if (retval) {
Theodore Ts'od9c56d32000-02-08 00:47:55 +0000312 com_err (program_name, retval, _("while trying to open %s"),
Theodore Ts'o3839e651997-04-26 13:21:57 +0000313 device_name);
Theodore Ts'od9c56d32000-02-08 00:47:55 +0000314 printf(_("Couldn't find valid filesystem superblock.\n"));
Theodore Ts'o3839e651997-04-26 13:21:57 +0000315 exit(1);
316 }
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000317 sb = (struct ext2fs_sb *) fs->super;
Theodore Ts'o3839e651997-04-26 13:21:57 +0000318
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000319 if (c_flag) {
Theodore Ts'o3839e651997-04-26 13:21:57 +0000320 fs->super->s_max_mnt_count = max_mount_count;
321 ext2fs_mark_super_dirty(fs);
Theodore Ts'od9c56d32000-02-08 00:47:55 +0000322 printf (_("Setting maximal mount count to %d\n"),
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000323 max_mount_count);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000324 }
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000325 if (C_flag) {
326 fs->super->s_mnt_count = mount_count;
327 ext2fs_mark_super_dirty(fs);
Theodore Ts'od9c56d32000-02-08 00:47:55 +0000328 printf (_("Setting current mount count to %d\n"), mount_count);
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000329 }
330 if (e_flag) {
Theodore Ts'o3839e651997-04-26 13:21:57 +0000331 fs->super->s_errors = errors;
332 ext2fs_mark_super_dirty(fs);
Theodore Ts'od9c56d32000-02-08 00:47:55 +0000333 printf (_("Setting error behavior to %d\n"), errors);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000334 }
Theodore Ts'of3db3561997-04-26 13:34:30 +0000335 if (g_flag)
336#ifdef EXT2_DEF_RESGID
337 {
338 fs->super->s_def_resgid = resgid;
339 ext2fs_mark_super_dirty(fs);
Theodore Ts'od9c56d32000-02-08 00:47:55 +0000340 printf (_("Setting reserved blocks gid to %lu\n"), resgid);
Theodore Ts'of3db3561997-04-26 13:34:30 +0000341 }
342#else
343 com_err (program_name, 0,
Theodore Ts'od9c56d32000-02-08 00:47:55 +0000344 _("The -g option is not supported by this version -- "
345 "Recompile with a newer kernel"));
Theodore Ts'of3db3561997-04-26 13:34:30 +0000346#endif
Theodore Ts'o818180c1998-06-27 05:11:14 +0000347 if (i_flag) {
Theodore Ts'o3839e651997-04-26 13:21:57 +0000348 fs->super->s_checkinterval = interval;
349 ext2fs_mark_super_dirty(fs);
Theodore Ts'od9c56d32000-02-08 00:47:55 +0000350 printf (_("Setting interval between check %lu seconds\n"), interval);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000351 }
Theodore Ts'o818180c1998-06-27 05:11:14 +0000352 if (m_flag) {
Theodore Ts'o3839e651997-04-26 13:21:57 +0000353 fs->super->s_r_blocks_count = (fs->super->s_blocks_count / 100)
354 * reserved_ratio;
355 ext2fs_mark_super_dirty(fs);
Theodore Ts'od9c56d32000-02-08 00:47:55 +0000356 printf (_("Setting reserved blocks percentage to %lu (%u blocks)\n"),
Theodore Ts'o3839e651997-04-26 13:21:57 +0000357 reserved_ratio, fs->super->s_r_blocks_count);
358 }
Theodore Ts'o818180c1998-06-27 05:11:14 +0000359 if (r_flag) {
360 if (reserved_blocks >= fs->super->s_blocks_count) {
Theodore Ts'of3db3561997-04-26 13:34:30 +0000361 com_err (program_name, 0,
Theodore Ts'od9c56d32000-02-08 00:47:55 +0000362 _("reserved blocks count is too big (%ul)"),
Theodore Ts'of3db3561997-04-26 13:34:30 +0000363 reserved_blocks);
364 exit (1);
365 }
366 fs->super->s_r_blocks_count = reserved_blocks;
367 ext2fs_mark_super_dirty(fs);
Theodore Ts'od9c56d32000-02-08 00:47:55 +0000368 printf (_("Setting reserved blocks count to %lu\n"),
Theodore Ts'of3db3561997-04-26 13:34:30 +0000369 reserved_blocks);
370 }
Theodore Ts'o521e3681997-04-29 17:48:10 +0000371 if (s_flag == 1) {
372#ifdef EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER
373 if (sb->s_feature_ro_compat &
374 EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER)
Theodore Ts'od9c56d32000-02-08 00:47:55 +0000375 fprintf(stderr, _("\nThe filesystem already"
Theodore Ts'oe1a0a3e2000-02-11 05:00:19 +0000376 " has sparse superblocks.\n"));
Theodore Ts'o521e3681997-04-29 17:48:10 +0000377 else {
378 sb->s_feature_ro_compat |=
379 EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER;
380 fs->super->s_state &= ~EXT2_VALID_FS;
381 ext2fs_mark_super_dirty(fs);
Theodore Ts'od9c56d32000-02-08 00:47:55 +0000382 printf(_("\nSparse superblock flag set. %s"),
Theodore Ts'oa4fa1002000-02-08 21:35:41 +0000383 _(please_fsck));
Theodore Ts'o521e3681997-04-29 17:48:10 +0000384 }
385#else /* !EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER */
386 com_err (program_name, 0,
Theodore Ts'od9c56d32000-02-08 00:47:55 +0000387 _("The -s option is not supported by this version -- "
388 "Recompile with a newer kernel"));
Theodore Ts'o521e3681997-04-29 17:48:10 +0000389#endif /* EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER */
390 }
391 if (s_flag == 0) {
392#ifdef EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER
393 if (!(sb->s_feature_ro_compat &
394 EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER))
Theodore Ts'od9c56d32000-02-08 00:47:55 +0000395 fprintf(stderr, _("\nThe filesystem already"
Theodore Ts'oe1a0a3e2000-02-11 05:00:19 +0000396 " has sparse superblocks disabled.\n"));
Theodore Ts'o521e3681997-04-29 17:48:10 +0000397 else {
398 sb->s_feature_ro_compat &=
399 ~EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER;
400 fs->super->s_state &= ~EXT2_VALID_FS;
401 fs->flags |= EXT2_FLAG_MASTER_SB_ONLY;
402 ext2fs_mark_super_dirty(fs);
Theodore Ts'od9c56d32000-02-08 00:47:55 +0000403 printf(_("\nSparse superblock flag cleared. %s"),
Theodore Ts'oa4fa1002000-02-08 21:35:41 +0000404 _(please_fsck));
Theodore Ts'o521e3681997-04-29 17:48:10 +0000405 }
406#else /* !EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER */
407 com_err (program_name, 0,
Theodore Ts'od9c56d32000-02-08 00:47:55 +0000408 _("The -s option is not supported by this version -- "
409 "Recompile with a newer kernel"));
Theodore Ts'o521e3681997-04-29 17:48:10 +0000410#endif /* EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER */
411 }
412
Theodore Ts'of3db3561997-04-26 13:34:30 +0000413 if (u_flag)
414#ifdef EXT2_DEF_RESUID
415 {
416 fs->super->s_def_resuid = resuid;
417 ext2fs_mark_super_dirty(fs);
Theodore Ts'od9c56d32000-02-08 00:47:55 +0000418 printf (_("Setting reserved blocks uid to %lu\n"), resuid);
Theodore Ts'of3db3561997-04-26 13:34:30 +0000419 }
420#else
421 com_err (program_name, 0,
Theodore Ts'od9c56d32000-02-08 00:47:55 +0000422 _("The -u option is not supported by this version -- "
423 "Recompile with a newer kernel"));
Theodore Ts'of3db3561997-04-26 13:34:30 +0000424#endif
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000425 if (L_flag) {
Theodore Ts'oa789d841998-03-30 01:20:55 +0000426 if (strlen(new_label) > sizeof(sb->s_volume_name))
Theodore Ts'od9c56d32000-02-08 00:47:55 +0000427 fprintf(stderr, _("Warning: label too "
428 "long, truncating.\n"));
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000429 memset(sb->s_volume_name, 0, sizeof(sb->s_volume_name));
430 strncpy(sb->s_volume_name, new_label,
431 sizeof(sb->s_volume_name));
432 ext2fs_mark_super_dirty(fs);
433 }
434 if (M_flag) {
435 memset(sb->s_last_mounted, 0, sizeof(sb->s_last_mounted));
436 strncpy(sb->s_last_mounted, new_last_mounted,
437 sizeof(sb->s_last_mounted));
438 ext2fs_mark_super_dirty(fs);
439 }
Theodore Ts'o896938d1999-10-23 01:04:50 +0000440 if (features_cmd) {
441 int sparse, old_sparse, filetype, old_filetype;
442
443 old_sparse = sb->s_feature_ro_compat &
444 EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER;
445 old_filetype = sb->s_feature_incompat &
446 EXT2_FEATURE_INCOMPAT_FILETYPE;
447 if (e2p_edit_feature(features_cmd,
448 &sb->s_feature_compat,
449 ok_features)) {
Theodore Ts'od9c56d32000-02-08 00:47:55 +0000450 fprintf(stderr, _("Invalid filesystem option set: %s\n"),
Theodore Ts'o896938d1999-10-23 01:04:50 +0000451 features_cmd);
452 exit(1);
453 }
454 sparse = sb->s_feature_ro_compat &
455 EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER;
456 filetype = sb->s_feature_incompat &
457 EXT2_FEATURE_INCOMPAT_FILETYPE;
458 if ((sparse != old_sparse) ||
459 (filetype != old_filetype)) {
460 fs->super->s_state &= ~EXT2_VALID_FS;
Theodore Ts'oa4fa1002000-02-08 21:35:41 +0000461 printf("\n%s\n", _(please_fsck));
Theodore Ts'o896938d1999-10-23 01:04:50 +0000462 }
463 ext2fs_mark_super_dirty(fs);
464 }
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000465 if (U_flag) {
466 if (strcasecmp(new_UUID, "null") == 0) {
467 uuid_clear(sb->s_uuid);
468 } else if (strcasecmp(new_UUID, "random") == 0) {
469 uuid_generate(sb->s_uuid);
470 } else if (uuid_parse(new_UUID, sb->s_uuid)) {
Theodore Ts'od9c56d32000-02-08 00:47:55 +0000471 com_err(program_name, 0, _("Invalid UUID format\n"));
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000472 exit(1);
473 }
474 ext2fs_mark_super_dirty(fs);
475 }
476
Theodore Ts'o3839e651997-04-26 13:21:57 +0000477 if (l_flag)
478 list_super (fs->super);
479 ext2fs_close (fs);
480 exit (0);
481}