mirror of
https://git.proxmox.com/git/fwupd
synced 2025-08-06 10:26:17 +00:00
trivial: Add fu_firmware_parse_file() helper for future use
This commit is contained in:
parent
341ab10808
commit
f591a3594b
@ -121,6 +121,31 @@ fu_firmware_parse (FuFirmware *self, GBytes *fw, FwupdInstallFlags flags, GError
|
||||
return fu_firmware_parse_full (self, fw, 0x0, 0x0, flags, error);
|
||||
}
|
||||
|
||||
/**
|
||||
* fu_firmware_parse_file:
|
||||
* @self: A #FuFirmware
|
||||
* @file: A #GFile
|
||||
* @flags: some #FwupdInstallFlags, e.g. %FWUPD_INSTALL_FLAG_FORCE
|
||||
* @error: A #GError, or %NULL
|
||||
*
|
||||
* Parses a firmware file, typically breaking the firmware into images.
|
||||
*
|
||||
* Returns: %TRUE for success
|
||||
*
|
||||
* Since: 1.3.3
|
||||
**/
|
||||
gboolean
|
||||
fu_firmware_parse_file (FuFirmware *self, GFile *file, FwupdInstallFlags flags, GError **error)
|
||||
{
|
||||
gchar *buf = NULL;
|
||||
gsize bufsz = 0;
|
||||
g_autoptr(GBytes) fw = NULL;
|
||||
if (!g_file_load_contents (file, NULL, &buf, &bufsz, NULL, error))
|
||||
return FALSE;
|
||||
fw = g_bytes_new_take (buf, bufsz);
|
||||
return fu_firmware_parse (self, fw, flags, error);
|
||||
}
|
||||
|
||||
/**
|
||||
* fu_firmware_write:
|
||||
* @self: A #FuFirmware
|
||||
@ -148,6 +173,33 @@ fu_firmware_write (FuFirmware *self, GError **error)
|
||||
return fu_firmware_get_image_default_bytes (self, error);
|
||||
}
|
||||
|
||||
/**
|
||||
* fu_firmware_write_file:
|
||||
* @self: A #FuFirmware
|
||||
* @file: A #GFile
|
||||
* @error: A #GError, or %NULL
|
||||
*
|
||||
* Writes a firmware, typically packing the images into a binary blob.
|
||||
*
|
||||
* Returns: %TRUE for success
|
||||
*
|
||||
* Since: 1.3.3
|
||||
**/
|
||||
gboolean
|
||||
fu_firmware_write_file (FuFirmware *self, GFile *file, GError **error)
|
||||
{
|
||||
g_autoptr(GBytes) blob = NULL;
|
||||
blob = fu_firmware_write (self, error);
|
||||
if (blob == NULL)
|
||||
return FALSE;
|
||||
return g_file_replace_contents (file,
|
||||
g_bytes_get_data (blob, NULL),
|
||||
g_bytes_get_size (blob),
|
||||
NULL, FALSE,
|
||||
G_FILE_CREATE_NONE,
|
||||
NULL, NULL, error);
|
||||
}
|
||||
|
||||
/**
|
||||
* fu_firmware_add_image:
|
||||
* @self: a #FuPlugin
|
||||
|
@ -48,6 +48,10 @@ gboolean fu_firmware_parse (FuFirmware *self,
|
||||
GBytes *fw,
|
||||
FwupdInstallFlags flags,
|
||||
GError **error);
|
||||
gboolean fu_firmware_parse_file (FuFirmware *self,
|
||||
GFile *file,
|
||||
FwupdInstallFlags flags,
|
||||
GError **error);
|
||||
gboolean fu_firmware_parse_full (FuFirmware *self,
|
||||
GBytes *fw,
|
||||
guint64 addr_start,
|
||||
@ -56,6 +60,9 @@ gboolean fu_firmware_parse_full (FuFirmware *self,
|
||||
GError **error);
|
||||
GBytes *fu_firmware_write (FuFirmware *self,
|
||||
GError **error);
|
||||
gboolean fu_firmware_write_file (FuFirmware *self,
|
||||
GFile *file,
|
||||
GError **error);
|
||||
|
||||
void fu_firmware_add_image (FuFirmware *self,
|
||||
FuFirmwareImage *image);
|
||||
|
Loading…
Reference in New Issue
Block a user