summaryrefslogtreecommitdiff
path: root/sbin/tunefs
diff options
context:
space:
mode:
Diffstat (limited to 'sbin/tunefs')
-rw-r--r--sbin/tunefs/tunefs.c30
1 files changed, 21 insertions, 9 deletions
diff --git a/sbin/tunefs/tunefs.c b/sbin/tunefs/tunefs.c
index 952dc6e0b01..f73aed3f6a2 100644
--- a/sbin/tunefs/tunefs.c
+++ b/sbin/tunefs/tunefs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tunefs.c,v 1.15 2001/11/05 07:39:17 mpech Exp $ */
+/* $OpenBSD: tunefs.c,v 1.16 2001/12/04 07:23:58 mickey Exp $ */
/* $NetBSD: tunefs.c,v 1.10 1995/03/18 15:01:31 cgd Exp $ */
/*
@@ -44,7 +44,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)tunefs.c 8.2 (Berkeley) 4/19/94";
#else
-static char rcsid[] = "$OpenBSD: tunefs.c,v 1.15 2001/11/05 07:39:17 mpech Exp $";
+static char rcsid[] = "$OpenBSD: tunefs.c,v 1.16 2001/12/04 07:23:58 mickey Exp $";
#endif
#endif /* not lint */
@@ -74,12 +74,12 @@ union {
} sbun;
#define sblock sbun.sb
-int fi;
+int fi = -1;
long dev_bsize = 1;
void bwrite(daddr_t, char *, int);
int bread(daddr_t, char *, int);
-void getsb(struct fs *, char *);
+void getsb(struct fs *, char *, int);
void usage __P((void));
void printfs __P((void));
@@ -118,7 +118,6 @@ again:
}
if (!S_ISBLK(st.st_mode) && !S_ISCHR(st.st_mode))
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++)
switch (*cp) {
@@ -128,10 +127,12 @@ again:
continue;
case 'p':
+ getsb(&sblock, special, O_RDONLY);
printfs();
return (0);
case 'a':
+ getsb(&sblock, special, O_RDWR);
name = "maximum contiguous block count";
if (argc < 1)
errx(10, "-a: missing %s", name);
@@ -146,6 +147,7 @@ again:
continue;
case 'd':
+ getsb(&sblock, special, O_RDWR);
name =
"rotational delay between contiguous blocks";
if (argc < 1)
@@ -158,6 +160,7 @@ again:
continue;
case 'e':
+ getsb(&sblock, special, O_RDWR);
name =
"maximum blocks per file in a cylinder group";
if (argc < 1)
@@ -173,6 +176,7 @@ again:
continue;
case 'f':
+ getsb(&sblock, special, O_RDWR);
name = "average file size";
if (argc < 1)
errx(10, "-f: missing %s", name);
@@ -187,6 +191,7 @@ again:
continue;
case 'm':
+ getsb(&sblock, special, O_RDWR);
name = "minimum percentage of free space";
if (argc < 1)
errx(10, "-m: missing %s", name);
@@ -206,6 +211,7 @@ again:
continue;
case 'n':
+ getsb(&sblock, special, O_RDWR);
name = "expected number of files per directory";
if (argc < 1)
errx(10, "-n: missing %s", name);
@@ -224,6 +230,7 @@ again:
" how to enable soft updates.");
case 'o':
+ getsb(&sblock, special, O_RDWR);
name = "optimization preference";
if (argc < 1)
errx(10, "-o: missing %s", name);
@@ -264,7 +271,9 @@ again:
for (i = 0; i < sblock.fs_ncg; i++)
bwrite(fsbtodb(&sblock, cgsblock(&sblock, i)),
(char *)&sblock, SBSIZE);
- close(fi);
+ if (close(fi))
+ err(1, "close: %s", special);
+
return (0);
}
@@ -288,18 +297,21 @@ usage()
}
void
-getsb(fs, file)
+getsb(fs, file, flags)
struct fs *fs;
char *file;
+ int flags;
{
- fi = open(file, 2);
+ if (fi >= 0)
+ return;
+ fi = open(file, flags);
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);
+ errx(5, "%s: bad magic number", file);
dev_bsize = fs->fs_fsize / fsbtodb(fs, 1);
}