seq_file.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. int seq_path(struct seq_file *, const struct path *, const char *);
  80. int seq_dentry(struct seq_file *, struct dentry *, const char *);
  81. int seq_path_root(struct seq_file *m, const struct path *path,
  82. const struct path *root, const char *esc);
  83. int seq_bitmap(struct seq_file *m, const unsigned long *bits,
  84. unsigned int nr_bits);
  85. static inline int seq_cpumask(struct seq_file *m, const struct cpumask *mask)
  86. {
  87. return seq_bitmap(m, cpumask_bits(mask), nr_cpu_ids);
  88. }
  89. static inline int seq_nodemask(struct seq_file *m, nodemask_t *mask)
  90. {
  91. return seq_bitmap(m, mask->bits, MAX_NUMNODES);
  92. }
  93. int seq_bitmap_list(struct seq_file *m, const unsigned long *bits,
  94. unsigned int nr_bits);
  95. static inline int seq_cpumask_list(struct seq_file *m,
  96. const struct cpumask *mask)
  97. {
  98. return seq_bitmap_list(m, cpumask_bits(mask), nr_cpu_ids);
  99. }
  100. static inline int seq_nodemask_list(struct seq_file *m, nodemask_t *mask)
  101. {
  102. return seq_bitmap_list(m, mask->bits, MAX_NUMNODES);
  103. }
  104. int single_open(struct file *, int (*)(struct seq_file *, void *), void *);
  105. int single_release(struct inode *, struct file *);
  106. void *__seq_open_private(struct file *, const struct seq_operations *, int);
  107. int seq_open_private(struct file *, const struct seq_operations *, int);
  108. int seq_release_private(struct inode *, struct file *);
  109. #define SEQ_START_TOKEN ((void *)1)
  110. /*
  111. * Helpers for iteration over list_head-s in seq_files
  112. */
  113. extern struct list_head *seq_list_start(struct list_head *head,
  114. loff_t pos);
  115. extern struct list_head *seq_list_start_head(struct list_head *head,
  116. loff_t pos);
  117. extern struct list_head *seq_list_next(void *v, struct list_head *head,
  118. loff_t *ppos);
  119. /*
  120. * Helpers for iteration over hlist_head-s in seq_files
  121. */
  122. extern struct hlist_node *seq_hlist_start(struct hlist_head *head,
  123. loff_t pos);
  124. extern struct hlist_node *seq_hlist_start_head(struct hlist_head *head,
  125. loff_t pos);
  126. extern struct hlist_node *seq_hlist_next(void *v, struct hlist_head *head,
  127. loff_t *ppos);
  128. extern struct hlist_node *seq_hlist_start_rcu(struct hlist_head *head,
  129. loff_t pos);
  130. extern struct hlist_node *seq_hlist_start_head_rcu(struct hlist_head *head,
  131. loff_t pos);
  132. extern struct hlist_node *seq_hlist_next_rcu(void *v,
  133. struct hlist_head *head,
  134. loff_t *ppos);
  135. #endif