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 $Date: 2008-08-19 03:03:38 -0700 (Tue, 19 Aug 2008) $
8 This program is free software; you may redistribute and/or modify it under
9 the terms of the GNU General Public License Version 2 as published by the
10 Free Software Foundation.
12 This program is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 /* This is the SCSI commands for Sun Solaris. */
21 #define LONG_PRINT_REQUEST_SENSE /* sigh! */
23 DEVICE_TYPE SCSI_OpenDevice(char *DeviceName)
25 int DeviceFD = open(DeviceName, O_RDWR | O_NDELAY);
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 uscsi_timeout=5*60;
43 void SCSI_Set_Timeout(int to)
48 void SCSI_Default_Timeout(void)
50 uscsi_timeout=5*60; /* the default */
54 int SCSI_DumpBuffer(int DataBufferLength, unsigned char *DataBuffer)
59 for (i = 0; i < DataBufferLength; i++)
69 fprintf(stderr, "%04x:", i);
77 fprintf(stderr, "%02x", (int)DataBuffer[i]);
80 fprintf(stderr, "\n");
85 int SCSI_ExecuteCommand(DEVICE_TYPE DeviceFD,
86 Direction_T Direction,
91 RequestSense_T *RequestSense)
94 struct uscsi_cmd Command;
97 fprintf(stderr,"------CDB--------\n");
98 SCSI_DumpBuffer(CDB_Length,(char *)CDB);
101 memset(&Command, 0, sizeof(struct uscsi_cmd));
102 memset(RequestSense, 0, sizeof(RequestSense_T));
106 Command.uscsi_flags = USCSI_DIAGNOSE | USCSI_ISOLATE | USCSI_RQENABLE;
107 if (DataBufferLength > 0)
109 memset(DataBuffer, 0, DataBufferLength);
110 Command.uscsi_flags |= USCSI_READ;
114 Command.uscsi_flags = USCSI_DIAGNOSE | USCSI_ISOLATE |
115 USCSI_WRITE | USCSI_RQENABLE;
118 /* Set timeout to 5 minutes. */
120 fprintf(stderr,"uscsi_timeout=%d\n",uscsi_timeout);
123 Command.uscsi_timeout = uscsi_timeout;
125 Command.uscsi_cdb = (caddr_t) CDB;
126 Command.uscsi_cdblen = CDB_Length;
127 Command.uscsi_bufaddr = DataBuffer;
128 Command.uscsi_buflen = DataBufferLength;
129 Command.uscsi_rqbuf = (caddr_t) RequestSense;
130 Command.uscsi_rqlen = sizeof(RequestSense_T);
131 ioctl_result = ioctl(DeviceFD, USCSICMD, &Command);
133 SCSI_Default_Timeout(); /* set it back to default, sigh. */
135 if (ioctl_result < 0)
143 if (RequestSense->ErrorCode > 1)
149 if (Direction==Input)
151 fprintf(stderr,"--------input data-----------\n");
152 SCSI_DumpBuffer(DataBufferLength, DataBuffer);