Add a new vfunc to check if two firmwares are compatible

For future use.
This commit is contained in:
Richard Hughes 2022-08-25 14:50:40 +01:00
parent e12b46b991
commit a5397c6836
3 changed files with 42 additions and 1 deletions

View File

@ -772,6 +772,37 @@ fu_firmware_tokenize(FuFirmware *self, GBytes *fw, FwupdInstallFlags flags, GErr
return TRUE; return TRUE;
} }
/**
* fu_firmware_check_compatible:
* @self: a #FuFirmware
* @other: a #FuFirmware
* @flags: install flags, e.g. %FWUPD_INSTALL_FLAG_FORCE
* @error: (nullable): optional return location for an error
*
* Check a new firmware is compatible with the existing firmware.
*
* Returns: %TRUE for success
*
* Since: 1.8.4
**/
gboolean
fu_firmware_check_compatible(FuFirmware *self,
FuFirmware *other,
FwupdInstallFlags flags,
GError **error)
{
FuFirmwareClass *klass = FU_FIRMWARE_GET_CLASS(self);
g_return_val_if_fail(FU_IS_FIRMWARE(self), FALSE);
g_return_val_if_fail(FU_IS_FIRMWARE(other), FALSE);
g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
/* optionally subclassed */
if (klass->check_compatible == NULL)
return TRUE;
return klass->check_compatible(self, other, flags, error);
}
static gboolean static gboolean
fu_firmware_check_magic_for_offset(FuFirmware *self, fu_firmware_check_magic_for_offset(FuFirmware *self,
GBytes *fw, GBytes *fw,

View File

@ -63,8 +63,12 @@ struct _FuFirmwareClass {
GChecksumType csum_kind, GChecksumType csum_kind,
GError **error)G_GNUC_WARN_UNUSED_RESULT; GError **error)G_GNUC_WARN_UNUSED_RESULT;
gboolean (*check_magic)(FuFirmware *self, GBytes *fw, gsize offset, GError **error); gboolean (*check_magic)(FuFirmware *self, GBytes *fw, gsize offset, GError **error);
gboolean (*check_compatible)(FuFirmware *self,
FuFirmware *other,
FwupdInstallFlags flags,
GError **error);
/*< private >*/ /*< private >*/
gpointer padding[25]; gpointer padding[24];
}; };
/** /**
@ -292,6 +296,11 @@ gboolean
fu_firmware_write_file(FuFirmware *self, GFile *file, GError **error) G_GNUC_WARN_UNUSED_RESULT; fu_firmware_write_file(FuFirmware *self, GFile *file, GError **error) G_GNUC_WARN_UNUSED_RESULT;
gchar * gchar *
fu_firmware_get_checksum(FuFirmware *self, GChecksumType csum_kind, GError **error); fu_firmware_get_checksum(FuFirmware *self, GChecksumType csum_kind, GError **error);
gboolean
fu_firmware_check_compatible(FuFirmware *self,
FuFirmware *other,
FwupdInstallFlags flags,
GError **error);
void void
fu_firmware_add_image(FuFirmware *self, FuFirmware *img); fu_firmware_add_image(FuFirmware *self, FuFirmware *img);

View File

@ -1086,6 +1086,7 @@ LIBFWUPDPLUGIN_1.8.4 {
fu_context_get_bios_settings; fu_context_get_bios_settings;
fu_context_reload_bios_settings; fu_context_reload_bios_settings;
fu_device_security_attr_new; fu_device_security_attr_new;
fu_firmware_check_compatible;
fu_plugin_add_string; fu_plugin_add_string;
fu_plugin_security_attr_new; fu_plugin_security_attr_new;
fu_plugin_to_string; fu_plugin_to_string;