forked from hiyohiyo/CrystalDiskInfo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NVMeInterpreter.cpp
170 lines (152 loc) · 5.35 KB
/
NVMeInterpreter.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*---------------------------------------------------------------------------*/
// Author : Minkyu Kim
// Web : http://naraeon.net/
// https://github.com/ebangin127/
// License : MIT License
/*---------------------------------------------------------------------------*/
#include "StdAfx.h"
#include "nvmeinterpreter.h"
void AddToATASmartBuf(SMART_ATTRIBUTE_LIST* ATASmartBuf, INT IdxInBuf, SMART_ATTRIBUTE AttrToAdd)
{
(*ATASmartBuf)[IdxInBuf] = AttrToAdd;
}
SMART_ATTRIBUTE SeperateCriticalWarningFrom(UCHAR* NVMeSmartBuf)
{
SMART_ATTRIBUTE attr = {};
attr.Id = 1;
attr.RawValue[0] = NVMeSmartBuf[0];
return attr;
}
SMART_ATTRIBUTE SeperateTemperatureFrom(UCHAR* NVMeSmartBuf)
{
const int TemperatureStart = 1;
SMART_ATTRIBUTE attr = {};
attr.Id = 2;
attr.RawValue[0] = NVMeSmartBuf[TemperatureStart];
attr.RawValue[1] = NVMeSmartBuf[TemperatureStart + 1];
return attr;
}
SMART_ATTRIBUTE SeperateAvailableSpareFrom(UCHAR* NVMeSmartBuf)
{
const int AvailableSpareStart = 3;
SMART_ATTRIBUTE attr = {};
attr.Id = 3;
attr.RawValue[0] = NVMeSmartBuf[AvailableSpareStart];
return attr;
}
SMART_ATTRIBUTE SeperateAvailableSpareThresholdFrom(UCHAR* NVMeSmartBuf)
{
const int AvailableSpareThresholdStart = 4;
SMART_ATTRIBUTE attr = {};
attr.Id = 4;
attr.RawValue[0] = NVMeSmartBuf[AvailableSpareThresholdStart];
return attr;
}
SMART_ATTRIBUTE SeperatePercentageUsedFrom(UCHAR* NVMeSmartBuf)
{
const int PercentageUsedStart = 5;
SMART_ATTRIBUTE attr = {};
attr.Id = 5;
attr.RawValue[0] = NVMeSmartBuf[PercentageUsedStart];
return attr;
}
SMART_ATTRIBUTE SeperateDataUnitsReadFrom(UCHAR* NVMeSmartBuf)
{
const int DataUnitsReadStart = 32;
SMART_ATTRIBUTE attr = {};
attr.Id = 6;
memcpy(attr.RawValue, &NVMeSmartBuf[DataUnitsReadStart], sizeof(attr.RawValue));
return attr;
}
SMART_ATTRIBUTE SeperateDataUnitsWrittenFrom(UCHAR* NVMeSmartBuf)
{
const int DataUnitsWrittenStart = 48;
SMART_ATTRIBUTE attr = {};
attr.Id = 7;
memcpy(attr.RawValue, &NVMeSmartBuf[DataUnitsWrittenStart], sizeof(attr.RawValue));
return attr;
}
SMART_ATTRIBUTE SeperateHostReadCommandsFrom(UCHAR* NVMeSmartBuf)
{
const int ReadStart = 64;
SMART_ATTRIBUTE attr = {};
attr.Id = 8;
memcpy(attr.RawValue, &NVMeSmartBuf[ReadStart], sizeof(attr.RawValue));
return attr;
}
SMART_ATTRIBUTE SeperateHostWriteCommandsFrom(UCHAR* NVMeSmartBuf)
{
const int WriteStart = 80;
SMART_ATTRIBUTE attr = {};
attr.Id = 9;
memcpy(attr.RawValue, &NVMeSmartBuf[WriteStart], sizeof(attr.RawValue));
return attr;
}
SMART_ATTRIBUTE SeperateControllerBusyTimeFrom(UCHAR* NVMeSmartBuf)
{
const int BusyTimeStart = 96;
SMART_ATTRIBUTE attr = {};
attr.Id = 10;
memcpy(attr.RawValue, &NVMeSmartBuf[BusyTimeStart], sizeof(attr.RawValue));
return attr;
}
SMART_ATTRIBUTE SeperatePowerCyclesFrom(UCHAR* NVMeSmartBuf)
{
const int PowerCycleStart = 112;
SMART_ATTRIBUTE attr = {};
attr.Id = 11;
memcpy(attr.RawValue, &NVMeSmartBuf[PowerCycleStart], sizeof(attr.RawValue));
return attr;
}
SMART_ATTRIBUTE SeperatePowerOnHoursFrom(UCHAR* NVMeSmartBuf)
{
const int PowerOnHoursStart = 128;
SMART_ATTRIBUTE attr = {};
attr.Id = 12;
memcpy(attr.RawValue, &NVMeSmartBuf[PowerOnHoursStart], sizeof(attr.RawValue));
return attr;
}
SMART_ATTRIBUTE SeperateUnsafeShutdownsFrom(UCHAR* NVMeSmartBuf)
{
const int UnsafeShutdownsStart = 144;
SMART_ATTRIBUTE attr = {};
attr.Id = 13;
memcpy(attr.RawValue, &NVMeSmartBuf[UnsafeShutdownsStart], sizeof(attr.RawValue));
return attr;
}
SMART_ATTRIBUTE SeperateMediaErrorsFrom(UCHAR* NVMeSmartBuf)
{
const int MediaErrorsStart = 160;
SMART_ATTRIBUTE attr = {};
attr.Id = 14;
memcpy(attr.RawValue, &NVMeSmartBuf[MediaErrorsStart], sizeof(attr.RawValue));
return attr;
}
SMART_ATTRIBUTE SeperateNumberOfErrorsFrom(UCHAR* NVMeSmartBuf)
{
const int NumberOfErrorsStart = 176;
SMART_ATTRIBUTE attr = {};
attr.Id = 15;
memcpy(attr.RawValue, &NVMeSmartBuf[NumberOfErrorsStart], sizeof(attr.RawValue));
return attr;
}
void NVMeSmartToATASmart(UCHAR* NVMeSmartBuf, void* ATASmartBufUncasted)
{
SMART_ATTRIBUTE_LIST* ATASmartBuf = (SMART_ATTRIBUTE_LIST*) ATASmartBufUncasted;
int IdxInBuf = 0;
AddToATASmartBuf(ATASmartBuf, IdxInBuf++, SeperateCriticalWarningFrom(NVMeSmartBuf));
AddToATASmartBuf(ATASmartBuf, IdxInBuf++, SeperateTemperatureFrom(NVMeSmartBuf));
AddToATASmartBuf(ATASmartBuf, IdxInBuf++, SeperateAvailableSpareFrom(NVMeSmartBuf));
AddToATASmartBuf(ATASmartBuf, IdxInBuf++, SeperateAvailableSpareThresholdFrom(NVMeSmartBuf));
AddToATASmartBuf(ATASmartBuf, IdxInBuf++, SeperatePercentageUsedFrom(NVMeSmartBuf));
AddToATASmartBuf(ATASmartBuf, IdxInBuf++, SeperateDataUnitsReadFrom(NVMeSmartBuf));
AddToATASmartBuf(ATASmartBuf, IdxInBuf++, SeperateDataUnitsWrittenFrom(NVMeSmartBuf));
AddToATASmartBuf(ATASmartBuf, IdxInBuf++, SeperateHostReadCommandsFrom(NVMeSmartBuf));
AddToATASmartBuf(ATASmartBuf, IdxInBuf++, SeperateHostWriteCommandsFrom(NVMeSmartBuf));
AddToATASmartBuf(ATASmartBuf, IdxInBuf++, SeperateControllerBusyTimeFrom(NVMeSmartBuf));
AddToATASmartBuf(ATASmartBuf, IdxInBuf++, SeperatePowerCyclesFrom(NVMeSmartBuf));
AddToATASmartBuf(ATASmartBuf, IdxInBuf++, SeperatePowerOnHoursFrom(NVMeSmartBuf));
AddToATASmartBuf(ATASmartBuf, IdxInBuf++, SeperateUnsafeShutdownsFrom(NVMeSmartBuf));
AddToATASmartBuf(ATASmartBuf, IdxInBuf++, SeperateMediaErrorsFrom(NVMeSmartBuf));
AddToATASmartBuf(ATASmartBuf, IdxInBuf++, SeperateNumberOfErrorsFrom(NVMeSmartBuf));
}