xref: /reactos/sdk/include/ddk/scsi.h (revision ede7a20a)
1 /*
2  * scsi.h
3  *
4  * SCSI port and class interface.
5  *
6  * This file is part of the w32api package.
7  *
8  * Contributors:
9  *   Created by Casper S. Hornstrup <chorns@users.sourceforge.net>
10  *
11  * THIS SOFTWARE IS NOT COPYRIGHTED
12  *
13  * This source code is offered for use in the public domain. You may
14  * use, modify or distribute it freely.
15  *
16  * This code is distributed in the hope that it will be useful but
17  * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
18  * DISCLAIMED. This includes but is not limited to warranties of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20  *
21  */
22 
23 #ifndef _NTSCSI_
24 #define _NTSCSI_
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 #ifndef _NTSCSI_USER_MODE_
31 #include "srb.h"
32 #endif
33 
34 #define NOTIFICATION_OPERATIONAL_CHANGE_CLASS_MASK    0x02
35 #define NOTIFICATION_POWER_MANAGEMENT_CLASS_MASK      0x04
36 #define NOTIFICATION_EXTERNAL_REQUEST_CLASS_MASK      0x08
37 #define NOTIFICATION_MEDIA_STATUS_CLASS_MASK          0x10
38 #define NOTIFICATION_MULTI_HOST_CLASS_MASK            0x20
39 #define NOTIFICATION_DEVICE_BUSY_CLASS_MASK           0x40
40 
41 
42 #define NOTIFICATION_NO_CLASS_EVENTS                  0x0
43 #define NOTIFICATION_OPERATIONAL_CHANGE_CLASS_EVENTS  0x1
44 #define NOTIFICATION_POWER_MANAGEMENT_CLASS_EVENTS    0x2
45 #define NOTIFICATION_EXTERNAL_REQUEST_CLASS_EVENTS    0x3
46 #define NOTIFICATION_MEDIA_STATUS_CLASS_EVENTS        0x4
47 #define NOTIFICATION_MULTI_HOST_CLASS_EVENTS          0x5
48 #define NOTIFICATION_DEVICE_BUSY_CLASS_EVENTS         0x6
49 
50 #define NOTIFICATION_OPERATIONAL_EVENT_NO_CHANGE         0x0
51 #define NOTIFICATION_OPERATIONAL_EVENT_CHANGE_REQUESTED  0x1
52 #define NOTIFICATION_OPERATIONAL_EVENT_CHANGE_OCCURRED   0x2
53 
54 #define NOTIFICATION_OPERATIONAL_STATUS_AVAILABLE        0x0
55 #define NOTIFICATION_OPERATIONAL_STATUS_TEMPORARY_BUSY   0x1
56 #define NOTIFICATION_OPERATIONAL_STATUS_EXTENDED_BUSY    0x2
57 
58 #define NOTIFICATION_OPERATIONAL_OPCODE_NONE             0x0
59 #define NOTIFICATION_OPERATIONAL_OPCODE_FEATURE_CHANGE   0x1
60 #define NOTIFICATION_OPERATIONAL_OPCODE_FEATURE_ADDED    0x2
61 #define NOTIFICATION_OPERATIONAL_OPCODE_UNIT_RESET       0x3
62 #define NOTIFICATION_OPERATIONAL_OPCODE_FIRMWARE_CHANGED 0x4
63 #define NOTIFICATION_OPERATIONAL_OPCODE_INQUIRY_CHANGED  0x5
64 
65 #define NOTIFICATION_POWER_EVENT_NO_CHANGE          0x0
66 #define NOTIFICATION_POWER_EVENT_CHANGE_SUCCEEDED   0x1
67 #define NOTIFICATION_POWER_EVENT_CHANGE_FAILED      0x2
68 
69 #define NOTIFICATION_POWER_STATUS_ACTIVE            0x1
70 #define NOTIFICATION_POWER_STATUS_IDLE              0x2
71 #define NOTIFICATION_POWER_STATUS_STANDBY           0x3
72 #define NOTIFICATION_POWER_STATUS_SLEEP             0x4
73 
74 #define NOTIFICATION_MEDIA_EVENT_NO_EVENT           0x0
75 #define NOTIFICATION_EXTERNAL_EVENT_NO_CHANGE       0x0
76 #define NOTIFICATION_EXTERNAL_EVENT_BUTTON_DOWN     0x1
77 #define NOTIFICATION_EXTERNAL_EVENT_BUTTON_UP       0x2
78 #define NOTIFICATION_EXTERNAL_EVENT_EXTERNAL        0x3
79 
80 #define NOTIFICATION_EXTERNAL_STATUS_READY          0x0
81 #define NOTIFICATION_EXTERNAL_STATUS_PREVENT        0x1
82 
83 #define NOTIFICATION_EXTERNAL_REQUEST_NONE          0x0000
84 #define NOTIFICATION_EXTERNAL_REQUEST_QUEUE_OVERRUN 0x0001
85 #define NOTIFICATION_EXTERNAL_REQUEST_PLAY          0x0101
86 #define NOTIFICATION_EXTERNAL_REQUEST_REWIND_BACK   0x0102
87 #define NOTIFICATION_EXTERNAL_REQUEST_FAST_FORWARD  0x0103
88 #define NOTIFICATION_EXTERNAL_REQUEST_PAUSE         0x0104
89 #define NOTIFICATION_EXTERNAL_REQUEST_STOP          0x0106
90 #define NOTIFICATION_EXTERNAL_REQUEST_ASCII_LOW     0x0200
91 #define NOTIFICATION_EXTERNAL_REQUEST_ASCII_HIGH    0x02ff
92 
93 #define NOTIFICATION_MEDIA_EVENT_NO_CHANGE          0x0
94 #define NOTIFICATION_MEDIA_EVENT_EJECT_REQUEST      0x1
95 #define NOTIFICATION_MEDIA_EVENT_NEW_MEDIA          0x2
96 #define NOTIFICATION_MEDIA_EVENT_MEDIA_REMOVAL      0x3
97 #define NOTIFICATION_MEDIA_EVENT_MEDIA_CHANGE       0x4
98 
99 #define NOTIFICATION_BUSY_EVENT_NO_EVENT               0x0
100 #define NOTIFICATION_MULTI_HOST_EVENT_NO_CHANGE        0x0
101 #define NOTIFICATION_MULTI_HOST_EVENT_CONTROL_REQUEST  0x1
102 #define NOTIFICATION_MULTI_HOST_EVENT_CONTROL_GRANT    0x2
103 #define NOTIFICATION_MULTI_HOST_EVENT_CONTROL_RELEASE  0x3
104 
105 #define NOTIFICATION_MULTI_HOST_STATUS_READY           0x0
106 #define NOTIFICATION_MULTI_HOST_STATUS_PREVENT         0x1
107 
108 #define NOTIFICATION_MULTI_HOST_PRIORITY_NO_REQUESTS   0x0
109 #define NOTIFICATION_MULTI_HOST_PRIORITY_LOW           0x1
110 #define NOTIFICATION_MULTI_HOST_PRIORITY_MEDIUM        0x2
111 #define NOTIFICATION_MULTI_HOST_PRIORITY_HIGH          0x3
112 
113 #define NOTIFICATION_BUSY_EVENT_NO_EVENT            0x0
114 #define NOTIFICATION_BUSY_EVENT_NO_CHANGE           0x0
115 #define NOTIFICATION_BUSY_EVENT_BUSY                0x1
116 
117 #define NOTIFICATION_BUSY_STATUS_NO_EVENT           0x0
118 #define NOTIFICATION_BUSY_STATUS_POWER              0x1
119 #define NOTIFICATION_BUSY_STATUS_IMMEDIATE          0x2
120 #define NOTIFICATION_BUSY_STATUS_DEFERRED           0x3
121 
122 #define DVD_FORMAT_LEAD_IN          0x00
123 #define DVD_FORMAT_COPYRIGHT        0x01
124 #define DVD_FORMAT_DISK_KEY         0x02
125 #define DVD_FORMAT_BCA              0x03
126 #define DVD_FORMAT_MANUFACTURING    0x04
127 
128 #define DVD_REPORT_AGID            0x00
129 #define DVD_CHALLENGE_KEY          0x01
130 #define DVD_KEY_1                  0x02
131 #define DVD_KEY_2                  0x03
132 #define DVD_TITLE_KEY              0x04
133 #define DVD_REPORT_ASF             0x05
134 #define DVD_INVALIDATE_AGID        0x3F
135 
136 #define BLANK_FULL              0x0
137 #define BLANK_MINIMAL           0x1
138 #define BLANK_TRACK             0x2
139 #define BLANK_UNRESERVE_TRACK   0x3
140 #define BLANK_TAIL              0x4
141 #define BLANK_UNCLOSE_SESSION   0x5
142 #define BLANK_SESSION           0x6
143 
144 #define CD_EXPECTED_SECTOR_ANY          0x0
145 #define CD_EXPECTED_SECTOR_CDDA         0x1
146 #define CD_EXPECTED_SECTOR_MODE1        0x2
147 #define CD_EXPECTED_SECTOR_MODE2        0x3
148 #define CD_EXPECTED_SECTOR_MODE2_FORM1  0x4
149 #define CD_EXPECTED_SECTOR_MODE2_FORM2  0x5
150 
151 #define DISK_STATUS_EMPTY       0x00
152 #define DISK_STATUS_INCOMPLETE  0x01
153 #define DISK_STATUS_COMPLETE    0x02
154 #define DISK_STATUS_OTHERS      0x03
155 
156 #define LAST_SESSION_EMPTY              0x00
157 #define LAST_SESSION_INCOMPLETE         0x01
158 #define LAST_SESSION_RESERVED_DAMAGED   0x02
159 #define LAST_SESSION_COMPLETE           0x03
160 
161 #define DISK_TYPE_CDDA          0x00
162 #define DISK_TYPE_CDI           0x10
163 #define DISK_TYPE_XA            0x20
164 #define DISK_TYPE_UNDEFINED     0xFF
165 
166 #define DISC_BGFORMAT_STATE_NONE        0x0
167 #define DISC_BGFORMAT_STATE_INCOMPLETE  0x1
168 #define DISC_BGFORMAT_STATE_RUNNING     0x2
169 #define DISC_BGFORMAT_STATE_COMPLETE    0x3
170 
171 #define DATA_BLOCK_MODE0    0x0
172 #define DATA_BLOCK_MODE1    0x1
173 #define DATA_BLOCK_MODE2    0x2
174 
175 /* READ_TOC formats */
176 #define READ_TOC_FORMAT_TOC         0x00
177 #define READ_TOC_FORMAT_SESSION     0x01
178 #define READ_TOC_FORMAT_FULL_TOC    0x02
179 #define READ_TOC_FORMAT_PMA         0x03
180 #define READ_TOC_FORMAT_ATIP        0x04
181 
182 #define CDB6GENERIC_LENGTH                   6
183 #define CDB10GENERIC_LENGTH                  10
184 #define CDB12GENERIC_LENGTH                  12
185 
186 #define SETBITON                             1
187 #define SETBITOFF                            0
188 
189 /* Mode Sense/Select page constants */
190 #define MODE_PAGE_VENDOR_SPECIFIC       0x00
191 #define MODE_PAGE_ERROR_RECOVERY        0x01
192 #define MODE_PAGE_DISCONNECT            0x02
193 #define MODE_PAGE_FORMAT_DEVICE         0x03
194 #define MODE_PAGE_MRW                   0x03
195 #define MODE_PAGE_RIGID_GEOMETRY        0x04
196 #define MODE_PAGE_FLEXIBILE             0x05
197 #define MODE_PAGE_WRITE_PARAMETERS      0x05
198 #define MODE_PAGE_VERIFY_ERROR          0x07
199 #define MODE_PAGE_CACHING               0x08
200 #define MODE_PAGE_PERIPHERAL            0x09
201 #define MODE_PAGE_CONTROL               0x0A
202 #define MODE_PAGE_MEDIUM_TYPES          0x0B
203 #define MODE_PAGE_NOTCH_PARTITION       0x0C
204 #define MODE_PAGE_CD_AUDIO_CONTROL      0x0E
205 #define MODE_PAGE_DATA_COMPRESS         0x0F
206 #define MODE_PAGE_DEVICE_CONFIG         0x10
207 #define MODE_PAGE_XOR_CONTROL           0x10
208 #define MODE_PAGE_MEDIUM_PARTITION      0x11
209 #define MODE_PAGE_ENCLOSURE_SERVICES_MANAGEMENT 0x14
210 #define MODE_PAGE_EXTENDED              0x15
211 #define MODE_PAGE_EXTENDED_DEVICE_SPECIFIC 0x16
212 #define MODE_PAGE_CDVD_FEATURE_SET      0x18
213 #define MODE_PAGE_PROTOCOL_SPECIFIC_LUN 0x18
214 #define MODE_PAGE_PROTOCOL_SPECIFIC_PORT 0x19
215 #define MODE_PAGE_POWER_CONDITION       0x1A
216 #define MODE_PAGE_LUN_MAPPING           0x1B
217 #define MODE_PAGE_FAULT_REPORTING       0x1C
218 #define MODE_PAGE_CDVD_INACTIVITY       0x1D
219 #define MODE_PAGE_ELEMENT_ADDRESS       0x1D
220 #define MODE_PAGE_TRANSPORT_GEOMETRY    0x1E
221 #define MODE_PAGE_DEVICE_CAPABILITIES   0x1F
222 #define MODE_PAGE_CAPABILITIES          0x2A
223 
224 #define MODE_SENSE_RETURN_ALL           0x3f
225 
226 #define MODE_SENSE_CURRENT_VALUES       0x00
227 #define MODE_SENSE_CHANGEABLE_VALUES    0x40
228 #define MODE_SENSE_DEFAULT_VAULES       0x80
229 #define MODE_SENSE_SAVED_VALUES         0xc0
230 
231 /* SCSI CDB operation codes */
232 #define SCSIOP_TEST_UNIT_READY          0x00
233 #define SCSIOP_REZERO_UNIT              0x01
234 #define SCSIOP_REWIND                   0x01
235 #define SCSIOP_REQUEST_BLOCK_ADDR       0x02
236 #define SCSIOP_REQUEST_SENSE            0x03
237 #define SCSIOP_FORMAT_UNIT              0x04
238 #define SCSIOP_READ_BLOCK_LIMITS        0x05
239 #define SCSIOP_REASSIGN_BLOCKS          0x07
240 #define SCSIOP_INIT_ELEMENT_STATUS      0x07
241 #define SCSIOP_READ6                    0x08
242 #define SCSIOP_RECEIVE                  0x08
243 #define SCSIOP_WRITE6                   0x0A
244 #define SCSIOP_PRINT                    0x0A
245 #define SCSIOP_SEND                     0x0A
246 #define SCSIOP_SEEK6                    0x0B
247 #define SCSIOP_TRACK_SELECT             0x0B
248 #define SCSIOP_SLEW_PRINT               0x0B
249 #define SCSIOP_SET_CAPACITY             0x0B
250 #define SCSIOP_SEEK_BLOCK               0x0C
251 #define SCSIOP_PARTITION                0x0D
252 #define SCSIOP_READ_REVERSE             0x0F
253 #define SCSIOP_WRITE_FILEMARKS          0x10
254 #define SCSIOP_FLUSH_BUFFER             0x10
255 #define SCSIOP_SPACE                    0x11
256 #define SCSIOP_INQUIRY                  0x12
257 #define SCSIOP_VERIFY6                  0x13
258 #define SCSIOP_RECOVER_BUF_DATA         0x14
259 #define SCSIOP_MODE_SELECT              0x15
260 #define SCSIOP_RESERVE_UNIT             0x16
261 #define SCSIOP_RELEASE_UNIT             0x17
262 #define SCSIOP_COPY                     0x18
263 #define SCSIOP_ERASE                    0x19
264 #define SCSIOP_MODE_SENSE               0x1A
265 #define SCSIOP_START_STOP_UNIT          0x1B
266 #define SCSIOP_STOP_PRINT               0x1B
267 #define SCSIOP_LOAD_UNLOAD              0x1B
268 #define SCSIOP_RECEIVE_DIAGNOSTIC       0x1C
269 #define SCSIOP_SEND_DIAGNOSTIC          0x1D
270 #define SCSIOP_MEDIUM_REMOVAL           0x1E
271 
272 #define SCSIOP_READ_FORMATTED_CAPACITY  0x23
273 #define SCSIOP_READ_CAPACITY            0x25
274 #define SCSIOP_READ                     0x28
275 #define SCSIOP_WRITE                    0x2A
276 #define SCSIOP_SEEK                     0x2B
277 #define SCSIOP_LOCATE                   0x2B
278 #define SCSIOP_POSITION_TO_ELEMENT      0x2B
279 #define SCSIOP_WRITE_VERIFY             0x2E
280 #define SCSIOP_VERIFY                   0x2F
281 #define SCSIOP_SEARCH_DATA_HIGH         0x30
282 #define SCSIOP_SEARCH_DATA_EQUAL        0x31
283 #define SCSIOP_SEARCH_DATA_LOW          0x32
284 #define SCSIOP_SET_LIMITS               0x33
285 #define SCSIOP_READ_POSITION            0x34
286 #define SCSIOP_SYNCHRONIZE_CACHE        0x35
287 #define SCSIOP_COMPARE                  0x39
288 #define SCSIOP_COPY_COMPARE             0x3A
289 #define SCSIOP_WRITE_DATA_BUFF          0x3B
290 #define SCSIOP_READ_DATA_BUFF           0x3C
291 #define SCSIOP_WRITE_LONG               0x3F
292 #define SCSIOP_CHANGE_DEFINITION        0x40
293 #define SCSIOP_WRITE_SAME               0x41
294 #define SCSIOP_READ_SUB_CHANNEL         0x42
295 #define SCSIOP_UNMAP                    0x42
296 #define SCSIOP_READ_TOC                 0x43
297 #define SCSIOP_READ_HEADER              0x44
298 #define SCSIOP_REPORT_DENSITY_SUPPORT   0x44
299 #define SCSIOP_PLAY_AUDIO               0x45
300 #define SCSIOP_GET_CONFIGURATION        0x46
301 #define SCSIOP_PLAY_AUDIO_MSF           0x47
302 #define SCSIOP_PLAY_TRACK_INDEX         0x48
303 #define SCSIOP_SANITIZE                 0x48
304 #define SCSIOP_PLAY_TRACK_RELATIVE      0x49
305 #define SCSIOP_GET_EVENT_STATUS         0x4A
306 #define SCSIOP_PAUSE_RESUME             0x4B
307 #define SCSIOP_LOG_SELECT               0x4C
308 #define SCSIOP_LOG_SENSE                0x4D
309 #define SCSIOP_STOP_PLAY_SCAN           0x4E
310 #define SCSIOP_XDWRITE                  0x50
311 #define SCSIOP_XPWRITE                  0x51
312 #define SCSIOP_READ_DISK_INFORMATION    0x51
313 #define SCSIOP_READ_DISC_INFORMATION    0x51
314 #define SCSIOP_READ_TRACK_INFORMATION   0x52
315 #define SCSIOP_XDWRITE_READ             0x53
316 #define SCSIOP_RESERVE_TRACK_RZONE      0x53
317 #define SCSIOP_SEND_OPC_INFORMATION     0x54
318 #define SCSIOP_MODE_SELECT10            0x55
319 #define SCSIOP_RESERVE_UNIT10           0x56
320 #define SCSIOP_RESERVE_ELEMENT          0x56
321 #define SCSIOP_RELEASE_UNIT10           0x57
322 #define SCSIOP_RELEASE_ELEMENT          0x57
323 #define SCSIOP_REPAIR_TRACK             0x58
324 #define SCSIOP_MODE_SENSE10             0x5A
325 #define SCSIOP_CLOSE_TRACK_SESSION      0x5B
326 #define SCSIOP_READ_BUFFER_CAPACITY     0x5C
327 #define SCSIOP_SEND_CUE_SHEET           0x5D
328 #define SCSIOP_PERSISTENT_RESERVE_IN    0x5E
329 #define SCSIOP_PERSISTENT_RESERVE_OUT   0x5F
330 
331 #define SCSIOP_OPERATION32              0x7F
332 
333 #define SCSIOP_XDWRITE_EXTENDED16       0x80
334 #define SCSIOP_WRITE_FILEMARKS16        0x80
335 #define SCSIOP_REBUILD16                0x81
336 #define SCSIOP_READ_REVERSE16           0x81
337 #define SCSIOP_REGENERATE16             0x82
338 #define SCSIOP_EXTENDED_COPY            0x83
339 #define SCSIOP_POPULATE_TOKEN           0x83
340 #define SCSIOP_WRITE_USING_TOKEN        0x83
341 #define SCSIOP_RECEIVE_COPY_RESULTS     0x84
342 #define SCSIOP_RECEIVE_ROD_TOKEN_INFORMATION 0x84
343 #define SCSIOP_ATA_PASSTHROUGH16        0x85
344 #define SCSIOP_ACCESS_CONTROL_IN        0x86
345 #define SCSIOP_ACCESS_CONTROL_OUT       0x87
346 #define SCSIOP_READ16                   0x88
347 #define SCSIOP_COMPARE_AND_WRITE        0x89
348 #define SCSIOP_WRITE16                  0x8A
349 #define SCSIOP_READ_ATTRIBUTES          0x8C
350 #define SCSIOP_WRITE_ATTRIBUTES         0x8D
351 #define SCSIOP_WRITE_VERIFY16           0x8E
352 #define SCSIOP_VERIFY16                 0x8F
353 #define SCSIOP_PREFETCH16               0x90
354 #define SCSIOP_SYNCHRONIZE_CACHE16      0x91
355 #define SCSIOP_SPACE16                  0x91
356 #define SCSIOP_LOCK_UNLOCK_CACHE16      0x92
357 #define SCSIOP_LOCATE16                 0x92
358 #define SCSIOP_WRITE_SAME16             0x93
359 #define SCSIOP_ERASE16                  0x93
360 #define SCSIOP_ZBC_OUT                  0x94
361 #define SCSIOP_ZBC_IN                   0x95
362 #define SCSIOP_READ_DATA_BUFF16         0x9B
363 #define SCSIOP_READ_CAPACITY16          0x9E
364 #define SCSIOP_GET_LBA_STATUS           0x9E
365 #define SCSIOP_GET_PHYSICAL_ELEMENT_STATUS 0x9E
366 #define SCSIOP_REMOVE_ELEMENT_AND_TRUNCATE 0x9E
367 #define SCSIOP_SERVICE_ACTION_IN16      0x9E
368 #define SCSIOP_SERVICE_ACTION_OUT16     0x9F
369 
370 #define SCSIOP_REPORT_LUNS              0xA0
371 #define SCSIOP_BLANK                    0xA1
372 #define SCSIOP_ATA_PASSTHROUGH12        0xA1
373 #define SCSIOP_SEND_EVENT               0xA2
374 #define SCSIOP_SECURITY_PROTOCOL_IN     0xA2
375 #define SCSIOP_SEND_KEY                 0xA3
376 #define SCSIOP_MAINTENANCE_IN           0xA3
377 #define SCSIOP_REPORT_KEY               0xA4
378 #define SCSIOP_MAINTENANCE_OUT          0xA4
379 #define SCSIOP_MOVE_MEDIUM              0xA5
380 #define SCSIOP_LOAD_UNLOAD_SLOT         0xA6
381 #define SCSIOP_EXCHANGE_MEDIUM          0xA6
382 #define SCSIOP_SET_READ_AHEAD           0xA7
383 #define SCSIOP_MOVE_MEDIUM_ATTACHED     0xA7
384 #define SCSIOP_READ12                   0xA8
385 #define SCSIOP_GET_MESSAGE              0xA8
386 #define SCSIOP_SERVICE_ACTION_OUT12     0xA9
387 #define SCSIOP_WRITE12                  0xAA
388 #define SCSIOP_SEND_MESSAGE             0xAB
389 #define SCSIOP_SERVICE_ACTION_IN12      0xAB
390 #define SCSIOP_GET_PERFORMANCE          0xAC
391 #define SCSIOP_READ_DVD_STRUCTURE       0xAD
392 #define SCSIOP_WRITE_VERIFY12           0xAE
393 #define SCSIOP_VERIFY12                 0xAF
394 #define SCSIOP_SEARCH_DATA_HIGH12       0xB0
395 #define SCSIOP_SEARCH_DATA_EQUAL12      0xB1
396 #define SCSIOP_SEARCH_DATA_LOW12        0xB2
397 #define SCSIOP_SET_LIMITS12             0xB3
398 #define SCSIOP_READ_ELEMENT_STATUS_ATTACHED 0xB4
399 #define SCSIOP_REQUEST_VOL_ELEMENT      0xB5
400 #define SCSIOP_SECURITY_PROTOCOL_OUT    0xB5
401 #define SCSIOP_SEND_VOLUME_TAG          0xB6
402 #define SCSIOP_SET_STREAMING            0xB6
403 #define SCSIOP_READ_DEFECT_DATA         0xB7
404 #define SCSIOP_READ_ELEMENT_STATUS      0xB8
405 #define SCSIOP_READ_CD_MSF              0xB9
406 #define SCSIOP_SCAN_CD                  0xBA
407 #define SCSIOP_REDUNDANCY_GROUP_IN      0xBA
408 #define SCSIOP_SET_CD_SPEED             0xBB
409 #define SCSIOP_REDUNDANCY_GROUP_OUT     0xBB
410 #define SCSIOP_PLAY_CD                  0xBC
411 #define SCSIOP_SPARE_IN                 0xBC
412 #define SCSIOP_MECHANISM_STATUS         0xBD
413 #define SCSIOP_SPARE_OUT                0xBD
414 #define SCSIOP_READ_CD                  0xBE
415 #define SCSIOP_VOLUME_SET_IN            0xBE
416 #define SCSIOP_SEND_DVD_STRUCTURE       0xBF
417 #define SCSIOP_VOLUME_SET_OUT           0xBF
418 #define SCSIOP_INIT_ELEMENT_RANGE       0xE7
419 
420 // SCSI operation parameters
421 
422 // SCSIOP_SANITIZE (0x48)
423 
424 #define SERVICE_ACTION_OVERWRITE                                                0x01
425 #define SERVICE_ACTION_BLOCK_ERASE                                              0x02
426 #define SERVICE_ACTION_CRYPTO_ERASE                                             0x03
427 #define SERVICE_ACTION_EXIT_FAILURE                                             0x1f
428 
429 // SCSIOP_OPERATION32 (0x7F)
430 
431 #define SERVICE_ACTION_XDWRITE                                                  0x0004
432 #define SERVICE_ACTION_XPWRITE                                                  0x0006
433 #define SERVICE_ACTION_XDWRITEREAD                                              0x0007
434 #define SERVICE_ACTION_WRITE                                                    0x000B
435 #define SERVICE_ACTION_WRITE_VERIFY                                             0x000C
436 #define SERVICE_ACTION_WRITE_SAME                                               0x000D
437 #define SERVICE_ACTION_ORWRITE                                                  0x000E
438 
439 // SCSIOP_POPULATE_TOKEN, SCSIOP_WRITE_USING_TOKEN (0x83)
440 
441 #define SERVICE_ACTION_POPULATE_TOKEN                                           0x10
442 #define SERVICE_ACTION_WRITE_USING_TOKEN                                        0x11
443 
444 // SCSIOP_RECEIVE_ROD_TOKEN_INFORMATION (0x84)
445 
446 #define SERVICE_ACTION_RECEIVE_TOKEN_INFORMATION                                0x07
447 
448 // SCSIOP_ZBC_OUT (0x94)
449 
450 #define SERVICE_ACTION_CLOSE_ZONE                                               0x01
451 #define SERVICE_ACTION_FINISH_ZONE                                              0x02
452 #define SERVICE_ACTION_OPEN_ZONE                                                0x03
453 #define SERVICE_ACTION_RESET_WRITE_POINTER                                      0x04
454 
455 // SCSIOP_ZBC_IN (0x95)
456 
457 #define SERVICE_ACTION_REPORT_ZONES                                             0x00
458 
459 #define REPORT_ZONES_OPTION_LIST_ALL_ZONES                                      0x00
460 #define REPORT_ZONES_OPTION_LIST_EMPTY_ZONES                                    0x01
461 #define REPORT_ZONES_OPTION_LIST_IMPLICITLY_OPENED_ZONES                        0x02
462 #define REPORT_ZONES_OPTION_LIST_EXPLICITLY_OPENED_ZONES                        0x03
463 #define REPORT_ZONES_OPTION_LIST_CLOSED_ZONES                                   0x04
464 #define REPORT_ZONES_OPTION_LIST_FULL_ZONES                                     0x05
465 #define REPORT_ZONES_OPTION_LIST_READ_ONLY_ZONES                                0x06
466 #define REPORT_ZONES_OPTION_LIST_OFFLINE_ZONES                                  0x07
467 #define REPORT_ZONES_OPTION_LIST_RWP_ZONES                                      0x10
468 #define REPORT_ZONES_OPTION_LIST_NON_SEQUENTIAL_WRITE_RESOURCES_ACTIVE_ZONES    0x11
469 #define REPORT_ZONES_OPTION_LIST_NOT_WRITE_POINTER_ZONES                        0x3F
470 
471 // SCSIOP_SERVICE_ACTION_IN16 (0x9E)
472 
473 #define SERVICE_ACTION_READ_CAPACITY16                                          0x10
474 #define SERVICE_ACTION_GET_LBA_STATUS                                           0x12
475 #define SERVICE_ACTION_GET_PHYSICAL_ELEMENT_STATUS                              0x17
476 #define SERVICE_ACTION_REMOVE_ELEMENT_AND_TRUNCATE                              0x18
477 
478 // SCSIOP_MAINTENANCE_IN (0xA3)
479 
480 #define SERVICE_ACTION_REPORT_TIMESTAMP                                         0x0F
481 
482 // SCSIOP_MAINTENANCE_OUT (0xA4)
483 
484 #define SERVICE_ACTION_SET_TIMESTAMP                                            0x0F
485 
486 #define CDB_RETURN_ON_COMPLETION   0
487 #define CDB_RETURN_IMMEDIATE       1
488 
489 #define CDB_FORCE_MEDIA_ACCESS 0x08
490 
491 #define SCSIOP_DENON_EJECT_DISC    0xE6
492 #define SCSIOP_DENON_STOP_AUDIO    0xE7
493 #define SCSIOP_DENON_PLAY_AUDIO    0xE8
494 #define SCSIOP_DENON_READ_TOC      0xE9
495 #define SCSIOP_DENON_READ_SUBCODE  0xEB
496 
497 #define SCSIMESS_ABORT                0x06
498 #define SCSIMESS_ABORT_WITH_TAG       0x0D
499 #define SCSIMESS_BUS_DEVICE_RESET     0X0C
500 #define SCSIMESS_CLEAR_QUEUE          0X0E
501 #define SCSIMESS_COMMAND_COMPLETE     0X00
502 #define SCSIMESS_DISCONNECT           0X04
503 #define SCSIMESS_EXTENDED_MESSAGE     0X01
504 #define SCSIMESS_IDENTIFY             0X80
505 #define SCSIMESS_IDENTIFY_WITH_DISCON 0XC0
506 #define SCSIMESS_IGNORE_WIDE_RESIDUE  0X23
507 #define SCSIMESS_INITIATE_RECOVERY    0X0F
508 #define SCSIMESS_INIT_DETECTED_ERROR  0X05
509 #define SCSIMESS_LINK_CMD_COMP        0X0A
510 #define SCSIMESS_LINK_CMD_COMP_W_FLAG 0X0B
511 #define SCSIMESS_MESS_PARITY_ERROR    0X09
512 #define SCSIMESS_MESSAGE_REJECT       0X07
513 #define SCSIMESS_NO_OPERATION         0X08
514 #define SCSIMESS_HEAD_OF_QUEUE_TAG    0X21
515 #define SCSIMESS_ORDERED_QUEUE_TAG    0X22
516 #define SCSIMESS_SIMPLE_QUEUE_TAG     0X20
517 #define SCSIMESS_RELEASE_RECOVERY     0X10
518 #define SCSIMESS_RESTORE_POINTERS     0X03
519 #define SCSIMESS_SAVE_DATA_POINTER    0X02
520 #define SCSIMESS_TERMINATE_IO_PROCESS 0X11
521 
522 #define SCSIMESS_MODIFY_DATA_POINTER  0X00
523 #define SCSIMESS_SYNCHRONOUS_DATA_REQ 0X01
524 #define SCSIMESS_WIDE_DATA_REQUEST    0X03
525 
526 #define SCSIMESS_MODIFY_DATA_LENGTH   5
527 #define SCSIMESS_SYNCH_DATA_LENGTH    3
528 #define SCSIMESS_WIDE_DATA_LENGTH     2
529 
530 #define CDB_INQUIRY_EVPD           0x01
531 
532 #define LUN0_FORMAT_SAVING_DEFECT_LIST 0
533 #define USE_DEFAULTMSB 0
534 #define USE_DEFAULTLSB 0
535 
536 #define START_UNIT_CODE 0x01
537 #define STOP_UNIT_CODE 0x00
538 
539 /* INQUIRYDATA.DeviceType constants */
540 #define DIRECT_ACCESS_DEVICE              0x00
541 #define SEQUENTIAL_ACCESS_DEVICE          0x01
542 #define PRINTER_DEVICE                    0x02
543 #define PROCESSOR_DEVICE                  0x03
544 #define WRITE_ONCE_READ_MULTIPLE_DEVICE   0x04
545 #define READ_ONLY_DIRECT_ACCESS_DEVICE    0x05
546 #define SCANNER_DEVICE                    0x06
547 #define OPTICAL_DEVICE                    0x07
548 #define MEDIUM_CHANGER                    0x08
549 #define COMMUNICATION_DEVICE              0x09
550 #define ARRAY_CONTROLLER_DEVICE           0x0C
551 #define SCSI_ENCLOSURE_DEVICE             0x0D
552 #define REDUCED_BLOCK_DEVICE              0x0E
553 #define OPTICAL_CARD_READER_WRITER_DEVICE 0x0F
554 #define BRIDGE_CONTROLLER_DEVICE          0x10
555 #define OBJECT_BASED_STORAGE_DEVICE       0x11
556 #define LOGICAL_UNIT_NOT_PRESENT_DEVICE   0x7F
557 
558 #define DEVICE_QUALIFIER_ACTIVE           0x00
559 #define DEVICE_QUALIFIER_NOT_ACTIVE       0x01
560 #define DEVICE_QUALIFIER_NOT_SUPPORTED    0x03
561 
562 /* INQUIRYDATA.DeviceTypeQualifier constants */
563 #define DEVICE_CONNECTED 0x00
564 
565 #define SCSISTAT_GOOD                     0x00
566 #define SCSISTAT_CHECK_CONDITION          0x02
567 #define SCSISTAT_CONDITION_MET            0x04
568 #define SCSISTAT_BUSY                     0x08
569 #define SCSISTAT_INTERMEDIATE             0x10
570 #define SCSISTAT_INTERMEDIATE_COND_MET    0x14
571 #define SCSISTAT_RESERVATION_CONFLICT     0x18
572 #define SCSISTAT_COMMAND_TERMINATED       0x22
573 #define SCSISTAT_QUEUE_FULL               0x28
574 
575 #define RESERVATION_ACTION_READ_KEYS                    0x00
576 #define RESERVATION_ACTION_READ_RESERVATIONS            0x01
577 
578 #define RESERVATION_ACTION_REGISTER                     0x00
579 #define RESERVATION_ACTION_RESERVE                      0x01
580 #define RESERVATION_ACTION_RELEASE                      0x02
581 #define RESERVATION_ACTION_CLEAR                        0x03
582 #define RESERVATION_ACTION_PREEMPT                      0x04
583 #define RESERVATION_ACTION_PREEMPT_ABORT                0x05
584 #define RESERVATION_ACTION_REGISTER_IGNORE_EXISTING     0x06
585 
586 #define RESERVATION_SCOPE_LU                            0x00
587 #define RESERVATION_SCOPE_ELEMENT                       0x02
588 
589 #define RESERVATION_TYPE_WRITE_EXCLUSIVE                0x01
590 #define RESERVATION_TYPE_EXCLUSIVE                      0x03
591 #define RESERVATION_TYPE_WRITE_EXCLUSIVE_REGISTRANTS    0x05
592 #define RESERVATION_TYPE_EXCLUSIVE_REGISTRANTS          0x06
593 
594 #define SENSE_BUFFER_SIZE sizeof(SENSE_DATA)
595 #define SENSE_BUFFER_SIZE_EX sizeof(SENSE_DATA_EX)
596 
597 #define MAX_SENSE_BUFFER_SIZE          255
598 
599 #define MAX_ADDITIONAL_SENSE_BYTES (MAX_SENSE_BUFFER_SIZE - SENSE_BUFFER_SIZE)
600 #define MAX_ADDITIONAL_SENSE_BYTES_EX (MAX_SENSE_BUFFER_SIZE - SENSE_BUFFER_SIZE_EX)
601 
602 /* Sense codes */
603 #define SCSI_SENSE_NO_SENSE               0x00
604 #define SCSI_SENSE_RECOVERED_ERROR        0x01
605 #define SCSI_SENSE_NOT_READY              0x02
606 #define SCSI_SENSE_MEDIUM_ERROR           0x03
607 #define SCSI_SENSE_HARDWARE_ERROR         0x04
608 #define SCSI_SENSE_ILLEGAL_REQUEST        0x05
609 #define SCSI_SENSE_UNIT_ATTENTION         0x06
610 #define SCSI_SENSE_DATA_PROTECT           0x07
611 #define SCSI_SENSE_BLANK_CHECK            0x08
612 #define SCSI_SENSE_UNIQUE                 0x09
613 #define SCSI_SENSE_COPY_ABORTED           0x0A
614 #define SCSI_SENSE_ABORTED_COMMAND        0x0B
615 #define SCSI_SENSE_EQUAL                  0x0C
616 #define SCSI_SENSE_VOL_OVERFLOW           0x0D
617 #define SCSI_SENSE_MISCOMPARE             0x0E
618 #define SCSI_SENSE_RESERVED               0x0F
619 
620 // Sense Error Codes
621 
622 #define SCSI_SENSE_ERRORCODE_FIXED_CURRENT        0x70
623 #define SCSI_SENSE_ERRORCODE_FIXED_DEFERRED       0x71
624 #define SCSI_SENSE_ERRORCODE_DESCRIPTOR_CURRENT   0x72
625 #define SCSI_SENSE_ERRORCODE_DESCRIPTOR_DEFERRED  0x73
626 
627 // Sense Descriptor Types
628 
629 #define SCSI_SENSE_DESCRIPTOR_TYPE_INFORMATION                  0x00
630 #define SCSI_SENSE_DESCRIPTOR_TYPE_COMMAND_SPECIFIC             0x01
631 #define SCSI_SENSE_DESCRIPTOR_TYPE_SENSE_KEY_SPECIFIC           0x02
632 #define SCSI_SENSE_DESCRIPTOR_TYPE_FIELD_REPLACEABLE_UNIT       0x03
633 #define SCSI_SENSE_DESCRIPTOR_TYPE_STREAM_COMMAND               0x04
634 #define SCSI_SENSE_DESCRIPTOR_TYPE_BLOCK_COMMAND                0x05
635 #define SCSI_SENSE_DESCRIPTOR_TYPE_OSD_OBJECT_IDENTIFICATION    0x06
636 #define SCSI_SENSE_DESCRIPTOR_TYPE_OSD_RESPONSE_INTEGRITY_CHECK 0x07
637 #define SCSI_SENSE_DESCRIPTOR_TYPE_OSD_ATTRIBUTE_IDENTIFICATION 0x08
638 #define SCSI_SENSE_DESCRIPTOR_TYPE_ATA_STATUS_RETURN            0x09
639 #define SCSI_SENSE_DESCRIPTOR_TYPE_PROGRESS_INDICATION          0x0A
640 #define SCSI_SENSE_DESCRIPTOR_TYPE_USER_DATA_SEGMENT_REFERRAL   0x0B
641 
642 /* Additional tape bit */
643 #define SCSI_ILLEGAL_LENGTH               0x20
644 #define SCSI_EOM                          0x40
645 #define SCSI_FILE_MARK                    0x80
646 
647 /* Additional Sense codes */
648 #define SCSI_ADSENSE_NO_SENSE                              0x00
649 #define SCSI_ADSENSE_NO_SEEK_COMPLETE                      0x02
650 #define SCSI_ADSENSE_WRITE                                 0x03
651 #define SCSI_ADSENSE_LUN_NOT_READY                         0x04
652 #define SCSI_ADSENSE_LUN_COMMUNICATION                     0x08
653 #define SCSI_ADSENSE_SERVO_ERROR                           0x09
654 #define SCSI_ADSENSE_WARNING                               0x0B
655 #define SCSI_ADSENSE_WRITE_ERROR                           0x0C
656 #define SCSI_ADSENSE_COPY_TARGET_DEVICE_ERROR              0x0D
657 #define SCSI_ADSENSE_UNRECOVERED_ERROR                     0x11
658 #define SCSI_ADSENSE_TRACK_ERROR                           0x14
659 #define SCSI_ADSENSE_SEEK_ERROR                            0x15
660 #define SCSI_ADSENSE_REC_DATA_NOECC                        0x17
661 #define SCSI_ADSENSE_REC_DATA_ECC                          0x18
662 #define SCSI_ADSENSE_DEFECT_LIST_ERROR                     0x19
663 #define SCSI_ADSENSE_PARAMETER_LIST_LENGTH                 0x1A
664 #define SCSI_ADSENSE_MISCOMPARE_DURING_VERIFY_OPERATION    0x1D
665 #define SCSI_ADSENSE_ILLEGAL_COMMAND                       0x20
666 #define SCSI_ADSENSE_ACCESS_DENIED                         0x20
667 #define SCSI_ADSENSE_ILLEGAL_BLOCK                         0x21
668 #define SCSI_ADSENSE_INVALID_TOKEN                         0x23
669 #define SCSI_ADSENSE_INVALID_CDB                           0x24
670 #define SCSI_ADSENSE_INVALID_LUN                           0x25
671 #define SCSI_ADSENSE_INVALID_FIELD_PARAMETER_LIST          0x26
672 #define SCSI_ADSENSE_WRITE_PROTECT                         0x27
673 #define SCSI_ADSENSE_MEDIUM_CHANGED                        0x28
674 #define SCSI_ADSENSE_BUS_RESET                             0x29
675 #define SCSI_ADSENSE_PARAMETERS_CHANGED                    0x2A
676 #define SCSI_ADSENSE_INSUFFICIENT_TIME_FOR_OPERATION       0x2E
677 #define SCSI_ADSENSE_INVALID_MEDIA                         0x30
678 #define SCSI_ADSENSE_DEFECT_LIST                           0x32
679 #define SCSI_ADSENSE_LB_PROVISIONING                       0x38
680 #define SCSI_ADSENSE_NO_MEDIA_IN_DEVICE                    0x3a
681 #define SCSI_ADSENSE_POSITION_ERROR                        0x3b
682 #define SCSI_ADSENSE_LOGICAL_UNIT_ERROR                    0x3e
683 #define SCSI_ADSENSE_OPERATING_CONDITIONS_CHANGED          0x3f
684 #define SCSI_ADSENSE_DATA_PATH_FAILURE                     0x41
685 #define SCSI_ADSENSE_POWER_ON_SELF_TEST_FAILURE            0x42
686 #define SCSI_ADSENSE_INTERNAL_TARGET_FAILURE               0x44
687 #define SCSI_ADSENSE_DATA_TRANSFER_ERROR                   0x4b
688 #define SCSI_ADSENSE_LUN_FAILED_SELF_CONFIGURATION         0x4c
689 #define SCSI_ADSENSE_RESOURCE_FAILURE                      0x55
690 #define SCSI_ADSENSE_OPERATOR_REQUEST                      0x5a
691 #define SCSI_ADSENSE_FAILURE_PREDICTION_THRESHOLD_EXCEEDED 0x5d
692 #define SCSI_ADSENSE_ILLEGAL_MODE_FOR_THIS_TRACK           0x64
693 #define SCSI_ADSENSE_COPY_PROTECTION_FAILURE               0x6f
694 #define SCSI_ADSENSE_POWER_CALIBRATION_ERROR               0x73
695 #define SCSI_ADSENSE_VENDOR_UNIQUE                         0x80
696 #define SCSI_ADSENSE_MUSIC_AREA                            0xA0
697 #define SCSI_ADSENSE_DATA_AREA                             0xA1
698 #define SCSI_ADSENSE_VOLUME_OVERFLOW                       0xA7
699 
700 #define SCSI_ADWRITE_PROTECT                        SCSI_ADSENSE_WRITE_PROTECT
701 #define SCSI_FAILURE_PREDICTION_THRESHOLD_EXCEEDED  SCSI_ADSENSE_FAILURE_PREDICTION_THRESHOLD_EXCEEDED
702 
703 // ADSENSE additional qualifiers
704 
705 // SCSI_ADSENSE_NO_SENSE (0x00)
706 
707 #define SCSI_SENSEQ_FILEMARK_DETECTED            0x01
708 #define SCSI_SENSEQ_END_OF_MEDIA_DETECTED        0x02
709 #define SCSI_SENSEQ_SETMARK_DETECTED             0x03
710 #define SCSI_SENSEQ_BEGINNING_OF_MEDIA_DETECTED  0x04
711 #define SCSI_SENSEQ_OPERATION_IS_IN_PROGRESS     0x16
712 
713 // SCSI_ADSENSE_WRITE (0x03)
714 
715 #define SCSI_SENSEQ_PERIPHERAL_DEVICE_WRITE_FAULT   0x00
716 #define SCSI_SENSEQ_NO_WRITE_CURRENT                0x01
717 #define SCSI_SENSEQ_EXCESSIVE_WRITE_ERRORS          0x02
718 
719 // SCSI_ADSENSE_LUN_NOT_READY (0x04)
720 
721 #define SCSI_SENSEQ_CAUSE_NOT_REPORTABLE         0x00
722 #define SCSI_SENSEQ_BECOMING_READY               0x01
723 #define SCSI_SENSEQ_INIT_COMMAND_REQUIRED        0x02
724 #define SCSI_SENSEQ_MANUAL_INTERVENTION_REQUIRED 0x03
725 #define SCSI_SENSEQ_FORMAT_IN_PROGRESS           0x04
726 #define SCSI_SENSEQ_REBUILD_IN_PROGRESS          0x05
727 #define SCSI_SENSEQ_RECALCULATION_IN_PROGRESS    0x06
728 #define SCSI_SENSEQ_OPERATION_IN_PROGRESS        0x07
729 #define SCSI_SENSEQ_LONG_WRITE_IN_PROGRESS       0x08
730 #define SCSI_SENSEQ_SPACE_ALLOC_IN_PROGRESS      0x14
731 
732 // SCSI_ADSENSE_LUN_COMMUNICATION (0x08)
733 
734 #define SCSI_SENSEQ_COMM_FAILURE                 0x00
735 #define SCSI_SENSEQ_COMM_TIMEOUT                 0x01
736 #define SCSI_SENSEQ_COMM_PARITY_ERROR            0x02
737 #define SCSI_SESNEQ_COMM_CRC_ERROR               0x03
738 #define SCSI_SENSEQ_UNREACHABLE_TARGET           0x04
739 
740 // SCSI_ADSENSE_SERVO_ERROR (0x09)
741 
742 #define SCSI_SENSEQ_TRACK_FOLLOWING_ERROR   0x00
743 #define SCSI_SENSEQ_TRACKING_SERVO_FAILURE  0x01
744 #define SCSI_SENSEQ_FOCUS_SERVO_FAILURE     0x02
745 #define SCSI_SENSEQ_SPINDLE_SERVO_FAILURE   0x03
746 #define SCSI_SENSEQ_HEAD_SELECT_FAULT       0x04
747 
748 // SCSI_ADSENSE_WARNING (0x0B)
749 
750 #define SCSI_SENSEQ_POWER_LOSS_EXPECTED          0x08
751 
752 // SCSI_ADSENSE_WRITE_ERROR (0x0C)
753 
754 #define SCSI_SENSEQ_LOSS_OF_STREAMING            0x09
755 #define SCSI_SENSEQ_PADDING_BLOCKS_ADDED         0x0A
756 
757 // SCSI_ADSENSE_COPY_TARGET_DEVICE_ERROR (0x0D)
758 
759 #define SCSI_SENSEQ_NOT_REACHABLE                0x02
760 #define SCSI_SENSEQ_DATA_UNDERRUN                0x04
761 
762 // SCSI_ADSENSE_UNRECOVERED_ERROR (0x11)
763 
764 #define SCSI_SENSEQ_UNRECOVERED_READ_ERROR       0x00
765 
766 // SCSI_ADSENSE_SEEK_ERROR (0x15)
767 
768 #define SCSI_SENSEQ_RANDOM_POSITIONING_ERROR                        0x00
769 #define SCSI_SENSEQ_MECHANICAL_POSITIONING_ERROR                    0x01
770 #define SCSI_SENSEQ_POSITIONING_ERROR_DETECTED_BY_READ_OF_MEDIUM    0x02
771 
772 // SCSI_ADSENSE_DEFECT_LIST_ERROR (0x19)
773 
774 #define SCSI_SENSEQ_DEFECT_LIST_ERROR                  0x00
775 #define SCSI_SENSEQ_DEFECT_LIST_NOT_AVAILABLE          0x01
776 #define SCSI_SENSEQ_DEFECT_LIST_ERROR_IN_PRIMARY_LIST  0x02
777 #define SCSI_SENSEQ_DEFECT_LIST_ERROR_IN_GROWN_LIST    0x03
778 
779 // SCSI_ADSENSE_ACCESS_DENIED (0x20)
780 
781 #define SCSI_SENSEQ_NO_ACCESS_RIGHTS             0x02
782 
783 // SCSI_ADSENSE_ILLEGAL_BLOCK (0x21)
784 
785 #define SCSI_SENSEQ_LOGICAL_ADDRESS_OUT_OF_RANGE 0x00
786 #define SCSI_SENSEQ_ILLEGAL_ELEMENT_ADDR         0x01
787 #define SCSI_SENSEQ_INVALID_WRITE_ADDRESS        0x02
788 #define SCSI_SENSEQ_INVALID_WRITE_CROSSING_LAYER_JUMP 0x03
789 #define SCSI_SENSEQ_UNALIGNED_WRITE              0x04
790 #define SCSI_SENSEQ_WRITE_BOUNDARY_VIOLATION     0x05
791 #define SCSI_SENSEQ_READ_INVALID_DATA            0x06
792 #define SCSI_SENSEQ_READ_BOUNDARY_VIOLATION      0x07
793 #define SCSI_SENSEQ_MISALIGNED_WRITE             0x08
794 
795 // SCSI_ADSENSE_INVALID_FIELD_PARAMETER_LIST (0x26)
796 
797 #define SCSI_SENSEQ_INVALID_RELEASE_OF_PERSISTENT_RESERVATION 0x04
798 #define SCSI_SENSEQ_TOO_MANY_SEGMENT_DESCRIPTORS 0x08
799 
800 // SCSI_ADSENSE_WRITE_PROTECT (0x27)
801 
802 #define SCSI_SENSEQ_SPACE_ALLOC_FAILED_WRITE_PROTECT 0x07
803 
804 // SCSI_ADSENSE_PARAMETERS_CHANGED (0x2A)
805 
806 #define SCSI_SENSEQ_CAPACITY_DATA_CHANGED        0x09
807 
808 // SCSI_ADSENSE_POSITION_ERROR (0x3b)
809 
810 #define SCSI_SENSEQ_DESTINATION_FULL             0x0d
811 #define SCSI_SENSEQ_SOURCE_EMPTY                 0x0e
812 
813 // SCSI_ADSENSE_INVALID_MEDIA (0x30)
814 
815 #define SCSI_SENSEQ_INCOMPATIBLE_MEDIA_INSTALLED 0x00
816 #define SCSI_SENSEQ_UNKNOWN_FORMAT 0x01
817 #define SCSI_SENSEQ_INCOMPATIBLE_FORMAT 0x02
818 #define SCSI_SENSEQ_CLEANING_CARTRIDGE_INSTALLED 0x03
819 
820 // SCSI_ADSENSE_DEFECT_LIST (0x32)
821 
822 #define SCSI_SENSEQ_NO_DEFECT_SPARE_LOCATION_AVAILABLE  0x00
823 #define SCSI_SENSEQ_DEFECT_LIST_UPDATE_FAILURE          0x01
824 
825 // SCSI_ADSENSE_LB_PROVISIONING (0x38)
826 
827 #define SCSI_SENSEQ_SOFT_THRESHOLD_REACHED 0x07
828 
829 // SCSI_ADSENSE_LOGICAL_UNIT_ERROR (0x3e)
830 
831 #define SCSI_SENSEQ_LOGICAL_UNIT_HAS_NOT_SELF_CONFIGURED_YET    0x00
832 #define SCSI_SENSEQ_LOGICAL_UNIT_FAILURE                        0x01
833 #define SCSI_SENSEQ_TIMEOUT_ON_LOGICAL_UNIT                     0x02
834 #define SCSI_SENSEQ_LOGICAL_UNIT_FAILED_SELF_TEST               0x03
835 #define SCSI_SENSEQ_LOGICAL_UNIT_FAILED_TO_UPDATE_SELF_TEST_LOG 0x04
836 
837 // SCSI_ADSENSE_OPERATING_CONDITIONS_CHANGED (0x3f)
838 
839 #define SCSI_SENSEQ_TARGET_OPERATING_CONDITIONS_CHANGED 0x00
840 #define SCSI_SENSEQ_MICROCODE_CHANGED                   0x01
841 #define SCSI_SENSEQ_OPERATING_DEFINITION_CHANGED        0x02
842 #define SCSI_SENSEQ_INQUIRY_DATA_CHANGED                0x03
843 #define SCSI_SENSEQ_COMPONENT_DEVICE_ATTACHED           0x04
844 #define SCSI_SENSEQ_DEVICE_IDENTIFIER_CHANGED           0x05
845 #define SCSI_SENSEQ_REDUNDANCY_GROUP_MODIFIED           0x06
846 #define SCSI_SENSEQ_REDUNDANCY_GROUP_DELETED            0x07
847 #define SCSI_SENSEQ_SPARE_MODIFIED                      0x08
848 #define SCSI_SENSEQ_SPARE_DELETED                       0x09
849 #define SCSI_SENSEQ_VOLUME_SET_MODIFIED                 0x0A
850 #define SCSI_SENSEQ_VOLUME_SET_DELETED                  0x0B
851 #define SCSI_SENSEQ_VOLUME_SET_DEASSIGNED               0x0C
852 #define SCSI_SENSEQ_VOLUME_SET_REASSIGNED               0x0D
853 #define SCSI_SENSEQ_REPORTED_LUNS_DATA_CHANGED          0x0E
854 #define SCSI_SENSEQ_ECHO_BUFFER_OVERWRITTEN             0x0F
855 #define SCSI_SENSEQ_MEDIUM_LOADABLE                     0x10
856 #define SCSI_SENSEQ_MEDIUM_AUXILIARY_MEMORY_ACCESSIBLE  0x11
857 
858 // SCSI_ADSENSE_INTERNAL_TARGET_FAILURE (0x44)
859 
860 #define SCSI_SENSEQ_INTERNAL_TARGET_FAILURE                 0x00
861 #define SCSI_SENSEQ_PRESISTENT_RESERVATION_INFORMATION_LOST 0x01
862 #define SCSI_SENSEQ_ATA_DEVICE_FAILED_SET_FEATURES          0x71
863 
864 // SCSI_ADSENSE_DATA_TRANSFER_ERROR (0x4b)
865 
866 #define SCSI_SENSEQ_INITIATOR_RESPONSE_TIMEOUT          0x06
867 
868 // SCSI_ADSENSE_RESOURCE_FAILURE (0x55)
869 
870 #define SCSI_SENSEQ_SYSTEM_RESOURCE_FAILURE             0x00
871 #define SCSI_SENSEQ_SYSTEM_BUFFER_FULL                  0x01
872 #define SCSI_SENSEQ_INSUFFICIENT_RESERVATION_RESOURCES  0x02
873 #define SCSI_SENSEQ_INSUFFICIENT_RESOURCES              0x03
874 
875 // SCSI_ADSENSE_OPERATOR_REQUEST (0x5a)
876 
877 #define SCSI_SENSEQ_STATE_CHANGE_INPUT                  0x00
878 #define SCSI_SENSEQ_MEDIUM_REMOVAL                      0x01
879 #define SCSI_SENSEQ_WRITE_PROTECT_ENABLE                0x02
880 #define SCSI_SENSEQ_WRITE_PROTECT_DISABLE               0x03
881 
882 // SCSI_ADSENSE_FAILURE_PREDICTION_THRESHOLD_EXCEEDED (0x5d)
883 
884 #define SCSI_SENSEQ_FAILURE_PREDICTION_THRESHOLD_EXCEEDED               0x00
885 #define SCSI_SENSEQ_MEDIA_FAILURE_PREDICTION_THRESHOLD_EXCEEDED         0x01
886 #define SCSI_SENSEQ_LUN_FAILURE_PREDICTION_THRESHOLD_EXCEEDED           0x02
887 #define SCSI_SENSEQ_SPARE_AREA_EXHAUSTION_PREDICTION_THRESHOLD_EXCEEDED 0x03
888 #define SCSI_SENSEQ_GENERAL_HARD_DRIVE_FAILURE                          0x10
889 #define SCSI_SENSEQ_DRIVE_ERROR_RATE_TOO_HIGH                           0x11
890 #define SCSI_SENSEQ_DATA_ERROR_RATE_TOO_HIGH                            0x12
891 #define SCSI_SENSEQ_SEEK_ERROR_RATE_TOO_HIGH                            0x13
892 #define SCSI_SENSEQ_TOO_MANY_BLOCK_REASSIGNS                            0x14
893 #define SCSI_SENSEQ_ACCESS_TIMES_TOO_HIGH                               0x15
894 #define SCSI_SENSEQ_START_UNIT_TIMES_TOO_HIGH                           0x16
895 #define SCSI_SENSEQ_CHANNEL_PARAMETRICS                                 0x17
896 #define SCSI_SENSEQ_CONTROLLER_DETECTED                                 0x18
897 #define SCSI_SENSEQ_THROUGHPUT_PERFORMANCE                              0x19
898 #define SCSI_SENSEQ_SEEK_TIME_PERFORMANCE                               0x1A
899 #define SCSI_SENSEQ_SPIN_UP_RETRY_COUNT                                 0x1B
900 #define SCSI_SENSEQ_DRIVE_CALIBRATION_RETRY_COUNT                       0x1C
901 #define SCSI_SENSEQ_DATA_CHANNEL_DATA_ERROR_RATE_TOO_HIGH               0x32
902 #define SCSI_SENSEQ_SERVO_DATA_ERROR_RATE_TOO_HIGH                      0x42
903 #define SCSI_SENSEQ_SERVER_SEEK_ERROR_RATE_TOO_HIGH                     0x43
904 #define SCSI_SENSEQ_FAILURE_PREDICTION_THRESHOLD_EXCEEDED_FALSE         0xFF
905 
906 // SCSI_ADSENSE_COPY_PROTECTION_FAILURE (0x6f)
907 
908 #define SCSI_SENSEQ_AUTHENTICATION_FAILURE                          0x00
909 #define SCSI_SENSEQ_KEY_NOT_PRESENT                                 0x01
910 #define SCSI_SENSEQ_KEY_NOT_ESTABLISHED                             0x02
911 #define SCSI_SENSEQ_READ_OF_SCRAMBLED_SECTOR_WITHOUT_AUTHENTICATION 0x03
912 #define SCSI_SENSEQ_MEDIA_CODE_MISMATCHED_TO_LOGICAL_UNIT           0x04
913 #define SCSI_SENSEQ_LOGICAL_UNIT_RESET_COUNT_ERROR                  0x05
914 
915 // SCSI_ADSENSE_POWER_CALIBRATION_ERROR (0x73)
916 
917 #define SCSI_SENSEQ_POWER_CALIBRATION_AREA_ALMOST_FULL  0x01
918 #define SCSI_SENSEQ_POWER_CALIBRATION_AREA_FULL         0x02
919 #define SCSI_SENSEQ_POWER_CALIBRATION_AREA_ERROR        0x03
920 #define SCSI_SENSEQ_PMA_RMA_UPDATE_FAILURE              0x04
921 #define SCSI_SENSEQ_PMA_RMA_IS_FULL                     0x05
922 #define SCSI_SENSEQ_PMA_RMA_ALMOST_FULL                 0x06
923 
924 #define FILE_DEVICE_SCSI 0x0000001b
925 
926 #define IOCTL_SCSI_EXECUTE_IN ((FILE_DEVICE_SCSI << 16) + 0x0011)
927 #define IOCTL_SCSI_EXECUTE_OUT ((FILE_DEVICE_SCSI << 16) + 0x0012)
928 #define IOCTL_SCSI_EXECUTE_NONE ((FILE_DEVICE_SCSI << 16) + 0x0013)
929 
930 /* SMART support in ATAPI */
931 #define IOCTL_SCSI_MINIPORT_SMART_VERSION               ((FILE_DEVICE_SCSI << 16) + 0x0500)
932 #define IOCTL_SCSI_MINIPORT_IDENTIFY                    ((FILE_DEVICE_SCSI << 16) + 0x0501)
933 #define IOCTL_SCSI_MINIPORT_READ_SMART_ATTRIBS          ((FILE_DEVICE_SCSI << 16) + 0x0502)
934 #define IOCTL_SCSI_MINIPORT_READ_SMART_THRESHOLDS       ((FILE_DEVICE_SCSI << 16) + 0x0503)
935 #define IOCTL_SCSI_MINIPORT_ENABLE_SMART                ((FILE_DEVICE_SCSI << 16) + 0x0504)
936 #define IOCTL_SCSI_MINIPORT_DISABLE_SMART               ((FILE_DEVICE_SCSI << 16) + 0x0505)
937 #define IOCTL_SCSI_MINIPORT_RETURN_STATUS               ((FILE_DEVICE_SCSI << 16) + 0x0506)
938 #define IOCTL_SCSI_MINIPORT_ENABLE_DISABLE_AUTOSAVE     ((FILE_DEVICE_SCSI << 16) + 0x0507)
939 #define IOCTL_SCSI_MINIPORT_SAVE_ATTRIBUTE_VALUES       ((FILE_DEVICE_SCSI << 16) + 0x0508)
940 #define IOCTL_SCSI_MINIPORT_EXECUTE_OFFLINE_DIAGS       ((FILE_DEVICE_SCSI << 16) + 0x0509)
941 #define IOCTL_SCSI_MINIPORT_ENABLE_DISABLE_AUTO_OFFLINE ((FILE_DEVICE_SCSI << 16) + 0x050a)
942 #define IOCTL_SCSI_MINIPORT_READ_SMART_LOG              ((FILE_DEVICE_SCSI << 16) + 0x050b)
943 #define IOCTL_SCSI_MINIPORT_WRITE_SMART_LOG             ((FILE_DEVICE_SCSI << 16) + 0x050c)
944 
945 /* CLUSTER support */
946 #define IOCTL_SCSI_MINIPORT_NOT_QUORUM_CAPABLE ((FILE_DEVICE_SCSI << 16) + 0x0520)
947 #define IOCTL_SCSI_MINIPORT_NOT_CLUSTER_CAPABLE ((FILE_DEVICE_SCSI << 16) + 0x0521)
948 
949 #define MODE_FD_SINGLE_SIDE               0x01
950 #define MODE_FD_DOUBLE_SIDE               0x02
951 #define MODE_FD_MAXIMUM_TYPE              0x1E
952 #define MODE_DSP_FUA_SUPPORTED            0x10
953 #define MODE_DSP_WRITE_PROTECT            0x80
954 
955 #define CDDA_CHANNEL_MUTED      0x0
956 #define CDDA_CHANNEL_ZERO       0x1
957 #define CDDA_CHANNEL_ONE        0x2
958 #define CDDA_CHANNEL_TWO        0x4
959 #define CDDA_CHANNEL_THREE      0x8
960 
961 #define CDVD_LMT_CADDY              0
962 #define CDVD_LMT_TRAY               1
963 #define CDVD_LMT_POPUP              2
964 #define CDVD_LMT_RESERVED1          3
965 #define CDVD_LMT_CHANGER_INDIVIDUAL 4
966 #define CDVD_LMT_CHANGER_CARTRIDGE  5
967 #define CDVD_LMT_RESERVED2          6
968 #define CDVD_LMT_RESERVED3          7
969 
970 #define LOADING_MECHANISM_CADDY                 0x00
971 #define LOADING_MECHANISM_TRAY                  0x01
972 #define LOADING_MECHANISM_POPUP                 0x02
973 #define LOADING_MECHANISM_INDIVIDUAL_CHANGER    0x04
974 #define LOADING_MECHANISM_CARTRIDGE_CHANGER     0x05
975 
976 #define MODE_BLOCK_DESC_LENGTH        8
977 #define MODE_HEADER_LENGTH            4
978 #define MODE_HEADER_LENGTH10          8
979 
980 /* CDROM audio control */
981 #define CDB_AUDIO_PAUSE                   0x00
982 #define CDB_AUDIO_RESUME                  0x01
983 #define CDB_DEVICE_START                  0x11
984 #define CDB_DEVICE_STOP                   0x10
985 #define CDB_EJECT_MEDIA                   0x10
986 #define CDB_LOAD_MEDIA                    0x01
987 #define CDB_SUBCHANNEL_HEADER             0x00
988 #define CDB_SUBCHANNEL_BLOCK              0x01
989 
990 #define CDROM_AUDIO_CONTROL_PAGE          0x0E
991 #define MODE_SELECT_IMMEDIATE             0x04
992 #define MODE_SELECT_PFBIT                 0x10
993 
994 #define CDB_USE_MSF                       0x01
995 
996 /* Multisession CDROMs */
997 #define GET_LAST_SESSION 0x01
998 #define GET_SESSION_DATA 0x02
999 
1000 typedef union _CDB {
1001   struct _CDB6GENERIC {
1002     UCHAR OperationCode;
1003     UCHAR Immediate:1;
1004     UCHAR CommandUniqueBits:4;
1005     UCHAR LogicalUnitNumber:3;
1006     UCHAR CommandUniqueBytes[3];
1007     UCHAR Link:1;
1008     UCHAR Flag:1;
1009     UCHAR Reserved:4;
1010     UCHAR VendorUnique:2;
1011   } CDB6GENERIC, *PCDB6GENERIC;
1012   struct _CDB6READWRITE {
1013     UCHAR OperationCode;
1014     UCHAR LogicalBlockMsb1:5;
1015     UCHAR LogicalUnitNumber:3;
1016     UCHAR LogicalBlockMsb0;
1017     UCHAR LogicalBlockLsb;
1018     UCHAR TransferBlocks;
1019     UCHAR Control;
1020   } CDB6READWRITE, *PCDB6READWRITE;
1021   struct _CDB6INQUIRY {
1022     UCHAR OperationCode;
1023     UCHAR Reserved1:5;
1024     UCHAR LogicalUnitNumber:3;
1025     UCHAR PageCode;
1026     UCHAR IReserved;
1027     UCHAR AllocationLength;
1028     UCHAR Control;
1029   } CDB6INQUIRY, *PCDB6INQUIRY;
1030   struct _CDB6INQUIRY3 {
1031     UCHAR OperationCode;
1032     UCHAR EnableVitalProductData:1;
1033     UCHAR CommandSupportData:1;
1034     UCHAR Reserved1:6;
1035     UCHAR PageCode;
1036     UCHAR Reserved2;
1037     UCHAR AllocationLength;
1038     UCHAR Control;
1039   } CDB6INQUIRY3, *PCDB6INQUIRY3;
1040   struct _CDB6VERIFY {
1041     UCHAR OperationCode;
1042     UCHAR Fixed:1;
1043     UCHAR ByteCompare:1;
1044     UCHAR Immediate:1;
1045     UCHAR Reserved:2;
1046     UCHAR LogicalUnitNumber:3;
1047     UCHAR VerificationLength[3];
1048     UCHAR Control;
1049   } CDB6VERIFY, *PCDB6VERIFY;
1050   struct _CDB6FORMAT {
1051     UCHAR OperationCode;
1052     UCHAR FormatControl:5;
1053     UCHAR LogicalUnitNumber:3;
1054     UCHAR FReserved1;
1055     UCHAR InterleaveMsb;
1056     UCHAR InterleaveLsb;
1057     UCHAR FReserved2;
1058   } CDB6FORMAT, *PCDB6FORMAT;
1059   struct _CDB10 {
1060     UCHAR OperationCode;
1061     UCHAR RelativeAddress:1;
1062     UCHAR Reserved1:2;
1063     UCHAR ForceUnitAccess:1;
1064     UCHAR DisablePageOut:1;
1065     UCHAR LogicalUnitNumber:3;
1066     UCHAR LogicalBlockByte0;
1067     UCHAR LogicalBlockByte1;
1068     UCHAR LogicalBlockByte2;
1069     UCHAR LogicalBlockByte3;
1070     UCHAR Reserved2;
1071     UCHAR TransferBlocksMsb;
1072     UCHAR TransferBlocksLsb;
1073     UCHAR Control;
1074   } CDB10, *PCDB10;
1075   struct _CDB12 {
1076     UCHAR OperationCode;
1077     UCHAR RelativeAddress:1;
1078     UCHAR Reserved1:2;
1079     UCHAR ForceUnitAccess:1;
1080     UCHAR DisablePageOut:1;
1081     UCHAR LogicalUnitNumber:3;
1082     UCHAR LogicalBlock[4];
1083     UCHAR TransferLength[4];
1084     UCHAR Reserved2;
1085     UCHAR Control;
1086   } CDB12, *PCDB12;
1087   struct _CDB16 {
1088      UCHAR OperationCode;
1089      UCHAR Reserved1:3;
1090      UCHAR ForceUnitAccess:1;
1091      UCHAR DisablePageOut:1;
1092      UCHAR Protection:3;
1093      UCHAR LogicalBlock[8];
1094      UCHAR TransferLength[4];
1095      UCHAR Reserved2;
1096      UCHAR Control;
1097   } CDB16, *PCDB16;
1098   struct _PAUSE_RESUME {
1099     UCHAR OperationCode;
1100     UCHAR Reserved1:5;
1101     UCHAR LogicalUnitNumber:3;
1102     UCHAR Reserved2[6];
1103     UCHAR Action;
1104     UCHAR Control;
1105   } PAUSE_RESUME, *PPAUSE_RESUME;
1106   struct _READ_TOC {
1107     UCHAR OperationCode;
1108     UCHAR Reserved0:1;
1109     UCHAR Msf:1;
1110     UCHAR Reserved1:3;
1111     UCHAR LogicalUnitNumber:3;
1112     UCHAR Format2:4;
1113     UCHAR Reserved2:4;
1114     UCHAR Reserved3[3];
1115     UCHAR StartingTrack;
1116     UCHAR AllocationLength[2];
1117     UCHAR Control:6;
1118     UCHAR Format:2;
1119   } READ_TOC, *PREAD_TOC;
1120   struct _READ_DISK_INFORMATION {
1121     UCHAR OperationCode;
1122     UCHAR Reserved1:5;
1123     UCHAR Lun:3;
1124     UCHAR Reserved2[5];
1125     UCHAR AllocationLength[2];
1126     UCHAR Control;
1127   } READ_DISK_INFORMATION, *PREAD_DISK_INFORMATION;
1128   struct _READ_TRACK_INFORMATION {
1129     UCHAR OperationCode;
1130     UCHAR Track:1;
1131     UCHAR Reserved1:3;
1132     UCHAR Reserved2:1;
1133     UCHAR Lun:3;
1134     UCHAR BlockAddress[4];
1135     UCHAR Reserved3;
1136     UCHAR AllocationLength[2];
1137     UCHAR Control;
1138   } READ_TRACK_INFORMATION, *PREAD_TRACK_INFORMATION;
1139   struct _RESERVE_TRACK_RZONE {
1140     UCHAR OperationCode;
1141     UCHAR Reserved1[4];
1142     UCHAR ReservationSize[4];
1143     UCHAR Control;
1144   } RESERVE_TRACK_RZONE, *PRESERVE_TRACK_RZONE;
1145   struct _SEND_OPC_INFORMATION {
1146     UCHAR OperationCode;
1147     UCHAR DoOpc:1;
1148     UCHAR Reserved1:7;
1149     UCHAR Exclude0:1;
1150     UCHAR Exclude1:1;
1151     UCHAR Reserved2:6;
1152     UCHAR Reserved3[4];
1153     UCHAR ParameterListLength[2];
1154     UCHAR Reserved4;
1155   } SEND_OPC_INFORMATION, *PSEND_OPC_INFORMATION;
1156   struct _REPAIR_TRACK {
1157     UCHAR OperationCode;
1158     UCHAR Immediate:1;
1159     UCHAR Reserved1:7;
1160     UCHAR Reserved2[2];
1161     UCHAR TrackNumber[2];
1162     UCHAR Reserved3[3];
1163     UCHAR Control;
1164   } REPAIR_TRACK, *PREPAIR_TRACK;
1165   struct _CLOSE_TRACK {
1166     UCHAR OperationCode;
1167     UCHAR Immediate:1;
1168     UCHAR Reserved1:7;
1169     UCHAR Track:1;
1170     UCHAR Session:1;
1171     UCHAR Reserved2:6;
1172     UCHAR Reserved3;
1173     UCHAR TrackNumber[2];
1174     UCHAR Reserved4[3];
1175     UCHAR Control;
1176   } CLOSE_TRACK, *PCLOSE_TRACK;
1177   struct _READ_BUFFER_CAPACITY {
1178     UCHAR OperationCode;
1179     UCHAR BlockInfo:1;
1180     UCHAR Reserved1:7;
1181     UCHAR Reserved2[5];
1182     UCHAR AllocationLength[2];
1183     UCHAR Control;
1184   } READ_BUFFER_CAPACITY, *PREAD_BUFFER_CAPACITY;
1185   struct _SEND_CUE_SHEET {
1186     UCHAR OperationCode;
1187     UCHAR Reserved[5];
1188     UCHAR CueSheetSize[3];
1189     UCHAR Control;
1190   } SEND_CUE_SHEET, *PSEND_CUE_SHEET;
1191   struct _READ_HEADER {
1192     UCHAR OperationCode;
1193     UCHAR Reserved1:1;
1194     UCHAR Msf:1;
1195     UCHAR Reserved2:3;
1196     UCHAR Lun:3;
1197     UCHAR LogicalBlockAddress[4];
1198     UCHAR Reserved3;
1199     UCHAR AllocationLength[2];
1200     UCHAR Control;
1201   } READ_HEADER, *PREAD_HEADER;
1202   struct _PLAY_AUDIO {
1203     UCHAR OperationCode;
1204     UCHAR Reserved1:5;
1205     UCHAR LogicalUnitNumber:3;
1206     UCHAR StartingBlockAddress[4];
1207     UCHAR Reserved2;
1208     UCHAR PlayLength[2];
1209     UCHAR Control;
1210   } PLAY_AUDIO, *PPLAY_AUDIO;
1211   struct _PLAY_AUDIO_MSF {
1212     UCHAR OperationCode;
1213     UCHAR Reserved1:5;
1214     UCHAR LogicalUnitNumber:3;
1215     UCHAR Reserved2;
1216     UCHAR StartingM;
1217     UCHAR StartingS;
1218     UCHAR StartingF;
1219     UCHAR EndingM;
1220     UCHAR EndingS;
1221     UCHAR EndingF;
1222     UCHAR Control;
1223   } PLAY_AUDIO_MSF, *PPLAY_AUDIO_MSF;
1224   struct _BLANK_MEDIA {
1225     UCHAR OperationCode;
1226     UCHAR BlankType:3;
1227     UCHAR Reserved1:1;
1228     UCHAR Immediate:1;
1229     UCHAR Reserved2:3;
1230     UCHAR AddressOrTrack[4];
1231     UCHAR Reserved3[5];
1232     UCHAR Control;
1233   } BLANK_MEDIA, *PBLANK_MEDIA;
1234   struct _PLAY_CD {
1235     UCHAR OperationCode;
1236     UCHAR Reserved1:1;
1237     UCHAR CMSF:1;
1238     UCHAR ExpectedSectorType:3;
1239     UCHAR Lun:3;
1240     _ANONYMOUS_UNION union {
1241       struct _LBA {
1242         UCHAR StartingBlockAddress[4];
1243         UCHAR PlayLength[4];
1244       } LBA;
1245       struct _MSF {
1246         UCHAR Reserved1;
1247         UCHAR StartingM;
1248         UCHAR StartingS;
1249         UCHAR StartingF;
1250         UCHAR EndingM;
1251         UCHAR EndingS;
1252         UCHAR EndingF;
1253         UCHAR Reserved2;
1254       } MSF;
1255     } DUMMYUNIONNAME;
1256     UCHAR Audio:1;
1257     UCHAR Composite:1;
1258     UCHAR Port1:1;
1259     UCHAR Port2:1;
1260     UCHAR Reserved2:3;
1261     UCHAR Speed:1;
1262     UCHAR Control;
1263   } PLAY_CD, *PPLAY_CD;
1264   struct _SCAN_CD {
1265     UCHAR OperationCode;
1266     UCHAR RelativeAddress:1;
1267     UCHAR Reserved1:3;
1268     UCHAR Direct:1;
1269     UCHAR Lun:3;
1270     UCHAR StartingAddress[4];
1271     UCHAR Reserved2[3];
1272     UCHAR Reserved3:6;
1273     UCHAR Type:2;
1274     UCHAR Reserved4;
1275     UCHAR Control;
1276   } SCAN_CD, *PSCAN_CD;
1277   struct _STOP_PLAY_SCAN {
1278     UCHAR OperationCode;
1279     UCHAR Reserved1:5;
1280     UCHAR Lun:3;
1281     UCHAR Reserved2[7];
1282     UCHAR Control;
1283   } STOP_PLAY_SCAN, *PSTOP_PLAY_SCAN;
1284   struct _SUBCHANNEL {
1285     UCHAR OperationCode;
1286     UCHAR Reserved0:1;
1287     UCHAR Msf:1;
1288     UCHAR Reserved1:3;
1289     UCHAR LogicalUnitNumber:3;
1290     UCHAR Reserved2:6;
1291     UCHAR SubQ:1;
1292     UCHAR Reserved3:1;
1293     UCHAR Format;
1294     UCHAR Reserved4[2];
1295     UCHAR TrackNumber;
1296     UCHAR AllocationLength[2];
1297     UCHAR Control;
1298   } SUBCHANNEL, *PSUBCHANNEL;
1299   struct _READ_CD {
1300     UCHAR OperationCode;
1301     UCHAR RelativeAddress:1;
1302     UCHAR Reserved0:1;
1303     UCHAR ExpectedSectorType:3;
1304     UCHAR Lun:3;
1305     UCHAR StartingLBA[4];
1306     UCHAR TransferBlocks[3];
1307     UCHAR Reserved2:1;
1308     UCHAR ErrorFlags:2;
1309     UCHAR IncludeEDC:1;
1310     UCHAR IncludeUserData:1;
1311     UCHAR HeaderCode:2;
1312     UCHAR IncludeSyncData:1;
1313     UCHAR SubChannelSelection:3;
1314     UCHAR Reserved3:5;
1315     UCHAR Control;
1316   } READ_CD, *PREAD_CD;
1317   struct _READ_CD_MSF {
1318     UCHAR OperationCode;
1319     UCHAR RelativeAddress:1;
1320     UCHAR Reserved1:1;
1321     UCHAR ExpectedSectorType:3;
1322     UCHAR Lun:3;
1323     UCHAR Reserved2;
1324     UCHAR StartingM;
1325     UCHAR StartingS;
1326     UCHAR StartingF;
1327     UCHAR EndingM;
1328     UCHAR EndingS;
1329     UCHAR EndingF;
1330     UCHAR Reserved3;
1331     UCHAR Reserved4:1;
1332     UCHAR ErrorFlags:2;
1333     UCHAR IncludeEDC:1;
1334     UCHAR IncludeUserData:1;
1335     UCHAR HeaderCode:2;
1336     UCHAR IncludeSyncData:1;
1337     UCHAR SubChannelSelection:3;
1338     UCHAR Reserved5:5;
1339     UCHAR Control;
1340   } READ_CD_MSF, *PREAD_CD_MSF;
1341   struct _PLXTR_READ_CDDA {
1342     UCHAR OperationCode;
1343     UCHAR Reserved0:5;
1344     UCHAR LogicalUnitNumber:3;
1345     UCHAR LogicalBlockByte0;
1346     UCHAR LogicalBlockByte1;
1347     UCHAR LogicalBlockByte2;
1348     UCHAR LogicalBlockByte3;
1349     UCHAR TransferBlockByte0;
1350     UCHAR TransferBlockByte1;
1351     UCHAR TransferBlockByte2;
1352     UCHAR TransferBlockByte3;
1353     UCHAR SubCode;
1354     UCHAR Control;
1355   } PLXTR_READ_CDDA, *PPLXTR_READ_CDDA;
1356   struct _NEC_READ_CDDA {
1357     UCHAR OperationCode;
1358     UCHAR Reserved0;
1359     UCHAR LogicalBlockByte0;
1360     UCHAR LogicalBlockByte1;
1361     UCHAR LogicalBlockByte2;
1362     UCHAR LogicalBlockByte3;
1363     UCHAR Reserved1;
1364     UCHAR TransferBlockByte0;
1365     UCHAR TransferBlockByte1;
1366     UCHAR Control;
1367   } NEC_READ_CDDA, *PNEC_READ_CDDA;
1368 #if (NTDDI_VERSION >= NTDDI_WIN8)
1369   struct _MODE_SENSE {
1370     UCHAR OperationCode;
1371     UCHAR Reserved1:3;
1372     UCHAR Dbd:1;
1373     UCHAR Reserved2:4;
1374     UCHAR PageCode:6;
1375     UCHAR Pc:2;
1376     UCHAR SubPageCode;
1377     UCHAR AllocationLength;
1378     UCHAR Control;
1379   } MODE_SENSE;
1380   struct _MODE_SENSE10 {
1381     UCHAR OperationCode;
1382     UCHAR Reserved1:3;
1383     UCHAR Dbd:1;
1384     UCHAR LongLBAAccepted:1;
1385     UCHAR Reserved2:3;
1386     UCHAR PageCode:6;
1387     UCHAR Pc:2;
1388     UCHAR SubPageCode;
1389     UCHAR Reserved3[3];
1390     UCHAR AllocationLength[2];
1391     UCHAR Control;
1392   } MODE_SENSE10;
1393 #else
1394   struct _MODE_SENSE {
1395     UCHAR OperationCode;
1396     UCHAR Reserved1:3;
1397     UCHAR Dbd:1;
1398     UCHAR Reserved2:1;
1399     UCHAR LogicalUnitNumber:3;
1400     UCHAR PageCode:6;
1401     UCHAR Pc:2;
1402     UCHAR Reserved3;
1403     UCHAR AllocationLength;
1404     UCHAR Control;
1405   } MODE_SENSE, *PMODE_SENSE;
1406   struct _MODE_SENSE10 {
1407     UCHAR OperationCode;
1408     UCHAR Reserved1:3;
1409     UCHAR Dbd:1;
1410     UCHAR Reserved2:1;
1411     UCHAR LogicalUnitNumber:3;
1412     UCHAR PageCode:6;
1413     UCHAR Pc:2;
1414     UCHAR Reserved3[4];
1415     UCHAR AllocationLength[2];
1416     UCHAR Control;
1417   } MODE_SENSE10, *PMODE_SENSE10;
1418 #endif
1419   struct _MODE_SELECT {
1420     UCHAR OperationCode;
1421     UCHAR SPBit:1;
1422     UCHAR Reserved1:3;
1423     UCHAR PFBit:1;
1424     UCHAR LogicalUnitNumber:3;
1425     UCHAR Reserved2[2];
1426     UCHAR ParameterListLength;
1427     UCHAR Control;
1428   } MODE_SELECT, *PMODE_SELECT;
1429   struct _MODE_SELECT10 {
1430     UCHAR OperationCode;
1431     UCHAR SPBit:1;
1432     UCHAR Reserved1:3;
1433     UCHAR PFBit:1;
1434     UCHAR LogicalUnitNumber:3;
1435     UCHAR Reserved2[5];
1436     UCHAR ParameterListLength[2];
1437     UCHAR Control;
1438   } MODE_SELECT10, *PMODE_SELECT10;
1439   struct _LOCATE {
1440     UCHAR OperationCode;
1441     UCHAR Immediate:1;
1442     UCHAR CPBit:1;
1443     UCHAR BTBit:1;
1444     UCHAR Reserved1:2;
1445     UCHAR LogicalUnitNumber:3;
1446     UCHAR Reserved3;
1447     UCHAR LogicalBlockAddress[4];
1448     UCHAR Reserved4;
1449     UCHAR Partition;
1450     UCHAR Control;
1451   } LOCATE, *PLOCATE;
1452   struct _LOGSENSE {
1453     UCHAR OperationCode;
1454     UCHAR SPBit:1;
1455     UCHAR PPCBit:1;
1456     UCHAR Reserved1:3;
1457     UCHAR LogicalUnitNumber:3;
1458     UCHAR PageCode:6;
1459     UCHAR PCBit:2;
1460     UCHAR Reserved2;
1461     UCHAR Reserved3;
1462     UCHAR ParameterPointer[2];
1463     UCHAR AllocationLength[2];
1464     UCHAR Control;
1465   } LOGSENSE, *PLOGSENSE;
1466   struct _LOGSELECT {
1467     UCHAR OperationCode;
1468     UCHAR SPBit:1;
1469     UCHAR PCRBit:1;
1470     UCHAR Reserved1:3;
1471     UCHAR LogicalUnitNumber:3;
1472     UCHAR Reserved:6;
1473     UCHAR PCBit:2;
1474     UCHAR Reserved2[4];
1475     UCHAR ParameterListLength[2];
1476     UCHAR Control;
1477   } LOGSELECT, *PLOGSELECT;
1478   struct _PRINT {
1479     UCHAR OperationCode;
1480     UCHAR Reserved:5;
1481     UCHAR LogicalUnitNumber:3;
1482     UCHAR TransferLength[3];
1483     UCHAR Control;
1484   } PRINT, *PPRINT;
1485   struct _SEEK {
1486     UCHAR OperationCode;
1487     UCHAR Reserved1:5;
1488     UCHAR LogicalUnitNumber:3;
1489     UCHAR LogicalBlockAddress[4];
1490     UCHAR Reserved2[3];
1491     UCHAR Control;
1492   } SEEK, *PSEEK;
1493   struct _ERASE {
1494     UCHAR OperationCode;
1495     UCHAR Long:1;
1496     UCHAR Immediate:1;
1497     UCHAR Reserved1:3;
1498     UCHAR LogicalUnitNumber:3;
1499     UCHAR Reserved2[3];
1500     UCHAR Control;
1501   } ERASE, *PERASE;
1502   struct _START_STOP {
1503     UCHAR OperationCode;
1504     UCHAR Immediate:1;
1505     UCHAR Reserved1:4;
1506     UCHAR LogicalUnitNumber:3;
1507     UCHAR Reserved2[2];
1508     UCHAR Start:1;
1509     UCHAR LoadEject:1;
1510     UCHAR Reserved3:6;
1511     UCHAR Control;
1512   } START_STOP, *PSTART_STOP;
1513   struct _MEDIA_REMOVAL {
1514     UCHAR OperationCode;
1515     UCHAR Reserved1:5;
1516     UCHAR LogicalUnitNumber:3;
1517     UCHAR Reserved2[2];
1518     UCHAR Prevent:1;
1519     UCHAR Persistant:1;
1520     UCHAR Reserved3:6;
1521     UCHAR Control;
1522   } MEDIA_REMOVAL, *PMEDIA_REMOVAL;
1523   struct _SEEK_BLOCK {
1524     UCHAR OperationCode;
1525     UCHAR Immediate:1;
1526     UCHAR Reserved1:7;
1527     UCHAR BlockAddress[3];
1528     UCHAR Link:1;
1529     UCHAR Flag:1;
1530     UCHAR Reserved2:4;
1531     UCHAR VendorUnique:2;
1532   } SEEK_BLOCK, *PSEEK_BLOCK;
1533   struct _REQUEST_BLOCK_ADDRESS {
1534     UCHAR OperationCode;
1535     UCHAR Reserved1[3];
1536     UCHAR AllocationLength;
1537     UCHAR Link:1;
1538     UCHAR Flag:1;
1539     UCHAR Reserved2:4;
1540     UCHAR VendorUnique:2;
1541   } REQUEST_BLOCK_ADDRESS, *PREQUEST_BLOCK_ADDRESS;
1542   struct _PARTITION {
1543     UCHAR OperationCode;
1544     UCHAR Immediate:1;
1545     UCHAR Sel:1;
1546     UCHAR PartitionSelect:6;
1547     UCHAR Reserved1[3];
1548     UCHAR Control;
1549   } PARTITION, *PPARTITION;
1550   struct _WRITE_TAPE_MARKS {
1551     UCHAR OperationCode;
1552     UCHAR Immediate:1;
1553     UCHAR WriteSetMarks:1;
1554     UCHAR Reserved:3;
1555     UCHAR LogicalUnitNumber:3;
1556     UCHAR TransferLength[3];
1557     UCHAR Control;
1558   } WRITE_TAPE_MARKS, *PWRITE_TAPE_MARKS;
1559   struct _SPACE_TAPE_MARKS {
1560     UCHAR OperationCode;
1561     UCHAR Code:3;
1562     UCHAR Reserved:2;
1563     UCHAR LogicalUnitNumber:3;
1564     UCHAR NumMarksMSB;
1565     UCHAR NumMarks;
1566     UCHAR NumMarksLSB;
1567   union {
1568     UCHAR value;
1569     struct {
1570       UCHAR Link:1;
1571       UCHAR Flag:1;
1572       UCHAR Reserved:4;
1573       UCHAR VendorUnique:2;
1574     } Fields;
1575   } Byte6;
1576   } SPACE_TAPE_MARKS, *PSPACE_TAPE_MARKS;
1577   struct _READ_POSITION {
1578     UCHAR Operation;
1579     UCHAR BlockType:1;
1580     UCHAR Reserved1:4;
1581     UCHAR Lun:3;
1582     UCHAR Reserved2[7];
1583     UCHAR Control;
1584   } READ_POSITION, *PREAD_POSITION;
1585   struct _CDB6READWRITETAPE {
1586     UCHAR OperationCode;
1587     UCHAR VendorSpecific:5;
1588     UCHAR Reserved:3;
1589     UCHAR TransferLenMSB;
1590     UCHAR TransferLen;
1591     UCHAR TransferLenLSB;
1592     UCHAR Link:1;
1593     UCHAR Flag:1;
1594     UCHAR Reserved1:4;
1595     UCHAR VendorUnique:2;
1596   } CDB6READWRITETAPE, *PCDB6READWRITETAPE;
1597   struct _INIT_ELEMENT_STATUS {
1598     UCHAR OperationCode;
1599     UCHAR Reserved1:5;
1600     UCHAR LogicalUnitNubmer:3;
1601     UCHAR Reserved2[3];
1602     UCHAR Reserved3:7;
1603     UCHAR NoBarCode:1;
1604   } INIT_ELEMENT_STATUS, *PINIT_ELEMENT_STATUS;
1605   struct _INITIALIZE_ELEMENT_RANGE {
1606     UCHAR OperationCode;
1607     UCHAR Range:1;
1608     UCHAR Reserved1:4;
1609     UCHAR LogicalUnitNubmer:3;
1610     UCHAR FirstElementAddress[2];
1611     UCHAR Reserved2[2];
1612     UCHAR NumberOfElements[2];
1613     UCHAR Reserved3;
1614     UCHAR Reserved4:7;
1615     UCHAR NoBarCode:1;
1616   } INITIALIZE_ELEMENT_RANGE, *PINITIALIZE_ELEMENT_RANGE;
1617   struct _POSITION_TO_ELEMENT {
1618     UCHAR OperationCode;
1619     UCHAR Reserved1:5;
1620     UCHAR LogicalUnitNumber:3;
1621     UCHAR TransportElementAddress[2];
1622     UCHAR DestinationElementAddress[2];
1623     UCHAR Reserved2[2];
1624     UCHAR Flip:1;
1625     UCHAR Reserved3:7;
1626     UCHAR Control;
1627   } POSITION_TO_ELEMENT, *PPOSITION_TO_ELEMENT;
1628   struct _MOVE_MEDIUM {
1629     UCHAR OperationCode;
1630     UCHAR Reserved1:5;
1631     UCHAR LogicalUnitNumber:3;
1632     UCHAR TransportElementAddress[2];
1633     UCHAR SourceElementAddress[2];
1634     UCHAR DestinationElementAddress[2];
1635     UCHAR Reserved2[2];
1636     UCHAR Flip:1;
1637     UCHAR Reserved3:7;
1638     UCHAR Control;
1639   } MOVE_MEDIUM, *PMOVE_MEDIUM;
1640   struct _EXCHANGE_MEDIUM {
1641     UCHAR OperationCode;
1642     UCHAR Reserved1:5;
1643     UCHAR LogicalUnitNumber:3;
1644     UCHAR TransportElementAddress[2];
1645     UCHAR SourceElementAddress[2];
1646     UCHAR Destination1ElementAddress[2];
1647     UCHAR Destination2ElementAddress[2];
1648     UCHAR Flip1:1;
1649     UCHAR Flip2:1;
1650     UCHAR Reserved3:6;
1651     UCHAR Control;
1652   } EXCHANGE_MEDIUM, *PEXCHANGE_MEDIUM;
1653   struct _READ_ELEMENT_STATUS {
1654     UCHAR OperationCode;
1655     UCHAR ElementType:4;
1656     UCHAR VolTag:1;
1657     UCHAR LogicalUnitNumber:3;
1658     UCHAR StartingElementAddress[2];
1659     UCHAR NumberOfElements[2];
1660     UCHAR Reserved1;
1661     UCHAR AllocationLength[3];
1662     UCHAR Reserved2;
1663     UCHAR Control;
1664   } READ_ELEMENT_STATUS, *PREAD_ELEMENT_STATUS;
1665   struct _SEND_VOLUME_TAG {
1666     UCHAR OperationCode;
1667     UCHAR ElementType:4;
1668     UCHAR Reserved1:1;
1669     UCHAR LogicalUnitNumber:3;
1670     UCHAR StartingElementAddress[2];
1671     UCHAR Reserved2;
1672     UCHAR ActionCode:5;
1673     UCHAR Reserved3:3;
1674     UCHAR Reserved4[2];
1675     UCHAR ParameterListLength[2];
1676     UCHAR Reserved5;
1677     UCHAR Control;
1678   } SEND_VOLUME_TAG, *PSEND_VOLUME_TAG;
1679   struct _REQUEST_VOLUME_ELEMENT_ADDRESS {
1680     UCHAR OperationCode;
1681     UCHAR ElementType:4;
1682     UCHAR VolTag:1;
1683     UCHAR LogicalUnitNumber:3;
1684     UCHAR StartingElementAddress[2];
1685     UCHAR NumberElements[2];
1686     UCHAR Reserved1;
1687     UCHAR AllocationLength[3];
1688     UCHAR Reserved2;
1689     UCHAR Control;
1690   } REQUEST_VOLUME_ELEMENT_ADDRESS, *PREQUEST_VOLUME_ELEMENT_ADDRESS;
1691   struct _LOAD_UNLOAD {
1692     UCHAR OperationCode;
1693     UCHAR Immediate:1;
1694     UCHAR Reserved1:4;
1695     UCHAR Lun:3;
1696     UCHAR Reserved2[2];
1697     UCHAR Start:1;
1698     UCHAR LoadEject:1;
1699     UCHAR Reserved3:6;
1700     UCHAR Reserved4[3];
1701     UCHAR Slot;
1702     UCHAR Reserved5[3];
1703   } LOAD_UNLOAD, *PLOAD_UNLOAD;
1704   struct _MECH_STATUS {
1705     UCHAR OperationCode;
1706     UCHAR Reserved:5;
1707     UCHAR Lun:3;
1708     UCHAR Reserved1[6];
1709     UCHAR AllocationLength[2];
1710     UCHAR Reserved2[1];
1711     UCHAR Control;
1712   } MECH_STATUS, *PMECH_STATUS;
1713   struct _SYNCHRONIZE_CACHE10 {
1714     UCHAR OperationCode;
1715     UCHAR RelAddr:1;
1716     UCHAR Immediate:1;
1717     UCHAR Reserved:3;
1718     UCHAR Lun:3;
1719     UCHAR LogicalBlockAddress[4];
1720     UCHAR Reserved2;
1721     UCHAR BlockCount[2];
1722     UCHAR Control;
1723   } SYNCHRONIZE_CACHE10, *PSYNCHRONIZE_CACHE10;
1724   struct _GET_EVENT_STATUS_NOTIFICATION {
1725     UCHAR OperationCode;
1726     UCHAR Immediate:1;
1727     UCHAR Reserved:4;
1728     UCHAR Lun:3;
1729     UCHAR Reserved2[2];
1730     UCHAR NotificationClassRequest;
1731     UCHAR Reserved3[2];
1732     UCHAR EventListLength[2];
1733     UCHAR Control;
1734   } GET_EVENT_STATUS_NOTIFICATION, *PGET_EVENT_STATUS_NOTIFICATION;
1735   struct _GET_PERFORMANCE {
1736     UCHAR OperationCode;
1737     UCHAR Except:2;
1738     UCHAR Write:1;
1739     UCHAR Tolerance:2;
1740     UCHAR Reserved0:3;
1741     UCHAR StartingLBA[4];
1742     UCHAR Reserved1[2];
1743     UCHAR MaximumNumberOfDescriptors[2];
1744     UCHAR Type;
1745     UCHAR Control;
1746   } GET_PERFORMANCE;
1747   struct _READ_DVD_STRUCTURE {
1748     UCHAR OperationCode;
1749     UCHAR Reserved1:5;
1750     UCHAR Lun:3;
1751     UCHAR RMDBlockNumber[4];
1752     UCHAR LayerNumber;
1753     UCHAR Format;
1754     UCHAR AllocationLength[2];
1755     UCHAR Reserved3:6;
1756     UCHAR AGID:2;
1757     UCHAR Control;
1758   } READ_DVD_STRUCTURE, *PREAD_DVD_STRUCTURE;
1759   struct _SET_STREAMING {
1760     UCHAR OperationCode;
1761     UCHAR Reserved[8];
1762     UCHAR ParameterListLength[2];
1763     UCHAR Control;
1764   } SET_STREAMING;
1765   struct _SEND_DVD_STRUCTURE {
1766     UCHAR OperationCode;
1767     UCHAR Reserved1:5;
1768     UCHAR Lun:3;
1769     UCHAR Reserved2[5];
1770     UCHAR Format;
1771     UCHAR ParameterListLength[2];
1772     UCHAR Reserved3;
1773     UCHAR Control;
1774   } SEND_DVD_STRUCTURE, *PSEND_DVD_STRUCTURE;
1775   struct _SEND_KEY {
1776     UCHAR OperationCode;
1777     UCHAR Reserved1:5;
1778     UCHAR Lun:3;
1779     UCHAR Reserved2[6];
1780     UCHAR ParameterListLength[2];
1781     UCHAR KeyFormat:6;
1782     UCHAR AGID:2;
1783     UCHAR Control;
1784   } SEND_KEY, *PSEND_KEY;
1785   struct _REPORT_KEY {
1786     UCHAR OperationCode;
1787     UCHAR Reserved1:5;
1788     UCHAR Lun:3;
1789     UCHAR LogicalBlockAddress[4];
1790     UCHAR Reserved2[2];
1791     UCHAR AllocationLength[2];
1792     UCHAR KeyFormat:6;
1793     UCHAR AGID:2;
1794     UCHAR Control;
1795   } REPORT_KEY, *PREPORT_KEY;
1796   struct _SET_READ_AHEAD {
1797     UCHAR OperationCode;
1798     UCHAR Reserved1:5;
1799     UCHAR Lun:3;
1800     UCHAR TriggerLBA[4];
1801     UCHAR ReadAheadLBA[4];
1802     UCHAR Reserved2;
1803     UCHAR Control;
1804   } SET_READ_AHEAD, *PSET_READ_AHEAD;
1805   struct _READ_FORMATTED_CAPACITIES {
1806     UCHAR OperationCode;
1807     UCHAR Reserved1:5;
1808     UCHAR Lun:3;
1809     UCHAR Reserved2[5];
1810     UCHAR AllocationLength[2];
1811     UCHAR Control;
1812   } READ_FORMATTED_CAPACITIES, *PREAD_FORMATTED_CAPACITIES;
1813   struct _REPORT_LUNS {
1814     UCHAR OperationCode;
1815     UCHAR Reserved1[5];
1816     UCHAR AllocationLength[4];
1817     UCHAR Reserved2[1];
1818     UCHAR Control;
1819   } REPORT_LUNS, *PREPORT_LUNS;
1820   struct _PERSISTENT_RESERVE_IN {
1821     UCHAR OperationCode;
1822     UCHAR ServiceAction:5;
1823     UCHAR Reserved1:3;
1824     UCHAR Reserved2[5];
1825     UCHAR AllocationLength[2];
1826     UCHAR Control;
1827   } PERSISTENT_RESERVE_IN, *PPERSISTENT_RESERVE_IN;
1828   struct _PERSISTENT_RESERVE_OUT {
1829     UCHAR OperationCode;
1830     UCHAR ServiceAction:5;
1831     UCHAR Reserved1:3;
1832     UCHAR Type:4;
1833     UCHAR Scope:4;
1834     UCHAR Reserved2[4];
1835     UCHAR ParameterListLength[2];
1836     UCHAR Control;
1837   } PERSISTENT_RESERVE_OUT, *PPERSISTENT_RESERVE_OUT;
1838   struct _GET_CONFIGURATION {
1839     UCHAR OperationCode;
1840     UCHAR RequestType:1;
1841     UCHAR Reserved1:7;
1842     UCHAR StartingFeature[2];
1843     UCHAR Reserved2[3];
1844     UCHAR AllocationLength[2];
1845     UCHAR Control;
1846   } GET_CONFIGURATION, *PGET_CONFIGURATION;
1847   struct _SET_CD_SPEED {
1848     UCHAR OperationCode;
1849     _ANONYMOUS_UNION union {
1850       UCHAR Reserved1;
1851       _ANONYMOUS_STRUCT struct {
1852         UCHAR RotationControl:2;
1853         UCHAR Reserved3:6;
1854       } DUMMYSTRUCTNAME;
1855     } DUMMYUNIONNAME;
1856     UCHAR ReadSpeed[2];
1857     UCHAR WriteSpeed[2];
1858     UCHAR Reserved2[5];
1859     UCHAR Control;
1860   } SET_CD_SPEED, *PSET_CD_SPEED;
1861   struct _READ12 {
1862     UCHAR OperationCode;
1863     UCHAR RelativeAddress:1;
1864     UCHAR Reserved1:2;
1865     UCHAR ForceUnitAccess:1;
1866     UCHAR DisablePageOut:1;
1867     UCHAR LogicalUnitNumber:3;
1868     UCHAR LogicalBlock[4];
1869     UCHAR TransferLength[4];
1870     UCHAR Reserved2:7;
1871     UCHAR Streaming:1;
1872     UCHAR Control;
1873   } READ12;
1874   struct _WRITE12 {
1875     UCHAR OperationCode;
1876     UCHAR RelativeAddress:1;
1877     UCHAR Reserved1:1;
1878     UCHAR EBP:1;
1879     UCHAR ForceUnitAccess:1;
1880     UCHAR DisablePageOut:1;
1881     UCHAR LogicalUnitNumber:3;
1882     UCHAR LogicalBlock[4];
1883     UCHAR TransferLength[4];
1884     UCHAR Reserved2:7;
1885     UCHAR Streaming:1;
1886     UCHAR Control;
1887   } WRITE12;
1888   struct _READ16 {
1889     UCHAR OperationCode;
1890     UCHAR Reserved1:3;
1891     UCHAR ForceUnitAccess:1;
1892     UCHAR DisablePageOut:1;
1893     UCHAR ReadProtect:3;
1894     UCHAR LogicalBlock[8];
1895     UCHAR TransferLength[4];
1896     UCHAR Reserved2:7;
1897     UCHAR Streaming:1;
1898     UCHAR Control;
1899   } READ16;
1900   struct _WRITE16 {
1901     UCHAR OperationCode;
1902     UCHAR Reserved1:3;
1903     UCHAR ForceUnitAccess:1;
1904     UCHAR DisablePageOut:1;
1905     UCHAR WriteProtect:3;
1906     UCHAR LogicalBlock[8];
1907     UCHAR TransferLength[4];
1908     UCHAR Reserved2:7;
1909     UCHAR Streaming:1;
1910     UCHAR Control;
1911   } WRITE16;
1912   struct _VERIFY16 {
1913     UCHAR OperationCode;
1914     UCHAR Reserved1:1;
1915     UCHAR ByteCheck:1;
1916     UCHAR BlockVerify:1;
1917     UCHAR Reserved2: 1;
1918     UCHAR DisablePageOut:1;
1919     UCHAR VerifyProtect:3;
1920     UCHAR LogicalBlock[8];
1921     UCHAR VerificationLength[4];
1922     UCHAR Reserved3:7;
1923     UCHAR Streaming:1;
1924     UCHAR Control;
1925   } VERIFY16;
1926   struct _SYNCHRONIZE_CACHE16 {
1927     UCHAR OperationCode;
1928     UCHAR Reserved1:1;
1929     UCHAR Immediate:1;
1930     UCHAR Reserved2:6;
1931     UCHAR LogicalBlock[8];
1932     UCHAR BlockCount[4];
1933     UCHAR Reserved3;
1934     UCHAR Control;
1935   } SYNCHRONIZE_CACHE16;
1936   struct _READ_CAPACITY16 {
1937     UCHAR OperationCode;
1938     UCHAR ServiceAction:5;
1939     UCHAR Reserved1:3;
1940     UCHAR LogicalBlock[8];
1941     UCHAR AllocationLength[4];
1942     UCHAR PMI:1;
1943     UCHAR Reserved2:7;
1944     UCHAR Control;
1945   } READ_CAPACITY16;
1946   struct _TOKEN_OPERATION {
1947     UCHAR OperationCode;
1948     UCHAR ServiceAction:5;
1949     UCHAR Reserved1:3;
1950     UCHAR Reserved2[4];
1951     UCHAR ListIdentifier[4];
1952     UCHAR ParameterListLength[4];
1953     UCHAR GroupNumber:5;
1954     UCHAR Reserved3:3;
1955     UCHAR Control;
1956   } TOKEN_OPERATION;
1957   struct _RECEIVE_TOKEN_INFORMATION {
1958     UCHAR OperationCode;
1959     UCHAR ServiceAction:5;
1960     UCHAR Reserved1:3;
1961     UCHAR ListIdentifier[4];
1962     UCHAR Reserved2[4];
1963     UCHAR AllocationLength[4];
1964     UCHAR Reserved3;
1965     UCHAR Control;
1966   } RECEIVE_TOKEN_INFORMATION;
1967   struct _UNMAP {
1968     UCHAR OperationCode;
1969     UCHAR Anchor:1;
1970     UCHAR Reserved1:7;
1971     UCHAR Reserved2[4];
1972     UCHAR GroupNumber:5;
1973     UCHAR Reserved3:3;
1974     UCHAR AllocationLength[2];
1975     UCHAR Control;
1976   } UNMAP;
1977   struct _GET_LBA_STATUS {
1978     UCHAR OperationCode;
1979     UCHAR ServiceAction:5;
1980     UCHAR Reserved1:3;
1981     UCHAR StartingLBA[8];
1982     UCHAR AllocationLength[4];
1983     UCHAR Reserved2;
1984     UCHAR Control;
1985   } GET_LBA_STATUS;
1986   ULONG AsUlong[4];
1987   UCHAR AsByte[16];
1988 } CDB, *PCDB;
1989 
1990 typedef struct _NOTIFICATION_EVENT_STATUS_HEADER {
1991   UCHAR EventDataLength[2];
1992   UCHAR NotificationClass:3;
1993   UCHAR Reserved:4;
1994   UCHAR NEA:1;
1995   UCHAR SupportedEventClasses;
1996   UCHAR ClassEventData[0];
1997 } NOTIFICATION_EVENT_STATUS_HEADER, *PNOTIFICATION_EVENT_STATUS_HEADER;
1998 
1999 typedef struct _NOTIFICATION_OPERATIONAL_STATUS {
2000   UCHAR OperationalEvent:4;
2001   UCHAR Reserved1:4;
2002   UCHAR OperationalStatus:4;
2003   UCHAR Reserved2:3;
2004   UCHAR PersistentPrevented:1;
2005   UCHAR Operation[2];
2006 } NOTIFICATION_OPERATIONAL_STATUS, *PNOTIFICATION_OPERATIONAL_STATUS;
2007 
2008 typedef struct _NOTIFICATION_POWER_STATUS {
2009   UCHAR PowerEvent:4;
2010   UCHAR Reserved:4;
2011   UCHAR PowerStatus;
2012   UCHAR Reserved2[2];
2013 } NOTIFICATION_POWER_STATUS, *PNOTIFICATION_POWER_STATUS;
2014 
2015 typedef struct _NOTIFICATION_EXTERNAL_STATUS {
2016   UCHAR ExternalEvent:4;
2017   UCHAR Reserved1:4;
2018   UCHAR ExternalStatus:4;
2019   UCHAR Reserved2:3;
2020   UCHAR PersistentPrevented:1;
2021   UCHAR Request[2];
2022 } NOTIFICATION_EXTERNAL_STATUS, *PNOTIFICATION_EXTERNAL_STATUS;
2023 
2024 typedef struct _NOTIFICATION_MEDIA_STATUS {
2025   UCHAR MediaEvent:4;
2026   UCHAR Reserved:4;
2027   _ANONYMOUS_UNION union {
2028     UCHAR PowerStatus;
2029     UCHAR MediaStatus;
2030     _ANONYMOUS_STRUCT struct {
2031       UCHAR DoorTrayOpen:1;
2032       UCHAR MediaPresent:1;
2033       UCHAR ReservedX:6;
2034     } DUMMYSTRUCTNAME;
2035   } DUMMYUNIONNAME;
2036   UCHAR StartSlot;
2037   UCHAR EndSlot;
2038 } NOTIFICATION_MEDIA_STATUS, *PNOTIFICATION_MEDIA_STATUS;
2039 
2040 typedef struct _NOTIFICATION_MULTI_HOST_STATUS {
2041   UCHAR MultiHostEvent:4;
2042   UCHAR Reserved1:4;
2043   UCHAR MultiHostStatus:4;
2044   UCHAR Reserved2:3;
2045   UCHAR PersistentPrevented:1;
2046   UCHAR Priority[2];
2047 } NOTIFICATION_MULTI_HOST_STATUS, *PNOTIFICATION_MULTI_HOST_STATUS;
2048 
2049 typedef struct _NOTIFICATION_BUSY_STATUS {
2050   UCHAR DeviceBusyEvent:4;
2051   UCHAR Reserved:4;
2052   UCHAR DeviceBusyStatus;
2053   UCHAR Time[2];
2054 } NOTIFICATION_BUSY_STATUS, *PNOTIFICATION_BUSY_STATUS;
2055 
2056 typedef struct _READ_DVD_STRUCTURES_HEADER {
2057   UCHAR Length[2];
2058   UCHAR Reserved[2];
2059   UCHAR Data[0];
2060 } READ_DVD_STRUCTURES_HEADER, *PREAD_DVD_STRUCTURES_HEADER;
2061 
2062 typedef struct _CDVD_KEY_HEADER {
2063   UCHAR DataLength[2];
2064   UCHAR Reserved[2];
2065   UCHAR Data[0];
2066 } CDVD_KEY_HEADER, *PCDVD_KEY_HEADER;
2067 
2068 typedef struct _CDVD_REPORT_AGID_DATA {
2069   UCHAR Reserved1[3];
2070   UCHAR Reserved2:6;
2071   UCHAR AGID:2;
2072 } CDVD_REPORT_AGID_DATA, *PCDVD_REPORT_AGID_DATA;
2073 
2074 typedef struct _CDVD_CHALLENGE_KEY_DATA {
2075   UCHAR ChallengeKeyValue[10];
2076   UCHAR Reserved[2];
2077 } CDVD_CHALLENGE_KEY_DATA, *PCDVD_CHALLENGE_KEY_DATA;
2078 
2079 typedef struct _CDVD_KEY_DATA {
2080   UCHAR Key[5];
2081   UCHAR Reserved[3];
2082 } CDVD_KEY_DATA, *PCDVD_KEY_DATA;
2083 
2084 typedef struct _CDVD_REPORT_ASF_DATA {
2085   UCHAR Reserved1[3];
2086   UCHAR Success:1;
2087   UCHAR Reserved2:7;
2088 } CDVD_REPORT_ASF_DATA, *PCDVD_REPORT_ASF_DATA;
2089 
2090 typedef struct _CDVD_TITLE_KEY_HEADER {
2091   UCHAR DataLength[2];
2092   UCHAR Reserved1[1];
2093   UCHAR Reserved2:3;
2094   UCHAR CGMS:2;
2095   UCHAR CP_SEC:1;
2096   UCHAR CPM:1;
2097   UCHAR Zero:1;
2098   CDVD_KEY_DATA TitleKey;
2099 } CDVD_TITLE_KEY_HEADER, *PCDVD_TITLE_KEY_HEADER;
2100 
2101 typedef struct _FORMAT_DESCRIPTOR {
2102   UCHAR NumberOfBlocks[4];
2103   UCHAR FormatSubType:2;
2104   UCHAR FormatType:6;
2105   UCHAR BlockLength[3];
2106 } FORMAT_DESCRIPTOR, *PFORMAT_DESCRIPTOR;
2107 
2108 typedef struct _FORMAT_LIST_HEADER {
2109   UCHAR Reserved;
2110   UCHAR VendorSpecific:1;
2111   UCHAR Immediate:1;
2112   UCHAR TryOut:1;
2113   UCHAR IP:1;
2114   UCHAR STPF:1;
2115   UCHAR DCRT:1;
2116   UCHAR DPRY:1;
2117   UCHAR FOV:1;
2118   UCHAR FormatDescriptorLength[2];
2119   FORMAT_DESCRIPTOR Descriptors[0];
2120 } FORMAT_LIST_HEADER, *PFORMAT_LIST_HEADER;
2121 
2122 typedef struct _FORMATTED_CAPACITY_DESCRIPTOR {
2123   UCHAR NumberOfBlocks[4];
2124   UCHAR Maximum:1;
2125   UCHAR Valid:1;
2126   UCHAR FormatType:6;
2127   UCHAR BlockLength[3];
2128 } FORMATTED_CAPACITY_DESCRIPTOR, *PFORMATTED_CAPACITY_DESCRIPTOR;
2129 
2130 typedef struct _FORMATTED_CAPACITY_LIST {
2131   UCHAR Reserved[3];
2132   UCHAR CapacityListLength;
2133   FORMATTED_CAPACITY_DESCRIPTOR Descriptors[0];
2134 } FORMATTED_CAPACITY_LIST, *PFORMATTED_CAPACITY_LIST;
2135 
2136 typedef struct _OPC_TABLE_ENTRY {
2137   UCHAR Speed[2];
2138   UCHAR OPCValue[6];
2139 } OPC_TABLE_ENTRY, *POPC_TABLE_ENTRY;
2140 
2141 typedef struct _DISC_INFORMATION {
2142   UCHAR Length[2];
2143   UCHAR DiscStatus:2;
2144   UCHAR LastSessionStatus:2;
2145   UCHAR Erasable:1;
2146   UCHAR Reserved1:3;
2147   UCHAR FirstTrackNumber;
2148   UCHAR NumberOfSessionsLsb;
2149   UCHAR LastSessionFirstTrackLsb;
2150   UCHAR LastSessionLastTrackLsb;
2151   UCHAR MrwStatus:2;
2152   UCHAR MrwDirtyBit:1;
2153   UCHAR Reserved2:2;
2154   UCHAR URU:1;
2155   UCHAR DBC_V:1;
2156   UCHAR DID_V:1;
2157   UCHAR DiscType;
2158   UCHAR NumberOfSessionsMsb;
2159   UCHAR LastSessionFirstTrackMsb;
2160   UCHAR LastSessionLastTrackMsb;
2161   UCHAR DiskIdentification[4];
2162   UCHAR LastSessionLeadIn[4];
2163   UCHAR LastPossibleLeadOutStartTime[4];
2164   UCHAR DiskBarCode[8];
2165   UCHAR Reserved4;
2166   UCHAR NumberOPCEntries;
2167   OPC_TABLE_ENTRY OPCTable[1];
2168 } DISC_INFORMATION, *PDISC_INFORMATION;
2169 
2170 typedef struct _DISK_INFORMATION {
2171   UCHAR Length[2];
2172   UCHAR DiskStatus:2;
2173   UCHAR LastSessionStatus:2;
2174   UCHAR Erasable:1;
2175   UCHAR Reserved1:3;
2176   UCHAR FirstTrackNumber;
2177   UCHAR NumberOfSessions;
2178   UCHAR LastSessionFirstTrack;
2179   UCHAR LastSessionLastTrack;
2180   UCHAR Reserved2:5;
2181   UCHAR GEN:1;
2182   UCHAR DBC_V:1;
2183   UCHAR DID_V:1;
2184   UCHAR DiskType;
2185   UCHAR Reserved3[3];
2186   UCHAR DiskIdentification[4];
2187   UCHAR LastSessionLeadIn[4];
2188   UCHAR LastPossibleStartTime[4];
2189   UCHAR DiskBarCode[8];
2190   UCHAR Reserved4;
2191   UCHAR NumberOPCEntries;
2192   OPC_TABLE_ENTRY OPCTable[0];
2193 } DISK_INFORMATION, *PDISK_INFORMATION;
2194 
2195 typedef struct _DATA_BLOCK_HEADER {
2196   UCHAR DataMode;
2197   UCHAR Reserved[4];
2198   _ANONYMOUS_UNION union {
2199     UCHAR LogicalBlockAddress[4];
2200     struct {
2201       UCHAR Reserved;
2202       UCHAR M;
2203       UCHAR S;
2204       UCHAR F;
2205     } MSF;
2206   } DUMMYUNIONNAME;
2207 } DATA_BLOCK_HEADER, *PDATA_BLOCK_HEADER;
2208 
2209 typedef struct _TRACK_INFORMATION {
2210   UCHAR Length[2];
2211   UCHAR TrackNumber;
2212   UCHAR SessionNumber;
2213   UCHAR Reserved1;
2214   UCHAR TrackMode:4;
2215   UCHAR Copy:1;
2216   UCHAR Damage:1;
2217   UCHAR Reserved2:2;
2218   UCHAR DataMode:4;
2219   UCHAR FP:1;
2220   UCHAR Packet:1;
2221   UCHAR Blank:1;
2222   UCHAR RT:1;
2223   UCHAR NWA_V:1;
2224   UCHAR Reserved3:7;
2225   UCHAR TrackStartAddress[4];
2226   UCHAR NextWritableAddress[4];
2227   UCHAR FreeBlocks[4];
2228   UCHAR FixedPacketSize[4];
2229 } TRACK_INFORMATION, *PTRACK_INFORMATION;
2230 
2231 typedef struct _TRACK_INFORMATION2 {
2232   UCHAR Length[2];
2233   UCHAR TrackNumberLsb;
2234   UCHAR SessionNumberLsb;
2235   UCHAR Reserved4;
2236   UCHAR TrackMode:4;
2237   UCHAR Copy:1;
2238   UCHAR Damage:1;
2239   UCHAR Reserved5:2;
2240   UCHAR DataMode:4;
2241   UCHAR FixedPacket:1;
2242   UCHAR Packet:1;
2243   UCHAR Blank:1;
2244   UCHAR ReservedTrack:1;
2245   UCHAR NWA_V:1;
2246   UCHAR LRA_V:1;
2247   UCHAR Reserved6:6;
2248   UCHAR TrackStartAddress[4];
2249   UCHAR NextWritableAddress[4];
2250   UCHAR FreeBlocks[4];
2251   UCHAR FixedPacketSize[4];
2252   UCHAR TrackSize[4];
2253   UCHAR LastRecordedAddress[4];
2254   UCHAR TrackNumberMsb;
2255   UCHAR SessionNumberMsb;
2256   UCHAR Reserved7[2];
2257 } TRACK_INFORMATION2, *PTRACK_INFORMATION2;
2258 
2259 typedef struct _TRACK_INFORMATION3 {
2260   UCHAR Length[2];
2261   UCHAR TrackNumberLsb;
2262   UCHAR SessionNumberLsb;
2263   UCHAR Reserved4;
2264   UCHAR TrackMode:4;
2265   UCHAR Copy:1;
2266   UCHAR Damage:1;
2267   UCHAR Reserved5:2;
2268   UCHAR DataMode:4;
2269   UCHAR FixedPacket:1;
2270   UCHAR Packet:1;
2271   UCHAR Blank:1;
2272   UCHAR ReservedTrack:1;
2273   UCHAR NWA_V:1;
2274   UCHAR LRA_V:1;
2275   UCHAR Reserved6:6;
2276   UCHAR TrackStartAddress[4];
2277   UCHAR NextWritableAddress[4];
2278   UCHAR FreeBlocks[4];
2279   UCHAR FixedPacketSize[4];
2280   UCHAR TrackSize[4];
2281   UCHAR LastRecordedAddress[4];
2282   UCHAR TrackNumberMsb;
2283   UCHAR SessionNumberMsb;
2284   UCHAR Reserved7[2];
2285   UCHAR ReadCompatibilityLba[4];
2286 } TRACK_INFORMATION3, *PTRACK_INFORMATION3;
2287 
2288 typedef struct _PERFORMANCE_DESCRIPTOR {
2289   UCHAR RandomAccess:1;
2290   UCHAR Exact:1;
2291   UCHAR RestoreDefaults:1;
2292   UCHAR WriteRotationControl:2;
2293   UCHAR Reserved1:3;
2294   UCHAR Reserved[3];
2295   UCHAR StartLba[4];
2296   UCHAR EndLba[4];
2297   UCHAR ReadSize[4];
2298   UCHAR ReadTime[4];
2299   UCHAR WriteSize[4];
2300   UCHAR WriteTime[4];
2301 } PERFORMANCE_DESCRIPTOR, *PPERFORMANCE_DESCRIPTOR;
2302 
2303 typedef struct _SCSI_EXTENDED_MESSAGE {
2304   UCHAR InitialMessageCode;
2305   UCHAR MessageLength;
2306   UCHAR MessageType;
2307   union _EXTENDED_ARGUMENTS {
2308     struct {
2309       UCHAR Modifier[4];
2310     } Modify;
2311     struct {
2312       UCHAR TransferPeriod;
2313       UCHAR ReqAckOffset;
2314     } Synchronous;
2315     struct{
2316       UCHAR Width;
2317     } Wide;
2318   } ExtendedArguments;
2319 }SCSI_EXTENDED_MESSAGE, *PSCSI_EXTENDED_MESSAGE;
2320 
2321 #ifndef _INQUIRYDATA_DEFINED /* also in minitape.h */
2322 #define _INQUIRYDATA_DEFINED
2323 
2324 #define INQUIRYDATABUFFERSIZE 36
2325 
2326 #if (NTDDI_VERSION < NTDDI_WINXP)
2327 typedef struct _INQUIRYDATA {
2328   UCHAR DeviceType:5;
2329   UCHAR DeviceTypeQualifier:3;
2330   UCHAR DeviceTypeModifier:7;
2331   UCHAR RemovableMedia:1;
2332   UCHAR Versions;
2333   UCHAR ResponseDataFormat:4;
2334   UCHAR HiSupport:1;
2335   UCHAR NormACA:1;
2336   UCHAR ReservedBit:1;
2337   UCHAR AERC:1;
2338   UCHAR AdditionalLength;
2339   UCHAR Reserved[2];
2340   UCHAR SoftReset:1;
2341   UCHAR CommandQueue:1;
2342   UCHAR Reserved2:1;
2343   UCHAR LinkedCommands:1;
2344   UCHAR Synchronous:1;
2345   UCHAR Wide16Bit:1;
2346   UCHAR Wide32Bit:1;
2347   UCHAR RelativeAddressing:1;
2348   UCHAR VendorId[8];
2349   UCHAR ProductId[16];
2350   UCHAR ProductRevisionLevel[4];
2351   UCHAR VendorSpecific[20];
2352   UCHAR Reserved3[40];
2353 } INQUIRYDATA, *PINQUIRYDATA;
2354 #else
2355 typedef struct _INQUIRYDATA {
2356   UCHAR DeviceType:5;
2357   UCHAR DeviceTypeQualifier:3;
2358   UCHAR DeviceTypeModifier:7;
2359   UCHAR RemovableMedia:1;
2360   _ANONYMOUS_UNION union {
2361     UCHAR Versions;
2362     _ANONYMOUS_STRUCT struct {
2363       UCHAR ANSIVersion:3;
2364       UCHAR ECMAVersion:3;
2365       UCHAR ISOVersion:2;
2366     } DUMMYSTRUCTNAME;
2367   } DUMMYUNIONNAME;
2368   UCHAR ResponseDataFormat:4;
2369   UCHAR HiSupport:1;
2370   UCHAR NormACA:1;
2371   UCHAR TerminateTask:1;
2372   UCHAR AERC:1;
2373   UCHAR AdditionalLength;
2374   UCHAR Reserved;
2375   UCHAR Addr16:1;
2376   UCHAR Addr32:1;
2377   UCHAR AckReqQ:1;
2378   UCHAR MediumChanger:1;
2379   UCHAR MultiPort:1;
2380   UCHAR ReservedBit2:1;
2381   UCHAR EnclosureServices:1;
2382   UCHAR ReservedBit3:1;
2383   UCHAR SoftReset:1;
2384   UCHAR CommandQueue:1;
2385   UCHAR TransferDisable:1;
2386   UCHAR LinkedCommands:1;
2387   UCHAR Synchronous:1;
2388   UCHAR Wide16Bit:1;
2389   UCHAR Wide32Bit:1;
2390   UCHAR RelativeAddressing:1;
2391   UCHAR VendorId[8];
2392   UCHAR ProductId[16];
2393   UCHAR ProductRevisionLevel[4];
2394   UCHAR VendorSpecific[20];
2395   UCHAR Reserved3[40];
2396 } INQUIRYDATA, *PINQUIRYDATA;
2397 #endif /* (NTDDI_VERSION < NTDDI_WINXP) */
2398 
2399 #endif /* _INQUIRYDATA_DEFINED */
2400 
2401 #define VPD_MAX_BUFFER_SIZE                0xff
2402 
2403 #define VPD_SUPPORTED_PAGES                0x00
2404 #define VPD_SERIAL_NUMBER                  0x80
2405 #define VPD_DEVICE_IDENTIFIERS             0x83
2406 #define VPD_MEDIA_SERIAL_NUMBER            0x84
2407 #define VPD_SOFTWARE_INTERFACE_IDENTIFIERS 0x84
2408 #define VPD_NETWORK_MANAGEMENT_ADDRESSES   0x85
2409 #define VPD_EXTENDED_INQUIRY_DATA          0x86
2410 #define VPD_MODE_PAGE_POLICY               0x87
2411 #define VPD_SCSI_PORTS                     0x88
2412 #define VPD_ATA_INFORMATION                0x89
2413 
2414 #define VPD_THIRD_PARTY_COPY               0x8F
2415 #define VPD_BLOCK_LIMITS                   0xB0
2416 #define VPD_BLOCK_DEVICE_CHARACTERISTICS   0xB1
2417 #define VPD_LOGICAL_BLOCK_PROVISIONING     0xB2
2418 #define VPD_ZONED_BLOCK_DEVICE_CHARACTERISTICS  0xB6
2419 
2420 typedef struct _VPD_MEDIA_SERIAL_NUMBER_PAGE {
2421   UCHAR DeviceType:5;
2422   UCHAR DeviceTypeQualifier:3;
2423   UCHAR PageCode;
2424   UCHAR Reserved;
2425   UCHAR PageLength;
2426   UCHAR SerialNumber[0];
2427 } VPD_MEDIA_SERIAL_NUMBER_PAGE, *PVPD_MEDIA_SERIAL_NUMBER_PAGE;
2428 
2429 typedef struct _VPD_SERIAL_NUMBER_PAGE {
2430   UCHAR DeviceType:5;
2431   UCHAR DeviceTypeQualifier:3;
2432   UCHAR PageCode;
2433   UCHAR Reserved;
2434   UCHAR PageLength;
2435   UCHAR SerialNumber[0];
2436 } VPD_SERIAL_NUMBER_PAGE, *PVPD_SERIAL_NUMBER_PAGE;
2437 
2438 typedef enum _VPD_CODE_SET {
2439   VpdCodeSetReserved = 0,
2440   VpdCodeSetBinary = 1,
2441   VpdCodeSetAscii = 2,
2442   VpdCodeSetUTF8 = 3
2443 } VPD_CODE_SET, *PVPD_CODE_SET;
2444 
2445 typedef enum _VPD_ASSOCIATION {
2446   VpdAssocDevice = 0,
2447   VpdAssocPort = 1,
2448   VpdAssocTarget = 2,
2449   VpdAssocReserved1 = 3,
2450   VpdAssocReserved2 = 4
2451 } VPD_ASSOCIATION, *PVPD_ASSOCIATION;
2452 
2453 typedef enum _VPD_IDENTIFIER_TYPE {
2454   VpdIdentifierTypeVendorSpecific = 0,
2455   VpdIdentifierTypeVendorId = 1,
2456   VpdIdentifierTypeEUI64 = 2,
2457   VpdIdentifierTypeFCPHName = 3,
2458   VpdIdentifierTypePortRelative = 4,
2459   VpdIdentifierTypeTargetPortGroup = 5,
2460   VpdIdentifierTypeLogicalUnitGroup = 6,
2461   VpdIdentifierTypeMD5LogicalUnitId = 7,
2462   VpdIdentifierTypeSCSINameString = 8
2463 } VPD_IDENTIFIER_TYPE, *PVPD_IDENTIFIER_TYPE;
2464 
2465 typedef struct _VPD_IDENTIFICATION_DESCRIPTOR {
2466   UCHAR CodeSet:4;
2467   UCHAR Reserved:4;
2468   UCHAR IdentifierType:4;
2469   UCHAR Association:2;
2470   UCHAR Reserved2:2;
2471   UCHAR Reserved3;
2472   UCHAR IdentifierLength;
2473   UCHAR Identifier[0];
2474 } VPD_IDENTIFICATION_DESCRIPTOR, *PVPD_IDENTIFICATION_DESCRIPTOR;
2475 
2476 typedef struct _VPD_IDENTIFICATION_PAGE {
2477   UCHAR DeviceType:5;
2478   UCHAR DeviceTypeQualifier:3;
2479   UCHAR PageCode;
2480   UCHAR Reserved;
2481   UCHAR PageLength;
2482   UCHAR Descriptors[0];
2483 } VPD_IDENTIFICATION_PAGE, *PVPD_IDENTIFICATION_PAGE;
2484 
2485 typedef struct _VPD_ATA_INFORMATION_PAGE {
2486   UCHAR DeviceType:5;
2487   UCHAR DeviceTypeQualifier:3;
2488   UCHAR PageCode;
2489   UCHAR PageLength[2];
2490   UCHAR Reserved0[4];
2491   UCHAR VendorId[8];
2492   UCHAR ProductId[16];
2493   UCHAR ProductRevisionLevel[4];
2494   UCHAR DeviceSignature[20];
2495   UCHAR CommandCode;
2496   UCHAR Reserved1[3];
2497   UCHAR IdentifyDeviceData[512];
2498 } VPD_ATA_INFORMATION_PAGE, *PVPD_ATA_INFORMATION_PAGE;
2499 
2500 #if (NTDDI_VERSION >= NTDDI_WIN8)
2501 typedef struct _VPD_THIRD_PARTY_COPY_PAGE {
2502   UCHAR DeviceType:5;
2503   UCHAR DeviceTypeQualifier:3;
2504   UCHAR PageCode;
2505   UCHAR PageLength[2];
2506 #if !defined(__midl)
2507   UCHAR ThirdPartyCopyDescriptors[ANYSIZE_ARRAY];
2508 #endif
2509 } VPD_THIRD_PARTY_COPY_PAGE, *PVPD_THIRD_PARTY_COPY_PAGE;
2510 
2511 typedef struct _WINDOWS_BLOCK_DEVICE_TOKEN_LIMITS_DESCRIPTOR {
2512   UCHAR DescriptorType[2];
2513   UCHAR DescriptorLength[2];
2514   UCHAR VendorSpecific[6];
2515   UCHAR MaximumRangeDescriptors[2];
2516   UCHAR MaximumInactivityTimer[4];
2517   UCHAR DefaultInactivityTimer[4];
2518   UCHAR MaximumTokenTransferSize[8];
2519   UCHAR OptimalTransferCount[8];
2520 } WINDOWS_BLOCK_DEVICE_TOKEN_LIMITS_DESCRIPTOR, *PWINDOWS_BLOCK_DEVICE_TOKEN_LIMITS_DESCRIPTOR;
2521 
2522 #define BLOCK_DEVICE_TOKEN_LIMITS_DESCRIPTOR_TYPE_WINDOWS       0x00
2523 
2524 #endif /* (NTDDI_VERSION >= NTDDI_WIN8) */
2525 
2526 typedef struct _VPD_BLOCK_LIMITS_PAGE {
2527   UCHAR DeviceType:5;
2528   UCHAR DeviceTypeQualifier:3;
2529   UCHAR PageCode;
2530   UCHAR PageLength[2];
2531   union {
2532     struct {
2533       UCHAR Reserved0;
2534       UCHAR MaximumCompareAndWriteLength;
2535       UCHAR OptimalTransferLengthGranularity[2];
2536       UCHAR MaximumTransferLength[4];
2537       UCHAR OptimalTransferLength[4];
2538       UCHAR MaxPrefetchXDReadXDWriteTransferLength[4];
2539       UCHAR MaximumUnmapLBACount[4];
2540       UCHAR MaximumUnmapBlockDescriptorCount[4];
2541       UCHAR OptimalUnmapGranularity[4];
2542       union {
2543         struct {
2544           UCHAR UnmapGranularityAlignmentByte3:7;
2545           UCHAR UGAValid:1;
2546           UCHAR UnmapGranularityAlignmentByte2;
2547           UCHAR UnmapGranularityAlignmentByte1;
2548           UCHAR UnmapGranularityAlignmentByte0;
2549         };
2550         UCHAR UnmapGranularityAlignment[4];
2551       };
2552       UCHAR Reserved1[28];
2553     };
2554 #if !defined(__midl)
2555   UCHAR Descriptors[0];
2556 #endif
2557   };
2558 } VPD_BLOCK_LIMITS_PAGE, *PVPD_BLOCK_LIMITS_PAGE;
2559 
2560 #define ZONED_CAPABILITIES_NOT_REPORTED       0x0
2561 #define ZONED_CAPABILITIES_HOST_AWARE         0x1
2562 #define ZONED_CAPABILITIES_DEVICE_MANAGED     0x2
2563 
2564 typedef struct _VPD_BLOCK_DEVICE_CHARACTERISTICS_PAGE {
2565   UCHAR DeviceType:5;
2566   UCHAR DeviceTypeQualifier:3;
2567   UCHAR PageCode;
2568   UCHAR Reserved0;
2569   UCHAR PageLength;
2570   UCHAR MediumRotationRateMsb;
2571   UCHAR MediumRotationRateLsb;
2572   UCHAR MediumProductType;
2573   UCHAR NominalFormFactor:4;
2574   UCHAR WACEREQ:2;
2575   UCHAR WABEREQ:2;
2576   UCHAR VBULS:1;
2577   UCHAR FUAB:1;
2578   UCHAR BOCS:1;
2579   UCHAR Reserved1:1;
2580   UCHAR ZONED:2;
2581   UCHAR Reserved2:2;
2582   UCHAR Reserved3[3];
2583   UCHAR DepopulationTime[4];
2584   UCHAR Reserved4[48];
2585 } VPD_BLOCK_DEVICE_CHARACTERISTICS_PAGE, *PVPD_BLOCK_DEVICE_CHARACTERISTICS_PAGE;
2586 
2587 #define PROVISIONING_TYPE_UNKNOWN       0x0
2588 #define PROVISIONING_TYPE_RESOURCE      0x1
2589 #define PROVISIONING_TYPE_THIN          0x2
2590 
2591 typedef struct _VPD_LOGICAL_BLOCK_PROVISIONING_PAGE {
2592   UCHAR DeviceType:5;
2593   UCHAR DeviceTypeQualifier:3;
2594   UCHAR PageCode;
2595   UCHAR PageLength[2];
2596   UCHAR ThresholdExponent;
2597   UCHAR DP:1;
2598   UCHAR ANC_SUP:1;
2599   UCHAR LBPRZ:1;
2600   UCHAR Reserved0:2;
2601   UCHAR LBPWS10:1;
2602   UCHAR LBPWS:1;
2603   UCHAR LBPU:1;
2604   UCHAR ProvisioningType:3;
2605   UCHAR Reserved1:5;
2606   UCHAR Reserved2;
2607 #if !defined(__midl)
2608   UCHAR ProvisioningGroupDescr[0];
2609 #endif
2610 } VPD_LOGICAL_BLOCK_PROVISIONING_PAGE, *PVPD_LOGICAL_BLOCK_PROVISIONING_PAGE;
2611 
2612 typedef struct _VPD_ZONED_BLOCK_DEVICE_CHARACTERISTICS_PAGE {
2613   UCHAR DeviceType:5;
2614   UCHAR DeviceTypeQualifier:3;
2615   UCHAR PageCode;
2616   UCHAR PageLength[2];
2617   UCHAR URSWRZ:1;
2618   UCHAR Reserved1:7;
2619   UCHAR Reserved2[3];
2620   UCHAR OptimalNumberOfOpenSequentialWritePreferredZone[4];
2621   UCHAR OptimalNumberOfNonSequentiallyWrittenSequentialWritePreferredZone[4];
2622   UCHAR MaxNumberOfOpenSequentialWriteRequiredZone[4];
2623   UCHAR Reserved3[44];
2624 } VPD_ZONED_BLOCK_DEVICE_CHARACTERISTICS_PAGE, *PVPD_ZONED_BLOCK_DEVICE_CHARACTERISTICS_PAGE;
2625 
2626 typedef struct _VPD_SUPPORTED_PAGES_PAGE {
2627   UCHAR DeviceType:5;
2628   UCHAR DeviceTypeQualifier:3;
2629   UCHAR PageCode;
2630   UCHAR Reserved;
2631   UCHAR PageLength;
2632   UCHAR SupportedPageList[0];
2633 } VPD_SUPPORTED_PAGES_PAGE, *PVPD_SUPPORTED_PAGES_PAGE;
2634 
2635 typedef struct _PRI_REGISTRATION_LIST {
2636   UCHAR Generation[4];
2637   UCHAR AdditionalLength[4];
2638   UCHAR ReservationKeyList[0][8];
2639 } PRI_REGISTRATION_LIST, *PPRI_REGISTRATION_LIST;
2640 
2641 typedef struct _PRI_RESERVATION_DESCRIPTOR {
2642   UCHAR ReservationKey[8];
2643   UCHAR ScopeSpecificAddress[4];
2644   UCHAR Reserved;
2645   UCHAR Type:4;
2646   UCHAR Scope:4;
2647   UCHAR Obsolete[2];
2648 } PRI_RESERVATION_DESCRIPTOR, *PPRI_RESERVATION_DESCRIPTOR;
2649 
2650 typedef struct _PRI_RESERVATION_LIST {
2651   UCHAR Generation[4];
2652   UCHAR AdditionalLength[4];
2653   PRI_RESERVATION_DESCRIPTOR Reservations[0];
2654 } PRI_RESERVATION_LIST, *PPRI_RESERVATION_LIST;
2655 
2656 typedef struct _PRO_PARAMETER_LIST {
2657   UCHAR ReservationKey[8];
2658   UCHAR ServiceActionReservationKey[8];
2659   UCHAR ScopeSpecificAddress[4];
2660   UCHAR ActivatePersistThroughPowerLoss:1;
2661   UCHAR Reserved1:7;
2662   UCHAR Reserved2;
2663   UCHAR Obsolete[2];
2664 } PRO_PARAMETER_LIST, *PPRO_PARAMETER_LIST;
2665 
2666 typedef struct _SENSE_DATA {
2667   UCHAR ErrorCode:7;
2668   UCHAR Valid:1;
2669   UCHAR SegmentNumber;
2670   UCHAR SenseKey:4;
2671   UCHAR Reserved:1;
2672   UCHAR IncorrectLength:1;
2673   UCHAR EndOfMedia:1;
2674   UCHAR FileMark:1;
2675   UCHAR Information[4];
2676   UCHAR AdditionalSenseLength;
2677   UCHAR CommandSpecificInformation[4];
2678   UCHAR AdditionalSenseCode;
2679   UCHAR AdditionalSenseCodeQualifier;
2680   UCHAR FieldReplaceableUnitCode;
2681   UCHAR SenseKeySpecific[3];
2682 } SENSE_DATA, *PSENSE_DATA;
2683 
2684 typedef struct _SCSI_SENSE_DESCRIPTOR_HEADER {
2685   UCHAR DescriptorType;
2686   UCHAR AdditionalLength;
2687 } SCSI_SENSE_DESCRIPTOR_HEADER, *PSCSI_SENSE_DESCRIPTOR_HEADER;
2688 
2689 typedef struct _SCSI_SENSE_DESCRIPTOR_INFORMATION {
2690   SCSI_SENSE_DESCRIPTOR_HEADER Header;
2691   UCHAR Valid:1;
2692   UCHAR Reserved1:7;
2693   UCHAR Reserved2;
2694   UCHAR Information[8];
2695 } SCSI_SENSE_DESCRIPTOR_INFORMATION, *PSCSI_SENSE_DESCRIPTOR_INFORMATION;
2696 
2697 typedef struct _SCSI_SENSE_DESCRIPTOR_BLOCK_COMMAND {
2698   SCSI_SENSE_DESCRIPTOR_HEADER Header;
2699   UCHAR Reserved1;
2700   UCHAR Reserved2:5;
2701   UCHAR IncorrectLength:1;
2702   UCHAR Reserved3:2;
2703 } SCSI_SENSE_DESCRIPTOR_BLOCK_COMMAND, *PSCSI_SENSE_DESCRIPTOR_BLOCK_COMMAND;
2704 
2705 typedef struct _SCSI_SENSE_DESCRIPTOR_ATA_STATUS_RETURN {
2706   SCSI_SENSE_DESCRIPTOR_HEADER Header;
2707   UCHAR Extend:1;
2708   UCHAR Reserved1:7;
2709   UCHAR Error;
2710   UCHAR SectorCount15_8;
2711   UCHAR SectorCount7_0;
2712   UCHAR LbaLow15_8;
2713   UCHAR LbaLow7_0;
2714   UCHAR LbaMid15_8;
2715   UCHAR LbaMid7_0;
2716   UCHAR LbaHigh15_8;
2717   UCHAR LbaHigh7_0;
2718   UCHAR Device;
2719   UCHAR Status;
2720 } SCSI_SENSE_DESCRIPTOR_ATA_STATUS_RETURN, *PSCSI_SENSE_DESCRIPTOR_ATA_STATUS_RETURN;
2721 
2722 typedef struct _SENSE_DATA FIXED_SENSE_DATA, *PFIXED_SENSE_DATA;
2723 
2724 typedef struct _DESCRIPTOR_SENSE_DATA {
2725   UCHAR ErrorCode:7;
2726   UCHAR Reserved1:1;
2727   UCHAR SenseKey:4;
2728   UCHAR Reserved2:4;
2729   UCHAR AdditionalSenseCode;
2730   UCHAR AdditionalSenseCodeQualifier;
2731   UCHAR Reserved3[3];
2732   UCHAR AdditionalSenseLength;
2733   UCHAR DescriptorBuffer[ANYSIZE_ARRAY];
2734 } DESCRIPTOR_SENSE_DATA, *PDESCRIPTOR_SENSE_DATA;
2735 
2736 typedef union _SENSE_DATA_EX {
2737   FIXED_SENSE_DATA FixedData;
2738   DESCRIPTOR_SENSE_DATA DescriptorData;
2739 } SENSE_DATA_EX, *PSENSE_DATA_EX;
2740 
2741 /* Read Capacity Data. Returned in Big Endian format */
2742 typedef struct _READ_CAPACITY_DATA {
2743   ULONG LogicalBlockAddress;
2744   ULONG BytesPerBlock;
2745 } READ_CAPACITY_DATA, *PREAD_CAPACITY_DATA;
2746 
2747 typedef struct _READ_CAPACITY_DATA_EX {
2748   LARGE_INTEGER LogicalBlockAddress;
2749   ULONG BytesPerBlock;
2750 } READ_CAPACITY_DATA_EX, *PREAD_CAPACITY_DATA_EX;
2751 
2752 #define RC_BASIS_LAST_LBA_NOT_SEQUENTIAL_WRITE_REQUIRED_ZONES       0x0
2753 #define RC_BASIS_LAST_LBA_ON_LOGICAL_UNIT                           0x1
2754 
2755 typedef struct _READ_CAPACITY16_DATA {
2756   LARGE_INTEGER LogicalBlockAddress;
2757   ULONG BytesPerBlock;
2758   UCHAR ProtectionEnable:1;
2759   UCHAR ProtectionType:3;
2760   UCHAR RcBasis:2;
2761   UCHAR Reserved:2;
2762   UCHAR LogicalPerPhysicalExponent:4;
2763   UCHAR ProtectionInfoExponent:4;
2764   UCHAR LowestAlignedBlock_MSB:6;
2765   UCHAR LBPRZ:1;
2766   UCHAR LBPME:1;
2767   UCHAR LowestAlignedBlock_LSB;
2768   UCHAR Reserved3[16];
2769 } READ_CAPACITY16_DATA, *PREAD_CAPACITY16_DATA;
2770 
2771 typedef struct _LBA_STATUS_DESCRIPTOR {
2772   ULONGLONG StartingLBA;
2773   ULONG LogicalBlockCount;
2774   UCHAR ProvisioningStatus:4;
2775   UCHAR Reserved1:4;
2776   UCHAR Reserved2[3];
2777 } LBA_STATUS_DESCRIPTOR, *PLBA_STATUS_DESCRIPTOR;
2778 
2779 typedef struct _LBA_STATUS_LIST_HEADER {
2780   ULONG ParameterLength;
2781   ULONG Reserved;
2782   LBA_STATUS_DESCRIPTOR Descriptors[0];
2783 } LBA_STATUS_LIST_HEADER, *PLBA_STATUS_LIST_HEADER;
2784 
2785 #define LBA_STATUS_MAPPED      0x0
2786 #define LBA_STATUS_DEALLOCATED 0x1
2787 #define LBA_STATUS_ANCHORED    0x2
2788 
2789 /* Read Block Limits Data. Returned in Big Endian format */
2790 typedef struct _READ_BLOCK_LIMITS {
2791   UCHAR Reserved;
2792   UCHAR BlockMaximumSize[3];
2793   UCHAR BlockMinimumSize[2];
2794 } READ_BLOCK_LIMITS_DATA, *PREAD_BLOCK_LIMITS_DATA;
2795 
2796 typedef struct _READ_BUFFER_CAPACITY_DATA {
2797   UCHAR DataLength[2];
2798   UCHAR Reserved1;
2799   UCHAR BlockDataReturned:1;
2800   UCHAR Reserved4:7;
2801   UCHAR TotalBufferSize[4];
2802   UCHAR AvailableBufferSize[4];
2803 } READ_BUFFER_CAPACITY_DATA, *PREAD_BUFFER_CAPACITY_DATA;
2804 
2805 typedef struct _MODE_PARAMETER_HEADER {
2806   UCHAR ModeDataLength;
2807   UCHAR MediumType;
2808   UCHAR DeviceSpecificParameter;
2809   UCHAR BlockDescriptorLength;
2810 } MODE_PARAMETER_HEADER, *PMODE_PARAMETER_HEADER;
2811 
2812 typedef struct _MODE_PARAMETER_HEADER10 {
2813   UCHAR ModeDataLength[2];
2814   UCHAR MediumType;
2815   UCHAR DeviceSpecificParameter;
2816   UCHAR Reserved[2];
2817   UCHAR BlockDescriptorLength[2];
2818 } MODE_PARAMETER_HEADER10, *PMODE_PARAMETER_HEADER10;
2819 
2820 typedef struct _MODE_PARAMETER_BLOCK {
2821   UCHAR DensityCode;
2822   UCHAR NumberOfBlocks[3];
2823   UCHAR Reserved;
2824   UCHAR BlockLength[3];
2825 } MODE_PARAMETER_BLOCK, *PMODE_PARAMETER_BLOCK;
2826 
2827 typedef struct _MODE_DISCONNECT_PAGE {
2828   UCHAR PageCode:6;
2829   UCHAR Reserved:1;
2830   UCHAR PageSavable:1;
2831   UCHAR PageLength;
2832   UCHAR BufferFullRatio;
2833   UCHAR BufferEmptyRatio;
2834   UCHAR BusInactivityLimit[2];
2835   UCHAR BusDisconnectTime[2];
2836   UCHAR BusConnectTime[2];
2837   UCHAR MaximumBurstSize[2];
2838   UCHAR DataTransferDisconnect:2;
2839   UCHAR Reserved2[3];
2840 } MODE_DISCONNECT_PAGE, *PMODE_DISCONNECT_PAGE;
2841 
2842 typedef struct _MODE_CACHING_PAGE {
2843   UCHAR PageCode:6;
2844   UCHAR Reserved:1;
2845   UCHAR PageSavable:1;
2846   UCHAR PageLength;
2847   UCHAR ReadDisableCache:1;
2848   UCHAR MultiplicationFactor:1;
2849   UCHAR WriteCacheEnable:1;
2850   UCHAR Reserved2:5;
2851   UCHAR WriteRetensionPriority:4;
2852   UCHAR ReadRetensionPriority:4;
2853   UCHAR DisablePrefetchTransfer[2];
2854   UCHAR MinimumPrefetch[2];
2855   UCHAR MaximumPrefetch[2];
2856   UCHAR MaximumPrefetchCeiling[2];
2857 } MODE_CACHING_PAGE, *PMODE_CACHING_PAGE;
2858 
2859 typedef struct _MODE_CDROM_WRITE_PARAMETERS_PAGE2 {
2860   UCHAR PageCode:6;
2861   UCHAR Reserved:1;
2862   UCHAR PageSavable:1;
2863   UCHAR PageLength;
2864   UCHAR WriteType:4;
2865   UCHAR TestWrite:1;
2866   UCHAR LinkSizeValid:1;
2867   UCHAR BufferUnderrunFreeEnabled:1;
2868   UCHAR Reserved2:1;
2869   UCHAR TrackMode:4;
2870   UCHAR Copy:1;
2871   UCHAR FixedPacket:1;
2872   UCHAR MultiSession:2;
2873   UCHAR DataBlockType:4;
2874   UCHAR Reserved3:4;
2875   UCHAR LinkSize;
2876   UCHAR Reserved4;
2877   UCHAR HostApplicationCode:6;
2878   UCHAR Reserved5:2;
2879   UCHAR SessionFormat;
2880   UCHAR Reserved6;
2881   UCHAR PacketSize[4];
2882   UCHAR AudioPauseLength[2];
2883   UCHAR MediaCatalogNumber[16];
2884   UCHAR ISRC[16];
2885   UCHAR SubHeaderData[4];
2886 } MODE_CDROM_WRITE_PARAMETERS_PAGE2, *PMODE_CDROM_WRITE_PARAMETERS_PAGE2;
2887 
2888 typedef struct _MODE_MRW_PAGE {
2889   UCHAR PageCode:6;
2890   UCHAR Reserved:1;
2891   UCHAR PageSavable:1;
2892   UCHAR PageLength;
2893   UCHAR Reserved1;
2894   UCHAR LbaSpace:1;
2895   UCHAR Reserved2:7;
2896   UCHAR Reserved3[4];
2897 } MODE_MRW_PAGE, *PMODE_MRW_PAGE;
2898 
2899 typedef struct _MODE_FLEXIBLE_DISK_PAGE {
2900   UCHAR PageCode:6;
2901   UCHAR Reserved:1;
2902   UCHAR PageSavable:1;
2903   UCHAR PageLength;
2904   UCHAR TransferRate[2];
2905   UCHAR NumberOfHeads;
2906   UCHAR SectorsPerTrack;
2907   UCHAR BytesPerSector[2];
2908   UCHAR NumberOfCylinders[2];
2909   UCHAR StartWritePrecom[2];
2910   UCHAR StartReducedCurrent[2];
2911   UCHAR StepRate[2];
2912   UCHAR StepPluseWidth;
2913   UCHAR HeadSettleDelay[2];
2914   UCHAR MotorOnDelay;
2915   UCHAR MotorOffDelay;
2916   UCHAR Reserved2:5;
2917   UCHAR MotorOnAsserted:1;
2918   UCHAR StartSectorNumber:1;
2919   UCHAR TrueReadySignal:1;
2920   UCHAR StepPlusePerCyclynder:4;
2921   UCHAR Reserved3:4;
2922   UCHAR WriteCompenstation;
2923   UCHAR HeadLoadDelay;
2924   UCHAR HeadUnloadDelay;
2925   UCHAR Pin2Usage:4;
2926   UCHAR Pin34Usage:4;
2927   UCHAR Pin1Usage:4;
2928   UCHAR Pin4Usage:4;
2929   UCHAR MediumRotationRate[2];
2930   UCHAR Reserved4[2];
2931 } MODE_FLEXIBLE_DISK_PAGE, *PMODE_FLEXIBLE_DISK_PAGE;
2932 
2933 typedef struct _MODE_FORMAT_PAGE {
2934   UCHAR PageCode:6;
2935   UCHAR Reserved:1;
2936   UCHAR PageSavable:1;
2937   UCHAR PageLength;
2938   UCHAR TracksPerZone[2];
2939   UCHAR AlternateSectorsPerZone[2];
2940   UCHAR AlternateTracksPerZone[2];
2941   UCHAR AlternateTracksPerLogicalUnit[2];
2942   UCHAR SectorsPerTrack[2];
2943   UCHAR BytesPerPhysicalSector[2];
2944   UCHAR Interleave[2];
2945   UCHAR TrackSkewFactor[2];
2946   UCHAR CylinderSkewFactor[2];
2947   UCHAR Reserved2:4;
2948   UCHAR SurfaceFirst:1;
2949   UCHAR RemovableMedia:1;
2950   UCHAR HardSectorFormating:1;
2951   UCHAR SoftSectorFormating:1;
2952   UCHAR Reserved3[3];
2953 } MODE_FORMAT_PAGE, *PMODE_FORMAT_PAGE;
2954 
2955 typedef struct _MODE_RIGID_GEOMETRY_PAGE {
2956   UCHAR PageCode:6;
2957   UCHAR Reserved:1;
2958   UCHAR PageSavable:1;
2959   UCHAR PageLength;
2960   UCHAR NumberOfCylinders[3];
2961   UCHAR NumberOfHeads;
2962   UCHAR StartWritePrecom[3];
2963   UCHAR StartReducedCurrent[3];
2964   UCHAR DriveStepRate[2];
2965   UCHAR LandZoneCyclinder[3];
2966   UCHAR RotationalPositionLock:2;
2967   UCHAR Reserved2:6;
2968   UCHAR RotationOffset;
2969   UCHAR Reserved3;
2970   UCHAR RoataionRate[2];
2971   UCHAR Reserved4[2];
2972 } MODE_RIGID_GEOMETRY_PAGE, *PMODE_RIGID_GEOMETRY_PAGE;
2973 
2974 typedef struct _MODE_READ_WRITE_RECOVERY_PAGE {
2975   UCHAR PageCode:6;
2976   UCHAR Reserved1:1;
2977   UCHAR PSBit:1;
2978   UCHAR PageLength;
2979   UCHAR DCRBit:1;
2980   UCHAR DTEBit:1;
2981   UCHAR PERBit:1;
2982   UCHAR EERBit:1;
2983   UCHAR RCBit:1;
2984   UCHAR TBBit:1;
2985   UCHAR ARRE:1;
2986   UCHAR AWRE:1;
2987   UCHAR ReadRetryCount;
2988   UCHAR Reserved4[4];
2989   UCHAR WriteRetryCount;
2990   UCHAR Reserved5[3];
2991 } MODE_READ_WRITE_RECOVERY_PAGE, *PMODE_READ_WRITE_RECOVERY_PAGE;
2992 
2993 typedef struct _MODE_READ_RECOVERY_PAGE {
2994   UCHAR PageCode:6;
2995   UCHAR Reserved1:1;
2996   UCHAR PSBit:1;
2997   UCHAR PageLength;
2998   UCHAR DCRBit:1;
2999   UCHAR DTEBit:1;
3000   UCHAR PERBit:1;
3001   UCHAR Reserved2:1;
3002   UCHAR RCBit:1;
3003   UCHAR TBBit:1;
3004   UCHAR Reserved3:2;
3005   UCHAR ReadRetryCount;
3006   UCHAR Reserved4[4];
3007 } MODE_READ_RECOVERY_PAGE, *PMODE_READ_RECOVERY_PAGE;
3008 
3009 typedef struct _MODE_INFO_EXCEPTIONS {
3010   UCHAR PageCode:6;
3011   UCHAR Reserved1:1;
3012   UCHAR PSBit:1;
3013   UCHAR PageLength;
3014   _ANONYMOUS_UNION union {
3015     UCHAR Flags;
3016     _ANONYMOUS_STRUCT struct {
3017       UCHAR LogErr:1;
3018       UCHAR Reserved2:1;
3019       UCHAR Test:1;
3020       UCHAR Dexcpt:1;
3021       UCHAR Reserved3:3;
3022       UCHAR Perf:1;
3023     } DUMMYSTRUCTNAME;
3024   } DUMMYUNIONNAME;
3025   UCHAR ReportMethod:4;
3026   UCHAR Reserved4:4;
3027   UCHAR IntervalTimer[4];
3028   UCHAR ReportCount[4];
3029 } MODE_INFO_EXCEPTIONS, *PMODE_INFO_EXCEPTIONS;
3030 
3031 typedef struct _POWER_CONDITION_PAGE {
3032   UCHAR PageCode:6;
3033   UCHAR Reserved:1;
3034   UCHAR PSBit:1;
3035   UCHAR PageLength;
3036   UCHAR Reserved2;
3037   UCHAR Standby:1;
3038   UCHAR Idle:1;
3039   UCHAR Reserved3:6;
3040   UCHAR IdleTimer[4];
3041   UCHAR StandbyTimer[4];
3042 } POWER_CONDITION_PAGE, *PPOWER_CONDITION_PAGE;
3043 
3044 typedef struct _CDDA_OUTPUT_PORT {
3045   UCHAR ChannelSelection:4;
3046   UCHAR Reserved:4;
3047   UCHAR Volume;
3048 } CDDA_OUTPUT_PORT, *PCDDA_OUTPUT_PORT;
3049 
3050 typedef struct _CDAUDIO_CONTROL_PAGE {
3051   UCHAR PageCode:6;
3052   UCHAR Reserved:1;
3053   UCHAR PSBit:1;
3054   UCHAR PageLength;
3055   UCHAR Reserved2:1;
3056   UCHAR StopOnTrackCrossing:1;
3057   UCHAR Immediate:1;
3058   UCHAR Reserved3:5;
3059   UCHAR Reserved4[3];
3060   UCHAR Obsolete[2];
3061   CDDA_OUTPUT_PORT CDDAOutputPorts[4];
3062 } CDAUDIO_CONTROL_PAGE, *PCDAUDIO_CONTROL_PAGE;
3063 
3064 typedef struct _CDVD_FEATURE_SET_PAGE {
3065   UCHAR PageCode:6;
3066   UCHAR Reserved:1;
3067   UCHAR PSBit:1;
3068   UCHAR PageLength;
3069   UCHAR CDAudio[2];
3070   UCHAR EmbeddedChanger[2];
3071   UCHAR PacketSMART[2];
3072   UCHAR PersistantPrevent[2];
3073   UCHAR EventStatusNotification[2];
3074   UCHAR DigitalOutput[2];
3075   UCHAR CDSequentialRecordable[2];
3076   UCHAR DVDSequentialRecordable[2];
3077   UCHAR RandomRecordable[2];
3078   UCHAR KeyExchange[2];
3079   UCHAR Reserved2[2];
3080 } CDVD_FEATURE_SET_PAGE, *PCDVD_FEATURE_SET_PAGE;
3081 
3082 typedef struct _CDVD_INACTIVITY_TIMEOUT_PAGE {
3083   UCHAR PageCode:6;
3084   UCHAR Reserved:1;
3085   UCHAR PSBit:1;
3086   UCHAR PageLength;
3087   UCHAR Reserved2[2];
3088   UCHAR SWPP:1;
3089   UCHAR DISP:1;
3090   UCHAR Reserved3:6;
3091   UCHAR Reserved4;
3092   UCHAR GroupOneMinimumTimeout[2];
3093   UCHAR GroupTwoMinimumTimeout[2];
3094 } CDVD_INACTIVITY_TIMEOUT_PAGE, *PCDVD_INACTIVITY_TIMEOUT_PAGE;
3095 
3096 typedef struct _CDVD_CAPABILITIES_PAGE {
3097   UCHAR PageCode:6;
3098   UCHAR Reserved:1;
3099   UCHAR PSBit:1;
3100   UCHAR PageLength;
3101   UCHAR CDRRead:1;
3102   UCHAR CDERead:1;
3103   UCHAR Method2:1;
3104   UCHAR DVDROMRead:1;
3105   UCHAR DVDRRead:1;
3106   UCHAR DVDRAMRead:1;
3107   UCHAR Reserved2:2;
3108   UCHAR CDRWrite:1;
3109   UCHAR CDEWrite:1;
3110   UCHAR TestWrite:1;
3111   UCHAR Reserved3:1;
3112   UCHAR DVDRWrite:1;
3113   UCHAR DVDRAMWrite:1;
3114   UCHAR Reserved4:2;
3115   UCHAR AudioPlay:1;
3116   UCHAR Composite:1;
3117   UCHAR DigitalPortOne:1;
3118   UCHAR DigitalPortTwo:1;
3119   UCHAR Mode2Form1:1;
3120   UCHAR Mode2Form2:1;
3121   UCHAR MultiSession:1;
3122   UCHAR BufferUnderrunFree:1;
3123   UCHAR CDDA:1;
3124   UCHAR CDDAAccurate:1;
3125   UCHAR RWSupported:1;
3126   UCHAR RWDeinterleaved:1;
3127   UCHAR C2Pointers:1;
3128   UCHAR ISRC:1;
3129   UCHAR UPC:1;
3130   UCHAR ReadBarCodeCapable:1;
3131   UCHAR Lock:1;
3132   UCHAR LockState:1;
3133   UCHAR PreventJumper:1;
3134   UCHAR Eject:1;
3135   UCHAR Reserved6:1;
3136   UCHAR LoadingMechanismType:3;
3137   UCHAR SeparateVolume:1;
3138   UCHAR SeperateChannelMute:1;
3139   UCHAR SupportsDiskPresent:1;
3140   UCHAR SWSlotSelection:1;
3141   UCHAR SideChangeCapable:1;
3142   UCHAR RWInLeadInReadable:1;
3143   UCHAR Reserved7:2;
3144   _ANONYMOUS_UNION union {
3145     UCHAR ReadSpeedMaximum[2];
3146     UCHAR ObsoleteReserved[2];
3147   } DUMMYUNIONNAME;
3148   UCHAR NumberVolumeLevels[2];
3149   UCHAR BufferSize[2];
3150   _ANONYMOUS_UNION union {
3151     UCHAR ReadSpeedCurrent[2];
3152     UCHAR ObsoleteReserved2[2];
3153   } DUMMYUNIONNAME2;
3154   UCHAR ObsoleteReserved3;
3155   UCHAR Reserved8:1;
3156   UCHAR BCK:1;
3157   UCHAR RCK:1;
3158   UCHAR LSBF:1;
3159   UCHAR Length:2;
3160   UCHAR Reserved9:2;
3161   _ANONYMOUS_UNION union {
3162     UCHAR WriteSpeedMaximum[2];
3163     UCHAR ObsoleteReserved4[2];
3164   } DUMMYUNIONNAME3;
3165   _ANONYMOUS_UNION union {
3166     UCHAR WriteSpeedCurrent[2];
3167     UCHAR ObsoleteReserved11[2];
3168   } DUMMYUNIONNAME4;
3169   _ANONYMOUS_UNION union {
3170     UCHAR CopyManagementRevision[2];
3171     UCHAR Reserved10[2];
3172   } DUMMYUNIONNAME5;
3173 } CDVD_CAPABILITIES_PAGE, *PCDVD_CAPABILITIES_PAGE;
3174 
3175 typedef struct _LUN_LIST {
3176   UCHAR LunListLength[4];
3177   UCHAR Reserved[4];
3178   UCHAR Lun[0][8];
3179 } LUN_LIST, *PLUN_LIST;
3180 
3181 typedef struct _MODE_PARM_READ_WRITE {
3182   MODE_PARAMETER_HEADER ParameterListHeader;
3183   MODE_PARAMETER_BLOCK ParameterListBlock;
3184 } MODE_PARM_READ_WRITE_DATA, *PMODE_PARM_READ_WRITE_DATA;
3185 
3186 typedef struct _PORT_OUTPUT {
3187   UCHAR ChannelSelection;
3188   UCHAR Volume;
3189 } PORT_OUTPUT, *PPORT_OUTPUT;
3190 
3191 typedef struct _AUDIO_OUTPUT {
3192   UCHAR CodePage;
3193   UCHAR ParameterLength;
3194   UCHAR Immediate;
3195   UCHAR Reserved[2];
3196   UCHAR LbaFormat;
3197   UCHAR LogicalBlocksPerSecond[2];
3198   PORT_OUTPUT PortOutput[4];
3199 } AUDIO_OUTPUT, *PAUDIO_OUTPUT;
3200 
3201 /* Atapi 2.5 changers */
3202 typedef struct _MECHANICAL_STATUS_INFORMATION_HEADER {
3203   UCHAR CurrentSlot:5;
3204   UCHAR ChangerState:2;
3205   UCHAR Fault:1;
3206   UCHAR Reserved:5;
3207   UCHAR MechanismState:3;
3208   UCHAR CurrentLogicalBlockAddress[3];
3209   UCHAR NumberAvailableSlots;
3210   UCHAR SlotTableLength[2];
3211 } MECHANICAL_STATUS_INFORMATION_HEADER, *PMECHANICAL_STATUS_INFORMATION_HEADER;
3212 
3213 typedef struct _SLOT_TABLE_INFORMATION {
3214   UCHAR DiscChanged:1;
3215   UCHAR Reserved:6;
3216   UCHAR DiscPresent:1;
3217   UCHAR Reserved2[3];
3218 } SLOT_TABLE_INFORMATION, *PSLOT_TABLE_INFORMATION;
3219 
3220 typedef struct _MECHANICAL_STATUS {
3221   MECHANICAL_STATUS_INFORMATION_HEADER MechanicalStatusHeader;
3222   SLOT_TABLE_INFORMATION SlotTableInfo[1];
3223 } MECHANICAL_STATUS, *PMECHANICAL_STATUS;
3224 
3225 /* Tape definitions */
3226 typedef struct _TAPE_POSITION_DATA {
3227   UCHAR Reserved1:2;
3228   UCHAR BlockPositionUnsupported:1;
3229   UCHAR Reserved2:3;
3230   UCHAR EndOfPartition:1;
3231   UCHAR BeginningOfPartition:1;
3232   UCHAR PartitionNumber;
3233   USHORT Reserved3;
3234   UCHAR FirstBlock[4];
3235   UCHAR LastBlock[4];
3236   UCHAR Reserved4;
3237   UCHAR NumberOfBlocks[3];
3238   UCHAR NumberOfBytes[4];
3239 } TAPE_POSITION_DATA, *PTAPE_POSITION_DATA;
3240 
3241 #include <pshpack1.h>
3242 typedef struct _UNMAP_BLOCK_DESCRIPTOR {
3243   UCHAR StartingLba[8];
3244   UCHAR LbaCount[4];
3245   UCHAR Reserved[4];
3246 } UNMAP_BLOCK_DESCRIPTOR, *PUNMAP_BLOCK_DESCRIPTOR;
3247 
3248 typedef struct _UNMAP_LIST_HEADER {
3249   UCHAR DataLength[2];
3250   UCHAR BlockDescrDataLength[2];
3251   UCHAR Reserved[4];
3252 #if !defined(__midl)
3253   UNMAP_BLOCK_DESCRIPTOR Descriptors[0];
3254 #endif
3255 } UNMAP_LIST_HEADER, *PUNMAP_LIST_HEADER;
3256 #include <poppack.h>
3257 
3258 #define LOG_PAGE_CODE_SUPPORTED_LOG_PAGES           0x00
3259 #define LOG_PAGE_CODE_WRITE_ERROR_COUNTERS          0x02
3260 #define LOG_PAGE_CODE_READ_ERROR_COUNTERS           0x03
3261 #define LOG_PAGE_CODE_LOGICAL_BLOCK_PROVISIONING    0x0C
3262 #define LOG_PAGE_CODE_TEMPERATURE                   0x0D
3263 #define LOG_PAGE_CODE_STARTSTOP_CYCLE_COUNTERS      0x0E
3264 #define LOG_PAGE_CODE_SELFTEST_RESULTS              0x10
3265 #define LOG_PAGE_CODE_SOLID_STATE_MEDIA             0x11
3266 #define LOG_PAGE_CODE_BACKGROUND_SCAN_RESULTS       0x15
3267 #define LOG_PAGE_CODE_INFORMATIONAL_EXCEPTIONS      0x2F
3268 
3269 
3270 #include <pshpack1.h>
3271 typedef struct _LOG_PARAMETER_HEADER {
3272   UCHAR ParameterCode[2];
3273   union {
3274     UCHAR ControlByte;
3275     struct {
3276       UCHAR FormatAndLinking:2;
3277       UCHAR TMC:2;
3278       UCHAR ETC:1;
3279       UCHAR TSD:1;
3280       UCHAR Obsolete:1;
3281       UCHAR DU:1;
3282     };
3283   };
3284   UCHAR ParameterLength;
3285 } LOG_PARAMETER_HEADER, *PLOG_PARAMETER_HEADER;
3286 
3287 typedef struct _LOG_PARAMETER {
3288   LOG_PARAMETER_HEADER Header;
3289   union {
3290 #if !defined(__midl)
3291     UCHAR AsByte[0];
3292 #endif
3293     struct _THRESHOLD_RESOURCE_COUNT {
3294       UCHAR ResourceCount[4];
3295       UCHAR Scope : 2;
3296       UCHAR Reserved1 : 6;
3297       UCHAR Reserved2[3];
3298     } THRESHOLD_RESOURCE_COUNT;
3299     struct _TEMPERATURE {
3300       UCHAR Reserved;
3301       UCHAR Temperature;
3302     } TEMPERATURE;
3303     struct _DATE_OF_MANUFACTURE {
3304       UCHAR Year[4];
3305       UCHAR Week[2];
3306     } DATE_OF_MANUFACTURE;
3307     struct _SELF_TEST_RESULTS {
3308       UCHAR SelfTestResults : 4;
3309       UCHAR Reserved1 : 1;
3310       UCHAR SelfTestCode : 3;
3311       UCHAR SelfTestNumber;
3312       UCHAR PowerOnHours[2];
3313       UCHAR AddressOfFirstFailure[8];
3314       UCHAR SenseKey : 4;
3315       UCHAR Reserved2 : 4;
3316       UCHAR AdditionalSenseCode;
3317       UCHAR AdditionalSenseCodeQualifier;
3318       UCHAR VendorSpecific;
3319     } SELF_TEST_RESULTS;
3320 
3321     struct _SOLID_STATE_MEDIA {
3322       UCHAR Reserved[3];
3323       UCHAR PercentageUsed;
3324     } SOLID_STATE_MEDIA;
3325 
3326     struct _BACKGROUND_SCAN_STATUS {
3327       UCHAR PowerOnMinutes[4];
3328       UCHAR Reserved;
3329       UCHAR ScanStatus;
3330       UCHAR ScansPerformed[2];
3331       UCHAR ScanProgress[2];
3332       UCHAR MediumScansPerformed[2];
3333     } BACKGROUND_SCAN_STATUS;
3334 
3335     struct _INFORMATIONAL_EXCEPTIONS {
3336       UCHAR ASC;
3337       UCHAR ASCQ;
3338       UCHAR MostRecentTemperature;
3339       UCHAR VendorSpecific[ANYSIZE_ARRAY];
3340     } INFORMATIONAL_EXCEPTIONS;
3341   };
3342 } LOG_PARAMETER, *PLOG_PARAMETER;
3343 
3344 typedef struct _LOG_PAGE {
3345   UCHAR PageCode:6;
3346   UCHAR SPF:1;
3347   UCHAR DS:1;
3348   UCHAR SubPageCode;
3349   UCHAR PageLength[2];
3350 #if !defined(__midl)
3351   LOG_PARAMETER Parameters[0];
3352 #endif
3353 
3354 } LOG_PAGE, *PLOG_PAGE;
3355 
3356 #include <poppack.h>
3357 
3358 #define LOG_PAGE_LBP_PARAMETER_CODE_AVAILABLE   0x1
3359 #define LOG_PAGE_LBP_PARAMETER_CODE_USED        0x2
3360 
3361 #define LOG_PAGE_LBP_RESOURCE_SCOPE_NOT_REPORTED            0x0
3362 #define LOG_PAGE_LBP_RESOURCE_SCOPE_DEDICATED_TO_LUN        0x1
3363 #define LOG_PAGE_LBP_RESOURCE_SCOPE_NOT_DEDICATED_TO_LUN    0x2
3364 
3365 typedef struct _LOG_PARAMETER_THRESHOLD_RESOURCE_COUNT {
3366   LOG_PARAMETER_HEADER Header;
3367   UCHAR ResourceCount[4];
3368   UCHAR Scope:2;
3369   UCHAR Reserved0:6;
3370   UCHAR Reserved1[3];
3371 } LOG_PARAMETER_THRESHOLD_RESOURCE_COUNT, *PLOG_PARAMETER_THRESHOLD_RESOURCE_COUNT;
3372 
3373 typedef struct _LOG_PAGE_LOGICAL_BLOCK_PROVISIONING {
3374   UCHAR PageCode:6;
3375   UCHAR SPF:1;
3376   UCHAR DS:1;
3377   UCHAR SubPageCode;
3378   UCHAR PageLength[2];
3379 #if !defined(__midl)
3380   LOG_PARAMETER_HEADER Parameters[0];
3381 #endif
3382 } LOG_PAGE_LOGICAL_BLOCK_PROVISIONING, *PLOG_PAGE_LOGICAL_BLOCK_PROVISIONING;
3383 
3384 typedef struct _MODE_CONTROL_PAGE {
3385   UCHAR PageCode:6;
3386   UCHAR Reserved1:1;
3387   UCHAR PageSavable:1;
3388   UCHAR PageLength;
3389   UCHAR RLEC:1;
3390   UCHAR GLTSD:1;
3391   UCHAR D_SENSE:1;
3392   UCHAR DPICZ:1;
3393   UCHAR TMF_ONLY:1;
3394   UCHAR TST:3;
3395   UCHAR Obsolete1:1;
3396   UCHAR QERR:2;
3397   UCHAR NUAR:1;
3398   UCHAR QueueAlgorithmModifier:4;
3399   UCHAR Obsolete2:3;
3400   UCHAR SWP:1;
3401   UCHAR UA_INTLCK_CTRL:2;
3402   UCHAR RAC:1;
3403   UCHAR VS:1;
3404   UCHAR AutoloadMode:3;
3405   UCHAR Reserved2:1;
3406   UCHAR RWWP:1;
3407   UCHAR ATMPE:1;
3408   UCHAR TAS:1;
3409   UCHAR ATO:1;
3410   UCHAR Obsolete3[2];
3411   UCHAR BusyTimeoutPeriod[2];
3412   UCHAR ExtendeSelfTestCompletionTime[2];
3413 } MODE_CONTROL_PAGE, *PMODE_CONTROL_PAGE;
3414 
3415 /* This structure is used to convert little endian ULONGs
3416    to SCSI CDB big endians values. */
3417 typedef union _EIGHT_BYTE {
3418   _ANONYMOUS_STRUCT struct {
3419     UCHAR Byte0;
3420     UCHAR Byte1;
3421     UCHAR Byte2;
3422     UCHAR Byte3;
3423     UCHAR Byte4;
3424     UCHAR Byte5;
3425     UCHAR Byte6;
3426     UCHAR Byte7;
3427   } DUMMYSTRUCTNAME;
3428   ULONGLONG AsULongLong;
3429 } EIGHT_BYTE, *PEIGHT_BYTE;
3430 
3431 typedef union _FOUR_BYTE {
3432   _ANONYMOUS_STRUCT struct {
3433     UCHAR Byte0;
3434     UCHAR Byte1;
3435     UCHAR Byte2;
3436     UCHAR Byte3;
3437   } DUMMYSTRUCTNAME;
3438   ULONG AsULong;
3439 } FOUR_BYTE, *PFOUR_BYTE;
3440 
3441 typedef union _TWO_BYTE {
3442   _ANONYMOUS_STRUCT struct {
3443     UCHAR Byte0;
3444     UCHAR Byte1;
3445   } DUMMYSTRUCTNAME;
3446   USHORT AsUShort;
3447 } TWO_BYTE, *PTWO_BYTE;
3448 
3449 /* Byte reversing macro for converting between
3450    big- and little-endian formats */
3451 #define REVERSE_BYTES_QUAD(Destination, Source) { \
3452   PEIGHT_BYTE _val1 = (PEIGHT_BYTE)(Destination); \
3453   PEIGHT_BYTE _val2 = (PEIGHT_BYTE)(Source); \
3454   _val1->Byte7 = _val2->Byte0; \
3455   _val1->Byte6 = _val2->Byte1; \
3456   _val1->Byte5 = _val2->Byte2; \
3457   _val1->Byte4 = _val2->Byte3; \
3458   _val1->Byte3 = _val2->Byte4; \
3459   _val1->Byte2 = _val2->Byte5; \
3460   _val1->Byte1 = _val2->Byte6; \
3461   _val1->Byte0 = _val2->Byte7; \
3462 }
3463 
3464 #define REVERSE_BYTES(Destination, Source) { \
3465   PFOUR_BYTE _val1 = (PFOUR_BYTE)(Destination); \
3466   PFOUR_BYTE _val2 = (PFOUR_BYTE)(Source); \
3467   _val1->Byte3 = _val2->Byte0; \
3468   _val1->Byte2 = _val2->Byte1; \
3469   _val1->Byte1 = _val2->Byte2; \
3470   _val1->Byte0 = _val2->Byte3; \
3471 }
3472 
3473 #define REVERSE_BYTES_SHORT(Destination, Source) { \
3474   PTWO_BYTE _val1 = (PTWO_BYTE)(Destination); \
3475   PTWO_BYTE _val2 = (PTWO_BYTE)(Source); \
3476   _val1->Byte1 = _val2->Byte0; \
3477   _val1->Byte0 = _val2->Byte1; \
3478 }
3479 
3480 #define REVERSE_SHORT(Short) { \
3481   UCHAR _val; \
3482   PTWO_BYTE _val2 = (PTWO_BYTE)(Short); \
3483   _val = _val2->Byte0; \
3484   _val2->Byte0 = _val2->Byte1; \
3485   _val2->Byte1 = _val; \
3486 }
3487 
3488 #define REVERSE_LONG(Long) { \
3489   UCHAR _val; \
3490   PFOUR_BYTE _val2 = (PFOUR_BYTE)(Long); \
3491   _val = _val2->Byte3; \
3492   _val2->Byte3 = _val2->Byte0; \
3493   _val2->Byte0 = _val; \
3494   _val = _val2->Byte2; \
3495   _val2->Byte2 = _val2->Byte1; \
3496   _val2->Byte1 = _val; \
3497 }
3498 
3499 #define WHICH_BIT(Data, Bit) { \
3500   UCHAR _val; \
3501   for (_val = 0; _val < 32; _val++) { \
3502     if (((Data) >> _val) == 1) { \
3503       break; \
3504     } \
3505   } \
3506   ASSERT(_val != 32); \
3507   (Bit) = _val; \
3508 }
3509 
3510 #if defined(_WIN64)
3511 #define STOR_ADDRESS_ALIGN           DECLSPEC_ALIGN(8)
3512 #else
3513 #define STOR_ADDRESS_ALIGN
3514 #endif
3515 
3516 typedef struct STOR_ADDRESS_ALIGN _STOR_ADDRESS {
3517   USHORT Type;
3518   USHORT Port;
3519   ULONG AddressLength;
3520   _Field_size_bytes_(AddressLength) UCHAR AddressData[ANYSIZE_ARRAY];
3521 } STOR_ADDRESS, *PSTOR_ADDRESS;
3522 
3523 #define STOR_ADDRESS_TYPE_UNKNOWN   0x0
3524 #define STOR_ADDRESS_TYPE_BTL8      0x1
3525 #define STOR_ADDRESS_TYPE_MAX       0xffff
3526 
3527 #define STOR_ADDR_BTL8_ADDRESS_LENGTH    4
3528 
3529 typedef struct STOR_ADDRESS_ALIGN _STOR_ADDR_BTL8 {
3530   _Field_range_(STOR_ADDRESS_TYPE_BTL8, STOR_ADDRESS_TYPE_BTL8)
3531   USHORT Type;
3532   USHORT Port;
3533   _Field_range_(STOR_ADDR_BTL8_ADDRESS_LENGTH, STOR_ADDR_BTL8_ADDRESS_LENGTH)
3534   ULONG AddressLength;
3535   UCHAR Path;
3536   UCHAR Target;
3537   UCHAR Lun;
3538   UCHAR Reserved;
3539 } STOR_ADDR_BTL8, *PSTOR_ADDR_BTL8;
3540 
3541 /* FIXME : This structure doesn't exist in the official header */
3542 typedef struct _MODE_CDROM_WRITE_PARAMETERS_PAGE {
3543   UCHAR PageLength;
3544   UCHAR WriteType:4;
3545   UCHAR TestWrite:1;
3546   UCHAR LinkSizeValid:1;
3547   UCHAR BufferUnderrunFreeEnabled:1;
3548   UCHAR Reserved2:1;
3549   UCHAR TrackMode:4;
3550   UCHAR Copy:1;
3551   UCHAR FixedPacket:1;
3552   UCHAR MultiSession:2;
3553   UCHAR DataBlockType:4;
3554   UCHAR Reserved3:4;
3555   UCHAR LinkSize;
3556   UCHAR Reserved4;
3557   UCHAR HostApplicationCode:6;
3558   UCHAR Reserved5:2;
3559   UCHAR SessionFormat;
3560   UCHAR Reserved6;
3561   UCHAR PacketSize[4];
3562   UCHAR AudioPauseLength[2];
3563   UCHAR Reserved7:7;
3564   UCHAR MediaCatalogNumberValid:1;
3565   UCHAR MediaCatalogNumber[13];
3566   UCHAR MediaCatalogNumberZero;
3567   UCHAR MediaCatalogNumberAFrame;
3568   UCHAR Reserved8:7;
3569   UCHAR ISRCValid:1;
3570   UCHAR ISRCCountry[2];
3571   UCHAR ISRCOwner[3];
3572   UCHAR ISRCRecordingYear[2];
3573   UCHAR ISRCSerialNumber[5];
3574   UCHAR ISRCZero;
3575   UCHAR ISRCAFrame;
3576   UCHAR ISRCReserved;
3577   UCHAR SubHeaderData[4];
3578 } MODE_CDROM_WRITE_PARAMETERS_PAGE, *PMODE_CDROM_WRITE_PARAMETERS_PAGE;
3579 
3580 #if (NTDDI_VERSION >= NTDDI_WIN8)
3581 #include <pshpack1.h>
3582 
3583 #define BLOCK_DEVICE_TOKEN_SIZE         512
3584 
3585 typedef struct {
3586   UCHAR LogicalBlockAddress[8];
3587   UCHAR TransferLength[4];
3588   UCHAR Reserved[4];
3589 } BLOCK_DEVICE_RANGE_DESCRIPTOR, *PBLOCK_DEVICE_RANGE_DESCRIPTOR;
3590 
3591 typedef struct {
3592   UCHAR PopulateTokenDataLength[2];
3593   UCHAR Immediate:1;
3594   UCHAR Reserved1:7;
3595   UCHAR Reserved2;
3596   UCHAR InactivityTimeout[4];
3597   UCHAR Reserved3[6];
3598   UCHAR BlockDeviceRangeDescriptorListLength[2];
3599 #if !defined(__midl)
3600   UCHAR BlockDeviceRangeDescriptor[ANYSIZE_ARRAY];
3601 #endif
3602 } POPULATE_TOKEN_HEADER, *PPOPULATE_TOKEN_HEADER;
3603 
3604 typedef struct {
3605   UCHAR WriteUsingTokenDataLength[2];
3606   UCHAR Immediate:1;
3607   UCHAR Reserved1:7;
3608   UCHAR Reserved2[5];
3609   UCHAR BlockOffsetIntoToken[8];
3610   UCHAR Token[BLOCK_DEVICE_TOKEN_SIZE];
3611   UCHAR Reserved3[6];
3612   UCHAR BlockDeviceRangeDescriptorListLength[2];
3613 #if !defined(__midl)
3614   UCHAR BlockDeviceRangeDescriptor[ANYSIZE_ARRAY];
3615 #endif
3616 } WRITE_USING_TOKEN_HEADER, *PWRITE_USING_TOKEN_HEADER;
3617 
3618 typedef struct {
3619   UCHAR AvailableData[4];
3620   UCHAR ResponseToServiceAction:5;
3621   UCHAR Reserved1:3;
3622   UCHAR OperationStatus:7;
3623   UCHAR Reserved2:1;
3624   UCHAR OperationCounter[2];
3625   UCHAR EstimatedStatusUpdateDelay[4];
3626   UCHAR CompletionStatus;
3627   UCHAR SenseDataFieldLength;
3628   UCHAR SenseDataLength;
3629   UCHAR TransferCountUnits;
3630   UCHAR TransferCount[8];
3631   UCHAR SegmentsProcessed[2];
3632   UCHAR Reserved3[6];
3633 #if !defined(__midl)
3634   UCHAR SenseData[ANYSIZE_ARRAY];
3635 #endif
3636 } RECEIVE_TOKEN_INFORMATION_HEADER, *PRECEIVE_TOKEN_INFORMATION_HEADER;
3637 
3638 typedef struct {
3639   UCHAR TokenDescriptorsLength[4];
3640 #if !defined(__midl)
3641   UCHAR TokenDescriptor[ANYSIZE_ARRAY];
3642 #endif
3643 } RECEIVE_TOKEN_INFORMATION_RESPONSE_HEADER, *PRECEIVE_TOKEN_INFORMATION_RESPONSE_HEADER;
3644 
3645 typedef struct {
3646   UCHAR TokenIdentifier[2];
3647   UCHAR Token[BLOCK_DEVICE_TOKEN_SIZE];
3648 } BLOCK_DEVICE_TOKEN_DESCRIPTOR, *PBLOCK_DEVICE_TOKEN_DESCRIPTOR;
3649 
3650 typedef enum _OPERATION_STATUS {
3651   OPERATION_COMPLETED_WITH_SUCCESS = 0x01,
3652   OPERATION_COMPLETED_WITH_ERROR = 0x02,
3653   OPERATION_COMPLETED_WITH_RESIDUAL_DATA = 0x03,
3654   OPERATION_IN_PROGRESS_IN_FOREGROUND = 0x11,
3655   OPERATION_IN_PROGRESS_IN_BACKGROUND = 0x12,
3656   OPERATION_TERMINATED = 0x60
3657 } OPERATION_STATUS, *POPERATION_STATUS;
3658 
3659 typedef enum _TRANSFER_COUNT_UNITS {
3660   TRANSFER_COUNT_UNITS_BYTES = 0,
3661   TRANSFER_COUNT_UNITS_KIBIBYTES = 1,
3662   TRANSFER_COUNT_UNITS_MEBIBYTES = 2,
3663   TRANSFER_COUNT_UNITS_GIBIBYTES = 3,
3664   TRANSFER_COUNT_UNITS_TEBIBYTES = 4,
3665   TRANSFER_COUNT_UNITS_PEBIBYTES = 5,
3666   TRANSFER_COUNT_UNITS_EXBIBYTES = 6,
3667   TRANSFER_COUNT_UNITS_NUMBER_BLOCKS = 0xF1
3668 } TRANSFER_COUNT_UNITS, *PTRANSFER_COUNT_UNITS;
3669 
3670 #include <poppack.h>
3671 #endif /* (NTDDI_VERSION >= NTDDI_WIN8) */
3672 
3673 // SCSI utility functions
3674 
3675 #define ScsiGetSenseErrorCode(SenseInfoBuffer) (((PUCHAR)(SenseInfoBuffer))[0] & 0x7f)
3676 
3677 #define ScsiGetSenseDescriptorLength(DescriptorBuffer) \
3678             (sizeof(SCSI_SENSE_DESCRIPTOR_HEADER) + ((PSCSI_SENSE_DESCRIPTOR_HEADER)(DescriptorBuffer))->AdditionalLength)
3679 
3680 #define IsFixedSenseDataFormat(SenseInfoBuffer) \
3681             ((ScsiGetSenseErrorCode(SenseInfoBuffer)) == SCSI_SENSE_ERRORCODE_FIXED_CURRENT || \
3682              (ScsiGetSenseErrorCode(SenseInfoBuffer)) == SCSI_SENSE_ERRORCODE_FIXED_DEFERRED)
3683 
3684 #define IsDescriptorSenseDataFormat(SenseInfoBuffer) \
3685             ((ScsiGetSenseErrorCode(SenseInfoBuffer)) == SCSI_SENSE_ERRORCODE_DESCRIPTOR_CURRENT || \
3686              (ScsiGetSenseErrorCode(SenseInfoBuffer)) == SCSI_SENSE_ERRORCODE_DESCRIPTOR_DEFERRED)
3687 
3688 #define IsSenseDataCurrentError(SenseInfoBuffer) \
3689             ((ScsiGetSenseErrorCode(SenseInfoBuffer)) == SCSI_SENSE_ERRORCODE_FIXED_CURRENT || \
3690              (ScsiGetSenseErrorCode(SenseInfoBuffer)) == SCSI_SENSE_ERRORCODE_DESCRIPTOR_CURRENT)
3691 
3692 #define IsSenseDataDeferredError(SenseInfoBuffer) \
3693             ((ScsiGetSenseErrorCode(SenseInfoBuffer)) == SCSI_SENSE_ERRORCODE_FIXED_DEFERRED || \
3694              (ScsiGetSenseErrorCode(SenseInfoBuffer)) == SCSI_SENSE_ERRORCODE_DESCRIPTOR_DEFERRED)
3695 
3696 #define IsSenseDataFormatValueValid(SenseInfoBuffer) \
3697             (IsFixedSenseDataFormat(SenseInfoBuffer) || IsDescriptorSenseDataFormat(SenseInfoBuffer))
3698 
3699 _Success_(return != FALSE)
3700 FORCEINLINE
3701 BOOLEAN
3702 ScsiGetTotalSenseByteCountIndicated(
3703   _In_reads_bytes_(SenseInfoBufferLength) PVOID SenseInfoBuffer,
3704   _In_ UCHAR SenseInfoBufferLength,
3705   _Out_ UCHAR *TotalByteCountIndicated)
3706 {
3707   BOOLEAN succeed = FALSE;
3708   UCHAR byteCount = 0;
3709   PFIXED_SENSE_DATA senseInfoBuffer = NULL;
3710 
3711   if (SenseInfoBuffer == NULL || SenseInfoBufferLength == 0 || TotalByteCountIndicated == NULL)
3712   {
3713 
3714     return FALSE;
3715   }
3716 
3717   senseInfoBuffer = (PFIXED_SENSE_DATA)SenseInfoBuffer;
3718 
3719   if (RTL_CONTAINS_FIELD(senseInfoBuffer, SenseInfoBufferLength, AdditionalSenseLength))
3720   {
3721 
3722     if (senseInfoBuffer->AdditionalSenseLength <=
3723         (MAX_SENSE_BUFFER_SIZE - RTL_SIZEOF_THROUGH_FIELD(FIXED_SENSE_DATA, AdditionalSenseLength)))
3724     {
3725 
3726       byteCount = senseInfoBuffer->AdditionalSenseLength +
3727                   RTL_SIZEOF_THROUGH_FIELD(FIXED_SENSE_DATA, AdditionalSenseLength);
3728 
3729       *TotalByteCountIndicated = byteCount;
3730 
3731       succeed = TRUE;
3732     }
3733   }
3734 
3735   return succeed;
3736 }
3737 
3738 _Success_(return != FALSE)
3739 FORCEINLINE
3740 BOOLEAN
3741 ScsiGetFixedSenseKeyAndCodes(
3742   _In_reads_bytes_(SenseInfoBufferLength) PVOID SenseInfoBuffer,
3743   _In_ UCHAR SenseInfoBufferLength,
3744   _Out_opt_ PUCHAR SenseKey,
3745   _Out_opt_ PUCHAR AdditionalSenseCode,
3746   _Out_opt_ PUCHAR AdditionalSenseCodeQualifier)
3747 {
3748   PFIXED_SENSE_DATA fixedSenseData = (PFIXED_SENSE_DATA)SenseInfoBuffer;
3749   BOOLEAN succeed = FALSE;
3750   ULONG dataLength = 0;
3751 
3752   if (SenseInfoBuffer == NULL || SenseInfoBufferLength == 0)
3753   {
3754     return FALSE;
3755   }
3756 
3757   if (RTL_CONTAINS_FIELD(fixedSenseData, SenseInfoBufferLength, AdditionalSenseLength))
3758   {
3759 
3760     dataLength = fixedSenseData->AdditionalSenseLength +
3761                  RTL_SIZEOF_THROUGH_FIELD(FIXED_SENSE_DATA, AdditionalSenseLength);
3762 
3763     if (dataLength > SenseInfoBufferLength)
3764     {
3765       dataLength = SenseInfoBufferLength;
3766     }
3767 
3768     if (SenseKey != NULL)
3769     {
3770       *SenseKey = fixedSenseData->SenseKey;
3771     }
3772 
3773     if (AdditionalSenseCode != NULL)
3774     {
3775       *AdditionalSenseCode = RTL_CONTAINS_FIELD(fixedSenseData, dataLength, AdditionalSenseCode)
3776                                  ? fixedSenseData->AdditionalSenseCode
3777                                  : 0;
3778     }
3779 
3780     if (AdditionalSenseCodeQualifier != NULL)
3781     {
3782       *AdditionalSenseCodeQualifier =
3783           RTL_CONTAINS_FIELD(fixedSenseData, dataLength, AdditionalSenseCodeQualifier)
3784               ? fixedSenseData->AdditionalSenseCodeQualifier
3785               : 0;
3786     }
3787 
3788     succeed = TRUE;
3789   }
3790 
3791   return succeed;
3792 }
3793 
3794 _Success_(return != FALSE)
3795 FORCEINLINE
3796 BOOLEAN
3797 ScsiGetDescriptorSenseKeyAndCodes(
3798   _In_reads_bytes_(SenseInfoBufferLength) PVOID SenseInfoBuffer,
3799   _In_ UCHAR SenseInfoBufferLength,
3800   _Out_opt_ PUCHAR SenseKey,
3801   _Out_opt_ PUCHAR AdditionalSenseCode,
3802   _Out_opt_ PUCHAR AdditionalSenseCodeQualifier)
3803 {
3804   PDESCRIPTOR_SENSE_DATA descriptorSenseData = (PDESCRIPTOR_SENSE_DATA)SenseInfoBuffer;
3805   BOOLEAN succeed = FALSE;
3806 
3807   if (SenseInfoBuffer == NULL || SenseInfoBufferLength == 0)
3808   {
3809     return FALSE;
3810   }
3811   if (RTL_CONTAINS_FIELD(descriptorSenseData, SenseInfoBufferLength, AdditionalSenseLength))
3812   {
3813 
3814     if (SenseKey)
3815     {
3816       *SenseKey = descriptorSenseData->SenseKey;
3817     }
3818 
3819     if (AdditionalSenseCode != NULL)
3820     {
3821       *AdditionalSenseCode = descriptorSenseData->AdditionalSenseCode;
3822     }
3823 
3824     if (AdditionalSenseCodeQualifier != NULL)
3825     {
3826       *AdditionalSenseCodeQualifier = descriptorSenseData->AdditionalSenseCodeQualifier;
3827     }
3828 
3829     succeed = TRUE;
3830   }
3831 
3832   return succeed;
3833 }
3834 
3835 typedef ULONG SCSI_SENSE_OPTIONS;
3836 
3837 #define SCSI_SENSE_OPTIONS_NONE ((SCSI_SENSE_OPTIONS)0x00000000)
3838 #define SCSI_SENSE_OPTIONS_FIXED_FORMAT_IF_UNKNOWN_FORMAT_INDICATED ((SCSI_SENSE_OPTIONS)0x00000001)
3839 
3840 _Success_(return != FALSE)
3841 FORCEINLINE
3842 BOOLEAN
3843 ScsiGetSenseKeyAndCodes(
3844   _In_reads_bytes_(SenseInfoBufferLength) PVOID SenseInfoBuffer,
3845   _In_ UCHAR SenseInfoBufferLength,
3846   _In_ SCSI_SENSE_OPTIONS Options,
3847   _Out_opt_ PUCHAR SenseKey,
3848   _Out_opt_ PUCHAR AdditionalSenseCode,
3849   _Out_opt_ PUCHAR AdditionalSenseCodeQualifier)
3850 {
3851   BOOLEAN succeed = FALSE;
3852 
3853   if (SenseInfoBuffer == NULL || SenseInfoBufferLength == 0)
3854   {
3855     return FALSE;
3856   }
3857 
3858   if (IsDescriptorSenseDataFormat(SenseInfoBuffer))
3859   {
3860     succeed = ScsiGetDescriptorSenseKeyAndCodes(SenseInfoBuffer, SenseInfoBufferLength, SenseKey,
3861                                                 AdditionalSenseCode, AdditionalSenseCodeQualifier);
3862   }
3863   else
3864   {
3865     if ((Options & SCSI_SENSE_OPTIONS_FIXED_FORMAT_IF_UNKNOWN_FORMAT_INDICATED) ||
3866         IsFixedSenseDataFormat(SenseInfoBuffer))
3867     {
3868 
3869       succeed = ScsiGetFixedSenseKeyAndCodes(SenseInfoBuffer, SenseInfoBufferLength, SenseKey,
3870                                              AdditionalSenseCode, AdditionalSenseCodeQualifier);
3871     }
3872   }
3873 
3874   return succeed;
3875 }
3876 
3877 _Success_(return != FALSE)
3878 FORCEINLINE
3879 BOOLEAN
3880 ScsiGetSenseDescriptor(
3881   _In_reads_bytes_(SenseInfoBufferLength) PVOID SenseInfoBuffer,
3882   _In_ UCHAR SenseInfoBufferLength,
3883   _Outptr_result_bytebuffer_(*DescriptorBufferLength) PVOID *DescriptorBuffer,
3884   _Out_ UCHAR *DescriptorBufferLength)
3885 {
3886   PDESCRIPTOR_SENSE_DATA descriptorSenseData;
3887   BOOLEAN succeed = FALSE;
3888   UCHAR dataLength = 0;
3889 
3890   if (SenseInfoBuffer == NULL || SenseInfoBufferLength == 0 || DescriptorBuffer == NULL ||
3891       DescriptorBufferLength == NULL)
3892   {
3893     return FALSE;
3894   }
3895 
3896   *DescriptorBuffer = NULL;
3897   *DescriptorBufferLength = 0;
3898 
3899   if (!IsDescriptorSenseDataFormat(SenseInfoBuffer))
3900   {
3901     return FALSE;
3902   }
3903 
3904   descriptorSenseData = (PDESCRIPTOR_SENSE_DATA)SenseInfoBuffer;
3905 
3906   if (RTL_CONTAINS_FIELD(descriptorSenseData, SenseInfoBufferLength, AdditionalSenseLength))
3907   {
3908     if (descriptorSenseData->AdditionalSenseLength <=
3909         (MAX_SENSE_BUFFER_SIZE -
3910          RTL_SIZEOF_THROUGH_FIELD(DESCRIPTOR_SENSE_DATA, AdditionalSenseLength)))
3911     {
3912       dataLength = descriptorSenseData->AdditionalSenseLength +
3913                    RTL_SIZEOF_THROUGH_FIELD(DESCRIPTOR_SENSE_DATA, AdditionalSenseLength);
3914 
3915       if (dataLength > SenseInfoBufferLength)
3916       {
3917         dataLength = SenseInfoBufferLength;
3918       }
3919 
3920       *DescriptorBufferLength =
3921           dataLength - RTL_SIZEOF_THROUGH_FIELD(DESCRIPTOR_SENSE_DATA, AdditionalSenseLength);
3922 
3923       if (*DescriptorBufferLength > 0)
3924       {
3925         *DescriptorBuffer = (PVOID)(descriptorSenseData->DescriptorBuffer);
3926         succeed = TRUE;
3927       }
3928     }
3929   }
3930 
3931   return succeed;
3932 }
3933 
3934 _Success_(return != FALSE)
3935 FORCEINLINE
3936 BOOLEAN
3937 ScsiValidateInformationSenseDescriptor(
3938   _In_reads_bytes_(DescriptorBufferLength) PVOID DescriptorBuffer,
3939   _In_ UCHAR DescriptorBufferLength)
3940 {
3941   PSCSI_SENSE_DESCRIPTOR_INFORMATION descriptor;
3942   UCHAR additionalLength;
3943 
3944   if (DescriptorBuffer == NULL ||
3945       DescriptorBufferLength < sizeof(SCSI_SENSE_DESCRIPTOR_INFORMATION))
3946   {
3947     return FALSE;
3948   }
3949 
3950   descriptor = (PSCSI_SENSE_DESCRIPTOR_INFORMATION)DescriptorBuffer;
3951 
3952   if (descriptor->Header.DescriptorType != SCSI_SENSE_DESCRIPTOR_TYPE_INFORMATION)
3953   {
3954     return FALSE;
3955   }
3956 
3957   additionalLength = sizeof(SCSI_SENSE_DESCRIPTOR_INFORMATION) -
3958                      RTL_SIZEOF_THROUGH_FIELD(SCSI_SENSE_DESCRIPTOR_INFORMATION, Header);
3959 
3960   if (descriptor->Header.AdditionalLength != additionalLength)
3961   {
3962     return FALSE;
3963   }
3964 
3965   if (descriptor->Valid == 0)
3966   {
3967     return FALSE;
3968   }
3969 
3970   return TRUE;
3971 }
3972 
3973 _Success_(return != FALSE)
3974 FORCEINLINE
3975 BOOLEAN
3976 ScsiValidateBlockCommandSenseDescriptor(
3977   _In_reads_bytes_(DescriptorBufferLength) PVOID DescriptorBuffer,
3978   _In_ UCHAR DescriptorBufferLength)
3979 {
3980   PSCSI_SENSE_DESCRIPTOR_BLOCK_COMMAND descriptor;
3981   UCHAR additionalLength;
3982 
3983   if (DescriptorBuffer == NULL ||
3984       DescriptorBufferLength < sizeof(SCSI_SENSE_DESCRIPTOR_BLOCK_COMMAND))
3985   {
3986     return FALSE;
3987   }
3988 
3989   descriptor = (PSCSI_SENSE_DESCRIPTOR_BLOCK_COMMAND)DescriptorBuffer;
3990 
3991   if (descriptor->Header.DescriptorType != SCSI_SENSE_DESCRIPTOR_TYPE_BLOCK_COMMAND)
3992   {
3993     return FALSE;
3994   }
3995 
3996   additionalLength = sizeof(SCSI_SENSE_DESCRIPTOR_BLOCK_COMMAND) -
3997                      RTL_SIZEOF_THROUGH_FIELD(SCSI_SENSE_DESCRIPTOR_BLOCK_COMMAND, Header);
3998 
3999   if (descriptor->Header.AdditionalLength != additionalLength)
4000   {
4001     return FALSE;
4002   }
4003 
4004   return TRUE;
4005 }
4006 
4007 _Success_(return != FALSE)
4008 FORCEINLINE
4009 BOOLEAN
4010 ScsiConvertToFixedSenseFormat(
4011   _In_reads_bytes_(SenseInfoBufferLength) PVOID SenseInfoBuffer,
4012   _In_ UCHAR SenseInfoBufferLength,
4013   _Out_writes_bytes_(OutBufferLength) PVOID OutBuffer,
4014   _In_ UCHAR OutBufferLength)
4015 {
4016   BOOLEAN succeed = FALSE;
4017   BOOLEAN validSense = FALSE;
4018   UCHAR senseKey = 0;
4019   UCHAR additionalSenseCode = 0;
4020   UCHAR additionalSenseCodeQualifier = 0;
4021   PFIXED_SENSE_DATA outBuffer = (PFIXED_SENSE_DATA)OutBuffer;
4022 
4023   if (SenseInfoBuffer == NULL || SenseInfoBufferLength == 0 || OutBuffer == NULL ||
4024       OutBufferLength < sizeof(FIXED_SENSE_DATA))
4025   {
4026     return FALSE;
4027   }
4028 
4029   if (IsDescriptorSenseDataFormat(SenseInfoBuffer))
4030   {
4031     RtlZeroMemory(OutBuffer, OutBufferLength);
4032 
4033     validSense =
4034         ScsiGetSenseKeyAndCodes(SenseInfoBuffer, SenseInfoBufferLength, SCSI_SENSE_OPTIONS_NONE,
4035                                 &senseKey, &additionalSenseCode, &additionalSenseCodeQualifier);
4036     if (validSense)
4037     {
4038 
4039       if (IsSenseDataCurrentError(SenseInfoBuffer))
4040       {
4041         outBuffer->ErrorCode = SCSI_SENSE_ERRORCODE_FIXED_CURRENT;
4042       }
4043       else
4044       {
4045         outBuffer->ErrorCode = SCSI_SENSE_ERRORCODE_FIXED_DEFERRED;
4046       }
4047       outBuffer->AdditionalSenseLength =
4048           sizeof(FIXED_SENSE_DATA) -
4049           RTL_SIZEOF_THROUGH_FIELD(FIXED_SENSE_DATA, AdditionalSenseLength);
4050       outBuffer->SenseKey = senseKey;
4051       outBuffer->AdditionalSenseCode = additionalSenseCode;
4052       outBuffer->AdditionalSenseCodeQualifier = additionalSenseCodeQualifier;
4053 
4054       succeed = TRUE;
4055     }
4056   }
4057 
4058   return succeed;
4059 }
4060 
4061 _Success_(return != FALSE)
4062 FORCEINLINE
4063 BOOLEAN
4064 ScsiGetNextSenseDescriptorByType(
4065     _In_reads_bytes_(BufferLength) PVOID Buffer,
4066     _In_ UCHAR BufferLength,
4067     _In_reads_(TypeListCount) PUCHAR TypeList,
4068     _In_ ULONG TypeListCount,
4069     _Out_ PUCHAR OutType,
4070     _Outptr_result_bytebuffer_(*OutBufferLength) PVOID *OutBuffer,
4071     _Out_ UCHAR *OutBufferLength)
4072 {
4073   PUCHAR remainingBuffer;
4074   UCHAR remainingBufferLength;
4075   UCHAR type;
4076   ULONG i;
4077   UCHAR descriptorLength;
4078 
4079   if (Buffer == NULL || BufferLength == 0 || TypeList == NULL || TypeListCount == 0 ||
4080       OutType == NULL || OutBuffer == NULL || OutBufferLength == NULL)
4081   {
4082     return FALSE;
4083   }
4084 
4085   *OutBuffer = NULL;
4086   *OutBufferLength = 0;
4087   *OutType = 0;
4088 
4089   remainingBuffer = (PUCHAR)Buffer;
4090   remainingBufferLength = BufferLength;
4091 
4092   while (remainingBufferLength >= sizeof(SCSI_SENSE_DESCRIPTOR_HEADER))
4093   {
4094     for (i = 0; i < TypeListCount; i++)
4095     {
4096       type = TypeList[i];
4097 
4098       if (((PSCSI_SENSE_DESCRIPTOR_HEADER)remainingBuffer)->DescriptorType == type)
4099       {
4100         *OutBuffer = (PVOID)remainingBuffer;
4101         *OutBufferLength = remainingBufferLength;
4102         *OutType = type;
4103         return TRUE;
4104       }
4105     }
4106 
4107     descriptorLength = ScsiGetSenseDescriptorLength(remainingBuffer);
4108 
4109     if (remainingBufferLength > descriptorLength)
4110     {
4111       remainingBuffer += descriptorLength;
4112       remainingBufferLength -= descriptorLength;
4113     }
4114     else
4115     {
4116       break;
4117     }
4118   }
4119 
4120   return FALSE;
4121 }
4122 
4123 #ifdef __cplusplus
4124 }
4125 #endif
4126 
4127 #endif /* _NTSCSI_ */
4128