Deleted Added
sdiff udiff text old ( 69314 ) new ( 69829 )
full compact
1/*
2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 28 unchanged lines hidden (view full) ---

37 The Regents of the University of California. All rights reserved.\n";
38#endif /* not lint */
39
40#ifndef lint
41#if 0
42static char sccsid[] = "@(#)tunefs.c 8.2 (Berkeley) 4/19/94";
43#endif
44static const char rcsid[] =
45 "$FreeBSD: head/sbin/tunefs/tunefs.c 69314 2000-11-28 18:17:15Z charnier $";
46#endif /* not lint */
47
48/*
49 * tunefs: change layout parameters to an existing file system.
50 */
51#include <sys/param.h>
52#include <sys/mount.h>
53#include <sys/stat.h>

--- 29 unchanged lines hidden (view full) ---

83void usage __P((void));
84void printfs __P((void));
85
86int
87main(argc, argv)
88 int argc;
89 char *argv[];
90{
91 char *special, *name, *action;
92 struct stat st;
93 int i;
94 int Aflag = 0, active = 0;
95 struct fstab *fs;
96 char *chg[2], device[MAXPATHLEN];
97 struct ufs_args args;
98 struct statfs stfs;
99 int found_arg, ch;
100
101 if (argc < 3)
102 usage();
103 special = argv[argc - 1];
104 fs = getfsfile(special);
105 if (fs) {
106 if (statfs(special, &stfs) == 0 &&
107 strcmp(special, stfs.f_mntonname) == 0) {
108 active = 1;
109 }
110 special = fs->fs_spec;
111 }
112again:
113 if (stat(special, &st) < 0) {
114 if (*special != '/') {
115 if (*special == 'r')
116 special++;
117 (void)sprintf(device, "%s/%s", _PATH_DEV, special);
118 special = device;
119 goto again;
120 }
121 err(1, "%s", special);
122 }
123 if ((st.st_mode & S_IFMT) != S_IFBLK &&
124 (st.st_mode & S_IFMT) != S_IFCHR)
125 errx(10, "%s: not a block or character device", special);
126 getsb(&sblock, special);
127
128 found_arg = 0; /* at least one arg is required */
129 while ((ch = getopt(argc, argv, "Aa:d:e:m:n:o:p")) != -1)
130 switch (ch) {
131 case 'A':
132 found_arg = 1;
133 Aflag++;
134 break;
135 case 'a':
136 found_arg = 1;
137 name = "maximum contiguous block count";
138 i = atoi(optarg);
139 if (i < 1)
140 errx(10, "%s must be >= 1 (was %s)", name, optarg);
141 if (sblock.fs_maxcontig == i) {
142 warnx("%s remains unchanged as %d", name, i);
143 break;
144 }
145 warnx("%s changes from %d to %d", name, sblock.fs_maxcontig, i);
146 sblock.fs_maxcontig = i;
147 break;
148 case 'd':
149 found_arg = 1;
150 name = "rotational delay between contiguous blocks";
151 i = atoi(optarg);
152 if (sblock.fs_rotdelay == i) {
153 warnx("%s remains unchanged as %dms", name, i);
154 break;
155 }
156 warnx("%s changes from %dms to %dms",
157 name, sblock.fs_rotdelay, i);
158 sblock.fs_rotdelay = i;
159 break;
160 case 'e':
161 found_arg = 1;
162 name = "maximum blocks per file in a cylinder group";
163 i = atoi(optarg);
164 if (i < 1)
165 errx(10, "%s must be >= 1 (was %s)", name, optarg);
166 if (sblock.fs_maxbpg == i) {
167 warnx("%s remains unchanged as %d", name, i);
168 break;
169 }
170 warnx("%s changes from %d to %d", name, sblock.fs_maxbpg, i);
171 sblock.fs_maxbpg = i;
172 break;
173 case 'm':
174 found_arg = 1;
175 name = "minimum percentage of free space";
176 i = atoi(optarg);
177 if (i < 0 || i > 99)
178 errx(10, "bad %s (%s)", name, optarg);
179 if (sblock.fs_minfree == i) {
180 warnx("%s remains unchanged as %d%%", name, i);
181 break;
182 }
183 warnx("%s changes from %d%% to %d%%",
184 name, sblock.fs_minfree, i);
185 sblock.fs_minfree = i;
186 if (i >= MINFREE && sblock.fs_optim == FS_OPTSPACE)
187 warnx(OPTWARN, "time", ">=", MINFREE);
188 if (i < MINFREE && sblock.fs_optim == FS_OPTTIME)
189 warnx(OPTWARN, "space", "<", MINFREE);
190 break;
191 case 'n':
192 found_arg = 1;
193 name = "soft updates";
194 if (strcmp(optarg, "enable") == 0) {
195 sblock.fs_flags |= FS_DOSOFTDEP;
196 action = "set";
197 } else if (strcmp(optarg, "disable") == 0) {
198 sblock.fs_flags &= ~FS_DOSOFTDEP;
199 action = "cleared";
200 } else {
201 errx(10, "bad %s (options are %s)",
202 name, "`enable' or `disable'");
203 }
204 warnx("%s %s", name, action);
205 break;
206 case 'o':
207 found_arg = 1;
208 name = "optimization preference";
209 chg[FS_OPTSPACE] = "space";
210 chg[FS_OPTTIME] = "time";
211 if (strcmp(optarg, chg[FS_OPTSPACE]) == 0)
212 i = FS_OPTSPACE;
213 else if (strcmp(optarg, chg[FS_OPTTIME]) == 0)
214 i = FS_OPTTIME;
215 else
216 errx(10, "bad %s (options are `space' or `time')",
217 name);
218 if (sblock.fs_optim == i) {
219 warnx("%s remains unchanged as %s", name, chg[i]);
220 break;
221 }
222 warnx("%s changes from %s to %s",
223 name, chg[sblock.fs_optim], chg[i]);
224 sblock.fs_optim = i;
225 if (sblock.fs_minfree >= MINFREE && i == FS_OPTSPACE)
226 warnx(OPTWARN, "time", ">=", MINFREE);
227 if (sblock.fs_minfree < MINFREE && i == FS_OPTTIME)
228 warnx(OPTWARN, "space", "<", MINFREE);
229 break;
230 case 'p':
231 printfs();
232 exit(0);
233 default:
234 usage();
235 }
236 argc -= optind;
237 argv += optind;
238
239 if (found_arg == 0 || argc != 1)
240 usage();
241
242 putsb(&sblock, special, Aflag);
243 if (active) {
244 bzero(&args, sizeof(args));
245 if (mount("ufs", fs->fs_file,
246 stfs.f_flags | MNT_UPDATE | MNT_RELOAD, &args) < 0)
247 err(9, "%s: reload", special);
248 warnx("file system reloaded");
249 }
250 exit(0);
251}
252
253void
254usage()
255{
256 fprintf(stderr, "%s\n%s\n%s\n",
257"usage: tunefs [-A] [-a maxcontig] [-d rotdelay] [-e maxbpg] [-m minfree]",
258" [-p] [-n enable | disable] [-o optimize_preference]",
259" special | filesystem");
260 exit(2);
261}
262
263void
264getsb(fs, file)
265 register struct fs *fs;
266 char *file;

--- 91 unchanged lines hidden ---