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