2014-06-26 03:54:42 +08:00
|
|
|
#ifndef _LINUX_SEQ_BUF_H
|
|
|
|
#define _LINUX_SEQ_BUF_H
|
|
|
|
|
|
|
|
#include <linux/fs.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Trace sequences are used to allow a function to call several other functions
|
|
|
|
* to create a string of data to use.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* seq_buf - seq buffer structure
|
|
|
|
* @buffer: pointer to the buffer
|
|
|
|
* @size: size of the buffer
|
|
|
|
* @len: the amount of data inside the buffer
|
|
|
|
* @readpos: The next position to read in the buffer.
|
|
|
|
*/
|
|
|
|
struct seq_buf {
|
2014-10-30 01:59:58 +08:00
|
|
|
char *buffer;
|
|
|
|
size_t size;
|
|
|
|
size_t len;
|
|
|
|
loff_t readpos;
|
2014-06-26 03:54:42 +08:00
|
|
|
};
|
|
|
|
|
2014-10-30 02:17:52 +08:00
|
|
|
static inline void seq_buf_clear(struct seq_buf *s)
|
|
|
|
{
|
|
|
|
s->len = 0;
|
|
|
|
s->readpos = 0;
|
|
|
|
}
|
|
|
|
|
2014-06-26 03:54:42 +08:00
|
|
|
static inline void
|
|
|
|
seq_buf_init(struct seq_buf *s, unsigned char *buf, unsigned int size)
|
|
|
|
{
|
|
|
|
s->buffer = buf;
|
|
|
|
s->size = size;
|
2014-10-30 02:17:52 +08:00
|
|
|
seq_buf_clear(s);
|
2014-06-26 03:54:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* seq_buf have a buffer that might overflow. When this happens
|
|
|
|
* the len and size are set to be equal.
|
|
|
|
*/
|
|
|
|
static inline bool
|
|
|
|
seq_buf_has_overflowed(struct seq_buf *s)
|
|
|
|
{
|
2014-10-30 03:26:09 +08:00
|
|
|
return s->len > s->size;
|
2014-06-26 03:54:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
seq_buf_set_overflow(struct seq_buf *s)
|
|
|
|
{
|
2014-10-30 03:26:09 +08:00
|
|
|
s->len = s->size + 1;
|
2014-06-26 03:54:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* How much buffer is left on the seq_buf?
|
|
|
|
*/
|
|
|
|
static inline unsigned int
|
|
|
|
seq_buf_buffer_left(struct seq_buf *s)
|
|
|
|
{
|
|
|
|
if (seq_buf_has_overflowed(s))
|
|
|
|
return 0;
|
|
|
|
|
2014-10-30 03:26:09 +08:00
|
|
|
return s->size - s->len;
|
2014-06-26 03:54:42 +08:00
|
|
|
}
|
|
|
|
|
2014-11-07 05:38:28 +08:00
|
|
|
/* How much buffer was written? */
|
|
|
|
static inline unsigned int seq_buf_used(struct seq_buf *s)
|
|
|
|
{
|
|
|
|
return min(s->len, s->size);
|
|
|
|
}
|
|
|
|
|
2014-06-26 03:54:42 +08:00
|
|
|
extern __printf(2, 3)
|
|
|
|
int seq_buf_printf(struct seq_buf *s, const char *fmt, ...);
|
|
|
|
extern __printf(2, 0)
|
|
|
|
int seq_buf_vprintf(struct seq_buf *s, const char *fmt, va_list args);
|
|
|
|
extern int
|
|
|
|
seq_buf_bprintf(struct seq_buf *s, const char *fmt, const u32 *binary);
|
|
|
|
extern int seq_buf_print_seq(struct seq_file *m, struct seq_buf *s);
|
|
|
|
extern int seq_buf_to_user(struct seq_buf *s, char __user *ubuf,
|
|
|
|
int cnt);
|
|
|
|
extern int seq_buf_puts(struct seq_buf *s, const char *str);
|
|
|
|
extern int seq_buf_putc(struct seq_buf *s, unsigned char c);
|
|
|
|
extern int seq_buf_putmem(struct seq_buf *s, const void *mem, unsigned int len);
|
|
|
|
extern int seq_buf_putmem_hex(struct seq_buf *s, const void *mem,
|
|
|
|
unsigned int len);
|
2014-10-30 01:48:37 +08:00
|
|
|
extern int seq_buf_path(struct seq_buf *s, const struct path *path, const char *esc);
|
2014-06-26 03:54:42 +08:00
|
|
|
|
|
|
|
extern int seq_buf_bitmask(struct seq_buf *s, const unsigned long *maskp,
|
|
|
|
int nmaskbits);
|
|
|
|
|
|
|
|
#endif /* _LINUX_SEQ_BUF_H */
|