]> git.ipfire.org Git - ipfire-2.x.git/blame - src/hwinfo/hwinfo.c
Signierten GPG-Schluessel importiert.
[ipfire-2.x.git] / src / hwinfo / hwinfo.c
CommitLineData
93afd047
MT
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include <unistd.h>
5#include <fcntl.h>
6#include <getopt.h>
7#include <errno.h>
8#include <sys/types.h>
9#include <sys/stat.h>
10
11#include "hd.h"
12#include "hd_int.h"
13
14static int get_probe_flags(int, char **, hd_data_t *);
15static void progress2(char *, char *);
16
17// ##### temporary solution, fix it later!
18str_list_t *read_file(char *file_name, unsigned start_line, unsigned lines);
19str_list_t *search_str_list(str_list_t *sl, char *str);
20str_list_t *add_str_list(str_list_t **sl, char *str);
21char *new_str(const char *);
22
23static unsigned deb = 0;
24static char *log_file = "";
25static char *list = NULL;
26static int listplus = 0;
27
28static int test = 0;
29static int is_short = 0;
30
31static char *showconfig = NULL;
32static char *saveconfig = NULL;
33static hd_hw_item_t hw_item[100] = { };
34static int hw_items = 0;
35
36int braille_install_info(hd_data_t *hd_data);
37int x11_install_info(hd_data_t *hd_data);
38int oem_install_info(hd_data_t *hd_data);
39void dump_packages(hd_data_t *hd_data);
40
41void do_hw(hd_data_t *hd_data, FILE *f, hd_hw_item_t hw_item);
42void do_hw_multi(hd_data_t *hd_data, FILE *f, hd_hw_item_t *hw_items);
43void do_short(hd_data_t *hd_data, hd_t *hd, FILE *f);
44void do_test(hd_data_t *hd_data);
45void help(void);
46void dump_db_raw(hd_data_t *hd_data);
47void dump_db(hd_data_t *hd_data);
48void do_chroot(hd_data_t *hd_data, char *dir);
49void ask_db(hd_data_t *hd_data, char *query);
50void get_mapping(hd_data_t *hd_data);
51
52
53struct {
54 unsigned db_idx;
55 unsigned separate:1;
56 char *root;
57} opt;
58
59struct option options[] = {
60 { "special", 1, NULL, 1 },
61 { "help", 0, NULL, 'h' },
62 { "debug", 1, NULL, 'd' },
63 { "version", 0, NULL, 400 },
64 { "log", 1, NULL, 'l' },
65 { "packages", 0, NULL, 'p' },
66 { "test", 0, NULL, 300 },
67 { "format", 1, NULL, 301 },
68 { "show-config", 1, NULL, 302 },
69 { "save-config", 1, NULL, 303 },
70 { "short", 0, NULL, 304 },
71 { "fast", 0, NULL, 305 },
72 { "dump-db", 1, NULL, 306 },
73 { "dump-db-raw", 1, NULL, 307 },
74 { "separate", 0, NULL, 308 },
75 { "root", 1, NULL, 309 },
76 { "db", 1, NULL, 310 },
77 { "only", 1, NULL, 311 },
78 { "listmd", 0, NULL, 312 },
79 { "map", 0, NULL, 313 },
80 { "kernel-version", 1, NULL, 314 },
81 { "cdrom", 0, NULL, 1000 + hw_cdrom },
82 { "floppy", 0, NULL, 1000 + hw_floppy },
83 { "disk", 0, NULL, 1000 + hw_disk },
84 { "network", 0, NULL, 1000 + hw_network },
85 { "display", 0, NULL, 1000 + hw_display },
86 { "gfxcard", 0, NULL, 1000 + hw_display },
87 { "framebuffer", 0, NULL, 1000 + hw_framebuffer },
88 { "monitor", 0, NULL, 1000 + hw_monitor },
89 { "camera", 0, NULL, 1000 + hw_camera },
90 { "mouse", 0, NULL, 1000 + hw_mouse },
91 { "joystick", 0, NULL, 1000 + hw_joystick },
92 { "keyboard", 0, NULL, 1000 + hw_keyboard },
93 { "chipcard", 0, NULL, 1000 + hw_chipcard },
94 { "sound", 0, NULL, 1000 + hw_sound },
95 { "isdn", 0, NULL, 1000 + hw_isdn },
96 { "modem", 0, NULL, 1000 + hw_modem },
97 { "storage-ctrl", 0, NULL, 1000 + hw_storage_ctrl },
98 { "storage_ctrl", 0, NULL, 1000 + hw_storage_ctrl },
99 { "netcard", 0, NULL, 1000 + hw_network_ctrl },
100 { "netcards", 0, NULL, 1000 + hw_network_ctrl }, // outdated, just kept for comaptibility
101 { "network-ctrl", 0, NULL, 1000 + hw_network_ctrl },
102 { "network_ctrl", 0, NULL, 1000 + hw_network_ctrl },
103 { "printer", 0, NULL, 1000 + hw_printer },
104 { "tv", 0, NULL, 1000 + hw_tv },
105 { "dvb", 0, NULL, 1000 + hw_dvb },
106 { "scanner", 0, NULL, 1000 + hw_scanner },
107 { "braille", 0, NULL, 1000 + hw_braille },
108 { "sys", 0, NULL, 1000 + hw_sys },
109 { "bios", 0, NULL, 1000 + hw_bios },
110 { "cpu", 0, NULL, 1000 + hw_cpu },
111 { "partition", 0, NULL, 1000 + hw_partition },
112 { "usb-ctrl", 0, NULL, 1000 + hw_usb_ctrl },
113 { "usb_ctrl", 0, NULL, 1000 + hw_usb_ctrl },
114 { "usb", 0, NULL, 1000 + hw_usb },
115 { "pci", 0, NULL, 1000 + hw_pci },
116 { "isapnp", 0, NULL, 1000 + hw_isapnp },
117 { "scsi", 0, NULL, 1000 + hw_scsi },
118 { "ide", 0, NULL, 1000 + hw_ide },
119 { "bridge", 0, NULL, 1000 + hw_bridge },
120 { "hub", 0, NULL, 1000 + hw_hub },
121 { "memory", 0, NULL, 1000 + hw_memory },
122 { "manual", 0, NULL, 1000 + hw_manual },
123 { "pcmcia", 0, NULL, 1000 + hw_pcmcia },
124 { "pcmcia_ctrl", 0, NULL, 1000 + hw_pcmcia_ctrl },
125 { "ieee1394", 0, NULL, 1000 + hw_ieee1394 },
126 { "ieee1394_ctrl", 0, NULL, 1000 + hw_ieee1394_ctrl },
127 { "firewire", 0, NULL, 1000 + hw_ieee1394 },
128 { "firewire_ctrl", 0, NULL, 1000 + hw_ieee1394_ctrl },
129 { "hotplug", 0, NULL, 1000 + hw_hotplug },
130 { "hotplug_ctrl", 0, NULL, 1000 + hw_hotplug_ctrl },
131 { "zip", 0, NULL, 1000 + hw_zip },
132 { "pppoe", 0, NULL, 1000 + hw_pppoe },
133 { "dsl", 0, NULL, 1000 + hw_dsl },
134 { "wlan", 0, NULL, 1000 + hw_wlan },
135 { "redasd", 0, NULL, 1000 + hw_redasd },
136 { "block", 0, NULL, 1000 + hw_block },
137 { "tape", 0, NULL, 1000 + hw_tape },
138 { "vbe", 0, NULL, 1000 + hw_vbe },
139 { "bluetooth", 0, NULL, 1000 + hw_bluetooth },
140 { "all", 0, NULL, 2000 },
141 { "reallyall", 0, NULL, 2001 },
142 { "smp", 0, NULL, 2002 },
143 { "arch", 0, NULL, 2003 },
144 { "uml", 0, NULL, 2004 },
145 { }
146};
147
148
149/*
150 * Just scan the hardware and dump all info.
151 */
152int main(int argc, char **argv)
153{
154 hd_data_t *hd_data;
155 hd_t *hd;
156 FILE *f = NULL;
157 int i;
158 unsigned first_probe = 1;
159
160 hd_data = calloc(1, sizeof *hd_data);
161 hd_data->progress = isatty(1) ? progress2 : NULL;
162 hd_data->debug=~(HD_DEB_DRIVER_INFO | HD_DEB_HDDB);
163
164 for(i = 0; i < argc; i++) {
165 if(strstr(argv[i], "--") == argv[i]) break;
166 }
167
168 if(i != argc) {
169 /* new style interface */
170
171 opterr = 0;
172
173 while((i = getopt_long(argc, argv, "hd:l:p", options, NULL)) != -1) {
174 switch(i) {
175 case 1:
176 if(!strcmp(optarg, "braille")) {
177 braille_install_info(hd_data);
178 }
179 else if(!strcmp(optarg, "x11")) {
180 x11_install_info(hd_data);
181 }
182 else if(!strcmp(optarg, "oem")) {
183 oem_install_info(hd_data);
184 }
185 else {
186 help();
187 return 1;
188 }
189 break;
190
191 case 'd':
192 hd_data->debug = strtol(optarg, NULL, 0);
193 break;
194
195 case 'l':
196 log_file = optarg;
197 break;
198
199 case 'p':
200 dump_packages(hd_data);
201 break;
202
203 case 300:
204 do_test(hd_data);
205 break;
206
207 case 301:
208 hd_data->flags.dformat = strtol(optarg, NULL, 0);
209 break;
210
211 case 302:
212 showconfig = optarg;
213 break;
214
215 case 303:
216 saveconfig = optarg;
217 break;
218
219 case 304:
220 is_short = 1;
221 break;
222
223 case 305:
224 hd_data->flags.fast = 1;
225 break;
226
227 case 306:
228 opt.db_idx = strtoul(optarg, NULL, 0);
229 dump_db(hd_data);
230 break;
231
232 case 307:
233 opt.db_idx = strtoul(optarg, NULL, 0);
234 dump_db_raw(hd_data);
235 break;
236
237 case 308:
238 /* basically for debugging */
239 opt.separate = 1;
240 break;
241
242 case 309:
243 opt.root = optarg;
244 break;
245
246 case 310:
247 ask_db(hd_data, optarg);
248 break;
249
250 case 311:
251 if(*optarg) add_str_list(&hd_data->only, optarg);
252 break;
253
254 case 312:
255 hd_data->flags.list_md = 1;
256 break;
257
258 case 313:
259 get_mapping(hd_data);
260 break;
261
262 case 314:
263 if(*optarg) setenv("LIBHD_KERNELVERSION", optarg, 1);
264 break;
265
266 case 400:
267 printf("%s\n", hd_version());
268 break;
269
270 case 1000 ... 1100:
271 if(hw_items < (int) (sizeof hw_item / sizeof *hw_item) - 1)
272 hw_item[hw_items++] = i - 1000;
273 break;
274
275 case 2000:
276 case 2001:
277 case 2002:
278 case 2003:
279 case 2004:
280 if(hw_items < (int) (sizeof hw_item / sizeof *hw_item) - 1)
281 hw_item[hw_items++] = i;
282 break;
283
284 default:
285 help();
286 return 0;
287 }
288 }
289
290 if(!hw_items && is_short) hw_item[hw_items++] = 2000; /* all */
291
292 if(hw_items >= 0 || showconfig || saveconfig) {
293 if(*log_file) {
294 if(!strcmp(log_file, "-")) {
295 f = fdopen(1, "w");
296 }
297 else {
298 f = fopen(log_file, "w+");
299 }
300 }
301
302 if(opt.root) do_chroot(hd_data, opt.root);
303
304 if(opt.separate || hw_items <= 1) {
305 for(i = 0; i < hw_items; i++) {
306 if(i) fputc('\n', f ? f : stdout);
307 do_hw(hd_data, f, hw_item[i]);
308 }
309 }
310 else {
311 hw_item[hw_items] = 0;
312 do_hw_multi(hd_data, f, hw_item);
313 }
314
315#ifndef LIBHD_TINY
316 if(showconfig) {
317 hd = hd_read_config(hd_data, showconfig);
318 if(hd) {
319 hd_dump_entry(hd_data, hd, f ? f : stdout);
320 hd = hd_free_hd_list(hd);
321 }
322 else {
323 fprintf(f ? f : stdout, "No config data: %s\n", showconfig);
324 }
325 }
326
327 if(saveconfig) {
328 for(hd = hd_data->hd; hd; hd = hd->next) {
329 if(!strcmp(hd->unique_id, saveconfig)) {
330 i = hd_write_config(hd_data, hd);
331 fprintf(f ? f : stdout, "%s: %s\n",
332 saveconfig,
333 i ? "Error writing config data" : "config saved"
334 );
335 break;
336 }
337 }
338 if(!hd) {
339 fprintf(f ? f : stdout, "No such hardware: %s\n", saveconfig);
340 }
341 }
342#endif
343
344 if(f) fclose(f);
345 }
346
347 hd_free_hd_data(hd_data);
348 free(hd_data);
349
350 return 0;
351 }
352
353 /* old style interface */
354
355 argc--; argv++;
356
357 if(argc == 1 && !strcmp(*argv, "-h")) {
358 help();
359 return 0;
360 }
361
362 do {
363 if(first_probe) /* only for the 1st probing */
364 hd_set_probe_feature(hd_data, pr_default);
365 else {
366 hd_clear_probe_feature(hd_data, pr_all);
367 }
368
369 if((i = get_probe_flags(argc, argv, hd_data)) < 0) return 1;
370 deb = hd_data->debug;
371 argc -= i; argv += i;
372
373 if(opt.root && first_probe) do_chroot(hd_data, opt.root);
374
375 hd_scan(hd_data);
376 if(hd_data->progress) printf("\r%64s\r", "");
377
378 first_probe = 0;
379 } while(argc);
380
381 if(*log_file) {
382 if(!strcmp(log_file, "-")) {
383 f = fdopen(1, "w");
384 }
385 else {
386 f = fopen(log_file, "w+");
387 }
388 }
389
390 if((hd_data->debug & HD_DEB_SHOW_LOG) && hd_data->log) {
391 if(*log_file) {
392 fprintf(f ? f : stdout,
393 "============ start hardware log ============\n"
394 );
395 }
396 fprintf(f ? f : stdout,
397 "============ start debug info ============\n%s=========== end debug info ============\n",
398 hd_data->log
399 );
400 }
401
402 for(hd = hd_data->hd; hd; hd = hd->next) {
403 hd_dump_entry(hd_data, hd, f ? f : stdout);
404 }
405
406 if(*log_file) {
407 fprintf(f ? f : stdout,
408 "============ end hardware log ============\n"
409 );
410 }
411
412 i = -1;
413 if(list) {
414 if(!strcmp(list, "cdrom")) i = hw_cdrom;
415 if(!strcmp(list, "disk")) i = hw_disk;
416 if(!strcmp(list, "floppy")) i = hw_floppy;
417 if(!strcmp(list, "network")) i = hw_network;
418 if(!strcmp(list, "display")) i = hw_display;
419 if(!strcmp(list, "monitor")) i = hw_monitor;
420 if(!strcmp(list, "mouse")) i = hw_mouse;
421 if(!strcmp(list, "keyboard")) i = hw_keyboard;
422 if(!strcmp(list, "sound")) i = hw_sound;
423 if(!strcmp(list, "isdn")) i = hw_isdn;
424 if(!strcmp(list, "dsl")) i = hw_dsl;
425 if(!strcmp(list, "modem")) i = hw_modem;
426 if(!strcmp(list, "storage_ctrl")) i = hw_storage_ctrl;
427 if(!strcmp(list, "network_ctrl")) i = hw_network_ctrl;
428 if(!strcmp(list, "netcards")) i = hw_network_ctrl;
429 if(!strcmp(list, "printer")) i = hw_printer;
430 if(!strcmp(list, "tv")) i = hw_tv;
431 if(!strcmp(list, "scanner")) i = hw_scanner;
432 if(!strcmp(list, "braille")) i = hw_braille;
433 if(!strcmp(list, "sys")) i = hw_sys;
434 if(!strcmp(list, "cpu")) i = hw_cpu;
435
436 if(i >= 0) {
437 hd = hd_list(hd_data, i, listplus, NULL);
438 printf("\n");
439 printf("-- %s list --\n", list);
440 for(; hd; hd = hd->next) hd_dump_entry(hd_data, hd, stdout);
441 printf("-- %s list end --\n", list);
442 hd = hd_free_hd_list(hd);
443 }
444 }
445
446 if(f) fclose(f);
447
448 hd_free_hd_data(hd_data);
449 free(hd_data);
450
451 return 0;
452}
453
454
455void do_hw(hd_data_t *hd_data, FILE *f, hd_hw_item_t hw_item)
456{
457 hd_t *hd, *hd0;
458 int smp = -1, uml = 0, i;
459 char *s, *t;
460 enum boot_arch b_arch;
461 enum cpu_arch c_arch;
462
463 hd0 = NULL;
464
465 switch(hw_item) {
466 case 2002:
467 smp = hd_smp_support(hd_data);
468 break;
469
470 case 2000:
471 case 2001:
472 case 2003:
473 i = -1;
474 switch((int) hw_item) {
475 case 2000: i = pr_default; break;
476 case 2001: i = pr_all; break;
477 case 2003: i = pr_cpu; break;
478 }
479 if(i != -1) {
480 hd_clear_probe_feature(hd_data, pr_all);
481 hd_set_probe_feature(hd_data, i);
482 hd_scan(hd_data);
483 hd0 = hd_data->hd;
484 }
485 break;
486
487 case 2004:
488 uml = hd_is_uml(hd_data);
489 break;
490
491 default:
492 hd0 = hd_list(hd_data, hw_item, 1, NULL);
493 }
494
495 if(hd_data->progress) {
496 printf("\r%64s\r", "");
497 fflush(stdout);
498 }
499
500 if(f) {
501 if((hd_data->debug & HD_DEB_SHOW_LOG) && hd_data->log) {
502 fprintf(f,
503 "============ start hardware log ============\n"
504 );
505 fprintf(f,
506 "============ start debug info ============\n%s=========== end debug info ============\n",
507 hd_data->log
508 );
509 }
510
511 for(hd = hd_data->hd; hd; hd = hd->next) {
512 hd_dump_entry(hd_data, hd, f);
513 }
514
515 fprintf(f,
516 "============ end hardware log ============\n"
517 );
518 }
519
520 if(hw_item == 2002) {
521 fprintf(f ? f : stdout,
522 "SMP support: %s",
523 smp < 0 ? "unknown" : smp > 0 ? "yes" : "no"
524 );
525 if(smp > 0) fprintf(f ? f : stdout, " (%u cpus)", smp);
526 fprintf(f ? f : stdout, "\n");
527 }
528 else if(hw_item == 2003) {
529 c_arch = hd_cpu_arch(hd_data);
530 b_arch = hd_boot_arch(hd_data);
531
532 s = t = "Unknown";
533 switch(c_arch) {
534 case arch_unknown:
535 break;
536 case arch_intel:
537 s = "X86 (32)";
538 break;
539 case arch_alpha:
540 s = "Alpha";
541 break;
542 case arch_sparc:
543 s = "Sparc (32)";
544 break;
545 case arch_sparc64:
546 s = "UltraSparc (64)";
547 break;
548 case arch_ppc:
549 s = "PowerPC";
550 break;
551 case arch_ppc64:
552 s = "PowerPC (64)";
553 break;
554 case arch_68k:
555 s = "68k";
556 break;
557 case arch_ia64:
558 s = "IA-64";
559 break;
560 case arch_s390:
561 s = "S390";
562 break;
563 case arch_s390x:
564 s = "S390x";
565 break;
566 case arch_arm:
567 s = "ARM";
568 break;
569 case arch_mips:
570 s = "MIPS";
571 break;
572 case arch_x86_64:
573 s = "X86_64";
574 break;
575 }
576
577 switch(b_arch) {
578 case boot_unknown:
579 break;
580 case boot_lilo:
581 t = "lilo";
582 break;
583 case boot_milo:
584 t = "milo";
585 break;
586 case boot_aboot:
587 t = "aboot";
588 break;
589 case boot_silo:
590 t = "silo";
591 break;
592 case boot_ppc:
593 t = "ppc";
594 break;
595 case boot_elilo:
596 t = "elilo";
597 break;
598 case boot_s390:
599 t = "s390";
600 break;
601 case boot_mips:
602 t = "mips";
603 break;
604 case boot_grub:
605 t = "grub";
606 break;
607 }
608
609 fprintf(f ? f : stdout, "Arch: %s/%s\n", s, t);
610 }
611 else if(hw_item == 2004) {
612 fprintf(f ? f : stdout, "UML: %s\n", uml ? "yes" : "no");
613 }
614 else {
615 if(is_short) {
616 /* always to stdout */
617 do_short(hd_data, hd0, stdout);
618 if(f) do_short(hd_data, hd0, f);
619 }
620 else {
621 for(hd = hd0; hd; hd = hd->next) {
622 hd_dump_entry(hd_data, hd, f ? f : stdout);
623 }
624 }
625 }
626
627 if(hw_item == hw_display && hd0) {
628 fprintf(f ? f : stdout, "\nPrimary display adapter: #%u\n", hd_display_adapter(hd_data));
629 }
630
631 if(hd0 != hd_data->hd) hd_free_hd_list(hd0);
632}
633
634
635void do_hw_multi(hd_data_t *hd_data, FILE *f, hd_hw_item_t *hw_items)
636{
637 hd_t *hd, *hd0;
638
639 hd0 = hd_list2(hd_data, hw_items, 1);
640
641 if(hd_data->progress) {
642 printf("\r%64s\r", "");
643 fflush(stdout);
644 }
645
646 if(f) {
647 if((hd_data->debug & HD_DEB_SHOW_LOG) && hd_data->log) {
648 fprintf(f,
649 "============ start hardware log ============\n"
650 );
651 fprintf(f,
652 "============ start debug info ============\n%s=========== end debug info ============\n",
653 hd_data->log
654 );
655 }
656
657 for(hd = hd_data->hd; hd; hd = hd->next) {
658 hd_dump_entry(hd_data, hd, f);
659 }
660
661 fprintf(f,
662 "============ end hardware log ============\n"
663 );
664 }
665
666 if(is_short) {
667 /* always to stdout */
668 do_short(hd_data, hd0, stdout);
669 if(f) do_short(hd_data, hd0, f);
670 }
671 else {
672 for(hd = hd0; hd; hd = hd->next) {
673 hd_dump_entry(hd_data, hd, f ? f : stdout);
674 }
675 }
676
677 hd_free_hd_list(hd0);
678}
679
680
681void do_short(hd_data_t *hd_data, hd_t *hd, FILE *f)
682{
683#ifndef LIBHD_TINY
684 hd_hw_item_t item;
685 hd_t *hd1;
686 int i;
687 char *s;
688
689 for(item = 1; item < hw_all; item++) {
690 i = 0;
691 s = hd_hw_item_name(item);
692 if(!s) continue;
693
694 if(item == hw_sys) continue;
695
696 for(hd1 = hd; hd1; hd1 = hd1->next) {
697 if(hd1->hw_class == item) {
698 if(!i++) fprintf(f, "%s:\n", s);
699 fprintf(f, " %-20s %s\n",
700 hd1->unix_dev_name ? hd1->unix_dev_name : "",
701 hd1->model ? hd1->model : "???"
702 );
703 }
704 }
705 }
706#endif
707}
708
709
710#if 0
711typedef struct {
712 char *vendor, *model, *driver;
713} scanner_t;
714
715static scanner_t scanner_data[] = {
716 { "Abaton", "SCAN 300/GS", "abaton" },
717 { "Abaton", "SCAN 300/S", "abaton" },
718 { "Acer", "300f", "SnapScan" },
719 { "Acer", "310s", "SnapScan" },
720 { "Acer", "610plus", "SnapScan" },
721 { "Acer", "610s", "SnapScan" },
722 { "Acer", "Prisa 1240", "SnapScan" },
723 { "Acer", "Prisa 3300", "SnapScan" },
724 { "Acer", "Prisa 4300", "SnapScan" },
725 { "Acer", "Prisa 5300", "SnapScan" },
726 { "Acer", "Prisa 620s", "SnapScan" },
727 { "Acer", "Prisa 620u", "SnapScan" },
728 { "Acer", "Prisa 620ut", "SnapScan" },
729 { "Acer", "Prisa 640bu", "SnapScan" },
730 { "Acer", "Prisa 640u", "SnapScan" },
731 { "Agfa", "Arcus II", "microtek" },
732 { "Agfa", "DuoScan", "microtek" },
733 { "Agfa", "FOCUS COLOR", "agfafocus" },
734 { "Agfa", "FOCUS GS SCANNER", "agfafocus" },
735 { "Agfa", "FOCUS II", "agfafocus" },
736 { "Agfa", "FOCUS LINEART SCANNER", "agfafocus" },
737 { "Agfa", "SnapScan 1212u", "SnapScan" },
738 { "Agfa", "SnapScan 1236s", "SnapScan" },
739 { "Agfa", "SnapScan 1236u", "SnapScan" },
740 { "Agfa", "SnapScan 300", "SnapScan" },
741 { "Agfa", "SnapScan 310", "SnapScan" },
742 { "Agfa", "SnapScan 600", "SnapScan" },
743 { "Agfa", "SnapScan e20", "SnapScan" },
744 { "Agfa", "SnapScan e25", "SnapScan" },
745 { "Agfa", "SnapScan e40", "SnapScan" },
746 { "Agfa", "SnapScan e50", "SnapScan" },
747 { "Agfa", "SnapScan e60", "SnapScan" },
748 { "Agfa", "StudioScan", "microtek" },
749 { "Agfa", "StudioScan II", "microtek" },
750 { "Agfa", "StudioScan IIsi", "microtek" },
751 { "Apple", "APPLE SCANNER", "apple" },
752 { "Apple", "COLORONESCANNER", "apple" },
753 { "Apple", "ONESCANNER", "apple" },
754 { "Artec", "A6000C", "artec" },
755 { "Artec", "A6000C PLUS", "artec" },
756 { "Artec", "AM12S", "artec" },
757 { "Artec", "AT12", "artec" },
758 { "Artec", "AT3", "artec" },
759 { "Artec", "AT6", "artec" },
760 { "Artec", "ColorOneScanner", "artec" },
761 { "Avision", "AV 620 CS", "avision" },
762 { "Avision", "AV 6240", "avision" },
763 { "Avision", "AV 630 CS", "avision" },
764 { "B&H SCSI", "COPISCAN II 2135", "bh" },
765 { "B&H SCSI", "COPISCAN II 2137", "bh" },
766 { "B&H SCSI", "COPISCAN II 2137A", "bh" },
767 { "B&H SCSI", "COPISCAN II 2138A", "bh" },
768 { "B&H SCSI", "COPISCAN II 3238", "bh" },
769 { "B&H SCSI", "COPISCAN II 3338", "bh" },
770 { "B&H SCSI", "COPISCAN II 6338", "bh" },
771 { "BlackWidow", "BW4800SP", "artec" },
772 { "Canon", "CANOSCAN 2700F", "canon" },
773 { "Canon", "CANOSCAN 300", "canon" },
774 { "Canon", "CANOSCAN 600", "canon" },
775 { "Devcom", "9636PRO", "pie" },
776 { "Devcom", "9636S", "pie" },
777 { "EDGE", "KTX-9600US", "umax" },
778 { "Epson", "ES-8500", "epson" },
779 { "Epson", "EXPRESSION 1600", "epson" },
780 { "Epson", "EXPRESSION 1680", "epson" },
781 { "Epson", "EXPRESSION 636", "epson" },
782 { "Epson", "EXPRESSION 800", "epson" },
783 { "Epson", "FILMSCAN 200", "epson" },
784 { "Epson", "GT-5500", "epson" },
785 { "Epson", "GT-7000", "epson" },
786 { "Epson", "GT-8000", "epson" },
787 { "Epson", "PERFECTION 1200PHOTO", "epson" },
788 { "Epson", "PERFECTION 1200S", "epson" },
789 { "Epson", "PERFECTION 1200U", "epson" },
790 { "Epson", "PERFECTION 1240", "epson" },
791 { "Epson", "PERFECTION 1640", "epson" },
792 { "Epson", "PERFECTION 1650", "epson" },
793 { "Epson", "PERFECTION 610", "epson" },
794 { "Epson", "PERFECTION 636S", "epson" },
795 { "Epson", "PERFECTION 636U", "epson" },
796 { "Epson", "PERFECTION 640", "epson" },
797 { "Epson", "PERFECTION1200", "epson" },
798 { "Epson", "Perfection 600", "umax" },
799 { "Escom", "Image Scanner 256", "umax" },
800 { "Escort", "Galleria 600", "umax" },
801 { "Fujitsu", "M3091DCD", "m3091" },
802 { "Fujitsu", "M3096G", "m3096g" },
803 { "Fujitsu", "SP15C", "sp15c" },
804 { "Genius", "ColorPage-HR5 Pro", "umax" },
805 { "Guillemot", "Maxi Scan A4 Deluxe", "SnapScan" },
806 { "HP", "HP OFFICEJET K SERIES", "hp" },
807 { "HP", "HP OFFICEJET V SERIES", "hp" },
808 { "HP", "HP PHOTOSMART PHOTOSCANNER", "hp" },
809 { "HP", "HP PSC 700 SERIES", "hp" },
810 { "HP", "HP PSC 900 SERIES", "hp" },
811 { "HP", "HP SCANJET 3C", "hp" },
812 { "HP", "HP SCANJET 3P", "hp" },
813 { "HP", "HP SCANJET 4100C", "hp" },
814 { "HP", "HP SCANJET 4C", "hp" },
815 { "HP", "HP SCANJET 4P", "hp" },
816 { "HP", "HP SCANJET 5200C", "hp" },
817 { "HP", "HP SCANJET 6100C", "hp" },
818 { "HP", "HP SCANJET 6200C", "hp" },
819 { "HP", "HP SCANJET 6250C", "hp" },
820 { "HP", "HP SCANJET 6300C", "hp" },
821 { "HP", "HP SCANJET 6350C", "hp" },
822 { "HP", "HP SCANJET 6390C", "hp" },
823 { "HP", "HP SCANJET IIC", "hp" },
824 { "HP", "HP SCANJET IICX", "hp" },
825 { "HP", "HP SCANJET IIP", "hp" },
826 { "HP", "HP ScanJet 5p", "hp" },
827 { "HP", "HP4200", "hp4200" },
828 { "Highscreen", "Scanboostar Premium", "umax" },
829 { "Linotype Hell", "Jade", "umax" },
830 { "Linotype Hell", "Jade2", "umax" },
831 { "Linotype Hell", "Linoscan 1400", "umax" },
832 { "Linotype Hell", "Opal", "umax" },
833 { "Linotype Hell", "Opal Ultra", "umax" },
834 { "Linotype Hell", "Saphir", "umax" },
835 { "Linotype Hell", "Saphir HiRes", "umax" },
836 { "Linotype Hell", "Saphir Ultra", "umax" },
837 { "Linotype Hell", "Saphir Ultra II", "umax" },
838 { "Linotype Hell", "Saphir2", "umax" },
839 { "Microtek", "Phantom 636", "microtek2" },
840 { "Microtek", "ScanMaker 330", "microtek2" },
841 { "Microtek", "ScanMaker 3600", "sm3600" },
842 { "Microtek", "ScanMaker 630", "microtek2" },
843 { "Microtek", "ScanMaker 636", "microtek2" },
844 { "Microtek", "ScanMaker 9600XL", "microtek2" },
845 { "Microtek", "ScanMaker E3plus", "microtek2" },
846 { "Microtek", "ScanMaker V300", "microtek2" },
847 { "Microtek", "ScanMaker V310", "microtek2" },
848 { "Microtek", "ScanMaker V600", "microtek2" },
849 { "Microtek", "ScanMaker V6USL", "microtek2" },
850 { "Microtek", "ScanMaker X6", "microtek2" },
851 { "Microtek", "ScanMaker X6EL", "microtek2" },
852 { "Microtek", "ScanMaker X6USB", "microtek2" },
853 { "Microtek", "Scanmaker 35", "microtek" },
854 { "Microtek", "Scanmaker 35t+", "microtek" },
855 { "Microtek", "Scanmaker 45t", "microtek" },
856 { "Microtek", "Scanmaker 600G", "microtek" },
857 { "Microtek", "Scanmaker 600G S", "microtek" },
858 { "Microtek", "Scanmaker 600GS", "microtek" },
859 { "Microtek", "Scanmaker 600S", "microtek" },
860 { "Microtek", "Scanmaker 600Z", "microtek" },
861 { "Microtek", "Scanmaker 600Z S", "microtek" },
862 { "Microtek", "Scanmaker 600ZS", "microtek" },
863 { "Microtek", "Scanmaker E2", "microtek" },
864 { "Microtek", "Scanmaker E3", "microtek" },
865 { "Microtek", "Scanmaker E6", "microtek" },
866 { "Microtek", "Scanmaker II", "microtek" },
867 { "Microtek", "Scanmaker IIG", "microtek" },
868 { "Microtek", "Scanmaker IIHR", "microtek" },
869 { "Microtek", "Scanmaker III", "microtek" },
870 { "Microtek", "Scanmaker IISP", "microtek" },
871 { "Microtek", "SlimScan C6", "microtek2" },
872 { "Mustek", "1200 CU", "mustek_usb" },
873 { "Mustek", "1200 CU Plus", "mustek_usb" },
874 { "Mustek", "1200 UB", "mustek_usb" },
875 { "Mustek", "600 CU", "mustek_usb" },
876 { "Mustek", "Paragon 1200 A3 Pro", "mustek" },
877 { "Mustek", "Paragon 1200 III SP", "mustek" },
878 { "Mustek", "Paragon 1200 LS", "mustek" },
879 { "Mustek", "Paragon 1200 SP Pro", "mustek" },
880 { "Mustek", "Paragon 600 II CD", "mustek" },
881 { "Mustek", "Paragon 800 II SP", "mustek" },
882 { "Mustek", "Paragon MFC-600S", "mustek" },
883 { "Mustek", "Paragon MFC-800S", "mustek" },
884 { "Mustek", "Paragon MFS-12000CX", "mustek" },
885 { "Mustek", "Paragon MFS-12000SP", "mustek" },
886 { "Mustek", "Paragon MFS-1200SP", "mustek" },
887 { "Mustek", "Paragon MFS-6000CX", "mustek" },
888 { "Mustek", "Paragon MFS-6000SP", "mustek" },
889 { "Mustek", "Paragon MFS-8000SP", "mustek" },
890 { "Mustek", "ScanExpress 12000SP", "mustek" },
891 { "Mustek", "ScanExpress 12000SP Plus", "mustek" },
892 { "Mustek", "ScanExpress 6000SP", "mustek" },
893 { "Mustek", "ScanExpress A3 SP", "mustek" },
894 { "Mustek", "ScanMagic 600 II SP", "mustek" },
895 { "Mustek", "ScanMagic 9636S", "mustek" },
896 { "Mustek", "ScanMagic 9636S Plus", "mustek" },
897 { "NEC", "PC-IN500/4C", "nec" },
898 { "Nikon", "AX-210", "umax" },
899 { "Nikon", "LS-1000", "coolscan" },
900 { "Nikon", "LS-20", "coolscan" },
901 { "Nikon", "LS-2000", "coolscan" },
902 { "Nikon", "LS-30", "coolscan" },
903 { "Pie", "9630S", "pie" },
904 { "Pie", "ScanAce 1230S", "pie" },
905 { "Pie", "ScanAce 1236S", "pie" },
906 { "Pie", "ScanAce 630S", "pie" },
907 { "Pie", "ScanAce 636S", "plustek" },
908 { "Pie", "ScanAce II", "pie" },
909 { "Pie", "ScanAce II Plus", "pie" },
910 { "Pie", "ScanAce III", "pie" },
911 { "Pie", "ScanAce III Plus", "pie" },
912 { "Pie", "ScanAce Plus", "pie" },
913 { "Pie", "ScanAce ScanMedia", "pie" },
914 { "Pie", "ScanAce ScanMedia II", "pie" },
915 { "Pie", "ScanAce V", "pie" },
916 { "Plustek", "OpticPro 19200S", "artec" },
917 { "Polaroid", "DMC", "dmc" },
918 { "Ricoh", "Ricoh IS50", "ricoh" },
919 { "Ricoh", "Ricoh IS60", "ricoh" },
920 { "Scanport", "SQ4836", "microtek2" },
921 { "Sharp", "9036 Flatbed scanner", "sharp" },
922 { "Sharp", "JX-250", "sharp" },
923 { "Sharp", "JX-320", "sharp" },
924 { "Sharp", "JX-330", "sharp" },
925 { "Sharp", "JX-350", "sharp" },
926 { "Sharp", "JX-610", "sharp" },
927 { "Siemens", "9036 Flatbed scanner", "s9036" },
928 { "Siemens", "FOCUS COLOR PLUS", "agfafocus" },
929 { "Siemens", "ST400", "st400" },
930 { "Siemens", "ST800", "st400" },
931 { "Tamarack", "Artiscan 12000C", "tamarack" },
932 { "Tamarack", "Artiscan 6000C", "tamarack" },
933 { "Tamarack", "Artiscan 8000C", "tamarack" },
934 { "Trust", "Compact Scan USB 19200", "mustek_usb" },
935 { "Trust", "Imagery 1200 SP", "mustek" },
936 { "Trust", "Imagery 4800 SP", "mustek" },
937 { "Trust", "SCSI Connect 19200", "mustek" },
938 { "Trust", "SCSI excellence series 19200", "mustek" },
939 { "UMAX", "Astra 1200S", "umax" },
940 { "UMAX", "Astra 1220S", "umax" },
941 { "UMAX", "Astra 2100S", "umax" },
942 { "UMAX", "Astra 2200", "umax" },
943 { "UMAX", "Astra 2200 S", "umax" },
944 { "UMAX", "Astra 2200 U", "umax" },
945 { "UMAX", "Astra 2400S", "umax" },
946 { "UMAX", "Astra 600S", "umax" },
947 { "UMAX", "Astra 610S", "umax" },
948 { "UMAX", "Gemini D-16", "umax" },
949 { "UMAX", "Mirage D-16L", "umax" },
950 { "UMAX", "Mirage II", "umax" },
951 { "UMAX", "Mirage IIse", "umax" },
952 { "UMAX", "PL-II", "umax" },
953 { "UMAX", "PSD", "umax" },
954 { "UMAX", "PowerLook", "umax" },
955 { "UMAX", "PowerLook 2000", "umax" },
956 { "UMAX", "PowerLook 3000", "umax" },
957 { "UMAX", "PowerLook III", "umax" },
958 { "UMAX", "Supervista S-12", "umax" },
959 { "UMAX", "UC 1200S", "umax" },
960 { "UMAX", "UC 1200SE", "umax" },
961 { "UMAX", "UC 1260", "umax" },
962 { "UMAX", "UC 630", "umax" },
963 { "UMAX", "UC 840", "umax" },
964 { "UMAX", "UG 630", "umax" },
965 { "UMAX", "UG 80", "umax" },
966 { "UMAX", "UMAX S-12", "umax" },
967 { "UMAX", "UMAX S-12G", "umax" },
968 { "UMAX", "UMAX S-6E", "umax" },
969 { "UMAX", "UMAX S-6EG", "umax" },
970 { "UMAX", "UMAX VT600", "umax" },
971 { "UMAX", "Vista S6", "umax" },
972 { "UMAX", "Vista S6E", "umax" },
973 { "UMAX", "Vista-S8", "umax" },
974 { "UMAX", "Vista-T630", "umax" },
975 { "Ultima", "A6000C", "artec" },
976 { "Ultima", "A6000C PLUS", "artec" },
977 { "Ultima", "AM12S", "artec" },
978 { "Ultima", "AT12", "artec" },
979 { "Ultima", "AT3", "artec" },
980 { "Ultima", "AT6", "artec" },
981 { "Ultima", "ColorOneScanner", "artec" },
982 { "Vobis", "HighScan", "microtek2" },
983 { "Vobis", "Scanboostar Premium", "umax" },
984 { "Vuego", "Close SnapScan 310 compatible.", "SnapScan" }
985};
986
987static char *scanner_info(hd_t *hd)
988{
989 int i;
990
991 if(!hd->vendor.name || !hd->device.name) return NULL;
992
993 for(i = 0; (unsigned) i < sizeof scanner_data / sizeof *scanner_data; i++) {
994 if(
995 !strcasecmp(scanner_data[i].vendor, hd->vendor.name) &&
996 !strcasecmp(scanner_data[i].model, hd->device.name)
997 ) {
998 return scanner_data[i].driver;
999 }
1000 }
1001
1002 return NULL;
1003}
1004
1005#endif
1006
1007void do_test(hd_data_t *hd_data)
1008{
1009#if 0
1010 hd_t *hd, *hd0;
1011 hd_res_t *res;
1012 driver_info_t *di;
1013 FILE *f;
1014 int i, wheels, buttons;
1015 unsigned u;
1016 uint64_t ul;
1017 char *s, *s1;
1018 hd_hw_item_t item, items[] = {
1019 hw_display, hw_monitor, hw_tv, hw_sound, hw_mouse, hw_disk, hw_cdrom,
1020 hw_floppy, hw_modem, hw_isdn, hw_scanner, hw_camera
1021 };
1022
1023 hd_set_probe_feature(hd_data, pr_default);
1024 hd_scan(hd_data);
1025
1026 f = fopen("/tmp/hw_overview.log", "w");
1027
1028 for(i = 0; (unsigned) i < sizeof items / sizeof *items; i++) {
1029 item = items[i];
1030 hd0 = hd_list(hd_data, item, 0, NULL);
1031
1032 if(!hd0) continue;
1033
1034 switch(item) {
1035 case hw_disk:
1036 fprintf(f, "Disk\n");
1037 for(hd = hd0; hd; hd = hd->next) {
1038 u = 0;
1039 for(res = hd->res; res; res = res->next) {
1040 if(res->any.type == res_size && res->size.unit == size_unit_sectors) {
1041 ul = (uint64_t) res->size.val1 * (res->size.val2 ?: 0x200);
1042 u = ((ul >> 29) + 1) >> 1;
1043 }
1044 }
1045 s = hd->bus.name;
1046 fprintf(f, " %s", hd->model);
1047 if(u) {
1048 fprintf(f, " (");
1049 if(s) fprintf(f, "%s, ", s);
1050 fprintf(f, "%u GB)", u);
1051 }
1052 fprintf(f, "\n");
1053 }
1054 fprintf(f, "\n");
1055 break;
1056
1057 case hw_cdrom:
1058 fprintf(f, "CD-ROM\n");
1059 for(hd = hd0; hd; hd = hd->next) {
1060 s = hd->bus.name;
1061 fprintf(f, " %s (", hd->model);
1062 if(s) fprintf(f, "%s, ", s);
1063 fprintf(f, "%s)", hd->prog_if.name ?: "CD-ROM");
1064 fprintf(f, "\n");
1065 }
1066 fprintf(f, "\n");
1067 break;
1068
1069 case hw_monitor:
1070 fprintf(f, "Monitor\n");
1071 for(hd = hd0; hd; hd = hd->next) {
1072 s = hd->model;
1073 if(!strcmp(hd->unique_id, "rdCR.EY_qmtb9YY0")) s = "not detected";
1074 fprintf(f, " %s\n", s);
1075 }
1076 fprintf(f, "\n");
1077 break;
1078
1079 case hw_display:
1080 fprintf(f, "GFX Card\n");
1081 for(hd = hd0; hd; hd = hd->next) {
1082 u = 0;
1083 s1 = NULL;
1084 for(di = hd->driver_info; di; di = di->next) {
1085 if(di->any.type == di_x11) {
1086 if(!s1) s1 = di->x11.server;
1087 if(di->x11.x3d && !u) {
1088 s1 = di->x11.server;
1089 u = 1;
1090 }
1091 }
1092 }
1093 if(!s1) {
1094 s1 = "not supported";
1095 u = 0;
1096 }
1097 fprintf(f, " %s (%s", hd->model, s1);
1098 if(u) fprintf(f, ", 3D support");
1099 fprintf(f, ")");
1100 fprintf(f, "\n");
1101 }
1102 fprintf(f, "\n");
1103 break;
1104
1105 case hw_mouse:
1106 fprintf(f, "Mouse\n");
1107 for(hd = hd0; hd; hd = hd->next) {
1108 buttons = wheels = -1; // make gcc happy
1109 s = NULL;
1110 for(di = hd->driver_info; di; di = di->next) {
1111 if(di->any.type == di_mouse) {
1112 buttons = di->mouse.buttons;
1113 wheels = di->mouse.wheels;
1114 s = di->mouse.xf86;
1115 break;
1116 }
1117 }
1118 if(!s) {
1119 s = "not supported";
1120 buttons = wheels = -1;
1121 }
1122 fprintf(f, " %s (%s", hd->model, s);
1123 if(buttons >= 0) fprintf(f, ", %d buttons", buttons);
1124 if(wheels >= 0) fprintf(f, ", %d wheels", wheels);
1125 fprintf(f, ")");
1126 fprintf(f, "\n");
1127 }
1128 fprintf(f, "\n");
1129 break;
1130
1131 case hw_tv:
1132 fprintf(f, "TV Card\n");
1133 for(hd = hd0; hd; hd = hd->next) {
1134 s = NULL;
1135 for(di = hd->driver_info; di; di = di->next) {
1136 if(
1137 (di->any.type == di_any || di->any.type == di_module) &&
1138 di->any.hddb0 &&
1139 di->any.hddb0->str
1140 ) {
1141 s = di->any.hddb0->str;
1142 break;
1143 }
1144 }
1145 if(!s) {
1146 s = "not supported";
1147 }
1148 fprintf(f, " %s (%s)\n", hd->model, s);
1149 }
1150 fprintf(f, "\n");
1151 break;
1152
1153 case hw_sound:
1154 fprintf(f, "Sound Card\n");
1155 for(hd = hd0; hd; hd = hd->next) {
1156 s = NULL;
1157 for(di = hd->driver_info; di; di = di->next) {
1158 if(
1159 (di->any.type == di_any || di->any.type == di_module) &&
1160 di->any.hddb0 &&
1161 di->any.hddb0->str
1162 ) {
1163 s = di->any.hddb0->str;
1164 break;
1165 }
1166 }
1167 if(!s) {
1168 s = "not supported";
1169 }
1170 fprintf(f, " %s (%s)\n", hd->model, s);
1171 }
1172 fprintf(f, "\n");
1173 break;
1174
1175 case hw_camera:
1176 fprintf(f, "Digital Camera/WebCam\n");
1177 for(hd = hd0; hd; hd = hd->next) {
1178 fprintf(f, " %s\n", hd->model);
1179 }
1180 fprintf(f, "\n");
1181 break;
1182
1183 case hw_floppy:
1184 fprintf(f, "Floppy/Zip Drive\n");
1185 for(hd = hd0; hd; hd = hd->next) {
1186 fprintf(f, " %s\n", hd->model);
1187 }
1188 fprintf(f, "\n");
1189 break;
1190
1191 case hw_modem:
1192 fprintf(f, "Modem\n");
1193 for(hd = hd0; hd; hd = hd->next) {
1194 fprintf(f, " %s\n", hd->model);
1195 }
1196 fprintf(f, "\n");
1197 break;
1198
1199 case hw_isdn:
1200 fprintf(f, "ISDN\n");
1201 for(hd = hd0; hd; hd = hd->next) {
1202 fprintf(f, " %s (%ssupported)\n", hd->model, hd->driver_info ? "" : "not ");
1203 }
1204 fprintf(f, "\n");
1205 break;
1206
1207 case hw_scanner:
1208 fprintf(f, "Scanner\n");
1209 for(hd = hd0; hd; hd = hd->next) {
1210 s = scanner_info(hd);
1211 if(!s) s = "not supported";
1212 fprintf(f, " %s (%s)\n", hd->model, s);
1213 }
1214 fprintf(f, "\n");
1215 break;
1216
1217 default:
1218 break;
1219 }
1220
1221 hd_free_hd_list(hd0);
1222
1223 }
1224
1225 fclose(f);
1226
1227 f = fopen("/tmp/hw_detail.log", "w");
1228
1229 if(hd_data->log) {
1230 fprintf(f,
1231 "============ start detailed hardware log ============\n"
1232 );
1233 fprintf(f,
1234 "============ start debug info ============\n%s=========== end debug info ============\n",
1235 hd_data->log
1236 );
1237 }
1238
1239 for(hd = hd_data->hd; hd; hd = hd->next) {
1240 hd_dump_entry(hd_data, hd, f);
1241 }
1242
1243 fprintf(f,
1244 "============ end detailed hardware log ============\n"
1245 );
1246
1247 fclose(f);
1248
1249 fprintf(stderr, "\n");
1250
1251#endif
1252
1253#if 0
1254 hd_t *hd;
1255 hd_t *hd0 = NULL;
1256
1257 for(hd = hd_list(hd_data, hw_cdrom, 1, hd0); hd; hd = hd->next) {
1258 fprintf(stderr, "cdrom: %s, %s\n", hd->unix_dev_name, hd->model);
1259 }
1260
1261 for(hd = hd_list(hd_data, hw_cdrom, 1, hd0); hd; hd = hd->next) {
1262 fprintf(stderr, "cdrom: %s, %s\n", hd->unix_dev_name, hd->model);
1263 }
1264#endif
1265
1266#if 0
1267 hd_t *hd;
1268
1269 hd = hd_list(hd_data, hw_disk, 1, NULL);
1270 hd_free_hd_list(hd);
1271 hd_free_hd_data(hd_data);
1272
1273 hd = hd_list(hd_data, hw_cdrom, 1, NULL);
1274 hd_free_hd_list(hd);
1275 hd_free_hd_data(hd_data);
1276
1277 hd = hd_list(hd_data, hw_storage_ctrl, 1, NULL);
1278 hd_free_hd_list(hd);
1279 hd_free_hd_data(hd_data);
1280
1281 hd = hd_list(hd_data, hw_display, 1, NULL);
1282 hd_free_hd_list(hd);
1283 hd_free_hd_data(hd_data);
1284
1285#if 0
1286 for(hd = hd_data->hd; hd; hd = hd->next) {
1287 hd_dump_entry(hd_data, hd, stdout);
1288 }
1289
1290 printf("%s\n", hd_data->log);
1291#endif
1292
1293#endif
1294
1295#if 0
1296 hd_t *hd, *hd0;
1297
1298 hd0 = hd_list(hd_data, hw_sound, 1, NULL);
1299 hd0 = hd_list(hd_data, hw_sound, 1, NULL);
1300
1301 for(hd = hd0; hd; hd = hd->next) {
1302 hd_dump_entry(hd_data, hd, stdout);
1303 }
1304
1305#if 0
1306 hd_data->log = free_mem(hd_data->log);
1307 dump_hddb_data(hd_data, hd_data->hddb_dev, "hddb_dev, final");
1308 if(hd_data->log) printf("%s", hd_data->log);
1309#endif
1310
1311#endif
1312
1313#if 0
1314 hd_t *hd;
1315 driver_info_t *di;
1316 str_list_t *sl;
1317
1318 hd = hd_list(hd_data, hw_sys, 1, NULL);
1319
1320 for(di = hd->driver_info; di; di = di->next) {
1321 if(di->any.type == di_module) {
1322 for(sl = di->module.names; sl; sl = sl->next) printf("%s\n", sl->str);
1323 }
1324 }
1325
1326#endif
1327}
1328
1329
1330void help()
1331{
1332 fprintf(stderr,
1333 "Usage: hwinfo [options]\n"
1334 "Probe for hardware.\n"
1335 " --short just a short listing\n"
1336 " --log logfile write info to logfile\n"
1337 " --debug level set debuglevel\n"
1338 " --version show libhd version\n"
1339 " --dump-db n dump hardware data base, 0: external, 1: internal\n"
1340 " --hw_item probe for hw_item\n"
1341 " hw_item is one of:\n"
1342 " all, bios, block, bluetooth, braille, bridge, camera, cdrom, chipcard, cpu,\n"
1343 " disk, dsl, dvb, floppy, framebuffer, gfxcard, hub, ide, isapnp, isdn,\n"
1344 " joystick, keyboard, memory, modem, monitor, mouse, netcard, network,\n"
1345 " partition, pci, pcmcia, pcmcia-ctrl, pppoe, printer, scanner, scsi, smp,\n"
1346 " sound, storage-ctrl, sys, tape, tv, usb, usb-ctrl, vbe, wlan, zip\n\n"
1347 " Note: debug info is shown only in the log file. (If you specify a\n"
1348 " log file the debug level is implicitly set to a reasonable value.)\n"
1349 );
1350}
1351
1352
1353/*
1354 * Parse command line options.
1355 */
1356int get_probe_flags(int argc, char **argv, hd_data_t *hd_data)
1357{
1358 int i, j, k;
1359 char *s, *t;
1360 for(i = 0; i < argc; i++) {
1361 s = argv[i];
1362
1363 if(!strcmp(s, ".")) {
1364 return i + 1;
1365 }
1366
1367 t = "debug=";
1368 if(!strncmp(s, t, strlen(t))) {
1369 hd_data->debug = strtol(s + strlen(t), NULL, 0);
1370 continue;
1371 }
1372
1373 t = "list=";
1374 if(!strncmp(s, t, strlen(t))) {
1375 list = s + strlen(t);
1376 continue;
1377 }
1378
1379 t = "list+=";
1380 if(!strncmp(s, t, strlen(t))) {
1381 list = s + strlen(t);
1382 listplus = 1;
1383 continue;
1384 }
1385
1386 t = "log=";
1387 if(!strncmp(s, t, strlen(t))) {
1388 log_file = s + strlen(t);
1389 continue;
1390 }
1391
1392 t = "only=";
1393 if(!strncmp(s, t, strlen(t))) {
1394 add_str_list(&hd_data->only, s + strlen(t));
1395 continue;
1396 }
1397
1398 t = "root=";
1399 if(!strncmp(s, t, strlen(t))) {
1400 opt.root = s + strlen(t);
1401 continue;
1402 }
1403
1404 k = 1;
1405 if(*s == '+')
1406 s++;
1407 else if(*s == '-')
1408 k = 0, s++;
1409
1410 if((j = hd_probe_feature_by_name(s))) {
1411 if(k)
1412 hd_set_probe_feature(hd_data, j);
1413 else
1414 hd_clear_probe_feature(hd_data, j);
1415 continue;
1416 }
1417
1418 fprintf(stderr, "oops: don't know what to do with \"%s\"\n", s);
1419 return -1;
1420 }
1421
1422 return argc;
1423}
1424
1425/*
1426 * A simple progress function.
1427 */
1428void progress2(char *pos, char *msg)
1429{
1430 if(!test) printf("\r%64s\r", "");
1431 printf("> %s: %s", pos, msg);
1432 if(test) printf("\n");
1433 fflush(stdout);
1434}
1435
1436
1437#define INSTALL_INF "/etc/install.inf"
1438
1439int braille_install_info(hd_data_t *hd_data)
1440{
1441 hd_t *hd;
1442 int ok = 0;
1443 char *braille = NULL;
1444 char *braille_dev = NULL;
1445 str_list_t *sl0, *sl;
1446 FILE *f;
1447
1448 hd = hd_list(hd_data, hw_braille, 1, NULL);
1449
1450 if(hd_data->progress) {
1451 printf("\r%64s\r", "");
1452 fflush(stdout);
1453 }
1454
1455 for(; hd; hd = hd->next) {
1456 if(
1457 hd->base_class.id == bc_braille && /* is a braille display */
1458 hd->unix_dev_name && /* and has a device name */
1459 (braille = hd->device.name)
1460 ) {
1461 braille_dev = hd->unix_dev_name;
1462 ok = 1;
1463 break;
1464 }
1465 }
1466
1467 if(!ok) return 1;
1468
1469 printf("found a %s at %s\n", braille, braille_dev);
1470
1471 sl0 = read_file(INSTALL_INF, 0, 0);
1472 f = fopen(INSTALL_INF, "w");
1473 if(!f) {
1474 perror(INSTALL_INF);
1475 return 1;
1476 }
1477
1478 for(sl = sl0; sl; sl = sl->next) {
1479 if(
1480 strstr(sl->str, "Braille:") != sl->str &&
1481 strstr(sl->str, "Brailledevice:") != sl->str
1482 ) {
1483 fprintf(f, "%s", sl->str);
1484 }
1485 }
1486
1487 fprintf(f, "Braille: %s\n", braille);
1488 fprintf(f, "Brailledevice: %s\n", braille_dev);
1489
1490 fclose(f);
1491
1492 return 0;
1493}
1494
1495
1496/*
1497 * get VGA parameter from /proc/cmdline
1498 */
1499int get_fb_mode()
1500{
1501#ifndef __PPC__
1502 FILE *f;
1503 char buf[256], *s, *t;
1504 int i, fb_mode = 0;
1505
1506 if((f = fopen("/proc/cmdline", "r"))) {
1507 if(fgets(buf, sizeof buf, f)) {
1508 t = buf;
1509 while((s = strsep(&t, " "))) {
1510 if(sscanf(s, "vga=%i", &i) == 1) fb_mode = i;
1511 if(strstr(s, "vga=normal") == s) fb_mode = 0;
1512 }
1513 }
1514 fclose(f);
1515 }
1516
1517 return fb_mode > 0x10 ? fb_mode : 0;
1518#else /* __PPC__ */
1519 /* this is the only valid test for active framebuffer ... */
1520 FILE *f = NULL;
1521 int fb_mode = 0;
1522 if((f = fopen("/dev/fb", "r"))) {
1523 fb_mode++;
1524 fclose(f);
1525 }
1526
1527 return fb_mode;
1528#endif
1529}
1530
1531
1532/*
1533 * read "x11i=" entry from /proc/cmdline
1534 */
1535char *get_x11i()
1536{
1537 FILE *f;
1538 char buf[256], *s, *t;
1539 static char x11i[64] = { };
1540
1541 if(*x11i) return x11i;
1542
1543 if((f = fopen("/proc/cmdline", "r"))) {
1544 if(fgets(buf, sizeof buf, f)) {
1545 t = buf;
1546 while((s = strsep(&t, " "))) {
1547 if(sscanf(s, "x11i=%60s", x11i) == 1) break;
1548 }
1549 }
1550 fclose(f);
1551 }
1552
1553 return x11i;
1554}
1555
1556
1557/*
1558 * Assumes xf86_ver to be either "3" or "4" (or empty).
1559 */
1560char *get_xserver(hd_data_t *hd_data, char **version, char **busid, driver_info_t **x11_driver)
1561{
1562 static char display[16];
1563 static char xf86_ver[2];
1564 static char id[32];
1565 char c, *x11i = get_x11i();
1566 driver_info_t *di;
1567 hd_t *hd;
1568
1569 *x11_driver = NULL;
1570
1571 *display = *xf86_ver = *id = c = 0;
1572 *version = xf86_ver;
1573 *busid = id;
1574
1575 if(x11i) {
1576 if(*x11i == '3' || *x11i == '4') {
1577 c = *x11i;
1578 }
1579 else {
1580 if(*x11i >= 'A' && *x11i <= 'Z') {
1581 c = '3';
1582 }
1583 if(*x11i >= 'a' && *x11i <= 'z') {
1584 c = '4';
1585 }
1586 if(c) {
1587 strncpy(display, x11i, sizeof display - 1);
1588 display[sizeof display - 1] = 0;
1589 }
1590 }
1591 }
1592
1593 if(c) { xf86_ver[0] = c; xf86_ver[1] = 0; }
1594
1595 hd = hd_get_device_by_idx(hd_data, hd_display_adapter(hd_data));
1596
1597 if(hd && hd->bus.id == bus_pci)
1598 sprintf(id, "%d:%d:%d", hd->slot >> 8, hd->slot & 0xff, hd->func);
1599
1600 if(!hd || *display) return display;
1601
1602 for(di = hd->driver_info; di; di = di->next) {
1603 if(di->any.type == di_x11 && di->x11.server && di->x11.xf86_ver && !di->x11.x3d) {
1604 if(c == 0 || c == di->x11.xf86_ver[0]) {
1605 xf86_ver[0] = di->x11.xf86_ver[0];
1606 xf86_ver[1] = 0;
1607 strncpy(display, di->x11.server, sizeof display - 1);
1608 display[sizeof display - 1] = 0;
1609 *x11_driver = di;
1610 break;
1611 }
1612 }
1613 }
1614
1615 if(*display) return display;
1616
1617 if(c == 0) c = '4'; /* default to XF 4, if nothing else is known */
1618
1619 xf86_ver[0] = c;
1620 xf86_ver[1] = 0;
1621 strcpy(display, c == '3' ? "FBDev" : "fbdev");
1622
1623 return display;
1624}
1625
1626int x11_install_info(hd_data_t *hd_data)
1627{
1628 hd_t *hd;
1629 driver_info_t *di;
1630 char *x11i;
1631 int fb_mode, kbd_ok = 0;
1632 unsigned yast2_color = 0;
1633 char *xkbrules = NULL, *xkbmodel = NULL, *xkblayout = NULL;
1634 char *xserver, *version, *busid;
1635 driver_info_t *x11_driver;
1636 str_list_t *sl0, *sl;
1637 FILE *f;
1638
1639 /* get color info */
1640 hd_set_probe_feature(hd_data, pr_cpu);
1641 hd_set_probe_feature(hd_data, pr_prom);
1642 hd_scan(hd_data);
1643
1644 x11i = get_x11i();
1645 fb_mode = get_fb_mode();
1646
1647 hd_list(hd_data, hw_display, 1, NULL);
1648
1649 for(hd = hd_list(hd_data, hw_keyboard, 1, NULL); hd; hd = hd->next) {
1650 kbd_ok = 1;
1651 di = hd->driver_info;
1652 if(di && di->any.type == di_kbd) {
1653 xkbrules = di->kbd.XkbRules;
1654 xkbmodel = di->kbd.XkbModel;
1655 xkblayout = di->kbd.XkbLayout;
1656 break;
1657 }
1658 /* don't free di */
1659 }
1660
1661 xserver = get_xserver(hd_data, &version, &busid, &x11_driver);
1662
1663 switch(hd_mac_color(hd_data)) {
1664 case 0x01:
1665 yast2_color = 0x5a4add;
1666 break;
1667 case 0x04:
1668 yast2_color = 0x32cd32;
1669 break;
1670 case 0x05:
1671 yast2_color = 0xff7f50;
1672 break;
1673 case 0x07:
1674 yast2_color = 0x000000;
1675 break;
1676 case 0xff:
1677 yast2_color = 0x7f7f7f;
1678 break;
1679 }
1680
1681 if(hd_data->progress) {
1682 printf("\r%64s\r", "");
1683 fflush(stdout);
1684 }
1685
1686 sl0 = read_file(INSTALL_INF, 0, 0);
1687 f = fopen(INSTALL_INF, "w");
1688 if(!f) {
1689 perror(INSTALL_INF);
1690 return 1;
1691 }
1692
1693 for(sl = sl0; sl; sl = sl->next) {
1694 if(
1695 strstr(sl->str, "Framebuffer:") != sl->str &&
1696 strstr(sl->str, "XServer:") != sl->str &&
1697 strstr(sl->str, "XVersion:") != sl->str &&
1698 strstr(sl->str, "XBusID:") != sl->str &&
1699 strstr(sl->str, "X11i:") != sl->str &&
1700 strstr(sl->str, "Keyboard:") != sl->str &&
1701 strstr(sl->str, "XkbRules:") != sl->str &&
1702 strstr(sl->str, "XkbModel:") != sl->str &&
1703 strstr(sl->str, "XkbLayout:") != sl->str &&
1704 strstr(sl->str, "XF86Ext:") != sl->str &&
1705 strstr(sl->str, "XF86Raw:") != sl->str
1706 ) {
1707 fprintf(f, "%s", sl->str);
1708 }
1709 }
1710
1711 fprintf(f, "Keyboard: %d\n", kbd_ok);
1712 if(fb_mode) fprintf(f, "Framebuffer: 0x%04x\n", fb_mode);
1713 if(x11i) fprintf(f, "X11i: %s\n", x11i);
1714 if(xserver && *xserver) {
1715 fprintf(f, "XServer: %s\n", xserver);
1716 if(*version) fprintf(f, "XVersion: %s\n", version);
1717 if(*busid) fprintf(f, "XBusID: %s\n", busid);
1718 }
1719 if(xkbrules && *xkbrules) fprintf(f, "XkbRules: %s\n", xkbrules);
1720 if(xkbmodel && *xkbmodel) fprintf(f, "XkbModel: %s\n", xkbmodel);
1721 if(xkblayout && *xkblayout) fprintf(f, "XkbLayout: %s\n", xkblayout);
1722
1723 if(x11_driver) {
1724 for(sl = x11_driver->x11.extensions; sl; sl = sl->next) {
1725 if(*sl->str) fprintf(f, "XF86Ext: Load\t\t\"%s\"\n", sl->str);
1726 }
1727 for(sl = x11_driver->x11.options; sl; sl = sl->next) {
1728 if(*sl->str) fprintf(f, "XF86Raw: Option\t\"%s\"\n", sl->str);
1729 }
1730 for(sl = x11_driver->x11.raw; sl; sl = sl->next) {
1731 if(*sl->str) fprintf(f, "XF86Raw: %s\n", sl->str);
1732 }
1733 }
1734
1735 fclose(f);
1736
1737 return 0;
1738}
1739
1740
1741char *xserver3map[] =
1742{
1743#ifdef __i386__
1744 "VGA16", "xvga16",
1745 "RUSH", "xrush",
1746#endif
1747#if defined(__i386__) || defined(__alpha__) || defined(__ia64__)
1748 "SVGA", "xsvga",
1749 "3DLABS", "xglint",
1750#endif
1751#if defined(__i386__) || defined(__alpha__)
1752 "MACH64", "xmach64",
1753 "P9000", "xp9k",
1754 "S3", "xs3",
1755#endif
1756#ifdef __alpha__
1757 "TGA", "xtga",
1758#endif
1759#ifdef __sparc__
1760 "SUNMONO", "xsunmono",
1761 "SUN", "xsun",
1762 "SUN24", "xsun24",
1763#endif
1764#if 0
1765 "VMWARE", "xvmware",
1766#endif
1767 0, 0
1768};
1769
1770
1771void dump_packages(hd_data_t *hd_data)
1772{
1773 str_list_t *sl;
1774 int i;
1775
1776 hd_data->progress = NULL;
1777 hd_scan(hd_data);
1778
1779 sl = get_hddb_packages(hd_data);
1780
1781 for(i = 0; xserver3map[i]; i += 2) {
1782 if (!search_str_list(sl, xserver3map[i + 1]))
1783 add_str_list(&sl, new_str(xserver3map[i + 1]));
1784 }
1785
1786 for(; sl; sl = sl->next) {
1787 printf("%s\n", sl->str);
1788 }
1789}
1790
1791
1792struct x11pack {
1793 struct x11pack *next;
1794 char *pack;
1795};
1796
1797int oem_install_info(hd_data_t *hd_data)
1798{
1799 hd_t *hd;
1800 str_list_t *str;
1801 str_list_t *x11packs = 0;
1802 str_list_t *sl0, *sl;
1803 FILE *f;
1804 int pcmcia, i;
1805
1806 driver_info_x11_t *di, *drvinfo;
1807
1808 hd_set_probe_feature(hd_data, pr_pci);
1809 hd_scan(hd_data);
1810 pcmcia = hd_has_pcmcia(hd_data);
1811
1812 for(hd = hd_list(hd_data, hw_display, 1, NULL); hd; hd = hd->next) {
1813 for(str = hd->requires; str; str = str->next) {
1814 if(!search_str_list(x11packs, str->str)) {
1815 add_str_list(&x11packs, str->str);
1816 }
1817 }
1818 drvinfo = (driver_info_x11_t *) hd->driver_info;
1819 for (di = drvinfo; di; di = (driver_info_x11_t *)di->next) {
1820 if (di->type != di_x11)
1821 continue;
1822 if (di->xf86_ver[0] == '3') {
1823 char *server = di->server;
1824 if (server) {
1825 for (i = 0; xserver3map[i]; i += 2)
1826 if (!strcmp(xserver3map[i], server))
1827 break;
1828 if (xserver3map[i])
1829 if (!search_str_list(x11packs, xserver3map[i + 1]))
1830 add_str_list(&x11packs, xserver3map[i + 1]);
1831 }
1832 }
1833 }
1834 }
1835
1836 if(hd_data->progress) {
1837 printf("\r%64s\r", "");
1838 fflush(stdout);
1839 }
1840
1841 sl0 = read_file(INSTALL_INF, 0, 0);
1842 f = fopen(INSTALL_INF, "w");
1843 if(!f) {
1844 perror(INSTALL_INF);
1845 return 1;
1846 }
1847 for(sl = sl0; sl; sl = sl->next) {
1848 if(
1849 strstr(sl->str, "X11Packages:") != sl->str &&
1850 strstr(sl->str, "Pcmcia:") != sl->str
1851 ) {
1852 fprintf(f, "%s", sl->str);
1853 }
1854 }
1855 if (x11packs) {
1856 fprintf(f, "X11Packages: ");
1857 for (sl = x11packs; sl; sl = sl->next) {
1858 if (sl != x11packs)
1859 fputc(',', f);
1860 fprintf(f, "%s", sl->str);
1861 }
1862 fputc('\n', f);
1863 }
1864 if (pcmcia)
1865 fprintf(f, "Pcmcia: %d\n", pcmcia);
1866 fclose(f);
1867 return 0;
1868}
1869
1870
1871void dump_db_raw(hd_data_t *hd_data)
1872{
1873 hd_data->progress = NULL;
1874 hd_clear_probe_feature(hd_data, pr_all);
1875 hd_scan(hd_data);
1876
1877 if(opt.db_idx >= sizeof hd_data->hddb2 / sizeof *hd_data->hddb2) return;
1878
1879 hddb_dump_raw(hd_data->hddb2[opt.db_idx], stdout);
1880}
1881
1882
1883void dump_db(hd_data_t *hd_data)
1884{
1885 hd_data->progress = NULL;
1886 hd_clear_probe_feature(hd_data, pr_all);
1887 hd_scan(hd_data);
1888
1889 if(opt.db_idx >= sizeof hd_data->hddb2 / sizeof *hd_data->hddb2) return;
1890
1891 hddb_dump(hd_data->hddb2[opt.db_idx], stdout);
1892}
1893
1894
1895void do_chroot(hd_data_t *hd_data, char *dir)
1896{
1897 int i;
1898
1899 i = chroot(dir);
1900 ADD2LOG("chroot %s: %s\n", dir, i ? strerror(errno) : "ok");
1901
1902 if(!i) chdir("/");
1903}
1904
1905
1906void ask_db(hd_data_t *hd_data, char *query)
1907{
1908 hd_t *hd;
1909 driver_info_t *di;
1910 str_list_t *sl, *query_sl;
1911 unsigned tag = 0, u, cnt;
1912 char buf[256];
1913
1914 setenv("hwprobe", "-all", 1);
1915 hd_scan(hd_data);
1916
1917 hd = add_hd_entry(hd_data, __LINE__, 0);
1918
1919 query_sl = hd_split(' ', query);
1920
1921 for(sl = query_sl; sl; sl = sl->next) {
1922 if(!strcmp(sl->str, "pci")) { tag = TAG_PCI; continue; }
1923 if(!strcmp(sl->str, "usb")) { tag = TAG_USB; continue; }
1924 if(!strcmp(sl->str, "pnp")) { tag = TAG_EISA; continue; }
1925 if(!strcmp(sl->str, "isapnp")) { tag = TAG_EISA; continue; }
1926 if(!strcmp(sl->str, "special")) { tag = TAG_SPECIAL; continue; }
1927 if(!strcmp(sl->str, "pcmcia")) { tag = TAG_PCMCIA; continue; }
1928
1929 if(sscanf(sl->str, "class=%i%n", &u, &cnt) >= 1 && !sl->str[cnt]) {
1930 hd->base_class.id = u >> 16;
1931 hd->sub_class.id = (u >> 8) & 0xff;
1932 hd->prog_if.id = u & 0xff;
1933 continue;
1934 }
1935
1936 if(sscanf(sl->str, "vendor=%i%n", &u, &cnt) >= 1 && !sl->str[cnt]) {
1937 hd->vendor.id = MAKE_ID(tag, u);
1938 continue;
1939 }
1940
1941 if(sscanf(sl->str, "vendor=%3s%n", buf, &cnt) >= 1 && !sl->str[cnt]) {
1942 u = name2eisa_id(buf);
1943 if(u) hd->vendor.id = u;
1944 tag = TAG_EISA;
1945 continue;
1946 }
1947
1948 if(sscanf(sl->str, "device=%i%n", &u, &cnt) >= 1 && !sl->str[cnt]) {
1949 hd->device.id = MAKE_ID(tag, u);
1950 continue;
1951 }
1952
1953 if(sscanf(sl->str, "subvendor=%i%n", &u, &cnt) >= 1 && !sl->str[cnt]) {
1954 hd->sub_vendor.id = MAKE_ID(tag, u);
1955 continue;
1956 }
1957
1958 if(sscanf(sl->str, "subvendor=%3s%n", buf, &cnt) >= 1 && !sl->str[cnt]) {
1959 u = name2eisa_id(buf);
1960 if(u) hd->sub_vendor.id = u;
1961 tag = TAG_EISA;
1962 continue;
1963 }
1964
1965 if(sscanf(sl->str, "subdevice=%i%n", &u, &cnt) >= 1 && !sl->str[cnt]) {
1966 hd->sub_device.id = MAKE_ID(tag, u);
1967 continue;
1968 }
1969
1970 if(sscanf(sl->str, "revision=%i%n", &u, &cnt) >= 1 && !sl->str[cnt]) {
1971 hd->revision.id = u;
1972 continue;
1973 }
1974
1975 if(sscanf(sl->str, "serial=%255s%n", buf, &cnt) >= 1 && !sl->str[cnt]) {
1976 hd->serial = new_str(buf);
1977 continue;
1978 }
1979
1980 }
1981
1982 free_str_list(query_sl);
1983
1984 hddb_add_info(hd_data, hd);
1985
1986 for(di = hd->driver_info; di; di = di->next) {
1987 if(di->any.type == di_module && di->module.modprobe) {
1988 for(sl = di->module.names; sl; sl = sl->next) {
1989 printf("%s%c", sl->str, sl->next ? ' ' : '\n');
1990 }
1991 }
1992 }
1993}
1994
1995
1996int is_same_block_dev(hd_t *hd1, hd_t *hd2)
1997{
1998 if(!hd1 || !hd2 || hd1 == hd2) return 0;
1999
2000 if(
2001 hd1->base_class.id != hd2->base_class.id ||
2002 hd1->sub_class.id != hd2->sub_class.id
2003 ) return 0;
2004
2005 if(
2006 !hd1->model ||
2007 !hd2->model ||
2008 strcmp(hd1->model, hd2->model)
2009 ) return 0;
2010
2011 if(hd1->revision.name || hd2->revision.name) {
2012 if(
2013 !hd1->revision.name ||
2014 !hd2->revision.name ||
2015 strcmp(hd1->revision.name, hd2->revision.name)
2016 ) return 0;
2017 }
2018
2019 if(hd1->serial || hd2->serial) {
2020 if(
2021 !hd1->serial ||
2022 !hd2->serial ||
2023 strcmp(hd1->serial, hd2->serial)
2024 ) return 0;
2025 }
2026
2027 return 1;
2028}
2029
2030
2031hd_t *get_same_block_dev(hd_t *hd_list, hd_t *hd, hd_status_value_t status)
2032{
2033 for(; hd_list; hd_list = hd_list->next) {
2034 if(hd_list->status.available != status) continue;
2035 if(is_same_block_dev(hd_list, hd)) return hd_list;
2036 }
2037
2038 return NULL;
2039}
2040
2041
2042void get_mapping(hd_data_t *hd_data)
2043{
2044 hd_t *hd_manual, *hd, *hd2;
2045 struct {
2046 hd_t *hd;
2047 unsigned unknown:1;
2048 } map[256] = { };
2049 unsigned maps = 0, u;
2050 int broken, first;
2051 hd_hw_item_t hw_items[] = { hw_disk, hw_cdrom, 0 };
2052
2053 hd_data->progress = NULL;
2054
2055 hd_data->flags.list_all = 1;
2056
2057 hd_manual = hd_list2(hd_data, hw_items, 1);
2058 for(hd = hd_manual; hd && maps < sizeof map / sizeof *map; hd = hd->next) {
2059 if(!hd->unix_dev_name) continue;
2060
2061 if(hd->status.available == status_yes) {
2062 /* check if we already have an active device with the same name */
2063 for(broken = u = 0; u < maps; u++) {
2064 if(!strcmp(map[u].hd->unix_dev_name, hd->unix_dev_name)) {
2065 map[u].unknown = 1;
2066 broken = 1;
2067 }
2068 }
2069 if(broken) continue;
2070
2071 /* ensure we really can tell different devices apart */
2072 if(get_same_block_dev(hd_manual, hd, status_yes)) {
2073 map[maps].hd = hd;
2074 map[maps].unknown = 1;
2075 }
2076 else {
2077 map[maps].hd = hd;
2078 }
2079 maps++;
2080 }
2081 }
2082
2083 /* ok, we have a list of all new devs */
2084
2085 for(u = 0; u < maps; u++) {
2086 if(map[u].unknown) {
2087 printf("%s\n", map[u].hd->unix_dev_name);
2088 }
2089 else {
2090 first = 1;
2091 for(hd2 = hd_manual; (hd2 = get_same_block_dev(hd2, map[u].hd, status_no)); hd2 = hd2->next) {
2092 if(hd2->unix_dev_name && strcmp(map[u].hd->unix_dev_name, hd2->unix_dev_name)) {
2093 printf("%s\t%s", first ? map[u].hd->unix_dev_name : "", hd2->unix_dev_name);
2094 first = 0;
2095 }
2096 }
2097 if(!first) printf("\n");
2098 }
2099
2100 }
2101
2102}
2103