ReactOS  0.4.14-dev-1115-gebeeb9d
disk.h File Reference
#include <ntddk.h>
#include <wmidata.h>
#include <classpnp.h>
Include dependency graph for disk.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _DISK_DATA
 
struct  _DISK_MEDIA_TYPES_LIST
 
struct  DISKREREGREQUEST
 
struct  _DISK_VERIFY_WORKITEM_CONTEXT
 

Macros

#define _WIN32_WINNT   0x0501
 
#define NTDDI_VERSION   NTDDI_WINXP
 
#define DISK_TAG_GENERAL   ' DcS'
 
#define DISK_TAG_SMART   'aDcS'
 
#define DISK_TAG_INFO_EXCEPTION   'ADcS'
 
#define DISK_TAG_DISABLE_CACHE   'CDcS'
 
#define DISK_TAG_CCONTEXT   'cDcS'
 
#define DISK_TAG_DISK_GEOM   'GDcS'
 
#define DISK_TAG_UPDATE_GEOM   'gDcS'
 
#define DISK_TAG_SENSE_INFO   'IDcS'
 
#define DISK_TAG_PNP_ID   'iDcS'
 
#define DISK_TAG_MODE_DATA   'MDcS'
 
#define DISK_CACHE_MBR_CHECK   'mDcS'
 
#define DISK_TAG_NAME   'NDcS'
 
#define DISK_TAG_READ_CAP   'PDcS'
 
#define DISK_TAG_PART_LIST   'pDcS'
 
#define DISK_TAG_SRB   'SDcS'
 
#define DISK_TAG_START   'sDcS'
 
#define DISK_TAG_UPDATE_CAP   'UDcS'
 
#define DISK_TAG_WI_CONTEXT   'WDcS'
 
#define HackDisableTaggedQueuing   (0x01)
 
#define HackDisableSynchronousTransfers   (0x02)
 
#define HackDisableSpinDown   (0x04)
 
#define HackDisableWriteCache   (0x08)
 
#define HackCauseNotReportableHack   (0x10)
 
#define HackRequiresStartUnitCommand   (0x20)
 
#define HackDisableWriteCacheNotSupported   (0x40)
 
#define DiskDeviceParameterSubkey   L"Disk"
 
#define DiskDeviceSpecialFlags   L"SpecialFlags"
 
#define DiskDeviceUserWriteCacheSetting   L"UserWriteCacheSetting"
 
#define FUNCTIONAL_EXTENSION_SIZE   sizeof(FUNCTIONAL_DEVICE_EXTENSION) + sizeof(DISK_DATA)
 
#define PHYSICAL_EXTENSION_SIZE   sizeof(PHYSICAL_DEVICE_EXTENSION) + sizeof(DISK_DATA)
 
#define MODE_DATA_SIZE   192
 
#define VALUE_BUFFER_SIZE   2048
 
#define SCSI_DISK_TIMEOUT   10
 
#define PARTITION0_LIST_SIZE   4
 
#define MAX_MEDIA_TYPES   4
 
#define MAX_SECTORS_PER_VERIFY   0x200
 
#define ONE_MILLI_SECOND   ((ULONGLONG)10 * 1000)
 
#define DISK_DEFAULT_FAILURE_POLLING_PERIOD   1 * 60 * 60
 
#define DiskIsValidSmartSelfTest(Subcommand)
 
#define DiskReadDriveCapacity(Fdo)   ClassReadDriveCapacity(Fdo)
 
#define DiskGetDetectInfo(FdoExtension, DetectInfo)   (STATUS_UNSUCCESSFUL)
 
#define DiskHashGuid(Guid)   (((PULONG) &Guid)[0] ^ ((PULONG) &Guid)[0] ^ ((PULONG) &Guid)[0] ^ ((PULONG) &Guid)[0])
 

Typedefs

typedef VOID(NTAPIPDISK_UPDATE_PARTITIONS) (IN PDEVICE_OBJECT Fdo, IN OUT PDRIVE_LAYOUT_INFORMATION_EX PartitionList)
 
typedef struct _DISK_DATA DISK_DATA
 
typedef struct _DISK_DATAPDISK_DATA
 
typedef struct _DISK_MEDIA_TYPES_LIST DISK_MEDIA_TYPES_LIST
 
typedef struct _DISK_MEDIA_TYPES_LISTPDISK_MEDIA_TYPES_LIST
 
typedef struct DISKREREGREQUESTPDISKREREGREQUEST
 
typedef enum _DISK_USER_WRITE_CACHE_SETTING DISK_USER_WRITE_CACHE_SETTING
 
typedef enum _DISK_USER_WRITE_CACHE_SETTINGPDISK_USER_WRITE_CACHE_SETTING
 
typedef struct _DISK_VERIFY_WORKITEM_CONTEXT DISK_VERIFY_WORKITEM_CONTEXT
 
typedef struct _DISK_VERIFY_WORKITEM_CONTEXTPDISK_VERIFY_WORKITEM_CONTEXT
 

Enumerations

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

Functions

NTSTATUS NTAPI DriverEntry (IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath)
 
VOID NTAPI DiskUnload (IN PDRIVER_OBJECT DriverObject)
 
NTSTATUS NTAPI DiskAddDevice (IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT Pdo)
 
NTSTATUS NTAPI DiskInitFdo (IN PDEVICE_OBJECT Fdo)
 
NTSTATUS NTAPI DiskInitPdo (IN PDEVICE_OBJECT Pdo)
 
NTSTATUS NTAPI DiskStartFdo (IN PDEVICE_OBJECT Fdo)
 
NTSTATUS NTAPI DiskStartPdo (IN PDEVICE_OBJECT Pdo)
 
NTSTATUS NTAPI DiskStopDevice (IN PDEVICE_OBJECT DeviceObject, IN UCHAR Type)
 
NTSTATUS NTAPI DiskRemoveDevice (IN PDEVICE_OBJECT DeviceObject, IN UCHAR Type)
 
NTSTATUS NTAPI DiskReadWriteVerification (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI DiskDeviceControl (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
VOID NTAPI DiskFdoProcessError (PDEVICE_OBJECT DeviceObject, PSCSI_REQUEST_BLOCK Srb, NTSTATUS *Status, BOOLEAN *Retry)
 
NTSTATUS NTAPI DiskShutdownFlush (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI DiskGetCacheInformation (IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, IN PDISK_CACHE_INFORMATION CacheInfo)
 
NTSTATUS NTAPI DiskSetCacheInformation (IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, IN PDISK_CACHE_INFORMATION CacheInfo)
 
VOID NTAPI DisableWriteCache (IN PDEVICE_OBJECT DeviceObject, IN PIO_WORKITEM WorkItem)
 
VOID NTAPI DiskIoctlVerify (IN PDEVICE_OBJECT DeviceObject, IN PDISK_VERIFY_WORKITEM_CONTEXT Context)
 
NTSTATUS NTAPI DiskModeSelect (IN PDEVICE_OBJECT DeviceObject, IN PCHAR ModeSelectBuffer, IN ULONG Length, IN BOOLEAN SavePage)
 
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 DiskGetInfoExceptionInformation (IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, OUT PMODE_INFO_EXCEPTIONS ReturnPageData)
 
NTSTATUS NTAPI DiskSetInfoExceptionInformation (IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, IN PMODE_INFO_EXCEPTIONS PageData)
 
NTSTATUS NTAPI DiskDetectFailurePrediction (PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, PFAILURE_PREDICTION_METHOD FailurePredictCapability)
 
BOOLEAN NTAPI EnumerateBusKey (IN PFUNCTIONAL_DEVICE_EXTENSION DeviceExtension, HANDLE BusKey, PULONG DiskNumber)
 
NTSTATUS NTAPI DiskCreateFdo (IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT LowerDeviceObject, IN PULONG DeviceCount, IN BOOLEAN DasdAccessOnly)
 
VOID NTAPI UpdateDeviceObjects (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
VOID NTAPI DiskSetSpecialHacks (IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, IN ULONG_PTR Data)
 
VOID NTAPI DiskScanRegistryForSpecial (IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension)
 
VOID NTAPI ResetBus (IN PDEVICE_OBJECT DeviceObject)
 
NTSTATUS NTAPI DiskEnumerateDevice (IN PDEVICE_OBJECT Fdo)
 
NTSTATUS NTAPI DiskQueryId (IN PDEVICE_OBJECT Pdo, IN BUS_QUERY_ID_TYPE IdType, IN PUNICODE_STRING UnicodeIdString)
 
NTSTATUS NTAPI DiskQueryPnpCapabilities (IN PDEVICE_OBJECT DeviceObject, IN PDEVICE_CAPABILITIES Capabilities)
 
NTSTATUS NTAPI DiskGenerateDeviceName (IN BOOLEAN IsFdo, IN ULONG DeviceNumber, IN OPTIONAL ULONG PartitionNumber, IN OPTIONAL PLARGE_INTEGER StartingOffset, IN OPTIONAL PLARGE_INTEGER PartitionLength, OUT PUCHAR *RawName)
 
VOID NTAPI DiskCreateSymbolicLinks (IN PDEVICE_OBJECT DeviceObject)
 
VOID NTAPI DiskUpdatePartitions (IN PDEVICE_OBJECT Fdo, IN OUT PDRIVE_LAYOUT_INFORMATION_EX PartitionList)
 
VOID NTAPI DiskUpdateRemovablePartitions (IN PDEVICE_OBJECT Fdo, IN OUT PDRIVE_LAYOUT_INFORMATION_EX PartitionList)
 
NTSTATUS NTAPI DiskCreatePdo (IN PDEVICE_OBJECT Fdo, IN ULONG PartitionOrdinal, IN PPARTITION_INFORMATION_EX PartitionEntry, IN PARTITION_STYLE PartitionStyle, OUT PDEVICE_OBJECT *Pdo)
 
VOID NTAPI DiskDeleteSymbolicLinks (IN PDEVICE_OBJECT DeviceObject)
 
NTSTATUS NTAPI DiskPdoQueryWmiRegInfo (IN PDEVICE_OBJECT DeviceObject, OUT ULONG *RegFlags, OUT PUNICODE_STRING InstanceName)
 
NTSTATUS NTAPI DiskPdoQueryWmiDataBlock (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN ULONG GuidIndex, IN ULONG BufferAvail, OUT PUCHAR Buffer)
 
NTSTATUS NTAPI DiskPdoSetWmiDataBlock (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN ULONG GuidIndex, IN ULONG BufferSize, IN PUCHAR Buffer)
 
NTSTATUS NTAPI DiskPdoSetWmiDataItem (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN ULONG GuidIndex, IN ULONG DataItemId, IN ULONG BufferSize, IN PUCHAR Buffer)
 
NTSTATUS NTAPI DiskPdoExecuteWmiMethod (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN ULONG GuidIndex, IN ULONG MethodId, IN ULONG InBufferSize, IN ULONG OutBufferSize, IN PUCHAR Buffer)
 
NTSTATUS NTAPI DiskFdoQueryWmiRegInfo (IN PDEVICE_OBJECT DeviceObject, OUT ULONG *RegFlags, OUT PUNICODE_STRING InstanceName)
 
NTSTATUS NTAPI DiskFdoQueryWmiRegInfoEx (IN PDEVICE_OBJECT DeviceObject, OUT ULONG *RegFlags, OUT PUNICODE_STRING InstanceName, OUT PUNICODE_STRING MofName)
 
NTSTATUS NTAPI DiskFdoQueryWmiDataBlock (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN ULONG GuidIndex, IN ULONG BufferAvail, OUT PUCHAR Buffer)
 
NTSTATUS NTAPI DiskFdoSetWmiDataBlock (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN ULONG GuidIndex, IN ULONG BufferSize, IN PUCHAR Buffer)
 
NTSTATUS NTAPI DiskFdoSetWmiDataItem (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN ULONG GuidIndex, IN ULONG DataItemId, IN ULONG BufferSize, IN PUCHAR Buffer)
 
NTSTATUS NTAPI DiskFdoExecuteWmiMethod (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN ULONG GuidIndex, IN ULONG MethodId, IN ULONG InBufferSize, IN ULONG OutBufferSize, IN PUCHAR Buffer)
 
NTSTATUS NTAPI DiskWmiFunctionControl (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN ULONG GuidIndex, IN CLASSENABLEDISABLEFUNCTION Function, IN BOOLEAN Enable)
 
NTSTATUS 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 DiskEnableDisableFailurePrediction (PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, BOOLEAN Enable)
 
NTSTATUS NTAPI DiskEnableDisableFailurePredictPolling (PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, BOOLEAN Enable, ULONG PollTimeInSeconds)
 
VOID NTAPI DiskAcquirePartitioningLock (IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension)
 
VOID NTAPI DiskReleasePartitioningLock (IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension)
 
NTSTATUS NTAPI DiskInitializeReregistration (void)
 
VOID NTAPI DiskConvertPartitionToExtended (IN PPARTITION_INFORMATION Partition, OUT PPARTITION_INFORMATION_EX PartitionEx)
 
PDRIVE_LAYOUT_INFORMATION_EX NTAPI DiskConvertLayoutToExtended (IN CONST PDRIVE_LAYOUT_INFORMATION Layout)
 
PDRIVE_LAYOUT_INFORMATION NTAPI DiskConvertExtendedToLayout (IN CONST PDRIVE_LAYOUT_INFORMATION_EX LayoutEx)
 
NTSTATUS NTAPI DiskReadPartitionTableEx (IN PFUNCTIONAL_DEVICE_EXTENSION Fdo, IN BOOLEAN BypassCache, OUT PDRIVE_LAYOUT_INFORMATION_EX *DriveLayout)
 
NTSTATUS NTAPI DiskWritePartitionTableEx (IN PFUNCTIONAL_DEVICE_EXTENSION Fdo, IN PDRIVE_LAYOUT_INFORMATION_EX DriveLayout)
 
NTSTATUS NTAPI DiskSetPartitionInformationEx (IN PFUNCTIONAL_DEVICE_EXTENSION Fdo, IN ULONG PartitionNumber, IN struct _SET_PARTITION_INFORMATION_EX *PartitionInfo)
 
NTSTATUS NTAPI DiskSetPartitionInformation (IN PFUNCTIONAL_DEVICE_EXTENSION Fdo, IN ULONG SectorSize, IN ULONG PartitionNumber, IN ULONG PartitionType)
 
NTSTATUS NTAPI DiskVerifyPartitionTable (IN PFUNCTIONAL_DEVICE_EXTENSION Fdo, IN BOOLEAN FixErrors)
 
BOOLEAN NTAPI DiskInvalidatePartitionTable (IN PFUNCTIONAL_DEVICE_EXTENSION Fdo, IN BOOLEAN PartitionLockHeld)
 

Variables

CLASSPNP_SCAN_FOR_SPECIAL_INFO DiskBadControllers []
 
const DISK_MEDIA_TYPES_LIST DiskMediaTypes []
 
GUIDREGINFO DiskWmiFdoGuidList []
 
GUIDREGINFO DiskWmiPdoGuidList []
 

Macro Definition Documentation

◆ _WIN32_WINNT

#define _WIN32_WINNT   0x0501

Definition at line 27 of file disk.h.

◆ DISK_CACHE_MBR_CHECK

#define DISK_CACHE_MBR_CHECK   'mDcS'

Definition at line 57 of file disk.h.

◆ DISK_DEFAULT_FAILURE_POLLING_PERIOD

#define DISK_DEFAULT_FAILURE_POLLING_PERIOD   1 * 60 * 60

Definition at line 382 of file disk.h.

◆ DISK_TAG_CCONTEXT

#define DISK_TAG_CCONTEXT   'cDcS'

Definition at line 51 of file disk.h.

◆ DISK_TAG_DISABLE_CACHE

#define DISK_TAG_DISABLE_CACHE   'CDcS'

Definition at line 50 of file disk.h.

◆ DISK_TAG_DISK_GEOM

#define DISK_TAG_DISK_GEOM   'GDcS'

Definition at line 52 of file disk.h.

◆ DISK_TAG_GENERAL

#define DISK_TAG_GENERAL   ' DcS'

Definition at line 47 of file disk.h.

◆ DISK_TAG_INFO_EXCEPTION

#define DISK_TAG_INFO_EXCEPTION   'ADcS'

Definition at line 49 of file disk.h.

◆ DISK_TAG_MODE_DATA

#define DISK_TAG_MODE_DATA   'MDcS'

Definition at line 56 of file disk.h.

◆ DISK_TAG_NAME

#define DISK_TAG_NAME   'NDcS'

Definition at line 58 of file disk.h.

◆ DISK_TAG_PART_LIST

#define DISK_TAG_PART_LIST   'pDcS'

Definition at line 60 of file disk.h.

◆ DISK_TAG_PNP_ID

#define DISK_TAG_PNP_ID   'iDcS'

Definition at line 55 of file disk.h.

◆ DISK_TAG_READ_CAP

#define DISK_TAG_READ_CAP   'PDcS'

Definition at line 59 of file disk.h.

◆ DISK_TAG_SENSE_INFO

#define DISK_TAG_SENSE_INFO   'IDcS'

Definition at line 54 of file disk.h.

◆ DISK_TAG_SMART

#define DISK_TAG_SMART   'aDcS'

Definition at line 48 of file disk.h.

◆ DISK_TAG_SRB

#define DISK_TAG_SRB   'SDcS'

Definition at line 61 of file disk.h.

◆ DISK_TAG_START

#define DISK_TAG_START   'sDcS'

Definition at line 62 of file disk.h.

◆ DISK_TAG_UPDATE_CAP

#define DISK_TAG_UPDATE_CAP   'UDcS'

Definition at line 63 of file disk.h.

◆ DISK_TAG_UPDATE_GEOM

#define DISK_TAG_UPDATE_GEOM   'gDcS'

Definition at line 53 of file disk.h.

◆ DISK_TAG_WI_CONTEXT

#define DISK_TAG_WI_CONTEXT   'WDcS'

Definition at line 64 of file disk.h.

◆ DiskDeviceParameterSubkey

#define DiskDeviceParameterSubkey   L"Disk"

Definition at line 317 of file disk.h.

◆ DiskDeviceSpecialFlags

#define DiskDeviceSpecialFlags   L"SpecialFlags"

Definition at line 318 of file disk.h.

◆ DiskDeviceUserWriteCacheSetting

#define DiskDeviceUserWriteCacheSetting   L"UserWriteCacheSetting"

Definition at line 319 of file disk.h.

◆ DiskGetDetectInfo

#define DiskGetDetectInfo (   FdoExtension,
  DetectInfo 
)    (STATUS_UNSUCCESSFUL)

Definition at line 976 of file disk.h.

◆ DiskHashGuid

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

Definition at line 980 of file disk.h.

◆ DiskIsValidSmartSelfTest

#define DiskIsValidSmartSelfTest (   Subcommand)
Value:
( ((Subcommand) == SMART_OFFLINE_ROUTINE_OFFLINE) || \
((Subcommand) == SMART_SHORT_SELFTEST_OFFLINE) || \
((Subcommand) == SMART_EXTENDED_SELFTEST_OFFLINE) )
#define SMART_SHORT_SELFTEST_OFFLINE
Definition: ntdddisk.h:607
#define SMART_EXTENDED_SELFTEST_OFFLINE
Definition: ntdddisk.h:608
#define SMART_OFFLINE_ROUTINE_OFFLINE
Definition: ntdddisk.h:606

Definition at line 533 of file disk.h.

◆ DiskReadDriveCapacity

#define DiskReadDriveCapacity (   Fdo)    ClassReadDriveCapacity(Fdo)

Definition at line 860 of file disk.h.

◆ FUNCTIONAL_EXTENSION_SIZE

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

Definition at line 322 of file disk.h.

◆ HackCauseNotReportableHack

#define HackCauseNotReportableHack   (0x10)

Definition at line 312 of file disk.h.

◆ HackDisableSpinDown

#define HackDisableSpinDown   (0x04)

Definition at line 310 of file disk.h.

◆ HackDisableSynchronousTransfers

#define HackDisableSynchronousTransfers   (0x02)

Definition at line 309 of file disk.h.

◆ HackDisableTaggedQueuing

#define HackDisableTaggedQueuing   (0x01)

Definition at line 308 of file disk.h.

◆ HackDisableWriteCache

#define HackDisableWriteCache   (0x08)

Definition at line 311 of file disk.h.

◆ HackDisableWriteCacheNotSupported

#define HackDisableWriteCacheNotSupported   (0x40)

Definition at line 314 of file disk.h.

◆ HackRequiresStartUnitCommand

#define HackRequiresStartUnitCommand   (0x20)

Definition at line 313 of file disk.h.

◆ MAX_MEDIA_TYPES

#define MAX_MEDIA_TYPES   4

Definition at line 330 of file disk.h.

◆ MAX_SECTORS_PER_VERIFY

#define MAX_SECTORS_PER_VERIFY   0x200

Definition at line 361 of file disk.h.

◆ MODE_DATA_SIZE

#define MODE_DATA_SIZE   192

Definition at line 325 of file disk.h.

◆ NTDDI_VERSION

#define NTDDI_VERSION   NTDDI_WINXP

Definition at line 28 of file disk.h.

◆ ONE_MILLI_SECOND

#define ONE_MILLI_SECOND   ((ULONGLONG)10 * 1000)

Definition at line 366 of file disk.h.

◆ PARTITION0_LIST_SIZE

#define PARTITION0_LIST_SIZE   4

Definition at line 328 of file disk.h.

◆ PHYSICAL_EXTENSION_SIZE

#define PHYSICAL_EXTENSION_SIZE   sizeof(PHYSICAL_DEVICE_EXTENSION) + sizeof(DISK_DATA)

Definition at line 323 of file disk.h.

◆ SCSI_DISK_TIMEOUT

#define SCSI_DISK_TIMEOUT   10

Definition at line 327 of file disk.h.

◆ VALUE_BUFFER_SIZE

#define VALUE_BUFFER_SIZE   2048

Definition at line 326 of file disk.h.

Typedef Documentation

◆ DISK_DATA

◆ DISK_MEDIA_TYPES_LIST

◆ DISK_USER_WRITE_CACHE_SETTING

◆ DISK_VERIFY_WORKITEM_CONTEXT

◆ PDISK_DATA

◆ PDISK_MEDIA_TYPES_LIST

◆ PDISK_UPDATE_PARTITIONS

typedef VOID(NTAPI * PDISK_UPDATE_PARTITIONS) (IN PDEVICE_OBJECT Fdo, IN OUT PDRIVE_LAYOUT_INFORMATION_EX PartitionList)

Definition at line 68 of file disk.h.

◆ PDISK_USER_WRITE_CACHE_SETTING

◆ PDISK_VERIFY_WORKITEM_CONTEXT

◆ PDISKREREGREQUEST

Enumeration Type Documentation

◆ _DISK_USER_WRITE_CACHE_SETTING

Enumerator
DiskWriteCacheDisable 
DiskWriteCacheEnable 
DiskWriteCacheDefault 

Definition at line 353 of file disk.h.

354 {
358 
enum _DISK_USER_WRITE_CACHE_SETTING * PDISK_USER_WRITE_CACHE_SETTING
enum _DISK_USER_WRITE_CACHE_SETTING DISK_USER_WRITE_CACHE_SETTING

Function Documentation

◆ DisableWriteCache()

VOID NTAPI DisableWriteCache ( IN PDEVICE_OBJECT  DeviceObject,
IN PIO_WORKITEM  WorkItem 
)

Definition at line 3616 of file disk.c.

3621 {
3622  ULONG specialFlags = 0;
3623  PFUNCTIONAL_DEVICE_EXTENSION fdoExtension;
3624  DISK_CACHE_INFORMATION cacheInfo;
3625  NTSTATUS status;
3626 
3627  PAGED_CODE();
3628 
3629  fdoExtension = Fdo->DeviceExtension;
3630 
3631  ASSERT(fdoExtension->CommonExtension.IsFdo);
3632 
3633  DebugPrint((1, "Disk.DisableWriteCache: Disabling Write Cache\n"));
3634 
3635  ClassGetDeviceParameter(fdoExtension,
3638  &specialFlags);
3639 
3640  RtlZeroMemory(&cacheInfo, sizeof(DISK_CACHE_INFORMATION));
3641 
3642  status = DiskGetCacheInformation(fdoExtension, &cacheInfo);
3643 
3644  if (NT_SUCCESS(status) && (cacheInfo.WriteCacheEnabled != FALSE)) {
3645 
3646  cacheInfo.WriteCacheEnabled = FALSE;
3647 
3648  status = DiskSetCacheInformation(fdoExtension, &cacheInfo);
3649 
3651  {
3652  //
3653  // This device does not allow for
3654  // the write cache to be disabled
3655  //
3657 
3659  }
3660 
3661  //
3662  // ISSUE ( April 5, 2001 ) : This should happen inside of DiskSetCacheInformation
3663  //
3664  CLEAR_FLAG(fdoExtension->DeviceFlags, DEV_WRITE_CACHE);
3665  }
3666 
3667  //
3668  // Set a flag in the registry to help
3669  // identify this device across boots
3670  //
3671  SET_FLAG(specialFlags, HackDisableWriteCache);
3672 
3674 
3675  ClassSetDeviceParameter(fdoExtension,
3678  specialFlags);
3679 
3680  IoFreeWorkItem(WorkItem);
3681 }
#define HackDisableWriteCache
Definition: disk.h:311
LONG NTSTATUS
Definition: precomp.h:26
COMMON_DEVICE_EXTENSION CommonExtension
Definition: classpnp.h:695
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define CLASS_SPECIAL_DISABLE_WRITE_CACHE_NOT_SUPPORTED
Definition: classpnp.h:168
VOID NTAPI IoFreeWorkItem(IN PIO_WORKITEM IoWorkItem)
Definition: iowork.c:64
#define PAGED_CODE()
Definition: video.h:57
#define DEV_WRITE_CACHE
Definition: class2.h:21
#define DiskDeviceParameterSubkey
Definition: disk.h:317
#define CLASS_SPECIAL_DISABLE_WRITE_CACHE
Definition: classpnp.h:165
NTSTATUS NTAPI ClassSetDeviceParameter(IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, IN PWSTR SubkeyName OPTIONAL, IN PWSTR ParameterName, IN ULONG ParameterValue)
Definition: utils.c:136
#define DiskDeviceSpecialFlags
Definition: disk.h:318
#define CLEAR_FLAG(Flags, Bit)
Definition: classpnp.h:155
VOID NTAPI ClassGetDeviceParameter(IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, IN PWSTR SubkeyName OPTIONAL, IN PWSTR ParameterName, IN OUT PULONG ParameterValue)
Definition: utils.c:52
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
NTSTATUS NTAPI DiskGetCacheInformation(IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, IN PDISK_CACHE_INFORMATION CacheInfo)
Definition: disk.c:4314
#define HackDisableWriteCacheNotSupported
Definition: disk.h:314
#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
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
NTSTATUS NTAPI DiskSetCacheInformation(IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, IN PDISK_CACHE_INFORMATION CacheInfo)
Definition: disk.c:4432
static SERVICE_STATUS status
Definition: service.c:31
Definition: ps.c:97

◆ DiskAcquirePartitioningLock()

VOID NTAPI DiskAcquirePartitioningLock ( IN PFUNCTIONAL_DEVICE_EXTENSION  FdoExtension)

Definition at line 1214 of file enum.c.

1217 {
1218  PDISK_DATA diskData = FdoExtension->CommonExtension.DriverData;
1219 
1220  PAGED_CODE();
1221 
1222  ASSERT_FDO(FdoExtension->DeviceObject);
1223 
1225  UserRequest,
1226  UserMode,
1227  FALSE,
1228  NULL);
1229  return;
1230 }
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
#define ASSERT_FDO(x)
Definition: pci.h:35
smooth NULL
Definition: ftsmooth.c:416
KEVENT PartitioningEvent
Definition: disk.h:242

Referenced by DiskDeviceControl(), DiskEnumerateDevice(), DiskIoctlCreateDisk(), DiskIoctlGetDriveLayout(), DiskIoctlGetDriveLayoutEx(), DiskIoctlGetLengthInfo(), DiskIoctlGetPartitionInfo(), DiskIoctlGetPartitionInfoEx(), DiskIoctlSetDriveLayout(), DiskIoctlSetDriveLayoutEx(), DiskIoctlSetPartitionInfo(), DiskIoctlSetPartitionInfoEx(), DiskRemoveDevice(), DiskStartFdo(), and DiskStopDevice().

◆ DiskAddDevice()

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

Definition at line 44 of file pnp.c.

69 {
70  ULONG rootPartitionMountable = FALSE;
71 
72  PCONFIGURATION_INFORMATION configurationInformation;
73  ULONG diskCount;
74 
76 
77  PAGED_CODE();
78 
79  //
80  // See if we should be allowing file systems to mount on partition zero.
81  //
82 
83  TRY {
84  HANDLE deviceKey;
85 
86  UNICODE_STRING diskKeyName;
87  OBJECT_ATTRIBUTES objectAttributes;
88  HANDLE diskKey;
89 
90  RTL_QUERY_REGISTRY_TABLE queryTable[2];
91 
94  KEY_READ,
95  &deviceKey);
96 
97  if(!NT_SUCCESS(status)) {
98  DebugPrint((1, "DiskAddDevice: Error %#08lx opening device key "
99  "for pdo %#08lx\n",
101  LEAVE;
102  }
103 
104  RtlInitUnicodeString(&diskKeyName, L"Disk");
105  InitializeObjectAttributes(&objectAttributes,
106  &diskKeyName,
108  deviceKey,
109  NULL);
110 
111  status = ZwOpenKey(&diskKey, KEY_READ, &objectAttributes);
112  ZwClose(deviceKey);
113 
114  if(!NT_SUCCESS(status)) {
115  DebugPrint((1, "DiskAddDevice: Error %#08lx opening disk key "
116  "for pdo %#08lx device key %#x\n",
117  status, PhysicalDeviceObject, deviceKey));
118  LEAVE;
119  }
120 
121  RtlZeroMemory(queryTable, sizeof(queryTable));
122 
123  queryTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT;
124  queryTable[0].Name = L"RootPartitionMountable";
125  queryTable[0].EntryContext = &(rootPartitionMountable);
126 
128  diskKey,
129  queryTable,
130  NULL,
131  NULL);
132 
133  if(!NT_SUCCESS(status)) {
134  DebugPrint((1, "DiskAddDevice: Error %#08lx reading value from "
135  "disk key %#x for pdo %#08lx\n",
136  status, diskKey, PhysicalDeviceObject));
137  }
138 
139  ZwClose(diskKey);
140 
141  } FINALLY {
142 
143  //
144  // Do nothing.
145  //
146 
147  if(!NT_SUCCESS(status)) {
148  DebugPrint((1, "DiskAddDevice: Will %sallow file system to mount on "
149  "partition zero of disk %#08lx\n",
150  (rootPartitionMountable ? "" : "not "),
152  }
153  }
154 
155  //
156  // Create device objects for disk
157  //
158 
159  diskCount = 0;
160 
162  DriverObject,
164  &diskCount,
165  (BOOLEAN) !rootPartitionMountable
166  );
167 
168  //
169  // Get the number of disks already initialized.
170  //
171 
172  configurationInformation = IoGetConfigurationInformation();
173 
174  if (NT_SUCCESS(status)) {
175 
176  //
177  // Increment system disk device count.
178  //
179 
180  configurationInformation->DiskCount++;
181 
182  }
183 
184  return status;
185 
186 } // end DiskAddDevice()
#define FINALLY
Definition: classpnp.h:113
NTSTATUS NTAPI DiskCreateFdo(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT PhysicalDeviceObject, IN PULONG DeviceCount, IN BOOLEAN DasdAccessOnly)
Definition: disk.c:375
NTSYSAPI NTSTATUS WINAPI RtlQueryRegistryValues(ULONG, PCWSTR, PRTL_QUERY_REGISTRY_TABLE, PVOID, PVOID)
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
PCONFIGURATION_INFORMATION NTAPI IoGetConfigurationInformation(VOID)
Definition: iorsrce.c:830
#define PLUGPLAY_REGKEY_DEVICE
Definition: iofuncs.h:2738
#define KEY_READ
Definition: nt_native.h:1023
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
LONG NTSTATUS
Definition: precomp.h:26
#define LEAVE
Definition: classpnp.h:112
#define TRY(sps, bps)
PDEVICE_OBJECT PhysicalDeviceObject
Definition: btrfs_drv.h:1122
#define PAGED_CODE()
Definition: video.h:57
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static const WCHAR L[]
Definition: oid.c:1250
#define RTL_REGISTRY_HANDLE
Definition: nt_native.h:168
ULONG NTAPI DebugPrint(IN PSTRING DebugString, IN ULONG ComponentId, IN ULONG Level)
Definition: debug.c:23
NTSTATUS NTAPI IoOpenDeviceRegistryKey(IN PDEVICE_OBJECT DeviceObject, IN ULONG DevInstKeyType, IN ACCESS_MASK DesiredAccess, OUT PHANDLE DevInstRegKey)
Definition: pnpmgr.c:4586
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
static SERVICE_STATUS status
Definition: service.c:31
#define RTL_QUERY_REGISTRY_DIRECT
Definition: nt_native.h:144
Definition: ps.c:97

Referenced by DriverEntry().

◆ DiskConvertExtendedToLayout()

PDRIVE_LAYOUT_INFORMATION NTAPI DiskConvertExtendedToLayout ( IN CONST PDRIVE_LAYOUT_INFORMATION_EX  LayoutEx)

Definition at line 40 of file enum.c.

43 {
44  ULONG i;
45  ULONG LayoutSize;
47  PPARTITION_INFORMATION Partition;
48  PPARTITION_INFORMATION_EX PartitionEx;
49 
50  PAGED_CODE ();
51 
52  ASSERT ( LayoutEx );
53 
54 
55  //
56  // The only valid conversion is from an MBR extended layout structure to
57  // the old structure.
58  //
59 
60  if (LayoutEx->PartitionStyle != PARTITION_STYLE_MBR) {
61  ASSERT ( FALSE );
62  return NULL;
63  }
64 
66  LayoutEx->PartitionCount * sizeof (PARTITION_INFORMATION);
67 
68  Layout = ExAllocatePoolWithTag (
70  LayoutSize,
72  );
73 
74  if ( Layout == NULL ) {
75  return NULL;
76  }
77 
78  Layout->Signature = LayoutEx->Mbr.Signature;
79  Layout->PartitionCount = LayoutEx->PartitionCount;
80 
81  for (i = 0; i < LayoutEx->PartitionCount; i++) {
82 
83  Partition = &Layout->PartitionEntry[i];
84  PartitionEx = &LayoutEx->PartitionEntry[i];
85 
86  Partition->StartingOffset = PartitionEx->StartingOffset;
87  Partition->PartitionLength = PartitionEx->PartitionLength;
88  Partition->RewritePartition = PartitionEx->RewritePartition;
89  Partition->PartitionNumber = PartitionEx->PartitionNumber;
90 
91  Partition->PartitionType = PartitionEx->Mbr.PartitionType;
92  Partition->BootIndicator = PartitionEx->Mbr.BootIndicator;
93  Partition->RecognizedPartition = PartitionEx->Mbr.RecognizedPartition;
94  Partition->HiddenSectors = PartitionEx->Mbr.HiddenSectors;
95  }
96 
97  return Layout;
98 }
#define DISK_TAG_PART_LIST
Definition: disk.h:60
LARGE_INTEGER PartitionLength
Definition: ntdddisk.h:399
struct _PARTITION_INFORMATION PARTITION_INFORMATION
PARTITION_INFORMATION_MBR Mbr
Definition: imports.h:226
#define PAGED_CODE()
Definition: video.h:57
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
smooth NULL
Definition: ftsmooth.c:416
PARTITION_INFORMATION PartitionEntry[1]
Definition: ntdddisk.h:476
LARGE_INTEGER StartingOffset
Definition: ntdddisk.h:398
LARGE_INTEGER PartitionLength
Definition: imports.h:222
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
BOOLEAN RewritePartition
Definition: ntdddisk.h:405
LARGE_INTEGER StartingOffset
Definition: imports.h:221
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
unsigned int ULONG
Definition: retypes.h:1
BOOLEAN RecognizedPartition
Definition: ntdddisk.h:404

Referenced by DiskIoctlGetDriveLayout().

◆ DiskConvertLayoutToExtended()

PDRIVE_LAYOUT_INFORMATION_EX NTAPI DiskConvertLayoutToExtended ( IN CONST PDRIVE_LAYOUT_INFORMATION  Layout)

Definition at line 147 of file enum.c.

169 {
170  ULONG i;
171  ULONG size;
173 
174  PAGED_CODE ();
175 
176  ASSERT ( Layout != NULL );
177 
178 
179  //
180  // Allocate enough space for a DRIVE_LAYOUT_INFORMATION_EX structure
181  // plus as many PARTITION_INFORMATION_EX structures as are in the
182  // source array.
183  //
184 
186  Layout->PartitionCount * sizeof ( PARTITION_INFORMATION_EX );
187 
188  layoutEx = ExAllocatePoolWithTag(
189  NonPagedPool,
190  size,
192  );
193 
194  if ( layoutEx == NULL ) {
195  return NULL;
196  }
197 
198  //
199  // Convert the disk information.
200  //
201 
203  layoutEx->PartitionCount = Layout->PartitionCount;
204  layoutEx->Mbr.Signature = Layout->Signature;
205 
206  for (i = 0; i < Layout->PartitionCount; i++) {
207 
208  //
209  // Convert each entry.
210  //
211 
213  &Layout->PartitionEntry[i],
214  &layoutEx->PartitionEntry[i]
215  );
216  }
217 
218  return layoutEx;
219 }
#define DISK_TAG_PART_LIST
Definition: disk.h:60
#define PAGED_CODE()
Definition: video.h:57
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
struct _PARTITION_INFORMATION_EX PARTITION_INFORMATION_EX
VOID NTAPI DiskConvertPartitionToExtended(IN PPARTITION_INFORMATION Partition, OUT PPARTITION_INFORMATION_EX PartitionEx)
Definition: enum.c:102
smooth NULL
Definition: ftsmooth.c:416
PARTITION_INFORMATION PartitionEntry[1]
Definition: ntdddisk.h:476
GLsizeiptr size
Definition: glext.h:5919
DRIVE_LAYOUT_INFORMATION_MBR Mbr
Definition: ntdddisk.h:494
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
PARTITION_INFORMATION_EX PartitionEntry[1]
Definition: ntdddisk.h:497
unsigned int ULONG
Definition: retypes.h:1

Referenced by DiskIoctlSetDriveLayout(), and DiskReadPartitionTableEx().

◆ DiskConvertPartitionToExtended()

VOID NTAPI DiskConvertPartitionToExtended ( IN PPARTITION_INFORMATION  Partition,
OUT PPARTITION_INFORMATION_EX  PartitionEx 
)

Definition at line 102 of file enum.c.

127 {
128  PAGED_CODE ();
129 
130  ASSERT ( PartitionEx != NULL );
131  ASSERT ( Partition != NULL );
132 
133  PartitionEx->PartitionStyle = PARTITION_STYLE_MBR;
134  PartitionEx->StartingOffset = Partition->StartingOffset;
135  PartitionEx->PartitionLength = Partition->PartitionLength;
136  PartitionEx->RewritePartition = Partition->RewritePartition;
137  PartitionEx->PartitionNumber = Partition->PartitionNumber;
138 
139  PartitionEx->Mbr.PartitionType = Partition->PartitionType;
140  PartitionEx->Mbr.BootIndicator = Partition->BootIndicator;
141  PartitionEx->Mbr.RecognizedPartition = Partition->RecognizedPartition;
142  PartitionEx->Mbr.HiddenSectors = Partition->HiddenSectors;
143 }
#define PAGED_CODE()
Definition: video.h:57
smooth NULL
Definition: ftsmooth.c:416
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)

Referenced by DiskConvertLayoutToExtended().

◆ DiskCreateFdo()

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

Definition at line 375 of file disk.c.

408 {
409  CCHAR ntNameBuffer[MAXIMUM_FILENAME_LENGTH];
410  //STRING ntNameString;
411  //UNICODE_STRING ntUnicodeString;
412 
413  PUCHAR deviceName = NULL;
414 
415  OBJECT_ATTRIBUTES objectAttributes;
416  HANDLE handle;
417 
419 
420  PDEVICE_OBJECT lowerDevice = NULL;
421  PDEVICE_OBJECT deviceObject = NULL;
422 
423  PFUNCTIONAL_DEVICE_EXTENSION fdoExtension;
424  //STORAGE_PROPERTY_ID propertyId;
425  //PSTORAGE_DEVICE_DESCRIPTOR deviceDescriptor;
426 
427  PAGED_CODE();
428 
429  *DeviceCount = 0;
430 
431  //
432  // Set up an object directory to contain the objects for this
433  // device and all its partitions.
434  //
435 
436  do {
437 
438  WCHAR buffer[64];
439  UNICODE_STRING unicodeDirectoryName;
440 
441  swprintf(buffer, L"\\Device\\Harddisk%d", *DeviceCount);
442 
443  RtlInitUnicodeString(&unicodeDirectoryName, buffer);
444 
445  InitializeObjectAttributes(&objectAttributes,
446  &unicodeDirectoryName,
448  NULL,
449  NULL);
450 
453  &objectAttributes);
454 
455  (*DeviceCount)++;
456 
457  } while((status == STATUS_OBJECT_NAME_COLLISION) ||
459 
460  if (!NT_SUCCESS(status)) {
461 
462  DebugPrint((1, "DiskCreateFdo: Could not create directory - %lx\n",
463  status));
464 
465  return(status);
466  }
467 
468  //
469  // When this loop exits the count is inflated by one - fix that.
470  //
471 
472  (*DeviceCount)--;
473 
474  //
475  // Claim the device.
476  //
477 
479 
480  status = ClassClaimDevice(lowerDevice, FALSE);
481 
482  if (!NT_SUCCESS(status)) {
484  ZwClose(handle);
485  ObDereferenceObject(lowerDevice);
486  return status;
487  }
488 
489  //
490  // Create a device object for this device. Each physical disk will
491  // have at least one device object. The required device object
492  // describes the entire device. Its directory path is
493  // \Device\HarddiskN\Partition0, where N = device number.
494  //
495 
497  *DeviceCount,
498  0,
499  NULL,
500  NULL,
501  &deviceName);
502 
503  if(!NT_SUCCESS(status)) {
504  DebugPrint((1, "DiskCreateFdo - couldn't create name %lx\n",
505  status));
506 
507  goto DiskCreateFdoExit;
508 
509  }
510 
512  deviceName,
514  TRUE,
515  &deviceObject);
516 
517  if (!NT_SUCCESS(status)) {
518 
519  DebugPrint((1,
520  "DiskCreateFdo: Can not create device object %s\n",
521  ntNameBuffer));
522 
523  goto DiskCreateFdoExit;
524  }
525 
526  //
527  // Indicate that IRPs should include MDLs for data transfers.
528  //
529 
530  SET_FLAG(deviceObject->Flags, DO_DIRECT_IO);
531 
532  fdoExtension = deviceObject->DeviceExtension;
533 
534  if(DasdAccessOnly) {
535 
536  //
537  // Indicate that only RAW should be allowed to mount on the root
538  // partition object. This ensures that a file system can't doubly
539  // mount on a super-floppy by mounting once on P0 and once on P1.
540  //
541 
542  SET_FLAG(deviceObject->Vpb->Flags, VPB_RAW_MOUNT);
543  }
544 
545  //
546  // Initialize lock count to zero. The lock count is used to
547  // disable the ejection mechanism on devices that support
548  // removable media. Only the lock count in the physical
549  // device extension is used.
550  //
551 
552  fdoExtension->LockCount = 0;
553 
554  //
555  // Save system disk number.
556  //
557 
558  fdoExtension->DeviceNumber = *DeviceCount;
559 
560  //
561  // Set the alignment requirements for the device based on the
562  // host adapter requirements
563  //
564 
565  if (lowerDevice->AlignmentRequirement > deviceObject->AlignmentRequirement) {
566  deviceObject->AlignmentRequirement = lowerDevice->AlignmentRequirement;
567  }
568 
569  //
570  // Finally, attach to the pdo
571  //
572 
573  fdoExtension->LowerPdo = PhysicalDeviceObject;
574 
575  fdoExtension->CommonExtension.LowerDeviceObject =
577  deviceObject,
579 
580  if(fdoExtension->CommonExtension.LowerDeviceObject == NULL) {
581 
582  //
583  // Uh - oh, we couldn't attach
584  // cleanup and return
585  //
586 
588  goto DiskCreateFdoExit;
589  }
590 
591  {
592  PDISK_DATA diskData = fdoExtension->CommonExtension.DriverData;
593 
594  //
595  // Initialize the partitioning lock as it may be used in the remove
596  // code.
597  //
598 
601  TRUE);
602  }
603 
604 
605  //
606  // Clear the init flag.
607  //
608 
609  CLEAR_FLAG(deviceObject->Flags, DO_DEVICE_INITIALIZING);
610 
611  //
612  // Store a handle to the device object directory for this disk
613  //
614 
615  fdoExtension->DeviceDirectory = handle;
616 
617  ObDereferenceObject(lowerDevice);
618 
619  return STATUS_SUCCESS;
620 
621 DiskCreateFdoExit:
622 
623  //
624  // Release the device since an error occurred.
625  //
626 
627  if (deviceObject != NULL) {
628  IoDeleteDevice(deviceObject);
629  }
630 
631  //
632  // Delete directory and return.
633  //
634 
635  if (!NT_SUCCESS(status)) {
637  ZwClose(handle);
638  }
639 
640  ObDereferenceObject(lowerDevice);
641 
642  return(status);
643 }
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
#define STATUS_OBJECT_NAME_COLLISION
Definition: udferr_usr.h:150
NTSTATUS NTAPI ClassClaimDevice(IN PDEVICE_OBJECT LowerDeviceObject, IN BOOLEAN Release)
Definition: class.c:5985
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED LPLOOKUPSERVICE_COMPLETION_ROUTINE HANDLE * handle
Definition: sock.c:82
#define TRUE
Definition: types.h:120
NTSTATUS NTAPI ClassCreateDeviceObject(IN PDRIVER_OBJECT DriverObject, IN PCCHAR ObjectNameBuffer, IN PDEVICE_OBJECT LowerDevice, IN BOOLEAN IsFdo, IN OUT PDEVICE_OBJECT *DeviceObject)
Definition: class.c:5687
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
unsigned char * PUCHAR
Definition: retypes.h:3
#define STATUS_OBJECT_NAME_EXISTS
Definition: ntstatus.h:114
LONG NTSTATUS
Definition: precomp.h:26
COMMON_DEVICE_EXTENSION CommonExtension
Definition: classpnp.h:695
GLuint buffer
Definition: glext.h:5915
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
PDEVICE_OBJECT PhysicalDeviceObject
Definition: btrfs_drv.h:1122
#define MAXIMUM_FILENAME_LENGTH
Definition: env_spec_w32.h:41
#define PAGED_CODE()
Definition: video.h:57
#define DO_DIRECT_IO
Definition: env_spec_w32.h:396
ULONG DeviceCount
Definition: mpu401.c:26
PDEVICE_OBJECT NTAPI IoAttachDeviceToDeviceStack(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:966
#define CLEAR_FLAG(Flags, Bit)
Definition: classpnp.h:155
NTSYSAPI NTSTATUS NTAPI ZwCreateDirectoryObject(_Out_ PHANDLE DirectoryHandle, _In_ ACCESS_MASK DesiredAccess, _In_ POBJECT_ATTRIBUTES ObjectAttributes)
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
NTSTATUS NTAPI DiskGenerateDeviceName(IN BOOLEAN IsFdo, IN ULONG DeviceNumber, IN OPTIONAL ULONG PartitionNumber, IN OPTIONAL PLARGE_INTEGER StartingOffset, IN OPTIONAL PLARGE_INTEGER PartitionLength, OUT PUCHAR *RawName)
Definition: pnp.c:783
KEVENT PartitioningEvent
Definition: disk.h:242
PDEVICE_OBJECT NTAPI IoGetAttachedDeviceReference(PDEVICE_OBJECT DeviceObject)
Definition: device.c:1406
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
char CCHAR
Definition: typedefs.h:51
#define swprintf(buf, format,...)
Definition: sprintf.c:56
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
static const WCHAR L[]
Definition: oid.c:1250
PDEVICE_OBJECT LowerPdo
Definition: classpnp.h:697
#define OBJ_PERMANENT
Definition: winternl.h:226
ULONG AlignmentRequirement
Definition: env_spec_w32.h:420
#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
#define VPB_RAW_MOUNT
Definition: iotypes.h:1768
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define DIRECTORY_ALL_ACCESS
Definition: nt_native.h:1259
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
return STATUS_SUCCESS
Definition: btrfs.c:2938
static SERVICE_STATUS status
Definition: service.c:31
NTSYSAPI NTSTATUS NTAPI ZwMakeTemporaryObject(_In_ HANDLE Handle)
Definition: ps.c:97

Referenced by DiskAddDevice().

◆ DiskCreatePdo()

NTSTATUS NTAPI DiskCreatePdo ( IN PDEVICE_OBJECT  Fdo,
IN ULONG  PartitionOrdinal,
IN PPARTITION_INFORMATION_EX  PartitionEntry,
IN PARTITION_STYLE  PartitionStyle,
OUT PDEVICE_OBJECT Pdo 
)

Definition at line 1025 of file enum.c.

1060 {
1061  PFUNCTIONAL_DEVICE_EXTENSION fdoExtension = Fdo->DeviceExtension;
1062 
1063  PDEVICE_OBJECT pdo = NULL;
1064  PPHYSICAL_DEVICE_EXTENSION pdoExtension = NULL;
1065 
1066  PUCHAR deviceName = NULL;
1067 
1068  PDISK_DATA diskData = fdoExtension->CommonExtension.DriverData;
1069 
1070  ULONG numberListElements;
1071 
1073 
1074  PAGED_CODE();
1075 
1076  //
1077  // Create partition object and set up partition parameters.
1078  //
1079 
1081  fdoExtension->DeviceNumber,
1085  &deviceName);
1086 
1087  if(!NT_SUCCESS(status)) {
1088 
1089  DebugPrint((1, "DiskCreatePdo - Can't generate name %lx\n", status));
1090  return status;
1091  }
1092 
1093  DebugPrint((2, "DiskCreatePdo: Create device object %s\n", deviceName));
1094 
1095  status = ClassCreateDeviceObject(Fdo->DriverObject,
1096  deviceName,
1097  Fdo,
1098  FALSE,
1099  &pdo);
1100 
1101  if (!NT_SUCCESS(status)) {
1102 
1103  DebugPrint((1, "DiskEnumerateDevice: Can't create device object for %s\n", deviceName));
1104 
1105  return status;
1106  }
1107 
1108  //
1109  // Set up device extension fields.
1110  //
1111 
1112  pdoExtension = pdo->DeviceExtension;
1113 
1114  //
1115  // Set up device object fields.
1116  //
1117 
1118  SET_FLAG(pdo->Flags, DO_DIRECT_IO);
1119 
1120  pdo->StackSize = (CCHAR)
1121  pdoExtension->CommonExtension.LowerDeviceObject->StackSize + 1;
1122 
1123  //
1124  // Get pointer to new disk data.
1125  //
1126 
1127  diskData = (PDISK_DATA) pdoExtension->CommonExtension.DriverData;
1128 
1129  //
1130  // Set the alignment requirements for the device based on the
1131  // host adapter requirements
1132  //
1133 
1134  if (Fdo->AlignmentRequirement > pdo->AlignmentRequirement) {
1135  pdo->AlignmentRequirement = Fdo->AlignmentRequirement;
1136  }
1137 
1138  if (fdoExtension->SrbFlags & SRB_FLAGS_QUEUE_ACTION_ENABLE) {
1139  numberListElements = 30;
1140  } else {
1141  numberListElements = 8;
1142  }
1143 
1144  //
1145  // Build the lookaside list for srb's for this partition based on
1146  // whether the adapter and disk can do tagged queueing. Don't bother to
1147  // check the status - this can't fail when called for a PDO.
1148  //
1149 
1151  numberListElements);
1152 
1153  //
1154  // Set the sense-data pointer in the device extension.
1155  //
1156 
1157  diskData->PartitionOrdinal = PartitionOrdinal;
1158  pdoExtension->CommonExtension.PartitionNumber = PartitionEntry->PartitionNumber;
1159 
1160  //
1161  // Initialize relevant data.
1162  //
1163 
1164  if (PartitionStyle == PARTITION_STYLE_MBR) {
1165 
1166  diskData->Mbr.PartitionType = PartitionEntry->Mbr.PartitionType;
1167  diskData->Mbr.BootIndicator = PartitionEntry->Mbr.BootIndicator;
1168  diskData->Mbr.HiddenSectors = PartitionEntry->Mbr.HiddenSectors;
1169 
1170  } else {
1171 
1172  diskData->Efi.PartitionType = PartitionEntry->Gpt.PartitionType;
1173  diskData->Efi.PartitionId = PartitionEntry->Gpt.PartitionType;
1174  diskData->Efi.Attributes = PartitionEntry->Gpt.Attributes;
1175  RtlCopyMemory (diskData->Efi.PartitionName,
1176  PartitionEntry->Gpt.Name,
1177  sizeof (diskData->Efi.PartitionName)
1178  );
1179  }
1180 
1181  DebugPrint((2, "DiskEnumerateDevice: Partition type is %x\n",
1182  diskData->Mbr.PartitionType));
1183 
1184  pdoExtension->CommonExtension.StartingOffset =
1186 
1187  pdoExtension->CommonExtension.PartitionLength =
1189 
1190 
1191  DebugPrint((1, "DiskCreatePdo: hidden sectors value for pdo %#p set to %#x\n",
1192  pdo,
1193  diskData->Mbr.HiddenSectors));
1194 
1195  //
1196  // Check for removable media support.
1197  //
1198 
1199  if (fdoExtension->DeviceDescriptor->RemovableMedia) {
1200  SET_FLAG(pdo->Characteristics, FILE_REMOVABLE_MEDIA);
1201  }
1202 
1203  pdoExtension->CommonExtension.DeviceObject = pdo;
1204 
1206 
1207  *Pdo = pdo;
1208 
1209  return status;
1210 }
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
COMMON_DEVICE_EXTENSION CommonExtension
Definition: classpnp.h:628
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
LARGE_INTEGER PartitionLength
Definition: ntdddisk.h:399
NTSTATUS NTAPI ClassCreateDeviceObject(IN PDRIVER_OBJECT DriverObject, IN PCCHAR ObjectNameBuffer, IN PDEVICE_OBJECT LowerDevice, IN BOOLEAN IsFdo, IN OUT PDEVICE_OBJECT *DeviceObject)
Definition: class.c:5687
_In_ PDEVICE_OBJECT Pdo
Definition: classpnp.h:301
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList
unsigned char * PUCHAR
Definition: retypes.h:3
LONG NTSTATUS
Definition: precomp.h:26
COMMON_DEVICE_EXTENSION CommonExtension
Definition: classpnp.h:695
#define PAGED_CODE()
Definition: video.h:57
#define DO_DIRECT_IO
Definition: env_spec_w32.h:396
ULONG PartitionOrdinal
Definition: disk.c:79
PDEVICE_OBJECT DeviceObject
Definition: kstypes.h:153
#define FILE_REMOVABLE_MEDIA
Definition: nt_native.h:807
#define CLEAR_FLAG(Flags, Bit)
Definition: classpnp.h:155
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
PARTITION_INFORMATION PartitionEntry[1]
Definition: ntdddisk.h:476
NTSTATUS NTAPI DiskGenerateDeviceName(IN BOOLEAN IsFdo, IN ULONG DeviceNumber, IN OPTIONAL ULONG PartitionNumber, IN OPTIONAL PLARGE_INTEGER StartingOffset, IN OPTIONAL PLARGE_INTEGER PartitionLength, OUT PUCHAR *RawName)
Definition: pnp.c:783
VOID NTAPI ClassInitializeSrbLookasideList(IN PCOMMON_DEVICE_EXTENSION CommonExtension, IN ULONG NumberElements)
Definition: obsolete.c:941
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
char CCHAR
Definition: typedefs.h:51
LARGE_INTEGER StartingOffset
Definition: ntdddisk.h:398
PSTORAGE_DEVICE_DESCRIPTOR DeviceDescriptor
Definition: classpnp.h:698
ULONG AlignmentRequirement
Definition: env_spec_w32.h:420
#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
struct _DISK_DATA::@1018::@1022 Efi
struct _DISK_DATA::@1018::@1021 Mbr
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:2938
static SERVICE_STATUS status
Definition: service.c:31
#define SRB_FLAGS_QUEUE_ACTION_ENABLE
Definition: srb.h:387
Definition: ps.c:97

Referenced by DiskUpdatePartitions(), and DiskUpdateRemovablePartitions().

◆ DiskCreateSymbolicLinks()

VOID NTAPI DiskCreateSymbolicLinks ( IN PDEVICE_OBJECT  DeviceObject)

Definition at line 864 of file pnp.c.

890 {
892 
893  PDISK_DATA diskData = commonExtension->DriverData;
894 
895  WCHAR wideSourceName[64];
896  UNICODE_STRING unicodeSourceName;
897 
899 
900  PAGED_CODE();
901 
902  //
903  // Build the destination for the link first using the device name
904  // stored in the device object
905  //
906 
907  ASSERT(commonExtension->DeviceName.Buffer);
908 
909  if(!diskData->LinkStatus.WellKnownNameCreated) {
910  //
911  // Put together the source name using the partition and device number
912  // in the device extension and disk data segment
913  //
914 
915  swprintf(wideSourceName, L"\\Device\\Harddisk%d\\Partition%d",
916  commonExtension->PartitionZeroExtension->DeviceNumber,
917  (commonExtension->IsFdo ?
918  0 :
919  commonExtension->PartitionNumber));
920 
921  RtlInitUnicodeString(&unicodeSourceName, wideSourceName);
922 
923  DebugPrint((1, "DiskCreateSymbolicLink: Linking %wZ to %wZ\n",
924  &unicodeSourceName,
925  &commonExtension->DeviceName));
926 
927  status = IoCreateSymbolicLink(&unicodeSourceName,
928  &commonExtension->DeviceName);
929 
930  #if DBG
931 
934 
935  DebugPrint((1, "DiskCreateSymbolicLink: name %wZ already exists\n",
936  &unicodeSourceName));
937  }
938  #endif
939 
940  if(NT_SUCCESS(status)){
941  diskData->LinkStatus.WellKnownNameCreated = TRUE;
942  }
943  }
944 
945  if((!diskData->LinkStatus.PhysicalDriveLinkCreated) &&
946  (commonExtension->IsFdo)) {
947 
948  //
949  // Create a physical drive N link using the device number we saved
950  // away during AddDevice.
951  //
952 
953  swprintf(wideSourceName,
954  L"\\DosDevices\\PhysicalDrive%d",
955  commonExtension->PartitionZeroExtension->DeviceNumber);
956 
957  RtlInitUnicodeString(&unicodeSourceName, wideSourceName);
958 
959  DebugPrint((1, "DiskCreateSymbolicLink: Linking %wZ to %wZ\n",
960  &unicodeSourceName,
961  &(commonExtension->DeviceName)));
962 
963  status = IoCreateSymbolicLink(&unicodeSourceName,
964  &(commonExtension->DeviceName));
965 
966 #if DBG
967 
970 
971  DebugPrint((1, "DiskCreateSymbolicLink: name %wZ already exists\n",
972  &unicodeSourceName));
973  }
974 #endif
975 
976  if(NT_SUCCESS(status)) {
977  diskData->LinkStatus.PhysicalDriveLinkCreated = TRUE;
978  }
979  } else if(commonExtension->IsFdo == FALSE) {
980  diskData->LinkStatus.PhysicalDriveLinkCreated = FALSE;
981  }
982 
983  return;
984 }
#define STATUS_OBJECT_NAME_COLLISION
Definition: udferr_usr.h:150
struct _DISK_DATA::@1020 LinkStatus
#define TRUE
Definition: types.h:120
struct _FUNCTIONAL_DEVICE_EXTENSION * PartitionZeroExtension
Definition: classpnp.h:575
#define STATUS_OBJECT_NAME_EXISTS
Definition: ntstatus.h:114
LONG NTSTATUS
Definition: precomp.h:26
#define PAGED_CODE()
Definition: video.h:57
PVOID DeviceExtension
Definition: env_spec_w32.h:418
UNICODE_STRING DeviceName
Definition: classpnp.h:591
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define swprintf(buf, format,...)
Definition: sprintf.c:56
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
static const WCHAR L[]
Definition: oid.c:1250
ULONG NTAPI DebugPrint(IN PSTRING DebugString, IN ULONG ComponentId, IN ULONG Level)
Definition: debug.c:23
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
static SERVICE_STATUS status
Definition: service.c:31
Definition: ps.c:97

Referenced by DiskInitFdo(), and DiskInitPdo().

◆ DiskDeleteSymbolicLinks()

VOID NTAPI DiskDeleteSymbolicLinks ( IN PDEVICE_OBJECT  DeviceObject)

Definition at line 988 of file pnp.c.

1010 {
1012  PDISK_DATA diskData = commonExtension->DriverData;
1013 
1014  WCHAR wideLinkName[64];
1015  UNICODE_STRING unicodeLinkName;
1016 
1017  PAGED_CODE();
1018 
1019  if(diskData->LinkStatus.WellKnownNameCreated) {
1020 
1021  swprintf(wideLinkName,
1022  L"\\Device\\Harddisk%d\\Partition%d",
1023  commonExtension->PartitionZeroExtension->DeviceNumber,
1024  (commonExtension->IsFdo ? 0 :
1025  commonExtension->PartitionNumber));
1026 
1027  RtlInitUnicodeString(&unicodeLinkName, wideLinkName);
1028 
1029  IoDeleteSymbolicLink(&unicodeLinkName);
1030 
1031  diskData->LinkStatus.WellKnownNameCreated = FALSE;
1032  }
1033 
1034  if(diskData->LinkStatus.PhysicalDriveLinkCreated) {
1035 
1037 
1038  swprintf(wideLinkName,
1039  L"\\DosDevices\\PhysicalDrive%d",
1040  commonExtension->PartitionZeroExtension->DeviceNumber);
1041 
1042  RtlInitUnicodeString(&unicodeLinkName, wideLinkName);
1043 
1044  IoDeleteSymbolicLink(&unicodeLinkName);
1045 
1046  diskData->LinkStatus.PhysicalDriveLinkCreated = FALSE;
1047  }
1048 
1049  return;
1050 }
struct _DISK_DATA::@1020 LinkStatus
struct _FUNCTIONAL_DEVICE_EXTENSION * PartitionZeroExtension
Definition: classpnp.h:575
#define PAGED_CODE()
Definition: video.h:57
#define ASSERT_FDO(x)
Definition: pci.h:35
PVOID DeviceExtension
Definition: env_spec_w32.h:418
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define swprintf(buf, format,...)
Definition: sprintf.c:56
static const WCHAR L[]
Definition: oid.c:1250
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)

Referenced by DiskRemoveDevice().

◆ 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().

◆ DiskDeviceControl()

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

◆ 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().

◆ DiskEnumerateDevice()

NTSTATUS NTAPI DiskEnumerateDevice ( IN PDEVICE_OBJECT  Fdo)

Definition at line 223 of file enum.c.

249 {
250  PCOMMON_DEVICE_EXTENSION commonExtension = Fdo->DeviceExtension;
251  PFUNCTIONAL_DEVICE_EXTENSION fdoExtension = Fdo->DeviceExtension;
252 
253  //PPHYSICAL_DEVICE_EXTENSION pdoExtension = NULL;
254 
255  PDISK_DATA diskData = (PDISK_DATA) commonExtension->DriverData;
256 
257  //PDEVICE_OBJECT pdo = NULL;
258 
259  //ULONG numberListElements = 0;
260 
261  PDRIVE_LAYOUT_INFORMATION_EX partitionList;
262 
264 
265  ASSERT(commonExtension->IsFdo);
266 
267  PAGED_CODE();
268 
269  //
270  // Update our image of the size of the drive. This may be necessary if
271  // the drive size is extended or we just released a reservation to
272  // ensure the kernel doesn't reject the partition table.
273  //
274 
276 
277  //
278  // Lock out anyone else trying to repartition the disk.
279  //
280 
281  DiskAcquirePartitioningLock(fdoExtension);
282 
283  //
284  // Create objects for all the partitions on the device.
285  //
286 
287  status = DiskReadPartitionTableEx(fdoExtension, FALSE, &partitionList);
288 
289  //
290  // If the I/O read partition table failed and this is a removable device,
291  // then fix up the partition list to make it look like there is one
292  // zero length partition.
293  //
294 
295  if ((!NT_SUCCESS(status) || partitionList->PartitionCount == 0) &&
296  Fdo->Characteristics & FILE_REMOVABLE_MEDIA) {
297 
298  SIZE_T partitionListSize;
299 
300  //
301  // Remember whether the drive is ready.
302  //
303 
304  diskData->ReadyStatus = status;
305 
306  //
307  // Allocate and zero a partition list.
308  //
309 
310  partitionListSize =
312 
313  partitionList = ExAllocatePoolWithTag(NonPagedPool,
314  partitionListSize,
316 
317  if (partitionList != NULL) {
318 
319  RtlZeroMemory( partitionList, partitionListSize );
320 
321  //
322  // Set the partition count to one and the status to success
323  // so one device object will be created. Set the partition type
324  // to a bogus value.
325  //
326 
327  partitionList->PartitionStyle = PARTITION_STYLE_MBR;
328  partitionList->PartitionCount = 1;
329 
331  } else {
333  }
334  }
335 
336  if (NT_SUCCESS(status)) {
337 
338  diskData->UpdatePartitionRoutine(Fdo, partitionList);
339 
340  //
341  // Record disk signature.
342  //
343 
344  if (partitionList->PartitionStyle == PARTITION_STYLE_MBR) {
345 
347  diskData->Mbr.Signature = partitionList->Mbr.Signature;
348 
349  } else {
350 
352  diskData->Efi.DiskId = partitionList->Gpt.DiskId;
353  }
354  }
355 
356  DiskReleasePartitioningLock(fdoExtension);
357 
358  return(STATUS_SUCCESS);
359 
360 } // end DiskEnumerateDevice()
#define DISK_TAG_PART_LIST
Definition: disk.h:60
struct _DISK_DATA * PDISK_DATA
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
NTSTATUS ReadyStatus
Definition: disk.h:222
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI DiskAcquirePartitioningLock(IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension)
Definition: enum.c:1214
#define PAGED_CODE()
Definition: video.h:57
PDISK_UPDATE_PARTITIONS UpdatePartitionRoutine
Definition: disk.h:230
#define FILE_REMOVABLE_MEDIA
Definition: nt_native.h:807
smooth NULL
Definition: ftsmooth.c:416
PARTITION_INFORMATION PartitionEntry[1]
Definition: ntdddisk.h:476
PARTITION_STYLE PartitionStyle
Definition: disk.h:103
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define DiskReadDriveCapacity(Fdo)
Definition: disk.h:860
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
ULONG_PTR SIZE_T
Definition: typedefs.h:79
struct _DISK_DATA::@1018::@1022 Efi
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
NTSTATUS NTAPI DiskReadPartitionTableEx(IN PFUNCTIONAL_DEVICE_EXTENSION Fdo, IN BOOLEAN BypassCache, OUT PDRIVE_LAYOUT_INFORMATION_EX *DriveLayout)
Definition: part.c:49
struct _DISK_DATA::@1018::@1021 Mbr
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
VOID NTAPI DiskReleasePartitioningLock(IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension)
Definition: enum.c:1234
return STATUS_SUCCESS
Definition: btrfs.c:2938
static SERVICE_STATUS status
Definition: service.c:31
Definition: ps.c:97

Referenced by DiskIoctlGetLengthInfo(), DiskIoctlGetPartitionInfo(), DiskIoctlGetPartitionInfoEx(), and DriverEntry().

◆ 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:255
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().

◆ DiskFdoProcessError()

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

Definition at line 3803 of file disk.c.

3833 {
3834  PFUNCTIONAL_DEVICE_EXTENSION fdoExtension = Fdo->DeviceExtension;
3835  PCDB cdb = (PCDB)(Srb->Cdb);
3836 
3837  ASSERT(fdoExtension->CommonExtension.IsFdo);
3838 
3839  if (*Status == STATUS_DATA_OVERRUN &&
3840  ( cdb->CDB10.OperationCode == SCSIOP_WRITE ||
3841  cdb->CDB10.OperationCode == SCSIOP_READ)) {
3842 
3843  *Retry = TRUE;
3844 
3845  //
3846  // Update the error count for the device.
3847  //
3848 
3849  fdoExtension->ErrorCount++;
3850 
3851  } else if (SRB_STATUS(Srb->SrbStatus) == SRB_STATUS_ERROR &&
3852  Srb->ScsiStatus == SCSISTAT_BUSY) {
3853 
3854  //
3855  // a disk drive should never be busy this long. Reset the scsi bus
3856  // maybe this will clear the condition.
3857  //
3858 
3859  ResetBus(Fdo);
3860 
3861  //
3862  // Update the error count for the device.
3863  //
3864 
3865  fdoExtension->ErrorCount++;
3866 
3867  } else {
3868 
3869  BOOLEAN invalidatePartitionTable = FALSE;
3870 
3871  //
3872  // See if this might indicate that something on the drive has changed.
3873  //
3874 
3875  if ((Srb->SrbStatus & SRB_STATUS_AUTOSENSE_VALID) &&
3876  (Srb->SenseInfoBufferLength >=
3877  FIELD_OFFSET(SENSE_DATA, CommandSpecificInformation))) {
3878 
3879  PSENSE_DATA senseBuffer = Srb->SenseInfoBuffer;
3880  ULONG senseKey = senseBuffer->SenseKey & 0xf;
3881  ULONG asc = senseBuffer->AdditionalSenseCode;
3882  ULONG ascq = senseBuffer->AdditionalSenseCodeQualifier;
3883 
3884  switch (senseKey) {
3885 
3887 
3888  switch (asc) {
3889 
3890  case SCSI_ADSENSE_INVALID_CDB: {
3891 
3892  if (((cdb->CDB10.OperationCode == SCSIOP_READ) ||
3893  (cdb->CDB10.OperationCode == SCSIOP_WRITE)) &&
3894  (cdb->CDB10.ForceUnitAccess) &&
3895  TEST_FLAG(fdoExtension->DeviceFlags, DEV_WRITE_CACHE)) {
3896 
3897  //
3898  // This device does not permit FUA while
3899  // the DEV_WRITE_CACHE flag is turned on
3900  //
3901 
3902  PIO_WORKITEM workItem = IoAllocateWorkItem(Fdo);
3903  if (workItem) {
3904 
3905  IoQueueWorkItem(workItem,
3908  workItem);
3909  }
3910 
3911  cdb->CDB10.ForceUnitAccess = FALSE;
3912  *Retry = TRUE;
3913  }
3914 
3915  break;
3916  }
3917  } // end switch(asc)
3918  break;
3919  }
3920 
3921  case SCSI_SENSE_NOT_READY: {
3922 
3923  switch (asc) {
3925  switch (ascq) {
3929  invalidatePartitionTable = TRUE;
3930  break;
3931  }
3932  } // end switch(ascq)
3933  break;
3934  }
3935 
3937  invalidatePartitionTable = TRUE;
3938  break;
3939  }
3940  } // end switch(asc)
3941  break;
3942  }
3943 
3944  case SCSI_SENSE_MEDIUM_ERROR: {
3945  invalidatePartitionTable = TRUE;
3946  break;
3947  }
3948 
3950  invalidatePartitionTable = TRUE;
3951  break;
3952  }
3953 
3955  switch (senseBuffer->AdditionalSenseCode) {
3957  invalidatePartitionTable = TRUE;
3958  break;
3959  }
3960  }
3961  break;
3962  }
3963 
3965  invalidatePartitionTable = TRUE;
3966  break;
3967  }
3968 
3969  } // end switch(senseKey)
3970  } else {
3971 
3972  //
3973  // On any exceptional scsi condition which might indicate that the
3974  // device was changed we will flush out the state of the partition
3975  // table.
3976  //
3977 
3978  switch (SRB_STATUS(Srb->SrbStatus)) {
3981  case SRB_STATUS_NO_DEVICE:
3982  case SRB_STATUS_NO_HBA:
3985  case SRB_STATUS_TIMEOUT:
3990  case SRB_STATUS_ERROR: {
3991  invalidatePartitionTable = TRUE;
3992  break;
3993  }
3994  } // end switch(Srb->SrbStatus)
3995  }
3996 
3997  if(invalidatePartitionTable) {
3998  if(DiskInvalidatePartitionTable(fdoExtension, FALSE)) {
3999  IoInvalidateDeviceRelations(fdoExtension->LowerPdo,
4000  BusRelations);
4001  }
4002  }
4003  }
4004  return;
4005 }
UCHAR SenseKey
Definition: cdrw_hw.h:1167
#define SCSISTAT_BUSY
Definition: cdrw_hw.h:1081
#define TRUE
Definition: types.h:120
#define STATUS_DATA_OVERRUN
Definition: udferr_usr.h:152
#define TEST_FLAG(Flags, Bit)
Definition: classpnp.h:156
#define SRB_STATUS_AUTOSENSE_VALID
Definition: srb.h:379
IO_WORKITEM_ROUTINE * PIO_WORKITEM_ROUTINE
Definition: iotypes.h:483
VOID NTAPI ResetBus(IN PDEVICE_OBJECT Fdo)
Definition: disk.c:4162
Definition: cdrw_hw.h:28
#define SRB_STATUS_REQUEST_FLUSHED
Definition: srb.h:353
COMMON_DEVICE_EXTENSION CommonExtension
Definition: classpnp.h:695
#define SRB_STATUS_COMMAND_TIMEOUT
Definition: srb.h:343
#define SRB_STATUS_NO_DEVICE
Definition: srb.h:340
#define SCSI_ADSENSE_LUN_NOT_READY
Definition: cdrw_hw.h:1218
struct _CDB::_CDB10 CDB10
PIO_WORKITEM NTAPI IoAllocateWorkItem(IN PDEVICE_OBJECT DeviceObject)
Definition: iowork.c:75
#define SCSI_SENSE_NOT_READY
Definition: cdrw_hw.h:1189
#define SRB_STATUS_INVALID_TARGET_ID
Definition: srb.h:355
#define SRB_STATUS(Status)
Definition: srb.h:381
#define DEV_WRITE_CACHE
Definition: class2.h:21
#define SRB_STATUS_ERROR
Definition: srb.h:336
#define SCSI_SENSE_MEDIUM_ERROR
Definition: cdrw_hw.h:1190
#define SRB_STATUS_PARITY_ERROR
Definition: srb.h:346
#define SCSI_SENSEQ_MANUAL_INTERVENTION_REQUIRED
Definition: cdrw_hw.h:1315
#define SCSIOP_READ
Definition: cdrw_hw.h:905
#define SCSI_ADSENSE_NO_MEDIA_IN_DEVICE
Definition: cdrw_hw.h:1221
#define SCSIOP_WRITE
Definition: cdrw_hw.h:906
unsigned char BOOLEAN
#define SRB_STATUS_NO_HBA
Definition: srb.h:348
union _CDB * PCDB
IN PSCSI_REQUEST_BLOCK IN OUT NTSTATUS IN OUT BOOLEAN * Retry
Definition: class2.h:49
UCHAR AdditionalSenseCodeQualifier
Definition: cdrw_hw.h:1176
VOID NTAPI DisableWriteCache(IN PDEVICE_OBJECT DeviceObject, IN PSCSI_INQUIRY_DATA LunInfo)
Definition: disk.c:3552
#define SCSI_SENSEQ_BECOMING_READY
Definition: cdrw_hw.h:1313
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define SCSI_SENSE_HARDWARE_ERROR
Definition: cdrw_hw.h:1191
PDEVICE_OBJECT LowerPdo
Definition: classpnp.h:697
#define SRB_STATUS_SELECTION_TIMEOUT
Definition: srb.h:342
#define SCSI_SENSE_RECOVERED_ERROR
Definition: cdrw_hw.h:1188
#define SCSI_SENSEQ_CAUSE_NOT_REPORTABLE
Definition: cdrw_hw.h:1312
#define SRB_STATUS_INVALID_LUN
Definition: srb.h:354
Status
Definition: gdiplustypes.h:24
VOID NTAPI IoQueueWorkItem(IN PIO_WORKITEM IoWorkItem, IN PIO_WORKITEM_ROUTINE WorkerRoutine, IN WORK_QUEUE_TYPE QueueType, IN PVOID Context)
Definition: iowork.c:40
VOID NTAPI IoInvalidateDeviceRelations(IN PDEVICE_OBJECT DeviceObject, IN DEVICE_RELATION_TYPE Type)
Definition: pnpmgr.c:5111
#define SRB_STATUS_TIMEOUT
Definition: srb.h:341
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
unsigned int ULONG
Definition: retypes.h:1
#define SRB_STATUS_UNEXPECTED_BUS_FREE
Definition: srb.h:350
#define SRB_STATUS_INVALID_PATH_ID
Definition: srb.h:339
IN PSCSI_REQUEST_BLOCK Srb
Definition: class2.h:49
UCHAR AdditionalSenseCode
Definition: cdrw_hw.h:1175
#define SCSI_SENSE_ILLEGAL_REQUEST
Definition: cdrw_hw.h:1192
BOOLEAN NTAPI DiskInvalidatePartitionTable(IN PFUNCTIONAL_DEVICE_EXTENSION Fdo, IN BOOLEAN PartitionLockHeld)
Definition: part.c:291
#define SCSI_SENSE_UNIT_ATTENTION
Definition: cdrw_hw.h:1193
#define SCSI_ADSENSE_INVALID_CDB
Definition: cdrw_hw.h:1265
#define SCSI_ADSENSE_MEDIUM_CHANGED
Definition: cdrw_hw.h:1288

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:264
#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().

◆ DiskGenerateDeviceName()

NTSTATUS NTAPI DiskGenerateDeviceName ( IN BOOLEAN  IsFdo,
IN ULONG  DeviceNumber,
IN OPTIONAL ULONG  PartitionNumber,
IN OPTIONAL PLARGE_INTEGER  StartingOffset,
IN OPTIONAL PLARGE_INTEGER  PartitionLength,
OUT PUCHAR RawName 
)

Definition at line 783 of file pnp.c.

820 {
821  UCHAR rawName[64];
822  static ULONG diskDeviceSequenceNumber = 0;
823 
824  PAGED_CODE();
825 
826  if(!IsFdo) {
827 
829  ASSERT(ARGUMENT_PRESENT(PartitionLength));
831 
833  StartingOffset->QuadPart,
834  PartitionLength->QuadPart,
835  diskDeviceSequenceNumber++);
836  } else {
837 
839  ASSERT(!ARGUMENT_PRESENT(PartitionLength));
841 
843  diskDeviceSequenceNumber++);
844 
845  }
846 
847  *RawName = ExAllocatePoolWithTag(PagedPool,
848  strlen(rawName) + 1,
849  DISK_TAG_NAME);
850 
851  if(*RawName == NULL) {
853  }
854 
855  strcpy(*RawName, rawName);
856 
857  DebugPrint((2, "DiskGenerateDeviceName: generated \"%s\"\n", rawName));
858 
859  return STATUS_SUCCESS;
860 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ PFCB _In_ LONGLONG StartingOffset
Definition: cdprocs.h:282
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
_In_z_ PCCHAR _In_ PDEVICE_OBJECT _In_ BOOLEAN IsFdo
Definition: classpnp.h:789
#define PDO_NAME_FORMAT
_In_ ULONG _In_ ULONG PartitionNumber
Definition: iofuncs.h:2056
#define PAGED_CODE()
Definition: video.h:57
uint32_t ULONG_PTR
Definition: typedefs.h:64
#define sprintf(buf, format,...)
Definition: sprintf.c:55
smooth NULL
Definition: ftsmooth.c:416
#define FDO_NAME_FORMAT
#define ARGUMENT_PRESENT(ArgumentPointer)
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define DISK_TAG_NAME
Definition: disk.h:58
unsigned char UCHAR
Definition: xmlstorage.h:181
ULONG NTAPI DebugPrint(IN PSTRING DebugString, IN ULONG ComponentId, IN ULONG Level)
Definition: debug.c:23
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
unsigned int ULONG
Definition: retypes.h:1
_In_ PCHAR _In_ ULONG DeviceNumber
Definition: classpnp.h:1036
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by DiskCreateFdo(), and DiskCreatePdo().

◆ DiskGetCacheInformation()

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

Definition at line 4314 of file disk.c.

4319 {
4320  PMODE_PARAMETER_HEADER modeData;
4321  PMODE_CACHING_PAGE pageData;
4322 
4323  ULONG length;
4324 
4325  //NTSTATUS status;
4326 
4327  PAGED_CODE();
4328 
4332 
4333  if (modeData == NULL) {
4334 
4335  DebugPrint((1, "DiskGetSetCacheInformation: Unable to allocate mode "
4336  "data buffer\n"));
4338  }
4339 
4340  RtlZeroMemory(modeData, MODE_DATA_SIZE);
4341 
4342  length = ClassModeSense(FdoExtension->DeviceObject,
4343  (PUCHAR) modeData,
4346 
4347  if (length < sizeof(MODE_PARAMETER_HEADER)) {
4348 
4349  //
4350  // Retry the request in case of a check condition.
4351  //
4352 
4353  length = ClassModeSense(FdoExtension->DeviceObject,
4354  (PUCHAR) modeData,
4357 
4358  if (length < sizeof(MODE_PARAMETER_HEADER)) {
4359 
4360 
4361  DebugPrint((1, "Disk.DisableWriteCache: Mode Sense failed\n"));
4362 
4363  ExFreePool(modeData);
4364  return STATUS_IO_DEVICE_ERROR;
4365  }
4366  }
4367 
4368  //
4369  // If the length is greater than length indicated by the mode data reset
4370  // the data to the mode data.
4371  //
4372 
4373  if (length > (ULONG) (modeData->ModeDataLength + 1)) {
4374  length = modeData->ModeDataLength + 1;
4375  }
4376 
4377  //
4378  // Check to see if the write cache is enabled.
4379  //
4380 
4381  pageData = ClassFindModePage((PUCHAR) modeData,
4382  length,
4384  TRUE);
4385 
4386  //
4387  // Check if valid caching page exists.
4388  //
4389 
4390  if (pageData == NULL) {
4391  ExFreePool(modeData);
4392  return STATUS_NOT_SUPPORTED;
4393  }
4394 
4395  //
4396  // Copy the parameters over.
4397  //
4398 
4399  RtlZeroMemory(CacheInfo, sizeof(DISK_CACHE_INFORMATION));
4400 
4401  CacheInfo->ParametersSavable = pageData->PageSavable;
4402 
4403  CacheInfo->ReadCacheEnabled = !(pageData->ReadDisableCache);
4404  CacheInfo->WriteCacheEnabled = pageData->WriteCacheEnable;
4405 
4406  CacheInfo->ReadRetentionPriority = pageData->ReadRetensionPriority;
4407  CacheInfo->WriteRetentionPriority = pageData->WriteRetensionPriority;
4408 
4409  CacheInfo->DisablePrefetchTransferLength =
4410  ((pageData->DisablePrefetchTransfer[0] << 8) +
4411  pageData->DisablePrefetchTransfer[1]);
4412 
4413  CacheInfo->ScalarPrefetch.Minimum =
4414  ((pageData->MinimumPrefetch[0] << 8) + pageData->MinimumPrefetch[1]);
4415 
4416  CacheInfo->ScalarPrefetch.Maximum =
4417  ((pageData->MaximumPrefetch[0] << 8) + pageData->MaximumPrefetch[1]);
4418 
4419  if(pageData->MultiplicationFactor) {
4420  CacheInfo->PrefetchScalar = TRUE;
4421  CacheInfo->ScalarPrefetch.MaximumBlocks =
4422  ((pageData->MaximumPrefetchCeiling[0] << 8) +
4423  pageData->MaximumPrefetchCeiling[1]);
4424  }
4425 
4426  ExFreePool(modeData);
4427  return STATUS_SUCCESS;
4428 }
#define TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
UCHAR WriteCacheEnable
Definition: cdrw_hw.h:2779
#define MODE_PAGE_CACHING
Definition: cdrw_hw.h:846
unsigned char * PUCHAR
Definition: retypes.h:3
ULONG NTAPI ClassModeSense(IN PDEVICE_OBJECT Fdo, IN PCHAR ModeSenseBuffer, IN ULONG Length, IN UCHAR PageMode)
Definition: class.c:4122
#define MODE_SENSE_RETURN_ALL
Definition: cdrw_hw.h:857
UCHAR ReadDisableCache
Definition: cdrw_hw.h:2777
UCHAR ReadRetensionPriority
Definition: cdrw_hw.h:2783
UCHAR MaximumPrefetch[2]
Definition: cdrw_hw.h:2787
#define PAGED_CODE()
Definition: video.h:57
#define STATUS_IO_DEVICE_ERROR
Definition: udferr_usr.h:179
PVOID NTAPI ClassFindModePage(IN PCHAR ModeSenseBuffer, IN ULONG Length, IN UCHAR PageMode, IN BOOLEAN Use6Byte)
Definition: class.c:4209
#define MODE_DATA_SIZE
Definition: disk.c:164
UCHAR MultiplicationFactor
Definition: cdrw_hw.h:2778
smooth NULL
Definition: ftsmooth.c:416
#define DISK_TAG_DISABLE_CACHE
Definition: disk.h:50
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
UCHAR MinimumPrefetch[2]
Definition: cdrw_hw.h:2786
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
ULONG NTAPI DebugPrint(IN PSTRING DebugString, IN ULONG ComponentId, IN ULONG Level)
Definition: debug.c:23
UCHAR DisablePrefetchTransfer[2]
Definition: cdrw_hw.h:2785
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:409
unsigned int ULONG
Definition: retypes.h:1
UCHAR MaximumPrefetchCeiling[2]
Definition: cdrw_hw.h:2788
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
UCHAR WriteRetensionPriority
Definition: cdrw_hw.h:2782
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by DisableWriteCache(), DiskDeviceControl(), and DiskStartFdo().

◆ DiskGetInfoExceptionInformation()

NTSTATUS NTAPI DiskGetInfoExceptionInformation ( IN PFUNCTIONAL_DEVICE_EXTENSION  FdoExtension,
OUT PMODE_INFO_EXCEPTIONS  ReturnPageData 
)

◆ DiskInitFdo()

NTSTATUS NTAPI DiskInitFdo ( IN PDEVICE_OBJECT  Fdo)

Definition at line 190 of file pnp.c.

211 {
212  PFUNCTIONAL_DEVICE_EXTENSION fdoExtension = Fdo->DeviceExtension;
213 
214  PDISK_DATA diskData = (PDISK_DATA) fdoExtension->CommonExtension.DriverData;
215 
216  //ULONG srbFlags = 0;
217 
218  ULONG timeOut = 0;
219 
220  ULONG bytesPerSector;
221  //UCHAR sectorShift;
222 
223  //BOOLEAN dmActive = FALSE;
224  PULONG dmSkew;
225  //ULONG dmByteSkew;
226 
228 
229  PAGED_CODE();
230 
231  //
232  // Build the lookaside list for srb's for the physical disk. Should only
233  // need a couple. If this fails then we don't have an emergency SRB so
234  // fail the call to initialize.
235  //
236 
239 
240  //
241  // Because all requests share a common sense buffer, it is possible
242  // for the buffer to be overwritten if the port driver completes
243  // multiple failed requests that require a request sense before the
244  // class driver's completion routine can consume the data in the buffer.
245  // To prevent this, we allow the port driver to allocate a unique sense
246  // buffer each time it needs one. We are responsible for freeing this
247  // buffer. This also allows the adapter to be configured to support
248  // additional sense data beyond the minimum 18 bytes.
249  //
250 
252 
253  //
254  // Initialize the srb flags.
255  //
256 
257  if (fdoExtension->DeviceDescriptor->CommandQueueing &&
258  fdoExtension->AdapterDescriptor->CommandQueueing) {
259 
260  fdoExtension->SrbFlags = SRB_FLAGS_QUEUE_ACTION_ENABLE;
261 
262  }
263 
264  if (!TEST_FLAG(Fdo->Characteristics, FILE_REMOVABLE_MEDIA)) {
265  SET_FLAG(fdoExtension->DeviceFlags, DEV_SAFE_START_UNIT);
266  }
267 
268  //
269  // Look for controllers that require special flags.
270  //
271 
273 
274  //
275  // Look into the registry to see if this device
276  // requires special attention - [ like a hack ]
277  //
278 
279  DiskScanRegistryForSpecial(fdoExtension);
280 
281  //srbFlags = fdoExtension->SrbFlags;
282 
283  //
284  // Clear buffer for drive geometry.
285  //
286 
287  RtlZeroMemory(&(fdoExtension->DiskGeometry),
288  sizeof(DISK_GEOMETRY));
289 
290  //
291  // Allocate request sense buffer.
292  //
293 
297 
298  if (fdoExtension->SenseData == NULL) {
299 
300  //
301  // The buffer can not be allocated.
302  //
303 
304  DebugPrint((1, "DiskInitFdo: Can not allocate request sense buffer\n"));
305 
307  return status;
308  }
309 
310  //
311  // Physical device object will describe the entire
312  // device, starting at byte offset 0.
313  //
314 
315  fdoExtension->CommonExtension.StartingOffset.QuadPart = (LONGLONG)(0);
316 
317  //
318  // Set timeout value in seconds.
319  //
320 
321  timeOut = ClassQueryTimeOutRegistryValue(Fdo);
322  if (timeOut) {
323  fdoExtension->TimeOutValue = timeOut;
324  } else {
325  fdoExtension->TimeOutValue = SCSI_DISK_TIMEOUT;
326  }
327 
328  //
329  // If this is a removable drive, build an entry in devicemap\scsi
330  // indicating it's physicaldriveN name, set up the appropriate
331  // update partitions routine and set the flags correctly.
332  // note: only do this after the timeout value is set, above.
333  //
334 
335  if (fdoExtension->DeviceDescriptor->RemovableMedia) {
337  "PhysicalDrive",
338  fdoExtension->DeviceNumber,
339  NULL,
340  0);
341  //
342  // Enable media change notification for removable disks
343  //
345  "Disk");
346 
347  SET_FLAG(Fdo->Characteristics, FILE_REMOVABLE_MEDIA);
349 
350  } else {
351 
354 
355  }
356 
357  //
358  // Read the drive capacity. Don't use the disk version of the routine here
359  // since we don't know the disk signature yet - the disk version will
360  // attempt to determine the BIOS reported geometry.
361  //
362 
364 
365  //
366  // If the read capacity failed then just return, unless this is a
367  // removable disk where a device object partition needs to be created.
368  //
369 
370  if (!NT_SUCCESS(status) &&
371  !(Fdo->Characteristics & FILE_REMOVABLE_MEDIA)) {
372 
373  DebugPrint((1,
374  "DiskInitFdo: Can't read capacity for device %p\n",
375  Fdo));
376 
377  if (fdoExtension->DeviceDescriptor->RemovableMedia) {
378  fdoExtension->DiskGeometry.MediaType = RemovableMedia;
379  Fdo->Flags &= ~DO_VERIFY_VOLUME;
380  } else {
381  fdoExtension->DiskGeometry.MediaType = FixedMedia;
382  }
383 
385  }
386 
387  //
388  // Set up sector size fields.
389  //
390  // Stack variables will be used to update
391  // the partition device extensions.
392  //
393  // The device extension field SectorShift is
394  // used to calculate sectors in I/O transfers.
395  //
396  // The DiskGeometry structure is used to service
397  // IOCTls used by the format utility.
398  //
399 
400  bytesPerSector = fdoExtension->DiskGeometry.BytesPerSector;
401 
402  //
403  // Make sure sector size is not zero.
404  //
405 
406  if (bytesPerSector == 0) {
407 
408  //
409  // Default sector size for disk is 512.
410  //
411 
412  bytesPerSector = fdoExtension->DiskGeometry.BytesPerSector = 512;
413  }
414 
415  //sectorShift = fdoExtension->SectorShift;
416 
417  //
418  // Determine is DM Driver is loaded on an IDE drive that is
419  // under control of Atapi - this could be either a crashdump or
420  // an Atapi device is sharing the controller with an IDE disk.
421  //
422 
424  fdoExtension->DiskGeometry.BytesPerSector,
425  (ULONG)0x54,
426  (PVOID*)&dmSkew);
427 
428  if (dmSkew) {
429 
430  //
431  // Update the device extension, so that the call to IoReadPartitionTable
432  // will get the correct information. Any I/O to this disk will have
433  // to be skewed by *dmSkew sectors aka DMByteSkew.
434  //
435 
436  fdoExtension->DMSkew = *dmSkew;
437  fdoExtension->DMActive = TRUE;
438  fdoExtension->DMByteSkew = fdoExtension->DMSkew * bytesPerSector;
439 
440  //
441  // Save away the information that we need, since this deviceExtension will soon be
442  // blown away.
443  //
444 
445  //dmActive = TRUE;
446  //dmByteSkew = fdoExtension->DMByteSkew;
447 
448  }
449 
450 #if defined(_X86_)
451  //
452  // Try to read the signature off the disk and determine the correct drive
453  // geometry based on that. This requires rereading the disk size to get
454  // the cylinder count updated correctly.
455  //
456 
457  if(fdoExtension->DeviceDescriptor->RemovableMedia == FALSE) {
458  DiskReadSignature(Fdo);
460  }
461 #endif
462 
463  //
464  // Register interfaces for this device
465  //
466  {
467  UNICODE_STRING interfaceName;
468 
469  RtlInitUnicodeString(&interfaceName, NULL);
470 
471  status = IoRegisterDeviceInterface(fdoExtension->LowerPdo,
472  (LPGUID) &DiskClassGuid,
473  NULL,
474  &interfaceName);
475 
476  if(NT_SUCCESS(status)) {
477 
478  diskData->DiskInterfaceString = interfaceName;
479  status = IoSetDeviceInterfaceState(&interfaceName, TRUE);
480 
481  } else {
482  interfaceName.Buffer = NULL;
483  }
484 
485  if(!NT_SUCCESS(status)) {
486 
487  DebugPrint((1, "DiskInitFdo: Unable to register or set disk DCA "
488  "for fdo %p [%lx]\n", Fdo, status));
489 
490  RtlFreeUnicodeString(&interfaceName);
492  }
493  }
494 
496 
497  //
498  // Determine the type of disk and enable failure prediction in the hardware
499  // and enable failure prediction polling.
500  //
501 
502  if (InitSafeBootMode == 0)
503  {
504  DiskDetectFailurePrediction(fdoExtension,
505  &diskData->FailurePredictionCapability);
506 
508  {
509  //
510  // Cool, we've got some sort of failure prediction, enable it
511  // at the hardware and then enable polling for it
512  //
513 
514  //
515  // By default we allow performance to be degradeded if failure
516  // prediction is enabled.
517  //
518  // TODO: Make a registry entry ?
519  //
520 
521  diskData->AllowFPPerfHit = TRUE;
522 
523  //
524  // Enable polling only after Atapi and SBP2 add support for the new
525  // SRB flag that indicates that the request should not reset the
526  // drive spin down idle timer.
527  //
528 
530  TRUE,
532 
533  DebugPrint((3, "DiskInitFdo: Failure Prediction Poll enabled as "
534  "%d for device %p\n",
535  diskData->FailurePredictionCapability,
536  Fdo));
537  }
538  } else {
539 
540  //
541  // In safe boot mode we do not enable failure prediction, as perhaps
542  // it is the reason why normal boot does not work
543  //
544 
546 
547  }
548 
549  //
550  // Initialize the verify mutex
551  //
552 
554 
555  return(STATUS_SUCCESS);
556 
557 } // end DiskInitFdo()
VOID NTAPI DiskUpdatePartitions(IN PDEVICE_OBJECT Fdo, IN OUT PDRIVE_LAYOUT_INFORMATION_EX PartitionList)
Definition: enum.c:592
struct _DISK_DATA * PDISK_DATA
#define TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
NTSTATUS NTAPI DiskEnableDisableFailurePredictPolling(PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, BOOLEAN Enable, ULONG PollTimeInSeconds)
Definition: diskwmi.c:949
#define TEST_FLAG(Flags, Bit)
Definition: classpnp.h:156
DISK_GEOMETRY DiskGeometry
Definition: classpnp.h:704
#define SRB_FLAGS_NO_QUEUE_FREEZE
Definition: srb.h:396
VOID NTAPI DiskSetSpecialHacks(IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, IN ULONG_PTR Data)
Definition: disk.c:4009
CLASSPNP_SCAN_FOR_SPECIAL_INFO DiskBadControllers[]
Definition: data.c:38
LONG NTSTATUS
Definition: precomp.h:26
COMMON_DEVICE_EXTENSION CommonExtension
Definition: classpnp.h:695
#define DISK_DEFAULT_FAILURE_POLLING_PERIOD
Definition: disk.h:382
#define DO_VERIFY_VOLUME
Definition: env_spec_w32.h:393
ULONG BytesPerSector
Definition: ntdddisk.h:381
#define DISK_TAG_START
Definition: disk.h:62
VOID NTAPI ClassUpdateInformationInRegistry(IN PDEVICE_OBJECT Fdo, IN PCHAR DeviceName, IN ULONG DeviceNumber, IN PINQUIRYDATA InquiryData, IN ULONG InquiryDataLength)
Definition: class.c:7322
#define SENSE_BUFFER_SIZE
Definition: cdrw_hw.h:1183
BOOLEAN AllowFPPerfHi