#endif /* not lint */
#ifndef lint
-static char sccsid[] = "@(#)tunefs.c 8.1 (Berkeley) 6/5/93";
+static char sccsid[] = "@(#)tunefs.c 8.2 (Berkeley) 4/19/94";
#endif /* not lint */
/*
#include <ufs/ffs/fs.h>
-#include <unistd.h>
#include <errno.h>
+#include <err.h>
+#include <fcntl.h>
#include <fstab.h>
#include <stdio.h>
#include <paths.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+/* the optimization warning string template */
+#define OPTWARN "should optimize for %s with minfree %s %d%%"
union {
struct fs sb;
int fi;
long dev_bsize = 1;
+void bwrite(daddr_t, char *, int);
+int bread(daddr_t, char *, int);
+void getsb(struct fs *, char *);
+void usage __P((void));
+
+int
main(argc, argv)
int argc;
char *argv[];
argc--, argv++;
if (argc < 2)
- goto usage;
+ usage();
special = argv[argc - 1];
fs = getfsfile(special);
if (fs)
special = device;
goto again;
}
- fprintf(stderr, "tunefs: "); perror(special);
- exit(1);
+ err(1, "%s", special);
}
if ((st.st_mode & S_IFMT) != S_IFBLK &&
(st.st_mode & S_IFMT) != S_IFCHR)
- fatal("%s: not a block or character device", special);
+ errx(10, "%s: not a block or character device", special);
getsb(&sblock, special);
for (; argc > 0 && argv[0][0] == '-'; argc--, argv++) {
for (cp = &argv[0][1]; *cp; cp++)
case 'a':
name = "maximum contiguous block count";
if (argc < 1)
- fatal("-a: missing %s", name);
+ errx(10, "-a: missing %s", name);
argc--, argv++;
i = atoi(*argv);
if (i < 1)
- fatal("%s: %s must be >= 1",
- *argv, name);
- fprintf(stdout, "%s changes from %d to %d\n",
- name, sblock.fs_maxcontig, i);
+ errx(10, "%s must be >= 1 (was %s)",
+ name, *argv);
+ warnx("%s changes from %d to %d",
+ name, sblock.fs_maxcontig, i);
sblock.fs_maxcontig = i;
continue;
name =
"rotational delay between contiguous blocks";
if (argc < 1)
- fatal("-d: missing %s", name);
+ errx(10, "-d: missing %s", name);
argc--, argv++;
i = atoi(*argv);
- fprintf(stdout,
- "%s changes from %dms to %dms\n",
- name, sblock.fs_rotdelay, i);
+ warnx("%s changes from %dms to %dms",
+ name, sblock.fs_rotdelay, i);
sblock.fs_rotdelay = i;
continue;
name =
"maximum blocks per file in a cylinder group";
if (argc < 1)
- fatal("-e: missing %s", name);
+ errx(10, "-e: missing %s", name);
argc--, argv++;
i = atoi(*argv);
if (i < 1)
- fatal("%s: %s must be >= 1",
- *argv, name);
- fprintf(stdout, "%s changes from %d to %d\n",
- name, sblock.fs_maxbpg, i);
+ errx(10, "%s must be >= 1 (was %s)",
+ name, *argv);
+ warnx("%s changes from %d to %d",
+ name, sblock.fs_maxbpg, i);
sblock.fs_maxbpg = i;
continue;
case 'm':
name = "minimum percentage of free space";
if (argc < 1)
- fatal("-m: missing %s", name);
+ errx(10, "-m: missing %s", name);
argc--, argv++;
i = atoi(*argv);
if (i < 0 || i > 99)
- fatal("%s: bad %s", *argv, name);
- fprintf(stdout,
- "%s changes from %d%% to %d%%\n",
- name, sblock.fs_minfree, i);
+ errx(10, "bad %s (%s)", name, *argv);
+ warnx("%s changes from %d%% to %d%%",
+ name, sblock.fs_minfree, i);
sblock.fs_minfree = i;
- if (i >= 10 && sblock.fs_optim == FS_OPTSPACE)
- fprintf(stdout, "should optimize %s",
- "for time with minfree >= 10%\n");
- if (i < 10 && sblock.fs_optim == FS_OPTTIME)
- fprintf(stdout, "should optimize %s",
- "for space with minfree < 10%\n");
+ if (i >= MINFREE &&
+ sblock.fs_optim == FS_OPTSPACE)
+ warnx(OPTWARN, "time", ">=", MINFREE);
+ if (i < MINFREE &&
+ sblock.fs_optim == FS_OPTTIME)
+ warnx(OPTWARN, "space", "<", MINFREE);
continue;
case 'o':
name = "optimization preference";
if (argc < 1)
- fatal("-o: missing %s", name);
+ errx(10, "-o: missing %s", name);
argc--, argv++;
chg[FS_OPTSPACE] = "space";
chg[FS_OPTTIME] = "time";
else if (strcmp(*argv, chg[FS_OPTTIME]) == 0)
i = FS_OPTTIME;
else
- fatal("%s: bad %s (options are `space' or `time')",
- *argv, name);
+ errx(10, "bad %s (options are `space' or `time')",
+ name);
if (sblock.fs_optim == i) {
- fprintf(stdout,
- "%s remains unchanged as %s\n",
- name, chg[i]);
+ warnx("%s remains unchanged as %s",
+ name, chg[i]);
continue;
}
- fprintf(stdout,
- "%s changes from %s to %s\n",
- name, chg[sblock.fs_optim], chg[i]);
+ warnx("%s changes from %s to %s",
+ name, chg[sblock.fs_optim], chg[i]);
sblock.fs_optim = i;
- if (sblock.fs_minfree >= 10 && i == FS_OPTSPACE)
- fprintf(stdout, "should optimize %s",
- "for time with minfree >= 10%\n");
- if (sblock.fs_minfree < 10 && i == FS_OPTTIME)
- fprintf(stdout, "should optimize %s",
- "for space with minfree < 10%\n");
+ if (sblock.fs_minfree >= MINFREE &&
+ i == FS_OPTSPACE)
+ warnx(OPTWARN, "time", ">=", MINFREE);
+ if (sblock.fs_minfree < MINFREE &&
+ i == FS_OPTTIME)
+ warnx(OPTWARN, "space", "<", MINFREE);
continue;
default:
- fatal("-%c: unknown flag", *cp);
+ usage();
}
}
if (argc != 1)
- goto usage;
+ usage();
bwrite((daddr_t)SBOFF / dev_bsize, (char *)&sblock, SBSIZE);
if (Aflag)
for (i = 0; i < sblock.fs_ncg; i++)
(char *)&sblock, SBSIZE);
close(fi);
exit(0);
-usage:
+}
+
+void
+usage()
+{
+
fprintf(stderr, "Usage: tunefs tuneup-options special-device\n");
fprintf(stderr, "where tuneup-options are:\n");
fprintf(stderr, "\t-a maximum contiguous blocks\n");
exit(2);
}
+void
getsb(fs, file)
register struct fs *fs;
char *file;
{
fi = open(file, 2);
- if (fi < 0) {
- fprintf(stderr, "tunefs: %s: %s\n", file, strerror(errno));
- exit(3);
- }
- if (bread((daddr_t)SBOFF, (char *)fs, SBSIZE)) {
- fprintf(stderr, "tunefs: %s: bad super block\n", file);
- exit(4);
- }
- if (fs->fs_magic != FS_MAGIC) {
- fprintf(stderr, "tunefs: %s: bad magic number\n", file);
- exit(5);
- }
+ if (fi < 0)
+ err(3, "cannot open %s", file);
+ if (bread((daddr_t)SBOFF, (char *)fs, SBSIZE))
+ err(4, "%s: bad super block", file);
+ if (fs->fs_magic != FS_MAGIC)
+ err(5, "%s: bad magic number", file);
dev_bsize = fs->fs_fsize / fsbtodb(fs, 1);
}
+void
bwrite(blk, buf, size)
- char *buf;
daddr_t blk;
- register size;
+ char *buf;
+ int size;
{
- if (lseek(fi, (off_t)blk * dev_bsize, SEEK_SET) < 0) {
- perror("FS SEEK");
- exit(6);
- }
- if (write(fi, buf, size) != size) {
- perror("FS WRITE");
- exit(7);
- }
+
+ if (lseek(fi, (off_t)blk * dev_bsize, SEEK_SET) < 0)
+ err(6, "FS SEEK");
+ if (write(fi, buf, size) != size)
+ err(7, "FS WRITE");
}
+int
bread(bno, buf, cnt)
daddr_t bno;
char *buf;
+ int cnt;
{
- register i;
+ int i;
if (lseek(fi, (off_t)bno * dev_bsize, SEEK_SET) < 0)
return(1);
}
return (0);
}
-
-/* VARARGS1 */
-fatal(fmt, arg1, arg2)
- char *fmt, *arg1, *arg2;
-{
-
- fprintf(stderr, "tunefs: ");
- fprintf(stderr, fmt, arg1, arg2);
- putc('\n', stderr);
- exit(10);
-}