Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 3 Mar 2000 13:07:39 -0500 (EST)
From:      Luoqi Chen <luoqi@watermarkgroup.com>
To:        current@FreeBSD.ORG, sheldonh@uunet.co.za
Subject:   Re:  tunefs -p doesn't work for read-write mounts
Message-ID:  <200003031807.NAA21331@lor.watermarkgroup.com>

next in thread | raw e-mail | index | archive | help
> Hi folks,
> 
> Shouldn't I be able to show the current tuneables for a given filesystem?
> 
> # tunefs -p /usr
> tunefs: cannot work on read-write mounted file system
> 
> This is on a recent CURRENT.
> 
> Ciao,
> Sheldon.
> 
You were supposed to use a raw device for a mounted fs, but that no longer
works after the elimination of block device. I have a quick fix for this
problem: open the device read-only to read the superblock and later re-open
it read-write before writing back.

-lq

Index: tunefs.c
===================================================================
RCS file: /home/ncvs/src/sbin/tunefs/tunefs.c,v
retrieving revision 1.11
diff -u -r1.11 tunefs.c
--- tunefs.c	2000/01/30 05:24:55	1.11
+++ tunefs.c	2000/03/03 16:04:04
@@ -75,9 +75,10 @@
 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 +104,6 @@
 	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 +249,7 @@
 	}
 	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 +276,7 @@
 	char *file;
 {
 
-	fi = open(file, 2);
+	fi = open(file, 0);
 	if (fi < 0)
 		err(3, "cannot open %s", file);
 	if (bread((daddr_t)SBOFF, (char *)fs, SBSIZE))
@@ -291,6 +284,30 @@
 	if (fs->fs_magic != FS_MAGIC)
 		err(5, "%s: bad magic number", file);
 	dev_bsize = fs->fs_fsize / fsbtodb(fs, 1);
+}
+
+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, 2); 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


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200003031807.NAA21331>