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, *Jvalue, *Lvalue, *lvalue, *Nvalue, *nvalue;
80 const char *special, *on;
83 int Aflag, aflag, eflag, evalue, fflag, fvalue, Jflag, Lflag, lflag;
84 int mflag, mvalue, Nflag, nflag, oflag, ovalue, pflag, sflag, svalue;
92 Aflag = aflag = eflag = fflag = Jflag = Lflag = lflag = mflag = 0;
93 Nflag = nflag = oflag = pflag = sflag = 0;
94 avalue = Jvalue = Lvalue = lvalue = Nvalue = 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:J:L:l:m:N:n:o:ps:")) != -1)
108 name = "POSIX.1e ACLs";
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 = "gjournaled file system";
142 if (strcmp(Jvalue, "enable") &&
143 strcmp(Jvalue, "disable")) {
144 errx(10, "bad %s (options are %s)",
145 name, "`enable' or `disable'");
153 name = "volume label";
156 while (isalnum(Lvalue[++i]));
157 if (Lvalue[i] != '\0') {
159 "bad %s. Valid characters are alphanumerics.",
162 if (strlen(Lvalue) >= MAXVOLLEN) {
163 errx(10, "bad %s. Length is longer than %d.",
164 name, MAXVOLLEN - 1);
171 name = "multilabel MAC file system";
173 if (strcmp(lvalue, "enable") &&
174 strcmp(lvalue, "disable")) {
175 errx(10, "bad %s (options are %s)",
176 name, "`enable' or `disable'");
183 name = "minimum percentage of free space";
184 mvalue = atoi(optarg);
185 if (mvalue < 0 || mvalue > 99)
186 errx(10, "bad %s (%s)", name, optarg);
194 if (strcmp(Nvalue, "enable") &&
195 strcmp(Nvalue, "disable")) {
196 errx(10, "bad %s (options are %s)",
197 name, "`enable' or `disable'");
204 name = "soft updates";
206 if (strcmp(nvalue, "enable") != 0 &&
207 strcmp(nvalue, "disable") != 0) {
208 errx(10, "bad %s (options are %s)",
209 name, "`enable' or `disable'");
216 name = "optimization preference";
217 if (strcmp(optarg, "space") == 0)
218 ovalue = FS_OPTSPACE;
219 else if (strcmp(optarg, "time") == 0)
223 "bad %s (options are `space' or `time')",
235 name = "expected number of files per directory";
236 svalue = atoi(optarg);
238 errx(10, "%s must be >= 1 (was %s)",
248 if (found_arg == 0 || argc != 1)
251 on = special = argv[0];
252 if (ufs_disk_fillout(&disk, special) == -1)
254 if (disk.d_name != special) {
255 special = disk.d_name;
256 if (statfs(special, &stfs) == 0 &&
257 strcmp(special, stfs.f_mntonname) == 0)
266 name = "volume label";
267 strlcpy(sblock.fs_volname, Lvalue, MAXVOLLEN);
270 name = "POSIX.1e ACLs";
271 if (strcmp(avalue, "enable") == 0) {
272 if (sblock.fs_flags & FS_ACLS) {
273 warnx("%s remains unchanged as enabled", name);
274 } else if (sblock.fs_flags & FS_NFS4ACLS) {
275 warnx("%s and NFSv4 ACLs are mutually "
278 sblock.fs_flags |= FS_ACLS;
279 warnx("%s set", name);
281 } else if (strcmp(avalue, "disable") == 0) {
282 if ((~sblock.fs_flags & FS_ACLS) ==
284 warnx("%s remains unchanged as disabled",
287 sblock.fs_flags &= ~FS_ACLS;
288 warnx("%s cleared", name);
293 name = "maximum blocks per file in a cylinder group";
294 if (sblock.fs_maxbpg == evalue)
295 warnx("%s remains unchanged as %d", name, evalue);
297 warnx("%s changes from %d to %d",
298 name, sblock.fs_maxbpg, evalue);
299 sblock.fs_maxbpg = evalue;
303 name = "average file size";
304 if (sblock.fs_avgfilesize == (unsigned)fvalue) {
305 warnx("%s remains unchanged as %d", name, fvalue);
308 warnx("%s changes from %d to %d",
309 name, sblock.fs_avgfilesize, fvalue);
310 sblock.fs_avgfilesize = fvalue;
315 if (strcmp(Jvalue, "enable") == 0) {
316 if (sblock.fs_flags & FS_GJOURNAL) {
317 warnx("%s remains unchanged as enabled", name);
319 sblock.fs_flags |= FS_GJOURNAL;
320 warnx("%s set", name);
322 } else if (strcmp(Jvalue, "disable") == 0) {
323 if ((~sblock.fs_flags & FS_GJOURNAL) ==
325 warnx("%s remains unchanged as disabled",
328 sblock.fs_flags &= ~FS_GJOURNAL;
329 warnx("%s cleared", name);
335 if (strcmp(lvalue, "enable") == 0) {
336 if (sblock.fs_flags & FS_MULTILABEL) {
337 warnx("%s remains unchanged as enabled", name);
339 sblock.fs_flags |= FS_MULTILABEL;
340 warnx("%s set", name);
342 } else if (strcmp(lvalue, "disable") == 0) {
343 if ((~sblock.fs_flags & FS_MULTILABEL) ==
345 warnx("%s remains unchanged as disabled",
348 sblock.fs_flags &= ~FS_MULTILABEL;
349 warnx("%s cleared", name);
354 name = "minimum percentage of free space";
355 if (sblock.fs_minfree == mvalue)
356 warnx("%s remains unchanged as %d%%", name, mvalue);
358 warnx("%s changes from %d%% to %d%%",
359 name, sblock.fs_minfree, mvalue);
360 sblock.fs_minfree = mvalue;
361 if (mvalue >= MINFREE && sblock.fs_optim == FS_OPTSPACE)
362 warnx(OPTWARN, "time", ">=", MINFREE);
363 if (mvalue < MINFREE && sblock.fs_optim == FS_OPTTIME)
364 warnx(OPTWARN, "space", "<", MINFREE);
369 if (strcmp(Nvalue, "enable") == 0) {
370 if (sblock.fs_flags & FS_NFS4ACLS) {
371 warnx("%s remains unchanged as enabled", name);
372 } else if (sblock.fs_flags & FS_ACLS) {
373 warnx("%s and POSIX.1e ACLs are mutually "
376 sblock.fs_flags |= FS_NFS4ACLS;
377 warnx("%s set", name);
379 } else if (strcmp(Nvalue, "disable") == 0) {
380 if ((~sblock.fs_flags & FS_NFS4ACLS) ==
382 warnx("%s remains unchanged as disabled",
385 sblock.fs_flags &= ~FS_NFS4ACLS;
386 warnx("%s cleared", name);
391 name = "soft updates";
392 if (strcmp(nvalue, "enable") == 0) {
393 if (sblock.fs_flags & FS_DOSOFTDEP)
394 warnx("%s remains unchanged as enabled", name);
395 else if (sblock.fs_clean == 0) {
396 warnx("%s cannot be enabled until fsck is run",
399 sblock.fs_flags |= FS_DOSOFTDEP;
400 warnx("%s set", name);
402 } else if (strcmp(nvalue, "disable") == 0) {
403 if ((~sblock.fs_flags & FS_DOSOFTDEP) == FS_DOSOFTDEP)
404 warnx("%s remains unchanged as disabled", name);
406 sblock.fs_flags &= ~FS_DOSOFTDEP;
407 warnx("%s cleared", name);
412 name = "optimization preference";
413 chg[FS_OPTSPACE] = "space";
414 chg[FS_OPTTIME] = "time";
415 if (sblock.fs_optim == ovalue)
416 warnx("%s remains unchanged as %s", name, chg[ovalue]);
418 warnx("%s changes from %s to %s",
419 name, chg[sblock.fs_optim], chg[ovalue]);
420 sblock.fs_optim = ovalue;
421 if (sblock.fs_minfree >= MINFREE &&
422 ovalue == FS_OPTSPACE)
423 warnx(OPTWARN, "time", ">=", MINFREE);
424 if (sblock.fs_minfree < MINFREE && ovalue == FS_OPTTIME)
425 warnx(OPTWARN, "space", "<", MINFREE);
429 name = "expected number of files per directory";
430 if (sblock.fs_avgfpdir == (unsigned)svalue) {
431 warnx("%s remains unchanged as %d", name, svalue);
434 warnx("%s changes from %d to %d",
435 name, sblock.fs_avgfpdir, svalue);
436 sblock.fs_avgfpdir = svalue;
440 if (sbwrite(&disk, Aflag) == -1)
442 ufs_disk_close(&disk);
444 bzero(&args, sizeof(args));
446 stfs.f_flags | MNT_UPDATE | MNT_RELOAD, &args) < 0)
447 err(9, "%s: reload", special);
448 warnx("file system reloaded");
452 if (disk.d_error != NULL)
453 errx(11, "%s: %s", special, disk.d_error);
455 err(12, "%s", special);
461 fprintf(stderr, "%s\n%s\n%s\n%s\n",
462 "usage: tunefs [-A] [-a enable | disable] [-e maxbpg] [-f avgfilesize]",
463 " [-J enable | disable ] [-L volname] [-l enable | disable]",
464 " [-m minfree] [-N enable | disable] [-n enable | disable]",
465 " [-o space | time] [-p] [-s avgfpdir] special | filesystem");
472 warnx("POSIX.1e ACLs: (-a) %s",
473 (sblock.fs_flags & FS_ACLS)? "enabled" : "disabled");
474 warnx("NFSv4 ACLs: (-N) %s",
475 (sblock.fs_flags & FS_NFS4ACLS)? "enabled" : "disabled");
476 warnx("MAC multilabel: (-l) %s",
477 (sblock.fs_flags & FS_MULTILABEL)? "enabled" : "disabled");
478 warnx("soft updates: (-n) %s",
479 (sblock.fs_flags & FS_DOSOFTDEP)? "enabled" : "disabled");
480 warnx("gjournal: (-J) %s",
481 (sblock.fs_flags & FS_GJOURNAL)? "enabled" : "disabled");
482 warnx("maximum blocks per file in a cylinder group: (-e) %d",
484 warnx("average file size: (-f) %d",
485 sblock.fs_avgfilesize);
486 warnx("average number of files in a directory: (-s) %d",
488 warnx("minimum percentage of free space: (-m) %d%%",
490 warnx("optimization preference: (-o) %s",
491 sblock.fs_optim == FS_OPTSPACE ? "space" : "time");
492 if (sblock.fs_minfree >= MINFREE &&
493 sblock.fs_optim == FS_OPTSPACE)
494 warnx(OPTWARN, "time", ">=", MINFREE);
495 if (sblock.fs_minfree < MINFREE &&
496 sblock.fs_optim == FS_OPTTIME)
497 warnx(OPTWARN, "space", "<", MINFREE);
498 warnx("volume label: (-L) %s",