1 /* Changes 2003 Steve Heck <steve.heck@am.sony.com>
3 $Date: 2007-03-04 15:27:11 -0800 (Sun, 04 Mar 2007) $
6 This program is free software; you may redistribute and/or modify it under
7 the terms of the GNU General Public License Version 2 as published by the
8 Free Software Foundation.
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
12 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 /* This is the SCSI commands for AIX using GSC Generic SCSI Interface. */
20 #define LONG_PRINT_REQUEST_SENSE /* sigh! */
22 DEVICE_TYPE SCSI_OpenDevice(char *DeviceName)
24 int DeviceFD = open(DeviceName, 0);
27 FatalError("cannot open SCSI device '%s' - %m\n", DeviceName);
28 return (DEVICE_TYPE) DeviceFD;
32 void SCSI_CloseDevice(char *DeviceName, DEVICE_TYPE DeviceFD)
34 if (close(DeviceFD) < 0)
35 FatalError("cannot close SCSI device '%s' - %m\n", DeviceName);
39 #define HAS_SCSI_TIMEOUT
41 static int timeout = 9 * 60;
43 void SCSI_Set_Timeout(int to)
48 void SCSI_Default_Timeout(void)
50 timeout = 9 * 60; /* the default */
54 int SCSI_DumpBuffer(int DataBufferLength, unsigned char *DataBuffer)
59 for (i = 0; i < DataBufferLength; i++)
63 fprintf(stderr, "\n");
69 fprintf(stderr, "%04x:", i);
77 fprintf(stderr, "%02x", (int)DataBuffer[i]);
80 fprintf(stderr, "\n");
86 int SCSI_ExecuteCommand(DEVICE_TYPE DeviceFD,
87 Direction_T Direction,
92 RequestSense_T *RequestSense)
99 fprintf(stderr,"------CDB--------\n");
100 SCSI_DumpBuffer(CDB_Length,(char *)CDB);
103 /* memset(&scmd, 0, sizeof(struct scmd_t)); */
104 /* memset(RequestSense, 0, sizeof(RequestSense_T)); */
109 if (DataBufferLength > 0)
111 memset(DataBuffer, 0, DataBufferLength);
119 /* Set timeout to 5 minutes. */
121 fprintf(stderr,"timeout=%d\n",timeout);
125 scmd.timeval = timeout;
127 scmd.cdb = (caddr_t) CDB;
128 scmd.cdblen = CDB_Length;
129 scmd.data_buf = DataBuffer;
130 scmd.datalen = DataBufferLength;
131 scmd.sense_buf = (caddr_t) RequestSense;
132 scmd.senselen = sizeof(RequestSense_T);
133 scmd.statusp = &sbyte;
134 ioctl_result = ioctl(DeviceFD, GSC_CMD, (caddr_t) &scmd);
136 SCSI_Default_Timeout(); /* set it back to default, sigh. */
138 if (ioctl_result < 0)
151 if (Direction==Input)
153 fprintf(stderr,"--------input data-----------\n");
154 SCSI_DumpBuffer(DataBufferLength,DataBuffer);