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