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
|
/*
* HardInfo - Displays System Information
* Copyright (C) 2003-2007 Leandro A. F. Pereira <leandro@hardinfo.org>
*
* 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
*/
/*
* DMI support based on patch by Stewart Adam <s.adam@diffingo.com>
*/
#include <unistd.h>
#include <sys/types.h>
#include "devices.h"
typedef struct _DMIInfo DMIInfo;
struct _DMIInfo {
const gchar *name;
const gchar *file; /* for sysfs */
const gchar *param; /* for dmidecode */
};
DMIInfo dmi_info_table[] = {
{ "$BIOS", NULL, NULL },
{ "Date", "/sys/class/dmi/id/bios_date", "bios-release-date" },
{ "Vendor", "/sys/class/dmi/id/bios_vendor", "bios-vendor" },
{ "Version#0", "/sys/class/dmi/id/bios_version", "bios-version" },
{ "$Board", NULL, NULL },
{ "Name", "/sys/class/dmi/id/board_name", "baseboard-product-name" },
{ "Vendor", "/sys/class/dmi/id/board_vendor", "baseboard-manufacturer" },
{ "$Product", NULL, NULL },
{ "Name", "/sys/class/dmi/id/product_name", "system-product-name" },
{ "Family", "/sys/class/dmi/id/product_family", "system-product-family" },
{ "Version#1", "/sys/class/dmi/id/product_version", "system-product-version" },
};
gchar *dmi_info = NULL;
static void add_to_moreinfo(const char *group, const char *key, char *value)
{
char *new_key = g_strconcat("DMI:", group, ":", key, NULL);
moreinfo_add_with_prefix("DEV", new_key, g_strdup(g_strstrip(value)));
}
gboolean dmi_get_info_dmidecode()
{
FILE *dmi_pipe;
gchar buffer[256];
const gchar *group;
DMIInfo *info;
gboolean dmi_failed = FALSE;
gint i;
if (dmi_info) {
g_free(dmi_info);
dmi_info = NULL;
}
for (i = 0; i < G_N_ELEMENTS(dmi_info_table); i++) {
info = &dmi_info_table[i];
if (*(info->name) == '$') {
group = info->name + 1;
dmi_info = h_strdup_cprintf("[%s]\n", dmi_info, group);
} else {
gchar *temp;
if (!info->param)
continue;
temp = g_strconcat("dmidecode -s ", info->param, NULL);
if ((dmi_pipe = popen(temp, "r"))) {
g_free(temp);
(void)fgets(buffer, 256, dmi_pipe);
if (pclose(dmi_pipe)) {
dmi_failed = TRUE;
break;
}
add_to_moreinfo(group, info->name, buffer);
const gchar *url = vendor_get_url(buffer);
if (url) {
const gchar *vendor = vendor_get_name(buffer);
if (g_strstr_len(vendor, -1, g_strstrip(buffer)) ||
g_strstr_len(g_strstrip(buffer), -1, vendor)) {
dmi_info = h_strdup_cprintf("%s=%s (%s)\n",
dmi_info,
info->name,
g_strstrip(buffer),
url);
} else {
dmi_info = h_strdup_cprintf("%s=%s (%s, %s)\n",
dmi_info,
info->name,
g_strstrip(buffer),
vendor, url);
}
} else {
dmi_info = h_strdup_cprintf("%s=%s\n",
dmi_info,
info->name,
buffer);
}
} else {
g_free(temp);
dmi_failed = TRUE;
break;
}
}
}
if (dmi_failed) {
g_free(dmi_info);
dmi_info = NULL;
}
return !dmi_failed;
}
gboolean dmi_get_info_sys()
{
FILE *dmi_file;
gchar buffer[256];
const gchar *group = NULL;
DMIInfo *info;
gboolean dmi_succeeded = FALSE;
gint i;
if (dmi_info) {
g_free(dmi_info);
dmi_info = NULL;
}
for (i = 0; i < G_N_ELEMENTS(dmi_info_table); i++) {
info = &dmi_info_table[i];
if (*(info->name) == '$') {
group = info->name + 1;
dmi_info = h_strdup_cprintf("[%s]\n", dmi_info, group);
} else if (group && info->file) {
if ((dmi_file = fopen(info->file, "r"))) {
(void)fgets(buffer, 256, dmi_file);
fclose(dmi_file);
add_to_moreinfo(group, info->name, buffer);
const gchar *url = vendor_get_url(buffer);
if (url) {
const gchar *vendor = vendor_get_name(buffer);
if (g_strstr_len(vendor, -1, g_strstrip(buffer)) ||
g_strstr_len(g_strstrip(buffer), -1, vendor)) {
dmi_info = h_strdup_cprintf("%s=%s (%s)\n",
dmi_info,
info->name,
g_strstrip(buffer),
url);
} else {
dmi_info = h_strdup_cprintf("%s=%s (%s, %s)\n",
dmi_info,
info->name,
g_strstrip(buffer),
vendor, url);
}
} else {
dmi_info = h_strdup_cprintf("%s=%s\n",
dmi_info,
info->name,
g_strstrip(buffer));
}
dmi_succeeded = TRUE;
} else {
dmi_info = h_strdup_cprintf("%s=%s\n",
dmi_info,
info->name,
_("(Not available; Perhaps try running HardInfo as root.)") );
}
}
}
if (!dmi_succeeded) {
g_free(dmi_info);
dmi_info = NULL;
}
return dmi_succeeded;
}
void __scan_dmi()
{
gboolean dmi_ok;
dmi_ok = dmi_get_info_sys();
if (!dmi_ok) {
dmi_ok = dmi_get_info_dmidecode();
}
if (!dmi_ok) {
dmi_info = g_strdup("[No DMI information]\n"
"There was an error retrieving the information.=\n"
"Please try running HardInfo as root.=\n");
}
}
|