Coverage Report

Created: 2026-07-16 07:10

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/fu-ifd-struct.c
Line
Count
Source
1
/*
2
 * This file is auto-generated, do not modify!
3
 *
4
 * SPDX-License-Identifier: LGPL-2.1-or-later
5
 */
6
7
#include "config.h"
8
9
#include <glib.h>
10
11
#include "fu-ifd-struct.h"
12
#include "fu-byte-array.h"
13
#include "fu-bytes.h"
14
#include "fu-mem-private.h"
15
#include "fu-string.h"
16
17
#ifdef G_LOG_DOMAIN
18
  #undef G_LOG_DOMAIN
19
#endif
20
0
#define G_LOG_DOMAIN "FuStruct"
21
22
/**
23
 * fu_ifd_region_to_string:
24
 * @val: value, e.g. %FU_IFD_REGION_BIOS
25
 *
26
 * Converts an enumerated value to a string.
27
 *
28
 * Returns: identifier string
29
 **/
30
const gchar *
31
fu_ifd_region_to_string(FuIfdRegion val)
32
7.10k
{
33
7.10k
    if (val == FU_IFD_REGION_DESC)
34
2.01k
        return "desc";
35
5.09k
    if (val == FU_IFD_REGION_BIOS)
36
2.00k
        return "bios";
37
3.09k
    if (val == FU_IFD_REGION_ME)
38
813
        return "me";
39
2.28k
    if (val == FU_IFD_REGION_GBE)
40
602
        return "gbe";
41
1.67k
    if (val == FU_IFD_REGION_PLATFORM)
42
466
        return "platform";
43
1.21k
    if (val == FU_IFD_REGION_DEVEXP)
44
359
        return "devexp";
45
854
    if (val == FU_IFD_REGION_BIOS2)
46
268
        return "bios2";
47
586
    if (val == FU_IFD_REGION_EC)
48
192
        return "ec";
49
394
    if (val == FU_IFD_REGION_IE)
50
0
        return "ie";
51
394
    if (val == FU_IFD_REGION_10GBE)
52
0
        return "10gbe";
53
394
    if (val == FU_IFD_REGION_MAX)
54
0
        return "max";
55
394
    return NULL;
56
394
}
57
58
/**
59
 * fu_ifd_access_to_string:
60
 * @val: value, e.g. %FU_IFD_ACCESS_READ
61
 *
62
 * Converts an enumerated value to a string.
63
 *
64
 * Returns: identifier string
65
 *
66
 **/
67
gchar *
68
fu_ifd_access_to_string(FuIfdAccess val)
69
0
{
70
0
    const gchar *data[3] = {0};
71
0
    guint idx = 0;
72
0
    if (val == FU_IFD_ACCESS_NONE)
73
0
        return g_strdup("none");
74
0
    if (val & FU_IFD_ACCESS_READ)
75
0
        data[idx++] = "read";
76
0
    if (val & FU_IFD_ACCESS_WRITE)
77
0
        data[idx++] = "write";
78
0
    return g_strjoinv(",", (gchar **)data);
79
0
}
80
/**
81
 * fu_struct_ifd_fdbar_ref: (skip):
82
 **/
83
FuStructIfdFdbar *
84
fu_struct_ifd_fdbar_ref(FuStructIfdFdbar *st)
85
0
{
86
0
    g_return_val_if_fail(st != NULL, NULL);
87
0
    st->refcount++;
88
0
    return st;
89
0
}
90
/**
91
 * fu_struct_ifd_fdbar_unref: (skip):
92
 **/
93
void
94
fu_struct_ifd_fdbar_unref(FuStructIfdFdbar *st)
95
4.85k
{
96
4.85k
    g_return_if_fail(st != NULL);
97
4.85k
    if (st->refcount == 0) {
98
0
        g_critical("FuStructIfdFdbar refcount already zero");
99
0
        return;
100
0
    }
101
4.85k
    if (--st->refcount > 0)
102
0
        return;
103
4.85k
    if (st->buf != NULL)
104
4.85k
        g_byte_array_unref(st->buf);
105
4.85k
    g_free(st);
106
4.85k
}
107
/**
108
 * fu_struct_ifd_fdbar_new_internal: (skip):
109
 **/
110
static FuStructIfdFdbar *
111
fu_struct_ifd_fdbar_new_internal(void)
112
4.85k
{
113
4.85k
    FuStructIfdFdbar *st = g_new0(FuStructIfdFdbar, 1);
114
4.85k
    st->refcount = 1;
115
4.85k
    return st;
116
4.85k
}
117
118
/* getters */
119
/**
120
 * fu_struct_ifd_fdbar_get_signature: (skip):
121
 **/
122
static guint32
123
fu_struct_ifd_fdbar_get_signature(const FuStructIfdFdbar *st)
124
4.14k
{
125
4.14k
    g_return_val_if_fail(st != NULL, 0x0);
126
4.14k
    return fu_memread_uint32(st->buf->data + 16, G_LITTLE_ENDIAN);
127
4.14k
}
128
/**
129
 * fu_struct_ifd_fdbar_get_descriptor_map0: (skip):
130
 **/
131
guint32
132
fu_struct_ifd_fdbar_get_descriptor_map0(const FuStructIfdFdbar *st)
133
2.01k
{
134
2.01k
    g_return_val_if_fail(st != NULL, 0x0);
135
2.01k
    return fu_memread_uint32(st->buf->data + 20, G_LITTLE_ENDIAN);
136
2.01k
}
137
/**
138
 * fu_struct_ifd_fdbar_get_descriptor_map1: (skip):
139
 **/
140
guint32
141
fu_struct_ifd_fdbar_get_descriptor_map1(const FuStructIfdFdbar *st)
142
2.01k
{
143
2.01k
    g_return_val_if_fail(st != NULL, 0x0);
144
2.01k
    return fu_memread_uint32(st->buf->data + 24, G_LITTLE_ENDIAN);
145
2.01k
}
146
/**
147
 * fu_struct_ifd_fdbar_get_descriptor_map2: (skip):
148
 **/
149
guint32
150
fu_struct_ifd_fdbar_get_descriptor_map2(const FuStructIfdFdbar *st)
151
2.01k
{
152
2.01k
    g_return_val_if_fail(st != NULL, 0x0);
153
2.01k
    return fu_memread_uint32(st->buf->data + 28, G_LITTLE_ENDIAN);
154
2.01k
}
155
156
/* setters */
157
/**
158
 * fu_struct_ifd_fdbar_set_signature: (skip):
159
 **/
160
static void
161
fu_struct_ifd_fdbar_set_signature(FuStructIfdFdbar *st, guint32 value)
162
747
{
163
747
    g_return_if_fail(st != NULL);
164
747
    fu_memwrite_uint32(st->buf->data + 16, value, G_LITTLE_ENDIAN);
165
747
}
166
/**
167
 * fu_struct_ifd_fdbar_set_descriptor_map0: (skip):
168
 **/
169
void
170
fu_struct_ifd_fdbar_set_descriptor_map0(FuStructIfdFdbar *st, guint32 value)
171
427
{
172
427
    g_return_if_fail(st != NULL);
173
427
    fu_memwrite_uint32(st->buf->data + 20, value, G_LITTLE_ENDIAN);
174
427
}
175
/**
176
 * fu_struct_ifd_fdbar_set_descriptor_map1: (skip):
177
 **/
178
void
179
fu_struct_ifd_fdbar_set_descriptor_map1(FuStructIfdFdbar *st, guint32 value)
180
427
{
181
427
    g_return_if_fail(st != NULL);
182
427
    fu_memwrite_uint32(st->buf->data + 24, value, G_LITTLE_ENDIAN);
183
427
}
184
/**
185
 * fu_struct_ifd_fdbar_set_descriptor_map2: (skip):
186
 **/
187
void
188
fu_struct_ifd_fdbar_set_descriptor_map2(FuStructIfdFdbar *st, guint32 value)
189
427
{
190
427
    g_return_if_fail(st != NULL);
191
427
    fu_memwrite_uint32(st->buf->data + 28, value, G_LITTLE_ENDIAN);
192
427
}
193
/**
194
 * fu_struct_ifd_fdbar_new: (skip):
195
 **/
196
FuStructIfdFdbar *
197
fu_struct_ifd_fdbar_new(void)
198
747
{
199
747
    FuStructIfdFdbar *st = fu_struct_ifd_fdbar_new_internal();
200
747
    st->buf = g_byte_array_sized_new(32);
201
747
    fu_byte_array_set_size(st->buf, 32, 0x0);
202
747
    memcpy(st->buf->data + 0x0, "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF", 16); /* nocheck:blocked */
203
747
    fu_struct_ifd_fdbar_set_signature(st, 0x0FF0A55A);
204
747
    return st;
205
747
}
206
/**
207
 * fu_struct_ifd_fdbar_to_string: (skip):
208
 **/
209
static gchar *
210
fu_struct_ifd_fdbar_to_string(const FuStructIfdFdbar *st)
211
0
{
212
0
    g_autoptr(GString) str = g_string_new("FuStructIfdFdbar:\n");
213
0
    g_return_val_if_fail(st != NULL, NULL);
214
0
    g_string_append_printf(str, "  signature: 0x%x\n",
215
0
                           (guint) fu_struct_ifd_fdbar_get_signature(st));
216
0
    g_string_append_printf(str, "  descriptor_map0: 0x%x\n",
217
0
                           (guint) fu_struct_ifd_fdbar_get_descriptor_map0(st));
218
0
    g_string_append_printf(str, "  descriptor_map1: 0x%x\n",
219
0
                           (guint) fu_struct_ifd_fdbar_get_descriptor_map1(st));
220
0
    g_string_append_printf(str, "  descriptor_map2: 0x%x\n",
221
0
                           (guint) fu_struct_ifd_fdbar_get_descriptor_map2(st));
222
0
    if (str->len > 0)
223
0
        g_string_set_size(str, str->len - 1);
224
0
    return g_string_free(g_steal_pointer(&str), FALSE);
225
0
}
226
static gboolean
227
fu_struct_ifd_fdbar_validate_internal(FuStructIfdFdbar *st, GError **error)
228
4.09k
{
229
4.09k
    g_return_val_if_fail(st != NULL, FALSE);
230
4.09k
    if (fu_struct_ifd_fdbar_get_signature(st) != 0x0FF0A55A) {
231
43
        g_set_error(error,
232
43
                    FWUPD_ERROR,
233
43
                    FWUPD_ERROR_INVALID_DATA,
234
43
                    "constant FuStructIfdFdbar.signature was not valid, "
235
43
                    "expected 0x%x and got 0x%x",
236
43
                    (guint) 0x0FF0A55A,
237
43
                    (guint) fu_struct_ifd_fdbar_get_signature(st));
238
43
        return FALSE;
239
43
    }
240
4.05k
    return TRUE;
241
4.09k
}
242
/**
243
 * fu_struct_ifd_fdbar_validate_stream: (skip):
244
 **/
245
gboolean
246
fu_struct_ifd_fdbar_validate_stream(FuInputStream *stream, gsize offset, GError **error)
247
2.09k
{
248
2.09k
    g_autoptr(FuStructIfdFdbar) st = fu_struct_ifd_fdbar_new_internal();
249
2.09k
    g_return_val_if_fail(FU_IS_INPUT_STREAM(stream), FALSE);
250
2.09k
    g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
251
2.09k
    st->buf = fu_input_stream_read_byte_array(stream, offset, 32, NULL, error);
252
2.09k
    if (st->buf == NULL) {
253
0
        g_prefix_error(error, "FuStructIfdFdbar failed read of 0x%x: ", (guint) 32);
254
0
        return FALSE;
255
0
    }
256
2.09k
    if (st->buf->len != 32) {
257
14
        g_set_error(error,
258
14
                    FWUPD_ERROR,
259
14
                    FWUPD_ERROR_INVALID_DATA,
260
14
                    "FuStructIfdFdbar requested 0x%x and got 0x%x",
261
14
                    (guint) 32,
262
14
                    (guint) st->buf->len);
263
14
        return FALSE;
264
14
    }
265
2.08k
    return fu_struct_ifd_fdbar_validate_internal(st, error);
266
2.09k
}
267
static gboolean
268
fu_struct_ifd_fdbar_parse_internal(FuStructIfdFdbar *st, GError **error)
269
2.01k
{
270
2.01k
    if (g_log_get_debug_enabled()) {
271
0
        g_autofree gchar *str = fu_struct_ifd_fdbar_to_string(st);
272
0
        g_debug("%s", str);
273
0
    }
274
2.01k
    if (!fu_struct_ifd_fdbar_validate_internal(st, error))
275
0
        return FALSE;
276
2.01k
    return TRUE;
277
2.01k
}
278
/**
279
 * fu_struct_ifd_fdbar_parse_stream: (skip):
280
 **/
281
FuStructIfdFdbar *
282
fu_struct_ifd_fdbar_parse_stream(FuInputStream *stream, gsize offset, GError **error)
283
2.01k
{
284
2.01k
    g_autoptr(FuStructIfdFdbar) st = fu_struct_ifd_fdbar_new_internal();
285
2.01k
    st->buf = fu_input_stream_read_byte_array(stream, offset, 32, NULL, error);
286
2.01k
    if (st->buf == NULL) {
287
0
        g_prefix_error(error, "FuStructIfdFdbar failed read of 0x%x: ", (guint) 32);
288
0
        return NULL;
289
0
    }
290
2.01k
    if (st->buf->len != 32) {
291
0
        g_set_error(error,
292
0
                    FWUPD_ERROR,
293
0
                    FWUPD_ERROR_INVALID_DATA,
294
0
                    "FuStructIfdFdbar requested 0x%x and got 0x%x",
295
0
                    (guint) 32,
296
0
                    (guint) st->buf->len);
297
0
        return NULL;
298
0
    }
299
2.01k
    if (!fu_struct_ifd_fdbar_parse_internal(st, error))
300
0
        return NULL;
301
2.01k
    return g_steal_pointer(&st);
302
2.01k
}
303
/**
304
 * fu_struct_ifd_fcba_ref: (skip):
305
 **/
306
FuStructIfdFcba *
307
fu_struct_ifd_fcba_ref(FuStructIfdFcba *st)
308
0
{
309
0
    g_return_val_if_fail(st != NULL, NULL);
310
0
    st->refcount++;
311
0
    return st;
312
0
}
313
/**
314
 * fu_struct_ifd_fcba_unref: (skip):
315
 **/
316
void
317
fu_struct_ifd_fcba_unref(FuStructIfdFcba *st)
318
2.76k
{
319
2.76k
    g_return_if_fail(st != NULL);
320
2.76k
    if (st->refcount == 0) {
321
0
        g_critical("FuStructIfdFcba refcount already zero");
322
0
        return;
323
0
    }
324
2.76k
    if (--st->refcount > 0)
325
0
        return;
326
2.76k
    if (st->buf != NULL)
327
2.76k
        g_byte_array_unref(st->buf);
328
2.76k
    g_free(st);
329
2.76k
}
330
/**
331
 * fu_struct_ifd_fcba_new_internal: (skip):
332
 **/
333
static FuStructIfdFcba *
334
fu_struct_ifd_fcba_new_internal(void)
335
2.76k
{
336
2.76k
    FuStructIfdFcba *st = g_new0(FuStructIfdFcba, 1);
337
2.76k
    st->refcount = 1;
338
2.76k
    return st;
339
2.76k
}
340
341
/* getters */
342
/**
343
 * fu_struct_ifd_fcba_get_flcomp: (skip):
344
 **/
345
guint32
346
fu_struct_ifd_fcba_get_flcomp(const FuStructIfdFcba *st)
347
2.01k
{
348
2.01k
    g_return_val_if_fail(st != NULL, 0x0);
349
2.01k
    return fu_memread_uint32(st->buf->data + 0, G_LITTLE_ENDIAN);
350
2.01k
}
351
/**
352
 * fu_struct_ifd_fcba_get_flill: (skip):
353
 **/
354
guint32
355
fu_struct_ifd_fcba_get_flill(const FuStructIfdFcba *st)
356
2.01k
{
357
2.01k
    g_return_val_if_fail(st != NULL, 0x0);
358
2.01k
    return fu_memread_uint32(st->buf->data + 4, G_LITTLE_ENDIAN);
359
2.01k
}
360
/**
361
 * fu_struct_ifd_fcba_get_flill1: (skip):
362
 **/
363
guint32
364
fu_struct_ifd_fcba_get_flill1(const FuStructIfdFcba *st)
365
2.01k
{
366
2.01k
    g_return_val_if_fail(st != NULL, 0x0);
367
2.01k
    return fu_memread_uint32(st->buf->data + 8, G_LITTLE_ENDIAN);
368
2.01k
}
369
370
/* setters */
371
/**
372
 * fu_struct_ifd_fcba_set_flcomp: (skip):
373
 **/
374
void
375
fu_struct_ifd_fcba_set_flcomp(FuStructIfdFcba *st, guint32 value)
376
427
{
377
427
    g_return_if_fail(st != NULL);
378
427
    fu_memwrite_uint32(st->buf->data + 0, value, G_LITTLE_ENDIAN);
379
427
}
380
/**
381
 * fu_struct_ifd_fcba_set_flill: (skip):
382
 **/
383
void
384
fu_struct_ifd_fcba_set_flill(FuStructIfdFcba *st, guint32 value)
385
427
{
386
427
    g_return_if_fail(st != NULL);
387
427
    fu_memwrite_uint32(st->buf->data + 4, value, G_LITTLE_ENDIAN);
388
427
}
389
/**
390
 * fu_struct_ifd_fcba_set_flill1: (skip):
391
 **/
392
void
393
fu_struct_ifd_fcba_set_flill1(FuStructIfdFcba *st, guint32 value)
394
427
{
395
427
    g_return_if_fail(st != NULL);
396
427
    fu_memwrite_uint32(st->buf->data + 8, value, G_LITTLE_ENDIAN);
397
427
}
398
/**
399
 * fu_struct_ifd_fcba_new: (skip):
400
 **/
401
FuStructIfdFcba *
402
fu_struct_ifd_fcba_new(void)
403
747
{
404
747
    FuStructIfdFcba *st = fu_struct_ifd_fcba_new_internal();
405
747
    st->buf = g_byte_array_sized_new(12);
406
747
    fu_byte_array_set_size(st->buf, 12, 0x0);
407
747
    return st;
408
747
}
409
/**
410
 * fu_struct_ifd_fcba_to_string: (skip):
411
 **/
412
static gchar *
413
fu_struct_ifd_fcba_to_string(const FuStructIfdFcba *st)
414
0
{
415
0
    g_autoptr(GString) str = g_string_new("FuStructIfdFcba:\n");
416
0
    g_return_val_if_fail(st != NULL, NULL);
417
0
    g_string_append_printf(str, "  flcomp: 0x%x\n",
418
0
                           (guint) fu_struct_ifd_fcba_get_flcomp(st));
419
0
    g_string_append_printf(str, "  flill: 0x%x\n",
420
0
                           (guint) fu_struct_ifd_fcba_get_flill(st));
421
0
    g_string_append_printf(str, "  flill1: 0x%x\n",
422
0
                           (guint) fu_struct_ifd_fcba_get_flill1(st));
423
0
    if (str->len > 0)
424
0
        g_string_set_size(str, str->len - 1);
425
0
    return g_string_free(g_steal_pointer(&str), FALSE);
426
0
}
427
static gboolean
428
fu_struct_ifd_fcba_parse_internal(FuStructIfdFcba *st, GError **error)
429
2.01k
{
430
2.01k
    if (g_log_get_debug_enabled()) {
431
0
        g_autofree gchar *str = fu_struct_ifd_fcba_to_string(st);
432
0
        g_debug("%s", str);
433
0
    }
434
2.01k
    return TRUE;
435
2.01k
}
436
/**
437
 * fu_struct_ifd_fcba_parse_stream: (skip):
438
 **/
439
FuStructIfdFcba *
440
fu_struct_ifd_fcba_parse_stream(FuInputStream *stream, gsize offset, GError **error)
441
2.01k
{
442
2.01k
    g_autoptr(FuStructIfdFcba) st = fu_struct_ifd_fcba_new_internal();
443
2.01k
    st->buf = fu_input_stream_read_byte_array(stream, offset, 12, NULL, error);
444
2.01k
    if (st->buf == NULL) {
445
0
        g_prefix_error(error, "FuStructIfdFcba failed read of 0x%x: ", (guint) 12);
446
0
        return NULL;
447
0
    }
448
2.01k
    if (st->buf->len != 12) {
449
0
        g_set_error(error,
450
0
                    FWUPD_ERROR,
451
0
                    FWUPD_ERROR_INVALID_DATA,
452
0
                    "FuStructIfdFcba requested 0x%x and got 0x%x",
453
0
                    (guint) 12,
454
0
                    (guint) st->buf->len);
455
0
        return NULL;
456
0
    }
457
2.01k
    if (!fu_struct_ifd_fcba_parse_internal(st, error))
458
0
        return NULL;
459
2.01k
    return g_steal_pointer(&st);
460
2.01k
}