From e73e09cc9c2f0fe2a1cda631f1518a4f549d2de8 Mon Sep 17 00:00:00 2001 From: Paul Werelds Date: Sat, 2 Oct 2010 14:39:25 +0000 Subject: [PATCH] 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. --- Hardware/HDD/HDDGroup.cs | 144 +++++++++++++++++++++++++++------------ 1 file changed, 99 insertions(+), 45 deletions(-) diff --git a/Hardware/HDD/HDDGroup.cs b/Hardware/HDD/HDDGroup.cs index 859236d..03f26b5 100644 --- a/Hardware/HDD/HDDGroup.cs +++ b/Hardware/HDD/HDDGroup.cs @@ -19,7 +19,7 @@ Portions created by the Initial Developer are Copyright (C) 2009-2010 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 either the GNU General Public License Version 2 or later (the "GPL"), or @@ -37,6 +37,7 @@ using System; using System.Collections.Generic; +using System.Text; namespace OpenHardwareMonitor.Hardware.HDD { internal class HDDGroup : IGroup { @@ -45,59 +46,56 @@ namespace OpenHardwareMonitor.Hardware.HDD { private readonly List hardware = new List(); + private readonly Dictionary ignoredDrives = new Dictionary(); + public HDDGroup(ISettings settings) { - int p = (int)Environment.OSVersion.Platform; - if ((p != 4) && (p != 128)) { - for (int drive = 0; drive < MAX_DRIVES; drive++) { - IntPtr handle = SMART.OpenPhysicalDrive(drive); + if (p == 4 || p == 128) return; - if (handle == SMART.INVALID_HANDLE_VALUE) - continue; + for (int drive = 0; drive < MAX_DRIVES; drive++) { + IntPtr handle = SMART.OpenPhysicalDrive(drive); - if (SMART.EnableSmart(handle, drive)) { + if (handle == SMART.INVALID_HANDLE_VALUE) + continue; - string name = SMART.ReadName(handle, drive); - if (name != null) { - - SMART.DriveAttribute[] attributes = - SMART.ReadSmart(handle, drive); - - if (attributes == null) - continue; - - int attribute = -1; - for (int i = 0; i < attributes.Length; i++) - if (attributes[i].ID == SMART.AttributeID.Temperature) { - attribute = i; - break; - } - if (attribute == -1) - 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) { - hardware.Add(new HDD(name, handle, drive, attribute, settings)); - 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) { + int attribute = -1; + + 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; + break; + } + i++; + } + + if (attribute >= 0) + { + hardware.Add(new HDD(name, handle, drive, attribute, settings)); + continue; + } + } + + SMART.CloseHandle(handle); } } - public IHardware[] Hardware { get { return hardware.ToArray(); @@ -105,7 +103,63 @@ namespace OpenHardwareMonitor.Hardware.HDD { } 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() {