1 #ifndef _LINUX_PROC_FS_H
2 #define _LINUX_PROC_FS_H
3 
4 #include <linux/config.h>
5 #include <linux/slab.h>
6 
7 /*
8  * The proc filesystem constants/structures
9  */
10 
11 /*
12  * Offset of the first process in the /proc root directory..
13  */
14 #define FIRST_PROCESS_ENTRY 256
15 
16 
17 /*
18  * We always define these enumerators
19  */
20 
21 enum {
22 	PROC_ROOT_INO = 1,
23 };
24 
25 /* Finally, the dynamically allocatable proc entries are reserved: */
26 
27 #define PROC_DYNAMIC_FIRST 4096
28 #define PROC_NDYNAMIC      4096
29 
30 #define PROC_SUPER_MAGIC 0x9fa0
31 
32 /*
33  * This is not completely implemented yet. The idea is to
34  * create an in-memory tree (like the actual /proc filesystem
35  * tree) of these proc_dir_entries, so that we can dynamically
36  * add new files to /proc.
37  *
38  * The "next" pointer creates a linked list of one /proc directory,
39  * while parent/subdir create the directory structure (every
40  * /proc file has a parent, but "subdir" is NULL for all
41  * non-directory entries).
42  *
43  * "get_info" is called at "read", while "owner" is used to protect module
44  * from unloading while proc_dir_entry is in use
45  */
46 
47 typedef	int (read_proc_t)(char *page, char **start, off_t off,
48 			  int count, int *eof, void *data);
49 typedef	int (write_proc_t)(struct file *file, const char *buffer,
50 			   unsigned long count, void *data);
51 typedef int (get_info_t)(char *, char **, off_t, int);
52 
53 struct proc_dir_entry {
54 	unsigned short low_ino;
55 	unsigned short namelen;
56 	const char *name;
57 	mode_t mode;
58 	nlink_t nlink;
59 	uid_t uid;
60 	gid_t gid;
61 	unsigned long size;
62 	struct inode_operations * proc_iops;
63 	struct file_operations * proc_fops;
64 	get_info_t *get_info;
65 	struct module *owner;
66 	struct proc_dir_entry *next, *parent, *subdir;
67 	void *data;
68 	read_proc_t *read_proc;
69 	write_proc_t *write_proc;
70 	atomic_t count;		/* use count */
71 	int deleted;		/* delete flag */
72 	kdev_t	rdev;
73 	void *set;
74 };
75 
76 #define PROC_INODE_PROPER(inode) ((inode)->i_ino & ~0xffff)
77 
78 #ifdef CONFIG_PROC_FS
79 
80 extern struct proc_dir_entry proc_root;
81 extern struct proc_dir_entry *proc_root_fs;
82 extern struct proc_dir_entry *proc_net;
83 extern struct proc_dir_entry *proc_net_stat;
84 extern struct proc_dir_entry *proc_bus;
85 extern struct proc_dir_entry *proc_root_driver;
86 extern struct proc_dir_entry *proc_root_kcore;
87 
88 extern void proc_root_init(void);
89 extern void proc_misc_init(void);
90 
91 struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry);
92 void proc_pid_delete_inode(struct inode *inode);
93 int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir);
94 
95 extern struct proc_dir_entry *create_proc_entry(const char *name, mode_t mode,
96 						struct proc_dir_entry *parent);
97 extern void remove_proc_entry(const char *name, struct proc_dir_entry *parent);
98 
99 extern struct vfsmount *proc_mnt;
100 extern struct super_block *proc_read_super(struct super_block *,void *,int);
101 extern struct inode * proc_get_inode(struct super_block *, int, struct proc_dir_entry *);
102 
103 extern int proc_match(int, const char *,struct proc_dir_entry *);
104 
105 /*
106  * These are generic /proc routines that use the internal
107  * "struct proc_dir_entry" tree to traverse the filesystem.
108  *
109  * The /proc root directory has extended versions to take care
110  * of the /proc/<pid> subdirectories.
111  */
112 extern int proc_readdir(struct file *, void *, filldir_t);
113 extern struct dentry *proc_lookup(struct inode *, struct dentry *);
114 
115 extern struct file_operations proc_kcore_operations;
116 extern struct file_operations proc_kmsg_operations;
117 extern struct file_operations ppc_htab_operations;
118 
119 /*
120  * proc_tty.c
121  */
122 struct tty_driver;
123 extern void proc_tty_init(void);
124 extern void proc_tty_register_driver(struct tty_driver *driver);
125 extern void proc_tty_unregister_driver(struct tty_driver *driver);
126 
127 /*
128  * proc_devtree.c
129  */
130 extern void proc_device_tree_init(void);
131 
132 /*
133  * proc_rtas.c
134  */
135 extern void proc_rtas_init(void);
136 
137 /*
138  * PPC64
139  */
140 extern void proc_ppc64_init(void);
141 extern void iSeries_proc_create(void);
142 
143 extern struct proc_dir_entry *proc_symlink(const char *,
144 		struct proc_dir_entry *, const char *);
145 extern struct proc_dir_entry *proc_mknod(const char *,mode_t,
146 		struct proc_dir_entry *,kdev_t);
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 
create_proc_read_entry(const char * name,mode_t mode,struct proc_dir_entry * base,read_proc_t * read_proc,void * data)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 
create_proc_info_entry(const char * name,mode_t mode,struct proc_dir_entry * base,get_info_t * get_info)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 
proc_net_create(const char * name,mode_t mode,get_info_t * get_info)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 
proc_net_fops_create(const char * name,mode_t mode,struct file_operations * fops)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 
182 	if (res)
183 		res->proc_fops = fops;
184 	return res;
185 }
186 
proc_net_remove(const char * name)187 static inline void proc_net_remove(const char *name)
188 {
189 	remove_proc_entry(name,proc_net);
190 }
191 
192 #else
193 
194 #define proc_root_driver NULL
195 
proc_net_create(const char * name,mode_t mode,get_info_t * get_info)196 static inline struct proc_dir_entry *proc_net_create(const char *name, mode_t mode,
197 	get_info_t *get_info) {return NULL;}
proc_net_remove(const char * name)198 static inline void proc_net_remove(const char *name) {}
199 
create_proc_entry(const char * name,mode_t mode,struct proc_dir_entry * parent)200 static inline struct proc_dir_entry *create_proc_entry(const char *name,
201 	mode_t mode, struct proc_dir_entry *parent) { return NULL; }
202 
remove_proc_entry(const char * name,struct proc_dir_entry * parent)203 static inline void remove_proc_entry(const char *name, struct proc_dir_entry *parent) {};
proc_symlink(const char * name,struct proc_dir_entry * parent,char * dest)204 static inline struct proc_dir_entry *proc_symlink(const char *name,
205 		struct proc_dir_entry *parent,char *dest) {return NULL;}
proc_mknod(const char * name,mode_t mode,struct proc_dir_entry * parent,kdev_t rdev)206 static inline struct proc_dir_entry *proc_mknod(const char *name,mode_t mode,
207 		struct proc_dir_entry *parent,kdev_t rdev) {return NULL;}
proc_mkdir(const char * name,struct proc_dir_entry * parent)208 static inline struct proc_dir_entry *proc_mkdir(const char *name,
209 	struct proc_dir_entry *parent) {return NULL;}
210 
create_proc_read_entry(const char * name,mode_t mode,struct proc_dir_entry * base,int (* read_proc)(char *,char **,off_t,int,int *,void *),void * data)211 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
212 	mode_t mode, struct proc_dir_entry *base,
213 	int (*read_proc)(char *, char **, off_t, int, int *, void *),
214 	void * data) { return NULL; }
create_proc_info_entry(const char * name,mode_t mode,struct proc_dir_entry * base,get_info_t * get_info)215 static inline struct proc_dir_entry *create_proc_info_entry(const char *name,
216 	mode_t mode, struct proc_dir_entry *base, get_info_t *get_info)
217 	{ return NULL; }
218 
proc_tty_register_driver(struct tty_driver * driver)219 static inline void proc_tty_register_driver(struct tty_driver *driver) {};
proc_tty_unregister_driver(struct tty_driver * driver)220 static inline void proc_tty_unregister_driver(struct tty_driver *driver) {};
221 
222 extern struct proc_dir_entry proc_root;
223 
224 #endif /* CONFIG_PROC_FS */
225 
PDE(const struct inode * inode)226 static inline struct proc_dir_entry *PDE(const struct inode *inode)
227 {
228 	return (struct proc_dir_entry *)inode->u.generic_ip;
229 }
230 
231 #endif /* _LINUX_PROC_FS_H */
232