# HG changeset patch # User moel.mich # Date 1325412882 0 # Node ID 4c31341a48007a626bbe61c9e7df4eac2b06e612 # Parent c6ee430d6995bcf4aa62ce460b4672269d457209 Added the hard drive firmware version to the report. This could be important if the SMART attribute layout changes with firmware versions on some drives. diff -r c6ee430d6995 -r 4c31341a4800 Hardware/HDD/AbstractHarddrive.cs --- a/Hardware/HDD/AbstractHarddrive.cs Sat Dec 31 17:31:04 2011 +0000 +++ b/Hardware/HDD/AbstractHarddrive.cs Sun Jan 01 10:14:42 2012 +0000 @@ -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 @@ typeof(GenericHarddisk) }; + private string firmwareRevision; private readonly ISmart smart; private readonly IntPtr handle; @@ -66,11 +67,13 @@ 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 @@ 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 @@ smart.CloseHandle(deviceHandle); - if (string.IsNullOrEmpty(name)) + if (!nameValid || string.IsNullOrEmpty(name)) return null; foreach (Type type in hddTypes) { @@ -136,8 +142,8 @@ // 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 @@ 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 -r c6ee430d6995 -r 4c31341a4800 Hardware/HDD/DebugSmart.cs --- a/Hardware/HDD/DebugSmart.cs Sat Dec 31 17:31:04 2011 +0000 +++ b/Hardware/HDD/DebugSmart.cs Sun Jan 01 10:14:42 2012 +0000 @@ -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 @@ 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 -r c6ee430d6995 -r 4c31341a4800 Hardware/HDD/HDDGeneric.cs --- a/Hardware/HDD/HDDGeneric.cs Sat Dec 31 17:31:04 2011 +0000 +++ b/Hardware/HDD/HDDGeneric.cs Sun Jan 01 10:14:42 2012 +0000 @@ -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 @@ 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 -r c6ee430d6995 -r 4c31341a4800 Hardware/HDD/ISmart.cs --- a/Hardware/HDD/ISmart.cs Sat Dec 31 17:31:04 2011 +0000 +++ b/Hardware/HDD/ISmart.cs Sun Jan 01 10:14:42 2012 +0000 @@ -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 @@ 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 -r c6ee430d6995 -r 4c31341a4800 Hardware/HDD/SSDIndilinx.cs --- a/Hardware/HDD/SSDIndilinx.cs Sat Dec 31 17:31:04 2011 +0000 +++ b/Hardware/HDD/SSDIndilinx.cs Sun Jan 01 10:14:42 2012 +0000 @@ -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 @@ 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 -r c6ee430d6995 -r 4c31341a4800 Hardware/HDD/SSDIntel.cs --- a/Hardware/HDD/SSDIntel.cs Sat Dec 31 17:31:04 2011 +0000 +++ b/Hardware/HDD/SSDIntel.cs Sun Jan 01 10:14:42 2012 +0000 @@ -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 @@ 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 -r c6ee430d6995 -r 4c31341a4800 Hardware/HDD/SSDPlextor.cs --- a/Hardware/HDD/SSDPlextor.cs Sat Dec 31 17:31:04 2011 +0000 +++ b/Hardware/HDD/SSDPlextor.cs Sun Jan 01 10:14:42 2012 +0000 @@ -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 @@ 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 -r c6ee430d6995 -r 4c31341a4800 Hardware/HDD/SSDSandforce.cs --- a/Hardware/HDD/SSDSandforce.cs Sat Dec 31 17:31:04 2011 +0000 +++ b/Hardware/HDD/SSDSandforce.cs Sun Jan 01 10:14:42 2012 +0000 @@ -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 @@ 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 -r c6ee430d6995 -r 4c31341a4800 Hardware/HDD/WindowsSmart.cs --- a/Hardware/HDD/WindowsSmart.cs Sat Dec 31 17:31:04 2011 +0000 +++ b/Hardware/HDD/WindowsSmart.cs Sun Jan 01 10:14:42 2012 +0000 @@ -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 @@ 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 @@ out result, Marshal.SizeOf(typeof(DriveIdentifyResult)), out bytesReturned, IntPtr.Zero); - if (!valid) - return null; - else { + if (!valid) { + name = null; + firmwareRevision = null; + return false; + } - 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'}); - } + name = GetString(result.Identify.ModelNumber); + firmwareRevision = GetString(result.Identify.FirmwareRevision); + return true; } public void CloseHandle(IntPtr handle) {