18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: LGPL-2.1
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (C) 2009, 2010 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci */
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#ifndef _TRACE_SEQ_H
88c2ecf20Sopenharmony_ci#define _TRACE_SEQ_H
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#include <stdarg.h>
118c2ecf20Sopenharmony_ci#include <stdio.h>
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci/* ----------------------- trace_seq ----------------------- */
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#ifndef TRACE_SEQ_BUF_SIZE
168c2ecf20Sopenharmony_ci#define TRACE_SEQ_BUF_SIZE 4096
178c2ecf20Sopenharmony_ci#endif
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_cienum trace_seq_fail {
208c2ecf20Sopenharmony_ci	TRACE_SEQ__GOOD,
218c2ecf20Sopenharmony_ci	TRACE_SEQ__BUFFER_POISONED,
228c2ecf20Sopenharmony_ci	TRACE_SEQ__MEM_ALLOC_FAILED,
238c2ecf20Sopenharmony_ci};
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci/*
268c2ecf20Sopenharmony_ci * Trace sequences are used to allow a function to call several other functions
278c2ecf20Sopenharmony_ci * to create a string of data to use (up to a max of PAGE_SIZE).
288c2ecf20Sopenharmony_ci */
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_cistruct trace_seq {
318c2ecf20Sopenharmony_ci	char			*buffer;
328c2ecf20Sopenharmony_ci	unsigned int		buffer_size;
338c2ecf20Sopenharmony_ci	unsigned int		len;
348c2ecf20Sopenharmony_ci	unsigned int		readpos;
358c2ecf20Sopenharmony_ci	enum trace_seq_fail	state;
368c2ecf20Sopenharmony_ci};
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_civoid trace_seq_init(struct trace_seq *s);
398c2ecf20Sopenharmony_civoid trace_seq_reset(struct trace_seq *s);
408c2ecf20Sopenharmony_civoid trace_seq_destroy(struct trace_seq *s);
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ciextern int trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
438c2ecf20Sopenharmony_ci	__attribute__ ((format (printf, 2, 3)));
448c2ecf20Sopenharmony_ciextern int trace_seq_vprintf(struct trace_seq *s, const char *fmt, va_list args)
458c2ecf20Sopenharmony_ci	__attribute__ ((format (printf, 2, 0)));
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ciextern int trace_seq_puts(struct trace_seq *s, const char *str);
488c2ecf20Sopenharmony_ciextern int trace_seq_putc(struct trace_seq *s, unsigned char c);
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ciextern void trace_seq_terminate(struct trace_seq *s);
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ciextern int trace_seq_do_fprintf(struct trace_seq *s, FILE *fp);
538c2ecf20Sopenharmony_ciextern int trace_seq_do_printf(struct trace_seq *s);
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci#endif /* _TRACE_SEQ_H */
56