1 Star 0 Fork 25

dashnfschina/util-linux

forked from src-anolis-os/util-linux 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0052-lscpu-dmi-split-to-parse-dmi-table.patch 2.99 KB
一键复制 编辑 原始数据 按行查看 历史
From 60a1a900b22e6d714fbbde03322569ad4732b4ba Mon Sep 17 00:00:00 2001
From: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
Date: Fri, 11 Sep 2020 09:53:26 -0400
Subject: [PATCH 52/55] lscpu-dmi: split to parse dmi table
Split out a function to parse dmi table.
Signed-off-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
---
sys-utils/lscpu-dmi.c | 60 ++++++++++++++++++++++++++++---------------
1 file changed, 40 insertions(+), 20 deletions(-)
diff --git a/sys-utils/lscpu-dmi.c b/sys-utils/lscpu-dmi.c
index 29bd2e4fc..9b57fe9e6 100644
--- a/sys-utils/lscpu-dmi.c
+++ b/sys-utils/lscpu-dmi.c
@@ -42,6 +42,12 @@ struct dmi_header
uint8_t *data;
};
+struct dmi_info {
+ char *vendor;
+ char *product;
+ char *manufacturer;
+};
+
static int checksum(const uint8_t *buf, size_t len)
{
uint8_t sum = 0;
@@ -105,20 +111,13 @@ static char *dmi_string(const struct dmi_header *dm, uint8_t s)
return bp;
}
-static int hypervisor_from_dmi_table(uint32_t base, uint16_t len,
- uint16_t num, const char *devmem)
+static int parse_dmi_table(uint16_t len, uint16_t num,
+ uint8_t *data,
+ struct dmi_info *di)
{
- uint8_t *buf;
- uint8_t *data;
+ uint8_t *buf = data;
+ int rc = -1;
int i = 0;
- char *vendor = NULL;
- char *product = NULL;
- char *manufacturer = NULL;
- int rc = HYPER_NONE;
-
- data = buf = get_mem_chunk(base, len, devmem);
- if (!buf)
- goto done;
/* 4 is the length of an SMBIOS structure header */
while (i < num && data + 4 <= buf + len) {
@@ -142,11 +141,11 @@ static int hypervisor_from_dmi_table(uint32_t base, uint16_t len,
next += 2;
switch (h.type) {
case 0:
- vendor = dmi_string(&h, data[0x04]);
+ di->vendor = dmi_string(&h, data[0x04]);
break;
case 1:
- manufacturer = dmi_string(&h, data[0x04]);
- product = dmi_string(&h, data[0x05]);
+ di->manufacturer = dmi_string(&h, data[0x04]);
+ di->product = dmi_string(&h, data[0x05]);
break;
default:
break;
@@ -155,15 +154,36 @@ static int hypervisor_from_dmi_table(uint32_t base, uint16_t len,
data = next;
i++;
}
- if (manufacturer && !strcmp(manufacturer, "innotek GmbH"))
+ rc = 0;
+done:
+ return rc;
+}
+
+static int hypervisor_from_dmi_table(uint32_t base, uint16_t len,
+ uint16_t num, const char *devmem)
+{
+ uint8_t *data;
+ int rc = HYPER_NONE;
+ struct dmi_info di;
+
+ data = get_mem_chunk(base, len, devmem);
+ if (!data)
+ return rc;
+
+ memset(&di, 0, sizeof(struct dmi_info));
+ rc = parse_dmi_table(len, num, data, &di);
+ if (rc < 0)
+ goto done;
+
+ if (di.manufacturer && !strcmp(di.manufacturer, "innotek GmbH"))
rc = HYPER_INNOTEK;
- else if (manufacturer && strstr(manufacturer, "HITACHI") &&
- product && strstr(product, "LPAR"))
+ else if (di.manufacturer && strstr(di.manufacturer, "HITACHI") &&
+ di.product && strstr(di.product, "LPAR"))
rc = HYPER_HITACHI;
- else if (vendor && !strcmp(vendor, "Parallels"))
+ else if (di.vendor && !strcmp(di.vendor, "Parallels"))
rc = HYPER_PARALLELS;
done:
- free(buf);
+ free(data);
return rc;
}
--
2.29.2
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/dashnfschina/util-linux.git
git@gitee.com:dashnfschina/util-linux.git
dashnfschina
util-linux
util-linux
a8

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385