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