Coverage Report

Created: 2026-08-15 06:58

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/fwupd/libfwupdplugin/fu-hwids-dmi.c
Line
Count
Source
1
/*
2
 * Copyright 2021 Richard Hughes <richard@hughsie.com>
3
 *
4
 * SPDX-License-Identifier: LGPL-2.1-or-later
5
 */
6
7
0
#define G_LOG_DOMAIN "FuContext"
8
9
#include "config.h"
10
11
#include "fu-context-private.h"
12
#include "fu-hwids-private.h"
13
#include "fu-path.h"
14
#include "fu-smbios-struct.h"
15
#include "fu-string.h"
16
17
gboolean
18
fu_hwids_dmi_setup(FuContext *ctx, FuHwids *self, GError **error)
19
0
{
20
0
  const gchar *path;
21
0
  struct {
22
0
    const gchar *hwid;
23
0
    const gchar *key;
24
0
  } map[] = {{FU_HWIDS_KEY_BASEBOARD_MANUFACTURER, "board_vendor"},
25
0
       {FU_HWIDS_KEY_BASEBOARD_PRODUCT, "board_name"},
26
0
       {FU_HWIDS_KEY_BIOS_VENDOR, "bios_vendor"},
27
0
       {FU_HWIDS_KEY_BIOS_VERSION, "bios_version"},
28
0
       {FU_HWIDS_KEY_BIOS_RELEASE_DATE, "bios_date"},
29
0
       {FU_HWIDS_KEY_FAMILY, "product_family"},
30
0
       {FU_HWIDS_KEY_MANUFACTURER, "sys_vendor"},
31
0
       {FU_HWIDS_KEY_PRODUCT_NAME, "product_name"},
32
0
       {FU_HWIDS_KEY_PRODUCT_SKU, "product_sku"},
33
0
       {FU_HWIDS_KEY_ENCLOSURE_KIND, "chassis_type"},
34
0
       {NULL, NULL}};
35
36
  /* the values the kernel parsed; these are world-readable */
37
0
  path = fu_context_get_path(ctx, FU_PATH_KIND_SYSFSDIR_DMI, error);
38
0
  if (path == NULL)
39
0
    return FALSE;
40
0
  if (!g_file_test(path, G_FILE_TEST_IS_DIR)) {
41
0
    g_set_error(error, FWUPD_ERROR, FWUPD_ERROR_NOT_SUPPORTED, "no %s", path);
42
0
    return FALSE;
43
0
  }
44
0
  for (guint i = 0; map[i].key != NULL; i++) {
45
0
    gsize bufsz = 0;
46
0
    g_autofree gchar *buf = NULL;
47
0
    g_autofree gchar *fn = g_build_filename(path, map[i].key, NULL);
48
0
    g_autoptr(GError) error_local = NULL;
49
50
0
    if (!g_file_get_contents(fn, &buf, &bufsz, &error_local)) {
51
0
      g_debug("unable to read SMBIOS data from %s: %s", fn, error_local->message);
52
0
      continue;
53
0
    }
54
0
    if (bufsz == 0)
55
0
      continue;
56
57
    /* trim trailing newline added by kernel */
58
0
    if (buf[bufsz - 1] == '\n')
59
0
      buf[bufsz - 1] = 0;
60
0
    fu_hwids_add_value(self, map[i].hwid, buf);
61
62
0
    if (g_strcmp0(map[i].hwid, FU_HWIDS_KEY_ENCLOSURE_KIND) == 0) {
63
0
      guint64 val = 0;
64
0
      if (!fu_strtoull(buf,
65
0
           &val,
66
0
           FU_SMBIOS_CHASSIS_KIND_OTHER,
67
0
           FU_SMBIOS_CHASSIS_KIND_LAST,
68
0
           FU_INTEGER_BASE_AUTO,
69
0
           &error_local)) {
70
0
        g_warning("ignoring enclosure kind %s", buf);
71
0
        continue;
72
0
      }
73
0
      fu_context_set_chassis_kind(ctx, val);
74
0
    }
75
0
  }
76
77
  /* success */
78
0
  return TRUE;
79
0
}