proc_fs.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. #ifndef _LINUX_PROC_FS_H
  2. #define _LINUX_PROC_FS_H
  3. #include <linux/config.h>
  4. #include <linux/slab.h>
  5. #include <linux/fs.h>
  6. #include <asm/atomic.h>
  7. /*
  8. * The proc filesystem constants/structures
  9. */
  10. /*
  11. * Offset of the first process in the /proc root directory..
  12. */
  13. #define FIRST_PROCESS_ENTRY 256
  14. /*
  15. * We always define these enumerators
  16. */
  17. enum {
  18. PROC_ROOT_INO = 1,
  19. };
  20. #define PROC_SUPER_MAGIC 0x9fa0
  21. /*
  22. * This is not completely implemented yet. The idea is to
  23. * create an in-memory tree (like the actual /proc filesystem
  24. * tree) of these proc_dir_entries, so that we can dynamically
  25. * add new files to /proc.
  26. *
  27. * The "next" pointer creates a linked list of one /proc directory,
  28. * while parent/subdir create the directory structure (every
  29. * /proc file has a parent, but "subdir" is NULL for all
  30. * non-directory entries).
  31. *
  32. * "get_info" is called at "read", while "owner" is used to protect module
  33. * from unloading while proc_dir_entry is in use
  34. */
  35. typedef int (read_proc_t)(char *page, char **start, off_t off,
  36. int count, int *eof, void *data);
  37. typedef int (write_proc_t)(struct file *file, const char __user *buffer,
  38. unsigned long count, void *data);
  39. typedef int (get_info_t)(char *, char **, off_t, int);
  40. struct proc_dir_entry {
  41. unsigned int low_ino;
  42. unsigned short namelen;
  43. const char *name;
  44. mode_t mode;
  45. nlink_t nlink;
  46. uid_t uid;
  47. gid_t gid;
  48. unsigned long size;
  49. struct inode_operations * proc_iops;
  50. struct file_operations * proc_fops;
  51. get_info_t *get_info;
  52. struct module *owner;
  53. struct proc_dir_entry *next, *parent, *subdir;
  54. void *data;
  55. read_proc_t *read_proc;
  56. write_proc_t *write_proc;
  57. atomic_t count; /* use count */
  58. int deleted; /* delete flag */
  59. };
  60. struct kcore_list {
  61. struct kcore_list *next;
  62. unsigned long addr;
  63. size_t size;
  64. };
  65. #ifdef CONFIG_PROC_FS
  66. extern struct proc_dir_entry proc_root;
  67. extern struct proc_dir_entry *proc_root_fs;
  68. extern struct proc_dir_entry *proc_net;
  69. extern struct proc_dir_entry *proc_net_stat;
  70. extern struct proc_dir_entry *proc_bus;
  71. extern struct proc_dir_entry *proc_root_driver;
  72. extern struct proc_dir_entry *proc_root_kcore;
  73. extern void proc_root_init(void);
  74. extern void proc_misc_init(void);
  75. struct mm_struct;
  76. struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct nameidata *);
  77. struct dentry *proc_pid_unhash(struct task_struct *p);
  78. void proc_pid_flush(struct dentry *proc_dentry);
  79. int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir);
  80. unsigned long task_vsize(struct mm_struct *);
  81. int task_statm(struct mm_struct *, int *, int *, int *, int *);
  82. char *task_mem(struct mm_struct *, char *);
  83. extern struct proc_dir_entry *create_proc_entry(const char *name, mode_t mode,
  84. struct proc_dir_entry *parent);
  85. extern void remove_proc_entry(const char *name, struct proc_dir_entry *parent);
  86. extern struct vfsmount *proc_mnt;
  87. extern int proc_fill_super(struct super_block *,void *,int);
  88. extern struct inode *proc_get_inode(struct super_block *, unsigned int, struct proc_dir_entry *);
  89. extern int proc_match(int, const char *,struct proc_dir_entry *);
  90. /*
  91. * These are generic /proc routines that use the internal
  92. * "struct proc_dir_entry" tree to traverse the filesystem.
  93. *
  94. * The /proc root directory has extended versions to take care
  95. * of the /proc/<pid> subdirectories.
  96. */
  97. extern int proc_readdir(struct file *, void *, filldir_t);
  98. extern struct dentry *proc_lookup(struct inode *, struct dentry *, struct nameidata *);
  99. extern struct file_operations proc_kcore_operations;
  100. extern struct file_operations proc_kmsg_operations;
  101. extern struct file_operations ppc_htab_operations;
  102. /*
  103. * proc_tty.c
  104. */
  105. struct tty_driver;
  106. extern void proc_tty_init(void);
  107. extern void proc_tty_register_driver(struct tty_driver *driver);
  108. extern void proc_tty_unregister_driver(struct tty_driver *driver);
  109. /*
  110. * proc_devtree.c
  111. */
  112. struct device_node;
  113. extern void proc_device_tree_init(void);
  114. #ifdef CONFIG_PROC_DEVICETREE
  115. extern void proc_device_tree_add_node(struct device_node *, struct proc_dir_entry *);
  116. #else /* !CONFIG_PROC_DEVICETREE */
  117. static inline void proc_device_tree_add_node(struct device_node *np, struct proc_dir_entry *pde)
  118. {
  119. return;
  120. }
  121. #endif /* CONFIG_PROC_DEVICETREE */
  122. extern struct proc_dir_entry *proc_symlink(const char *,
  123. struct proc_dir_entry *, const char *);
  124. extern struct proc_dir_entry *proc_mkdir(const char *,struct proc_dir_entry *);
  125. extern struct proc_dir_entry *proc_mkdir_mode(const char *name, mode_t mode,
  126. struct proc_dir_entry *parent);
  127. static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
  128. mode_t mode, struct proc_dir_entry *base,
  129. read_proc_t *read_proc, void * data)
  130. {
  131. struct proc_dir_entry *res=create_proc_entry(name,mode,base);
  132. if (res) {
  133. res->read_proc=read_proc;
  134. res->data=data;
  135. }
  136. return res;
  137. }
  138. static inline struct proc_dir_entry *create_proc_info_entry(const char *name,
  139. mode_t mode, struct proc_dir_entry *base, get_info_t *get_info)
  140. {
  141. struct proc_dir_entry *res=create_proc_entry(name,mode,base);
  142. if (res) res->get_info=get_info;
  143. return res;
  144. }
  145. static inline struct proc_dir_entry *proc_net_create(const char *name,
  146. mode_t mode, get_info_t *get_info)
  147. {
  148. return create_proc_info_entry(name,mode,proc_net,get_info);
  149. }
  150. static inline struct proc_dir_entry *proc_net_fops_create(const char *name,
  151. mode_t mode, struct file_operations *fops)
  152. {
  153. struct proc_dir_entry *res = create_proc_entry(name, mode, proc_net);
  154. if (res)
  155. res->proc_fops = fops;
  156. return res;
  157. }
  158. static inline void proc_net_remove(const char *name)
  159. {
  160. remove_proc_entry(name,proc_net);
  161. }
  162. #else
  163. #define proc_root_driver NULL
  164. #define proc_net NULL
  165. #define proc_bus NULL
  166. #define proc_net_fops_create(name, mode, fops) ({ (void)(mode), NULL; })
  167. #define proc_net_create(name, mode, info) ({ (void)(mode), NULL; })
  168. static inline void proc_net_remove(const char *name) {}
  169. static inline struct dentry *proc_pid_unhash(struct task_struct *p) { return NULL; }
  170. static inline void proc_pid_flush(struct dentry *proc_dentry) { }
  171. static inline struct proc_dir_entry *create_proc_entry(const char *name,
  172. mode_t mode, struct proc_dir_entry *parent) { return NULL; }
  173. #define remove_proc_entry(name, parent) do {} while (0)
  174. static inline struct proc_dir_entry *proc_symlink(const char *name,
  175. struct proc_dir_entry *parent,const char *dest) {return NULL;}
  176. static inline struct proc_dir_entry *proc_mkdir(const char *name,
  177. struct proc_dir_entry *parent) {return NULL;}
  178. static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
  179. mode_t mode, struct proc_dir_entry *base,
  180. read_proc_t *read_proc, void * data) { return NULL; }
  181. static inline struct proc_dir_entry *create_proc_info_entry(const char *name,
  182. mode_t mode, struct proc_dir_entry *base, get_info_t *get_info)
  183. { return NULL; }
  184. struct tty_driver;
  185. static inline void proc_tty_register_driver(struct tty_driver *driver) {};
  186. static inline void proc_tty_unregister_driver(struct tty_driver *driver) {};
  187. extern struct proc_dir_entry proc_root;
  188. #endif /* CONFIG_PROC_FS */
  189. #if !defined(CONFIG_PROC_KCORE)
  190. static inline void kclist_add(struct kcore_list *new, void *addr, size_t size)
  191. {
  192. }
  193. #else
  194. extern void kclist_add(struct kcore_list *, void *, size_t);
  195. #endif
  196. struct proc_inode {
  197. struct task_struct *task;
  198. int type;
  199. union {
  200. int (*proc_get_link)(struct inode *, struct dentry **, struct vfsmount **);
  201. int (*proc_read)(struct task_struct *task, char *page);
  202. } op;
  203. struct proc_dir_entry *pde;
  204. struct inode vfs_inode;
  205. };
  206. static inline struct proc_inode *PROC_I(const struct inode *inode)
  207. {
  208. return container_of(inode, struct proc_inode, vfs_inode);
  209. }
  210. static inline struct proc_dir_entry *PDE(const struct inode *inode)
  211. {
  212. return PROC_I(inode)->pde;
  213. }
  214. #endif /* _LINUX_PROC_FS_H */