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