proc_fs.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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 completion;
  9. /*
  10. * The proc filesystem constants/structures
  11. */
  12. /*
  13. * Offset of the first process in the /proc root directory..
  14. */
  15. #define FIRST_PROCESS_ENTRY 256
  16. /*
  17. * We always define these enumerators
  18. */
  19. enum {
  20. PROC_ROOT_INO = 1,
  21. };
  22. /*
  23. * This is not completely implemented yet. The idea is to
  24. * create an in-memory tree (like the actual /proc filesystem
  25. * tree) of these proc_dir_entries, so that we can dynamically
  26. * add new files to /proc.
  27. *
  28. * The "next" pointer creates a linked list of one /proc directory,
  29. * while parent/subdir create the directory structure (every
  30. * /proc file has a parent, but "subdir" is NULL for all
  31. * non-directory entries).
  32. *
  33. * "get_info" is called at "read", while "owner" is used to protect module
  34. * from unloading while proc_dir_entry is in use
  35. */
  36. typedef int (read_proc_t)(char *page, char **start, off_t off,
  37. int count, int *eof, void *data);
  38. typedef int (write_proc_t)(struct file *file, const char __user *buffer,
  39. unsigned long count, void *data);
  40. typedef int (get_info_t)(char *, char **, off_t, int);
  41. struct proc_dir_entry {
  42. unsigned int low_ino;
  43. unsigned short namelen;
  44. const char *name;
  45. mode_t mode;
  46. nlink_t nlink;
  47. uid_t uid;
  48. gid_t gid;
  49. loff_t size;
  50. const struct inode_operations *proc_iops;
  51. /*
  52. * NULL ->proc_fops means "PDE is going away RSN" or
  53. * "PDE is just created". In either case, e.g. ->read_proc won't be
  54. * called because it's too late or too early, respectively.
  55. *
  56. * If you're allocating ->proc_fops dynamically, save a pointer
  57. * somewhere.
  58. */
  59. const struct file_operations *proc_fops;
  60. get_info_t *get_info;
  61. struct module *owner;
  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 deleted; /* delete flag */
  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;
  85. extern struct proc_dir_entry *proc_root_fs;
  86. extern struct proc_dir_entry *proc_net;
  87. extern struct proc_dir_entry *proc_net_stat;
  88. extern struct proc_dir_entry *proc_bus;
  89. extern struct proc_dir_entry *proc_root_driver;
  90. extern struct proc_dir_entry *proc_root_kcore;
  91. extern spinlock_t proc_subdir_lock;
  92. extern void proc_root_init(void);
  93. extern void proc_misc_init(void);
  94. struct mm_struct;
  95. void proc_flush_task(struct task_struct *task);
  96. struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct nameidata *);
  97. int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir);
  98. unsigned long task_vsize(struct mm_struct *);
  99. int task_statm(struct mm_struct *, int *, int *, int *, int *);
  100. char *task_mem(struct mm_struct *, char *);
  101. void clear_refs_smap(struct mm_struct *mm);
  102. struct proc_dir_entry *de_get(struct proc_dir_entry *de);
  103. void de_put(struct proc_dir_entry *de);
  104. extern struct proc_dir_entry *create_proc_entry(const char *name, mode_t mode,
  105. struct proc_dir_entry *parent);
  106. extern void remove_proc_entry(const char *name, struct proc_dir_entry *parent);
  107. extern struct vfsmount *proc_mnt;
  108. extern int proc_fill_super(struct super_block *,void *,int);
  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 proc_kmsg_operations;
  121. extern const struct file_operations ppc_htab_operations;
  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. static inline struct proc_dir_entry *create_proc_info_entry(const char *name,
  161. mode_t mode, struct proc_dir_entry *base, get_info_t *get_info)
  162. {
  163. struct proc_dir_entry *res=create_proc_entry(name,mode,base);
  164. if (res) res->get_info=get_info;
  165. return res;
  166. }
  167. static inline struct proc_dir_entry *proc_net_create(const char *name,
  168. mode_t mode, get_info_t *get_info)
  169. {
  170. return create_proc_info_entry(name,mode,proc_net,get_info);
  171. }
  172. static inline struct proc_dir_entry *proc_net_fops_create(const char *name,
  173. mode_t mode, const struct file_operations *fops)
  174. {
  175. struct proc_dir_entry *res = create_proc_entry(name, mode, proc_net);
  176. if (res)
  177. res->proc_fops = fops;
  178. return res;
  179. }
  180. static inline void proc_net_remove(const char *name)
  181. {
  182. remove_proc_entry(name,proc_net);
  183. }
  184. #else
  185. #define proc_root_driver NULL
  186. #define proc_net NULL
  187. #define proc_bus NULL
  188. #define proc_net_fops_create(name, mode, fops) ({ (void)(mode), NULL; })
  189. #define proc_net_create(name, mode, info) ({ (void)(mode), NULL; })
  190. static inline void proc_net_remove(const char *name) {}
  191. static inline void proc_flush_task(struct task_struct *task) { }
  192. static inline struct proc_dir_entry *create_proc_entry(const char *name,
  193. mode_t mode, struct proc_dir_entry *parent) { return NULL; }
  194. #define remove_proc_entry(name, parent) do {} while (0)
  195. static inline struct proc_dir_entry *proc_symlink(const char *name,
  196. struct proc_dir_entry *parent,const char *dest) {return NULL;}
  197. static inline struct proc_dir_entry *proc_mkdir(const char *name,
  198. struct proc_dir_entry *parent) {return NULL;}
  199. static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
  200. mode_t mode, struct proc_dir_entry *base,
  201. read_proc_t *read_proc, void * data) { return NULL; }
  202. static inline struct proc_dir_entry *create_proc_info_entry(const char *name,
  203. mode_t mode, struct proc_dir_entry *base, get_info_t *get_info)
  204. { return NULL; }
  205. struct tty_driver;
  206. static inline void proc_tty_register_driver(struct tty_driver *driver) {};
  207. static inline void proc_tty_unregister_driver(struct tty_driver *driver) {};
  208. extern struct proc_dir_entry proc_root;
  209. #endif /* CONFIG_PROC_FS */
  210. #if !defined(CONFIG_PROC_KCORE)
  211. static inline void kclist_add(struct kcore_list *new, void *addr, size_t size)
  212. {
  213. }
  214. #else
  215. extern void kclist_add(struct kcore_list *, void *, size_t);
  216. #endif
  217. union proc_op {
  218. int (*proc_get_link)(struct inode *, struct dentry **, struct vfsmount **);
  219. int (*proc_read)(struct task_struct *task, char *page);
  220. };
  221. struct proc_inode {
  222. struct pid *pid;
  223. int fd;
  224. union proc_op op;
  225. struct proc_dir_entry *pde;
  226. struct inode vfs_inode;
  227. };
  228. static inline struct proc_inode *PROC_I(const struct inode *inode)
  229. {
  230. return container_of(inode, struct proc_inode, vfs_inode);
  231. }
  232. static inline struct proc_dir_entry *PDE(const struct inode *inode)
  233. {
  234. return PROC_I(inode)->pde;
  235. }
  236. struct proc_maps_private {
  237. struct pid *pid;
  238. struct task_struct *task;
  239. #ifdef CONFIG_MMU
  240. struct vm_area_struct *tail_vma;
  241. #endif
  242. };
  243. #endif /* _LINUX_PROC_FS_H */