The tunefs code assumed that the last argument was the device specification.
We need to parse the arguments first, then open the device (if specified) and then apply the changes. This change will disallow the (undocumented) use of multiple instances of the same argument on the same command line for the sack of a better error message. Other changes are: 1) the softupdates (-n) now issue a warning about remaining unchanged 2) the usage and man page is changed to specify "space | time" instead of "optimization preference". PR: bin/23335 Submitted by:Mark Peek <mark@whistle.com>
This commit is contained in:
parent
fdd5d777dc
commit
77edab906e
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=69829
@ -47,7 +47,7 @@
|
|||||||
.Op Fl m Ar minfree
|
.Op Fl m Ar minfree
|
||||||
.Bk -words
|
.Bk -words
|
||||||
.Op Fl n Ar enable | disable
|
.Op Fl n Ar enable | disable
|
||||||
.Op Fl o Ar optimize_preference
|
.Op Fl o Ar space | time
|
||||||
.Op Fl p
|
.Op Fl p
|
||||||
.Ek
|
.Ek
|
||||||
.Ar special | Ar filesystem
|
.Ar special | Ar filesystem
|
||||||
@ -108,7 +108,7 @@ been deleted to get under the higher threshold.
|
|||||||
.It Fl n Ar enable | disable
|
.It Fl n Ar enable | disable
|
||||||
Turn on/off soft updates.
|
Turn on/off soft updates.
|
||||||
An unmounted filesystem is required.
|
An unmounted filesystem is required.
|
||||||
.It Fl o Ar optimize_preference
|
.It Fl o Ar space | time
|
||||||
The file system can either try to minimize the time spent
|
The file system can either try to minimize the time spent
|
||||||
allocating blocks, or it can attempt to minimize the space
|
allocating blocks, or it can attempt to minimize the space
|
||||||
fragmentation on the disk.
|
fragmentation on the disk.
|
||||||
|
@ -88,10 +88,13 @@ main(argc, argv)
|
|||||||
int argc;
|
int argc;
|
||||||
char *argv[];
|
char *argv[];
|
||||||
{
|
{
|
||||||
char *special, *name, *action;
|
char *special, *name;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
int i;
|
|
||||||
int Aflag = 0, active = 0;
|
int Aflag = 0, active = 0;
|
||||||
|
int aflag = 0, dflag = 0, eflag = 0, mflag = 0;
|
||||||
|
int nflag = 0, oflag = 0, pflag = 0;
|
||||||
|
int avalue = 0, dvalue = 0, evalue = 0, mvalue = 0, ovalue = 0;
|
||||||
|
char *nvalue = NULL;
|
||||||
struct fstab *fs;
|
struct fstab *fs;
|
||||||
char *chg[2], device[MAXPATHLEN];
|
char *chg[2], device[MAXPATHLEN];
|
||||||
struct ufs_args args;
|
struct ufs_args args;
|
||||||
@ -100,7 +103,80 @@ main(argc, argv)
|
|||||||
|
|
||||||
if (argc < 3)
|
if (argc < 3)
|
||||||
usage();
|
usage();
|
||||||
special = argv[argc - 1];
|
found_arg = 0; /* at least one arg is required */
|
||||||
|
while ((ch = getopt(argc, argv, "Aa:d:e:m:n:o:p")) != -1)
|
||||||
|
switch (ch) {
|
||||||
|
case 'A':
|
||||||
|
found_arg = 1;
|
||||||
|
Aflag++;
|
||||||
|
break;
|
||||||
|
case 'a':
|
||||||
|
found_arg = 1;
|
||||||
|
name = "maximum contiguous block count";
|
||||||
|
avalue = atoi(optarg);
|
||||||
|
if (avalue < 1)
|
||||||
|
errx(10, "%s must be >= 1 (was %s)", name, optarg);
|
||||||
|
aflag = 1;
|
||||||
|
break;
|
||||||
|
case 'd':
|
||||||
|
found_arg = 1;
|
||||||
|
name = "rotational delay between contiguous blocks";
|
||||||
|
dvalue = atoi(optarg);
|
||||||
|
dflag = 1;
|
||||||
|
break;
|
||||||
|
case 'e':
|
||||||
|
found_arg = 1;
|
||||||
|
name = "maximum blocks per file in a cylinder group";
|
||||||
|
evalue = atoi(optarg);
|
||||||
|
if (evalue < 1)
|
||||||
|
errx(10, "%s must be >= 1 (was %s)", name, optarg);
|
||||||
|
eflag = 1;
|
||||||
|
break;
|
||||||
|
case 'm':
|
||||||
|
found_arg = 1;
|
||||||
|
name = "minimum percentage of free space";
|
||||||
|
mvalue = atoi(optarg);
|
||||||
|
if (mvalue < 0 || mvalue > 99)
|
||||||
|
errx(10, "bad %s (%s)", name, optarg);
|
||||||
|
mflag = 1;
|
||||||
|
break;
|
||||||
|
case 'n':
|
||||||
|
found_arg = 1;
|
||||||
|
name = "soft updates";
|
||||||
|
nvalue = optarg;
|
||||||
|
if (strcmp(nvalue, "enable") && strcmp(nvalue, "disable")) {
|
||||||
|
errx(10, "bad %s (options are %s)",
|
||||||
|
name, "`enable' or `disable'");
|
||||||
|
}
|
||||||
|
nflag = 1;
|
||||||
|
break;
|
||||||
|
case 'o':
|
||||||
|
found_arg = 1;
|
||||||
|
name = "optimization preference";
|
||||||
|
chg[FS_OPTSPACE] = "space";
|
||||||
|
chg[FS_OPTTIME] = "time";
|
||||||
|
if (strcmp(optarg, chg[FS_OPTSPACE]) == 0)
|
||||||
|
ovalue = FS_OPTSPACE;
|
||||||
|
else if (strcmp(optarg, chg[FS_OPTTIME]) == 0)
|
||||||
|
ovalue = FS_OPTTIME;
|
||||||
|
else
|
||||||
|
errx(10, "bad %s (options are `space' or `time')",
|
||||||
|
name);
|
||||||
|
oflag = 1;
|
||||||
|
break;
|
||||||
|
case 'p':
|
||||||
|
pflag = 1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
usage();
|
||||||
|
}
|
||||||
|
argc -= optind;
|
||||||
|
argv += optind;
|
||||||
|
|
||||||
|
if (found_arg == 0 || argc != 1)
|
||||||
|
usage();
|
||||||
|
|
||||||
|
special = argv[0];
|
||||||
fs = getfsfile(special);
|
fs = getfsfile(special);
|
||||||
if (fs) {
|
if (fs) {
|
||||||
if (statfs(special, &stfs) == 0 &&
|
if (statfs(special, &stfs) == 0 &&
|
||||||
@ -125,119 +201,95 @@ main(argc, argv)
|
|||||||
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);
|
||||||
|
|
||||||
found_arg = 0; /* at least one arg is required */
|
if (pflag) {
|
||||||
while ((ch = getopt(argc, argv, "Aa:d:e:m:n:o:p")) != -1)
|
printfs();
|
||||||
switch (ch) {
|
exit(0);
|
||||||
case 'A':
|
}
|
||||||
found_arg = 1;
|
if (aflag) {
|
||||||
Aflag++;
|
|
||||||
break;
|
|
||||||
case 'a':
|
|
||||||
found_arg = 1;
|
|
||||||
name = "maximum contiguous block count";
|
name = "maximum contiguous block count";
|
||||||
i = atoi(optarg);
|
if (sblock.fs_maxcontig == avalue) {
|
||||||
if (i < 1)
|
warnx("%s remains unchanged as %d", name, avalue);
|
||||||
errx(10, "%s must be >= 1 (was %s)", name, optarg);
|
|
||||||
if (sblock.fs_maxcontig == i) {
|
|
||||||
warnx("%s remains unchanged as %d", name, i);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
warnx("%s changes from %d to %d", name, sblock.fs_maxcontig, i);
|
else {
|
||||||
sblock.fs_maxcontig = i;
|
warnx("%s changes from %d to %d",
|
||||||
break;
|
name, sblock.fs_maxcontig, avalue);
|
||||||
case 'd':
|
sblock.fs_maxcontig = avalue;
|
||||||
found_arg = 1;
|
}
|
||||||
|
}
|
||||||
|
if (dflag) {
|
||||||
name = "rotational delay between contiguous blocks";
|
name = "rotational delay between contiguous blocks";
|
||||||
i = atoi(optarg);
|
if (sblock.fs_rotdelay == dvalue) {
|
||||||
if (sblock.fs_rotdelay == i) {
|
warnx("%s remains unchanged as %dms", name, dvalue);
|
||||||
warnx("%s remains unchanged as %dms", name, i);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
warnx("%s changes from %dms to %dms",
|
else {
|
||||||
name, sblock.fs_rotdelay, i);
|
warnx("%s changes from %dms to %dms",
|
||||||
sblock.fs_rotdelay = i;
|
name, sblock.fs_rotdelay, dvalue);
|
||||||
break;
|
sblock.fs_rotdelay = dvalue;
|
||||||
case 'e':
|
}
|
||||||
found_arg = 1;
|
}
|
||||||
|
if (eflag) {
|
||||||
name = "maximum blocks per file in a cylinder group";
|
name = "maximum blocks per file in a cylinder group";
|
||||||
i = atoi(optarg);
|
if (sblock.fs_maxbpg == evalue) {
|
||||||
if (i < 1)
|
warnx("%s remains unchanged as %d", name, evalue);
|
||||||
errx(10, "%s must be >= 1 (was %s)", name, optarg);
|
|
||||||
if (sblock.fs_maxbpg == i) {
|
|
||||||
warnx("%s remains unchanged as %d", name, i);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
warnx("%s changes from %d to %d", name, sblock.fs_maxbpg, i);
|
else {
|
||||||
sblock.fs_maxbpg = i;
|
warnx("%s changes from %d to %d",
|
||||||
break;
|
name, sblock.fs_maxbpg, evalue);
|
||||||
case 'm':
|
sblock.fs_maxbpg = evalue;
|
||||||
found_arg = 1;
|
}
|
||||||
|
}
|
||||||
|
if (mflag) {
|
||||||
name = "minimum percentage of free space";
|
name = "minimum percentage of free space";
|
||||||
i = atoi(optarg);
|
if (sblock.fs_minfree == mvalue) {
|
||||||
if (i < 0 || i > 99)
|
warnx("%s remains unchanged as %d%%", name, mvalue);
|
||||||
errx(10, "bad %s (%s)", name, optarg);
|
|
||||||
if (sblock.fs_minfree == i) {
|
|
||||||
warnx("%s remains unchanged as %d%%", name, i);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
warnx("%s changes from %d%% to %d%%",
|
else {
|
||||||
name, sblock.fs_minfree, i);
|
warnx("%s changes from %d%% to %d%%",
|
||||||
sblock.fs_minfree = i;
|
name, sblock.fs_minfree, mvalue);
|
||||||
if (i >= MINFREE && sblock.fs_optim == FS_OPTSPACE)
|
sblock.fs_minfree = mvalue;
|
||||||
warnx(OPTWARN, "time", ">=", MINFREE);
|
if (mvalue >= MINFREE && sblock.fs_optim == FS_OPTSPACE)
|
||||||
if (i < MINFREE && sblock.fs_optim == FS_OPTTIME)
|
warnx(OPTWARN, "time", ">=", MINFREE);
|
||||||
warnx(OPTWARN, "space", "<", MINFREE);
|
if (mvalue < MINFREE && sblock.fs_optim == FS_OPTTIME)
|
||||||
break;
|
warnx(OPTWARN, "space", "<", MINFREE);
|
||||||
case 'n':
|
}
|
||||||
found_arg = 1;
|
}
|
||||||
|
if (nflag) {
|
||||||
name = "soft updates";
|
name = "soft updates";
|
||||||
if (strcmp(optarg, "enable") == 0) {
|
if (strcmp(nvalue, "enable") == 0) {
|
||||||
sblock.fs_flags |= FS_DOSOFTDEP;
|
if ( sblock.fs_flags & FS_DOSOFTDEP ) {
|
||||||
action = "set";
|
warnx("%s remains unchanged as enabled", name);
|
||||||
} else if (strcmp(optarg, "disable") == 0) {
|
} else {
|
||||||
sblock.fs_flags &= ~FS_DOSOFTDEP;
|
sblock.fs_flags |= FS_DOSOFTDEP;
|
||||||
action = "cleared";
|
warnx("%s set", name);
|
||||||
} else {
|
}
|
||||||
errx(10, "bad %s (options are %s)",
|
} else if (strcmp(nvalue, "disable") == 0) {
|
||||||
name, "`enable' or `disable'");
|
if ((~sblock.fs_flags & FS_DOSOFTDEP) == FS_DOSOFTDEP) {
|
||||||
|
warnx("%s remains unchanged as disabled", name);
|
||||||
|
} else {
|
||||||
|
sblock.fs_flags &= ~FS_DOSOFTDEP;
|
||||||
|
warnx("%s cleared", name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
warnx("%s %s", name, action);
|
}
|
||||||
break;
|
if (oflag) {
|
||||||
case 'o':
|
|
||||||
found_arg = 1;
|
|
||||||
name = "optimization preference";
|
name = "optimization preference";
|
||||||
chg[FS_OPTSPACE] = "space";
|
chg[FS_OPTSPACE] = "space";
|
||||||
chg[FS_OPTTIME] = "time";
|
chg[FS_OPTTIME] = "time";
|
||||||
if (strcmp(optarg, chg[FS_OPTSPACE]) == 0)
|
if (sblock.fs_optim == ovalue) {
|
||||||
i = FS_OPTSPACE;
|
warnx("%s remains unchanged as %s", name, chg[ovalue]);
|
||||||
else if (strcmp(optarg, chg[FS_OPTTIME]) == 0)
|
|
||||||
i = FS_OPTTIME;
|
|
||||||
else
|
|
||||||
errx(10, "bad %s (options are `space' or `time')",
|
|
||||||
name);
|
|
||||||
if (sblock.fs_optim == i) {
|
|
||||||
warnx("%s remains unchanged as %s", name, chg[i]);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
warnx("%s changes from %s to %s",
|
else {
|
||||||
name, chg[sblock.fs_optim], chg[i]);
|
warnx("%s changes from %s to %s",
|
||||||
sblock.fs_optim = i;
|
name, chg[sblock.fs_optim], chg[ovalue]);
|
||||||
if (sblock.fs_minfree >= MINFREE && i == FS_OPTSPACE)
|
sblock.fs_optim = ovalue;
|
||||||
warnx(OPTWARN, "time", ">=", MINFREE);
|
if (sblock.fs_minfree >= MINFREE &&
|
||||||
if (sblock.fs_minfree < MINFREE && i == FS_OPTTIME)
|
ovalue == FS_OPTSPACE)
|
||||||
warnx(OPTWARN, "space", "<", MINFREE);
|
warnx(OPTWARN, "time", ">=", MINFREE);
|
||||||
break;
|
if (sblock.fs_minfree < MINFREE &&
|
||||||
case 'p':
|
ovalue == FS_OPTTIME)
|
||||||
printfs();
|
warnx(OPTWARN, "space", "<", MINFREE);
|
||||||
exit(0);
|
}
|
||||||
default:
|
}
|
||||||
usage();
|
|
||||||
}
|
|
||||||
argc -= optind;
|
|
||||||
argv += optind;
|
|
||||||
|
|
||||||
if (found_arg == 0 || argc != 1)
|
|
||||||
usage();
|
|
||||||
|
|
||||||
putsb(&sblock, special, Aflag);
|
putsb(&sblock, special, Aflag);
|
||||||
if (active) {
|
if (active) {
|
||||||
@ -255,7 +307,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 space | time]",
|
||||||
" special | filesystem");
|
" special | filesystem");
|
||||||
exit(2);
|
exit(2);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user