proc_fs.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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. /*
  18. * We always define these enumerators
  19. */
  20. enum {
  21. PROC_ROOT_INO = 1,
  22. };
  23. /*
  24. * This is not completely implemented yet. The idea is to
  25. * create an in-memory tree (like the actual /proc filesystem
  26. * tree) of these proc_dir_entries, so that we can dynamically
  27. * add new files to /proc.
  28. *
  29. * The "next" pointer creates a linked list of one /proc directory,
  30. * while parent/subdir create the directory structure (every
  31. * /proc file has a parent, but "subdir" is NULL for all
  32. * non-directory entries).
  33. *
  34. * "get_info" is called at "read", while "owner" is used to protect module
  35. * from unloading while proc_dir_entry is in use
  36. */
  37. typedef int (read_proc_t)(char *page, char **start, off_t off,
  38. int count, int *eof, void *data);
  39. typedef int (write_proc_t)(struct file *file, const char __user *buffer,
  40. unsigned long count, void *data);
  41. typedef int (get_info_t)(char *, char **, off_t, int);
  42. struct proc_dir_entry {
  43. unsigned int low_ino;
  44. unsigned short namelen;
  45. const char *name;
  46. mode_t mode;
  47. nlink_t nlink;
  48. uid_t uid;
  49. gid_t gid;
  50. loff_t size;
  51. const struct inode_operations *proc_iops;
  52. /*
  53. * NULL ->proc_fops means "PDE is going away RSN" or
  54. * "PDE is just created". In either case, e.g. ->read_proc won't be
  55. * called because it's too late or too early, respectively.
  56. *
  57. * If you're allocating ->proc_fops dynamically, save a pointer
  58. * somewhere.
  59. */
  60. const struct file_operations *proc_fops;
  61. get_info_t *get_info;
  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 deleted; /* delete flag */
  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. };
  73. struct kcore_list {
  74. struct kcore_list *next;
  75. unsigned long addr;
  76. size_t size;
  77. };
  78. struct vmcore {
  79. struct list_head list;
  80. unsigned long long paddr;
  81. unsigned long long size;
  82. loff_t offset;
  83. };
  84. #ifdef CONFIG_PROC_FS
  85. extern struct proc_dir_entry proc_root;
  86. extern struct proc_dir_entry *proc_root_fs;
  87. extern struct proc_dir_entry *proc_bus;
  88. extern struct proc_dir_entry *proc_root_driver;
  89. extern struct proc_dir_entry *proc_root_kcore;
  90. extern spinlock_t proc_subdir_lock;
  91. extern void proc_root_init(void);
  92. extern void proc_misc_init(void);
  93. struct mm_struct;
  94. void proc_flush_task(struct task_struct *task);
  95. struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct nameidata *);
  96. int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir);
  97. unsigned long task_vsize(struct mm_struct *);
  98. int task_statm(struct mm_struct *, int *, int *, int *, int *);
  99. char *task_mem(struct mm_struct *, char *);
  100. void clear_refs_smap(struct mm_struct *mm);
  101. struct proc_dir_entry *de_get(struct proc_dir_entry *de);
  102. void de_put(struct proc_dir_entry *de);
  103. extern struct proc_dir_entry *create_proc_entry(const char *name, mode_t mode,
  104. struct proc_dir_entry *parent);
  105. extern void remove_proc_entry(const char *name, struct proc_dir_entry *parent);
  106. extern struct vfsmount *proc_mnt;
  107. extern int proc_fill_super(struct super_block *,void *,int);
  108. extern struct inode *proc_get_inode(struct super_block *, unsigned int, struct proc_dir_entry *);
  109. /*
  110. * These are generic /proc routines that use the internal
  111. * "struct proc_dir_entry" tree to traverse the filesystem.
  112. *
  113. * The /proc root directory has extended versions to take care
  114. * of the /proc/<pid> subdirectories.
  115. */
  116. extern int proc_readdir(struct file *, void *, filldir_t);
  117. extern struct dentry *proc_lookup(struct inode *, struct dentry *, struct nameidata *);
  118. extern const struct file_operations proc_kcore_operations;
  119. extern const struct file_operations proc_kmsg_operations;
  120. extern const struct file_operations ppc_htab_operations;
  121. /*
  122. * proc_tty.c
  123. */
  124. struct tty_driver;
  125. extern void proc_tty_init(void);
  126. extern void proc_tty_register_driver(struct tty_driver *driver);
  127. extern void proc_tty_unregister_driver(struct tty_driver *driver);
  128. /*
  129. * proc_devtree.c
  130. */
  131. #ifdef CONFIG_PROC_DEVICETREE
  132. struct device_node;
  133. struct property;
  134. extern void proc_device_tree_init(void);
  135. extern void proc_device_tree_add_node(struct device_node *, struct proc_dir_entry *);
  136. extern void proc_device_tree_add_prop(struct proc_dir_entry *pde, struct property *prop);
  137. extern void proc_device_tree_remove_prop(struct proc_dir_entry *pde,
  138. struct property *prop);
  139. extern void proc_device_tree_update_prop(struct proc_dir_entry *pde,
  140. struct property *newprop,
  141. struct property *oldprop);
  142. #endif /* CONFIG_PROC_DEVICETREE */
  143. extern struct proc_dir_entry *proc_symlink(const char *,
  144. struct proc_dir_entry *, const char *);
  145. extern struct proc_dir_entry *proc_mkdir(const char *,struct proc_dir_entry *);
  146. extern struct proc_dir_entry *proc_mkdir_mode(const char *name, mode_t mode,
  147. struct proc_dir_entry *parent);
  148. static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
  149. mode_t mode, struct proc_dir_entry *base,
  150. read_proc_t *read_proc, void * data)
  151. {
  152. struct proc_dir_entry *res=create_proc_entry(name,mode,base);
  153. if (res) {
  154. res->read_proc=read_proc;
  155. res->data=data;
  156. }
  157. return res;
  158. }
  159. static inline struct proc_dir_entry *create_proc_info_entry(const char *name,
  160. mode_t mode, struct proc_dir_entry *base, get_info_t *get_info)
  161. {
  162. struct proc_dir_entry *res=create_proc_entry(name,mode,base);
  163. if (res) res->get_info=get_info;
  164. return res;
  165. }
  166. extern struct proc_dir_entry *proc_net_create(struct net *net,
  167. const char *name, mode_t mode, get_info_t *get_info);
  168. extern struct proc_dir_entry *proc_net_fops_create(struct net *net,
  169. const char *name, mode_t mode, const struct file_operations *fops);
  170. extern void proc_net_remove(struct net *net, const char *name);
  171. #else
  172. #define proc_root_driver NULL
  173. #define proc_bus NULL
  174. #define proc_net_fops_create(net, name, mode, fops) ({ (void)(mode), NULL; })
  175. #define proc_net_create(net, name, mode, info) ({ (void)(mode), NULL; })
  176. static inline void proc_net_remove(struct net *net, const char *name) {}
  177. static inline void proc_flush_task(struct task_struct *task) { }
  178. static inline struct proc_dir_entry *create_proc_entry(const char *name,
  179. mode_t mode, struct proc_dir_entry *parent) { return NULL; }
  180. #define remove_proc_entry(name, parent) do {} while (0)
  181. static inline struct proc_dir_entry *proc_symlink(const char *name,
  182. struct proc_dir_entry *parent,const char *dest) {return NULL;}
  183. static inline struct proc_dir_entry *proc_mkdir(const char *name,
  184. struct proc_dir_entry *parent) {return NULL;}
  185. static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
  186. mode_t mode, struct proc_dir_entry *base,
  187. read_proc_t *read_proc, void * data) { return NULL; }
  188. static inline struct proc_dir_entry *create_proc_info_entry(const char *name,
  189. mode_t mode, struct proc_dir_entry *base, get_info_t *get_info)
  190. { return NULL; }
  191. struct tty_driver;
  192. static inline void proc_tty_register_driver(struct tty_driver *driver) {};
  193. static inline void proc_tty_unregister_driver(struct tty_driver *driver) {};
  194. extern struct proc_dir_entry proc_root;
  195. #endif /* CONFIG_PROC_FS */
  196. #if !defined(CONFIG_PROC_KCORE)
  197. static inline void kclist_add(struct kcore_list *new, void *addr, size_t size)
  198. {
  199. }
  200. #else
  201. extern void kclist_add(struct kcore_list *, void *, size_t);
  202. #endif
  203. union proc_op {
  204. int (*proc_get_link)(struct inode *, struct dentry **, struct vfsmount **);
  205. int (*proc_read)(struct task_struct *task, char *page);
  206. };
  207. struct proc_inode {
  208. struct pid *pid;
  209. int fd;
  210. union proc_op op;
  211. struct proc_dir_entry *pde;
  212. struct inode vfs_inode;
  213. };
  214. static inline struct proc_inode *PROC_I(const struct inode *inode)
  215. {
  216. return container_of(inode, struct proc_inode, vfs_inode);
  217. }
  218. static inline struct proc_dir_entry *PDE(const struct inode *inode)
  219. {
  220. return PROC_I(inode)->pde;
  221. }
  222. static inline struct net *PDE_NET(struct proc_dir_entry *pde)
  223. {
  224. return pde->parent->data;
  225. }
  226. struct net *get_proc_net(const struct inode *inode);
  227. struct proc_maps_private {
  228. struct pid *pid;
  229. struct task_struct *task;
  230. #ifdef CONFIG_MMU
  231. struct vm_area_struct *tail_vma;
  232. #endif
  233. };
  234. #endif /* _LINUX_PROC_FS_H */