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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
|
/*
* HardInfo - Displays System Information
* Copyright (C) 2003-2019 Leandro A. F. Pereira <leandro@hardinfo.org>
* Copyright (C) 2019 Burt P. <pburt0@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 2.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "hardinfo.h"
#include "devices.h"
#include "vendor.h"
gboolean no_handles = FALSE;
/* strings from dmidecode */
static const char empty_mem_str[] = "No Module Installed";
static const char unknown_mfgr_str[] = "<BAD INDEX>";
static const char mobo_location[] = "System Board Or Motherboard";
static const char mobo_shorter[] = "Mainboard";
static const unsigned long dta = 16; /* array */
static const unsigned long dtm = 17; /* socket */
#define UNKIFNULL2(f) ((f) ? f : _("(Unknown)"))
typedef struct {
unsigned long handle;
unsigned long array_handle;
gboolean populated;
gchar *locator;
gchar *full_locator;
gchar *size_str;
gchar *type;
gchar *type_detail;
gchar *array_locator;
gchar *bank_locator;
gchar *form_factor;
gchar *speed_str;
gchar *configured_clock_str;
gchar *voltage_min_str;
gchar *voltage_max_str;
gchar *voltage_conf_str;
gchar *partno;
gchar *data_width;
gchar *total_width;
gchar *mfgr;
const Vendor *vendor;
//TODO: gboolean spd_matched;
} dmi_mem;
dmi_mem *dmi_mem_new(unsigned long h) {
dmi_mem *s = g_new0(dmi_mem, 1);
s->handle = h;
s->locator = dmidecode_match("Locator", &dtm, &h);
s->size_str = dmidecode_match("Size", &dtm, &h);
s->bank_locator = dmidecode_match("Bank Locator", &dtm, &h);
gchar *ah = dmidecode_match("Array Handle", &dtm, &h);
if (ah) {
s->array_handle = strtol(ah, NULL, 16);
g_free(ah);
s->array_locator = dmidecode_match("Location", &dta, &s->array_handle);
if (g_str_has_prefix(s->array_locator, mobo_location)) {
g_free(s->array_locator);
s->array_locator = g_strdup(mobo_shorter);
}
}
gchar *h_str = g_strdup_printf("(0x%lx)", s->handle);
s->full_locator = g_strdup_printf("%s/%s",
s->array_locator ? s->array_locator : ".",
s->locator ? s->locator : h_str);
g_free(h_str);
if (!g_str_has_prefix(s->size_str, empty_mem_str)) {
s->populated = 1;
s->form_factor = dmidecode_match("Form Factor", &dtm, &h);
s->type = dmidecode_match("Type", &dtm, &h);
s->type_detail = dmidecode_match("Type Detail", &dtm, &h);
s->speed_str = dmidecode_match("Speed", &dtm, &h);
s->configured_clock_str = dmidecode_match("Configured Clock Speed", &dtm, &h);
if (!s->configured_clock_str)
s->configured_clock_str = dmidecode_match("Configured Memory Speed", &dtm, &h);
s->voltage_min_str = dmidecode_match("Minimum Voltage", &dtm, &h);
s->voltage_max_str = dmidecode_match("Maximum Voltage", &dtm, &h);
s->voltage_conf_str = dmidecode_match("Configured Voltage", &dtm, &h);
s->partno = dmidecode_match("Part Number", &dtm, &h);
s->data_width = dmidecode_match("Data Width", &dtm, &h);
s->total_width = dmidecode_match("Total Width", &dtm, &h);
s->mfgr = dmidecode_match("Manufacturer", &dtm, &h);
if (g_str_has_prefix(s->mfgr, unknown_mfgr_str)) {
/* the manufacturer code is unknown to dmidecode */
g_free(s->mfgr);
s->mfgr = NULL;
}
s->vendor = vendor_match(s->mfgr, NULL);
}
return s;
}
void dmi_mem_free(dmi_mem* s) {
if (s) {
g_free(s->locator);
g_free(s->full_locator);
g_free(s->size_str);
g_free(s->type);
g_free(s->type_detail);
g_free(s->bank_locator);
g_free(s->array_locator);
g_free(s->form_factor);
g_free(s->speed_str);
g_free(s->configured_clock_str);
g_free(s->voltage_min_str);
g_free(s->voltage_max_str);
g_free(s->voltage_conf_str);
g_free(s->partno);
g_free(s->data_width);
g_free(s->total_width);
g_free(s->mfgr);
g_free(s);
}
}
GSList *get_dmi_mem_list() {
GSList *ret = NULL;
dmi_handle_list *hlm = dmidecode_handles(&dtm);
if (hlm) {
unsigned long i = 0;
for(i = 0; i < hlm->count; i++) {
unsigned long h = hlm->handles[i];
ret = g_slist_append(ret, dmi_mem_new(h));
}
dmi_handle_list_free(hlm);
}
return ret;
}
gchar *dmi_mem_socket_info() {
gchar *ret = strdup("");
/* Arrays */
dmi_handle_list *hla = dmidecode_handles(&dta);
if (hla) {
unsigned long i = 0;
for(i = 0; i < hla->count; i++) {
unsigned long h = hla->handles[i];
gchar *array_locator = dmidecode_match("Location", &dta, &h);
gchar *array_use = dmidecode_match("Use", &dta, &h);
gchar *array_ecc = dmidecode_match("Error Correction Type", &dta, &h);
gchar *array_devs = dmidecode_match("Number Of Devices", &dta, &h);
if (g_str_has_prefix(array_locator, mobo_location)) {
g_free(array_locator);
array_locator = g_strdup(mobo_shorter);
}
gchar *array_max_size = dmidecode_match("Maximum Capacity", &dta, &h);
ret = h_strdup_cprintf("[%s %s]\n"
"%s=0x%x\n"
"%s=%s\n"
"%s=%s\n"
"%s=%s\n"
"%s=%s\n",
ret,
_("Memory Array"), array_locator ? array_locator : ".",
_("Array DMI Handle"), h,
_("Use"), UNKIFNULL2(array_use),
_("Error Correction Type"), UNKIFNULL2(array_ecc),
_("Max Size"), UNKIFNULL2(array_max_size),
_("Devices (Sockets)"), UNKIFNULL2(array_devs)
);
g_free(array_locator);
g_free(array_use);
g_free(array_ecc);
g_free(array_devs);
g_free(array_max_size);
}
dmi_handle_list_free(hla);
}
/* Sockets */
GSList *mems = get_dmi_mem_list();
GSList *l = mems;
for(; l; l = l->next) {
dmi_mem *s = (dmi_mem*)l->data;
if (s->populated) {
gchar *vendor_str = NULL;
if (s->vendor) {
if (s->vendor->url)
vendor_str = g_strdup_printf(" (%s, %s)",
s->vendor->name, s->vendor->url );
}
ret = h_strdup_cprintf("[%s %s]\n"
"%s=0x%lx, 0x%lx\n"
"%s=%s\n"
"%s=%s\n"
"%s=%s%s\n"
"%s=%s\n"
"%s=%s / %s\n"
"%s=%s\n"
"%s=%s\n"
"%s=%s\n"
"%s=%s / %s\n"
"%s=%s\n"
"%s=%s\n"
"%s=%s\n",
ret,
_("Memory Socket"), s->full_locator,
_("DMI Handles (Array, Socket)"), s->array_handle, s->handle,
_("Bank Locator"), UNKIFNULL2(s->bank_locator),
_("Form Factor"), UNKIFNULL2(s->form_factor),
_("Manufacturer"), UNKIFNULL2(s->mfgr), vendor_str ? vendor_str : "",
_("Part Number"), UNKIFNULL2(s->partno),
_("Type"), UNKIFNULL2(s->type), UNKIFNULL2(s->type_detail),
_("Size"), UNKIFNULL2(s->size_str),
_("Rated Speed"), UNKIFNULL2(s->speed_str),
_("Configured Speed"), UNKIFNULL2(s->configured_clock_str),
_("Data Width/Total Width"), UNKIFNULL2(s->data_width), UNKIFNULL2(s->total_width),
_("Minimum Voltage"), UNKIFNULL2(s->voltage_min_str),
_("Maximum Voltage"), UNKIFNULL2(s->voltage_max_str),
_("Configured Voltage"), UNKIFNULL2(s->voltage_conf_str)
);
g_free(vendor_str);
} else {
ret = h_strdup_cprintf("[%s %s]\n"
"%s=0x%x, 0x%x\n"
"%s=%s\n"
"%s=%s\n",
ret,
_("Memory Socket"), s->full_locator,
_("DMI Handles (Array, Socket)"), s->array_handle, s->handle,
_("Bank Locator"), UNKIFNULL2(s->bank_locator),
_("Size"), _("(Empty)")
);
}
}
no_handles = FALSE;
if(!mems) {
no_handles = TRUE;
ret = g_strdup_printf("[%s]\n%s=%s\n",
_("Socket Information"), _("Result"),
(getuid() == 0)
? _("(Not available)")
: _("(Not available; Perhaps try running HardInfo as root.)") );
}
g_slist_free_full(mems, (GDestroyNotify)dmi_mem_free);
return ret;
}
gboolean dmi_mem_show_hinote(const char **msg) {
if (no_handles) {
if (getuid() == 0) {
*msg = g_strdup(
_("To view DMI memory information the <b><i>dmidecode</i></b> utility must be\n"
"available."));
} else {
*msg = g_strdup(
_("To view DMI memory information the <b><i>dmidecode</i></b> utility must be\n"
"available, and HardInfo must be run with superuser privileges."));
}
return TRUE;
}
return FALSE;
}
|