From: alan@nabeth.cxo.dec.com (Alan Rollow - Dr. File System's Home for Wayward Inodes.)
Subject: Re: Looking for examples of SCSI CAM routine usage
Date: Wed, 26 Jan 1994 19:22:30 GMT [thread overview]
Message-ID: <1994Jan26.192230.12821@nntpd2.cxo.dec.com> (raw)
In-Reply-To: 1994Jan21.161229.6512@dxcern.cern.ch
In article <1994Jan21.161229.6512@dxcern.cern.ch>, michelotto@mvxpd5.pd.infn.it (Michele Michelotto) writes:
>I'm looking for some example of SCSI_CAM routines usage.
>I would like to use an existing driver to submit a generic command
>to a certain SCSI device.
>I would like avoid writing a new driver even using the low level
>SCSI CAM routines.
Find below, an example program that does an INQUIRY
/*
* Author: Alan Rollow, Subsystems Engineering, Digital Equipment Corp.
* File: inquire.c
* Date: 8/12/93
* Version: 1.1
*
* inquire.c - Simple (?) program to use the CAM User Agent to do
* INQUIRY of a device. Allow specifying the device by name
* rather then (bus,target,lun).
*
* (?) After this exercise one wonders if the people that
* design Standards ever have to use them...
*/
#ifndef lint
static char SccsId[] = "@(#)inquire.c 1.1 (SCSI) 8/12/93" ;
#endif
#include <sys/types.h>
#include <sys/file.h>
#include <sys/ioctl.h>
#include <sys/devio.h>
#include <io/common/iotypes.h>
#include <io/cam/cam.h>
#include <io/cam/dec_cam.h>
#include <io/cam/uagt.h>
#include <io/cam/scsi_all.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <errno.h>
/*
* Space for the inquiry results.
*/
#define INQUIRY_LEN 36
#define SCSI_IDS 8
unsigned char buf[INQUIRY_LEN] ;
/*
* Program name for error messages.
*/
char *program ;
/*
* Given a device name, use DEVIOCGET to get the generic
* information about the device, which includes, SCSI ID
* and bus name. Use that to fill in the appropriate
* fields of the CCB structure.
*
* Assume a LUN number of 0.
*/
set_scsi_ids(char *device, CCB_SCSIIO *ccb)
{
register fd ;
struct devget data ;
if((fd = open(device, O_RDONLY|O_NDELAY)) == -1 ) {
fprintf(stderr, "%s: Can't open %s: %s.\n", program,
device, strerror(errno)) ;
return -1 ;
}
if( ioctl(fd, DEVIOCGET, (char *)&data) == -1 ) {
fprintf(stderr, "%s: DEVIOCGET failed on %s: %s.\n", program,
device, strerror(errno)) ;
if( close(fd) == -1 )
fprintf(stderr, "%s: Can't close %s: %s.\n", program,
device, strerror(errno)) ;
return - 1 ;
}
/*
* The assumption that the unit number % 8 is probably
* only valid for 8 bit SCSI.
*/
ccb->cam_ch.cam_path_id = data.bus_num ;
ccb->cam_ch.cam_target_id = data.unit_num % SCSI_IDS ;
ccb->cam_ch.cam_target_lun = 0 ;
return 1 ;
}
main(int argc, char *argv[])
{
register fd, i ;
UAGT_CAM_CCB ua_ccb ;
CCB_SCSIIO ccb ;
ALL_INQ_CDB *inq ;
program = argv[0] ;
if((fd = open("/dev/cam", O_RDONLY)) == -1 ) {
fprintf(stderr, "%s: Can't open /dev/cam: %s.\n", program,
strerror(errno)) ;
exit(errno) ;
}
for(i = 1; i < argc; i++) {
/*
* Setup the CCB.
*/
bzero((char *)&ccb, sizeof(CCB_SCSIIO)) ;
ccb.cam_ch.my_addr = (struct ccb_header *)&ccb ;
ccb.cam_ch.cam_ccb_len = sizeof(CCB_SCSIIO) ;
ccb.cam_ch.cam_func_code = XPT_SCSI_IO ;
ccb.cam_ch.cam_flags = CAM_DIR_IN | CAM_DIS_AUTOSENSE ;
if( set_scsi_ids(argv[i], &ccb) == -1 )
continue ;
/*
* Setup the rest of the CCB for the INQUIRY.
*/
ccb.cam_data_ptr = buf ;
ccb.cam_dxfer_len = INQUIRY_LEN ;
ccb.cam_timeout = CAM_TIME_DEFAULT ;
ccb.cam_cdb_len = sizeof(ALL_INQ_CDB) ;
/*
* Setup the INQUIRY CDB.
*/
inq = (ALL_INQ_CDB *)ccb.cam_cdb_io.cam_cdb_bytes ;
inq->opcode = ALL_INQ_OP ;
inq->alloc_len = INQUIRY_LEN ;
inq->evpd = 0 ;
inq->lun = 0 ;
inq->page = 0 ;
inq->control = 0 ;
/*
* Setup the User Agent data structure.
*/
bzero((char *)&ua_ccb, sizeof(UAGT_CAM_CCB)) ;
ua_ccb.uagt_ccb = (CCB_HEADER *)&ccb ;
ua_ccb.uagt_ccblen = sizeof(CCB_SCSIIO) ;
ua_ccb.uagt_buffer = buf ;
ua_ccb.uagt_buflen = INQUIRY_LEN ;
ua_ccb.uagt_snsbuf = NULL ;
ua_ccb.uagt_snslen = 0 ;
ua_ccb.uagt_cdb = NULL ;
ua_ccb.uagt_cdblen = 0 ;
/*
* Now we finally get to do the I/O to do the
* inquiry.
*/
if( ioctl(fd, UAGT_CAM_IO, (char *)&ua_ccb) == -1 ) {
fprintf(stderr, "%s: User Agent ioctl failed: %s.\n",
program, strerror(errno)) ;
continue ;
}
/*
* Check the CCB to see if the INQUIRY failed.
*/
if( ccb.cam_ch.cam_status != CAM_REQ_CMP )
fprintf(stderr, "%s: The INQUIRY failed on %s: %x.\n",
program, argv[i], ccb.cam_ch.cam_status) ;
else
print_inquiry(argv[i], (ALL_INQ_DATA *)buf) ;
}
if( close(fd) == -1 )
fprintf(stderr, "%s: Can't close /dev/cam: %s.\n", program,
strerror(errno)) ;
return 0 ;
}
print_inquiry(char *device, ALL_INQ_DATA *inq)
{
printf("%s: %8.8s %16.16s %4.4s\n", device, inq->vid,
inq->pid, inq->revlevel) ;
}
--
Alan Rollow alan@nabeth.cxo.dec.com
prev parent reply other threads:[~1994-01-26 19:22 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
1994-01-21 16:12 Looking for examples of SCSI CAM routine usage Michele Michelotto
1994-01-25 16:46 ` John A. Gallant USG
1994-01-26 19:22 ` Alan Rollow - Dr. File System's Home for Wayward Inodes. [this message]
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox