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