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)
36 #include <sys/types.h>
38 #include <linux/ext2_fs.h>
40 #include "ext2fs/ext2fs.h"
41 #include "et/com_err.h"
44 #include "../version.h"
46 const char * program_name = "tune2fs";
47 char * device_name = NULL;
57 unsigned long interval;
58 unsigned long reserved_ratio = 0;
59 unsigned long reserved_blocks = 0;
60 unsigned short errors;
61 unsigned long resgid = 0;
62 unsigned long resuid = 0;
64 static volatile void usage (void)
66 fprintf (stderr, "Usage: %s [-c max-mounts-count] [-e errors-behavior] "
68 "\t[-i interval[d|m|w]] [-l] [-m reserved-blocks-percent]\n"
69 "\t[-r reserved-blocks-count] [-u user] device\n", program_name);
73 void main (int argc, char ** argv)
82 fprintf (stderr, "tune2fs %s, %s for EXT2 FS %s, %s\n",
83 E2FSPROGS_VERSION, E2FSPROGS_DATE,
84 EXT2FS_VERSION, EXT2FS_DATE);
87 initialize_ext2_error_table();
88 while ((c = getopt (argc, argv, "c:e:g:i:lm:r:u:")) != EOF)
92 max_mount_count = strtoul (optarg, &tmp, 0);
93 if (*tmp || max_mount_count > 16000)
95 com_err (program_name, 0,
96 "bad mounts count - %s",
103 if (strcmp (optarg, "continue") == 0)
104 errors = EXT2_ERRORS_CONTINUE;
105 else if (strcmp (optarg, "remount-ro") == 0)
106 errors = EXT2_ERRORS_RO;
107 else if (strcmp (optarg, "panic") == 0)
108 errors = EXT2_ERRORS_PANIC;
111 com_err (program_name, 0,
112 "bad error behavior - %s",
119 resgid = strtoul (optarg, &tmp, 0);
122 gr = getgrnam (optarg);
132 com_err (program_name, 0,
133 "bad gid/group name - %s",
140 interval = strtoul (optarg, &tmp, 0);
151 case 'M': /* months! */
152 interval *= 86400 * 30;
156 case 'W': /* weeks */
157 interval *= 86400 * 7;
161 if (*tmp || interval > (365 * 86400))
163 com_err (program_name, 0,
164 "bad interval - %s", optarg);
173 reserved_ratio = strtoul (optarg, &tmp, 0);
174 if (*tmp || reserved_ratio > 50)
176 com_err (program_name, 0,
177 "bad reserved block ratio - %s",
184 reserved_blocks = strtoul (optarg, &tmp, 0);
187 com_err (program_name, 0,
188 "bad reserved blocks count - %s",
195 resuid = strtoul (optarg, &tmp, 0);
198 pw = getpwnam (optarg);
208 com_err (program_name, 0,
209 "bad uid/user name - %s",
218 if (optind < argc - 1 || optind == argc)
220 if (!c_flag && !e_flag && !g_flag && !i_flag && !l_flag && !m_flag
221 && !r_flag && !u_flag)
223 device_name = argv[optind];
224 retval = ext2fs_open (device_name,
225 (c_flag || e_flag || g_flag || i_flag || m_flag
226 || r_flag || u_flag) ? EXT2_FLAG_RW : 0,
227 0, 0, unix_io_manager, &fs);
230 com_err (program_name, retval, "while trying to open %s",
232 printf("Couldn't find valid filesystem superblock.\n");
238 fs->super->s_max_mnt_count = max_mount_count;
239 ext2fs_mark_super_dirty(fs);
240 printf ("Setting maximal mount count to %d\n", max_mount_count);
244 fs->super->s_errors = errors;
245 ext2fs_mark_super_dirty(fs);
246 printf ("Setting error behavior to %d\n", errors);
249 #ifdef EXT2_DEF_RESGID
251 fs->super->s_def_resgid = resgid;
252 ext2fs_mark_super_dirty(fs);
253 printf ("Setting reserved blocks gid to %lu\n", resgid);
256 com_err (program_name, 0,
257 "The -g option is not supported by this version -- "
258 "Recompile with a newer kernel");
262 fs->super->s_checkinterval = interval;
263 ext2fs_mark_super_dirty(fs);
264 printf ("Setting interval between check %lu seconds\n", interval);
268 fs->super->s_r_blocks_count = (fs->super->s_blocks_count / 100)
270 ext2fs_mark_super_dirty(fs);
271 printf ("Setting reserved blocks percentage to %lu (%lu blocks)\n",
272 reserved_ratio, fs->super->s_r_blocks_count);
276 if (reserved_blocks >= fs->super->s_blocks_count)
278 com_err (program_name, 0,
279 "reserved blocks count is too big (%ul)",
283 fs->super->s_r_blocks_count = reserved_blocks;
284 ext2fs_mark_super_dirty(fs);
285 printf ("Setting reserved blocks count to %lu\n",
289 #ifdef EXT2_DEF_RESUID
291 fs->super->s_def_resuid = resuid;
292 ext2fs_mark_super_dirty(fs);
293 printf ("Setting reserved blocks uid to %lu\n", resuid);
296 com_err (program_name, 0,
297 "The -u option is not supported by this version -- "
298 "Recompile with a newer kernel");
301 list_super (fs->super);