1 #ifndef _LINUX_SEQ_FILE_H
2 #define _LINUX_SEQ_FILE_H
4 #include <linux/types.h>
5 #include <linux/string.h>
7 #include <linux/mutex.h>
8 #include <linux/cpumask.h>
9 #include <linux/nodemask.h>
11 struct seq_operations
;
16 struct user_namespace
;
28 const struct seq_operations
*op
;
31 struct user_namespace
*user_ns
;
36 struct seq_operations
{
37 void * (*start
) (struct seq_file
*m
, loff_t
*pos
);
38 void (*stop
) (struct seq_file
*m
, void *v
);
39 void * (*next
) (struct seq_file
*m
, void *v
, loff_t
*pos
);
40 int (*show
) (struct seq_file
*m
, void *v
);
46 * seq_get_buf - get buffer to write arbitrary data to
47 * @m: the seq_file handle
48 * @bufp: the beginning of the buffer is stored here
50 * Return the number of bytes available in the buffer, or zero if
53 static inline size_t seq_get_buf(struct seq_file
*m
, char **bufp
)
55 BUG_ON(m
->count
> m
->size
);
56 if (m
->count
< m
->size
)
57 *bufp
= m
->buf
+ m
->count
;
61 return m
->size
- m
->count
;
65 * seq_commit - commit data to the buffer
66 * @m: the seq_file handle
67 * @num: the number of bytes to commit
69 * Commit @num bytes of data written to a buffer previously acquired
70 * by seq_buf_get. To signal an error condition, or that the data
71 * didn't fit in the available space, pass a negative @num value.
73 static inline void seq_commit(struct seq_file
*m
, int num
)
78 BUG_ON(m
->count
+ num
> m
->size
);
84 * seq_setwidth - set padding width
85 * @m: the seq_file handle
86 * @size: the max number of bytes to pad.
88 * Call seq_setwidth() for setting max width, then call seq_printf() etc. and
89 * finally call seq_pad() to pad the remaining bytes.
91 static inline void seq_setwidth(struct seq_file
*m
, size_t size
)
93 m
->pad_until
= m
->count
+ size
;
95 void seq_pad(struct seq_file
*m
, char c
);
97 char *mangle_path(char *s
, const char *p
, const char *esc
);
98 int seq_open(struct file
*, const struct seq_operations
*);
99 ssize_t
seq_read(struct file
*, char __user
*, size_t, loff_t
*);
100 loff_t
seq_lseek(struct file
*, loff_t
, int);
101 int seq_release(struct inode
*, struct file
*);
102 int seq_escape(struct seq_file
*, const char *, const char *);
103 int seq_putc(struct seq_file
*m
, char c
);
104 int seq_puts(struct seq_file
*m
, const char *s
);
105 int seq_write(struct seq_file
*seq
, const void *data
, size_t len
);
107 __printf(2, 3) int seq_printf(struct seq_file
*, const char *, ...);
108 __printf(2, 0) int seq_vprintf(struct seq_file
*, const char *, va_list args
);
110 int seq_path(struct seq_file
*, const struct path
*, const char *);
111 int seq_dentry(struct seq_file
*, struct dentry
*, const char *);
112 int seq_path_root(struct seq_file
*m
, const struct path
*path
,
113 const struct path
*root
, const char *esc
);
114 int seq_bitmap(struct seq_file
*m
, const unsigned long *bits
,
115 unsigned int nr_bits
);
116 static inline int seq_cpumask(struct seq_file
*m
, const struct cpumask
*mask
)
118 return seq_bitmap(m
, cpumask_bits(mask
), nr_cpu_ids
);
121 static inline int seq_nodemask(struct seq_file
*m
, nodemask_t
*mask
)
123 return seq_bitmap(m
, mask
->bits
, MAX_NUMNODES
);
126 int seq_bitmap_list(struct seq_file
*m
, const unsigned long *bits
,
127 unsigned int nr_bits
);
129 static inline int seq_cpumask_list(struct seq_file
*m
,
130 const struct cpumask
*mask
)
132 return seq_bitmap_list(m
, cpumask_bits(mask
), nr_cpu_ids
);
135 static inline int seq_nodemask_list(struct seq_file
*m
, nodemask_t
*mask
)
137 return seq_bitmap_list(m
, mask
->bits
, MAX_NUMNODES
);
140 int single_open(struct file
*, int (*)(struct seq_file
*, void *), void *);
141 int single_open_size(struct file
*, int (*)(struct seq_file
*, void *), void *, size_t);
142 int single_release(struct inode
*, struct file
*);
143 void *__seq_open_private(struct file
*, const struct seq_operations
*, int);
144 int seq_open_private(struct file
*, const struct seq_operations
*, int);
145 int seq_release_private(struct inode
*, struct file
*);
146 int seq_put_decimal_ull(struct seq_file
*m
, char delimiter
,
147 unsigned long long num
);
148 int seq_put_decimal_ll(struct seq_file
*m
, char delimiter
,
151 static inline struct user_namespace
*seq_user_ns(struct seq_file
*seq
)
153 #ifdef CONFIG_USER_NS
156 extern struct user_namespace init_user_ns
;
157 return &init_user_ns
;
161 #define SEQ_START_TOKEN ((void *)1)
163 * Helpers for iteration over list_head-s in seq_files
166 extern struct list_head
*seq_list_start(struct list_head
*head
,
168 extern struct list_head
*seq_list_start_head(struct list_head
*head
,
170 extern struct list_head
*seq_list_next(void *v
, struct list_head
*head
,
174 * Helpers for iteration over hlist_head-s in seq_files
177 extern struct hlist_node
*seq_hlist_start(struct hlist_head
*head
,
179 extern struct hlist_node
*seq_hlist_start_head(struct hlist_head
*head
,
181 extern struct hlist_node
*seq_hlist_next(void *v
, struct hlist_head
*head
,
184 extern struct hlist_node
*seq_hlist_start_rcu(struct hlist_head
*head
,
186 extern struct hlist_node
*seq_hlist_start_head_rcu(struct hlist_head
*head
,
188 extern struct hlist_node
*seq_hlist_next_rcu(void *v
,
189 struct hlist_head
*head
,
192 /* Helpers for iterating over per-cpu hlist_head-s in seq_files */
193 extern struct hlist_node
*seq_hlist_start_percpu(struct hlist_head __percpu
*head
, int *cpu
, loff_t pos
);
195 extern struct hlist_node
*seq_hlist_next_percpu(void *v
, struct hlist_head __percpu
*head
, int *cpu
, loff_t
*pos
);