Subject: misc/897: badsect(8) attempts to open mounted device
To: None <gnats-admin@NetBSD.ORG>
From: Kenneth Stailey <kstailey@leidecker.gsfc.nasa.gov>
List: netbsd-bugs
Date: 03/22/1995 21:05:07
>Number:         897
>Category:       misc
>Synopsis:       badsect(8) attempts to open mounted device
>Confidential:   no
>Severity:       critical
>Priority:       low
>Responsible:    misc-bug-people (Misc Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Mar 22 21:05:04 1995
>Originator:     Kenneth Stailey
>Organization:
self
>Release:        March 18th tarballs
>Environment:
System: NetBSD pluto 1.0A NetBSD 1.0A (PLUTO) #19: Sat Mar 18 16:46:13 EST 1995 ken@pluto:/usr/src/sys/arch/i386/compile/PLUTO i386


>Description:
	badsect attepts to open the block special device file of
	a mounted filesystem as par for the course.  EBUSY is all you get.
>How-To-Repeat:
	Try capture a sector with badsect.  It will fail on an open.
>Fix:
	Apply this fix to badsect.c:

--- badsect.c.DIST	Tue Jan 31 06:11:38 1995
+++ badsect.c	Wed Mar 22 23:48:05 1995
@@ -111,14 +111,20 @@
 		exit(3);
 	}
 	while ((dp = readdir(dirp)) != NULL) {
-		strcpy(&name[5], dp->d_name);
-		if (stat(name, &devstat) < 0) {
+		char tmp[BUFSIZ];
+
+		strcpy(tmp, name);
+		strcat(tmp,  dp->d_name);
+		if (stat(tmp, &devstat) < 0) {
 			perror(name);
 			exit(4);
 		}
 		if (stbuf.st_dev == devstat.st_rdev &&
-		    S_ISBLK(devstat.st_mode))
+		    S_ISBLK(devstat.st_mode)) {
+			strcat(name, "r");
+			strcat(name, dp->d_name);
 			break;
+		}
 	}
 	closedir(dirp);
 	if (dp == NULL) {

--XAA07507.795934566/pluto.spacenet.com--


>Audit-Trail:
>Unformatted: