xref: /freebsd/sbin/tunefs/tunefs.c (revision b1f0fda09fdaa7c35192f6f637491e817815def3)
18fae3551SRodney W. Grimes /*
28fae3551SRodney W. Grimes  * Copyright (c) 1983, 1993
38fae3551SRodney W. Grimes  *	The Regents of the University of California.  All rights reserved.
48fae3551SRodney W. Grimes  *
58fae3551SRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
68fae3551SRodney W. Grimes  * modification, are permitted provided that the following conditions
78fae3551SRodney W. Grimes  * are met:
88fae3551SRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
98fae3551SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
108fae3551SRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
118fae3551SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
128fae3551SRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
138fae3551SRodney W. Grimes  * 3. All advertising materials mentioning features or use of this software
148fae3551SRodney W. Grimes  *    must display the following acknowledgement:
158fae3551SRodney W. Grimes  *	This product includes software developed by the University of
168fae3551SRodney W. Grimes  *	California, Berkeley and its contributors.
178fae3551SRodney W. Grimes  * 4. Neither the name of the University nor the names of its contributors
188fae3551SRodney W. Grimes  *    may be used to endorse or promote products derived from this software
198fae3551SRodney W. Grimes  *    without specific prior written permission.
208fae3551SRodney W. Grimes  *
218fae3551SRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
228fae3551SRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
238fae3551SRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
248fae3551SRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
258fae3551SRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
268fae3551SRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
278fae3551SRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
288fae3551SRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
298fae3551SRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
308fae3551SRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
318fae3551SRodney W. Grimes  * SUCH DAMAGE.
328fae3551SRodney W. Grimes  */
338fae3551SRodney W. Grimes 
348fae3551SRodney W. Grimes #ifndef lint
358679b1b4SPhilippe Charnier static const char copyright[] =
368fae3551SRodney W. Grimes "@(#) Copyright (c) 1983, 1993\n\
378fae3551SRodney W. Grimes 	The Regents of the University of California.  All rights reserved.\n";
388fae3551SRodney W. Grimes #endif /* not lint */
398fae3551SRodney W. Grimes 
408fae3551SRodney W. Grimes #ifndef lint
418679b1b4SPhilippe Charnier #if 0
428fae3551SRodney W. Grimes static char sccsid[] = "@(#)tunefs.c	8.2 (Berkeley) 4/19/94";
438679b1b4SPhilippe Charnier #endif
448679b1b4SPhilippe Charnier static const char rcsid[] =
457f3dea24SPeter Wemm   "$FreeBSD$";
468fae3551SRodney W. Grimes #endif /* not lint */
478fae3551SRodney W. Grimes 
488fae3551SRodney W. Grimes /*
498fae3551SRodney W. Grimes  * tunefs: change layout parameters to an existing file system.
508fae3551SRodney W. Grimes  */
518fae3551SRodney W. Grimes #include <sys/param.h>
527382c45aSLuoqi Chen #include <sys/mount.h>
5375766e17SPoul-Henning Kamp #include <sys/disklabel.h>
548fae3551SRodney W. Grimes #include <sys/stat.h>
558fae3551SRodney W. Grimes 
567382c45aSLuoqi Chen #include <ufs/ufs/ufsmount.h>
571c85e6a3SKirk McKusick #include <ufs/ufs/dinode.h>
581c85e6a3SKirk McKusick #include <ufs/ffs/fs.h>
598fae3551SRodney W. Grimes 
608fae3551SRodney W. Grimes #include <err.h>
618fae3551SRodney W. Grimes #include <fcntl.h>
628fae3551SRodney W. Grimes #include <fstab.h>
63b1f0fda0SJuli Mallett #include <libufs.h>
648fae3551SRodney W. Grimes #include <paths.h>
658679b1b4SPhilippe Charnier #include <stdio.h>
668fae3551SRodney W. Grimes #include <stdlib.h>
67060ac658SSheldon Hearn #include <string.h>
688fae3551SRodney W. Grimes #include <unistd.h>
698fae3551SRodney W. Grimes 
708fae3551SRodney W. Grimes /* the optimization warning string template */
718fae3551SRodney W. Grimes #define	OPTWARN	"should optimize for %s with minfree %s %d%%"
728fae3551SRodney W. Grimes 
73b1f0fda0SJuli Mallett struct uufsd disk;
74b1f0fda0SJuli Mallett #define	sblock disk.d_fs
758fae3551SRodney W. Grimes 
76d476a036SWarner Losh void usage(void);
77d476a036SWarner Losh void printfs(void);
788fae3551SRodney W. Grimes 
798fae3551SRodney W. Grimes int
80b1f0fda0SJuli Mallett main(int argc, char *argv[])
818fae3551SRodney W. Grimes {
82c33fa91fSDima Dorfman 	char *special;
83c33fa91fSDima Dorfman 	const char *name;
848fae3551SRodney W. Grimes 	struct stat st;
85289e09eeSRobert Watson 	int Aflag = 0, active = 0, aflag = 0;
86289e09eeSRobert Watson 	int eflag = 0, fflag = 0, lflag = 0, mflag = 0;
87a61ab64aSKirk McKusick 	int nflag = 0, oflag = 0, pflag = 0, sflag = 0;
88a9098c89SPoul-Henning Kamp 	int evalue = 0, fvalue = 0;
89a61ab64aSKirk McKusick 	int mvalue = 0, ovalue = 0, svalue = 0;
90289e09eeSRobert Watson 	char *avalue = NULL, *lvalue = NULL, *nvalue = NULL;
918fae3551SRodney W. Grimes 	struct fstab *fs;
92c33fa91fSDima Dorfman 	const char *chg[2];
93c33fa91fSDima Dorfman 	char device[MAXPATHLEN];
947382c45aSLuoqi Chen 	struct ufs_args args;
957382c45aSLuoqi Chen 	struct statfs stfs;
962af14b60SPhilippe Charnier 	int found_arg, ch;
978fae3551SRodney W. Grimes 
982af14b60SPhilippe Charnier         if (argc < 3)
998fae3551SRodney W. Grimes                 usage();
10077edab90SPhilippe Charnier 	found_arg = 0; /* at least one arg is required */
101a2325efeSRobert Watson 	while ((ch = getopt(argc, argv, "Aa:e:f:l:m:n:o:ps:")) != -1)
10277edab90SPhilippe Charnier 	  switch (ch) {
103a2325efeSRobert Watson 	  case 'A':
104a2325efeSRobert Watson 		found_arg = 1;
105a2325efeSRobert Watson 		Aflag++;
106a2325efeSRobert Watson 		break;
107289e09eeSRobert Watson 	  case 'a':
108289e09eeSRobert Watson 		found_arg = 1;
109289e09eeSRobert Watson 		name = "ACLs";
110289e09eeSRobert Watson 		avalue = optarg;
111289e09eeSRobert Watson 		if (strcmp(avalue, "enable") && strcmp(avalue, "disable")) {
112289e09eeSRobert Watson 			errx(10, "bad %s (options are %s)", name,
113289e09eeSRobert Watson 			    "`enable' or `disable'");
114289e09eeSRobert Watson 		}
115289e09eeSRobert Watson 		aflag = 1;
116289e09eeSRobert Watson 		break;
11777edab90SPhilippe Charnier 	  case 'e':
11877edab90SPhilippe Charnier 		found_arg = 1;
11977edab90SPhilippe Charnier 		name = "maximum blocks per file in a cylinder group";
12077edab90SPhilippe Charnier 		evalue = atoi(optarg);
12177edab90SPhilippe Charnier 		if (evalue < 1)
12277edab90SPhilippe Charnier 			errx(10, "%s must be >= 1 (was %s)", name, optarg);
12377edab90SPhilippe Charnier 		eflag = 1;
12477edab90SPhilippe Charnier 		break;
125a61ab64aSKirk McKusick 	  case 'f':
126a61ab64aSKirk McKusick 		found_arg = 1;
127a61ab64aSKirk McKusick 		name = "average file size";
128a61ab64aSKirk McKusick 		fvalue = atoi(optarg);
129a61ab64aSKirk McKusick 		if (fvalue < 1)
130a61ab64aSKirk McKusick 			errx(10, "%s must be >= 1 (was %s)", name, optarg);
131a61ab64aSKirk McKusick 		fflag = 1;
132a61ab64aSKirk McKusick 		break;
133289e09eeSRobert Watson 	  case 'l':
134289e09eeSRobert Watson 		found_arg = 1;
135289e09eeSRobert Watson 		name = "multilabel MAC file system";
136289e09eeSRobert Watson 		lvalue = optarg;
137289e09eeSRobert Watson 		if (strcmp(lvalue, "enable") && strcmp(lvalue, "disable")) {
138289e09eeSRobert Watson 			errx(10, "bad %s (options are %s)", name,
139289e09eeSRobert Watson 			    "`enable' or `disable'");
140289e09eeSRobert Watson 		}
141289e09eeSRobert Watson 		lflag = 1;
142289e09eeSRobert Watson 		break;
14377edab90SPhilippe Charnier 	  case 'm':
14477edab90SPhilippe Charnier 		found_arg = 1;
14577edab90SPhilippe Charnier 		name = "minimum percentage of free space";
14677edab90SPhilippe Charnier 		mvalue = atoi(optarg);
14777edab90SPhilippe Charnier 		if (mvalue < 0 || mvalue > 99)
14877edab90SPhilippe Charnier 			errx(10, "bad %s (%s)", name, optarg);
14977edab90SPhilippe Charnier 		mflag = 1;
15077edab90SPhilippe Charnier 		break;
15177edab90SPhilippe Charnier 	  case 'n':
15277edab90SPhilippe Charnier 		found_arg = 1;
15377edab90SPhilippe Charnier  		name = "soft updates";
15477edab90SPhilippe Charnier  		nvalue = optarg;
15577edab90SPhilippe Charnier                 if (strcmp(nvalue, "enable") && strcmp(nvalue, "disable")) {
15677edab90SPhilippe Charnier  			errx(10, "bad %s (options are %s)",
15777edab90SPhilippe Charnier  			    name, "`enable' or `disable'");
15877edab90SPhilippe Charnier  		}
15977edab90SPhilippe Charnier 		nflag = 1;
16077edab90SPhilippe Charnier  		break;
16177edab90SPhilippe Charnier 	  case 'o':
16277edab90SPhilippe Charnier 		found_arg = 1;
16377edab90SPhilippe Charnier 		name = "optimization preference";
16477edab90SPhilippe Charnier 		chg[FS_OPTSPACE] = "space";
16577edab90SPhilippe Charnier 		chg[FS_OPTTIME] = "time";
16677edab90SPhilippe Charnier 		if (strcmp(optarg, chg[FS_OPTSPACE]) == 0)
16777edab90SPhilippe Charnier 			ovalue = FS_OPTSPACE;
16877edab90SPhilippe Charnier 		else if (strcmp(optarg, chg[FS_OPTTIME]) == 0)
16977edab90SPhilippe Charnier 			ovalue = FS_OPTTIME;
17077edab90SPhilippe Charnier 		else
17177edab90SPhilippe Charnier 			errx(10, "bad %s (options are `space' or `time')",
17277edab90SPhilippe Charnier 					    name);
17377edab90SPhilippe Charnier 		oflag = 1;
17477edab90SPhilippe Charnier 		break;
17577edab90SPhilippe Charnier 	  case 'p':
176e50fa3d2SBen Smithurst 		found_arg = 1;
17777edab90SPhilippe Charnier 		pflag = 1;
17877edab90SPhilippe Charnier 		break;
179a61ab64aSKirk McKusick 	  case 's':
180a61ab64aSKirk McKusick 		found_arg = 1;
181a61ab64aSKirk McKusick 		name = "expected number of files per directory";
182a61ab64aSKirk McKusick 		svalue = atoi(optarg);
183a61ab64aSKirk McKusick 		if (svalue < 1)
184a61ab64aSKirk McKusick 			errx(10, "%s must be >= 1 (was %s)", name, optarg);
185a61ab64aSKirk McKusick 		sflag = 1;
186a61ab64aSKirk McKusick 		break;
18777edab90SPhilippe Charnier 	  default:
18877edab90SPhilippe Charnier 		usage();
18977edab90SPhilippe Charnier 	  }
19077edab90SPhilippe Charnier 	argc -= optind;
19177edab90SPhilippe Charnier 	argv += optind;
19277edab90SPhilippe Charnier 
19377edab90SPhilippe Charnier 	if (found_arg == 0 || argc != 1)
19477edab90SPhilippe Charnier 	  usage();
19577edab90SPhilippe Charnier 
19677edab90SPhilippe Charnier 	special = argv[0];
1978fae3551SRodney W. Grimes 	fs = getfsfile(special);
1987382c45aSLuoqi Chen 	if (fs) {
1999ea6e95eSLuoqi Chen 		if (statfs(special, &stfs) == 0 &&
2009ea6e95eSLuoqi Chen 		    strcmp(special, stfs.f_mntonname) == 0) {
2017382c45aSLuoqi Chen 			active = 1;
202b20ae6a0SLuoqi Chen 		}
2038fae3551SRodney W. Grimes 		special = fs->fs_spec;
2047382c45aSLuoqi Chen 	}
2058fae3551SRodney W. Grimes again:
2068fae3551SRodney W. Grimes 	if (stat(special, &st) < 0) {
2078fae3551SRodney W. Grimes 		if (*special != '/') {
2088fae3551SRodney W. Grimes 			if (*special == 'r')
2098fae3551SRodney W. Grimes 				special++;
21047f07d95SIan Dowse 			(void)snprintf(device, sizeof(device), "%s%s",
21155fd28c8SKris Kennaway 				       _PATH_DEV, special);
2128fae3551SRodney W. Grimes 			special = device;
2138fae3551SRodney W. Grimes 			goto again;
2148fae3551SRodney W. Grimes 		}
2158fae3551SRodney W. Grimes 		err(1, "%s", special);
2168fae3551SRodney W. Grimes 	}
21747f07d95SIan Dowse 	if (fs == NULL && (st.st_mode & S_IFMT) == S_IFDIR)
21847f07d95SIan Dowse 		errx(10, "%s: unknown file system", special);
219b1f0fda0SJuli Mallett 	if (ufs_disk_fillout(&disk, special) == -1) {
220b1f0fda0SJuli Mallett 		if (disk.d_error != NULL)
221b1f0fda0SJuli Mallett 			errx(11, "%s: %s", special, disk.d_error);
222b1f0fda0SJuli Mallett 		else
223b1f0fda0SJuli Mallett 			err(12, "%s", special);
224b1f0fda0SJuli Mallett 	}
2258fae3551SRodney W. Grimes 
22677edab90SPhilippe Charnier 	if (pflag) {
22777edab90SPhilippe Charnier 		printfs();
22877edab90SPhilippe Charnier 		exit(0);
22977edab90SPhilippe Charnier 	}
230289e09eeSRobert Watson 	if (aflag) {
231289e09eeSRobert Watson 		name = "ACLs";
232289e09eeSRobert Watson 		if (strcmp(avalue, "enable") == 0) {
233289e09eeSRobert Watson 			if (sblock.fs_flags & FS_ACLS) {
234289e09eeSRobert Watson 				warnx("%s remains unchanged as enabled", name);
235289e09eeSRobert Watson 			} else {
236289e09eeSRobert Watson 				sblock.fs_flags |= FS_ACLS;
237289e09eeSRobert Watson 				warnx("%s set", name);
238289e09eeSRobert Watson 			}
239289e09eeSRobert Watson 		} else if (strcmp(avalue, "disable") == 0) {
240289e09eeSRobert Watson 			if ((~sblock.fs_flags & FS_ACLS) ==
241289e09eeSRobert Watson 			    FS_ACLS) {
242289e09eeSRobert Watson 				warnx("%s remains unchanged as disabled",
243289e09eeSRobert Watson 				    name);
244289e09eeSRobert Watson 			} else {
245289e09eeSRobert Watson 				sblock.fs_flags &= ~FS_ACLS;
246273500c2SRobert Watson 				warnx("%s cleared", name);
247289e09eeSRobert Watson 			}
248289e09eeSRobert Watson 		}
249289e09eeSRobert Watson 	}
25077edab90SPhilippe Charnier 	if (eflag) {
2512af14b60SPhilippe Charnier 		name = "maximum blocks per file in a cylinder group";
25277edab90SPhilippe Charnier 		if (sblock.fs_maxbpg == evalue) {
25377edab90SPhilippe Charnier 			warnx("%s remains unchanged as %d", name, evalue);
2542af14b60SPhilippe Charnier 		}
25577edab90SPhilippe Charnier 		else {
25677edab90SPhilippe Charnier 			warnx("%s changes from %d to %d",
25777edab90SPhilippe Charnier 					name, sblock.fs_maxbpg, evalue);
25877edab90SPhilippe Charnier 			sblock.fs_maxbpg = evalue;
25977edab90SPhilippe Charnier 		}
26077edab90SPhilippe Charnier 	}
261a61ab64aSKirk McKusick 	if (fflag) {
262a61ab64aSKirk McKusick 		name = "average file size";
263a61ab64aSKirk McKusick 		if (sblock.fs_avgfilesize == fvalue) {
264a61ab64aSKirk McKusick 			warnx("%s remains unchanged as %d", name, fvalue);
265a61ab64aSKirk McKusick 		}
266a61ab64aSKirk McKusick 		else {
267a61ab64aSKirk McKusick 			warnx("%s changes from %d to %d",
268a61ab64aSKirk McKusick 					name, sblock.fs_avgfilesize, fvalue);
269a61ab64aSKirk McKusick 			sblock.fs_avgfilesize = fvalue;
270a61ab64aSKirk McKusick 		}
271a61ab64aSKirk McKusick 	}
272289e09eeSRobert Watson 	if (lflag) {
273289e09eeSRobert Watson 		name = "multilabel";
274289e09eeSRobert Watson 		if (strcmp(lvalue, "enable") == 0) {
275289e09eeSRobert Watson 			if (sblock.fs_flags & FS_MULTILABEL) {
276289e09eeSRobert Watson 				warnx("%s remains unchanged as enabled", name);
277289e09eeSRobert Watson 			} else {
278289e09eeSRobert Watson 				sblock.fs_flags |= FS_MULTILABEL;
279289e09eeSRobert Watson 				warnx("%s set", name);
280289e09eeSRobert Watson 			}
281289e09eeSRobert Watson 		} else if (strcmp(lvalue, "disable") == 0) {
282289e09eeSRobert Watson 			if ((~sblock.fs_flags & FS_MULTILABEL) ==
283289e09eeSRobert Watson 			    FS_MULTILABEL) {
284289e09eeSRobert Watson 				warnx("%s remains unchanged as disabled",
285289e09eeSRobert Watson 				    name);
286289e09eeSRobert Watson 			} else {
287289e09eeSRobert Watson 				sblock.fs_flags &= ~FS_MULTILABEL;
288273500c2SRobert Watson 				warnx("%s cleared", name);
289289e09eeSRobert Watson 			}
290289e09eeSRobert Watson 		}
291289e09eeSRobert Watson 	}
29277edab90SPhilippe Charnier 	if (mflag) {
2938fae3551SRodney W. Grimes 		name = "minimum percentage of free space";
29477edab90SPhilippe Charnier 		if (sblock.fs_minfree == mvalue) {
29577edab90SPhilippe Charnier 			warnx("%s remains unchanged as %d%%", name, mvalue);
2962af14b60SPhilippe Charnier 		}
29777edab90SPhilippe Charnier 		else {
2988fae3551SRodney W. Grimes 			warnx("%s changes from %d%% to %d%%",
29977edab90SPhilippe Charnier 				    name, sblock.fs_minfree, mvalue);
30077edab90SPhilippe Charnier 			sblock.fs_minfree = mvalue;
30177edab90SPhilippe Charnier 			if (mvalue >= MINFREE && sblock.fs_optim == FS_OPTSPACE)
3028fae3551SRodney W. Grimes 				warnx(OPTWARN, "time", ">=", MINFREE);
30377edab90SPhilippe Charnier 			if (mvalue < MINFREE && sblock.fs_optim == FS_OPTTIME)
3048fae3551SRodney W. Grimes 				warnx(OPTWARN, "space", "<", MINFREE);
305b1897c19SJulian Elischer 		}
30677edab90SPhilippe Charnier 	}
30777edab90SPhilippe Charnier 	if (nflag) {
30877edab90SPhilippe Charnier  		name = "soft updates";
30977edab90SPhilippe Charnier  		if (strcmp(nvalue, "enable") == 0) {
31077edab90SPhilippe Charnier 			if (sblock.fs_flags & FS_DOSOFTDEP) {
31177edab90SPhilippe Charnier 				warnx("%s remains unchanged as enabled", name);
3121c2665d8SKirk McKusick 			} else if (sblock.fs_clean == 0) {
3131c2665d8SKirk McKusick 				warnx("%s cannot be enabled until fsck is run",
3141c2665d8SKirk McKusick 				    name);
31577edab90SPhilippe Charnier 			} else {
31677edab90SPhilippe Charnier  				sblock.fs_flags |= FS_DOSOFTDEP;
31777edab90SPhilippe Charnier  				warnx("%s set", name);
31877edab90SPhilippe Charnier 			}
31977edab90SPhilippe Charnier  		} else if (strcmp(nvalue, "disable") == 0) {
32077edab90SPhilippe Charnier 			if ((~sblock.fs_flags & FS_DOSOFTDEP) == FS_DOSOFTDEP) {
32177edab90SPhilippe Charnier 				warnx("%s remains unchanged as disabled", name);
32277edab90SPhilippe Charnier 			} else {
32377edab90SPhilippe Charnier  				sblock.fs_flags &= ~FS_DOSOFTDEP;
32477edab90SPhilippe Charnier  				warnx("%s cleared", name);
32577edab90SPhilippe Charnier 			}
32677edab90SPhilippe Charnier  		}
32777edab90SPhilippe Charnier 	}
32877edab90SPhilippe Charnier 	if (oflag) {
3298fae3551SRodney W. Grimes 		name = "optimization preference";
3308fae3551SRodney W. Grimes 		chg[FS_OPTSPACE] = "space";
3318fae3551SRodney W. Grimes 		chg[FS_OPTTIME] = "time";
33277edab90SPhilippe Charnier 		if (sblock.fs_optim == ovalue) {
33377edab90SPhilippe Charnier 			warnx("%s remains unchanged as %s", name, chg[ovalue]);
3348fae3551SRodney W. Grimes 		}
33577edab90SPhilippe Charnier 		else {
3368fae3551SRodney W. Grimes 			warnx("%s changes from %s to %s",
33777edab90SPhilippe Charnier 				    name, chg[sblock.fs_optim], chg[ovalue]);
33877edab90SPhilippe Charnier 			sblock.fs_optim = ovalue;
33977edab90SPhilippe Charnier 			if (sblock.fs_minfree >= MINFREE &&
34077edab90SPhilippe Charnier 					ovalue == FS_OPTSPACE)
3418fae3551SRodney W. Grimes 				warnx(OPTWARN, "time", ">=", MINFREE);
34277edab90SPhilippe Charnier 			if (sblock.fs_minfree < MINFREE &&
34377edab90SPhilippe Charnier 					ovalue == FS_OPTTIME)
3448fae3551SRodney W. Grimes 				warnx(OPTWARN, "space", "<", MINFREE);
3458fae3551SRodney W. Grimes 		}
34677edab90SPhilippe Charnier 	}
347a61ab64aSKirk McKusick 	if (sflag) {
348a61ab64aSKirk McKusick 		name = "expected number of files per directory";
349a61ab64aSKirk McKusick 		if (sblock.fs_avgfpdir == svalue) {
350a61ab64aSKirk McKusick 			warnx("%s remains unchanged as %d", name, svalue);
351a61ab64aSKirk McKusick 		}
352a61ab64aSKirk McKusick 		else {
353a61ab64aSKirk McKusick 			warnx("%s changes from %d to %d",
354a61ab64aSKirk McKusick 					name, sblock.fs_avgfpdir, svalue);
355a61ab64aSKirk McKusick 			sblock.fs_avgfpdir = svalue;
356a61ab64aSKirk McKusick 		}
357a61ab64aSKirk McKusick 	}
3582af14b60SPhilippe Charnier 
359b1f0fda0SJuli Mallett 	sbwrite(&disk, Aflag);
3607382c45aSLuoqi Chen 	if (active) {
3617382c45aSLuoqi Chen 		bzero(&args, sizeof(args));
3627382c45aSLuoqi Chen 		if (mount("ufs", fs->fs_file,
3637382c45aSLuoqi Chen 		    stfs.f_flags | MNT_UPDATE | MNT_RELOAD, &args) < 0)
3647382c45aSLuoqi Chen 			err(9, "%s: reload", special);
3657382c45aSLuoqi Chen 		warnx("file system reloaded");
3667382c45aSLuoqi Chen 	}
3678fae3551SRodney W. Grimes 	exit(0);
3688fae3551SRodney W. Grimes }
3698fae3551SRodney W. Grimes 
3708fae3551SRodney W. Grimes void
371b1f0fda0SJuli Mallett usage(void)
3728fae3551SRodney W. Grimes {
3738679b1b4SPhilippe Charnier 	fprintf(stderr, "%s\n%s\n%s\n",
374a2325efeSRobert Watson "usage: tunefs [-A] [-a enable | disable] [-e maxbpg] [-f avgfilesize]",
375289e09eeSRobert Watson "              [-l enable | disable] [-m minfree] [-n enable | disable]",
376289e09eeSRobert Watson "              [-o space | time] [-p] [-s avgfpdir] special | filesystem");
3778fae3551SRodney W. Grimes 	exit(2);
3788fae3551SRodney W. Grimes }
3798fae3551SRodney W. Grimes 
3808fae3551SRodney W. Grimes void
381b1f0fda0SJuli Mallett printfs(void)
38216a7269eSJoerg Wunsch {
38381dc101cSRobert Watson 	warnx("ACLs: (-a)                                         %s",
38481dc101cSRobert Watson 		(sblock.fs_flags & FS_ACLS)? "enabled" : "disabled");
38581dc101cSRobert Watson 	warnx("MAC multilabel: (-l)                               %s",
38681dc101cSRobert Watson 		(sblock.fs_flags & FS_MULTILABEL)? "enabled" : "disabled");
387b1897c19SJulian Elischer 	warnx("soft updates: (-n)                                 %s",
388b1897c19SJulian Elischer 		(sblock.fs_flags & FS_DOSOFTDEP)? "enabled" : "disabled");
38916a7269eSJoerg Wunsch 	warnx("maximum blocks per file in a cylinder group: (-e)  %d",
39016a7269eSJoerg Wunsch 	      sblock.fs_maxbpg);
391a61ab64aSKirk McKusick 	warnx("average file size: (-f)                            %d",
392a61ab64aSKirk McKusick 	      sblock.fs_avgfilesize);
393a61ab64aSKirk McKusick 	warnx("average number of files in a directory: (-s)       %d",
394a61ab64aSKirk McKusick 	      sblock.fs_avgfpdir);
39516a7269eSJoerg Wunsch 	warnx("minimum percentage of free space: (-m)             %d%%",
39616a7269eSJoerg Wunsch 	      sblock.fs_minfree);
39716a7269eSJoerg Wunsch 	warnx("optimization preference: (-o)                      %s",
39816a7269eSJoerg Wunsch 	      sblock.fs_optim == FS_OPTSPACE ? "space" : "time");
39916a7269eSJoerg Wunsch 	if (sblock.fs_minfree >= MINFREE &&
40016a7269eSJoerg Wunsch 	    sblock.fs_optim == FS_OPTSPACE)
40116a7269eSJoerg Wunsch 		warnx(OPTWARN, "time", ">=", MINFREE);
40216a7269eSJoerg Wunsch 	if (sblock.fs_minfree < MINFREE &&
40316a7269eSJoerg Wunsch 	    sblock.fs_optim == FS_OPTTIME)
40416a7269eSJoerg Wunsch 		warnx(OPTWARN, "space", "<", MINFREE);
40516a7269eSJoerg Wunsch }
406