Coverage Report

Created: 2025-11-11 06:44

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