seq_file.h 4.4 KB

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