-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscsistub.cpp
151 lines (125 loc) · 3.75 KB
/
scsistub.cpp
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/**
** scsistub.cpp
** Saturday. September 21, 2002
**
** Connect the command-line to the Scsi-over-whatever devices named,
** but hard-code the Scsi command to try, rather than parsing it from
** the command line.
**/
/**
** Decide what to say.
**/
#define CDB "\x12\0\0\0\x24\0"
#define IN_LENGTH 0x24
#define OUT_LENGTH 0
#define SENSE_LENGTH 0xE /* offsetof SK ASC ASCQ < xE */
#define SECONDS -1 /* negative means max */
/**
** Link with standard C libraries.
**/
#include <stdio.h> /* FILE ... */
#include <stdlib.h> /* calloc ... */
#include <string.h> /* memmove ... */
/**
** Maybe link with more libraries.
**/
#ifdef __MSDOS__
#include <alloc.h> /* farcalloc ... */
#endif
/**
** Link with the *.c* of ../plscsi/.
**/
#include "plscsi.h"
/**
** Stand in place of "scsi.cpp".
**/
// #define SCSI_STUB SCSI_STUB
#ifdef SCSI_STUB
/**
** Print a result.
**/
static void inquiryPrintln(char const * name, char const * dataChars, INT dataLength)
{
FILE * fi = stdout;
(void) fprintf(fi, "%s\t// ", name);
if (0x23 < dataLength)
{
int availableLength = (4 + (sizeof dataChars[4]) + (dataChars[4] & 0xFF));
if (dataChars[4] == '\0') availableLength = 0x24;
if (0x23 < availableLength)
{
char chars[0x1C];
(void) memmove(&chars[0], &dataChars[8], 0x1C); chars[0x1C] = '\0';
(void) fprintf(fi, "%c %s",
((dataChars[2] & 0x3F) | 0x40), /* version of Scsi */
&chars[0] /* vendorIdentification:productIdentification:productRevisionLevel */
);
}
}
(void) fprintf(fi, "\n");
}
/**
** Run from the command line.
**/
int main(int argc, char const * const * argv)
{
--argc; ++argv;
char cdbChars[] = CDB;
int cdbLength = ((sizeof cdbChars) - 1);
INT maxLength = (OUT_LENGTH + IN_LENGTH);
int direction = ((0 < IN_LENGTH) ? X1_DATA_IN : X2_DATA_OUT);
if (maxLength == 0) direction = X0_DATA_NOT;
char * dataChars = (char *) CALLOC(1, maxLength);
for (int argi = 0; argi < argc; ++argi)
{
char const * name = argv[argi];
#ifdef SGIO
Sgio * sgio = newSgio();
if (sgioOpen(sgio, name) == 0)
{
(void) sgioLimitSense(sgio, SENSE_LENGTH);
(void) sgioLimitSeconds(sgio, SECONDS, 0);
int exitInt = sgioSay(sgio, &cdbChars[0], cdbLength, dataChars, maxLength, direction);
if (exitInt == 0)
{
inquiryPrintln(name, dataChars, maxLength);
}
continue;
}
#endif
#ifdef XXXASPI
Aspi * aspi = newAspi();
if (aspiOpen(aspi, name) == 0)
{
(void) aspiLimitSense(aspi, SENSE_LENGTH);
#ifdef WINASPI
(void) aspiLimitSeconds(aspi, SECONDS, 0);
#endif
INT exitInt = aspiSay(aspi, &cdbChars[0], cdbLength, dataChars, maxLength, direction);
if (exitInt == 0)
{
inquiryPrintln(name, dataChars, maxLength);
}
continue;
}
#endif
#ifdef SPTX
int maxSptLength = -1; /* -1 = don't care */
Sptx * sptx = newSptx(maxSptLength);
if (sptxOpen(sptx, name) == 0)
{
(void) sptxLimitSense(sptx, SENSE_LENGTH);
(void) sptxLimitSeconds(sptx, SECONDS, 0);
int exitInt = sptxSay(sptx, &cdbChars[0], cdbLength, dataChars, maxLength, direction);
if (exitInt == 0)
{
inquiryPrintln(name, dataChars, maxLength);
}
continue;
}
#endif
}
return 0;
}
#endif /* SCSI_STUB */
/* end of file */