1#ifndef _LINUX_SEQ_BUF_H
2#define _LINUX_SEQ_BUF_H
3
4#include <linux/fs.h>
5
6
7
8
9
10
11
12
13
14
15
16
17
18struct seq_buf {
19 char *buffer;
20 size_t size;
21 size_t len;
22 loff_t readpos;
23};
24
25static inline void seq_buf_clear(struct seq_buf *s)
26{
27 s->len = 0;
28 s->readpos = 0;
29}
30
31static inline void
32seq_buf_init(struct seq_buf *s, unsigned char *buf, unsigned int size)
33{
34 s->buffer = buf;
35 s->size = size;
36 seq_buf_clear(s);
37}
38
39
40
41
42
43static inline bool
44seq_buf_has_overflowed(struct seq_buf *s)
45{
46 return s->len > s->size;
47}
48
49static inline void
50seq_buf_set_overflow(struct seq_buf *s)
51{
52 s->len = s->size + 1;
53}
54
55
56
57
58static inline unsigned int
59seq_buf_buffer_left(struct seq_buf *s)
60{
61 if (seq_buf_has_overflowed(s))
62 return 0;
63
64 return s->size - s->len;
65}
66
67
68static inline unsigned int seq_buf_used(struct seq_buf *s)
69{
70 return min(s->len, s->size);
71}
72
73
74
75
76
77
78
79
80
81static inline size_t seq_buf_get_buf(struct seq_buf *s, char **bufp)
82{
83 WARN_ON(s->len > s->size + 1);
84
85 if (s->len < s->size) {
86 *bufp = s->buffer + s->len;
87 return s->size - s->len;
88 }
89
90 *bufp = NULL;
91 return 0;
92}
93
94
95
96
97
98
99
100
101
102
103static inline void seq_buf_commit(struct seq_buf *s, int num)
104{
105 if (num < 0) {
106 seq_buf_set_overflow(s);
107 } else {
108
109 BUG_ON(s->len + num > s->size);
110 s->len += num;
111 }
112}
113
114extern __printf(2, 3)
115int seq_buf_printf(struct seq_buf *s, const char *fmt, ...);
116extern __printf(2, 0)
117int seq_buf_vprintf(struct seq_buf *s, const char *fmt, va_list args);
118extern int seq_buf_print_seq(struct seq_file *m, struct seq_buf *s);
119extern int seq_buf_to_user(struct seq_buf *s, char __user *ubuf,
120 int cnt);
121extern int seq_buf_puts(struct seq_buf *s, const char *str);
122extern int seq_buf_putc(struct seq_buf *s, unsigned char c);
123extern int seq_buf_putmem(struct seq_buf *s, const void *mem, unsigned int len);
124extern int seq_buf_putmem_hex(struct seq_buf *s, const void *mem,
125 unsigned int len);
126extern int seq_buf_path(struct seq_buf *s, const struct path *path, const char *esc);
127
128#ifdef CONFIG_BINARY_PRINTF
129extern int
130seq_buf_bprintf(struct seq_buf *s, const char *fmt, const u32 *binary);
131#endif
132
133#endif
134