blob: 8a454fa0d501c93b6e9c3e66c48049c7d5fe121c [file] [log] [blame]
Richard Hughes02c90d82018-08-09 12:13:03 +01001/*
Richard Hughes943d2c92017-06-21 09:04:39 +01002 * Copyright (C) 2017 Richard Hughes <richard@hughsie.com>
3 *
Mario Limonciello51308e62018-05-28 20:05:46 -05004 * SPDX-License-Identifier: LGPL-2.1+
Richard Hughes943d2c92017-06-21 09:04:39 +01005 */
6
Richard Hughesbfd946e2019-02-09 08:21:40 +00007#pragma once
Richard Hughes943d2c92017-06-21 09:04:39 +01008
Richard Hughesadc9dad2017-09-04 13:19:27 +01009#include <gio/gio.h>
Richard Hughes943d2c92017-06-21 09:04:39 +010010
Richard Hughes8f0b2d12020-08-12 12:41:53 +010011#include "fu-volume.h"
12
Mario Limonciello39602652019-04-29 21:08:58 -050013/**
14 * FuAppFlags:
15 * @FU_APP_FLAGS_NONE: No flags set
16 * @FU_APP_FLAGS_NO_IDLE_SOURCES: Disallow idle sources
Mario Limonciello39602652019-04-29 21:08:58 -050017 *
18 * The flags to use when loading an application.
19 **/
Richard Hughes5b5f6552018-05-18 10:22:39 +010020typedef enum {
21 FU_APP_FLAGS_NONE = 0,
22 FU_APP_FLAGS_NO_IDLE_SOURCES = 1 << 0,
Mario Limonciello39602652019-04-29 21:08:58 -050023 /*< private >*/
Richard Hughes5b5f6552018-05-18 10:22:39 +010024 FU_APP_FLAGS_LAST
25} FuAppFlags;
26
Mario Limonciello39602652019-04-29 21:08:58 -050027/**
28 * FuDumpFlags:
29 * @FU_DUMP_FLAGS_NONE: No flags set
30 * @FU_DUMP_FLAGS_SHOW_ASCII: Show ASCII in debugging dumps
31 * @FU_DUMP_FLAGS_SHOW_ADDRESSES: Show addresses in debugging dumps
32 *
33 * The flags to use when configuring debugging
34 **/
Richard Hughes4be17d12018-05-30 20:36:29 +010035typedef enum {
Richard Hughes35481862019-01-06 12:01:58 +000036 FU_DUMP_FLAGS_NONE = 0,
37 FU_DUMP_FLAGS_SHOW_ASCII = 1 << 0,
38 FU_DUMP_FLAGS_SHOW_ADDRESSES = 1 << 1,
Mario Limonciello39602652019-04-29 21:08:58 -050039 /*< private >*/
Richard Hughes35481862019-01-06 12:01:58 +000040 FU_DUMP_FLAGS_LAST
41} FuDumpFlags;
42
Richard Hughes37c6a7b2019-08-14 21:57:43 +010043typedef guint FuEndianType;
44
Mario Limonciello39602652019-04-29 21:08:58 -050045/**
46 * FuPathKind:
47 * @FU_PATH_KIND_CACHEDIR_PKG: The cache directory (IE /var/cache/fwupd)
48 * @FU_PATH_KIND_DATADIR_PKG: The non-volatile data store (IE /usr/share/fwupd)
49 * @FU_PATH_KIND_EFIAPPDIR: The location to store EFI apps before install (IE /usr/libexec/fwupd/efi)
50 * @FU_PATH_KIND_LOCALSTATEDIR: The local state directory (IE /var)
51 * @FU_PATH_KIND_LOCALSTATEDIR_PKG: The local state directory for the package (IE /var/lib/fwupd)
52 * @FU_PATH_KIND_PLUGINDIR_PKG: The location to look for plugins for package (IE /usr/lib/[triplet]/fwupd-plugins-3)
53 * @FU_PATH_KIND_SYSCONFDIR: The configuration location (IE /etc)
54 * @FU_PATH_KIND_SYSCONFDIR_PKG: The package configuration location (IE /etc/fwupd)
55 * @FU_PATH_KIND_SYSFSDIR_FW: The sysfs firmware location (IE /sys/firmware)
56 * @FU_PATH_KIND_SYSFSDIR_DRIVERS: The platform sysfs directory (IE /sys/bus/platform/drivers)
57 * @FU_PATH_KIND_SYSFSDIR_TPM: The TPM sysfs directory (IE /sys/class/tpm)
Richard Hughesc3689582020-05-06 12:35:20 +010058 * @FU_PATH_KIND_PROCFS: The procfs location (IE /proc)
Mario Limonciellod8af5de2019-11-04 09:33:34 -060059 * @FU_PATH_KIND_POLKIT_ACTIONS: The directory for policy kit actions (IE /usr/share/polkit-1/actions/)
Richard Hughesafdba372019-11-23 12:57:35 +000060 * @FU_PATH_KIND_OFFLINE_TRIGGER: The file for the offline trigger (IE /system-update)
Mario Limonciello9dce1f72020-02-04 09:12:52 -060061 * @FU_PATH_KIND_SYSFSDIR_SECURITY: The sysfs security location (IE /sys/kernel/security)
Richard Hughesa7157912020-05-11 17:14:05 +010062 * @FU_PATH_KIND_ACPI_TABLES: The location of the ACPI tables
Mario Limonciello39602652019-04-29 21:08:58 -050063 *
64 * Path types to use when dynamically determining a path at runtime
65 **/
Richard Hughes35481862019-01-06 12:01:58 +000066typedef enum {
Richard Hughes4be17d12018-05-30 20:36:29 +010067 FU_PATH_KIND_CACHEDIR_PKG,
68 FU_PATH_KIND_DATADIR_PKG,
Mario Limoncielloe6e2bf92018-07-10 12:11:25 -050069 FU_PATH_KIND_EFIAPPDIR,
Richard Hughes4be17d12018-05-30 20:36:29 +010070 FU_PATH_KIND_LOCALSTATEDIR,
71 FU_PATH_KIND_LOCALSTATEDIR_PKG,
72 FU_PATH_KIND_PLUGINDIR_PKG,
73 FU_PATH_KIND_SYSCONFDIR,
74 FU_PATH_KIND_SYSCONFDIR_PKG,
Richard Hughes282b10d2018-06-22 14:48:00 +010075 FU_PATH_KIND_SYSFSDIR_FW,
Richard Hughes83390f62018-06-22 20:36:46 +010076 FU_PATH_KIND_SYSFSDIR_DRIVERS,
Richard Hughesb56015e2018-12-12 09:25:32 +000077 FU_PATH_KIND_SYSFSDIR_TPM,
Richard Hughesc3689582020-05-06 12:35:20 +010078 FU_PATH_KIND_PROCFS,
Mario Limonciello057c67a2019-05-23 10:44:19 -050079 FU_PATH_KIND_POLKIT_ACTIONS,
Richard Hughesafdba372019-11-23 12:57:35 +000080 FU_PATH_KIND_OFFLINE_TRIGGER,
Mario Limonciello9dce1f72020-02-04 09:12:52 -060081 FU_PATH_KIND_SYSFSDIR_SECURITY,
Richard Hughesa7157912020-05-11 17:14:05 +010082 FU_PATH_KIND_ACPI_TABLES,
Mario Limonciello39602652019-04-29 21:08:58 -050083 /*< private >*/
Richard Hughes4be17d12018-05-30 20:36:29 +010084 FU_PATH_KIND_LAST
85} FuPathKind;
86
Richard Hughes049ccc82017-08-09 15:26:56 +010087typedef void (*FuOutputHandler) (const gchar *line,
88 gpointer user_data);
89
90gboolean fu_common_spawn_sync (const gchar * const *argv,
Richard Hughes4eada342017-10-03 21:20:32 +010091 FuOutputHandler handler_cb,
Richard Hughes049ccc82017-08-09 15:26:56 +010092 gpointer handler_user_data,
Richard Hughesb768e4d2019-02-26 13:55:18 +000093 guint timeout_ms,
Richard Hughes049ccc82017-08-09 15:26:56 +010094 GCancellable *cancellable,
95 GError **error);
96
Richard Hughes4be17d12018-05-30 20:36:29 +010097gchar *fu_common_get_path (FuPathKind path_kind);
Richard Hughes484ee292019-03-22 16:10:50 +000098gchar *fu_common_realpath (const gchar *filename,
99 GError **error);
Richard Hughesa84d7a72020-05-06 12:11:51 +0100100GPtrArray *fu_common_filename_glob (const gchar *directory,
101 const gchar *pattern,
102 GError **error);
Richard Hughes5c508de2019-11-22 09:57:34 +0000103gboolean fu_common_fnmatch (const gchar *pattern,
104 const gchar *str);
Richard Hughes954dd9f2017-08-08 13:36:25 +0100105gboolean fu_common_rmtree (const gchar *directory,
106 GError **error);
Richard Hughes89e968b2018-03-07 10:01:08 +0000107GPtrArray *fu_common_get_files_recursive (const gchar *path,
108 GError **error);
Richard Hughes7ee42fe2017-08-15 14:06:21 +0100109gboolean fu_common_mkdir_parent (const gchar *filename,
110 GError **error);
Richard Hughes943d2c92017-06-21 09:04:39 +0100111gboolean fu_common_set_contents_bytes (const gchar *filename,
Richard Hughes4eada342017-10-03 21:20:32 +0100112 GBytes *bytes,
Richard Hughes943d2c92017-06-21 09:04:39 +0100113 GError **error);
Richard Hughesd0d2ae62017-08-08 12:22:30 +0100114GBytes *fu_common_get_contents_bytes (const gchar *filename,
115 GError **error);
Richard Hughes943d2c92017-06-21 09:04:39 +0100116GBytes *fu_common_get_contents_fd (gint fd,
117 gsize count,
118 GError **error);
Richard Hughes94f939a2017-08-08 12:21:39 +0100119gboolean fu_common_extract_archive (GBytes *blob,
120 const gchar *dir,
121 GError **error);
Richard Hughes41cbe2a2017-08-08 14:13:35 +0100122GBytes *fu_common_firmware_builder (GBytes *bytes,
123 const gchar *script_fn,
124 const gchar *output_fn,
125 GError **error);
Richard Hughese82eef32018-05-20 10:41:26 +0100126GError *fu_common_error_array_get_best (GPtrArray *errors);
Richard Hughes73bf2332018-08-28 09:38:09 +0100127guint64 fu_common_strtoull (const gchar *str);
Richard Hughes22367e72018-08-30 10:24:04 +0100128gchar *fu_common_find_program_in_path (const gchar *basename,
129 GError **error);
Richard Hughesa574a752018-08-31 13:31:03 +0100130gchar *fu_common_strstrip (const gchar *str);
Richard Hughese59cb9a2018-12-05 14:37:40 +0000131void fu_common_dump_raw (const gchar *log_domain,
132 const gchar *title,
133 const guint8 *data,
134 gsize len);
Richard Hughes35481862019-01-06 12:01:58 +0000135void fu_common_dump_full (const gchar *log_domain,
136 const gchar *title,
137 const guint8 *data,
138 gsize len,
139 guint columns,
140 FuDumpFlags flags);
Richard Hughese59cb9a2018-12-05 14:37:40 +0000141void fu_common_dump_bytes (const gchar *log_domain,
142 const gchar *title,
143 GBytes *bytes);
Richard Hughesfc90f392019-01-15 21:21:16 +0000144GBytes *fu_common_bytes_align (GBytes *bytes,
145 gsize blksz,
146 gchar padval);
Richard Hughes36999462019-03-19 20:23:29 +0000147gboolean fu_common_bytes_is_empty (GBytes *bytes);
Richard Hughes2aad1042019-03-21 09:03:32 +0000148gboolean fu_common_bytes_compare (GBytes *bytes1,
149 GBytes *bytes2,
150 GError **error);
Richard Hughes38245ff2019-09-18 14:46:09 +0100151gboolean fu_common_bytes_compare_raw (const guint8 *buf1,
152 gsize bufsz1,
153 const guint8 *buf2,
154 gsize bufsz2,
155 GError **error);
Richard Hughes7afd7cb2019-08-07 11:42:42 +0100156GBytes *fu_common_bytes_pad (GBytes *bytes,
157 gsize sz);
Richard Hughesae96a1f2019-09-23 11:16:36 +0100158gsize fu_common_strwidth (const gchar *text);
Richard Hughes5308ea42019-08-09 12:25:13 +0100159gboolean fu_memcpy_safe (guint8 *dst,
160 gsize dst_sz,
161 gsize dst_offset,
162 const guint8 *src,
163 gsize src_sz,
164 gsize src_offset,
165 gsize n,
166 GError **error);
Richard Hughesc21a0b92019-10-24 12:24:37 +0100167gboolean fu_common_read_uint8_safe (const guint8 *buf,
168 gsize bufsz,
169 gsize offset,
170 guint8 *value,
171 GError **error);
Richard Hughes80768f52019-10-22 07:19:14 +0100172gboolean fu_common_read_uint16_safe (const guint8 *buf,
173 gsize bufsz,
174 gsize offset,
175 guint16 *value,
176 FuEndianType endian,
177 GError **error);
178gboolean fu_common_read_uint32_safe (const guint8 *buf,
179 gsize bufsz,
180 gsize offset,
181 guint32 *value,
182 FuEndianType endian,
183 GError **error);
Richard Hughes943d2c92017-06-21 09:04:39 +0100184
Richard Hughesa2a8f8e2020-10-20 09:27:26 +0100185void fu_byte_array_set_size (GByteArray *array,
186 guint length);
Richard Hughes37c6a7b2019-08-14 21:57:43 +0100187void fu_byte_array_append_uint8 (GByteArray *array,
188 guint8 data);
189void fu_byte_array_append_uint16 (GByteArray *array,
190 guint16 data,
191 FuEndianType endian);
192void fu_byte_array_append_uint32 (GByteArray *array,
193 guint32 data,
194 FuEndianType endian);
Richard Hughesae252cd2017-12-08 10:48:15 +0000195
196void fu_common_write_uint16 (guint8 *buf,
197 guint16 val_native,
198 FuEndianType endian);
199void fu_common_write_uint32 (guint8 *buf,
200 guint32 val_native,
201 FuEndianType endian);
202guint16 fu_common_read_uint16 (const guint8 *buf,
203 FuEndianType endian);
204guint32 fu_common_read_uint32 (const guint8 *buf,
205 FuEndianType endian);
206
Richard Hughes83e56c12018-10-10 20:24:41 +0100207guint fu_common_string_replace (GString *string,
208 const gchar *search,
209 const gchar *replace);
Richard Hughescea28de2019-08-09 11:16:40 +0100210void fu_common_string_append_kv (GString *str,
Richard Hughes6e3e62b2019-08-14 10:43:08 +0100211 guint idt,
Richard Hughescea28de2019-08-09 11:16:40 +0100212 const gchar *key,
213 const gchar *value);
Richard Hughes6e3e62b2019-08-14 10:43:08 +0100214void fu_common_string_append_ku (GString *str,
215 guint idt,
216 const gchar *key,
217 guint64 value);
218void fu_common_string_append_kx (GString *str,
219 guint idt,
220 const gchar *key,
221 guint64 value);
222void fu_common_string_append_kb (GString *str,
223 guint idt,
224 const gchar *key,
225 gboolean value);
Richard Hughes7afd7cb2019-08-07 11:42:42 +0100226gchar **fu_common_strnsplit (const gchar *str,
227 gsize sz,
228 const gchar *delimiter,
229 gint max_tokens);
Mario Limonciello9dce1f72020-02-04 09:12:52 -0600230gboolean fu_common_kernel_locked_down (void);
Richard Hughesbd1dc2a2020-08-20 15:35:28 +0100231gboolean fu_common_cpuid (guint32 leaf,
232 guint32 *eax,
233 guint32 *ebx,
234 guint32 *ecx,
235 guint32 *edx,
236 GError **error);
Richard Hughes9223c892020-05-09 20:32:08 +0100237gboolean fu_common_is_cpu_intel (void);
Richard Hughes36111472020-08-12 15:04:24 +0100238gboolean fu_common_is_live_media (void);
Richard Hughes8f0b2d12020-08-12 12:41:53 +0100239GPtrArray *fu_common_get_volumes_by_kind (const gchar *kind,
240 GError **error);
Richard Hughes0bdf5612020-10-30 14:56:22 +0000241FuVolume *fu_common_get_volume_by_device (const gchar *device,
242 GError **error);
243FuVolume *fu_common_get_volume_by_devnum (guint32 devnum,
244 GError **error);
Richard Hughes8f0b2d12020-08-12 12:41:53 +0100245FuVolume *fu_common_get_esp_for_path (const gchar *esp_path,
246 GError **error);
247FuVolume *fu_common_get_esp_default (GError **error);
Richard Hughes6f5e35a2020-09-25 14:14:52 +0100248
Richard Hughes44ae2a72020-09-25 18:00:21 +0100249guint8 fu_common_crc8 (const guint8 *buf,
250 gsize bufsz);
Richard Hughes6f5e35a2020-09-25 14:14:52 +0100251guint16 fu_common_crc16 (const guint8 *buf,
252 gsize bufsz);
253guint32 fu_common_crc32 (const guint8 *buf,
254 gsize bufsz);
255guint32 fu_common_crc32_full (const guint8 *buf,
256 gsize bufsz,
257 guint32 crc,
258 guint32 polynomial);