/work/fu-sbatlevel-section-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-sbatlevel-section-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_sbat_level_section_header_ref: (skip): |
22 | | **/ |
23 | | FuStructSbatLevelSectionHeader * |
24 | | fu_struct_sbat_level_section_header_ref(FuStructSbatLevelSectionHeader *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_sbat_level_section_header_unref: (skip): |
32 | | **/ |
33 | | void |
34 | | fu_struct_sbat_level_section_header_unref(FuStructSbatLevelSectionHeader *st) |
35 | 235 | { |
36 | 235 | g_return_if_fail(st != NULL); |
37 | 235 | if (st->refcount == 0) { |
38 | 0 | g_critical("FuStructSbatLevelSectionHeader refcount already zero"); |
39 | 0 | return; |
40 | 0 | } |
41 | 235 | if (--st->refcount > 0) |
42 | 0 | return; |
43 | 235 | if (st->buf != NULL) |
44 | 207 | g_byte_array_unref(st->buf); |
45 | 235 | g_free(st); |
46 | 235 | } |
47 | | /** |
48 | | * fu_struct_sbat_level_section_header_new_internal: (skip): |
49 | | **/ |
50 | | static FuStructSbatLevelSectionHeader * |
51 | | fu_struct_sbat_level_section_header_new_internal(void) |
52 | 235 | { |
53 | 235 | FuStructSbatLevelSectionHeader *st = g_new0(FuStructSbatLevelSectionHeader, 1); |
54 | 235 | st->refcount = 1; |
55 | 235 | return st; |
56 | 235 | } |
57 | | |
58 | | /* getters */ |
59 | | /** |
60 | | * fu_struct_sbat_level_section_header_get_version: (skip): |
61 | | **/ |
62 | | static guint32 |
63 | | fu_struct_sbat_level_section_header_get_version(const FuStructSbatLevelSectionHeader *st) |
64 | 253 | { |
65 | 253 | g_return_val_if_fail(st != NULL, 0x0); |
66 | 253 | return fu_memread_uint32(st->buf->data + 0, G_LITTLE_ENDIAN); |
67 | 253 | } |
68 | | /** |
69 | | * fu_struct_sbat_level_section_header_get_previous: (skip): |
70 | | **/ |
71 | | guint32 |
72 | | fu_struct_sbat_level_section_header_get_previous(const FuStructSbatLevelSectionHeader *st) |
73 | 149 | { |
74 | 149 | g_return_val_if_fail(st != NULL, 0x0); |
75 | 149 | return fu_memread_uint32(st->buf->data + 4, G_LITTLE_ENDIAN); |
76 | 149 | } |
77 | | /** |
78 | | * fu_struct_sbat_level_section_header_get_latest: (skip): |
79 | | **/ |
80 | | guint32 |
81 | | fu_struct_sbat_level_section_header_get_latest(const FuStructSbatLevelSectionHeader *st) |
82 | 100 | { |
83 | 100 | g_return_val_if_fail(st != NULL, 0x0); |
84 | 100 | return fu_memread_uint32(st->buf->data + 8, G_LITTLE_ENDIAN); |
85 | 100 | } |
86 | | |
87 | | /* setters */ |
88 | | /** |
89 | | * fu_struct_sbat_level_section_header_set_version: (skip): |
90 | | **/ |
91 | | static void |
92 | | fu_struct_sbat_level_section_header_set_version(FuStructSbatLevelSectionHeader *st, guint32 value) |
93 | 30 | { |
94 | 30 | g_return_if_fail(st != NULL); |
95 | 30 | fu_memwrite_uint32(st->buf->data + 0, value, G_LITTLE_ENDIAN); |
96 | 30 | } |
97 | | /** |
98 | | * fu_struct_sbat_level_section_header_set_previous: (skip): |
99 | | **/ |
100 | | void |
101 | | fu_struct_sbat_level_section_header_set_previous(FuStructSbatLevelSectionHeader *st, guint32 value) |
102 | 30 | { |
103 | 30 | g_return_if_fail(st != NULL); |
104 | 30 | fu_memwrite_uint32(st->buf->data + 4, value, G_LITTLE_ENDIAN); |
105 | 30 | } |
106 | | /** |
107 | | * fu_struct_sbat_level_section_header_set_latest: (skip): |
108 | | **/ |
109 | | void |
110 | | fu_struct_sbat_level_section_header_set_latest(FuStructSbatLevelSectionHeader *st, guint32 value) |
111 | 28 | { |
112 | 28 | g_return_if_fail(st != NULL); |
113 | 28 | fu_memwrite_uint32(st->buf->data + 8, value, G_LITTLE_ENDIAN); |
114 | 28 | } |
115 | | /** |
116 | | * fu_struct_sbat_level_section_header_new: (skip): |
117 | | **/ |
118 | | FuStructSbatLevelSectionHeader * |
119 | | fu_struct_sbat_level_section_header_new(void) |
120 | 30 | { |
121 | 30 | FuStructSbatLevelSectionHeader *st = fu_struct_sbat_level_section_header_new_internal(); |
122 | 30 | st->buf = g_byte_array_sized_new(12); |
123 | 30 | fu_byte_array_set_size(st->buf, 12, 0x0); |
124 | 30 | fu_struct_sbat_level_section_header_set_version(st, 0x0); |
125 | 30 | return st; |
126 | 30 | } |
127 | | /** |
128 | | * fu_struct_sbat_level_section_header_to_string: (skip): |
129 | | **/ |
130 | | static gchar * |
131 | | fu_struct_sbat_level_section_header_to_string(const FuStructSbatLevelSectionHeader *st) |
132 | 0 | { |
133 | 0 | g_autoptr(GString) str = g_string_new("FuStructSbatLevelSectionHeader:\n"); |
134 | 0 | g_return_val_if_fail(st != NULL, NULL); |
135 | 0 | g_string_append_printf(str, " version: 0x%x\n", |
136 | 0 | (guint) fu_struct_sbat_level_section_header_get_version(st)); |
137 | 0 | g_string_append_printf(str, " previous: 0x%x\n", |
138 | 0 | (guint) fu_struct_sbat_level_section_header_get_previous(st)); |
139 | 0 | g_string_append_printf(str, " latest: 0x%x\n", |
140 | 0 | (guint) fu_struct_sbat_level_section_header_get_latest(st)); |
141 | 0 | if (str->len > 0) |
142 | 0 | g_string_set_size(str, str->len - 1); |
143 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
144 | 0 | } |
145 | | static gboolean |
146 | | fu_struct_sbat_level_section_header_validate_internal(FuStructSbatLevelSectionHeader *st, GError **error) |
147 | 201 | { |
148 | 201 | g_return_val_if_fail(st != NULL, FALSE); |
149 | 201 | if (fu_struct_sbat_level_section_header_get_version(st) != 0x0) { |
150 | 52 | g_set_error(error, |
151 | 52 | FWUPD_ERROR, |
152 | 52 | FWUPD_ERROR_INVALID_DATA, |
153 | 52 | "constant FuStructSbatLevelSectionHeader.version was not valid, " |
154 | 52 | "expected 0x%x and got 0x%x", |
155 | 52 | (guint) 0x0, |
156 | 52 | (guint) fu_struct_sbat_level_section_header_get_version(st)); |
157 | 52 | return FALSE; |
158 | 52 | } |
159 | 149 | return TRUE; |
160 | 201 | } |
161 | | static gboolean |
162 | | fu_struct_sbat_level_section_header_parse_internal(FuStructSbatLevelSectionHeader *st, GError **error) |
163 | 201 | { |
164 | 201 | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
165 | 0 | g_autofree gchar *str = fu_struct_sbat_level_section_header_to_string(st); |
166 | 0 | g_debug("%s", str); |
167 | 0 | } |
168 | 201 | if (!fu_struct_sbat_level_section_header_validate_internal(st, error)) |
169 | 52 | return FALSE; |
170 | 149 | return TRUE; |
171 | 201 | } |
172 | | /** |
173 | | * fu_struct_sbat_level_section_header_parse_stream: (skip): |
174 | | **/ |
175 | | FuStructSbatLevelSectionHeader * |
176 | | fu_struct_sbat_level_section_header_parse_stream(GInputStream *stream, gsize offset, GError **error) |
177 | 205 | { |
178 | 205 | g_autoptr(FuStructSbatLevelSectionHeader) st = fu_struct_sbat_level_section_header_new_internal(); |
179 | 205 | st->buf = fu_input_stream_read_byte_array(stream, offset, 12, NULL, error); |
180 | 205 | if (st->buf == NULL) { |
181 | 0 | g_prefix_error(error, "FuStructSbatLevelSectionHeader failed read of 0x%x: ", (guint) 12); |
182 | 0 | return NULL; |
183 | 0 | } |
184 | 205 | if (st->buf->len != 12) { |
185 | 4 | g_set_error(error, |
186 | 4 | FWUPD_ERROR, |
187 | 4 | FWUPD_ERROR_INVALID_DATA, |
188 | 4 | "FuStructSbatLevelSectionHeader requested 0x%x and got 0x%x", |
189 | 4 | (guint) 12, |
190 | 4 | (guint) st->buf->len); |
191 | 4 | return NULL; |
192 | 4 | } |
193 | 201 | if (!fu_struct_sbat_level_section_header_parse_internal(st, error)) |
194 | 52 | return NULL; |
195 | 149 | return g_steal_pointer(&st); |
196 | 201 | } |