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.

This commit is contained in:
Michael Möller
2012-01-01 10:14:42 +00:00
parent de089a3d28
commit a0b8e326eb
9 changed files with 65 additions and 43 deletions

View File

@@ -16,7 +16,7 @@
The Initial Developer of the Original Code is
Michael Möller <m.moeller@gmx.ch>.
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<SmartAttribute> smartAttributes;
private IDictionary<SmartAttribute, Sensor> sensors;
protected AbstractHarddrive(ISmart smart, string name, int index,
protected AbstractHarddrive(ISmart smart, string name,
string firmwareRevision, int index,
IEnumerable<SmartAttribute> 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}",

View File

@@ -16,7 +16,7 @@
The Initial Developer of the Original Code is
Michael Möller <m.moeller@gmx.ch>.
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) { }

View File

@@ -16,7 +16,7 @@
The Initial Developer of the Original Code is
Roland Reinl <roland-reinl@gmx.de>.
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) {}
}
}

View File

@@ -16,7 +16,7 @@
The Initial Developer of the Original Code is
Michael Möller <m.moeller@gmx.ch>.
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);

View File

@@ -16,7 +16,7 @@
The Initial Developer of the Original Code is
Roland Reinl <roland-reinl@gmx.de>.
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) {}
}
}

View File

@@ -16,7 +16,7 @@
The Initial Developer of the Original Code is
Michael Möller <m.moeller@gmx.ch>.
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) {}
}
}

View File

@@ -16,7 +16,7 @@
The Initial Developer of the Original Code is
Michael Möller <m.moeller@gmx.ch>.
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) {}
}
}

View File

@@ -16,7 +16,7 @@
The Initial Developer of the Original Code is
Michael Möller <m.moeller@gmx.ch>.
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)
{ }
}
}

View File

@@ -16,7 +16,7 @@
The Initial Developer of the Original Code is
Michael Möller <m.moeller@gmx.ch>.
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):
@@ -329,7 +329,18 @@ namespace OpenHardwareMonitor.Hardware.HDD {
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) {