proc_fs.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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. void *set;
  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_net;
  88. extern struct proc_dir_entry *proc_net_stat;
  89. extern struct proc_dir_entry *proc_bus;
  90. extern struct proc_dir_entry *proc_root_driver;
  91. extern struct proc_dir_entry *proc_root_kcore;
  92. extern spinlock_t proc_subdir_lock;
  93. extern void proc_root_init(void);
  94. extern void proc_misc_init(void);
  95. struct mm_struct;
  96. void proc_flush_task(struct task_struct *task);
  97. struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct nameidata *);
  98. int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir);
  99. unsigned long task_vsize(struct mm_struct *);
  100. int task_statm(struct mm_struct *, int *, int *, int *, int *);
  101. char *task_mem(struct mm_struct *, char *);
  102. void clear_refs_smap(struct mm_struct *mm);
  103. struct proc_dir_entry *de_get(struct proc_dir_entry *de);
  104. void de_put(struct proc_dir_entry *de);
  105. extern struct proc_dir_entry *create_proc_entry(const char *name, mode_t mode,
  106. struct proc_dir_entry *parent);
  107. extern void remove_proc_entry(const char *name, struct proc_dir_entry *parent);
  108. extern struct vfsmount *proc_mnt;
  109. extern int proc_fill_super(struct super_block *,void *,int);
  110. extern struct inode *proc_get_inode(struct super_block *, unsigned int, struct proc_dir_entry *);
  111. /*
  112. * These are generic /proc routines that use the internal
  113. * "struct proc_dir_entry" tree to traverse the filesystem.
  114. *
  115. * The /proc root directory has extended versions to take care
  116. * of the /proc/<pid> subdirectories.
  117. */
  118. extern int proc_readdir(struct file *, void *, filldir_t);
  119. extern struct dentry *proc_lookup(struct inode *, struct dentry *, struct nameidata *);
  120. extern const struct file_operations proc_kcore_operations;
  121. extern const struct file_operations proc_kmsg_operations;
  122. extern const struct file_operations ppc_htab_operations;
  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 *create_proc_read_entry(const char *name,
  151. mode_t mode, struct proc_dir_entry *base,
  152. read_proc_t *read_proc, void * data)
  153. {
  154. struct proc_dir_entry *res=create_proc_entry(name,mode,base);
  155. if (res) {
  156. res->read_proc=read_proc;
  157. res->data=data;
  158. }
  159. return res;
  160. }
  161. static inline struct proc_dir_entry *create_proc_info_entry(const char *name,
  162. mode_t mode, struct proc_dir_entry *base, get_info_t *get_info)
  163. {
  164. struct proc_dir_entry *res=create_proc_entry(name,mode,base);
  165. if (res) res->get_info=get_info;
  166. return res;
  167. }
  168. static inline struct proc_dir_entry *proc_net_create(const char *name,
  169. mode_t mode, get_info_t *get_info)
  170. {
  171. return create_proc_info_entry(name,mode,proc_net,get_info);
  172. }
  173. static inline struct proc_dir_entry *proc_net_fops_create(const char *name,
  174. mode_t mode, const struct file_operations *fops)
  175. {
  176. struct proc_dir_entry *res = create_proc_entry(name, mode, proc_net);
  177. if (res)
  178. res->proc_fops = fops;
  179. return res;
  180. }
  181. static inline void proc_net_remove(const char *name)
  182. {
  183. remove_proc_entry(name,proc_net);
  184. }
  185. #else
  186. #define proc_root_driver NULL
  187. #define proc_net NULL
  188. #define proc_bus NULL
  189. #define proc_net_fops_create(name, mode, fops) ({ (void)(mode), NULL; })
  190. #define proc_net_create(name, mode, info) ({ (void)(mode), NULL; })
  191. static inline void proc_net_remove(const char *name) {}
  192. static inline void proc_flush_task(struct task_struct *task) { }
  193. static inline struct proc_dir_entry *create_proc_entry(const char *name,
  194. mode_t mode, struct proc_dir_entry *parent) { return NULL; }
  195. #define remove_proc_entry(name, parent) do {} while (0)
  196. static inline struct proc_dir_entry *proc_symlink(const char *name,
  197. struct proc_dir_entry *parent,const char *dest) {return NULL;}
  198. static inline struct proc_dir_entry *proc_mkdir(const char *name,
  199. struct proc_dir_entry *parent) {return NULL;}
  200. static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
  201. mode_t mode, struct proc_dir_entry *base,
  202. read_proc_t *read_proc, void * data) { return NULL; }
  203. static inline struct proc_dir_entry *create_proc_info_entry(const char *name,
  204. mode_t mode, struct proc_dir_entry *base, get_info_t *get_info)
  205. { return NULL; }
  206. struct tty_driver;
  207. static inline void proc_tty_register_driver(struct tty_driver *driver) {};
  208. static inline void proc_tty_unregister_driver(struct tty_driver *driver) {};
  209. extern struct proc_dir_entry proc_root;
  210. #endif /* CONFIG_PROC_FS */
  211. #if !defined(CONFIG_PROC_KCORE)
  212. static inline void kclist_add(struct kcore_list *new, void *addr, size_t size)
  213. {
  214. }
  215. #else
  216. extern void kclist_add(struct kcore_list *, void *, size_t);
  217. #endif
  218. union proc_op {
  219. int (*proc_get_link)(struct inode *, struct dentry **, struct vfsmount **);
  220. int (*proc_read)(struct task_struct *task, char *page);
  221. };
  222. struct proc_inode {
  223. struct pid *pid;
  224. int fd;
  225. union proc_op op;
  226. struct proc_dir_entry *pde;
  227. struct inode vfs_inode;
  228. };
  229. static inline struct proc_inode *PROC_I(const struct inode *inode)
  230. {
  231. return container_of(inode, struct proc_inode, vfs_inode);
  232. }
  233. static inline struct proc_dir_entry *PDE(const struct inode *inode)
  234. {
  235. return PROC_I(inode)->pde;
  236. }
  237. struct proc_maps_private {
  238. struct pid *pid;
  239. struct task_struct *task;
  240. #ifdef CONFIG_MMU
  241. struct vm_area_struct *tail_vma;
  242. #endif
  243. };
  244. #endif /* _LINUX_PROC_FS_H */