blob: 4f7a96a9d71a9f0552d94511300d5cf5eedef3b2 [file] [log] [blame]
Steven Rostedt (Red Hat)3a161d92014-06-25 15:54:42 -04001#ifndef _LINUX_SEQ_BUF_H
2#define _LINUX_SEQ_BUF_H
3
4#include <linux/fs.h>
5
6/*
7 * Trace sequences are used to allow a function to call several other functions
8 * to create a string of data to use.
9 */
10
11/**
12 * seq_buf - seq buffer structure
13 * @buffer: pointer to the buffer
14 * @size: size of the buffer
15 * @len: the amount of data inside the buffer
16 * @readpos: The next position to read in the buffer.
17 */
18struct seq_buf {
19 unsigned char *buffer;
20 unsigned int size;
21 unsigned int len;
22 unsigned int readpos;
23};
24
25static inline void
26seq_buf_init(struct seq_buf *s, unsigned char *buf, unsigned int size)
27{
28 s->buffer = buf;
29 s->size = size;
30 s->len = 0;
31 s->readpos = 0;
32}
33
34/*
35 * seq_buf have a buffer that might overflow. When this happens
36 * the len and size are set to be equal.
37 */
38static inline bool
39seq_buf_has_overflowed(struct seq_buf *s)
40{
41 return s->len == s->size;
42}
43
44static inline void
45seq_buf_set_overflow(struct seq_buf *s)
46{
47 s->len = s->size;
48}
49
50/*
51 * How much buffer is left on the seq_buf?
52 */
53static inline unsigned int
54seq_buf_buffer_left(struct seq_buf *s)
55{
56 if (seq_buf_has_overflowed(s))
57 return 0;
58
59 return (s->size - 1) - s->len;
60}
61
62extern __printf(2, 3)
63int seq_buf_printf(struct seq_buf *s, const char *fmt, ...);
64extern __printf(2, 0)
65int seq_buf_vprintf(struct seq_buf *s, const char *fmt, va_list args);
66extern int
67seq_buf_bprintf(struct seq_buf *s, const char *fmt, const u32 *binary);
68extern int seq_buf_print_seq(struct seq_file *m, struct seq_buf *s);
69extern int seq_buf_to_user(struct seq_buf *s, char __user *ubuf,
70 int cnt);
71extern int seq_buf_puts(struct seq_buf *s, const char *str);
72extern int seq_buf_putc(struct seq_buf *s, unsigned char c);
73extern int seq_buf_putmem(struct seq_buf *s, const void *mem, unsigned int len);
74extern int seq_buf_putmem_hex(struct seq_buf *s, const void *mem,
75 unsigned int len);
76extern int seq_buf_path(struct seq_buf *s, const struct path *path);
77
78extern int seq_buf_bitmask(struct seq_buf *s, const unsigned long *maskp,
79 int nmaskbits);
80
81#endif /* _LINUX_SEQ_BUF_H */