GNU Linux-libre 4.19.245-gnu1
[releases.git] / include / linux / proc_fs.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * The proc filesystem constants/structures
4  */
5 #ifndef _LINUX_PROC_FS_H
6 #define _LINUX_PROC_FS_H
7
8 #include <linux/types.h>
9 #include <linux/fs.h>
10
11 struct proc_dir_entry;
12 struct seq_file;
13 struct seq_operations;
14
15 #ifdef CONFIG_PROC_FS
16
17 typedef int (*proc_write_t)(struct file *, char *, size_t);
18
19 extern void proc_root_init(void);
20 extern void proc_flush_task(struct task_struct *);
21
22 extern struct proc_dir_entry *proc_symlink(const char *,
23                 struct proc_dir_entry *, const char *);
24 struct proc_dir_entry *_proc_mkdir(const char *, umode_t, struct proc_dir_entry *, void *, bool);
25 extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *);
26 extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
27                                               struct proc_dir_entry *, void *);
28 extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
29                                               struct proc_dir_entry *);
30 struct proc_dir_entry *proc_create_mount_point(const char *name);
31
32 struct proc_dir_entry *proc_create_seq_private(const char *name, umode_t mode,
33                 struct proc_dir_entry *parent, const struct seq_operations *ops,
34                 unsigned int state_size, void *data);
35 #define proc_create_seq_data(name, mode, parent, ops, data) \
36         proc_create_seq_private(name, mode, parent, ops, 0, data)
37 #define proc_create_seq(name, mode, parent, ops) \
38         proc_create_seq_private(name, mode, parent, ops, 0, NULL)
39 struct proc_dir_entry *proc_create_single_data(const char *name, umode_t mode,
40                 struct proc_dir_entry *parent,
41                 int (*show)(struct seq_file *, void *), void *data);
42 #define proc_create_single(name, mode, parent, show) \
43         proc_create_single_data(name, mode, parent, show, NULL)
44  
45 extern struct proc_dir_entry *proc_create_data(const char *, umode_t,
46                                                struct proc_dir_entry *,
47                                                const struct file_operations *,
48                                                void *);
49
50 struct proc_dir_entry *proc_create(const char *name, umode_t mode, struct proc_dir_entry *parent, const struct file_operations *proc_fops);
51 extern void proc_set_size(struct proc_dir_entry *, loff_t);
52 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
53 extern void *PDE_DATA(const struct inode *);
54 extern void *proc_get_parent_data(const struct inode *);
55 extern void proc_remove(struct proc_dir_entry *);
56 extern void remove_proc_entry(const char *, struct proc_dir_entry *);
57 extern int remove_proc_subtree(const char *, struct proc_dir_entry *);
58
59 struct proc_dir_entry *proc_create_net_data(const char *name, umode_t mode,
60                 struct proc_dir_entry *parent, const struct seq_operations *ops,
61                 unsigned int state_size, void *data);
62 #define proc_create_net(name, mode, parent, state_size, ops) \
63         proc_create_net_data(name, mode, parent, state_size, ops, NULL)
64 struct proc_dir_entry *proc_create_net_single(const char *name, umode_t mode,
65                 struct proc_dir_entry *parent,
66                 int (*show)(struct seq_file *, void *), void *data);
67 struct proc_dir_entry *proc_create_net_data_write(const char *name, umode_t mode,
68                                                   struct proc_dir_entry *parent,
69                                                   const struct seq_operations *ops,
70                                                   proc_write_t write,
71                                                   unsigned int state_size, void *data);
72 struct proc_dir_entry *proc_create_net_single_write(const char *name, umode_t mode,
73                                                     struct proc_dir_entry *parent,
74                                                     int (*show)(struct seq_file *, void *),
75                                                     proc_write_t write,
76                                                     void *data);
77
78 #else /* CONFIG_PROC_FS */
79
80 static inline void proc_root_init(void)
81 {
82 }
83
84 static inline void proc_flush_task(struct task_struct *task)
85 {
86 }
87
88 static inline struct proc_dir_entry *proc_symlink(const char *name,
89                 struct proc_dir_entry *parent,const char *dest) { return NULL;}
90 static inline struct proc_dir_entry *proc_mkdir(const char *name,
91         struct proc_dir_entry *parent) {return NULL;}
92 static inline struct proc_dir_entry *proc_create_mount_point(const char *name) { return NULL; }
93 static inline struct proc_dir_entry *_proc_mkdir(const char *name, umode_t mode,
94                 struct proc_dir_entry *parent, void *data, bool force_lookup)
95 {
96         return NULL;
97 }
98 static inline struct proc_dir_entry *proc_mkdir_data(const char *name,
99         umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
100 static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
101         umode_t mode, struct proc_dir_entry *parent) { return NULL; }
102 #define proc_create_seq_private(name, mode, parent, ops, size, data) ({NULL;})
103 #define proc_create_seq_data(name, mode, parent, ops, data) ({NULL;})
104 #define proc_create_seq(name, mode, parent, ops) ({NULL;})
105 #define proc_create_single(name, mode, parent, show) ({NULL;})
106 #define proc_create_single_data(name, mode, parent, show, data) ({NULL;})
107 #define proc_create(name, mode, parent, proc_fops) ({NULL;})
108 #define proc_create_data(name, mode, parent, proc_fops, data) ({NULL;})
109
110 static inline void proc_set_size(struct proc_dir_entry *de, loff_t size) {}
111 static inline void proc_set_user(struct proc_dir_entry *de, kuid_t uid, kgid_t gid) {}
112 static inline void *PDE_DATA(const struct inode *inode) {BUG(); return NULL;}
113 static inline void *proc_get_parent_data(const struct inode *inode) { BUG(); return NULL; }
114
115 static inline void proc_remove(struct proc_dir_entry *de) {}
116 #define remove_proc_entry(name, parent) do {} while (0)
117 static inline int remove_proc_subtree(const char *name, struct proc_dir_entry *parent) { return 0; }
118
119 #define proc_create_net_data(name, mode, parent, ops, state_size, data) ({NULL;})
120 #define proc_create_net(name, mode, parent, state_size, ops) ({NULL;})
121 #define proc_create_net_single(name, mode, parent, show, data) ({NULL;})
122
123 #endif /* CONFIG_PROC_FS */
124
125 struct net;
126
127 static inline struct proc_dir_entry *proc_net_mkdir(
128         struct net *net, const char *name, struct proc_dir_entry *parent)
129 {
130         return _proc_mkdir(name, 0, parent, net, true);
131 }
132
133 struct ns_common;
134 int open_related_ns(struct ns_common *ns,
135                    struct ns_common *(*get_ns)(struct ns_common *ns));
136
137 /* get the associated pid namespace for a file in procfs */
138 static inline struct pid_namespace *proc_pid_ns(const struct inode *inode)
139 {
140         return inode->i_sb->s_fs_info;
141 }
142
143 #endif /* _LINUX_PROC_FS_H */