proc: Split kcore bits from linux/procfs.h into linux/kcore.h
[platform/adaptation/renesas_rcar/renesas_kernel.git] / include / linux / proc_fs.h
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 <linux/spinlock.h>
7 #include <linux/magic.h>
8 #include <linux/atomic.h>
9
10 struct net;
11 struct completion;
12 struct mm_struct;
13
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
23 /* Worst case buffer size needed for holding an integer. */
24 #define PROC_NUMBUF 13
25
26 /*
27  * We always define these enumerators
28  */
29
30 enum {
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,
36 };
37
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).
48  */
49
50 struct proc_dir_entry {
51         unsigned int low_ino;
52         umode_t mode;
53         nlink_t nlink;
54         kuid_t uid;
55         kgid_t gid;
56         loff_t size;
57         const struct inode_operations *proc_iops;
58         const struct file_operations *proc_fops;
59         struct proc_dir_entry *next, *parent, *subdir;
60         void *data;
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 */
67         u8 namelen;
68         char name[];
69 };
70
71 #ifdef CONFIG_PROC_FS
72
73 extern void proc_root_init(void);
74
75 void proc_flush_task(struct task_struct *task);
76
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,
80                                 void *data);
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);
83
84 struct pid_namespace;
85
86 extern int pid_ns_prepare_proc(struct pid_namespace *ns);
87 extern void pid_ns_release_proc(struct pid_namespace *ns);
88
89 /*
90  * proc_tty.c
91  */
92 struct tty_driver;
93 #ifdef CONFIG_TTY
94 extern void proc_tty_init(void);
95 #else
96 static inline void proc_tty_init(void)
97 { }
98 #endif
99 extern void proc_tty_register_driver(struct tty_driver *driver);
100 extern void proc_tty_unregister_driver(struct tty_driver *driver);
101
102 /*
103  * proc_devtree.c
104  */
105 #ifdef CONFIG_PROC_DEVICETREE
106 struct device_node;
107 struct property;
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 */
117
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);
123
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)
126 {
127         return proc_create_data(name, mode, parent, proc_fops, NULL);
128 }
129  
130 extern struct proc_dir_entry *proc_net_mkdir(struct net *net, const char *name,
131         struct proc_dir_entry *parent);
132
133 extern struct file *proc_ns_fget(int fd);
134 extern bool proc_ns_inode(struct inode *inode);
135
136 extern int proc_alloc_inum(unsigned int *pino);
137 extern void proc_free_inum(unsigned int inum);
138 #else
139
140 static inline void proc_flush_task(struct task_struct *task)
141 {
142 }
143
144 #define proc_create(name, mode, parent, fops)  ({ (void)(mode), NULL; })
145
146 static inline struct proc_dir_entry *proc_create_data(const char *name,
147         umode_t mode, struct proc_dir_entry *parent,
148         const struct file_operations *proc_fops, void *data)
149 {
150         return NULL;
151 }
152 #define remove_proc_entry(name, parent) do {} while (0)
153 #define remove_proc_subtree(name, parent) do {} while (0)
154
155 static inline struct proc_dir_entry *proc_symlink(const char *name,
156                 struct proc_dir_entry *parent,const char *dest) {return NULL;}
157 static inline struct proc_dir_entry *proc_mkdir(const char *name,
158         struct proc_dir_entry *parent) {return NULL;}
159 static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
160         umode_t mode, struct proc_dir_entry *parent) { return NULL; }
161
162 struct tty_driver;
163 static inline void proc_tty_register_driver(struct tty_driver *driver) {};
164 static inline void proc_tty_unregister_driver(struct tty_driver *driver) {};
165
166 static inline int pid_ns_prepare_proc(struct pid_namespace *ns)
167 {
168         return 0;
169 }
170
171 static inline void pid_ns_release_proc(struct pid_namespace *ns)
172 {
173 }
174
175 static inline struct file *proc_ns_fget(int fd)
176 {
177         return ERR_PTR(-EINVAL);
178 }
179
180 static inline bool proc_ns_inode(struct inode *inode)
181 {
182         return false;
183 }
184
185 static inline int proc_alloc_inum(unsigned int *inum)
186 {
187         *inum = 1;
188         return 0;
189 }
190 static inline void proc_free_inum(unsigned int inum)
191 {
192 }
193 #endif /* CONFIG_PROC_FS */
194
195 struct nsproxy;
196 struct 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);
202         unsigned int (*inum)(void *ns);
203 };
204 extern const struct proc_ns_operations netns_operations;
205 extern const struct proc_ns_operations utsns_operations;
206 extern const struct proc_ns_operations ipcns_operations;
207 extern const struct proc_ns_operations pidns_operations;
208 extern const struct proc_ns_operations userns_operations;
209 extern const struct proc_ns_operations mntns_operations;
210
211 union proc_op {
212         int (*proc_get_link)(struct dentry *, struct path *);
213         int (*proc_read)(struct task_struct *task, char *page);
214         int (*proc_show)(struct seq_file *m,
215                 struct pid_namespace *ns, struct pid *pid,
216                 struct task_struct *task);
217 };
218
219 struct ctl_table_header;
220 struct ctl_table;
221
222 struct proc_inode {
223         struct pid *pid;
224         int fd;
225         union proc_op op;
226         struct proc_dir_entry *pde;
227         struct ctl_table_header *sysctl;
228         struct ctl_table *sysctl_entry;
229         void *ns;
230         const struct proc_ns_operations *ns_ops;
231         struct inode vfs_inode;
232 };
233
234 static inline struct proc_inode *PROC_I(const struct inode *inode)
235 {
236         return container_of(inode, struct proc_inode, vfs_inode);
237 }
238
239 static inline struct proc_dir_entry *PDE(const struct inode *inode)
240 {
241         return PROC_I(inode)->pde;
242 }
243
244 static inline void *PDE_DATA(const struct inode *inode)
245 {
246         return PROC_I(inode)->pde->data;
247 }
248
249 static inline struct net *PDE_NET(struct proc_dir_entry *pde)
250 {
251         return pde->parent->data;
252 }
253
254 #include <linux/signal.h>
255
256 void render_sigset_t(struct seq_file *m, const char *header, sigset_t *set);
257 #endif /* _LINUX_PROC_FS_H */