Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 18 Jan 2003 19:19:01 -0800
From:      Juli Mallett <jmallett@FreeBSD.org>
To:        current@FreeBSD.org
Subject:   Re: badsect testers?
Message-ID:  <20030118191901.A96887@FreeBSD.org>
In-Reply-To: <20030118191821.A96796@FreeBSD.org>; from jmallett@FreeBSD.org on Sat, Jan 18, 2003 at 07:18:21PM -0800
References:  <20030118191821.A96796@FreeBSD.org>

next in thread | previous in thread | raw e-mail | index | archive | help
* De: Juli Mallett <jmallett@FreeBSD.org> [ Data: 2003-01-18 ]
	[ Subjecte: badsect testers? ]
> Can someone who actually uses badsect, or who has clue about it, test this
> diff, to make it use libufs?

Err, THIS diff.

%%%
Index: Makefile
===================================================================
RCS file: /home/ncvs/src/sbin/badsect/Makefile,v
retrieving revision 1.5
diff -d -u -r1.5 Makefile
--- Makefile	4 Dec 2001 02:19:44 -0000	1.5
+++ Makefile	19 Jan 2003 03:17:32 -0000
@@ -4,5 +4,6 @@
 PROG=	badsect
 WARNS=	0
 MAN=	badsect.8
+LDADD=	-lufs
 
 .include <bsd.prog.mk>
Index: badsect.c
===================================================================
RCS file: /home/ncvs/src/sbin/badsect/badsect.c,v
retrieving revision 1.16
diff -d -u -r1.16 badsect.c
--- badsect.c	27 Nov 2002 02:18:56 -0000	1.16
+++ badsect.c	19 Jan 2003 03:17:32 -0000
@@ -65,37 +65,21 @@
 #include <err.h>
 #include <dirent.h>
 #include <fcntl.h>
+#include <libufs.h>
 #include <paths.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
 
-union {
-	struct	fs fs;
-	char	fsx[SBLOCKSIZE];
-} ufs;
-#define sblock	ufs.fs
-union {
-	struct	cg cg;
-	char	cgx[MAXBSIZE];
-} ucg;
-#define	acg	ucg.cg
-struct	fs *fs;
-int	fso, fsi;
+#define sblock	disk.d_fs
+#define	acg	disk.d_cg
+struct	uufsd disk;
+struct	fs *fs = &sblock;
 int	errs;
-long	dev_bsize = 1;
 
-char buf[MAXBSIZE];
-
-void	rdfs(daddr_t, int, char *);
 int	chkuse(daddr_t, int);
 
-/*
- * Possible superblock locations ordered from most to least likely.
- */
-static int sblock_try[] = SBLOCKSEARCH;
-
 static void
 usage(void)
 {
@@ -137,23 +121,12 @@
 		    (u_long)stbuf.st_rdev, argv[1]);
 		exit(5);
 	}
-	if ((fsi = open(name, O_RDONLY)) < 0)
-		err(6, "%s", name);
-	fs = &sblock;
-	for (i = 0; sblock_try[i] != -1; i++) {
-		rdfs(sblock_try[i] / dev_bsize, SBLOCKSIZE, (char *)fs);
-		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) {
-		printf("Cannot find file system\n");
-		exit(7);
+	if (ufs_disk_fillout(&disk, name) == -1) {
+		if (disk.d_error != NULL)
+			errx(6, "%s: %s", name, disk.d_error);
+		else
+			err(7, "%s", name);
 	}
-	dev_bsize = fs->fs_fsize / fsbtodb(fs, 1);
 	for (argc -= 2, argv += 2; argc > 0; argc--, argv++) {
 		number = atol(*argv);
 		if (chkuse(number, 1))
@@ -175,6 +148,7 @@
 			errs++;
 		}
 	}
+	ufs_disk_close(&disk);
 	printf("Don't forget to run ``fsck %s''\n", name);
 	exit(errs);
 }
@@ -204,8 +178,11 @@
 			return (1);
 		}
 	}
-	rdfs(fsbtodb(fs, cgtod(fs, cg)), (int)sblock.fs_cgsize,
-	    (char *)&acg);
+	if (cgread1(&disk, cg) != 1) {
+		fprintf(stderr, "cg %d: could not be read\n", cg);
+		errs++;
+		return (1);
+	}
 	if (!cg_chkmagic(&acg)) {
 		fprintf(stderr, "cg %d: bad magic number\n", cg);
 		errs++;
@@ -215,23 +192,4 @@
 	if (isclr(cg_blksfree(&acg), bn))
 		printf("Warning: sector %ld is in use\n", (long)blkno);
 	return (0);
-}
-
-/*
- * read a block from the file system
- */
-void
-rdfs(daddr_t bno, int size, char *bf)
-{
-	int n;
-
-	if (lseek(fsi, (off_t)bno * dev_bsize, SEEK_SET) < 0) {
-		printf("seek error: %ld\n", (long)bno);
-		err(1, "rdfs");
-	}
-	n = read(fsi, bf, size);
-	if (n != size) {
-		printf("read error: %ld\n", (long)bno);
-		err(1, "rdfs");
-	}
 }
%%%
-- 
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?20030118191901.A96887>