1 /* Copyright 1997, 1998 Leonard Zubkoff <lnz@dandelion.com>
2 Changes copyright 2000 Eric Green <eric@badtux.org>
3 Copyright 2007-2008 by Robert Nelson <robertn@the-nelsons.org>
5 This program is free software; you may redistribute and/or modify it under
6 the terms of the GNU General Public License Version 2 as published by the
7 Free Software Foundation.
9 This program is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
11 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 unsigned flags; // IN: SCTL_READ
17 unsigned cdb_length; // IN
18 unsigned char cdb[16]; // IN
20 unsigned data_length; // IN
21 unsigned max_msecs; // IN: milli-seconds before abort
22 unsigned data_xfer; // OUT
23 unsigned cdb_status; // OUT: SCSI status
24 unsigned char sense[256]; // OUT
25 unsigned sense_status; // OUT: SCSI status
26 unsigned sense_xfer; // OUT: bytes of sense data received
27 unsigned reserved[16]; // IN: Must be zero; OUT: undefined
33 /* Hockey Pux may define these. If so, *UN*define them. */
42 /* This is the SCSI commands for HPUX. */
44 #define LONG_PRINT_REQUEST_SENSE /* Sigh! */
46 DEVICE_TYPE SCSI_OpenDevice(char *DeviceName)
48 int DeviceFD = open(DeviceName, O_RDWR | O_NDELAY);
51 FatalError("cannot open SCSI device '%s' - %m\n", DeviceName);
53 return (DEVICE_TYPE) DeviceFD;
57 void SCSI_CloseDevice(char *DeviceName, DEVICE_TYPE DeviceFD)
59 if (close(DeviceFD) < 0)
60 FatalError("cannot close SCSI device '%s' - %m\n", DeviceName);
64 #define DEFAULT_HZ (5*60*MTX_HZ)
66 static int sctl_io_timeout=DEFAULT_HZ; /* default timeout is 5 minutes. */
69 void SCSI_Set_Timeout(int to)
71 sctl_io_timeout=to*60*MTX_HZ;
74 void SCSI_Default_Timeout(void)
76 sctl_io_timeout=DEFAULT_HZ;
80 int SCSI_ExecuteCommand(DEVICE_TYPE DeviceFD,
81 Direction_T Direction,
86 RequestSense_T *RequestSense)
89 struct sctl_io Command;
93 memset(&Command, 0, sizeof(struct sctl_io));
94 memset(RequestSense, 0, sizeof(RequestSense_T));
99 if (DataBufferLength > 0)
100 memset(DataBuffer, 0, DataBufferLength);
101 Command.flags = SCTL_READ | SCTL_INIT_SDTR;
105 Command.flags = SCTL_INIT_WDTR | SCTL_INIT_SDTR;
109 Command.max_msecs = sctl_io_timeout; /* Set timeout to <n> minutes. */
110 memcpy(Command.cdb, CDB, CDB_Length);
111 Command.cdb_length = CDB_Length;
112 Command.data = DataBuffer;
113 Command.data_length = DataBufferLength;
114 ioctl_result=ioctl(DeviceFD, SIOC_IO, &Command);
115 SCSI_Default_Timeout(); /* change the default back to 5 minutes */
117 if (ioctl_result < 0)
123 if (Command.sense_xfer > sizeof(RequestSense_T))
125 Command.sense_xfer=sizeof(RequestSense_T);
128 if (Command.sense_xfer)
130 memcpy(RequestSense, Command.sense, Command.sense_xfer);
133 return Command.sense_status;