proc_fs.h 8.6 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 <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. typedef int (read_proc_t)(char *page, char **start, off_t off,
  42. int count, int *eof, void *data);
  43. typedef int (write_proc_t)(struct file *file, const char __user *buffer,
  44. unsigned long count, void *data);
  45. struct proc_dir_entry {
  46. unsigned int low_ino;
  47. umode_t mode;
  48. nlink_t nlink;
  49. kuid_t uid;
  50. kgid_t gid;
  51. loff_t size;
  52. const struct inode_operations *proc_iops;
  53. /*
  54. * NULL ->proc_fops means "PDE is going away RSN" or
  55. * "PDE is just created". In either case, e.g. ->read_proc won't be
  56. * called because it's too late or too early, respectively.
  57. *
  58. * If you're allocating ->proc_fops dynamically, save a pointer
  59. * somewhere.
  60. */
  61. const struct file_operations *proc_fops;
  62. struct proc_dir_entry *next, *parent, *subdir;
  63. void *data;
  64. read_proc_t *read_proc;
  65. write_proc_t *write_proc;
  66. atomic_t count; /* use count */
  67. int pde_users; /* number of callers into module in progress */
  68. struct completion *pde_unload_completion;
  69. struct list_head pde_openers; /* who did ->open, but not ->release */
  70. spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
  71. u8 namelen;
  72. char name[];
  73. };
  74. enum kcore_type {
  75. KCORE_TEXT,
  76. KCORE_VMALLOC,
  77. KCORE_RAM,
  78. KCORE_VMEMMAP,
  79. KCORE_OTHER,
  80. };
  81. struct kcore_list {
  82. struct list_head list;
  83. unsigned long addr;
  84. size_t size;
  85. int type;
  86. };
  87. struct vmcore {
  88. struct list_head list;
  89. unsigned long long paddr;
  90. unsigned long long size;
  91. loff_t offset;
  92. };
  93. #ifdef CONFIG_PROC_FS
  94. extern void proc_root_init(void);
  95. void proc_flush_task(struct task_struct *task);
  96. extern struct proc_dir_entry *create_proc_entry(const char *name, umode_t mode,
  97. struct proc_dir_entry *parent);
  98. struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
  99. struct proc_dir_entry *parent,
  100. const struct file_operations *proc_fops,
  101. void *data);
  102. extern void remove_proc_entry(const char *name, struct proc_dir_entry *parent);
  103. extern int remove_proc_subtree(const char *name, struct proc_dir_entry *parent);
  104. struct pid_namespace;
  105. extern int pid_ns_prepare_proc(struct pid_namespace *ns);
  106. extern void pid_ns_release_proc(struct pid_namespace *ns);
  107. /*
  108. * proc_tty.c
  109. */
  110. struct tty_driver;
  111. #ifdef CONFIG_TTY
  112. extern void proc_tty_init(void);
  113. #else
  114. static inline void proc_tty_init(void)
  115. { }
  116. #endif
  117. extern void proc_tty_register_driver(struct tty_driver *driver);
  118. extern void proc_tty_unregister_driver(struct tty_driver *driver);
  119. /*
  120. * proc_devtree.c
  121. */
  122. #ifdef CONFIG_PROC_DEVICETREE
  123. struct device_node;
  124. struct property;
  125. extern void proc_device_tree_init(void);
  126. extern void proc_device_tree_add_node(struct device_node *, struct proc_dir_entry *);
  127. extern void proc_device_tree_add_prop(struct proc_dir_entry *pde, struct property *prop);
  128. extern void proc_device_tree_remove_prop(struct proc_dir_entry *pde,
  129. struct property *prop);
  130. extern void proc_device_tree_update_prop(struct proc_dir_entry *pde,
  131. struct property *newprop,
  132. struct property *oldprop);
  133. #endif /* CONFIG_PROC_DEVICETREE */
  134. extern struct proc_dir_entry *proc_symlink(const char *,
  135. struct proc_dir_entry *, const char *);
  136. extern struct proc_dir_entry *proc_mkdir(const char *,struct proc_dir_entry *);
  137. extern struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
  138. struct proc_dir_entry *parent);
  139. static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
  140. struct proc_dir_entry *parent, const struct file_operations *proc_fops)
  141. {
  142. return proc_create_data(name, mode, parent, proc_fops, NULL);
  143. }
  144. static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
  145. umode_t mode, struct proc_dir_entry *base,
  146. read_proc_t *read_proc, void * data)
  147. {
  148. struct proc_dir_entry *res=create_proc_entry(name,mode,base);
  149. if (res) {
  150. res->read_proc=read_proc;
  151. res->data=data;
  152. }
  153. return res;
  154. }
  155. extern struct proc_dir_entry *proc_net_mkdir(struct net *net, const char *name,
  156. struct proc_dir_entry *parent);
  157. extern struct file *proc_ns_fget(int fd);
  158. extern bool proc_ns_inode(struct inode *inode);
  159. extern int proc_alloc_inum(unsigned int *pino);
  160. extern void proc_free_inum(unsigned int inum);
  161. #else
  162. static inline void proc_flush_task(struct task_struct *task)
  163. {
  164. }
  165. static inline struct proc_dir_entry *create_proc_entry(const char *name,
  166. umode_t mode, struct proc_dir_entry *parent) { return NULL; }
  167. #define proc_create(name, mode, parent, fops) ({ (void)(mode), NULL; })
  168. static inline struct proc_dir_entry *proc_create_data(const char *name,
  169. umode_t mode, struct proc_dir_entry *parent,
  170. const struct file_operations *proc_fops, void *data)
  171. {
  172. return NULL;
  173. }
  174. #define remove_proc_entry(name, parent) do {} while (0)
  175. #define remove_proc_subtree(name, parent) do {} while (0)
  176. static inline struct proc_dir_entry *proc_symlink(const char *name,
  177. struct proc_dir_entry *parent,const char *dest) {return NULL;}
  178. static inline struct proc_dir_entry *proc_mkdir(const char *name,
  179. struct proc_dir_entry *parent) {return NULL;}
  180. static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
  181. umode_t mode, struct proc_dir_entry *parent) { return NULL; }
  182. static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
  183. umode_t mode, struct proc_dir_entry *base,
  184. read_proc_t *read_proc, void * data) { return NULL; }
  185. struct tty_driver;
  186. static inline void proc_tty_register_driver(struct tty_driver *driver) {};
  187. static inline void proc_tty_unregister_driver(struct tty_driver *driver) {};
  188. static inline int pid_ns_prepare_proc(struct pid_namespace *ns)
  189. {
  190. return 0;
  191. }
  192. static inline void pid_ns_release_proc(struct pid_namespace *ns)
  193. {
  194. }
  195. static inline struct file *proc_ns_fget(int fd)
  196. {
  197. return ERR_PTR(-EINVAL);
  198. }
  199. static inline bool proc_ns_inode(struct inode *inode)
  200. {
  201. return false;
  202. }
  203. static inline int proc_alloc_inum(unsigned int *inum)
  204. {
  205. *inum = 1;
  206. return 0;
  207. }
  208. static inline void proc_free_inum(unsigned int inum)
  209. {
  210. }
  211. #endif /* CONFIG_PROC_FS */
  212. #if !defined(CONFIG_PROC_KCORE)
  213. static inline void
  214. kclist_add(struct kcore_list *new, void *addr, size_t size, int type)
  215. {
  216. }
  217. #else
  218. extern void kclist_add(struct kcore_list *, void *, size_t, int type);
  219. #endif
  220. struct nsproxy;
  221. struct proc_ns_operations {
  222. const char *name;
  223. int type;
  224. void *(*get)(struct task_struct *task);
  225. void (*put)(void *ns);
  226. int (*install)(struct nsproxy *nsproxy, void *ns);
  227. unsigned int (*inum)(void *ns);
  228. };
  229. extern const struct proc_ns_operations netns_operations;
  230. extern const struct proc_ns_operations utsns_operations;
  231. extern const struct proc_ns_operations ipcns_operations;
  232. extern const struct proc_ns_operations pidns_operations;
  233. extern const struct proc_ns_operations userns_operations;
  234. extern const struct proc_ns_operations mntns_operations;
  235. union proc_op {
  236. int (*proc_get_link)(struct dentry *, struct path *);
  237. int (*proc_read)(struct task_struct *task, char *page);
  238. int (*proc_show)(struct seq_file *m,
  239. struct pid_namespace *ns, struct pid *pid,
  240. struct task_struct *task);
  241. };
  242. struct ctl_table_header;
  243. struct ctl_table;
  244. struct proc_inode {
  245. struct pid *pid;
  246. int fd;
  247. union proc_op op;
  248. struct proc_dir_entry *pde;
  249. struct ctl_table_header *sysctl;
  250. struct ctl_table *sysctl_entry;
  251. void *ns;
  252. const struct proc_ns_operations *ns_ops;
  253. struct inode vfs_inode;
  254. };
  255. static inline struct proc_inode *PROC_I(const struct inode *inode)
  256. {
  257. return container_of(inode, struct proc_inode, vfs_inode);
  258. }
  259. static inline struct proc_dir_entry *PDE(const struct inode *inode)
  260. {
  261. return PROC_I(inode)->pde;
  262. }
  263. static inline struct net *PDE_NET(struct proc_dir_entry *pde)
  264. {
  265. return pde->parent->data;
  266. }
  267. #include <linux/signal.h>
  268. void render_sigset_t(struct seq_file *m, const char *header, sigset_t *set);
  269. #endif /* _LINUX_PROC_FS_H */