diff --git a/PInvoke/Kernel32/WinIOCtl.Enums.cs b/PInvoke/Kernel32/WinIOCtl.Enums.cs index 8135e2ea7..d9ba1093a 100644 --- a/PInvoke/Kernel32/WinIOCtl.Enums.cs +++ b/PInvoke/Kernel32/WinIOCtl.Enums.cs @@ -1,4 +1,5 @@ using System; +using Vanara.InteropServices; namespace Vanara.PInvoke; @@ -2119,15 +2120,18 @@ public enum STORAGE_PORT_CODE_SET public enum STORAGE_PROPERTY_ID { /// Indicates that the caller is querying for the device descriptor, STORAGE_DEVICE_DESCRIPTOR. - StorageDeviceProperty, + [CorrespondingType(typeof(STORAGE_DEVICE_DESCRIPTOR))] + StorageDeviceProperty = 0, /// Indicates that the caller is querying for the adapter descriptor, STORAGE_ADAPTER_DESCRIPTOR. + [CorrespondingType(typeof(STORAGE_ADAPTER_DESCRIPTOR))] StorageAdapterProperty, /// /// Indicates that the caller is querying for the device identifiers provided with the SCSI vital product data pages. Data is /// returned using the STORAGE_DEVICE_ID_DESCRIPTOR structure. /// + [CorrespondingType(typeof(STORAGE_DEVICE_ID_DESCRIPTOR))] StorageDeviceIdProperty, /// @@ -2135,12 +2139,14 @@ public enum STORAGE_PROPERTY_ID /// the STORAGE_DEVICE_UNIQUE_IDENTIFIER structure (see the storduid.h header in the DDK). Windows Server 2003 and Windows XP: /// This value is not supported before Windows Vista and Windows Server 2008. /// + [CorrespondingType(typeof(STORAGE_DEVICE_UNIQUE_IDENTIFIER))] StorageDeviceUniqueIdProperty, /// /// Indicates that the caller is querying for the write cache property. Data is returned using the STORAGE_WRITE_CACHE_PROPERTY /// structure. Windows Server 2003 and Windows XP: This value is not supported before Windows Vista and Windows Server 2008. /// + [CorrespondingType(typeof(STORAGE_WRITE_CACHE_PROPERTY))] StorageDeviceWriteCacheProperty, /// Reserved for system use. @@ -2150,12 +2156,14 @@ public enum STORAGE_PROPERTY_ID /// Indicates that the caller is querying for the access alignment descriptor, STORAGE_ACCESS_ALIGNMENT_DESCRIPTOR. Windows /// Server 2003 and Windows XP: This value is not supported before Windows Vista and Windows Server 2008. /// + [CorrespondingType(typeof(STORAGE_ACCESS_ALIGNMENT_DESCRIPTOR))] StorageAccessAlignmentProperty, /// /// Indicates that the caller is querying for the trim descriptor, DEVICE_TRIM_DESCRIPTOR. Windows Server 2008, Windows Vista, /// Windows Server 2003 and Windows XP: This value is not supported before Windows 7 and Windows Server 2008 R2. /// + [CorrespondingType(typeof(DEVICE_TRIM_DESCRIPTOR))] StorageDeviceTrimProperty, /// @@ -2163,6 +2171,7 @@ public enum STORAGE_PROPERTY_ID /// structure. Windows 7, Windows Server 2008 R2, Windows Server 2008, Windows Vista, Windows Server 2003 and Windows XP: This /// value is not supported before Windows 8 and Windows Server 2012. /// + [CorrespondingType(typeof(DEVICE_POWER_DESCRIPTOR))] StorageDevicePowerProperty, /// Reserved for system use. @@ -2172,81 +2181,111 @@ public enum STORAGE_PROPERTY_ID /// Indicates that the caller is querying for the medium product type. Data is returned using the /// STORAGE_MEDIUM_PRODUCT_TYPE_DESCRIPTOR structure. /// + [CorrespondingType(typeof(STORAGE_MEDIUM_PRODUCT_TYPE_DESCRIPTOR))] StorageDeviceMediumProductType, /// /// Indicates that the caller is querying for RPMB support and properties. Data is returned using the STORAGE_RPMB_DESCRIPTOR structure. /// + [CorrespondingType(typeof(STORAGE_RPMB_DESCRIPTOR))] StorageAdapterRpmbProperty, - /// + /// + /// Provides info on the storage adapter encryption capabilities. This is currently supported on UFS (Universal Flash Storage) adapters. + /// StorageAdapterCryptoProperty, /// /// Indicates that the caller is querying for the device I/O capability property. Data is returned using the /// DEVICE_IO_CAPABILITY_DESCRIPTOR structure. /// - StorageDeviceIoCapabilityProperty, + [CorrespondingType(typeof(STORAGE_DEVICE_IO_CAPABILITY_DESCRIPTOR))] + StorageDeviceIoCapabilityProperty = 48, /// /// Indicates that the caller is querying for protocol-specific data from the adapter. Data is returned using the /// STORAGE_PROTOCOL_DATA_DESCRIPTOR structure. See the remarks for more info. /// + [CorrespondingType(typeof(STORAGE_PROTOCOL_DATA_DESCRIPTOR))] StorageAdapterProtocolSpecificProperty, /// /// Indicates that the caller is querying for protocol-specific data from the device. Data is returned using the /// STORAGE_PROTOCOL_DATA_DESCRIPTOR structure. See the remarks for more info. /// + [CorrespondingType(typeof(STORAGE_PROTOCOL_DATA_DESCRIPTOR))] StorageDeviceProtocolSpecificProperty, /// /// Indicates that the caller is querying temperature data from the adapter. Data is returned using the /// STORAGE_TEMPERATURE_DATA_DESCRIPTOR structure. /// + [CorrespondingType(typeof(STORAGE_TEMPERATURE_DATA_DESCRIPTOR))] StorageAdapterTemperatureProperty, /// /// Indicates that the caller is querying for temperature data from the device. Data is returned using the /// STORAGE_TEMPERATURE_DATA_DESCRIPTOR structure. /// + [CorrespondingType(typeof(STORAGE_TEMPERATURE_DATA_DESCRIPTOR))] StorageDeviceTemperatureProperty, /// /// Indicates that the caller is querying for topology information from the adapter. Data is returned using the /// STORAGE_PHYSICAL_TOPOLOGY_DESCRIPTOR structure. /// + [CorrespondingType(typeof(STORAGE_PHYSICAL_TOPOLOGY_DESCRIPTOR))] StorageAdapterPhysicalTopologyProperty, /// /// Indicates that the caller is querying for topology information from the device. Data is returned using the /// STORAGE_PHYSICAL_TOPOLOGY_DESCRIPTOR structure. /// + [CorrespondingType(typeof(STORAGE_PHYSICAL_TOPOLOGY_DESCRIPTOR))] StorageDevicePhysicalTopologyProperty, /// Reserved for future use. StorageDeviceAttributesProperty, - /// + /// Provides health information about the storage device (specifically for the persistent memory stack). + [CorrespondingType(typeof(STORAGE_DEVICE_MANAGEMENT_STATUS))] StorageDeviceManagementStatus, - /// + /// + /// Indicates that the caller is querying for the adapter serial number. Data is returned using the STORAGE_ADAPTER_SERIAL_NUMBER structure. + /// + [CorrespondingType(typeof(STORAGE_ADAPTER_SERIAL_NUMBER))] StorageAdapterSerialNumberProperty, - /// + /// Reserved for system use. StorageDeviceLocationProperty, - /// + /// Provides the non-uniform memory access (NUMA) node of the storage device. StorageDeviceNumaProperty, - /// + /// Reserved for system use. StorageDeviceZonedDeviceProperty, - /// + /// + /// Provides the unsafe shutdown count value used to determine if the device data might have been lost during a power loss event + /// (specifically for the persistent memory stack). + /// StorageDeviceUnsafeShutdownCount, - /// + /// + /// Provides info on how many bytes have been read/write from a solid-state drive (SSD). This property is supported only for + /// Non-Volatile Memory Express (NVMe) devices that implement a certain NVMe feature. + /// StorageDeviceEnduranceProperty, + + /// Provides info on the state of the LED associated with a storage device. This is a server-oriented feature. + StorageDeviceLedStateProperty, + + /// Reserved for system use. + StorageDeviceSelfEncryptionProperty = 64, + + /// Provides identification info for a storage device that can be physically replaced with a Field Replacement Unit (FRU). + StorageFruIdProperty } /// diff --git a/PInvoke/Kernel32/WinIOCtl.STORAGE_DEVICE_MANAGEMENT_STATUS.cs b/PInvoke/Kernel32/WinIOCtl.STORAGE_DEVICE_MANAGEMENT_STATUS.cs new file mode 100644 index 000000000..bb58a5ba2 --- /dev/null +++ b/PInvoke/Kernel32/WinIOCtl.STORAGE_DEVICE_MANAGEMENT_STATUS.cs @@ -0,0 +1,203 @@ +using System.Runtime.InteropServices; +using Vanara.InteropServices; + +namespace Vanara.PInvoke; + +public static partial class Kernel32 +{ + private const int STORAGE_ADAPTER_SERIAL_NUMBER_V1_MAX_LENGTH = 128; + + private const int STORAGE_DEVICE_MAX_OPERATIONAL_STATUS = 16; + + /// Constants for StorageDeviceManagementStatus + [PInvokeData("winioctl.h")] + public enum STORAGE_DISK_HEALTH_STATUS + { + DiskHealthUnknown = 0, + DiskHealthUnhealthy, + DiskHealthWarning, + DiskHealthHealthy, + DiskHealthMax, + } + + /// Operational States + [PInvokeData("winioctl.h")] + public enum STORAGE_DISK_OPERATIONAL_STATUS + { + DiskOpStatusNone = 0, + DiskOpStatusUnknown, + DiskOpStatusOk, + DiskOpStatusPredictingFailure, + DiskOpStatusInService, + DiskOpStatusHardwareError, + DiskOpStatusNotUsable, + DiskOpStatusTransientError, + DiskOpStatusMissing, + } + + /// Operational Reasons + [PInvokeData("winioctl.h")] + public enum STORAGE_OPERATIONAL_STATUS_REASON + { + DiskOpReasonUnknown = 0, + DiskOpReasonScsiSenseCode, + DiskOpReasonMedia, + DiskOpReasonIo, + DiskOpReasonThresholdExceeded, + DiskOpReasonLostData, + DiskOpReasonEnergySource, + DiskOpReasonConfiguration, + DiskOpReasonDeviceController, + DiskOpReasonMediaController, + DiskOpReasonComponent, + DiskOpReasonNVDIMM_N, + DiskOpReasonBackgroundOperation, + DiskOpReasonInvalidFirmware, + DiskOpReasonHealthCheck, + DiskOpReasonLostDataPersistence, + DiskOpReasonDisabledByPlatform, + DiskOpReasonLostWritePersistence, + DiskOpReasonDataPersistenceLossImminent, + DiskOpReasonWritePersistenceLossImminent, + DiskOpReasonMax, + } + + /// + /// The NULL-terminated Unicode string of the adapter serial number for the StorageAdapterSerialNumberProperty as defined in STORAGE_PROPERTY_ID. + /// + // https://learn.microsoft.com/en-us/windows/win32/api/winioctl/ns-winioctl-storage_adapter_serial_number typedef struct + // _STORAGE_ADAPTER_SERIAL_NUMBER { DWORD Version; DWORD Size; WCHAR SerialNumber[STORAGE_ADAPTER_SERIAL_NUMBER_V1_MAX_LENGTH]; } + // STORAGE_ADAPTER_SERIAL_NUMBER, *PSTORAGE_ADAPTER_SERIAL_NUMBER; + [PInvokeData("winioctl.h", MSDNShortId = "NS:winioctl._STORAGE_ADAPTER_SERIAL_NUMBER")] + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] + public struct STORAGE_ADAPTER_SERIAL_NUMBER + { + /// The version of this structure. The Size serves as the version. + public uint Version; + + /// The size of this structure. + public uint Size; + + /// The serial number. + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = STORAGE_ADAPTER_SERIAL_NUMBER_V1_MAX_LENGTH)] + public string SerialNumber; + } + + /// Structure for STORAGE_PROPERTY_ID.StorageDeviceManagementStatus + [PInvokeData("winioctl.h")] + [VanaraMarshaler(typeof(SafeAnysizeStructMarshaler), nameof(NumberOfAdditionalReasons))] + [StructLayout(LayoutKind.Sequential)] + public struct STORAGE_DEVICE_MANAGEMENT_STATUS + { + /// Sizeof() of this structure serves as the version. + public uint Version; + + /// + /// The total size of the structure, including operational status reasons that didn't fit in the caller's array. Callers should use + /// this field to learn how big the input buffer should be to contain all the available information. + /// + public uint Size; + + /// Health status. + public STORAGE_DISK_HEALTH_STATUS Health; + + /// The number of operational status returned. + public uint NumberOfOperationalStatus; + + /// The number of additional reasons returned. + public uint NumberOfAdditionalReasons; + + /// + /// Operational statuses. The primary operational status is the first element in the array. There are NumberOfOperationalStatus valid + /// elements in the array. + /// + [MarshalAs(UnmanagedType.ByValArray, SizeConst = STORAGE_DEVICE_MAX_OPERATIONAL_STATUS)] + public STORAGE_DISK_OPERATIONAL_STATUS[] OperationalStatus; + + /// Additional reasons. There are NumberOfAdditionalReasons valid elements in the array. + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)] + public STORAGE_OPERATIONAL_REASON[] AdditionalReasons; + } + + /// The STORAGE_DEVICE_UNIQUE_IDENTIFIER structure defines a device unique identifier (DUID). + // https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/storduid/ns-storduid-_storage_device_unique_identifier typedef struct + // _STORAGE_DEVICE_UNIQUE_IDENTIFIER { ULONG Version; ULONG Size; ULONG StorageDeviceIdOffset; ULONG StorageDeviceOffset; ULONG + // DriveLayoutSignatureOffset; } STORAGE_DEVICE_UNIQUE_IDENTIFIER, *PSTORAGE_DEVICE_UNIQUE_IDENTIFIER; + [PInvokeData("storduid.h", MSDNShortId = "NS:storduid._STORAGE_DEVICE_UNIQUE_IDENTIFIER")] + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] + public struct STORAGE_DEVICE_UNIQUE_IDENTIFIER + { + /// The version of the DUID. + public uint Version; + + /// The size, in bytes, of the identifier header and the identifiers (IDs) that follow the header. + public uint Size; + + /// + /// The offset, in bytes, from the beginning of the header to the device ID descriptor (STORAGE_DEVICE_ID_DESCRIPTOR). The device ID + /// descriptor contains the IDs that are extracted from page 0x83 of the device's vital product data (VPD). + /// + public uint StorageDeviceIdOffset; + + /// + /// The offset, in bytes, from the beginning of the header to the device descriptor (STORAGE_DEVICE_DESCRIPTOR). The device + /// descriptor contains IDs that are extracted from non-VPD inquiry data. + /// + public uint StorageDeviceOffset; + + /// The offset, in bytes, to the drive layout signature (STORAGE_DEVICE_LAYOUT_SIGNATURE). + public uint DriveLayoutSignatureOffset; + } + + /// Additional reasons. + [PInvokeData("winioctl.h")] + [StructLayout(LayoutKind.Explicit)] + public struct STORAGE_OPERATIONAL_REASON + { + [FieldOffset(0)] + public uint Version; + + [FieldOffset(4)] + public uint Size; + + [FieldOffset(8)] + public STORAGE_OPERATIONAL_STATUS_REASON Reason; + + [FieldOffset(12)] + public RawBytesUnion RawBytes; + + /// This is the format if Reason == DiskOpReasonScsiSenseCode. + [StructLayout(LayoutKind.Sequential)] + public struct ScsiSenseKeyStruct + { + public byte SenseKey; + public byte ASC; + public byte ASCQ; + public byte Reserved; + } + + /// This is the format if Reason == DiskOpReasonNVDIMM_N. + [StructLayout(LayoutKind.Sequential)] + public unsafe struct NVDIMM_NStruct + { + public byte CriticalHealth; + public byte ModuleHealth[2]; + public byte ErrorThresholdStatus; + } + + [StructLayout(LayoutKind.Explicit)] + public struct RawBytesUnion + { + /// This is the format if Reason == DiskOpReasonScsiSenseCode. + [FieldOffset(0)] + public ScsiSenseKeyStruct ScsiSenseKey; + + /// This is the format if Reason == DiskOpReasonNVDIMM_N. + [FieldOffset(0)] + public NVDIMM_NStruct NVDIMM_N; + + [FieldOffset(0)] + public uint AsUlong; + } + } +} \ No newline at end of file