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.23 2006/05/25 01:47:08 johnfranks 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.23 2006/05/25 01:47:08 johnfranks 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;
120 /* inquiry failed or no SCSI communication available */
122 free(pDev[ip].inquiry);
123 pDev[ip].inquiry = NULL;
128 if ((DeviceFD = open(pDev[ip].dev, O_RDWR | O_EXCL)) >= 0)
130 pDev[ip].fd = DeviceFD;
131 pDev[ip].devopen = 1;
134 pDev[ip].devopen = 0;
141 int SCSI_CloseDevice(int DeviceFD)
143 extern OpenFiles_T *pDev;
146 if (pDev[DeviceFD].devopen == 1)
148 pDev[DeviceFD].devopen = 0;
149 ret = close(pDev[DeviceFD].fd);
155 int SCSI_ExecuteCommand(int DeviceFD,
156 Direction_T Direction,
160 size_t DataBufferLength,
161 RequestSense_T *pRequestSense,
162 size_t RequestSenseLength)
164 extern OpenFiles_T *pDev;
165 ExtendedRequestSense_T ExtendedRequestSense;
170 /* Basic sanity checks */
171 assert(CDB_Length <= UCHAR_MAX);
172 assert(RequestSenseLength <= UCHAR_MAX);
174 /* Clear buffer for cases where sense is not returned */
175 memset(pRequestSense, 0, RequestSenseLength);
177 if (pDev[DeviceFD].avail == 0)
182 memset(&ds, 0, SIZEOF(struct dsreq));
183 memset(pRequestSense, 0, RequestSenseLength);
184 memset(&ExtendedRequestSense, 0 , SIZEOF(ExtendedRequestSense_T));
186 ds.ds_flags = DSRQ_SENSE|DSRQ_TRACE|DSRQ_PRINT;
190 ds.ds_cmdbuf = (caddr_t)CDB;
191 ds.ds_cmdlen = CDB_Length;
192 /* Data buffer for results */
193 ds.ds_databuf = (caddr_t)DataBuffer;
194 ds.ds_datalen = DataBufferLength;
196 ds.ds_sensebuf = (caddr_t)pRequestSense;
197 ds.ds_senselen = RequestSenseLength;
202 ds.ds_flags = ds.ds_flags | DSRQ_READ;
205 ds.ds_flags = ds.ds_flags | DSRQ_WRITE;
209 while (--retries > 0) {
210 if (pDev[DeviceFD].devopen == 0)
212 if (SCSI_OpenDevice(DeviceFD) == 0)
214 dbprintf(("SCSI_ExecuteCommand could not open %s: %s\n",
217 sleep(1); /* Give device a little time befor retry */
221 Result = ioctl(pDev[DeviceFD].fd, DS_ENTER, &ds);
222 SCSI_CloseDevice(DeviceFD);
226 RET(&ds) = DSRT_DEVSCSI;
227 SCSI_CloseDevice(DeviceFD);
230 DecodeSCSI(CDB, "SCSI_ExecuteCommand : ");
231 dbprintf(("\t\t\tSTATUS(%02X) RET(%02X)\n", STATUS(&ds), RET(&ds)));
234 case ST_BUSY: /* BUSY */
237 case STA_RESERV: /* RESERV CONFLICT */
242 case ST_GOOD: /* GOOD 0x00 */
250 case ST_CHECK: /* CHECK CONDITION 0x02 */
258 case ST_COND_MET: /* INTERM/GOOD 0x10 */
266 int Tape_Ioctl ( int DeviceFD, int command)
268 extern OpenFiles_T *pDev;
271 if (pDev[DeviceFD].devopen == 0)
273 if (SCSI_OpenDevice(DeviceFD) == 0)
280 mtop.mt_op = MTUNLOAD;
287 ioctl(pDev[DeviceFD].fd, MTIOCTOP, &mtop);
288 SCSI_CloseDevice(DeviceFD);
292 int Tape_Status( int DeviceFD)
294 extern OpenFiles_T *pDev;
298 if (pDev[DeviceFD].devopen == 0)
300 if (SCSI_OpenDevice(DeviceFD) == 0)
304 if (ioctl(pDev[DeviceFD].fd , MTIOCGET, &mtget) != 0)
306 dbprintf(("Tape_Status error ioctl %s\n",strerror(errno)));
307 SCSI_CloseDevice(DeviceFD);
311 switch(mtget.mt_dposn)
314 ret = ret | TAPE_EOT;
317 ret = ret | TAPE_BOT;
320 ret = ret | TAPE_WR_PROT;
333 SCSI_CloseDevice(DeviceFD);
337 int ScanBus(int print)
340 struct dirent *dirent;
341 extern OpenFiles_T *pDev;
345 if ((dir = opendir("/dev/scsi")) == NULL)
347 dbprintf(("Can not read /dev/scsi: %s", strerror(errno)));
351 while ((dirent = readdir(dir)) != NULL)
353 if (strstr(dirent->d_name, "sc") != NULL)
355 pDev[count].dev = malloc(10);
356 pDev[count].inqdone = 0;
357 sprintf(pDev[count].dev,"/dev/scsi/%s", dirent->d_name);
358 if (OpenDevice(count,pDev[count].dev, "Scan", NULL ))
360 SCSI_CloseDevice(count);
361 pDev[count].inqdone = 0;
365 printf("name /dev/scsi/%s ", dirent->d_name);
367 switch (pDev[count].inquiry->type)
400 printf("unknown %d",pDev[count].inquiry->type);
406 printf("Count %d\n",count);
408 free(pDev[count].dev);
409 pDev[count].dev=NULL;
419 * indent-tabs-mode: nil