From clive@cartier.cirx.org  Thu Jun 29 01:52:26 2000
Return-Path: <clive@cartier.cirx.org>
Received: from cartier.cirx.org (cartier.cirx.org [211.72.15.243])
	by hub.freebsd.org (Postfix) with ESMTP id 00C1F37B79D
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 29 Jun 2000 01:52:19 -0700 (PDT)
	(envelope-from clive@cartier.cirx.org)
Received: (from clive@localhost)
	by cartier.cirx.org (8.9.3/8.9.3) id QAA11846;
	Thu, 29 Jun 2000 16:52:15 +0800 (CST)
	(envelope-from clive)
Message-Id: <200006290852.QAA11846@cartier.cirx.org>
Date: Thu, 29 Jun 2000 16:52:15 +0800 (CST)
From: clive@CirX.ORG
Sender: clive@cartier.cirx.org
Reply-To: clive@CirX.ORG
To: FreeBSD-gnats-submit@freebsd.org
Subject: Let badsect recognize character device.
X-Send-Pr-Version: 3.2

>Number:         19574
>Category:       i386
>Synopsis:       Let badsect recognize character device.
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Jun 29 02:00:01 PDT 2000
>Closed-Date:    Thu Nov 9 02:51:32 PST 2000
>Last-Modified:  Thu Nov 09 02:53:10 PST 2000
>Originator:     Clive Lin <clive@CirX.ORG>
>Release:        FreeBSD 5.0-CURRENT i386
>Organization:
This site doesnt' exist
>Environment:

	FreeBSD 5.0-CURRENT #0: Sun Jun 25 21:22:16 CST 2000     root@cartier.cirx.org:/usr/local/src/sys/compile/CARTIER 

>Description:

	1) There's no block device in 5.0-C.
	2) But our sbin/badsect still look for block device.
	3) So why not fix the bug instead of buying a new hard drive ? :->
	4) Since on -current the only bug fingured out is about style(9),
	   I think it's ok to send-pr.

>How-To-Repeat:

	1) Use any FreeBSD version that has no block device.
	2) Prepare a slice that doesn't store important data.
	3) Mkdir BAD within the slice root.
	4) badsect BAD [any sector number within this slice]

	*) If it's hard to figure out which sector is within the slice
	   test wanted, then prepare a hard drive that really has bad
	   sector. After some accessing, the bad sector number will be
	   reported on the console.

>Fix:

	Apply patch.

Index: badsect.c
===================================================================
RCS file: /home/ncvs/src/sbin/badsect/badsect.c,v
retrieving revision 1.7
diff -u -r1.7 badsect.c
--- badsect.c	1999/08/28 00:12:28	1.7
+++ badsect.c	2000/06/29 08:39:56
@@ -118,11 +118,17 @@
 		err(3, "%s", name);
 	name_dir_end = name + strlen(name);
 	while ((dp = readdir(dirp)) != NULL) {
+		/*
+		 * Opening of a mounted on device is not allowed.
+		 * Attempt to open the raw device instead.
+		 */
+		if (dp->d_name[0] != 'r')
+			continue ; 
 		strcpy(name_dir_end, dp->d_name);
 		if (lstat(name, &devstat) < 0)
 			err(4, "%s", name);
 		if (stbuf.st_dev == devstat.st_rdev &&
-		    (devstat.st_mode & IFMT) == IFBLK)
+		    (devstat.st_mode & IFMT) == IFCHR)
 			break;
 	}
 	closedir(dirp);
@@ -131,12 +137,6 @@
 		    (u_long)stbuf.st_rdev, argv[1]);
 		exit(5);
 	}
-	/*
-	 * Opening of a mounted on device is not allowed.
-	 * Attempt to open the raw device instead.
-	 */
-	memcpy(name_dir_end + 1, name_dir_end, strlen(name_dir_end) + 1);
-	*name_dir_end = 'r';
 	if ((fsi = open(name, O_RDONLY)) < 0)
 		err(6, "%s", name);
 	fs = &sblock;

>Release-Note:
>Audit-Trail:

From: Bruce Evans <bde@zeta.org.au>
To: clive@CirX.ORG
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: i386/19574: Let badsect recognize character device.
Date: Sun, 2 Jul 2000 01:34:19 +1000 (EST)

 On Thu, 29 Jun 2000 clive@CirX.ORG wrote:
 
 > >Description:
 > 
 > 	1) There's no block device in 5.0-C.
 > 	2) But our sbin/badsect still look for block device.
 
 The patch leaves a lot of dead code related to block devices.
 
 > Index: badsect.c
 > ===================================================================
 > RCS file: /home/ncvs/src/sbin/badsect/badsect.c,v
 > retrieving revision 1.7
 > diff -u -r1.7 badsect.c
 > --- badsect.c	1999/08/28 00:12:28	1.7
 > +++ badsect.c	2000/06/29 08:39:56
 > @@ -118,11 +118,17 @@
 >  		err(3, "%s", name);
 >  	name_dir_end = name + strlen(name);
 >  	while ((dp = readdir(dirp)) != NULL) {
 > +		/*
 > +		 * Opening of a mounted on device is not allowed.
 
 Opening it read-only is now allowed.  Otherwise badsect wouldn't work at
 all.
 
 > +		 * Attempt to open the raw device instead.
 
 All disk devices are now raw.
 
 > +		 */
 > +		if (dp->d_name[0] != 'r')
 > +			continue ; 
 
 The non-'r' name should be preferred.
 
 statfs(2) should be used instead of the readdir() loop.
 
 Bruce
 
 
State-Changed-From-To: open->closed 
State-Changed-By: adrian 
State-Changed-When: Thu Nov 9 02:51:32 PST 2000 
State-Changed-Why:  


Fixed in rev 1.8 of badsect.c (and MFCed to RELENG_4) 


http://www.freebsd.org/cgi/query-pr.cgi?pr=19574 
>Unformatted:
