seq_file.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. void *private;
  24. };
  25. struct seq_operations {
  26. void * (*start) (struct seq_file *m, loff_t *pos);
  27. void (*stop) (struct seq_file *m, void *v);
  28. void * (*next) (struct seq_file *m, void *v, loff_t *pos);
  29. int (*show) (struct seq_file *m, void *v);
  30. };
  31. #define SEQ_SKIP 1
  32. /**
  33. * seq_get_buf - get buffer to write arbitrary data to
  34. * @m: the seq_file handle
  35. * @bufp: the beginning of the buffer is stored here
  36. *
  37. * Return the number of bytes available in the buffer, or zero if
  38. * there's no space.
  39. */
  40. static inline size_t seq_get_buf(struct seq_file *m, char **bufp)
  41. {
  42. BUG_ON(m->count > m->size);
  43. if (m->count < m->size)
  44. *bufp = m->buf + m->count;
  45. else
  46. *bufp = NULL;
  47. return m->size - m->count;
  48. }
  49. /**
  50. * seq_commit - commit data to the buffer
  51. * @m: the seq_file handle
  52. * @num: the number of bytes to commit
  53. *
  54. * Commit @num bytes of data written to a buffer previously acquired
  55. * by seq_buf_get. To signal an error condition, or that the data
  56. * didn't fit in the available space, pass a negative @num value.
  57. */
  58. static inline void seq_commit(struct seq_file *m, int num)
  59. {
  60. if (num < 0) {
  61. m->count = m->size;
  62. } else {
  63. BUG_ON(m->count + num > m->size);
  64. m->count += num;
  65. }
  66. }
  67. char *mangle_path(char *s, char *p, char *esc);
  68. int seq_open(struct file *, const struct seq_operations *);
  69. ssize_t seq_read(struct file *, char __user *, size_t, loff_t *);
  70. loff_t seq_lseek(struct file *, loff_t, int);
  71. int seq_release(struct inode *, struct file *);
  72. int seq_escape(struct seq_file *, const char *, const char *);
  73. int seq_putc(struct seq_file *m, char c);
  74. int seq_puts(struct seq_file *m, const char *s);
  75. int seq_write(struct seq_file *seq, const void *data, size_t len);
  76. int seq_printf(struct seq_file *, const char *, ...)
  77. __attribute__ ((format (printf,2,3)));
  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. #endif