proc_fs.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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 <asm/atomic.h>
  8. struct net;
  9. struct completion;
  10. struct mm_struct;
  11. /*
  12. * The proc filesystem constants/structures
  13. */
  14. /*
  15. * Offset of the first process in the /proc root directory..
  16. */
  17. #define FIRST_PROCESS_ENTRY 256
  18. /* Worst case buffer size needed for holding an integer. */
  19. #define PROC_NUMBUF 13
  20. /*
  21. * We always define these enumerators
  22. */
  23. enum {
  24. PROC_ROOT_INO = 1,
  25. };
  26. /*
  27. * This is not completely implemented yet. The idea is to
  28. * create an in-memory tree (like the actual /proc filesystem
  29. * tree) of these proc_dir_entries, so that we can dynamically
  30. * add new files to /proc.
  31. *
  32. * The "next" pointer creates a linked list of one /proc directory,
  33. * while parent/subdir create the directory structure (every
  34. * /proc file has a parent, but "subdir" is NULL for all
  35. * non-directory entries).
  36. */
  37. typedef int (read_proc_t)(char *page, char **start, off_t off,
  38. int count, int *eof, void *data);
  39. typedef int (write_proc_t)(struct file *file, const char __user *buffer,
  40. unsigned long count, void *data);
  41. struct proc_dir_entry {
  42. unsigned int low_ino;
  43. unsigned short namelen;
  44. const char *name;
  45. mode_t mode;
  46. nlink_t nlink;
  47. uid_t uid;
  48. gid_t gid;
  49. loff_t size;
  50. const struct inode_operations *proc_iops;
  51. /*
  52. * NULL ->proc_fops means "PDE is going away RSN" or
  53. * "PDE is just created". In either case, e.g. ->read_proc won't be
  54. * called because it's too late or too early, respectively.
  55. *
  56. * If you're allocating ->proc_fops dynamically, save a pointer
  57. * somewhere.
  58. */
  59. const struct file_operations *proc_fops;
  60. struct proc_dir_entry *next, *parent, *subdir;
  61. void *data;
  62. read_proc_t *read_proc;
  63. write_proc_t *write_proc;
  64. atomic_t count; /* use count */
  65. int pde_users; /* number of callers into module in progress */
  66. spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
  67. struct completion *pde_unload_completion;
  68. struct list_head pde_openers; /* who did ->open, but not ->release */
  69. };
  70. struct kcore_list {
  71. struct kcore_list *next;
  72. unsigned long addr;
  73. size_t size;
  74. };
  75. struct vmcore {
  76. struct list_head list;
  77. unsigned long long paddr;
  78. unsigned long long size;
  79. loff_t offset;
  80. };
  81. #ifdef CONFIG_PROC_FS
  82. extern void proc_root_init(void);
  83. void proc_flush_task(struct task_struct *task);
  84. extern struct proc_dir_entry *create_proc_entry(const char *name, mode_t mode,
  85. struct proc_dir_entry *parent);
  86. struct proc_dir_entry *proc_create_data(const char *name, mode_t mode,
  87. struct proc_dir_entry *parent,
  88. const struct file_operations *proc_fops,
  89. void *data);
  90. extern void remove_proc_entry(const char *name, struct proc_dir_entry *parent);
  91. struct pid_namespace;
  92. extern int pid_ns_prepare_proc(struct pid_namespace *ns);
  93. extern void pid_ns_release_proc(struct pid_namespace *ns);
  94. /*
  95. * proc_tty.c
  96. */
  97. struct tty_driver;
  98. extern void proc_tty_init(void);
  99. extern void proc_tty_register_driver(struct tty_driver *driver);
  100. extern void proc_tty_unregister_driver(struct tty_driver *driver);
  101. /*
  102. * proc_devtree.c
  103. */
  104. #ifdef CONFIG_PROC_DEVICETREE
  105. struct device_node;
  106. struct property;
  107. extern void proc_device_tree_init(void);
  108. extern void proc_device_tree_add_node(struct device_node *, struct proc_dir_entry *);
  109. extern void proc_device_tree_add_prop(struct proc_dir_entry *pde, struct property *prop);
  110. extern void proc_device_tree_remove_prop(struct proc_dir_entry *pde,
  111. struct property *prop);
  112. extern void proc_device_tree_update_prop(struct proc_dir_entry *pde,
  113. struct property *newprop,
  114. struct property *oldprop);
  115. #endif /* CONFIG_PROC_DEVICETREE */
  116. extern struct proc_dir_entry *proc_symlink(const char *,
  117. struct proc_dir_entry *, const char *);
  118. extern struct proc_dir_entry *proc_mkdir(const char *,struct proc_dir_entry *);
  119. extern struct proc_dir_entry *proc_mkdir_mode(const char *name, mode_t mode,
  120. struct proc_dir_entry *parent);
  121. static inline struct proc_dir_entry *proc_create(const char *name, mode_t mode,
  122. struct proc_dir_entry *parent, const struct file_operations *proc_fops)
  123. {
  124. return proc_create_data(name, mode, parent, proc_fops, NULL);
  125. }
  126. static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
  127. mode_t mode, struct proc_dir_entry *base,
  128. read_proc_t *read_proc, void * data)
  129. {
  130. struct proc_dir_entry *res=create_proc_entry(name,mode,base);
  131. if (res) {
  132. res->read_proc=read_proc;
  133. res->data=data;
  134. }
  135. return res;
  136. }
  137. extern struct proc_dir_entry *proc_net_fops_create(struct net *net,
  138. const char *name, mode_t mode, const struct file_operations *fops);
  139. extern void proc_net_remove(struct net *net, const char *name);
  140. extern struct proc_dir_entry *proc_net_mkdir(struct net *net, const char *name,
  141. struct proc_dir_entry *parent);
  142. /* While the {get|set|dup}_mm_exe_file functions are for mm_structs, they are
  143. * only needed to implement /proc/<pid>|self/exe so we define them here. */
  144. extern void set_mm_exe_file(struct mm_struct *mm, struct file *new_exe_file);
  145. extern struct file *get_mm_exe_file(struct mm_struct *mm);
  146. extern void dup_mm_exe_file(struct mm_struct *oldmm, struct mm_struct *newmm);
  147. #else
  148. #define proc_net_fops_create(net, name, mode, fops) ({ (void)(mode), NULL; })
  149. static inline void proc_net_remove(struct net *net, const char *name) {}
  150. static inline void proc_flush_task(struct task_struct *task)
  151. {
  152. }
  153. static inline struct proc_dir_entry *create_proc_entry(const char *name,
  154. mode_t mode, struct proc_dir_entry *parent) { return NULL; }
  155. static inline struct proc_dir_entry *proc_create(const char *name,
  156. mode_t mode, struct proc_dir_entry *parent,
  157. const struct file_operations *proc_fops)
  158. {
  159. return NULL;
  160. }
  161. static inline struct proc_dir_entry *proc_create_data(const char *name,
  162. mode_t mode, struct proc_dir_entry *parent,
  163. const struct file_operations *proc_fops, void *data)
  164. {
  165. return NULL;
  166. }
  167. #define remove_proc_entry(name, parent) do {} while (0)
  168. static inline struct proc_dir_entry *proc_symlink(const char *name,
  169. struct proc_dir_entry *parent,const char *dest) {return NULL;}
  170. static inline struct proc_dir_entry *proc_mkdir(const char *name,
  171. struct proc_dir_entry *parent) {return NULL;}
  172. static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
  173. mode_t mode, struct proc_dir_entry *base,
  174. read_proc_t *read_proc, void * data) { return NULL; }
  175. struct tty_driver;
  176. static inline void proc_tty_register_driver(struct tty_driver *driver) {};
  177. static inline void proc_tty_unregister_driver(struct tty_driver *driver) {};
  178. static inline int pid_ns_prepare_proc(struct pid_namespace *ns)
  179. {
  180. return 0;
  181. }
  182. static inline void pid_ns_release_proc(struct pid_namespace *ns)
  183. {
  184. }
  185. static inline void set_mm_exe_file(struct mm_struct *mm,
  186. struct file *new_exe_file)
  187. {}
  188. static inline struct file *get_mm_exe_file(struct mm_struct *mm)
  189. {
  190. return NULL;
  191. }
  192. static inline void dup_mm_exe_file(struct mm_struct *oldmm,
  193. struct mm_struct *newmm)
  194. {}
  195. #endif /* CONFIG_PROC_FS */
  196. #if !defined(CONFIG_PROC_KCORE)
  197. static inline void kclist_add(struct kcore_list *new, void *addr, size_t size)
  198. {
  199. }
  200. #else
  201. extern void kclist_add(struct kcore_list *, void *, size_t);
  202. #endif
  203. union proc_op {
  204. int (*proc_get_link)(struct inode *, struct path *);
  205. int (*proc_read)(struct task_struct *task, char *page);
  206. int (*proc_show)(struct seq_file *m,
  207. struct pid_namespace *ns, struct pid *pid,
  208. struct task_struct *task);
  209. };
  210. struct ctl_table_header;
  211. struct ctl_table;
  212. struct proc_inode {
  213. struct pid *pid;
  214. int fd;
  215. union proc_op op;
  216. struct proc_dir_entry *pde;
  217. struct ctl_table_header *sysctl;
  218. struct ctl_table *sysctl_entry;
  219. struct inode vfs_inode;
  220. };
  221. static inline struct proc_inode *PROC_I(const struct inode *inode)
  222. {
  223. return container_of(inode, struct proc_inode, vfs_inode);
  224. }
  225. static inline struct proc_dir_entry *PDE(const struct inode *inode)
  226. {
  227. return PROC_I(inode)->pde;
  228. }
  229. static inline struct net *PDE_NET(struct proc_dir_entry *pde)
  230. {
  231. return pde->parent->data;
  232. }
  233. struct proc_maps_private {
  234. struct pid *pid;
  235. struct task_struct *task;
  236. #ifdef CONFIG_MMU
  237. struct vm_area_struct *tail_vma;
  238. #endif
  239. };
  240. #endif /* _LINUX_PROC_FS_H */