* Clears the elog events from the given buffer, which is a valid RW_ELOG region. * A LOG_CLEAR event is appended. */
| 226 | * A LOG_CLEAR event is appended. |
| 227 | */ |
| 228 | static int cmd_clear(const struct buffer *buf, |
| 229 | enum elogtool_flag flags __maybe_unused) |
| 230 | { |
| 231 | uint32_t used_data_size; |
| 232 | struct buffer copy; |
| 233 | |
| 234 | /* Clone the buffer to avoid changing the offset of the original buffer */ |
| 235 | buffer_clone(©, buf); |
| 236 | buffer_seek(©, sizeof(struct elog_header)); |
| 237 | |
| 238 | /* |
| 239 | * Calculate the size of the "used" buffer, needed for ELOG_TYPE_LOG_CLEAR. |
| 240 | * Then overwrite the entire buffer with ELOG_TYPE_EOL. |
| 241 | * Finally insert a LOG_CLEAR event into the buffer. |
| 242 | */ |
| 243 | used_data_size = next_available_event_offset(©); |
| 244 | memset(buffer_get(©), ELOG_TYPE_EOL, buffer_size(©)); |
| 245 | |
| 246 | if (!eventlog_init_event(©, ELOG_TYPE_LOG_CLEAR, |
| 247 | &used_data_size, sizeof(used_data_size))) |
| 248 | return ELOGTOOL_EXIT_NOT_ENOUGH_BUFFER_SPACE; |
| 249 | |
| 250 | return ELOGTOOL_EXIT_SUCCESS; |
| 251 | } |
| 252 | |
| 253 | static void cmd_add_usage(void) |
| 254 | { |
nothing calls this directly
no test coverage detected