Coverage Report

Created: 2026-04-28 06:49

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
/* setters */
126
/**
127
 * fu_struct_acpi_table_set_signature: (skip):
128
 **/
129
gboolean
130
fu_struct_acpi_table_set_signature(FuStructAcpiTable *st, const gchar *value, GError **error)
131
0
{
132
0
    gsize len;
133
0
    g_return_val_if_fail(st != NULL, FALSE);
134
0
    g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
135
0
    if (value == NULL) {
136
0
        memset(st->buf->data + 0, 0x0, 4);
137
0
        return TRUE;
138
0
    }
139
0
    len = strlen(value);
140
0
    if (len > 4) {
141
0
        g_set_error(error,
142
0
                    FWUPD_ERROR,
143
0
                    FWUPD_ERROR_INVALID_DATA,
144
0
                    "string '%s' (0x%x bytes) does not fit in FuStructAcpiTable.signature (0x%x bytes)",
145
0
                    value, (guint) len, (guint) 4);
146
0
        return FALSE;
147
0
    }
148
0
    return fu_memcpy_safe(st->buf->data, st->buf->len, 0, (const guint8 *)value, len, 0x0, len, error);
149
0
}
150
/**
151
 * fu_struct_acpi_table_set_length: (skip):
152
 **/
153
void
154
fu_struct_acpi_table_set_length(FuStructAcpiTable *st, guint32 value)
155
0
{
156
0
    g_return_if_fail(st != NULL);
157
0
    fu_memwrite_uint32(st->buf->data + 4, value, G_LITTLE_ENDIAN);
158
0
}
159
/**
160
 * fu_struct_acpi_table_set_revision: (skip):
161
 **/
162
void
163
fu_struct_acpi_table_set_revision(FuStructAcpiTable *st, guint8 value)
164
0
{
165
0
    g_return_if_fail(st != NULL);
166
0
    st->buf->data[8] = value;
167
0
}
168
/**
169
 * fu_struct_acpi_table_set_checksum: (skip):
170
 **/
171
void
172
fu_struct_acpi_table_set_checksum(FuStructAcpiTable *st, guint8 value)
173
0
{
174
0
    g_return_if_fail(st != NULL);
175
0
    st->buf->data[9] = value;
176
0
}
177
/**
178
 * fu_struct_acpi_table_set_oem_id: (skip):
179
 **/
180
gboolean
181
fu_struct_acpi_table_set_oem_id(FuStructAcpiTable *st, const gchar *value, GError **error)
182
0
{
183
0
    gsize len;
184
0
    g_return_val_if_fail(st != NULL, FALSE);
185
0
    g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
186
0
    if (value == NULL) {
187
0
        memset(st->buf->data + 10, 0x0, 6);
188
0
        return TRUE;
189
0
    }
190
0
    len = strlen(value);
191
0
    if (len > 6) {
192
0
        g_set_error(error,
193
0
                    FWUPD_ERROR,
194
0
                    FWUPD_ERROR_INVALID_DATA,
195
0
                    "string '%s' (0x%x bytes) does not fit in FuStructAcpiTable.oem_id (0x%x bytes)",
196
0
                    value, (guint) len, (guint) 6);
197
0
        return FALSE;
198
0
    }
199
0
    return fu_memcpy_safe(st->buf->data, st->buf->len, 10, (const guint8 *)value, len, 0x0, len, error);
200
0
}
201
/**
202
 * fu_struct_acpi_table_set_oem_table_id: (skip):
203
 **/
204
gboolean
205
fu_struct_acpi_table_set_oem_table_id(FuStructAcpiTable *st, const gchar *value, GError **error)
206
0
{
207
0
    gsize len;
208
0
    g_return_val_if_fail(st != NULL, FALSE);
209
0
    g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
210
0
    if (value == NULL) {
211
0
        memset(st->buf->data + 16, 0x0, 8);
212
0
        return TRUE;
213
0
    }
214
0
    len = strlen(value);
215
0
    if (len > 8) {
216
0
        g_set_error(error,
217
0
                    FWUPD_ERROR,
218
0
                    FWUPD_ERROR_INVALID_DATA,
219
0
                    "string '%s' (0x%x bytes) does not fit in FuStructAcpiTable.oem_table_id (0x%x bytes)",
220
0
                    value, (guint) len, (guint) 8);
221
0
        return FALSE;
222
0
    }
223
0
    return fu_memcpy_safe(st->buf->data, st->buf->len, 16, (const guint8 *)value, len, 0x0, len, error);
224
0
}
225
/**
226
 * fu_struct_acpi_table_set_oem_revision: (skip):
227
 **/
228
void
229
fu_struct_acpi_table_set_oem_revision(FuStructAcpiTable *st, guint32 value)
230
0
{
231
0
    g_return_if_fail(st != NULL);
232
0
    fu_memwrite_uint32(st->buf->data + 24, value, G_BIG_ENDIAN);
233
0
}
234
/**
235
 * fu_struct_acpi_table_new: (skip):
236
 **/
237
FuStructAcpiTable *
238
fu_struct_acpi_table_new(void)
239
0
{
240
0
    FuStructAcpiTable *st = fu_struct_acpi_table_new_internal();
241
0
    st->buf = g_byte_array_sized_new(36);
242
0
    fu_byte_array_set_size(st->buf, 36, 0x0);
243
0
    return st;
244
0
}
245
/**
246
 * fu_struct_acpi_table_to_string: (skip):
247
 **/
248
static gchar *
249
fu_struct_acpi_table_to_string(const FuStructAcpiTable *st)
250
0
{
251
0
    g_autoptr(GString) str = g_string_new("FuStructAcpiTable:\n");
252
0
    g_return_val_if_fail(st != NULL, NULL);
253
0
    {
254
0
        g_autofree gchar *tmp = fu_struct_acpi_table_get_signature(st);
255
0
        if (tmp != NULL)
256
0
            g_string_append_printf(str, "  signature: %s\n", tmp);
257
0
    }
258
0
    g_string_append_printf(str, "  length: 0x%x\n",
259
0
                           (guint) fu_struct_acpi_table_get_length(st));
260
0
    g_string_append_printf(str, "  revision: 0x%x\n",
261
0
                           (guint) fu_struct_acpi_table_get_revision(st));
262
0
    g_string_append_printf(str, "  checksum: 0x%x\n",
263
0
                           (guint) fu_struct_acpi_table_get_checksum(st));
264
0
    {
265
0
        g_autofree gchar *tmp = fu_struct_acpi_table_get_oem_id(st);
266
0
        if (tmp != NULL)
267
0
            g_string_append_printf(str, "  oem_id: %s\n", tmp);
268
0
    }
269
0
    {
270
0
        g_autofree gchar *tmp = fu_struct_acpi_table_get_oem_table_id(st);
271
0
        if (tmp != NULL)
272
0
            g_string_append_printf(str, "  oem_table_id: %s\n", tmp);
273
0
    }
274
0
    g_string_append_printf(str, "  oem_revision: 0x%x\n",
275
0
                           (guint) fu_struct_acpi_table_get_oem_revision(st));
276
0
    if (str->len > 0)
277
0
        g_string_set_size(str, str->len - 1);
278
0
    return g_string_free(g_steal_pointer(&str), FALSE);
279
0
}
280
static gboolean
281
fu_struct_acpi_table_validate_internal(FuStructAcpiTable *st, GError **error)
282
0
{
283
0
    g_return_val_if_fail(st != NULL, FALSE);
284
0
    return TRUE;
285
0
}
286
static gboolean
287
fu_struct_acpi_table_parse_internal(FuStructAcpiTable *st, GError **error)
288
0
{
289
0
    if (g_log_get_debug_enabled()) {
290
0
        g_autofree gchar *str = fu_struct_acpi_table_to_string(st);
291
0
        g_debug("%s", str);
292
0
    }
293
0
    if (!fu_struct_acpi_table_validate_internal(st, error))
294
0
        return FALSE;
295
0
    return TRUE;
296
0
}
297
/**
298
 * fu_struct_acpi_table_parse_stream: (skip):
299
 **/
300
FuStructAcpiTable *
301
fu_struct_acpi_table_parse_stream(GInputStream *stream, gsize offset, GError **error)
302
0
{
303
0
    g_autoptr(FuStructAcpiTable) st = fu_struct_acpi_table_new_internal();
304
0
    st->buf = fu_input_stream_read_byte_array(stream, offset, 36, NULL, error);
305
0
    if (st->buf == NULL) {
306
0
        g_prefix_error(error, "FuStructAcpiTable failed read of 0x%x: ", (guint) 36);
307
0
        return NULL;
308
0
    }
309
0
    if (st->buf->len != 36) {
310
0
        g_set_error(error,
311
0
                    FWUPD_ERROR,
312
0
                    FWUPD_ERROR_INVALID_DATA,
313
0
                    "FuStructAcpiTable requested 0x%x and got 0x%x",
314
0
                    (guint) 36,
315
0
                    (guint) st->buf->len);
316
0
        return NULL;
317
0
    }
318
0
    if (!fu_struct_acpi_table_parse_internal(st, error))
319
0
        return NULL;
320
0
    return g_steal_pointer(&st);
321
0
}