ReactOS  0.4.15-dev-1184-g23e04ae
disk.h File Reference
#include "ntddk.h"
#include "scsi.h"
#include <wmidata.h>
#include "classpnp.h"
#include <wmistr.h>
#include "ntstrsafe.h"
#include <storswtr.h>
Include dependency graph for disk.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _DISK_GROUP_CONTEXT
 
struct  _DISK_DATA
 
struct  _DISK_MEDIA_TYPES_LIST
 
struct  DISKREREGREQUEST
 
struct  _DISK_VERIFY_WORKITEM_CONTEXT
 

Macros

#define DEBUG_COMP_ID   DPFLTR_DISK_ID
 
#define WPP_GUID_DISK   (945186BF, 3DD6, 4f3f, 9C8E, 9EDD3FC9D558)
 
#define WPP_CONTROL_GUIDS   WPP_CONTROL_GUIDS_NORMAL_FLAGS(WPP_GUID_DISK)
 
#define DISK_TAG_GENERAL   ' DcS'
 
#define DISK_TAG_SMART   'aDcS'
 
#define DISK_TAG_INFO_EXCEPTION   'ADcS'
 
#define DISK_TAG_DISABLE_CACHE   'CDcS'
 
#define DISK_TAG_CCONTEXT   'cDcS'
 
#define DISK_TAG_DISK_GEOM   'GDcS'
 
#define DISK_TAG_UPDATE_GEOM   'gDcS'
 
#define DISK_TAG_SENSE_INFO   'IDcS'
 
#define DISK_TAG_PNP_ID   'iDcS'
 
#define DISK_TAG_MODE_DATA   'MDcS'
 
#define DISK_CACHE_MBR_CHECK   'mDcS'
 
#define DISK_TAG_NAME   'NDcS'
 
#define DISK_TAG_READ_CAP   'PDcS'
 
#define DISK_TAG_PART_LIST   'pDcS'
 
#define DISK_TAG_SRB   'SDcS'
 
#define DISK_TAG_START   'sDcS'
 
#define DISK_TAG_UPDATE_CAP   'UDcS'
 
#define DISK_TAG_WI_CONTEXT   'WDcS'
 
#define HackDisableTaggedQueuing   (0x01)
 
#define HackDisableSynchronousTransfers   (0x02)
 
#define HackDisableSpinDown   (0x04)
 
#define HackDisableWriteCache   (0x08)
 
#define HackCauseNotReportableHack   (0x10)
 
#define HackRequiresStartUnitCommand   (0x20)
 
#define DiskDeviceParameterSubkey   L"Disk"
 
#define DiskDeviceUserWriteCacheSetting   L"UserWriteCacheSetting"
 
#define DiskDeviceCacheIsPowerProtected   L"CacheIsPowerProtected"
 
#define FUNCTIONAL_EXTENSION_SIZE   sizeof(FUNCTIONAL_DEVICE_EXTENSION) + sizeof(DISK_DATA)
 
#define MODE_DATA_SIZE   192
 
#define VALUE_BUFFER_SIZE   2048
 
#define SCSI_DISK_TIMEOUT   10
 
#define PARTITION0_LIST_SIZE   4
 
#define MAX_MEDIA_TYPES   4
 
#define MAX_SECTORS_PER_VERIFY   0x100
 
#define ONE_MILLI_SECOND   ((ULONGLONG)10 * 1000)
 
#define DISK_DEFAULT_FAILURE_POLLING_PERIOD   1 * 60 * 60
 
#define CHECK_IRQL()
 
#define DiskIsValidSmartSelfTest(Subcommand)
 
#define DiskReadDriveCapacity(Fdo)   ClassReadDriveCapacity(Fdo)
 
#define DiskGetDetectInfo(FdoExtension, DetectInfo)   (STATUS_UNSUCCESSFUL)
 
#define DiskHashGuid(Guid)   (((PULONG) &Guid)[0] ^ ((PULONG) &Guid)[0] ^ ((PULONG) &Guid)[0] ^ ((PULONG) &Guid)[0])
 

Typedefs

typedef struct _DISK_GROUP_CONTEXT DISK_GROUP_CONTEXT
 
typedef struct _DISK_GROUP_CONTEXTPDISK_GROUP_CONTEXT
 
typedef enum _DISK_USER_WRITE_CACHE_SETTING DISK_USER_WRITE_CACHE_SETTING
 
typedef enum _DISK_USER_WRITE_CACHE_SETTINGPDISK_USER_WRITE_CACHE_SETTING
 
typedef struct _DISK_DATA DISK_DATA
 
typedef struct _DISK_DATAPDISK_DATA
 
typedef struct _DISK_MEDIA_TYPES_LIST DISK_MEDIA_TYPES_LIST
 
typedef struct _DISK_MEDIA_TYPES_LISTPDISK_MEDIA_TYPES_LIST
 
typedef struct DISKREREGREQUESTPDISKREREGREQUEST
 
typedef struct _DISK_VERIFY_WORKITEM_CONTEXT DISK_VERIFY_WORKITEM_CONTEXT
 
typedef struct _DISK_VERIFY_WORKITEM_CONTEXTPDISK_VERIFY_WORKITEM_CONTEXT
 

Enumerations

enum  _DISK_USER_WRITE_CACHE_SETTING { DiskWriteCacheDisable = 0, DiskWriteCacheEnable = 1, DiskWriteCacheDefault = -1 }
 

Functions

VOID NTAPI DiskUnload (IN PDRIVER_OBJECT DriverObject)
 
NTSTATUS NTAPI DiskAddDevice (IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT Pdo)
 
NTSTATUS NTAPI DiskInitFdo (IN PDEVICE_OBJECT Fdo)
 
NTSTATUS NTAPI DiskStartFdo (IN PDEVICE_OBJECT Fdo)
 
NTSTATUS NTAPI DiskStopDevice (IN PDEVICE_OBJECT DeviceObject, IN UCHAR Type)
 
NTSTATUS NTAPI DiskRemoveDevice (IN PDEVICE_OBJECT DeviceObject, IN UCHAR Type)
 
NTSTATUS NTAPI DiskReadWriteVerification (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI DiskDeviceControl (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
VOID NTAPI DiskFdoProcessError (PDEVICE_OBJECT DeviceObject, PSCSI_REQUEST_BLOCK Srb, NTSTATUS *Status, BOOLEAN *Retry)
 
NTSTATUS NTAPI DiskShutdownFlush (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI DiskGetCacheInformation (IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, IN PDISK_CACHE_INFORMATION CacheInfo)
 
NTSTATUS NTAPI DiskSetCacheInformation (IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, IN PDISK_CACHE_INFORMATION CacheInfo)
 
VOID DiskLogCacheInformation (IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, IN PDISK_CACHE_INFORMATION CacheInfo, IN NTSTATUS Status)
 
NTSTATUS DiskIoctlGetCacheSetting (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS DiskIoctlSetCacheSetting (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
VOID DiskFlushDispatch (IN PDEVICE_OBJECT Fdo, IN PDISK_GROUP_CONTEXT FlushContext)
 
NTSTATUS DiskModeSelect (IN PDEVICE_OBJECT DeviceObject, _In_reads_bytes_(Length) PCHAR ModeSelectBuffer, IN ULONG Length, IN BOOLEAN SavePage)
 
NTSTATUS DiskPerformSmartCommand (IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, IN ULONG SrbControlCode, IN UCHAR Command, IN UCHAR Feature, IN UCHAR SectorCount, IN UCHAR SectorNumber, IN OUT PSRB_IO_CONTROL SrbControl, OUT PULONG BufferSize)
 
NTSTATUS DiskGetInfoExceptionInformation (IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, OUT PMODE_INFO_EXCEPTIONS ReturnPageData)
 
NTSTATUS DiskSetInfoExceptionInformation (IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, IN PMODE_INFO_EXCEPTIONS PageData)
 
NTSTATUS DiskGetModePage (_In_ PDEVICE_OBJECT Fdo, _In_ UCHAR PageMode, _In_ UCHAR PageControl, _In_ PMODE_PARAMETER_HEADER ModeData, _Inout_ PULONG ModeDataSize, _Out_ PVOID *PageData)
 
NTSTATUS DiskEnableInfoExceptions (_In_ PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, _In_ BOOLEAN Enable)
 
NTSTATUS DiskDetectFailurePrediction (PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, PFAILURE_PREDICTION_METHOD FailurePredictCapability, BOOLEAN ScsiAddressAvailable)
 
NTSTATUS DiskCreateFdo (IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT LowerDeviceObject, IN PULONG DeviceCount, IN BOOLEAN DasdAccessOnly)
 
VOID NTAPI DiskSetSpecialHacks (IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, IN ULONG_PTR Data)
 
VOID ResetBus (IN PDEVICE_OBJECT DeviceObject)
 
NTSTATUS DiskGenerateDeviceName (IN ULONG DeviceNumber, OUT PCCHAR *RawName)
 
VOID DiskCreateSymbolicLinks (IN PDEVICE_OBJECT DeviceObject)
 
VOID DiskDeleteSymbolicLinks (IN PDEVICE_OBJECT DeviceObject)
 
NTSTATUS NTAPI DiskFdoQueryWmiRegInfo (IN PDEVICE_OBJECT DeviceObject, OUT ULONG *RegFlags, OUT PUNICODE_STRING InstanceName)
 
NTSTATUS NTAPI DiskFdoQueryWmiRegInfoEx (IN PDEVICE_OBJECT DeviceObject, OUT ULONG *RegFlags, OUT PUNICODE_STRING InstanceName, OUT PUNICODE_STRING MofName)
 
NTSTATUS NTAPI DiskFdoQueryWmiDataBlock (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN ULONG GuidIndex, IN ULONG BufferAvail, OUT PUCHAR Buffer)
 
NTSTATUS NTAPI DiskFdoSetWmiDataBlock (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN ULONG GuidIndex, IN ULONG BufferSize, IN PUCHAR Buffer)
 
NTSTATUS NTAPI DiskFdoSetWmiDataItem (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN ULONG GuidIndex, IN ULONG DataItemId, IN ULONG BufferSize, IN PUCHAR Buffer)
 
NTSTATUS NTAPI DiskFdoExecuteWmiMethod (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN ULONG GuidIndex, IN ULONG MethodId, IN ULONG InBufferSize, IN ULONG OutBufferSize, IN PUCHAR Buffer)
 
NTSTATUS NTAPI DiskWmiFunctionControl (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN ULONG GuidIndex, IN CLASSENABLEDISABLEFUNCTION Function, IN BOOLEAN Enable)
 
NTSTATUS DiskReadFailurePredictStatus (PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, PSTORAGE_FAILURE_PREDICT_STATUS DiskSmartStatus)
 
NTSTATUS DiskReadFailurePredictData (PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, PSTORAGE_FAILURE_PREDICT_DATA DiskSmartData)
 
NTSTATUS DiskEnableDisableFailurePrediction (PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, BOOLEAN Enable)
 
NTSTATUS DiskEnableDisableFailurePredictPolling (PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, BOOLEAN Enable, ULONG PollTimeInSeconds)
 
NTSTATUS DiskInitializeReregistration (VOID)
 
NTSTATUS DiskDetermineMediaTypes (IN PDEVICE_OBJECT Fdo, IN PIRP Irp, IN UCHAR MediumType, IN UCHAR DensityCode, IN BOOLEAN MediaPresent, IN BOOLEAN IsWritable)
 
NTSTATUS DiskIoctlGetLengthInfo (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS DiskIoctlGetDriveGeometry (IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
 
NTSTATUS DiskIoctlGetDriveGeometryEx (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS DiskIoctlGetCacheInformation (IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
 
NTSTATUS DiskIoctlSetCacheInformation (IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
 
NTSTATUS DiskIoctlGetMediaTypesEx (IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
 
NTSTATUS DiskIoctlPredictFailure (IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
 
NTSTATUS DiskIoctlEnableFailurePrediction (IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
 
NTSTATUS DiskIoctlVerify (IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
 
NTSTATUS DiskIoctlReassignBlocks (IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
 
NTSTATUS DiskIoctlReassignBlocksEx (IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
 
NTSTATUS DiskIoctlIsWritable (IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
 
NTSTATUS DiskIoctlSetVerify (IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
 
NTSTATUS DiskIoctlClearVerify (IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
 
NTSTATUS DiskIoctlUpdateDriveSize (IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
 
NTSTATUS DiskIoctlGetVolumeDiskExtents (IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
 
NTSTATUS DiskIoctlSmartGetVersion (IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
 
NTSTATUS DiskIoctlSmartReceiveDriveData (IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
 
NTSTATUS DiskIoctlSmartSendDriveCommand (IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
 
__inline PCDB GetSrbScsiData (_In_ PSTORAGE_REQUEST_BLOCK SrbEx, _In_opt_ PUCHAR CdbLength8, _In_opt_ PULONG CdbLength32, _In_opt_ PUCHAR ScsiStatus, _In_opt_ PVOID *SenseInfoBuffer, _In_opt_ PUCHAR SenseInfoBufferLength)
 
__inline VOID SetSrbScsiData (_In_ PSTORAGE_REQUEST_BLOCK SrbEx, _In_ UCHAR CdbLength8, _In_ ULONG CdbLength32, _In_ UCHAR ScsiStatus, _In_opt_ PVOID SenseInfoBuffer, _In_ UCHAR SenseInfoBufferLength)
 

Variables

CLASSPNP_SCAN_FOR_SPECIAL_INFO DiskBadControllers []
 
const DISK_MEDIA_TYPES_LIST DiskMediaTypes []
 
const DISK_MEDIA_TYPES_LIST DiskMediaTypesExclude []
 
DRIVER_INITIALIZE DriverEntry
 
IO_WORKITEM_ROUTINE DisableWriteCache
 
IO_WORKITEM_ROUTINE DiskIoctlVerifyThread
 
IO_COMPLETION_ROUTINE DiskFlushComplete
 
GUIDREGINFO DiskWmiFdoGuidList []
 

Macro Definition Documentation

◆ CHECK_IRQL

#define CHECK_IRQL ( )
Value:
NT_ASSERT(KeGetCurrentIrql() < DISPATCH_LEVEL); \
}
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
#define STATUS_INVALID_LEVEL
Definition: ntstatus.h:564
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696

Definition at line 458 of file disk.h.

◆ DEBUG_COMP_ID

#define DEBUG_COMP_ID   DPFLTR_DISK_ID

Definition at line 35 of file disk.h.

◆ DISK_CACHE_MBR_CHECK

#define DISK_CACHE_MBR_CHECK   'mDcS'

Definition at line 63 of file disk.h.

◆ DISK_DEFAULT_FAILURE_POLLING_PERIOD

#define DISK_DEFAULT_FAILURE_POLLING_PERIOD   1 * 60 * 60

Definition at line 456 of file disk.h.

◆ DISK_TAG_CCONTEXT

#define DISK_TAG_CCONTEXT   'cDcS'

Definition at line 57 of file disk.h.

◆ DISK_TAG_DISABLE_CACHE

#define DISK_TAG_DISABLE_CACHE   'CDcS'

Definition at line 56 of file disk.h.

◆ DISK_TAG_DISK_GEOM

#define DISK_TAG_DISK_GEOM   'GDcS'

Definition at line 58 of file disk.h.

◆ DISK_TAG_GENERAL

#define DISK_TAG_GENERAL   ' DcS'

Definition at line 53 of file disk.h.

◆ DISK_TAG_INFO_EXCEPTION

#define DISK_TAG_INFO_EXCEPTION   'ADcS'

Definition at line 55 of file disk.h.

◆ DISK_TAG_MODE_DATA

#define DISK_TAG_MODE_DATA   'MDcS'

Definition at line 62 of file disk.h.

◆ DISK_TAG_NAME

#define DISK_TAG_NAME   'NDcS'

Definition at line 64 of file disk.h.

◆ DISK_TAG_PART_LIST

#define DISK_TAG_PART_LIST   'pDcS'

Definition at line 66 of file disk.h.

◆ DISK_TAG_PNP_ID

#define DISK_TAG_PNP_ID   'iDcS'

Definition at line 61 of file disk.h.

◆ DISK_TAG_READ_CAP

#define DISK_TAG_READ_CAP   'PDcS'

Definition at line 65 of file disk.h.

◆ DISK_TAG_SENSE_INFO

#define DISK_TAG_SENSE_INFO   'IDcS'

Definition at line 60 of file disk.h.

◆ DISK_TAG_SMART

#define DISK_TAG_SMART   'aDcS'

Definition at line 54 of file disk.h.

◆ DISK_TAG_SRB

#define DISK_TAG_SRB   'SDcS'

Definition at line 67 of file disk.h.

◆ DISK_TAG_START

#define DISK_TAG_START   'sDcS'

Definition at line 68 of file disk.h.

◆ DISK_TAG_UPDATE_CAP

#define DISK_TAG_UPDATE_CAP   'UDcS'

Definition at line 69 of file disk.h.

◆ DISK_TAG_UPDATE_GEOM

#define DISK_TAG_UPDATE_GEOM   'gDcS'

Definition at line 59 of file disk.h.

◆ DISK_TAG_WI_CONTEXT

#define DISK_TAG_WI_CONTEXT   'WDcS'

Definition at line 70 of file disk.h.

◆ DiskDeviceCacheIsPowerProtected

#define DiskDeviceCacheIsPowerProtected   L"CacheIsPowerProtected"

Definition at line 405 of file disk.h.

◆ DiskDeviceParameterSubkey

#define DiskDeviceParameterSubkey   L"Disk"

Definition at line 403 of file disk.h.

◆ DiskDeviceUserWriteCacheSetting

#define DiskDeviceUserWriteCacheSetting   L"UserWriteCacheSetting"

Definition at line 404 of file disk.h.

◆ DiskGetDetectInfo

#define DiskGetDetectInfo (   FdoExtension,
  DetectInfo 
)    (STATUS_UNSUCCESSFUL)

Definition at line 857 of file disk.h.

◆ DiskHashGuid

#define DiskHashGuid (   Guid)    (((PULONG) &Guid)[0] ^ ((PULONG) &Guid)[0] ^ ((PULONG) &Guid)[0] ^ ((PULONG) &Guid)[0])

Definition at line 861 of file disk.h.

◆ DiskIsValidSmartSelfTest

#define DiskIsValidSmartSelfTest (   Subcommand)
Value:
( ((Subcommand) == SMART_OFFLINE_ROUTINE_OFFLINE) || \
((Subcommand) == SMART_SHORT_SELFTEST_OFFLINE) || \
((Subcommand) == SMART_EXTENDED_SELFTEST_OFFLINE) )
#define SMART_SHORT_SELFTEST_OFFLINE
Definition: ntdddisk.h:689
#define SMART_EXTENDED_SELFTEST_OFFLINE
Definition: ntdddisk.h:690
#define SMART_OFFLINE_ROUTINE_OFFLINE
Definition: ntdddisk.h:688

Definition at line 615 of file disk.h.

◆ DiskReadDriveCapacity

#define DiskReadDriveCapacity (   Fdo)    ClassReadDriveCapacity(Fdo)

Definition at line 814 of file disk.h.

◆ FUNCTIONAL_EXTENSION_SIZE

#define FUNCTIONAL_EXTENSION_SIZE   sizeof(FUNCTIONAL_DEVICE_EXTENSION) + sizeof(DISK_DATA)

Definition at line 408 of file disk.h.

◆ HackCauseNotReportableHack

#define HackCauseNotReportableHack   (0x10)

Definition at line 399 of file disk.h.

◆ HackDisableSpinDown

#define HackDisableSpinDown   (0x04)

Definition at line 397 of file disk.h.

◆ HackDisableSynchronousTransfers

#define HackDisableSynchronousTransfers   (0x02)

Definition at line 396 of file disk.h.

◆ HackDisableTaggedQueuing

#define HackDisableTaggedQueuing   (0x01)

Definition at line 395 of file disk.h.

◆ HackDisableWriteCache

#define HackDisableWriteCache   (0x08)

Definition at line 398 of file disk.h.

◆ HackRequiresStartUnitCommand

#define HackRequiresStartUnitCommand   (0x20)

Definition at line 400 of file disk.h.

◆ MAX_MEDIA_TYPES

#define MAX_MEDIA_TYPES   4

Definition at line 415 of file disk.h.

◆ MAX_SECTORS_PER_VERIFY

#define MAX_SECTORS_PER_VERIFY   0x100

Definition at line 435 of file disk.h.

◆ MODE_DATA_SIZE

#define MODE_DATA_SIZE   192

Definition at line 410 of file disk.h.

◆ ONE_MILLI_SECOND

#define ONE_MILLI_SECOND   ((ULONGLONG)10 * 1000)

Definition at line 440 of file disk.h.

◆ PARTITION0_LIST_SIZE

#define PARTITION0_LIST_SIZE   4

Definition at line 413 of file disk.h.

◆ SCSI_DISK_TIMEOUT

#define SCSI_DISK_TIMEOUT   10

Definition at line 412 of file disk.h.

◆ VALUE_BUFFER_SIZE

#define VALUE_BUFFER_SIZE   2048

Definition at line 411 of file disk.h.

◆ WPP_CONTROL_GUIDS

Definition at line 44 of file disk.h.

◆ WPP_GUID_DISK

#define WPP_GUID_DISK   (945186BF, 3DD6, 4f3f, 9C8E, 9EDD3FC9D558)

Definition at line 42 of file disk.h.

Typedef Documentation

◆ DISK_DATA

◆ DISK_GROUP_CONTEXT

◆ DISK_MEDIA_TYPES_LIST

◆ DISK_USER_WRITE_CACHE_SETTING

◆ DISK_VERIFY_WORKITEM_CONTEXT

◆ PDISK_DATA

◆ PDISK_GROUP_CONTEXT

◆ PDISK_MEDIA_TYPES_LIST

◆ PDISK_USER_WRITE_CACHE_SETTING

◆ PDISK_VERIFY_WORKITEM_CONTEXT

◆ PDISKREREGREQUEST

Enumeration Type Documentation

◆ _DISK_USER_WRITE_CACHE_SETTING

Enumerator
DiskWriteCacheDisable 
DiskWriteCacheEnable 
DiskWriteCacheDefault 

Definition at line 177 of file disk.h.

178 {
182 
enum _DISK_USER_WRITE_CACHE_SETTING * PDISK_USER_WRITE_CACHE_SETTING
enum _DISK_USER_WRITE_CACHE_SETTING DISK_USER_WRITE_CACHE_SETTING

Function Documentation

◆ DiskAddDevice()

NTSTATUS NTAPI DiskAddDevice ( IN PDRIVER_OBJECT  DriverObject,
IN PDEVICE_OBJECT  Pdo 
)

Definition at line 53 of file pnp.c.

78 {
79  ULONG rootPartitionMountable = FALSE;
80 
81  PCONFIGURATION_INFORMATION configurationInformation;
82  ULONG diskCount;
83 
85 
86  PAGED_CODE();
87 
88  //
89  // See if we should be allowing file systems to mount on partition zero.
90  //
91 
92  TRY {
93  HANDLE deviceKey = NULL;
94 
95  UNICODE_STRING diskKeyName;
96  OBJECT_ATTRIBUTES objectAttributes = {0};
97  HANDLE diskKey;
98 
99  RTL_QUERY_REGISTRY_TABLE queryTable[2] = { 0 };
100 
103  KEY_READ,
104  &deviceKey);
105 
106  if(!NT_SUCCESS(status)) {
107  TracePrint((TRACE_LEVEL_ERROR, TRACE_FLAG_PNP, "DiskAddDevice: Error %#08lx opening device key "
108  "for pdo %p\n",
110  LEAVE;
111  }
112 
113  RtlInitUnicodeString(&diskKeyName, L"Disk");
114  InitializeObjectAttributes(&objectAttributes,
115  &diskKeyName,
117  deviceKey,
118  NULL);
119 
120  status = ZwOpenKey(&diskKey, KEY_READ, &objectAttributes);
121  ZwClose(deviceKey);
122 
123  if(!NT_SUCCESS(status)) {
124  TracePrint((TRACE_LEVEL_ERROR, TRACE_FLAG_PNP, "DiskAddDevice: Error %#08lx opening disk key "
125  "for pdo %p device key %p\n",
126  status, PhysicalDeviceObject, deviceKey));
127  LEAVE;
128  }
129 
131  queryTable[0].Name = L"RootPartitionMountable";
132  queryTable[0].EntryContext = &(rootPartitionMountable);
134 
135 #pragma prefast(suppress:6309, "We don't have QueryRoutine so Context doesn't make any sense")
137  diskKey,
138  queryTable,
139  NULL,
140  NULL);
141 
142  if(!NT_SUCCESS(status)) {
143  TracePrint((TRACE_LEVEL_ERROR, TRACE_FLAG_PNP, "DiskAddDevice: Error %#08lx reading value from "
144  "disk key %p for pdo %p\n",
145  status, diskKey, PhysicalDeviceObject));
146  }
147 
148  ZwClose(diskKey);
149 
150  } FINALLY {
151 
152  //
153  // Do nothing.
154  //
155 
156  if(!NT_SUCCESS(status)) {
157  TracePrint((TRACE_LEVEL_WARNING, TRACE_FLAG_PNP, "DiskAddDevice: Will %sallow file system to mount on "
158  "partition zero of disk %p\n",
159  (rootPartitionMountable ? "" : "not "),
161  }
162  }
163 
164  //
165  // Create device objects for disk
166  //
167 
168  diskCount = 0;
169 
171  DriverObject,
173  &diskCount,
174  (BOOLEAN) !rootPartitionMountable
175  );
176 
177  //
178  // Get the number of disks already initialized.
179  //
180 
181  configurationInformation = IoGetConfigurationInformation();
182 
183  if (NT_SUCCESS(status)) {
184 
185  //
186  // Increment system disk device count.
187  //
188 
189  configurationInformation->DiskCount++;
190 
191  }
192 
193  return status;
194 
195 } // end DiskAddDevice()
#define FINALLY
Definition: classpnp.h:116
NTSYSAPI NTSTATUS WINAPI RtlQueryRegistryValues(ULONG, PCWSTR, PRTL_QUERY_REGISTRY_TABLE, PVOID, PVOID)
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
PCONFIGURATION_INFORMATION NTAPI IoGetConfigurationInformation(VOID)
Definition: iorsrce.c:830
#define PLUGPLAY_REGKEY_DEVICE
Definition: iofuncs.h:2782
#define KEY_READ
Definition: nt_native.h:1023
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
LONG NTSTATUS
Definition: precomp.h:26
#define LEAVE
Definition: classpnp.h:115
#define TRY(sps, bps)
PDEVICE_OBJECT PhysicalDeviceObject
Definition: btrfs_drv.h:1155
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define FALSE
Definition: types.h:117
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
#define RTL_QUERY_REGISTRY_TYPECHECK
NTSTATUS DiskCreateFdo(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT PhysicalDeviceObject, IN PULONG DeviceCount, IN BOOLEAN DasdAccessOnly)
Definition: disk.c:307
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static const WCHAR L[]
Definition: oid.c:1250
#define RTL_REGISTRY_HANDLE
Definition: nt_native.h:168
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
#define TRACE_LEVEL_WARNING
Definition: storswtr.h:28
#define RTL_QUERY_REGISTRY_TYPECHECK_SHIFT
NTSTATUS NTAPI IoOpenDeviceRegistryKey(IN PDEVICE_OBJECT DeviceObject, IN ULONG DevInstKeyType, IN ACCESS_MASK DesiredAccess, OUT PHANDLE DevInstRegKey)
Definition: pnpmgr.c:2335
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define REG_NONE
Definition: nt_native.h:1492
#define REG_DWORD
Definition: sdbapi.c:596
static SERVICE_STATUS status
Definition: service.c:31
#define RTL_QUERY_REGISTRY_DIRECT
Definition: nt_native.h:144
#define PAGED_CODE()
Definition: ps.c:97

Referenced by DriverEntry().

◆ DiskCreateFdo()

NTSTATUS DiskCreateFdo ( IN PDRIVER_OBJECT  DriverObject,
IN PDEVICE_OBJECT  LowerDeviceObject,
IN PULONG  DeviceCount,
IN BOOLEAN  DasdAccessOnly 
)

Definition at line 307 of file disk.c.

340 {
341  PCCHAR deviceName = NULL;
342  HANDLE handle = NULL;
343  PDEVICE_OBJECT lowerDevice = NULL;
344  PDEVICE_OBJECT deviceObject = NULL;
345  PFUNCTIONAL_DEVICE_EXTENSION fdoExtension;
347 
348  PAGED_CODE();
349 
350  *DeviceCount = 0;
351 
352  //
353  // Set up an object directory to contain the objects for this
354  // device and all its partitions.
355  //
356 
357  do {
358 
359  WCHAR dirBuffer[64] = { 0 };
360  UNICODE_STRING dirName;
361  OBJECT_ATTRIBUTES objectAttribs;
362 
363  status = RtlStringCchPrintfW(dirBuffer, sizeof(dirBuffer) / sizeof(dirBuffer[0]) - 1, L"\\Device\\Harddisk%d", *DeviceCount);
364  if (!NT_SUCCESS(status)) {
365  TracePrint((TRACE_LEVEL_FATAL, TRACE_FLAG_PNP, "DiskCreateFdo: Format symbolic link failed with error: 0x%X\n", status));
366  return status;
367  }
368 
369  RtlInitUnicodeString(&dirName, dirBuffer);
370 
371  InitializeObjectAttributes(&objectAttribs,
372  &dirName,
374  NULL,
375  NULL);
376 
379  &objectAttribs);
380 
381  (*DeviceCount)++;
382 
383  } while((status == STATUS_OBJECT_NAME_COLLISION) ||
385 
386  if (!NT_SUCCESS(status)) {
387 
388  TracePrint((TRACE_LEVEL_FATAL, TRACE_FLAG_PNP, "DiskCreateFdo: Could not create directory - %lx\n", status));
389 
390  return(status);
391  }
392 
393  //
394  // When this loop exits the count is inflated by one - fix that.
395  //
396 
397  (*DeviceCount)--;
398 
399  //
400  // Claim the device.
401  //
402 
404 
405  status = ClassClaimDevice(lowerDevice, FALSE);
406 
407  if (!NT_SUCCESS(status)) {
409  ZwClose(handle);
410  ObDereferenceObject(lowerDevice);
411  return status;
412  }
413 
414  //
415  // Create a device object for this device. Each physical disk will
416  // have at least one device object. The required device object
417  // describes the entire device. Its directory path is
418  // \Device\HarddiskN\Partition0, where N = device number.
419  //
420 
421  status = DiskGenerateDeviceName(*DeviceCount, &deviceName);
422 
423  if(!NT_SUCCESS(status)) {
424  TracePrint((TRACE_LEVEL_FATAL, TRACE_FLAG_PNP, "DiskCreateFdo - couldn't create name %lx\n", status));
425 
426  goto DiskCreateFdoExit;
427 
428  }
429 
430  status = ClassCreateDeviceObject(DriverObject,
431  deviceName,
433  TRUE,
434  &deviceObject);
435 
436  if (!NT_SUCCESS(status)) {
437  TracePrint((TRACE_LEVEL_FATAL, TRACE_FLAG_PNP, "DiskCreateFdo: Can not create device object %s\n", deviceName));
438  goto DiskCreateFdoExit;
439  }
440 
441  FREE_POOL(deviceName);
442 
443  //
444  // Indicate that IRPs should include MDLs for data transfers.
445  //
446 
447  SET_FLAG(deviceObject->Flags, DO_DIRECT_IO);
448 
449  fdoExtension = deviceObject->DeviceExtension;
450 
451  if(DasdAccessOnly) {
452 
453  //
454  // Inidicate that only RAW should be allowed to mount on the root
455  // partition object. This ensures that a file system can't doubly
456  // mount on a super-floppy by mounting once on P0 and once on P1.
457  //
458 
459 #ifdef _MSC_VER
460 #pragma prefast(suppress:28175);
461 #endif
462  SET_FLAG(deviceObject->Vpb->Flags, VPB_RAW_MOUNT);
463  }
464 
465  //
466  // Initialize lock count to zero. The lock count is used to
467  // disable the ejection mechanism on devices that support
468  // removable media. Only the lock count in the physical
469  // device extension is used.
470  //
471 
472  fdoExtension->LockCount = 0;
473 
474  //
475  // Save system disk number.
476  //
477 
478  fdoExtension->DeviceNumber = *DeviceCount;
479 
480  //
481  // Set the alignment requirements for the device based on the
482  // host adapter requirements
483  //
484 
485  if (lowerDevice->AlignmentRequirement > deviceObject->AlignmentRequirement) {
486  deviceObject->AlignmentRequirement = lowerDevice->AlignmentRequirement;
487  }
488 
489  //
490  // Finally, attach to the pdo
491  //
492 
493  fdoExtension->LowerPdo = PhysicalDeviceObject;
494 
495  fdoExtension->CommonExtension.LowerDeviceObject =
497 
498 
499  if(fdoExtension->CommonExtension.LowerDeviceObject == NULL) {
500 
501  //
502  // Uh - oh, we couldn't attach
503  // cleanup and return
504  //
505 
507  goto DiskCreateFdoExit;
508  }
509 
510  //
511  // Clear the init flag.
512  //
513 
514  CLEAR_FLAG(deviceObject->Flags, DO_DEVICE_INITIALIZING);
515 
516  //
517  // Store a handle to the device object directory for this disk
518  //
519 
520  fdoExtension->DeviceDirectory = handle;
521 
522  ObDereferenceObject(lowerDevice);
523 
524  return STATUS_SUCCESS;
525 
526 DiskCreateFdoExit:
527 
528  if (deviceObject != NULL)
529  {
530  IoDeleteDevice(deviceObject);
531  }
532 
533  FREE_POOL(deviceName);
534 
535  ObDereferenceObject(lowerDevice);
536 
538  ZwClose(handle);
539 
540  return status;
541 }
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
#define STATUS_OBJECT_NAME_COLLISION
Definition: udferr_usr.h:150
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED LPLOOKUPSERVICE_COMPLETION_ROUTINE HANDLE * handle
Definition: sock.c:82
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define TRUE
Definition: types.h:120
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
NTSTRSAFEVAPI RtlStringCchPrintfW(_Out_writes_(cchDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cchDest, _In_ _Printf_format_string_ NTSTRSAFE_PCWSTR pszFormat,...)
Definition: ntstrsafe.h:1110
#define STATUS_OBJECT_NAME_EXISTS
Definition: ntstatus.h:114
LONG NTSTATUS
Definition: precomp.h:26
COMMON_DEVICE_EXTENSION CommonExtension
Definition: classpnp.h:873
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
PDEVICE_OBJECT PhysicalDeviceObject
Definition: btrfs_drv.h:1155
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define DO_DIRECT_IO
Definition: env_spec_w32.h:396
#define FALSE
Definition: types.h:117
#define FREE_POOL(_PoolPtr)
Definition: cdrom.h:782
#define TRACE_LEVEL_FATAL
Definition: storswtr.h:26
ULONG DeviceCount
Definition: mpu401.c:26
PDEVICE_OBJECT NTAPI IoAttachDeviceToDeviceStack(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:966
NTSYSAPI NTSTATUS NTAPI ZwCreateDirectoryObject(_Out_ PHANDLE DirectoryHandle, _In_ ACCESS_MASK DesiredAccess, _In_ POBJECT_ATTRIBUTES ObjectAttributes)
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS DiskGenerateDeviceName(IN ULONG DeviceNumber, OUT PCCHAR *RawName)
Definition: pnp.c:610
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
#define CLEAR_FLAG(Flags, Bit)
Definition: cdrom.h:1494
PDEVICE_OBJECT NTAPI IoGetAttachedDeviceReference(PDEVICE_OBJECT DeviceObject)
Definition: device.c:1406
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
static const WCHAR L[]
Definition: oid.c:1250
PDEVICE_OBJECT LowerPdo
Definition: classpnp.h:875
#define OBJ_PERMANENT
Definition: winternl.h:226
ULONG AlignmentRequirement
Definition: env_spec_w32.h:420
#define VPB_RAW_MOUNT
Definition: iotypes.h:1791
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
#define DIRECTORY_ALL_ACCESS
Definition: nt_native.h:1259
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
return STATUS_SUCCESS
Definition: btrfs.c:3014
static SERVICE_STATUS status
Definition: service.c:31
NTSYSAPI NTSTATUS NTAPI ZwMakeTemporaryObject(_In_ HANDLE Handle)
#define SET_FLAG(Flags, Bit)
Definition: cdrom.h:1493
#define PAGED_CODE()
Definition: ps.c:97

Referenced by DiskAddDevice().

◆ DiskCreateSymbolicLinks()

VOID DiskCreateSymbolicLinks ( IN PDEVICE_OBJECT  DeviceObject)

Definition at line 674 of file pnp.c.

700 {
701  PCOMMON_DEVICE_EXTENSION commonExtension = DeviceObject->DeviceExtension;
702  PDISK_DATA diskData = commonExtension->DriverData;
703 
704  WCHAR wideSourceName[64] = { 0 };
705  UNICODE_STRING unicodeSourceName;
706 
708 
709  PAGED_CODE();
710 
711  //
712  // Build the destination for the link first using the device name
713  // stored in the device object
714  //
715 
716  NT_ASSERT(commonExtension->DeviceName.Buffer);
717 
718  if(!diskData->LinkStatus.WellKnownNameCreated) {
719  //
720  // Put together the source name using the partition and device number
721  // in the device extension and disk data segment
722  //
723 
724  status = RtlStringCchPrintfW(wideSourceName, sizeof(wideSourceName) / sizeof(wideSourceName[0]) - 1,
725  L"\\Device\\Harddisk%d\\Partition0",
726  commonExtension->PartitionZeroExtension->DeviceNumber);
727 
728  if (NT_SUCCESS(status)) {
729 
730  RtlInitUnicodeString(&unicodeSourceName, wideSourceName);
731 
732  TracePrint((TRACE_LEVEL_INFORMATION, TRACE_FLAG_PNP, "DiskCreateSymbolicLink: Linking %wZ to %wZ\n",
733  &unicodeSourceName,
734  &commonExtension->DeviceName));
735 
736  status = IoCreateSymbolicLink(&unicodeSourceName,
737  &commonExtension->DeviceName);
738 
739  if(NT_SUCCESS(status)){
740  diskData->LinkStatus.WellKnownNameCreated = TRUE;
741  }
742  }
743  }
744 
745  if (!diskData->LinkStatus.PhysicalDriveLinkCreated) {
746 
747  //
748  // Create a physical drive N link using the device number we saved
749  // away during AddDevice.
750  //
751 
752  status = RtlStringCchPrintfW(wideSourceName, sizeof(wideSourceName) / sizeof(wideSourceName[0]) - 1,
753  L"\\DosDevices\\PhysicalDrive%d",
754  commonExtension->PartitionZeroExtension->DeviceNumber);
755  if (NT_SUCCESS(status)) {
756 
757  RtlInitUnicodeString(&unicodeSourceName, wideSourceName);
758 
759  TracePrint((TRACE_LEVEL_INFORMATION, TRACE_FLAG_PNP, "DiskCreateSymbolicLink: Linking %wZ to %wZ\n",
760  &unicodeSourceName,
761  &(commonExtension->DeviceName)));
762 
763  status = IoCreateSymbolicLink(&unicodeSourceName,
764  &(commonExtension->DeviceName));
765 
766  if(NT_SUCCESS(status)) {
767  diskData->LinkStatus.PhysicalDriveLinkCreated = TRUE;
768  }
769  }
770  }
771 
772 
773  return;
774 }
#define TRUE
Definition: types.h:120
NTSTRSAFEVAPI RtlStringCchPrintfW(_Out_writes_(cchDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cchDest, _In_ _Printf_format_string_ NTSTRSAFE_PCWSTR pszFormat,...)
Definition: ntstrsafe.h:1110
struct _FUNCTIONAL_DEVICE_EXTENSION * PartitionZeroExtension
Definition: classpnp.h:599
LONG NTSTATUS
Definition: precomp.h:26
#define TRACE_LEVEL_INFORMATION
Definition: storswtr.h:29
UNICODE_STRING DeviceName
Definition: classpnp.h:615
struct _DISK_DATA::@1038 LinkStatus
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static const WCHAR L[]
Definition: oid.c:1250
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
static SERVICE_STATUS status
Definition: service.c:31
#define PAGED_CODE()
#define NT_ASSERT
Definition: rtlfuncs.h:3312
Definition: ps.c:97

Referenced by DiskInitFdo().

◆ DiskDeleteSymbolicLinks()

VOID DiskDeleteSymbolicLinks ( IN PDEVICE_OBJECT  DeviceObject)

Definition at line 778 of file pnp.c.

800 {
801  PCOMMON_DEVICE_EXTENSION commonExtension = DeviceObject->DeviceExtension;
802  PDISK_DATA diskData = commonExtension->DriverData;
803 
804  WCHAR wideLinkName[64] = { 0 };
805  UNICODE_STRING unicodeLinkName;
807 
808  PAGED_CODE();
809 
810  if(diskData->LinkStatus.WellKnownNameCreated) {
811 
812  status = RtlStringCchPrintfW(wideLinkName, sizeof(wideLinkName) / sizeof(wideLinkName[0]) - 1,
813  L"\\Device\\Harddisk%d\\Partition0",
814  commonExtension->PartitionZeroExtension->DeviceNumber);
815  if (NT_SUCCESS(status)) {
816  RtlInitUnicodeString(&unicodeLinkName, wideLinkName);
817  IoDeleteSymbolicLink(&unicodeLinkName);
818  }
819  diskData->LinkStatus.WellKnownNameCreated = FALSE;
820  }
821 
822  if(diskData->LinkStatus.PhysicalDriveLinkCreated) {
823 
824  status = RtlStringCchPrintfW(wideLinkName, sizeof(wideLinkName) / sizeof(wideLinkName[0]) - 1,
825  L"\\DosDevices\\PhysicalDrive%d",
826  commonExtension->PartitionZeroExtension->DeviceNumber);
827  if (NT_SUCCESS(status)) {
828  RtlInitUnicodeString(&unicodeLinkName, wideLinkName);
829  IoDeleteSymbolicLink(&unicodeLinkName);
830  }
831  diskData->LinkStatus.PhysicalDriveLinkCreated = FALSE;
832  }
833 
834 
835  return;
836 }
NTSTRSAFEVAPI RtlStringCchPrintfW(_Out_writes_(cchDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cchDest, _In_ _Printf_format_string_ NTSTRSAFE_PCWSTR pszFormat,...)
Definition: ntstrsafe.h:1110
struct _FUNCTIONAL_DEVICE_EXTENSION * PartitionZeroExtension
Definition: classpnp.h:599
LONG NTSTATUS
Definition: precomp.h:26
#define FALSE
Definition: types.h:117
struct _DISK_DATA::@1038 LinkStatus
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static const WCHAR L[]
Definition: oid.c:1250
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
static SERVICE_STATUS status
Definition: service.c:31
#define PAGED_CODE()
Definition: ps.c:97

Referenced by DiskRemoveDevice().

◆ DiskDetectFailurePrediction()

NTSTATUS DiskDetectFailurePrediction ( PFUNCTIONAL_DEVICE_EXTENSION  FdoExtension,
PFAILURE_PREDICTION_METHOD  FailurePredictCapability,
BOOLEAN  ScsiAddressAvailable 
)

Definition at line 2230 of file diskwmi.c.

2270 {
2272  PDISK_DATA diskData = (PDISK_DATA)(commonExtension->DriverData);
2273  BOOLEAN supportFP;
2274  NTSTATUS status;
2275  STORAGE_PREDICT_FAILURE checkFailure;
2276  STORAGE_FAILURE_PREDICT_STATUS diskSmartStatus;
2277 
2278  PAGED_CODE();
2279 
2280  //
2281  // Assume no failure predict mechanisms
2282  //
2283  *FailurePredictCapability = FailurePredictionNone;
2284 
2285  //
2286  // See if this is an IDE drive that supports SMART. If so enable SMART
2287  // and then ensure that it suports the SMART READ STATUS command
2288  //
2289 
2290  if (ScsiAddressAvailable)
2291  {
2292  DiskGetIdentifyInfo(FdoExtension, &supportFP);
2293 
2294  if (supportFP)
2295  {
2297  if (NT_SUCCESS(status))
2298  {
2299  *FailurePredictCapability = FailurePredictionSmart;
2300  diskData->FailurePredictionEnabled = TRUE;
2301 
2303  &diskSmartStatus);
2304 
2305  TracePrint((TRACE_LEVEL_INFORMATION, TRACE_FLAG_WMI, "Disk: Device %p %s IDE SMART\n",
2306  FdoExtension->DeviceObject,
2307  NT_SUCCESS(status) ? "does" : "does not"));
2308 
2309  if (!NT_SUCCESS(status))
2310  {
2311  *FailurePredictCapability = FailurePredictionNone;
2312  diskData->FailurePredictionEnabled = FALSE;
2313  }
2314  }
2315  return(status);
2316  }
2317  }
2318  //
2319  // See if there is a a filter driver to intercept
2320  // IOCTL_STORAGE_PREDICT_FAILURE
2321  //
2323  &checkFailure);
2324 
2325  TracePrint((TRACE_LEVEL_INFORMATION, TRACE_FLAG_WMI, "Disk: Device %p %s IOCTL_STORAGE_FAILURE_PREDICT\n",
2326  FdoExtension->DeviceObject,
2327  NT_SUCCESS(status) ? "does" : "does not"));
2328 
2329  if (NT_SUCCESS(status))
2330  {
2331  *FailurePredictCapability = FailurePredictionIoctl;
2332  diskData->FailurePredictionEnabled = TRUE;
2333  if (checkFailure.PredictFailure)
2334  {
2335  checkFailure.PredictFailure = 512;
2336  ClassNotifyFailurePredicted(FdoExtension,
2337  (PUCHAR)&checkFailure,
2338  sizeof(checkFailure),
2339  (BOOLEAN)(FdoExtension->FailurePredicted == FALSE),
2340  0x11,
2341  diskData->ScsiAddress.PathId,
2342  diskData->ScsiAddress.TargetId,
2343  diskData->ScsiAddress.Lun);
2344 
2345  FdoExtension->FailurePredicted = TRUE;
2346  }
2347  return(status);
2348  }
2349 
2350  //
2351  // Finally we assume it will not be a scsi smart drive. but
2352  // we'll also send off an asynchronous mode sense so that if
2353  // it is SMART we'll reregister the device object
2354  //
2355 
2356  *FailurePredictCapability = FailurePredictionNone;
2357 
2359 
2360  return(STATUS_SUCCESS);
2361 }
UCHAR PathId
Definition: scsi_port.h:149
struct _DISK_DATA * PDISK_DATA
NTSTATUS DiskReadFailurePredictStatus(PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, PSTORAGE_FAILURE_PREDICT_STATUS DiskSmartStatus)
Definition: diskwmi.c:1251
#define TRUE
Definition: types.h:120
unsigned char * PUCHAR
Definition: retypes.h:3
LONG NTSTATUS
Definition: precomp.h:26
SCSI_ADDRESS ScsiAddress
Definition: disk.h:325
NTSTATUS DiskInfoExceptionCheck(PFUNCTIONAL_DEVICE_EXTENSION FdoExtension)
Definition: diskwmi.c:1922
#define TRACE_LEVEL_INFORMATION
Definition: storswtr.h:29
UCHAR TargetId
Definition: scsi_port.h:150
#define FALSE
Definition: types.h:117
BOOLEAN FailurePredictionEnabled
Definition: disk.h:346
unsigned char BOOLEAN
_inline NTSTATUS DiskEnableSmart(PFUNCTIONAL_DEVICE_EXTENSION FdoExtension)
Definition: diskwmi.c:271
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
struct _COMMON_DEVICE_EXTENSION * PCOMMON_DEVICE_EXTENSION
NTSTATUS DiskGetIdentifyInfo(PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, PBOOLEAN SupportSmart)
Definition: diskwmi.c:813
NTSTATUS DiskSendFailurePredictIoctl(PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, PSTORAGE_PREDICT_FAILURE checkFailure)
Definition: diskwmi.c:854
return STATUS_SUCCESS
Definition: btrfs.c:3014
static SERVICE_STATUS status
Definition: service.c:31
#define PAGED_CODE()
Definition: ps.c:97

Referenced by DiskInitFdo().

◆ DiskDetermineMediaTypes()

NTSTATUS DiskDetermineMediaTypes ( IN PDEVICE_OBJECT  Fdo,
IN PIRP  Irp,
IN UCHAR  MediumType,
IN UCHAR  DensityCode,
IN BOOLEAN  MediaPresent,
IN BOOLEAN  IsWritable 
)

Definition at line 655 of file disk.c.

685 {
686  PFUNCTIONAL_DEVICE_EXTENSION fdoExtension = Fdo->DeviceExtension;
688 
689  PGET_MEDIA_TYPES mediaTypes = Irp->AssociatedIrp.SystemBuffer;
690  PDEVICE_MEDIA_INFO mediaInfo = &mediaTypes->MediaInfo[0];
691  BOOLEAN deviceMatched = FALSE;
692 
693  PAGED_CODE();
694 
695  //
696  // this should be checked prior to calling into this routine
697  // as we use the buffer as mediaTypes
698  //
699 
700  NT_ASSERT(irpStack->Parameters.DeviceIoControl.OutputBufferLength >=
701  sizeof(GET_MEDIA_TYPES));
702 
703  //
704  // Determine if this device is removable or fixed.
705  //
706 
707  if (!TEST_FLAG(Fdo->Characteristics, FILE_REMOVABLE_MEDIA)) {
708 
709  //
710  // Fixed disk.
711  //
712 
713  mediaTypes->DeviceType = FILE_DEVICE_DISK;
714  mediaTypes->MediaInfoCount = 1;
715 
716  mediaInfo->DeviceSpecific.DiskInfo.Cylinders.QuadPart = fdoExtension->DiskGeometry.Cylinders.QuadPart;
717  mediaInfo->DeviceSpecific.DiskInfo.MediaType = FixedMedia;
718  mediaInfo->DeviceSpecific.DiskInfo.TracksPerCylinder = fdoExtension->DiskGeometry.TracksPerCylinder;
719  mediaInfo->DeviceSpecific.DiskInfo.SectorsPerTrack = fdoExtension->DiskGeometry.SectorsPerTrack;
720  mediaInfo->DeviceSpecific.DiskInfo.BytesPerSector = fdoExtension->DiskGeometry.BytesPerSector;
721  mediaInfo->DeviceSpecific.DiskInfo.NumberMediaSides = 1;
722  mediaInfo->DeviceSpecific.DiskInfo.MediaCharacteristics = (MEDIA_CURRENTLY_MOUNTED | MEDIA_READ_WRITE);
723 
724  if (!IsWritable) {
725 
726  SET_FLAG(mediaInfo->DeviceSpecific.DiskInfo.MediaCharacteristics,
728  }
729 
730  } else {
731 
732  PCCHAR vendorId = (PCCHAR) fdoExtension->DeviceDescriptor + fdoExtension->DeviceDescriptor->VendorIdOffset;
733  PCCHAR productId = (PCCHAR) fdoExtension->DeviceDescriptor + fdoExtension->DeviceDescriptor->ProductIdOffset;
734  PCCHAR productRevision = (PCCHAR) fdoExtension->DeviceDescriptor + fdoExtension->DeviceDescriptor->ProductRevisionOffset;
735  DISK_MEDIA_TYPES_LIST const *mediaListEntry;
736  ULONG currentMedia;
737  ULONG i;
738  ULONG j;
739  ULONG sizeNeeded;
740 
741  TracePrint((TRACE_LEVEL_INFORMATION, TRACE_FLAG_IOCTL,
742  "DiskDetermineMediaTypes: Vendor %s, Product %s\n",
743  vendorId,
744  productId));
745 
746 
747  //
748  // If there's an entry with such vendorId & ProductId in the DiskMediaTypesExclude list,
749  // this device shouldn't be looked up in the DiskMediaTypes list to determine a medium type.
750  // The exclude table allows to narrow down the set of devices described by the DiskMediaTypes
751  // list (e.g.: DiskMediaTypes says "all HP devices" and DiskMediaTypesExlclude says
752  // "except for HP RDX")
753  //
754 
755  for (i = 0; DiskMediaTypesExclude[i].VendorId != NULL; i++) {
756  mediaListEntry = &DiskMediaTypesExclude[i];
757 
758  if (strncmp(mediaListEntry->VendorId,vendorId,strlen(mediaListEntry->VendorId))) {
759  continue;
760  }
761 
762  if ((mediaListEntry->ProductId != NULL) &&
763  strncmp(mediaListEntry->ProductId, productId, strlen(mediaListEntry->ProductId))) {
764  continue;
765  }
766 
767  goto SkipTable;
768  }
769 
770  //
771  // Run through the list until we find the entry with a NULL Vendor Id.
772  //
773 
774  for (i = 0; DiskMediaTypes[i].VendorId != NULL; i++) {
775 
776  mediaListEntry = &DiskMediaTypes[i];
777 
778  if (strncmp(mediaListEntry->VendorId,vendorId,strlen(mediaListEntry->VendorId))) {
779  continue;
780  }
781 
782  if ((mediaListEntry->ProductId != NULL) &&
783  strncmp(mediaListEntry->ProductId, productId, strlen(mediaListEntry->ProductId))) {
784  continue;
785  }
786 
787  if ((mediaListEntry->Revision != NULL) &&
788  strncmp(mediaListEntry->Revision, productRevision, strlen(mediaListEntry->Revision))) {
789  continue;
790  }
791 
792  deviceMatched = TRUE;
793 
794  mediaTypes->DeviceType = FILE_DEVICE_DISK;
795  mediaTypes->MediaInfoCount = mediaListEntry->NumberOfTypes;
796 
797  //
798  // Ensure that buffer is large enough.
799  //
800 
801  sizeNeeded = FIELD_OFFSET(GET_MEDIA_TYPES, MediaInfo[0]) +
802  (mediaListEntry->NumberOfTypes *
803  sizeof(DEVICE_MEDIA_INFO)
804  );
805 
806  if (irpStack->Parameters.DeviceIoControl.OutputBufferLength <
807  sizeNeeded) {
808 
809  //
810  // Buffer too small
811  //
812 
813  Irp->IoStatus.Status = STATUS_BUFFER_TOO_SMALL;
815  }
816 
817  for (j = 0; j < mediaListEntry->NumberOfTypes; j++) {
818 
819  mediaInfo->DeviceSpecific.RemovableDiskInfo.Cylinders.QuadPart = fdoExtension->DiskGeometry.Cylinders.QuadPart;
820  mediaInfo->DeviceSpecific.RemovableDiskInfo.TracksPerCylinder = fdoExtension->DiskGeometry.TracksPerCylinder;
821  mediaInfo->DeviceSpecific.RemovableDiskInfo.SectorsPerTrack = fdoExtension->DiskGeometry.SectorsPerTrack;
822  mediaInfo->DeviceSpecific.RemovableDiskInfo.BytesPerSector = fdoExtension->DiskGeometry.BytesPerSector;
823  mediaInfo->DeviceSpecific.RemovableDiskInfo.NumberMediaSides = mediaListEntry->NumberOfSides;
824 
825  //
826  // Set the type.
827  //
828 
829  mediaInfo->DeviceSpecific.RemovableDiskInfo.MediaType = mediaListEntry->MediaTypes[j];
830 
831  if (mediaInfo->DeviceSpecific.RemovableDiskInfo.MediaType == MO_5_WO) {
832  mediaInfo->DeviceSpecific.RemovableDiskInfo.MediaCharacteristics = MEDIA_WRITE_ONCE;
833  } else {
834  mediaInfo->DeviceSpecific.RemovableDiskInfo.MediaCharacteristics = MEDIA_READ_WRITE;
835  }
836 
837  //
838  // Status will either be success, if media is present, or no media.
839  // It would be optimal to base from density code and medium type, but not all devices
840  // have values for these fields.
841  //
842 
843  if (MediaPresent) {
844 
845  //
846  // The usage of MediumType and DensityCode is device specific, so this may need
847  // to be extended to further key off of product/vendor ids.
848  // Currently, the MO units are the only devices that return this information.
849  //
850 
851  if (MediumType == 2) {
852  currentMedia = MO_5_WO;
853  } else if (MediumType == 3) {
854  currentMedia = MO_5_RW;
855 
856  if (DensityCode == 0x87) {
857 
858  //
859  // Indicate that the pinnacle 4.6 G media
860  // is present. Other density codes will default to normal
861  // RW MO media.
862  //
863 
864  currentMedia = PINNACLE_APEX_5_RW;
865  }
866  } else {
867  currentMedia = 0;
868  }
869 
870  if (currentMedia) {
871  if (mediaInfo->DeviceSpecific.RemovableDiskInfo.MediaType == (STORAGE_MEDIA_TYPE)currentMedia) {
872  SET_FLAG(mediaInfo->DeviceSpecific.RemovableDiskInfo.MediaCharacteristics, MEDIA_CURRENTLY_MOUNTED);
873  }
874 
875  } else {
876  SET_FLAG(mediaInfo->DeviceSpecific.RemovableDiskInfo.MediaCharacteristics, MEDIA_CURRENTLY_MOUNTED);
877  }
878  }
879 
880  if (!IsWritable) {
881  SET_FLAG(mediaInfo->DeviceSpecific.RemovableDiskInfo.MediaCharacteristics, MEDIA_WRITE_PROTECTED);
882  }
883 
884  //
885  // Advance to next entry.
886  //
887 
888  mediaInfo++;
889  }
890  }
891 
892 SkipTable:
893 
894  if (!deviceMatched) {
895 
896  TracePrint((TRACE_LEVEL_WARNING, TRACE_FLAG_IOCTL,
897  "DiskDetermineMediaTypes: Unknown device. Vendor: %s Product: %s Revision: %s\n",
898  vendorId,
899  productId,
900  productRevision));
901  //
902  // Build an entry for unknown.
903  //
904 
905  mediaTypes->DeviceType = FILE_DEVICE_DISK;
906  mediaTypes->MediaInfoCount = 1;
907 
908  mediaInfo->DeviceSpecific.RemovableDiskInfo.Cylinders.QuadPart = fdoExtension->DiskGeometry.Cylinders.QuadPart;
909  mediaInfo->DeviceSpecific.RemovableDiskInfo.MediaType = RemovableMedia;
910  mediaInfo->DeviceSpecific.RemovableDiskInfo.TracksPerCylinder = fdoExtension->DiskGeometry.TracksPerCylinder;
911  mediaInfo->DeviceSpecific.RemovableDiskInfo.SectorsPerTrack = fdoExtension->DiskGeometry.SectorsPerTrack;
912  mediaInfo->DeviceSpecific.RemovableDiskInfo.BytesPerSector = fdoExtension->DiskGeometry.BytesPerSector;
913  mediaInfo->DeviceSpecific.RemovableDiskInfo.NumberMediaSides = 1;
914  mediaInfo->DeviceSpecific.RemovableDiskInfo.MediaCharacteristics = MEDIA_READ_WRITE;
915 
916  if (MediaPresent) {
917 
918  SET_FLAG(mediaInfo->DeviceSpecific.RemovableDiskInfo.MediaCharacteristics, MEDIA_CURRENTLY_MOUNTED);
919  }
920 
921  if (!IsWritable) {
922 
923  SET_FLAG(mediaInfo->DeviceSpecific.RemovableDiskInfo.MediaCharacteristics, MEDIA_WRITE_PROTECTED);
924  }
925  }
926  }
927 
928  Irp->IoStatus.Information =
929  FIELD_OFFSET(GET_MEDIA_TYPES, MediaInfo[0]) +
930  (mediaTypes->MediaInfoCount * sizeof(DEVICE_MEDIA_INFO));
931 
932  return STATUS_SUCCESS;
933 }
#define FILE_DEVICE_DISK
Definition: winioctl.h:112
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
DISK_GEOMETRY DiskGeometry
Definition: classpnp.h:888
_In_ PIRP Irp
Definition: csq.h:116
#define TRUE
Definition: types.h:120
union _DEVICE_MEDIA_INFO::@3120 DeviceSpecific
DISK_MEDIA_TYPES_LIST const DiskMediaTypesExclude[]
Definition: data.c:67
ULONG BytesPerSector
Definition: ntdddisk.h:442
ULONG TracksPerCylinder
Definition: ntdddisk.h:440
#define TRACE_LEVEL_INFORMATION
Definition: storswtr.h:29
#define MEDIA_WRITE_PROTECTED
Definition: minitape.h:35
struct _DEVICE_MEDIA_INFO::@3120::@3122 RemovableDiskInfo
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
enum _STORAGE_MEDIA_TYPE STORAGE_MEDIA_TYPE
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define FALSE
Definition: types.h:117
#define MEDIA_WRITE_ONCE
Definition: minitape.h:32
#define FILE_REMOVABLE_MEDIA
Definition: nt_native.h:807
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
struct _DEVICE_MEDIA_INFO::@3120::@3121 DiskInfo
#define TEST_FLAG(Flags, Bit)
Definition: cdrom.h:1495
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
LARGE_INTEGER Cylinders
Definition: ntdddisk.h:438
ULONG SectorsPerTrack
Definition: ntdddisk.h:441
PSTORAGE_DEVICE_DESCRIPTOR DeviceDescriptor
Definition: classpnp.h:876
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
#define MEDIA_READ_WRITE
Definition: minitape.h:34
ULONG DeviceType
Definition: ntddstor.h:494
DISK_MEDIA_TYPES_LIST const DiskMediaTypes[]
Definition: data.c:72
ULONG MediaInfoCount
Definition: ntddstor.h:495
#define TRACE_LEVEL_WARNING
Definition: storswtr.h:28
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
#define MEDIA_CURRENTLY_MOUNTED
Definition: minitape.h:36
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
_Must_inspect_result_ _Out_ PBOOLEAN IsWritable
Definition: fltkernel.h:1744
struct _DEVICE_MEDIA_INFO DEVICE_MEDIA_INFO
unsigned int ULONG
Definition: retypes.h:1
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3107
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define SET_FLAG(Flags, Bit)
Definition: cdrom.h:1493
LONGLONG QuadPart
Definition: typedefs.h:114
DEVICE_MEDIA_INFO MediaInfo[1]
Definition: ntddstor.h:496
#define PAGED_CODE()
#define NT_ASSERT
Definition: rtlfuncs.h:3312

Referenced by DiskIoctlGetMediaTypesEx().

◆ DiskDeviceControl()

NTSTATUS NTAPI DiskDeviceControl ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

◆ DiskEnableDisableFailurePrediction()

NTSTATUS DiskEnableDisableFailurePrediction ( PFUNCTIONAL_DEVICE_EXTENSION  FdoExtension,
BOOLEAN  Enable 
)

Definition at line 1126 of file diskwmi.c.

1147 {
1148  NTSTATUS status;
1149  PCOMMON_DEVICE_EXTENSION commonExtension = &(FdoExtension->CommonExtension);
1150  PDISK_DATA diskData = (PDISK_DATA)(commonExtension->DriverData);
1151 
1152  PAGED_CODE();
1153 
1154  switch(diskData->FailurePredictionCapability)
1155  {
1157  {
1158  if (Enable)
1159  {
1161  } else {
1163  }
1164 
1165  if (NT_SUCCESS(status)) {
1166  diskData->FailurePredictionEnabled = Enable;
1167  }
1168 
1169  break;
1170  }
1171 
1174  {
1175  //
1176  // We assume that the drive is already setup properly for
1177  // failure prediction
1178  //
1180  break;
1181  }
1182 
1183  default:
1184  {
1186  }
1187  }
1188  return status;
1189 }
struct _DISK_DATA * PDISK_DATA
LONG NTSTATUS
Definition: precomp.h:26
_In_ ULONGLONG _In_ ULONGLONG _In_ BOOLEAN Enable
Definition: ntddpcm.h:140
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
BOOLEAN FailurePredictionEnabled
Definition: disk.h:346
_inline NTSTATUS DiskEnableSmart(PFUNCTIONAL_DEVICE_EXTENSION FdoExtension)
Definition: diskwmi.c:271
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
FAILURE_PREDICTION_METHOD FailurePredictionCapability
Definition: disk.h:331
_inline NTSTATUS DiskDisableSmart(PFUNCTIONAL_DEVICE_EXTENSION FdoExtension)
Definition: diskwmi.c:293
return STATUS_SUCCESS
Definition: btrfs.c:3014
static SERVICE_STATUS status
Definition: service.c:31
#define PAGED_CODE()
Definition: ps.c:97

Referenced by DiskEnableDisableFailurePredictPolling(), DiskFdoExecuteWmiMethod(), DiskIoctlEnableFailurePrediction(), and DiskWmiFunctionControl().

◆ DiskEnableDisableFailurePredictPolling()

NTSTATUS DiskEnableDisableFailurePredictPolling ( PFUNCTIONAL_DEVICE_EXTENSION  FdoExtension,
BOOLEAN  Enable,
ULONG  PollTimeInSeconds 
)

Definition at line 1193 of file diskwmi.c.

1217 {
1218  NTSTATUS status;
1220  PDISK_DATA diskData = (PDISK_DATA)(commonExtension->DriverData);
1221 
1222  PAGED_CODE();
1223 
1224  if (Enable)
1225  {
1227  Enable);
1228  } else {
1230  }
1231 
1232  if (NT_SUCCESS(status))
1233  {
1234  status = ClassSetFailurePredictionPoll(FdoExtension,
1235  Enable ? diskData->FailurePredictionCapability :
1237  PollTimeInSeconds);
1238 
1239  //
1240  // Even if this failed we do not want to disable FP on the
1241  // hardware. FP is only ever disabled on the hardware by
1242  // specific command of the user.
1243  //
1244  }
1245 
1246  return status;
1247 }
struct _DISK_DATA * PDISK_DATA
LONG NTSTATUS
Definition: precomp.h:26
_In_ ULONGLONG _In_ ULONGLONG _In_ BOOLEAN Enable
Definition: ntddpcm.h:140
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
struct _COMMON_DEVICE_EXTENSION * PCOMMON_DEVICE_EXTENSION
FAILURE_PREDICTION_METHOD FailurePredictionCapability
Definition: disk.h:331
NTSTATUS DiskEnableDisableFailurePrediction(PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, BOOLEAN Enable)
Definition: diskwmi.c:1126
return STATUS_SUCCESS
Definition: btrfs.c:3014
static SERVICE_STATUS status
Definition: service.c:31
#define PAGED_CODE()
Definition: ps.c:97

Referenced by DiskFdoExecuteWmiMethod(), DiskInitFdo(), and DiskWmiFunctionControl().

◆ DiskEnableInfoExceptions()

NTSTATUS DiskEnableInfoExceptions ( _In_ PFUNCTIONAL_DEVICE_EXTENSION  FdoExtension,
_In_ BOOLEAN  Enable 
)

Definition at line 979 of file diskwmi.c.

983 {
984  PDISK_DATA diskData = (PDISK_DATA)(FdoExtension->CommonExtension.DriverData);
986  PMODE_PARAMETER_HEADER modeData;
987  PMODE_INFO_EXCEPTIONS pageData;
988  MODE_INFO_EXCEPTIONS changeablePageData;
989  ULONG modeDataSize;
990 
991  PAGED_CODE();
992 
993  modeDataSize = MODE_DATA_SIZE;
994 
995  modeData = ExAllocatePoolWithTag(NonPagedPoolNxCacheAligned,
996  modeDataSize,
998 
999  if (modeData == NULL) {
1000 
1001  TracePrint((TRACE_LEVEL_ERROR, TRACE_FLAG_WMI, "DiskEnableInfoExceptions: Unable to allocate mode "
1002  "data buffer\n"));
1004  }
1005 
1006  //
1007  // First see which data is actually changeable.
1008  //
1009  status = DiskGetModePage(FdoExtension->DeviceObject,
1011  1, // Page Control = 1 indicates we want changeable values.
1012  modeData,
1013  &modeDataSize,
1014  (PVOID*)&pageData);
1015 
1016  if (!NT_SUCCESS(status) || pageData == NULL) {
1017  TracePrint((TRACE_LEVEL_INFORMATION, TRACE_FLAG_WMI, "DiskEnableInfoExceptions: does NOT support SMART for device %p\n",
1018  FdoExtension->DeviceObject));
1019  FREE_POOL(modeData);
1020  return STATUS_NOT_SUPPORTED;
1021  }
1022 
1023  TracePrint((TRACE_LEVEL_INFORMATION, TRACE_FLAG_WMI, "DiskEnableInfoExceptions: DOES support SMART for device %p\n",
1024  FdoExtension->DeviceObject));
1025 
1026  //
1027  // At the very least, the DEXCPT bit must be changeable.
1028  // If it's not, bail out now.
1029  //
1030  if (pageData->Dexcpt == 0) {
1031  TracePrint((TRACE_LEVEL_INFORMATION, TRACE_FLAG_WMI, "DiskEnableInfoExceptions: does NOT support DEXCPT bit for device %p\n",
1032  FdoExtension->DeviceObject));
1033  FREE_POOL(modeData);
1034  return STATUS_NOT_SUPPORTED;
1035  }
1036 
1037  //
1038  // Cache away which values are changeable.
1039  //
1040  RtlCopyMemory(&changeablePageData, pageData, sizeof(MODE_INFO_EXCEPTIONS));
1041 
1042  //
1043  // Now get the current values.
1044  //
1045  status = DiskGetModePage(FdoExtension->DeviceObject,
1047  0, // Page Control = 0 indicates we want current values.
1048  modeData,
1049  &modeDataSize,
1050  (PVOID*)&pageData);
1051 
1052  if (!NT_SUCCESS(status) || pageData == NULL) {
1053  //
1054  // At this point we know the device supports this mode page so
1055  // assert if something goes wrong here.
1056  //
1057  NT_ASSERT(NT_SUCCESS(status) && pageData);
1058  FREE_POOL(modeData);
1059  return STATUS_NOT_SUPPORTED;
1060  }
1061 
1062  //
1063  // If the device is currently configured to not report any informational
1064  // exceptions and we cannot change the value of that field, there's
1065  // nothing to be done.
1066  //
1067  if (pageData->ReportMethod == 0 && changeablePageData.ReportMethod == 0) {
1068  TracePrint((TRACE_LEVEL_INFORMATION, TRACE_FLAG_WMI, "DiskEnableInfoExceptions: MRIE field is 0 and is not changeable for device %p\n",
1069  FdoExtension->DeviceObject));
1070  FREE_POOL(modeData);
1071  return STATUS_NOT_SUPPORTED;
1072  }
1073 
1074  //
1075  // If the PERF bit is changeable, set it now.
1076  //
1077  if (changeablePageData.Perf) {
1078  pageData->Perf = diskData->AllowFPPerfHit ? 0 : 1;
1079  }
1080 
1081  //
1082  // If the MRIE field is changeable, set it to 4 so that informational
1083  // exceptions get reported with the "Recovered Error" sense key.
1084  //
1085  if (changeablePageData.ReportMethod) {
1086  pageData->ReportMethod = 4;
1087  }
1088 
1089  //
1090  // Finally, set the DEXCPT bit appropriately to enable/disable
1091  // informational exception reporting and send the Mode Select.
1092  //
1093  pageData->Dexcpt = !Enable;
1094 
1095  status = ClassModeSelect(FdoExtension->DeviceObject,
1096  (PCHAR)modeData,
1097  modeDataSize,
1098  pageData->PSBit);
1099 
1100  //
1101  // Update the failure prediction state. Note that for this particular
1102  // mode FailurePredictionNone is used when it's not enabled.
1103  //
1104  if (NT_SUCCESS(status)) {
1105  if (Enable) {
1107  diskData->FailurePredictionEnabled = TRUE;
1108  } else {
1110  diskData->FailurePredictionEnabled = FALSE;
1111  }
1112  }
1113 
1114  FREE_POOL(modeData);
1115 
1116  return status;
1117 }
signed char * PCHAR
Definition: retypes.h:7
#define MODE_PAGE_FAULT_REPORTING
Definition: scsi.h:218
struct _DISK_DATA * PDISK_DATA
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
_In_ ULONGLONG _In_ ULONGLONG _In_ BOOLEAN Enable
Definition: ntddpcm.h:140
NTSTATUS NTAPI ClassModeSelect(_In_ PDEVICE_OBJECT Fdo, _In_reads_bytes_(Length) PCHAR ModeSelectBuffer, _In_ ULONG Length, _In_ BOOLEAN SavePages)
Definition: class.c:6873
#define TRACE_LEVEL_INFORMATION
Definition: storswtr.h:29
BOOLEAN AllowFPPerfHit
Definition: disk.h:332
#define DISK_TAG_INFO_EXCEPTION
Definition: disk.h:55
#define FALSE
Definition: types.h:117
#define FREE_POOL(_PoolPtr)
Definition: cdrom.h:782
BOOLEAN FailurePredictionEnabled
Definition: disk.h:346
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
FAILURE_PREDICTION_METHOD FailurePredictionCapability
Definition: disk.h:331
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
NTSTATUS DiskGetModePage(_In_ PDEVICE_OBJECT Fdo, _In_ UCHAR PageMode, _In_ UCHAR PageControl, _In_ PMODE_PARAMETER_HEADER ModeData, _Inout_ PULONG ModeDataSize, _Out_ PVOID *PageData)
Definition: diskwmi.c:903
#define MODE_DATA_SIZE
Definition: cdrom.c:173
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:423
unsigned int ULONG
Definition: retypes.h:1
static SERVICE_STATUS status
Definition: service.c:31
#define PAGED_CODE()
#define NT_ASSERT
Definition: rtlfuncs.h:3312
Definition: ps.c:97

Referenced by DiskIoctlEnableFailurePrediction().

◆ DiskFdoExecuteWmiMethod()

NTSTATUS NTAPI DiskFdoExecuteWmiMethod ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp,
IN ULONG  GuidIndex,
IN ULONG  MethodId,
IN ULONG  InBufferSize,
IN ULONG  OutBufferSize,
IN PUCHAR  Buffer 
)

Definition at line 3045 of file diskwmi.c.

3088 {
3089  PFUNCTIONAL_DEVICE_EXTENSION fdoExtension = DeviceObject->DeviceExtension;
3090  PCOMMON_DEVICE_EXTENSION commonExtension = DeviceObject->DeviceExtension;
3091  PDISK_DATA diskData = (PDISK_DATA)(commonExtension->DriverData);
3092  ULONG sizeNeeded = 0;
3093  NTSTATUS status;
3094 
3095  PAGED_CODE();
3096 
3097  TracePrint((TRACE_LEVEL_INFORMATION, TRACE_FLAG_WMI, "Disk: DiskExecuteWmiMethod, DeviceObject %p, Irp %p, Guid Id %d, MethodId %d\n"
3098  " InBufferSize %#x, OutBufferSize %#x, Buffer %p\n",
3099  DeviceObject, Irp,
3101 
3102  switch(GuidIndex)
3103  {
3104  case SmartPerformFunction:
3105  {
3106 
3109  (diskData->FailurePredictionCapability ==
3111  (diskData->FailurePredictionCapability ==
3113 
3114 
3115  switch(MethodId)
3116  {
3117  //
3118  // void AllowPerformanceHit([in] boolean Allow)
3119  //
3121  {
3122  BOOLEAN allowPerfHit;
3123 
3124  sizeNeeded = 0;
3125  if (InBufferSize >= sizeof(BOOLEAN))
3126  {
3128 
3129  allowPerfHit = *((PBOOLEAN)Buffer);
3130  if (diskData->AllowFPPerfHit != allowPerfHit)
3131  {
3132  diskData->AllowFPPerfHit = allowPerfHit;
3133  if (diskData->FailurePredictionCapability ==
3135  {
3136  MODE_INFO_EXCEPTIONS modeInfo;
3137 
3138  status = DiskGetInfoExceptionInformation(fdoExtension,
3139  &modeInfo);
3140  if (NT_SUCCESS(status))
3141  {
3142  modeInfo.Perf = allowPerfHit ? 0 : 1;
3143  status = DiskSetInfoExceptionInformation(fdoExtension,
3144  &modeInfo);
3145  }
3146  }
3147  else
3148  {
3150  }
3151  }
3152 
3153  TracePrint((TRACE_LEVEL_INFORMATION, TRACE_FLAG_WMI, "DiskFdoWmiExecuteMethod: AllowPerformanceHit %x for device %p --> %lx\n",
3154  allowPerfHit,
3155  fdoExtension->DeviceObject,
3156  status));
3157  } else {
3159  }
3160  break;
3161  }
3162 
3163  //
3164  // void EnableDisableHardwareFailurePrediction([in] boolean Enable)
3165  //
3167  {
3168  BOOLEAN enable;
3169 
3170  sizeNeeded = 0;
3171  if (InBufferSize >= sizeof(BOOLEAN))
3172  {
3174  enable = *((PBOOLEAN)Buffer);
3175  if (!enable)
3176  {
3177  //
3178  // If we are disabling we need to also disable
3179  // polling
3180  //
3182  fdoExtension,
3183  enable,
3184  0);
3185  }
3186 
3188  fdoExtension,
3189  enable);
3190 
3191  TracePrint((TRACE_LEVEL_INFORMATION, TRACE_FLAG_WMI, "DiskFdoWmiExecuteMethod: EnableDisableHardwareFailurePrediction: %x for device %p --> %lx\n",
3192  enable,
3193  fdoExtension->DeviceObject,
3194  status));
3195  } else {
3197  }
3198  break;
3199  }
3200 
3201  //
3202  // void EnableDisableFailurePredictionPolling(
3203  // [in] uint32 Period,
3204  // [in] boolean Enable)
3205  //
3207  {
3208  BOOLEAN enable;
3209  ULONG period;
3210 
3211  sizeNeeded = 0;
3212  if (InBufferSize >= (sizeof(ULONG) + sizeof(BOOLEAN)))
3213  {
3214  period = *((PULONG)Buffer);
3215  Buffer += sizeof(ULONG);
3216  enable = *((PBOOLEAN)Buffer);
3217 
3219  fdoExtension,
3220  enable,
3221  period);
3222 
3223  TracePrint((TRACE_LEVEL_INFORMATION, TRACE_FLAG_WMI, "DiskFdoWmiExecuteMethod: EnableDisableFailurePredictionPolling: %x %x for device %p --> %lx\n",
3224  enable,
3225  period,
3226  fdoExtension->DeviceObject,
3227  status));
3228  } else {
3230  }
3231  break;
3232  }
3233 
3234  //
3235  // void GetFailurePredictionCapability([out] uint32 Capability)
3236  //
3238  {
3239  sizeNeeded = sizeof(ULONG);
3240  if (OutBufferSize >= sizeNeeded)
3241  {
3244  TracePrint((TRACE_LEVEL_INFORMATION, TRACE_FLAG_WMI, "DiskFdoWmiExecuteMethod: GetFailurePredictionCapability: %x for device %p --> %lx\n",
3246  fdoExtension->DeviceObject,
3247  status));
3248  } else {
3250  }
3251  break;
3252  }
3253 
3254  //
3255  // void EnableOfflineDiags([out] boolean Success);
3256  //
3257  case EnableOfflineDiags:
3258  {
3259  sizeNeeded = sizeof(BOOLEAN);
3260  if (OutBufferSize >= sizeNeeded)
3261  {
3262  if (diskData->FailurePredictionCapability ==
3264  {
3265  //
3266  // Initiate or resume offline diagnostics.
3267  // This may cause a loss of performance
3268  // to the disk, but mayincrease the amount
3269  // of disk checking.
3270  //
3271  status = DiskExecuteSmartDiagnostics(fdoExtension,
3272  0);
3273 
3274  } else {
3276  }
3277 
3279 
3280  TracePrint((TRACE_LEVEL_INFORMATION, TRACE_FLAG_WMI, "DiskFdoWmiExecuteMethod: EnableOfflineDiags for device %p --> %lx\n",
3281  fdoExtension->DeviceObject,
3282  status));
3283  } else {
3285  }
3286  break;
3287  }
3288 
3289  //
3290  // void ReadLogSectors([in] uint8 LogAddress,
3291  // [in] uint8 SectorCount,
3292  // [out] uint32 Length,
3293  // [out, WmiSizeIs("Length")] uint8 LogSectors[]
3294  // );
3295  //
3296  case ReadLogSectors:
3297  {
3298  if (diskData->FailurePredictionCapability ==
3300  {
3301  if (InBufferSize >= sizeof(READ_LOG_SECTORS_IN))
3302  {
3303  PREAD_LOG_SECTORS_IN inParams;
3304  PREAD_LOG_SECTORS_OUT outParams;
3305  ULONG readSize;
3306 
3307  inParams = (PREAD_LOG_SECTORS_IN)Buffer;
3308  readSize = inParams->SectorCount * SMART_LOG_SECTOR_SIZE;
3309  sizeNeeded = FIELD_OFFSET(READ_LOG_SECTORS_OUT,
3310  LogSectors) + readSize;
3311 
3312  if (OutBufferSize >= sizeNeeded)
3313  {
3314  outParams = (PREAD_LOG_SECTORS_OUT)Buffer;
3315  status = DiskReadSmartLog(fdoExtension,
3316  inParams->SectorCount,
3317  inParams->LogAddress,
3318  outParams->LogSectors);
3319 
3320  if (NT_SUCCESS(status))
3321  {
3322  outParams->Length = readSize;
3323  } else {
3324  //
3325  // SMART command failure is
3326  // indicated by successful
3327  // execution, but no data returned
3328  //
3329  outParams->Length = 0;
3331  }
3332  } else {
3334  }
3335 
3336  } else {
3338  }
3339  } else {
3341  }
3342  break;
3343  }
3344 
3345  // void WriteLogSectors([in] uint8 LogAddress,
3346  // [in] uint8 SectorCount,
3347  // [in] uint32 Length,
3348  // [in, WmiSizeIs("Length")] uint8 LogSectors[],
3349  // [out] boolean Success
3350  // );
3351  case WriteLogSectors:
3352  {
3353  if (diskData->FailurePredictionCapability ==
3355  {
3357  LogSectors))
3358  {
3359  PWRITE_LOG_SECTORS_IN inParams;
3360  PWRITE_LOG_SECTORS_OUT outParams;
3361  ULONG writeSize;
3362 
3363  inParams = (PWRITE_LOG_SECTORS_IN)Buffer;
3364  writeSize = inParams->SectorCount * SMART_LOG_SECTOR_SIZE;
3366  LogSectors) +
3367  writeSize))
3368  {
3369  sizeNeeded = sizeof(WRITE_LOG_SECTORS_OUT);
3370 
3371  if (OutBufferSize >= sizeNeeded)
3372  {
3373  outParams = (PWRITE_LOG_SECTORS_OUT)Buffer;
3374  status = DiskWriteSmartLog(fdoExtension,
3375  inParams->SectorCount,
3376  inParams->LogAddress,
3377  inParams->LogSectors);
3378 
3379  if (NT_SUCCESS(status))
3380  {
3381  outParams->Success = TRUE;
3382  } else {
3383  outParams->Success = FALSE;
3385  }
3386  } else {
3388  }
3389  } else {
3391  }
3392  } else {
3394  }
3395  } else {
3397  }
3398  break;
3399  }
3400 
3401  // void ExecuteSelfTest([in] uint8 Subcommand,
3402  // [out,
3403  // Values{"0", "1", "2"},
3404  // ValueMap{"Successful Completion",
3405  // "Captive Mode Required",
3406  // "Unsuccessful Completion"}
3407  // ]
3408  // uint32 ReturnCode);
3409  case ExecuteSelfTest:
3410  {
3411  if (diskData->FailurePredictionCapability ==
3413  {
3414  if (InBufferSize >= sizeof(EXECUTE_SELF_TEST_IN))
3415  {
3416  sizeNeeded = sizeof(EXECUTE_SELF_TEST_OUT);
3417  if (OutBufferSize >= sizeNeeded)
3418  {
3419  PEXECUTE_SELF_TEST_IN inParam;
3420  PEXECUTE_SELF_TEST_OUT outParam;
3421 
3422  inParam = (PEXECUTE_SELF_TEST_IN)Buffer;
3423  outParam = (PEXECUTE_SELF_TEST_OUT)Buffer;
3424 
3425  if (DiskIsValidSmartSelfTest(inParam->Subcommand))
3426  {
3427  status = DiskExecuteSmartDiagnostics(fdoExtension,
3428  inParam->Subcommand);
3429  if (NT_SUCCESS(status))
3430  {
3431  //
3432  // Return self test executed
3433  // without a problem
3434  //
3435  outParam->ReturnCode = 0;
3436  } else {
3437  //
3438  // Return Self test execution
3439  // failed status
3440  //
3441  outParam->ReturnCode = 2;
3443  }
3444  } else {
3445  //
3446  // If self test subcommand requires
3447  // captive mode then return that
3448  // status
3449  //
3450  outParam->ReturnCode = 1;
3452  }
3453 
3454  } else {
3456  }
3457 
3458  } else {
3460  }
3461  } else {
3463  }
3464 
3465  break;
3466  }
3467 
3468  default :
3469  {
3470  sizeNeeded = 0;
3472  break;
3473  }
3474  }
3475 
3476  break;
3477  }
3478 
3479  case DiskGeometryGuid:
3480  case SmartStatusGuid:
3481  case SmartDataGuid:
3482  case SmartEventGuid:
3483  case SmartThresholdsGuid:
3485  {
3486  sizeNeeded = 0;
3488  break;
3489  }
3490 
3491  default:
3492  {
3493  sizeNeeded = 0;
3495  }
3496  }
3497 
3498  TracePrint((TRACE_LEVEL_INFORMATION, TRACE_FLAG_WMI, "Disk: DiskExecuteMethod Device %p, Irp %p returns %lx\n",
3499  DeviceObject, Irp, status));
3500 
3502  Irp,
3503  status,
3504  sizeNeeded,
3505  IO_NO_INCREMENT);
3506 
3507  return status;
3508 }
#define SMART_LOG_SECTOR_SIZE
Definition: ntdddisk.h:705
struct _DISK_DATA * PDISK_DATA
#define WriteLogSectors
Definition: wmidata.h:3387
_In_ LPCGUID _In_ SIZE_T InBufferSize
Definition: potypes.h:547
#define STATUS_WMI_GUID_NOT_FOUND
Definition: ntstatus.h:776
_In_ PIRP Irp
Definition: csq.h:116
#define TRUE
Definition: types.h:120
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define SmartEventGuid
Definition: diskwmi.c:150
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
struct _WRITE_LOG_SECTORS_OUT * PWRITE_LOG_SECTORS_OUT
#define TRACE_LEVEL_INFORMATION
Definition: storswtr.h:29
#define DiskGeometryGuid
Definition: diskwmi.c:140
BOOLEAN AllowFPPerfHit
Definition: disk.h:332
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
NTSTATUS DiskSetInfoExceptionInformation(IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, IN PMODE_INFO_EXCEPTIONS PageData)
Definition: disk.c:2981
struct _EXECUTE_SELF_TEST_OUT * PEXECUTE_SELF_TEST_OUT
#define FALSE
Definition: types.h:117
long LONG
Definition: pedump.c:60
#define ScsiInfoExceptionsGuid
Definition: diskwmi.c:152
unsigned char BOOLEAN
NTSTATUS DiskGetInfoExceptionInformation(IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, IN PMODE_INFO_EXCEPTIONS ReturnPageData)
Definition: disk.c:2892
_In_ PIRP _In_ ULONG GuidIndex
Definition: classpnp.h:418
_inline NTSTATUS DiskExecuteSmartDiagnostics(PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, UCHAR Subcommand)
Definition: diskwmi.c:359
Definition: bufpool.h:45
#define ReadLogSectors
Definition: wmidata.h:3374
#define ExecuteSelfTest
Definition: wmidata.h:3407
struct _EXECUTE_SELF_TEST_IN * PEXECUTE_SELF_TEST_IN
NTSTATUS DiskWriteSmartLog(IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, IN UCHAR SectorCount, IN UCHAR LogAddress, IN PUCHAR Buffer)
Definition: diskwmi.c:429
_In_ PIRP _In_ ULONG _In_ ULONG MethodId
Definition: classpnp.h:446
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define DiskIsValidSmartSelfTest(Subcommand)
Definition: disk.h:615
struct _EXECUTE_SELF_TEST_OUT EXECUTE_SELF_TEST_OUT
enum FAILURE_PREDICTION_METHOD * PFAILURE_PREDICTION_METHOD
#define SmartStatusGuid
Definition: diskwmi.c:141
NTSTATUS DiskEnableDisableFailurePredictPolling(PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, BOOLEAN Enable, ULONG PollTimeInSeconds)
Definition: diskwmi.c:1193
PDEVICE_OBJECT DeviceObject
Definition: classpnp.h:871
char * PBOOLEAN
Definition: retypes.h:11
#define EnableDisableFailurePredictionPolling
Definition: diskwmi.c:146
#define EnableDisableHardwareFailurePrediction
Definition: diskwmi.c:145
#define SmartThresholdsGuid
Definition: diskwmi.c:151
FAILURE_PREDICTION_METHOD FailurePredictionCapability
Definition: disk.h:331
NTSTATUS DiskEnableDisableFailurePrediction(PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, BOOLEAN Enable)
Definition: diskwmi.c:1126
#define AllowDisallowPerformanceHit
Definition: diskwmi.c:144
struct _READ_LOG_SECTORS_IN * PREAD_LOG_SECTORS_IN
GLboolean enable
Definition: glext.h:11120
NTSTATUS DiskReadSmartLog(IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, IN UCHAR SectorCount, IN UCHAR LogAddress, OUT PUCHAR Buffer)
Definition: diskwmi.c:379
SCSIPORT_API NTSTATUS NTAPI ClassWmiCompleteRequest(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp, _In_ NTSTATUS Status, _In_ ULONG BufferUsed, _In_ CCHAR PriorityBoost)
Definition: classwmi.c:1009
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
struct _WRITE_LOG_SECTORS_IN * PWRITE_LOG_SECTORS_IN
_In_ LPCGUID _In_ SIZE_T _In_ SIZE_T OutBufferSize
Definition: potypes.h:549
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
unsigned int * PULONG
Definition: retypes.h:1
struct _READ_LOG_SECTORS_OUT * PREAD_LOG_SECTORS_OUT
#define BOOLEAN
Definition: pedump.c:73
#define SmartPerformFunction
Definition: diskwmi.c:143
#define SmartDataGuid
Definition: diskwmi.c:142
#define STATUS_WMI_ITEMID_NOT_FOUND
Definition: ntstatus.h:778
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:581
#define EnableOfflineDiags
Definition: diskwmi.c:148
#define GetFailurePredictionCapability
Definition: diskwmi.c:147
return STATUS_SUCCESS
Definition: btrfs.c:3014
static SERVICE_STATUS status
Definition: service.c:31
struct _WRITE_LOG_SECTORS_OUT WRITE_LOG_SECTORS_OUT
#define PAGED_CODE()
#define NT_ASSERT
Definition: rtlfuncs.h:3312
Definition: ps.c:97

Referenced by DriverEntry().

◆ DiskFdoProcessError()

VOID NTAPI DiskFdoProcessError ( PDEVICE_OBJECT  DeviceObject,
PSCSI_REQUEST_BLOCK  Srb,
NTSTATUS Status,
BOOLEAN Retry 
)

Definition at line 2272 of file disk.c.

2302 {
2303  PFUNCTIONAL_DEVICE_EXTENSION fdoExtension = Fdo->DeviceExtension;
2304  PSTORAGE_REQUEST_BLOCK srbEx;
2305  PCDB cdb = NULL;
2306  UCHAR scsiStatus = 0;
2307  UCHAR senseBufferLength = 0;
2308  PVOID senseBuffer = NULL;
2309  CDB noOp = {0};
2310 
2311  //
2312  // Get relevant fields from SRB
2313  //
2314  if (Srb->Function == SRB_FUNCTION_STORAGE_REQUEST_BLOCK) {
2315 
2316  srbEx = (PSTORAGE_REQUEST_BLOCK)Srb;
2317 
2318  //
2319  // Look for SCSI SRB specific fields
2320  //
2321  if ((srbEx->SrbFunction == SRB_FUNCTION_EXECUTE_SCSI) &&
2322  (srbEx->NumSrbExData > 0)) {
2323  cdb = GetSrbScsiData(srbEx, NULL, NULL, &scsiStatus, &senseBuffer, &senseBufferLength);
2324 
2325  //
2326  // cdb and sense buffer should not be NULL
2327  //
2328  NT_ASSERT(cdb != NULL);
2329  NT_ASSERT(senseBuffer != NULL);
2330 
2331  }
2332 
2333  if (cdb == NULL) {
2334 
2335  //
2336  // Use a cdb that is all 0s
2337  //
2338  cdb = &noOp;
2339  }
2340 
2341  } else {
2342 
2343  cdb = (PCDB)(Srb->Cdb);
2344  scsiStatus = Srb->ScsiStatus;
2345  senseBufferLength = Srb->SenseInfoBufferLength;
2346  senseBuffer = Srb->SenseInfoBuffer;
2347  }
2348 
2349  if (*Status == STATUS_DATA_OVERRUN &&
2350  (cdb != NULL) &&
2351  (IS_SCSIOP_READWRITE(cdb->CDB10.OperationCode))) {
2352 
2353  *Retry = TRUE;
2354 
2355  //
2356  // Update the error count for the device.
2357  //
2358 
2359  fdoExtension->ErrorCount++;
2360 
2361  } else if (SRB_STATUS(Srb->SrbStatus) == SRB_STATUS_ERROR &&
2362  scsiStatus == SCSISTAT_BUSY) {
2363 
2364  //
2365  // a disk drive should never be busy this long. Reset the scsi bus
2366  // maybe this will clear the condition.
2367  //
2368 
2369  ResetBus(Fdo);
2370 
2371  //
2372  // Update the error count for the device.
2373  //
2374 
2375  fdoExtension->ErrorCount++;
2376 
2377  } else {
2378 
2379  BOOLEAN invalidatePartitionTable = FALSE;
2380 
2381  //
2382  // See if this might indicate that something on the drive has changed.
2383  //
2384 
2385  if ((Srb->SrbStatus & SRB_STATUS_AUTOSENSE_VALID) &&
2386  (senseBuffer != NULL) && (cdb != NULL)) {
2387 
2389  UCHAR senseKey = 0;
2390  UCHAR asc = 0;
2391  UCHAR ascq = 0;
2392 
2393  validSense = ScsiGetSenseKeyAndCodes(senseBuffer,
2394  senseBufferLength,
2396  &senseKey,
2397  &asc,
2398  &ascq);
2399 
2400  if (validSense) {
2401 
2402  switch (senseKey) {
2403 
2405 
2406  switch (asc) {
2407 
2409  {
2410  //
2411  // Look to see if this is an Io request with the ForceUnitAccess flag set
2412  //
2413  if (((cdb->CDB10.OperationCode == SCSIOP_WRITE) ||
2414  (cdb->CDB10.OperationCode == SCSIOP_WRITE16)) &&
2415  (cdb->CDB10.ForceUnitAccess))
2416  {
2417  PDISK_DATA diskData = (PDISK_DATA)fdoExtension->CommonExtension.DriverData;
2418 
2420  {
2421  PIO_ERROR_LOG_PACKET logEntry = NULL;
2422 
2423  //
2424  // The user has explicitly requested that write caching be turned on.
2425  // Warn the user that writes with FUA enabled are not working and that
2426  // they should disable write cache.
2427  //
2428 
2429  logEntry = IoAllocateErrorLogEntry(fdoExtension->DeviceObject,
2430  sizeof(IO_ERROR_LOG_PACKET) + (4 * sizeof(ULONG)));
2431 
2432  if (logEntry != NULL)
2433  {
2434  logEntry->FinalStatus = *Status;
2436  logEntry->SequenceNumber = 0;
2437  logEntry->MajorFunctionCode = IRP_MJ_SCSI;
2438  logEntry->IoControlCode = 0;
2439  logEntry->RetryCount = 0;
2440  logEntry->UniqueErrorValue = 0;
2441  logEntry->DumpDataSize = 4 * sizeof(ULONG);
2442 
2443  logEntry->DumpData[0] = diskData->ScsiAddress.PortNumber;
2444  logEntry->DumpData[1] = diskData->ScsiAddress.PathId;
2445  logEntry->DumpData[2] = diskData->ScsiAddress.TargetId;
2446  logEntry->DumpData[3] = diskData->ScsiAddress.Lun;
2447 
2448  //
2449  // Write the error log packet.
2450  //
2451 
2452  IoWriteErrorLogEntry(logEntry);
2453  }
2454  }
2455  else
2456  {
2457  //
2458  // Turn off write caching on this device. This is so that future
2459  // critical requests need not be sent down with ForceUnitAccess
2460  //
2461  PIO_WORKITEM workItem = IoAllocateWorkItem(Fdo);
2462 
2463  if (workItem)
2464  {
2465  IoQueueWorkItem(workItem, DisableWriteCache, CriticalWorkQueue, workItem);
2466  }
2467  }
2468 
2470  ADJUST_FUA_FLAG(fdoExtension);
2471 
2472 
2473  cdb->CDB10.ForceUnitAccess = FALSE;
2474  *Retry = TRUE;
2475 
2476  } else if ((cdb->CDB6FORMAT.OperationCode == SCSIOP_MODE_SENSE) &&
2477  (cdb->MODE_SENSE.PageCode == MODE_SENSE_RETURN_ALL)) {
2478 
2479  //
2480  // Mode sense for all pages failed. This command could fail with
2481  // SCSI_SENSE_ILLEGAL_REQUEST / SCSI_ADSENSE_INVALID_CDB if the data
2482  // to be returned is more than 256 bytes. In which case, try to get
2483  // only MODE_PAGE_CACHING since we only need the block descriptor.
2484  //
2485  // Simply change the page code and retry the request
2486  //
2487 
2488  cdb->MODE_SENSE.PageCode = MODE_PAGE_CACHING;
2489  *Retry = TRUE;
2490  }
2491 
2492  break;
2493  }
2494  } // end switch(asc)
2495  break;
2496  }
2497 
2498  case SCSI_SENSE_NOT_READY: {
2499 
2500  switch (asc) {
2502  switch (ascq) {
2506  invalidatePartitionTable = TRUE;
2507  break;
2508  }
2509  } // end switch(ascq)
2510  break;
2511  }
2512 
2514  invalidatePartitionTable = TRUE;
2515  break;
2516  }
2517  } // end switch(asc)
2518  break;
2519  }
2520 
2521  case SCSI_SENSE_MEDIUM_ERROR: {
2522  invalidatePartitionTable = TRUE;
2523  break;
2524  }
2525 
2527  invalidatePartitionTable = TRUE;
2528  break;
2529  }
2530 
2532  {
2533  invalidatePartitionTable = TRUE;
2534  break;
2535  }
2536 
2538  invalidatePartitionTable = TRUE;
2539  break;
2540  }
2541 
2542  } // end switch(senseKey)
2543  } // end if (validSense)
2544  } else {
2545 
2546  //
2547  // On any exceptional scsi condition which might indicate that the
2548  // device was changed we will flush out the state of the partition
2549  // table.
2550  //
2551 
2552  switch (SRB_STATUS(Srb->SrbStatus)) {
2555  case SRB_STATUS_NO_DEVICE:
2556  case SRB_STATUS_NO_HBA:
2559  case SRB_STATUS_TIMEOUT:
2564  {
2565  invalidatePartitionTable = TRUE;
2566  break;
2567  }
2568 
2569  case SRB_STATUS_ERROR:
2570  {
2571  if (scsiStatus == SCSISTAT_RESERVATION_CONFLICT)
2572  {
2573  invalidatePartitionTable = TRUE;
2574  }
2575 
2576  break;
2577  }
2578  } // end switch(Srb->SrbStatus)
2579  }
2580 
2581  if (invalidatePartitionTable && TEST_FLAG(Fdo->Characteristics, FILE_REMOVABLE_MEDIA)) {
2582 
2583  //
2584  // Inform the upper layers that the volume
2585  // on this disk is in need of verification
2586  //
2587 
2588  SET_FLAG(Fdo->Flags, DO_VERIFY_VOLUME);
2589  }
2590  }
2591 
2592  return;
2593 }
UCHAR PathId
Definition: scsi_port.h:149
UCHAR PortNumber
Definition: scsi_port.h:148
#define SCSISTAT_BUSY
Definition: cdrw_hw.h:1081
struct _DISK_DATA * PDISK_DATA
#define CLASS_SPECIAL_FUA_NOT_SUPPORTED
Definition: classpnp.h:174
UCHAR senseKey
Definition: scsi.h:4019
#define STATUS_DATA_OVERRUN
Definition: udferr_usr.h:152
#define MODE_PAGE_CACHING
Definition: cdrw_hw.h:846
#define SRB_STATUS_AUTOSENSE_VALID
Definition: srb.h:379
NTSTATUS FinalStatus
Definition: iotypes.h:1989
#define TRUE
Definition: types.h:120
#define SCSIOP_MODE_SENSE
Definition: cdrw_hw.h:896
Definition: cdrw_hw.h:28
#define IO_WARNING_WRITE_FUA_PROBLEM
Definition: ntiologc.h:93
#define SRB_STATUS_REQUEST_FLUSHED
Definition: srb.h:353
COMMON_DEVICE_EXTENSION CommonExtension
Definition: classpnp.h:873
struct _CDB::_CDB6FORMAT CDB6FORMAT
SCSI_ADDRESS ScsiAddress
Definition: disk.h:325
#define DO_VERIFY_VOLUME
Definition: env_spec_w32.h:393
#define SRB_STATUS_COMMAND_TIMEOUT
Definition: srb.h:343
#define MODE_SENSE_RETURN_ALL
Definition: cdrw_hw.h:857
#define SRB_STATUS_NO_DEVICE
Definition: srb.h:340
#define SCSI_SENSE_OPTIONS_FIXED_FORMAT_IF_UNKNOWN_FORMAT_INDICATED
Definition: scsi.h:3839
#define SCSI_ADSENSE_LUN_NOT_READY
Definition: cdrw_hw.h:1218
#define SCSIOP_WRITE16
Definition: scsi.h:915
struct _CDB::_CDB10 CDB10
PIO_WORKITEM NTAPI IoAllocateWorkItem(IN PDEVICE_OBJECT DeviceObject)
Definition: iowork.c:75
#define SCSI_SENSE_NOT_READY
Definition: cdrw_hw.h:1189
#define SRB_STATUS_INVALID_TARGET_ID
Definition: srb.h:355
UCHAR TargetId
Definition: scsi_port.h:150
#define SRB_STATUS(Status)
Definition: srb.h:381
VOID NTAPI IoWriteErrorLogEntry(IN PVOID ElEntry)
Definition: error.c:628
#define IRP_MJ_SCSI
#define SRB_STATUS_ERROR
Definition: srb.h:336
#define SCSI_SENSE_MEDIUM_ERROR
Definition: cdrw_hw.h:1190
NTSTATUS ErrorCode
Definition: iotypes.h:1987
#define SRB_STATUS_PARITY_ERROR
Definition: srb.h:346
#define SCSI_SENSEQ_MANUAL_INTERVENTION_REQUIRED
Definition: cdrw_hw.h:1315
#define FALSE
Definition: types.h:117
#define FILE_REMOVABLE_MEDIA
Definition: nt_native.h:807
#define ADJUST_FUA_FLAG(fdoExt)
Definition: classpnp.h:53
#define SCSI_ADSENSE_NO_MEDIA_IN_DEVICE
Definition: cdrw_hw.h:1221
#define SCSIOP_WRITE
Definition: cdrw_hw.h:906
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define SRB_STATUS_NO_HBA
Definition: srb.h:348
DISK_USER_WRITE_CACHE_SETTING WriteCacheOverride
Definition: disk.h:385
* PSTORAGE_REQUEST_BLOCK
Definition: srb.h:652
union _CDB * PCDB
IN PSCSI_REQUEST_BLOCK IN OUT NTSTATUS IN OUT BOOLEAN * Retry
Definition: class2.h:49
#define TEST_FLAG(Flags, Bit)
Definition: cdrom.h:1495
struct _CDB::_MODE_SENSE MODE_SENSE
PVOID NTAPI IoAllocateErrorLogEntry(IN PVOID IoObject, IN UCHAR EntrySize)
Definition: error.c:528
VOID NTAPI DisableWriteCache(IN PDEVICE_OBJECT DeviceObject, IN PSCSI_INQUIRY_DATA LunInfo)
Definition: disk.c:3552
if(!(yy_init))
Definition: macro.lex.yy.c:714
#define SCSI_SENSEQ_BECOMING_READY
Definition: cdrw_hw.h:1313
#define SCSISTAT_RESERVATION_CONFLICT
Definition: cdrw_hw.h:1084
PDEVICE_OBJECT DeviceObject
Definition: classpnp.h:871
__inline PCDB GetSrbScsiData(_In_ PSTORAGE_REQUEST_BLOCK SrbEx, _In_opt_ PUCHAR CdbLength8, _In_opt_ PULONG CdbLength32, _In_opt_ PUCHAR ScsiStatus, _In_opt_ PVOID *SenseInfoBuffer, _In_opt_ PUCHAR SenseInfoBufferLength)
Definition: disk.h:990
#define SCSI_SENSE_HARDWARE_ERROR
Definition: cdrw_hw.h:1191
#define SRB_FUNCTION_STORAGE_REQUEST_BLOCK
Definition: srb.h:99
unsigned char UCHAR
Definition: xmlstorage.h:181
Status
Definition: gdiplustypes.h:24
#define SRB_STATUS_SELECTION_TIMEOUT
Definition: srb.h:342
#define SCSI_SENSE_RECOVERED_ERROR
Definition: cdrw_hw.h:1188
#define SCSI_SENSEQ_CAUSE_NOT_REPORTABLE
Definition: cdrw_hw.h:1312
#define SRB_STATUS_INVALID_LUN
Definition: srb.h:354
VOID NTAPI IoQueueWorkItem(IN PIO_WORKITEM IoWorkItem, IN PIO_WORKITEM_ROUTINE WorkerRoutine, IN WORK_QUEUE_TYPE QueueType, IN PVOID Context)
Definition: iowork.c:40
#define IS_SCSIOP_READWRITE(opCode)
Definition: cdrom.h:803
#define SRB_STATUS_TIMEOUT
Definition: srb.h:341
#define SRB_FUNCTION_EXECUTE_SCSI
Definition: srb.h:307
unsigned int ULONG
Definition: retypes.h:1
#define SRB_STATUS_UNEXPECTED_BUS_FREE
Definition: srb.h:350
#define SRB_STATUS_INVALID_PATH_ID
Definition: srb.h:339
IN PSCSI_REQUEST_BLOCK Srb
Definition: class2.h:49
#define SCSI_SENSE_ILLEGAL_REQUEST
Definition: cdrw_hw.h:1192
VOID ResetBus(IN PDEVICE_OBJECT Fdo)
Definition: disk.c:2701
#define SET_FLAG(Flags, Bit)
Definition: cdrom.h:1493
#define SCSI_SENSE_UNIT_ATTENTION
Definition: cdrw_hw.h:1193
#define SCSI_ADSENSE_INVALID_CDB
Definition: cdrw_hw.h:1265
BOOLEAN validSense
Definition: scsi.h:4018
#define NT_ASSERT
Definition: rtlfuncs.h:3312

Referenced by DriverEntry().

◆ DiskFdoQueryWmiDataBlock()

NTSTATUS NTAPI DiskFdoQueryWmiDataBlock ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp,
IN ULONG  GuidIndex,
IN ULONG  BufferAvail,
OUT PUCHAR  Buffer 
)

Definition at line 2638 of file diskwmi.c.

2674 {
2675  NTSTATUS status;
2676  PFUNCTIONAL_DEVICE_EXTENSION fdoExtension = DeviceObject->DeviceExtension;
2677  PCOMMON_DEVICE_EXTENSION commonExtension = DeviceObject->DeviceExtension;
2678  PDISK_DATA diskData = (PDISK_DATA)(commonExtension->DriverData);
2679  ULONG sizeNeeded;
2680 
2681  PAGED_CODE();
2682 
2683  TracePrint((TRACE_LEVEL_INFORMATION, TRACE_FLAG_WMI, "Disk: DiskQueryWmiDataBlock, Device %p, Irp %p, GuiIndex %d\n"
2684  " BufferAvail %lx Buffer %p\n",
2685  DeviceObject, Irp,
2687 
2688  switch (GuidIndex)
2689  {
2690  case DiskGeometryGuid:
2691  {
2692  sizeNeeded = sizeof(DISK_GEOMETRY);
2693  if (BufferAvail >= sizeNeeded)
2694  {
2695  if (DeviceObject->Characteristics & FILE_REMOVABLE_MEDIA)
2696  {
2697  //
2698  // Issue ReadCapacity to update device extension
2699  // with information for current media.
2700  status = DiskReadDriveCapacity(commonExtension->PartitionZeroExtension->DeviceObject);
2701 
2702  //
2703  // Note whether the drive is ready.
2704  diskData->ReadyStatus = status;
2705 
2706  if (!NT_SUCCESS(status))
2707  {
2708  break;
2709  }
2710  }
2711 
2712  //
2713  // Copy drive geometry information from device extension.
2715  &(fdoExtension->DiskGeometry),
2716  sizeof(DISK_GEOMETRY));
2717 
2719  } else {
2721  }
2722  break;
2723  }
2724 
2725  case SmartStatusGuid:
2726  {
2727  PSTORAGE_FAILURE_PREDICT_STATUS diskSmartStatus;
2728 
2730 
2731  sizeNeeded = sizeof(STORAGE_FAILURE_PREDICT_STATUS);
2732  if (BufferAvail >= sizeNeeded)
2733  {
2734  STORAGE_PREDICT_FAILURE checkFailure;
2735 
2736  diskSmartStatus = (PSTORAGE_FAILURE_PREDICT_STATUS)Buffer;
2737 
2738  status = DiskSendFailurePredictIoctl(fdoExtension,
2739  &checkFailure);
2740 
2741  if (NT_SUCCESS(status))
2742  {
2743  if (diskData->FailurePredictionCapability ==
2745  {
2746  diskSmartStatus->Reason = *((PULONG)checkFailure.VendorSpecific);
2747  } else {
2748  diskSmartStatus->Reason = 0; // unknown
2749  }
2750 
2751  diskSmartStatus->PredictFailure = (checkFailure.PredictFailure != 0);
2752  }
2753  } else {
2755  }
2756  break;
2757  }
2758 
2759  case SmartDataGuid:
2760  {
2761  PSTORAGE_FAILURE_PREDICT_DATA diskSmartData;
2762 
2765  (diskData->FailurePredictionCapability ==
2767 
2768  sizeNeeded = sizeof(STORAGE_FAILURE_PREDICT_DATA);
2769  if (BufferAvail >= sizeNeeded)
2770  {
2772 
2773  diskSmartData = (PSTORAGE_FAILURE_PREDICT_DATA)Buffer;
2774 
2775  status = DiskSendFailurePredictIoctl(fdoExtension,
2776  checkFailure);
2777 
2778  if (NT_SUCCESS(status))
2779  {
2780  diskSmartData->Length = 512;
2781  }
2782  } else {
2784  }
2785 
2786  break;
2787  }
2788 
2789  case SmartThresholdsGuid:
2790  {
2791  PSTORAGE_FAILURE_PREDICT_THRESHOLDS diskSmartThresholds;
2792 
2795 
2796  sizeNeeded = sizeof(STORAGE_FAILURE_PREDICT_THRESHOLDS);
2797  if (BufferAvail >= sizeNeeded)
2798  {
2799  diskSmartThresholds = (PSTORAGE_FAILURE_PREDICT_THRESHOLDS)Buffer;
2801  diskSmartThresholds);
2802  } else {
2804  }
2805 
2806  break;
2807  }
2808 
2809  case SmartPerformFunction:
2810  {
2811  sizeNeeded = 0;
2813  break;
2814  }
2815 
2817  {
2818  PSTORAGE_SCSI_INFO_EXCEPTIONS infoExceptions;
2819  MODE_INFO_EXCEPTIONS modeInfo;
2820 
2823 
2824  sizeNeeded = sizeof(STORAGE_SCSI_INFO_EXCEPTIONS);
2825  if (BufferAvail >= sizeNeeded)
2826  {
2827  infoExceptions = (PSTORAGE_SCSI_INFO_EXCEPTIONS)Buffer;
2828  status = DiskGetInfoExceptionInformation(fdoExtension,
2829  &modeInfo);
2830  if (NT_SUCCESS(status))
2831  {
2832  infoExceptions->PageSavable = modeInfo.PSBit;
2833  infoExceptions->Flags = modeInfo.Flags;
2834  infoExceptions->MRIE = modeInfo.ReportMethod;
2835  infoExceptions->Padding = 0;
2836  REVERSE_BYTES(&infoExceptions->IntervalTimer,
2837  &modeInfo.IntervalTimer);
2838  REVERSE_BYTES(&infoExceptions->ReportCount,
2839  &modeInfo.ReportCount)
2840  }
2841  } else {
2843  }
2844 
2845  break;
2846  }
2847 
2848  default:
2849  {
2850  sizeNeeded = 0;
2852  }
2853  }
2854  TracePrint((TRACE_LEVEL_INFORMATION, TRACE_FLAG_WMI, "Disk: DiskQueryWmiDataBlock Device %p, Irp %p returns %lx\n",
2855  DeviceObject, Irp, status));
2856 
2858  Irp,
2859  status,
2860  sizeNeeded,
2861  IO_NO_INCREMENT);
2862 
2863  return status;
2864 }
struct _STORAGE_FAILURE_PREDICT_THRESHOLDS STORAGE_FAILURE_PREDICT_THRESHOLDS
struct _DISK_DATA * PDISK_DATA
UCHAR IntervalTimer[4]
Definition: scsi.h:3028
struct _STORAGE_SCSI_INFO_EXCEPTIONS * PSTORAGE_SCSI_INFO_EXCEPTIONS
#define STATUS_WMI_GUID_NOT_FOUND
Definition: ntstatus.h:776
struct _STORAGE_FAILURE_PREDICT_DATA STORAGE_FAILURE_PREDICT_DATA
DISK_GEOMETRY DiskGeometry
Definition: classpnp.h:888
_In_ PIRP Irp
Definition: csq.h:116
NTSTATUS ReadyStatus
Definition: disk.h:319
struct _FUNCTIONAL_DEVICE_EXTENSION * PartitionZeroExtension
Definition: classpnp.h:599
LONG NTSTATUS
Definition: precomp.h:26
#define REVERSE_BYTES(Destination, Source)
Definition: scsi.h:3465
struct _STORAGE_FAILURE_PREDICT_STATUS STORAGE_FAILURE_PREDICT_STATUS
struct _STORAGE_FAILURE_PREDICT_DATA * PSTORAGE_FAILURE_PREDICT_DATA
struct _STORAGE_FAILURE_PREDICT_THRESHOLDS * PSTORAGE_FAILURE_PREDICT_THRESHOLDS
#define TRACE_LEVEL_INFORMATION
Definition: storswtr.h:29
#define DiskGeometryGuid
Definition: diskwmi.c:140
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:264
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
struct _STORAGE_FAILURE_PREDICT_STATUS * PSTORAGE_FAILURE_PREDICT_STATUS
NTSTATUS DiskReadFailurePredictThresholds(PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, PSTORAGE_FAILURE_PREDICT_THRESHOLDS DiskSmartThresholds)
Definition: diskwmi.c:1417
#define FILE_REMOVABLE_MEDIA
Definition: nt_native.h:807
#define ScsiInfoExceptionsGuid
Definition: diskwmi.c:152
NTSTATUS DiskGetInfoExceptionInformation(IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, IN PMODE_INFO_EXCEPTIONS ReturnPageData)
Definition: disk.c:2892
_In_ PIRP _In_ ULONG GuidIndex
Definition: classpnp.h:418
struct _STORAGE_PREDICT_FAILURE * PSTORAGE_PREDICT_FAILURE
Definition: bufpool.h:45
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define DiskReadDriveCapacity(Fdo)
Definition: disk.h:814
#define SmartStatusGuid
Definition: diskwmi.c:141
#define SmartThresholdsGuid
Definition: diskwmi.c:151
FAILURE_PREDICTION_METHOD FailurePredictionCapability
Definition: disk.h:331
struct _STORAGE_SCSI_INFO_EXCEPTIONS STORAGE_SCSI_INFO_EXCEPTIONS
_In_ PIRP _In_ ULONG _In_ ULONG BufferAvail
Definition: classpnp.h:418
UCHAR VendorSpecific[512]
Definition: ntddstor.h:501
struct _DISK_GEOMETRY DISK_GEOMETRY
SCSIPORT_API NTSTATUS NTAPI ClassWmiCompleteRequest(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp, _In_ NTSTATUS Status, _In_ ULONG BufferUsed, _In_ CCHAR PriorityBoost)
Definition: classwmi.c:1009
UCHAR ReportCount[4]
Definition: scsi.h:3029
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
unsigned int * PULONG
Definition: retypes.h:1
NTSTATUS DiskSendFailurePredictIoctl(PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, PSTORAGE_PREDICT_FAILURE checkFailure)
Definition: diskwmi.c:854
#define SmartPerformFunction
Definition: diskwmi.c:143
#define SmartDataGuid
Definition: diskwmi.c:142
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:581
return STATUS_SUCCESS
Definition: btrfs.c:3014
static SERVICE_STATUS status
Definition: service.c:31
#define PAGED_CODE()
#define NT_ASSERT
Definition: rtlfuncs.h:3312
Definition: ps.c:97

Referenced by DriverEntry().

◆ DiskFdoQueryWmiRegInfo()

NTSTATUS NTAPI DiskFdoQueryWmiRegInfo ( IN PDEVICE_OBJECT  DeviceObject,
OUT ULONG RegFlags,
OUT PUNICODE_STRING  InstanceName 
)

Definition at line 2479 of file diskwmi.c.

2517 {
2518  PCOMMON_DEVICE_EXTENSION commonExtension = DeviceObject->DeviceExtension;
2519  PDISK_DATA diskData = (PDISK_DATA)(commonExtension->DriverData);
2520 
2521  PAGED_CODE();
2523 
2526 
2527  switch (diskData->FailurePredictionCapability)
2528  {
2530  {
2532  //
2533  // Fall Through
2534  //
2535  }
2537  {
2542 
2543  break;
2544  }
2545 
2547  {
2553  break;
2554  }
2555 
2556 
2557  default:
2558  {
2563  break;
2564  }
2565  }
2566 
2567  //
2568  // Use devnode for FDOs
2570 
2571  return STATUS_SUCCESS;
2572 }
struct _DISK_DATA * PDISK_DATA
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
#define SmartEventGuid
Definition: diskwmi.c:150
GUIDREGINFO DiskWmiFdoGuidList[]
Definition: diskwmi.c:92
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
#define ScsiInfoExceptionsGuid
Definition: diskwmi.c:152
_Out_ ULONG * RegFlags
Definition: classpnp.h:403
#define WMIREG_FLAG_INSTANCE_PDO
Definition: wmistr.h:69
#define CLEAR_FLAG(Flags, Bit)
Definition: cdrom.h:1494
#define WMIREG_FLAG_REMOVE_GUID
Definition: wmistr.h:70
#define SmartStatusGuid
Definition: diskwmi.c:141
#define SmartThresholdsGuid
Definition: diskwmi.c:151
FAILURE_PREDICTION_METHOD FailurePredictionCapability
Definition: disk.h:331
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
_Must_inspect_result_ _Inout_ PFLT_VOLUME _In_opt_ PCUNICODE_STRING InstanceName
Definition: fltkernel.h:1162
#define SmartPerformFunction
Definition: diskwmi.c:143
#define SmartDataGuid
Definition: diskwmi.c:142
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define SET_FLAG(Flags, Bit)
Definition: cdrom.h:1493
#define PAGED_CODE()

Referenced by DiskFdoQueryWmiRegInfoEx(), and DriverEntry().

◆ DiskFdoQueryWmiRegInfoEx()

NTSTATUS NTAPI DiskFdoQueryWmiRegInfoEx ( IN PDEVICE_OBJECT  DeviceObject,
OUT ULONG RegFlags,
OUT PUNICODE_STRING  InstanceName,
OUT PUNICODE_STRING  MofName 
)

Definition at line 2577 of file diskwmi.c.

2620 {
2621  NTSTATUS status;
2622 
2623  UNREFERENCED_PARAMETER(MofName);
2624 
2626  RegFlags,
2627  InstanceName);
2628 
2629  //
2630  // Leave MofName alone since disk doesn't have one
2631  //
2632  return(status);
2633 }
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI DiskFdoQueryWmiRegInfo(IN PDEVICE_OBJECT DeviceObject, OUT ULONG *RegFlags, OUT PUNICODE_STRING InstanceName)
Definition: diskwmi.c:2479
_Out_ ULONG * RegFlags
Definition: classpnp.h:403
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
_Must_inspect_result_ _Inout_ PFLT_VOLUME _In_opt_ PCUNICODE_STRING InstanceName
Definition: fltkernel.h:1162
static SERVICE_STATUS status
Definition: service.c:31
Definition: ps.c:97

Referenced by DriverEntry().

◆ DiskFdoSetWmiDataBlock()

NTSTATUS NTAPI DiskFdoSetWmiDataBlock ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp,
IN ULONG  GuidIndex,
IN ULONG  BufferSize,
IN PUCHAR  Buffer 
)

Definition at line 2869 of file diskwmi.c.

2904 {
2905  NTSTATUS status;
2906  PFUNCTIONAL_DEVICE_EXTENSION fdoExtension = DeviceObject->DeviceExtension;
2907  PCOMMON_DEVICE_EXTENSION commonExtension = DeviceObject->DeviceExtension;
2908  PDISK_DATA diskData = (PDISK_DATA)(commonExtension->DriverData);
2909 
2910  PAGED_CODE();
2911 
2912  TracePrint((TRACE_LEVEL_INFORMATION, TRACE_FLAG_WMI, "Disk: DiskSetWmiDataBlock, Device %p, Irp %p, GuiIndex %d\n"
2913  " BufferSize %#x Buffer %p\n",
2914  DeviceObject, Irp,
2916 
2918  {
2919  PSTORAGE_SCSI_INFO_EXCEPTIONS infoExceptions;
2920  MODE_INFO_EXCEPTIONS modeInfo = {0};
2921 
2923  {
2924  infoExceptions = (PSTORAGE_SCSI_INFO_EXCEPTIONS)Buffer;
2925 
2927  modeInfo.PageLength = sizeof(MODE_INFO_EXCEPTIONS) - 2;
2928 
2929  modeInfo.PSBit = 0;
2930  modeInfo.Flags = infoExceptions->Flags;
2931 
2932  modeInfo.ReportMethod = infoExceptions->MRIE;
2933 
2934  REVERSE_BYTES(&modeInfo.IntervalTimer[0],
2935  &infoExceptions->IntervalTimer);
2936 
2937  REVERSE_BYTES(&modeInfo.ReportCount[0],
2938  &infoExceptions->ReportCount);
2939 
2940  if (modeInfo.Perf == 1)
2941  {
2942  diskData->AllowFPPerfHit = FALSE;
2943  } else {
2944  diskData->AllowFPPerfHit = TRUE;
2945  }
2946 
2947  status = DiskSetInfoExceptionInformation(fdoExtension,
2948  &modeInfo);
2949  } else {
2951  }
2952 
2953  } else if (GuidIndex <= SmartThresholdsGuid)
2954  {
2956  } else {
2958  }
2959 
2960  TracePrint((TRACE_LEVEL_INFORMATION, TRACE_FLAG_WMI, "Disk: DiskSetWmiDataBlock Device %p, Irp %p returns %lx\n",
2961  DeviceObject, Irp, status));
2962 
2964  Irp,
2965  status,
2966  0,
2967  IO_NO_INCREMENT);
2968 
2969  return status;
2970 }
#define MODE_PAGE_FAULT_REPORTING
Definition: scsi.h:218
struct _DISK_DATA * PDISK_DATA
UCHAR IntervalTimer[4]
Definition: scsi.h:3028
struct _STORAGE_SCSI_INFO_EXCEPTIONS * PSTORAGE_SCSI_INFO_EXCEPTIONS
#define STATUS_WMI_GUID_NOT_FOUND
Definition: ntstatus.h:776
_In_ PIRP Irp
Definition: csq.h:116
#define TRUE
Definition: types.h:120
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
#define REVERSE_BYTES(Destination, Source)
Definition: scsi.h:3465
#define STATUS_WMI_READ_ONLY
Definition: ntstatus.h:818
#define TRACE_LEVEL_INFORMATION
Definition: storswtr.h:29
BOOLEAN AllowFPPerfHit
Definition: disk.h:332
NTSTATUS DiskSetInfoExceptionInformation(IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, IN PMODE_INFO_EXCEPTIONS PageData)
Definition: disk.c:2981
#define FALSE
Definition: types.h:117
#define ScsiInfoExceptionsGuid
Definition: diskwmi.c:152
_In_ PIRP _In_ ULONG GuidIndex
Definition: classpnp.h:418
Definition: bufpool.h:45
#define BufferSize
Definition: mmc.h:75
#define SmartThresholdsGuid
Definition: diskwmi.c:151
SCSIPORT_API NTSTATUS NTAPI ClassWmiCompleteRequest(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp, _In_ NTSTATUS Status, _In_ ULONG BufferUsed, _In_ CCHAR PriorityBoost)
Definition: classwmi.c:1009
UCHAR ReportCount[4]
Definition: scsi.h:3029
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
struct _MODE_INFO_EXCEPTIONS MODE_INFO_EXCEPTIONS
#define IO_NO_INCREMENT
Definition: iotypes.h:581
static SERVICE_STATUS status
Definition: service.c:31
#define PAGED_CODE()
Definition: ps.c:97

Referenced by DriverEntry().

◆ DiskFdoSetWmiDataItem()

NTSTATUS NTAPI DiskFdoSetWmiDataItem ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp,
IN ULONG  GuidIndex,
IN ULONG  DataItemId,
IN ULONG  BufferSize,
IN PUCHAR  Buffer 
)

Definition at line 2975 of file diskwmi.c.

3013 {
3014  NTSTATUS status;
3015 
3016  PAGED_CODE();
3017 
3018  TracePrint((TRACE_LEVEL_INFORMATION, TRACE_FLAG_WMI, "Disk: DiskSetWmiDataItem, Device %p, Irp %p, GuiIndex %d, DataId %d\n"
3019  " BufferSize %#x Buffer %p\n",
3020  DeviceObject, Irp,
3022 
3024  {
3026  } else {
3028  }
3029 
3030  TracePrint((TRACE_LEVEL_INFORMATION, TRACE_FLAG_WMI, "Disk: DiskSetWmiDataItem Device %p, Irp %p returns %lx\n",
3031  DeviceObject, Irp, status));
3032 
3034  Irp,
3035  status,
3036  0,
3037  IO_NO_INCREMENT);
3038 
3039  return status;
3040 }
#define STATUS_WMI_GUID_NOT_FOUND
Definition: ntstatus.h:776
_In_ PIRP Irp
Definition: csq.h:116
_In_ PIRP _In_ ULONG _In_ ULONG DataItemId
Definition: classpnp.h:436
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_WMI_READ_ONLY
Definition: ntstatus.h:818
#define TRACE_LEVEL_INFORMATION
Definition: storswtr.h:29
_In_ PIRP _In_ ULONG GuidIndex
Definition: classpnp.h:418
Definition: bufpool.h:45
#define BufferSize
Definition: mmc.h:75
#define SmartThresholdsGuid
Definition: diskwmi.c:151
SCSIPORT_API NTSTATUS NTAPI ClassWmiCompleteRequest(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp, _In_ NTSTATUS Status, _In_ ULONG BufferUsed, _In_ CCHAR PriorityBoost)
Definition: classwmi.c:1009
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
#define IO_NO_INCREMENT
Definition: iotypes.h:581
static SERVICE_STATUS status
Definition: service.c:31
#define PAGED_CODE()
Definition: ps.c:97

Referenced by DriverEntry().

◆ DiskFlushDispatch()

VOID DiskFlushDispatch ( IN PDEVICE_OBJECT  Fdo,
IN PDISK_GROUP_CONTEXT  FlushContext 
)

Definition at line 1530 of file disk.c.

1554 {
1555  PFUNCTIONAL_DEVICE_EXTENSION fdoExt = Fdo->DeviceExtension;
1556  PSCSI_REQUEST_BLOCK srb = &FlushContext->Srb.Srb;
1557  PSTORAGE_REQUEST_BLOCK srbEx = &FlushContext->Srb.SrbEx;
1559  PSTOR_ADDR_BTL8 storAddrBtl8;
1560  PSRBEX_DATA_SCSI_CDB16 srbExDataCdb16;
1561  NTSTATUS SyncCacheStatus = STATUS_SUCCESS;
1562 
1563  //
1564  // Fill in the srb fields appropriately
1565  //
1566  if (fdoExt->AdapterDescriptor->SrbType == SRB_TYPE_STORAGE_REQUEST_BLOCK) {
1567  RtlZeroMemory(srbEx, sizeof(FlushContext->Srb.SrbExBuffer));
1568 
1569  srbEx->Length = FIELD_OFFSET(STORAGE_REQUEST_BLOCK, Signature);
1570  srbEx->Function = SRB_FUNCTION_STORAGE_REQUEST_BLOCK;
1571  srbEx->Signature = SRB_SIGNATURE;
1572  srbEx->Version = STORAGE_REQUEST_BLOCK_VERSION_1;
1573  srbEx->SrbLength = sizeof(FlushContext->Srb.SrbExBuffer);
1574  srbEx->RequestPriority = IoGetIoPriorityHint(FlushContext->CurrIrp);
1575  srbEx->AddressOffset = sizeof(STORAGE_REQUEST_BLOCK);
1576  srbEx->TimeOutValue = fdoExt->TimeOutValue * 4;
1577  srbEx->RequestTag = SP_UNTAGGED;
1578  srbEx->RequestAttribute = SRB_SIMPLE_TAG_REQUEST;
1579  srbEx->SrbFlags = fdoExt->SrbFlags;
1580 
1581  //
1582  // Set up address fields
1583  //
1584 
1585  storAddrBtl8 = (PSTOR_ADDR_BTL8) ((PUCHAR)srbEx + srbEx->AddressOffset);
1586  storAddrBtl8->Type = STOR_ADDRESS_TYPE_BTL8;
1587  storAddrBtl8->AddressLength = STOR_ADDR_BTL8_ADDRESS_LENGTH;
1588 
1589  } else {
1591 
1593  srb->TimeOutValue = fdoExt->TimeOutValue * 4;
1594  srb->QueueTag = SP_UNTAGGED;
1596  srb->SrbFlags = fdoExt->SrbFlags;
1597  }
1598 
1599  //
1600  // If write caching is enabled then send down a synchronize cache request
1601  //
1602  if (TEST_FLAG(fdoExt->DeviceFlags, DEV_WRITE_CACHE))
1603  {
1604 
1605  if (fdoExt->AdapterDescriptor->SrbType == SRB_TYPE_STORAGE_REQUEST_BLOCK) {
1606  srbEx->SrbFunction = SRB_FUNCTION_EXECUTE_SCSI;
1607  srbEx->NumSrbExData = 1;
1608 
1609  //
1610  // Set up SCSI SRB extended data fields
1611  //
1612 
1613  srbEx->SrbExDataOffset[0] = sizeof(STORAGE_REQUEST_BLOCK) +
1614  sizeof(STOR_ADDR_BTL8);
1615  if ((srbEx->SrbExDataOffset[0] + sizeof(SRBEX_DATA_SCSI_CDB16)) <= srbEx->SrbLength) {
1616  srbExDataCdb16 = (PSRBEX_DATA_SCSI_CDB16)((PUCHAR)srbEx + srbEx->SrbExDataOffset[0]);
1617  srbExDataCdb16->Type = SrbExDataTypeScsiCdb16;
1618  srbExDataCdb16->Length = SRBEX_DATA_SCSI_CDB16_LENGTH;
1619  srbExDataCdb16->CdbLength = 10;
1620  srbExDataCdb16->Cdb[0] = SCSIOP_SYNCHRONIZE_CACHE;
1621  } else {
1622  // Should not happen
1623  NT_ASSERT(FALSE);
1624  return;
1625  }
1626 
1627  } else {
1629  srb->CdbLength = 10;
1630  srb->Cdb[0] = SCSIOP_SYNCHRONIZE_CACHE;
1631  }
1632 
1633  TracePrint((TRACE_LEVEL_VERBOSE, TRACE_FLAG_SCSI, "DiskFlushDispatch: sending sync cache\n"));
1634 
1635  SyncCacheStatus = ClassSendSrbSynchronous(Fdo, srb, NULL, 0, TRUE);
1636  }
1637 
1638  //
1639  // Set up a FLUSH SRB
1640  //
1641  if (fdoExt->AdapterDescriptor->SrbType == SRB_TYPE_STORAGE_REQUEST_BLOCK) {
1642  srbEx->SrbFunction = SRB_FUNCTION_FLUSH;
1643  srbEx->NumSrbExData = 0;
1644  srbEx->SrbExDataOffset[0] = 0;
1645  srbEx->OriginalRequest = FlushContext->CurrIrp;
1646  srbEx->SrbStatus = 0;
1647 
1648  //
1649  // Make sure that this srb does not get freed
1650  //
1651  SET_FLAG(srbEx->SrbFlags, SRB_CLASS_FLAGS_PERSISTANT);
1652 
1653  } else {
1655  srb->CdbLength = 0;
1656  srb->OriginalRequest = FlushContext->CurrIrp;
1657  srb->SrbStatus = 0;
1658  srb->ScsiStatus = 0;
1659 
1660  //
1661  // Make sure that this srb does not get freed
1662  //
1664  }
1665 
1666  //
1667  // Make sure that this request does not get retried
1668  //
1669  irpSp = IoGetCurrentIrpStackLocation(FlushContext->CurrIrp);
1670 
1671  irpSp->Parameters.Others.Argument4 = (PVOID) 0;
1672 
1673  //
1674  // Fill in the irp fields appropriately
1675  //
1676  irpSp = IoGetNextIrpStackLocation(FlushContext->CurrIrp);
1677 
1678  irpSp->MajorFunction = IRP_MJ_SCSI;
1679  irpSp->Parameters.Scsi.Srb = srb;
1680 
1681  IoSetCompletionRoutine(FlushContext->CurrIrp, DiskFlushComplete, (PVOID)SyncCacheStatus, TRUE, TRUE, TRUE);
1682 
1683  TracePrint((TRACE_LEVEL_VERBOSE, TRACE_FLAG_SCSI, "DiskFlushDispatch: sending srb flush on irp %p\n", FlushContext->CurrIrp));
1684 
1685  //
1686  // Send down the flush request
1687  //
1688  IoCallDriver(((PCOMMON_DEVICE_EXTENSION)fdoExt)->LowerDeviceObject, FlushContext->CurrIrp);
1689 }
#define STOR_ADDRESS_TYPE_BTL8
Definition: scsi.h:3525
#define SRB_TYPE_STORAGE_REQUEST_BLOCK
Definition: srb.h:655
#define SCSIOP_SYNCHRONIZE_CACHE
Definition: cdrw_hw.h:918
ULONG SrbFlags
Definition: srb.h:252
PVOID OriginalRequest
Definition: srb.h:258
UCHAR Cdb[16]
Definition: srb.h:271
#define STORAGE_REQUEST_BLOCK_VERSION_1
Definition: srb.h:608
struct STOR_ADDRESS_ALIGN _STOR_ADDR_BTL8 * PSTOR_ADDR_BTL8
#define TRUE
Definition: types.h:120
unsigned char * PUCHAR
Definition: retypes.h:3
LONG NTSTATUS
Definition: precomp.h:26
UCHAR CdbLength
Definition: srb.h:250
UCHAR QueueAction
Definition: srb.h:249
ULONG TimeOutValue
Definition: srb.h:254
UCHAR SrbStatus
Definition: srb.h:243
#define DEV_WRITE_CACHE
Definition: class2.h:21
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:498
#define SP_UNTAGGED
Definition: srb.h:225
#define IRP_MJ_SCSI
struct SRB_ALIGN _SRBEX_DATA_SCSI_CDB16 SRBEX_DATA_SCSI_CDB16
#define FALSE
Definition: types.h:117
#define TRACE_LEVEL_VERBOSE
Definition: storswtr.h:30
UCHAR ScsiStatus
Definition: srb.h:244
#define STOR_ADDR_BTL8_ADDRESS_LENGTH
Definition: scsi.h:3528
#define SRB_CLASS_FLAGS_PERSISTANT
Definition: classpnp.h:20
struct SRB_ALIGN _SRBEX_DATA_SCSI_CDB16 * PSRBEX_DATA_SCSI_CDB16
smooth NULL
Definition: ftsmooth.c:416
* PSTORAGE_REQUEST_BLOCK
Definition: srb.h:652
void * PVOID
Definition: retypes.h:9
UCHAR QueueTag
Definition: srb.h:248
#define TEST_FLAG(Flags, Bit)
Definition: cdrom.h:1495
#define SRB_FUNCTION_FLUSH
Definition: srb.h:315
NTSTATUS NTAPI ClassSendSrbSynchronous(_In_ PDEVICE_OBJECT Fdo, _Inout_ PSCSI_REQUEST_BLOCK _Srb, _In_reads_bytes_opt_(BufferLength) PVOID BufferAddress, _In_ ULONG BufferLength, _In_ BOOLEAN WriteToDevice)
Definition: class.c:4042
UCHAR Function
Definition: srb.h:242
PSTORAGE_ADAPTER_DESCRIPTOR AdapterDescriptor
Definition: classpnp.h:877
irpSp
Definition: iofuncs.h:2715
USHORT Length
Definition: srb.h:241
#define SRB_FUNCTION_STORAGE_REQUEST_BLOCK
Definition: srb.h:99
_In_z_ PCCHAR _In_ PDEVICE_OBJECT LowerDeviceObject
Definition: classpnp.h:982
#define SRB_SIGNATURE
Definition: srb.h:607
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2691
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
STORAGE_REQUEST_BLOCK
Definition: srb.h:652
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define SRB_SIMPLE_TAG_REQUEST
Definition: srb.h:415
#define SCSI_REQUEST_BLOCK_SIZE
Definition: srb.h:274
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
NTKRNLVISTAAPI IO_PRIORITY_HINT NTAPI IoGetIoPriorityHint(_In_ PIRP Irp)
Definition: io.c:123
NTSTATUS NTAPI DiskFlushComplete(IN PDEVICE_OBJECT Fdo, IN PIRP Irp, IN PVOID Context)
Definition: disk.c:1695
struct STOR_ADDRESS_ALIGN _STOR_ADDR_BTL8 STOR_ADDR_BTL8
#define SRB_FUNCTION_EXECUTE_SCSI
Definition: srb.h:307
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
return STATUS_SUCCESS
Definition: btrfs.c:3014
static const WCHAR Signature[]
Definition: parser.c:141
#define SRBEX_DATA_SCSI_CDB16_LENGTH
Definition: srb.h:480
#define SET_FLAG(Flags, Bit)
Definition: cdrom.h:1493
#define NT_ASSERT
Definition: rtlfuncs.h:3312

Referenced by DiskShutdownFlush().

◆ DiskGenerateDeviceName()

NTSTATUS DiskGenerateDeviceName ( IN ULONG  DeviceNumber,
OUT PCCHAR *  RawName 
)

Definition at line 610 of file pnp.c.

639 {
640  CHAR rawName[64] = { 0 };
642 
643  PAGED_CODE();
644 
645  status = RtlStringCchPrintfA(rawName, sizeof(rawName) - 1, FDO_NAME_FORMAT, DeviceNumber,
647  if (!NT_SUCCESS(status)) {
648  TracePrint((TRACE_LEVEL_ERROR, TRACE_FLAG_PNP, "DiskGenerateDeviceName: Format FDO name failed with error: 0x%X\n", status));
649  return status;
650  }
651 
652  *RawName = ExAllocatePoolWithTag(PagedPool,
653  strlen(rawName) + 1,
654  DISK_TAG_NAME);
655 
656  if(*RawName == NULL) {
658  }
659 
660  status = RtlStringCchCopyA(*RawName, strlen(rawName) + 1, rawName);
661  if (!NT_SUCCESS(status)) {
662  TracePrint((TRACE_LEVEL_ERROR, TRACE_FLAG_PNP, "DiskGenerateDeviceName: Device name copy failed with error: 0x%X\n", status));
663  FREE_POOL(*RawName);
664  return status;
665  }
666 
667  TracePrint((TRACE_LEVEL_INFORMATION, TRACE_FLAG_PNP, "DiskGenerateDeviceName: generated \"%s\"\n", rawName));
668 
669  return STATUS_SUCCESS;
670 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char CHAR
Definition: xmlstorage.h:175
LONG NTSTATUS
Definition: precomp.h:26
#define TRACE_LEVEL_INFORMATION
Definition: storswtr.h:29
#define FREE_POOL(_PoolPtr)
Definition: cdrom.h:782
NTSTRSAFEVAPI RtlStringCchPrintfA(_Out_writes_(cchDest) _Always_(_Post_z_) NTSTRSAFE_PSTR pszDest, _In_ size_t cchDest, _In_ _Printf_format_string_ NTSTRSAFE_PCSTR pszFormat,...)
Definition: ntstrsafe.h:1085
smooth NULL
Definition: ftsmooth.c:416
#define FDO_NAME_FORMAT
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define DISK_TAG_NAME
Definition: disk.h:64
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
NTSTRSAFEAPI RtlStringCchCopyA(_Out_writes_(cchDest) _Always_(_Post_z_) NTSTRSAFE_PSTR pszDest, _In_ size_t cchDest, _In_ NTSTRSAFE_PCSTR pszSrc)
Definition: ntstrsafe.h:110
_In_ PCHAR _In_ ULONG DeviceNumber
Definition: classpnp.h:1229
return STATUS_SUCCESS
Definition: btrfs.c:3014
static SERVICE_STATUS status
Definition: service.c:31
ULONG diskDeviceSequenceNumber
Definition: pnp.c:35
#define PAGED_CODE()
Definition: ps.c:97

Referenced by DiskCreateFdo().

◆ DiskGetCacheInformation()

NTSTATUS NTAPI DiskGetCacheInformation ( IN PFUNCTIONAL_DEVICE_EXTENSION  FdoExtension,
IN PDISK_CACHE_INFORMATION  CacheInfo 
)

Definition at line 3015 of file disk.c.

3040 {
3041  PMODE_PARAMETER_HEADER modeData;
3042  PMODE_CACHING_PAGE pageData;
3043 
3044  ULONG length;
3045 
3046  PAGED_CODE();
3047 
3048 
3049 
3050  modeData = ExAllocatePoolWithTag(NonPagedPoolNxCacheAligned,
3053 
3054  if (modeData == NULL) {
3055 
3056  TracePrint((TRACE_LEVEL_ERROR, TRACE_FLAG_IOCTL, "DiskGetSetCacheInformation: Unable to allocate mode "
3057  "data buffer\n"));
3059  }
3060 
3061  RtlZeroMemory(modeData, MODE_DATA_SIZE);
3062 
3063  length = ClassModeSense(FdoExtension->DeviceObject,
3064  (PCHAR) modeData,
3067 
3068  if (length < sizeof(MODE_PARAMETER_HEADER)) {
3069 
3070  //
3071  // Retry the request in case of a check condition.
3072  //
3073 
3074  length = ClassModeSense(FdoExtension->DeviceObject,
3075  (PCHAR) modeData,
3078 
3079  if (length < sizeof(MODE_PARAMETER_HEADER)) {
3080 
3081  TracePrint((TRACE_LEVEL_ERROR, TRACE_FLAG_IOCTL, "DiskGetCacheInformation: Mode Sense failed\n"));
3082 
3083  FREE_POOL(modeData);
3084  return STATUS_IO_DEVICE_ERROR;
3085  }
3086  }
3087 
3088  //
3089  // If the length is greater than length indicated by the mode data reset
3090  // the data to the mode data.
3091  //
3092 
3093  if (length > (ULONG) (modeData->ModeDataLength + 1)) {
3094  length = modeData->ModeDataLength + 1;
3095  }
3096 
3097  //
3098  // Check to see if the write cache is enabled.
3099  //
3100 
3101  pageData = ClassFindModePage((PCHAR) modeData,
3102  length,
3104  TRUE);
3105 
3106  //
3107  // Check if valid caching page exists.
3108  //
3109 
3110  if (pageData == NULL) {
3111  TracePrint((TRACE_LEVEL_ERROR, TRACE_FLAG_IOCTL, "DiskGetCacheInformation: Unable to find caching mode page.\n"));
3112  FREE_POOL(modeData);
3113  return STATUS_NOT_SUPPORTED;
3114  }
3115 
3116  //
3117  // Copy the parameters over.
3118  //
3119 
3120  RtlZeroMemory(CacheInfo, sizeof(DISK_CACHE_INFORMATION));
3121 
3122  CacheInfo->ParametersSavable = pageData->PageSavable;
3123 
3124  CacheInfo->ReadCacheEnabled = !(pageData->ReadDisableCache);
3125  CacheInfo->WriteCacheEnabled = pageData->WriteCacheEnable;
3126 
3127 
3128  //
3129  // Translate the values in the mode page into the ones defined in
3130  // ntdddisk.h.
3131  //
3132 
3133  CacheInfo->ReadRetentionPriority =
3135  CacheInfo->WriteRetentionPriority =
3137 
3138  CacheInfo->DisablePrefetchTransferLength =
3139  ((pageData->DisablePrefetchTransfer[0] << 8) +
3140  pageData->DisablePrefetchTransfer[1]);
3141 
3142  CacheInfo->ScalarPrefetch.Minimum =
3143  ((pageData->MinimumPrefetch[0] << 8) + pageData->MinimumPrefetch[1]);
3144 
3145  CacheInfo->ScalarPrefetch.Maximum =
3146  ((pageData->MaximumPrefetch[0] << 8) + pageData->MaximumPrefetch[1]);
3147 
3148  if(pageData->MultiplicationFactor) {
3149  CacheInfo->PrefetchScalar = TRUE;
3150  CacheInfo->ScalarPrefetch.MaximumBlocks =
3151  ((pageData->MaximumPrefetchCeiling[0] << 8) +
3152  pageData->MaximumPrefetchCeiling[1]);
3153  }
3154 
3155 
3156  FREE_POOL(modeData);
3157  return STATUS_SUCCESS;
3158 }
signed char * PCHAR
Definition: retypes.h:7
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
UCHAR WriteCacheEnable
Definition: cdrw_hw.h:2779
#define MODE_PAGE_CACHING
Definition: cdrw_hw.h:846
#define TRUE
Definition: types.h:120
#define TRANSLATE_RETENTION_PRIORITY(_x)
Definition: disk.c:99
UCHAR ReadDisableCache
Definition: cdrw_hw.h:2777
UCHAR ReadRetensionPriority
Definition: cdrw_hw.h:2783
UCHAR MaximumPrefetch[2]
Definition: cdrw_hw.h:2787
#define STATUS_IO_DEVICE_ERROR
Definition: udferr_usr.h:179
#define FREE_POOL(_PoolPtr)
Definition: cdrom.h:782
#define MODE_DATA_SIZE
Definition: disk.c:164
UCHAR MultiplicationFactor
Definition: cdrw_hw.h:2778
smooth NULL
Definition: ftsmooth.c:416
#define DISK_TAG_DISABLE_CACHE
Definition: disk.h:56
PVOID NTAPI ClassFindModePage(_In_reads_bytes_(Length) PCHAR ModeSenseBuffer, _In_ ULONG Length, _In_ UCHAR PageMode, _In_ BOOLEAN Use6Byte)
Definition: class.c:6798
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
UCHAR MinimumPrefetch[2]
Definition: cdrw_hw.h:2786
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
ULONG NTAPI ClassModeSense(_In_ PDEVICE_OBJECT Fdo, _In_reads_bytes_(Length) PCHAR ModeSenseBuffer, _In_ ULONG Length, _In_ UCHAR PageMode)
Definition: class.c:6637
UCHAR DisablePrefetchTransfer[2]
Definition: cdrw_hw.h:2785
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:423
unsigned int ULONG
Definition: retypes.h:1
UCHAR MaximumPrefetchCeiling[2]
Definition: cdrw_hw.h:2788
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
UCHAR WriteRetensionPriority
Definition: cdrw_hw.h:2782
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define PAGED_CODE()

Referenced by DiskIoctlGetCacheInformation(), and DiskStartFdo().

◆ DiskGetInfoExceptionInformation()

NTSTATUS DiskGetInfoExceptionInformation ( IN PFUNCTIONAL_DEVICE_EXTENSION  FdoExtension,
OUT PMODE_INFO_EXCEPTIONS  ReturnPageData 
)

◆ DiskGetModePage()

NTSTATUS DiskGetModePage ( _In_ PDEVICE_OBJECT  Fdo,
_In_ UCHAR  PageMode,
_In_ UCHAR  PageControl,
_In_ PMODE_PARAMETER_HEADER  ModeData,
_Inout_ PULONG  ModeDataSize,
_Out_ PVOID PageData 
)

Definition at line 903 of file diskwmi.c.

911 {
912  ULONG size = 0;
913  PVOID pageData = NULL;
914 
915  PAGED_CODE();
916 
917  if (ModeData == NULL ||
918  ModeDataSize == NULL ||
919  *ModeDataSize < sizeof(MODE_PARAMETER_HEADER) ||
920  PageData == NULL) {
922  }
923 
924  RtlZeroMemory (ModeData, *ModeDataSize);
925 
926  size = ClassModeSenseEx(Fdo,
927  (PCHAR) ModeData,
928  *ModeDataSize,
929  PageMode,
930  PageControl);
931 
932  if (size < sizeof(MODE_PARAMETER_HEADER)) {
933 
934  //
935  // Retry the request in case of a check condition.
936  //
937  size = ClassModeSenseEx(Fdo,
938  (PCHAR) ModeData,
939  *ModeDataSize,
940  PageMode,
941  PageControl);
942 
943  if (size < sizeof(MODE_PARAMETER_HEADER)) {
944  TracePrint((TRACE_LEVEL_ERROR, TRACE_FLAG_WMI, "DiskGetModePage: Mode Sense for Page Mode %d with Page Control %d failed\n",
946  *ModeDataSize = 0;
947  return STATUS_IO_DEVICE_ERROR;
948  }
949  }
950 
951  //
952  // If the length is greater than length indicated by the mode data reset
953  // the data to the mode data.
954  //
955  if (size > (ULONG) (ModeData->ModeDataLength + 1)) {
956  size = ModeData->ModeDataLength + 1;
957  }
958 
959  *ModeDataSize = size;
960 
961  //
962  // Find the mode page
963  //
964  pageData = ClassFindModePage((PCHAR) ModeData,
965  size,
966  PageMode,
967  TRUE);
968 
969  if (pageData) {
970  *PageData = pageData;
971  return STATUS_SUCCESS;
972  } else {
973  *PageData = NULL;
974  return STATUS_NOT_SUPPORTED;
975  }
976 }
signed char * PCHAR
Definition: retypes.h:7
_In_ size_t _In_ UCHAR PageMode
Definition: cdrom.h:1325
#define TRUE
Definition: types.h:120
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_IO_DEVICE_ERROR
Definition: udferr_usr.h:179
_In_ ULONG _In_ UCHAR _In_ UCHAR PageControl
Definition: cdrom.h:1316
smooth NULL
Definition: ftsmooth.c:416
GLsizeiptr size
Definition: glext.h:5919
PVOID NTAPI ClassFindModePage(_In_reads_bytes_(Length) PCHAR ModeSenseBuffer, _In_ ULONG Length, _In_ UCHAR PageMode, _In_ BOOLEAN Use6Byte)
Definition: class.c:6798
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:423
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
ULONG NTAPI ClassModeSenseEx(_In_ PDEVICE_OBJECT Fdo, _In_reads_bytes_(Length) PCHAR ModeSenseBuffer, _In_ ULONG Length, _In_ UCHAR PageMode, _In_ UCHAR PageControl)
Definition: class.c:6656
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define PAGED_CODE()

Referenced by DiskEnableInfoExceptions().

◆ DiskInitFdo()

NTSTATUS NTAPI DiskInitFdo ( IN PDEVICE_OBJECT  Fdo)

Definition at line 200 of file pnp.c.

221 {
222  PFUNCTIONAL_DEVICE_EXTENSION fdoExtension = Fdo->DeviceExtension;
223  PDISK_DATA diskData = (PDISK_DATA) fdoExtension->CommonExtension.DriverData;
224 
225  ULONG srbFlags = 0;
226  ULONG timeOut = 0;
227  ULONG bytesPerSector;
228 
229  PULONG dmSkew;
230 
232 
233  PAGED_CODE();
234 
235  //
236  // Build the lookaside list for srb's for the physical disk. Should only
237  // need a couple. If this fails then we don't have an emergency SRB so
238  // fail the call to initialize.
239  //
240 
241  ClassInitializeSrbLookasideList((PCOMMON_DEVICE_EXTENSION) fdoExtension,
243 
244  if (fdoExtension->DeviceDescriptor->RemovableMedia)
245  {
246  SET_FLAG(Fdo->Characteristics, FILE_REMOVABLE_MEDIA);
247  }
248 
249  //
250  // Initialize the srb flags.
251  //
252 
253  //
254  // Because all requests share a common sense buffer, it is possible
255  // for the buffer to be overwritten if the port driver completes
256  // multiple failed requests that require a request sense before the
257  // class driver's completion routine can consume the data in the buffer.
258  // To prevent this, we allow the port driver to allocate a unique sense
259  // buffer each time it needs one. We are responsible for freeing this
260  // buffer. This also allows the adapter to be configured to support
261  // additional sense data beyond the minimum 18 bytes.
262  //
263 
265 
266  if (fdoExtension->DeviceDescriptor->CommandQueueing &&
267  fdoExtension->AdapterDescriptor->CommandQueueing) {
268 
270 
271  }
272 
273  //
274  // Look for controllers that require special flags.
275  //
276 
277  ClassScanForSpecial(fdoExtension, DiskBadControllers, DiskSetSpecialHacks);
278 
279  //
280  // Clear buffer for drive geometry.
281  //
282 
283  RtlZeroMemory(&(fdoExtension->DiskGeometry),
284  sizeof(DISK_GEOMETRY));
285 
286  //
287  // Allocate request sense buffer.
288  //
289 
290  fdoExtension->SenseData = ExAllocatePoolWithTag(NonPagedPoolNxCacheAligned,
293 
294  if (fdoExtension->SenseData == NULL) {
295 
296  //
297  // The buffer can not be allocated.
298  //
299 
300  TracePrint((TRACE_LEVEL_ERROR, TRACE_FLAG_PNP, "DiskInitFdo: Can not allocate request sense buffer\n"));
301 
303  return status;
304  }
305 
306  //
307  // Set the buffer size of SenseData
308  //
309 
310  fdoExtension->SenseDataLength = SENSE_BUFFER_SIZE_EX;
311 
312  //
313  // Physical device object will describe the entire
314  // device, starting at byte offset 0.
315