1 /* Changes 2003 Steve Heck <steve.heck@am.sony.com>
2 Copyright 2007-2008 by Robert Nelson <robertn@the-nelsons.org>
4 $Date: 2008-08-19 03:03:38 -0700 (Tue, 19 Aug 2008) $
7 This program is free software; you may redistribute and/or modify it under
8 the terms of the GNU General Public License Version 2 as published by the
9 Free Software Foundation.
11 This program is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 /* This is the SCSI commands for AIX using GSC Generic SCSI Interface. */
21 #define LONG_PRINT_REQUEST_SENSE /* sigh! */
23 DEVICE_TYPE SCSI_OpenDevice(char *DeviceName)
25 int DeviceFD = open(DeviceName, 0);
28 FatalError("cannot open SCSI device '%s' - %m\n", DeviceName);
29 return (DEVICE_TYPE) DeviceFD;
33 void SCSI_CloseDevice(char *DeviceName, DEVICE_TYPE DeviceFD)
35 if (close(DeviceFD) < 0)
36 FatalError("cannot close SCSI device '%s' - %m\n", DeviceName);
40 #define HAS_SCSI_TIMEOUT
42 static int timeout = 9 * 60;
44 void SCSI_Set_Timeout(int to)
49 void SCSI_Default_Timeout(void)
51 timeout = 9 * 60; /* the default */
55 int SCSI_DumpBuffer(int DataBufferLength, unsigned char *DataBuffer)
60 for (i = 0; i < DataBufferLength; i++)
64 fprintf(stderr, "\n");
70 fprintf(stderr, "%04x:", i);
78 fprintf(stderr, "%02x", (int)DataBuffer[i]);
81 fprintf(stderr, "\n");
87 int SCSI_ExecuteCommand(DEVICE_TYPE DeviceFD,
88 Direction_T Direction,
93 RequestSense_T *RequestSense)
100 fprintf(stderr,"------CDB--------\n");
101 SCSI_DumpBuffer(CDB_Length,(char *)CDB);
104 /* memset(&scmd, 0, sizeof(struct scmd_t)); */
105 /* memset(RequestSense, 0, sizeof(RequestSense_T)); */
110 if (DataBufferLength > 0)
112 memset(DataBuffer, 0, DataBufferLength);
120 /* Set timeout to 5 minutes. */
122 fprintf(stderr,"timeout=%d\n",timeout);
126 scmd.timeval = timeout;
128 scmd.cdb = (caddr_t) CDB;
129 scmd.cdblen = CDB_Length;
130 scmd.data_buf = DataBuffer;
131 scmd.datalen = DataBufferLength;
132 scmd.sense_buf = (caddr_t) RequestSense;
133 scmd.senselen = sizeof(RequestSense_T);
134 scmd.statusp = &sbyte;
135 ioctl_result = ioctl(DeviceFD, GSC_CMD, (caddr_t) &scmd);
137 SCSI_Default_Timeout(); /* set it back to default, sigh. */
139 if (ioctl_result < 0)
152 if (Direction==Input)
154 fprintf(stderr,"--------input data-----------\n");
155 SCSI_DumpBuffer(DataBufferLength,DataBuffer);