* file named AUTHORS, in the root directory of this distribution.
*/
/*
- * $Id: scsi-hpux_new.c,v 1.1.2.12.4.1.2.4 2003/06/05 20:44:23 martinea Exp $
+ * $Id: scsi-hpux_new.c,v 1.19 2006/05/25 01:47:08 johnfranks Exp $
*
* Interface to execute SCSI commands on an HP-UX Workstation
*
*/
-#include <amanda.h>
+#include "amanda.h"
-#ifdef HAVE_HPUX_LIKE_SCSI
-
-# ifdef HAVE_FCNTL_H
-#include <fcntl.h>
-#endif
-/*
-#ifdef HAVE_STDIO_H
-*/
-#include <stdio.h>
-/*
-#endif
-*/
-#ifdef HAVE_SYS_IOCTL_H
-#include <sys/ioctl.h>
-#endif
-#ifdef HAVE_SYS_SCSI_H
#include <sys/scsi.h>
-#endif
-
#include <sys/mtio.h>
#include <scsi-defs.h>
void SCSI_OS_Version()
{
#ifndef lint
- static char rcsid[] = "$Id: scsi-hpux_new.c,v 1.1.2.12.4.1.2.4 2003/06/05 20:44:23 martinea Exp $";
+ static char rcsid[] = "$Id: scsi-hpux_new.c,v 1.19 2006/05/25 01:47:08 johnfranks Exp $";
DebugPrint(DEBUG_INFO, SECTION_INFO, "scsi-os-layer: %s\n",rcsid);
#endif
}
if (pDev[ip].inqdone == 0)
{
pDev[ip].inqdone = 1;
- if ((DeviceFD = open(pDev[ip].dev, O_RDWR| O_NDELAY)) > 0)
+ if ((DeviceFD = open(pDev[ip].dev, O_RDWR| O_NDELAY)) >= 0)
{
pDev[ip].avail = 1;
pDev[ip].fd = DeviceFD;
free(pDev[ip].inquiry);
return(0);
}
- } else {
- close(DeviceFD);
- free(pDev[ip].inquiry);
- pDev[ip].inquiry = NULL;
- return(1);
}
- return(1);
+ close(DeviceFD);
+ free(pDev[ip].inquiry);
+ pDev[ip].inquiry = NULL;
+ return(1);
}
} else {
- if ((DeviceFD = open(pDev[ip].dev, O_RDWR| O_NDELAY)) > 0)
+ if ((DeviceFD = open(pDev[ip].dev, O_RDWR| O_NDELAY)) >= 0)
{
pDev[ip].fd = DeviceFD;
pDev[ip].devopen = 1;
int SCSI_ExecuteCommand(int DeviceFD,
Direction_T Direction,
CDB_T CDB,
- int CDB_Length,
+ size_t CDB_Length,
void *DataBuffer,
- int DataBufferLength,
- char *RequestSense,
- int RequestSenseLength)
+ size_t DataBufferLength,
+ RequestSense_T *RequestSenseBuf,
+ size_t RequestSenseLength)
{
extern OpenFiles_T *pDev;
struct sctl_io sctl_io;
- extern int errno;
int Retries = 3;
int Zero = 0, Result;
+ /* Basic sanity checks */
+ assert(CDB_Length <= UCHAR_MAX);
+ assert(RequestSenseLength <= UCHAR_MAX);
+
+ /* Clear buffer for cases where sense is not returned */
+ memset(RequestSenseBuf, 0, RequestSenseLength);
+
if (pDev[DeviceFD].avail == 0)
{
return(SCSI_ERROR);
}
- memset(&sctl_io, '\0', sizeof(struct sctl_io));
+ memset(&sctl_io, '\0', SIZEOF(struct sctl_io));
sctl_io.flags = 0;
sctl_io.max_msecs = 240000;
while (--Retries > 0) {
if (pDev[DeviceFD].devopen == 0)
- SCSI_OpenDevice(DeviceFD);
+ {
+ if (SCSI_OpenDevice(DeviceFD) == 0)
+ {
+ dbprintf(_("SCSI_ExecuteCommand could not open %s: %s\n"),
+ pDev[DeviceFD].dev,
+ strerror(errno));
+ sleep(1); /* Give device a little time befor retry */
+ continue;
+ }
+ }
DecodeSCSI(CDB, "SCSI_ExecuteCommand : ");
Result = ioctl(pDev[DeviceFD].fd, SIOC_IO, &sctl_io);
SCSI_CloseDevice(DeviceFD);
- memcpy(RequestSense, sctl_io.sense, RequestSenseLength);
+ memcpy(RequestSenseBuf, sctl_io.sense, RequestSenseLength);
switch(sctl_io.cdb_status)
{
case S_GOOD:
return(SCSI_OK);
+
case S_CHECK_CONDITION:
return(SCSI_CHECK);
- break;
+
default:
return(SCSI_ERROR);
- break;
}
}
return(SCSI_ERROR);
int ret = 0;
if (pDev[DeviceFD].devopen == 0)
- {
- SCSI_OpenDevice(DeviceFD);
- }
+ if (SCSI_OpenDevice(DeviceFD) == 0)
+ return(-1);
switch (command)
{
mtop.mt_op = MTOFFL;
mtop.mt_count = 1;
break;
+
default:
break;
}
if (ioctl(pDev[DeviceFD].fd , MTIOCTOP, &mtop) != 0)
{
- dbprintf(("Tape_Ioctl error ioctl %d\n",errno));
+ dbprintf(_("Tape_Ioctl error ioctl %s\n"), strerror(errno));
SCSI_CloseDevice(DeviceFD);
return(-1);
}
int ret = 0;
if (pDev[DeviceFD].devopen == 0)
- SCSI_OpenDevice(DeviceFD);
+ if (SCSI_OpenDevice(DeviceFD) == 0)
+ return(-1);
if (ioctl(pDev[DeviceFD].fd, MTIOCGET, &mtget) != 0)
{
- dbprintf(("Tape_Status error ioctl %d\n",errno));
+ dbprintf(_("Tape_Status error ioctl %s\n"), strerror(errno));
SCSI_CloseDevice(DeviceFD);
return(-1);
}
- dbprintf(("ioctl -> mtget.mt_gstat %X\n",mtget.mt_gstat));
+ dbprintf(_("ioctl -> mtget.mt_gstat %X\n"),mtget.mt_gstat);
if (GMT_ONLINE(mtget.mt_gstat))
{
ret = TAPE_ONLINE;
*/
return(-1);
}
-#endif
/*
* Local variables:
* indent-tabs-mode: nil