Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何理解MSStorage Driver_atapismart数据?_C#_Wmi - Fatal编程技术网

C# 如何理解MSStorage Driver_atapismart数据?

C# 如何理解MSStorage Driver_atapismart数据?,c#,wmi,C#,Wmi,我找到了以下用于处理硬盘S.M.A.R.T数据的代码。 请参阅: 微软公司 //作者:克莱门斯·瓦特斯(clemensv@microsoft.com) //以MS-PL为准的代码:http://opensource.org/licenses/ms-pl.html //智能属性和背景:http://en.wikipedia.org/wiki/S.M.A.R.T. //智能属性概述:http://www.t13.org/Documents/UploadedDocuments/docs2005/e0

我找到了以下用于处理硬盘S.M.A.R.T数据的代码。 请参阅:

微软公司 //作者:克莱门斯·瓦特斯(clemensv@microsoft.com) //以MS-PL为准的代码:http://opensource.org/licenses/ms-pl.html //智能属性和背景:http://en.wikipedia.org/wiki/S.M.A.R.T. //智能属性概述:http://www.t13.org/Documents/UploadedDocuments/docs2005/e05171r0-ACS-SMARTAttributes_Overview.pdf 命名空间SmartDataApp { 使用制度; 使用System.Collections.Generic; 使用制度管理; 使用System.Runtime.InteropServices; 公共枚举SmartAttributeType:字节 { ReadErrorRate=0x01, 吞吐量性能=0x02, 正常运行时间=0x03, StartStopCount=0x04, RealLocatedSectorScont=0x05, ReadChannelMargin=0x06, 参见Kerrorrate=0x07, 请参阅时间性能=0x08, 功率小时数POH=0x09, SpinRetryCount=0x0A, CalibrationRetryCount=0x0B, PowerCycleCount=0x0C, SoftReadErrorRate=0x0D, SATA降档错误计数=0xB7, EndtoEnderror=0xB8, 头部稳定性=0xB9, 诱导振动检测=0xBA, ReportedUncorrectableErrors=0xBB, CommandTimeout=0xBC, HighFlyWrites=0xBD, 气流温度WDC=0xBE, 温度差From100=0xBE, GSenseErrorRate=0xBF, POWERPOFRECTCOUNT=0xC0, LoadCycleCount=0xC1, 温度=0xC2, 硬件eCRecovered=0xC3, ReallocationEventCount=0xC4, CurrentPendingSectorCount=0xC5, 无法更正的扇区计数=0xC6, UltraDmacrErrorCount=0xC7, MultiZoneErrorRate=0xC8, WriteErrorRateFujitsu=0xC8, OffTrackSoftReadErrorRate=0xC9, DataAddressMarkerrors=0xCA, RunOutCancel=0xCB, SofteCcorrection=0xCC, Thermalaslapyratetar=0xCD, 飞行高度=0xCE, SpinHighCurrent=0xCF, SpinBuzz=0xD0, OfflineSeekPerformance=0xD1, 写入期间的振动=0xD3, 写入期间的冲击=0xD4, DiskShift=0xDC, GSenseErrorRateAlt=0xDD, LoadedHours=0xDE, LoadUnloadAddressCount=0xDF, 载荷摩擦力=0xE0, LoadUnloadCycleCount=0xE1, LoadInTime=0xE2, 扭矩放大计数=0xE3, 断电循环=0xE4, GMRHEADAMPLITE=0xE6, 驱动器温度=0xE7, 首飞小时=0xF0, TransferrRorratefujitsu=0xF0, 总写入量=0xF1, 总读取=0xF2, ReadErrorRetryRate=0xFA, 自由跌落保护=0xFE, } 公共类智能数据 { 只读字典属性; 只读ushort结构版本; 公共智能数据(字节[]arrVendorSpecific) { 属性=新字典(); 对于(int offset=2;offset// (c) Microsoft Corporation // Author: Clemens Vasters (clemensv@microsoft.com) // Code subject to MS-PL: http://opensource.org/licenses/ms-pl.html // SMART Attributes and Background: http://en.wikipedia.org/wiki/S.M.A.R.T. // SMART Attributes Overview: http://www.t13.org/Documents/UploadedDocuments/docs2005/e05171r0-ACS-SMARTAttributes_Overview.pdf namespace SmartDataApp { using System; using System.Collections.Generic; using System.Management; using System.Runtime.InteropServices; public enum SmartAttributeType : byte { ReadErrorRate = 0x01, ThroughputPerformance = 0x02, SpinUpTime = 0x03, StartStopCount = 0x04, ReallocatedSectorsCount = 0x05, ReadChannelMargin = 0x06, SeekErrorRate = 0x07, SeekTimePerformance = 0x08, PowerOnHoursPOH = 0x09, SpinRetryCount = 0x0A, CalibrationRetryCount = 0x0B, PowerCycleCount = 0x0C, SoftReadErrorRate = 0x0D, SATADownshiftErrorCount = 0xB7, EndtoEnderror = 0xB8, HeadStability = 0xB9, InducedOpVibrationDetection = 0xBA, ReportedUncorrectableErrors = 0xBB, CommandTimeout = 0xBC, HighFlyWrites = 0xBD, AirflowTemperatureWDC = 0xBE, TemperatureDifferencefrom100 = 0xBE, GSenseErrorRate = 0xBF, PoweroffRetractCount = 0xC0, LoadCycleCount = 0xC1, Temperature = 0xC2, HardwareECCRecovered = 0xC3, ReallocationEventCount = 0xC4, CurrentPendingSectorCount = 0xC5, UncorrectableSectorCount = 0xC6, UltraDMACRCErrorCount = 0xC7, MultiZoneErrorRate = 0xC8, WriteErrorRateFujitsu = 0xC8, OffTrackSoftReadErrorRate = 0xC9, DataAddressMarkerrors = 0xCA, RunOutCancel = 0xCB, SoftECCCorrection = 0xCC, ThermalAsperityRateTAR = 0xCD, FlyingHeight = 0xCE, SpinHighCurrent = 0xCF, SpinBuzz = 0xD0, OfflineSeekPerformance = 0xD1, VibrationDuringWrite = 0xD3, ShockDuringWrite = 0xD4, DiskShift = 0xDC, GSenseErrorRateAlt = 0xDD, LoadedHours = 0xDE, LoadUnloadRetryCount = 0xDF, LoadFriction = 0xE0, LoadUnloadCycleCount = 0xE1, LoadInTime = 0xE2, TorqueAmplificationCount = 0xE3, PowerOffRetractCycle = 0xE4, GMRHeadAmplitude = 0xE6, DriveTemperature = 0xE7, HeadFlyingHours = 0xF0, TransferErrorRateFujitsu = 0xF0, TotalLBAsWritten = 0xF1, TotalLBAsRead = 0xF2, ReadErrorRetryRate = 0xFA, FreeFallProtection = 0xFE, } public class SmartData { readonly Dictionary<SmartAttributeType, SmartAttribute> attributes; readonly ushort structureVersion; public SmartData(byte[] arrVendorSpecific) { attributes = new Dictionary<SmartAttributeType, SmartAttribute>(); for (int offset = 2; offset < arrVendorSpecific.Length; ) { var a = FromBytes<SmartAttribute>(arrVendorSpecific, ref offset, 12); // Attribute values 0x00, 0xfe, 0xff are invalid if (a.AttributeType != 0x00 && (byte)a.AttributeType != 0xfe && (byte)a.AttributeType != 0xff) { attributes[a.AttributeType] = a; } } structureVersion = (ushort)(arrVendorSpecific[0] * 256 + arrVendorSpecific[1]); } public ushort StructureVersion { get { return this.structureVersion; } } public SmartAttribute this[SmartAttributeType v] { get { return this.attributes[v]; } } public IEnumerable<SmartAttribute> Attributes { get { return this.attributes.Values; } } static T FromBytes<T>(byte[] bytearray, ref int offset, int count) { IntPtr ptr = IntPtr.Zero; try { ptr = Marshal.AllocHGlobal(count); Marshal.Copy(bytearray, offset, ptr, count); offset += count; return (T)Marshal.PtrToStructure(ptr, typeof(T)); } finally { if (ptr != IntPtr.Zero) { Marshal.FreeHGlobal(ptr); } } } } [StructLayout(LayoutKind.Sequential)] public struct SmartAttribute { public SmartAttributeType AttributeType; public ushort Flags; public byte Value; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] public byte[] VendorData; public bool Advisory { get { return (Flags & 0x1) == 0x0; // Bit 0 unset? } } public bool FailureImminent { get { return (Flags & 0x1) == 0x1; // Bit 0 set? } } public bool OnlineDataCollection { get { return (Flags & 0x2) == 0x2; // Bit 0 set? } } } public class Program { public static void Main() { try { var searcher = new ManagementObjectSearcher("root\\WMI", "SELECT * FROM MSStorageDriver_ATAPISmartData"); foreach (ManagementObject queryObj in searcher.Get()) { Console.WriteLine("-----------------------------------"); Console.WriteLine("MSStorageDriver_ATAPISmartData instance"); Console.WriteLine("-----------------------------------"); var arrVendorSpecific = (byte[])queryObj.GetPropertyValue("VendorSpecific"); // Create SMART data from 'vendor specific' array var d = new SmartData(arrVendorSpecific); foreach (var b in d.Attributes) { Console.Write("{0} :{1} : ", b.AttributeType, b.Value); foreach (byte vendorByte in b.VendorData) { Console.Write("{0:x} ", vendorByte); } Console.WriteLine(); } } } catch (ManagementException e) { Console.WriteLine("An error occurred while querying for WMI data: " + e.Message); } } } }