Coverage Report

Created: 2026-12-01 06:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/fu-acpi-table-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-acpi-table-struct.h"
12
#include "fu-byte-array.h"
13
#include "fu-bytes.h"
14
#include "fu-mem.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_acpi_fadt_pm_profile_to_string:
24
 * @val: value, e.g. %FU_ACPI_FADT_PM_PROFILE_DESKTOP
25
 *
26
 * Converts an enumerated value to a string.
27
 *
28
 * Returns: identifier string
29
 **/
30
const gchar *
31
fu_acpi_fadt_pm_profile_to_string(FuAcpiFadtPmProfile val)
32
0
{
33
0
    if (val == FU_ACPI_FADT_PM_PROFILE_UNSPECIFIED)
34
0
        return "unspecified";
35
0
    if (val == FU_ACPI_FADT_PM_PROFILE_DESKTOP)
36
0
        return "desktop";
37
0
    if (val == FU_ACPI_FADT_PM_PROFILE_MOBILE)
38
0
        return "mobile";
39
0
    if (val == FU_ACPI_FADT_PM_PROFILE_WORKSTATION)
40
0
        return "workstation";
41
0
    if (val == FU_ACPI_FADT_PM_PROFILE_ENTERPRISE_SERVER)
42
0
        return "enterprise-server";
43
0
    if (val == FU_ACPI_FADT_PM_PROFILE_SOHO_SERVER)
44
0
        return "soho-server";
45
0
    if (val == FU_ACPI_FADT_PM_PROFILE_APPLIANCE_PC)
46
0
        return "appliance-pc";
47
0
    if (val == FU_ACPI_FADT_PM_PROFILE_PERFORMANCE_SERVER)
48
0
        return "performance-server";
49
0
    if (val == FU_ACPI_FADT_PM_PROFILE_TABLET)
50
0
        return "tablet";
51
0
    return NULL;
52
0
}
53
/**
54
 * fu_struct_acpi_table_ref: (skip):
55
 **/
56
FuStructAcpiTable *
57
fu_struct_acpi_table_ref(FuStructAcpiTable *st)
58
0
{
59
0
    g_return_val_if_fail(st != NULL, NULL);
60
0
    st->refcount++;
61
0
    return st;
62
0
}
63
/**
64
 * fu_struct_acpi_table_unref: (skip):
65
 **/
66
void
67
fu_struct_acpi_table_unref(FuStructAcpiTable *st)
68
2.50k
{
69
2.50k
    g_return_if_fail(st != NULL);
70
2.50k
    if (st->refcount == 0) {
71
0
        g_critical("FuStructAcpiTable refcount already zero");
72
0
        return;
73
0
    }
74
2.50k
    if (--st->refcount > 0)
75
0
        return;
76
2.50k
    if (st->buf != NULL)
77
2.35k
        g_byte_array_unref(st->buf);
78
2.50k
    g_free(st);
79
2.50k
}
80
/**
81
 * fu_struct_acpi_table_new_internal: (skip):
82
 **/
83
static FuStructAcpiTable *
84
fu_struct_acpi_table_new_internal(void)
85
2.50k
{
86
2.50k
    FuStructAcpiTable *st = g_new0(FuStructAcpiTable, 1);
87
2.50k
    st->refcount = 1;
88
2.50k
    return st;
89
2.50k
}
90
91
/* getters */
92
/**
93
 * fu_struct_acpi_table_get_signature: (skip):
94
 **/
95
gchar *
96
fu_struct_acpi_table_get_signature(const FuStructAcpiTable *st)
97
2.33k
{
98
2.33k
    g_return_val_if_fail(st != NULL, NULL);
99
2.33k
    return fu_memstrsafe(st->buf->data, st->buf->len, 0, 4, NULL);
100
2.33k
}
101
/**
102
 * fu_struct_acpi_table_get_length: (skip):
103
 **/
104
guint32
105
fu_struct_acpi_table_get_length(const FuStructAcpiTable *st)
106
2.33k
{
107
2.33k
    g_return_val_if_fail(st != NULL, 0x0);
108
2.33k
    return fu_memread_uint32(st->buf->data + 4, G_LITTLE_ENDIAN);
109
2.33k
}
110
/**
111
 * fu_struct_acpi_table_get_revision: (skip):
112
 **/
113
guint8
114
fu_struct_acpi_table_get_revision(const FuStructAcpiTable *st)
115
2.33k
{
116
2.33k
    g_return_val_if_fail(st != NULL, 0x0);
117
2.33k
    return st->buf->data[8];
118
2.33k
}
119
/**
120
 * fu_struct_acpi_table_get_checksum: (skip):
121
 **/
122
guint8
123
fu_struct_acpi_table_get_checksum(const FuStructAcpiTable *st)
124
0
{
125
0
    g_return_val_if_fail(st != NULL, 0x0);
126
0
    return st->buf->data[9];
127
0
}
128
/**
129
 * fu_struct_acpi_table_get_oem_id: (skip):
130
 **/
131
gchar *
132
fu_struct_acpi_table_get_oem_id(const FuStructAcpiTable *st)
133
2.33k
{
134
2.33k
    g_return_val_if_fail(st != NULL, NULL);
135
2.33k
    return fu_memstrsafe(st->buf->data, st->buf->len, 10, 6, NULL);
136
2.33k
}
137
/**
138
 * fu_struct_acpi_table_get_oem_table_id: (skip):
139
 **/
140
gchar *
141
fu_struct_acpi_table_get_oem_table_id(const FuStructAcpiTable *st)
142
2.33k
{
143
2.33k
    g_return_val_if_fail(st != NULL, NULL);
144
2.33k
    return fu_memstrsafe(st->buf->data, st->buf->len, 16, 8, NULL);
145
2.33k
}
146
/**
147
 * fu_struct_acpi_table_get_oem_revision: (skip):
148
 **/
149
guint32
150
fu_struct_acpi_table_get_oem_revision(const FuStructAcpiTable *st)
151
2.33k
{
152
2.33k
    g_return_val_if_fail(st != NULL, 0x0);
153
2.33k
    return fu_memread_uint32(st->buf->data + 24, G_LITTLE_ENDIAN);
154
2.33k
}
155
/**
156
 * fu_struct_acpi_table_get_creator_id: (skip):
157
 **/
158
gchar *
159
fu_struct_acpi_table_get_creator_id(const FuStructAcpiTable *st)
160
0
{
161
0
    g_return_val_if_fail(st != NULL, NULL);
162
0
    return fu_memstrsafe(st->buf->data, st->buf->len, 28, 4, NULL);
163
0
}
164
/**
165
 * fu_struct_acpi_table_get_creator_revision: (skip):
166
 **/
167
guint32
168
fu_struct_acpi_table_get_creator_revision(const FuStructAcpiTable *st)
169
0
{
170
0
    g_return_val_if_fail(st != NULL, 0x0);
171
0
    return fu_memread_uint32(st->buf->data + 32, G_LITTLE_ENDIAN);
172
0
}
173
174
/* setters */
175
/**
176
 * fu_struct_acpi_table_set_signature: (skip):
177
 **/
178
gboolean
179
fu_struct_acpi_table_set_signature(FuStructAcpiTable *st, const gchar *value, GError **error)
180
147
{
181
147
    gsize len;
182
147
    g_return_val_if_fail(st != NULL, FALSE);
183
147
    g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
184
147
    if (value == NULL) {
185
0
        memset(st->buf->data + 0, 0x0, 4);
186
0
        return TRUE;
187
0
    }
188
147
    len = strlen(value);
189
147
    if (len > 4) {
190
0
        g_set_error(error,
191
0
                    FWUPD_ERROR,
192
0
                    FWUPD_ERROR_INVALID_DATA,
193
0
                    "string '%s' (0x%x bytes) does not fit in FuStructAcpiTable.signature (0x%x bytes)",
194
0
                    value, (guint) len, (guint) 4);
195
0
        return FALSE;
196
0
    }
197
147
    return fu_memcpy_safe(st->buf->data, st->buf->len, 0, (const guint8 *)value, len, 0x0, len, error);
198
147
}
199
/**
200
 * fu_struct_acpi_table_set_length: (skip):
201
 **/
202
void
203
fu_struct_acpi_table_set_length(FuStructAcpiTable *st, guint32 value)
204
147
{
205
147
    g_return_if_fail(st != NULL);
206
147
    fu_memwrite_uint32(st->buf->data + 4, value, G_LITTLE_ENDIAN);
207
147
}
208
/**
209
 * fu_struct_acpi_table_set_revision: (skip):
210
 **/
211
void
212
fu_struct_acpi_table_set_revision(FuStructAcpiTable *st, guint8 value)
213
147
{
214
147
    g_return_if_fail(st != NULL);
215
147
    st->buf->data[8] = value;
216
147
}
217
/**
218
 * fu_struct_acpi_table_set_checksum: (skip):
219
 **/
220
void
221
fu_struct_acpi_table_set_checksum(FuStructAcpiTable *st, guint8 value)
222
147
{
223
147
    g_return_if_fail(st != NULL);
224
147
    st->buf->data[9] = value;
225
147
}
226
/**
227
 * fu_struct_acpi_table_set_oem_id: (skip):
228
 **/
229
gboolean
230
fu_struct_acpi_table_set_oem_id(FuStructAcpiTable *st, const gchar *value, GError **error)
231
147
{
232
147
    gsize len;
233
147
    g_return_val_if_fail(st != NULL, FALSE);
234
147
    g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
235
147
    if (value == NULL) {
236
147
        memset(st->buf->data + 10, 0x0, 6);
237
147
        return TRUE;
238
147
    }
239
0
    len = strlen(value);
240
0
    if (len > 6) {
241
0
        g_set_error(error,
242
0
                    FWUPD_ERROR,
243
0
                    FWUPD_ERROR_INVALID_DATA,
244
0
                    "string '%s' (0x%x bytes) does not fit in FuStructAcpiTable.oem_id (0x%x bytes)",
245
0
                    value, (guint) len, (guint) 6);
246
0
        return FALSE;
247
0
    }
248
0
    return fu_memcpy_safe(st->buf->data, st->buf->len, 10, (const guint8 *)value, len, 0x0, len, error);
249
0
}
250
/**
251
 * fu_struct_acpi_table_set_oem_table_id: (skip):
252
 **/
253
gboolean
254
fu_struct_acpi_table_set_oem_table_id(FuStructAcpiTable *st, const gchar *value, GError **error)
255
147
{
256
147
    gsize len;
257
147
    g_return_val_if_fail(st != NULL, FALSE);
258
147
    g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
259
147
    if (value == NULL) {
260
0
        memset(st->buf->data + 16, 0x0, 8);
261
0
        return TRUE;
262
0
    }
263
147
    len = strlen(value);
264
147
    if (len > 8) {
265
0
        g_set_error(error,
266
0
                    FWUPD_ERROR,
267
0
                    FWUPD_ERROR_INVALID_DATA,
268
0
                    "string '%s' (0x%x bytes) does not fit in FuStructAcpiTable.oem_table_id (0x%x bytes)",
269
0
                    value, (guint) len, (guint) 8);
270
0
        return FALSE;
271
0
    }
272
147
    return fu_memcpy_safe(st->buf->data, st->buf->len, 16, (const guint8 *)value, len, 0x0, len, error);
273
147
}
274
/**
275
 * fu_struct_acpi_table_set_oem_revision: (skip):
276
 **/
277
void
278
fu_struct_acpi_table_set_oem_revision(FuStructAcpiTable *st, guint32 value)
279
147
{
280
147
    g_return_if_fail(st != NULL);
281
147
    fu_memwrite_uint32(st->buf->data + 24, value, G_LITTLE_ENDIAN);
282
147
}
283
/**
284
 * fu_struct_acpi_table_set_creator_id: (skip):
285
 **/
286
gboolean
287
fu_struct_acpi_table_set_creator_id(FuStructAcpiTable *st, const gchar *value, GError **error)
288
147
{
289
147
    gsize len;
290
147
    g_return_val_if_fail(st != NULL, FALSE);
291
147
    g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
292
147
    if (value == NULL) {
293
0
        memset(st->buf->data + 28, 0x0, 4);
294
0
        return TRUE;
295
0
    }
296
147
    len = strlen(value);
297
147
    if (len > 4) {
298
0
        g_set_error(error,
299
0
                    FWUPD_ERROR,
300
0
                    FWUPD_ERROR_INVALID_DATA,
301
0
                    "string '%s' (0x%x bytes) does not fit in FuStructAcpiTable.creator_id (0x%x bytes)",
302
0
                    value, (guint) len, (guint) 4);
303
0
        return FALSE;
304
0
    }
305
147
    return fu_memcpy_safe(st->buf->data, st->buf->len, 28, (const guint8 *)value, len, 0x0, len, error);
306
147
}
307
/**
308
 * fu_struct_acpi_table_set_creator_revision: (skip):
309
 **/
310
void
311
fu_struct_acpi_table_set_creator_revision(FuStructAcpiTable *st, guint32 value)
312
147
{
313
147
    g_return_if_fail(st != NULL);
314
147
    fu_memwrite_uint32(st->buf->data + 32, value, G_LITTLE_ENDIAN);
315
147
}
316
/**
317
 * fu_struct_acpi_table_new: (skip):
318
 **/
319
FuStructAcpiTable *
320
fu_struct_acpi_table_new(void)
321
147
{
322
147
    FuStructAcpiTable *st = fu_struct_acpi_table_new_internal();
323
147
    st->buf = g_byte_array_sized_new(36);
324
147
    fu_byte_array_set_size(st->buf, 36, 0x0);
325
147
    return st;
326
147
}
327
/**
328
 * fu_struct_acpi_table_to_string: (skip):
329
 **/
330
static gchar *
331
fu_struct_acpi_table_to_string(const FuStructAcpiTable *st)
332
0
{
333
0
    g_autoptr(GString) str = g_string_new("FuStructAcpiTable:\n");
334
0
    g_return_val_if_fail(st != NULL, NULL);
335
0
    {
336
0
        g_autofree gchar *tmp = fu_struct_acpi_table_get_signature(st);
337
0
        if (tmp != NULL)
338
0
            g_string_append_printf(str, "  signature: %s\n", tmp);
339
0
    }
340
0
    g_string_append_printf(str, "  length: 0x%x\n",
341
0
                           (guint) fu_struct_acpi_table_get_length(st));
342
0
    g_string_append_printf(str, "  revision: 0x%x\n",
343
0
                           (guint) fu_struct_acpi_table_get_revision(st));
344
0
    g_string_append_printf(str, "  checksum: 0x%x\n",
345
0
                           (guint) fu_struct_acpi_table_get_checksum(st));
346
0
    {
347
0
        g_autofree gchar *tmp = fu_struct_acpi_table_get_oem_id(st);
348
0
        if (tmp != NULL)
349
0
            g_string_append_printf(str, "  oem_id: %s\n", tmp);
350
0
    }
351
0
    {
352
0
        g_autofree gchar *tmp = fu_struct_acpi_table_get_oem_table_id(st);
353
0
        if (tmp != NULL)
354
0
            g_string_append_printf(str, "  oem_table_id: %s\n", tmp);
355
0
    }
356
0
    g_string_append_printf(str, "  oem_revision: 0x%x\n",
357
0
                           (guint) fu_struct_acpi_table_get_oem_revision(st));
358
0
    {
359
0
        g_autofree gchar *tmp = fu_struct_acpi_table_get_creator_id(st);
360
0
        if (tmp != NULL)
361
0
            g_string_append_printf(str, "  creator_id: %s\n", tmp);
362
0
    }
363
0
    g_string_append_printf(str, "  creator_revision: 0x%x\n",
364
0
                           (guint) fu_struct_acpi_table_get_creator_revision(st));
365
0
    if (str->len > 0)
366
0
        g_string_set_size(str, str->len - 1);
367
0
    return g_string_free(g_steal_pointer(&str), FALSE);
368
0
}
369
static gboolean
370
fu_struct_acpi_table_parse_internal(FuStructAcpiTable *st, GError **error)
371
2.33k
{
372
2.33k
    if (g_log_get_debug_enabled()) {
373
0
        g_autofree gchar *str = fu_struct_acpi_table_to_string(st);
374
0
        g_debug("%s", str);
375
0
    }
376
2.33k
    return TRUE;
377
2.33k
}
378
/**
379
 * fu_struct_acpi_table_parse_stream: (skip):
380
 **/
381
FuStructAcpiTable *
382
fu_struct_acpi_table_parse_stream(FuInputStream *stream, gsize offset, GError **error)
383
2.35k
{
384
2.35k
    g_autoptr(FuStructAcpiTable) st = fu_struct_acpi_table_new_internal();
385
2.35k
    st->buf = fu_input_stream_read_byte_array(stream, offset, 36, NULL, error);
386
2.35k
    if (st->buf == NULL) {
387
0
        g_prefix_error(error, "FuStructAcpiTable failed read of 0x%x: ", (guint) 36);
388
0
        return NULL;
389
0
    }
390
2.35k
    if (st->buf->len != 36) {
391
25
        g_set_error(error,
392
25
                    FWUPD_ERROR,
393
25
                    FWUPD_ERROR_INVALID_DATA,
394
25
                    "FuStructAcpiTable requested 0x%x and got 0x%x",
395
25
                    (guint) 36,
396
25
                    (guint) st->buf->len);
397
25
        return NULL;
398
25
    }
399
2.33k
    if (!fu_struct_acpi_table_parse_internal(st, error))
400
0
        return NULL;
401
2.33k
    return g_steal_pointer(&st);
402
2.33k
}