diff options
| author | svn2git <svn2git@FreeBSD.org> | 1994-05-01 08:00:00 +0000 |
|---|---|---|
| committer | svn2git <svn2git@FreeBSD.org> | 1994-05-01 08:00:00 +0000 |
| commit | a16f65c7d117419bd266c28a1901ef129a337569 (patch) | |
| tree | 2626602f66dc3551e7a7c7bc9ad763c3bc7ab40a /sbin/scsi | |
| parent | 8503f4f13f77abf7adc8f7e329c6f9c1d52b6a20 (diff) | |
Diffstat (limited to 'sbin/scsi')
| -rw-r--r-- | sbin/scsi/Makefile | 7 | ||||
| -rw-r--r-- | sbin/scsi/procargs.c | 86 | ||||
| -rw-r--r-- | sbin/scsi/scsi.1 | 55 | ||||
| -rw-r--r-- | sbin/scsi/scsi.c | 102 |
4 files changed, 250 insertions, 0 deletions
diff --git a/sbin/scsi/Makefile b/sbin/scsi/Makefile new file mode 100644 index 000000000000..b0839776186d --- /dev/null +++ b/sbin/scsi/Makefile @@ -0,0 +1,7 @@ +# $Id: Makefile,v 1.1 1993/11/18 05:05:25 rgrimes Exp $ + +PROG= scsi +MAN1= scsi.1 +SRCS= procargs.c scsi.c + +.include <bsd.prog.mk> diff --git a/sbin/scsi/procargs.c b/sbin/scsi/procargs.c new file mode 100644 index 000000000000..0a7de8487d23 --- /dev/null +++ b/sbin/scsi/procargs.c @@ -0,0 +1,86 @@ +/* + * Written By Julian ELischer + * Copyright julian Elischer 1993. + * Permission is granted to use or redistribute this file in any way as long + * as this notice remains. Julian Elischer does not guarantee that this file + * is totally correct for any given task and users of this file must + * accept responsibility for any damage that occurs from the application of this + * file. + * + * (julian@tfs.com julian@dialix.oz.au) + * + * $Id: procargs.c,v 1.1 1993/11/18 05:05:26 rgrimes Exp $ + */ + +#include <stdio.h> +#include <sys/file.h> + +extern int fd; +extern int debuglevel; +extern int inqflag; +extern int reprobe; +extern int dflag; +extern int bus; +extern int targ; +extern int lun; +char *myname; + +void procargs(int argc, char **argv, char **envp) +{ + extern char *optarg; + extern int optind; + int fflag, + ch; + + myname = *argv; + fflag = 0; + inqflag = 0; + dflag = 0; + while ((ch = getopt(argc, argv, "irf:d:b:t:l:")) != EOF) { + switch (ch) { + case 'r': + reprobe = 1; + break; + case 'i': + inqflag = 1; + break; + case 'f': + if ((fd = open(optarg, O_RDWR, 0)) < 0) { + (void) fprintf(stderr, + "%s: unable to open device %s.\n", + myname, optarg); + exit(1); + } + fflag = 1; + break; + case 'd': + debuglevel = atoi(optarg); + dflag = 1; + break; + case 'b': + bus = atoi(optarg); + break; + case 't': + targ = atoi(optarg); + break; + case 'l': + lun = atoi(optarg); + break; + case '?': + default: + usage(); + } + } + argc -= optind; + argv += optind; + if (!fflag) usage(); +} + +usage() +{ + printf("usage: %s -f devicename [-d level] [-i] [-r [-b bus] " + "[-t targ] [-l lun]]\n",myname); + printf("where r = reprobe, i = inquire, d = debug\n"); + printf("If debugging is not compiled in the kernel, 'd' will have no effect\n"); + exit (1); +} diff --git a/sbin/scsi/scsi.1 b/sbin/scsi/scsi.1 new file mode 100644 index 000000000000..34bb64fea124 --- /dev/null +++ b/sbin/scsi/scsi.1 @@ -0,0 +1,55 @@ +.\" +.\" Written By Julian ELischer +.\" Copyright julian Elischer 1993. +.\" Permission is granted to use or redistribute this file in any way as long +.\" as this notice remains. Julian Elischer does not guarantee that this file +.\" is totally correct for any given task and users of this file must +.\" accept responsibility for any damage that occurs from the application of this +.\" file. +.\" +.\" (julian@tfs.com julian@dialix.oz.au) +.\" +.\" $Id: scsi.1,v 1.1 1993/11/18 05:05:27 rgrimes Exp $ +.\" +.Dd October 11, 1993 +.Dt SCSI 1 +.Os BSD 4 +.Sh NAME +.Nm scsi +.Nd simple program to assist with scsi devices. +.Sh SYNOPSIS +usage: scsi -f devicename [-d level] [-i] [-r [-b bus] [-t targ] [-l lun]] +.Pp +where r = reprobe, i = inquire, d = debug +.Pp +If debugging is not compiled in the kernel, 'd' will have no effect +.Sh DESCRIPTION +The +.Nm Scsi +program is used to give some simple commands to a scsi device. It is also +really a sample usage of the general scsi commands. A more comprehensive +program should be written. +.Pp +This program allows the operator to ask the systen to reprobe for +more devices, and also to set any debug level on any scsi device. As +a sample of a generic scsi command, it also can also perform a scsi +.Em Enquiry +command against the device against which it is openned. The +reprobe can be aimed at any specific bus or target or even lun. +By default it reprobes lun0 of all possible targets not yet taken. +an lun of -1 will force testing of all LUNs. As a word of warning, this +will override the system's caution about attaching devices not on lun0 +so if a device responds to the +.Em inquiry +command on all luns (as many erroneously do), the system may think it has +found a lot more devices, which are really just the bad luns of an existing +device. + +.Pp +.Sh SEE ALSO +.Xr scsi 4 +.Sh HISTORY +The +.Nm scsi +command appeared in 386BSD 0.1.2.4/FreeBSD + diff --git a/sbin/scsi/scsi.c b/sbin/scsi/scsi.c new file mode 100644 index 000000000000..360c86947527 --- /dev/null +++ b/sbin/scsi/scsi.c @@ -0,0 +1,102 @@ +/* + * Written By Julian ELischer + * Copyright julian Elischer 1993. + * Permission is granted to use or redistribute this file in any way as long + * as this notice remains. Julian Elischer does not guarantee that this file + * is totally correct for any given task and users of this file must + * accept responsibility for any damage that occurs from the application of this + * file. + * + * (julian@tfs.com julian@dialix.oz.au) + * + * $Id: scsi.c,v 1.1 1993/11/18 05:05:28 rgrimes Exp $ + */ + +#include <stdio.h> +#include <sys/scsiio.h> +#include <sys/file.h> +#include <scsi/scsi_all.h> +void show_mem(); +int fd; +int debuglevel; +int dflag,inqflag; +int reprobe; +int bus = -1; /* all busses */ +int targ = -1; /* all targs */ +int lun = 0; /* just lun 0 */ + +main(int argc, char **argv, char **envp) +{ + struct scsi_addr scaddr; + struct scsi_inquiry_data dat; + + procargs(argc,argv,envp); + if(reprobe) { + scaddr.scbus = bus; + scaddr.target = targ; + scaddr.lun = lun; + + if (ioctl(fd,SCIOCREPROBE,&scaddr) == -1) + { + perror("ioctl"); + } + } + if(dflag) { + if (ioctl(fd,SCIOCDEBUG,&debuglevel) == -1) { + perror("ioctl [SCIODEBUG]"); + exit(1); + } + } + + if(inqflag) { + inq(fd,&dat); + show_mem(&dat,sizeof(dat)); + } +} + +/* + * Do a scsi operation asking a device what it is + * Use the scsi_cmd routine in the switch table. + */ +int inq(fd,inqbuf) + int fd; + struct scsi_inquiry_data *inqbuf; +{ + struct scsi_inquiry *cmd; + scsireq_t req; + cmd = (struct scsi_inquiry *) req.cmd; + + bzero(&req,sizeof(req)); + + cmd->op_code = INQUIRY; + cmd->length = sizeof(struct scsi_inquiry_data); + + req.flags = SCCMD_READ; /* info about the request status and type */ + req.timeout = 2000; + req.cmdlen = sizeof(*cmd); + req.databuf = (caddr_t)inqbuf; /* address in user space of buffer */ + req.datalen = sizeof(*inqbuf); /* size of user buffer */ + if (ioctl(fd,SCIOCCOMMAND,&req) == -1) + { + perror("ioctl"); + exit (1); + } +} + + +void +show_mem(address, num) + unsigned char *address; + int num; +{ + int x, y; + printf("------------------------------"); + for (y = 0; y < num; y += 1) { + if (!(y % 16)) + printf("\n%03d: ", y); + printf("%02x ", *address++); + } + printf("\n------------------------------\n"); +} + + |
