1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * The proc filesystem constants/structures
4*4882a593Smuzhiyun */
5*4882a593Smuzhiyun #ifndef _LINUX_PROC_FS_H
6*4882a593Smuzhiyun #define _LINUX_PROC_FS_H
7*4882a593Smuzhiyun
8*4882a593Smuzhiyun #include <linux/compiler.h>
9*4882a593Smuzhiyun #include <linux/types.h>
10*4882a593Smuzhiyun #include <linux/fs.h>
11*4882a593Smuzhiyun
12*4882a593Smuzhiyun struct proc_dir_entry;
13*4882a593Smuzhiyun struct seq_file;
14*4882a593Smuzhiyun struct seq_operations;
15*4882a593Smuzhiyun
16*4882a593Smuzhiyun enum {
17*4882a593Smuzhiyun /*
18*4882a593Smuzhiyun * All /proc entries using this ->proc_ops instance are never removed.
19*4882a593Smuzhiyun *
20*4882a593Smuzhiyun * If in doubt, ignore this flag.
21*4882a593Smuzhiyun */
22*4882a593Smuzhiyun #ifdef MODULE
23*4882a593Smuzhiyun PROC_ENTRY_PERMANENT = 0U,
24*4882a593Smuzhiyun #else
25*4882a593Smuzhiyun PROC_ENTRY_PERMANENT = 1U << 0,
26*4882a593Smuzhiyun #endif
27*4882a593Smuzhiyun };
28*4882a593Smuzhiyun
29*4882a593Smuzhiyun struct proc_ops {
30*4882a593Smuzhiyun unsigned int proc_flags;
31*4882a593Smuzhiyun int (*proc_open)(struct inode *, struct file *);
32*4882a593Smuzhiyun ssize_t (*proc_read)(struct file *, char __user *, size_t, loff_t *);
33*4882a593Smuzhiyun ssize_t (*proc_read_iter)(struct kiocb *, struct iov_iter *);
34*4882a593Smuzhiyun ssize_t (*proc_write)(struct file *, const char __user *, size_t, loff_t *);
35*4882a593Smuzhiyun loff_t (*proc_lseek)(struct file *, loff_t, int);
36*4882a593Smuzhiyun int (*proc_release)(struct inode *, struct file *);
37*4882a593Smuzhiyun __poll_t (*proc_poll)(struct file *, struct poll_table_struct *);
38*4882a593Smuzhiyun long (*proc_ioctl)(struct file *, unsigned int, unsigned long);
39*4882a593Smuzhiyun #ifdef CONFIG_COMPAT
40*4882a593Smuzhiyun long (*proc_compat_ioctl)(struct file *, unsigned int, unsigned long);
41*4882a593Smuzhiyun #endif
42*4882a593Smuzhiyun int (*proc_mmap)(struct file *, struct vm_area_struct *);
43*4882a593Smuzhiyun unsigned long (*proc_get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
44*4882a593Smuzhiyun } __randomize_layout;
45*4882a593Smuzhiyun
46*4882a593Smuzhiyun /* definitions for hide_pid field */
47*4882a593Smuzhiyun enum proc_hidepid {
48*4882a593Smuzhiyun HIDEPID_OFF = 0,
49*4882a593Smuzhiyun HIDEPID_NO_ACCESS = 1,
50*4882a593Smuzhiyun HIDEPID_INVISIBLE = 2,
51*4882a593Smuzhiyun HIDEPID_NOT_PTRACEABLE = 4, /* Limit pids to only ptraceable pids */
52*4882a593Smuzhiyun };
53*4882a593Smuzhiyun
54*4882a593Smuzhiyun /* definitions for proc mount option pidonly */
55*4882a593Smuzhiyun enum proc_pidonly {
56*4882a593Smuzhiyun PROC_PIDONLY_OFF = 0,
57*4882a593Smuzhiyun PROC_PIDONLY_ON = 1,
58*4882a593Smuzhiyun };
59*4882a593Smuzhiyun
60*4882a593Smuzhiyun struct proc_fs_info {
61*4882a593Smuzhiyun struct pid_namespace *pid_ns;
62*4882a593Smuzhiyun struct dentry *proc_self; /* For /proc/self */
63*4882a593Smuzhiyun struct dentry *proc_thread_self; /* For /proc/thread-self */
64*4882a593Smuzhiyun kgid_t pid_gid;
65*4882a593Smuzhiyun enum proc_hidepid hide_pid;
66*4882a593Smuzhiyun enum proc_pidonly pidonly;
67*4882a593Smuzhiyun };
68*4882a593Smuzhiyun
proc_sb_info(struct super_block * sb)69*4882a593Smuzhiyun static inline struct proc_fs_info *proc_sb_info(struct super_block *sb)
70*4882a593Smuzhiyun {
71*4882a593Smuzhiyun return sb->s_fs_info;
72*4882a593Smuzhiyun }
73*4882a593Smuzhiyun
74*4882a593Smuzhiyun #ifdef CONFIG_PROC_FS
75*4882a593Smuzhiyun
76*4882a593Smuzhiyun typedef int (*proc_write_t)(struct file *, char *, size_t);
77*4882a593Smuzhiyun
78*4882a593Smuzhiyun extern void proc_root_init(void);
79*4882a593Smuzhiyun extern void proc_flush_pid(struct pid *);
80*4882a593Smuzhiyun
81*4882a593Smuzhiyun extern struct proc_dir_entry *proc_symlink(const char *,
82*4882a593Smuzhiyun struct proc_dir_entry *, const char *);
83*4882a593Smuzhiyun struct proc_dir_entry *_proc_mkdir(const char *, umode_t, struct proc_dir_entry *, void *, bool);
84*4882a593Smuzhiyun extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *);
85*4882a593Smuzhiyun extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
86*4882a593Smuzhiyun struct proc_dir_entry *, void *);
87*4882a593Smuzhiyun extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
88*4882a593Smuzhiyun struct proc_dir_entry *);
89*4882a593Smuzhiyun struct proc_dir_entry *proc_create_mount_point(const char *name);
90*4882a593Smuzhiyun
91*4882a593Smuzhiyun struct proc_dir_entry *proc_create_seq_private(const char *name, umode_t mode,
92*4882a593Smuzhiyun struct proc_dir_entry *parent, const struct seq_operations *ops,
93*4882a593Smuzhiyun unsigned int state_size, void *data);
94*4882a593Smuzhiyun #define proc_create_seq_data(name, mode, parent, ops, data) \
95*4882a593Smuzhiyun proc_create_seq_private(name, mode, parent, ops, 0, data)
96*4882a593Smuzhiyun #define proc_create_seq(name, mode, parent, ops) \
97*4882a593Smuzhiyun proc_create_seq_private(name, mode, parent, ops, 0, NULL)
98*4882a593Smuzhiyun struct proc_dir_entry *proc_create_single_data(const char *name, umode_t mode,
99*4882a593Smuzhiyun struct proc_dir_entry *parent,
100*4882a593Smuzhiyun int (*show)(struct seq_file *, void *), void *data);
101*4882a593Smuzhiyun #define proc_create_single(name, mode, parent, show) \
102*4882a593Smuzhiyun proc_create_single_data(name, mode, parent, show, NULL)
103*4882a593Smuzhiyun
104*4882a593Smuzhiyun extern struct proc_dir_entry *proc_create_data(const char *, umode_t,
105*4882a593Smuzhiyun struct proc_dir_entry *,
106*4882a593Smuzhiyun const struct proc_ops *,
107*4882a593Smuzhiyun void *);
108*4882a593Smuzhiyun
109*4882a593Smuzhiyun struct proc_dir_entry *proc_create(const char *name, umode_t mode, struct proc_dir_entry *parent, const struct proc_ops *proc_ops);
110*4882a593Smuzhiyun extern void proc_set_size(struct proc_dir_entry *, loff_t);
111*4882a593Smuzhiyun extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
112*4882a593Smuzhiyun extern void *PDE_DATA(const struct inode *);
113*4882a593Smuzhiyun extern void *proc_get_parent_data(const struct inode *);
114*4882a593Smuzhiyun extern void proc_remove(struct proc_dir_entry *);
115*4882a593Smuzhiyun extern void remove_proc_entry(const char *, struct proc_dir_entry *);
116*4882a593Smuzhiyun extern int remove_proc_subtree(const char *, struct proc_dir_entry *);
117*4882a593Smuzhiyun
118*4882a593Smuzhiyun struct proc_dir_entry *proc_create_net_data(const char *name, umode_t mode,
119*4882a593Smuzhiyun struct proc_dir_entry *parent, const struct seq_operations *ops,
120*4882a593Smuzhiyun unsigned int state_size, void *data);
121*4882a593Smuzhiyun #define proc_create_net(name, mode, parent, ops, state_size) \
122*4882a593Smuzhiyun proc_create_net_data(name, mode, parent, ops, state_size, NULL)
123*4882a593Smuzhiyun struct proc_dir_entry *proc_create_net_single(const char *name, umode_t mode,
124*4882a593Smuzhiyun struct proc_dir_entry *parent,
125*4882a593Smuzhiyun int (*show)(struct seq_file *, void *), void *data);
126*4882a593Smuzhiyun struct proc_dir_entry *proc_create_net_data_write(const char *name, umode_t mode,
127*4882a593Smuzhiyun struct proc_dir_entry *parent,
128*4882a593Smuzhiyun const struct seq_operations *ops,
129*4882a593Smuzhiyun proc_write_t write,
130*4882a593Smuzhiyun unsigned int state_size, void *data);
131*4882a593Smuzhiyun struct proc_dir_entry *proc_create_net_single_write(const char *name, umode_t mode,
132*4882a593Smuzhiyun struct proc_dir_entry *parent,
133*4882a593Smuzhiyun int (*show)(struct seq_file *, void *),
134*4882a593Smuzhiyun proc_write_t write,
135*4882a593Smuzhiyun void *data);
136*4882a593Smuzhiyun extern struct pid *tgid_pidfd_to_pid(const struct file *file);
137*4882a593Smuzhiyun
138*4882a593Smuzhiyun struct bpf_iter_aux_info;
139*4882a593Smuzhiyun extern int bpf_iter_init_seq_net(void *priv_data, struct bpf_iter_aux_info *aux);
140*4882a593Smuzhiyun extern void bpf_iter_fini_seq_net(void *priv_data);
141*4882a593Smuzhiyun
142*4882a593Smuzhiyun #ifdef CONFIG_PROC_PID_ARCH_STATUS
143*4882a593Smuzhiyun /*
144*4882a593Smuzhiyun * The architecture which selects CONFIG_PROC_PID_ARCH_STATUS must
145*4882a593Smuzhiyun * provide proc_pid_arch_status() definition.
146*4882a593Smuzhiyun */
147*4882a593Smuzhiyun int proc_pid_arch_status(struct seq_file *m, struct pid_namespace *ns,
148*4882a593Smuzhiyun struct pid *pid, struct task_struct *task);
149*4882a593Smuzhiyun #endif /* CONFIG_PROC_PID_ARCH_STATUS */
150*4882a593Smuzhiyun
151*4882a593Smuzhiyun #else /* CONFIG_PROC_FS */
152*4882a593Smuzhiyun
proc_root_init(void)153*4882a593Smuzhiyun static inline void proc_root_init(void)
154*4882a593Smuzhiyun {
155*4882a593Smuzhiyun }
156*4882a593Smuzhiyun
proc_flush_pid(struct pid * pid)157*4882a593Smuzhiyun static inline void proc_flush_pid(struct pid *pid)
158*4882a593Smuzhiyun {
159*4882a593Smuzhiyun }
160*4882a593Smuzhiyun
proc_symlink(const char * name,struct proc_dir_entry * parent,const char * dest)161*4882a593Smuzhiyun static inline struct proc_dir_entry *proc_symlink(const char *name,
162*4882a593Smuzhiyun struct proc_dir_entry *parent,const char *dest) { return NULL;}
proc_mkdir(const char * name,struct proc_dir_entry * parent)163*4882a593Smuzhiyun static inline struct proc_dir_entry *proc_mkdir(const char *name,
164*4882a593Smuzhiyun struct proc_dir_entry *parent) {return NULL;}
proc_create_mount_point(const char * name)165*4882a593Smuzhiyun static inline struct proc_dir_entry *proc_create_mount_point(const char *name) { return NULL; }
_proc_mkdir(const char * name,umode_t mode,struct proc_dir_entry * parent,void * data,bool force_lookup)166*4882a593Smuzhiyun static inline struct proc_dir_entry *_proc_mkdir(const char *name, umode_t mode,
167*4882a593Smuzhiyun struct proc_dir_entry *parent, void *data, bool force_lookup)
168*4882a593Smuzhiyun {
169*4882a593Smuzhiyun return NULL;
170*4882a593Smuzhiyun }
proc_mkdir_data(const char * name,umode_t mode,struct proc_dir_entry * parent,void * data)171*4882a593Smuzhiyun static inline struct proc_dir_entry *proc_mkdir_data(const char *name,
172*4882a593Smuzhiyun umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
proc_mkdir_mode(const char * name,umode_t mode,struct proc_dir_entry * parent)173*4882a593Smuzhiyun static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
174*4882a593Smuzhiyun umode_t mode, struct proc_dir_entry *parent) { return NULL; }
175*4882a593Smuzhiyun #define proc_create_seq_private(name, mode, parent, ops, size, data) ({NULL;})
176*4882a593Smuzhiyun #define proc_create_seq_data(name, mode, parent, ops, data) ({NULL;})
177*4882a593Smuzhiyun #define proc_create_seq(name, mode, parent, ops) ({NULL;})
178*4882a593Smuzhiyun #define proc_create_single(name, mode, parent, show) ({NULL;})
179*4882a593Smuzhiyun #define proc_create_single_data(name, mode, parent, show, data) ({NULL;})
180*4882a593Smuzhiyun #define proc_create(name, mode, parent, proc_ops) ({NULL;})
181*4882a593Smuzhiyun #define proc_create_data(name, mode, parent, proc_ops, data) ({NULL;})
182*4882a593Smuzhiyun
proc_set_size(struct proc_dir_entry * de,loff_t size)183*4882a593Smuzhiyun static inline void proc_set_size(struct proc_dir_entry *de, loff_t size) {}
proc_set_user(struct proc_dir_entry * de,kuid_t uid,kgid_t gid)184*4882a593Smuzhiyun static inline void proc_set_user(struct proc_dir_entry *de, kuid_t uid, kgid_t gid) {}
PDE_DATA(const struct inode * inode)185*4882a593Smuzhiyun static inline void *PDE_DATA(const struct inode *inode) {BUG(); return NULL;}
proc_get_parent_data(const struct inode * inode)186*4882a593Smuzhiyun static inline void *proc_get_parent_data(const struct inode *inode) { BUG(); return NULL; }
187*4882a593Smuzhiyun
proc_remove(struct proc_dir_entry * de)188*4882a593Smuzhiyun static inline void proc_remove(struct proc_dir_entry *de) {}
189*4882a593Smuzhiyun #define remove_proc_entry(name, parent) do {} while (0)
remove_proc_subtree(const char * name,struct proc_dir_entry * parent)190*4882a593Smuzhiyun static inline int remove_proc_subtree(const char *name, struct proc_dir_entry *parent) { return 0; }
191*4882a593Smuzhiyun
192*4882a593Smuzhiyun #define proc_create_net_data(name, mode, parent, ops, state_size, data) ({NULL;})
193*4882a593Smuzhiyun #define proc_create_net(name, mode, parent, state_size, ops) ({NULL;})
194*4882a593Smuzhiyun #define proc_create_net_single(name, mode, parent, show, data) ({NULL;})
195*4882a593Smuzhiyun
tgid_pidfd_to_pid(const struct file * file)196*4882a593Smuzhiyun static inline struct pid *tgid_pidfd_to_pid(const struct file *file)
197*4882a593Smuzhiyun {
198*4882a593Smuzhiyun return ERR_PTR(-EBADF);
199*4882a593Smuzhiyun }
200*4882a593Smuzhiyun
201*4882a593Smuzhiyun #endif /* CONFIG_PROC_FS */
202*4882a593Smuzhiyun
203*4882a593Smuzhiyun struct net;
204*4882a593Smuzhiyun
proc_net_mkdir(struct net * net,const char * name,struct proc_dir_entry * parent)205*4882a593Smuzhiyun static inline struct proc_dir_entry *proc_net_mkdir(
206*4882a593Smuzhiyun struct net *net, const char *name, struct proc_dir_entry *parent)
207*4882a593Smuzhiyun {
208*4882a593Smuzhiyun return _proc_mkdir(name, 0, parent, net, true);
209*4882a593Smuzhiyun }
210*4882a593Smuzhiyun
211*4882a593Smuzhiyun struct ns_common;
212*4882a593Smuzhiyun int open_related_ns(struct ns_common *ns,
213*4882a593Smuzhiyun struct ns_common *(*get_ns)(struct ns_common *ns));
214*4882a593Smuzhiyun
215*4882a593Smuzhiyun /* get the associated pid namespace for a file in procfs */
proc_pid_ns(struct super_block * sb)216*4882a593Smuzhiyun static inline struct pid_namespace *proc_pid_ns(struct super_block *sb)
217*4882a593Smuzhiyun {
218*4882a593Smuzhiyun return proc_sb_info(sb)->pid_ns;
219*4882a593Smuzhiyun }
220*4882a593Smuzhiyun
221*4882a593Smuzhiyun bool proc_ns_file(const struct file *file);
222*4882a593Smuzhiyun
223*4882a593Smuzhiyun #endif /* _LINUX_PROC_FS_H */
224