proc_fs.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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. 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. PROC_IPC_INIT_INO = 0xEFFFFFFFU,
  26. PROC_UTS_INIT_INO = 0xEFFFFFFEU,
  27. PROC_USER_INIT_INO = 0xEFFFFFFDU,
  28. PROC_PID_INIT_INO = 0xEFFFFFFCU,
  29. };
  30. /*
  31. * This is not completely implemented yet. The idea is to
  32. * create an in-memory tree (like the actual /proc filesystem
  33. * tree) of these proc_dir_entries, so that we can dynamically
  34. * add new files to /proc.
  35. *
  36. * The "next" pointer creates a linked list of one /proc directory,
  37. * while parent/subdir create the directory structure (every
  38. * /proc file has a parent, but "subdir" is NULL for all
  39. * non-directory entries).
  40. */
  41. struct proc_dir_entry {
  42. unsigned int low_ino;
  43. umode_t mode;
  44. nlink_t nlink;
  45. kuid_t uid;
  46. kgid_t gid;
  47. loff_t size;
  48. const struct inode_operations *proc_iops;
  49. const struct file_operations *proc_fops;
  50. struct proc_dir_entry *next, *parent, *subdir;
  51. void *data;
  52. atomic_t count; /* use count */
  53. atomic_t in_use; /* number of callers into module in progress; */
  54. /* negative -> it's going away RSN */
  55. struct completion *pde_unload_completion;
  56. struct list_head pde_openers; /* who did ->open, but not ->release */
  57. spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
  58. u8 namelen;
  59. char name[];
  60. };
  61. enum kcore_type {
  62. KCORE_TEXT,
  63. KCORE_VMALLOC,
  64. KCORE_RAM,
  65. KCORE_VMEMMAP,
  66. KCORE_OTHER,
  67. };
  68. struct kcore_list {
  69. struct list_head list;
  70. unsigned long addr;
  71. size_t size;
  72. int type;
  73. };
  74. struct vmcore {
  75. struct list_head list;
  76. unsigned long long paddr;
  77. unsigned long long size;
  78. loff_t offset;
  79. };
  80. #ifdef CONFIG_PROC_FS
  81. extern void proc_root_init(void);
  82. void proc_flush_task(struct task_struct *task);
  83. struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
  84. struct proc_dir_entry *parent,
  85. const struct file_operations *proc_fops,
  86. void *data);
  87. extern void remove_proc_entry(const char *name, struct proc_dir_entry *parent);
  88. extern int remove_proc_subtree(const char *name, struct proc_dir_entry *parent);
  89. struct pid_namespace;
  90. extern int pid_ns_prepare_proc(struct pid_namespace *ns);
  91. extern void pid_ns_release_proc(struct pid_namespace *ns);
  92. /*
  93. * proc_tty.c
  94. */
  95. struct tty_driver;
  96. #ifdef CONFIG_TTY
  97. extern void proc_tty_init(void);
  98. #else
  99. static inline void proc_tty_init(void)
  100. { }
  101. #endif
  102. extern void proc_tty_register_driver(struct tty_driver *driver);
  103. extern void proc_tty_unregister_driver(struct tty_driver *driver);
  104. /*
  105. * proc_devtree.c
  106. */
  107. #ifdef CONFIG_PROC_DEVICETREE
  108. struct device_node;
  109. struct property;
  110. extern void proc_device_tree_init(void);
  111. extern void proc_device_tree_add_node(struct device_node *, struct proc_dir_entry *);
  112. extern void proc_device_tree_add_prop(struct proc_dir_entry *pde, struct property *prop);
  113. extern void proc_device_tree_remove_prop(struct proc_dir_entry *pde,
  114. struct property *prop);
  115. extern void proc_device_tree_update_prop(struct proc_dir_entry *pde,
  116. struct property *newprop,
  117. struct property *oldprop);
  118. #endif /* CONFIG_PROC_DEVICETREE */
  119. extern struct proc_dir_entry *proc_symlink(const char *,
  120. struct proc_dir_entry *, const char *);
  121. extern struct proc_dir_entry *proc_mkdir(const char *,struct proc_dir_entry *);
  122. extern struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
  123. struct proc_dir_entry *parent);
  124. static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
  125. struct proc_dir_entry *parent, const struct file_operations *proc_fops)
  126. {
  127. return proc_create_data(name, mode, parent, proc_fops, NULL);
  128. }
  129. extern struct proc_dir_entry *proc_net_mkdir(struct net *net, const char *name,
  130. struct proc_dir_entry *parent);
  131. extern struct file *proc_ns_fget(int fd);
  132. extern bool proc_ns_inode(struct inode *inode);
  133. extern int proc_alloc_inum(unsigned int *pino);
  134. extern void proc_free_inum(unsigned int inum);
  135. #else
  136. static inline void proc_flush_task(struct task_struct *task)
  137. {
  138. }
  139. #define proc_create(name, mode, parent, fops) ({ (void)(mode), NULL; })
  140. static inline struct proc_dir_entry *proc_create_data(const char *name,
  141. umode_t mode, struct proc_dir_entry *parent,
  142. const struct file_operations *proc_fops, void *data)
  143. {
  144. return NULL;
  145. }
  146. #define remove_proc_entry(name, parent) do {} while (0)
  147. #define remove_proc_subtree(name, parent) do {} while (0)
  148. static inline struct proc_dir_entry *proc_symlink(const char *name,
  149. struct proc_dir_entry *parent,const char *dest) {return NULL;}
  150. static inline struct proc_dir_entry *proc_mkdir(const char *name,
  151. struct proc_dir_entry *parent) {return NULL;}
  152. static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
  153. umode_t mode, struct proc_dir_entry *parent) { return NULL; }
  154. struct tty_driver;
  155. static inline void proc_tty_register_driver(struct tty_driver *driver) {};
  156. static inline void proc_tty_unregister_driver(struct tty_driver *driver) {};
  157. static inline int pid_ns_prepare_proc(struct pid_namespace *ns)
  158. {
  159. return 0;
  160. }
  161. static inline void pid_ns_release_proc(struct pid_namespace *ns)
  162. {
  163. }
  164. static inline struct file *proc_ns_fget(int fd)
  165. {
  166. return ERR_PTR(-EINVAL);
  167. }
  168. static inline bool proc_ns_inode(struct inode *inode)
  169. {
  170. return false;
  171. }
  172. static inline int proc_alloc_inum(unsigned int *inum)
  173. {
  174. *inum = 1;
  175. return 0;
  176. }
  177. static inline void proc_free_inum(unsigned int inum)
  178. {
  179. }
  180. #endif /* CONFIG_PROC_FS */
  181. #if !defined(CONFIG_PROC_KCORE)
  182. static inline void
  183. kclist_add(struct kcore_list *new, void *addr, size_t size, int type)
  184. {
  185. }
  186. #else
  187. extern void kclist_add(struct kcore_list *, void *, size_t, int type);
  188. #endif
  189. struct nsproxy;
  190. struct proc_ns_operations {
  191. const char *name;
  192. int type;
  193. void *(*get)(struct task_struct *task);
  194. void (*put)(void *ns);
  195. int (*install)(struct nsproxy *nsproxy, void *ns);
  196. unsigned int (*inum)(void *ns);
  197. };
  198. extern const struct proc_ns_operations netns_operations;
  199. extern const struct proc_ns_operations utsns_operations;
  200. extern const struct proc_ns_operations ipcns_operations;
  201. extern const struct proc_ns_operations pidns_operations;
  202. extern const struct proc_ns_operations userns_operations;
  203. extern const struct proc_ns_operations mntns_operations;
  204. union proc_op {
  205. int (*proc_get_link)(struct dentry *, struct path *);
  206. int (*proc_read)(struct task_struct *task, char *page);
  207. int (*proc_show)(struct seq_file *m,
  208. struct pid_namespace *ns, struct pid *pid,
  209. struct task_struct *task);
  210. };
  211. struct ctl_table_header;
  212. struct ctl_table;
  213. struct proc_inode {
  214. struct pid *pid;
  215. int fd;
  216. union proc_op op;
  217. struct proc_dir_entry *pde;
  218. struct ctl_table_header *sysctl;
  219. struct ctl_table *sysctl_entry;
  220. void *ns;
  221. const struct proc_ns_operations *ns_ops;
  222. struct inode vfs_inode;
  223. };
  224. static inline struct proc_inode *PROC_I(const struct inode *inode)
  225. {
  226. return container_of(inode, struct proc_inode, vfs_inode);
  227. }
  228. static inline struct proc_dir_entry *PDE(const struct inode *inode)
  229. {
  230. return PROC_I(inode)->pde;
  231. }
  232. static inline void *PDE_DATA(const struct inode *inode)
  233. {
  234. return PROC_I(inode)->pde->data;
  235. }
  236. static inline struct net *PDE_NET(struct proc_dir_entry *pde)
  237. {
  238. return pde->parent->data;
  239. }
  240. #include <linux/signal.h>
  241. void render_sigset_t(struct seq_file *m, const char *header, sigset_t *set);
  242. #endif /* _LINUX_PROC_FS_H */