blob: 6903dc17a05322b1a0bb7e2c0d887d2d113f68d0 [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'oa418d3a1997-04-26 14:00:26 +000033#endif
Theodore Ts'of3db3561997-04-26 13:34:30 +000034#include <pwd.h>
Theodore Ts'o3839e651997-04-26 13:21:57 +000035#include <stdio.h>
36#include <stdlib.h>
37#include <string.h>
38#include <time.h>
39#include <unistd.h>
Theodore Ts'of3db3561997-04-26 13:34:30 +000040#include <sys/types.h>
Theodore Ts'o3839e651997-04-26 13:21:57 +000041
42#include <linux/ext2_fs.h>
43
44#include "ext2fs/ext2fs.h"
45#include "et/com_err.h"
Theodore Ts'o1e3472c1997-04-29 14:53:37 +000046#include "uuid/uuid.h"
Theodore Ts'o3839e651997-04-26 13:21:57 +000047#include "e2p/e2p.h"
48
49#include "../version.h"
Theodore Ts'od9c56d32000-02-08 00:47:55 +000050#include "nls-enable.h"
Theodore Ts'o3839e651997-04-26 13:21:57 +000051
52const char * program_name = "tune2fs";
53char * device_name = NULL;
Theodore Ts'o1e3472c1997-04-29 14:53:37 +000054char * new_label = NULL;
55char * new_last_mounted = NULL;
56char * new_UUID = NULL;
Theodore Ts'o3839e651997-04-26 13:21:57 +000057int c_flag = 0;
Theodore Ts'o1e3472c1997-04-29 14:53:37 +000058int C_flag = 0;
Theodore Ts'o3839e651997-04-26 13:21:57 +000059int e_flag = 0;
Theodore Ts'of3db3561997-04-26 13:34:30 +000060int g_flag = 0;
Theodore Ts'o3839e651997-04-26 13:21:57 +000061int i_flag = 0;
62int l_flag = 0;
Theodore Ts'o1e3472c1997-04-29 14:53:37 +000063int L_flag = 0;
Theodore Ts'o3839e651997-04-26 13:21:57 +000064int m_flag = 0;
Theodore Ts'o1e3472c1997-04-29 14:53:37 +000065int M_flag = 0;
Theodore Ts'of3db3561997-04-26 13:34:30 +000066int r_flag = 0;
Theodore Ts'o521e3681997-04-29 17:48:10 +000067int s_flag = -1;
Theodore Ts'of3db3561997-04-26 13:34:30 +000068int u_flag = 0;
Theodore Ts'o1e3472c1997-04-29 14:53:37 +000069int U_flag = 0;
70int max_mount_count, mount_count;
Theodore Ts'o3839e651997-04-26 13:21:57 +000071unsigned long interval;
72unsigned long reserved_ratio = 0;
Theodore Ts'of3db3561997-04-26 13:34:30 +000073unsigned long reserved_blocks = 0;
Theodore Ts'o3839e651997-04-26 13:21:57 +000074unsigned short errors;
Theodore Ts'of3db3561997-04-26 13:34:30 +000075unsigned long resgid = 0;
76unsigned long resuid = 0;
Theodore Ts'o3839e651997-04-26 13:21:57 +000077
Theodore Ts'o1e3472c1997-04-29 14:53:37 +000078#ifndef HAVE_STRCASECMP
79static 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'o818180c1998-06-27 05:11:14 +000094static void usage(void)
Theodore Ts'o3839e651997-04-26 13:21:57 +000095{
Theodore Ts'od9c56d32000-02-08 00:47:55 +000096 fprintf(stderr, _("Usage: %s [-c max-mounts-count] [-e errors-behavior] "
Theodore Ts'of3db3561997-04-26 13:34:30 +000097 "[-g group]\n"
Theodore Ts'o582134c2000-01-19 13:26:23 +000098 "\t[-i interval[d|m|w]] [-l] [-s sparse-flag] "
99 "[-m reserved-blocks-percent]\n"
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000100 "\t[-r reserved-blocks-count] [-u user] [-C mount-count]\n"
Theodore Ts'o896938d1999-10-23 01:04:50 +0000101 "\t[-L volume-label] [-M last-mounted-dir] [-U UUID]\n"
Theodore Ts'od9c56d32000-02-08 00:47:55 +0000102 "\t[-O [^]feature[,...]] device\n"), program_name);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000103 exit (1);
104}
105
Theodore Ts'o896938d1999-10-23 01:04:50 +0000106static __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'oa4fa1002000-02-08 21:35:41 +0000112static const char *please_fsck = N_("Please run e2fsck on the filesystem.\n");
Theodore Ts'o896938d1999-10-23 01:04:50 +0000113
Theodore Ts'o00e54331997-09-16 02:13:52 +0000114int main (int argc, char ** argv)
Theodore Ts'o3839e651997-04-26 13:21:57 +0000115{
Theodore Ts'o519149f1997-10-25 03:49:49 +0000116 int c;
Theodore Ts'o3839e651997-04-26 13:21:57 +0000117 char * tmp;
118 errcode_t retval;
119 ext2_filsys fs;
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000120 struct ext2fs_sb *sb;
Theodore Ts'of3db3561997-04-26 13:34:30 +0000121 struct group * gr;
122 struct passwd * pw;
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000123 int open_flag = 0;
Theodore Ts'o896938d1999-10-23 01:04:50 +0000124 char *features_cmd = 0;
Theodore Ts'o3839e651997-04-26 13:21:57 +0000125
Theodore Ts'od9c56d32000-02-08 00:47:55 +0000126#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'o3839e651997-04-26 13:21:57 +0000132 E2FSPROGS_VERSION, E2FSPROGS_DATE,
133 EXT2FS_VERSION, EXT2FS_DATE);
134 if (argc && *argv)
135 program_name = *argv;
136 initialize_ext2_error_table();
Theodore Ts'o896938d1999-10-23 01:04:50 +0000137 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 +0000138 switch (c)
139 {
140 case 'c':
141 max_mount_count = strtoul (optarg, &tmp, 0);
Theodore Ts'o818180c1998-06-27 05:11:14 +0000142 if (*tmp || max_mount_count > 16000) {
Theodore Ts'o3839e651997-04-26 13:21:57 +0000143 com_err (program_name, 0,
Theodore Ts'od9c56d32000-02-08 00:47:55 +0000144 _("bad mounts count - %s"),
Theodore Ts'o3839e651997-04-26 13:21:57 +0000145 optarg);
Theodore Ts'o818180c1998-06-27 05:11:14 +0000146 usage();
Theodore Ts'o3839e651997-04-26 13:21:57 +0000147 }
148 c_flag = 1;
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000149 open_flag = EXT2_FLAG_RW;
150 break;
151 case 'C':
152 mount_count = strtoul (optarg, &tmp, 0);
Theodore Ts'o818180c1998-06-27 05:11:14 +0000153 if (*tmp || mount_count > 16000) {
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000154 com_err (program_name, 0,
Theodore Ts'od9c56d32000-02-08 00:47:55 +0000155 _("bad mounts count - %s"),
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000156 optarg);
Theodore Ts'o818180c1998-06-27 05:11:14 +0000157 usage();
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000158 }
159 C_flag = 1;
160 open_flag = EXT2_FLAG_RW;
Theodore Ts'o3839e651997-04-26 13:21:57 +0000161 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'o818180c1998-06-27 05:11:14 +0000169 else {
Theodore Ts'o3839e651997-04-26 13:21:57 +0000170 com_err (program_name, 0,
Theodore Ts'od9c56d32000-02-08 00:47:55 +0000171 _("bad error behavior - %s"),
Theodore Ts'o3839e651997-04-26 13:21:57 +0000172 optarg);
Theodore Ts'o818180c1998-06-27 05:11:14 +0000173 usage();
Theodore Ts'o3839e651997-04-26 13:21:57 +0000174 }
175 e_flag = 1;
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000176 open_flag = EXT2_FLAG_RW;
Theodore Ts'o3839e651997-04-26 13:21:57 +0000177 break;
Theodore Ts'of3db3561997-04-26 13:34:30 +0000178 case 'g':
179 resgid = strtoul (optarg, &tmp, 0);
Theodore Ts'o818180c1998-06-27 05:11:14 +0000180 if (*tmp) {
Theodore Ts'of3db3561997-04-26 13:34:30 +0000181 gr = getgrnam (optarg);
182 if (gr == NULL)
183 tmp = optarg;
Theodore Ts'oa418d3a1997-04-26 14:00:26 +0000184 else {
Theodore Ts'of3db3561997-04-26 13:34:30 +0000185 resgid = gr->gr_gid;
Theodore Ts'oa418d3a1997-04-26 14:00:26 +0000186 *tmp =0;
187 }
Theodore Ts'of3db3561997-04-26 13:34:30 +0000188 }
Theodore Ts'o818180c1998-06-27 05:11:14 +0000189 if (*tmp) {
Theodore Ts'of3db3561997-04-26 13:34:30 +0000190 com_err (program_name, 0,
Theodore Ts'od9c56d32000-02-08 00:47:55 +0000191 _("bad gid/group name - %s"),
Theodore Ts'of3db3561997-04-26 13:34:30 +0000192 optarg);
Theodore Ts'o818180c1998-06-27 05:11:14 +0000193 usage();
Theodore Ts'of3db3561997-04-26 13:34:30 +0000194 }
195 g_flag = 1;
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000196 open_flag = EXT2_FLAG_RW;
Theodore Ts'of3db3561997-04-26 13:34:30 +0000197 break;
Theodore Ts'o3839e651997-04-26 13:21:57 +0000198 case 'i':
199 interval = strtoul (optarg, &tmp, 0);
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000200 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'o3839e651997-04-26 13:21:57 +0000209 tmp++;
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000210 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'o3839e651997-04-26 13:21:57 +0000221 }
Theodore Ts'o818180c1998-06-27 05:11:14 +0000222 if (*tmp || interval > (365 * 86400)) {
Theodore Ts'o3839e651997-04-26 13:21:57 +0000223 com_err (program_name, 0,
Theodore Ts'od9c56d32000-02-08 00:47:55 +0000224 _("bad interval - %s"), optarg);
Theodore Ts'o818180c1998-06-27 05:11:14 +0000225 usage();
Theodore Ts'o3839e651997-04-26 13:21:57 +0000226 }
227 i_flag = 1;
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000228 open_flag = EXT2_FLAG_RW;
Theodore Ts'o3839e651997-04-26 13:21:57 +0000229 break;
230 case 'l':
231 l_flag = 1;
232 break;
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000233 case 'L':
234 new_label = optarg;
235 L_flag = 1;
236 open_flag = EXT2_FLAG_RW;
237 break;
Theodore Ts'o3839e651997-04-26 13:21:57 +0000238 case 'm':
239 reserved_ratio = strtoul (optarg, &tmp, 0);
Theodore Ts'o818180c1998-06-27 05:11:14 +0000240 if (*tmp || reserved_ratio > 50) {
Theodore Ts'o3839e651997-04-26 13:21:57 +0000241 com_err (program_name, 0,
Theodore Ts'od9c56d32000-02-08 00:47:55 +0000242 _("bad reserved block ratio - %s"),
Theodore Ts'o3839e651997-04-26 13:21:57 +0000243 optarg);
Theodore Ts'o818180c1998-06-27 05:11:14 +0000244 usage();
Theodore Ts'o3839e651997-04-26 13:21:57 +0000245 }
246 m_flag = 1;
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000247 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'o3839e651997-04-26 13:21:57 +0000253 break;
Theodore Ts'o896938d1999-10-23 01:04:50 +0000254 case 'O':
255 features_cmd = optarg;
256 open_flag = EXT2_FLAG_RW;
257 break;
Theodore Ts'of3db3561997-04-26 13:34:30 +0000258 case 'r':
259 reserved_blocks = strtoul (optarg, &tmp, 0);
Theodore Ts'o818180c1998-06-27 05:11:14 +0000260 if (*tmp) {
Theodore Ts'of3db3561997-04-26 13:34:30 +0000261 com_err (program_name, 0,
Theodore Ts'od9c56d32000-02-08 00:47:55 +0000262 _("bad reserved blocks count - %s"),
Theodore Ts'of3db3561997-04-26 13:34:30 +0000263 optarg);
Theodore Ts'o818180c1998-06-27 05:11:14 +0000264 usage();
Theodore Ts'of3db3561997-04-26 13:34:30 +0000265 }
266 r_flag = 1;
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000267 open_flag = EXT2_FLAG_RW;
Theodore Ts'of3db3561997-04-26 13:34:30 +0000268 break;
Theodore Ts'o521e3681997-04-29 17:48:10 +0000269 case 's':
270 s_flag = atoi(optarg);
271 open_flag = EXT2_FLAG_RW;
272 break;
Theodore Ts'of3db3561997-04-26 13:34:30 +0000273 case 'u':
274 resuid = strtoul (optarg, &tmp, 0);
Theodore Ts'o818180c1998-06-27 05:11:14 +0000275 if (*tmp) {
Theodore Ts'of3db3561997-04-26 13:34:30 +0000276 pw = getpwnam (optarg);
277 if (pw == NULL)
278 tmp = optarg;
Theodore Ts'oa418d3a1997-04-26 14:00:26 +0000279 else {
Theodore Ts'of3db3561997-04-26 13:34:30 +0000280 resuid = pw->pw_uid;
Theodore Ts'oa418d3a1997-04-26 14:00:26 +0000281 *tmp = 0;
282 }
Theodore Ts'of3db3561997-04-26 13:34:30 +0000283 }
Theodore Ts'o818180c1998-06-27 05:11:14 +0000284 if (*tmp) {
Theodore Ts'of3db3561997-04-26 13:34:30 +0000285 com_err (program_name, 0,
Theodore Ts'od9c56d32000-02-08 00:47:55 +0000286 _("bad uid/user name - %s"),
Theodore Ts'of3db3561997-04-26 13:34:30 +0000287 optarg);
Theodore Ts'o818180c1998-06-27 05:11:14 +0000288 usage();
Theodore Ts'of3db3561997-04-26 13:34:30 +0000289 }
290 u_flag = 1;
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000291 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'of3db3561997-04-26 13:34:30 +0000297 break;
Theodore Ts'o3839e651997-04-26 13:21:57 +0000298 default:
Theodore Ts'o818180c1998-06-27 05:11:14 +0000299 usage();
Theodore Ts'o3839e651997-04-26 13:21:57 +0000300 }
301 if (optind < argc - 1 || optind == argc)
Theodore Ts'o818180c1998-06-27 05:11:14 +0000302 usage();
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000303 if (!open_flag && !l_flag)
304 usage();
Theodore Ts'o3839e651997-04-26 13:21:57 +0000305 device_name = argv[optind];
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000306 retval = ext2fs_open (device_name, open_flag, 0, 0,
307 unix_io_manager, &fs);
Theodore Ts'o818180c1998-06-27 05:11:14 +0000308 if (retval) {
Theodore Ts'od9c56d32000-02-08 00:47:55 +0000309 com_err (program_name, retval, _("while trying to open %s"),
Theodore Ts'o3839e651997-04-26 13:21:57 +0000310 device_name);
Theodore Ts'od9c56d32000-02-08 00:47:55 +0000311 printf(_("Couldn't find valid filesystem superblock.\n"));
Theodore Ts'o3839e651997-04-26 13:21:57 +0000312 exit(1);
313 }
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000314 sb = (struct ext2fs_sb *) fs->super;
Theodore Ts'o3839e651997-04-26 13:21:57 +0000315
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000316 if (c_flag) {
Theodore Ts'o3839e651997-04-26 13:21:57 +0000317 fs->super->s_max_mnt_count = max_mount_count;
318 ext2fs_mark_super_dirty(fs);
Theodore Ts'od9c56d32000-02-08 00:47:55 +0000319 printf (_("Setting maximal mount count to %d\n"),
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000320 max_mount_count);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000321 }
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000322 if (C_flag) {
323 fs->super->s_mnt_count = mount_count;
324 ext2fs_mark_super_dirty(fs);
Theodore Ts'od9c56d32000-02-08 00:47:55 +0000325 printf (_("Setting current mount count to %d\n"), mount_count);
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000326 }
327 if (e_flag) {
Theodore Ts'o3839e651997-04-26 13:21:57 +0000328 fs->super->s_errors = errors;
329 ext2fs_mark_super_dirty(fs);
Theodore Ts'od9c56d32000-02-08 00:47:55 +0000330 printf (_("Setting error behavior to %d\n"), errors);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000331 }
Theodore Ts'of3db3561997-04-26 13:34:30 +0000332 if (g_flag)
333#ifdef EXT2_DEF_RESGID
334 {
335 fs->super->s_def_resgid = resgid;
336 ext2fs_mark_super_dirty(fs);
Theodore Ts'od9c56d32000-02-08 00:47:55 +0000337 printf (_("Setting reserved blocks gid to %lu\n"), resgid);
Theodore Ts'of3db3561997-04-26 13:34:30 +0000338 }
339#else
340 com_err (program_name, 0,
Theodore Ts'od9c56d32000-02-08 00:47:55 +0000341 _("The -g option is not supported by this version -- "
342 "Recompile with a newer kernel"));
Theodore Ts'of3db3561997-04-26 13:34:30 +0000343#endif
Theodore Ts'o818180c1998-06-27 05:11:14 +0000344 if (i_flag) {
Theodore Ts'o3839e651997-04-26 13:21:57 +0000345 fs->super->s_checkinterval = interval;
346 ext2fs_mark_super_dirty(fs);
Theodore Ts'od9c56d32000-02-08 00:47:55 +0000347 printf (_("Setting interval between check %lu seconds\n"), interval);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000348 }
Theodore Ts'o818180c1998-06-27 05:11:14 +0000349 if (m_flag) {
Theodore Ts'o3839e651997-04-26 13:21:57 +0000350 fs->super->s_r_blocks_count = (fs->super->s_blocks_count / 100)
351 * reserved_ratio;
352 ext2fs_mark_super_dirty(fs);
Theodore Ts'od9c56d32000-02-08 00:47:55 +0000353 printf (_("Setting reserved blocks percentage to %lu (%u blocks)\n"),
Theodore Ts'o3839e651997-04-26 13:21:57 +0000354 reserved_ratio, fs->super->s_r_blocks_count);
355 }
Theodore Ts'o818180c1998-06-27 05:11:14 +0000356 if (r_flag) {
357 if (reserved_blocks >= fs->super->s_blocks_count) {
Theodore Ts'of3db3561997-04-26 13:34:30 +0000358 com_err (program_name, 0,
Theodore Ts'od9c56d32000-02-08 00:47:55 +0000359 _("reserved blocks count is too big (%ul)"),
Theodore Ts'of3db3561997-04-26 13:34:30 +0000360 reserved_blocks);
361 exit (1);
362 }
363 fs->super->s_r_blocks_count = reserved_blocks;
364 ext2fs_mark_super_dirty(fs);
Theodore Ts'od9c56d32000-02-08 00:47:55 +0000365 printf (_("Setting reserved blocks count to %lu\n"),
Theodore Ts'of3db3561997-04-26 13:34:30 +0000366 reserved_blocks);
367 }
Theodore Ts'o521e3681997-04-29 17:48:10 +0000368 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'od9c56d32000-02-08 00:47:55 +0000372 fprintf(stderr, _("\nThe filesystem already"
Theodore Ts'oe1a0a3e2000-02-11 05:00:19 +0000373 " has sparse superblocks.\n"));
Theodore Ts'o521e3681997-04-29 17:48:10 +0000374 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'od9c56d32000-02-08 00:47:55 +0000379 printf(_("\nSparse superblock flag set. %s"),
Theodore Ts'oa4fa1002000-02-08 21:35:41 +0000380 _(please_fsck));
Theodore Ts'o521e3681997-04-29 17:48:10 +0000381 }
382#else /* !EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER */
383 com_err (program_name, 0,
Theodore Ts'od9c56d32000-02-08 00:47:55 +0000384 _("The -s option is not supported by this version -- "
385 "Recompile with a newer kernel"));
Theodore Ts'o521e3681997-04-29 17:48:10 +0000386#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'od9c56d32000-02-08 00:47:55 +0000392 fprintf(stderr, _("\nThe filesystem already"
Theodore Ts'oe1a0a3e2000-02-11 05:00:19 +0000393 " has sparse superblocks disabled.\n"));
Theodore Ts'o521e3681997-04-29 17:48:10 +0000394 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'od9c56d32000-02-08 00:47:55 +0000400 printf(_("\nSparse superblock flag cleared. %s"),
Theodore Ts'oa4fa1002000-02-08 21:35:41 +0000401 _(please_fsck));
Theodore Ts'o521e3681997-04-29 17:48:10 +0000402 }
403#else /* !EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER */
404 com_err (program_name, 0,
Theodore Ts'od9c56d32000-02-08 00:47:55 +0000405 _("The -s option is not supported by this version -- "
406 "Recompile with a newer kernel"));
Theodore Ts'o521e3681997-04-29 17:48:10 +0000407#endif /* EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER */
408 }
409
Theodore Ts'of3db3561997-04-26 13:34:30 +0000410 if (u_flag)
411#ifdef EXT2_DEF_RESUID
412 {
413 fs->super->s_def_resuid = resuid;
414 ext2fs_mark_super_dirty(fs);
Theodore Ts'od9c56d32000-02-08 00:47:55 +0000415 printf (_("Setting reserved blocks uid to %lu\n"), resuid);
Theodore Ts'of3db3561997-04-26 13:34:30 +0000416 }
417#else
418 com_err (program_name, 0,
Theodore Ts'od9c56d32000-02-08 00:47:55 +0000419 _("The -u option is not supported by this version -- "
420 "Recompile with a newer kernel"));
Theodore Ts'of3db3561997-04-26 13:34:30 +0000421#endif
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000422 if (L_flag) {
Theodore Ts'oa789d841998-03-30 01:20:55 +0000423 if (strlen(new_label) > sizeof(sb->s_volume_name))
Theodore Ts'od9c56d32000-02-08 00:47:55 +0000424 fprintf(stderr, _("Warning: label too "
425 "long, truncating.\n"));
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000426 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'o896938d1999-10-23 01:04:50 +0000437 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'od9c56d32000-02-08 00:47:55 +0000447 fprintf(stderr, _("Invalid filesystem option set: %s\n"),
Theodore Ts'o896938d1999-10-23 01:04:50 +0000448 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'oa4fa1002000-02-08 21:35:41 +0000458 printf("\n%s\n", _(please_fsck));
Theodore Ts'o896938d1999-10-23 01:04:50 +0000459 }
460 ext2fs_mark_super_dirty(fs);
461 }
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000462 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'od9c56d32000-02-08 00:47:55 +0000468 com_err(program_name, 0, _("Invalid UUID format\n"));
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000469 exit(1);
470 }
471 ext2fs_mark_super_dirty(fs);
472 }
473
Theodore Ts'o3839e651997-04-26 13:21:57 +0000474 if (l_flag)
475 list_super (fs->super);
476 ext2fs_close (fs);
477 exit (0);
478}