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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
|
typedef struct _SCSI_PASS_THROUGH_WITH_BUFFERS
{
SCSI_PASS_THROUGH spt;
ULONG Filler; // realign buffers to double word boundary
UCHAR ucSenseBuf[32];
UCHAR ucDataBuf[512];
} SCSI_PASS_THROUGH_WITH_BUFFERS, *PSCSI_PASS_THROUGH_WITH_BUFFERS;
typedef struct _SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER
{
SCSI_PASS_THROUGH_DIRECT sptd;
ULONG Filler; // realign buffer to double word boundary
UCHAR ucSenseBuf[32];
} SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, *PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER;
typedef struct _SCSI_TWOBYTES
{
UCHAR High;
UCHAR Low;
} SCSI_TWOBYTES, *PSCSI_TWOBYTES;
typedef struct _SCSI_THREEBYTES
{
UCHAR High;
UCHAR Mid;
UCHAR Low;
} SCSI_THREEBYTES, *PSCSI_THREEBYTES;
typedef struct _SCSI_MODE_HEADER
{
UCHAR ModeDataLength;
UCHAR MediumType;
UCHAR DeviceSpecificParameter;
UCHAR BlockDescriptorLength;
} SCSI_MODE_HEADER, *PSCSI_MODE_HEADER;
typedef struct _SCSI_MODE_FORMAT_PAGE
{
UCHAR PC_RES_PageCode;
UCHAR PageLength;
SCSI_TWOBYTES TracksPerZone;
SCSI_TWOBYTES AlternateSectorsPerZone;
SCSI_TWOBYTES AlternateTracksPerZone;
SCSI_TWOBYTES AlternateTracksPerLogicalUnit;
SCSI_TWOBYTES SectorsPerTrack;
SCSI_TWOBYTES DataBytesPerPhysicalSector;
SCSI_TWOBYTES Interleave;
SCSI_TWOBYTES TrackSkewFactor;
SCSI_TWOBYTES CylinderSkewFactor;
UCHAR FormattingBits;
SCSI_THREEBYTES Reserved;
} SCSI_MODE_FORMAT_PAGE, *PSCSI_MODE_FORMAT_PAGE;
//
// Define mode caching page.
//
typedef struct _MODE_CACHING_PAGE {
UCHAR PageCode : 6;
UCHAR Reserved : 1;
UCHAR PageSavable : 1;
UCHAR PageLength;
UCHAR ReadDisableCache : 1;
UCHAR MultiplicationFactor : 1;
UCHAR WriteCacheEnable : 1;
UCHAR Reserved2 : 5;
UCHAR WriteRetensionPriority : 4;
UCHAR ReadRetensionPriority : 4;
UCHAR DisablePrefetchTransfer[2];
UCHAR MinimumPrefetch[2];
UCHAR MaximumPrefetch[2];
UCHAR MaximumPrefetchCeiling[2];
}MODE_CACHING_PAGE, *PMODE_CACHING_PAGE;
//
// Command Descriptor Block constants.
//
#define CDB6GENERIC_LENGTH 6
#define CDB10GENERIC_LENGTH 10
#define SETBITON 1
#define SETBITOFF 0
//
// Mode Sense/Select page constants.
//
#define READ_DEFECT_PLIST 0x10
#define READ_DEFECT_GLIST 0x04
#define MODE_PAGE_ERROR_RECOVERY 0x01
#define MODE_PAGE_DISCONNECT 0x02
#define MODE_PAGE_FORMAT_DEVICE 0x03
#define MODE_PAGE_RIGID_GEOMETRY 0x04
#define MODE_PAGE_FLEXIBILE 0x05
#define MODE_PAGE_VERIFY_ERROR 0x07
#define MODE_PAGE_CACHING 0x08
#define MODE_PAGE_PERIPHERAL 0x09
#define MODE_PAGE_CONTROL 0x0A
#define MODE_PAGE_MEDIUM_TYPES 0x0B
#define MODE_PAGE_NOTCH_PARTITION 0x0C
#define MODE_SENSE_RETURN_ALL 0x3f
#define MODE_SENSE_CURRENT_VALUES 0x00
#define MODE_SENSE_CHANGEABLE_VALUES 0x40
#define MODE_SENSE_ALL_CHANGEABLE_VALUES 0x7F
#define MODE_SENSE_DEFAULT_VALUES 0x80
#define MODE_SENSE_SAVED_VALUES 0xc0
#define MODE_SENSE_FORMAT_DEVICE_PAGE 0x03
#define MODE_SENSE_DISABLE_BLOCK_DESCRIPTORS 0x08
#define MODE_SELECT_SAVE_PAGES 0x01
#define MODE_SELECT_DONT_SAVE_PAGES 0x00
#define MODE_PAGE_DEVICE_CONFIG 0x10
#define MODE_PAGE_MEDIUM_PARTITION 0x11
#define MODE_PAGE_DATA_COMPRESS 0x0f
//
// SCSI CDB operation codes
//
#define SCSIOP_TEST_UNIT_READY 0x00
#define SCSIOP_REZERO_UNIT 0x01
#define SCSIOP_REWIND 0x01
#define SCSIOP_REQUEST_BLOCK_ADDR 0x02
#define SCSIOP_REQUEST_SENSE 0x03
#define SCSIOP_FORMAT_UNIT 0x04
#define SCSIOP_READ_BLOCK_LIMITS 0x05
#define SCSIOP_REASSIGN_BLOCKS 0x07
#define SCSIOP_READ6 0x08
#define SCSIOP_RECEIVE 0x08
#define SCSIOP_WRITE6 0x0A
#define SCSIOP_PRINT 0x0A
#define SCSIOP_SEND 0x0A
#define SCSIOP_SEEK6 0x0B
#define SCSIOP_TRACK_SELECT 0x0B
#define SCSIOP_SLEW_PRINT 0x0B
#define SCSIOP_SEEK_BLOCK 0x0C
#define SCSIOP_PARTITION 0x0D
#define SCSIOP_READ_REVERSE 0x0F
#define SCSIOP_WRITE_FILEMARKS 0x10
#define SCSIOP_FLUSH_BUFFER 0x10
#define SCSIOP_SPACE 0x11
#define SCSIOP_INQUIRY 0x12
#define SCSIOP_VERIFY6 0x13
#define SCSIOP_RECOVER_BUF_DATA 0x14
#define SCSIOP_MODE_SELECT 0x15
#define SCSIOP_RESERVE_UNIT 0x16
#define SCSIOP_RELEASE_UNIT 0x17
#define SCSIOP_COPY 0x18
#define SCSIOP_ERASE 0x19
#define SCSIOP_MODE_SENSE 0x1A
#define SCSIOP_START_STOP_UNIT 0x1B
#define SCSIOP_STOP_PRINT 0x1B
#define SCSIOP_LOAD_UNLOAD 0x1B
#define SCSIOP_RECEIVE_DIAGNOSTIC 0x1C
#define SCSIOP_SEND_DIAGNOSTIC 0x1D
#define SCSIOP_MEDIUM_REMOVAL 0x1E
#define SCSIOP_READ_CAPACITY 0x25
#define SCSIOP_READ 0x28
#define SCSIOP_WRITE 0x2A
#define SCSIOP_SEEK 0x2B
#define SCSIOP_LOCATE 0x2B
#define SCSIOP_WRITE_VERIFY 0x2E
#define SCSIOP_VERIFY 0x2F
#define SCSIOP_SEARCH_DATA_HIGH 0x30
#define SCSIOP_SEARCH_DATA_EQUAL 0x31
#define SCSIOP_SEARCH_DATA_LOW 0x32
#define SCSIOP_SET_LIMITS 0x33
#define SCSIOP_READ_POSITION 0x34
#define SCSIOP_SYNCHRONIZE_CACHE 0x35
#define SCSIOP_READ_DEFECT_DATA 0x37
#define SCSIOP_COMPARE 0x39
#define SCSIOP_COPY_COMPARE 0x3A
#define SCSIOP_WRITE_DATA_BUFF 0x3B
#define SCSIOP_READ_DATA_BUFF 0x3C
#define SCSIOP_CHANGE_DEFINITION 0x40
#define SCSIOP_READ_SUB_CHANNEL 0x42
#define SCSIOP_READ_TOC 0x43
#define SCSIOP_READ_HEADER 0x44
#define SCSIOP_PLAY_AUDIO 0x45
#define SCSIOP_PLAY_AUDIO_MSF 0x47
#define SCSIOP_PLAY_TRACK_INDEX 0x48
#define SCSIOP_PLAY_TRACK_RELATIVE 0x49
#define SCSIOP_PAUSE_RESUME 0x4B
#define SCSIOP_LOG_SELECT 0x4C
#define SCSIOP_LOG_SENSE 0x4D
//
// Sense Data Format
//
typedef struct _SENSE_DATA {
UCHAR ErrorCode:7;
UCHAR Valid:1;
UCHAR SegmentNumber;
UCHAR SenseKey:4;
UCHAR Reserved:1;
UCHAR IncorrectLength:1;
UCHAR EndOfMedia:1;
UCHAR FileMark:1;
UCHAR Information[4];
UCHAR AdditionalSenseLength;
UCHAR CommandSpecificInformation[4];
UCHAR AdditionalSenseCode;
UCHAR AdditionalSenseCodeQualifier;
UCHAR FieldReplaceableUnitCode;
UCHAR SenseKeySpecific[3];
} SENSE_DATA, *PSENSE_DATA;
//
// Default request sense buffer size
//
#define SENSE_BUFFER_SIZE 18
//
// Sense codes
//
#define SCSI_SENSE_NO_SENSE 0x00
#define SCSI_SENSE_RECOVERED_ERROR 0x01
#define SCSI_SENSE_NOT_READY 0x02
#define SCSI_SENSE_MEDIUM_ERROR 0x03
#define SCSI_SENSE_HARDWARE_ERROR 0x04
#define SCSI_SENSE_ILLEGAL_REQUEST 0x05
#define SCSI_SENSE_UNIT_ATTENTION 0x06
#define SCSI_SENSE_DATA_PROTECT 0x07
#define SCSI_SENSE_BLANK_CHECK 0x08
#define SCSI_SENSE_UNIQUE 0x09
#define SCSI_SENSE_COPY_ABORTED 0x0A
#define SCSI_SENSE_ABORTED_COMMAND 0x0B
#define SCSI_SENSE_EQUAL 0x0C
#define SCSI_SENSE_VOL_OVERFLOW 0x0D
#define SCSI_SENSE_MISCOMPARE 0x0E
#define SCSI_SENSE_RESERVED 0x0F
//
// Additional tape bit
//
#define SCSI_ILLEGAL_LENGTH 0x20
#define SCSI_EOM 0x40
#define SCSI_FILE_MARK 0x80
//
// Additional Sense codes
//
#define SCSI_ADSENSE_NO_SENSE 0x00
#define SCSI_ADSENSE_LUN_NOT_READY 0x04
#define SCSI_ADSENSE_ILLEGAL_COMMAND 0x20
#define SCSI_ADSENSE_ILLEGAL_BLOCK 0x21
#define SCSI_ADSENSE_INVALID_LUN 0x25
#define SCSI_ADSENSE_INVALID_CDB 0x24
#define SCSI_ADSENSE_MUSIC_AREA 0xA0
#define SCSI_ADSENSE_DATA_AREA 0xA1
#define SCSI_ADSENSE_VOLUME_OVERFLOW 0xA7
#define SCSI_ADSENSE_NO_MEDIA_IN_DEVICE 0x3a
#define SCSI_ADWRITE_PROTECT 0x27
#define SCSI_ADSENSE_MEDIUM_CHANGED 0x28
#define SCSI_ADSENSE_BUS_RESET 0x29
#define SCSI_ADSENSE_TRACK_ERROR 0x14
#define SCSI_ADSENSE_SEEK_ERROR 0x15
#define SCSI_ADSENSE_REC_DATA_NOECC 0x17
#define SCSI_ADSENSE_REC_DATA_ECC 0x18
//
// Additional sense code qualifier
//
#define SCSI_SENSEQ_FORMAT_IN_PROGRESS 0x04
#define SCSI_SENSEQ_INIT_COMMAND_REQUIRED 0x02
#define SCSI_SENSEQ_MANUAL_INTERVENTION_REQUIRED 0x03
#define SCSI_SENSEQ_BECOMING_READY 0x01
#define SCSI_SENSEQ_FILEMARK_DETECTED 0x01
#define SCSI_SENSEQ_SETMARK_DETECTED 0x03
#define SCSI_SENSEQ_END_OF_MEDIA_DETECTED 0x02
#define SCSI_SENSEQ_BEGINNING_OF_MEDIA_DETECTED 0x04
//
// Define mode flexible disk page.
//
typedef struct _MODE_FLEXIBLE_DISK_PAGE {
UCHAR PageCode : 6;
UCHAR Reserved : 1;
UCHAR PageSavable : 1;
UCHAR PageLength;
UCHAR TransferRate[2];
UCHAR NumberOfHeads;
UCHAR SectorsPerTrack;
UCHAR BytesPerSector[2];
UCHAR NumberOfCylinders[2];
UCHAR StartWritePrecom[2];
UCHAR StartReducedCurrent[2];
UCHAR StepRate[2];
UCHAR StepPluseWidth;
UCHAR HeadSettleDelay[2];
UCHAR MotorOnDelay;
UCHAR MotorOffDelay;
UCHAR Reserved2 : 5;
UCHAR MotorOnAsserted : 1;
UCHAR StartSectorNumber : 1;
UCHAR TrueReadySignal : 1;
UCHAR StepPlusePerCyclynder : 4;
UCHAR Reserved3 : 4;
UCHAR WriteCompenstation;
UCHAR HeadLoadDelay;
UCHAR HeadUnloadDelay;
UCHAR Pin2Usage : 4;
UCHAR Pin34Usage : 4;
UCHAR Pin1Usage : 4;
UCHAR Pin4Usage : 4;
UCHAR MediumRotationRate[2];
UCHAR Reserved4[2];
}MODE_FLEXIBLE_DISK_PAGE, *PMODE_FLEXIBLE_DISK_PAGE;
//
// Define mode format page.
//
typedef struct _MODE_FORMAT_PAGE {
UCHAR PageCode : 6;
UCHAR Reserved : 1;
UCHAR PageSavable : 1;
UCHAR PageLength;
UCHAR TracksPerZone[2];
UCHAR AlternateSectorsPerZone[2];
UCHAR AlternateTracksPerZone[2];
UCHAR AlternateTracksPerLogicalUnit[2];
UCHAR SectorsPerTrack[2];
UCHAR BytesPerPhysicalSector[2];
UCHAR Interleave[2];
UCHAR TrackSkewFactor[2];
UCHAR CylinderSkewFactor[2];
UCHAR Reserved2 : 4;
UCHAR SurfaceFirst : 1;
UCHAR RemovableMedia : 1;
UCHAR HardSectorFormating : 1;
UCHAR SoftSectorFormating : 1;
UCHAR Reserved3[2];
} MODE_FORMAT_PAGE, *PMODE_FORMAT_PAGE;
//
// Define rigid disk driver geometry page.
//
typedef struct _MODE_RIGID_GEOMETRY_PAGE {
UCHAR PageCode : 6;
UCHAR Reserved : 1;
UCHAR PageSavable : 1;
UCHAR PageLength;
UCHAR NumberOfCylinders[2];
UCHAR NumberOfHeads;
UCHAR StartWritePrecom[2];
UCHAR StartReducedCurrent[2];
UCHAR DriveStepRate[2];
UCHAR LandZoneCyclinder[2];
UCHAR RotationalPositionLock : 2;
UCHAR Reserved2 : 6;
UCHAR RotationOffset;
UCHAR Reserved3;
UCHAR RoataionRate[2];
UCHAR Reserved4[2];
}MODE_RIGID_GEOMETRY_PAGE, *PMODE_RIGID_GEOMETRY_PAGE;
//
// Define read write recovery page
//
typedef struct _MODE_READ_WRITE_RECOVERY_PAGE {
UCHAR PageCode : 6;
UCHAR Reserved1 : 1;
UCHAR PSBit : 1;
UCHAR PageLength;
UCHAR DCRBit : 1;
UCHAR DTEBit : 1;
UCHAR PERBit : 1;
UCHAR EERBit : 1;
UCHAR RCBit : 1;
UCHAR TBBit : 1;
UCHAR ARRE : 1;
UCHAR AWRE : 1;
UCHAR ReadRetryCount;
UCHAR Reserved4[4];
UCHAR WriteRetryCount;
UCHAR Reserved5[3];
} MODE_READ_WRITE_RECOVERY_PAGE, *PMODE_READ_WRITE_RECOVERY_PAGE;
/* Prototypes */
VOID DoInquiry(PSCSI_PASS_THROUGH_WITH_BUFFERS, HANDLE);
VOID DoModeSense(PSCSI_PASS_THROUGH_WITH_BUFFERS, HANDLE, ULONG);
VOID DoModeSelect(PSCSI_PASS_THROUGH_WITH_BUFFERS, HANDLE, ULONG, ULONG);
VOID
PrintError(ULONG);
VOID
PrintDataBuffer(PUCHAR, ULONG);
VOID
PrintInquiryDataBuffer(PUCHAR, ULONG);
VOID
PrintInquiryData(PVOID);
VOID
PrintInquiryStatusResults(BOOLEAN, DWORD, PSCSI_PASS_THROUGH_WITH_BUFFERS, ULONG);
VOID
PrintSenseInfo(PSCSI_PASS_THROUGH_WITH_BUFFERS);
BOOL
SetDiscPage(PUCHAR, PUCHAR, ULONG);
BOOL
EnableWriteCache(PUCHAR, ULONG, PUCHAR, ULONG);
BOOL
VerifyModePage( PUCHAR, PUCHAR, ULONG);
|