proc_fs.h
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:6k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. #ifndef _LINUX_PROC_FS_H
  2. #define _LINUX_PROC_FS_H
  3. #include <linux/config.h>
  4. #include <linux/slab.h>
  5. /*
  6.  * The proc filesystem constants/structures
  7.  */
  8. /*
  9.  * Offset of the first process in the /proc root directory..
  10.  */
  11. #define FIRST_PROCESS_ENTRY 256
  12. /*
  13.  * We always define these enumerators
  14.  */
  15. enum {
  16. PROC_ROOT_INO = 1,
  17. };
  18. /* Finally, the dynamically allocatable proc entries are reserved: */
  19. #define PROC_DYNAMIC_FIRST 4096
  20. #define PROC_NDYNAMIC      4096
  21. #define PROC_SUPER_MAGIC 0x9fa0
  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 *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 short 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. unsigned long size;
  50. struct inode_operations * proc_iops;
  51. struct file_operations * proc_fops;
  52. get_info_t *get_info;
  53. struct module *owner;
  54. struct proc_dir_entry *next, *parent, *subdir;
  55. void *data;
  56. read_proc_t *read_proc;
  57. write_proc_t *write_proc;
  58. atomic_t count; /* use count */
  59. int deleted; /* delete flag */
  60. kdev_t rdev;
  61. };
  62. #define PROC_INODE_PROPER(inode) ((inode)->i_ino & ~0xffff)
  63. #ifdef CONFIG_PROC_FS
  64. extern struct proc_dir_entry proc_root;
  65. extern struct proc_dir_entry *proc_root_fs;
  66. extern struct proc_dir_entry *proc_net;
  67. extern struct proc_dir_entry *proc_bus;
  68. extern struct proc_dir_entry *proc_root_driver;
  69. extern struct proc_dir_entry *proc_root_kcore;
  70. extern void proc_root_init(void);
  71. extern void proc_misc_init(void);
  72. struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry);
  73. void proc_pid_delete_inode(struct inode *inode);
  74. int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir);
  75. extern struct proc_dir_entry *create_proc_entry(const char *name, mode_t mode,
  76. struct proc_dir_entry *parent);
  77. extern void remove_proc_entry(const char *name, struct proc_dir_entry *parent);
  78. extern struct vfsmount *proc_mnt;
  79. extern struct super_block *proc_read_super(struct super_block *,void *,int);
  80. extern struct inode * proc_get_inode(struct super_block *, int, struct proc_dir_entry *);
  81. extern int proc_match(int, const char *,struct proc_dir_entry *);
  82. /*
  83.  * These are generic /proc routines that use the internal
  84.  * "struct proc_dir_entry" tree to traverse the filesystem.
  85.  *
  86.  * The /proc root directory has extended versions to take care
  87.  * of the /proc/<pid> subdirectories.
  88.  */
  89. extern int proc_readdir(struct file *, void *, filldir_t);
  90. extern struct dentry *proc_lookup(struct inode *, struct dentry *);
  91. extern struct file_operations proc_kcore_operations;
  92. extern struct file_operations proc_kmsg_operations;
  93. extern struct file_operations ppc_htab_operations;
  94. /*
  95.  * proc_tty.c
  96.  */
  97. struct tty_driver;
  98. extern void proc_tty_init(void);
  99. extern void proc_tty_register_driver(struct tty_driver *driver);
  100. extern void proc_tty_unregister_driver(struct tty_driver *driver);
  101. /*
  102.  * proc_devtree.c
  103.  */
  104. extern void proc_device_tree_init(void);
  105. /*
  106.  * proc_rtas.c
  107.  */
  108. extern void proc_rtas_init(void);
  109. /*
  110.  * PPC64
  111.  */ 
  112. extern void proc_ppc64_init(void);
  113. extern void iSeries_proc_create(void);
  114. extern struct proc_dir_entry *proc_symlink(const char *,
  115. struct proc_dir_entry *, const char *);
  116. extern struct proc_dir_entry *proc_mknod(const char *,mode_t,
  117. struct proc_dir_entry *,kdev_t);
  118. extern struct proc_dir_entry *proc_mkdir(const char *,struct proc_dir_entry *);
  119. static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
  120. mode_t mode, struct proc_dir_entry *base, 
  121. read_proc_t *read_proc, void * data)
  122. {
  123. struct proc_dir_entry *res=create_proc_entry(name,mode,base);
  124. if (res) {
  125. res->read_proc=read_proc;
  126. res->data=data;
  127. }
  128. return res;
  129. }
  130.  
  131. static inline struct proc_dir_entry *create_proc_info_entry(const char *name,
  132. mode_t mode, struct proc_dir_entry *base, get_info_t *get_info)
  133. {
  134. struct proc_dir_entry *res=create_proc_entry(name,mode,base);
  135. if (res) res->get_info=get_info;
  136. return res;
  137. }
  138.  
  139. static inline struct proc_dir_entry *proc_net_create(const char *name,
  140. mode_t mode, get_info_t *get_info)
  141. {
  142. return create_proc_info_entry(name,mode,proc_net,get_info);
  143. }
  144. static inline void proc_net_remove(const char *name)
  145. {
  146. remove_proc_entry(name,proc_net);
  147. }
  148. #else
  149. #define proc_root_driver NULL
  150. static inline struct proc_dir_entry *proc_net_create(const char *name, mode_t mode, 
  151. get_info_t *get_info) {return NULL;}
  152. static inline void proc_net_remove(const char *name) {}
  153. static inline struct proc_dir_entry *create_proc_entry(const char *name,
  154. mode_t mode, struct proc_dir_entry *parent) { return NULL; }
  155. static inline void remove_proc_entry(const char *name, struct proc_dir_entry *parent) {};
  156. static inline struct proc_dir_entry *proc_symlink(const char *name,
  157. struct proc_dir_entry *parent,char *dest) {return NULL;}
  158. static inline struct proc_dir_entry *proc_mknod(const char *name,mode_t mode,
  159. struct proc_dir_entry *parent,kdev_t rdev) {return NULL;}
  160. static inline struct proc_dir_entry *proc_mkdir(const char *name,
  161. struct proc_dir_entry *parent) {return NULL;}
  162. static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
  163. mode_t mode, struct proc_dir_entry *base, 
  164. int (*read_proc)(char *, char **, off_t, int, int *, void *),
  165. void * data) { return NULL; }
  166. static inline struct proc_dir_entry *create_proc_info_entry(const char *name,
  167. mode_t mode, struct proc_dir_entry *base, get_info_t *get_info)
  168. { return NULL; }
  169. static inline void proc_tty_register_driver(struct tty_driver *driver) {};
  170. static inline void proc_tty_unregister_driver(struct tty_driver *driver) {};
  171. extern struct proc_dir_entry proc_root;
  172. #endif /* CONFIG_PROC_FS */
  173. #endif /* _LINUX_PROC_FS_H */