Remove .Op when arg is required (special | filesystem). Document that at

least one flag is required and check this in the code. Make use of getopt(3).
Generalyze printing `... remains unchanged ...'.
This commit is contained in:
Philippe Charnier 2000-11-28 18:17:15 +00:00
parent 57757e9f36
commit 2af14b60ed
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=69314
2 changed files with 117 additions and 126 deletions

View File

@ -50,7 +50,7 @@
.Op Fl o Ar optimize_preference .Op Fl o Ar optimize_preference
.Op Fl p .Op Fl p
.Ek .Ek
.Op Ar special | Ar filesystem .Ar special | Ar filesystem
.Sh DESCRIPTION .Sh DESCRIPTION
.Nm Tunefs .Nm Tunefs
is designed to change the dynamic parameters of a file system is designed to change the dynamic parameters of a file system
@ -123,6 +123,8 @@ obtained in the
.Xr dumpfs 8 .Xr dumpfs 8
manual page. manual page.
.El .El
.Pp
At least one of the above flags is required.
.Sh ERRORS .Sh ERRORS
If If
.Nm .Nm

View File

@ -88,7 +88,7 @@ main(argc, argv)
int argc; int argc;
char *argv[]; char *argv[];
{ {
char *cp, *special, *name, *action; char *special, *name, *action;
struct stat st; struct stat st;
int i; int i;
int Aflag = 0, active = 0; int Aflag = 0, active = 0;
@ -96,10 +96,10 @@ main(argc, argv)
char *chg[2], device[MAXPATHLEN]; char *chg[2], device[MAXPATHLEN];
struct ufs_args args; struct ufs_args args;
struct statfs stfs; struct statfs stfs;
int found_arg, ch;
argc--, argv++; if (argc < 3)
if (argc < 2) usage();
usage();
special = argv[argc - 1]; special = argv[argc - 1];
fs = getfsfile(special); fs = getfsfile(special);
if (fs) { if (fs) {
@ -124,132 +124,121 @@ main(argc, argv)
(st.st_mode & S_IFMT) != S_IFCHR) (st.st_mode & S_IFMT) != S_IFCHR)
errx(10, "%s: not a block or character device", special); errx(10, "%s: not a block or character device", special);
getsb(&sblock, special); getsb(&sblock, special);
for (; argc > 0 && argv[0][0] == '-'; argc--, argv++) {
for (cp = &argv[0][1]; *cp; cp++)
switch (*cp) {
case 'A': found_arg = 0; /* at least one arg is required */
Aflag++; while ((ch = getopt(argc, argv, "Aa:d:e:m:n:o:p")) != -1)
continue; switch (ch) {
case 'A':
case 'p': found_arg = 1;
printfs(); Aflag++;
exit(0); break;
case 'a':
case 'a': found_arg = 1;
name = "maximum contiguous block count"; name = "maximum contiguous block count";
if (argc < 1) i = atoi(optarg);
errx(10, "-a: missing %s", name); if (i < 1)
argc--, argv++; errx(10, "%s must be >= 1 (was %s)", name, optarg);
i = atoi(*argv); if (sblock.fs_maxcontig == i) {
if (i < 1) warnx("%s remains unchanged as %d", name, i);
errx(10, "%s must be >= 1 (was %s)", break;
name, *argv); }
warnx("%s changes from %d to %d", warnx("%s changes from %d to %d", name, sblock.fs_maxcontig, i);
name, sblock.fs_maxcontig, i); sblock.fs_maxcontig = i;
sblock.fs_maxcontig = i; break;
continue; case 'd':
found_arg = 1;
case 'd': name = "rotational delay between contiguous blocks";
name = i = atoi(optarg);
"rotational delay between contiguous blocks"; if (sblock.fs_rotdelay == i) {
if (argc < 1) warnx("%s remains unchanged as %dms", name, i);
errx(10, "-d: missing %s", name); break;
argc--, argv++; }
i = atoi(*argv); warnx("%s changes from %dms to %dms",
warnx("%s changes from %dms to %dms",
name, sblock.fs_rotdelay, i); name, sblock.fs_rotdelay, i);
sblock.fs_rotdelay = i; sblock.fs_rotdelay = i;
continue; break;
case 'e':
case 'e': found_arg = 1;
name = name = "maximum blocks per file in a cylinder group";
"maximum blocks per file in a cylinder group"; i = atoi(optarg);
if (argc < 1) if (i < 1)
errx(10, "-e: missing %s", name); errx(10, "%s must be >= 1 (was %s)", name, optarg);
argc--, argv++; if (sblock.fs_maxbpg == i) {
i = atoi(*argv); warnx("%s remains unchanged as %d", name, i);
if (i < 1) break;
errx(10, "%s must be >= 1 (was %s)", }
name, *argv); warnx("%s changes from %d to %d", name, sblock.fs_maxbpg, i);
warnx("%s changes from %d to %d", sblock.fs_maxbpg = i;
name, sblock.fs_maxbpg, i); break;
sblock.fs_maxbpg = i; case 'm':
continue; found_arg = 1;
name = "minimum percentage of free space";
case 'm': i = atoi(optarg);
name = "minimum percentage of free space"; if (i < 0 || i > 99)
if (argc < 1) errx(10, "bad %s (%s)", name, optarg);
errx(10, "-m: missing %s", name); if (sblock.fs_minfree == i) {
argc--, argv++; warnx("%s remains unchanged as %d%%", name, i);
i = atoi(*argv); break;
if (i < 0 || i > 99) }
errx(10, "bad %s (%s)", name, *argv); warnx("%s changes from %d%% to %d%%",
warnx("%s changes from %d%% to %d%%",
name, sblock.fs_minfree, i); name, sblock.fs_minfree, i);
sblock.fs_minfree = i; sblock.fs_minfree = i;
if (i >= MINFREE && if (i >= MINFREE && sblock.fs_optim == FS_OPTSPACE)
sblock.fs_optim == FS_OPTSPACE) warnx(OPTWARN, "time", ">=", MINFREE);
warnx(OPTWARN, "time", ">=", MINFREE); if (i < MINFREE && sblock.fs_optim == FS_OPTTIME)
if (i < MINFREE && warnx(OPTWARN, "space", "<", MINFREE);
sblock.fs_optim == FS_OPTTIME) break;
warnx(OPTWARN, "space", "<", MINFREE); case 'n':
continue; found_arg = 1;
name = "soft updates";
case 'n': if (strcmp(optarg, "enable") == 0) {
name = "soft updates"; sblock.fs_flags |= FS_DOSOFTDEP;
if (argc < 1) action = "set";
errx(10, "-n: missing %s", name); } else if (strcmp(optarg, "disable") == 0) {
argc--, argv++; sblock.fs_flags &= ~FS_DOSOFTDEP;
if (strcmp(*argv, "enable") == 0) { action = "cleared";
sblock.fs_flags |= FS_DOSOFTDEP; } else {
action = "set"; errx(10, "bad %s (options are %s)",
} else if (strcmp(*argv, "disable") == 0) { name, "`enable' or `disable'");
sblock.fs_flags &= ~FS_DOSOFTDEP; }
action = "cleared"; warnx("%s %s", name, action);
} else { break;
errx(10, "bad %s (options are %s)", case 'o':
name, "`enable' or `disable'"); found_arg = 1;
} name = "optimization preference";
warnx("%s %s", name, action); chg[FS_OPTSPACE] = "space";
continue; chg[FS_OPTTIME] = "time";
if (strcmp(optarg, chg[FS_OPTSPACE]) == 0)
case 'o': i = FS_OPTSPACE;
name = "optimization preference"; else if (strcmp(optarg, chg[FS_OPTTIME]) == 0)
if (argc < 1) i = FS_OPTTIME;
errx(10, "-o: missing %s", name); else
argc--, argv++; errx(10, "bad %s (options are `space' or `time')",
chg[FS_OPTSPACE] = "space";
chg[FS_OPTTIME] = "time";
if (strcmp(*argv, chg[FS_OPTSPACE]) == 0)
i = FS_OPTSPACE;
else if (strcmp(*argv, chg[FS_OPTTIME]) == 0)
i = FS_OPTTIME;
else
errx(10, "bad %s (options are `space' or `time')",
name); name);
if (sblock.fs_optim == i) { if (sblock.fs_optim == i) {
warnx("%s remains unchanged as %s", warnx("%s remains unchanged as %s", name, chg[i]);
name, chg[i]); break;
continue; }
} warnx("%s changes from %s to %s",
warnx("%s changes from %s to %s",
name, chg[sblock.fs_optim], chg[i]); name, chg[sblock.fs_optim], chg[i]);
sblock.fs_optim = i; sblock.fs_optim = i;
if (sblock.fs_minfree >= MINFREE && if (sblock.fs_minfree >= MINFREE && i == FS_OPTSPACE)
i == FS_OPTSPACE) warnx(OPTWARN, "time", ">=", MINFREE);
warnx(OPTWARN, "time", ">=", MINFREE); if (sblock.fs_minfree < MINFREE && i == FS_OPTTIME)
if (sblock.fs_minfree < MINFREE && warnx(OPTWARN, "space", "<", MINFREE);
i == FS_OPTTIME) break;
warnx(OPTWARN, "space", "<", MINFREE); case 'p':
continue; printfs();
exit(0);
default: default:
usage();
}
}
if (argc != 1)
usage(); usage();
}
argc -= optind;
argv += optind;
if (found_arg == 0 || argc != 1)
usage();
putsb(&sblock, special, Aflag); putsb(&sblock, special, Aflag);
if (active) { if (active) {
bzero(&args, sizeof(args)); bzero(&args, sizeof(args));
@ -267,7 +256,7 @@ usage()
fprintf(stderr, "%s\n%s\n%s\n", fprintf(stderr, "%s\n%s\n%s\n",
"usage: tunefs [-A] [-a maxcontig] [-d rotdelay] [-e maxbpg] [-m minfree]", "usage: tunefs [-A] [-a maxcontig] [-d rotdelay] [-e maxbpg] [-m minfree]",
" [-p] [-n enable | disable] [-o optimize_preference]", " [-p] [-n enable | disable] [-o optimize_preference]",
" [special | filesystem]"); " special | filesystem");
exit(2); exit(2);
} }