File: scsi_sgi.c

package info (click to toggle)
mtx 1.3.12-12
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 1,148 kB
  • sloc: ansic: 7,121; sh: 3,199; python: 203; perl: 117; makefile: 113
file content (81 lines) | stat: -rw-r--r-- 2,290 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/* Copyright 1997, 1998 Leonard Zubkoff <lnz@dandelion.com>
   Changes copyright 2000 Eric Green <eric@badtux.org>
   Copyright 2007-2008 by Robert Nelson <robertn@the-nelsons.org>

$Date: 2008-08-19 03:03:38 -0700 (Tue, 19 Aug 2008) $
$Revision: 193 $

  This program is free software; you may redistribute and/or modify it under
  the terms of the GNU General Public License Version 2 as published by the
  Free Software Foundation.

  This program is distributed in the hope that it will be useful, but
  WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  for complete details.

*/

/* This is the SCSI commands for SGI Iris */
DEVICE_TYPE SCSI_OpenDevice(char *DeviceName)
{
	dsreq_t *DeviceFD = dsopen(DeviceName, O_RDWR | O_EXCL);
	if (DeviceFD == 0)
		FatalError("cannot open SCSI device '%s' - %m\n", DeviceName);
	return (DEVICE_TYPE) DeviceFD;
}


void SCSI_CloseDevice(char *DeviceName, DEVICE_TYPE DeviceFD)
{
	dsclose((dsreq_t *) DeviceFD);
}

#define MTX_HZ 1000 
#define MTX_DEFAULT_SCSI_TIMEOUT 60*5*MTX_HZ /* 5 minutes! */

static int mtx_default_timeout = MTX_DEFAULT_SCSI_TIMEOUT ;
void SCSI_Set_Timeout(int sec)
{
	mtx_default_timeout=sec*MTX_HZ;
}

void SCSI_Default_Timeout()
{
	mtx_default_timeout=MTX_DEFAULT_SCSI_TIMEOUT;
}

int SCSI_ExecuteCommand(DEVICE_TYPE DeviceFD,
						Direction_T Direction,
						CDB_T *CDB,
						int CDB_Length,
						void *DataBuffer,
						int DataBufferLength,
						RequestSense_T *RequestSense)
{
	dsreq_t *dsp = (dsreq_t *) DeviceFD;
	int Result;
	memset(RequestSense, 0, sizeof(RequestSense_T));
	memcpy(CMDBUF(dsp), CDB, CDB_Length);

	if (Direction == Input)
	{
		memset(DataBuffer, 0, DataBufferLength);
		filldsreq(dsp, (unsigned char *) DataBuffer, DataBufferLength, DSRQ_READ | DSRQ_SENSE);
	}
	else
		filldsreq(dsp, (unsigned char *) DataBuffer, DataBufferLength, DSRQ_WRITE | DSRQ_SENSE);

	/* Set 5 minute timeout. */
	/* TIME(dsp) = 300 * 1000; */
	TIME(dsp) = mtx_default_timeout;
	Result = doscsireq(getfd((dsp)), dsp);
	
	if (SENSESENT(dsp) > 0)
	{
		memcpy(RequestSense, SENSEBUF(dsp), min(sizeof(RequestSense_T), SENSESENT(dsp)));
	}

	SCSI_Default_Timeout(); /* reset the mtx default timeout */
	return Result;
}