[PSDK]
[reactos.git] / reactos / include / ddk / classpnp.h
1
2 #pragma once
3
4 #define _CLASS_
5
6 #include <ntdddisk.h>
7 #include <ntddcdrm.h>
8 #include <ntddtape.h>
9 #include <ntddscsi.h>
10 #include <ntddstor.h>
11
12 #include <stdio.h>
13
14 #include <scsi.h>
15
16 #define SRB_CLASS_FLAGS_LOW_PRIORITY 0x10000000
17 #define SRB_CLASS_FLAGS_PERSISTANT 0x20000000
18 #define SRB_CLASS_FLAGS_PAGING 0x40000000
19 #define SRB_CLASS_FLAGS_FREE_MDL 0x80000000
20
21 #define IS_CLEANUP_REQUEST(majorFunction) \
22 ((majorFunction == IRP_MJ_CLOSE) || \
23 (majorFunction == IRP_MJ_CLEANUP) || \
24 (majorFunction == IRP_MJ_SHUTDOWN))
25
26 #define DO_MCD(fdoExtension) \
27 (((fdoExtension)->MediaChangeDetectionInfo != NULL) && \
28 ((fdoExtension)->MediaChangeDetectionInfo->MediaChangeDetectionDisableCount == 0))
29
30 #define IS_SCSIOP_READ(opCode) \
31 ((opCode == SCSIOP_READ6) || \
32 (opCode == SCSIOP_READ) || \
33 (opCode == SCSIOP_READ12) || \
34 (opCode == SCSIOP_READ16))
35
36 #define IS_SCSIOP_WRITE(opCode) \
37 ((opCode == SCSIOP_WRITE6) || \
38 (opCode == SCSIOP_WRITE) || \
39 (opCode == SCSIOP_WRITE12) || \
40 (opCode == SCSIOP_WRITE16))
41
42 #define IS_SCSIOP_READWRITE(opCode) (IS_SCSIOP_READ(opCode) || IS_SCSIOP_WRITE(opCode))
43
44 #define MAXIMUM_RETRIES 4
45
46 #define CLASS_DRIVER_EXTENSION_KEY ((PVOID) ClassInitialize)
47
48 #define NO_REMOVE 0
49 #define REMOVE_PENDING 1
50 #define REMOVE_COMPLETE 2
51
52 #define ClassAcquireRemoveLock(devobj, tag) \
53 ClassAcquireRemoveLockEx(devobj, tag, __FILE__, __LINE__)
54
55 #ifdef TRY
56 #undef TRY
57 #endif
58 #ifdef LEAVE
59 #undef LEAVE
60 #endif
61
62 #ifdef FINALLY
63 #undef FINALLY
64 #endif
65
66 #define TRY
67 #define LEAVE goto __tryLabel;
68 #define FINALLY __tryLabel:
69
70 #if defined DebugPrint
71 #undef DebugPrint
72 #endif
73
74 #if DBG
75 #define DebugPrint(x) ClassDebugPrint x
76 #else
77 #define DebugPrint(x)
78 #endif
79
80 #define DEBUG_BUFFER_LENGTH 256
81
82 #define START_UNIT_TIMEOUT (60 * 4)
83
84 #define MEDIA_CHANGE_DEFAULT_TIME 1
85 #define MEDIA_CHANGE_TIMEOUT_TIME 300
86
87 #define MAXIMUM_RETRY_FOR_SINGLE_IO_IN_100NS_UNITS 0x3b9aca00
88
89 #ifdef ALLOCATE_SRB_FROM_POOL
90
91 #define ClasspAllocateSrb(ext)
92 ExAllocatePoolWithTag(NonPagedPool, \
93 sizeof(SCSI_REQUEST_BLOCK), \
94 'sBRS')
95
96 #define ClasspFreeSrb(ext, srb) ExFreePool((srb));
97
98 #else /* ALLOCATE_SRB_FROM_POOL */
99
100 #define ClasspAllocateSrb(ext) \
101 ExAllocateFromNPagedLookasideList( \
102 &((ext)->CommonExtension.SrbLookasideList))
103
104 #define ClasspFreeSrb(ext, srb) \
105 ExFreeToNPagedLookasideList( \
106 &((ext)->CommonExtension.SrbLookasideList), \
107 (srb))
108
109 #endif /* ALLOCATE_SRB_FROM_POOL */
110
111 #define SET_FLAG(Flags, Bit) ((Flags) |= (Bit))
112 #define CLEAR_FLAG(Flags, Bit) ((Flags) &= ~(Bit))
113 #define TEST_FLAG(Flags, Bit) (((Flags) & (Bit)) != 0)
114
115 #define CLASS_WORKING_SET_MAXIMUM 2048
116
117 #define CLASS_INTERPRET_SENSE_INFO2_MAXIMUM_HISTORY_COUNT 30000
118
119 #define CLASS_SPECIAL_DISABLE_SPIN_DOWN 0x00000001
120 #define CLASS_SPECIAL_DISABLE_SPIN_UP 0x00000002
121 #define CLASS_SPECIAL_NO_QUEUE_LOCK 0x00000008
122 #define CLASS_SPECIAL_DISABLE_WRITE_CACHE 0x00000010
123 #define CLASS_SPECIAL_CAUSE_NOT_REPORTABLE_HACK 0x00000020
124 #if ((NTDDI_VERSION == NTDDI_WIN2KSP3) || (OSVER(NTDDI_VERSION) == NTDDI_WINXP))
125 #define CLASS_SPECIAL_DISABLE_WRITE_CACHE_NOT_SUPPORTED 0x00000040
126 #endif
127 #define CLASS_SPECIAL_MODIFY_CACHE_UNSUCCESSFUL 0x00000040
128 #define CLASS_SPECIAL_FUA_NOT_SUPPORTED 0x00000080
129 #define CLASS_SPECIAL_VALID_MASK 0x000000FB
130 #define CLASS_SPECIAL_RESERVED (~CLASS_SPECIAL_VALID_MASK)
131
132 #define DEV_WRITE_CACHE 0x00000001
133 #define DEV_USE_SCSI1 0x00000002
134 #define DEV_SAFE_START_UNIT 0x00000004
135 #define DEV_NO_12BYTE_CDB 0x00000008
136 #define DEV_POWER_PROTECTED 0x00000010
137 #define DEV_USE_16BYTE_CDB 0x00000020
138
139 #define GUID_CLASSPNP_QUERY_REGINFOEX {0x00e34b11, 0x2444, 0x4745, {0xa5, 0x3d, 0x62, 0x01, 0x00, 0xcd, 0x82, 0xf7}}
140 #define GUID_CLASSPNP_SENSEINFO2 {0x509a8c5f, 0x71d7, 0x48f6, {0x82, 0x1e, 0x17, 0x3c, 0x49, 0xbf, 0x2f, 0x18}}
141 #define GUID_CLASSPNP_WORKING_SET {0x105701b0, 0x9e9b, 0x47cb, {0x97, 0x80, 0x81, 0x19, 0x8a, 0xf7, 0xb5, 0x24}}
142
143 #define DEFAULT_FAILURE_PREDICTION_PERIOD 60 * 60 * 1
144
145 typedef enum _MEDIA_CHANGE_DETECTION_STATE {
146 MediaUnknown,
147 MediaPresent,
148 MediaNotPresent,
149 MediaUnavailable
150 } MEDIA_CHANGE_DETECTION_STATE, *PMEDIA_CHANGE_DETECTION_STATE;
151
152 typedef enum _CLASS_DEBUG_LEVEL {
153 ClassDebugError = 0,
154 ClassDebugWarning = 1,
155 ClassDebugTrace = 2,
156 ClassDebugInfo = 3,
157 ClassDebugMediaLocks = 8,
158 ClassDebugMCN = 9,
159 ClassDebugDelayedRetry = 10,
160 ClassDebugSenseInfo = 11,
161 ClassDebugRemoveLock = 12,
162 ClassDebugExternal4 = 13,
163 ClassDebugExternal3 = 14,
164 ClassDebugExternal2 = 15,
165 ClassDebugExternal1 = 16
166 } CLASS_DEBUG_LEVEL, *PCLASS_DEBUG_LEVEL;
167
168 typedef enum {
169 EventGeneration,
170 DataBlockCollection
171 } CLASSENABLEDISABLEFUNCTION;
172
173 typedef enum {
174 FailurePredictionNone = 0,
175 FailurePredictionIoctl,
176 FailurePredictionSmart,
177 FailurePredictionSense
178 } FAILURE_PREDICTION_METHOD, *PFAILURE_PREDICTION_METHOD;
179
180 typedef enum {
181 PowerDownDeviceInitial,
182 PowerDownDeviceLocked,
183 PowerDownDeviceStopped,
184 PowerDownDeviceOff,
185 PowerDownDeviceUnlocked
186 } CLASS_POWER_DOWN_STATE;
187
188 typedef enum {
189 PowerDownDeviceInitial2,
190 PowerDownDeviceLocked2,
191 PowerDownDeviceFlushed2,
192 PowerDownDeviceStopped2,
193 PowerDownDeviceOff2,
194 PowerDownDeviceUnlocked2
195 } CLASS_POWER_DOWN_STATE2;
196
197 typedef enum {
198 PowerUpDeviceInitial,
199 PowerUpDeviceLocked,
200 PowerUpDeviceOn,
201 PowerUpDeviceStarted,
202 PowerUpDeviceUnlocked
203 } CLASS_POWER_UP_STATE;
204
205 struct _CLASS_INIT_DATA;
206 typedef struct _CLASS_INIT_DATA CLASS_INIT_DATA, *PCLASS_INIT_DATA;
207
208 struct _CLASS_PRIVATE_FDO_DATA;
209 typedef struct _CLASS_PRIVATE_FDO_DATA CLASS_PRIVATE_FDO_DATA, *PCLASS_PRIVATE_FDO_DATA;
210
211 struct _CLASS_PRIVATE_PDO_DATA;
212 typedef struct _CLASS_PRIVATE_PDO_DATA CLASS_PRIVATE_PDO_DATA, *PCLASS_PRIVATE_PDO_DATA;
213
214 struct _CLASS_PRIVATE_COMMON_DATA;
215 typedef struct _CLASS_PRIVATE_COMMON_DATA CLASS_PRIVATE_COMMON_DATA, *PCLASS_PRIVATE_COMMON_DATA;
216
217 struct _MEDIA_CHANGE_DETECTION_INFO;
218 typedef struct _MEDIA_CHANGE_DETECTION_INFO MEDIA_CHANGE_DETECTION_INFO, *PMEDIA_CHANGE_DETECTION_INFO;
219
220 struct _DICTIONARY_HEADER;
221 typedef struct _DICTIONARY_HEADER DICTIONARY_HEADER, *PDICTIONARY_HEADER;
222
223 typedef struct _DICTIONARY {
224 ULONGLONG Signature;
225 PDICTIONARY_HEADER List;
226 KSPIN_LOCK SpinLock;
227 } DICTIONARY, *PDICTIONARY;
228
229 typedef struct _CLASSPNP_SCAN_FOR_SPECIAL_INFO {
230 PCHAR VendorId;
231 PCHAR ProductId;
232 PCHAR ProductRevision;
233 ULONG_PTR Data;
234 } CLASSPNP_SCAN_FOR_SPECIAL_INFO, *PCLASSPNP_SCAN_FOR_SPECIAL_INFO;
235
236 typedef VOID
237 (NTAPI *PCLASS_ERROR)(
238 PDEVICE_OBJECT DeviceObject,
239 PSCSI_REQUEST_BLOCK Srb,
240 NTSTATUS *Status,
241 BOOLEAN *Retry);
242
243 typedef NTSTATUS
244 (NTAPI *PCLASS_ADD_DEVICE)(
245 PDRIVER_OBJECT DriverObject,
246 PDEVICE_OBJECT Pdo);
247
248 typedef NTSTATUS
249 (NTAPI *PCLASS_POWER_DEVICE)(
250 PDEVICE_OBJECT DeviceObject,
251 PIRP Irp);
252
253 typedef NTSTATUS
254 (NTAPI *PCLASS_START_DEVICE)(
255 PDEVICE_OBJECT DeviceObject);
256
257 typedef NTSTATUS
258 (NTAPI *PCLASS_STOP_DEVICE)(
259 PDEVICE_OBJECT DeviceObject,
260 UCHAR Type);
261
262 typedef NTSTATUS
263 (NTAPI *PCLASS_INIT_DEVICE)(
264 PDEVICE_OBJECT DeviceObject);
265
266 typedef NTSTATUS
267 (NTAPI *PCLASS_ENUM_DEVICE)(
268 PDEVICE_OBJECT DeviceObject);
269
270 typedef NTSTATUS
271 (NTAPI *PCLASS_READ_WRITE)(
272 PDEVICE_OBJECT DeviceObject,
273 PIRP Irp);
274
275 typedef NTSTATUS
276 (NTAPI *PCLASS_DEVICE_CONTROL)(
277 PDEVICE_OBJECT DeviceObject,
278 PIRP Irp);
279
280 typedef NTSTATUS
281 (NTAPI *PCLASS_SHUTDOWN_FLUSH)(
282 PDEVICE_OBJECT DeviceObject,
283 PIRP Irp);
284
285 typedef NTSTATUS
286 (NTAPI *PCLASS_CREATE_CLOSE)(
287 PDEVICE_OBJECT DeviceObject,
288 PIRP Irp);
289
290 typedef NTSTATUS
291 (NTAPI *PCLASS_QUERY_ID)(
292 PDEVICE_OBJECT DeviceObject,
293 BUS_QUERY_ID_TYPE IdType,
294 PUNICODE_STRING IdString);
295
296 typedef NTSTATUS
297 (NTAPI *PCLASS_REMOVE_DEVICE)(
298 PDEVICE_OBJECT DeviceObject,
299 UCHAR Type);
300
301 typedef VOID
302 (NTAPI *PCLASS_UNLOAD)(
303 PDRIVER_OBJECT DriverObject);
304
305 typedef NTSTATUS
306 (NTAPI *PCLASS_QUERY_PNP_CAPABILITIES)(
307 PDEVICE_OBJECT PhysicalDeviceObject,
308 PDEVICE_CAPABILITIES Capabilities);
309
310 typedef VOID
311 (NTAPI *PCLASS_TICK)(
312 PDEVICE_OBJECT DeviceObject);
313
314 typedef NTSTATUS
315 (NTAPI *PCLASS_QUERY_WMI_REGINFO_EX)(
316 PDEVICE_OBJECT DeviceObject,
317 ULONG *RegFlags,
318 PUNICODE_STRING Name,
319 PUNICODE_STRING MofResouceName);
320
321 typedef NTSTATUS
322 (NTAPI *PCLASS_QUERY_WMI_REGINFO)(
323 PDEVICE_OBJECT DeviceObject,
324 ULONG *RegFlags,
325 PUNICODE_STRING Name);
326
327 typedef NTSTATUS
328 (NTAPI *PCLASS_QUERY_WMI_DATABLOCK)(
329 PDEVICE_OBJECT DeviceObject,
330 PIRP Irp,
331 ULONG GuidIndex,
332 ULONG BufferAvail,
333 PUCHAR Buffer);
334
335 typedef NTSTATUS
336 (NTAPI *PCLASS_SET_WMI_DATABLOCK)(
337 PDEVICE_OBJECT DeviceObject,
338 PIRP Irp,
339 ULONG GuidIndex,
340 ULONG BufferSize,
341 PUCHAR Buffer);
342
343 typedef NTSTATUS
344 (NTAPI *PCLASS_SET_WMI_DATAITEM)(
345 PDEVICE_OBJECT DeviceObject,
346 PIRP Irp,
347 ULONG GuidIndex,
348 ULONG DataItemId,
349 ULONG BufferSize,
350 PUCHAR Buffer);
351
352 typedef NTSTATUS
353 (NTAPI *PCLASS_EXECUTE_WMI_METHOD)(
354 PDEVICE_OBJECT DeviceObject,
355 PIRP Irp,
356 ULONG GuidIndex,
357 ULONG MethodId,
358 ULONG InBufferSize,
359 ULONG OutBufferSize,
360 PUCHAR Buffer);
361
362 typedef NTSTATUS
363 (NTAPI *PCLASS_WMI_FUNCTION_CONTROL)(
364 PDEVICE_OBJECT DeviceObject,
365 PIRP Irp,
366 ULONG GuidIndex,
367 CLASSENABLEDISABLEFUNCTION Function,
368 BOOLEAN Enable);
369
370 typedef struct _SRB_HISTORY_ITEM {
371 LARGE_INTEGER TickCountSent;
372 LARGE_INTEGER TickCountCompleted;
373 ULONG MillisecondsDelayOnRetry;
374 SENSE_DATA NormalizedSenseData;
375 UCHAR SrbStatus;
376 UCHAR ClassDriverUse;
377 } SRB_HISTORY_ITEM, *PSRB_HISTORY_ITEM;
378
379 typedef struct _SRB_HISTORY {
380 ULONG_PTR ClassDriverUse[4];
381 ULONG TotalHistoryCount;
382 ULONG UsedHistoryCount;
383 SRB_HISTORY_ITEM History[1];
384 } SRB_HISTORY, *PSRB_HISTORY;
385
386 typedef BOOLEAN
387 (NTAPI *PCLASS_INTERPRET_SENSE_INFO)(
388 PDEVICE_OBJECT Fdo,
389 PIRP OriginalRequest,
390 PSCSI_REQUEST_BLOCK Srb,
391 UCHAR MajorFunctionCode,
392 ULONG IoDeviceCode,
393 ULONG PreviousRetryCount,
394 SRB_HISTORY *RequestHistory,
395 NTSTATUS *Status,
396 LONGLONG *RetryIn100nsUnits);
397
398 typedef VOID
399 (NTAPI *PCLASS_COMPRESS_RETRY_HISTORY_DATA)(
400 PDEVICE_OBJECT DeviceObject,
401 PSRB_HISTORY RequestHistory);
402
403 typedef struct {
404 GUID Guid;
405 ULONG InstanceCount;
406 ULONG Flags;
407 } GUIDREGINFO, *PGUIDREGINFO;
408
409 typedef struct _CLASS_WMI_INFO {
410 ULONG GuidCount;
411 PGUIDREGINFO GuidRegInfo;
412 PCLASS_QUERY_WMI_REGINFO ClassQueryWmiRegInfo;
413 PCLASS_QUERY_WMI_DATABLOCK ClassQueryWmiDataBlock;
414 PCLASS_SET_WMI_DATABLOCK ClassSetWmiDataBlock;
415 PCLASS_SET_WMI_DATAITEM ClassSetWmiDataItem;
416 PCLASS_EXECUTE_WMI_METHOD ClassExecuteWmiMethod;
417 PCLASS_WMI_FUNCTION_CONTROL ClassWmiFunctionControl;
418 } CLASS_WMI_INFO, *PCLASS_WMI_INFO;
419
420 typedef struct _CLASS_DEV_INFO {
421 ULONG DeviceExtensionSize;
422 DEVICE_TYPE DeviceType;
423 UCHAR StackSize;
424 ULONG DeviceCharacteristics;
425 PCLASS_ERROR ClassError;
426 PCLASS_READ_WRITE ClassReadWriteVerification;
427 PCLASS_DEVICE_CONTROL ClassDeviceControl;
428 PCLASS_SHUTDOWN_FLUSH ClassShutdownFlush;
429 PCLASS_CREATE_CLOSE ClassCreateClose;
430 PCLASS_INIT_DEVICE ClassInitDevice;
431 PCLASS_START_DEVICE ClassStartDevice;
432 PCLASS_POWER_DEVICE ClassPowerDevice;
433 PCLASS_STOP_DEVICE ClassStopDevice;
434 PCLASS_REMOVE_DEVICE ClassRemoveDevice;
435 PCLASS_QUERY_PNP_CAPABILITIES ClassQueryPnpCapabilities;
436 CLASS_WMI_INFO ClassWmiInfo;
437 } CLASS_DEV_INFO, *PCLASS_DEV_INFO;
438
439 struct _CLASS_INIT_DATA {
440 ULONG InitializationDataSize;
441 CLASS_DEV_INFO FdoData;
442 CLASS_DEV_INFO PdoData;
443 PCLASS_ADD_DEVICE ClassAddDevice;
444 PCLASS_ENUM_DEVICE ClassEnumerateDevice;
445 PCLASS_QUERY_ID ClassQueryId;
446 PDRIVER_STARTIO ClassStartIo;
447 PCLASS_UNLOAD ClassUnload;
448 PCLASS_TICK ClassTick;
449 };
450
451 typedef struct _FILE_OBJECT_EXTENSION {
452 PFILE_OBJECT FileObject;
453 PDEVICE_OBJECT DeviceObject;
454 ULONG LockCount;
455 ULONG McnDisableCount;
456 } FILE_OBJECT_EXTENSION, *PFILE_OBJECT_EXTENSION;
457
458 typedef struct _CLASS_WORKING_SET {
459 ULONG Size;
460 ULONG XferPacketsWorkingSetMaximum;
461 ULONG XferPacketsWorkingSetMinimum;
462 } CLASS_WORKING_SET, *PCLASS_WORKING_SET;
463
464 typedef struct _CLASS_INTERPRET_SENSE_INFO2 {
465 ULONG Size;
466 ULONG HistoryCount;
467 PCLASS_COMPRESS_RETRY_HISTORY_DATA Compress;
468 PCLASS_INTERPRET_SENSE_INFO Interpret;
469 } CLASS_INTERPRET_SENSE_INFO2, *PCLASS_INTERPRET_SENSE_INFO2;
470
471 C_ASSERT((MAXULONG - sizeof(SRB_HISTORY)) / 30000 >= sizeof(SRB_HISTORY_ITEM));
472
473 typedef struct _CLASS_DRIVER_EXTENSION {
474 UNICODE_STRING RegistryPath;
475 CLASS_INIT_DATA InitData;
476 ULONG DeviceCount;
477 #if (NTDDI_VERSION >= NTDDI_WINXP)
478 PCLASS_QUERY_WMI_REGINFO_EX ClassFdoQueryWmiRegInfoEx;
479 PCLASS_QUERY_WMI_REGINFO_EX ClassPdoQueryWmiRegInfoEx;
480 #endif
481 #if (NTDDI_VERSION >= NTDDI_VISTA)
482 REGHANDLE EtwHandle;
483 PDRIVER_DISPATCH DeviceMajorFunctionTable[IRP_MJ_MAXIMUM_FUNCTION + 1];
484 PDRIVER_DISPATCH MpDeviceMajorFunctionTable[IRP_MJ_MAXIMUM_FUNCTION + 1];
485 PCLASS_INTERPRET_SENSE_INFO2 InterpretSenseInfo;
486 PCLASS_WORKING_SET WorkingSet;
487 #endif
488 } CLASS_DRIVER_EXTENSION, *PCLASS_DRIVER_EXTENSION;
489
490 typedef struct _COMMON_DEVICE_EXTENSION {
491 ULONG Version;
492 PDEVICE_OBJECT DeviceObject;
493 PDEVICE_OBJECT LowerDeviceObject;
494 struct _FUNCTIONAL_DEVICE_EXTENSION *PartitionZeroExtension;
495 PCLASS_DRIVER_EXTENSION DriverExtension;
496 LONG RemoveLock;
497 KEVENT RemoveEvent;
498 KSPIN_LOCK RemoveTrackingSpinlock;
499 PVOID RemoveTrackingList;
500 LONG RemoveTrackingUntrackedCount;
501 PVOID DriverData;
502 _ANONYMOUS_STRUCT struct {
503 BOOLEAN IsFdo:1;
504 BOOLEAN IsInitialized:1;
505 BOOLEAN IsSrbLookasideListInitialized:1;
506 } DUMMYSTRUCTNAME;
507 UCHAR PreviousState;
508 UCHAR CurrentState;
509 ULONG IsRemoved;
510 UNICODE_STRING DeviceName;
511 struct _PHYSICAL_DEVICE_EXTENSION *ChildList;
512 ULONG PartitionNumber;
513 LARGE_INTEGER PartitionLength;
514 LARGE_INTEGER StartingOffset;
515 PCLASS_DEV_INFO DevInfo;
516 ULONG PagingPathCount;
517 ULONG DumpPathCount;
518 ULONG HibernationPathCount;
519 KEVENT PathCountEvent;
520 #ifndef ALLOCATE_SRB_FROM_POOL
521 NPAGED_LOOKASIDE_LIST SrbLookasideList;
522 #endif
523 UNICODE_STRING MountedDeviceInterfaceName;
524 ULONG GuidCount;
525 PGUIDREGINFO GuidRegInfo;
526 DICTIONARY FileObjectDictionary;
527 #if (NTDDI_VERSION >= NTDDI_WINXP)
528 PCLASS_PRIVATE_COMMON_DATA PrivateCommonData;
529 #else
530 ULONG_PTR Reserved1;
531 #endif
532 #if (NTDDI_VERSION >= NTDDI_VISTA)
533 PDRIVER_DISPATCH *DispatchTable;
534 #else
535 ULONG_PTR Reserved2;
536 #endif
537 ULONG_PTR Reserved3;
538 ULONG_PTR Reserved4;
539 } COMMON_DEVICE_EXTENSION, *PCOMMON_DEVICE_EXTENSION;
540
541 typedef struct _PHYSICAL_DEVICE_EXTENSION {
542 _ANONYMOUS_UNION union {
543 _ANONYMOUS_STRUCT struct {
544 ULONG Version;
545 PDEVICE_OBJECT DeviceObject;
546 } DUMMYSTRUCTNAME;
547 COMMON_DEVICE_EXTENSION CommonExtension;
548 } DUMMYUNIONNAME;
549 BOOLEAN IsMissing;
550 BOOLEAN IsEnumerated;
551 #if (NTDDI_VERSION >= NTDDI_WINXP)
552 PCLASS_PRIVATE_PDO_DATA PrivatePdoData;
553 #else
554 ULONG_PTR Reserved1;
555 #endif
556 ULONG_PTR Reserved2;
557 ULONG_PTR Reserved3;
558 ULONG_PTR Reserved4;
559 } PHYSICAL_DEVICE_EXTENSION, *PPHYSICAL_DEVICE_EXTENSION;
560
561 struct _FAILURE_PREDICTION_INFO;
562 typedef struct _FAILURE_PREDICTION_INFO *PFAILURE_PREDICTION_INFO;
563
564 typedef struct _CLASS_POWER_OPTIONS {
565 ULONG PowerDown:1;
566 ULONG LockQueue:1;
567 ULONG HandleSpinDown:1;
568 ULONG HandleSpinUp:1;
569 ULONG Reserved:27;
570 } CLASS_POWER_OPTIONS, *PCLASS_POWER_OPTIONS;
571
572 typedef struct _CLASS_POWER_CONTEXT {
573 union {
574 CLASS_POWER_DOWN_STATE PowerDown;
575 CLASS_POWER_DOWN_STATE2 PowerDown2;
576 CLASS_POWER_UP_STATE PowerUp;
577 } PowerChangeState;
578 CLASS_POWER_OPTIONS Options;
579 BOOLEAN InUse;
580 BOOLEAN QueueLocked;
581 NTSTATUS FinalStatus;
582 ULONG RetryCount;
583 ULONG RetryInterval;
584 PIO_COMPLETION_ROUTINE CompletionRoutine;
585 PDEVICE_OBJECT DeviceObject;
586 PIRP Irp;
587 SCSI_REQUEST_BLOCK Srb;
588 } CLASS_POWER_CONTEXT, *PCLASS_POWER_CONTEXT;
589
590 typedef struct _COMPLETION_CONTEXT {
591 PDEVICE_OBJECT DeviceObject;
592 SCSI_REQUEST_BLOCK Srb;
593 } COMPLETION_CONTEXT, *PCOMPLETION_CONTEXT;
594
595 SCSIPORTAPI
596 ULONG
597 NTAPI
598 ClassInitialize(
599 PVOID Argument1,
600 PVOID Argument2,
601 PCLASS_INIT_DATA InitializationData);
602
603 typedef struct _CLASS_QUERY_WMI_REGINFO_EX_LIST {
604 ULONG Size;
605 PCLASS_QUERY_WMI_REGINFO_EX ClassFdoQueryWmiRegInfoEx;
606 PCLASS_QUERY_WMI_REGINFO_EX ClassPdoQueryWmiRegInfoEx;
607 } CLASS_QUERY_WMI_REGINFO_EX_LIST, *PCLASS_QUERY_WMI_REGINFO_EX_LIST;
608
609 typedef struct _FUNCTIONAL_DEVICE_EXTENSION {
610 _ANONYMOUS_UNION union {
611 _ANONYMOUS_STRUCT struct {
612 ULONG Version;
613 PDEVICE_OBJECT DeviceObject;
614 } DUMMYSTRUCTNAME;
615 COMMON_DEVICE_EXTENSION CommonExtension;
616 } DUMMYUNIONNAME;
617 PDEVICE_OBJECT LowerPdo;
618 PSTORAGE_DEVICE_DESCRIPTOR DeviceDescriptor;
619 PSTORAGE_ADAPTER_DESCRIPTOR AdapterDescriptor;
620 DEVICE_POWER_STATE DevicePowerState;
621 ULONG DMByteSkew;
622 ULONG DMSkew;
623 BOOLEAN DMActive;
624 DISK_GEOMETRY DiskGeometry;
625 PSENSE_DATA SenseData;
626 ULONG TimeOutValue;
627 ULONG DeviceNumber;
628 ULONG SrbFlags;
629 ULONG ErrorCount;
630 LONG LockCount;
631 LONG ProtectedLockCount;
632 LONG InternalLockCount;
633 KEVENT EjectSynchronizationEvent;
634 USHORT DeviceFlags;
635 UCHAR SectorShift;
636 #if (NTDDI_VERSION >= NTDDI_VISTA)
637 UCHAR CdbForceUnitAccess;
638 #else
639 UCHAR ReservedByte;
640 #endif
641 PMEDIA_CHANGE_DETECTION_INFO MediaChangeDetectionInfo;
642 PKEVENT Unused1;
643 HANDLE Unused2;
644 FILE_OBJECT_EXTENSION KernelModeMcnContext;
645 ULONG MediaChangeCount;
646 HANDLE DeviceDirectory;
647 KSPIN_LOCK ReleaseQueueSpinLock;
648 PIRP ReleaseQueueIrp;
649 SCSI_REQUEST_BLOCK ReleaseQueueSrb;
650 BOOLEAN ReleaseQueueNeeded;
651 BOOLEAN ReleaseQueueInProgress;
652 BOOLEAN ReleaseQueueIrpFromPool;
653 BOOLEAN FailurePredicted;
654 ULONG FailureReason;
655 PFAILURE_PREDICTION_INFO FailurePredictionInfo;
656 BOOLEAN PowerDownInProgress;
657 ULONG EnumerationInterlock;
658 KEVENT ChildLock;
659 PKTHREAD ChildLockOwner;
660 ULONG ChildLockAcquisitionCount;
661 ULONG ScanForSpecialFlags;
662 KDPC PowerRetryDpc;
663 KTIMER PowerRetryTimer;
664 CLASS_POWER_CONTEXT PowerContext;
665
666 #if (NTDDI_VERSION <= NTDDI_WIN2K)
667
668 #if (SPVER(NTDDI_VERSION) < 2))
669 ULONG_PTR Reserved1;
670 ULONG_PTR Reserved2;
671 ULONG_PTR Reserved3;
672 ULONG_PTR Reserved4;
673 #else
674 ULONG CompletionSuccessCount;
675 ULONG SavedSrbFlags;
676 ULONG SavedErrorCount;
677 ULONG_PTR Reserved1;
678 #endif
679
680 #else /* (NTDDI_VERSION <= NTDDI_WIN2K) */
681
682 PCLASS_PRIVATE_FDO_DATA PrivateFdoData;
683 ULONG_PTR Reserved2;
684 ULONG_PTR Reserved3;
685 ULONG_PTR Reserved4;
686
687 #endif /* (NTDDI_VERSION <= NTDDI_WIN2K) */
688
689 } FUNCTIONAL_DEVICE_EXTENSION, *PFUNCTIONAL_DEVICE_EXTENSION;
690
691 SCSIPORTAPI
692 ULONG
693 NTAPI
694 ClassInitializeEx(
695 PDRIVER_OBJECT DriverObject,
696 LPGUID Guid,
697 PVOID Data);
698
699 SCSIPORTAPI
700 NTSTATUS
701 NTAPI
702 ClassCreateDeviceObject(
703 PDRIVER_OBJECT DriverObject,
704 PCCHAR ObjectNameBuffer,
705 PDEVICE_OBJECT LowerDeviceObject,
706 BOOLEAN IsFdo,
707 PDEVICE_OBJECT *DeviceObject);
708
709 SCSIPORTAPI
710 NTSTATUS
711 NTAPI
712 ClassReadDriveCapacity(
713 PDEVICE_OBJECT DeviceObject);
714
715 SCSIPORTAPI
716 VOID
717 NTAPI
718 ClassReleaseQueue(
719 PDEVICE_OBJECT DeviceObject);
720
721 SCSIPORTAPI
722 VOID
723 NTAPI
724 ClassSplitRequest(
725 PDEVICE_OBJECT DeviceObject,
726 PIRP Irp,
727 ULONG MaximumBytes);
728
729 SCSIPORTAPI
730 NTSTATUS
731 NTAPI
732 ClassDeviceControl(
733 PDEVICE_OBJECT DeviceObject,
734 PIRP Irp);
735
736 SCSIPORTAPI
737 BOOLEAN
738 NTAPI
739 ClassInterpretSenseInfo(
740 PDEVICE_OBJECT DeviceObject,
741 PSCSI_REQUEST_BLOCK Srb,
742 UCHAR MajorFunctionCode,
743 ULONG IoDeviceCode,
744 ULONG RetryCount,
745 NTSTATUS *Status,
746 ULONG *RetryInterval);
747
748 VOID
749 NTAPI
750 ClassSendDeviceIoControlSynchronous(
751 ULONG IoControlCode,
752 PDEVICE_OBJECT TargetDeviceObject,
753 PVOID Buffer,
754 ULONG InputBufferLength,
755 ULONG OutputBufferLength,
756 BOOLEAN InternalDeviceIoControl,
757 PIO_STATUS_BLOCK IoStatus);
758
759 SCSIPORTAPI
760 NTSTATUS
761 NTAPI
762 ClassSendIrpSynchronous(
763 PDEVICE_OBJECT TargetDeviceObject,
764 PIRP Irp);
765
766 SCSIPORTAPI
767 NTSTATUS
768 NTAPI
769 ClassForwardIrpSynchronous(
770 PCOMMON_DEVICE_EXTENSION CommonExtension,
771 PIRP Irp);
772
773 SCSIPORTAPI
774 NTSTATUS
775 NTAPI
776 ClassSendSrbSynchronous(
777 PDEVICE_OBJECT DeviceObject,
778 PSCSI_REQUEST_BLOCK Srb,
779 PVOID BufferAddress,
780 ULONG BufferLength,
781 BOOLEAN WriteToDevice);
782
783 SCSIPORTAPI
784 NTSTATUS
785 NTAPI
786 ClassSendSrbAsynchronous(
787 PDEVICE_OBJECT DeviceObject,
788 PSCSI_REQUEST_BLOCK Srb,
789 PIRP Irp,
790 PVOID BufferAddress,
791 ULONG BufferLength,
792 BOOLEAN WriteToDevice);
793
794 SCSIPORTAPI
795 NTSTATUS
796 NTAPI
797 ClassBuildRequest(
798 PDEVICE_OBJECT DeviceObject,
799 PIRP Irp);
800
801 SCSIPORTAPI
802 ULONG
803 NTAPI
804 ClassModeSense(
805 PDEVICE_OBJECT DeviceObject,
806 PCHAR ModeSenseBuffer,
807 ULONG Length,
808 UCHAR PageMode);
809
810 SCSIPORTAPI
811 PVOID
812 NTAPI
813 ClassFindModePage(
814 PCHAR ModeSenseBuffer,
815 ULONG Length,
816 UCHAR PageMode,
817 BOOLEAN Use6Byte);
818
819 SCSIPORTAPI
820 NTSTATUS
821 NTAPI
822 ClassClaimDevice(
823 PDEVICE_OBJECT LowerDeviceObject,
824 BOOLEAN Release);
825
826 SCSIPORTAPI
827 VOID
828 NTAPI
829 ClassInitializeSrbLookasideList(
830 PCOMMON_DEVICE_EXTENSION CommonExtension,
831 ULONG NumberElements);
832
833 SCSIPORTAPI
834 VOID
835 NTAPI
836 ClassDeleteSrbLookasideList(
837 PCOMMON_DEVICE_EXTENSION CommonExtension);
838
839 SCSIPORTAPI
840 ULONG
841 NTAPI
842 ClassQueryTimeOutRegistryValue(
843 PDEVICE_OBJECT DeviceObject);
844
845 SCSIPORTAPI
846 NTSTATUS
847 NTAPI
848 ClassGetDescriptor(
849 PDEVICE_OBJECT DeviceObject,
850 PSTORAGE_PROPERTY_ID PropertyId,
851 PVOID *Descriptor);
852
853 SCSIPORTAPI
854 VOID
855 NTAPI
856 ClassInvalidateBusRelations(
857 PDEVICE_OBJECT Fdo);
858
859 SCSIPORTAPI
860 VOID
861 NTAPI
862 ClassMarkChildrenMissing(
863 PFUNCTIONAL_DEVICE_EXTENSION Fdo);
864
865 SCSIPORTAPI
866 BOOLEAN
867 NTAPI
868 ClassMarkChildMissing(
869 PPHYSICAL_DEVICE_EXTENSION PdoExtension,
870 BOOLEAN AcquireChildLock);
871
872 SCSIPORTAPI
873 VOID
874 NTAPI
875 ClassDebugPrint(
876 CLASS_DEBUG_LEVEL DebugPrintLevel,
877 PCCHAR DebugMessage,
878 ...);
879
880 SCSIPORTAPI
881 PCLASS_DRIVER_EXTENSION
882 NTAPI
883 ClassGetDriverExtension(
884 PDRIVER_OBJECT DriverObject);
885
886 SCSIPORTAPI
887 VOID
888 NTAPI
889 ClassCompleteRequest(
890 PDEVICE_OBJECT DeviceObject,
891 PIRP Irp,
892 CCHAR PriorityBoost);
893
894 SCSIPORTAPI
895 VOID
896 NTAPI
897 ClassReleaseRemoveLock(
898 PDEVICE_OBJECT DeviceObject,
899 PIRP Tag);
900
901 SCSIPORTAPI
902 ULONG
903 NTAPI
904 ClassAcquireRemoveLockEx(
905 PDEVICE_OBJECT DeviceObject,
906 PVOID Tag,
907 PCSTR File,
908 ULONG Line);
909
910 SCSIPORTAPI
911 VOID
912 NTAPI
913 ClassUpdateInformationInRegistry(
914 PDEVICE_OBJECT Fdo,
915 PCHAR DeviceName,
916 ULONG DeviceNumber,
917 PINQUIRYDATA InquiryData,
918 ULONG InquiryDataLength);
919
920 SCSIPORTAPI
921 NTSTATUS
922 NTAPI
923 ClassWmiCompleteRequest(
924 PDEVICE_OBJECT DeviceObject,
925 PIRP Irp,
926 NTSTATUS Status,
927 ULONG BufferUsed,
928 CCHAR PriorityBoost);
929
930 SCSIPORTAPI
931 NTSTATUS
932 NTAPI
933 ClassWmiFireEvent(
934 PDEVICE_OBJECT DeviceObject,
935 LPGUID Guid,
936 ULONG InstanceIndex,
937 ULONG EventDataSize,
938 PVOID EventData);
939
940 SCSIPORTAPI
941 VOID
942 NTAPI
943 ClassResetMediaChangeTimer(
944 PFUNCTIONAL_DEVICE_EXTENSION FdoExtension);
945
946 SCSIPORTAPI
947 VOID
948 NTAPI
949 ClassInitializeMediaChangeDetection(
950 PFUNCTIONAL_DEVICE_EXTENSION FdoExtension,
951 PUCHAR EventPrefix);
952
953 SCSIPORTAPI
954 NTSTATUS
955 NTAPI
956 ClassInitializeTestUnitPolling(
957 PFUNCTIONAL_DEVICE_EXTENSION FdoExtension,
958 BOOLEAN AllowDriveToSleep);
959
960 SCSIPORTAPI
961 PVPB
962 NTAPI
963 ClassGetVpb(
964 PDEVICE_OBJECT DeviceObject);
965
966 SCSIPORTAPI
967 NTSTATUS
968 NTAPI
969 ClassSpinDownPowerHandler(
970 PDEVICE_OBJECT DeviceObject,
971 PIRP Irp);
972
973 NTSTATUS
974 NTAPI
975 ClassStopUnitPowerHandler(
976 PDEVICE_OBJECT DeviceObject,
977 PIRP Irp);
978
979 NTSTATUS
980 NTAPI
981 ClassSetFailurePredictionPoll(
982 PFUNCTIONAL_DEVICE_EXTENSION FdoExtension,
983 FAILURE_PREDICTION_METHOD FailurePredictionMethod,
984 ULONG PollingPeriod);
985
986 VOID
987 NTAPI
988 ClassNotifyFailurePredicted(
989 PFUNCTIONAL_DEVICE_EXTENSION FdoExtension,
990 PUCHAR Buffer,
991 ULONG BufferSize,
992 BOOLEAN LogError,
993 ULONG UniqueErrorValue,
994 UCHAR PathId,
995 UCHAR TargetId,
996 UCHAR Lun);
997
998 SCSIPORTAPI
999 VOID
1000 NTAPI
1001 ClassAcquireChildLock(
1002 PFUNCTIONAL_DEVICE_EXTENSION FdoExtension);
1003
1004 SCSIPORTAPI
1005 VOID
1006 NTAPI
1007 ClassReleaseChildLock(
1008 PFUNCTIONAL_DEVICE_EXTENSION FdoExtension);
1009
1010 VOID
1011 NTAPI
1012 ClassSendStartUnit(
1013 PDEVICE_OBJECT DeviceObject);
1014
1015 SCSIPORTAPI
1016 NTSTATUS
1017 NTAPI
1018 ClassRemoveDevice(
1019 PDEVICE_OBJECT DeviceObject,
1020 UCHAR RemoveType);
1021
1022 SCSIPORTAPI
1023 VOID
1024 NTAPI
1025 ClassCheckMediaState(
1026 PFUNCTIONAL_DEVICE_EXTENSION FdoExtension);
1027
1028 SCSIPORTAPI
1029 VOID
1030 NTAPI
1031 ClassSetMediaChangeState(
1032 PFUNCTIONAL_DEVICE_EXTENSION FdoExtension,
1033 MEDIA_CHANGE_DETECTION_STATE State,
1034 BOOLEAN Wait);
1035
1036 SCSIPORTAPI
1037 VOID
1038 NTAPI
1039 ClassEnableMediaChangeDetection(
1040 PFUNCTIONAL_DEVICE_EXTENSION FdoExtension);
1041
1042 SCSIPORTAPI
1043 VOID
1044 NTAPI
1045 ClassDisableMediaChangeDetection(
1046 PFUNCTIONAL_DEVICE_EXTENSION FdoExtension);
1047
1048 SCSIPORTAPI
1049 VOID
1050 NTAPI
1051 ClassCleanupMediaChangeDetection(
1052 PFUNCTIONAL_DEVICE_EXTENSION FdoExtension);
1053
1054 VOID
1055 NTAPI
1056 ClassGetDeviceParameter(
1057 PFUNCTIONAL_DEVICE_EXTENSION FdoExtension,
1058 PWSTR SubkeyName,
1059 PWSTR ParameterName,
1060 PULONG ParameterValue);
1061
1062 NTSTATUS
1063 NTAPI
1064 ClassSetDeviceParameter(
1065 PFUNCTIONAL_DEVICE_EXTENSION FdoExtension,
1066 PWSTR SubkeyName,
1067 PWSTR ParameterName,
1068 ULONG ParameterValue);
1069
1070 #if (NTDDI_VERSION >= NTDDI_VISTA)
1071
1072 PFILE_OBJECT_EXTENSION
1073 NTAPI
1074 ClassGetFsContext(
1075 PCOMMON_DEVICE_EXTENSION CommonExtension,
1076 PFILE_OBJECT FileObject);
1077
1078 VOID
1079 NTAPI
1080 ClassSendNotification(
1081 PFUNCTIONAL_DEVICE_EXTENSION FdoExtension,
1082 const GUID *Guid,
1083 ULONG ExtraDataSize,
1084 PVOID ExtraData);
1085
1086 #endif /* (NTDDI_VERSION >= NTDDI_VISTA) */
1087
1088 static __inline
1089 BOOLEAN
1090 PORT_ALLOCATED_SENSE(
1091 PFUNCTIONAL_DEVICE_EXTENSION FdoExtension,
1092 PSCSI_REQUEST_BLOCK Srb)
1093 {
1094 return ((BOOLEAN)((TEST_FLAG(Srb->SrbFlags, SRB_FLAGS_PORT_DRIVER_ALLOCSENSE) &&
1095 TEST_FLAG(Srb->SrbFlags, SRB_FLAGS_FREE_SENSE_BUFFER)) &&
1096 (Srb->SenseInfoBuffer != FdoExtension->SenseData)));
1097 }
1098
1099 static __inline
1100 VOID
1101 FREE_PORT_ALLOCATED_SENSE_BUFFER(
1102 PFUNCTIONAL_DEVICE_EXTENSION FdoExtension,
1103 PSCSI_REQUEST_BLOCK Srb)
1104 {
1105 ASSERT(TEST_FLAG(Srb->SrbFlags, SRB_FLAGS_PORT_DRIVER_ALLOCSENSE));
1106 ASSERT(TEST_FLAG(Srb->SrbFlags, SRB_FLAGS_FREE_SENSE_BUFFER));
1107 ASSERT(Srb->SenseInfoBuffer != FdoExtension->SenseData);
1108
1109 ExFreePool(Srb->SenseInfoBuffer);
1110 Srb->SenseInfoBuffer = FdoExtension->SenseData;
1111 Srb->SenseInfoBufferLength = SENSE_BUFFER_SIZE;
1112 CLEAR_FLAG(Srb->SrbFlags, SRB_FLAGS_FREE_SENSE_BUFFER);
1113 return;
1114 }
1115
1116 typedef VOID
1117 (NTAPI *PCLASS_SCAN_FOR_SPECIAL_HANDLER)(
1118 PFUNCTIONAL_DEVICE_EXTENSION FdoExtension,
1119 ULONG_PTR Data);
1120
1121 VOID
1122 NTAPI
1123 ClassScanForSpecial(
1124 PFUNCTIONAL_DEVICE_EXTENSION FdoExtension,
1125 CLASSPNP_SCAN_FOR_SPECIAL_INFO DeviceList[],
1126 PCLASS_SCAN_FOR_SPECIAL_HANDLER Function);