Coverage Report

Created: 2025-07-01 07:09

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