Subject: bin/2719: 'badsect' accesses wrong device (doesn't work that way)
To: None <gnats-bugs@NetBSD.ORG>
From: Phillip F Knaack <flipk@idea.exnet.iastate.edu>
List: netbsd-bugs
Date: 08/29/1996 11:58:20
>Number:         2719
>Category:       bin
>Synopsis:       'badsect' accesses wrong device (doesn't work that way)
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Aug 29 13:20:01 1996
>Last-Modified:
>Originator:     Phillip F Knaack
>Organization:
	Information Development for Extension Audiences (IDEA)
	Iowa State University Extension
>Release:        1.2_ALPHA
>Environment:
System: NetBSD idea.exnet.iastate.edu 1.2_ALPHA NetBSD 1.2_ALPHA (NCREMP) #11: Fri Jun 21 11:12:44 CDT 1996 root@ncremp.ag.iastate.edu:/usr/src/sys/arch/i386/compile/NCREMP i386
	Basically stock 1.2_ALPHA machine.

>Description:
	'badsect' uses the directory you specify to locate the actual block
device in /dev of the mounted filesystem. however, it tries to read from the
block device to determine if the block you specified is in use or not (rather
than the raw device, you can't access the block device when a filesystem is
mounted).
>How-To-Repeat:
	(/dev/wd1e is mounted on /local/disk1, assume bad block is 17462)
	# badsect /local/disk1/BAD 17462
	/dev/wd1e: device busy
	#
>Fix:

	The following patch appears to fix it perfectly (after locating the
device node, tack an extra 'r' in front of the name to get the char device).

*** /local/disk1/src/sbin/badsect/badsect.c     Fri Oct 13 20:08:15 1995
--- /usr/src/sbin/badsect/badsect.c     Thu Aug 29 11:46:20 1996
***************
*** 125,130 ****
--- 125,137 ----
                    S_ISBLK(devstat.st_mode))
                        break;
        }
+       /*
+        * we've found the block device, but since the filesystem 
+        * is mounted, we must write to the raw (character) device
+        * instead.
+        */
+       name[5] = 'r';
+       strcpy(&name[6], dp->d_name);
        closedir(dirp);
        if (dp == NULL) {
                printf("Cannot find dev 0%o corresponding to %s\n",

>Audit-Trail:
>Unformatted: