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