Added a S.M.A.R.T dump for all drives, regardless of temperature presence so that we can start debugging SSD's and such.

This commit is contained in:
Paul Werelds
2010-10-02 14:39:25 +00:00
parent 9619107616
commit e73e09cc9c

View File

@@ -19,7 +19,7 @@
Portions created by the Initial Developer are Copyright (C) 2009-2010 Portions created by the Initial Developer are Copyright (C) 2009-2010
the Initial Developer. All Rights Reserved. the Initial Developer. All Rights Reserved.
Contributor(s): Contributor(s): Paul Werelds
Alternatively, the contents of this file may be used under the terms of Alternatively, the contents of this file may be used under the terms of
either the GNU General Public License Version 2 or later (the "GPL"), or either the GNU General Public License Version 2 or later (the "GPL"), or
@@ -37,6 +37,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text;
namespace OpenHardwareMonitor.Hardware.HDD { namespace OpenHardwareMonitor.Hardware.HDD {
internal class HDDGroup : IGroup { internal class HDDGroup : IGroup {
@@ -45,58 +46,55 @@ namespace OpenHardwareMonitor.Hardware.HDD {
private readonly List<HDD> hardware = new List<HDD>(); private readonly List<HDD> hardware = new List<HDD>();
public HDDGroup(ISettings settings) { private readonly Dictionary<string, SMART.DriveAttribute[]> ignoredDrives = new Dictionary<string, SMART.DriveAttribute[]>();
public HDDGroup(ISettings settings) {
int p = (int)Environment.OSVersion.Platform; int p = (int)Environment.OSVersion.Platform;
if ((p != 4) && (p != 128)) { if (p == 4 || p == 128) return;
for (int drive = 0; drive < MAX_DRIVES; drive++) { for (int drive = 0; drive < MAX_DRIVES; drive++) {
IntPtr handle = SMART.OpenPhysicalDrive(drive); IntPtr handle = SMART.OpenPhysicalDrive(drive);
if (handle == SMART.INVALID_HANDLE_VALUE) if (handle == SMART.INVALID_HANDLE_VALUE)
continue; continue;
if (SMART.EnableSmart(handle, drive)) { if (!SMART.EnableSmart(handle, drive)) {
SMART.CloseHandle(handle);
continue;
}
string name = SMART.ReadName(handle, drive); string name = SMART.ReadName(handle, drive);
if (name != null) { if (name == null) {
SMART.CloseHandle(handle);
SMART.DriveAttribute[] attributes =
SMART.ReadSmart(handle, drive);
if (attributes == null)
continue; continue;
}
SMART.DriveAttribute[] attributes = SMART.ReadSmart(handle, drive);
if (attributes != null) {
int attribute = -1; int attribute = -1;
for (int i = 0; i < attributes.Length; i++)
if (attributes[i].ID == SMART.AttributeID.Temperature) { int i = 0;
foreach (SMART.DriveAttribute attr in attributes) {
if (attr.ID == SMART.AttributeID.Temperature
|| attr.ID == SMART.AttributeID.DriveTemperature
|| attr.ID == SMART.AttributeID.AirflowTemperature) {
attribute = i; attribute = i;
break; break;
} }
if (attribute == -1) i++;
for (int i = 0; i < attributes.Length; i++)
if (attributes[i].ID == SMART.AttributeID.DriveTemperature) {
attribute = i;
break;
}
if (attribute == -1)
for (int i = 0; i < attributes.Length; i++)
if (attributes[i].ID == SMART.AttributeID.AirflowTemperature)
{
attribute = i;
break;
} }
if (attribute >= 0) { if (attribute >= 0)
{
hardware.Add(new HDD(name, handle, drive, attribute, settings)); hardware.Add(new HDD(name, handle, drive, attribute, settings));
continue; continue;
} }
} }
}
SMART.CloseHandle(handle); SMART.CloseHandle(handle);
} }
} }
}
public IHardware[] Hardware { public IHardware[] Hardware {
get { get {
@@ -105,7 +103,63 @@ namespace OpenHardwareMonitor.Hardware.HDD {
} }
public string GetReport() { public string GetReport() {
return null; int p = (int)Environment.OSVersion.Platform;
if (p == 4 || p == 128) return null;
StringBuilder r = new StringBuilder();
r.AppendLine("S.M.A.R.T Data");
r.AppendLine();
for (int drive = 0; drive < MAX_DRIVES; drive++) {
IntPtr handle = SMART.OpenPhysicalDrive(drive);
if (handle == SMART.INVALID_HANDLE_VALUE)
continue;
if (!SMART.EnableSmart(handle, drive)) {
SMART.CloseHandle(handle);
continue;
}
string name = SMART.ReadName(handle, drive);
if (name == null) {
SMART.CloseHandle(handle);
continue;
}
SMART.DriveAttribute[] attributes = SMART.ReadSmart(handle, drive);
if (attributes != null) {
r.AppendLine("Drive name: " + name);
r.AppendLine();
r.AppendFormat(" {0}{1}{2}{3}{4}{5}",
("ID").PadRight(6),
("RawValue").PadRight(20),
("WorstValue").PadRight(12),
("AttrValue").PadRight(12),
("Name"),
Environment.NewLine);
foreach (SMART.DriveAttribute attr in attributes) {
if (attr.ID == 0) continue;
string raw = BitConverter.ToString(attr.RawValue);
r.AppendFormat(" {0}{1}{2}{3}{4}{5}",
attr.ID.ToString("d").PadRight(6),
raw.Replace("-", " ").PadRight(20),
attr.WorstValue.ToString().PadRight(12),
attr.AttrValue.ToString().PadRight(12),
attr.ID,
Environment.NewLine)
;
}
r.AppendLine();
}
SMART.CloseHandle(handle);
}
return r.ToString();
} }
public void Close() { public void Close() {