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-fmap-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 | | * fu_struct_fmap_ref: (skip): |
23 | | **/ |
24 | | FuStructFmap * |
25 | | fu_struct_fmap_ref(FuStructFmap *st) |
26 | 0 | { |
27 | 0 | g_return_val_if_fail(st != NULL, NULL); |
28 | 0 | st->refcount++; |
29 | 0 | return st; |
30 | 0 | } |
31 | | /** |
32 | | * fu_struct_fmap_unref: (skip): |
33 | | **/ |
34 | | void |
35 | | fu_struct_fmap_unref(FuStructFmap *st) |
36 | 14.0k | { |
37 | 14.0k | g_return_if_fail(st != NULL); |
38 | 14.0k | if (st->refcount == 0) { |
39 | 0 | g_critical("FuStructFmap refcount already zero"); |
40 | 0 | return; |
41 | 0 | } |
42 | 14.0k | if (--st->refcount > 0) |
43 | 0 | return; |
44 | 14.0k | if (st->buf != NULL) |
45 | 14.0k | g_byte_array_unref(st->buf); |
46 | 14.0k | g_free(st); |
47 | 14.0k | } |
48 | | /** |
49 | | * fu_struct_fmap_new_internal: (skip): |
50 | | **/ |
51 | | static FuStructFmap * |
52 | | fu_struct_fmap_new_internal(void) |
53 | 14.0k | { |
54 | 14.0k | FuStructFmap *st = g_new0(FuStructFmap, 1); |
55 | 14.0k | st->refcount = 1; |
56 | 14.0k | return st; |
57 | 14.0k | } |
58 | | |
59 | | /* getters */ |
60 | | /** |
61 | | * fu_struct_fmap_get_signature: (skip): |
62 | | **/ |
63 | | static gchar * |
64 | | fu_struct_fmap_get_signature(const FuStructFmap *st) |
65 | 156 | { |
66 | 156 | g_return_val_if_fail(st != NULL, NULL); |
67 | 156 | return fu_memstrsafe(st->buf->data, st->buf->len, 0, 8, NULL); |
68 | 156 | } |
69 | | /** |
70 | | * fu_struct_fmap_get_ver_major: (skip): |
71 | | **/ |
72 | | guint8 |
73 | | fu_struct_fmap_get_ver_major(const FuStructFmap *st) |
74 | 6.62k | { |
75 | 6.62k | g_return_val_if_fail(st != NULL, 0x0); |
76 | 6.62k | return st->buf->data[8]; |
77 | 6.62k | } |
78 | | /** |
79 | | * fu_struct_fmap_get_ver_minor: (skip): |
80 | | **/ |
81 | | guint8 |
82 | | fu_struct_fmap_get_ver_minor(const FuStructFmap *st) |
83 | 6.62k | { |
84 | 6.62k | g_return_val_if_fail(st != NULL, 0x0); |
85 | 6.62k | return st->buf->data[9]; |
86 | 6.62k | } |
87 | | /** |
88 | | * fu_struct_fmap_get_base: (skip): |
89 | | **/ |
90 | | guint64 |
91 | | fu_struct_fmap_get_base(const FuStructFmap *st) |
92 | 6.62k | { |
93 | 6.62k | g_return_val_if_fail(st != NULL, 0x0); |
94 | 6.62k | return fu_memread_uint64(st->buf->data + 10, G_LITTLE_ENDIAN); |
95 | 6.62k | } |
96 | | /** |
97 | | * fu_struct_fmap_get_size: (skip): |
98 | | **/ |
99 | | guint32 |
100 | | fu_struct_fmap_get_size(const FuStructFmap *st) |
101 | 6.68k | { |
102 | 6.68k | g_return_val_if_fail(st != NULL, 0x0); |
103 | 6.68k | return fu_memread_uint32(st->buf->data + 18, G_LITTLE_ENDIAN); |
104 | 6.68k | } |
105 | | /** |
106 | | * fu_struct_fmap_get_name: (skip): |
107 | | **/ |
108 | | gchar * |
109 | | fu_struct_fmap_get_name(const FuStructFmap *st) |
110 | 0 | { |
111 | 0 | g_return_val_if_fail(st != NULL, NULL); |
112 | 0 | return fu_memstrsafe(st->buf->data, st->buf->len, 22, 32, NULL); |
113 | 0 | } |
114 | | /** |
115 | | * fu_struct_fmap_get_nareas: (skip): |
116 | | **/ |
117 | | guint16 |
118 | | fu_struct_fmap_get_nareas(const FuStructFmap *st) |
119 | 6.56k | { |
120 | 6.56k | g_return_val_if_fail(st != NULL, 0x0); |
121 | 6.56k | return fu_memread_uint16(st->buf->data + 54, G_LITTLE_ENDIAN); |
122 | 6.56k | } |
123 | | |
124 | | /* setters */ |
125 | | /** |
126 | | * fu_struct_fmap_set_signature: (skip): |
127 | | **/ |
128 | | static gboolean |
129 | | fu_struct_fmap_set_signature(FuStructFmap *st, const gchar *value, GError **error) |
130 | 551 | { |
131 | 551 | gsize len; |
132 | 551 | g_return_val_if_fail(st != NULL, FALSE); |
133 | 551 | g_return_val_if_fail(error == NULL || *error == NULL, FALSE); |
134 | 551 | if (value == NULL) { |
135 | 0 | memset(st->buf->data + 0, 0x0, 8); |
136 | 0 | return TRUE; |
137 | 0 | } |
138 | 551 | len = strlen(value); |
139 | 551 | if (len > 8) { |
140 | 0 | g_set_error(error, |
141 | 0 | FWUPD_ERROR, |
142 | 0 | FWUPD_ERROR_INVALID_DATA, |
143 | 0 | "string '%s' (0x%x bytes) does not fit in FuStructFmap.signature (0x%x bytes)", |
144 | 0 | value, (guint) len, (guint) 8); |
145 | 0 | return FALSE; |
146 | 0 | } |
147 | 551 | return fu_memcpy_safe(st->buf->data, st->buf->len, 0, (const guint8 *)value, len, 0x0, len, error); |
148 | 551 | } |
149 | | /** |
150 | | * fu_struct_fmap_set_ver_major: (skip): |
151 | | **/ |
152 | | void |
153 | | fu_struct_fmap_set_ver_major(FuStructFmap *st, guint8 value) |
154 | 661 | { |
155 | 661 | g_return_if_fail(st != NULL); |
156 | 661 | st->buf->data[8] = value; |
157 | 661 | } |
158 | | /** |
159 | | * fu_struct_fmap_set_ver_minor: (skip): |
160 | | **/ |
161 | | void |
162 | | fu_struct_fmap_set_ver_minor(FuStructFmap *st, guint8 value) |
163 | 661 | { |
164 | 661 | g_return_if_fail(st != NULL); |
165 | 661 | st->buf->data[9] = value; |
166 | 661 | } |
167 | | /** |
168 | | * fu_struct_fmap_set_base: (skip): |
169 | | **/ |
170 | | void |
171 | | fu_struct_fmap_set_base(FuStructFmap *st, guint64 value) |
172 | 110 | { |
173 | 110 | g_return_if_fail(st != NULL); |
174 | 110 | fu_memwrite_uint64(st->buf->data + 10, value, G_LITTLE_ENDIAN); |
175 | 110 | } |
176 | | /** |
177 | | * fu_struct_fmap_set_size: (skip): |
178 | | **/ |
179 | | void |
180 | | fu_struct_fmap_set_size(FuStructFmap *st, guint32 value) |
181 | 110 | { |
182 | 110 | g_return_if_fail(st != NULL); |
183 | 110 | fu_memwrite_uint32(st->buf->data + 18, value, G_LITTLE_ENDIAN); |
184 | 110 | } |
185 | | /** |
186 | | * fu_struct_fmap_set_name: (skip): |
187 | | **/ |
188 | | gboolean |
189 | | fu_struct_fmap_set_name(FuStructFmap *st, const gchar *value, GError **error) |
190 | 0 | { |
191 | 0 | gsize len; |
192 | 0 | g_return_val_if_fail(st != NULL, FALSE); |
193 | 0 | g_return_val_if_fail(error == NULL || *error == NULL, FALSE); |
194 | 0 | if (value == NULL) { |
195 | 0 | memset(st->buf->data + 22, 0x0, 32); |
196 | 0 | return TRUE; |
197 | 0 | } |
198 | 0 | len = strlen(value); |
199 | 0 | if (len > 32) { |
200 | 0 | g_set_error(error, |
201 | 0 | FWUPD_ERROR, |
202 | 0 | FWUPD_ERROR_INVALID_DATA, |
203 | 0 | "string '%s' (0x%x bytes) does not fit in FuStructFmap.name (0x%x bytes)", |
204 | 0 | value, (guint) len, (guint) 32); |
205 | 0 | return FALSE; |
206 | 0 | } |
207 | 0 | return fu_memcpy_safe(st->buf->data, st->buf->len, 22, (const guint8 *)value, len, 0x0, len, error); |
208 | 0 | } |
209 | | /** |
210 | | * fu_struct_fmap_set_nareas: (skip): |
211 | | **/ |
212 | | void |
213 | | fu_struct_fmap_set_nareas(FuStructFmap *st, guint16 value) |
214 | 110 | { |
215 | 110 | g_return_if_fail(st != NULL); |
216 | 110 | fu_memwrite_uint16(st->buf->data + 54, value, G_LITTLE_ENDIAN); |
217 | 110 | } |
218 | | /** |
219 | | * fu_struct_fmap_new: (skip): |
220 | | **/ |
221 | | FuStructFmap * |
222 | | fu_struct_fmap_new(void) |
223 | 551 | { |
224 | 551 | FuStructFmap *st = fu_struct_fmap_new_internal(); |
225 | 551 | st->buf = g_byte_array_sized_new(56); |
226 | 551 | fu_byte_array_set_size(st->buf, 56, 0x0); |
227 | 551 | fu_struct_fmap_set_signature(st, "__FMAP__", NULL); |
228 | 551 | fu_struct_fmap_set_ver_major(st, 0x1); |
229 | 551 | fu_struct_fmap_set_ver_minor(st, 0x1); |
230 | 551 | return st; |
231 | 551 | } |
232 | | /** |
233 | | * fu_struct_fmap_to_string: (skip): |
234 | | **/ |
235 | | static gchar * |
236 | | fu_struct_fmap_to_string(const FuStructFmap *st) |
237 | 0 | { |
238 | 0 | g_autoptr(GString) str = g_string_new("FuStructFmap:\n"); |
239 | 0 | g_return_val_if_fail(st != NULL, NULL); |
240 | 0 | { |
241 | 0 | g_autofree gchar *tmp = fu_struct_fmap_get_signature(st); |
242 | 0 | if (tmp != NULL) |
243 | 0 | g_string_append_printf(str, " signature: %s\n", tmp); |
244 | 0 | } |
245 | 0 | g_string_append_printf(str, " ver_major: 0x%x\n", |
246 | 0 | (guint) fu_struct_fmap_get_ver_major(st)); |
247 | 0 | g_string_append_printf(str, " ver_minor: 0x%x\n", |
248 | 0 | (guint) fu_struct_fmap_get_ver_minor(st)); |
249 | 0 | g_string_append_printf(str, " base: 0x%x\n", |
250 | 0 | (guint) fu_struct_fmap_get_base(st)); |
251 | 0 | g_string_append_printf(str, " size: 0x%x\n", |
252 | 0 | (guint) fu_struct_fmap_get_size(st)); |
253 | 0 | { |
254 | 0 | g_autofree gchar *tmp = fu_struct_fmap_get_name(st); |
255 | 0 | if (tmp != NULL) |
256 | 0 | g_string_append_printf(str, " name: %s\n", tmp); |
257 | 0 | } |
258 | 0 | g_string_append_printf(str, " nareas: 0x%x\n", |
259 | 0 | (guint) fu_struct_fmap_get_nareas(st)); |
260 | 0 | if (str->len > 0) |
261 | 0 | g_string_set_size(str, str->len - 1); |
262 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
263 | 0 | } |
264 | | static gboolean |
265 | | fu_struct_fmap_validate_internal(FuStructFmap *st, GError **error) |
266 | 13.4k | { |
267 | 13.4k | g_return_val_if_fail(st != NULL, FALSE); |
268 | 13.4k | if (strncmp((const gchar *) (st->buf->data + 0), "__FMAP__", 8) != 0) { |
269 | 156 | g_autofree gchar *str = fu_struct_fmap_get_signature(st); |
270 | 156 | g_set_error(error, |
271 | 156 | FWUPD_ERROR, |
272 | 156 | FWUPD_ERROR_INVALID_DATA, |
273 | 156 | "constant FuStructFmap.signature was not valid, " |
274 | 156 | "expected '__FMAP__' and got '%s'", |
275 | 156 | str); |
276 | 156 | return FALSE; |
277 | 156 | } |
278 | 13.2k | return TRUE; |
279 | 13.4k | } |
280 | | /** |
281 | | * fu_struct_fmap_validate_stream: (skip): |
282 | | **/ |
283 | | gboolean |
284 | | fu_struct_fmap_validate_stream(GInputStream *stream, gsize offset, GError **error) |
285 | 6.82k | { |
286 | 6.82k | g_autoptr(FuStructFmap) st = fu_struct_fmap_new_internal(); |
287 | 6.82k | g_return_val_if_fail(G_IS_INPUT_STREAM(stream), FALSE); |
288 | 6.82k | g_return_val_if_fail(error == NULL || *error == NULL, FALSE); |
289 | 6.82k | st->buf = fu_input_stream_read_byte_array(stream, offset, 56, NULL, error); |
290 | 6.82k | if (st->buf == NULL) { |
291 | 0 | g_prefix_error(error, "FuStructFmap failed read of 0x%x: ", (guint) 56); |
292 | 0 | return FALSE; |
293 | 0 | } |
294 | 6.82k | if (st->buf->len != 56) { |
295 | 41 | g_set_error(error, |
296 | 41 | FWUPD_ERROR, |
297 | 41 | FWUPD_ERROR_INVALID_DATA, |
298 | 41 | "FuStructFmap requested 0x%x and got 0x%x", |
299 | 41 | (guint) 56, |
300 | 41 | (guint) st->buf->len); |
301 | 41 | return FALSE; |
302 | 41 | } |
303 | 6.78k | return fu_struct_fmap_validate_internal(st, error); |
304 | 6.82k | } |
305 | | static gboolean |
306 | | fu_struct_fmap_parse_internal(FuStructFmap *st, GError **error) |
307 | 6.62k | { |
308 | 6.62k | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
309 | 0 | g_autofree gchar *str = fu_struct_fmap_to_string(st); |
310 | 0 | g_debug("%s", str); |
311 | 0 | } |
312 | 6.62k | if (!fu_struct_fmap_validate_internal(st, error)) |
313 | 0 | return FALSE; |
314 | 6.62k | return TRUE; |
315 | 6.62k | } |
316 | | /** |
317 | | * fu_struct_fmap_parse_stream: (skip): |
318 | | **/ |
319 | | FuStructFmap * |
320 | | fu_struct_fmap_parse_stream(GInputStream *stream, gsize offset, GError **error) |
321 | 6.62k | { |
322 | 6.62k | g_autoptr(FuStructFmap) st = fu_struct_fmap_new_internal(); |
323 | 6.62k | st->buf = fu_input_stream_read_byte_array(stream, offset, 56, NULL, error); |
324 | 6.62k | if (st->buf == NULL) { |
325 | 0 | g_prefix_error(error, "FuStructFmap failed read of 0x%x: ", (guint) 56); |
326 | 0 | return NULL; |
327 | 0 | } |
328 | 6.62k | if (st->buf->len != 56) { |
329 | 0 | g_set_error(error, |
330 | 0 | FWUPD_ERROR, |
331 | 0 | FWUPD_ERROR_INVALID_DATA, |
332 | 0 | "FuStructFmap requested 0x%x and got 0x%x", |
333 | 0 | (guint) 56, |
334 | 0 | (guint) st->buf->len); |
335 | 0 | return NULL; |
336 | 0 | } |
337 | 6.62k | if (!fu_struct_fmap_parse_internal(st, error)) |
338 | 0 | return NULL; |
339 | 6.62k | return g_steal_pointer(&st); |
340 | 6.62k | } |
341 | | /** |
342 | | * fu_struct_fmap_area_ref: (skip): |
343 | | **/ |
344 | | FuStructFmapArea * |
345 | | fu_struct_fmap_area_ref(FuStructFmapArea *st) |
346 | 0 | { |
347 | 0 | g_return_val_if_fail(st != NULL, NULL); |
348 | 0 | st->refcount++; |
349 | 0 | return st; |
350 | 0 | } |
351 | | /** |
352 | | * fu_struct_fmap_area_unref: (skip): |
353 | | **/ |
354 | | void |
355 | | fu_struct_fmap_area_unref(FuStructFmapArea *st) |
356 | 4.64M | { |
357 | 4.64M | g_return_if_fail(st != NULL); |
358 | 4.64M | if (st->refcount == 0) { |
359 | 0 | g_critical("FuStructFmapArea refcount already zero"); |
360 | 0 | return; |
361 | 0 | } |
362 | 4.64M | if (--st->refcount > 0) |
363 | 0 | return; |
364 | 4.64M | if (st->buf != NULL) |
365 | 4.64M | g_byte_array_unref(st->buf); |
366 | 4.64M | g_free(st); |
367 | 4.64M | } |
368 | | /** |
369 | | * fu_struct_fmap_area_new_internal: (skip): |
370 | | **/ |
371 | | static FuStructFmapArea * |
372 | | fu_struct_fmap_area_new_internal(void) |
373 | 4.64M | { |
374 | 4.64M | FuStructFmapArea *st = g_new0(FuStructFmapArea, 1); |
375 | 4.64M | st->refcount = 1; |
376 | 4.64M | return st; |
377 | 4.64M | } |
378 | | |
379 | | /* getters */ |
380 | | /** |
381 | | * fu_struct_fmap_area_get_offset: (skip): |
382 | | **/ |
383 | | guint32 |
384 | | fu_struct_fmap_area_get_offset(const FuStructFmapArea *st) |
385 | 57.8k | { |
386 | 57.8k | g_return_val_if_fail(st != NULL, 0x0); |
387 | 57.8k | return fu_memread_uint32(st->buf->data + 0, G_LITTLE_ENDIAN); |
388 | 57.8k | } |
389 | | /** |
390 | | * fu_struct_fmap_area_get_size: (skip): |
391 | | **/ |
392 | | guint32 |
393 | | fu_struct_fmap_area_get_size(const FuStructFmapArea *st) |
394 | 4.64M | { |
395 | 4.64M | g_return_val_if_fail(st != NULL, 0x0); |
396 | 4.64M | return fu_memread_uint32(st->buf->data + 4, G_LITTLE_ENDIAN); |
397 | 4.64M | } |
398 | | /** |
399 | | * fu_struct_fmap_area_get_name: (skip): |
400 | | **/ |
401 | | gchar * |
402 | | fu_struct_fmap_area_get_name(const FuStructFmapArea *st) |
403 | 52.8k | { |
404 | 52.8k | g_return_val_if_fail(st != NULL, NULL); |
405 | 52.8k | return fu_memstrsafe(st->buf->data, st->buf->len, 8, 32, NULL); |
406 | 52.8k | } |
407 | | /** |
408 | | * fu_struct_fmap_area_get_flags: (skip): |
409 | | **/ |
410 | | guint16 |
411 | | fu_struct_fmap_area_get_flags(const FuStructFmapArea *st) |
412 | 0 | { |
413 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
414 | 0 | return fu_memread_uint16(st->buf->data + 40, G_LITTLE_ENDIAN); |
415 | 0 | } |
416 | | |
417 | | /* setters */ |
418 | | /** |
419 | | * fu_struct_fmap_area_set_offset: (skip): |
420 | | **/ |
421 | | void |
422 | | fu_struct_fmap_area_set_offset(FuStructFmapArea *st, guint32 value) |
423 | 154 | { |
424 | 154 | g_return_if_fail(st != NULL); |
425 | 154 | fu_memwrite_uint32(st->buf->data + 0, value, G_LITTLE_ENDIAN); |
426 | 154 | } |
427 | | /** |
428 | | * fu_struct_fmap_area_set_size: (skip): |
429 | | **/ |
430 | | void |
431 | | fu_struct_fmap_area_set_size(FuStructFmapArea *st, guint32 value) |
432 | 154 | { |
433 | 154 | g_return_if_fail(st != NULL); |
434 | 154 | fu_memwrite_uint32(st->buf->data + 4, value, G_LITTLE_ENDIAN); |
435 | 154 | } |
436 | | /** |
437 | | * fu_struct_fmap_area_set_name: (skip): |
438 | | **/ |
439 | | gboolean |
440 | | fu_struct_fmap_area_set_name(FuStructFmapArea *st, const gchar *value, GError **error) |
441 | 154 | { |
442 | 154 | gsize len; |
443 | 154 | g_return_val_if_fail(st != NULL, FALSE); |
444 | 154 | g_return_val_if_fail(error == NULL || *error == NULL, FALSE); |
445 | 154 | if (value == NULL) { |
446 | 0 | memset(st->buf->data + 8, 0x0, 32); |
447 | 0 | return TRUE; |
448 | 0 | } |
449 | 154 | len = strlen(value); |
450 | 154 | if (len > 32) { |
451 | 0 | g_set_error(error, |
452 | 0 | FWUPD_ERROR, |
453 | 0 | FWUPD_ERROR_INVALID_DATA, |
454 | 0 | "string '%s' (0x%x bytes) does not fit in FuStructFmapArea.name (0x%x bytes)", |
455 | 0 | value, (guint) len, (guint) 32); |
456 | 0 | return FALSE; |
457 | 0 | } |
458 | 154 | return fu_memcpy_safe(st->buf->data, st->buf->len, 8, (const guint8 *)value, len, 0x0, len, error); |
459 | 154 | } |
460 | | /** |
461 | | * fu_struct_fmap_area_set_flags: (skip): |
462 | | **/ |
463 | | void |
464 | | fu_struct_fmap_area_set_flags(FuStructFmapArea *st, guint16 value) |
465 | 0 | { |
466 | 0 | g_return_if_fail(st != NULL); |
467 | 0 | fu_memwrite_uint16(st->buf->data + 40, value, G_LITTLE_ENDIAN); |
468 | 0 | } |
469 | | /** |
470 | | * fu_struct_fmap_area_new: (skip): |
471 | | **/ |
472 | | FuStructFmapArea * |
473 | | fu_struct_fmap_area_new(void) |
474 | 154 | { |
475 | 154 | FuStructFmapArea *st = fu_struct_fmap_area_new_internal(); |
476 | 154 | st->buf = g_byte_array_sized_new(42); |
477 | 154 | fu_byte_array_set_size(st->buf, 42, 0x0); |
478 | 154 | return st; |
479 | 154 | } |
480 | | /** |
481 | | * fu_struct_fmap_area_to_string: (skip): |
482 | | **/ |
483 | | static gchar * |
484 | | fu_struct_fmap_area_to_string(const FuStructFmapArea *st) |
485 | 0 | { |
486 | 0 | g_autoptr(GString) str = g_string_new("FuStructFmapArea:\n"); |
487 | 0 | g_return_val_if_fail(st != NULL, NULL); |
488 | 0 | g_string_append_printf(str, " offset: 0x%x\n", |
489 | 0 | (guint) fu_struct_fmap_area_get_offset(st)); |
490 | 0 | g_string_append_printf(str, " size: 0x%x\n", |
491 | 0 | (guint) fu_struct_fmap_area_get_size(st)); |
492 | 0 | { |
493 | 0 | g_autofree gchar *tmp = fu_struct_fmap_area_get_name(st); |
494 | 0 | if (tmp != NULL) |
495 | 0 | g_string_append_printf(str, " name: %s\n", tmp); |
496 | 0 | } |
497 | 0 | g_string_append_printf(str, " flags: 0x%x\n", |
498 | 0 | (guint) fu_struct_fmap_area_get_flags(st)); |
499 | 0 | if (str->len > 0) |
500 | 0 | g_string_set_size(str, str->len - 1); |
501 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
502 | 0 | } |
503 | | static gboolean |
504 | | fu_struct_fmap_area_validate_internal(FuStructFmapArea *st, GError **error) |
505 | 4.64M | { |
506 | 4.64M | g_return_val_if_fail(st != NULL, FALSE); |
507 | 4.64M | return TRUE; |
508 | 4.64M | } |
509 | | static gboolean |
510 | | fu_struct_fmap_area_parse_internal(FuStructFmapArea *st, GError **error) |
511 | 4.64M | { |
512 | 4.64M | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
513 | 0 | g_autofree gchar *str = fu_struct_fmap_area_to_string(st); |
514 | 0 | g_debug("%s", str); |
515 | 0 | } |
516 | 4.64M | if (!fu_struct_fmap_area_validate_internal(st, error)) |
517 | 0 | return FALSE; |
518 | 4.64M | return TRUE; |
519 | 4.64M | } |
520 | | /** |
521 | | * fu_struct_fmap_area_parse_stream: (skip): |
522 | | **/ |
523 | | FuStructFmapArea * |
524 | | fu_struct_fmap_area_parse_stream(GInputStream *stream, gsize offset, GError **error) |
525 | 4.64M | { |
526 | 4.64M | g_autoptr(FuStructFmapArea) st = fu_struct_fmap_area_new_internal(); |
527 | 4.64M | st->buf = fu_input_stream_read_byte_array(stream, offset, 42, NULL, error); |
528 | 4.64M | if (st->buf == NULL) { |
529 | 299 | g_prefix_error(error, "FuStructFmapArea failed read of 0x%x: ", (guint) 42); |
530 | 299 | return NULL; |
531 | 299 | } |
532 | 4.64M | if (st->buf->len != 42) { |
533 | 694 | g_set_error(error, |
534 | 694 | FWUPD_ERROR, |
535 | 694 | FWUPD_ERROR_INVALID_DATA, |
536 | 694 | "FuStructFmapArea requested 0x%x and got 0x%x", |
537 | 694 | (guint) 42, |
538 | 694 | (guint) st->buf->len); |
539 | 694 | return NULL; |
540 | 694 | } |
541 | 4.64M | if (!fu_struct_fmap_area_parse_internal(st, error)) |
542 | 0 | return NULL; |
543 | 4.64M | return g_steal_pointer(&st); |
544 | 4.64M | } |