aboutsummaryrefslogtreecommitdiff
path: root/sbin/tunefs/tunefs.c
diff options
context:
space:
mode:
authorSheldon Hearn <sheldonh@FreeBSD.org>2000-03-14 07:44:32 +0000
committerSheldon Hearn <sheldonh@FreeBSD.org>2000-03-14 07:44:32 +0000
commit060ac658ccca26020473d73f26668c673a8b4b89 (patch)
treebf23c0ac8cc54208e6b0b842dc01ef9c5a91da61 /sbin/tunefs/tunefs.c
parent2a30e2ac0b09cb67cd405a077241278929a8ca65 (diff)
downloadsrc-060ac658ccca26020473d73f26668c673a8b4b89.tar.gz
src-060ac658ccca26020473d73f26668c673a8b4b89.zip
Open the device read-only initially and re-open read-write if necessary
later. This allows tunefs -p on mounted filesystems. Side-effects: Use K&R prototypes. Use definitions from fcntl.h for the flags argument to open(2). There are cosmetic differences between this and the submitted patch. PR: 17143 Reported by: Peter Edwards <peter.edwards@ireland.com> Submitted by: luoqi
Notes
Notes: svn path=/head/; revision=58047
Diffstat (limited to 'sbin/tunefs/tunefs.c')
-rw-r--r--sbin/tunefs/tunefs.c46
1 files changed, 33 insertions, 13 deletions
diff --git a/sbin/tunefs/tunefs.c b/sbin/tunefs/tunefs.c
index 1cdaae8bf643..42aa1c1d4cd0 100644
--- a/sbin/tunefs/tunefs.c
+++ b/sbin/tunefs/tunefs.c
@@ -61,6 +61,7 @@ static const char rcsid[] =
#include <paths.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <unistd.h>
/* the optimization warning string template */
@@ -75,9 +76,10 @@ union {
int fi;
long dev_bsize = 1;
-void bwrite(daddr_t, char *, int);
-int bread(daddr_t, char *, int);
-void getsb(struct fs *, char *);
+void bwrite __P((daddr_t, char *, int));
+int bread __P((daddr_t, char *, int));
+void getsb __P((struct fs *, char *));
+void putsb __P((struct fs *, char *, int));
void usage __P((void));
void printfs __P((void));
@@ -103,9 +105,6 @@ main(argc, argv)
if (fs) {
if (statfs(special, &stfs) == 0 &&
strcmp(special, stfs.f_mntonname) == 0) {
- if ((stfs.f_flags & MNT_RDONLY) == 0) {
- errx(1, "cannot work on read-write mounted file system");
- }
active = 1;
}
special = fs->fs_spec;
@@ -251,12 +250,7 @@ again:
}
if (argc != 1)
usage();
- bwrite((daddr_t)SBOFF / dev_bsize, (char *)&sblock, SBSIZE);
- if (Aflag)
- for (i = 0; i < sblock.fs_ncg; i++)
- bwrite(fsbtodb(&sblock, cgsblock(&sblock, i)),
- (char *)&sblock, SBSIZE);
- close(fi);
+ putsb(&sblock, special, Aflag);
if (active) {
bzero(&args, sizeof(args));
if (mount("ufs", fs->fs_file,
@@ -283,7 +277,7 @@ getsb(fs, file)
char *file;
{
- fi = open(file, 2);
+ fi = open(file, O_RDONLY);
if (fi < 0)
err(3, "cannot open %s", file);
if (bread((daddr_t)SBOFF, (char *)fs, SBSIZE))
@@ -294,6 +288,32 @@ getsb(fs, file)
}
void
+putsb(fs, file, all)
+ register struct fs *fs;
+ char *file;
+ int all;
+{
+ int i;
+
+ /*
+ * Re-open the device read-write. Use the read-only file
+ * descriptor as an interlock to prevent the device from
+ * being mounted while we are switching mode.
+ */
+ i = fi;
+ fi = open(file, O_RDWR);
+ close(i);
+ if (fi < 0)
+ err(3, "cannot open %s", file);
+ bwrite((daddr_t)SBOFF / dev_bsize, (char *)fs, SBSIZE);
+ if (all)
+ for (i = 0; i < fs->fs_ncg; i++)
+ bwrite(fsbtodb(fs, cgsblock(fs, i)),
+ (char *)fs, SBSIZE);
+ close(fi);
+}
+
+void
printfs()
{
warnx("soft updates: (-n) %s",