blob: 291d778e46c55820579d28605029b7c72fe03243 [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 Hughesb63cfa92021-01-05 22:57:12 +000087/**
88 * FuCpuVendor:
89 * @FU_CPU_VENDOR_UNKNOWN: Unknown
90 * @FU_CPU_VENDOR_INTEL: Intel
91 * @FU_CPU_VENDOR_AMD: AMD
92 *
93 * The CPU vendor.
94 **/
95typedef enum {
96 FU_CPU_VENDOR_UNKNOWN,
97 FU_CPU_VENDOR_INTEL,
98 FU_CPU_VENDOR_AMD,
99 /*< private >*/
100 FU_CPU_VENDOR_LAST
101} FuCpuVendor;
102
Richard Hughes049ccc82017-08-09 15:26:56 +0100103typedef void (*FuOutputHandler) (const gchar *line,
104 gpointer user_data);
105
106gboolean fu_common_spawn_sync (const gchar * const *argv,
Richard Hughes4eada342017-10-03 21:20:32 +0100107 FuOutputHandler handler_cb,
Richard Hughes049ccc82017-08-09 15:26:56 +0100108 gpointer handler_user_data,
Richard Hughesb768e4d2019-02-26 13:55:18 +0000109 guint timeout_ms,
Richard Hughes049ccc82017-08-09 15:26:56 +0100110 GCancellable *cancellable,
Richard Hughesa2abc422020-12-22 09:38:59 +0000111 GError **error)
112 G_GNUC_WARN_UNUSED_RESULT;
Richard Hughes049ccc82017-08-09 15:26:56 +0100113
Richard Hughes4be17d12018-05-30 20:36:29 +0100114gchar *fu_common_get_path (FuPathKind path_kind);
Richard Hughes484ee292019-03-22 16:10:50 +0000115gchar *fu_common_realpath (const gchar *filename,
Richard Hughesa2abc422020-12-22 09:38:59 +0000116 GError **error)
117 G_GNUC_WARN_UNUSED_RESULT;
Richard Hughesa84d7a72020-05-06 12:11:51 +0100118GPtrArray *fu_common_filename_glob (const gchar *directory,
119 const gchar *pattern,
Richard Hughesa2abc422020-12-22 09:38:59 +0000120 GError **error)
121 G_GNUC_WARN_UNUSED_RESULT;
Richard Hughes5c508de2019-11-22 09:57:34 +0000122gboolean fu_common_fnmatch (const gchar *pattern,
123 const gchar *str);
Richard Hughes954dd9f2017-08-08 13:36:25 +0100124gboolean fu_common_rmtree (const gchar *directory,
Richard Hughesa2abc422020-12-22 09:38:59 +0000125 GError **error)
126 G_GNUC_WARN_UNUSED_RESULT;
Richard Hughes89e968b2018-03-07 10:01:08 +0000127GPtrArray *fu_common_get_files_recursive (const gchar *path,
Richard Hughesa2abc422020-12-22 09:38:59 +0000128 GError **error)
129 G_GNUC_WARN_UNUSED_RESULT;
Richard Hughes7ee42fe2017-08-15 14:06:21 +0100130gboolean fu_common_mkdir_parent (const gchar *filename,
Richard Hughesa2abc422020-12-22 09:38:59 +0000131 GError **error)
132 G_GNUC_WARN_UNUSED_RESULT;
Richard Hughes943d2c92017-06-21 09:04:39 +0100133gboolean fu_common_set_contents_bytes (const gchar *filename,
Richard Hughes4eada342017-10-03 21:20:32 +0100134 GBytes *bytes,
Richard Hughesa2abc422020-12-22 09:38:59 +0000135 GError **error)
136 G_GNUC_WARN_UNUSED_RESULT;
Richard Hughesd0d2ae62017-08-08 12:22:30 +0100137GBytes *fu_common_get_contents_bytes (const gchar *filename,
Richard Hughesa2abc422020-12-22 09:38:59 +0000138 GError **error)
139 G_GNUC_WARN_UNUSED_RESULT;
Richard Hughes943d2c92017-06-21 09:04:39 +0100140GBytes *fu_common_get_contents_fd (gint fd,
141 gsize count,
Richard Hughesa2abc422020-12-22 09:38:59 +0000142 GError **error)
143 G_GNUC_WARN_UNUSED_RESULT;
Richard Hughes94f939a2017-08-08 12:21:39 +0100144gboolean fu_common_extract_archive (GBytes *blob,
145 const gchar *dir,
Richard Hughesa2abc422020-12-22 09:38:59 +0000146 GError **error)
147 G_GNUC_WARN_UNUSED_RESULT;
Richard Hughes41cbe2a2017-08-08 14:13:35 +0100148GBytes *fu_common_firmware_builder (GBytes *bytes,
149 const gchar *script_fn,
150 const gchar *output_fn,
Richard Hughesa2abc422020-12-22 09:38:59 +0000151 GError **error)
152 G_GNUC_WARN_UNUSED_RESULT;
Richard Hughese82eef32018-05-20 10:41:26 +0100153GError *fu_common_error_array_get_best (GPtrArray *errors);
Richard Hughes73bf2332018-08-28 09:38:09 +0100154guint64 fu_common_strtoull (const gchar *str);
Richard Hughes22367e72018-08-30 10:24:04 +0100155gchar *fu_common_find_program_in_path (const gchar *basename,
Richard Hughesa2abc422020-12-22 09:38:59 +0000156 GError **error)
157 G_GNUC_WARN_UNUSED_RESULT;
Richard Hughesa574a752018-08-31 13:31:03 +0100158gchar *fu_common_strstrip (const gchar *str);
Richard Hughese59cb9a2018-12-05 14:37:40 +0000159void fu_common_dump_raw (const gchar *log_domain,
160 const gchar *title,
161 const guint8 *data,
162 gsize len);
Richard Hughes35481862019-01-06 12:01:58 +0000163void fu_common_dump_full (const gchar *log_domain,
164 const gchar *title,
165 const guint8 *data,
166 gsize len,
167 guint columns,
168 FuDumpFlags flags);
Richard Hughese59cb9a2018-12-05 14:37:40 +0000169void fu_common_dump_bytes (const gchar *log_domain,
170 const gchar *title,
171 GBytes *bytes);
Richard Hughesfc90f392019-01-15 21:21:16 +0000172GBytes *fu_common_bytes_align (GBytes *bytes,
173 gsize blksz,
174 gchar padval);
Richard Hughes36999462019-03-19 20:23:29 +0000175gboolean fu_common_bytes_is_empty (GBytes *bytes);
Richard Hughes2aad1042019-03-21 09:03:32 +0000176gboolean fu_common_bytes_compare (GBytes *bytes1,
177 GBytes *bytes2,
Richard Hughesa2abc422020-12-22 09:38:59 +0000178 GError **error)
179 G_GNUC_WARN_UNUSED_RESULT;
Richard Hughes38245ff2019-09-18 14:46:09 +0100180gboolean fu_common_bytes_compare_raw (const guint8 *buf1,
181 gsize bufsz1,
182 const guint8 *buf2,
183 gsize bufsz2,
Richard Hughesa2abc422020-12-22 09:38:59 +0000184 GError **error)
185 G_GNUC_WARN_UNUSED_RESULT;
Richard Hughes7afd7cb2019-08-07 11:42:42 +0100186GBytes *fu_common_bytes_pad (GBytes *bytes,
187 gsize sz);
Richard Hughes05e33772020-12-08 18:37:02 +0000188GBytes *fu_common_bytes_new_offset (GBytes *bytes,
189 gsize offset,
190 gsize length,
Richard Hughesa2abc422020-12-22 09:38:59 +0000191 GError **error)
192 G_GNUC_WARN_UNUSED_RESULT;
Richard Hughesae96a1f2019-09-23 11:16:36 +0100193gsize fu_common_strwidth (const gchar *text);
Richard Hughes5308ea42019-08-09 12:25:13 +0100194gboolean fu_memcpy_safe (guint8 *dst,
195 gsize dst_sz,
196 gsize dst_offset,
197 const guint8 *src,
198 gsize src_sz,
199 gsize src_offset,
200 gsize n,
Richard Hughesa2abc422020-12-22 09:38:59 +0000201 GError **error)
202 G_GNUC_WARN_UNUSED_RESULT;
Richard Hughesc21a0b92019-10-24 12:24:37 +0100203gboolean fu_common_read_uint8_safe (const guint8 *buf,
204 gsize bufsz,
205 gsize offset,
206 guint8 *value,
Richard Hughesa2abc422020-12-22 09:38:59 +0000207 GError **error)
208 G_GNUC_WARN_UNUSED_RESULT;
Richard Hughes80768f52019-10-22 07:19:14 +0100209gboolean fu_common_read_uint16_safe (const guint8 *buf,
210 gsize bufsz,
211 gsize offset,
212 guint16 *value,
213 FuEndianType endian,
Richard Hughesa2abc422020-12-22 09:38:59 +0000214 GError **error)
215 G_GNUC_WARN_UNUSED_RESULT;
Richard Hughes80768f52019-10-22 07:19:14 +0100216gboolean fu_common_read_uint32_safe (const guint8 *buf,
217 gsize bufsz,
218 gsize offset,
219 guint32 *value,
220 FuEndianType endian,
Richard Hughesa2abc422020-12-22 09:38:59 +0000221 GError **error)
222 G_GNUC_WARN_UNUSED_RESULT;
Richard Hughes943d2c92017-06-21 09:04:39 +0100223
Richard Hughesa2a8f8e2020-10-20 09:27:26 +0100224void fu_byte_array_set_size (GByteArray *array,
225 guint length);
Richard Hughes37c6a7b2019-08-14 21:57:43 +0100226void fu_byte_array_append_uint8 (GByteArray *array,
227 guint8 data);
228void fu_byte_array_append_uint16 (GByteArray *array,
229 guint16 data,
230 FuEndianType endian);
231void fu_byte_array_append_uint32 (GByteArray *array,
232 guint32 data,
233 FuEndianType endian);
Richard Hughesae252cd2017-12-08 10:48:15 +0000234
235void fu_common_write_uint16 (guint8 *buf,
236 guint16 val_native,
237 FuEndianType endian);
238void fu_common_write_uint32 (guint8 *buf,
239 guint32 val_native,
240 FuEndianType endian);
241guint16 fu_common_read_uint16 (const guint8 *buf,
242 FuEndianType endian);
243guint32 fu_common_read_uint32 (const guint8 *buf,
244 FuEndianType endian);
245
Richard Hughes83e56c12018-10-10 20:24:41 +0100246guint fu_common_string_replace (GString *string,
247 const gchar *search,
248 const gchar *replace);
Richard Hughescea28de2019-08-09 11:16:40 +0100249void fu_common_string_append_kv (GString *str,
Richard Hughes6e3e62b2019-08-14 10:43:08 +0100250 guint idt,
Richard Hughescea28de2019-08-09 11:16:40 +0100251 const gchar *key,
252 const gchar *value);
Richard Hughes6e3e62b2019-08-14 10:43:08 +0100253void fu_common_string_append_ku (GString *str,
254 guint idt,
255 const gchar *key,
256 guint64 value);
257void fu_common_string_append_kx (GString *str,
258 guint idt,
259 const gchar *key,
260 guint64 value);
261void fu_common_string_append_kb (GString *str,
262 guint idt,
263 const gchar *key,
264 gboolean value);
Richard Hughes7afd7cb2019-08-07 11:42:42 +0100265gchar **fu_common_strnsplit (const gchar *str,
266 gsize sz,
267 const gchar *delimiter,
268 gint max_tokens);
Richard Hughes364e2682021-01-05 14:38:15 +0000269gchar *fu_common_strsafe (const gchar *str,
270 gsize maxsz);
Richard Hughese52e1b42021-01-26 09:59:15 +0000271gchar *fu_common_strjoin_array (const gchar *separator,
272 GPtrArray *array);
Mario Limonciello9dce1f72020-02-04 09:12:52 -0600273gboolean fu_common_kernel_locked_down (void);
Richard Hughesbd1dc2a2020-08-20 15:35:28 +0100274gboolean fu_common_cpuid (guint32 leaf,
275 guint32 *eax,
276 guint32 *ebx,
277 guint32 *ecx,
278 guint32 *edx,
Richard Hughesa2abc422020-12-22 09:38:59 +0000279 GError **error)
280 G_GNUC_WARN_UNUSED_RESULT;
Richard Hughesb63cfa92021-01-05 22:57:12 +0000281gboolean fu_common_is_cpu_intel (void)
282G_DEPRECATED_FOR(fu_common_get_cpu_vendor);
283FuCpuVendor fu_common_get_cpu_vendor (void);
Richard Hughes36111472020-08-12 15:04:24 +0100284gboolean fu_common_is_live_media (void);
Richard Hughes68175e92021-01-14 09:43:33 +0000285guint64 fu_common_get_memory_size (void);
Richard Hughes8f0b2d12020-08-12 12:41:53 +0100286GPtrArray *fu_common_get_volumes_by_kind (const gchar *kind,
Richard Hughesa2abc422020-12-22 09:38:59 +0000287 GError **error)
288 G_GNUC_WARN_UNUSED_RESULT;
Richard Hughes0bdf5612020-10-30 14:56:22 +0000289FuVolume *fu_common_get_volume_by_device (const gchar *device,
Richard Hughesa2abc422020-12-22 09:38:59 +0000290 GError **error)
291 G_GNUC_WARN_UNUSED_RESULT;
Richard Hughes0bdf5612020-10-30 14:56:22 +0000292FuVolume *fu_common_get_volume_by_devnum (guint32 devnum,
Richard Hughesa2abc422020-12-22 09:38:59 +0000293 GError **error)
294 G_GNUC_WARN_UNUSED_RESULT;
Richard Hughes8f0b2d12020-08-12 12:41:53 +0100295FuVolume *fu_common_get_esp_for_path (const gchar *esp_path,
Richard Hughesa2abc422020-12-22 09:38:59 +0000296 GError **error)
297 G_GNUC_WARN_UNUSED_RESULT;
298FuVolume *fu_common_get_esp_default (GError **error)
299 G_GNUC_WARN_UNUSED_RESULT;
Richard Hughes6f5e35a2020-09-25 14:14:52 +0100300
Richard Hughes44ae2a72020-09-25 18:00:21 +0100301guint8 fu_common_crc8 (const guint8 *buf,
302 gsize bufsz);
Richard Hughes6f5e35a2020-09-25 14:14:52 +0100303guint16 fu_common_crc16 (const guint8 *buf,
304 gsize bufsz);
305guint32 fu_common_crc32 (const guint8 *buf,
306 gsize bufsz);
307guint32 fu_common_crc32_full (const guint8 *buf,
308 gsize bufsz,
309 guint32 crc,
310 guint32 polynomial);