1 #ifndef _LINUX_SEQ_BUF_H
2 #define _LINUX_SEQ_BUF_H
7 * Trace sequences are used to allow a function to call several other functions
8 * to create a string of data to use.
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.
25 static inline void seq_buf_clear(struct seq_buf
*s
)
32 seq_buf_init(struct seq_buf
*s
, unsigned char *buf
, unsigned int size
)
40 * seq_buf have a buffer that might overflow. When this happens
41 * the len and size are set to be equal.
44 seq_buf_has_overflowed(struct seq_buf
*s
)
46 return s
->len
> s
->size
;
50 seq_buf_set_overflow(struct seq_buf
*s
)
56 * How much buffer is left on the seq_buf?
58 static inline unsigned int
59 seq_buf_buffer_left(struct seq_buf
*s
)
61 if (seq_buf_has_overflowed(s
))
64 return s
->size
- s
->len
;
67 /* How much buffer was written? */
68 static inline unsigned int seq_buf_used(struct seq_buf
*s
)
70 return min(s
->len
, s
->size
);
74 * seq_buf_get_buf - get buffer to write arbitrary data to
75 * @s: the seq_buf handle
76 * @bufp: the beginning of the buffer is stored here
78 * Return the number of bytes available in the buffer, or zero if
81 static inline size_t seq_buf_get_buf(struct seq_buf
*s
, char **bufp
)
83 WARN_ON(s
->len
> s
->size
+ 1);
85 if (s
->len
< s
->size
) {
86 *bufp
= s
->buffer
+ s
->len
;
87 return s
->size
- s
->len
;
95 * seq_buf_commit - commit data to the buffer
96 * @s: the seq_buf handle
97 * @num: the number of bytes to commit
99 * Commit @num bytes of data written to a buffer previously acquired
100 * by seq_buf_get. To signal an error condition, or that the data
101 * didn't fit in the available space, pass a negative @num value.
103 static inline void seq_buf_commit(struct seq_buf
*s
, int num
)
106 seq_buf_set_overflow(s
);
108 /* num must be negative on overflow */
109 BUG_ON(s
->len
+ num
> s
->size
);
114 extern __printf(2, 3)
115 int seq_buf_printf(struct seq_buf
*s
, const char *fmt
, ...);
116 extern __printf(2, 0)
117 int seq_buf_vprintf(struct seq_buf
*s
, const char *fmt
, va_list args
);
118 extern int seq_buf_print_seq(struct seq_file
*m
, struct seq_buf
*s
);
119 extern int seq_buf_to_user(struct seq_buf
*s
, char __user
*ubuf
,
121 extern int seq_buf_puts(struct seq_buf
*s
, const char *str
);
122 extern int seq_buf_putc(struct seq_buf
*s
, unsigned char c
);
123 extern int seq_buf_putmem(struct seq_buf
*s
, const void *mem
, unsigned int len
);
124 extern int seq_buf_putmem_hex(struct seq_buf
*s
, const void *mem
,
126 extern int seq_buf_path(struct seq_buf
*s
, const struct path
*path
, const char *esc
);
128 #ifdef CONFIG_BINARY_PRINTF
130 seq_buf_bprintf(struct seq_buf
*s
, const char *fmt
, const u32
*binary
);
133 #endif /* _LINUX_SEQ_BUF_H */