Merge tag 'io_uring-6.16-20250630' of git://git.kernel.dk/linux
[linux-block.git] / include / linux / proc_fs.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
1da177e4
LT
2/*
3 * The proc filesystem constants/structures
4 */
59d8053f
DH
5#ifndef _LINUX_PROC_FS_H
6#define _LINUX_PROC_FS_H
1da177e4 7
d919b33d 8#include <linux/compiler.h>
59d8053f
DH
9#include <linux/types.h>
10#include <linux/fs.h>
1da177e4 11
59d8053f 12struct proc_dir_entry;
3f3942ac 13struct seq_file;
fddda2b7 14struct seq_operations;
1da177e4 15
d919b33d
AD
16enum {
17 /*
18 * All /proc entries using this ->proc_ops instance are never removed.
19 *
20 * If in doubt, ignore this flag.
21 */
22#ifdef MODULE
654b33ad 23 PROC_ENTRY_PERMANENT = 0U,
d919b33d 24#else
654b33ad 25 PROC_ENTRY_PERMANENT = 1U << 0,
d919b33d 26#endif
654b33ad
YB
27
28 PROC_ENTRY_proc_read_iter = 1U << 1,
29 PROC_ENTRY_proc_compat_ioctl = 1U << 2,
d919b33d
AD
30};
31
d56c0d45 32struct proc_ops {
d919b33d 33 unsigned int proc_flags;
d56c0d45
AD
34 int (*proc_open)(struct inode *, struct file *);
35 ssize_t (*proc_read)(struct file *, char __user *, size_t, loff_t *);
fd5a13f4 36 ssize_t (*proc_read_iter)(struct kiocb *, struct iov_iter *);
d56c0d45 37 ssize_t (*proc_write)(struct file *, const char __user *, size_t, loff_t *);
d4455fac 38 /* mandatory unless nonseekable_open() or equivalent is used */
d56c0d45
AD
39 loff_t (*proc_lseek)(struct file *, loff_t, int);
40 int (*proc_release)(struct inode *, struct file *);
41 __poll_t (*proc_poll)(struct file *, struct poll_table_struct *);
42 long (*proc_ioctl)(struct file *, unsigned int, unsigned long);
43#ifdef CONFIG_COMPAT
44 long (*proc_compat_ioctl)(struct file *, unsigned int, unsigned long);
45#endif
46 int (*proc_mmap)(struct file *, struct vm_area_struct *);
47 unsigned long (*proc_get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
d919b33d 48} __randomize_layout;
d56c0d45 49
fa10fed3 50/* definitions for hide_pid field */
e61bb8b3 51enum proc_hidepid {
fa10fed3
AG
52 HIDEPID_OFF = 0,
53 HIDEPID_NO_ACCESS = 1,
54 HIDEPID_INVISIBLE = 2,
24a71ce5 55 HIDEPID_NOT_PTRACEABLE = 4, /* Limit pids to only ptraceable pids */
fa10fed3
AG
56};
57
6814ef2d 58/* definitions for proc mount option pidonly */
e61bb8b3 59enum proc_pidonly {
6814ef2d
AG
60 PROC_PIDONLY_OFF = 0,
61 PROC_PIDONLY_ON = 1,
62};
63
fa10fed3
AG
64struct proc_fs_info {
65 struct pid_namespace *pid_ns;
66 struct dentry *proc_self; /* For /proc/self */
67 struct dentry *proc_thread_self; /* For /proc/thread-self */
68 kgid_t pid_gid;
e61bb8b3
AG
69 enum proc_hidepid hide_pid;
70 enum proc_pidonly pidonly;
e31f0a57 71 struct rcu_head rcu;
fa10fed3
AG
72};
73
74static inline struct proc_fs_info *proc_sb_info(struct super_block *sb)
75{
76 return sb->s_fs_info;
77}
78
1da177e4
LT
79#ifdef CONFIG_PROC_FS
80
564def71
DH
81typedef int (*proc_write_t)(struct file *, char *, size_t);
82
1da177e4 83extern void proc_root_init(void);
7bc3e6e5 84extern void proc_flush_pid(struct pid *);
1da177e4 85
1da177e4
LT
86extern struct proc_dir_entry *proc_symlink(const char *,
87 struct proc_dir_entry *, const char *);
c6c75ded 88struct proc_dir_entry *_proc_mkdir(const char *, umode_t, struct proc_dir_entry *, void *, bool);
59d8053f 89extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *);
270b5ac2
DH
90extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
91 struct proc_dir_entry *, void *);
59d8053f
DH
92extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
93 struct proc_dir_entry *);
f97df70b 94struct proc_dir_entry *proc_create_mount_point(const char *name);
fddda2b7 95
44414d82 96struct proc_dir_entry *proc_create_seq_private(const char *name, umode_t mode,
fddda2b7 97 struct proc_dir_entry *parent, const struct seq_operations *ops,
44414d82
CH
98 unsigned int state_size, void *data);
99#define proc_create_seq_data(name, mode, parent, ops, data) \
100 proc_create_seq_private(name, mode, parent, ops, 0, data)
fddda2b7 101#define proc_create_seq(name, mode, parent, ops) \
44414d82 102 proc_create_seq_private(name, mode, parent, ops, 0, NULL)
3f3942ac
CH
103struct proc_dir_entry *proc_create_single_data(const char *name, umode_t mode,
104 struct proc_dir_entry *parent,
105 int (*show)(struct seq_file *, void *), void *data);
106#define proc_create_single(name, mode, parent, show) \
107 proc_create_single_data(name, mode, parent, show, NULL)
59d8053f
DH
108
109extern struct proc_dir_entry *proc_create_data(const char *, umode_t,
110 struct proc_dir_entry *,
d56c0d45 111 const struct proc_ops *,
59d8053f
DH
112 void *);
113
d56c0d45 114struct proc_dir_entry *proc_create(const char *name, umode_t mode, struct proc_dir_entry *parent, const struct proc_ops *proc_ops);
271a15ea
DH
115extern void proc_set_size(struct proc_dir_entry *, loff_t);
116extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
6dfbbae1
MS
117
118/*
119 * Obtain the private data passed by user through proc_create_data() or
120 * related.
121 */
122static inline void *pde_data(const struct inode *inode)
123{
124 return inode->i_private;
125}
126
4a520d27 127extern void *proc_get_parent_data(const struct inode *);
59d8053f
DH
128extern void proc_remove(struct proc_dir_entry *);
129extern void remove_proc_entry(const char *, struct proc_dir_entry *);
130extern int remove_proc_subtree(const char *, struct proc_dir_entry *);
131
c3506372
CH
132struct proc_dir_entry *proc_create_net_data(const char *name, umode_t mode,
133 struct proc_dir_entry *parent, const struct seq_operations *ops,
134 unsigned int state_size, void *data);
9573e8f7
ML
135#define proc_create_net(name, mode, parent, ops, state_size) \
136 proc_create_net_data(name, mode, parent, ops, state_size, NULL)
3617d949
CH
137struct proc_dir_entry *proc_create_net_single(const char *name, umode_t mode,
138 struct proc_dir_entry *parent,
139 int (*show)(struct seq_file *, void *), void *data);
564def71
DH
140struct proc_dir_entry *proc_create_net_data_write(const char *name, umode_t mode,
141 struct proc_dir_entry *parent,
142 const struct seq_operations *ops,
143 proc_write_t write,
144 unsigned int state_size, void *data);
145struct proc_dir_entry *proc_create_net_single_write(const char *name, umode_t mode,
146 struct proc_dir_entry *parent,
147 int (*show)(struct seq_file *, void *),
148 proc_write_t write,
149 void *data);
3eb39f47 150extern struct pid *tgid_pidfd_to_pid(const struct file *file);
c3506372 151
f9c79272
YS
152struct bpf_iter_aux_info;
153extern int bpf_iter_init_seq_net(void *priv_data, struct bpf_iter_aux_info *aux);
138d0be3
YS
154extern void bpf_iter_fini_seq_net(void *priv_data);
155
68bc30bb
AL
156#ifdef CONFIG_PROC_PID_ARCH_STATUS
157/*
158 * The architecture which selects CONFIG_PROC_PID_ARCH_STATUS must
159 * provide proc_pid_arch_status() definition.
160 */
161int proc_pid_arch_status(struct seq_file *m, struct pid_namespace *ns,
162 struct pid *pid, struct task_struct *task);
163#endif /* CONFIG_PROC_PID_ARCH_STATUS */
164
ef104443 165void arch_report_meminfo(struct seq_file *m);
0ee44885 166void arch_proc_pid_thread_features(struct seq_file *m, struct task_struct *task);
ef104443 167
59d8053f 168#else /* CONFIG_PROC_FS */
1da177e4 169
647f010b
AM
170static inline void proc_root_init(void)
171{
172}
173
7bc3e6e5 174static inline void proc_flush_pid(struct pid *pid)
60347f67
PE
175{
176}
1da177e4 177
1da177e4 178static inline struct proc_dir_entry *proc_symlink(const char *name,
59d8053f 179 struct proc_dir_entry *parent,const char *dest) { return NULL;}
1da177e4
LT
180static inline struct proc_dir_entry *proc_mkdir(const char *name,
181 struct proc_dir_entry *parent) {return NULL;}
f97df70b 182static inline struct proc_dir_entry *proc_create_mount_point(const char *name) { return NULL; }
c6c75ded
AD
183static inline struct proc_dir_entry *_proc_mkdir(const char *name, umode_t mode,
184 struct proc_dir_entry *parent, void *data, bool force_lookup)
185{
186 return NULL;
187}
270b5ac2
DH
188static inline struct proc_dir_entry *proc_mkdir_data(const char *name,
189 umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
f12a20fc 190static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
d161a13f 191 umode_t mode, struct proc_dir_entry *parent) { return NULL; }
3f3942ac 192#define proc_create_seq_private(name, mode, parent, ops, size, data) ({NULL;})
fddda2b7
CH
193#define proc_create_seq_data(name, mode, parent, ops, data) ({NULL;})
194#define proc_create_seq(name, mode, parent, ops) ({NULL;})
3f3942ac
CH
195#define proc_create_single(name, mode, parent, show) ({NULL;})
196#define proc_create_single_data(name, mode, parent, show, data) ({NULL;})
ae62fbe2
HG
197
198static inline struct proc_dir_entry *
199proc_create(const char *name, umode_t mode, struct proc_dir_entry *parent,
200 const struct proc_ops *proc_ops)
201{ return NULL; }
202
203static inline struct proc_dir_entry *
204proc_create_data(const char *name, umode_t mode, struct proc_dir_entry *parent,
205 const struct proc_ops *proc_ops, void *data)
206{ return NULL; }
59d8053f 207
271a15ea
DH
208static inline void proc_set_size(struct proc_dir_entry *de, loff_t size) {}
209static inline void proc_set_user(struct proc_dir_entry *de, kuid_t uid, kgid_t gid) {}
359745d7 210static inline void *pde_data(const struct inode *inode) {BUG(); return NULL;}
59d8053f 211static inline void *proc_get_parent_data(const struct inode *inode) { BUG(); return NULL; }
1da177e4 212
59d8053f
DH
213static inline void proc_remove(struct proc_dir_entry *de) {}
214#define remove_proc_entry(name, parent) do {} while (0)
215static inline int remove_proc_subtree(const char *name, struct proc_dir_entry *parent) { return 0; }
9043476f 216
c3506372 217#define proc_create_net_data(name, mode, parent, ops, state_size, data) ({NULL;})
c3d96f69 218#define proc_create_net_data_write(name, mode, parent, ops, write, state_size, data) ({NULL;})
c3506372 219#define proc_create_net(name, mode, parent, state_size, ops) ({NULL;})
3617d949 220#define proc_create_net_single(name, mode, parent, show, data) ({NULL;})
c3d96f69 221#define proc_create_net_single_write(name, mode, parent, show, write, data) ({NULL;})
c3506372 222
3eb39f47
CB
223static inline struct pid *tgid_pidfd_to_pid(const struct file *file)
224{
225 return ERR_PTR(-EBADF);
226}
227
59d8053f 228#endif /* CONFIG_PROC_FS */
1da177e4 229
f7790029
JL
230struct net;
231
270b5ac2
DH
232static inline struct proc_dir_entry *proc_net_mkdir(
233 struct net *net, const char *name, struct proc_dir_entry *parent)
234{
c6c75ded 235 return _proc_mkdir(name, 0, parent, net, true);
270b5ac2
DH
236}
237
c62cce2c
AV
238struct ns_common;
239int open_related_ns(struct ns_common *ns,
240 struct ns_common *(*get_ns)(struct ns_common *ns));
241
76f668be 242/* get the associated pid namespace for a file in procfs */
9d78edea 243static inline struct pid_namespace *proc_pid_ns(struct super_block *sb)
76f668be 244{
9d78edea 245 return proc_sb_info(sb)->pid_ns;
76f668be
CH
246}
247
303cc571
CB
248bool proc_ns_file(const struct file *file);
249
1da177e4 250#endif /* _LINUX_PROC_FS_H */