2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 4. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 static const char copyright[] =
33 "@(#) Copyright (c) 1983, 1993\n\
34 The Regents of the University of California. All rights reserved.\n";
38 static char sccsid[] = "@(#)tunefs.c 8.2 (Berkeley) 4/19/94";
41 #include <sys/cdefs.h>
42 __FBSDID("$FreeBSD$");
45 * tunefs: change layout parameters to an existing file system.
47 #include <sys/param.h>
48 #include <sys/mount.h>
49 #include <sys/disklabel.h>
52 #include <ufs/ufs/ufsmount.h>
53 #include <ufs/ufs/dinode.h>
54 #include <ufs/ffs/fs.h>
67 /* the optimization warning string template */
68 #define OPTWARN "should optimize for %s with minfree %s %d%%"
71 #define sblock disk.d_fs
77 main(int argc, char *argv[])
79 char *avalue, *Lvalue, *lvalue, *nvalue;
80 const char *special, *on;
83 int Aflag, aflag, eflag, evalue, fflag, fvalue, Lflag, lflag;
84 int mflag, mvalue, nflag, oflag, ovalue, pflag, sflag, svalue;
92 Aflag = aflag = eflag = fflag = Lflag = lflag = mflag = 0;
93 nflag = oflag = pflag = sflag = 0;
94 avalue = Lvalue = lvalue = nvalue = NULL;
95 evalue = fvalue = mvalue = ovalue = svalue = 0;
97 found_arg = 0; /* At least one arg is required. */
98 while ((ch = getopt(argc, argv, "Aa:e:f:L:l:m:n:o:ps:")) != -1)
110 if (strcmp(avalue, "enable") &&
111 strcmp(avalue, "disable")) {
112 errx(10, "bad %s (options are %s)",
113 name, "`enable' or `disable'");
120 name = "maximum blocks per file in a cylinder group";
121 evalue = atoi(optarg);
123 errx(10, "%s must be >= 1 (was %s)",
130 name = "average file size";
131 fvalue = atoi(optarg);
133 errx(10, "%s must be >= 1 (was %s)",
140 name = "volume label";
143 while (isalnum(Lvalue[++i]));
144 if (Lvalue[i] != '\0') {
146 "bad %s. Valid characters are alphanumerics.",
149 if (strlen(Lvalue) >= MAXVOLLEN) {
150 errx(10, "bad %s. Length is longer than %d.",
151 name, MAXVOLLEN - 1);
158 name = "multilabel MAC file system";
160 if (strcmp(lvalue, "enable") &&
161 strcmp(lvalue, "disable")) {
162 errx(10, "bad %s (options are %s)",
163 name, "`enable' or `disable'");
170 name = "minimum percentage of free space";
171 mvalue = atoi(optarg);
172 if (mvalue < 0 || mvalue > 99)
173 errx(10, "bad %s (%s)", name, optarg);
179 name = "soft updates";
181 if (strcmp(nvalue, "enable") != 0 &&
182 strcmp(nvalue, "disable") != 0) {
183 errx(10, "bad %s (options are %s)",
184 name, "`enable' or `disable'");
191 name = "optimization preference";
192 if (strcmp(optarg, "space") == 0)
193 ovalue = FS_OPTSPACE;
194 else if (strcmp(optarg, "time") == 0)
198 "bad %s (options are `space' or `time')",
210 name = "expected number of files per directory";
211 svalue = atoi(optarg);
213 errx(10, "%s must be >= 1 (was %s)",
223 if (found_arg == 0 || argc != 1)
226 on = special = argv[0];
227 if (ufs_disk_fillout(&disk, special) == -1)
229 if (disk.d_name != special) {
230 special = disk.d_name;
231 if (statfs(special, &stfs) == 0 &&
232 strcmp(special, stfs.f_mntonname) == 0)
241 name = "volume label";
242 strlcpy(sblock.fs_volname, Lvalue, MAXVOLLEN);
246 if (strcmp(avalue, "enable") == 0) {
247 if (sblock.fs_flags & FS_ACLS) {
248 warnx("%s remains unchanged as enabled", name);
250 sblock.fs_flags |= FS_ACLS;
251 warnx("%s set", name);
253 } else if (strcmp(avalue, "disable") == 0) {
254 if ((~sblock.fs_flags & FS_ACLS) ==
256 warnx("%s remains unchanged as disabled",
259 sblock.fs_flags &= ~FS_ACLS;
260 warnx("%s cleared", name);
265 name = "maximum blocks per file in a cylinder group";
266 if (sblock.fs_maxbpg == evalue)
267 warnx("%s remains unchanged as %d", name, evalue);
269 warnx("%s changes from %d to %d",
270 name, sblock.fs_maxbpg, evalue);
271 sblock.fs_maxbpg = evalue;
275 name = "average file size";
276 if (sblock.fs_avgfilesize == fvalue) {
277 warnx("%s remains unchanged as %d", name, fvalue);
280 warnx("%s changes from %d to %d",
281 name, sblock.fs_avgfilesize, fvalue);
282 sblock.fs_avgfilesize = fvalue;
287 if (strcmp(lvalue, "enable") == 0) {
288 if (sblock.fs_flags & FS_MULTILABEL) {
289 warnx("%s remains unchanged as enabled", name);
291 sblock.fs_flags |= FS_MULTILABEL;
292 warnx("%s set", name);
294 } else if (strcmp(lvalue, "disable") == 0) {
295 if ((~sblock.fs_flags & FS_MULTILABEL) ==
297 warnx("%s remains unchanged as disabled",
300 sblock.fs_flags &= ~FS_MULTILABEL;
301 warnx("%s cleared", name);
306 name = "minimum percentage of free space";
307 if (sblock.fs_minfree == mvalue)
308 warnx("%s remains unchanged as %d%%", name, mvalue);
310 warnx("%s changes from %d%% to %d%%",
311 name, sblock.fs_minfree, mvalue);
312 sblock.fs_minfree = mvalue;
313 if (mvalue >= MINFREE && sblock.fs_optim == FS_OPTSPACE)
314 warnx(OPTWARN, "time", ">=", MINFREE);
315 if (mvalue < MINFREE && sblock.fs_optim == FS_OPTTIME)
316 warnx(OPTWARN, "space", "<", MINFREE);
320 name = "soft updates";
321 if (strcmp(nvalue, "enable") == 0) {
322 if (sblock.fs_flags & FS_DOSOFTDEP)
323 warnx("%s remains unchanged as enabled", name);
324 else if (sblock.fs_clean == 0) {
325 warnx("%s cannot be enabled until fsck is run",
328 sblock.fs_flags |= FS_DOSOFTDEP;
329 warnx("%s set", name);
331 } else if (strcmp(nvalue, "disable") == 0) {
332 if ((~sblock.fs_flags & FS_DOSOFTDEP) == FS_DOSOFTDEP)
333 warnx("%s remains unchanged as disabled", name);
335 sblock.fs_flags &= ~FS_DOSOFTDEP;
336 warnx("%s cleared", name);
341 name = "optimization preference";
342 chg[FS_OPTSPACE] = "space";
343 chg[FS_OPTTIME] = "time";
344 if (sblock.fs_optim == ovalue)
345 warnx("%s remains unchanged as %s", name, chg[ovalue]);
347 warnx("%s changes from %s to %s",
348 name, chg[sblock.fs_optim], chg[ovalue]);
349 sblock.fs_optim = ovalue;
350 if (sblock.fs_minfree >= MINFREE &&
351 ovalue == FS_OPTSPACE)
352 warnx(OPTWARN, "time", ">=", MINFREE);
353 if (sblock.fs_minfree < MINFREE && ovalue == FS_OPTTIME)
354 warnx(OPTWARN, "space", "<", MINFREE);
358 name = "expected number of files per directory";
359 if (sblock.fs_avgfpdir == svalue) {
360 warnx("%s remains unchanged as %d", name, svalue);
363 warnx("%s changes from %d to %d",
364 name, sblock.fs_avgfpdir, svalue);
365 sblock.fs_avgfpdir = svalue;
369 if (sbwrite(&disk, Aflag) == -1)
371 ufs_disk_close(&disk);
373 bzero(&args, sizeof(args));
375 stfs.f_flags | MNT_UPDATE | MNT_RELOAD, &args) < 0)
376 err(9, "%s: reload", special);
377 warnx("file system reloaded");
381 if (disk.d_error != NULL)
382 errx(11, "%s: %s", special, disk.d_error);
384 err(12, "%s", special);
390 fprintf(stderr, "%s\n%s\n%s\n%s\n",
391 "usage: tunefs [-A] [-a enable | disable] [-e maxbpg] [-f avgfilesize]",
392 " [-L volname] [-l enable | disable] [-m minfree]",
393 " [-n enable | disable] [-o space | time] [-p]",
394 " [-s avgfpdir] special | filesystem");
401 warnx("ACLs: (-a) %s",
402 (sblock.fs_flags & FS_ACLS)? "enabled" : "disabled");
403 warnx("MAC multilabel: (-l) %s",
404 (sblock.fs_flags & FS_MULTILABEL)? "enabled" : "disabled");
405 warnx("soft updates: (-n) %s",
406 (sblock.fs_flags & FS_DOSOFTDEP)? "enabled" : "disabled");
407 warnx("maximum blocks per file in a cylinder group: (-e) %d",
409 warnx("average file size: (-f) %d",
410 sblock.fs_avgfilesize);
411 warnx("average number of files in a directory: (-s) %d",
413 warnx("minimum percentage of free space: (-m) %d%%",
415 warnx("optimization preference: (-o) %s",
416 sblock.fs_optim == FS_OPTSPACE ? "space" : "time");
417 if (sblock.fs_minfree >= MINFREE &&
418 sblock.fs_optim == FS_OPTSPACE)
419 warnx(OPTWARN, "time", ">=", MINFREE);
420 if (sblock.fs_minfree < MINFREE &&
421 sblock.fs_optim == FS_OPTTIME)
422 warnx(OPTWARN, "space", "<", MINFREE);
423 warnx("volume label: (-L) %s",