| 1 | #ifndef _LINUX_PROC_FS_H |
|---|
| 2 | #define _LINUX_PROC_FS_H |
|---|
| 3 | |
|---|
| 4 | #include <linux/slab.h> |
|---|
| 5 | #include <linux/fs.h> |
|---|
| 6 | #include <asm/atomic.h> |
|---|
| 7 | |
|---|
| 8 | /* |
|---|
| 9 | * The proc filesystem constants/structures |
|---|
| 10 | */ |
|---|
| 11 | |
|---|
| 12 | /* |
|---|
| 13 | * Offset of the first process in the /proc root directory.. |
|---|
| 14 | */ |
|---|
| 15 | #define FIRST_PROCESS_ENTRY 256 |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | /* |
|---|
| 19 | * We always define these enumerators |
|---|
| 20 | */ |
|---|
| 21 | |
|---|
| 22 | enum { |
|---|
| 23 | PROC_ROOT_INO = 1, |
|---|
| 24 | }; |
|---|
| 25 | |
|---|
| 26 | #define PROC_SUPER_MAGIC 0x9fa0 |
|---|
| 27 | |
|---|
| 28 | /* |
|---|
| 29 | * This is not completely implemented yet. The idea is to |
|---|
| 30 | * create an in-memory tree (like the actual /proc filesystem |
|---|
| 31 | * tree) of these proc_dir_entries, so that we can dynamically |
|---|
| 32 | * add new files to /proc. |
|---|
| 33 | * |
|---|
| 34 | * The "next" pointer creates a linked list of one /proc directory, |
|---|
| 35 | * while parent/subdir create the directory structure (every |
|---|
| 36 | * /proc file has a parent, but "subdir" is NULL for all |
|---|
| 37 | * non-directory entries). |
|---|
| 38 | * |
|---|
| 39 | * "get_info" is called at "read", while "owner" is used to protect module |
|---|
| 40 | * from unloading while proc_dir_entry is in use |
|---|
| 41 | */ |
|---|
| 42 | |
|---|
| 43 | typedef int (read_proc_t)(char *page, char **start, off_t off, |
|---|
| 44 | int count, int *eof, void *data); |
|---|
| 45 | typedef int (write_proc_t)(struct file *file, const char *buffer, |
|---|
| 46 | unsigned long count, void *data); |
|---|
| 47 | typedef int (get_info_t)(char *, char **, off_t, int); |
|---|
| 48 | |
|---|
| 49 | struct proc_dir_entry { |
|---|
| 50 | unsigned int low_ino; |
|---|
| 51 | unsigned short namelen; |
|---|
| 52 | const char *name; |
|---|
| 53 | mode_t mode; |
|---|
| 54 | nlink_t nlink; |
|---|
| 55 | uid_t uid; |
|---|
| 56 | gid_t gid; |
|---|
| 57 | unsigned long size; |
|---|
| 58 | struct inode_operations * proc_iops; |
|---|
| 59 | 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 | }; |
|---|
| 69 | |
|---|
| 70 | struct kcore_list { |
|---|
| 71 | struct kcore_list *next; |
|---|
| 72 | unsigned long addr; |
|---|
| 73 | size_t size; |
|---|
| 74 | }; |
|---|
| 75 | |
|---|
| 76 | #ifdef CONFIG_PROC_FS |
|---|
| 77 | |
|---|
| 78 | extern struct proc_dir_entry proc_root; |
|---|
| 79 | extern struct proc_dir_entry *proc_root_fs; |
|---|
| 80 | extern struct proc_dir_entry *proc_net; |
|---|
| 81 | extern struct proc_dir_entry *proc_net_stat; |
|---|
| 82 | extern struct proc_dir_entry *proc_bus; |
|---|
| 83 | extern struct proc_dir_entry *proc_root_driver; |
|---|
| 84 | extern struct proc_dir_entry *proc_root_kcore; |
|---|
| 85 | |
|---|
| 86 | extern void proc_root_init(void); |
|---|
| 87 | extern void proc_misc_init(void); |
|---|
| 88 | |
|---|
| 89 | struct mm_struct; |
|---|
| 90 | |
|---|
| 91 | struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct nameidata *); |
|---|
| 92 | struct dentry *proc_pid_unhash(struct task_struct *p); |
|---|
| 93 | void proc_pid_flush(struct dentry *proc_dentry); |
|---|
| 94 | int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir); |
|---|
| 95 | unsigned long task_vsize(struct mm_struct *); |
|---|
| 96 | int task_statm(struct mm_struct *, int *, int *, int *, int *); |
|---|
| 97 | char *task_mem(struct mm_struct *, char *); |
|---|
| 98 | |
|---|
| 99 | extern struct proc_dir_entry *create_proc_entry(const char *name, mode_t mode, |
|---|
| 100 | struct proc_dir_entry *parent); |
|---|
| 101 | extern void remove_proc_entry(const char *name, struct proc_dir_entry *parent); |
|---|
| 102 | |
|---|
| 103 | extern struct vfsmount *proc_mnt; |
|---|
| 104 | extern int proc_fill_super(struct super_block *,void *,int); |
|---|
| 105 | extern struct inode *proc_get_inode(struct super_block *, unsigned int, struct proc_dir_entry *); |
|---|
| 106 | |
|---|
| 107 | extern int proc_match(int, const char *,struct proc_dir_entry *); |
|---|
| 108 | |
|---|
| 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 | |
|---|
| 119 | extern struct file_operations proc_kcore_operations; |
|---|
| 120 | extern struct file_operations proc_kmsg_operations; |
|---|
| 121 | extern struct file_operations ppc_htab_operations; |
|---|
| 122 | |
|---|
| 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 | /* |
|---|
| 132 | * proc_devtree.c |
|---|
| 133 | */ |
|---|
| 134 | struct device_node; |
|---|
| 135 | extern void proc_device_tree_init(void); |
|---|
| 136 | #ifdef CONFIG_PROC_DEVICETREE |
|---|
| 137 | extern void proc_device_tree_add_node(struct device_node *, struct proc_dir_entry *); |
|---|
| 138 | #else /* !CONFIG_PROC_DEVICETREE */ |
|---|
| 139 | static inline void proc_device_tree_add_node(struct device_node *np, struct proc_dir_entry *pde) |
|---|
| 140 | { |
|---|
| 141 | return; |
|---|
| 142 | } |
|---|
| 143 | #endif /* CONFIG_PROC_DEVICETREE */ |
|---|
| 144 | |
|---|
| 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 | |
|---|
| 151 | static inline struct proc_dir_entry *create_proc_read_entry(const char *name, |
|---|
| 152 | mode_t mode, struct proc_dir_entry *base, |
|---|
| 153 | read_proc_t *read_proc, void * data) |
|---|
| 154 | { |
|---|
| 155 | struct proc_dir_entry *res=create_proc_entry(name,mode,base); |
|---|
| 156 | if (res) { |
|---|
| 157 | res->read_proc=read_proc; |
|---|
| 158 | res->data=data; |
|---|
| 159 | } |
|---|
| 160 | return res; |
|---|
| 161 | } |
|---|
| 162 | |
|---|
| 163 | static inline struct proc_dir_entry *create_proc_info_entry(const char *name, |
|---|
| 164 | mode_t mode, struct proc_dir_entry *base, get_info_t *get_info) |
|---|
| 165 | { |
|---|
| 166 | struct proc_dir_entry *res=create_proc_entry(name,mode,base); |
|---|
| 167 | if (res) res->get_info=get_info; |
|---|
| 168 | return res; |
|---|
| 169 | } |
|---|
| 170 | |
|---|
| 171 | static inline struct proc_dir_entry *proc_net_create(const char *name, |
|---|
| 172 | mode_t mode, get_info_t *get_info) |
|---|
| 173 | { |
|---|
| 174 | return create_proc_info_entry(name,mode,proc_net,get_info); |
|---|
| 175 | } |
|---|
| 176 | |
|---|
| 177 | static inline struct proc_dir_entry *proc_net_fops_create(const char *name, |
|---|
| 178 | mode_t mode, struct file_operations *fops) |
|---|
| 179 | { |
|---|
| 180 | struct proc_dir_entry *res = create_proc_entry(name, mode, proc_net); |
|---|
| 181 | if (res) |
|---|
| 182 | res->proc_fops = fops; |
|---|
| 183 | return res; |
|---|
| 184 | } |
|---|
| 185 | |
|---|
| 186 | static inline void proc_net_remove(const char *name) |
|---|
| 187 | { |
|---|
| 188 | remove_proc_entry(name,proc_net); |
|---|
| 189 | } |
|---|
| 190 | |
|---|
| 191 | #else |
|---|
| 192 | |
|---|
| 193 | #define proc_root_driver NULL |
|---|
| 194 | #define proc_net NULL |
|---|
| 195 | #define proc_bus NULL |
|---|
| 196 | |
|---|
| 197 | #define proc_net_fops_create(name, mode, fops) ({ (void)(mode), NULL; }) |
|---|
| 198 | #define proc_net_create(name, mode, info) ({ (void)(mode), NULL; }) |
|---|
| 199 | static inline void proc_net_remove(const char *name) {} |
|---|
| 200 | |
|---|
| 201 | static inline struct dentry *proc_pid_unhash(struct task_struct *p) { return NULL; } |
|---|
| 202 | static inline void proc_pid_flush(struct dentry *proc_dentry) { } |
|---|
| 203 | |
|---|
| 204 | static inline struct proc_dir_entry *create_proc_entry(const char *name, |
|---|
| 205 | mode_t mode, struct proc_dir_entry *parent) { return NULL; } |
|---|
| 206 | |
|---|
| 207 | #define remove_proc_entry(name, parent) do {} while (0) |
|---|
| 208 | |
|---|
| 209 | static inline struct proc_dir_entry *proc_symlink(const char *name, |
|---|
| 210 | struct proc_dir_entry *parent,const char *dest) {return NULL;} |
|---|
| 211 | static inline struct proc_dir_entry *proc_mkdir(const char *name, |
|---|
| 212 | struct proc_dir_entry *parent) {return NULL;} |
|---|
| 213 | |
|---|
| 214 | static inline struct proc_dir_entry *create_proc_read_entry(const char *name, |
|---|
| 215 | mode_t mode, struct proc_dir_entry *base, |
|---|
| 216 | read_proc_t *read_proc, void * data) { return NULL; } |
|---|
| 217 | static inline struct proc_dir_entry *create_proc_info_entry(const char *name, |
|---|
| 218 | mode_t mode, struct proc_dir_entry *base, get_info_t *get_info) |
|---|
| 219 | { return NULL; } |
|---|
| 220 | |
|---|
| 221 | struct tty_driver; |
|---|
| 222 | static inline void proc_tty_register_driver(struct tty_driver *driver) {}; |
|---|
| 223 | static inline void proc_tty_unregister_driver(struct tty_driver *driver) {}; |
|---|
| 224 | |
|---|
| 225 | extern struct proc_dir_entry proc_root; |
|---|
| 226 | |
|---|
| 227 | #endif /* CONFIG_PROC_FS */ |
|---|
| 228 | |
|---|
| 229 | #if !defined(CONFIG_PROC_KCORE) |
|---|
| 230 | static inline void kclist_add(struct kcore_list *new, void *addr, size_t size) |
|---|
| 231 | { |
|---|
| 232 | } |
|---|
| 233 | #else |
|---|
| 234 | extern void kclist_add(struct kcore_list *, void *, size_t); |
|---|
| 235 | #endif |
|---|
| 236 | |
|---|
| 237 | struct proc_inode { |
|---|
| 238 | struct task_struct *task; |
|---|
| 239 | int type; |
|---|
| 240 | union { |
|---|
| 241 | int (*proc_get_link)(struct inode *, struct dentry **, struct vfsmount **); |
|---|
| 242 | int (*proc_read)(struct task_struct *task, char *page); |
|---|
| 243 | } op; |
|---|
| 244 | struct proc_dir_entry *pde; |
|---|
| 245 | struct inode vfs_inode; |
|---|
| 246 | }; |
|---|
| 247 | |
|---|
| 248 | static inline struct proc_inode *PROC_I(const struct inode *inode) |
|---|
| 249 | { |
|---|
| 250 | return container_of(inode, struct proc_inode, vfs_inode); |
|---|
| 251 | } |
|---|
| 252 | |
|---|
| 253 | static inline struct proc_dir_entry *PDE(const struct inode *inode) |
|---|
| 254 | { |
|---|
| 255 | return PROC_I(inode)->pde; |
|---|
| 256 | } |
|---|
| 257 | |
|---|
| 258 | #endif /* _LINUX_PROC_FS_H */ |
|---|