seq_file.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. #ifndef _LINUX_SEQ_FILE_H
  2. #define _LINUX_SEQ_FILE_H
  3. #include <linux/types.h>
  4. #include <linux/string.h>
  5. #include <linux/bug.h>
  6. #include <linux/mutex.h>
  7. #include <linux/cpumask.h>
  8. #include <linux/nodemask.h>
  9. struct seq_operations;
  10. struct file;
  11. struct path;
  12. struct inode;
  13. struct dentry;
  14. struct user_namespace;
  15. struct seq_file {
  16. char *buf;
  17. size_t size;
  18. size_t from;
  19. size_t count;
  20. loff_t index;
  21. loff_t read_pos;
  22. u64 version;
  23. struct mutex lock;
  24. const struct seq_operations *op;
  25. int poll_event;
  26. #ifdef CONFIG_USER_NS
  27. struct user_namespace *user_ns;
  28. #endif
  29. void *private;
  30. };
  31. struct seq_operations {
  32. void * (*start) (struct seq_file *m, loff_t *pos);
  33. void (*stop) (struct seq_file *m, void *v);
  34. void * (*next) (struct seq_file *m, void *v, loff_t *pos);
  35. int (*show) (struct seq_file *m, void *v);
  36. };
  37. #define SEQ_SKIP 1
  38. /**
  39. * seq_get_buf - get buffer to write arbitrary data to
  40. * @m: the seq_file handle
  41. * @bufp: the beginning of the buffer is stored here
  42. *
  43. * Return the number of bytes available in the buffer, or zero if
  44. * there's no space.
  45. */
  46. static inline size_t seq_get_buf(struct seq_file *m, char **bufp)
  47. {
  48. BUG_ON(m->count > m->size);
  49. if (m->count < m->size)
  50. *bufp = m->buf + m->count;
  51. else
  52. *bufp = NULL;
  53. return m->size - m->count;
  54. }
  55. /**
  56. * seq_commit - commit data to the buffer
  57. * @m: the seq_file handle
  58. * @num: the number of bytes to commit
  59. *
  60. * Commit @num bytes of data written to a buffer previously acquired
  61. * by seq_buf_get. To signal an error condition, or that the data
  62. * didn't fit in the available space, pass a negative @num value.
  63. */
  64. static inline void seq_commit(struct seq_file *m, int num)
  65. {
  66. if (num < 0) {
  67. m->count = m->size;
  68. } else {
  69. BUG_ON(m->count + num > m->size);
  70. m->count += num;
  71. }
  72. }
  73. char *mangle_path(char *s, const char *p, const char *esc);
  74. int seq_open(struct file *, const struct seq_operations *);
  75. ssize_t seq_read(struct file *, char __user *, size_t, loff_t *);
  76. loff_t seq_lseek(struct file *, loff_t, int);
  77. int seq_release(struct inode *, struct file *);
  78. int seq_escape(struct seq_file *, const char *, const char *);
  79. int seq_putc(struct seq_file *m, char c);
  80. int seq_puts(struct seq_file *m, const char *s);
  81. int seq_write(struct seq_file *seq, const void *data, size_t len);
  82. __printf(2, 3) int seq_printf(struct seq_file *, const char *, ...);
  83. __printf(2, 0) int seq_vprintf(struct seq_file *, const char *, va_list args);
  84. int seq_path(struct seq_file *, const struct path *, const char *);
  85. int seq_dentry(struct seq_file *, struct dentry *, const char *);
  86. int seq_path_root(struct seq_file *m, const struct path *path,
  87. const struct path *root, const char *esc);
  88. int seq_bitmap(struct seq_file *m, const unsigned long *bits,
  89. unsigned int nr_bits);
  90. static inline int seq_cpumask(struct seq_file *m, const struct cpumask *mask)
  91. {
  92. return seq_bitmap(m, cpumask_bits(mask), nr_cpu_ids);
  93. }
  94. static inline int seq_nodemask(struct seq_file *m, nodemask_t *mask)
  95. {
  96. return seq_bitmap(m, mask->bits, MAX_NUMNODES);
  97. }
  98. int seq_bitmap_list(struct seq_file *m, const unsigned long *bits,
  99. unsigned int nr_bits);
  100. static inline int seq_cpumask_list(struct seq_file *m,
  101. const struct cpumask *mask)
  102. {
  103. return seq_bitmap_list(m, cpumask_bits(mask), nr_cpu_ids);
  104. }
  105. static inline int seq_nodemask_list(struct seq_file *m, nodemask_t *mask)
  106. {
  107. return seq_bitmap_list(m, mask->bits, MAX_NUMNODES);
  108. }
  109. int single_open(struct file *, int (*)(struct seq_file *, void *), void *);
  110. int single_open_size(struct file *, int (*)(struct seq_file *, void *), void *, size_t);
  111. int single_release(struct inode *, struct file *);
  112. void *__seq_open_private(struct file *, const struct seq_operations *, int);
  113. int seq_open_private(struct file *, const struct seq_operations *, int);
  114. int seq_release_private(struct inode *, struct file *);
  115. int seq_put_decimal_ull(struct seq_file *m, char delimiter,
  116. unsigned long long num);
  117. int seq_put_decimal_ll(struct seq_file *m, char delimiter,
  118. long long num);
  119. static inline struct user_namespace *seq_user_ns(struct seq_file *seq)
  120. {
  121. #ifdef CONFIG_USER_NS
  122. return seq->user_ns;
  123. #else
  124. extern struct user_namespace init_user_ns;
  125. return &init_user_ns;
  126. #endif
  127. }
  128. #define SEQ_START_TOKEN ((void *)1)
  129. /*
  130. * Helpers for iteration over list_head-s in seq_files
  131. */
  132. extern struct list_head *seq_list_start(struct list_head *head,
  133. loff_t pos);
  134. extern struct list_head *seq_list_start_head(struct list_head *head,
  135. loff_t pos);
  136. extern struct list_head *seq_list_next(void *v, struct list_head *head,
  137. loff_t *ppos);
  138. /*
  139. * Helpers for iteration over hlist_head-s in seq_files
  140. */
  141. extern struct hlist_node *seq_hlist_start(struct hlist_head *head,
  142. loff_t pos);
  143. extern struct hlist_node *seq_hlist_start_head(struct hlist_head *head,
  144. loff_t pos);
  145. extern struct hlist_node *seq_hlist_next(void *v, struct hlist_head *head,
  146. loff_t *ppos);
  147. extern struct hlist_node *seq_hlist_start_rcu(struct hlist_head *head,
  148. loff_t pos);
  149. extern struct hlist_node *seq_hlist_start_head_rcu(struct hlist_head *head,
  150. loff_t pos);
  151. extern struct hlist_node *seq_hlist_next_rcu(void *v,
  152. struct hlist_head *head,
  153. loff_t *ppos);
  154. #endif