proc: Split kcore bits from linux/procfs.h into linux/kcore.h
[linux-block.git] / include / linux / proc_fs.h
CommitLineData
1da177e4
LT
1#ifndef _LINUX_PROC_FS_H
2#define _LINUX_PROC_FS_H
3
1da177e4
LT
4#include <linux/slab.h>
5#include <linux/fs.h>
64a07bd8 6#include <linux/spinlock.h>
e18fa700 7#include <linux/magic.h>
60063497 8#include <linux/atomic.h>
1da177e4 9
457c4cbc 10struct net;
786d7e16 11struct completion;
57d3c64f
BN
12struct mm_struct;
13
1da177e4
LT
14/*
15 * The proc filesystem constants/structures
16 */
17
18/*
19 * Offset of the first process in the /proc root directory..
20 */
21#define FIRST_PROCESS_ENTRY 256
22
f248dcb3
MM
23/* Worst case buffer size needed for holding an integer. */
24#define PROC_NUMBUF 13
1da177e4
LT
25
26/*
27 * We always define these enumerators
28 */
29
30enum {
98f842e6
EB
31 PROC_ROOT_INO = 1,
32 PROC_IPC_INIT_INO = 0xEFFFFFFFU,
33 PROC_UTS_INIT_INO = 0xEFFFFFFEU,
34 PROC_USER_INIT_INO = 0xEFFFFFFDU,
35 PROC_PID_INIT_INO = 0xEFFFFFFCU,
1da177e4
LT
36};
37
1da177e4
LT
38/*
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.
43 *
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).
1da177e4
LT
48 */
49
1da177e4
LT
50struct proc_dir_entry {
51 unsigned int low_ino;
d161a13f 52 umode_t mode;
1da177e4 53 nlink_t nlink;
dcb0f222
EB
54 kuid_t uid;
55 kgid_t gid;
22e6c1b3 56 loff_t size;
c5ef1c42
AV
57 const struct inode_operations *proc_iops;
58 const struct file_operations *proc_fops;
1da177e4
LT
59 struct proc_dir_entry *next, *parent, *subdir;
60 void *data;
1da177e4 61 atomic_t count; /* use count */
05c0ae21 62 atomic_t in_use; /* number of callers into module in progress; */
866ad9a7 63 /* negative -> it's going away RSN */
786d7e16 64 struct completion *pde_unload_completion;
881adb85 65 struct list_head pde_openers; /* who did ->open, but not ->release */
09570f91
DH
66 spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
67 u8 namelen;
68 char name[];
1da177e4
LT
69};
70
1da177e4
LT
71#ifdef CONFIG_PROC_FS
72
1da177e4 73extern void proc_root_init(void);
1da177e4 74
48e6484d 75void proc_flush_task(struct task_struct *task);
7695650a 76
d161a13f 77struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
2d3a4e36 78 struct proc_dir_entry *parent,
59b74351
DL
79 const struct file_operations *proc_fops,
80 void *data);
1da177e4 81extern void remove_proc_entry(const char *name, struct proc_dir_entry *parent);
8ce584c7 82extern int remove_proc_subtree(const char *name, struct proc_dir_entry *parent);
1da177e4 83
07543f5c 84struct pid_namespace;
1da177e4 85
6f4e6433
PE
86extern int pid_ns_prepare_proc(struct pid_namespace *ns);
87extern void pid_ns_release_proc(struct pid_namespace *ns);
88
1da177e4
LT
89/*
90 * proc_tty.c
91 */
92struct tty_driver;
4f73bc4d 93#ifdef CONFIG_TTY
1da177e4 94extern void proc_tty_init(void);
4f73bc4d
JM
95#else
96static inline void proc_tty_init(void)
97{ }
98#endif
1da177e4
LT
99extern void proc_tty_register_driver(struct tty_driver *driver);
100extern void proc_tty_unregister_driver(struct tty_driver *driver);
101
102/*
103 * proc_devtree.c
104 */
183d0202 105#ifdef CONFIG_PROC_DEVICETREE
1da177e4 106struct device_node;
183d0202 107struct property;
1da177e4 108extern void proc_device_tree_init(void);
1da177e4 109extern void proc_device_tree_add_node(struct device_node *, struct proc_dir_entry *);
183d0202 110extern void proc_device_tree_add_prop(struct proc_dir_entry *pde, struct property *prop);
898b5395
DB
111extern void proc_device_tree_remove_prop(struct proc_dir_entry *pde,
112 struct property *prop);
113extern void proc_device_tree_update_prop(struct proc_dir_entry *pde,
114 struct property *newprop,
115 struct property *oldprop);
1da177e4
LT
116#endif /* CONFIG_PROC_DEVICETREE */
117
118extern struct proc_dir_entry *proc_symlink(const char *,
119 struct proc_dir_entry *, const char *);
120extern struct proc_dir_entry *proc_mkdir(const char *,struct proc_dir_entry *);
d161a13f 121extern struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
1da177e4
LT
122 struct proc_dir_entry *parent);
123
d161a13f 124static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
59b74351
DL
125 struct proc_dir_entry *parent, const struct file_operations *proc_fops)
126{
127 return proc_create_data(name, mode, parent, proc_fops, NULL);
128}
1da177e4 129
e5d69b9f
DL
130extern struct proc_dir_entry *proc_net_mkdir(struct net *net, const char *name,
131 struct proc_dir_entry *parent);
1da177e4 132
6b4e306a 133extern struct file *proc_ns_fget(int fd);
8823c079 134extern bool proc_ns_inode(struct inode *inode);
6b4e306a 135
33d6dce6
EB
136extern int proc_alloc_inum(unsigned int *pino);
137extern void proc_free_inum(unsigned int inum);
1da177e4
LT
138#else
139
60347f67
PE
140static inline void proc_flush_task(struct task_struct *task)
141{
142}
1da177e4 143
4fc1a601
G
144#define proc_create(name, mode, parent, fops) ({ (void)(mode), NULL; })
145
59b74351 146static inline struct proc_dir_entry *proc_create_data(const char *name,
d161a13f 147 umode_t mode, struct proc_dir_entry *parent,
59b74351
DL
148 const struct file_operations *proc_fops, void *data)
149{
150 return NULL;
151}
1da177e4 152#define remove_proc_entry(name, parent) do {} while (0)
8ce584c7 153#define remove_proc_subtree(name, parent) do {} while (0)
1da177e4
LT
154
155static inline struct proc_dir_entry *proc_symlink(const char *name,
156 struct proc_dir_entry *parent,const char *dest) {return NULL;}
157static inline struct proc_dir_entry *proc_mkdir(const char *name,
158 struct proc_dir_entry *parent) {return NULL;}
f12a20fc 159static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
d161a13f 160 umode_t mode, struct proc_dir_entry *parent) { return NULL; }
1da177e4 161
1da177e4
LT
162struct tty_driver;
163static inline void proc_tty_register_driver(struct tty_driver *driver) {};
164static inline void proc_tty_unregister_driver(struct tty_driver *driver) {};
165
6f4e6433
PE
166static inline int pid_ns_prepare_proc(struct pid_namespace *ns)
167{
168 return 0;
169}
170
171static inline void pid_ns_release_proc(struct pid_namespace *ns)
172{
173}
174
6b4e306a
EB
175static inline struct file *proc_ns_fget(int fd)
176{
177 return ERR_PTR(-EINVAL);
178}
179
8823c079
EB
180static inline bool proc_ns_inode(struct inode *inode)
181{
182 return false;
183}
184
33d6dce6
EB
185static inline int proc_alloc_inum(unsigned int *inum)
186{
187 *inum = 1;
188 return 0;
189}
190static inline void proc_free_inum(unsigned int inum)
191{
192}
1da177e4
LT
193#endif /* CONFIG_PROC_FS */
194
6b4e306a
EB
195struct nsproxy;
196struct proc_ns_operations {
197 const char *name;
198 int type;
199 void *(*get)(struct task_struct *task);
200 void (*put)(void *ns);
201 int (*install)(struct nsproxy *nsproxy, void *ns);
98f842e6 202 unsigned int (*inum)(void *ns);
6b4e306a 203};
13b6f576 204extern const struct proc_ns_operations netns_operations;
34482e89 205extern const struct proc_ns_operations utsns_operations;
a00eaf11 206extern const struct proc_ns_operations ipcns_operations;
57e8391d 207extern const struct proc_ns_operations pidns_operations;
cde1975b 208extern const struct proc_ns_operations userns_operations;
8823c079 209extern const struct proc_ns_operations mntns_operations;
6b4e306a 210
20cdc894 211union proc_op {
7773fbc5 212 int (*proc_get_link)(struct dentry *, struct path *);
20cdc894 213 int (*proc_read)(struct task_struct *task, char *page);
be614086
EB
214 int (*proc_show)(struct seq_file *m,
215 struct pid_namespace *ns, struct pid *pid,
216 struct task_struct *task);
20cdc894
EB
217};
218
9043476f
AV
219struct ctl_table_header;
220struct ctl_table;
221
1da177e4 222struct proc_inode {
13b41b09 223 struct pid *pid;
aed7a6c4 224 int fd;
20cdc894 225 union proc_op op;
1da177e4 226 struct proc_dir_entry *pde;
9043476f
AV
227 struct ctl_table_header *sysctl;
228 struct ctl_table *sysctl_entry;
6b4e306a
EB
229 void *ns;
230 const struct proc_ns_operations *ns_ops;
1da177e4
LT
231 struct inode vfs_inode;
232};
233
234static inline struct proc_inode *PROC_I(const struct inode *inode)
235{
236 return container_of(inode, struct proc_inode, vfs_inode);
237}
238
239static inline struct proc_dir_entry *PDE(const struct inode *inode)
240{
241 return PROC_I(inode)->pde;
242}
243
d9dda78b
AV
244static inline void *PDE_DATA(const struct inode *inode)
245{
246 return PROC_I(inode)->pde->data;
247}
248
457c4cbc
EB
249static inline struct net *PDE_NET(struct proc_dir_entry *pde)
250{
251 return pde->parent->data;
252}
253
138d22b5
CG
254#include <linux/signal.h>
255
256void render_sigset_t(struct seq_file *m, const char *header, sigset_t *set);
1da177e4 257#endif /* _LINUX_PROC_FS_H */