proc_fs.h 9.4 KB

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