wok-6.x view hardinfo/stuff/usb.patch @ rev 2793

Up: freetype (2.3.9) [security fix]
author Christophe Lincoln <pankso@slitaz.org>
date Tue Apr 28 15:36:15 2009 +0200 (2009-04-28)
parents
children
line source
1 --- util.c
2 +++ util.c
3 @@ -1048,3 +1048,55 @@
4 h_hash_table_remove_all_true,
5 NULL);
6 }
7 +
8 +gfloat
9 +h_sysfs_read_float(gchar *endpoint, gchar *entry)
10 +{
11 + gchar *tmp, *buffer;
12 + gfloat return_value = 0.0f;
13 +
14 + tmp = g_build_filename(endpoint, entry, NULL);
15 + if (g_file_get_contents(tmp, &buffer, NULL, NULL))
16 + return_value = atof(buffer);
17 +
18 + g_free(tmp);
19 + g_free(buffer);
20 +
21 + return return_value;
22 +}
23 +
24 +gint
25 +h_sysfs_read_int(gchar *endpoint, gchar *entry)
26 +{
27 + gchar *tmp, *buffer;
28 + gint return_value = 0.0f;
29 +
30 + tmp = g_build_filename(endpoint, entry, NULL);
31 + if (g_file_get_contents(tmp, &buffer, NULL, NULL))
32 + return_value = atoi(buffer);
33 +
34 + g_free(tmp);
35 + g_free(buffer);
36 +
37 + return return_value;
38 +}
39 +
40 +gchar *
41 +h_sysfs_read_string(gchar *endpoint, gchar *entry)
42 +{
43 + gchar *tmp, *return_value;
44 +
45 + tmp = g_build_filename(endpoint, entry, NULL);
46 + if (!g_file_get_contents(tmp, &return_value, NULL, NULL)) {
47 + g_free(return_value);
48 +
49 + return_value = NULL;
50 + } else {
51 + return_value = g_strstrip(return_value);
52 + }
53 +
54 + g_free(tmp);
55 +
56 + return return_value;
57 +}
58 +
60 --- arch/linux/common/usb.h
61 +++ arch/linux/common/usb.h
62 @@ -15,7 +15,6 @@
63 * along with this program; if not, write to the Free Software
64 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
65 */
66 -
67 static gboolean
68 remove_usb_devices(gpointer key, gpointer value, gpointer data)
69 {
70 @@ -23,8 +22,113 @@
71 }
73 static gchar *usb_list = NULL;
74 -void
75 -__scan_usb(void)
76 +
77 +void __scan_usb_sysfs_add_device(gchar * endpoint, int n)
78 +{
79 + gchar *manufacturer, *product, *mxpwr, *tmp, *strhash;
80 + gint bus, classid, vendor, prodid;
81 + gchar *version, *speed;
82 +
83 + classid = h_sysfs_read_int(endpoint, "bDeviceClass");
84 + vendor = h_sysfs_read_int(endpoint, "idVendor");
85 + prodid = h_sysfs_read_int(endpoint, "idProduct");
86 + bus = h_sysfs_read_int(endpoint, "busnum");
87 + if (!(speed = h_sysfs_read_string(endpoint, "speed"))) {
88 + speed = g_strdup("12");
89 + }
90 +
91 + if (!(version = h_sysfs_read_string(endpoint, "version"))) {
92 + version = g_strdup(" 1.0 ");
93 + }
94 +
95 + if (!(mxpwr = h_sysfs_read_string(endpoint, "bMaxPower"))) {
96 + mxpwr = g_strdup("0 mA");
97 + }
98 +
99 + if (!(manufacturer = h_sysfs_read_string(endpoint, "manufacturer"))) {
100 + manufacturer = g_strdup("Unknown");
101 + }
102 +
103 + if (!(product = h_sysfs_read_string(endpoint, "product"))) {
104 + if (classid == 9) {
105 + product = g_strdup_printf("USB %.2f Hub", version);
106 + } else {
107 + product = g_strdup_printf("Unknown USB %.2f Device (class %d)", version, classid);
108 + }
109 + }
110 +
111 + const gchar *url = vendor_get_url(manufacturer);
112 + if (url) {
113 + tmp = g_strdup_printf("%s (%s)", vendor_get_name(manufacturer), url);
114 +
115 + g_free(manufacturer);
116 + manufacturer = tmp;
117 + }
118 +
119 + tmp = g_strdup_printf("USB%d", n);
120 + usb_list = h_strdup_cprintf("$%s$%s=\n", usb_list, tmp, product);
121 +
122 + strhash = g_strdup_printf("[Device Information]\n"
123 + "Product=%s\n"
124 + "Manufacturer=%s\n"
125 + "Speed=%sMbit/s\n"
126 + "Max Current=%s\n"
127 + "[Misc]\n"
128 + "USB Version=%s\n"
129 + "Class=0x%x\n"
130 + "Vendor=0x%x\n"
131 + "Product ID=0x%x\n"
132 + "Bus=%d\n",
133 + product,
134 + manufacturer,
135 + speed,
136 + mxpwr,
137 + version, classid, vendor, prodid, bus);
138 +
139 + g_hash_table_insert(moreinfo, tmp, strhash);
140 +
141 + g_free(manufacturer);
142 + g_free(product);
143 + g_free(mxpwr);
144 + g_free(speed);
145 + g_free(version);
146 +}
147 +
148 +void __scan_usb_sysfs(void)
149 +{
150 + GDir *sysfs;
151 + gchar *filename;
152 + const gchar *sysfs_path = "/sys/class/usb_endpoint";
153 + gint usb_device_number = 0;
154 +
155 + if (!(sysfs = g_dir_open(sysfs_path, 0, NULL))) {
156 + return;
157 + }
158 +
159 + if (usb_list) {
160 + g_hash_table_foreach_remove(moreinfo, remove_usb_devices, NULL);
161 + g_free(usb_list);
162 + }
163 + usb_list = g_strdup("[USB Devices]\n");
164 +
165 + while ((filename = (gchar *) g_dir_read_name(sysfs))) {
166 + gchar *endpoint =
167 + g_build_filename(sysfs_path, filename, "device", NULL);
168 + gchar *temp;
169 +
170 + temp = g_build_filename(endpoint, "idVendor", NULL);
171 + if (g_file_test(temp, G_FILE_TEST_EXISTS)) {
172 + __scan_usb_sysfs_add_device(endpoint, ++usb_device_number);
173 + }
174 +
175 + g_free(temp);
176 + g_free(endpoint);
177 + }
178 +
179 + g_dir_close(sysfs);
180 +}
181 +
182 +int __scan_usb_procfs(void)
183 {
184 FILE *dev;
185 gchar buffer[128];
186 @@ -36,13 +140,13 @@
188 dev = fopen("/proc/bus/usb/devices", "r");
189 if (!dev)
190 - return;
191 + return 0;
193 if (usb_list) {
194 g_hash_table_foreach_remove(moreinfo, remove_usb_devices, NULL);
195 g_free(usb_list);
196 }
197 - usb_list = g_strdup("");
198 + usb_list = g_strdup("[USB Devices]\n");
200 while (fgets(buffer, 128, dev)) {
201 tmp = buffer;
202 @@ -73,52 +177,60 @@
203 mxpwr = strstr(buffer, "MxPwr=") + 6;
205 tmp = g_strdup_printf("USB%d", ++n);
206 -
207 +
208 if (*product == '\0') {
209 - g_free(product);
210 - if (classid == 9) {
211 - product = g_strdup_printf("USB %.2f Hub", ver);
212 - } else {
213 - product = g_strdup_printf("Unknown USB %.2f Device (class %d)",
214 - ver, classid);
215 - }
216 + g_free(product);
217 + if (classid == 9) {
218 + product = g_strdup_printf("USB %.2f Hub", ver);
219 + } else {
220 + product =
221 + g_strdup_printf
222 + ("Unknown USB %.2f Device (class %d)", ver,
223 + classid);
224 + }
225 }
226 -
227 +
229 if (classid == 9) { /* hub */
230 - usb_list = h_strdup_cprintf("[%s#%d]\n",
231 - usb_list, product, n);
232 - } else { /* everything else */
233 - usb_list = h_strdup_cprintf("$%s$%s=\n",
234 - usb_list, tmp, product);
235 -
236 - const gchar *url = vendor_get_url(manuf);
237 - if (url) {
238 - gchar *tmp = g_strdup_printf("%s (%s)", manuf, url);
239 - g_free(manuf);
240 - manuf = tmp;
241 - }
242 -
243 - gchar *strhash = g_strdup_printf("[Device Information]\n"
244 - "Product=%s\n"
245 - "Manufacturer=%s\n"
246 - "[Port #%d]\n"
247 - "Speed=%.2fMbit/s\n"
248 - "Max Current=%s\n"
249 - "[Misc]\n"
250 - "USB Version=%.2f\n"
251 - "Revision=%.2f\n"
252 - "Class=0x%x\n"
253 - "Vendor=0x%x\n"
254 - "Product ID=0x%x\n"
255 - "Bus=%d\n" "Level=%d\n",
256 - product, manuf,
257 - port, speed, mxpwr,
258 - ver, rev, classid,
259 - vendor, prodid, bus, level);
260 + usb_list = h_strdup_cprintf("[%s#%d]\n",
261 + usb_list, product, n);
262 + } else { /* everything else */
263 + usb_list = h_strdup_cprintf("$%s$%s=\n",
264 + usb_list, tmp, product);
265 +
266 + const gchar *url = vendor_get_url(manuf);
267 + if (url) {
268 + gchar *tmp =
269 + g_strdup_printf("%s (%s)", vendor_get_name(manuf),
270 + url);
271 + g_free(manuf);
272 + manuf = tmp;
273 + }
274 +
275 + gchar *strhash = g_strdup_printf("[Device Information]\n"
276 + "Product=%s\n",
277 + product);
278 + if (manuf && strlen(manuf))
279 + strhash = h_strdup_cprintf("Manufacturer=%s\n",
280 + strhash, manuf);
281 +
282 + strhash = h_strdup_cprintf("[Port #%d]\n"
283 + "Speed=%.2fMbit/s\n"
284 + "Max Current=%s\n"
285 + "[Misc]\n"
286 + "USB Version=%.2f\n"
287 + "Revision=%.2f\n"
288 + "Class=0x%x\n"
289 + "Vendor=0x%x\n"
290 + "Product ID=0x%x\n"
291 + "Bus=%d\n" "Level=%d\n",
292 + strhash,
293 + port, speed, mxpwr,
294 + ver, rev, classid,
295 + vendor, prodid, bus, level);
297 - g_hash_table_insert(moreinfo, tmp, strhash);
298 - }
299 + g_hash_table_insert(moreinfo, tmp, strhash);
300 + }
302 g_free(manuf);
303 g_free(product);
304 @@ -128,4 +240,12 @@
305 }
307 fclose(dev);
308 +
309 + return n;
310 +}
311 +
312 +void __scan_usb(void)
313 +{
314 + if (!__scan_usb_procfs())
315 + __scan_usb_sysfs();
316 }