proc_fs.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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 int 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. enum kcore_type {
  71. KCORE_TEXT,
  72. KCORE_VMALLOC,
  73. KCORE_RAM,
  74. KCORE_VMEMMAP,
  75. KCORE_OTHER,
  76. };
  77. struct kcore_list {
  78. struct list_head list;
  79. unsigned long addr;
  80. size_t size;
  81. int type;
  82. };
  83. struct vmcore {
  84. struct list_head list;
  85. unsigned long long paddr;
  86. unsigned long long size;
  87. loff_t offset;
  88. };
  89. #ifdef CONFIG_PROC_FS
  90. extern void proc_root_init(void);
  91. void proc_flush_task(struct task_struct *task);
  92. extern struct proc_dir_entry *create_proc_entry(const char *name, mode_t mode,
  93. struct proc_dir_entry *parent);
  94. struct proc_dir_entry *proc_create_data(const char *name, mode_t mode,
  95. struct proc_dir_entry *parent,
  96. const struct file_operations *proc_fops,
  97. void *data);
  98. extern void remove_proc_entry(const char *name, struct proc_dir_entry *parent);
  99. struct pid_namespace;
  100. extern int pid_ns_prepare_proc(struct pid_namespace *ns);
  101. extern void pid_ns_release_proc(struct pid_namespace *ns);
  102. /*
  103. * proc_tty.c
  104. */
  105. struct tty_driver;
  106. extern void proc_tty_init(void);
  107. extern void proc_tty_register_driver(struct tty_driver *driver);
  108. extern void proc_tty_unregister_driver(struct tty_driver *driver);
  109. /*
  110. * proc_devtree.c
  111. */
  112. #ifdef CONFIG_PROC_DEVICETREE
  113. struct device_node;
  114. struct property;
  115. extern void proc_device_tree_init(void);
  116. extern void proc_device_tree_add_node(struct device_node *, struct proc_dir_entry *);
  117. extern void proc_device_tree_add_prop(struct proc_dir_entry *pde, struct property *prop);
  118. extern void proc_device_tree_remove_prop(struct proc_dir_entry *pde,
  119. struct property *prop);
  120. extern void proc_device_tree_update_prop(struct proc_dir_entry *pde,
  121. struct property *newprop,
  122. struct property *oldprop);
  123. #endif /* CONFIG_PROC_DEVICETREE */
  124. extern struct proc_dir_entry *proc_symlink(const char *,
  125. struct proc_dir_entry *, const char *);
  126. extern struct proc_dir_entry *proc_mkdir(const char *,struct proc_dir_entry *);
  127. extern struct proc_dir_entry *proc_mkdir_mode(const char *name, mode_t mode,
  128. struct proc_dir_entry *parent);
  129. static inline struct proc_dir_entry *proc_create(const char *name, mode_t mode,
  130. struct proc_dir_entry *parent, const struct file_operations *proc_fops)
  131. {
  132. return proc_create_data(name, mode, parent, proc_fops, NULL);
  133. }
  134. static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
  135. mode_t mode, struct proc_dir_entry *base,
  136. read_proc_t *read_proc, void * data)
  137. {
  138. struct proc_dir_entry *res=create_proc_entry(name,mode,base);
  139. if (res) {
  140. res->read_proc=read_proc;
  141. res->data=data;
  142. }
  143. return res;
  144. }
  145. extern struct proc_dir_entry *proc_net_fops_create(struct net *net,
  146. const char *name, mode_t mode, const struct file_operations *fops);
  147. extern void proc_net_remove(struct net *net, const char *name);
  148. extern struct proc_dir_entry *proc_net_mkdir(struct net *net, const char *name,
  149. struct proc_dir_entry *parent);
  150. /* While the {get|set|dup}_mm_exe_file functions are for mm_structs, they are
  151. * only needed to implement /proc/<pid>|self/exe so we define them here. */
  152. extern void set_mm_exe_file(struct mm_struct *mm, struct file *new_exe_file);
  153. extern struct file *get_mm_exe_file(struct mm_struct *mm);
  154. extern void dup_mm_exe_file(struct mm_struct *oldmm, struct mm_struct *newmm);
  155. extern struct file *proc_ns_fget(int fd);
  156. #else
  157. #define proc_net_fops_create(net, name, mode, fops) ({ (void)(mode), NULL; })
  158. static inline void proc_net_remove(struct net *net, const char *name) {}
  159. static inline void proc_flush_task(struct task_struct *task)
  160. {
  161. }
  162. static inline struct proc_dir_entry *create_proc_entry(const char *name,
  163. mode_t mode, struct proc_dir_entry *parent) { return NULL; }
  164. static inline struct proc_dir_entry *proc_create(const char *name,
  165. mode_t mode, struct proc_dir_entry *parent,
  166. const struct file_operations *proc_fops)
  167. {
  168. return NULL;
  169. }
  170. static inline struct proc_dir_entry *proc_create_data(const char *name,
  171. mode_t mode, struct proc_dir_entry *parent,
  172. const struct file_operations *proc_fops, void *data)
  173. {
  174. return NULL;
  175. }
  176. #define remove_proc_entry(name, parent) do {} while (0)
  177. static inline struct proc_dir_entry *proc_symlink(const char *name,
  178. struct proc_dir_entry *parent,const char *dest) {return NULL;}
  179. static inline struct proc_dir_entry *proc_mkdir(const char *name,
  180. struct proc_dir_entry *parent) {return NULL;}
  181. static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
  182. mode_t mode, struct proc_dir_entry *base,
  183. read_proc_t *read_proc, void * data) { return NULL; }
  184. struct tty_driver;
  185. static inline void proc_tty_register_driver(struct tty_driver *driver) {};
  186. static inline void proc_tty_unregister_driver(struct tty_driver *driver) {};
  187. static inline int pid_ns_prepare_proc(struct pid_namespace *ns)
  188. {
  189. return 0;
  190. }
  191. static inline void pid_ns_release_proc(struct pid_namespace *ns)
  192. {
  193. }
  194. static inline void set_mm_exe_file(struct mm_struct *mm,
  195. struct file *new_exe_file)
  196. {}
  197. static inline struct file *get_mm_exe_file(struct mm_struct *mm)
  198. {
  199. return NULL;
  200. }
  201. static inline void dup_mm_exe_file(struct mm_struct *oldmm,
  202. struct mm_struct *newmm)
  203. {}
  204. static inline struct file *proc_ns_fget(int fd)
  205. {
  206. return ERR_PTR(-EINVAL);
  207. }
  208. #endif /* CONFIG_PROC_FS */
  209. #if !defined(CONFIG_PROC_KCORE)
  210. static inline void
  211. kclist_add(struct kcore_list *new, void *addr, size_t size, int type)
  212. {
  213. }
  214. #else
  215. extern void kclist_add(struct kcore_list *, void *, size_t, int type);
  216. #endif
  217. struct nsproxy;
  218. struct proc_ns_operations {
  219. const char *name;
  220. int type;
  221. void *(*get)(struct task_struct *task);
  222. void (*put)(void *ns);
  223. int (*install)(struct nsproxy *nsproxy, void *ns);
  224. };
  225. extern const struct proc_ns_operations netns_operations;
  226. extern const struct proc_ns_operations utsns_operations;
  227. extern const struct proc_ns_operations ipcns_operations;
  228. union proc_op {
  229. int (*proc_get_link)(struct inode *, struct path *);
  230. int (*proc_read)(struct task_struct *task, char *page);
  231. int (*proc_show)(struct seq_file *m,
  232. struct pid_namespace *ns, struct pid *pid,
  233. struct task_struct *task);
  234. };
  235. struct ctl_table_header;
  236. struct ctl_table;
  237. struct proc_inode {
  238. struct pid *pid;
  239. int fd;
  240. union proc_op op;
  241. struct proc_dir_entry *pde;
  242. struct ctl_table_header *sysctl;
  243. struct ctl_table *sysctl_entry;
  244. void *ns;
  245. const struct proc_ns_operations *ns_ops;
  246. struct inode vfs_inode;
  247. };
  248. static inline struct proc_inode *PROC_I(const struct inode *inode)
  249. {
  250. return container_of(inode, struct proc_inode, vfs_inode);
  251. }
  252. static inline struct proc_dir_entry *PDE(const struct inode *inode)
  253. {
  254. return PROC_I(inode)->pde;
  255. }
  256. static inline struct net *PDE_NET(struct proc_dir_entry *pde)
  257. {
  258. return pde->parent->data;
  259. }
  260. struct proc_maps_private {
  261. struct pid *pid;
  262. struct task_struct *task;
  263. #ifdef CONFIG_MMU
  264. struct vm_area_struct *tail_vma;
  265. #endif
  266. };
  267. #endif /* _LINUX_PROC_FS_H */