proc_fs.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. #ifndef _LINUX_PROC_FS_H
  2. #define _LINUX_PROC_FS_H
  3. #include <linux/slab.h>
  4. #include <linux/fs.h>
  5. #include <linux/spinlock.h>
  6. #include <linux/magic.h>
  7. #include <linux/atomic.h>
  8. #include <linux/proc_ns.h>
  9. struct net;
  10. struct completion;
  11. struct mm_struct;
  12. /*
  13. * The proc filesystem constants/structures
  14. */
  15. /*
  16. * Offset of the first process in the /proc root directory..
  17. */
  18. #define FIRST_PROCESS_ENTRY 256
  19. /* Worst case buffer size needed for holding an integer. */
  20. #define PROC_NUMBUF 13
  21. /*
  22. * This is not completely implemented yet. The idea is to
  23. * create an in-memory tree (like the actual /proc filesystem
  24. * tree) of these proc_dir_entries, so that we can dynamically
  25. * add new files to /proc.
  26. *
  27. * The "next" pointer creates a linked list of one /proc directory,
  28. * while parent/subdir create the directory structure (every
  29. * /proc file has a parent, but "subdir" is NULL for all
  30. * non-directory entries).
  31. */
  32. struct proc_dir_entry {
  33. unsigned int low_ino;
  34. umode_t mode;
  35. nlink_t nlink;
  36. kuid_t uid;
  37. kgid_t gid;
  38. loff_t size;
  39. const struct inode_operations *proc_iops;
  40. const struct file_operations *proc_fops;
  41. struct proc_dir_entry *next, *parent, *subdir;
  42. void *data;
  43. atomic_t count; /* use count */
  44. atomic_t in_use; /* number of callers into module in progress; */
  45. /* negative -> it's going away RSN */
  46. struct completion *pde_unload_completion;
  47. struct list_head pde_openers; /* who did ->open, but not ->release */
  48. spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
  49. u8 namelen;
  50. char name[];
  51. };
  52. #ifdef CONFIG_PROC_FS
  53. extern void proc_root_init(void);
  54. void proc_flush_task(struct task_struct *task);
  55. struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
  56. struct proc_dir_entry *parent,
  57. const struct file_operations *proc_fops,
  58. void *data);
  59. extern void remove_proc_entry(const char *name, struct proc_dir_entry *parent);
  60. extern int remove_proc_subtree(const char *name, struct proc_dir_entry *parent);
  61. /*
  62. * proc_tty.c
  63. */
  64. struct tty_driver;
  65. #ifdef CONFIG_TTY
  66. extern void proc_tty_init(void);
  67. #else
  68. static inline void proc_tty_init(void)
  69. { }
  70. #endif
  71. extern void proc_tty_register_driver(struct tty_driver *driver);
  72. extern void proc_tty_unregister_driver(struct tty_driver *driver);
  73. /*
  74. * proc_devtree.c
  75. */
  76. #ifdef CONFIG_PROC_DEVICETREE
  77. struct device_node;
  78. struct property;
  79. extern void proc_device_tree_init(void);
  80. extern void proc_device_tree_add_node(struct device_node *, struct proc_dir_entry *);
  81. extern void proc_device_tree_add_prop(struct proc_dir_entry *pde, struct property *prop);
  82. extern void proc_device_tree_remove_prop(struct proc_dir_entry *pde,
  83. struct property *prop);
  84. extern void proc_device_tree_update_prop(struct proc_dir_entry *pde,
  85. struct property *newprop,
  86. struct property *oldprop);
  87. #endif /* CONFIG_PROC_DEVICETREE */
  88. extern struct proc_dir_entry *proc_symlink(const char *,
  89. struct proc_dir_entry *, const char *);
  90. extern struct proc_dir_entry *proc_mkdir(const char *,struct proc_dir_entry *);
  91. extern struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
  92. struct proc_dir_entry *parent);
  93. static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
  94. struct proc_dir_entry *parent, const struct file_operations *proc_fops)
  95. {
  96. return proc_create_data(name, mode, parent, proc_fops, NULL);
  97. }
  98. extern struct proc_dir_entry *proc_net_mkdir(struct net *net, const char *name,
  99. struct proc_dir_entry *parent);
  100. extern void proc_set_size(struct proc_dir_entry *, loff_t);
  101. extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
  102. #else
  103. static inline void proc_flush_task(struct task_struct *task)
  104. {
  105. }
  106. #define proc_create(name, mode, parent, fops) ({ (void)(mode), NULL; })
  107. static inline struct proc_dir_entry *proc_create_data(const char *name,
  108. umode_t mode, struct proc_dir_entry *parent,
  109. const struct file_operations *proc_fops, void *data)
  110. {
  111. return NULL;
  112. }
  113. #define remove_proc_entry(name, parent) do {} while (0)
  114. #define remove_proc_subtree(name, parent) do {} while (0)
  115. static inline struct proc_dir_entry *proc_symlink(const char *name,
  116. struct proc_dir_entry *parent,const char *dest) {return NULL;}
  117. static inline struct proc_dir_entry *proc_mkdir(const char *name,
  118. struct proc_dir_entry *parent) {return NULL;}
  119. static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
  120. umode_t mode, struct proc_dir_entry *parent) { return NULL; }
  121. static inline void proc_set_size(struct proc_dir_entry *de, loff_t size) {}
  122. static inline void proc_set_user(struct proc_dir_entry *de, kuid_t uid, kgid_t gid) {}
  123. struct tty_driver;
  124. static inline void proc_tty_register_driver(struct tty_driver *driver) {};
  125. static inline void proc_tty_unregister_driver(struct tty_driver *driver) {};
  126. #endif /* CONFIG_PROC_FS */
  127. union proc_op {
  128. int (*proc_get_link)(struct dentry *, struct path *);
  129. int (*proc_read)(struct task_struct *task, char *page);
  130. int (*proc_show)(struct seq_file *m,
  131. struct pid_namespace *ns, struct pid *pid,
  132. struct task_struct *task);
  133. };
  134. struct ctl_table_header;
  135. struct ctl_table;
  136. struct proc_inode {
  137. struct pid *pid;
  138. int fd;
  139. union proc_op op;
  140. struct proc_dir_entry *pde;
  141. struct ctl_table_header *sysctl;
  142. struct ctl_table *sysctl_entry;
  143. struct proc_ns ns;
  144. struct inode vfs_inode;
  145. };
  146. static inline struct proc_inode *PROC_I(const struct inode *inode)
  147. {
  148. return container_of(inode, struct proc_inode, vfs_inode);
  149. }
  150. static inline struct proc_dir_entry *PDE(const struct inode *inode)
  151. {
  152. return PROC_I(inode)->pde;
  153. }
  154. static inline void *PDE_DATA(const struct inode *inode)
  155. {
  156. return PROC_I(inode)->pde->data;
  157. }
  158. static inline struct net *PDE_NET(struct proc_dir_entry *pde)
  159. {
  160. return pde->parent->data;
  161. }
  162. #include <linux/signal.h>
  163. void render_sigset_t(struct seq_file *m, const char *header, sigset_t *set);
  164. #endif /* _LINUX_PROC_FS_H */