proc_fs.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  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. * "get_info" is called at "read", while "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. typedef int (get_info_t)(char *, char **, off_t, int);
  44. typedef struct proc_dir_entry *(shadow_proc_t)(struct task_struct *task,
  45. struct proc_dir_entry *pde);
  46. struct proc_dir_entry {
  47. unsigned int low_ino;
  48. unsigned short namelen;
  49. const char *name;
  50. mode_t mode;
  51. nlink_t nlink;
  52. uid_t uid;
  53. gid_t gid;
  54. loff_t size;
  55. const struct inode_operations *proc_iops;
  56. /*
  57. * NULL ->proc_fops means "PDE is going away RSN" or
  58. * "PDE is just created". In either case, e.g. ->read_proc won't be
  59. * called because it's too late or too early, respectively.
  60. *
  61. * If you're allocating ->proc_fops dynamically, save a pointer
  62. * somewhere.
  63. */
  64. const struct file_operations *proc_fops;
  65. get_info_t *get_info;
  66. struct module *owner;
  67. struct proc_dir_entry *next, *parent, *subdir;
  68. void *data;
  69. read_proc_t *read_proc;
  70. write_proc_t *write_proc;
  71. atomic_t count; /* use count */
  72. int pde_users; /* number of callers into module in progress */
  73. spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
  74. struct completion *pde_unload_completion;
  75. shadow_proc_t *shadow_proc;
  76. };
  77. struct kcore_list {
  78. struct kcore_list *next;
  79. unsigned long addr;
  80. size_t size;
  81. };
  82. struct vmcore {
  83. struct list_head list;
  84. unsigned long long paddr;
  85. unsigned long long size;
  86. loff_t offset;
  87. };
  88. #ifdef CONFIG_PROC_FS
  89. extern struct proc_dir_entry proc_root;
  90. extern struct proc_dir_entry *proc_root_fs;
  91. extern struct proc_dir_entry *proc_bus;
  92. extern struct proc_dir_entry *proc_root_driver;
  93. extern struct proc_dir_entry *proc_root_kcore;
  94. extern spinlock_t proc_subdir_lock;
  95. extern void proc_root_init(void);
  96. extern void proc_misc_init(void);
  97. struct mm_struct;
  98. void proc_flush_task(struct task_struct *task);
  99. struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct nameidata *);
  100. int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir);
  101. unsigned long task_vsize(struct mm_struct *);
  102. int task_statm(struct mm_struct *, int *, int *, int *, int *);
  103. void task_mem(struct seq_file *, struct mm_struct *);
  104. void clear_refs_smap(struct mm_struct *mm);
  105. struct proc_dir_entry *de_get(struct proc_dir_entry *de);
  106. void de_put(struct proc_dir_entry *de);
  107. extern struct proc_dir_entry *create_proc_entry(const char *name, mode_t mode,
  108. struct proc_dir_entry *parent);
  109. struct proc_dir_entry *proc_create(const char *name, mode_t mode,
  110. struct proc_dir_entry *parent,
  111. const struct file_operations *proc_fops);
  112. extern void remove_proc_entry(const char *name, struct proc_dir_entry *parent);
  113. extern struct vfsmount *proc_mnt;
  114. struct pid_namespace;
  115. extern int proc_fill_super(struct super_block *);
  116. extern struct inode *proc_get_inode(struct super_block *, unsigned int, struct proc_dir_entry *);
  117. /*
  118. * These are generic /proc routines that use the internal
  119. * "struct proc_dir_entry" tree to traverse the filesystem.
  120. *
  121. * The /proc root directory has extended versions to take care
  122. * of the /proc/<pid> subdirectories.
  123. */
  124. extern int proc_readdir(struct file *, void *, filldir_t);
  125. extern struct dentry *proc_lookup(struct inode *, struct dentry *, struct nameidata *);
  126. extern const struct file_operations proc_kcore_operations;
  127. extern const struct file_operations proc_kmsg_operations;
  128. extern const struct file_operations ppc_htab_operations;
  129. extern int pid_ns_prepare_proc(struct pid_namespace *ns);
  130. extern void pid_ns_release_proc(struct pid_namespace *ns);
  131. /*
  132. * proc_tty.c
  133. */
  134. struct tty_driver;
  135. extern void proc_tty_init(void);
  136. extern void proc_tty_register_driver(struct tty_driver *driver);
  137. extern void proc_tty_unregister_driver(struct tty_driver *driver);
  138. /*
  139. * proc_devtree.c
  140. */
  141. #ifdef CONFIG_PROC_DEVICETREE
  142. struct device_node;
  143. struct property;
  144. extern void proc_device_tree_init(void);
  145. extern void proc_device_tree_add_node(struct device_node *, struct proc_dir_entry *);
  146. extern void proc_device_tree_add_prop(struct proc_dir_entry *pde, struct property *prop);
  147. extern void proc_device_tree_remove_prop(struct proc_dir_entry *pde,
  148. struct property *prop);
  149. extern void proc_device_tree_update_prop(struct proc_dir_entry *pde,
  150. struct property *newprop,
  151. struct property *oldprop);
  152. #endif /* CONFIG_PROC_DEVICETREE */
  153. extern struct proc_dir_entry *proc_symlink(const char *,
  154. struct proc_dir_entry *, const char *);
  155. extern struct proc_dir_entry *proc_mkdir(const char *,struct proc_dir_entry *);
  156. extern struct proc_dir_entry *proc_mkdir_mode(const char *name, mode_t mode,
  157. struct proc_dir_entry *parent);
  158. static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
  159. mode_t mode, struct proc_dir_entry *base,
  160. read_proc_t *read_proc, void * data)
  161. {
  162. struct proc_dir_entry *res=create_proc_entry(name,mode,base);
  163. if (res) {
  164. res->read_proc=read_proc;
  165. res->data=data;
  166. }
  167. return res;
  168. }
  169. static inline struct proc_dir_entry *create_proc_info_entry(const char *name,
  170. mode_t mode, struct proc_dir_entry *base, get_info_t *get_info)
  171. {
  172. struct proc_dir_entry *res=create_proc_entry(name,mode,base);
  173. if (res) res->get_info=get_info;
  174. return res;
  175. }
  176. extern struct proc_dir_entry *proc_net_fops_create(struct net *net,
  177. const char *name, mode_t mode, const struct file_operations *fops);
  178. extern void proc_net_remove(struct net *net, const char *name);
  179. extern struct proc_dir_entry *proc_net_mkdir(struct net *net, const char *name,
  180. struct proc_dir_entry *parent);
  181. #else
  182. #define proc_root_driver NULL
  183. #define proc_bus NULL
  184. #define proc_net_fops_create(net, name, mode, fops) ({ (void)(mode), NULL; })
  185. static inline void proc_net_remove(struct net *net, const char *name) {}
  186. static inline void proc_flush_task(struct task_struct *task)
  187. {
  188. }
  189. static inline struct proc_dir_entry *create_proc_entry(const char *name,
  190. mode_t mode, struct proc_dir_entry *parent) { return NULL; }
  191. static inline struct proc_dir_entry *proc_create(const char *name,
  192. mode_t mode, struct proc_dir_entry *parent,
  193. const struct file_operations *proc_fops)
  194. {
  195. return NULL;
  196. }
  197. #define remove_proc_entry(name, parent) do {} while (0)
  198. static inline struct proc_dir_entry *proc_symlink(const char *name,
  199. struct proc_dir_entry *parent,const char *dest) {return NULL;}
  200. static inline struct proc_dir_entry *proc_mkdir(const char *name,
  201. struct proc_dir_entry *parent) {return NULL;}
  202. static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
  203. mode_t mode, struct proc_dir_entry *base,
  204. read_proc_t *read_proc, void * data) { return NULL; }
  205. static inline struct proc_dir_entry *create_proc_info_entry(const char *name,
  206. mode_t mode, struct proc_dir_entry *base, get_info_t *get_info)
  207. { return NULL; }
  208. struct tty_driver;
  209. static inline void proc_tty_register_driver(struct tty_driver *driver) {};
  210. static inline void proc_tty_unregister_driver(struct tty_driver *driver) {};
  211. extern struct proc_dir_entry proc_root;
  212. static inline int pid_ns_prepare_proc(struct pid_namespace *ns)
  213. {
  214. return 0;
  215. }
  216. static inline void pid_ns_release_proc(struct pid_namespace *ns)
  217. {
  218. }
  219. #endif /* CONFIG_PROC_FS */
  220. #if !defined(CONFIG_PROC_KCORE)
  221. static inline void kclist_add(struct kcore_list *new, void *addr, size_t size)
  222. {
  223. }
  224. #else
  225. extern void kclist_add(struct kcore_list *, void *, size_t);
  226. #endif
  227. union proc_op {
  228. int (*proc_get_link)(struct inode *, struct path *);
  229. int (*proc_read)(struct task_struct *task, char *page);
  230. int (*proc_show)(struct seq_file *m,
  231. struct pid_namespace *ns, struct pid *pid,
  232. struct task_struct *task);
  233. };
  234. struct proc_inode {
  235. struct pid *pid;
  236. int fd;
  237. union proc_op op;
  238. struct proc_dir_entry *pde;
  239. struct inode vfs_inode;
  240. };
  241. static inline struct proc_inode *PROC_I(const struct inode *inode)
  242. {
  243. return container_of(inode, struct proc_inode, vfs_inode);
  244. }
  245. static inline struct proc_dir_entry *PDE(const struct inode *inode)
  246. {
  247. return PROC_I(inode)->pde;
  248. }
  249. static inline struct net *PDE_NET(struct proc_dir_entry *pde)
  250. {
  251. return pde->parent->data;
  252. }
  253. struct net *get_proc_net(const struct inode *inode);
  254. struct proc_maps_private {
  255. struct pid *pid;
  256. struct task_struct *task;
  257. #ifdef CONFIG_MMU
  258. struct vm_area_struct *tail_vma;
  259. #endif
  260. };
  261. #endif /* _LINUX_PROC_FS_H */