Coverage Report

Created: 2026-01-09 07:21

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