1 /* Copyright 1997, 1998 Leonard Zubkoff <lnz@dandelion.com>
2 Changes copyright 2000 Eric Green <eric@badtux.org>
4 $Date: 2007-03-04 15:27:11 -0800 (Sun, 04 Mar 2007) $
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
18 /* This is the SCSI commands for Sun Solaris. */
20 #define LONG_PRINT_REQUEST_SENSE /* sigh! */
22 DEVICE_TYPE SCSI_OpenDevice(char *DeviceName)
24 int DeviceFD = open(DeviceName, O_RDWR | O_NDELAY);
26 FatalError("cannot open SCSI device '%s' - %m\n", DeviceName);
27 return (DEVICE_TYPE) DeviceFD;
31 void SCSI_CloseDevice(char *DeviceName, DEVICE_TYPE DeviceFD)
33 if (close(DeviceFD) < 0)
34 FatalError("cannot close SCSI device '%s' - %m\n", DeviceName);
38 #define HAS_SCSI_TIMEOUT
40 static int uscsi_timeout=5*60;
42 void SCSI_Set_Timeout(int to)
47 void SCSI_Default_Timeout(void)
49 uscsi_timeout=5*60; /* the default */
53 int SCSI_DumpBuffer(int DataBufferLength, unsigned char *DataBuffer)
58 for (i = 0; i < DataBufferLength; i++)
68 fprintf(stderr, "%04x:", i);
76 fprintf(stderr, "%02x", (int)DataBuffer[i]);
79 fprintf(stderr, "\n");
84 int SCSI_ExecuteCommand(DEVICE_TYPE DeviceFD,
85 Direction_T Direction,
90 RequestSense_T *RequestSense)
93 struct uscsi_cmd Command;
96 fprintf(stderr,"------CDB--------\n");
97 SCSI_DumpBuffer(CDB_Length,(char *)CDB);
100 memset(&Command, 0, sizeof(struct uscsi_cmd));
101 memset(RequestSense, 0, sizeof(RequestSense_T));
105 Command.uscsi_flags = USCSI_DIAGNOSE | USCSI_ISOLATE | USCSI_RQENABLE;
106 if (DataBufferLength > 0)
108 memset(DataBuffer, 0, DataBufferLength);
109 Command.uscsi_flags |= USCSI_READ;
113 Command.uscsi_flags = USCSI_DIAGNOSE | USCSI_ISOLATE |
114 USCSI_WRITE | USCSI_RQENABLE;
117 /* Set timeout to 5 minutes. */
119 fprintf(stderr,"uscsi_timeout=%d\n",uscsi_timeout);
122 Command.uscsi_timeout = uscsi_timeout;
124 Command.uscsi_cdb = (caddr_t) CDB;
125 Command.uscsi_cdblen = CDB_Length;
126 Command.uscsi_bufaddr = DataBuffer;
127 Command.uscsi_buflen = DataBufferLength;
128 Command.uscsi_rqbuf = (caddr_t) RequestSense;
129 Command.uscsi_rqlen = sizeof(RequestSense_T);
130 ioctl_result = ioctl(DeviceFD, USCSICMD, &Command);
132 SCSI_Default_Timeout(); /* set it back to default, sigh. */
134 if (ioctl_result < 0)
142 if (RequestSense->ErrorCode > 1)
148 if (Direction==Input)
150 fprintf(stderr,"--------input data-----------\n");
151 SCSI_DumpBuffer(DataBufferLength, DataBuffer);