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-hpux_new.c,v 1.18 2005/10/15 13:20:47 martinea Exp $
29 * Interface to execute SCSI commands on an HP-UX Workstation
31 * Copyright (c) Thomas Hepper th@ant.han.de
37 #ifdef HAVE_HPUX_LIKE_SCSI
49 #ifdef HAVE_SYS_IOCTL_H
50 #include <sys/ioctl.h>
52 #ifdef HAVE_SYS_SCSI_H
58 #include <scsi-defs.h>
60 void SCSI_OS_Version()
63 static char rcsid[] = "$Id: scsi-hpux_new.c,v 1.18 2005/10/15 13:20:47 martinea Exp $";
64 DebugPrint(DEBUG_INFO, SECTION_INFO, "scsi-os-layer: %s\n",rcsid);
68 int SCSI_OpenDevice(int ip)
70 extern OpenFiles_T *pDev;
74 if (pDev[ip].inqdone == 0)
77 if ((DeviceFD = open(pDev[ip].dev, O_RDWR| O_NDELAY)) >= 0)
80 pDev[ip].fd = DeviceFD;
83 pDev[ip].inquiry = (SCSIInquiry_T *)malloc(INQUIRY_SIZE);
85 if (SCSI_Inquiry(ip, pDev[ip].inquiry, INQUIRY_SIZE) == 0)
87 if (pDev[ip].inquiry->type == TYPE_TAPE || pDev[ip].inquiry->type == TYPE_CHANGER)
90 pDev[ip].ident[i] = pDev[ip].inquiry->prod_ident[i];
91 for (i=15; i >= 0 && !isalnum(pDev[ip].inquiry->prod_ident[i]) ; i--)
93 pDev[ip].inquiry->prod_ident[i] = '\0';
97 if (pDev[ip].inquiry->type == TYPE_TAPE)
99 pDev[ip].type = stralloc("tape");
102 if (pDev[ip].inquiry->type == TYPE_CHANGER)
104 pDev[ip].type = stralloc("changer");
107 PrintInquiry(pDev[ip].inquiry);
111 free(pDev[ip].inquiry);
116 free(pDev[ip].inquiry);
117 pDev[ip].inquiry = NULL;
123 if ((DeviceFD = open(pDev[ip].dev, O_RDWR| O_NDELAY)) >= 0)
125 pDev[ip].fd = DeviceFD;
126 pDev[ip].devopen = 1;
134 int SCSI_CloseDevice(int DeviceFD)
136 extern OpenFiles_T *pDev;
139 ret = close(pDev[DeviceFD].fd);
140 pDev[DeviceFD].devopen = 0;
144 int SCSI_ExecuteCommand(int DeviceFD,
145 Direction_T Direction,
149 int DataBufferLength,
151 int RequestSenseLength)
153 extern OpenFiles_T *pDev;
154 struct sctl_io sctl_io;
157 int Zero = 0, Result;
159 if (pDev[DeviceFD].avail == 0)
165 memset(&sctl_io, '\0', sizeof(struct sctl_io));
168 sctl_io.max_msecs = 240000;
170 memcpy(sctl_io.cdb, CDB, CDB_Length);
171 sctl_io.cdb_length = CDB_Length;
172 /* Data buffer for results */
173 sctl_io.data = DataBuffer;
174 sctl_io.data_length = (unsigned)DataBufferLength;
179 sctl_io.flags = sctl_io.flags | SCTL_READ;
185 while (--Retries > 0) {
187 if (pDev[DeviceFD].devopen == 0)
189 if (SCSI_OpenDevice(DeviceFD) == 0)
191 dbprintf(("SCSI_ExecuteCommand could not open %s: %s\n",
194 sleep(1); /* Give device a little time befor retry */
199 DecodeSCSI(CDB, "SCSI_ExecuteCommand : ");
200 Result = ioctl(pDev[DeviceFD].fd, SIOC_IO, &sctl_io);
201 SCSI_CloseDevice(DeviceFD);
207 SCSI_CloseDevice(DeviceFD);
209 memcpy(RequestSense, sctl_io.sense, RequestSenseLength);
211 switch(sctl_io.cdb_status)
215 case S_CHECK_CONDITION:
226 * Send the command to the device with the
229 int Tape_Ioctl( int DeviceFD, int command)
231 extern OpenFiles_T *pDev;
235 if (pDev[DeviceFD].devopen == 0)
236 if (SCSI_OpenDevice(DeviceFD) == 0)
249 if (ioctl(pDev[DeviceFD].fd , MTIOCTOP, &mtop) != 0)
251 dbprintf(("Tape_Ioctl error ioctl %d\n",errno));
252 SCSI_CloseDevice(DeviceFD);
256 SCSI_CloseDevice(DeviceFD);
262 int Tape_Status( int DeviceFD)
264 extern OpenFiles_T *pDev;
268 if (pDev[DeviceFD].devopen == 0)
269 if (SCSI_OpenDevice(DeviceFD) == 0)
272 if (ioctl(pDev[DeviceFD].fd, MTIOCGET, &mtget) != 0)
274 dbprintf(("Tape_Status error ioctl %d\n",errno));
275 SCSI_CloseDevice(DeviceFD);
279 dbprintf(("ioctl -> mtget.mt_gstat %X\n",mtget.mt_gstat));
280 if (GMT_ONLINE(mtget.mt_gstat))
285 if (GMT_BOT(mtget.mt_gstat))
287 ret = ret | TAPE_BOT;
290 if (GMT_EOT(mtget.mt_gstat))
292 ret = ret | TAPE_EOT;
295 if (GMT_WR_PROT(mtget.mt_gstat))
297 ret = ret | TAPE_WR_PROT;
300 SCSI_CloseDevice(DeviceFD);
304 int ScanBus(int print)
314 * indent-tabs-mode: nil