diff --git a/Hardware/HDD/AbstractHarddrive.cs b/Hardware/HDD/AbstractHarddrive.cs index 4236b4f..451ae00 100644 --- a/Hardware/HDD/AbstractHarddrive.cs +++ b/Hardware/HDD/AbstractHarddrive.cs @@ -16,7 +16,7 @@ The Initial Developer of the Original Code is Michael Möller . - Portions created by the Initial Developer are Copyright (C) 2009-2011 + Portions created by the Initial Developer are Copyright (C) 2009-2012 the Initial Developer. All Rights Reserved. Contributor(s): @@ -57,6 +57,7 @@ namespace OpenHardwareMonitor.Hardware.HDD { typeof(GenericHarddisk) }; + private string firmwareRevision; private readonly ISmart smart; private readonly IntPtr handle; @@ -66,11 +67,13 @@ namespace OpenHardwareMonitor.Hardware.HDD { private IList smartAttributes; private IDictionary sensors; - protected AbstractHarddrive(ISmart smart, string name, int index, + protected AbstractHarddrive(ISmart smart, string name, + string firmwareRevision, int index, IEnumerable smartAttributes, ISettings settings) : base(name, new Identifier("hdd", index.ToString(CultureInfo.InvariantCulture)), settings) { + this.firmwareRevision = firmwareRevision; this.smart = smart; handle = smart.OpenDrive(index); @@ -92,7 +95,10 @@ namespace OpenHardwareMonitor.Hardware.HDD { if (deviceHandle == smart.InvalidHandle) return null; - string name = smart.ReadName(deviceHandle, driveIndex); + string name; + string firmwareRevision; + bool nameValid = smart.ReadNameAndFirmwareRevision(deviceHandle, + driveIndex, out name, out firmwareRevision); bool smartEnabled = smart.EnableSmart(deviceHandle, driveIndex); DriveAttributeValue[] values = {}; @@ -101,7 +107,7 @@ namespace OpenHardwareMonitor.Hardware.HDD { smart.CloseHandle(deviceHandle); - if (string.IsNullOrEmpty(name)) + if (!nameValid || string.IsNullOrEmpty(name)) return null; foreach (Type type in hddTypes) { @@ -136,8 +142,8 @@ namespace OpenHardwareMonitor.Hardware.HDD { // check if there is a matching name prefix for this type foreach (NamePrefixAttribute prefix in namePrefixes) { if (name.StartsWith(prefix.Prefix, StringComparison.InvariantCulture)) - return Activator.CreateInstance(type, smart, name, driveIndex, - settings) as AbstractHarddrive; + return Activator.CreateInstance(type, smart, name, firmwareRevision, + driveIndex, settings) as AbstractHarddrive; } } @@ -222,6 +228,7 @@ namespace OpenHardwareMonitor.Hardware.HDD { r.AppendLine(this.GetType().Name); r.AppendLine(); r.AppendLine("Drive name: " + name); + r.AppendLine("Firmware version: " + firmwareRevision); r.AppendLine(); r.AppendFormat(CultureInfo.InvariantCulture, " {0}{1}{2}{3}{4}{5}{6}{7}", diff --git a/Hardware/HDD/DebugSmart.cs b/Hardware/HDD/DebugSmart.cs index f114d00..3883759 100644 --- a/Hardware/HDD/DebugSmart.cs +++ b/Hardware/HDD/DebugSmart.cs @@ -16,7 +16,7 @@ The Initial Developer of the Original Code is Michael Möller . - Portions created by the Initial Developer are Copyright (C) 2011 + Portions created by the Initial Developer are Copyright (C) 2011-2012 the Initial Developer. All Rights Reserved. Contributor(s): @@ -219,11 +219,14 @@ namespace OpenHardwareMonitor.Hardware.HDD { return drives[driveNumber].DriveThresholdValues; } - public string ReadName(IntPtr handle, int driveNumber) { + public bool ReadNameAndFirmwareRevision(IntPtr handle, int driveNumber, + out string name, out string firmwareRevision) { if (handle != (IntPtr)driveNumber) throw new ArgumentOutOfRangeException(); - return drives[driveNumber].Name; + name = drives[driveNumber].Name; + firmwareRevision = ""; + return true; } public void CloseHandle(IntPtr handle) { } diff --git a/Hardware/HDD/HDDGeneric.cs b/Hardware/HDD/HDDGeneric.cs index 52f78a2..1fe0f5b 100644 --- a/Hardware/HDD/HDDGeneric.cs +++ b/Hardware/HDD/HDDGeneric.cs @@ -16,7 +16,7 @@ The Initial Developer of the Original Code is Roland Reinl . - Portions created by the Initial Developer are Copyright (C) 2011 + Portions created by the Initial Developer are Copyright (C) 2011-2012 the Initial Developer. All Rights Reserved. Contributor(s): @@ -116,8 +116,8 @@ namespace OpenHardwareMonitor.Hardware.HDD { null, SensorType.Temperature, 0) }; - public GenericHarddisk(ISmart smart, string name, int index, - ISettings settings) - : base(smart, name, index, smartAttributes, settings) { } + public GenericHarddisk(ISmart smart, string name, string firmwareRevision, + int index, ISettings settings) + : base(smart, name, firmwareRevision, index, smartAttributes, settings) {} } } diff --git a/Hardware/HDD/ISmart.cs b/Hardware/HDD/ISmart.cs index 887e6c7..4154247 100644 --- a/Hardware/HDD/ISmart.cs +++ b/Hardware/HDD/ISmart.cs @@ -16,7 +16,7 @@ The Initial Developer of the Original Code is Michael Möller . - Portions created by the Initial Developer are Copyright (C) 2011 + Portions created by the Initial Developer are Copyright (C) 2011-2012 the Initial Developer. All Rights Reserved. Contributor(s): @@ -51,7 +51,8 @@ namespace OpenHardwareMonitor.Hardware.HDD { DriveThresholdValue[] ReadSmartThresholds(IntPtr handle, int driveNumber); - string ReadName(IntPtr handle, int driveNumber); + bool ReadNameAndFirmwareRevision(IntPtr handle, int driveNumber, + out string name, out string firmwareRevision); void CloseHandle(IntPtr handle); diff --git a/Hardware/HDD/SSDIndilinx.cs b/Hardware/HDD/SSDIndilinx.cs index fbcef7c..3cf4057 100644 --- a/Hardware/HDD/SSDIndilinx.cs +++ b/Hardware/HDD/SSDIndilinx.cs @@ -16,7 +16,7 @@ The Initial Developer of the Original Code is Roland Reinl . - Portions created by the Initial Developer are Copyright (C) 2009-2011 + Portions created by the Initial Developer are Copyright (C) 2009-2012 the Initial Developer. All Rights Reserved. Contributor(s): @@ -68,8 +68,9 @@ namespace OpenHardwareMonitor.Hardware.HDD { new SmartAttribute(0xD4, SmartAttributeNames.SataErrorCountHandshake), }; - public SSDIndilinx(ISmart smart, string name, int index, ISettings settings) - : base(smart, name, index, smartAttributes, settings) { } + public SSDIndilinx(ISmart smart, string name, string firmwareRevision, + int index, ISettings settings) + : base(smart, name, firmwareRevision, index, smartAttributes, settings) {} } } diff --git a/Hardware/HDD/SSDIntel.cs b/Hardware/HDD/SSDIntel.cs index 372b216..0f3b785 100644 --- a/Hardware/HDD/SSDIntel.cs +++ b/Hardware/HDD/SSDIntel.cs @@ -16,7 +16,7 @@ The Initial Developer of the Original Code is Michael Möller . - Portions created by the Initial Developer are Copyright (C) 2009-2011 + Portions created by the Initial Developer are Copyright (C) 2009-2012 the Initial Developer. All Rights Reserved. Contributor(s): @@ -72,7 +72,8 @@ namespace OpenHardwareMonitor.Hardware.HDD { SensorType.Data, 1), }; - public SSDIntel(ISmart smart, string name, int index, ISettings settings) - : base(smart, name, index, smartAttributes, settings) { } + public SSDIntel(ISmart smart, string name, string firmwareRevision, + int index, ISettings settings) + : base(smart, name, firmwareRevision, index, smartAttributes, settings) {} } } diff --git a/Hardware/HDD/SSDPlextor.cs b/Hardware/HDD/SSDPlextor.cs index 9271502..5c5dcae 100644 --- a/Hardware/HDD/SSDPlextor.cs +++ b/Hardware/HDD/SSDPlextor.cs @@ -16,7 +16,7 @@ The Initial Developer of the Original Code is Michael Möller . - Portions created by the Initial Developer are Copyright (C) 2011 + Portions created by the Initial Developer are Copyright (C) 2011-2012 the Initial Developer. All Rights Reserved. Contributor(s): @@ -47,7 +47,8 @@ namespace OpenHardwareMonitor.Hardware.HDD { new SmartAttribute(0x0C, SmartAttributeNames.PowerCycleCount, RawToInt), }; - public SSDPlextor(ISmart smart, string name, int index, ISettings settings) - : base(smart, name, index, smartAttributes, settings) { } + public SSDPlextor(ISmart smart, string name, string firmwareRevision, + int index, ISettings settings) + : base(smart, name, firmwareRevision, index, smartAttributes, settings) {} } } diff --git a/Hardware/HDD/SSDSandforce.cs b/Hardware/HDD/SSDSandforce.cs index 5c304ae..1d7b2d2 100644 --- a/Hardware/HDD/SSDSandforce.cs +++ b/Hardware/HDD/SSDSandforce.cs @@ -16,7 +16,7 @@ The Initial Developer of the Original Code is Michael Möller . - Portions created by the Initial Developer are Copyright (C) 2009-2011 + Portions created by the Initial Developer are Copyright (C) 2009-2012 the Initial Developer. All Rights Reserved. Contributor(s): @@ -65,8 +65,9 @@ namespace OpenHardwareMonitor.Hardware.HDD { SensorType.Data, 1) }; - public SSDSandforce(ISmart smart, string name, int index, - ISettings settings) - : base(smart, name, index, smartAttributes, settings) { } + public SSDSandforce(ISmart smart, string name, string firmwareRevision, + int index, ISettings settings) + : base(smart, name, firmwareRevision, index, smartAttributes, settings) + { } } } diff --git a/Hardware/HDD/WindowsSmart.cs b/Hardware/HDD/WindowsSmart.cs index f3001fb..337737a 100644 --- a/Hardware/HDD/WindowsSmart.cs +++ b/Hardware/HDD/WindowsSmart.cs @@ -16,7 +16,7 @@ The Initial Developer of the Original Code is Michael Möller . - Portions created by the Initial Developer are Copyright (C) 2009-2011 + Portions created by the Initial Developer are Copyright (C) 2009-2012 the Initial Developer. All Rights Reserved. Contributor(s): @@ -327,9 +327,20 @@ namespace OpenHardwareMonitor.Hardware.HDD { out bytesReturned, IntPtr.Zero); return (isValid) ? result.Thresholds : new DriveThresholdValue[0]; - } + } - public string ReadName(IntPtr handle, int driveNumber) { + private string GetString(byte[] bytes) { + char[] chars = new char[bytes.Length]; + for (int i = 0; i < bytes.Length; i += 2) { + chars[i] = (char)bytes[i + 1]; + chars[i + 1] = (char)bytes[i]; + } + return new string(chars).Trim(new char[] { ' ', '\0' }); + } + + public bool ReadNameAndFirmwareRevision(IntPtr handle, int driveNumber, + out string name, out string firmwareRevision) + { DriveCommandParameter parameter = new DriveCommandParameter(); DriveIdentifyResult result; uint bytesReturned; @@ -342,19 +353,15 @@ namespace OpenHardwareMonitor.Hardware.HDD { out result, Marshal.SizeOf(typeof(DriveIdentifyResult)), out bytesReturned, IntPtr.Zero); - if (!valid) - return null; - else { - - byte[] bytes = result.Identify.ModelNumber; - char[] chars = new char[bytes.Length]; - for (int i = 0; i < bytes.Length; i += 2) { - chars[i] = (char)bytes[i + 1]; - chars[i + 1] = (char)bytes[i]; - } - - return new string(chars).Trim(new char[] {' ', '\0'}); + if (!valid) { + name = null; + firmwareRevision = null; + return false; } + + name = GetString(result.Identify.ModelNumber); + firmwareRevision = GetString(result.Identify.FirmwareRevision); + return true; } public void CloseHandle(IntPtr handle) {