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.19 2006/05/25 01:47:08 johnfranks Exp $
29 * Interface to execute SCSI commands on an HP-UX Workstation
31 * Copyright (c) Thomas Hepper th@ant.han.de
40 #include <scsi-defs.h>
42 void SCSI_OS_Version()
45 static char rcsid[] = "$Id: scsi-hpux_new.c,v 1.19 2006/05/25 01:47:08 johnfranks Exp $";
46 DebugPrint(DEBUG_INFO, SECTION_INFO, "scsi-os-layer: %s\n",rcsid);
50 int SCSI_OpenDevice(int ip)
52 extern OpenFiles_T *pDev;
56 if (pDev[ip].inqdone == 0)
59 if ((DeviceFD = open(pDev[ip].dev, O_RDWR| O_NDELAY)) >= 0)
62 pDev[ip].fd = DeviceFD;
65 pDev[ip].inquiry = (SCSIInquiry_T *)malloc(INQUIRY_SIZE);
67 if (SCSI_Inquiry(ip, pDev[ip].inquiry, INQUIRY_SIZE) == 0)
69 if (pDev[ip].inquiry->type == TYPE_TAPE || pDev[ip].inquiry->type == TYPE_CHANGER)
72 pDev[ip].ident[i] = pDev[ip].inquiry->prod_ident[i];
73 for (i=15; i >= 0 && !isalnum(pDev[ip].inquiry->prod_ident[i]) ; i--)
75 pDev[ip].inquiry->prod_ident[i] = '\0';
79 if (pDev[ip].inquiry->type == TYPE_TAPE)
81 pDev[ip].type = stralloc("tape");
84 if (pDev[ip].inquiry->type == TYPE_CHANGER)
86 pDev[ip].type = stralloc("changer");
89 PrintInquiry(pDev[ip].inquiry);
93 free(pDev[ip].inquiry);
98 free(pDev[ip].inquiry);
99 pDev[ip].inquiry = NULL;
103 if ((DeviceFD = open(pDev[ip].dev, O_RDWR| O_NDELAY)) >= 0)
105 pDev[ip].fd = DeviceFD;
106 pDev[ip].devopen = 1;
114 int SCSI_CloseDevice(int DeviceFD)
116 extern OpenFiles_T *pDev;
119 ret = close(pDev[DeviceFD].fd);
120 pDev[DeviceFD].devopen = 0;
124 int SCSI_ExecuteCommand(int DeviceFD,
125 Direction_T Direction,
129 size_t DataBufferLength,
130 RequestSense_T *RequestSenseBuf,
131 size_t RequestSenseLength)
133 extern OpenFiles_T *pDev;
134 struct sctl_io sctl_io;
136 int Zero = 0, Result;
138 /* Basic sanity checks */
139 assert(CDB_Length <= UCHAR_MAX);
140 assert(RequestSenseLength <= UCHAR_MAX);
142 /* Clear buffer for cases where sense is not returned */
143 memset(RequestSenseBuf, 0, RequestSenseLength);
145 if (pDev[DeviceFD].avail == 0)
151 memset(&sctl_io, '\0', SIZEOF(struct sctl_io));
154 sctl_io.max_msecs = 240000;
156 memcpy(sctl_io.cdb, CDB, CDB_Length);
157 sctl_io.cdb_length = CDB_Length;
158 /* Data buffer for results */
159 sctl_io.data = DataBuffer;
160 sctl_io.data_length = (unsigned)DataBufferLength;
165 sctl_io.flags = sctl_io.flags | SCTL_READ;
171 while (--Retries > 0) {
173 if (pDev[DeviceFD].devopen == 0)
175 if (SCSI_OpenDevice(DeviceFD) == 0)
177 dbprintf(_("SCSI_ExecuteCommand could not open %s: %s\n"),
180 sleep(1); /* Give device a little time befor retry */
185 DecodeSCSI(CDB, "SCSI_ExecuteCommand : ");
186 Result = ioctl(pDev[DeviceFD].fd, SIOC_IO, &sctl_io);
187 SCSI_CloseDevice(DeviceFD);
193 SCSI_CloseDevice(DeviceFD);
195 memcpy(RequestSenseBuf, sctl_io.sense, RequestSenseLength);
197 switch(sctl_io.cdb_status)
202 case S_CHECK_CONDITION:
212 * Send the command to the device with the
215 int Tape_Ioctl( int DeviceFD, int command)
217 extern OpenFiles_T *pDev;
221 if (pDev[DeviceFD].devopen == 0)
222 if (SCSI_OpenDevice(DeviceFD) == 0)
236 if (ioctl(pDev[DeviceFD].fd , MTIOCTOP, &mtop) != 0)
238 dbprintf(_("Tape_Ioctl error ioctl %s\n"), strerror(errno));
239 SCSI_CloseDevice(DeviceFD);
243 SCSI_CloseDevice(DeviceFD);
249 int Tape_Status( int DeviceFD)
251 extern OpenFiles_T *pDev;
255 if (pDev[DeviceFD].devopen == 0)
256 if (SCSI_OpenDevice(DeviceFD) == 0)
259 if (ioctl(pDev[DeviceFD].fd, MTIOCGET, &mtget) != 0)
261 dbprintf(_("Tape_Status error ioctl %s\n"), strerror(errno));
262 SCSI_CloseDevice(DeviceFD);
266 dbprintf(_("ioctl -> mtget.mt_gstat %X\n"),mtget.mt_gstat);
267 if (GMT_ONLINE(mtget.mt_gstat))
272 if (GMT_BOT(mtget.mt_gstat))
274 ret = ret | TAPE_BOT;
277 if (GMT_EOT(mtget.mt_gstat))
279 ret = ret | TAPE_EOT;
282 if (GMT_WR_PROT(mtget.mt_gstat))
284 ret = ret | TAPE_WR_PROT;
287 SCSI_CloseDevice(DeviceFD);
291 int ScanBus(int print)
300 * indent-tabs-mode: nil