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;
80 const char *special, *on;
83 int Aflag, aflag, eflag, evalue, fflag, fvalue, Jflag, Lflag, lflag;
84 int mflag, mvalue, nflag, oflag, ovalue, pflag, sflag, svalue;
92 Aflag = aflag = eflag = fflag = Jflag = Lflag = lflag = mflag = 0;
93 nflag = oflag = pflag = sflag = 0;
94 avalue = Jvalue = 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:J: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 = "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);
192 name = "soft updates";
194 if (strcmp(nvalue, "enable") != 0 &&
195 strcmp(nvalue, "disable") != 0) {
196 errx(10, "bad %s (options are %s)",
197 name, "`enable' or `disable'");
204 name = "optimization preference";
205 if (strcmp(optarg, "space") == 0)
206 ovalue = FS_OPTSPACE;
207 else if (strcmp(optarg, "time") == 0)
211 "bad %s (options are `space' or `time')",
223 name = "expected number of files per directory";
224 svalue = atoi(optarg);
226 errx(10, "%s must be >= 1 (was %s)",
236 if (found_arg == 0 || argc != 1)
239 on = special = argv[0];
240 if (ufs_disk_fillout(&disk, special) == -1)
242 if (disk.d_name != special) {
243 special = disk.d_name;
244 if (statfs(special, &stfs) == 0 &&
245 strcmp(special, stfs.f_mntonname) == 0)
254 name = "volume label";
255 strlcpy(sblock.fs_volname, Lvalue, MAXVOLLEN);
259 if (strcmp(avalue, "enable") == 0) {
260 if (sblock.fs_flags & FS_ACLS) {
261 warnx("%s remains unchanged as enabled", name);
263 sblock.fs_flags |= FS_ACLS;
264 warnx("%s set", name);
266 } else if (strcmp(avalue, "disable") == 0) {
267 if ((~sblock.fs_flags & FS_ACLS) ==
269 warnx("%s remains unchanged as disabled",
272 sblock.fs_flags &= ~FS_ACLS;
273 warnx("%s cleared", name);
278 name = "maximum blocks per file in a cylinder group";
279 if (sblock.fs_maxbpg == evalue)
280 warnx("%s remains unchanged as %d", name, evalue);
282 warnx("%s changes from %d to %d",
283 name, sblock.fs_maxbpg, evalue);
284 sblock.fs_maxbpg = evalue;
288 name = "average file size";
289 if (sblock.fs_avgfilesize == fvalue) {
290 warnx("%s remains unchanged as %d", name, fvalue);
293 warnx("%s changes from %d to %d",
294 name, sblock.fs_avgfilesize, fvalue);
295 sblock.fs_avgfilesize = fvalue;
300 if (strcmp(Jvalue, "enable") == 0) {
301 if (sblock.fs_flags & FS_GJOURNAL) {
302 warnx("%s remains unchanged as enabled", name);
304 sblock.fs_flags |= FS_GJOURNAL;
305 warnx("%s set", name);
307 } else if (strcmp(Jvalue, "disable") == 0) {
308 if ((~sblock.fs_flags & FS_GJOURNAL) ==
310 warnx("%s remains unchanged as disabled",
313 sblock.fs_flags &= ~FS_GJOURNAL;
314 warnx("%s cleared", name);
320 if (strcmp(lvalue, "enable") == 0) {
321 if (sblock.fs_flags & FS_MULTILABEL) {
322 warnx("%s remains unchanged as enabled", name);
324 sblock.fs_flags |= FS_MULTILABEL;
325 warnx("%s set", name);
327 } else if (strcmp(lvalue, "disable") == 0) {
328 if ((~sblock.fs_flags & FS_MULTILABEL) ==
330 warnx("%s remains unchanged as disabled",
333 sblock.fs_flags &= ~FS_MULTILABEL;
334 warnx("%s cleared", name);
339 name = "minimum percentage of free space";
340 if (sblock.fs_minfree == mvalue)
341 warnx("%s remains unchanged as %d%%", name, mvalue);
343 warnx("%s changes from %d%% to %d%%",
344 name, sblock.fs_minfree, mvalue);
345 sblock.fs_minfree = mvalue;
346 if (mvalue >= MINFREE && sblock.fs_optim == FS_OPTSPACE)
347 warnx(OPTWARN, "time", ">=", MINFREE);
348 if (mvalue < MINFREE && sblock.fs_optim == FS_OPTTIME)
349 warnx(OPTWARN, "space", "<", MINFREE);
353 name = "soft updates";
354 if (strcmp(nvalue, "enable") == 0) {
355 if (sblock.fs_flags & FS_DOSOFTDEP)
356 warnx("%s remains unchanged as enabled", name);
357 else if (sblock.fs_clean == 0) {
358 warnx("%s cannot be enabled until fsck is run",
361 sblock.fs_flags |= FS_DOSOFTDEP;
362 warnx("%s set", name);
364 } else if (strcmp(nvalue, "disable") == 0) {
365 if ((~sblock.fs_flags & FS_DOSOFTDEP) == FS_DOSOFTDEP)
366 warnx("%s remains unchanged as disabled", name);
368 sblock.fs_flags &= ~FS_DOSOFTDEP;
369 warnx("%s cleared", name);
374 name = "optimization preference";
375 chg[FS_OPTSPACE] = "space";
376 chg[FS_OPTTIME] = "time";
377 if (sblock.fs_optim == ovalue)
378 warnx("%s remains unchanged as %s", name, chg[ovalue]);
380 warnx("%s changes from %s to %s",
381 name, chg[sblock.fs_optim], chg[ovalue]);
382 sblock.fs_optim = ovalue;
383 if (sblock.fs_minfree >= MINFREE &&
384 ovalue == FS_OPTSPACE)
385 warnx(OPTWARN, "time", ">=", MINFREE);
386 if (sblock.fs_minfree < MINFREE && ovalue == FS_OPTTIME)
387 warnx(OPTWARN, "space", "<", MINFREE);
391 name = "expected number of files per directory";
392 if (sblock.fs_avgfpdir == svalue) {
393 warnx("%s remains unchanged as %d", name, svalue);
396 warnx("%s changes from %d to %d",
397 name, sblock.fs_avgfpdir, svalue);
398 sblock.fs_avgfpdir = svalue;
402 if (sbwrite(&disk, Aflag) == -1)
404 ufs_disk_close(&disk);
406 bzero(&args, sizeof(args));
408 stfs.f_flags | MNT_UPDATE | MNT_RELOAD, &args) < 0)
409 err(9, "%s: reload", special);
410 warnx("file system reloaded");
414 if (disk.d_error != NULL)
415 errx(11, "%s: %s", special, disk.d_error);
417 err(12, "%s", special);
423 fprintf(stderr, "%s\n%s\n%s\n%s\n",
424 "usage: tunefs [-A] [-a enable | disable] [-e maxbpg] [-f avgfilesize]",
425 " [-J enable | disable ] [-L volname] [-l enable | disable]",
426 " [-m minfree] [-n enable | disable] [-o space | time] [-p]",
427 " [-s avgfpdir] special | filesystem");
434 warnx("ACLs: (-a) %s",
435 (sblock.fs_flags & FS_ACLS)? "enabled" : "disabled");
436 warnx("MAC multilabel: (-l) %s",
437 (sblock.fs_flags & FS_MULTILABEL)? "enabled" : "disabled");
438 warnx("soft updates: (-n) %s",
439 (sblock.fs_flags & FS_DOSOFTDEP)? "enabled" : "disabled");
440 warnx("gjournal: (-J) %s",
441 (sblock.fs_flags & FS_GJOURNAL)? "enabled" : "disabled");
442 warnx("maximum blocks per file in a cylinder group: (-e) %d",
444 warnx("average file size: (-f) %d",
445 sblock.fs_avgfilesize);
446 warnx("average number of files in a directory: (-s) %d",
448 warnx("minimum percentage of free space: (-m) %d%%",
450 warnx("optimization preference: (-o) %s",
451 sblock.fs_optim == FS_OPTSPACE ? "space" : "time");
452 if (sblock.fs_minfree >= MINFREE &&
453 sblock.fs_optim == FS_OPTSPACE)
454 warnx(OPTWARN, "time", ">=", MINFREE);
455 if (sblock.fs_minfree < MINFREE &&
456 sblock.fs_optim == FS_OPTTIME)
457 warnx(OPTWARN, "space", "<", MINFREE);
458 warnx("volume label: (-L) %s",