1 #ifndef _LINUX_PROC_FS_H
2 #define _LINUX_PROC_FS_H
4 #include <linux/slab.h>
6 #include <linux/spinlock.h>
7 #include <linux/magic.h>
8 #include <linux/atomic.h>
15 * The proc filesystem constants/structures
19 * Offset of the first process in the /proc root directory..
21 #define FIRST_PROCESS_ENTRY 256
23 /* Worst case buffer size needed for holding an integer. */
24 #define PROC_NUMBUF 13
27 * We always define these enumerators
32 PROC_IPC_INIT_INO = 0xEFFFFFFFU,
33 PROC_UTS_INIT_INO = 0xEFFFFFFEU,
34 PROC_USER_INIT_INO = 0xEFFFFFFDU,
35 PROC_PID_INIT_INO = 0xEFFFFFFCU,
39 * This is not completely implemented yet. The idea is to
40 * create an in-memory tree (like the actual /proc filesystem
41 * tree) of these proc_dir_entries, so that we can dynamically
42 * add new files to /proc.
44 * The "next" pointer creates a linked list of one /proc directory,
45 * while parent/subdir create the directory structure (every
46 * /proc file has a parent, but "subdir" is NULL for all
47 * non-directory entries).
50 struct proc_dir_entry {
57 const struct inode_operations *proc_iops;
58 const struct file_operations *proc_fops;
59 struct proc_dir_entry *next, *parent, *subdir;
61 atomic_t count; /* use count */
62 atomic_t in_use; /* number of callers into module in progress; */
63 /* negative -> it's going away RSN */
64 struct completion *pde_unload_completion;
65 struct list_head pde_openers; /* who did ->open, but not ->release */
66 spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
73 extern void proc_root_init(void);
75 void proc_flush_task(struct task_struct *task);
77 struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
78 struct proc_dir_entry *parent,
79 const struct file_operations *proc_fops,
81 extern void remove_proc_entry(const char *name, struct proc_dir_entry *parent);
82 extern int remove_proc_subtree(const char *name, struct proc_dir_entry *parent);
86 extern int pid_ns_prepare_proc(struct pid_namespace *ns);
87 extern void pid_ns_release_proc(struct pid_namespace *ns);
94 extern void proc_tty_init(void);
96 static inline 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);
105 #ifdef CONFIG_PROC_DEVICETREE
108 extern void proc_device_tree_init(void);
109 extern void proc_device_tree_add_node(struct device_node *, struct proc_dir_entry *);
110 extern void proc_device_tree_add_prop(struct proc_dir_entry *pde, struct property *prop);
111 extern void proc_device_tree_remove_prop(struct proc_dir_entry *pde,
112 struct property *prop);
113 extern void proc_device_tree_update_prop(struct proc_dir_entry *pde,
114 struct property *newprop,
115 struct property *oldprop);
116 #endif /* CONFIG_PROC_DEVICETREE */
118 extern struct proc_dir_entry *proc_symlink(const char *,
119 struct proc_dir_entry *, const char *);
120 extern struct proc_dir_entry *proc_mkdir(const char *,struct proc_dir_entry *);
121 extern struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
122 struct proc_dir_entry *parent);
124 static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
125 struct proc_dir_entry *parent, const struct file_operations *proc_fops)
127 return proc_create_data(name, mode, parent, proc_fops, NULL);
130 extern struct proc_dir_entry *proc_net_mkdir(struct net *net, const char *name,
131 struct proc_dir_entry *parent);
133 extern void proc_set_size(struct proc_dir_entry *, loff_t);
134 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
136 extern struct file *proc_ns_fget(int fd);
137 extern bool proc_ns_inode(struct inode *inode);
139 extern int proc_alloc_inum(unsigned int *pino);
140 extern void proc_free_inum(unsigned int inum);
143 static inline void proc_flush_task(struct task_struct *task)
147 #define proc_create(name, mode, parent, fops) ({ (void)(mode), NULL; })
149 static inline struct proc_dir_entry *proc_create_data(const char *name,
150 umode_t mode, struct proc_dir_entry *parent,
151 const struct file_operations *proc_fops, void *data)
155 #define remove_proc_entry(name, parent) do {} while (0)
156 #define remove_proc_subtree(name, parent) do {} while (0)
158 static inline struct proc_dir_entry *proc_symlink(const char *name,
159 struct proc_dir_entry *parent,const char *dest) {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 *proc_mkdir_mode(const char *name,
163 umode_t mode, struct proc_dir_entry *parent) { return NULL; }
164 static inline void proc_set_size(struct proc_dir_entry *de, loff_t size) {}
165 static inline void proc_set_user(struct proc_dir_entry *de, kuid_t uid, kgid_t gid) {}
168 static inline void proc_tty_register_driver(struct tty_driver *driver) {};
169 static inline void proc_tty_unregister_driver(struct tty_driver *driver) {};
171 static inline int pid_ns_prepare_proc(struct pid_namespace *ns)
176 static inline void pid_ns_release_proc(struct pid_namespace *ns)
180 static inline struct file *proc_ns_fget(int fd)
182 return ERR_PTR(-EINVAL);
185 static inline bool proc_ns_inode(struct inode *inode)
190 static inline int proc_alloc_inum(unsigned int *inum)
195 static inline void proc_free_inum(unsigned int inum)
198 #endif /* CONFIG_PROC_FS */
201 struct proc_ns_operations {
204 void *(*get)(struct task_struct *task);
205 void (*put)(void *ns);
206 int (*install)(struct nsproxy *nsproxy, void *ns);
207 unsigned int (*inum)(void *ns);
209 extern const struct proc_ns_operations netns_operations;
210 extern const struct proc_ns_operations utsns_operations;
211 extern const struct proc_ns_operations ipcns_operations;
212 extern const struct proc_ns_operations pidns_operations;
213 extern const struct proc_ns_operations userns_operations;
214 extern const struct proc_ns_operations mntns_operations;
217 int (*proc_get_link)(struct dentry *, struct path *);
218 int (*proc_read)(struct task_struct *task, char *page);
219 int (*proc_show)(struct seq_file *m,
220 struct pid_namespace *ns, struct pid *pid,
221 struct task_struct *task);
224 struct ctl_table_header;
231 struct proc_dir_entry *pde;
232 struct ctl_table_header *sysctl;
233 struct ctl_table *sysctl_entry;
235 const struct proc_ns_operations *ns_ops;
236 struct inode vfs_inode;
239 static inline struct proc_inode *PROC_I(const struct inode *inode)
241 return container_of(inode, struct proc_inode, vfs_inode);
244 static inline struct proc_dir_entry *PDE(const struct inode *inode)
246 return PROC_I(inode)->pde;
249 static inline void *PDE_DATA(const struct inode *inode)
251 return PROC_I(inode)->pde->data;
254 static inline struct net *PDE_NET(struct proc_dir_entry *pde)
256 return pde->parent->data;
259 #include <linux/signal.h>
261 void render_sigset_t(struct seq_file *m, const char *header, sigset_t *set);
262 #endif /* _LINUX_PROC_FS_H */