Deleted Added
full compact
tunefs.c (69314) tunefs.c (69829)
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[] =
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 $";
45 "$FreeBSD: head/sbin/tunefs/tunefs.c 69829 2000-12-10 20:59:30Z 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{
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;
91 char *special, *name;
92 struct stat st;
92 struct stat st;
93 int i;
94 int Aflag = 0, active = 0;
93 int Aflag = 0, active = 0;
94 int aflag = 0, dflag = 0, eflag = 0, mflag = 0;
95 int nflag = 0, oflag = 0, pflag = 0;
96 int avalue = 0, dvalue = 0, evalue = 0, mvalue = 0, ovalue = 0;
97 char *nvalue = NULL;
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();
98 struct fstab *fs;
99 char *chg[2], device[MAXPATHLEN];
100 struct ufs_args args;
101 struct statfs stfs;
102 int found_arg, ch;
103
104 if (argc < 3)
105 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";
106 found_arg = 0; /* at least one arg is required */
107 while ((ch = getopt(argc, argv, "Aa:d:e:m:n:o:p")) != -1)
108 switch (ch) {
109 case 'A':
110 found_arg = 1;
111 Aflag++;
112 break;
113 case 'a':
114 found_arg = 1;
115 name = "maximum contiguous block count";
138 i = atoi(optarg);
139 if (i < 1)
116 avalue = atoi(optarg);
117 if (avalue < 1)
140 errx(10, "%s must be >= 1 (was %s)", name, optarg);
118 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;
119 aflag = 1;
147 break;
148 case 'd':
149 found_arg = 1;
150 name = "rotational delay between contiguous blocks";
120 break;
121 case 'd':
122 found_arg = 1;
123 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;
124 dvalue = atoi(optarg);
125 dflag = 1;
159 break;
160 case 'e':
161 found_arg = 1;
162 name = "maximum blocks per file in a cylinder group";
126 break;
127 case 'e':
128 found_arg = 1;
129 name = "maximum blocks per file in a cylinder group";
163 i = atoi(optarg);
164 if (i < 1)
130 evalue = atoi(optarg);
131 if (evalue < 1)
165 errx(10, "%s must be >= 1 (was %s)", name, optarg);
132 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;
133 eflag = 1;
172 break;
173 case 'm':
174 found_arg = 1;
175 name = "minimum percentage of free space";
134 break;
135 case 'm':
136 found_arg = 1;
137 name = "minimum percentage of free space";
176 i = atoi(optarg);
177 if (i < 0 || i > 99)
138 mvalue = atoi(optarg);
139 if (mvalue < 0 || mvalue > 99)
178 errx(10, "bad %s (%s)", name, optarg);
140 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);
141 mflag = 1;
190 break;
191 case 'n':
192 found_arg = 1;
193 name = "soft updates";
142 break;
143 case 'n':
144 found_arg = 1;
145 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 {
146 nvalue = optarg;
147 if (strcmp(nvalue, "enable") && strcmp(nvalue, "disable")) {
201 errx(10, "bad %s (options are %s)",
202 name, "`enable' or `disable'");
203 }
148 errx(10, "bad %s (options are %s)",
149 name, "`enable' or `disable'");
150 }
204 warnx("%s %s", name, action);
151 nflag = 1;
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)
152 break;
153 case 'o':
154 found_arg = 1;
155 name = "optimization preference";
156 chg[FS_OPTSPACE] = "space";
157 chg[FS_OPTTIME] = "time";
158 if (strcmp(optarg, chg[FS_OPTSPACE]) == 0)
212 i = FS_OPTSPACE;
159 ovalue = FS_OPTSPACE;
213 else if (strcmp(optarg, chg[FS_OPTTIME]) == 0)
160 else if (strcmp(optarg, chg[FS_OPTTIME]) == 0)
214 i = FS_OPTTIME;
161 ovalue = FS_OPTTIME;
215 else
216 errx(10, "bad %s (options are `space' or `time')",
217 name);
162 else
163 errx(10, "bad %s (options are `space' or `time')",
164 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);
165 oflag = 1;
229 break;
230 case 'p':
166 break;
167 case 'p':
231 printfs();
232 exit(0);
168 pflag = 1;
169 break;
233 default:
234 usage();
235 }
236 argc -= optind;
237 argv += optind;
238
239 if (found_arg == 0 || argc != 1)
240 usage();
241
170 default:
171 usage();
172 }
173 argc -= optind;
174 argv += optind;
175
176 if (found_arg == 0 || argc != 1)
177 usage();
178
179 special = argv[0];
180 fs = getfsfile(special);
181 if (fs) {
182 if (statfs(special, &stfs) == 0 &&
183 strcmp(special, stfs.f_mntonname) == 0) {
184 active = 1;
185 }
186 special = fs->fs_spec;
187 }
188again:
189 if (stat(special, &st) < 0) {
190 if (*special != '/') {
191 if (*special == 'r')
192 special++;
193 (void)sprintf(device, "%s/%s", _PATH_DEV, special);
194 special = device;
195 goto again;
196 }
197 err(1, "%s", special);
198 }
199 if ((st.st_mode & S_IFMT) != S_IFBLK &&
200 (st.st_mode & S_IFMT) != S_IFCHR)
201 errx(10, "%s: not a block or character device", special);
202 getsb(&sblock, special);
203
204 if (pflag) {
205 printfs();
206 exit(0);
207 }
208 if (aflag) {
209 name = "maximum contiguous block count";
210 if (sblock.fs_maxcontig == avalue) {
211 warnx("%s remains unchanged as %d", name, avalue);
212 }
213 else {
214 warnx("%s changes from %d to %d",
215 name, sblock.fs_maxcontig, avalue);
216 sblock.fs_maxcontig = avalue;
217 }
218 }
219 if (dflag) {
220 name = "rotational delay between contiguous blocks";
221 if (sblock.fs_rotdelay == dvalue) {
222 warnx("%s remains unchanged as %dms", name, dvalue);
223 }
224 else {
225 warnx("%s changes from %dms to %dms",
226 name, sblock.fs_rotdelay, dvalue);
227 sblock.fs_rotdelay = dvalue;
228 }
229 }
230 if (eflag) {
231 name = "maximum blocks per file in a cylinder group";
232 if (sblock.fs_maxbpg == evalue) {
233 warnx("%s remains unchanged as %d", name, evalue);
234 }
235 else {
236 warnx("%s changes from %d to %d",
237 name, sblock.fs_maxbpg, evalue);
238 sblock.fs_maxbpg = evalue;
239 }
240 }
241 if (mflag) {
242 name = "minimum percentage of free space";
243 if (sblock.fs_minfree == mvalue) {
244 warnx("%s remains unchanged as %d%%", name, mvalue);
245 }
246 else {
247 warnx("%s changes from %d%% to %d%%",
248 name, sblock.fs_minfree, mvalue);
249 sblock.fs_minfree = mvalue;
250 if (mvalue >= MINFREE && sblock.fs_optim == FS_OPTSPACE)
251 warnx(OPTWARN, "time", ">=", MINFREE);
252 if (mvalue < MINFREE && sblock.fs_optim == FS_OPTTIME)
253 warnx(OPTWARN, "space", "<", MINFREE);
254 }
255 }
256 if (nflag) {
257 name = "soft updates";
258 if (strcmp(nvalue, "enable") == 0) {
259 if ( sblock.fs_flags & FS_DOSOFTDEP ) {
260 warnx("%s remains unchanged as enabled", name);
261 } else {
262 sblock.fs_flags |= FS_DOSOFTDEP;
263 warnx("%s set", name);
264 }
265 } else if (strcmp(nvalue, "disable") == 0) {
266 if ((~sblock.fs_flags & FS_DOSOFTDEP) == FS_DOSOFTDEP) {
267 warnx("%s remains unchanged as disabled", name);
268 } else {
269 sblock.fs_flags &= ~FS_DOSOFTDEP;
270 warnx("%s cleared", name);
271 }
272 }
273 }
274 if (oflag) {
275 name = "optimization preference";
276 chg[FS_OPTSPACE] = "space";
277 chg[FS_OPTTIME] = "time";
278 if (sblock.fs_optim == ovalue) {
279 warnx("%s remains unchanged as %s", name, chg[ovalue]);
280 }
281 else {
282 warnx("%s changes from %s to %s",
283 name, chg[sblock.fs_optim], chg[ovalue]);
284 sblock.fs_optim = ovalue;
285 if (sblock.fs_minfree >= MINFREE &&
286 ovalue == FS_OPTSPACE)
287 warnx(OPTWARN, "time", ">=", MINFREE);
288 if (sblock.fs_minfree < MINFREE &&
289 ovalue == FS_OPTTIME)
290 warnx(OPTWARN, "space", "<", MINFREE);
291 }
292 }
293
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]",
294 putsb(&sblock, special, Aflag);
295 if (active) {
296 bzero(&args, sizeof(args));
297 if (mount("ufs", fs->fs_file,
298 stfs.f_flags | MNT_UPDATE | MNT_RELOAD, &args) < 0)
299 err(9, "%s: reload", special);
300 warnx("file system reloaded");
301 }
302 exit(0);
303}
304
305void
306usage()
307{
308 fprintf(stderr, "%s\n%s\n%s\n",
309"usage: tunefs [-A] [-a maxcontig] [-d rotdelay] [-e maxbpg] [-m minfree]",
258" [-p] [-n enable | disable] [-o optimize_preference]",
310" [-p] [-n enable | disable] [-o space | time]",
259" special | filesystem");
260 exit(2);
261}
262
263void
264getsb(fs, file)
265 register struct fs *fs;
266 char *file;

--- 91 unchanged lines hidden ---
311" special | filesystem");
312 exit(2);
313}
314
315void
316getsb(fs, file)
317 register struct fs *fs;
318 char *file;

--- 91 unchanged lines hidden ---