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