ReactOS  0.4.14-dev-342-gdc047f9
diskwmi.c File Reference
#include "disk.h"
#include <wmistr.h>
Include dependency graph for diskwmi.c:

Go to the source code of this file.

Macros

#define DiskGeometryGuid   0
 
#define SmartStatusGuid   1
 
#define SmartDataGuid   2
 
#define SmartPerformFunction   3
 
#define AllowDisallowPerformanceHit   1
 
#define EnableDisableHardwareFailurePrediction   2
 
#define EnableDisableFailurePredictionPolling   3
 
#define GetFailurePredictionCapability   4
 
#define EnableOfflineDiags   5
 
#define SmartEventGuid   4
 
#define SmartThresholdsGuid   5
 
#define ScsiInfoExceptionsGuid   6
 
#define DiskReadSmartData(FdoExtension, SrbControl, BufferSize)
 
#define DiskReadSmartThresholds(FdoExtension, SrbControl, BufferSize)
 
#define DiskReadSmartStatus(FdoExtension, SrbControl, BufferSize)
 
#define DiskGetIdentifyData(FdoExtension, SrbControl, BufferSize)
 

Functions

NTSTATUS NTAPI DiskSendFailurePredictIoctl (PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, PSTORAGE_PREDICT_FAILURE checkFailure)
 
NTSTATUS NTAPI DiskGetIdentifyInfo (PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, PBOOLEAN SupportSmart)
 
NTSTATUS NTAPI DiskDetectFailurePrediction (PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, PFAILURE_PREDICTION_METHOD FailurePredictCapability)
 
NTSTATUS NTAPI DiskReadFailurePredictThresholds (PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, PSTORAGE_FAILURE_PREDICT_THRESHOLDS DiskSmartThresholds)
 
NTSTATUS NTAPI DiskReadSmartLog (IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, IN UCHAR SectorCount, IN UCHAR LogAddress, OUT PUCHAR Buffer)
 
NTSTATUS NTAPI DiskWriteSmartLog (IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, IN UCHAR SectorCount, IN UCHAR LogAddress, IN PUCHAR Buffer)
 
void NTAPI DiskReregWorker (IN PVOID Context)
 
__inline NTSTATUS DiskEnableSmart (PFUNCTIONAL_DEVICE_EXTENSION FdoExtension)
 
__inline NTSTATUS DiskDisableSmart (PFUNCTIONAL_DEVICE_EXTENSION FdoExtension)
 
__inline NTSTATUS DiskEnableSmartAttributeAutosave (PFUNCTIONAL_DEVICE_EXTENSION FdoExtension)
 
__inline NTSTATUS DiskDisableSmartAttributeAutosave (PFUNCTIONAL_DEVICE_EXTENSION FdoExtension)
 
__inline NTSTATUS DiskExecuteSmartDiagnostics (PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, UCHAR Subcommand)
 
NTSTATUS NTAPI 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 NTAPI DiskEnableDisableFailurePrediction (PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, BOOLEAN Enable)
 
NTSTATUS NTAPI DiskEnableDisableFailurePredictPolling (PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, BOOLEAN Enable, ULONG PollTimeInSeconds)
 
NTSTATUS NTAPI DiskReadFailurePredictStatus (PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, PSTORAGE_FAILURE_PREDICT_STATUS DiskSmartStatus)
 
NTSTATUS NTAPI DiskReadFailurePredictData (PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, PSTORAGE_FAILURE_PREDICT_DATA DiskSmartData)
 
NTSTATUS NTAPI DiskInitializeReregistration (void)
 
NTSTATUS NTAPI DiskPostReregisterRequest (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS NTAPI DiskInfoExceptionComplete (PDEVICE_OBJECT DeviceObject, PIRP Irp, PVOID Context)
 
NTSTATUS NTAPI DiskInfoExceptionCheck (PFUNCTIONAL_DEVICE_EXTENSION FdoExtension)
 
NTSTATUS NTAPI DiskWmiFunctionControl (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN ULONG GuidIndex, IN CLASSENABLEDISABLEFUNCTION Function, IN BOOLEAN Enable)
 
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)
 

Variables

WORK_QUEUE_ITEM DiskReregWorkItem
 
SINGLE_LIST_ENTRY DiskReregHead
 
KSPIN_LOCK DiskReregSpinlock
 
LONG DiskReregWorkItems
 
GUIDREGINFO DiskWmiFdoGuidList []
 
GUID DiskPredictFailureEventGuid = WMI_STORAGE_PREDICT_FAILURE_EVENT_GUID
 

Macro Definition Documentation

◆ AllowDisallowPerformanceHit

#define AllowDisallowPerformanceHit   1

Definition at line 150 of file diskwmi.c.

◆ DiskGeometryGuid

#define DiskGeometryGuid   0

Definition at line 146 of file diskwmi.c.

◆ DiskGetIdentifyData

#define DiskGetIdentifyData (   FdoExtension,
  SrbControl,
  BufferSize 
)
Value:
ID_CMD, \
0, \
0, \
0, \
(SrbControl), \
NTSTATUS NTAPI 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)
Definition: diskwmi.c:493
#define ID_CMD
Definition: helper.h:20
#define BufferSize
Definition: classpnp.h:419
#define IOCTL_SCSI_MINIPORT_IDENTIFY
Definition: cdrw_hw.h:1458

Definition at line 276 of file diskwmi.c.

◆ DiskReadSmartData

#define DiskReadSmartData (   FdoExtension,
  SrbControl,
  BufferSize 
)
Value:
0, \
0, \
(SrbControl), \
#define IOCTL_SCSI_MINIPORT_READ_SMART_ATTRIBS
Definition: cdrw_hw.h:1459
NTSTATUS NTAPI 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)
Definition: diskwmi.c:493
#define BufferSize
Definition: classpnp.h:419
#define READ_ATTRIBUTES
Definition: ntdddisk.h:633
#define SMART_CMD
Definition: helper.h:21

Definition at line 216 of file diskwmi.c.

◆ DiskReadSmartStatus

#define DiskReadSmartStatus (   FdoExtension,
  SrbControl,
  BufferSize 
)
Value:
0, \
0, \
(SrbControl), \
NTSTATUS NTAPI 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)
Definition: diskwmi.c:493
#define RETURN_SMART_STATUS
Definition: ntdddisk.h:642
#define IOCTL_SCSI_MINIPORT_RETURN_STATUS
Definition: cdrw_hw.h:1463
#define BufferSize
Definition: classpnp.h:419
#define SMART_CMD
Definition: helper.h:21

Definition at line 256 of file diskwmi.c.

◆ DiskReadSmartThresholds

#define DiskReadSmartThresholds (   FdoExtension,
  SrbControl,
  BufferSize 
)
Value:
0, \
0, \
(SrbControl), \
NTSTATUS NTAPI 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)
Definition: diskwmi.c:493
#define IOCTL_SCSI_MINIPORT_READ_SMART_THRESHOLDS
Definition: cdrw_hw.h:1460
#define READ_THRESHOLDS
Definition: ntdddisk.h:634
#define BufferSize
Definition: classpnp.h:419
#define SMART_CMD
Definition: helper.h:21

Definition at line 236 of file diskwmi.c.

◆ EnableDisableFailurePredictionPolling

#define EnableDisableFailurePredictionPolling   3

Definition at line 152 of file diskwmi.c.

◆ EnableDisableHardwareFailurePrediction

#define EnableDisableHardwareFailurePrediction   2

Definition at line 151 of file diskwmi.c.

◆ EnableOfflineDiags

#define EnableOfflineDiags   5

Definition at line 154 of file diskwmi.c.

◆ GetFailurePredictionCapability

#define GetFailurePredictionCapability   4

Definition at line 153 of file diskwmi.c.

◆ ScsiInfoExceptionsGuid

#define ScsiInfoExceptionsGuid   6

Definition at line 158 of file diskwmi.c.

◆ SmartDataGuid

#define SmartDataGuid   2

Definition at line 148 of file diskwmi.c.

◆ SmartEventGuid

#define SmartEventGuid   4

Definition at line 156 of file diskwmi.c.

◆ SmartPerformFunction

#define SmartPerformFunction   3

Definition at line 149 of file diskwmi.c.

◆ SmartStatusGuid

#define SmartStatusGuid   1

Definition at line 147 of file diskwmi.c.

◆ SmartThresholdsGuid

#define SmartThresholdsGuid   5

Definition at line 157 of file diskwmi.c.

Function Documentation

◆ DiskDetectFailurePrediction()

NTSTATUS NTAPI DiskDetectFailurePrediction ( PFUNCTIONAL_DEVICE_EXTENSION  FdoExtension,
PFAILURE_PREDICTION_METHOD  FailurePredictCapability 
)

Definition at line 1778 of file diskwmi.c.

1810 {
1812  PDISK_DATA diskData = (PDISK_DATA)(commonExtension->DriverData);
1813  BOOLEAN supportFP;
1814  NTSTATUS status;
1815  STORAGE_PREDICT_FAILURE checkFailure;
1816  STORAGE_FAILURE_PREDICT_STATUS diskSmartStatus;
1817  //BOOLEAN logErr;
1818 
1819  PAGED_CODE();
1820 
1821  //
1822  // Assume no failure predict mechanisms
1823  //
1824  *FailurePredictCapability = FailurePredictionNone;
1825 
1826  //
1827  // See if this is an IDE drive that supports SMART. If so enable SMART
1828  // and then ensure that it supports the SMART READ STATUS command
1829  //
1831  &supportFP);
1832 
1833  if (supportFP)
1834  {
1836  if (NT_SUCCESS(status))
1837  {
1838  *FailurePredictCapability = FailurePredictionSmart;
1839 
1841  &diskSmartStatus);
1842 
1843  DebugPrint((1, "Disk: Device %p %s IDE SMART\n",
1844  FdoExtension->DeviceObject,
1845  NT_SUCCESS(status) ? "does" : "does not"));
1846 
1847  if (! NT_SUCCESS(status))
1848  {
1849  *FailurePredictCapability = FailurePredictionNone;
1850  }
1851  }
1852  return(status);
1853  }
1854 
1855  //
1856  // See if there is a a filter driver to intercept
1857  // IOCTL_STORAGE_PREDICT_FAILURE
1858  //
1860  &checkFailure);
1861 
1862  DebugPrint((1, "Disk: Device %p %s IOCTL_STORAGE_FAILURE_PREDICT\n",
1863  FdoExtension->DeviceObject,
1864  NT_SUCCESS(status) ? "does" : "does not"));
1865 
1866  if (NT_SUCCESS(status))
1867  {
1868  *FailurePredictCapability = FailurePredictionIoctl;
1869  if (checkFailure.PredictFailure)
1870  {
1871  checkFailure.PredictFailure = 512;
1873  (PUCHAR)&checkFailure,
1874  sizeof(checkFailure),
1875  (BOOLEAN)(FdoExtension->FailurePredicted == FALSE),
1876  0x11,
1877  diskData->ScsiAddress.PathId,
1878  diskData->ScsiAddress.TargetId,
1879  diskData->ScsiAddress.Lun);
1880 
1881  FdoExtension->FailurePredicted = TRUE;
1882  }
1883  return(status);
1884  }
1885 
1886  //
1887  // Finally we assume it will not be a scsi smart drive. but
1888  // we'll also send off an asynchronous mode sense so that if
1889  // it is SMART we'll reregister the device object
1890  //
1891 
1893 
1894  *FailurePredictCapability = FailurePredictionNone;
1895 
1896  return(STATUS_SUCCESS);
1897 }
UCHAR PathId
Definition: scsi_port.h:149
struct _DISK_DATA * PDISK_DATA
#define TRUE
Definition: types.h:120
VOID NTAPI ClassNotifyFailurePredicted(PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, PUCHAR Buffer, ULONG BufferSize, BOOLEAN LogError, ULONG UniqueErrorValue, UCHAR PathId, UCHAR TargetId, UCHAR Lun)
Definition: autorun.c:3468
unsigned char * PUCHAR
Definition: retypes.h:3
LONG NTSTATUS
Definition: precomp.h:26
SCSI_ADDRESS ScsiAddress
Definition: disk.h:236
UCHAR TargetId
Definition: scsi_port.h:150
#define PAGED_CODE()
Definition: video.h:57
NTSTATUS NTAPI DiskSendFailurePredictIoctl(PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, PSTORAGE_PREDICT_FAILURE checkFailure)
Definition: diskwmi.c:833
unsigned char BOOLEAN
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
struct _COMMON_DEVICE_EXTENSION * PCOMMON_DEVICE_EXTENSION
NTSTATUS NTAPI DiskGetIdentifyInfo(PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, PBOOLEAN SupportSmart)
Definition: diskwmi.c:792
ULONG NTAPI DebugPrint(IN PSTRING DebugString, IN ULONG ComponentId, IN ULONG Level)
Definition: debug.c:23
NTSTATUS NTAPI DiskReadFailurePredictStatus(PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, PSTORAGE_FAILURE_PREDICT_STATUS DiskSmartStatus)
Definition: diskwmi.c:1007
NTSTATUS NTAPI DiskInfoExceptionCheck(PFUNCTIONAL_DEVICE_EXTENSION FdoExtension)
Definition: diskwmi.c:1562
__inline NTSTATUS DiskEnableSmart(PFUNCTIONAL_DEVICE_EXTENSION FdoExtension)
Definition: diskwmi.c:293
return STATUS_SUCCESS
Definition: btrfs.c:2938
static SERVICE_STATUS status
Definition: service.c:31
Definition: ps.c:97

Referenced by DiskInitFdo().

◆ DiskDisableSmart()

__inline NTSTATUS DiskDisableSmart ( PFUNCTIONAL_DEVICE_EXTENSION  FdoExtension)

Definition at line 314 of file diskwmi.c.

317 {
318  UCHAR srbControl[sizeof(SRB_IO_CONTROL) + sizeof(SENDCMDINPARAMS)];
319  ULONG bufferSize = sizeof(srbControl);
322  SMART_CMD,
324  0,
325  0,
326  (PSRB_IO_CONTROL)srbControl,
327  &bufferSize);
328 }
NTSTATUS NTAPI 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)
Definition: diskwmi.c:493
#define DISABLE_SMART
Definition: ntdddisk.h:641
unsigned char UCHAR
Definition: xmlstorage.h:181
#define SMART_CMD
Definition: helper.h:21
struct _SRB_IO_CONTROL SRB_IO_CONTROL
unsigned int ULONG
Definition: retypes.h:1
#define IOCTL_SCSI_MINIPORT_DISABLE_SMART
Definition: cdrw_hw.h:1462

Referenced by DiskEnableDisableFailurePrediction().

◆ DiskDisableSmartAttributeAutosave()

__inline NTSTATUS DiskDisableSmartAttributeAutosave ( PFUNCTIONAL_DEVICE_EXTENSION  FdoExtension)

Definition at line 354 of file diskwmi.c.

357 {
358  UCHAR srbControl[sizeof(SRB_IO_CONTROL) + sizeof(SENDCMDINPARAMS)];
359  ULONG bufferSize = sizeof(srbControl);
362  SMART_CMD,
364  0x00,
365  0,
366  (PSRB_IO_CONTROL)srbControl,
367  &bufferSize);
368 }
#define ENABLE_DISABLE_AUTOSAVE
Definition: ntdddisk.h:635
NTSTATUS NTAPI 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)
Definition: diskwmi.c:493
#define IOCTL_SCSI_MINIPORT_ENABLE_DISABLE_AUTOSAVE
Definition: cdrw_hw.h:1464
unsigned char UCHAR
Definition: xmlstorage.h:181
#define SMART_CMD
Definition: helper.h:21
struct _SRB_IO_CONTROL SRB_IO_CONTROL
unsigned int ULONG
Definition: retypes.h:1

◆ DiskEnableDisableFailurePrediction()

NTSTATUS NTAPI DiskEnableDisableFailurePrediction ( PFUNCTIONAL_DEVICE_EXTENSION  FdoExtension,
BOOLEAN  Enable 
)

Definition at line 885 of file diskwmi.c.

906 {
908  PCOMMON_DEVICE_EXTENSION commonExtension = &(FdoExtension->CommonExtension);
909  PDISK_DATA diskData = (PDISK_DATA)(commonExtension->DriverData);
910 
911  PAGED_CODE();
912 
913  switch(diskData->FailurePredictionCapability)
914  {
916  {
917 
918  if (Enable)
919  {
921  } else {
923  }
924 
925  break;
926  }
927 
930  {
931  //
932  // We assume that the drive is already setup properly for
933  // failure prediction
934  //
936  break;
937  }
938 
939  default:
940  {
942  }
943  }
944  return status;
945 }
struct _DISK_DATA * PDISK_DATA
__inline NTSTATUS DiskDisableSmart(PFUNCTIONAL_DEVICE_EXTENSION FdoExtension)
Definition: diskwmi.c:314
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
#define PAGED_CODE()
Definition: video.h:57
FAILURE_PREDICTION_METHOD FailurePredictionCapability
Definition: disk.h:257
__inline NTSTATUS DiskEnableSmart(PFUNCTIONAL_DEVICE_EXTENSION FdoExtension)
Definition: diskwmi.c:293
return STATUS_SUCCESS
Definition: btrfs.c:2938
static SERVICE_STATUS status
Definition: service.c:31
Definition: ps.c:97

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

◆ DiskEnableDisableFailurePredictPolling()

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

Definition at line 949 of file diskwmi.c.

973 {
976  PDISK_DATA diskData = (PDISK_DATA)(commonExtension->DriverData);
977 
978  PAGED_CODE();
979 
980  if (Enable)
981  {
983  Enable);
984  } else {
986  }
987 
988  if (NT_SUCCESS(status))
989  {
991  Enable ? diskData->FailurePredictionCapability :
993  PollTimeInSeconds);
994 
995  //
996  // Even if this failed we do not want to disable FP on the
997  // hardware. FP is only ever disabled on the hardware by
998  // specific command of the user.
999  //
1000  }
1001 
1002  return status;
1003 }
struct _DISK_DATA * PDISK_DATA
LONG NTSTATUS
Definition: precomp.h:26
_In_ ULONGLONG _In_ ULONGLONG _In_ BOOLEAN Enable
Definition: ntddpcm.h:140
#define PAGED_CODE()
Definition: video.h:57
NTSTATUS NTAPI DiskEnableDisableFailurePrediction(PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, BOOLEAN Enable)
Definition: diskwmi.c:885
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
struct _COMMON_DEVICE_EXTENSION * PCOMMON_DEVICE_EXTENSION
NTSTATUS NTAPI ClassSetFailurePredictionPoll(PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, FAILURE_PREDICTION_METHOD FailurePredictionMethod, ULONG PollingPeriod)
Definition: autorun.c:3552
FAILURE_PREDICTION_METHOD FailurePredictionCapability
Definition: disk.h:257
return STATUS_SUCCESS
Definition: btrfs.c:2938
static SERVICE_STATUS status
Definition: service.c:31
Definition: ps.c:97

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

◆ DiskEnableSmart()

__inline NTSTATUS DiskEnableSmart ( PFUNCTIONAL_DEVICE_EXTENSION  FdoExtension)

Definition at line 293 of file diskwmi.c.

296 {
297  UCHAR srbControl[sizeof(SRB_IO_CONTROL) + sizeof(SENDCMDINPARAMS)];
298  ULONG bufferSize = sizeof(srbControl);
299 
302  SMART_CMD,
303  ENABLE_SMART,
304  0,
305  0,
306  (PSRB_IO_CONTROL)srbControl,
307  &bufferSize);
308 }
NTSTATUS NTAPI 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)
Definition: diskwmi.c:493
#define ENABLE_SMART
Definition: ntdddisk.h:640
#define IOCTL_SCSI_MINIPORT_ENABLE_SMART
Definition: cdrw_hw.h:1461
unsigned char UCHAR
Definition: xmlstorage.h:181
#define SMART_CMD
Definition: helper.h:21
struct _SRB_IO_CONTROL SRB_IO_CONTROL
unsigned int ULONG
Definition: retypes.h:1

Referenced by DiskDetectFailurePrediction(), and DiskEnableDisableFailurePrediction().

◆ DiskEnableSmartAttributeAutosave()

__inline NTSTATUS DiskEnableSmartAttributeAutosave ( PFUNCTIONAL_DEVICE_EXTENSION  FdoExtension)

Definition at line 334 of file diskwmi.c.

337 {
338  UCHAR srbControl[sizeof(SRB_IO_CONTROL) + sizeof(SENDCMDINPARAMS)];
339  ULONG bufferSize = sizeof(srbControl);
342  SMART_CMD,
344  0xf1,
345  0,
346  (PSRB_IO_CONTROL)srbControl,
347  &bufferSize);
348 }
#define ENABLE_DISABLE_AUTOSAVE
Definition: ntdddisk.h:635
NTSTATUS NTAPI 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)
Definition: diskwmi.c:493
#define IOCTL_SCSI_MINIPORT_ENABLE_DISABLE_AUTOSAVE
Definition: cdrw_hw.h:1464
unsigned char UCHAR
Definition: xmlstorage.h:181
#define SMART_CMD
Definition: helper.h:21
struct _SRB_IO_CONTROL SRB_IO_CONTROL
unsigned int ULONG
Definition: retypes.h:1

◆ DiskExecuteSmartDiagnostics()

__inline NTSTATUS DiskExecuteSmartDiagnostics ( PFUNCTIONAL_DEVICE_EXTENSION  FdoExtension,
UCHAR  Subcommand 
)

Definition at line 374 of file diskwmi.c.

378 {
379  UCHAR srbControl[sizeof(SRB_IO_CONTROL) + sizeof(SENDCMDINPARAMS)];
380  ULONG bufferSize = sizeof(srbControl);
383  SMART_CMD,
385  0,
386  Subcommand,
387  (PSRB_IO_CONTROL)srbControl,
388  &bufferSize);
389 }
NTSTATUS NTAPI 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)
Definition: diskwmi.c:493
#define EXECUTE_OFFLINE_DIAGS
Definition: ntdddisk.h:637
#define IOCTL_SCSI_MINIPORT_EXECUTE_OFFLINE_DIAGS
Definition: cdrw_hw.h:1466
unsigned char UCHAR
Definition: xmlstorage.h:181
#define SMART_CMD
Definition: helper.h:21
struct _SRB_IO_CONTROL SRB_IO_CONTROL
unsigned int ULONG
Definition: retypes.h:1

Referenced by DiskFdoExecuteWmiMethod().

◆ 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 2576 of file diskwmi.c.

2619 {
2622  PDISK_DATA diskData = (PDISK_DATA)(commonExtension->DriverData);
2623  ULONG sizeNeeded;
2624  NTSTATUS status;
2625 
2626  PAGED_CODE();
2627 
2628  DebugPrint((3, "Disk: DiskExecuteWmiMethod, DeviceObject %p, Irp %p, Guid Id %d, MethodId %d\n"
2629  " InBufferSize %#x, OutBufferSize %#x, Buffer %p\n",
2630  DeviceObject, Irp,
2632 
2633  switch(GuidIndex)
2634  {
2635  case SmartPerformFunction:
2636  {
2637 
2638  ASSERT((diskData->FailurePredictionCapability ==
2640  (diskData->FailurePredictionCapability ==
2642  (diskData->FailurePredictionCapability ==
2644 
2645 
2646  switch(MethodId)
2647  {
2648  //
2649  // void AllowPerformanceHit([in] boolean Allow)
2650  //
2652  {
2653  BOOLEAN allowPerfHit;
2654 
2655  sizeNeeded = 0;
2656  if (InBufferSize >= sizeof(BOOLEAN))
2657  {
2659 
2660  allowPerfHit = *((PBOOLEAN)Buffer);
2661  if (diskData->AllowFPPerfHit != allowPerfHit)
2662  {
2663  diskData->AllowFPPerfHit = allowPerfHit;
2664  if (diskData->FailurePredictionCapability ==
2666  {
2667  MODE_INFO_EXCEPTIONS modeInfo;
2668 
2669  status = DiskGetInfoExceptionInformation(fdoExtension,
2670  &modeInfo);
2671  if (NT_SUCCESS(status))
2672  {
2673  modeInfo.Perf = allowPerfHit ? 0 : 1;
2674  status = DiskSetInfoExceptionInformation(fdoExtension,
2675  &modeInfo);
2676  }
2677  }
2678  }
2679 
2680  DebugPrint((3, "DiskFdoWmiExecuteMethod: AllowPerformanceHit %x for device %p --> %lx\n",
2681  allowPerfHit,
2682  fdoExtension->DeviceObject,
2683  status));
2684  } else {
2686  }
2687  break;
2688  }
2689 
2690  //
2691  // void EnableDisableHardwareFailurePrediction([in] boolean Enable)
2692  //
2694  {
2695  BOOLEAN enable;
2696 
2697  sizeNeeded = 0;
2698  if (InBufferSize >= sizeof(BOOLEAN))
2699  {
2701  enable = *((PBOOLEAN)Buffer);
2702  if (! enable)
2703  {
2704  //
2705  // If we are disabling we need to also disable
2706  // polling
2707  //
2709  fdoExtension,
2710  enable,
2711  0);
2712  }
2713 
2715  fdoExtension,
2716  enable);
2717 
2718  DebugPrint((3, "DiskFdoWmiExecuteMethod: EnableDisableHardwareFailurePrediction: %x for device %p --> %lx\n",
2719  enable,
2720  fdoExtension->DeviceObject,
2721  status));
2722  } else {
2724  }
2725  break;
2726  }
2727 
2728  //
2729  // void EnableDisableFailurePredictionPolling(
2730  // [in] uint32 Period,
2731  // [in] boolean Enable)
2732  //
2734  {
2735  BOOLEAN enable;
2736  ULONG period;
2737 
2738  sizeNeeded = 0;
2739  if (InBufferSize >= (sizeof(ULONG) + sizeof(BOOLEAN)))
2740  {
2741  period = *((PULONG)Buffer);
2742  Buffer += sizeof(ULONG);
2743  enable = *((PBOOLEAN)Buffer);
2744 
2746  fdoExtension,
2747  enable,
2748  period);
2749 
2750  DebugPrint((3, "DiskFdoWmiExecuteMethod: EnableDisableFailurePredictionPolling: %x %x for device %p --> %lx\n",
2751  enable,
2752  period,
2753  fdoExtension->DeviceObject,
2754  status));
2755  } else {
2757  }
2758  break;
2759  }
2760 
2761  //
2762  // void GetFailurePredictionCapability([out] uint32 Capability)
2763  //
2765  {
2766  sizeNeeded = sizeof(ULONG);
2767  if (OutBufferSize >= sizeNeeded)
2768  {
2771  DebugPrint((3, "DiskFdoWmiExecuteMethod: GetFailurePredictionCapability: %x for device %p --> %lx\n",
2773  fdoExtension->DeviceObject,
2774  status));
2775  } else {
2777  }
2778  break;
2779  }
2780 
2781  //
2782  // void EnableOfflineDiags([out] boolean Success);
2783  //
2784  case EnableOfflineDiags:
2785  {
2786  sizeNeeded = sizeof(BOOLEAN);
2787  if (OutBufferSize >= sizeNeeded)
2788  {
2789  if (diskData->FailurePredictionCapability ==
2791  {
2792  //
2793  // Initiate or resume offline diagnostics.
2794  // This may cause a loss of performance
2795  // to the disk, but mayincrease the amount
2796  // of disk checking.
2797  //
2798  status = DiskExecuteSmartDiagnostics(fdoExtension,
2799  0);
2800 
2801  } else {
2803  }
2804 
2806 
2807  DebugPrint((3, "DiskFdoWmiExecuteMethod: EnableOfflineDiags for device %p --> %lx\n",
2808  fdoExtension->DeviceObject,
2809  status));
2810  } else {
2812  }
2813  break;
2814  }
2815 
2816  //
2817  // void ReadLogSectors([in] uint8 LogAddress,
2818  // [in] uint8 SectorCount,
2819  // [out] uint32 Length,
2820  // [out, WmiSizeIs("Length")] uint8 LogSectors[]
2821  // );
2822  //
2823  case ReadLogSectors:
2824  {
2825  sizeNeeded = 0;
2826  if (diskData->FailurePredictionCapability ==
2828  {
2829  if (InBufferSize >= sizeof(READ_LOG_SECTORS_IN))
2830  {
2831  PREAD_LOG_SECTORS_IN inParams;
2832  PREAD_LOG_SECTORS_OUT outParams;
2833  ULONG readSize;
2834 
2835  inParams = (PREAD_LOG_SECTORS_IN)Buffer;
2836  readSize = inParams->SectorCount * SMART_LOG_SECTOR_SIZE;
2837  sizeNeeded = FIELD_OFFSET(READ_LOG_SECTORS_OUT,
2838  LogSectors) + readSize;
2839 
2840  if (OutBufferSize >= sizeNeeded)
2841  {
2842  outParams = (PREAD_LOG_SECTORS_OUT)Buffer;
2843  status = DiskReadSmartLog(fdoExtension,
2844  inParams->SectorCount,
2845  inParams->LogAddress,
2846  outParams->LogSectors);
2847 
2848  if (NT_SUCCESS(status))
2849  {
2850  outParams->Length = readSize;
2851  } else {
2852  //
2853  // SMART command failure is
2854  // indicated by successful
2855  // execution, but no data returned
2856  //
2857  outParams->Length = 0;
2859  }
2860  } else {
2862  }
2863 
2864  } else {
2866  }
2867  } else {
2869  }
2870  break;
2871  }
2872 
2873  // void WriteLogSectors([in] uint8 LogAddress,
2874  // [in] uint8 SectorCount,
2875  // [in] uint32 Length,
2876  // [in, WmiSizeIs("Length")] uint8 LogSectors[],
2877  // [out] boolean Success
2878  // );
2879  case WriteLogSectors:
2880  {
2881  sizeNeeded = 0;
2882  if (diskData->FailurePredictionCapability ==
2884  {
2886  LogSectors))
2887  {
2888  PWRITE_LOG_SECTORS_IN inParams;
2889  PWRITE_LOG_SECTORS_OUT outParams;
2890  ULONG writeSize;
2891 
2892  inParams = (PWRITE_LOG_SECTORS_IN)Buffer;
2893  writeSize = inParams->SectorCount * SMART_LOG_SECTOR_SIZE;
2895  LogSectors) +
2896  writeSize))
2897  {
2898  sizeNeeded = sizeof(WRITE_LOG_SECTORS_OUT);
2899 
2900  if (OutBufferSize >= sizeNeeded)
2901  {
2902  outParams = (PWRITE_LOG_SECTORS_OUT)Buffer;
2903  status = DiskWriteSmartLog(fdoExtension,
2904  inParams->SectorCount,
2905  inParams->LogAddress,
2906  inParams->LogSectors);
2907 
2908  if (NT_SUCCESS(status))
2909  {
2910  outParams->Success = TRUE;
2911  } else {
2912  outParams->Success = FALSE;
2914  }
2915  } else {
2917  }
2918  } else {
2920  }
2921  } else {
2923  }
2924  } else {
2926  }
2927  break;
2928  }
2929 
2930  // void ExecuteSelfTest([in] uint8 Subcommand,
2931  // [out,
2932  // Values{"0", "1", "2"},
2933  // ValueMap{"Successful Completion",
2934  // "Captive Mode Required",
2935  // "Unsuccessful Completion"}
2936  // ]
2937  // uint32 ReturnCode);
2938  case ExecuteSelfTest:
2939  {
2940  sizeNeeded = 0;
2941  if (diskData->FailurePredictionCapability ==
2943  {
2944  if (InBufferSize >= sizeof(EXECUTE_SELF_TEST_IN))
2945  {
2946  sizeNeeded = sizeof(EXECUTE_SELF_TEST_OUT);
2947  if (OutBufferSize >= sizeNeeded)
2948  {
2949  PEXECUTE_SELF_TEST_IN inParam;
2950  PEXECUTE_SELF_TEST_OUT outParam;
2951 
2952  inParam = (PEXECUTE_SELF_TEST_IN)Buffer;
2953  outParam = (PEXECUTE_SELF_TEST_OUT)Buffer;
2954 
2955  if (DiskIsValidSmartSelfTest(inParam->Subcommand))
2956  {
2957  status = DiskExecuteSmartDiagnostics(fdoExtension,
2958  inParam->Subcommand);
2959  if (NT_SUCCESS(status))
2960  {
2961  //
2962  // Return self test executed
2963  // without a problem
2964  //
2965  outParam->ReturnCode = 0;
2966  } else {
2967  //
2968  // Return Self test execution
2969  // failed status
2970  //
2971  outParam->ReturnCode = 2;
2973  }
2974  } else {
2975  //
2976  // If self test subcommand requires
2977  // captive mode then return that
2978  // status
2979  //
2980  outParam->ReturnCode = 1;
2982  }
2983 
2984  } else {
2986  }
2987 
2988  } else {
2990  }
2991  } else {
2993  }
2994 
2995  break;
2996  }
2997 
2998  default :
2999  {
3000  sizeNeeded = 0;
3002  break;
3003  }
3004  }
3005 
3006  break;
3007  }
3008 
3009  case DiskGeometryGuid:
3010  case SmartStatusGuid:
3011  case SmartDataGuid:
3012  {
3013 
3014  sizeNeeded = 0;
3016  break;
3017  }
3018 
3019  default:
3020  {
3021  sizeNeeded = 0;
3023  }
3024  }
3025 
3026  DebugPrint((3, "Disk: DiskExecuteMethod Device %p, Irp %p returns %lx\n",
3027  DeviceObject, Irp, status));
3028 
3030  Irp,
3031  status,
3032  sizeNeeded,
3033  IO_NO_INCREMENT);
3034 
3035  return status;
3036 }
#define SMART_LOG_SECTOR_SIZE
Definition: ntdddisk.h:623
struct _DISK_DATA * PDISK_DATA
#define TRUE
Definition: types.h:120
NTSTATUS NTAPI DiskReadSmartLog(IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, IN UCHAR SectorCount, IN UCHAR LogAddress, OUT PUCHAR Buffer)
Definition: diskwmi.c:394
#define WriteLogSectors
Definition: wmidata.h:3387
#define STATUS_WMI_GUID_NOT_FOUND
Definition: ntstatus.h:762
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
_In_ PIRP _In_ ULONG _In_ ULONG _In_ ULONG _In_ ULONG OutBufferSize
Definition: classpnp.h:429
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
struct _WRITE_LOG_SECTORS_OUT * PWRITE_LOG_SECTORS_OUT
#define DiskGeometryGuid
Definition: diskwmi.c:146
BOOLEAN AllowFPPerfHit
Definition: disk.h:258
#define PAGED_CODE()
Definition: video.h:57
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
NTSTATUS NTAPI DiskEnableDisableFailurePrediction(PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, BOOLEAN Enable)
Definition: diskwmi.c:885
struct _EXECUTE_SELF_TEST_OUT * PEXECUTE_SELF_TEST_OUT
PVOID DeviceExtension
Definition: env_spec_w32.h:418
unsigned char BOOLEAN
_In_ PIRP _In_ ULONG GuidIndex
Definition: classpnp.h:401
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
_In_ PIRP _In_ ULONG _In_ ULONG MethodId
Definition: classpnp.h:429
_In_ PIRP _In_ ULONG _In_ ULONG _In_ ULONG InBufferSize
Definition: classpnp.h:429
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define DiskIsValidSmartSelfTest(Subcommand)
Definition: disk.h:533
struct _EXECUTE_SELF_TEST_OUT EXECUTE_SELF_TEST_OUT
NTSTATUS NTAPI DiskEnableDisableFailurePredictPolling(PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, BOOLEAN Enable, ULONG PollTimeInSeconds)
Definition: diskwmi.c:949
enum FAILURE_PREDICTION_METHOD * PFAILURE_PREDICTION_METHOD
#define SmartStatusGuid
Definition: diskwmi.c:147
NTSTATUS NTAPI DiskWriteSmartLog(IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, IN UCHAR SectorCount, IN UCHAR LogAddress, IN PUCHAR Buffer)
Definition: diskwmi.c:446
PDEVICE_OBJECT DeviceObject
Definition: classpnp.h:693
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
char * PBOOLEAN
Definition: retypes.h:11
#define EnableDisableFailurePredictionPolling
Definition: diskwmi.c:152
#define EnableDisableHardwareFailurePrediction
Definition: diskwmi.c:151
FAILURE_PREDICTION_METHOD FailurePredictionCapability
Definition: disk.h:257
ULONG NTAPI DebugPrint(IN PSTRING DebugString, IN ULONG ComponentId, IN ULONG Level)
Definition: debug.c:23
SCSIPORTAPI NTSTATUS NTAPI ClassWmiCompleteRequest(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN NTSTATUS Status, IN ULONG BufferUsed, IN CCHAR PriorityBoost)
Definition: classwmi.c:559
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define AllowDisallowPerformanceHit
Definition: diskwmi.c:150
struct _READ_LOG_SECTORS_IN * PREAD_LOG_SECTORS_IN
GLboolean enable
Definition: glext.h:11120
__inline NTSTATUS DiskExecuteSmartDiagnostics(PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, UCHAR Subcommand)
Definition: diskwmi.c:374
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
struct _WRITE_LOG_SECTORS_IN * PWRITE_LOG_SECTORS_IN
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:149
#define SmartDataGuid
Definition: diskwmi.c:148
#define STATUS_WMI_ITEMID_NOT_FOUND
Definition: ntstatus.h:764
NTSTATUS NTAPI DiskGetInfoExceptionInformation(IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, IN PMODE_INFO_EXCEPTIONS ReturnPageData)
Definition: disk.c:4862
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:566
#define EnableOfflineDiags
Definition: diskwmi.c:154
#define GetFailurePredictionCapability
Definition: diskwmi.c:153
return STATUS_SUCCESS
Definition: btrfs.c:2938
static SERVICE_STATUS status
Definition: service.c:31
NTSTATUS NTAPI DiskSetInfoExceptionInformation(IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, IN PMODE_INFO_EXCEPTIONS PageData)
Definition: disk.c:4954
struct _WRITE_LOG_SECTORS_OUT WRITE_LOG_SECTORS_OUT
Definition: ps.c:97

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 2170 of file diskwmi.c.

2206 {
2207  NTSTATUS status;
2210  PDISK_DATA diskData = (PDISK_DATA)(commonExtension->DriverData);
2211  ULONG sizeNeeded;
2212 
2213  PAGED_CODE();
2214 
2215  DebugPrint((3, "Disk: DiskQueryWmiDataBlock, Device %p, Irp %p, GuiIndex %d\n"
2216  " BufferAvail %lx Buffer %lx\n",
2217  DeviceObject, Irp,
2219 
2220  switch (GuidIndex)
2221  {
2222  case DiskGeometryGuid:
2223  {
2224  sizeNeeded = sizeof(DISK_GEOMETRY);
2225  if (BufferAvail >= sizeNeeded)
2226  {
2227  if (DeviceObject->Characteristics & FILE_REMOVABLE_MEDIA)
2228  {
2229  //
2230  // Issue ReadCapacity to update device extension
2231  // with information for current media.
2232  status = DiskReadDriveCapacity(commonExtension->PartitionZeroExtension->DeviceObject);
2233 
2234  //
2235  // Note whether the drive is ready.
2236  diskData->ReadyStatus = status;
2237 
2238  if (!NT_SUCCESS(status))
2239  {
2240  break;
2241  }
2242  }
2243 
2244  //
2245  // Copy drive geometry information from device extension.
2247  &(fdoExtension->DiskGeometry),
2248  sizeof(DISK_GEOMETRY));
2249 
2251  } else {
2253  }
2254  break;
2255  }
2256 
2257  case SmartStatusGuid:
2258  {
2259  PSTORAGE_FAILURE_PREDICT_STATUS diskSmartStatus;
2260 
2262 
2263 
2264  sizeNeeded = sizeof(STORAGE_FAILURE_PREDICT_STATUS);
2265  if (BufferAvail >= sizeNeeded)
2266  {
2267  STORAGE_PREDICT_FAILURE checkFailure;
2268 
2269  diskSmartStatus = (PSTORAGE_FAILURE_PREDICT_STATUS)Buffer;
2270 
2271  status = DiskSendFailurePredictIoctl(fdoExtension,
2272  &checkFailure);
2273 
2274  if (NT_SUCCESS(status))
2275  {
2276  if (diskData->FailurePredictionCapability ==
2278  {
2279  diskSmartStatus->Reason = *((PULONG)checkFailure.VendorSpecific);
2280  } else {
2281  diskSmartStatus->Reason = 0; // unknown
2282  }
2283 
2284  diskSmartStatus->PredictFailure = (checkFailure.PredictFailure != 0);
2285  }
2286  } else {
2288  }
2289  break;
2290  }
2291 
2292  case SmartDataGuid:
2293  {
2294  PSTORAGE_FAILURE_PREDICT_DATA diskSmartData;
2295 
2296  ASSERT((diskData->FailurePredictionCapability ==
2298  (diskData->FailurePredictionCapability ==
2300 
2301  sizeNeeded = sizeof(STORAGE_FAILURE_PREDICT_DATA);
2302  if (BufferAvail >= sizeNeeded)
2303  {
2305 
2306  diskSmartData = (PSTORAGE_FAILURE_PREDICT_DATA)Buffer;
2307 
2308  status = DiskSendFailurePredictIoctl(fdoExtension,
2309  checkFailure);
2310 
2311  if (NT_SUCCESS(status))
2312  {
2313  diskSmartData->Length = 512;
2314  }
2315  } else {
2317  }
2318 
2319  break;
2320  }
2321 
2322  case SmartThresholdsGuid:
2323  {
2324  PSTORAGE_FAILURE_PREDICT_THRESHOLDS diskSmartThresholds;
2325 
2326  ASSERT((diskData->FailurePredictionCapability ==
2328 
2329  sizeNeeded = sizeof(STORAGE_FAILURE_PREDICT_THRESHOLDS);
2330  if (BufferAvail >= sizeNeeded)
2331  {
2332  diskSmartThresholds = (PSTORAGE_FAILURE_PREDICT_THRESHOLDS)Buffer;
2334  diskSmartThresholds);
2335  } else {
2337  }
2338 
2339  break;
2340  }
2341 
2342  case SmartPerformFunction:
2343  {
2344  sizeNeeded = 0;
2346  break;
2347  }
2348 
2350  {
2351  PSTORAGE_SCSI_INFO_EXCEPTIONS infoExceptions;
2352  MODE_INFO_EXCEPTIONS modeInfo;
2353 
2354  ASSERT((diskData->FailurePredictionCapability ==
2356 
2357  sizeNeeded = sizeof(STORAGE_SCSI_INFO_EXCEPTIONS);
2358  if (BufferAvail >= sizeNeeded)
2359  {
2360  infoExceptions = (PSTORAGE_SCSI_INFO_EXCEPTIONS)Buffer;
2361  status = DiskGetInfoExceptionInformation(fdoExtension,
2362  &modeInfo);
2363 
2364  if (NT_SUCCESS(status))
2365  {
2366  infoExceptions->PageSavable = modeInfo.PSBit;
2367  infoExceptions->Flags = modeInfo.Flags;
2368  infoExceptions->MRIE = modeInfo.ReportMethod;
2369  infoExceptions->Padding = 0;
2370  REVERSE_BYTES(&infoExceptions->IntervalTimer,
2371  &modeInfo.IntervalTimer);
2372  REVERSE_BYTES(&infoExceptions->ReportCount,
2373  &modeInfo.ReportCount)
2374  }
2375  } else {
2377  }
2378 
2379  break;
2380  }
2381 
2382  default:
2383  {
2384  sizeNeeded = 0;
2386  }
2387  }
2388  DebugPrint((3, "Disk: DiskQueryWmiDataBlock Device %p, Irp %p returns %lx\n",
2389  DeviceObject, Irp, status));
2390 
2392  Irp,
2393  status,
2394  sizeNeeded,
2395  IO_NO_INCREMENT);
2396 
2397  return status;
2398 }
struct _STORAGE_FAILURE_PREDICT_THRESHOLDS STORAGE_FAILURE_PREDICT_THRESHOLDS
struct _DISK_DATA * PDISK_DATA
UCHAR IntervalTimer[4]
Definition: scsi.h:2444
struct _STORAGE_SCSI_INFO_EXCEPTIONS * PSTORAGE_SCSI_INFO_EXCEPTIONS
#define STATUS_WMI_GUID_NOT_FOUND
Definition: ntstatus.h:762
struct _STORAGE_FAILURE_PREDICT_DATA STORAGE_FAILURE_PREDICT_DATA
DISK_GEOMETRY DiskGeometry
Definition: classpnp.h:704
_In_ PIRP Irp
Definition: csq.h:116
NTSTATUS ReadyStatus
Definition: disk.h:222
struct _FUNCTIONAL_DEVICE_EXTENSION * PartitionZeroExtension
Definition: classpnp.h:575
LONG NTSTATUS
Definition: precomp.h:26
#define REVERSE_BYTES(Destination, Source)
Definition: scsi.h:2707
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 DiskGeometryGuid
Definition: diskwmi.c:146
#define PAGED_CODE()
Definition: video.h:57
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
struct _STORAGE_FAILURE_PREDICT_STATUS * PSTORAGE_FAILURE_PREDICT_STATUS
#define FILE_REMOVABLE_MEDIA
Definition: nt_native.h:807
NTSTATUS NTAPI DiskSendFailurePredictIoctl(PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, PSTORAGE_PREDICT_FAILURE checkFailure)
Definition: diskwmi.c:833
#define ScsiInfoExceptionsGuid
Definition: diskwmi.c:158
PVOID DeviceExtension
Definition: env_spec_w32.h:418
_In_ PIRP _In_ ULONG GuidIndex
Definition: classpnp.h:401
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:860
#define SmartStatusGuid
Definition: diskwmi.c:147
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define SmartThresholdsGuid
Definition: diskwmi.c:157
FAILURE_PREDICTION_METHOD FailurePredictionCapability
Definition: disk.h:257
struct _STORAGE_SCSI_INFO_EXCEPTIONS STORAGE_SCSI_INFO_EXCEPTIONS
_In_ PIRP _In_ ULONG _In_ ULONG BufferAvail
Definition: classpnp.h:401
NTSTATUS NTAPI DiskReadFailurePredictThresholds(PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, PSTORAGE_FAILURE_PREDICT_THRESHOLDS DiskSmartThresholds)
Definition: diskwmi.c:1175
ULONG NTAPI DebugPrint(IN PSTRING DebugString, IN ULONG ComponentId, IN ULONG Level)
Definition: debug.c:23
SCSIPORTAPI NTSTATUS NTAPI ClassWmiCompleteRequest(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN NTSTATUS Status, IN ULONG BufferUsed, IN CCHAR PriorityBoost)
Definition: classwmi.c:559
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
UCHAR VendorSpecific[512]
Definition: ntddstor.h:409
struct _DISK_GEOMETRY DISK_GEOMETRY
UCHAR ReportCount[4]
Definition: scsi.h:2445
unsigned int * PULONG
Definition: retypes.h:1
#define SmartPerformFunction
Definition: diskwmi.c:149
#define SmartDataGuid
Definition: diskwmi.c:148
NTSTATUS NTAPI DiskGetInfoExceptionInformation(IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, IN PMODE_INFO_EXCEPTIONS ReturnPageData)
Definition: disk.c:4862
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:566
return STATUS_SUCCESS
Definition: btrfs.c:2938
static SERVICE_STATUS status
Definition: service.c:31
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 2014 of file diskwmi.c.

2052 {
2053  //PFUNCTIONAL_DEVICE_EXTENSION fdoExtension = DeviceObject->DeviceExtension;
2055  PDISK_DATA diskData = (PDISK_DATA)(commonExtension->DriverData);
2056  //NTSTATUS status;
2057 
2058  PAGED_CODE();
2059 
2062 
2063  switch (diskData->FailurePredictionCapability)
2064  {
2066  {
2068  //
2069  // Fall Through
2070  //
2071  }
2073  {
2078 
2079  break;
2080  }
2081 
2083  {
2089  break;
2090  }
2091 
2092 
2093  default:
2094  {
2099  break;
2100  }
2101  }
2102 
2103  //
2104  // Use devnode for FDOs
2106 
2107  return STATUS_SUCCESS;
2108 }
struct _DISK_DATA * PDISK_DATA
#define SmartEventGuid
Definition: diskwmi.c:156
GUIDREGINFO DiskWmiFdoGuidList[]
Definition: diskwmi.c:96
#define PAGED_CODE()
Definition: video.h:57
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
#define CLEAR_FLAG(Flags, Bit)
Definition: classpnp.h:155
#define ScsiInfoExceptionsGuid
Definition: diskwmi.c:158
PVOID DeviceExtension
Definition: env_spec_w32.h:418
_Out_ ULONG * RegFlags
Definition: classpnp.h:386
#define WMIREG_FLAG_INSTANCE_PDO
Definition: wmistr.h:69
#define WMIREG_FLAG_REMOVE_GUID
Definition: wmistr.h:70
#define SmartStatusGuid
Definition: diskwmi.c:147
#define SmartThresholdsGuid
Definition: diskwmi.c:157
FAILURE_PREDICTION_METHOD FailurePredictionCapability
Definition: disk.h:257
#define SET_FLAG(Flags, Bit)
Definition: classpnp.h:154
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define SmartPerformFunction
Definition: diskwmi.c:149
#define SmartDataGuid
Definition: diskwmi.c:148
return STATUS_SUCCESS
Definition: btrfs.c:2938

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 2112 of file diskwmi.c.

2155 {
2156  NTSTATUS status;
2157 
2159  RegFlags,
2160  InstanceName);
2161 
2162  //
2163  // Leave MofName alone since disk doesn't have one
2164  //
2165  return(status);
2166 }
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI DiskFdoQueryWmiRegInfo(IN PDEVICE_OBJECT DeviceObject, OUT ULONG *RegFlags, OUT PUNICODE_STRING InstanceName)
Definition: diskwmi.c:2014
_Out_ ULONG * RegFlags
Definition: classpnp.h:386
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
_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 2402 of file diskwmi.c.

2437 {
2438  NTSTATUS status;
2441  PDISK_DATA diskData = (PDISK_DATA)(commonExtension->DriverData);
2442 
2443  PAGED_CODE();
2444 
2445  DebugPrint((3, "Disk: DiskSetWmiDataBlock, Device %p, Irp %p, GuiIndex %d\n"
2446  " BufferSize %#x Buffer %p\n",
2447  DeviceObject, Irp,
2449 
2451  {
2452  PSTORAGE_SCSI_INFO_EXCEPTIONS infoExceptions;
2453  MODE_INFO_EXCEPTIONS modeInfo;
2454 
2456  {
2457  infoExceptions = (PSTORAGE_SCSI_INFO_EXCEPTIONS)Buffer;
2458 
2460  modeInfo.PageLength = sizeof(MODE_INFO_EXCEPTIONS) - 2;
2461 
2462  modeInfo.PSBit = 0;
2463  modeInfo.Flags = infoExceptions->Flags;
2464 
2465  modeInfo.ReportMethod = infoExceptions->MRIE;
2466 
2467  REVERSE_BYTES(&modeInfo.IntervalTimer[0],
2468  &infoExceptions->IntervalTimer);
2469 
2470  REVERSE_BYTES(&modeInfo.ReportCount[0],
2471  &infoExceptions->ReportCount);
2472 
2473  if (modeInfo.Perf == 1)
2474  {
2475  diskData->AllowFPPerfHit = FALSE;
2476  } else {
2477  diskData->AllowFPPerfHit = TRUE;
2478  }
2479 
2480  status = DiskSetInfoExceptionInformation(fdoExtension,
2481  &modeInfo);
2482  } else {
2484  }
2485 
2486  } else if (GuidIndex <= SmartEventGuid)
2487  {
2489  } else {
2491  }
2492 
2493  DebugPrint((3, "Disk: DiskSetWmiDataBlock Device %p, Irp %p returns %lx\n",
2494  DeviceObject, Irp, status));
2495 
2497  Irp,
2498  status,
2499  0,
2500  IO_NO_INCREMENT);
2501 
2502  return status;
2503 }
#define MODE_PAGE_FAULT_REPORTING
Definition: scsi.h:217
struct _DISK_DATA * PDISK_DATA
UCHAR IntervalTimer[4]
Definition: scsi.h:2444
struct _STORAGE_SCSI_INFO_EXCEPTIONS * PSTORAGE_SCSI_INFO_EXCEPTIONS
#define TRUE
Definition: types.h:120
#define STATUS_WMI_GUID_NOT_FOUND
Definition: ntstatus.h:762
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define SmartEventGuid
Definition: diskwmi.c:156
LONG NTSTATUS
Definition: precomp.h:26
#define REVERSE_BYTES(Destination, Source)
Definition: scsi.h:2707
#define STATUS_WMI_READ_ONLY
Definition: ntstatus.h:804
BOOLEAN AllowFPPerfHit
Definition: disk.h:258
#define PAGED_CODE()
Definition: video.h:57
#define ScsiInfoExceptionsGuid
Definition: diskwmi.c:158
PVOID DeviceExtension
Definition: env_spec_w32.h:418
_In_ PIRP _In_ ULONG GuidIndex
Definition: classpnp.h:401
Definition: bufpool.h:45
#define BufferSize
Definition: classpnp.h:419
ULONG NTAPI DebugPrint(IN PSTRING DebugString, IN ULONG ComponentId, IN ULONG Level)
Definition: debug.c:23
SCSIPORTAPI NTSTATUS NTAPI ClassWmiCompleteRequest(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN NTSTATUS Status, IN ULONG BufferUsed, IN CCHAR PriorityBoost)
Definition: classwmi.c:559
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
UCHAR ReportCount[4]
Definition: scsi.h:2445
struct _MODE_INFO_EXCEPTIONS MODE_INFO_EXCEPTIONS
#define IO_NO_INCREMENT
Definition: iotypes.h:566
static SERVICE_STATUS status
Definition: service.c:31
NTSTATUS NTAPI DiskSetInfoExceptionInformation(IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, IN PMODE_INFO_EXCEPTIONS PageData)
Definition: disk.c:4954
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 2507 of file diskwmi.c.

2545 {
2546  NTSTATUS status;
2547 
2548  PAGED_CODE();
2549 
2550  DebugPrint((3, "Disk: DiskSetWmiDataItem, Device %p, Irp %p, GuiIndex %d, DataId %d\n"
2551  " BufferSize %#x Buffer %p\n",
2552  DeviceObject, Irp,
2554 
2555  if (GuidIndex <= SmartEventGuid)
2556  {
2558  } else {
2560  }
2561 
2562  DebugPrint((3, "Disk: DiskSetWmiDataItem Device %p, Irp %p returns %lx\n",
2563  DeviceObject, Irp, status));
2564 
2566  Irp,
2567  status,
2568  0,
2569  IO_NO_INCREMENT);
2570 
2571  return status;
2572 }
#define STATUS_WMI_GUID_NOT_FOUND
Definition: ntstatus.h:762
_In_ PIRP Irp
Definition: csq.h:116
_In_ PIRP _In_ ULONG _In_ ULONG DataItemId
Definition: classpnp.h:419
#define SmartEventGuid
Definition: diskwmi.c:156
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_WMI_READ_ONLY
Definition: ntstatus.h:804
#define PAGED_CODE()
Definition: video.h:57
_In_ PIRP _In_ ULONG GuidIndex
Definition: classpnp.h:401
Definition: bufpool.h:45
#define BufferSize
Definition: classpnp.h:419
ULONG NTAPI DebugPrint(IN PSTRING DebugString, IN ULONG ComponentId, IN ULONG Level)
Definition: debug.c:23
SCSIPORTAPI NTSTATUS NTAPI ClassWmiCompleteRequest(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN NTSTATUS Status, IN ULONG BufferUsed, IN CCHAR PriorityBoost)
Definition: classwmi.c:559
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define IO_NO_INCREMENT
Definition: iotypes.h:566
static SERVICE_STATUS status
Definition: service.c:31
Definition: ps.c:97

Referenced by DriverEntry().

◆ DiskGetIdentifyInfo()

NTSTATUS NTAPI DiskGetIdentifyInfo ( PFUNCTIONAL_DEVICE_EXTENSION  FdoExtension,
PBOOLEAN  SupportSmart 
)

Definition at line 792 of file diskwmi.c.

796 {
797  UCHAR outBuffer[sizeof(SRB_IO_CONTROL) + (sizeof(SENDCMDINPARAMS)-1) + IDENTIFY_BUFFER_SIZE];
798  ULONG outBufferSize = sizeof(outBuffer);
800 
801  PAGED_CODE();
802 
804  (PSRB_IO_CONTROL)outBuffer,
805  &outBufferSize);
806 
807  if (NT_SUCCESS(status))
808  {
809  PUSHORT identifyData = (PUSHORT)&(outBuffer[sizeof(SRB_IO_CONTROL) + sizeof(SENDCMDOUTPARAMS)-1]);
810  USHORT commandSetSupported = identifyData[82];
811 
812  *SupportSmart = ((commandSetSupported != 0xffff) &&
813  (commandSetSupported != 0) &&
814  ((commandSetSupported & 1) == 1));
815  } else {
816  *SupportSmart = FALSE;
817  }
818 
819  DebugPrint((3, "DiskGetIdentifyInfo: SMART %s supported for device %p, status %lx\n",
820  *SupportSmart ? "is" : "is not",
821  FdoExtension->DeviceObject,
822  status));
823 
824  return status;
825 }
LONG NTSTATUS
Definition: precomp.h:26
struct _SENDCMDOUTPARAMS SENDCMDOUTPARAMS
#define IDENTIFY_BUFFER_SIZE
Definition: ntdddisk.h:621
#define PAGED_CODE()
Definition: video.h:57
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
unsigned char UCHAR
Definition: xmlstorage.h:181
ULONG NTAPI DebugPrint(IN PSTRING DebugString, IN ULONG ComponentId, IN ULONG Level)
Definition: debug.c:23
unsigned short USHORT
Definition: pedump.c:61
struct _SRB_IO_CONTROL SRB_IO_CONTROL
#define DiskGetIdentifyData(FdoExtension, SrbControl, BufferSize)
Definition: diskwmi.c:276
unsigned int ULONG
Definition: retypes.h:1
static SERVICE_STATUS status
Definition: service.c:31
unsigned short * PUSHORT
Definition: retypes.h:2
Definition: ps.c:97

Referenced by DiskDetectFailurePrediction().

◆ DiskInfoExceptionCheck()

NTSTATUS NTAPI DiskInfoExceptionCheck ( PFUNCTIONAL_DEVICE_EXTENSION  FdoExtension)

Definition at line 1562 of file diskwmi.c.

1565 {
1566  PUCHAR modeData;
1567  PSCSI_REQUEST_BLOCK srb;
1568  PCDB cdb;
1569  PIRP irp;
1570  PIO_STACK_LOCATION irpStack;
1571  PVOID senseInfoBuffer;
1572  ULONG isRemoved;
1573 
1577  if (modeData == NULL)
1578  {
1579  DebugPrint((1, "DiskInfoExceptionCheck: Can't allocate mode data "
1580  "buffer\n"));
1582  }
1583 
1586  DISK_TAG_SRB);
1587  if (srb == NULL)
1588  {
1589  ExFreePool(modeData);
1590  DebugPrint((1, "DiskInfoExceptionCheck: Can't allocate srb "
1591  "buffer\n"));
1593  }
1594 
1595  //
1596  // Build the MODE SENSE CDB.
1597  //
1599 
1600  cdb = (PCDB)srb->Cdb;
1601  srb->CdbLength = 6;
1602  cdb = (PCDB)srb->Cdb;
1603 
1604  //
1605  // Set timeout value from device extension.
1606  //
1607  srb->TimeOutValue = FdoExtension->TimeOutValue;
1608 
1609  cdb->MODE_SENSE.OperationCode = SCSIOP_MODE_SENSE;
1610  cdb->MODE_SENSE.PageCode = MODE_PAGE_FAULT_REPORTING;
1611  cdb->MODE_SENSE.AllocationLength = MODE_DATA_SIZE;
1612 
1613  //
1614  // Write length to SRB.
1615  //
1617 
1618  //
1619  // Set SCSI bus address.
1620  //
1621 
1623 
1624  //
1625  // Enable auto request sense.
1626  //
1627 
1629 
1630  //
1631  // Sense buffer is in aligned nonpaged pool.
1632  //
1633 
1636  '7CcS');
1637 
1638  if (senseInfoBuffer == NULL)
1639  {
1640  ExFreePool(srb);
1641  ExFreePool(modeData);
1642  DebugPrint((1, "DiskInfoExceptionCheck: Can't allocate request sense "
1643  "buffer\n"));
1645  }
1646 
1647  srb->SenseInfoBuffer = senseInfoBuffer;
1648  srb->DataBuffer = modeData;
1649 
1650  srb->SrbFlags = FdoExtension->SrbFlags;
1651 
1652 
1654 
1655  //
1656  // Disable synchronous transfer for these requests.
1657  //
1659 
1660  //
1661  // Don't freeze the queue on an error
1662  //
1664 
1666  srb->QueueTag = SP_UNTAGGED;
1667 
1668 
1669  //
1670  // Build device I/O control request with METHOD_NEITHER data transfer.
1671  // We'll queue a completion routine to cleanup the MDL's and such ourself.
1672  //
1673 
1674  irp = IoAllocateIrp(
1675  (CCHAR) (FdoExtension->CommonExtension.LowerDeviceObject->StackSize + 1),
1676  FALSE);
1677 
1678  if (irp == NULL)
1679  {
1680  ExFreePool(senseInfoBuffer);
1681  ExFreePool(srb);
1682  ExFreePool(modeData);
1683  DebugPrint((1, "DiskInfoExceptionCheck: Can't allocate Irp\n"));
1685  }
1686 
1687  isRemoved = ClassAcquireRemoveLock(FdoExtension->DeviceObject, irp);
1688 
1689  if (isRemoved)
1690  {
1691  ClassReleaseRemoveLock(FdoExtension->DeviceObject, irp);
1692  IoFreeIrp(irp);
1693  ExFreePool(senseInfoBuffer);
1694  ExFreePool(srb);
1695  ExFreePool(modeData);
1696  DebugPrint((1, "DiskInfoExceptionCheck: RemoveLock says isRemoved\n"));
1698  }
1699 
1700  //
1701  // Get next stack location.
1702  //
1703 
1705  irpStack = IoGetCurrentIrpStackLocation(irp);
1706  irpStack->DeviceObject = FdoExtension->DeviceObject;
1707 
1708  //
1709  // Save retry count in current Irp stack.
1710  //
1711  irpStack->Parameters.Others.Argument4 = (PVOID)MAXIMUM_RETRIES;
1712 
1713 
1714  irpStack = IoGetNextIrpStackLocation(irp);
1715 
1716  //
1717  // Set up SRB for execute scsi request. Save SRB address in next stack
1718  // for the port driver.
1719  //
1720 
1721  irpStack->MajorFunction = IRP_MJ_SCSI;
1722  irpStack->Parameters.Scsi.Srb = srb;
1723 
1726  srb,
1727  TRUE,
1728  TRUE,
1729  TRUE);
1730 
1731  irp->MdlAddress = IoAllocateMdl( modeData,
1733  FALSE,
1734  FALSE,
1735  irp );
1736  if (irp->MdlAddress == NULL)
1737  {
1738  ClassReleaseRemoveLock(FdoExtension->DeviceObject, irp);
1739  ExFreePool(srb);
1740  ExFreePool(modeData);
1741  ExFreePool(senseInfoBuffer);
1742  IoFreeIrp( irp );
1743  DebugPrint((1, "DiskINfoExceptionCheck: Can't allocate MDL\n"));
1745  }
1746 
1747  MmBuildMdlForNonPagedPool(irp->MdlAddress);
1748 
1749  //
1750  // Set the transfer length.
1751  //
1753 
1754  //
1755  // Zero out status.
1756  //
1757  srb->ScsiStatus = srb->SrbStatus = 0;
1758  srb->NextSrb = 0;
1759 
1760  //
1761  // Set up IRP Address.
1762  //
1763  srb->OriginalRequest = irp;
1764 
1765  //
1766  // Call the port driver with the request and wait for it to complete.
1767  //
1768 
1769  IoMarkIrpPending(irp);
1770  IoCallDriver(FdoExtension->CommonExtension.LowerDeviceObject,
1771  irp);
1772 
1773  return(STATUS_PENDING);
1774 }
#define STATUS_DEVICE_DOES_NOT_EXIST
Definition: ntstatus.h:414
#define MODE_PAGE_FAULT_REPORTING
Definition: scsi.h:217
#define TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define ClassAcquireRemoveLock(devobj, tag)
Definition: classpnp.h:97
ULONG SrbFlags
Definition: srb.h:252
PVOID OriginalRequest
Definition: srb.h:258
UCHAR Cdb[16]
Definition: srb.h:271
#define SRB_FLAGS_NO_QUEUE_FREEZE
Definition: srb.h:396
#define SCSIOP_MODE_SENSE
Definition: cdrw_hw.h:896
PVOID DataBuffer
Definition: srb.h:255
unsigned char * PUCHAR
Definition: retypes.h:3
ULONG DataTransferLength
Definition: srb.h:253
VOID NTAPI MmBuildMdlForNonPagedPool(IN PMDL Mdl)
Definition: mdlsup.c:428
Definition: cdrw_hw.h:28
UCHAR CdbLength
Definition: srb.h:250
struct _SCSI_REQUEST_BLOCK * NextSrb
Definition: srb.h:257
UCHAR QueueAction
Definition: srb.h:249
#define SRB_FLAGS_DATA_IN
Definition: srb.h:392
ULONG TimeOutValue
Definition: srb.h:254
UCHAR SrbStatus
Definition: srb.h:243
#define SENSE_BUFFER_SIZE
Definition: cdrw_hw.h:1183
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:515
#define SP_UNTAGGED
Definition: srb.h:225
#define IRP_MJ_SCSI
#define DISK_TAG_INFO_EXCEPTION
Definition: disk.h:49
UCHAR ScsiStatus
Definition: srb.h:244
smooth NULL
Definition: ftsmooth.c:416
union _CDB * PCDB
void * PVOID
Definition: retypes.h:9
UCHAR QueueTag
Definition: srb.h:248
#define MAXIMUM_RETRIES
Definition: class2.h:14
struct _CDB::_MODE_SENSE MODE_SENSE
#define STATUS_PENDING
Definition: ntstatus.h:82
char CCHAR
Definition: typedefs.h:50
UCHAR Function
Definition: srb.h:242
#define SRB_FLAGS_DISABLE_SYNCH_TRANSFER
Definition: srb.h:389
PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2867
USHORT Length
Definition: srb.h:241
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2647
#define SET_FLAG(Flags, Bit)
Definition: classpnp.h:154
ULONG NTAPI DebugPrint(IN PSTRING DebugString, IN ULONG ComponentId, IN ULONG Level)
Definition: debug.c:23
PMDL NTAPI IoAllocateMdl(IN PVOID VirtualAddress, IN ULONG Length, IN BOOLEAN SecondaryBuffer, IN BOOLEAN ChargeQuota, IN PIRP Irp)
Definition: iomdl.c:22
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
UCHAR SenseInfoBufferLength
Definition: srb.h:251
NTSTATUS NTAPI DiskInfoExceptionComplete(PDEVICE_OBJECT DeviceObject, PIRP Irp, PVOID Context)
Definition: diskwmi.c:1361
#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
#define DISK_TAG_SRB
Definition: disk.h:61
PVOID SenseInfoBuffer
Definition: srb.h:256
VOID NTAPI IoFreeIrp(IN PIRP Irp)
Definition: irp.c:1666
#define MODE_DATA_SIZE
Definition: cdrom.c:173
#define SRB_FUNCTION_EXECUTE_SCSI
Definition: srb.h:307
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
PIRP NTAPI IoAllocateIrp(IN CCHAR StackSize, IN BOOLEAN ChargeQuota)
Definition: irp.c:615
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
IoMarkIrpPending(Irp)
FORCEINLINE VOID IoSetNextIrpStackLocation(_Inout_ PIRP Irp)
Definition: iofuncs.h:2632
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
VOID NTAPI ClassReleaseRemoveLock(IN PDEVICE_OBJECT DeviceObject, IN OPTIONAL PIRP Tag)
Definition: lock.c:212

Referenced by DiskDetectFailurePrediction().

◆ DiskInfoExceptionComplete()

NTSTATUS NTAPI DiskInfoExceptionComplete ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp,
PVOID  Context 
)

Definition at line 1361 of file diskwmi.c.

1366 {
1369  PDISK_DATA diskData = (PDISK_DATA)(commonExtension->DriverData);
1373  NTSTATUS status;
1374  BOOLEAN retry;
1375  ULONG retryInterval;
1376  ULONG srbStatus;
1377  BOOLEAN freeLockAndIrp = TRUE;
1378  //KIRQL oldIrql;
1379 
1380  ASSERT(fdoExtension->CommonExtension.IsFdo);
1381 
1382  srbStatus = SRB_STATUS(srb->SrbStatus);
1383 
1384  //
1385  // Check SRB status for success of completing request.
1386  // SRB_STATUS_DATA_OVERRUN also indicates success.
1387  //
1388  if ((srbStatus != SRB_STATUS_SUCCESS) &&
1389  (srbStatus != SRB_STATUS_DATA_OVERRUN))
1390  {
1391  DebugPrint((2, "DiskInfoExceptionComplete: IRP %p, SRB %p\n", Irp, srb));
1392 
1393  retry = ClassInterpretSenseInfo(
1394  DeviceObject,
1395  srb,
1396  irpStack->MajorFunction,
1397  0,
1398  MAXIMUM_RETRIES -
1399  ((ULONG)(ULONG_PTR)irpStack->Parameters.Others.Argument4),
1400  &status,
1401  &retryInterval);
1402 
1403  //
1404  // If the status is verified required and the this request
1405  // should bypass verify required then retry the request.
1406  //
1407 
1408  if (TEST_FLAG(irpStack->Flags, SL_OVERRIDE_VERIFY_VOLUME) &&
1410  {
1412  retry = TRUE;
1413  }
1414 
1415  if (retry && irpStack->Parameters.Others.Argument4)
1416  {
1417  irpStack->Parameters.Others.Argument4 =
1418  (PVOID)((ULONG_PTR)irpStack->Parameters.Others.Argument4 - 1);
1419 
1420  //
1421  // Retry request.
1422  //
1423 
1424  DebugPrint((1, "DiskInfoExceptionComplete: Retry request %p\n", Irp));
1425 
1426  ASSERT(srb->DataBuffer == MmGetMdlVirtualAddress(Irp->MdlAddress));
1427 
1428  //
1429  // Reset byte count of transfer in SRB Extension.
1430  //
1431  srb->DataTransferLength = Irp->MdlAddress->ByteCount;
1432 
1433  //
1434  // Zero SRB statuses.
1435  //
1436 
1437  srb->SrbStatus = srb->ScsiStatus = 0;
1438 
1439  //
1440  // Set the no disconnect flag, disable synchronous data transfers and
1441  // disable tagged queuing. This fixes some errors.
1442  //
1443 
1447 
1449  srb->QueueTag = SP_UNTAGGED;
1450 
1451  //
1452  // Set up major SCSI function.
1453  //
1454 
1455  nextIrpStack->MajorFunction = IRP_MJ_SCSI;
1456 
1457  //
1458  // Save SRB address in next stack for port driver.
1459  //
1460 
1461  nextIrpStack->Parameters.Scsi.Srb = srb;
1462 
1463 
1466  srb,
1467  TRUE, TRUE, TRUE);
1468 
1469  (VOID)IoCallDriver(commonExtension->LowerDeviceObject, Irp);
1470 
1472  }
1473 
1474  } else {
1475 
1476  //
1477  // Get the results from the mode sense
1478  //
1479  PMODE_INFO_EXCEPTIONS pageData;
1480  PMODE_PARAMETER_HEADER modeData;
1481  ULONG modeDataLength;
1482 
1483  modeData = srb->DataBuffer;
1484  modeDataLength = srb->DataTransferLength;
1485 
1486  pageData = ClassFindModePage((PUCHAR) modeData,
1487  modeDataLength,
1489  TRUE);
1490  if (pageData != NULL)
1491  {
1492  DebugPrint((1, "DiskInfoExceptionComplete: %p supports SMART\n",
1493  DeviceObject));
1494 
1495  if (pageData->Dexcpt == 0)
1496  {
1499 
1500  if (NT_SUCCESS(status))
1501  {
1502  //
1503  // Make sure we won't free the remove lock and the irp
1504  // since we need to keep these until after the work
1505  // item has completed running
1506  //
1507  freeLockAndIrp = FALSE;
1508  }
1509  } else {
1510  DebugPrint((1, "DiskInfoExceptionComplete: %p is not enabled for SMART\n",
1511  DeviceObject));
1512 
1513  }
1514 
1515  } else {
1516  DebugPrint((1, "DiskInfoExceptionComplete: %p does not supports SMART\n",
1517  DeviceObject));
1518 
1519  }
1520 
1521  //
1522  // Set status for successful request
1523  //
1524 
1526 
1527  } // end if (SRB_STATUS(srb->SrbStatus) == SRB_STATUS_SUCCESS)
1528 
1529  //
1530  // Free the srb
1531  //
1533  ExFreePool(srb->DataBuffer);
1534  ExFreePool(srb);
1535 
1536  if (freeLockAndIrp)
1537  {
1538  //
1539  // Set status in completing IRP.
1540  //
1541 
1542  Irp->IoStatus.Status = status;
1543 
1544  //
1545  // If pending has be returned for this irp then mark the current stack as
1546  // pending.
1547  //
1548 
1549  if (Irp->PendingReturned) {
1551  }
1552 
1554  IoFreeMdl(Irp->MdlAddress);
1555  IoFreeIrp(Irp);
1556  }
1557 
1559 
1560 }
#define MODE_PAGE_FAULT_REPORTING
Definition: scsi.h:217
struct _DISK_DATA * PDISK_DATA
#define TRUE
Definition: types.h:120
ULONG SrbFlags
Definition: srb.h:252
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:68
#define MmGetMdlVirtualAddress(_Mdl)
#define TEST_FLAG(Flags, Bit)
Definition: classpnp.h:156
_In_ PIRP Irp
Definition: csq.h:116
PVOID DataBuffer
Definition: srb.h:255
unsigned char * PUCHAR
Definition: retypes.h:3
ULONG DataTransferLength
Definition: srb.h:253
LONG NTSTATUS
Definition: precomp.h:26
COMMON_DEVICE_EXTENSION CommonExtension
Definition: classpnp.h:695
UCHAR QueueAction
Definition: srb.h:249
#define STATUS_VERIFY_REQUIRED
Definition: udferr_usr.h:130
UCHAR SrbStatus
Definition: srb.h:243
#define SRB_STATUS(Status)
Definition: srb.h:381
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:515
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define SP_UNTAGGED
Definition: srb.h:225
#define IRP_MJ_SCSI
#define STATUS_IO_DEVICE_ERROR
Definition: udferr_usr.h:179
UCHAR ScsiStatus
Definition: srb.h:244
#define CLEAR_FLAG(Flags, Bit)
Definition: classpnp.h:155
PVOID DeviceExtension
Definition: env_spec_w32.h:418
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define SL_OVERRIDE_VERIFY_VOLUME
Definition: iotypes.h:1780
PVOID NTAPI ClassFindModePage(IN PCHAR ModeSenseBuffer, IN ULONG Length, IN UCHAR PageMode, IN BOOLEAN Use6Byte)
Definition: class.c:4209
void * PVOID
Definition: retypes.h:9
UCHAR QueueTag
Definition: srb.h:248
#define MAXIMUM_RETRIES
Definition: class2.h:14
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define SRB_FLAGS_DISABLE_SYNCH_TRANSFER
Definition: srb.h:389
BOOLEAN NTAPI ClassInterpretSenseInfo(IN PDEVICE_OBJECT Fdo, IN PSCSI_REQUEST_BLOCK Srb, IN UCHAR MajorFunctionCode, IN ULONG IoDeviceCode, IN ULONG RetryCount, OUT NTSTATUS *Status, OUT OPTIONAL ULONG *RetryInterval)
Definition: class.c:2994
#define SRB_STATUS_DATA_OVERRUN
Definition: srb.h:349
VOID NTAPI IoFreeMdl(PMDL Mdl)
Definition: iomdl.c:146
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define SRB_FLAGS_DISABLE_DISCONNECT
Definition: srb.h:388
#define VOID
Definition: acefi.h:82
FAILURE_PREDICTION_METHOD FailurePredictionCapability
Definition: disk.h:257
NTSTATUS NTAPI DiskPostReregisterRequest(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: diskwmi.c:1320
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2647
#define SET_FLAG(Flags, Bit)
Definition: classpnp.h:154
ULONG NTAPI DebugPrint(IN PSTRING DebugString, IN ULONG ComponentId, IN ULONG Level)
Definition: debug.c:23
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
NTSTATUS NTAPI DiskInfoExceptionComplete(PDEVICE_OBJECT DeviceObject, PIRP Irp, PVOID Context)
Definition: diskwmi.c:1361
#define SRB_SIMPLE_TAG_REQUEST
Definition: srb.h:415
PDEVICE_OBJECT LowerDeviceObject
Definition: classpnp.h:574
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
PVOID SenseInfoBuffer
Definition: srb.h:256
VOID NTAPI IoFreeIrp(IN PIRP Irp)
Definition: irp.c:1666
struct tagContext Context
Definition: acpixf.h:1030
unsigned int ULONG
Definition: retypes.h:1
#define SRB_STATUS_SUCCESS
Definition: srb.h:333
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
return STATUS_SUCCESS
Definition: btrfs.c:2938
IoMarkIrpPending(Irp)
static SERVICE_STATUS status
Definition: service.c:31
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define SRB_FLAGS_QUEUE_ACTION_ENABLE
Definition: srb.h:387
VOID NTAPI ClassReleaseRemoveLock(IN PDEVICE_OBJECT DeviceObject, IN OPTIONAL PIRP Tag)
Definition: lock.c:212
Definition: ps.c:97

Referenced by DiskInfoExceptionCheck().

◆ DiskInitializeReregistration()

NTSTATUS NTAPI DiskInitializeReregistration ( void  )

Definition at line 1301 of file diskwmi.c.

1304 {
1305  PAGED_CODE();
1306 
1307  //
1308  // Initialize the global work item and spinlock used to manage the
1309  // list of disks reregistering their guids
1310  //
1313  NULL );
1314 
1316 
1317  return(STATUS_SUCCESS);
1318 }
KSPIN_LOCK DiskReregSpinlock
Definition: diskwmi.c:93
#define PAGED_CODE()
Definition: video.h:57
void NTAPI DiskReregWorker(IN PVOID Context)
Definition: diskwmi.c:1256
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:251
smooth NULL
Definition: ftsmooth.c:416
#define ExInitializeWorkItem(Item, Routine, Context)
Definition: exfuncs.h:265
WORK_QUEUE_ITEM DiskReregWorkItem
Definition: diskwmi.c:91
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by DriverEntry().

◆ DiskPerformSmartCommand()

NTSTATUS NTAPI 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 
)

Definition at line 493 of file diskwmi.c.

535 {
537  PDISK_DATA diskData = (PDISK_DATA)(commonExtension->DriverData);
538  PUCHAR buffer;
539  PSENDCMDINPARAMS cmdInParameters;
540  //PSENDCMDOUTPARAMS cmdOutParameters;
541  //ULONG outBufferSize;
543  ULONG availableBufferSize;
544  KEVENT event;
545  PIRP irp;
546  IO_STATUS_BLOCK ioStatus;
547  SCSI_REQUEST_BLOCK srb;
548  LARGE_INTEGER startingOffset;
549  ULONG length;
550  PIO_STACK_LOCATION irpStack;
551 
552  PAGED_CODE();
553 
554  //
555  // Point to the 'buffer' portion of the SRB_CONTROL and compute how
556  // much room we have left in the srb control
557  //
558 
559  buffer = (PUCHAR)SrbControl;
560  buffer += sizeof(SRB_IO_CONTROL);
561 
562  cmdInParameters = (PSENDCMDINPARAMS)buffer;
563  //cmdOutParameters = (PSENDCMDOUTPARAMS)buffer;
564 
565  availableBufferSize = *BufferSize - sizeof(SRB_IO_CONTROL);
566 
567 #if DBG
568  //
569  // Ensure control codes and buffer lengths passed are correct
570  //
571  {
572  ULONG controlCode;
573  ULONG lengthNeeded = sizeof(SENDCMDINPARAMS) - 1;
574 
575  if (Command == SMART_CMD)
576  {
577  switch (Feature)
578  {
579 
580  case ENABLE_SMART:
581  {
582  controlCode = IOCTL_SCSI_MINIPORT_ENABLE_SMART;
583 
584  break;
585  }
586 
587  case DISABLE_SMART:
588  {
589  controlCode = IOCTL_SCSI_MINIPORT_DISABLE_SMART;
590  break;
591  }
592 
593  case RETURN_SMART_STATUS:
594  {
595  //
596  // Ensure bBuffer is at least 2 bytes (to hold the values of
597  // cylinderLow and cylinderHigh).
598  //
599 
600  lengthNeeded = sizeof(SENDCMDINPARAMS) - 1 + sizeof(IDEREGS);
601 
602  controlCode = IOCTL_SCSI_MINIPORT_RETURN_STATUS;
603  break;
604  }
605 
607  {
609  break;
610  }
611 
613  {
615  break;
616  }
617 
618 
620  {
622  break;
623  }
624 
625  case READ_ATTRIBUTES:
626  {
628  lengthNeeded = READ_ATTRIBUTE_BUFFER_SIZE + sizeof(SENDCMDOUTPARAMS) - 1;
629  break;
630  }
631 
632  case READ_THRESHOLDS:
633  {
635  lengthNeeded = READ_THRESHOLD_BUFFER_SIZE + sizeof(SENDCMDOUTPARAMS) - 1;
636  break;
637  }
638 
639  case SMART_READ_LOG:
640  {
642  lengthNeeded = (SectorCount * SMART_LOG_SECTOR_SIZE) +
643  sizeof(SENDCMDINPARAMS) - 1;
644  break;
645  }
646 
647  case SMART_WRITE_LOG:
648  {
650  lengthNeeded = (SectorCount * SMART_LOG_SECTOR_SIZE) +
651  sizeof(SENDCMDINPARAMS) - 1;
652  break;
653  }
654 
655  default:
656  controlCode = 0;
657  break;
658 
659  }
660  } else if (Command == ID_CMD) {
661  controlCode = IOCTL_SCSI_MINIPORT_IDENTIFY;
662  lengthNeeded = IDENTIFY_BUFFER_SIZE + sizeof(SENDCMDOUTPARAMS) -1;
663  } else {
664  controlCode = 0;
665  ASSERT(FALSE);
666  }
667 
668  ASSERT(controlCode == SrbControlCode);
669  ASSERT(availableBufferSize >= lengthNeeded);
670  }
671 #endif
672 
673  //
674  // Build SrbControl and input to SMART command
675  //
676 
677  SrbControl->HeaderLength = sizeof(SRB_IO_CONTROL);
678  RtlMoveMemory (SrbControl->Signature, "SCSIDISK", 8);
679  SrbControl->Timeout = FdoExtension->TimeOutValue;
680  SrbControl->Length = availableBufferSize;
681 
682  SrbControl->ControlCode = SrbControlCode;
683 
684  cmdInParameters->cBufferSize = sizeof(SENDCMDINPARAMS);
685  cmdInParameters->bDriveNumber = diskData->ScsiAddress.TargetId;
686  cmdInParameters->irDriveRegs.bFeaturesReg = Feature;
687  cmdInParameters->irDriveRegs.bSectorCountReg = SectorCount;
688  cmdInParameters->irDriveRegs.bSectorNumberReg = SectorNumber;
689  cmdInParameters->irDriveRegs.bCylLowReg = SMART_CYL_LOW;
690  cmdInParameters->irDriveRegs.bCylHighReg = SMART_CYL_HI;
691  cmdInParameters->irDriveRegs.bCommandReg = Command;
692 
693 
694  //
695  // Create and send irp
696  //
698 
699  startingOffset.QuadPart = (LONGLONG) 1;
700 
701  length = SrbControl->HeaderLength + SrbControl->Length;
702 
704  IRP_MJ_SCSI,
705  commonExtension->LowerDeviceObject,
706  SrbControl,
707  length,
708  &startingOffset,
709  &event,
710  &ioStatus);
711 
712  if (irp == NULL) {
714  }
715 
716  irpStack = IoGetNextIrpStackLocation(irp);
717 
718  //
719  // Set major and minor codes.
720  //
721 
722  irpStack->MajorFunction = IRP_MJ_SCSI;
723  irpStack->MinorFunction = 1;
724 
725  //
726  // Fill in SRB fields.
727  //
728 
729  irpStack->Parameters.Others.Argument1 = &srb;
730 
731  //
732  // Zero out the srb.
733  //
734 
735  RtlZeroMemory(&srb, sizeof(SCSI_REQUEST_BLOCK));
736 
737  srb.PathId = diskData->ScsiAddress.PathId;
738  srb.TargetId = diskData->ScsiAddress.TargetId;
739  srb.Lun = diskData->ScsiAddress.Lun;
740 
742  srb.Length = sizeof(SCSI_REQUEST_BLOCK);
743 
744  srb.SrbFlags = FdoExtension->SrbFlags;
748 
750  srb.QueueTag = SP_UNTAGGED;
751 
752  srb.OriginalRequest = irp;
753 
754  //
755  // Set timeout to requested value.
756  //
757 
758  srb.TimeOutValue = SrbControl->Timeout;
759 
760  //
761  // Set the data buffer.
762  //
763 
764  srb.DataBuffer = SrbControl;
766 
767  //
768  // Flush the data buffer for output. This will insure that the data is
769  // written back to memory. Since the data-in flag is the the port driver
770  // will flush the data again for input which will ensure the data is not
771  // in the cache.
772  //
773 
774  KeFlushIoBuffers(irp->MdlAddress, FALSE, TRUE);
775 
776  //
777  // Call port driver to handle this request.
778  //
779 
780  status = IoCallDriver(commonExtension->LowerDeviceObject, irp);
781 
782  if (status == STATUS_PENDING) {
784  status = ioStatus.Status;
785  }
786 
787  return status;
788 }
UCHAR PathId
Definition: scsi_port.h:149
ULONG cBufferSize
Definition: helper.h:31
#define SMART_LOG_SECTOR_SIZE
Definition: ntdddisk.h:623
struct _DISK_DATA * PDISK_DATA
#define TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define IOCTL_SCSI_MINIPORT_READ_SMART_ATTRIBS
Definition: cdrw_hw.h:1459
ULONG SrbFlags
Definition: srb.h:252
UCHAR bSectorNumberReg
Definition: helper.h:11
PVOID OriginalRequest
Definition: srb.h:258
PIRP NTAPI IoBuildSynchronousFsdRequest(IN ULONG MajorFunction, IN PDEVICE_OBJECT DeviceObject, IN PVOID Buffer, IN ULONG Length, IN PLARGE_INTEGER StartingOffset, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:1069
#define SRB_FLAGS_NO_QUEUE_FREEZE
Definition: srb.h:396
PVOID DataBuffer
Definition: srb.h:255
#define SMART_CYL_LOW
Definition: ntdddisk.h:568
unsigned char * PUCHAR
Definition: retypes.h:3
ULONG DataTransferLength
Definition: srb.h:253
#define ENABLE_DISABLE_AUTOSAVE
Definition: ntdddisk.h:635
LONG NTSTATUS
Definition: precomp.h:26
SCSI_ADDRESS ScsiAddress
Definition: disk.h:236
struct _SENDCMDOUTPARAMS SENDCMDOUTPARAMS
GLuint buffer
Definition: glext.h:5915
#define IDENTIFY_BUFFER_SIZE
Definition: ntdddisk.h:621
#define DISABLE_SMART
Definition: ntdddisk.h:641
Definition: shell.h:41
UCHAR QueueAction
Definition: srb.h:249
#define SRB_FLAGS_DATA_IN
Definition: srb.h:392
ULONG TimeOutValue
Definition: srb.h:254
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
UCHAR TargetId
Definition: scsi_port.h:150
UCHAR bSectorCountReg
Definition: helper.h:10
#define ENABLE_SMART
Definition: ntdddisk.h:640
#define PAGED_CODE()
Definition: video.h:57
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define SP_UNTAGGED
Definition: srb.h:225
#define IRP_MJ_SCSI
struct _SENDCMDINPARAMS SENDCMDINPARAMS
#define IOCTL_SCSI_MINIPORT_ENABLE_DISABLE_AUTOSAVE
Definition: cdrw_hw.h:1464
smooth NULL
Definition: ftsmooth.c:416
#define IOCTL_SCSI_MINIPORT_READ_SMART_THRESHOLDS
Definition: cdrw_hw.h:1460
#define READ_THRESHOLD_BUFFER_SIZE
Definition: ntdddisk.h:622
UCHAR QueueTag
Definition: srb.h:248
UCHAR TargetId
Definition: srb.h:246
#define RETURN_SMART_STATUS
Definition: ntdddisk.h:642
#define READ_ATTRIBUTE_BUFFER_SIZE
Definition: ntdddisk.h:620
#define EXECUTE_OFFLINE_DIAGS
Definition: ntdddisk.h:637
int64_t LONGLONG
Definition: typedefs.h:66
#define ID_CMD
Definition: helper.h:20
#define READ_THRESHOLDS
Definition: ntdddisk.h:634
#define SAVE_ATTRIBUTE_VALUES
Definition: ntdddisk.h:636
IDEREGS irDriveRegs
Definition: helper.h:32
#define STATUS_PENDING
Definition: ntstatus.h:82
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
struct Command Command
UCHAR Function
Definition: srb.h:242
#define IOCTL_SCSI_MINIPORT_EXECUTE_OFFLINE_DIAGS
Definition: cdrw_hw.h:1466
#define IOCTL_SCSI_MINIPORT_RETURN_STATUS
Definition: cdrw_hw.h:1463
UCHAR bCommandReg
Definition: helper.h:15
struct _COMMON_DEVICE_EXTENSION * PCOMMON_DEVICE_EXTENSION
#define BufferSize
Definition: classpnp.h:419
#define SRB_FLAGS_NO_KEEP_AWAKE
Definition: srb.h:404
#define IOCTL_SCSI_MINIPORT_ENABLE_SMART
Definition: cdrw_hw.h:1461
USHORT Length
Definition: srb.h:241
#define READ_ATTRIBUTES
Definition: ntdddisk.h:633
struct _SCSI_REQUEST_BLOCK SCSI_REQUEST_BLOCK
#define IOCTL_SCSI_MINIPORT_READ_SMART_LOG
Definition: scsi.h:1420
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define IOCTL_SCSI_MINIPORT_SAVE_ATTRIBUTE_VALUES
Definition: cdrw_hw.h:1465
#define SRB_FUNCTION_IO_CONTROL
Definition: srb.h:309
UCHAR bCylLowReg
Definition: helper.h:12
struct _cl_event * event
Definition: glext.h:7739
ULONG SectorCount
Definition: part_xbox.c:32
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2647
#define SET_FLAG(Flags, Bit)
Definition: classpnp.h:154
#define SMART_CMD
Definition: helper.h:21
UCHAR bFeaturesReg
Definition: helper.h:9
#define SMART_CYL_HI
Definition: ntdddisk.h:569
#define KeFlushIoBuffers(_Mdl, _ReadOperation, _DmaOperation)
Definition: ke.h:161
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
UCHAR PathId
Definition: srb.h:245
struct _SRB_IO_CONTROL SRB_IO_CONTROL
#define IOCTL_SCSI_MINIPORT_IDENTIFY
Definition: cdrw_hw.h:1458
#define IOCTL_SCSI_MINIPORT_WRITE_SMART_LOG
Definition: scsi.h:1421
#define SRB_SIMPLE_TAG_REQUEST
Definition: srb.h:415
#define SMART_READ_LOG
Definition: ntdddisk.h:638
PDEVICE_OBJECT LowerDeviceObject
Definition: classpnp.h:574
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
UCHAR bCylHighReg
Definition: helper.h:13
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define SMART_WRITE_LOG
Definition: ntdddisk.h:639
#define IOCTL_SCSI_MINIPORT_DISABLE_SMART
Definition: cdrw_hw.h:1462
UCHAR bDriveNumber
Definition: helper.h:33
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
Definition: helper.h:8
static SERVICE_STATUS status
Definition: service.c:31
LONGLONG QuadPart
Definition: typedefs.h:112
struct _SENDCMDINPARAMS * PSENDCMDINPARAMS
Definition: ps.c:97

Referenced by DiskDisableSmart(), DiskDisableSmartAttributeAutosave(), DiskEnableSmart(), DiskEnableSmartAttributeAutosave(), DiskExecuteSmartDiagnostics(), DiskReadSmartLog(), and DiskWriteSmartLog().

◆ DiskPostReregisterRequest()

NTSTATUS NTAPI DiskPostReregisterRequest ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 1320 of file diskwmi.c.

1324 {
1325  PDISKREREGREQUEST reregRequest;
1326  NTSTATUS status;
1327 
1328  reregRequest = ExAllocatePoolWithTag(NonPagedPool,
1329  sizeof(DISKREREGREQUEST),
1330  DISK_TAG_SMART);
1331 
1332  if (reregRequest != NULL)
1333  {
1334  //
1335  // add the disk that needs reregistration to the stack of disks
1336  // to reregister. If the list is transitioning from empty to
1337  // non empty then also kick off the work item so that the
1338  // reregistration worker can do the reregister.
1339  //
1340  reregRequest->DeviceObject = DeviceObject;
1341  reregRequest->Irp = Irp;
1343  &DiskReregHead,
1344  &reregRequest->Next,
1346 
1348  {
1350  }
1352  } else {
1353  DebugPrint((1, "DiskPostReregisterRequest: could not allocate reregRequest for %p\n",
1354  DeviceObject));
1356  }
1357 
1358  return(status);
1359 }
KSPIN_LOCK DiskReregSpinlock
Definition: diskwmi.c:93
VOID NTAPI ExQueueWorkItem(IN PWORK_QUEUE_ITEM WorkItem, IN WORK_QUEUE_TYPE QueueType)
Definition: work.c:717
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ PIRP Irp
Definition: csq.h:116
PDEVICE_OBJECT DeviceObject
Definition: disk.h:346
LONG NTSTATUS
Definition: precomp.h:26
PSINGLE_LIST_ENTRY NTAPI ExInterlockedPushEntryList(IN OUT PSINGLE_LIST_ENTRY ListHead, IN OUT PSINGLE_LIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:227
LONG DiskReregWorkItems
Definition: diskwmi.c:94
smooth NULL
Definition: ftsmooth.c:416
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
SINGLE_LIST_ENTRY Next
Definition: disk.h:345
#define DISK_TAG_SMART
Definition: disk.h:48
SINGLE_LIST_ENTRY DiskReregHead
Definition: diskwmi.c:92
ULONG NTAPI DebugPrint(IN PSTRING DebugString, IN ULONG ComponentId, IN ULONG Level)
Definition: debug.c:23
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define InterlockedIncrement
Definition: armddk.h:53
WORK_QUEUE_ITEM DiskReregWorkItem
Definition: diskwmi.c:91
return STATUS_SUCCESS
Definition: btrfs.c:2938
static SERVICE_STATUS status
Definition: service.c:31
Definition: ps.c:97

Referenced by DiskInfoExceptionComplete().

◆ DiskReadFailurePredictData()

NTSTATUS NTAPI DiskReadFailurePredictData ( PFUNCTIONAL_DEVICE_EXTENSION  FdoExtension,
PSTORAGE_FAILURE_PREDICT_DATA  DiskSmartData 
)

Definition at line 1083 of file diskwmi.c.

1105 {
1107  PDISK_DATA diskData = (PDISK_DATA)(commonExtension->DriverData);
1108  NTSTATUS status;
1109 
1110  PAGED_CODE();
1111 
1112  switch(diskData->FailurePredictionCapability)
1113  {
1115  {
1116  PUCHAR outBuffer;
1117  ULONG outBufferSize;
1118  PSENDCMDOUTPARAMS cmdOutParameters;
1119 
1120  outBufferSize = sizeof(SRB_IO_CONTROL) +
1121  (sizeof(SENDCMDOUTPARAMS)-1) +
1123 
1124  outBuffer = ExAllocatePoolWithTag(NonPagedPool,
1125  outBufferSize,
1126  DISK_TAG_SMART);
1127 
1128  if (outBuffer != NULL)
1129  {
1131  (PSRB_IO_CONTROL)outBuffer,
1132  &outBufferSize);
1133 
1134  if (NT_SUCCESS(status))
1135  {
1136  cmdOutParameters = (PSENDCMDOUTPARAMS)(outBuffer +
1137  sizeof(SRB_IO_CONTROL));
1138 
1139  DiskSmartData->Length = READ_ATTRIBUTE_BUFFER_SIZE;
1140  RtlCopyMemory(DiskSmartData->VendorSpecific,
1141  cmdOutParameters->bBuffer,
1143  }
1144  ExFreePool(outBuffer);
1145  } else {
1147  }
1148 
1149  break;
1150  }
1151 
1153  {
1154  DiskSmartData->Length = sizeof(ULONG);
1155  *((PULONG)DiskSmartData->VendorSpecific) = FdoExtension->FailureReason;
1156 
1158  break;
1159  }
1160 
1162  case FailurePredictionNone:
1163  default:
1164  {
1166  break;
1167  }
1168  }
1169 
1170  return status;
1171 }
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
struct _SENDCMDOUTPARAMS * PSENDCMDOUTPARAMS
unsigned char * PUCHAR
Definition: retypes.h:3
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define PAGED_CODE()
Definition: video.h:57
smooth NULL
Definition: ftsmooth.c:416
#define READ_ATTRIBUTE_BUFFER_SIZE
Definition: ntdddisk.h:620
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
struct _COMMON_DEVICE_EXTENSION * PCOMMON_DEVICE_EXTENSION
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
FAILURE_PREDICTION_METHOD FailurePredictionCapability
Definition: disk.h:257
#define DISK_TAG_SMART
Definition: disk.h:48
struct _SRB_IO_CONTROL SRB_IO_CONTROL
#define DiskReadSmartData(FdoExtension, SrbControl, BufferSize)
Definition: diskwmi.c:216
unsigned int * PULONG
Definition: retypes.h:1
UCHAR bBuffer[1]
Definition: helper.h:27
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:2938
static SERVICE_STATUS status
Definition: service.c:31
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
Definition: ps.c:97

Referenced by DiskDeviceControl().

◆ DiskReadFailurePredictStatus()

NTSTATUS NTAPI DiskReadFailurePredictStatus ( PFUNCTIONAL_DEVICE_EXTENSION  FdoExtension,
PSTORAGE_FAILURE_PREDICT_STATUS  DiskSmartStatus 
)

Definition at line 1007 of file diskwmi.c.

1028 {
1030  PDISK_DATA diskData = (PDISK_DATA)(commonExtension->DriverData);
1031  NTSTATUS status;
1032 
1033  PAGED_CODE();
1034 
1035  DiskSmartStatus->PredictFailure = FALSE;
1036 
1037  switch(diskData->FailurePredictionCapability)
1038  {
1040  {
1041  UCHAR outBuffer[sizeof(SRB_IO_CONTROL) + (sizeof(SENDCMDINPARAMS) - 1 + sizeof(IDEREGS))];
1042  ULONG outBufferSize = sizeof(outBuffer);
1043  PSENDCMDOUTPARAMS cmdOutParameters;
1044 
1046  (PSRB_IO_CONTROL)outBuffer,
1047  &outBufferSize);
1048 
1049  if (NT_SUCCESS(status))
1050  {
1051  cmdOutParameters = (PSENDCMDOUTPARAMS)(outBuffer +
1052  sizeof(SRB_IO_CONTROL));
1053 
1054  DiskSmartStatus->Reason = 0; // Unknown;
1055  DiskSmartStatus->PredictFailure = ((((PUCHAR)cmdOutParameters->bBuffer)[3] == 0xf4) &&
1056  (((PUCHAR)cmdOutParameters->bBuffer)[4] == 0x2c));
1057  }
1058  break;
1059  }
1060 
1062  {
1063  DiskSmartStatus->Reason = FdoExtension->FailureReason;
1064  DiskSmartStatus->PredictFailure = FdoExtension->FailurePredicted;
1066  break;
1067  }
1068 
1070  case FailurePredictionNone:
1071  default:
1072  {
1074  break;
1075  }
1076  }
1077 
1078  return status;
1079 }
struct _DISK_DATA * PDISK_DATA
struct _SENDCMDOUTPARAMS * PSENDCMDOUTPARAMS
unsigned char * PUCHAR
Definition: retypes.h:3
#define DiskReadSmartStatus(FdoExtension, SrbControl, BufferSize)
Definition: diskwmi.c:256
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define PAGED_CODE()
Definition: video.h:57
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
struct _COMMON_DEVICE_EXTENSION * PCOMMON_DEVICE_EXTENSION
unsigned char UCHAR
Definition: xmlstorage.h:181
FAILURE_PREDICTION_METHOD FailurePredictionCapability
Definition: disk.h:257
struct _SRB_IO_CONTROL SRB_IO_CONTROL
UCHAR bBuffer[1]
Definition: helper.h:27
unsigned int ULONG
Definition: retypes.h:1
struct _IDEREGS IDEREGS
return STATUS_SUCCESS
Definition: btrfs.c:2938
static SERVICE_STATUS status
Definition: service.c:31
Definition: ps.c:97

Referenced by DiskDetectFailurePrediction(), and DiskDeviceControl().

◆ DiskReadFailurePredictThresholds()

NTSTATUS NTAPI DiskReadFailurePredictThresholds ( PFUNCTIONAL_DEVICE_EXTENSION  FdoExtension,
PSTORAGE_FAILURE_PREDICT_THRESHOLDS  DiskSmartThresholds 
)

Definition at line 1175 of file diskwmi.c.

1197 {
1199  PDISK_DATA diskData = (PDISK_DATA)(commonExtension->DriverData);
1200  NTSTATUS status;
1201 
1202  PAGED_CODE();
1203 
1204  switch(diskData->FailurePredictionCapability)
1205  {
1207  {
1208  PUCHAR outBuffer;
1209  PSENDCMDOUTPARAMS cmdOutParameters;
1210  ULONG outBufferSize;
1211 
1212  outBufferSize = sizeof(SRB_IO_CONTROL) +
1213  (sizeof(SENDCMDOUTPARAMS)-1) +
1215 
1216  outBuffer = ExAllocatePoolWithTag(NonPagedPool,
1217  outBufferSize,
1218  DISK_TAG_SMART);
1219 
1220  if (outBuffer != NULL)
1221  {
1223  (PSRB_IO_CONTROL)outBuffer,
1224  &outBufferSize);
1225 
1226  if (NT_SUCCESS(status))
1227  {
1228  cmdOutParameters = (PSENDCMDOUTPARAMS)(outBuffer +
1229  sizeof(SRB_IO_CONTROL));
1230 
1231  RtlCopyMemory(DiskSmartThresholds->VendorSpecific,
1232  cmdOutParameters->bBuffer,
1234  }
1235  ExFreePool(outBuffer);
1236  } else {
1238  }
1239 
1240  break;
1241  }
1242 
1245  case FailurePredictionNone:
1246  default:
1247  {
1249  break;
1250  }
1251  }
1252 
1253  return status;
1254 }
#define DiskReadSmartThresholds(FdoExtension, SrbControl, BufferSize)
Definition: diskwmi.c:236
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
struct _SENDCMDOUTPARAMS * PSENDCMDOUTPARAMS
unsigned char * PUCHAR
Definition: retypes.h:3
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define PAGED_CODE()
Definition: video.h:57
smooth NULL
Definition: ftsmooth.c:416
#define READ_THRESHOLD_BUFFER_SIZE
Definition: ntdddisk.h:622
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
struct _COMMON_DEVICE_EXTENSION * PCOMMON_DEVICE_EXTENSION
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
FAILURE_PREDICTION_METHOD FailurePredictionCapability
Definition: disk.h:257
#define DISK_TAG_SMART
Definition: disk.h:48
struct _SRB_IO_CONTROL SRB_IO_CONTROL
UCHAR bBuffer[1]
Definition: helper.h:27
unsigned int ULONG
Definition: retypes.h:1
static SERVICE_STATUS status
Definition: service.c:31
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
Definition: ps.c:97

Referenced by DiskFdoQueryWmiDataBlock().

◆ DiskReadSmartLog()

NTSTATUS NTAPI DiskReadSmartLog ( IN PFUNCTIONAL_DEVICE_EXTENSION  FdoExtension,
IN UCHAR  SectorCount,
IN UCHAR  LogAddress,
OUT PUCHAR  Buffer 
)

Definition at line 394 of file diskwmi.c.

400 {
401  PSRB_IO_CONTROL srbControl;
403  PSENDCMDOUTPARAMS sendCmdOutParams;
404  ULONG logSize, bufferSize;
405 
406  PAGED_CODE();
407 
409  bufferSize = sizeof(SRB_IO_CONTROL) + sizeof(SENDCMDINPARAMS) - 1 +
410  logSize;
411 
412  srbControl = ExAllocatePoolWithTag(NonPagedPool,
413  bufferSize,
415 
416  if (srbControl != NULL)
417  {
420  SMART_CMD,
422  SectorCount,
423  LogAddress,
424  srbControl,
425  &bufferSize);
426 
427  if (NT_SUCCESS(status))
428  {
429  sendCmdOutParams = (PSENDCMDOUTPARAMS)((PUCHAR)srbControl +
430  sizeof(SRB_IO_CONTROL));
432  &sendCmdOutParams->bBuffer[0],
433  logSize);
434  }
435 
436  ExFreePool(srbControl);
437  } else {
439  }
440  return(status);
441 }
#define SMART_LOG_SECTOR_SIZE
Definition: ntdddisk.h:623
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
struct _SENDCMDOUTPARAMS * PSENDCMDOUTPARAMS
unsigned char * PUCHAR
Definition: retypes.h:3
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI 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)
Definition: diskwmi.c:493
#define PAGED_CODE()
Definition: video.h:57
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define IOCTL_SCSI_MINIPORT_READ_SMART_LOG
Definition: scsi.h:1420
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
ULONG SectorCount
Definition: part_xbox.c:32
#define DISK_TAG_SMART
Definition: disk.h:48
#define SMART_CMD
Definition: helper.h:21
struct _SRB_IO_CONTROL SRB_IO_CONTROL
#define SMART_READ_LOG
Definition: ntdddisk.h:638
UCHAR bBuffer[1]
Definition: helper.h:27
unsigned int ULONG
Definition: retypes.h:1
static SERVICE_STATUS status
Definition: service.c:31
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
Definition: ps.c:97

Referenced by DiskFdoExecuteWmiMethod().

◆ DiskReregWorker()

void NTAPI DiskReregWorker ( IN PVOID  Context)

Definition at line 1256 of file diskwmi.c.

1259 {
1260  PDISKREREGREQUEST reregRequest;
1261  NTSTATUS status;
1262  PDEVICE_OBJECT deviceObject;
1263  PIRP irp;
1264 
1265  PAGED_CODE();
1266 
1267  do
1268  {
1270  &DiskReregHead,
1272 
1273  deviceObject = reregRequest->DeviceObject;
1274  irp = reregRequest->Irp;
1275 
1276  status = IoWMIRegistrationControl(deviceObject,
1278 
1279  if (! NT_SUCCESS(status))
1280  {
1281  DebugPrint((1, "DiskReregWorker: Reregistration failed %x\n",
1282  status));
1283  }
1284 
1285  //
1286  // Release remove lock and free irp, now that we are done
1287  // processing this
1288  //
1289  ClassReleaseRemoveLock(deviceObject, irp);
1290 
1291  IoFreeMdl(irp->MdlAddress);
1292  IoFreeIrp(irp);
1293 
1294  ExFreePool(reregRequest);
1295 
1297 
1298 
1299 }
KSPIN_LOCK DiskReregSpinlock
Definition: diskwmi.c:93
PDEVICE_OBJECT DeviceObject
Definition: disk.h:346
LONG NTSTATUS
Definition: precomp.h:26
LONG DiskReregWorkItems
Definition: diskwmi.c:94
#define PAGED_CODE()
Definition: video.h:57
NTSTATUS NTAPI IoWMIRegistrationControl(IN PDEVICE_OBJECT DeviceObject, IN ULONG Action)
Definition: wmi.c:68
PSINGLE_LIST_ENTRY NTAPI ExInterlockedPopEntryList(IN OUT PSINGLE_LIST_ENTRY ListHead, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:201
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
VOID NTAPI IoFreeMdl(PMDL Mdl)
Definition: iomdl.c:146
#define InterlockedDecrement
Definition: armddk.h:52
#define WMIREG_ACTION_UPDATE_GUIDS
SINGLE_LIST_ENTRY DiskReregHead
Definition: diskwmi.c:92
ULONG NTAPI DebugPrint(IN PSTRING DebugString, IN ULONG ComponentId, IN ULONG Level)
Definition: debug.c:23
struct DISKREREGREQUEST * PDISKREREGREQUEST
VOID NTAPI IoFreeIrp(IN PIRP Irp)
Definition: irp.c:1666
static SERVICE_STATUS status
Definition: service.c:31
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
VOID NTAPI ClassReleaseRemoveLock(IN PDEVICE_OBJECT DeviceObject, IN OPTIONAL PIRP Tag)
Definition: lock.c:212
Definition: ps.c:97

Referenced by DiskInitializeReregistration().

◆ DiskSendFailurePredictIoctl()

NTSTATUS NTAPI DiskSendFailurePredictIoctl ( PFUNCTIONAL_DEVICE_EXTENSION  FdoExtension,
PSTORAGE_PREDICT_FAILURE  checkFailure 
)

Definition at line 833 of file diskwmi.c.

837 {
838  KEVENT event;
839  PDEVICE_OBJECT deviceObject;
840  IO_STATUS_BLOCK ioStatus;
841  PIRP irp;
843 
844  PAGED_CODE();
845 
847 
848  deviceObject = IoGetAttachedDeviceReference(FdoExtension->DeviceObject);
849 
852  deviceObject,
853  NULL,
854  0,
855  checkFailure,
856  sizeof(STORAGE_PREDICT_FAILURE),
857  FALSE,
858  &event,
859  &ioStatus);
860 
861  if (irp != NULL)
862  {
863  status = IoCallDriver(deviceObject, irp);
864  if (status == STATUS_PENDING)
865  {
867  status = ioStatus.Status;
868  }
869 
870  } else {
872  }
873 
874  ObDereferenceObject(deviceObject);
875 
876  return status;
877 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define PAGED_CODE()
Definition: video.h:57
smooth NULL
Definition: ftsmooth.c:416
PDEVICE_OBJECT NTAPI IoGetAttachedDeviceReference(PDEVICE_OBJECT DeviceObject)
Definition: device.c:1406
#define STATUS_PENDING
Definition: ntstatus.h:82
struct _cl_event * event
Definition: glext.h:7739
#define IOCTL_STORAGE_PREDICT_FAILURE
Definition: ntddstor.h:135
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
PIRP NTAPI IoBuildDeviceIoControlRequest(IN ULONG IoControlCode, IN PDEVICE_OBJECT DeviceObject, IN PVOID InputBuffer, IN ULONG InputBufferLength, IN PVOID OutputBuffer, IN ULONG OutputBufferLength, IN BOOLEAN InternalDeviceIoControl, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:881
static SERVICE_STATUS status
Definition: service.c:31
Definition: ps.c:97

Referenced by DiskDetectFailurePrediction(), and DiskFdoQueryWmiDataBlock().

◆ DiskWmiFunctionControl()

NTSTATUS NTAPI DiskWmiFunctionControl ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp,
IN ULONG  GuidIndex,
IN CLASSENABLEDISABLEFUNCTION  Function,
IN BOOLEAN  Enable 
)

Definition at line 1901 of file diskwmi.c.

1947 {
1949  //PCOMMON_DEVICE_EXTENSION commonExtension = DeviceObject->DeviceExtension;
1951  //PDISK_DATA diskData = (PDISK_DATA)(commonExtension->DriverData);
1952  //ULONG enableCount;
1953 
1954  PAGED_CODE();
1955 
1956  if ((Function == DataBlockCollection) && Enable)
1957  {
1958  if ((GuidIndex == SmartStatusGuid) ||
1959  (GuidIndex == SmartDataGuid) ||
1962  {
1964  TRUE);
1965  DebugPrint((3, "Disk: DeviceObject %p, Irp %p Enable -> %lx\n",
1966  DeviceObject,
1967  Irp,
1968  status));
1969 
1970  } else {
1971  DebugPrint((3, "Disk: DeviceObject %p, Irp %p, GuidIndex %d %s for Collection\n",
1972  DeviceObject, Irp,
1973  GuidIndex,
1974  Enable ? "Enabled" : "Disabled")); }
1975  } else if (Function == EventGeneration) {
1976  DebugPrint((3, "Disk: DeviceObject %p, Irp %p, GuidIndex %d %s for Event Generation\n",
1977  DeviceObject, Irp,
1978  GuidIndex,
1979  Enable ? "Enabled" : "Disabled"));
1980 
1981 
1982  if ((GuidIndex == SmartEventGuid) && Enable)
1983  {
1985  Enable,
1986  0);
1987  DebugPrint((3, "Disk: DeviceObject %p, Irp %p %s -> %lx\n",
1988  DeviceObject,
1989  Irp,
1990  Enable ? "DiskEnableSmartPolling" : "DiskDisableSmartPolling",
1991  status));
1992  }
1993 
1994 #if DBG
1995  } else {
1996  DebugPrint((3, "Disk: DeviceObject %p, Irp %p, GuidIndex %d %s for function %d\n",
1997  DeviceObject, Irp,
1998  GuidIndex,
1999  Enable ? "Enabled" : "Disabled",
2000  Function));
2001 #endif
2002  }
2003 
2005  Irp,
2006  status,
2007  0,
2008  IO_NO_INCREMENT);
2009  return status;
2010 }
#define TRUE
Definition: types.h:120
_In_ PIRP Irp
Definition: csq.h:116
#define SmartEventGuid
Definition: diskwmi.c:156
LONG NTSTATUS
Definition: precomp.h:26
_In_ ULONGLONG _In_ ULONGLONG _In_ BOOLEAN Enable
Definition: ntddpcm.h:140
#define PAGED_CODE()
Definition: video.h:57
NTSTATUS NTAPI DiskEnableDisableFailurePrediction(PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, BOOLEAN Enable)
Definition: diskwmi.c:885
static LPOVERLAPPED_COMPLETION_ROUTINE Function
Definition: sync.c:684
PVOID DeviceExtension
Definition: env_spec_w32.h:418
_In_ PIRP _In_ ULONG GuidIndex
Definition: classpnp.h:401
NTSTATUS NTAPI DiskEnableDisableFailurePredictPolling(PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, BOOLEAN Enable, ULONG PollTimeInSeconds)
Definition: diskwmi.c:949
#define SmartStatusGuid
Definition: diskwmi.c:147
#define SmartThresholdsGuid
Definition: diskwmi.c:157
ULONG NTAPI DebugPrint(IN PSTRING DebugString, IN ULONG ComponentId, IN ULONG Level)
Definition: debug.c:23
SCSIPORTAPI NTSTATUS NTAPI ClassWmiCompleteRequest(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN NTSTATUS Status, IN ULONG BufferUsed, IN CCHAR PriorityBoost)
Definition: classwmi.c:559
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define SmartPerformFunction
Definition: diskwmi.c:149
#define SmartDataGuid
Definition: diskwmi.c:148
#define IO_NO_INCREMENT
Definition: iotypes.h:566
return STATUS_SUCCESS
Definition: btrfs.c:2938
static SERVICE_STATUS status
Definition: service.c:31
Definition: ps.c:97

Referenced by DriverEntry().

◆ DiskWriteSmartLog()

NTSTATUS NTAPI DiskWriteSmartLog ( IN PFUNCTIONAL_DEVICE_EXTENSION  FdoExtension,
IN UCHAR  SectorCount,
IN UCHAR  LogAddress,
IN PUCHAR  Buffer 
)

Definition at line 446 of file diskwmi.c.

452 {
453  PSRB_IO_CONTROL srbControl;
455  PSENDCMDINPARAMS sendCmdInParams;
456  ULONG logSize, bufferSize;
457 
458  PAGED_CODE();
459 
461  bufferSize = sizeof(SRB_IO_CONTROL) + sizeof(SENDCMDINPARAMS) - 1 +
462  logSize;
463 
464  srbControl = ExAllocatePoolWithTag(NonPagedPool,
465  bufferSize,
467 
468  if (srbControl != NULL)
469  {
470  sendCmdInParams = (PSENDCMDINPARAMS)((PUCHAR)srbControl +
471  sizeof(SRB_IO_CONTROL));
472  RtlCopyMemory(&sendCmdInParams->bBuffer[0],
473  Buffer,
474  logSize);
477  SMART_CMD,
479  SectorCount,
480  LogAddress,
481  srbControl,
482  &bufferSize);
483 
484  ExFreePool(srbControl);
485  } else {
487  }
488  return(status);
489 }
#define SMART_LOG_SECTOR_SIZE
Definition: ntdddisk.h:623
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
UCHAR bBuffer[1]
Definition: helper.h:36
unsigned char * PUCHAR
Definition: retypes.h:3
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI 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)
Definition: diskwmi.c:493
#define PAGED_CODE()
Definition: video.h:57
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
ULONG SectorCount
Definition: part_xbox.c:32
#define DISK_TAG_SMART
Definition: disk.h:48
#define SMART_CMD
Definition: helper.h:21
struct _SRB_IO_CONTROL SRB_IO_CONTROL
#define IOCTL_SCSI_MINIPORT_WRITE_SMART_LOG
Definition: scsi.h:1421
unsigned int ULONG
Definition: retypes.h:1
#define SMART_WRITE_LOG
Definition: ntdddisk.h:639
static SERVICE_STATUS status
Definition: service.c:31
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
struct _SENDCMDINPARAMS * PSENDCMDINPARAMS
Definition: ps.c:97

Referenced by DiskFdoExecuteWmiMethod().

Variable Documentation

◆ DiskPredictFailureEventGuid

GUID DiskPredictFailureEventGuid = WMI_STORAGE_PREDICT_FAILURE_EVENT_GUID

Definition at line 144 of file diskwmi.c.

◆ DiskReregHead

SINGLE_LIST_ENTRY DiskReregHead

Definition at line 92 of file diskwmi.c.

Referenced by DiskPostReregisterRequest(), and DiskReregWorker().

◆ DiskReregSpinlock

KSPIN_LOCK DiskReregSpinlock

◆ DiskReregWorkItem

WORK_QUEUE_ITEM DiskReregWorkItem

Definition at line 91 of file diskwmi.c.

Referenced by DiskInitializeReregistration(), and DiskPostReregisterRequest().

◆ DiskReregWorkItems

LONG DiskReregWorkItems

Definition at line 94 of file diskwmi.c.

Referenced by DiskPostReregisterRequest(), and DiskReregWorker().

◆ DiskWmiFdoGuidList

GUIDREGINFO DiskWmiFdoGuidList[]

Definition at line 96 of file diskwmi.c.

Referenced by DiskFdoQueryWmiRegInfo(), and DriverEntry().