Coverage Report

Created: 2025-11-09 07:06

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/fu-acpi-phat-struct.c
Line
Count
Source
1
/* auto-generated, do not modify */
2
#include "config.h"
3
4
#include <glib.h>
5
6
#include "fu-acpi-phat-struct.h"
7
#include "fu-byte-array.h"
8
#include "fu-mem-private.h"
9
#include "fu-string.h"
10
11
#ifdef G_LOG_DOMAIN
12
  #undef G_LOG_DOMAIN
13
#endif
14
0
#define G_LOG_DOMAIN "FuStruct"
15
/**
16
 * fu_struct_acpi_phat_hdr_ref: (skip):
17
 **/
18
FuStructAcpiPhatHdr *
19
fu_struct_acpi_phat_hdr_ref(FuStructAcpiPhatHdr *st)
20
0
{
21
0
    g_return_val_if_fail(st != NULL, NULL);
22
0
    st->refcount++;
23
0
    return st;
24
0
}
25
/**
26
 * fu_struct_acpi_phat_hdr_unref: (skip):
27
 **/
28
void
29
fu_struct_acpi_phat_hdr_unref(FuStructAcpiPhatHdr *st)
30
81.0k
{
31
81.0k
    g_return_if_fail(st != NULL);
32
81.0k
    if (st->refcount == 0) {
33
0
        g_critical("FuStructAcpiPhatHdr refcount already zero");
34
0
        return;
35
0
    }
36
81.0k
    if (--st->refcount > 0)
37
0
        return;
38
81.0k
    if (st->buf != NULL)
39
81.0k
        g_byte_array_unref(st->buf);
40
81.0k
    g_free(st);
41
81.0k
}
42
static FuStructAcpiPhatHdr *
43
fu_struct_acpi_phat_hdr_new_internal(void)
44
81.0k
{
45
81.0k
    FuStructAcpiPhatHdr *st = g_new0(FuStructAcpiPhatHdr, 1);
46
81.0k
    st->refcount = 1;
47
81.0k
    return st;
48
81.0k
}
49
50
/* getters */
51
/**
52
 * fu_struct_acpi_phat_hdr_get_magic: (skip):
53
 **/
54
static gchar *
55
fu_struct_acpi_phat_hdr_get_magic(const FuStructAcpiPhatHdr *st)
56
78.5k
{
57
78.5k
    g_return_val_if_fail(st != NULL, NULL);
58
78.5k
    return fu_memstrsafe(st->buf->data, st->buf->len, 0, 4, NULL);
59
78.5k
}
60
61
/* setters */
62
static gboolean
63
fu_struct_acpi_phat_hdr_validate_internal(FuStructAcpiPhatHdr *st, GError **error)
64
80.6k
{
65
80.6k
    g_return_val_if_fail(st != NULL, FALSE);
66
80.6k
    if (strncmp((const gchar *) (st->buf->data + 0), "PHAT", 4) != 0) {
67
78.5k
        g_autofree gchar *str = fu_struct_acpi_phat_hdr_get_magic(st);
68
78.5k
        g_set_error(error,
69
78.5k
                    FWUPD_ERROR,
70
78.5k
                    FWUPD_ERROR_INVALID_DATA,
71
78.5k
                    "constant FuStructAcpiPhatHdr.magic was not valid, "
72
78.5k
                    "expected 'PHAT' and got '%s'",
73
78.5k
                    str);
74
78.5k
        return FALSE;
75
78.5k
    }
76
2.15k
    return TRUE;
77
80.6k
}
78
/**
79
 * fu_struct_acpi_phat_hdr_validate_stream: (skip):
80
 **/
81
gboolean
82
fu_struct_acpi_phat_hdr_validate_stream(GInputStream *stream, gsize offset, GError **error)
83
81.0k
{
84
81.0k
    g_autoptr(FuStructAcpiPhatHdr) st = fu_struct_acpi_phat_hdr_new_internal();
85
81.0k
    g_return_val_if_fail(G_IS_INPUT_STREAM(stream), FALSE);
86
81.0k
    g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
87
81.0k
    st->buf = fu_input_stream_read_byte_array(stream, offset, 4, NULL, error);
88
81.0k
    if (st->buf == NULL) {
89
0
        g_prefix_error(error, "FuStructAcpiPhatHdr failed read of 0x%x: ", (guint) 4);
90
0
        return FALSE;
91
0
    }
92
81.0k
    if (st->buf->len != 4) {
93
400
        g_set_error(error,
94
400
                    FWUPD_ERROR,
95
400
                    FWUPD_ERROR_INVALID_DATA,
96
400
                    "FuStructAcpiPhatHdr requested 0x%x and got 0x%x",
97
400
                    (guint) 4,
98
400
                    (guint) st->buf->len);
99
400
        return FALSE;
100
400
    }
101
80.6k
    return fu_struct_acpi_phat_hdr_validate_internal(st, error);
102
81.0k
}
103
/**
104
 * fu_struct_acpi_phat_health_record_ref: (skip):
105
 **/
106
FuStructAcpiPhatHealthRecord *
107
fu_struct_acpi_phat_health_record_ref(FuStructAcpiPhatHealthRecord *st)
108
0
{
109
0
    g_return_val_if_fail(st != NULL, NULL);
110
0
    st->refcount++;
111
0
    return st;
112
0
}
113
/**
114
 * fu_struct_acpi_phat_health_record_unref: (skip):
115
 **/
116
void
117
fu_struct_acpi_phat_health_record_unref(FuStructAcpiPhatHealthRecord *st)
118
3.11k
{
119
3.11k
    g_return_if_fail(st != NULL);
120
3.11k
    if (st->refcount == 0) {
121
0
        g_critical("FuStructAcpiPhatHealthRecord refcount already zero");
122
0
        return;
123
0
    }
124
3.11k
    if (--st->refcount > 0)
125
0
        return;
126
3.11k
    if (st->buf != NULL)
127
2.18k
        g_byte_array_unref(st->buf);
128
3.11k
    g_free(st);
129
3.11k
}
130
static FuStructAcpiPhatHealthRecord *
131
fu_struct_acpi_phat_health_record_new_internal(void)
132
3.11k
{
133
3.11k
    FuStructAcpiPhatHealthRecord *st = g_new0(FuStructAcpiPhatHealthRecord, 1);
134
3.11k
    st->refcount = 1;
135
3.11k
    return st;
136
3.11k
}
137
138
/* getters */
139
/**
140
 * fu_struct_acpi_phat_health_record_get_signature: (skip):
141
 **/
142
guint16
143
fu_struct_acpi_phat_health_record_get_signature(const FuStructAcpiPhatHealthRecord *st)
144
0
{
145
0
    g_return_val_if_fail(st != NULL, 0x0);
146
0
    return fu_memread_uint16(st->buf->data + 0, G_LITTLE_ENDIAN);
147
0
}
148
/**
149
 * fu_struct_acpi_phat_health_record_get_rcdlen: (skip):
150
 **/
151
guint16
152
fu_struct_acpi_phat_health_record_get_rcdlen(const FuStructAcpiPhatHealthRecord *st)
153
2.15k
{
154
2.15k
    g_return_val_if_fail(st != NULL, 0x0);
155
2.15k
    return fu_memread_uint16(st->buf->data + 2, G_LITTLE_ENDIAN);
156
2.15k
}
157
/**
158
 * fu_struct_acpi_phat_health_record_get_version: (skip):
159
 **/
160
guint8
161
fu_struct_acpi_phat_health_record_get_version(const FuStructAcpiPhatHealthRecord *st)
162
0
{
163
0
    g_return_val_if_fail(st != NULL, 0x0);
164
0
    return st->buf->data[4];
165
0
}
166
/**
167
 * fu_struct_acpi_phat_health_record_get_flags: (skip):
168
 **/
169
guint8
170
fu_struct_acpi_phat_health_record_get_flags(const FuStructAcpiPhatHealthRecord *st)
171
2.15k
{
172
2.15k
    g_return_val_if_fail(st != NULL, 0x0);
173
2.15k
    return st->buf->data[7];
174
2.15k
}
175
/**
176
 * fu_struct_acpi_phat_health_record_get_device_signature: (skip):
177
 **/
178
const fwupd_guid_t *
179
fu_struct_acpi_phat_health_record_get_device_signature(const FuStructAcpiPhatHealthRecord *st)
180
2.15k
{
181
2.15k
    g_return_val_if_fail(st != NULL, NULL);
182
2.15k
    return (const fwupd_guid_t *) (st->buf->data + 8);
183
2.15k
}
184
/**
185
 * fu_struct_acpi_phat_health_record_get_device_specific_data: (skip):
186
 **/
187
guint32
188
fu_struct_acpi_phat_health_record_get_device_specific_data(const FuStructAcpiPhatHealthRecord *st)
189
2.15k
{
190
2.15k
    g_return_val_if_fail(st != NULL, 0x0);
191
2.15k
    return fu_memread_uint32(st->buf->data + 24, G_LITTLE_ENDIAN);
192
2.15k
}
193
194
/* setters */
195
/**
196
 * fu_struct_acpi_phat_health_record_set_signature: (skip):
197
 **/
198
void
199
fu_struct_acpi_phat_health_record_set_signature(FuStructAcpiPhatHealthRecord *st, guint16 value)
200
930
{
201
930
    g_return_if_fail(st != NULL);
202
930
    fu_memwrite_uint16(st->buf->data + 0, value, G_LITTLE_ENDIAN);
203
930
}
204
/**
205
 * fu_struct_acpi_phat_health_record_set_rcdlen: (skip):
206
 **/
207
void
208
fu_struct_acpi_phat_health_record_set_rcdlen(FuStructAcpiPhatHealthRecord *st, guint16 value)
209
930
{
210
930
    g_return_if_fail(st != NULL);
211
930
    fu_memwrite_uint16(st->buf->data + 2, value, G_LITTLE_ENDIAN);
212
930
}
213
/**
214
 * fu_struct_acpi_phat_health_record_set_version: (skip):
215
 **/
216
void
217
fu_struct_acpi_phat_health_record_set_version(FuStructAcpiPhatHealthRecord *st, guint8 value)
218
930
{
219
930
    g_return_if_fail(st != NULL);
220
930
    st->buf->data[4] = value;
221
930
}
222
/**
223
 * fu_struct_acpi_phat_health_record_set_flags: (skip):
224
 **/
225
void
226
fu_struct_acpi_phat_health_record_set_flags(FuStructAcpiPhatHealthRecord *st, guint8 value)
227
930
{
228
930
    g_return_if_fail(st != NULL);
229
930
    st->buf->data[7] = value;
230
930
}
231
/**
232
 * fu_struct_acpi_phat_health_record_set_device_signature: (skip):
233
 **/
234
void
235
fu_struct_acpi_phat_health_record_set_device_signature(FuStructAcpiPhatHealthRecord *st, const fwupd_guid_t *value)
236
930
{
237
930
    g_return_if_fail(st != NULL);
238
930
    g_return_if_fail(value != NULL);
239
930
    memcpy(st->buf->data + 8, value, sizeof(*value)); /* nocheck:blocked */
240
930
}
241
/**
242
 * fu_struct_acpi_phat_health_record_set_device_specific_data: (skip):
243
 **/
244
void
245
fu_struct_acpi_phat_health_record_set_device_specific_data(FuStructAcpiPhatHealthRecord *st, guint32 value)
246
0
{
247
0
    g_return_if_fail(st != NULL);
248
0
    fu_memwrite_uint32(st->buf->data + 24, value, G_LITTLE_ENDIAN);
249
0
}
250
/**
251
 * fu_struct_acpi_phat_health_record_new: (skip):
252
 **/
253
FuStructAcpiPhatHealthRecord *
254
fu_struct_acpi_phat_health_record_new(void)
255
930
{
256
930
    FuStructAcpiPhatHealthRecord *st = fu_struct_acpi_phat_health_record_new_internal();
257
930
    st->buf = g_byte_array_sized_new(28);
258
930
    fu_byte_array_set_size(st->buf, 28, 0x0);
259
930
    fu_struct_acpi_phat_health_record_set_signature(st, 0x1);
260
930
    return st;
261
930
}
262
/**
263
 * fu_struct_acpi_phat_health_record_to_string: (skip):
264
 **/
265
static gchar *
266
fu_struct_acpi_phat_health_record_to_string(const FuStructAcpiPhatHealthRecord *st)
267
0
{
268
0
    g_autoptr(GString) str = g_string_new("FuStructAcpiPhatHealthRecord:\n");
269
0
    g_return_val_if_fail(st != NULL, NULL);
270
0
    g_string_append_printf(str, "  signature: 0x%x\n",
271
0
                           (guint) fu_struct_acpi_phat_health_record_get_signature(st));
272
0
    g_string_append_printf(str, "  rcdlen: 0x%x\n",
273
0
                           (guint) fu_struct_acpi_phat_health_record_get_rcdlen(st));
274
0
    g_string_append_printf(str, "  version: 0x%x\n",
275
0
                           (guint) fu_struct_acpi_phat_health_record_get_version(st));
276
0
    g_string_append_printf(str, "  flags: 0x%x\n",
277
0
                           (guint) fu_struct_acpi_phat_health_record_get_flags(st));
278
0
    {
279
0
        g_autofree gchar *tmp = fwupd_guid_to_string(fu_struct_acpi_phat_health_record_get_device_signature(st), FWUPD_GUID_FLAG_MIXED_ENDIAN);
280
0
        g_string_append_printf(str, "  device_signature: %s\n", tmp);
281
0
    }
282
0
    g_string_append_printf(str, "  device_specific_data: 0x%x\n",
283
0
                           (guint) fu_struct_acpi_phat_health_record_get_device_specific_data(st));
284
0
    if (str->len > 0)
285
0
        g_string_set_size(str, str->len - 1);
286
0
    return g_string_free(g_steal_pointer(&str), FALSE);
287
0
}
288
static gboolean
289
fu_struct_acpi_phat_health_record_validate_internal(FuStructAcpiPhatHealthRecord *st, GError **error)
290
2.15k
{
291
2.15k
    g_return_val_if_fail(st != NULL, FALSE);
292
2.15k
    return TRUE;
293
2.15k
}
294
static gboolean
295
fu_struct_acpi_phat_health_record_parse_internal(FuStructAcpiPhatHealthRecord *st, GError **error)
296
2.15k
{
297
2.15k
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
298
0
        g_autofree gchar *str = fu_struct_acpi_phat_health_record_to_string(st);
299
0
        g_debug("%s", str);
300
0
    }
301
2.15k
    if (!fu_struct_acpi_phat_health_record_validate_internal(st, error))
302
0
        return FALSE;
303
2.15k
    return TRUE;
304
2.15k
}
305
/**
306
 * fu_struct_acpi_phat_health_record_parse_stream: (skip):
307
 **/
308
FuStructAcpiPhatHealthRecord *
309
fu_struct_acpi_phat_health_record_parse_stream(GInputStream *stream, gsize offset, GError **error)
310
2.18k
{
311
2.18k
    g_autoptr(FuStructAcpiPhatHealthRecord) st = fu_struct_acpi_phat_health_record_new_internal();
312
2.18k
    st->buf = fu_input_stream_read_byte_array(stream, offset, 28, NULL, error);
313
2.18k
    if (st->buf == NULL) {
314
0
        g_prefix_error(error, "FuStructAcpiPhatHealthRecord failed read of 0x%x: ", (guint) 28);
315
0
        return NULL;
316
0
    }
317
2.18k
    if (st->buf->len != 28) {
318
32
        g_set_error(error,
319
32
                    FWUPD_ERROR,
320
32
                    FWUPD_ERROR_INVALID_DATA,
321
32
                    "FuStructAcpiPhatHealthRecord requested 0x%x and got 0x%x",
322
32
                    (guint) 28,
323
32
                    (guint) st->buf->len);
324
32
        return NULL;
325
32
    }
326
2.15k
    if (!fu_struct_acpi_phat_health_record_parse_internal(st, error))
327
0
        return NULL;
328
2.15k
    return g_steal_pointer(&st);
329
2.15k
}
330
/**
331
 * fu_struct_acpi_phat_version_element_ref: (skip):
332
 **/
333
FuStructAcpiPhatVersionElement *
334
fu_struct_acpi_phat_version_element_ref(FuStructAcpiPhatVersionElement *st)
335
0
{
336
0
    g_return_val_if_fail(st != NULL, NULL);
337
0
    st->refcount++;
338
0
    return st;
339
0
}
340
/**
341
 * fu_struct_acpi_phat_version_element_unref: (skip):
342
 **/
343
void
344
fu_struct_acpi_phat_version_element_unref(FuStructAcpiPhatVersionElement *st)
345
30.0k
{
346
30.0k
    g_return_if_fail(st != NULL);
347
30.0k
    if (st->refcount == 0) {
348
0
        g_critical("FuStructAcpiPhatVersionElement refcount already zero");
349
0
        return;
350
0
    }
351
30.0k
    if (--st->refcount > 0)
352
0
        return;
353
30.0k
    if (st->buf != NULL)
354
25.4k
        g_byte_array_unref(st->buf);
355
30.0k
    g_free(st);
356
30.0k
}
357
static FuStructAcpiPhatVersionElement *
358
fu_struct_acpi_phat_version_element_new_internal(void)
359
30.0k
{
360
30.0k
    FuStructAcpiPhatVersionElement *st = g_new0(FuStructAcpiPhatVersionElement, 1);
361
30.0k
    st->refcount = 1;
362
30.0k
    return st;
363
30.0k
}
364
365
/* getters */
366
/**
367
 * fu_struct_acpi_phat_version_element_get_component_id: (skip):
368
 **/
369
const fwupd_guid_t *
370
fu_struct_acpi_phat_version_element_get_component_id(const FuStructAcpiPhatVersionElement *st)
371
25.4k
{
372
25.4k
    g_return_val_if_fail(st != NULL, NULL);
373
25.4k
    return (const fwupd_guid_t *) (st->buf->data + 0);
374
25.4k
}
375
/**
376
 * fu_struct_acpi_phat_version_element_get_version_value: (skip):
377
 **/
378
guint64
379
fu_struct_acpi_phat_version_element_get_version_value(const FuStructAcpiPhatVersionElement *st)
380
25.4k
{
381
25.4k
    g_return_val_if_fail(st != NULL, 0x0);
382
25.4k
    return fu_memread_uint64(st->buf->data + 16, G_LITTLE_ENDIAN);
383
25.4k
}
384
/**
385
 * fu_struct_acpi_phat_version_element_get_producer_id: (skip):
386
 **/
387
gchar *
388
fu_struct_acpi_phat_version_element_get_producer_id(const FuStructAcpiPhatVersionElement *st)
389
25.4k
{
390
25.4k
    g_return_val_if_fail(st != NULL, NULL);
391
25.4k
    return fu_memstrsafe(st->buf->data, st->buf->len, 24, 4, NULL);
392
25.4k
}
393
394
/* setters */
395
/**
396
 * fu_struct_acpi_phat_version_element_set_component_id: (skip):
397
 **/
398
void
399
fu_struct_acpi_phat_version_element_set_component_id(FuStructAcpiPhatVersionElement *st, const fwupd_guid_t *value)
400
4.64k
{
401
4.64k
    g_return_if_fail(st != NULL);
402
4.64k
    g_return_if_fail(value != NULL);
403
4.64k
    memcpy(st->buf->data + 0, value, sizeof(*value)); /* nocheck:blocked */
404
4.64k
}
405
/**
406
 * fu_struct_acpi_phat_version_element_set_version_value: (skip):
407
 **/
408
void
409
fu_struct_acpi_phat_version_element_set_version_value(FuStructAcpiPhatVersionElement *st, guint64 value)
410
4.64k
{
411
4.64k
    g_return_if_fail(st != NULL);
412
4.64k
    fu_memwrite_uint64(st->buf->data + 16, value, G_LITTLE_ENDIAN);
413
4.64k
}
414
/**
415
 * fu_struct_acpi_phat_version_element_set_producer_id: (skip):
416
 **/
417
gboolean
418
fu_struct_acpi_phat_version_element_set_producer_id(FuStructAcpiPhatVersionElement *st, const gchar *value, GError **error)
419
4.64k
{
420
4.64k
    gsize len;
421
4.64k
    g_return_val_if_fail(st != NULL, FALSE);
422
4.64k
    g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
423
4.64k
    if (value == NULL) {
424
2.61k
        memset(st->buf->data + 24, 0x0, 4);
425
2.61k
        return TRUE;
426
2.61k
    }
427
2.02k
    len = strlen(value);
428
2.02k
    if (len > 4) {
429
0
        g_set_error(error,
430
0
                    FWUPD_ERROR,
431
0
                    FWUPD_ERROR_INVALID_DATA,
432
0
                    "string '%s' (0x%x bytes) does not fit in FuStructAcpiPhatVersionElement.producer_id (0x%x bytes)",
433
0
                    value, (guint) len, (guint) 4);
434
0
        return FALSE;
435
0
    }
436
2.02k
    return fu_memcpy_safe(st->buf->data, st->buf->len, 24, (const guint8 *)value, len, 0x0, len, error);
437
2.02k
}
438
/**
439
 * fu_struct_acpi_phat_version_element_new: (skip):
440
 **/
441
FuStructAcpiPhatVersionElement *
442
fu_struct_acpi_phat_version_element_new(void)
443
4.64k
{
444
4.64k
    FuStructAcpiPhatVersionElement *st = fu_struct_acpi_phat_version_element_new_internal();
445
4.64k
    st->buf = g_byte_array_sized_new(28);
446
4.64k
    fu_byte_array_set_size(st->buf, 28, 0x0);
447
4.64k
    return st;
448
4.64k
}
449
/**
450
 * fu_struct_acpi_phat_version_element_to_string: (skip):
451
 **/
452
static gchar *
453
fu_struct_acpi_phat_version_element_to_string(const FuStructAcpiPhatVersionElement *st)
454
0
{
455
0
    g_autoptr(GString) str = g_string_new("FuStructAcpiPhatVersionElement:\n");
456
0
    g_return_val_if_fail(st != NULL, NULL);
457
0
    {
458
0
        g_autofree gchar *tmp = fwupd_guid_to_string(fu_struct_acpi_phat_version_element_get_component_id(st), FWUPD_GUID_FLAG_MIXED_ENDIAN);
459
0
        g_string_append_printf(str, "  component_id: %s\n", tmp);
460
0
    }
461
0
    g_string_append_printf(str, "  version_value: 0x%x\n",
462
0
                           (guint) fu_struct_acpi_phat_version_element_get_version_value(st));
463
0
    {
464
0
        g_autofree gchar *tmp = fu_struct_acpi_phat_version_element_get_producer_id(st);
465
0
        if (tmp != NULL)
466
0
            g_string_append_printf(str, "  producer_id: %s\n", tmp);
467
0
    }
468
0
    if (str->len > 0)
469
0
        g_string_set_size(str, str->len - 1);
470
0
    return g_string_free(g_steal_pointer(&str), FALSE);
471
0
}
472
static gboolean
473
fu_struct_acpi_phat_version_element_validate_internal(FuStructAcpiPhatVersionElement *st, GError **error)
474
25.4k
{
475
25.4k
    g_return_val_if_fail(st != NULL, FALSE);
476
25.4k
    return TRUE;
477
25.4k
}
478
static gboolean
479
fu_struct_acpi_phat_version_element_parse_internal(FuStructAcpiPhatVersionElement *st, GError **error)
480
25.4k
{
481
25.4k
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
482
0
        g_autofree gchar *str = fu_struct_acpi_phat_version_element_to_string(st);
483
0
        g_debug("%s", str);
484
0
    }
485
25.4k
    if (!fu_struct_acpi_phat_version_element_validate_internal(st, error))
486
0
        return FALSE;
487
25.4k
    return TRUE;
488
25.4k
}
489
/**
490
 * fu_struct_acpi_phat_version_element_parse_stream: (skip):
491
 **/
492
FuStructAcpiPhatVersionElement *
493
fu_struct_acpi_phat_version_element_parse_stream(GInputStream *stream, gsize offset, GError **error)
494
25.4k
{
495
25.4k
    g_autoptr(FuStructAcpiPhatVersionElement) st = fu_struct_acpi_phat_version_element_new_internal();
496
25.4k
    st->buf = fu_input_stream_read_byte_array(stream, offset, 28, NULL, error);
497
25.4k
    if (st->buf == NULL) {
498
0
        g_prefix_error(error, "FuStructAcpiPhatVersionElement failed read of 0x%x: ", (guint) 28);
499
0
        return NULL;
500
0
    }
501
25.4k
    if (st->buf->len != 28) {
502
0
        g_set_error(error,
503
0
                    FWUPD_ERROR,
504
0
                    FWUPD_ERROR_INVALID_DATA,
505
0
                    "FuStructAcpiPhatVersionElement requested 0x%x and got 0x%x",
506
0
                    (guint) 28,
507
0
                    (guint) st->buf->len);
508
0
        return NULL;
509
0
    }
510
25.4k
    if (!fu_struct_acpi_phat_version_element_parse_internal(st, error))
511
0
        return NULL;
512
25.4k
    return g_steal_pointer(&st);
513
25.4k
}
514
/**
515
 * fu_struct_acpi_phat_version_record_ref: (skip):
516
 **/
517
FuStructAcpiPhatVersionRecord *
518
fu_struct_acpi_phat_version_record_ref(FuStructAcpiPhatVersionRecord *st)
519
0
{
520
0
    g_return_val_if_fail(st != NULL, NULL);
521
0
    st->refcount++;
522
0
    return st;
523
0
}
524
/**
525
 * fu_struct_acpi_phat_version_record_unref: (skip):
526
 **/
527
void
528
fu_struct_acpi_phat_version_record_unref(FuStructAcpiPhatVersionRecord *st)
529
26.2k
{
530
26.2k
    g_return_if_fail(st != NULL);
531
26.2k
    if (st->refcount == 0) {
532
0
        g_critical("FuStructAcpiPhatVersionRecord refcount already zero");
533
0
        return;
534
0
    }
535
26.2k
    if (--st->refcount > 0)
536
0
        return;
537
26.2k
    if (st->buf != NULL)
538
20.3k
        g_byte_array_unref(st->buf);
539
26.2k
    g_free(st);
540
26.2k
}
541
static FuStructAcpiPhatVersionRecord *
542
fu_struct_acpi_phat_version_record_new_internal(void)
543
26.2k
{
544
26.2k
    FuStructAcpiPhatVersionRecord *st = g_new0(FuStructAcpiPhatVersionRecord, 1);
545
26.2k
    st->refcount = 1;
546
26.2k
    return st;
547
26.2k
}
548
549
/* getters */
550
/**
551
 * fu_struct_acpi_phat_version_record_get_signature: (skip):
552
 **/
553
guint16
554
fu_struct_acpi_phat_version_record_get_signature(const FuStructAcpiPhatVersionRecord *st)
555
0
{
556
0
    g_return_val_if_fail(st != NULL, 0x0);
557
0
    return fu_memread_uint16(st->buf->data + 0, G_LITTLE_ENDIAN);
558
0
}
559
/**
560
 * fu_struct_acpi_phat_version_record_get_rcdlen: (skip):
561
 **/
562
guint16
563
fu_struct_acpi_phat_version_record_get_rcdlen(const FuStructAcpiPhatVersionRecord *st)
564
0
{
565
0
    g_return_val_if_fail(st != NULL, 0x0);
566
0
    return fu_memread_uint16(st->buf->data + 2, G_LITTLE_ENDIAN);
567
0
}
568
/**
569
 * fu_struct_acpi_phat_version_record_get_version: (skip):
570
 **/
571
guint8
572
fu_struct_acpi_phat_version_record_get_version(const FuStructAcpiPhatVersionRecord *st)
573
0
{
574
0
    g_return_val_if_fail(st != NULL, 0x0);
575
0
    return st->buf->data[4];
576
0
}
577
/**
578
 * fu_struct_acpi_phat_version_record_get_record_count: (skip):
579
 **/
580
guint32
581
fu_struct_acpi_phat_version_record_get_record_count(const FuStructAcpiPhatVersionRecord *st)
582
20.2k
{
583
20.2k
    g_return_val_if_fail(st != NULL, 0x0);
584
20.2k
    return fu_memread_uint32(st->buf->data + 8, G_LITTLE_ENDIAN);
585
20.2k
}
586
587
/* setters */
588
/**
589
 * fu_struct_acpi_phat_version_record_set_signature: (skip):
590
 **/
591
void
592
fu_struct_acpi_phat_version_record_set_signature(FuStructAcpiPhatVersionRecord *st, guint16 value)
593
5.89k
{
594
5.89k
    g_return_if_fail(st != NULL);
595
5.89k
    fu_memwrite_uint16(st->buf->data + 0, value, G_LITTLE_ENDIAN);
596
5.89k
}
597
/**
598
 * fu_struct_acpi_phat_version_record_set_rcdlen: (skip):
599
 **/
600
void
601
fu_struct_acpi_phat_version_record_set_rcdlen(FuStructAcpiPhatVersionRecord *st, guint16 value)
602
5.89k
{
603
5.89k
    g_return_if_fail(st != NULL);
604
5.89k
    fu_memwrite_uint16(st->buf->data + 2, value, G_LITTLE_ENDIAN);
605
5.89k
}
606
/**
607
 * fu_struct_acpi_phat_version_record_set_version: (skip):
608
 **/
609
void
610
fu_struct_acpi_phat_version_record_set_version(FuStructAcpiPhatVersionRecord *st, guint8 value)
611
5.89k
{
612
5.89k
    g_return_if_fail(st != NULL);
613
5.89k
    st->buf->data[4] = value;
614
5.89k
}
615
/**
616
 * fu_struct_acpi_phat_version_record_set_record_count: (skip):
617
 **/
618
void
619
fu_struct_acpi_phat_version_record_set_record_count(FuStructAcpiPhatVersionRecord *st, guint32 value)
620
5.89k
{
621
5.89k
    g_return_if_fail(st != NULL);
622
5.89k
    fu_memwrite_uint32(st->buf->data + 8, value, G_LITTLE_ENDIAN);
623
5.89k
}
624
/**
625
 * fu_struct_acpi_phat_version_record_new: (skip):
626
 **/
627
FuStructAcpiPhatVersionRecord *
628
fu_struct_acpi_phat_version_record_new(void)
629
5.89k
{
630
5.89k
    FuStructAcpiPhatVersionRecord *st = fu_struct_acpi_phat_version_record_new_internal();
631
5.89k
    st->buf = g_byte_array_sized_new(12);
632
5.89k
    fu_byte_array_set_size(st->buf, 12, 0x0);
633
5.89k
    fu_struct_acpi_phat_version_record_set_signature(st, 0x0);
634
5.89k
    return st;
635
5.89k
}
636
/**
637
 * fu_struct_acpi_phat_version_record_to_string: (skip):
638
 **/
639
static gchar *
640
fu_struct_acpi_phat_version_record_to_string(const FuStructAcpiPhatVersionRecord *st)
641
0
{
642
0
    g_autoptr(GString) str = g_string_new("FuStructAcpiPhatVersionRecord:\n");
643
0
    g_return_val_if_fail(st != NULL, NULL);
644
0
    g_string_append_printf(str, "  signature: 0x%x\n",
645
0
                           (guint) fu_struct_acpi_phat_version_record_get_signature(st));
646
0
    g_string_append_printf(str, "  rcdlen: 0x%x\n",
647
0
                           (guint) fu_struct_acpi_phat_version_record_get_rcdlen(st));
648
0
    g_string_append_printf(str, "  version: 0x%x\n",
649
0
                           (guint) fu_struct_acpi_phat_version_record_get_version(st));
650
0
    g_string_append_printf(str, "  record_count: 0x%x\n",
651
0
                           (guint) fu_struct_acpi_phat_version_record_get_record_count(st));
652
0
    if (str->len > 0)
653
0
        g_string_set_size(str, str->len - 1);
654
0
    return g_string_free(g_steal_pointer(&str), FALSE);
655
0
}
656
static gboolean
657
fu_struct_acpi_phat_version_record_validate_internal(FuStructAcpiPhatVersionRecord *st, GError **error)
658
20.2k
{
659
20.2k
    g_return_val_if_fail(st != NULL, FALSE);
660
20.2k
    return TRUE;
661
20.2k
}
662
static gboolean
663
fu_struct_acpi_phat_version_record_parse_internal(FuStructAcpiPhatVersionRecord *st, GError **error)
664
20.2k
{
665
20.2k
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
666
0
        g_autofree gchar *str = fu_struct_acpi_phat_version_record_to_string(st);
667
0
        g_debug("%s", str);
668
0
    }
669
20.2k
    if (!fu_struct_acpi_phat_version_record_validate_internal(st, error))
670
0
        return FALSE;
671
20.2k
    return TRUE;
672
20.2k
}
673
/**
674
 * fu_struct_acpi_phat_version_record_parse_stream: (skip):
675
 **/
676
FuStructAcpiPhatVersionRecord *
677
fu_struct_acpi_phat_version_record_parse_stream(GInputStream *stream, gsize offset, GError **error)
678
20.3k
{
679
20.3k
    g_autoptr(FuStructAcpiPhatVersionRecord) st = fu_struct_acpi_phat_version_record_new_internal();
680
20.3k
    st->buf = fu_input_stream_read_byte_array(stream, offset, 12, NULL, error);
681
20.3k
    if (st->buf == NULL) {
682
0
        g_prefix_error(error, "FuStructAcpiPhatVersionRecord failed read of 0x%x: ", (guint) 12);
683
0
        return NULL;
684
0
    }
685
20.3k
    if (st->buf->len != 12) {
686
38
        g_set_error(error,
687
38
                    FWUPD_ERROR,
688
38
                    FWUPD_ERROR_INVALID_DATA,
689
38
                    "FuStructAcpiPhatVersionRecord requested 0x%x and got 0x%x",
690
38
                    (guint) 12,
691
38
                    (guint) st->buf->len);
692
38
        return NULL;
693
38
    }
694
20.2k
    if (!fu_struct_acpi_phat_version_record_parse_internal(st, error))
695
0
        return NULL;
696
20.2k
    return g_steal_pointer(&st);
697
20.2k
}