fix lintian issues
[debian/mtx] / scsi_sgi.c
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>
4
5 $Date: 2008-08-19 03:03:38 -0700 (Tue, 19 Aug 2008) $
6 $Revision: 193 $
7
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.
11
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
15   for complete details.
16
17 */
18
19 /* This is the SCSI commands for SGI Iris */
20 DEVICE_TYPE SCSI_OpenDevice(char *DeviceName)
21 {
22         dsreq_t *DeviceFD = dsopen(DeviceName, O_RDWR | O_EXCL);
23         if (DeviceFD == 0)
24                 FatalError("cannot open SCSI device '%s' - %m\n", DeviceName);
25         return (DEVICE_TYPE) DeviceFD;
26 }
27
28
29 void SCSI_CloseDevice(char *DeviceName, DEVICE_TYPE DeviceFD)
30 {
31         dsclose((dsreq_t *) DeviceFD);
32 }
33
34 #define MTX_HZ 1000 
35 #define MTX_DEFAULT_SCSI_TIMEOUT 60*5*MTX_HZ /* 5 minutes! */
36
37 static int mtx_default_timeout = MTX_DEFAULT_SCSI_TIMEOUT ;
38 void SCSI_Set_Timeout(int sec)
39 {
40         mtx_default_timeout=sec*MTX_HZ;
41 }
42
43 void SCSI_Default_Timeout()
44 {
45         mtx_default_timeout=MTX_DEFAULT_SCSI_TIMEOUT;
46 }
47
48 int SCSI_ExecuteCommand(DEVICE_TYPE DeviceFD,
49                                                 Direction_T Direction,
50                                                 CDB_T *CDB,
51                                                 int CDB_Length,
52                                                 void *DataBuffer,
53                                                 int DataBufferLength,
54                                                 RequestSense_T *RequestSense)
55 {
56         dsreq_t *dsp = (dsreq_t *) DeviceFD;
57         int Result;
58         memset(RequestSense, 0, sizeof(RequestSense_T));
59         memcpy(CMDBUF(dsp), CDB, CDB_Length);
60
61         if (Direction == Input)
62         {
63                 memset(DataBuffer, 0, DataBufferLength);
64                 filldsreq(dsp, (unsigned char *) DataBuffer, DataBufferLength, DSRQ_READ | DSRQ_SENSE);
65         }
66         else
67                 filldsreq(dsp, (unsigned char *) DataBuffer, DataBufferLength, DSRQ_WRITE | DSRQ_SENSE);
68
69         /* Set 5 minute timeout. */
70         /* TIME(dsp) = 300 * 1000; */
71         TIME(dsp) = mtx_default_timeout;
72         Result = doscsireq(getfd((dsp)), dsp);
73         
74         if (SENSESENT(dsp) > 0)
75         {
76                 memcpy(RequestSense, SENSEBUF(dsp), min(sizeof(RequestSense_T), SENSESENT(dsp)));
77         }
78
79         SCSI_Default_Timeout(); /* reset the mtx default timeout */
80         return Result;
81 }