Coverage Report

Created: 2026-05-30 06:50

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