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>
51
#ifndef HAVE_BSD_STATFS
52
#include <sys/statvfs.h>
53
#define statfs statvfs
54
#define f_flags f_flag
58
#include <ufs/ufs/ufsmount.h>
60
#include <ufs/ufs/dinode.h>
61
#include <ufs/ffs/fs.h>
74
/* the optimization warning string template */
75
#define OPTWARN "should optimize for %s with minfree %s %d%%"
78
#define sblock disk.d_fs
84
main(int argc, char *argv[])
86
char *avalue, *Jvalue, *Lvalue, *lvalue, *Nvalue, *nvalue;
87
const char *special, *on;
90
int Aflag, aflag, eflag, evalue, fflag, fvalue, Jflag, Lflag, lflag;
91
int mflag, mvalue, Nflag, nflag, oflag, ovalue, pflag, sflag, svalue;
97
#ifdef HAVE_BSD_STATFS
103
Aflag = aflag = eflag = fflag = Jflag = Lflag = lflag = mflag = 0;
104
Nflag = nflag = oflag = pflag = sflag = 0;
105
avalue = Jvalue = Lvalue = lvalue = Nvalue = nvalue = NULL;
106
evalue = fvalue = mvalue = ovalue = svalue = 0;
108
found_arg = 0; /* At least one arg is required. */
109
while ((ch = getopt(argc, argv, "Aa:e:f:J:L:l:m:N:n:o:ps:")) != -1)
119
name = "POSIX.1e ACLs";
121
if (strcmp(avalue, "enable") &&
122
strcmp(avalue, "disable")) {
123
errx(10, "bad %s (options are %s)",
124
name, "`enable' or `disable'");
131
name = "maximum blocks per file in a cylinder group";
132
evalue = atoi(optarg);
134
errx(10, "%s must be >= 1 (was %s)",
141
name = "average file size";
142
fvalue = atoi(optarg);
144
errx(10, "%s must be >= 1 (was %s)",
151
name = "gjournaled file system";
153
if (strcmp(Jvalue, "enable") &&
154
strcmp(Jvalue, "disable")) {
155
errx(10, "bad %s (options are %s)",
156
name, "`enable' or `disable'");
164
name = "volume label";
167
while (isalnum(Lvalue[++i]));
168
if (Lvalue[i] != '\0') {
170
"bad %s. Valid characters are alphanumerics.",
173
if (strlen(Lvalue) >= MAXVOLLEN) {
174
errx(10, "bad %s. Length is longer than %d.",
175
name, MAXVOLLEN - 1);
182
name = "multilabel MAC file system";
184
if (strcmp(lvalue, "enable") &&
185
strcmp(lvalue, "disable")) {
186
errx(10, "bad %s (options are %s)",
187
name, "`enable' or `disable'");
194
name = "minimum percentage of free space";
195
mvalue = atoi(optarg);
196
if (mvalue < 0 || mvalue > 99)
197
errx(10, "bad %s (%s)", name, optarg);
205
if (strcmp(Nvalue, "enable") &&
206
strcmp(Nvalue, "disable")) {
207
errx(10, "bad %s (options are %s)",
208
name, "`enable' or `disable'");
215
name = "soft updates";
217
if (strcmp(nvalue, "enable") != 0 &&
218
strcmp(nvalue, "disable") != 0) {
219
errx(10, "bad %s (options are %s)",
220
name, "`enable' or `disable'");
227
name = "optimization preference";
228
if (strcmp(optarg, "space") == 0)
229
ovalue = FS_OPTSPACE;
230
else if (strcmp(optarg, "time") == 0)
234
"bad %s (options are `space' or `time')",
246
name = "expected number of files per directory";
247
svalue = atoi(optarg);
249
errx(10, "%s must be >= 1 (was %s)",
259
if (found_arg == 0 || argc != 1)
262
on = special = argv[0];
263
if (ufs_disk_fillout(&disk, special) == -1)
265
if (disk.d_name != special) {
266
special = disk.d_name;
267
#ifdef HAVE_BSD_STATFS
268
if (statfs(special, &stfs) == 0 &&
269
strcmp(special, stfs.f_mntonname) == 0)
279
name = "volume label";
280
strlcpy(sblock.fs_volname, Lvalue, MAXVOLLEN);
283
name = "POSIX.1e ACLs";
284
if (strcmp(avalue, "enable") == 0) {
285
if (sblock.fs_flags & FS_ACLS) {
286
warnx("%s remains unchanged as enabled", name);
287
} else if (sblock.fs_flags & FS_NFS4ACLS) {
288
warnx("%s and NFSv4 ACLs are mutually "
291
sblock.fs_flags |= FS_ACLS;
292
warnx("%s set", name);
294
} else if (strcmp(avalue, "disable") == 0) {
295
if ((~sblock.fs_flags & FS_ACLS) ==
297
warnx("%s remains unchanged as disabled",
300
sblock.fs_flags &= ~FS_ACLS;
301
warnx("%s cleared", name);
306
name = "maximum blocks per file in a cylinder group";
307
if (sblock.fs_maxbpg == evalue)
308
warnx("%s remains unchanged as %d", name, evalue);
310
warnx("%s changes from %d to %d",
311
name, sblock.fs_maxbpg, evalue);
312
sblock.fs_maxbpg = evalue;
316
name = "average file size";
317
if (sblock.fs_avgfilesize == (unsigned)fvalue) {
318
warnx("%s remains unchanged as %d", name, fvalue);
321
warnx("%s changes from %d to %d",
322
name, sblock.fs_avgfilesize, fvalue);
323
sblock.fs_avgfilesize = fvalue;
328
if (strcmp(Jvalue, "enable") == 0) {
329
if (sblock.fs_flags & FS_GJOURNAL) {
330
warnx("%s remains unchanged as enabled", name);
332
sblock.fs_flags |= FS_GJOURNAL;
333
warnx("%s set", name);
335
} else if (strcmp(Jvalue, "disable") == 0) {
336
if ((~sblock.fs_flags & FS_GJOURNAL) ==
338
warnx("%s remains unchanged as disabled",
341
sblock.fs_flags &= ~FS_GJOURNAL;
342
warnx("%s cleared", name);
348
if (strcmp(lvalue, "enable") == 0) {
349
if (sblock.fs_flags & FS_MULTILABEL) {
350
warnx("%s remains unchanged as enabled", name);
352
sblock.fs_flags |= FS_MULTILABEL;
353
warnx("%s set", name);
355
} else if (strcmp(lvalue, "disable") == 0) {
356
if ((~sblock.fs_flags & FS_MULTILABEL) ==
358
warnx("%s remains unchanged as disabled",
361
sblock.fs_flags &= ~FS_MULTILABEL;
362
warnx("%s cleared", name);
367
name = "minimum percentage of free space";
368
if (sblock.fs_minfree == mvalue)
369
warnx("%s remains unchanged as %d%%", name, mvalue);
371
warnx("%s changes from %d%% to %d%%",
372
name, sblock.fs_minfree, mvalue);
373
sblock.fs_minfree = mvalue;
374
if (mvalue >= MINFREE && sblock.fs_optim == FS_OPTSPACE)
375
warnx(OPTWARN, "time", ">=", MINFREE);
376
if (mvalue < MINFREE && sblock.fs_optim == FS_OPTTIME)
377
warnx(OPTWARN, "space", "<", MINFREE);
382
if (strcmp(Nvalue, "enable") == 0) {
383
if (sblock.fs_flags & FS_NFS4ACLS) {
384
warnx("%s remains unchanged as enabled", name);
385
} else if (sblock.fs_flags & FS_ACLS) {
386
warnx("%s and POSIX.1e ACLs are mutually "
389
sblock.fs_flags |= FS_NFS4ACLS;
390
warnx("%s set", name);
392
} else if (strcmp(Nvalue, "disable") == 0) {
393
if ((~sblock.fs_flags & FS_NFS4ACLS) ==
395
warnx("%s remains unchanged as disabled",
398
sblock.fs_flags &= ~FS_NFS4ACLS;
399
warnx("%s cleared", name);
404
name = "soft updates";
405
if (strcmp(nvalue, "enable") == 0) {
406
if (sblock.fs_flags & FS_DOSOFTDEP)
407
warnx("%s remains unchanged as enabled", name);
408
else if (sblock.fs_clean == 0) {
409
warnx("%s cannot be enabled until fsck is run",
412
sblock.fs_flags |= FS_DOSOFTDEP;
413
warnx("%s set", name);
415
} else if (strcmp(nvalue, "disable") == 0) {
416
if ((~sblock.fs_flags & FS_DOSOFTDEP) == FS_DOSOFTDEP)
417
warnx("%s remains unchanged as disabled", name);
419
sblock.fs_flags &= ~FS_DOSOFTDEP;
420
warnx("%s cleared", name);
425
name = "optimization preference";
426
chg[FS_OPTSPACE] = "space";
427
chg[FS_OPTTIME] = "time";
428
if (sblock.fs_optim == ovalue)
429
warnx("%s remains unchanged as %s", name, chg[ovalue]);
431
warnx("%s changes from %s to %s",
432
name, chg[sblock.fs_optim], chg[ovalue]);
433
sblock.fs_optim = ovalue;
434
if (sblock.fs_minfree >= MINFREE &&
435
ovalue == FS_OPTSPACE)
436
warnx(OPTWARN, "time", ">=", MINFREE);
437
if (sblock.fs_minfree < MINFREE && ovalue == FS_OPTTIME)
438
warnx(OPTWARN, "space", "<", MINFREE);
442
name = "expected number of files per directory";
443
if (sblock.fs_avgfpdir == (unsigned)svalue) {
444
warnx("%s remains unchanged as %d", name, svalue);
447
warnx("%s changes from %d to %d",
448
name, sblock.fs_avgfpdir, svalue);
449
sblock.fs_avgfpdir = svalue;
453
if (sbwrite(&disk, Aflag) == -1)
455
ufs_disk_close(&disk);
456
#if HAVE_BSD_MOUNT && HAVE_BSD_STATFS
458
bzero(&args, sizeof(args));
460
stfs.f_flags | MNT_UPDATE | MNT_RELOAD, &args) < 0)
461
err(9, "%s: reload", special);
462
warnx("file system reloaded");
467
if (disk.d_error != NULL)
468
errx(11, "%s: %s", special, disk.d_error);
470
err(12, "%s", special);
476
fprintf(stderr, "%s\n%s\n%s\n%s\n",
477
"usage: tunefs [-A] [-a enable | disable] [-e maxbpg] [-f avgfilesize]",
478
" [-J enable | disable ] [-L volname] [-l enable | disable]",
479
" [-m minfree] [-N enable | disable] [-n enable | disable]",
480
" [-o space | time] [-p] [-s avgfpdir] special | filesystem");
487
warnx("POSIX.1e ACLs: (-a) %s",
488
(sblock.fs_flags & FS_ACLS)? "enabled" : "disabled");
489
warnx("NFSv4 ACLs: (-N) %s",
490
(sblock.fs_flags & FS_NFS4ACLS)? "enabled" : "disabled");
491
warnx("MAC multilabel: (-l) %s",
492
(sblock.fs_flags & FS_MULTILABEL)? "enabled" : "disabled");
493
warnx("soft updates: (-n) %s",
494
(sblock.fs_flags & FS_DOSOFTDEP)? "enabled" : "disabled");
495
warnx("gjournal: (-J) %s",
496
(sblock.fs_flags & FS_GJOURNAL)? "enabled" : "disabled");
497
warnx("maximum blocks per file in a cylinder group: (-e) %d",
499
warnx("average file size: (-f) %d",
500
sblock.fs_avgfilesize);
501
warnx("average number of files in a directory: (-s) %d",
503
warnx("minimum percentage of free space: (-m) %d%%",
505
warnx("optimization preference: (-o) %s",
506
sblock.fs_optim == FS_OPTSPACE ? "space" : "time");
507
if (sblock.fs_minfree >= MINFREE &&
508
sblock.fs_optim == FS_OPTSPACE)
509
warnx(OPTWARN, "time", ">=", MINFREE);
510
if (sblock.fs_minfree < MINFREE &&
511
sblock.fs_optim == FS_OPTTIME)
512
warnx(OPTWARN, "space", "<", MINFREE);
513
warnx("volume label: (-L) %s",