proc_fs.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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. /*
  11. * The proc filesystem constants/structures
  12. */
  13. /*
  14. * Offset of the first process in the /proc root directory..
  15. */
  16. #define FIRST_PROCESS_ENTRY 256
  17. /* Worst case buffer size needed for holding an integer. */
  18. #define PROC_NUMBUF 13
  19. /*
  20. * We always define these enumerators
  21. */
  22. enum {
  23. PROC_ROOT_INO = 1,
  24. };
  25. /*
  26. * This is not completely implemented yet. The idea is to
  27. * create an in-memory tree (like the actual /proc filesystem
  28. * tree) of these proc_dir_entries, so that we can dynamically
  29. * add new files to /proc.
  30. *
  31. * The "next" pointer creates a linked list of one /proc directory,
  32. * while parent/subdir create the directory structure (every
  33. * /proc file has a parent, but "subdir" is NULL for all
  34. * non-directory entries).
  35. *
  36. * "owner" is used to protect module
  37. * from unloading while proc_dir_entry is in use
  38. */
  39. typedef int (read_proc_t)(char *page, char **start, off_t off,
  40. int count, int *eof, void *data);
  41. typedef int (write_proc_t)(struct file *file, const char __user *buffer,
  42. unsigned long count, void *data);
  43. struct proc_dir_entry {
  44. unsigned int low_ino;
  45. unsigned short namelen;
  46. const char *name;
  47. mode_t mode;
  48. nlink_t nlink;
  49. uid_t uid;
  50. gid_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 module *owner;
  63. struct proc_dir_entry *next, *parent, *subdir;
  64. void *data;
  65. read_proc_t *read_proc;
  66. write_proc_t *write_proc;
  67. atomic_t count; /* use count */
  68. int pde_users; /* number of callers into module in progress */
  69. spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
  70. struct completion *pde_unload_completion;
  71. };
  72. struct kcore_list {
  73. struct kcore_list *next;
  74. unsigned long addr;
  75. size_t size;
  76. };
  77. struct vmcore {
  78. struct list_head list;
  79. unsigned long long paddr;
  80. unsigned long long size;
  81. loff_t offset;
  82. };
  83. #ifdef CONFIG_PROC_FS
  84. extern struct proc_dir_entry *proc_root_kcore;
  85. extern spinlock_t proc_subdir_lock;
  86. extern void proc_root_init(void);
  87. extern void proc_misc_init(void);
  88. struct mm_struct;
  89. void proc_flush_task(struct task_struct *task);
  90. struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct nameidata *);
  91. int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir);
  92. unsigned long task_vsize(struct mm_struct *);
  93. int task_statm(struct mm_struct *, int *, int *, int *, int *);
  94. void task_mem(struct seq_file *, struct mm_struct *);
  95. void clear_refs_smap(struct mm_struct *mm);
  96. struct proc_dir_entry *de_get(struct proc_dir_entry *de);
  97. void de_put(struct proc_dir_entry *de);
  98. extern struct proc_dir_entry *create_proc_entry(const char *name, mode_t mode,
  99. struct proc_dir_entry *parent);
  100. struct proc_dir_entry *proc_create(const char *name, mode_t mode,
  101. struct proc_dir_entry *parent,
  102. const struct file_operations *proc_fops);
  103. extern void remove_proc_entry(const char *name, struct proc_dir_entry *parent);
  104. extern struct vfsmount *proc_mnt;
  105. struct pid_namespace;
  106. extern int proc_fill_super(struct super_block *);
  107. extern struct inode *proc_get_inode(struct super_block *, unsigned int, struct proc_dir_entry *);
  108. /*
  109. * These are generic /proc routines that use the internal
  110. * "struct proc_dir_entry" tree to traverse the filesystem.
  111. *
  112. * The /proc root directory has extended versions to take care
  113. * of the /proc/<pid> subdirectories.
  114. */
  115. extern int proc_readdir(struct file *, void *, filldir_t);
  116. extern struct dentry *proc_lookup(struct inode *, struct dentry *, struct nameidata *);
  117. extern const struct file_operations proc_kcore_operations;
  118. extern const struct file_operations proc_kmsg_operations;
  119. extern const struct file_operations ppc_htab_operations;
  120. extern int pid_ns_prepare_proc(struct pid_namespace *ns);
  121. extern void pid_ns_release_proc(struct pid_namespace *ns);
  122. /*
  123. * proc_tty.c
  124. */
  125. struct tty_driver;
  126. extern void proc_tty_init(void);
  127. extern void proc_tty_register_driver(struct tty_driver *driver);
  128. extern void proc_tty_unregister_driver(struct tty_driver *driver);
  129. /*
  130. * proc_devtree.c
  131. */
  132. #ifdef CONFIG_PROC_DEVICETREE
  133. struct device_node;
  134. struct property;
  135. extern void proc_device_tree_init(void);
  136. extern void proc_device_tree_add_node(struct device_node *, struct proc_dir_entry *);
  137. extern void proc_device_tree_add_prop(struct proc_dir_entry *pde, struct property *prop);
  138. extern void proc_device_tree_remove_prop(struct proc_dir_entry *pde,
  139. struct property *prop);
  140. extern void proc_device_tree_update_prop(struct proc_dir_entry *pde,
  141. struct property *newprop,
  142. struct property *oldprop);
  143. #endif /* CONFIG_PROC_DEVICETREE */
  144. extern struct proc_dir_entry *proc_symlink(const char *,
  145. struct proc_dir_entry *, const char *);
  146. extern struct proc_dir_entry *proc_mkdir(const char *,struct proc_dir_entry *);
  147. extern struct proc_dir_entry *proc_mkdir_mode(const char *name, mode_t mode,
  148. struct proc_dir_entry *parent);
  149. static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
  150. mode_t mode, struct proc_dir_entry *base,
  151. read_proc_t *read_proc, void * data)
  152. {
  153. struct proc_dir_entry *res=create_proc_entry(name,mode,base);
  154. if (res) {
  155. res->read_proc=read_proc;
  156. res->data=data;
  157. }
  158. return res;
  159. }
  160. extern struct proc_dir_entry *proc_net_fops_create(struct net *net,
  161. const char *name, mode_t mode, const struct file_operations *fops);
  162. extern void proc_net_remove(struct net *net, const char *name);
  163. extern struct proc_dir_entry *proc_net_mkdir(struct net *net, const char *name,
  164. struct proc_dir_entry *parent);
  165. /* While the {get|set|dup}_mm_exe_file functions are for mm_structs, they are
  166. * only needed to implement /proc/<pid>|self/exe so we define them here. */
  167. extern void set_mm_exe_file(struct mm_struct *mm, struct file *new_exe_file);
  168. extern struct file *get_mm_exe_file(struct mm_struct *mm);
  169. extern void dup_mm_exe_file(struct mm_struct *oldmm, struct mm_struct *newmm);
  170. #else
  171. #define proc_net_fops_create(net, name, mode, fops) ({ (void)(mode), NULL; })
  172. static inline void proc_net_remove(struct net *net, const char *name) {}
  173. static inline void proc_flush_task(struct task_struct *task)
  174. {
  175. }
  176. static inline struct proc_dir_entry *create_proc_entry(const char *name,
  177. mode_t mode, struct proc_dir_entry *parent) { return NULL; }
  178. static inline struct proc_dir_entry *proc_create(const char *name,
  179. mode_t mode, struct proc_dir_entry *parent,
  180. const struct file_operations *proc_fops)
  181. {
  182. return NULL;
  183. }
  184. #define remove_proc_entry(name, parent) do {} while (0)
  185. static inline struct proc_dir_entry *proc_symlink(const char *name,
  186. struct proc_dir_entry *parent,const char *dest) {return NULL;}
  187. static inline struct proc_dir_entry *proc_mkdir(const char *name,
  188. struct proc_dir_entry *parent) {return NULL;}
  189. static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
  190. mode_t mode, struct proc_dir_entry *base,
  191. read_proc_t *read_proc, void * data) { return NULL; }
  192. struct tty_driver;
  193. static inline void proc_tty_register_driver(struct tty_driver *driver) {};
  194. static inline void proc_tty_unregister_driver(struct tty_driver *driver) {};
  195. static inline int pid_ns_prepare_proc(struct pid_namespace *ns)
  196. {
  197. return 0;
  198. }
  199. static inline void pid_ns_release_proc(struct pid_namespace *ns)
  200. {
  201. }
  202. static inline void set_mm_exe_file(struct mm_struct *mm,
  203. struct file *new_exe_file)
  204. {}
  205. static inline struct file *get_mm_exe_file(struct mm_struct *mm)
  206. {
  207. return NULL;
  208. }
  209. static inline void dup_mm_exe_file(struct mm_struct *oldmm,
  210. struct mm_struct *newmm)
  211. {}
  212. #endif /* CONFIG_PROC_FS */
  213. #if !defined(CONFIG_PROC_KCORE)
  214. static inline void kclist_add(struct kcore_list *new, void *addr, size_t size)
  215. {
  216. }
  217. #else
  218. extern void kclist_add(struct kcore_list *, void *, size_t);
  219. #endif
  220. union proc_op {
  221. int (*proc_get_link)(struct inode *, struct path *);
  222. int (*proc_read)(struct task_struct *task, char *page);
  223. int (*proc_show)(struct seq_file *m,
  224. struct pid_namespace *ns, struct pid *pid,
  225. struct task_struct *task);
  226. };
  227. struct proc_inode {
  228. struct pid *pid;
  229. int fd;
  230. union proc_op op;
  231. struct proc_dir_entry *pde;
  232. struct inode vfs_inode;
  233. };
  234. static inline struct proc_inode *PROC_I(const struct inode *inode)
  235. {
  236. return container_of(inode, struct proc_inode, vfs_inode);
  237. }
  238. static inline struct proc_dir_entry *PDE(const struct inode *inode)
  239. {
  240. return PROC_I(inode)->pde;
  241. }
  242. static inline struct net *PDE_NET(struct proc_dir_entry *pde)
  243. {
  244. return pde->parent->data;
  245. }
  246. struct net *get_proc_net(const struct inode *inode);
  247. struct proc_maps_private {
  248. struct pid *pid;
  249. struct task_struct *task;
  250. #ifdef CONFIG_MMU
  251. struct vm_area_struct *tail_vma;
  252. #endif
  253. };
  254. #endif /* _LINUX_PROC_FS_H */