1 #ifndef _LINUX_TRACE_SEQ_H
2 #define _LINUX_TRACE_SEQ_H
4 #include <linux/seq_buf.h>
9 * Trace sequences are used to allow a function to call several other functions
10 * to create a string of data to use (up to a max of PAGE_SIZE).
14 unsigned char buffer[PAGE_SIZE];
20 trace_seq_init(struct trace_seq *s)
22 seq_buf_init(&s->seq, s->buffer, PAGE_SIZE);
27 * trace_seq_used - amount of actual data written to buffer
28 * @s: trace sequence descriptor
30 * Returns the amount of data written to the buffer.
34 * Use this instead of @s->seq.len if you need to pass the amount
35 * of data from the buffer to another buffer (userspace, or what not).
36 * The @s->seq.len on overflow is bigger than the buffer size and
37 * using it can cause access to undefined memory.
39 static inline int trace_seq_used(struct trace_seq *s)
41 return seq_buf_used(&s->seq);
45 * trace_seq_buffer_ptr - return pointer to next location in buffer
46 * @s: trace sequence descriptor
48 * Returns the pointer to the buffer where the next write to
49 * the buffer will happen. This is useful to save the location
50 * that is about to be written to and then return the result
53 static inline unsigned char *
54 trace_seq_buffer_ptr(struct trace_seq *s)
56 return s->buffer + seq_buf_used(&s->seq);
60 * trace_seq_has_overflowed - return true if the trace_seq took too much
61 * @s: trace sequence descriptor
63 * Returns true if too much data was added to the trace_seq and it is
64 * now full and will not take anymore.
66 static inline bool trace_seq_has_overflowed(struct trace_seq *s)
68 return s->full || seq_buf_has_overflowed(&s->seq);
72 * Currently only defined when tracing is enabled.
76 void trace_seq_printf(struct trace_seq *s, const char *fmt, ...);
78 void trace_seq_vprintf(struct trace_seq *s, const char *fmt, va_list args);
80 trace_seq_bprintf(struct trace_seq *s, const char *fmt, const u32 *binary);
81 extern int trace_print_seq(struct seq_file *m, struct trace_seq *s);
82 extern int trace_seq_to_user(struct trace_seq *s, char __user *ubuf,
84 extern void trace_seq_puts(struct trace_seq *s, const char *str);
85 extern void trace_seq_putc(struct trace_seq *s, unsigned char c);
86 extern void trace_seq_putmem(struct trace_seq *s, const void *mem, unsigned int len);
87 extern void trace_seq_putmem_hex(struct trace_seq *s, const void *mem,
89 extern int trace_seq_path(struct trace_seq *s, const struct path *path);
91 extern void trace_seq_bitmask(struct trace_seq *s, const unsigned long *maskp,
94 #else /* CONFIG_TRACING */
95 static inline void trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
99 trace_seq_bprintf(struct trace_seq *s, const char *fmt, const u32 *binary)
104 trace_seq_bitmask(struct trace_seq *s, const unsigned long *maskp,
109 static inline int trace_print_seq(struct seq_file *m, struct trace_seq *s)
113 static inline int trace_seq_to_user(struct trace_seq *s, char __user *ubuf,
118 static inline void trace_seq_puts(struct trace_seq *s, const char *str)
121 static inline void trace_seq_putc(struct trace_seq *s, unsigned char c)
125 trace_seq_putmem(struct trace_seq *s, const void *mem, unsigned int len)
128 static inline void trace_seq_putmem_hex(struct trace_seq *s, const void *mem,
132 static inline int trace_seq_path(struct trace_seq *s, const struct path *path)
136 #endif /* CONFIG_TRACING */
138 #endif /* _LINUX_TRACE_SEQ_H */