[PSDK/DDK]: Last couple of fixes to headers. Classpnp can compile (and link) now.
[reactos.git] / reactos / include / ddk / classpnp.h
index a33cb84..368f390 100644 (file)
 
 #include <scsi.h>
 
-#define DEBUG_BUFFER_LENGTH               256
-
 #define SRB_CLASS_FLAGS_LOW_PRIORITY      0x10000000
 #define SRB_CLASS_FLAGS_PERSISTANT        0x20000000
 #define SRB_CLASS_FLAGS_PAGING            0x40000000
 #define SRB_CLASS_FLAGS_FREE_MDL          0x80000000
 
+#define ASSERT_FDO(x) \
+    ASSERT(((PCOMMON_DEVICE_EXTENSION) (x)->DeviceExtension)->IsFdo)
+
+#define ASSERT_PDO(x) \
+    ASSERT(!(((PCOMMON_DEVICE_EXTENSION) (x)->DeviceExtension)->IsFdo))
+
 #define IS_CLEANUP_REQUEST(majorFunction)   \
   ((majorFunction == IRP_MJ_CLOSE) ||       \
    (majorFunction == IRP_MJ_CLEANUP) ||     \
 
 #define IS_SCSIOP_READWRITE(opCode) (IS_SCSIOP_READ(opCode) || IS_SCSIOP_WRITE(opCode))
 
+#define ADJUST_FUA_FLAG(fdoExt) {                                                       \
+    if (TEST_FLAG(fdoExt->DeviceFlags, DEV_WRITE_CACHE) &&                              \
+        !TEST_FLAG(fdoExt->DeviceFlags, DEV_POWER_PROTECTED) &&                         \
+        !TEST_FLAG(fdoExt->ScanForSpecialFlags, CLASS_SPECIAL_FUA_NOT_SUPPORTED) ) {    \
+        fdoExt->CdbForceUnitAccess = TRUE;                                              \
+    } else {                                                                            \
+        fdoExt->CdbForceUnitAccess = FALSE;                                             \
+    }                                                                                   \
+}
+
+#define FREE_POOL(_PoolPtr)     \
+    if (_PoolPtr != NULL) {     \
+        ExFreePool(_PoolPtr);   \
+        _PoolPtr = NULL;        \
+    }
+
+#ifdef POOL_TAGGING
+#undef ExAllocatePool
+#undef ExAllocatePoolWithQuota
+#define ExAllocatePool(a,b) ExAllocatePoolWithTag(a,b,'nUcS')
+//#define ExAllocatePool(a,b) #assert(0)
+#define ExAllocatePoolWithQuota(a,b) ExAllocatePoolWithQuotaTag(a,b,'nUcS')
+#endif
+
+#define CLASS_TAG_AUTORUN_DISABLE           'ALcS'
+#define CLASS_TAG_FILE_OBJECT_EXTENSION     'FLcS'
+#define CLASS_TAG_MEDIA_CHANGE_DETECTION    'MLcS'
+#define CLASS_TAG_MOUNT                     'mLcS'
+#define CLASS_TAG_RELEASE_QUEUE             'qLcS'
+#define CLASS_TAG_POWER                     'WLcS'
+#define CLASS_TAG_WMI                       'wLcS'
+#define CLASS_TAG_FAILURE_PREDICT           'fLcS'
+#define CLASS_TAG_DEVICE_CONTROL            'OIcS'
+#define CLASS_TAG_MODE_DATA                 'oLcS'
+#define CLASS_TAG_MULTIPATH                 'mPcS'
+
 #define MAXIMUM_RETRIES 4
 
 #define CLASS_DRIVER_EXTENSION_KEY ((PVOID) ClassInitialize)
 #define ClassAcquireRemoveLock(devobj, tag) \
   ClassAcquireRemoveLockEx(devobj, tag, __FILE__, __LINE__)
 
+#ifdef TRY
+#undef TRY
+#endif
+#ifdef LEAVE
+#undef LEAVE
+#endif
+
+#ifdef FINALLY
+#undef FINALLY
+#endif
+
+#define TRY
+#define LEAVE             goto __tryLabel;
+#define FINALLY           __tryLabel:
+
+#if defined DebugPrint
+#undef DebugPrint
+#endif
+
+#if DBG
+#define DebugPrint(x) ClassDebugPrint x
+#else
+#define DebugPrint(x)
+#endif
+
+#define DEBUG_BUFFER_LENGTH               256
+
 #define START_UNIT_TIMEOUT                  (60 * 4)
 
 #define MEDIA_CHANGE_DEFAULT_TIME          1
 
 #endif /* ALLOCATE_SRB_FROM_POOL */
 
+#define SET_FLAG(Flags, Bit)    ((Flags) |= (Bit))
+#define CLEAR_FLAG(Flags, Bit)  ((Flags) &= ~(Bit))
+#define TEST_FLAG(Flags, Bit)   (((Flags) & (Bit)) != 0)
+
 #define CLASS_WORKING_SET_MAXIMUM                         2048
 
 #define CLASS_INTERPRET_SENSE_INFO2_MAXIMUM_HISTORY_COUNT 30000
 
 #define DEFAULT_FAILURE_PREDICTION_PERIOD 60 * 60 * 1
 
+static inline ULONG CountOfSetBitsUChar(UCHAR _X)
+{ ULONG i = 0; while (_X) { _X &= _X - 1; i++; } return i; }
+static inline ULONG CountOfSetBitsULong(ULONG _X)
+{ ULONG i = 0; while (_X) { _X &= _X - 1; i++; } return i; }
+static inline ULONG CountOfSetBitsULong32(ULONG32 _X)
+{ ULONG i = 0; while (_X) { _X &= _X - 1; i++; } return i; }
+static inline ULONG CountOfSetBitsULong64(ULONG64 _X)
+{ ULONG i = 0; while (_X) { _X &= _X - 1; i++; } return i; }
+static inline ULONG CountOfSetBitsUlongPtr(ULONG_PTR _X)
+{ ULONG i = 0; while (_X) { _X &= _X - 1; i++; } return i; }
+
 typedef enum _MEDIA_CHANGE_DETECTION_STATE {
   MediaUnknown,
   MediaPresent,
@@ -188,12 +270,9 @@ typedef struct _CLASS_PRIVATE_COMMON_DATA CLASS_PRIVATE_COMMON_DATA, *PCLASS_PRI
 struct _MEDIA_CHANGE_DETECTION_INFO;
 typedef struct _MEDIA_CHANGE_DETECTION_INFO MEDIA_CHANGE_DETECTION_INFO, *PMEDIA_CHANGE_DETECTION_INFO;
 
-struct _DICTIONARY_HEADER;
-typedef struct _DICTIONARY_HEADER DICTIONARY_HEADER, *PDICTIONARY_HEADER;
-
 typedef struct _DICTIONARY {
   ULONGLONG Signature;
-  PDICTIONARY_HEADER List;
+  struct _DICTIONARY_HEADER* List;
   KSPIN_LOCK SpinLock;
 } DICTIONARY, *PDICTIONARY;
 
@@ -529,9 +608,6 @@ typedef struct _PHYSICAL_DEVICE_EXTENSION {
   ULONG_PTR Reserved4;
 } PHYSICAL_DEVICE_EXTENSION, *PPHYSICAL_DEVICE_EXTENSION;
 
-struct _FAILURE_PREDICTION_INFO;
-typedef struct _FAILURE_PREDICTION_INFO *PFAILURE_PREDICTION_INFO;
-
 typedef struct _CLASS_POWER_OPTIONS {
   ULONG PowerDown:1;
   ULONG LockQueue:1;
@@ -577,6 +653,88 @@ typedef struct _CLASS_QUERY_WMI_REGINFO_EX_LIST {
   PCLASS_QUERY_WMI_REGINFO_EX ClassPdoQueryWmiRegInfoEx;
 } CLASS_QUERY_WMI_REGINFO_EX_LIST, *PCLASS_QUERY_WMI_REGINFO_EX_LIST;
 
+typedef struct _FUNCTIONAL_DEVICE_EXTENSION {
+  _ANONYMOUS_UNION union {
+    _ANONYMOUS_STRUCT struct {
+      ULONG Version;
+      PDEVICE_OBJECT DeviceObject;
+    } DUMMYSTRUCTNAME;
+    COMMON_DEVICE_EXTENSION CommonExtension;
+  } DUMMYUNIONNAME;
+  PDEVICE_OBJECT LowerPdo;
+  PSTORAGE_DEVICE_DESCRIPTOR DeviceDescriptor;
+  PSTORAGE_ADAPTER_DESCRIPTOR AdapterDescriptor;
+  DEVICE_POWER_STATE DevicePowerState;
+  ULONG DMByteSkew;
+  ULONG DMSkew;
+  BOOLEAN DMActive;
+  DISK_GEOMETRY DiskGeometry;
+  PSENSE_DATA SenseData;
+  ULONG TimeOutValue;
+  ULONG DeviceNumber;
+  ULONG SrbFlags;
+  ULONG ErrorCount;
+  LONG LockCount;
+  LONG ProtectedLockCount;
+  LONG InternalLockCount;
+  KEVENT EjectSynchronizationEvent;
+  USHORT DeviceFlags;
+  UCHAR SectorShift;
+#if (NTDDI_VERSION >= NTDDI_VISTA)
+  UCHAR CdbForceUnitAccess;
+#else
+  UCHAR ReservedByte;
+#endif
+  PMEDIA_CHANGE_DETECTION_INFO MediaChangeDetectionInfo;
+  PKEVENT Unused1;
+  HANDLE Unused2;
+  FILE_OBJECT_EXTENSION KernelModeMcnContext;
+  ULONG MediaChangeCount;
+  HANDLE DeviceDirectory;
+  KSPIN_LOCK ReleaseQueueSpinLock;
+  PIRP ReleaseQueueIrp;
+  SCSI_REQUEST_BLOCK ReleaseQueueSrb;
+  BOOLEAN ReleaseQueueNeeded;
+  BOOLEAN ReleaseQueueInProgress;
+  BOOLEAN ReleaseQueueIrpFromPool;
+  BOOLEAN FailurePredicted;
+  ULONG FailureReason;
+  struct _FAILURE_PREDICTION_INFO* FailurePredictionInfo;
+  BOOLEAN PowerDownInProgress;
+  ULONG EnumerationInterlock;
+  KEVENT ChildLock;
+  PKTHREAD ChildLockOwner;
+  ULONG ChildLockAcquisitionCount;
+  ULONG ScanForSpecialFlags;
+  KDPC PowerRetryDpc;
+  KTIMER PowerRetryTimer;
+  CLASS_POWER_CONTEXT PowerContext;
+
+#if (NTDDI_VERSION <= NTDDI_WIN2K)
+
+#if (SPVER(NTDDI_VERSION) < 2))
+  ULONG_PTR Reserved1;
+  ULONG_PTR Reserved2;
+  ULONG_PTR Reserved3;
+  ULONG_PTR Reserved4;
+#else
+  ULONG CompletionSuccessCount;
+  ULONG SavedSrbFlags;
+  ULONG SavedErrorCount;
+  ULONG_PTR Reserved1;
+#endif
+
+#else /* (NTDDI_VERSION <= NTDDI_WIN2K) */
+
+  PCLASS_PRIVATE_FDO_DATA PrivateFdoData;
+  ULONG_PTR Reserved2;
+  ULONG_PTR Reserved3;
+  ULONG_PTR Reserved4;
+
+#endif /* (NTDDI_VERSION <= NTDDI_WIN2K) */
+
+} FUNCTIONAL_DEVICE_EXTENSION, *PFUNCTIONAL_DEVICE_EXTENSION;
+
 SCSIPORTAPI
 ULONG
 NTAPI
@@ -622,6 +780,22 @@ ClassDeviceControl(
   PDEVICE_OBJECT DeviceObject,
   PIRP Irp);
 
+SCSIPORTAPI
+NTSTATUS
+NTAPI
+ClassIoComplete(
+  PDEVICE_OBJECT DeviceObject,
+  PIRP Irp,
+  PVOID Context);
+
+SCSIPORTAPI
+NTSTATUS
+NTAPI
+ClassIoCompleteAssociated(
+  PDEVICE_OBJECT DeviceObject,
+  PIRP Irp,
+  PVOID Context);
+
 SCSIPORTAPI
 BOOLEAN
 NTAPI
@@ -711,6 +885,13 @@ NTAPI
 ClassClaimDevice(
   PDEVICE_OBJECT LowerDeviceObject,
   BOOLEAN Release);
+  
+SCSIPORTAPI
+NTSTATUS
+NTAPI
+ClassInternalIoControl (
+  PDEVICE_OBJECT DeviceObject,
+  PIRP Irp);
 
 SCSIPORTAPI
 VOID
@@ -737,7 +918,7 @@ NTAPI
 ClassGetDescriptor(
   PDEVICE_OBJECT DeviceObject,
   PSTORAGE_PROPERTY_ID PropertyId,
-  PVOID *Descriptor);
+  PSTORAGE_DESCRIPTOR_HEADER *Descriptor);
 
 SCSIPORTAPI
 VOID
@@ -896,6 +1077,13 @@ NTAPI
 ClassReleaseChildLock(
   PFUNCTIONAL_DEVICE_EXTENSION FdoExtension);
 
+NTSTATUS
+NTAPI
+ClassSignalCompletion(
+  PDEVICE_OBJECT DeviceObject,
+  PIRP Irp,
+  PKEVENT Event);
+
 VOID
 NTAPI
 ClassSendStartUnit(
@@ -908,12 +1096,28 @@ ClassRemoveDevice(
   PDEVICE_OBJECT DeviceObject,
   UCHAR RemoveType);
 
+SCSIPORTAPI
+NTSTATUS
+NTAPI
+ClassAsynchronousCompletion(
+  PDEVICE_OBJECT DeviceObject,
+  PIRP Irp,
+  PVOID Event);
+
 SCSIPORTAPI
 VOID
 NTAPI
 ClassCheckMediaState(
   PFUNCTIONAL_DEVICE_EXTENSION FdoExtension);
 
+SCSIPORTAPI
+NTSTATUS
+NTAPI
+ClassCheckVerifyComplete(
+  PDEVICE_OBJECT DeviceObject,
+  PIRP Irp,
+  PVOID Context);
+
 SCSIPORTAPI
 VOID
 NTAPI