proc: Supply PDE attribute setting accessor functions
[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 void proc_set_size(struct proc_dir_entry *, loff_t);
134 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
135
136 extern struct file *proc_ns_fget(int fd);
137 extern bool proc_ns_inode(struct inode *inode);
138
139 extern int proc_alloc_inum(unsigned int *pino);
140 extern void proc_free_inum(unsigned int inum);
141 #else
142
143 static inline void proc_flush_task(struct task_struct *task)
144 {
145 }
146
147 #define proc_create(name, mode, parent, fops)  ({ (void)(mode), NULL; })
148
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)
152 {
153         return NULL;
154 }
155 #define remove_proc_entry(name, parent) do {} while (0)
156 #define remove_proc_subtree(name, parent) do {} while (0)
157
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) {}
166
167 struct tty_driver;
168 static inline void proc_tty_register_driver(struct tty_driver *driver) {};
169 static inline void proc_tty_unregister_driver(struct tty_driver *driver) {};
170
171 static inline int pid_ns_prepare_proc(struct pid_namespace *ns)
172 {
173         return 0;
174 }
175
176 static inline void pid_ns_release_proc(struct pid_namespace *ns)
177 {
178 }
179
180 static inline struct file *proc_ns_fget(int fd)
181 {
182         return ERR_PTR(-EINVAL);
183 }
184
185 static inline bool proc_ns_inode(struct inode *inode)
186 {
187         return false;
188 }
189
190 static inline int proc_alloc_inum(unsigned int *inum)
191 {
192         *inum = 1;
193         return 0;
194 }
195 static inline void proc_free_inum(unsigned int inum)
196 {
197 }
198 #endif /* CONFIG_PROC_FS */
199
200 struct nsproxy;
201 struct proc_ns_operations {
202         const char *name;
203         int type;
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);
208 };
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;
215
216 union proc_op {
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);
222 };
223
224 struct ctl_table_header;
225 struct ctl_table;
226
227 struct proc_inode {
228         struct pid *pid;
229         int fd;
230         union proc_op op;
231         struct proc_dir_entry *pde;
232         struct ctl_table_header *sysctl;
233         struct ctl_table *sysctl_entry;
234         void *ns;
235         const struct proc_ns_operations *ns_ops;
236         struct inode vfs_inode;
237 };
238
239 static inline struct proc_inode *PROC_I(const struct inode *inode)
240 {
241         return container_of(inode, struct proc_inode, vfs_inode);
242 }
243
244 static inline struct proc_dir_entry *PDE(const struct inode *inode)
245 {
246         return PROC_I(inode)->pde;
247 }
248
249 static inline void *PDE_DATA(const struct inode *inode)
250 {
251         return PROC_I(inode)->pde->data;
252 }
253
254 static inline struct net *PDE_NET(struct proc_dir_entry *pde)
255 {
256         return pde->parent->data;
257 }
258
259 #include <linux/signal.h>
260
261 void render_sigset_t(struct seq_file *m, const char *header, sigset_t *set);
262 #endif /* _LINUX_PROC_FS_H */