2 * tune2fs.c - Change the file system parameters on
3 * an unmounted second extended file system
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)
9 * This file can be redistributed under the terms of the GNU General
16 * 93/10/31 - Added the -c option to change the maximal mount counts
17 * 93/12/14 - Added -l flag to list contents of superblock
18 * M.J.E. Mol (marcel@duteca.et.tudelft.nl)
19 * F.W. ten Wolde (franky@duteca.et.tudelft.nl)
20 * 93/12/29 - Added the -e option to change errors behavior
21 * 94/02/27 - Ported to use the ext2fs library
22 * 94/03/06 - Added the checks interval from Uwe Ohse (uwe@tirka.gun.de)
34 #include <sys/types.h>
36 #include <linux/ext2_fs.h>
38 #include "ext2fs/ext2fs.h"
39 #include "et/com_err.h"
42 #include "../version.h"
44 const char * program_name = "tune2fs";
45 char * device_name = NULL;
55 unsigned long interval;
56 unsigned long reserved_ratio = 0;
57 unsigned long reserved_blocks = 0;
58 unsigned short errors;
59 unsigned long resgid = 0;
60 unsigned long resuid = 0;
62 static volatile void usage (void)
64 fprintf (stderr, "Usage: %s [-c max-mounts-count] [-e errors-behavior] "
66 "\t[-i interval[d|m|w]] [-l] [-m reserved-blocks-percent]\n"
67 "\t[-r reserved-blocks-count] [-u user] device\n", program_name);
71 void main (int argc, char ** argv)
80 fprintf (stderr, "tune2fs %s, %s for EXT2 FS %s, %s\n",
81 E2FSPROGS_VERSION, E2FSPROGS_DATE,
82 EXT2FS_VERSION, EXT2FS_DATE);
85 initialize_ext2_error_table();
86 while ((c = getopt (argc, argv, "c:e:g:i:lm:r:u:")) != EOF)
90 max_mount_count = strtoul (optarg, &tmp, 0);
91 if (*tmp || max_mount_count > 16000)
93 com_err (program_name, 0,
94 "bad mounts count - %s",
101 if (strcmp (optarg, "continue") == 0)
102 errors = EXT2_ERRORS_CONTINUE;
103 else if (strcmp (optarg, "remount-ro") == 0)
104 errors = EXT2_ERRORS_RO;
105 else if (strcmp (optarg, "panic") == 0)
106 errors = EXT2_ERRORS_PANIC;
109 com_err (program_name, 0,
110 "bad error behavior - %s",
117 resgid = strtoul (optarg, &tmp, 0);
120 gr = getgrnam (optarg);
128 com_err (program_name, 0,
129 "bad gid/group name - %s",
136 interval = strtoul (optarg, &tmp, 0);
147 case 'M': /* months! */
148 interval *= 86400 * 30;
152 case 'W': /* weeks */
153 interval *= 86400 * 7;
157 if (*tmp || interval > (365 * 86400))
159 com_err (program_name, 0,
160 "bad interval - %s", optarg);
169 reserved_ratio = strtoul (optarg, &tmp, 0);
170 if (*tmp || reserved_ratio > 50)
172 com_err (program_name, 0,
173 "bad reserved block ratio - %s",
180 reserved_blocks = strtoul (optarg, &tmp, 0);
183 com_err (program_name, 0,
184 "bad reserved blocks count - %s",
191 resuid = strtoul (optarg, &tmp, 0);
194 pw = getpwnam (optarg);
202 com_err (program_name, 0,
203 "bad uid/user name - %s",
212 if (optind < argc - 1 || optind == argc)
214 if (!c_flag && !e_flag && !g_flag && !i_flag && !l_flag && !m_flag
215 && !r_flag && !u_flag)
217 device_name = argv[optind];
218 retval = ext2fs_open (device_name,
219 (c_flag || e_flag || g_flag || i_flag || m_flag
220 || r_flag || u_flag) ? EXT2_FLAG_RW : 0,
221 0, 0, unix_io_manager, &fs);
224 com_err (program_name, retval, "while trying to open %s",
226 printf("Couldn't find valid filesystem superblock.\n");
232 fs->super->s_max_mnt_count = max_mount_count;
233 ext2fs_mark_super_dirty(fs);
234 printf ("Setting maximal mount count to %d\n", max_mount_count);
238 fs->super->s_errors = errors;
239 ext2fs_mark_super_dirty(fs);
240 printf ("Setting error behavior to %d\n", errors);
243 #ifdef EXT2_DEF_RESGID
245 fs->super->s_def_resgid = resgid;
246 ext2fs_mark_super_dirty(fs);
247 printf ("Setting reserved blocks gid to %lu\n", resgid);
250 com_err (program_name, 0,
251 "The -g option is not supported by this version -- "
252 "Recompile with a newer kernel");
256 fs->super->s_checkinterval = interval;
257 ext2fs_mark_super_dirty(fs);
258 printf ("Setting interval between check %lu seconds\n", interval);
262 fs->super->s_r_blocks_count = (fs->super->s_blocks_count / 100)
264 ext2fs_mark_super_dirty(fs);
265 printf ("Setting reserved blocks percentage to %lu (%lu blocks)\n",
266 reserved_ratio, fs->super->s_r_blocks_count);
270 if (reserved_blocks >= fs->super->s_blocks_count)
272 com_err (program_name, 0,
273 "reserved blocks count is too big (%ul)",
277 fs->super->s_r_blocks_count = reserved_blocks;
278 ext2fs_mark_super_dirty(fs);
279 printf ("Setting reserved blocks count to %lu\n",
283 #ifdef EXT2_DEF_RESUID
285 fs->super->s_def_resuid = resuid;
286 ext2fs_mark_super_dirty(fs);
287 printf ("Setting reserved blocks uid to %lu\n", resuid);
290 com_err (program_name, 0,
291 "The -u option is not supported by this version -- "
292 "Recompile with a newer kernel");
295 list_super (fs->super);