Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 17 Jan 2003 21:10:40 -0800
From:      Juli Mallett <jmallett@FreeBSD.org>
To:        current@FreeBSD.org
Subject:   tunefs using libufs.
Message-ID:  <20030117211040.B20672@FreeBSD.org>

next in thread | raw e-mail | index | archive | help
Can I get some tests of these changes to make tunefs use libufs?

Thanx,
juli.

%%%
Index: Makefile
===================================================================
RCS file: /home/ncvs/src/sbin/tunefs/Makefile,v
retrieving revision 1.6
diff -d -u -r1.6 Makefile
--- Makefile	4 Dec 2001 02:19:58 -0000	1.6
+++ Makefile	18 Jan 2003 05:08:29 -0000
@@ -3,5 +3,6 @@
 
 PROG=	tunefs
 MAN=	tunefs.8
+LDADD=	-lufs
 
 .include <bsd.prog.mk>
Index: tunefs.c
===================================================================
RCS file: /home/ncvs/src/sbin/tunefs/tunefs.c,v
retrieving revision 1.33
diff -d -u -r1.33 tunefs.c
--- tunefs.c	27 Nov 2002 02:18:57 -0000	1.33
+++ tunefs.c	18 Jan 2003 05:08:29 -0000
@@ -60,6 +60,7 @@
 #include <err.h>
 #include <fcntl.h>
 #include <fstab.h>
+#include <libufs.h>
 #include <paths.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -69,26 +70,17 @@
 /* the optimization warning string template */
 #define	OPTWARN	"should optimize for %s with minfree %s %d%%"
 
-union {
-	struct	fs sb;
-	char pad[MAXBSIZE];
-} sbun;
-#define	sblock sbun.sb
+struct uufsd disk;
+#define	sblock disk.d_fs
 
 int fi;
 long dev_bsize = 1;
 
-void bwrite(ufs2_daddr_t, const char *, int);
-int bread(ufs2_daddr_t, char *, int);
-void getsb(struct fs *, const char *);
-void putsb(struct fs *, const char *, int);
 void usage(void);
 void printfs(void);
 
 int
-main(argc, argv)
-	int argc;
-	char *argv[];
+main(int argc, char *argv[])
 {
 	char *special;
 	const char *name;
@@ -227,7 +219,12 @@
 	}
 	if (fs == NULL && (st.st_mode & S_IFMT) == S_IFDIR)
 		errx(10, "%s: unknown file system", special);
-	getsb(&sblock, special);
+	if (ufs_disk_fillout(&disk, special) == -1) {
+		if (disk.d_error != NULL)
+			errx(11, "%s: %s", special, disk.d_error);
+		else
+			err(12, "%s", special);
+	}
 
 	if (pflag) {
 		printfs();
@@ -362,7 +359,7 @@
 		}
 	}
 
-	putsb(&sblock, special, Aflag);
+	sbwrite(&disk, Aflag);
 	if (active) {
 		bzero(&args, sizeof(args));
 		if (mount("ufs", fs->fs_file,
@@ -374,7 +371,7 @@
 }
 
 void
-usage()
+usage(void)
 {
 	fprintf(stderr, "%s\n%s\n%s\n",
 "usage: tunefs [-A] [-a enable | disable] [-e maxbpg] [-f avgfilesize]",
@@ -383,66 +380,8 @@
 	exit(2);
 }
 
-/*
- * Possible superblock locations ordered from most to least likely.
- */
-static int sblock_try[] = SBLOCKSEARCH;
-static ufs2_daddr_t sblockloc;
-
-void
-getsb(fs, file)
-	struct fs *fs;
-	const char *file;
-{
-	int i;
-
-	fi = open(file, O_RDONLY);
-	if (fi < 0)
-		err(3, "cannot open %s", file);
-	for (i = 0; sblock_try[i] != -1; i++) {
-		if (bread(sblock_try[i], (char *)fs, SBLOCKSIZE))
-			err(4, "%s: bad super block", file);
-		if ((fs->fs_magic == FS_UFS1_MAGIC ||
-		     (fs->fs_magic == FS_UFS2_MAGIC &&
-		      fs->fs_sblockloc == sblock_try[i])) &&
-		    fs->fs_bsize <= MAXBSIZE &&
-		    fs->fs_bsize >= sizeof(struct fs))
-			break;
-	}
-	if (sblock_try[i] == -1)
-		err(5, "Cannot find file system superblock");
-	dev_bsize = fs->fs_fsize / fsbtodb(fs, 1);
-	sblockloc = sblock_try[i] / dev_bsize;
-}
-
 void
-putsb(fs, file, all)
-	struct fs *fs;
-	const 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(sblockloc, (const char *)fs, SBLOCKSIZE);
-	if (all)
-		for (i = 0; i < fs->fs_ncg; i++)
-			bwrite(fsbtodb(fs, cgsblock(fs, i)),
-			    (const char *)fs, SBLOCKSIZE);
-	close(fi);
-}
-
-void
-printfs()
+printfs(void)
 {
 	warnx("ACLs: (-a)                                         %s",
 		(sblock.fs_flags & FS_ACLS)? "enabled" : "disabled");
@@ -466,35 +405,4 @@
 	if (sblock.fs_minfree < MINFREE &&
 	    sblock.fs_optim == FS_OPTTIME)
 		warnx(OPTWARN, "space", "<", MINFREE);
-}
-
-void
-bwrite(blk, buf, size)
-	ufs2_daddr_t blk;
-	const char *buf;
-	int size;
-{
-
-	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)
-	ufs2_daddr_t bno;
-	char *buf;
-	int cnt;
-{
-	int i;
-
-	if (lseek(fi, (off_t)bno * dev_bsize, SEEK_SET) < 0)
-		return(1);
-	if ((i = read(fi, buf, cnt)) != cnt) {
-		for(i=0; i<sblock.fs_bsize; i++)
-			buf[i] = 0;
-		return (1);
-	}
-	return (0);
 }
%%%
-- 
Juli Mallett <jmallett@FreeBSD.org>
AIM: BSDFlata -- IRC: juli on EFnet.
OpenDarwin, Mono, FreeBSD Developer.
ircd-hybrid Developer, EFnet addict.
FreeBSD on MIPS-Anything on FreeBSD.

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?20030117211040.B20672>