Subject: Scsireprobe appears to be broken in 1.2G
To: None <current-users@NetBSD.ORG>
From: Brian Buhrow <buhrow@cats.ucsc.edu>
List: current-users
Date: 10/02/1997 09:35:36
	Hello folks.  I'm running 1.2G/i386 with sources as of September 10,
1997 or so.  Although I'm very happy with the latest changes, I'm somewhat
disappointed to find that the ability to do on-the-fly scsi reprobing seems
to be broken in these sources.
	When I wish to connect a new scsi device to my test machine, I often
just plug it in and run the following program against sd0d of the system.
(I got this from someone on these lists.)
With the 1.2G kernel, I get: sd0d: bad file descriptor.
	Is this really broken or have I compiled out some option that I was
supposed to leave in in order for this to work?
-thanks
-Brian

/*
* From: osymh@lightning.oscs.montana.edu (Michael L. Hitch)
* Date: Mon, 20 Feb 1995 11:05:48 -0700
* In-Reply-To: Olaf Seibert's message of Feb 20, 12:10pm
* X-Mailer: Mail User's Shell (7.2.5 10/14/92)
* To: Olaf Seibert <rhialto@mbfys.kun.nl>, current-users@NetBSD.ORG
* Subject: Re: scsi tapes
* Sender: owner-current-users@NetBSD.ORG
* Precedence: list
* X-Loop: current-users@NetBSD.ORG
* Status: OR
* 
* On Feb 20, 12:10pm, Olaf Seibert wrote:
* } But what if you have a scsi tape unit that's mostly turned off (because
* } you don't need it very often) and so you reboot without the tape unit
* } being turned on. With Linux you absolutely need to reboot before you
* } can use your tape.
* } 
* } Could NetBSD do better? (Not only for scsi buses necessarily but on any
* } bus that could potentially have devices that are not switched on at
* } boot time)
* } 
* } I realise that the dynamic mapping of scsi targets to devices (st*
* } at scsibus? target ? lun ? ) could not work, but a fixed mapping could.
* } (Or am I being silly and it works already - I cannot try this myself).
* 
*   NetBSD already supports reprobing the SCSI bus(es).  I have an external
* CDROM that I normally don't have turned on.  I write a simple program
* to do a reprobe of the SCSI system so that I could connect the CDROM
* without needing to reboot.  By default, the program will reprobe all
* logical units on all targets on all SCSI adapters.  It will use /dev/rsd0c
* as the SCSI device to open to do the ioctl.  It will take an argument
* of the form "device[:bus[:target[:lun]]]" to specify a different
* device and to limit the bus, target, or logical unit to reprobe.  I
* do "scsireprobe sd1:1:0:1" with my Adaptec ACB400A MFF-SCSI adapter
* to get the second disk configured (the ACB400A connects 2 MFM drives
* and uses the logical unit to address the drives), since the initial
* probe only gets the first logical unit it finds on each target.
* 
* 
------------------------  scsireprobe.c ------------------------------
*/
#include <stdio.h>
#include <string.h>
#include <sys/fcntl.h>
#include <sys/scsiio.h>

int fd;

main (argc, argv)
int argc;
char *argv[];
{
	char *devname;
	char namebuf[128];
	char *np;
	struct scsi_addr zzz = {-1, -1, -1};

	if (argc > 1)
		devname = argv[1];
	else
		devname = "/dev/rsd0c";
	np = strchr (devname, ':');
	if (np) {
		*np++ = 0;
		zzz.scbus = atoi (np);
		np = strchr (np, ':');
		if (np) {
			zzz.target = atoi (++np);
			np = strchr (np, ':');
			if (np)
				zzz.lun = atoi (++np);
		}
	}
	if (*devname != '/') {
		sprintf (namebuf, "/dev/r%sc", devname);
		devname = namebuf;
	}
	fd = open (devname, O_RDONLY);
	if (fd < 0)
		perror("open");
	else {
		printf ("reprobing %s:%d:%d:%d\n", devname,
		    zzz.scbus, zzz.target, zzz.lun);
		if (ioctl (fd, SCIOCREPROBE, &zzz) < 0)
			perror("ioctl");
	}
	close (fd);
}