2 * Amanda, The Advanced Maryland Automatic Network Disk Archiver
3 * Copyright (c) 1991-2000 University of Maryland at College Park
6 * Permission to use, copy, modify, distribute, and sell this software and its
7 * documentation for any purpose is hereby granted without fee, provided that
8 * the above copyright notice appear in all copies and that both that
9 * copyright notice and this permission notice appear in supporting
10 * documentation, and that the name of U.M. not be used in advertising or
11 * publicity pertaining to distribution of the software without specific,
12 * written prior permission. U.M. makes no representations about the
13 * suitability of this software for any purpose. It is provided "as is"
14 * without express or implied warranty.
16 * U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M.
18 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
20 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 * Authors: the Amanda Development Team. Its members are listed in a
24 * file named AUTHORS, in the root directory of this distribution.
27 * $Id: scsi-irix.c,v 1.22 2005/10/15 13:20:47 martinea Exp $
29 * Interface to execute SCSI commands on an SGI Workstation
31 * Copyright (c) Thomas Hepper th@ant.han.de
37 #ifdef HAVE_IRIX_LIKE_SCSI
46 #ifdef HAVE_SYS_TYPES_H
47 #include <sys/types.h>
49 #ifdef HAVE_SYS_STAT_H
57 #include <sys/dsreq.h>
60 #include <scsi-defs.h>
62 void SCSI_OS_Version()
65 static char rcsid[] = "$Id: scsi-irix.c,v 1.22 2005/10/15 13:20:47 martinea Exp $";
66 DebugPrint(DEBUG_INFO, SECTION_INFO, "scsi-os-layer: %s\n",rcsid);
73 int SCSI_OpenDevice(int ip)
75 extern OpenFiles_T *pDev;
79 if (pDev[ip].inqdone == 0)
81 if ((DeviceFD = open(pDev[ip].dev, O_RDWR | O_EXCL)) >= 0)
83 pDev[ip].inqdone = 1; pDev[ip].SCSI = 0;
85 pDev[ip].fd = DeviceFD;
86 pDev[ip].inquiry = (SCSIInquiry_T *)malloc(INQUIRY_SIZE);
87 if (SCSI_Inquiry(ip, pDev[ip].inquiry, INQUIRY_SIZE) == 0)
89 if (pDev[ip].inquiry->type == TYPE_TAPE || pDev[ip].inquiry->type == TYPE_CHANGER)
92 pDev[ip].ident[i] = pDev[ip].inquiry->prod_ident[i];
93 for (i=15; i >= 0 && !isalnum((int)pDev[ip].ident[i]) ; i--)
95 pDev[ip].ident[i] = '\0';
100 if (pDev[ip].inquiry->type == TYPE_TAPE)
102 pDev[ip].type = stralloc("tape");
105 if (pDev[ip].inquiry->type == TYPE_CHANGER)
107 pDev[ip].type = stralloc("changer");
110 PrintInquiry(pDev[ip].inquiry);
112 } else { /* ! TYPE_TAPE ! TYPE_CHANGER */
114 free(pDev[ip].inquiry);
115 pDev[ip].inquiry = NULL;
119 } else { /* inquiry failed */
121 free(pDev[ip].inquiry);
122 pDev[ip].inquiry = NULL;
128 * Open ok, but no SCSI communication available
131 free(pDev[ip].inquiry);
132 pDev[ip].inquiry = NULL;
138 if ((DeviceFD = open(pDev[ip].dev, O_RDWR | O_EXCL)) >= 0)
140 pDev[ip].fd = DeviceFD;
141 pDev[ip].devopen = 1;
144 pDev[ip].devopen = 0;
151 int SCSI_CloseDevice(int DeviceFD)
153 extern OpenFiles_T *pDev;
156 if (pDev[DeviceFD].devopen == 1)
158 pDev[DeviceFD].devopen = 0;
159 ret = close(pDev[DeviceFD].fd);
165 int SCSI_ExecuteCommand(int DeviceFD,
166 Direction_T Direction,
170 int DataBufferLength,
172 int RequestSenseLength)
174 extern OpenFiles_T *pDev;
175 ExtendedRequestSense_T ExtendedRequestSense;
180 if (pDev[DeviceFD].avail == 0)
185 memset(&ds, 0, sizeof(struct dsreq));
186 memset(pRequestSense, 0, RequestSenseLength);
187 memset(&ExtendedRequestSense, 0 , sizeof(ExtendedRequestSense_T));
189 ds.ds_flags = DSRQ_SENSE|DSRQ_TRACE|DSRQ_PRINT;
193 ds.ds_cmdbuf = (caddr_t)CDB;
194 ds.ds_cmdlen = CDB_Length;
195 /* Data buffer for results */
196 ds.ds_databuf = (caddr_t)DataBuffer;
197 ds.ds_datalen = DataBufferLength;
199 ds.ds_sensebuf = (caddr_t)pRequestSense;
200 ds.ds_senselen = RequestSenseLength;
205 ds.ds_flags = ds.ds_flags | DSRQ_READ;
208 ds.ds_flags = ds.ds_flags | DSRQ_WRITE;
212 while (--retries > 0) {
213 if (pDev[DeviceFD].devopen == 0)
215 if (SCSI_OpenDevice(DeviceFD) == 0)
217 dbprintf(("SCSI_ExecuteCommand could not open %s: %s\n",
220 sleep(1); /* Give device a little time befor retry */
224 Result = ioctl(pDev[DeviceFD].fd, DS_ENTER, &ds);
225 SCSI_CloseDevice(DeviceFD);
229 RET(&ds) = DSRT_DEVSCSI;
230 SCSI_CloseDevice(DeviceFD);
233 DecodeSCSI(CDB, "SCSI_ExecuteCommand : ");
234 dbprintf(("\t\t\tSTATUS(%02X) RET(%02X)\n", STATUS(&ds), RET(&ds)));
237 case ST_BUSY: /* BUSY */
239 case STA_RESERV: /* RESERV CONFLICT */
243 case ST_GOOD: /* GOOD 0x00 */
256 case ST_CHECK: /* CHECK CONDITION 0x02 */
268 case ST_COND_MET: /* INTERM/GOOD 0x10 */
276 int Tape_Ioctl ( int DeviceFD, int command)
278 extern OpenFiles_T *pDev;
281 if (pDev[DeviceFD].devopen == 0)
283 if (SCSI_OpenDevice(DeviceFD) == 0)
290 mtop.mt_op = MTUNLOAD;
297 ioctl(pDev[DeviceFD].fd, MTIOCTOP, &mtop);
298 SCSI_CloseDevice(DeviceFD);
302 int Tape_Status( int DeviceFD)
304 extern OpenFiles_T *pDev;
308 if (pDev[DeviceFD].devopen == 0)
310 if (SCSI_OpenDevice(DeviceFD) == 0)
314 if (ioctl(pDev[DeviceFD].fd , MTIOCGET, &mtget) != 0)
316 dbprintf(("Tape_Status error ioctl %d\n",errno));
317 SCSI_CloseDevice(DeviceFD);
321 switch(mtget.mt_dposn)
324 ret = ret | TAPE_EOT;
327 ret = ret | TAPE_BOT;
330 ret = ret | TAPE_WR_PROT;
343 SCSI_CloseDevice(DeviceFD);
347 int ScanBus(int print)
350 struct dirent *dirent;
351 extern OpenFiles_T *pDev;
355 if ((dir = opendir("/dev/scsi")) == NULL)
357 dbprintf(("Can not read /dev/scsi: %s", strerror(errno)));
361 while ((dirent = readdir(dir)) != NULL)
363 if (strstr(dirent->d_name, "sc") != NULL)
365 pDev[count].dev = malloc(10);
366 pDev[count].inqdone = 0;
367 sprintf(pDev[count].dev,"/dev/scsi/%s", dirent->d_name);
368 if (OpenDevice(count,pDev[count].dev, "Scan", NULL ))
370 SCSI_CloseDevice(count);
371 pDev[count].inqdone = 0;
375 printf("name /dev/scsi/%s ", dirent->d_name);
377 switch (pDev[count].inquiry->type)
410 printf("unknown %d",pDev[count].inquiry->type);
416 printf("Count %d\n",count);
418 free(pDev[count].dev);
419 pDev[count].dev=NULL;
429 * indent-tabs-mode: nil