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