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