mirror of
https://git.proxmox.com/git/fwupd
synced 2025-08-14 14:22:13 +00:00
trivial: Add fu_smbios_get_integer() helper
This commit is contained in:
parent
f2a3e01f96
commit
9f93b8bc66
@ -280,21 +280,10 @@ fu_hwids_convert_padded_integer_cb (FuSmbios *smbios,
|
|||||||
guint8 type, guint8 offset,
|
guint8 type, guint8 offset,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
g_autoptr(GBytes) data = NULL;
|
guint tmp = fu_smbios_get_integer (smbios, type, offset, error);
|
||||||
const guint8 *data_raw;
|
if (tmp == G_MAXUINT)
|
||||||
gsize data_sz = 0;
|
|
||||||
data = fu_smbios_get_data (smbios, type, error);
|
|
||||||
if (data == NULL)
|
|
||||||
return NULL;
|
return NULL;
|
||||||
data_raw = g_bytes_get_data (data, &data_sz);
|
return g_strdup_printf ("%02x", tmp);
|
||||||
if (offset >= data_sz) {
|
|
||||||
g_set_error_literal (error,
|
|
||||||
FWUPD_ERROR,
|
|
||||||
FWUPD_ERROR_INVALID_FILE,
|
|
||||||
"offset bigger than data");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return g_strdup_printf ("%02x", data_raw[offset]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gchar *
|
static gchar *
|
||||||
@ -302,21 +291,10 @@ fu_hwids_convert_integer_cb (FuSmbios *smbios,
|
|||||||
guint8 type, guint8 offset,
|
guint8 type, guint8 offset,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
g_autoptr(GBytes) data = NULL;
|
guint tmp = fu_smbios_get_integer (smbios, type, offset, error);
|
||||||
const guint8 *data_raw;
|
if (tmp == G_MAXUINT)
|
||||||
gsize data_sz = 0;
|
|
||||||
data = fu_smbios_get_data (smbios, type, error);
|
|
||||||
if (data == NULL)
|
|
||||||
return NULL;
|
return NULL;
|
||||||
data_raw = g_bytes_get_data (data, &data_sz);
|
return g_strdup_printf ("%x", tmp);
|
||||||
if (offset >= data_sz) {
|
|
||||||
g_set_error_literal (error,
|
|
||||||
FWUPD_ERROR,
|
|
||||||
FWUPD_ERROR_INVALID_FILE,
|
|
||||||
"offset bigger than data");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return g_strdup_printf ("%x", data_raw[offset]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -502,6 +502,53 @@ fu_smbios_get_data (FuSmbios *self, guint8 type, GError **error)
|
|||||||
return g_bytes_new (item->buf->data, item->buf->len);
|
return g_bytes_new (item->buf->data, item->buf->len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* fu_smbios_get_integer:
|
||||||
|
* @self: A #FuSmbios
|
||||||
|
* @type: A structure type, e.g. %FU_SMBIOS_STRUCTURE_TYPE_BIOS
|
||||||
|
* @offset: A structure offset
|
||||||
|
* @error: A #GError or %NULL
|
||||||
|
*
|
||||||
|
* Reads an integer value from the SMBIOS string table of a specific structure.
|
||||||
|
*
|
||||||
|
* The @type and @offset can be referenced from the DMTF SMBIOS specification:
|
||||||
|
* https://www.dmtf.org/sites/default/files/standards/documents/DSP0134_3.1.1.pdf
|
||||||
|
*
|
||||||
|
* Returns: an integer, or %G_MAXUINT if invalid or not found
|
||||||
|
*
|
||||||
|
* Since: 1.5.0
|
||||||
|
**/
|
||||||
|
guint
|
||||||
|
fu_smbios_get_integer (FuSmbios *self, guint8 type, guint8 offset, GError **error)
|
||||||
|
{
|
||||||
|
FuSmbiosItem *item;
|
||||||
|
|
||||||
|
g_return_val_if_fail (FU_IS_SMBIOS (self), 0);
|
||||||
|
|
||||||
|
/* get item */
|
||||||
|
item = fu_smbios_get_item_for_type (self, type);
|
||||||
|
if (item == NULL) {
|
||||||
|
g_set_error (error,
|
||||||
|
FWUPD_ERROR,
|
||||||
|
FWUPD_ERROR_INVALID_FILE,
|
||||||
|
"no structure with type %02x", type);
|
||||||
|
return G_MAXUINT;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* check offset valid */
|
||||||
|
if (offset >= item->buf->len) {
|
||||||
|
g_set_error (error,
|
||||||
|
FWUPD_ERROR,
|
||||||
|
FWUPD_ERROR_INVALID_FILE,
|
||||||
|
"offset bigger than size %u",
|
||||||
|
item->buf->len);
|
||||||
|
return G_MAXUINT;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* success */
|
||||||
|
return item->buf->data[offset];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* fu_smbios_get_string:
|
* fu_smbios_get_string:
|
||||||
* @self: A #FuSmbios
|
* @self: A #FuSmbios
|
||||||
|
@ -26,6 +26,10 @@ const gchar *fu_smbios_get_string (FuSmbios *self,
|
|||||||
guint8 type,
|
guint8 type,
|
||||||
guint8 offset,
|
guint8 offset,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
guint fu_smbios_get_integer (FuSmbios *self,
|
||||||
|
guint8 type,
|
||||||
|
guint8 offset,
|
||||||
|
GError **error);
|
||||||
GBytes *fu_smbios_get_data (FuSmbios *self,
|
GBytes *fu_smbios_get_data (FuSmbios *self,
|
||||||
guint8 type,
|
guint8 type,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
@ -654,6 +654,7 @@ LIBFWUPDPLUGIN_1.5.0 {
|
|||||||
fu_security_attrs_new;
|
fu_security_attrs_new;
|
||||||
fu_security_attrs_remove_all;
|
fu_security_attrs_remove_all;
|
||||||
fu_security_attrs_to_variant;
|
fu_security_attrs_to_variant;
|
||||||
|
fu_smbios_get_integer;
|
||||||
fu_udev_device_get_number;
|
fu_udev_device_get_number;
|
||||||
fu_udev_device_get_subsystem_model;
|
fu_udev_device_get_subsystem_model;
|
||||||
fu_udev_device_get_subsystem_vendor;
|
fu_udev_device_get_subsystem_vendor;
|
||||||
|
Loading…
Reference in New Issue
Block a user