MCPcopy Create free account
hub / github.com/coreboot/coreboot / shrink_buffer

Function shrink_buffer

util/cbfstool/elogtool.c:155–194  ·  view source on GitHub ↗

* Shrinks buffer by ~bytes_to_shrink, then appends a LOG_CLEAR event, * and finally fills the remaining area with EOL events. * Buffer offset must point to a valid event_header struct. */

Source from the content-addressed store, hash-verified

153 * Buffer offset must point to a valid event_header struct.
154 */
155static int shrink_buffer(const struct buffer *buf, size_t bytes_to_shrink)
156{
157 struct buffer copy, *iter = ©
158 const struct event_header *event;
159 uint32_t cleared;
160 int remaining;
161 uint8_t *data;
162
163 assert(buffer_offset(buf) >= sizeof(struct elog_header));
164
165 buffer_clone(&copy, buf);
166
167 /* Save copy of first event for later */
168 data = buffer_get(buf);
169
170 /* Set buffer offset pointing to the event right after bytes_to_shrink */
171 while (buffer_offset(iter) < bytes_to_shrink) {
172 event = buffer_get(iter);
173 assert(!(event->type == ELOG_TYPE_EOL || event->length == 0));
174
175 buffer_seek(iter, event->length);
176 }
177
178 /* Must be relative to the buffer offset */
179 cleared = buffer_offset(iter) - buffer_offset(buf);
180 remaining = buffer_size(iter);
181
182 /* Overlapping copy */
183 memmove(data, data + cleared, remaining);
184 memset(data + remaining, ELOG_TYPE_EOL, cleared);
185
186 /* Re-init copy to have a clean offset. Needed for init_event() */
187 buffer_clone(&copy, buf);
188 buffer_seek(&copy, next_available_event_offset(&copy));
189
190 if (!eventlog_init_event(&copy, ELOG_TYPE_LOG_CLEAR, &cleared, sizeof(cleared)))
191 return ELOGTOOL_EXIT_NOT_ENOUGH_BUFFER_SPACE;
192
193 return ELOGTOOL_EXIT_SUCCESS;
194}
195
196static int cmd_list(const struct buffer *buf, enum elogtool_flag flags)
197{

Callers 1

cmd_addFunction · 0.85

Calls 9

buffer_offsetFunction · 0.85
buffer_cloneFunction · 0.85
buffer_getFunction · 0.85
buffer_seekFunction · 0.85
buffer_sizeFunction · 0.85
eventlog_init_eventFunction · 0.85
memmoveFunction · 0.50
memsetFunction · 0.50

Tested by

no test coverage detected