Subject: bin/994: badsect tries to use block device
To: None <gnats-admin@NetBSD.ORG>
From: None <jhawk@MIT.EDU>
List: netbsd-bugs
Date: 04/25/1995 15:05:15
>Number:         994
>Category:       bin
>Synopsis:       badsect tries to use block device
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Apr 25 15:05:13 1995
>Originator:     John Hawkinson
>Organization:
MIT SIPB
>Release:        Tue Apr 25 18:03:03 EDT 1995
>Environment:
	
System: NetBSD lola-granola 1.0A NetBSD 1.0A (LOLA) #46: Thu Apr 20 21:45:36 EDT 1995 mycroft@lola-granola:/afs/sipb.mit.edu/project/netbsd/dev/current-source/src/sys/arch/i386/compile/LOLA i386

>Description:

	badsect(8) tries to open the block device (eg: /dev/wd0f)
	instead of the raw device (/dev/rwdof) and thus fails to
	work entirely.

>How-To-Repeat:

	mount /u1
	cd /u1; mkdir BAD
	badsect BAD 59828
	/dev/wd0f: Device busy

>Fix:

	I'm at a loss as to the Right Way (tm) to obtain the raw device.
	I decided to use fsck's method of prepending "r"...

*** badsect.c	1995/04/25 18:25:40	1.1
--- badsect.c	1995/04/25 21:53:14	1.2
***************
*** 100,106 ****
  	struct stat stbuf, devstat;
  	register struct direct *dp;
  	DIR *dirp;
! 	char name[BUFSIZ];
  
  	if (argc < 3) {
  		fprintf(stderr, "usage: badsect bbdir blkno [ blkno ]\n");
--- 100,106 ----
  	struct stat stbuf, devstat;
  	register struct direct *dp;
  	DIR *dirp;
! 	char name[BUFSIZ], rname[BUFSIZ];
  
  	if (argc < 3) {
  		fprintf(stderr, "usage: badsect bbdir blkno [ blkno ]\n");
***************
*** 131,139 ****
  			stbuf.st_rdev, argv[1]);
  		exit(5);
  	}
! 	if ((fsi = open(name, 0)) < 0) {
! 		perror(name);
! 		exit(6);
  	}
  	fs = &sblock;
  	rdfs(SBOFF, SBSIZE, (char *)fs);
--- 131,151 ----
  			stbuf.st_rdev, argv[1]);
  		exit(5);
  	}
! 	strncpy(rname, name, 5);
! 	strcat(rname,"r");
! 	strcat(rname, &name[5]);
! 	if (stat(rname, &devstat) < 0) {
! 	  perror(rname);
! 	  fprintf(stderr, "Can't find raw device %s\n", rname);
! 	  exit(6);
! 	}
! 	if (!S_ISCHR(devstat.st_mode)) {
! 	  fprintf(stderr,"%s is not a character device\n", rname);
! 	  exit(7);
! 	}
! 	if ((fsi = open(rname, 0)) < 0) {
! 		perror(rname);
! 		exit(8);
  	}
  	fs = &sblock;
  	rdfs(SBOFF, SBSIZE, (char *)fs);
***************
*** 148,154 ****
  			errs++;
  		}
  	}
! 	printf("Don't forget to run ``fsck %s''\n", name);
  	exit(errs);
  }
  
--- 160,166 ----
  			errs++;
  		}
  	}
! 	printf("Don't forget to run ``fsck %s''\n", rname);
  	exit(errs);
  }
  


>Audit-Trail:
>Unformatted: