fu-common

fu-common — common functionality for plugins to use

Functions

Description

Helper functions that can be used by the daemon and plugins.

See also: FuPlugin

Functions

FuOutputHandler ()

void
(*FuOutputHandler) (const gchar *line,
                    gpointer user_data);

fu_common_spawn_sync ()

gboolean
fu_common_spawn_sync (const gchar * const *argv,
                      FuOutputHandler handler_cb,
                      gpointer handler_user_data,
                      GCancellable *cancellable,
                      GError **error);

Runs a subprocess and waits for it to exit. Any output on standard out or standard error will be forwarded to handler_cb as whole lines.

Parameters

argv

The argument list to run

 

handler_cb

A FuOutputHandler or NULL.

[scope call]

handler_user_data

the user data to pass to handler_cb

 

cancellable

a GCancellable, or NULL

 

error

A GError or NULL

 

Returns

TRUE for success


fu_common_rmtree ()

gboolean
fu_common_rmtree (const gchar *directory,
                  GError **error);

Recursively removes a directory.

Parameters

directory

a directory name

 

error

A GError or NULL

 

Returns

TRUE for success, FALSE otherwise


fu_common_mkdir_parent ()

gboolean
fu_common_mkdir_parent (const gchar *filename,
                        GError **error);

Creates any required directories, including any parent directories.

Parameters

filename

A full pathname

 

error

A GError, or NULL

 

Returns

TRUE for success


fu_common_set_contents_bytes ()

gboolean
fu_common_set_contents_bytes (const gchar *filename,
                              GBytes *bytes,
                              GError **error);

Writes a blob of data to a filename, creating the parent directories as required.

Parameters

filename

A filename

 

bytes

The data to write

 

error

A GError, or NULL

 

Returns

TRUE for success


fu_common_get_contents_bytes ()

GBytes *
fu_common_get_contents_bytes (const gchar *filename,
                              GError **error);

Reads a blob of data from a file.

Parameters

filename

A filename

 

error

A GError, or NULL

 

Returns

a GBytes, or NULL for failure


fu_common_get_contents_fd ()

GBytes *
fu_common_get_contents_fd (gint fd,
                           gsize count,
                           GError **error);

Reads a blob from a specific file descriptor.

Note: this will close the fd when done

Parameters

fd

A file descriptor

 

count

The maximum number of bytes to read

 

error

A GError, or NULL

 

Returns

a GBytes, or NULL.

[transfer full]


fu_common_extract_archive ()

gboolean
fu_common_extract_archive (GBytes *blob,
                           const gchar *dir,
                           GError **error);

Extracts an achive to a directory.

Parameters

blob

a GBytes archive as a blob

 

dir

a directory name to extract to

 

error

A GError, or NULL

 

Returns

TRUE for success


fu_common_firmware_builder ()

GBytes *
fu_common_firmware_builder (GBytes *bytes,
                            const gchar *script_fn,
                            const gchar *output_fn,
                            GError **error);

Builds a firmware file using tools from the host session in a bubblewrap jail. Several things happen during build:

  1. The bytes data is untarred to a temporary location

  2. A bubblewrap container is set up

  3. The startup.sh script is run inside the container

  4. The firmware.bin is extracted from the container

  5. The temporary location is deleted

Parameters

bytes

The data to use

 

script_fn

Name of the script to run in the tarball, e.g. startup.sh

 

output_fn

Name of the generated firmware, e.g. firmware.bin

 

error

A GError, or NULL

 

Returns

a new GBytes, or NULL for error

Types and Values