Also exclude OEM variant of 980 Pro NVMe

This commit is contained in:
PhyxionNL
2022-02-23 16:55:43 +01:00
parent a72a517153
commit cd9e15d7dc
5 changed files with 33 additions and 43 deletions
@@ -75,15 +75,13 @@ namespace LibreHardwareMonitor.Hardware.Storage
if (info == null)
return null;
info.DiskSize = diskSize;
info.DeviceId = deviceId;
info.Scsi = $@"\\.\SCSI{scsiPort}:";
if (info.Removable || info.BusType == Kernel32.STORAGE_BUS_TYPE.BusTypeVirtual || info.BusType == Kernel32.STORAGE_BUS_TYPE.BusTypeFileBackedVirtual)
if (info.Removable || info.BusType is Kernel32.STORAGE_BUS_TYPE.BusTypeVirtual or Kernel32.STORAGE_BUS_TYPE.BusTypeFileBackedVirtual)
return null;
//fallback, when it is not possible to read out with the nvme implementation,
//try it with the sata smart implementation
if (info.BusType == Kernel32.STORAGE_BUS_TYPE.BusTypeNvme)
@@ -137,7 +135,6 @@ namespace LibreHardwareMonitor.Hardware.Storage
if (data == null)
return;
ulong value = (ulong)data.Properties["PercentDiskWriteTime"].Value;
ulong valueBase = (ulong)data.Properties["PercentDiskWriteTime_Base"].Value;
_perfWrite.Update(value, valueBase);
@@ -216,7 +213,6 @@ namespace LibreHardwareMonitor.Hardware.Storage
if (!DriveInfos[i].IsReady)
continue;
try
{
totalSize += DriveInfos[i].TotalSize;
@@ -253,7 +249,6 @@ namespace LibreHardwareMonitor.Hardware.Storage
if (!di.IsReady)
continue;
try
{
r.AppendLine("Logical Drive Name: " + di.Name);
@@ -32,8 +32,7 @@ namespace LibreHardwareMonitor.Hardware.Storage
private static NVMeInfo GetDeviceInfo(StorageInfo storageInfo)
{
var smart = new NVMeSmart(storageInfo);
NVMeInfo info = smart.GetInfo();
return info;
return smart.GetInfo();
}
internal static AbstractStorage CreateInstance(StorageInfo storageInfo, ISettings settings)
@@ -23,7 +23,7 @@ namespace LibreHardwareMonitor.Hardware.Storage
public bool IdentifyController(SafeHandle hDevice, out Kernel32.NVME_IDENTIFY_CONTROLLER_DATA data)
{
data = Kernel32.CreateStruct<Kernel32.NVME_IDENTIFY_CONTROLLER_DATA>();
if (hDevice == null || hDevice.IsInvalid)
if (hDevice?.IsInvalid != false)
return false;
bool result = false;
@@ -83,8 +83,7 @@ namespace LibreHardwareMonitor.Hardware.Storage
{
IntPtr offset = Marshal.OffsetOf<Kernel32.SCSI_PASS_THROUGH_WITH_BUFFERS>(nameof(Kernel32.SCSI_PASS_THROUGH_WITH_BUFFERS.DataBuf));
IntPtr newPtr = IntPtr.Add(buffer, offset.ToInt32());
Kernel32.NVME_IDENTIFY_CONTROLLER_DATA item = Marshal.PtrToStructure<Kernel32.NVME_IDENTIFY_CONTROLLER_DATA>(newPtr);
data = item;
data = Marshal.PtrToStructure<Kernel32.NVME_IDENTIFY_CONTROLLER_DATA>(newPtr);
Marshal.FreeHGlobal(buffer);
result = true;
}
@@ -164,8 +163,7 @@ namespace LibreHardwareMonitor.Hardware.Storage
{
IntPtr offset = Marshal.OffsetOf<Kernel32.SCSI_PASS_THROUGH_WITH_BUFFERS>(nameof(Kernel32.SCSI_PASS_THROUGH_WITH_BUFFERS.DataBuf));
IntPtr newPtr = IntPtr.Add(buffer, offset.ToInt32());
Kernel32.NVME_HEALTH_INFO_LOG item = Marshal.PtrToStructure<Kernel32.NVME_HEALTH_INFO_LOG>(newPtr);
data = item;
data = Marshal.PtrToStructure<Kernel32.NVME_HEALTH_INFO_LOG>(newPtr);
Marshal.FreeHGlobal(buffer);
result = true;
}
@@ -22,9 +22,17 @@ namespace LibreHardwareMonitor.Hardware.Storage
// Test samsung protocol.
// Exclude Samsung 980 Pro, this SSD uses the NVMeWindows generic protocol.
// Exclude Samsung 980 Pro and PM9A1, these use the NVMeWindows generic protocol.
// Samsung 980 Pro can accessed via IdentifyDevice and IdentifyController but not by HealthInfoLog.
if (NVMeDrive == null && storageInfo.Name.IndexOf("Samsung", StringComparison.OrdinalIgnoreCase) > -1 && storageInfo.Name.IndexOf("980 Pro", StringComparison.OrdinalIgnoreCase) == -1)
string name = storageInfo.Name;
if (NVMeDrive == null &&
name.IndexOf("Samsung", StringComparison.OrdinalIgnoreCase) > -1 &&
name.IndexOf("980 Pro", StringComparison.OrdinalIgnoreCase) == -1 &&
name.IndexOf("MZVL2256HCHQ", StringComparison.OrdinalIgnoreCase) == -1 &&
name.IndexOf("MZVL2512HCJQ", StringComparison.OrdinalIgnoreCase) == -1 &&
name.IndexOf("MZVL21T0HCLR", StringComparison.OrdinalIgnoreCase) == -1 &&
name.IndexOf("MZVL22T0HBLB", StringComparison.OrdinalIgnoreCase) == -1)
{
_handle = NVMeSamsung.IdentifyDevice(storageInfo);
if (_handle != null)
@@ -34,7 +42,7 @@ namespace LibreHardwareMonitor.Hardware.Storage
}
// Test Intel protocol.
if (NVMeDrive == null && storageInfo.Name.IndexOf("Intel", StringComparison.OrdinalIgnoreCase) > -1)
if (NVMeDrive == null && name.IndexOf("Intel", StringComparison.OrdinalIgnoreCase) > -1)
{
_handle = NVMeIntel.IdentifyDevice(storageInfo);
if (_handle != null)
@@ -44,7 +52,7 @@ namespace LibreHardwareMonitor.Hardware.Storage
}
// Test Intel raid protocol.
if (NVMeDrive == null && storageInfo.Name.IndexOf("Intel", StringComparison.OrdinalIgnoreCase) > -1)
if (NVMeDrive == null && name.IndexOf("Intel", StringComparison.OrdinalIgnoreCase) > -1)
{
_handle = NVMeIntelRst.IdentifyDevice(storageInfo);
if (_handle != null)
@@ -68,11 +76,7 @@ namespace LibreHardwareMonitor.Hardware.Storage
{
get
{
if (_handle == null || _handle.IsInvalid)
return false;
return true;
return _handle is { IsInvalid: false };
}
}
@@ -118,7 +122,6 @@ namespace LibreHardwareMonitor.Hardware.Storage
if (_handle == null || _handle.IsClosed)
return null;
bool valid = false;
var data = new Kernel32.NVME_IDENTIFY_CONTROLLER_DATA();
if (NVMeDrive != null)
@@ -127,7 +130,6 @@ namespace LibreHardwareMonitor.Hardware.Storage
if (!valid)
return null;
return new NVMeInfo(_driveNumber, data);
}
@@ -136,7 +138,6 @@ namespace LibreHardwareMonitor.Hardware.Storage
if (_handle == null || _handle.IsClosed)
return null;
bool valid = false;
var data = new Kernel32.NVME_HEALTH_INFO_LOG();
if (NVMeDrive != null)
@@ -145,7 +146,6 @@ namespace LibreHardwareMonitor.Hardware.Storage
if (!valid)
return null;
return new NVMeHealthInfo(data);
}
@@ -12,7 +12,7 @@ namespace LibreHardwareMonitor.Hardware.Storage
{
internal class StorageGroup : IGroup
{
private readonly List<AbstractStorage> _hardware = new List<AbstractStorage>();
private readonly List<AbstractStorage> _hardware = new();
public StorageGroup(ISettings settings)
{
@@ -20,24 +20,22 @@ namespace LibreHardwareMonitor.Hardware.Storage
return;
//https://docs.microsoft.com/en-us/windows/win32/cimwin32prov/win32-diskdrive
string query = "SELECT * FROM Win32_DiskDrive";
using (var mosDisks = new ManagementObjectSearcher(query) {Options = {Timeout = TimeSpan.FromSeconds(10)}})
using (ManagementObjectCollection queryCollection = mosDisks.Get())
{
foreach (ManagementBaseObject disk in queryCollection)
{
string deviceId = (string)disk.Properties["DeviceId"].Value; // is \\.\PhysicalDrive0..n
uint idx = Convert.ToUInt32(disk.Properties["Index"].Value);
ulong diskSize = Convert.ToUInt64(disk.Properties["Size"].Value);
int scsi = Convert.ToInt32(disk.Properties["SCSIPort"].Value);
using var diskDriveSearcher = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive") { Options = { Timeout = TimeSpan.FromSeconds(10) } };
using ManagementObjectCollection diskDrives = diskDriveSearcher.Get();
if (deviceId != null)
foreach (ManagementBaseObject diskDrive in diskDrives)
{
string deviceId = (string)diskDrive.Properties["DeviceId"].Value; // is \\.\PhysicalDrive0..n
uint idx = Convert.ToUInt32(diskDrive.Properties["Index"].Value);
ulong diskSize = Convert.ToUInt64(diskDrive.Properties["Size"].Value);
int scsi = Convert.ToInt32(diskDrive.Properties["SCSIPort"].Value);
if (deviceId != null)
{
var instance = AbstractStorage.CreateInstance(deviceId, idx, diskSize, scsi, settings);
if (instance != null)
{
var instance = AbstractStorage.CreateInstance(deviceId, idx, diskSize, scsi, settings);
if (instance != null)
{
_hardware.Add(instance);
}
_hardware.Add(instance);
}
}
}