seq_file.h 4.7 KB

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