]>
git.ipfire.org Git - ipfire-2.x.git/blob - src/hwinfo/src/hd/sys.c
1 #define _GNU_SOURCE /* we want memmem() */
16 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
19 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
23 static void sigsegv_handler(int signum
);
24 static void chk_vmware(hd_data_t
*hd_data
, sys_info_t
*st
);
27 #if defined(__i386__) || defined(__x86_64__)
28 static int is_txt(char c
);
29 static int is_decimal(char c
);
30 static int txt_len(char *s
);
31 static int decimal_len(char *s
);
32 static int chk_vaio(hd_data_t
*hd_data
, sys_info_t
*st
);
34 void *memmem(const void *haystack
, size_t haystacklen
, const void *needle
, size_t needlelen
);
38 void hd_scan_sys(hd_data_t
*hd_data
)
42 #if defined(__PPC__) || defined(__sparc__)
43 char buf0
[80], *s
, *t
;
47 if(!hd_probe_feature(hd_data
, pr_sys
)) return;
49 hd_data
->module
= mod_sys
;
52 remove_hd_entries(hd_data
);
54 PROGRESS(1, 0, "cpu");
56 hd
= add_hd_entry(hd_data
, __LINE__
, 0);
57 hd
->base_class
.id
= bc_internal
;
58 hd
->sub_class
.id
= sc_int_sys
;
59 hd
->detail
= new_mem(sizeof *hd
->detail
);
60 hd
->detail
->type
= hd_detail_sys
;
61 hd
->detail
->sys
.data
= st
= new_mem(sizeof *st
);
64 hd_data
->cpu
= read_file(PROC_CPUINFO
, 0, 0);
68 for(sl
= hd_data
->cpu
; sl
; sl
= sl
->next
) {
69 if(sscanf(sl
->str
, "motherboard : %79[^\n]", buf0
) == 1) {
70 if((s
= strstr(buf0
, "MacRISC"))) {
71 for(t
= s
+ sizeof "MacRISC" - 1; isalnum(*t
); t
++);
73 st
->system_type
= new_str(s
);
74 hd_data
->flags
.no_parport
= 1;
77 if(sscanf(sl
->str
, "machine : %79[^\n]", buf0
) == 1) {
78 if(strstr(buf0
, "PReP")) {
79 st
->system_type
= new_str("PReP");
81 else if(strstr(buf0
, "CHRP")) {
82 st
->system_type
= new_str(/* is_64 ? "CHRP64" : */ "CHRP");
84 else if(strstr(buf0
, "iSeries")) {
85 st
->system_type
= new_str("iSeries");
86 hd_data
->flags
.iseries
= 1;
88 if(strstr(buf0
, "PowerBook2,")) {
89 st
->model
= new_str("iBook");
91 else if(strstr(buf0
, "PowerBook")) {
92 st
->model
= new_str("PowerBook");
95 if(sscanf(sl
->str
, "pmac-generation : %79[^\n]", buf0
) == 1) {
96 st
->generation
= new_str(buf0
);
102 for(sl
= hd_data
->cpu
; sl
; sl
= sl
->next
) {
103 if(sscanf(sl
->str
, "type : %79[^\n]", buf0
) == 1) {
104 st
->system_type
= new_str(buf0
);
109 #if defined(__i386__) || defined(__x86_64__)
110 chk_vaio(hd_data
, st
);
113 #if defined(__i386__)
114 chk_vmware(hd_data
, st
);
117 if(st
->vendor
) hd
->vendor
.name
= new_str(st
->vendor
);
118 if(st
->model
) hd
->device
.name
= new_str(st
->model
);
119 if(st
->serial
) hd
->serial
= new_str(st
->serial
);
122 #if defined(__i386__)
123 void sigsegv_handler(int signum
) { exit(77); }
125 void chk_vmware(hd_data_t
*hd_data
, sys_info_t
*st
)
127 static int is_vmware
= -1;
130 /* do the check only once */
136 signal(SIGSEGV
, sigsegv_handler
);
143 "\tmov $0x564d5868,%eax\n"
145 "\tmov $0x5658,%edx\n"
156 if(waitpid(child
, &status
, 0) == child
) {
157 status
= WEXITSTATUS(status
);
158 if(status
== 66) is_vmware
= 1;
159 if(status
== 77) is_vmware
= 0;
163 ADD2LOG(" vmware check: %d\n", is_vmware
);
167 st
->model
= new_str("VMWare");
170 hd_data
->in_vmware
= is_vmware
;
173 #endif /* __i386__ */
176 #if defined(__i386__) || defined(__x86_64__)
179 if(c
< ' ' || c
== 0x7f) return 0;
184 int is_decimal(char c
)
186 if(c
< '0' || c
> '9') return 0;
195 for(i
= 0; i
< 0x100; i
++) {
196 if(!is_txt(s
[i
])) break;
202 int decimal_len(char *s
)
206 for(i
= 0; i
< 0x100; i
++) {
207 if(!is_decimal(s
[i
])) break;
213 int chk_vaio(hd_data_t
*hd_data
, sys_info_t
*st
)
216 unsigned char *data
, *s
, *s0
, *s1
;
218 if(!hd_data
->bios_rom
.data
) return 0;
220 data
= hd_data
->bios_rom
.data
+ 0xe8000 - hd_data
->bios_rom
.start
;
222 if(!(s
= memmem(data
, 0x10000, "Sony Corp", sizeof "Sony Corp" - 1))) return 0;
224 if((i
= txt_len(s
))) st
->vendor
= canon_str(s
, i
);
227 if(!(s
= memmem(s
, 0x1000, "PCG-", sizeof "PCG-" - 1))) return 0;
229 if((i
= txt_len(s
))) {
230 st
->model
= canon_str(s
, i
);
234 ADD2LOG(" vaio: %s\n", st
->model
);
236 for(i
= 0; i
< 0x1000; i
++) {
237 if(is_decimal(s
[i
]) && txt_len(s
+ i
) >= 10 && decimal_len(s
+ i
) >= 5) {
238 st
->serial
= canon_str(s
+ i
, txt_len(s
+ i
));
244 s0
= strrchr(st
->model
, '(');
245 s1
= strrchr(st
->model
, ')');
247 if(s0
&& s1
&& s1
- s0
>= 3 && s1
[1] == 0) {
248 st
->lang
= canon_str(s0
+ 1, s1
- s0
- 1);
249 for(s
= st
->lang
; *s
; s
++) {
250 if(*s
>= 'A' && *s
<= 'Z') *s
+= 'a' - 'A';
252 if(!strcmp(st
->lang
, "uc")) strcpy(st
->lang
, "en");
253 *s0
= 0; /* cut the model entry */
257 return st
->model
? 1 : 0;
259 #endif /* __i386__ || __x86_64__ */