]>
git.ipfire.org Git - thirdparty/util-linux.git/blob - sys-utils/lscpu-dmi.c
1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2020 FUJITSU LIMITED. All rights reserved.
8 void to_dmi_header(struct lscpu_dmi_header
*h
, uint8_t *data
)
12 memcpy(&h
->handle
, data
+ 2, sizeof(h
->handle
));
16 char *dmi_string(const struct lscpu_dmi_header
*dm
, uint8_t s
)
18 char *bp
= (char *)dm
->data
;
24 while (s
> 1 && *bp
) {
30 return !*bp
? NULL
: bp
;
33 int parse_dmi_table(uint16_t len
, uint16_t num
,
41 /* 4 is the length of an SMBIOS structure header */
42 while (i
< num
&& data
+ 4 <= buf
+ len
) {
44 struct lscpu_dmi_header h
;
46 to_dmi_header(&h
, data
);
49 * If a short entry is found (less than 4 bytes), not only it
50 * is invalid, but we cannot reliably locate the next entry.
51 * Better stop at this point.
56 /* look for the next handle */
57 next
= data
+ h
.length
;
58 while (next
- buf
+ 1 < len
&& (next
[0] != 0 || next
[1] != 0))
63 di
->vendor
= dmi_string(&h
, data
[0x04]);
66 di
->manufacturer
= dmi_string(&h
, data
[0x04]);
67 di
->product
= dmi_string(&h
, data
[0x05]);
84 size_t get_number_of_physical_sockets_from_dmi(void)
86 static char const sys_fw_dmi_tables
[] = _PATH_SYS_DMI
;
92 if (stat(sys_fw_dmi_tables
, &st
))
95 data
= get_mem_chunk(0, st
.st_size
, sys_fw_dmi_tables
);
99 memset(&di
, 0, sizeof(struct dmi_info
));
100 rc
= parse_dmi_table(st
.st_size
, st
.st_size
/4, data
, &di
);
104 if ((rc
< 0) || !di
.sockets
)