File Index
Files and directories
Sign in
FILE

proc_fs.h

File preview with syntax highlighting.

linux-6.19.14/include/linux/proc_fs.h C
  1/* SPDX-License-Identifier: GPL-2.0 */
  2/*
  3 * The proc filesystem constants/structures
  4 */
  5#ifndef _LINUX_PROC_FS_H
  6#define _LINUX_PROC_FS_H
  7
  8#include <linux/compiler.h>
  9#include <linux/types.h>
 10#include <linux/fs.h>
 11
 12struct proc_dir_entry;
 13struct seq_file;
 14struct seq_operations;
 15
 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	PROC_ENTRY_proc_read_iter	= 1U << 1,
 29	PROC_ENTRY_proc_compat_ioctl	= 1U << 2,
 30	PROC_ENTRY_proc_lseek		= 1U << 3,
 31
 32	PROC_ENTRY_FORCE_LOOKUP		= 1U << 7,
 33};
 34
 35struct proc_ops {
 36	unsigned int proc_flags;
 37	int	(*proc_open)(struct inode *, struct file *);
 38	ssize_t	(*proc_read)(struct file *, char __user *, size_t, loff_t *);
 39	ssize_t (*proc_read_iter)(struct kiocb *, struct iov_iter *);
 40	ssize_t	(*proc_write)(struct file *, const char __user *, size_t, loff_t *);
 41	/* mandatory unless nonseekable_open() or equivalent is used */
 42	loff_t	(*proc_lseek)(struct file *, loff_t, int);
 43	int	(*proc_release)(struct inode *, struct file *);
 44	__poll_t (*proc_poll)(struct file *, struct poll_table_struct *);
 45	long	(*proc_ioctl)(struct file *, unsigned int, unsigned long);
 46#ifdef CONFIG_COMPAT
 47	long	(*proc_compat_ioctl)(struct file *, unsigned int, unsigned long);
 48#endif
 49	int	(*proc_mmap)(struct file *, struct vm_area_struct *);
 50	unsigned long (*proc_get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
 51} __randomize_layout;
 52
 53/* definitions for hide_pid field */
 54enum proc_hidepid {
 55	HIDEPID_OFF	  = 0,
 56	HIDEPID_NO_ACCESS = 1,
 57	HIDEPID_INVISIBLE = 2,
 58	HIDEPID_NOT_PTRACEABLE = 4, /* Limit pids to only ptraceable pids */
 59};
 60
 61/* definitions for proc mount option pidonly */
 62enum proc_pidonly {
 63	PROC_PIDONLY_OFF = 0,
 64	PROC_PIDONLY_ON  = 1,
 65};
 66
 67struct proc_fs_info {
 68	struct pid_namespace *pid_ns;
 69	kgid_t pid_gid;
 70	enum proc_hidepid hide_pid;
 71	enum proc_pidonly pidonly;
 72	struct rcu_head rcu;
 73};
 74
 75static inline struct proc_fs_info *proc_sb_info(struct super_block *sb)
 76{
 77	return sb->s_fs_info;
 78}
 79
 80#ifdef CONFIG_PROC_FS
 81
 82typedef int (*proc_write_t)(struct file *, char *, size_t);
 83
 84extern void proc_root_init(void);
 85extern void proc_flush_pid(struct pid *);
 86
 87extern struct proc_dir_entry *proc_symlink(const char *,
 88		struct proc_dir_entry *, const char *);
 89struct proc_dir_entry *_proc_mkdir(const char *, umode_t, struct proc_dir_entry *, void *, bool);
 90extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *);
 91extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
 92					      struct proc_dir_entry *, void *);
 93extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
 94					      struct proc_dir_entry *);
 95struct proc_dir_entry *proc_create_mount_point(const char *name);
 96
 97struct proc_dir_entry *proc_create_seq_private(const char *name, umode_t mode,
 98		struct proc_dir_entry *parent, const struct seq_operations *ops,
 99		unsigned int state_size, void *data);
100#define proc_create_seq_data(name, mode, parent, ops, data) \
101	proc_create_seq_private(name, mode, parent, ops, 0, data)
102#define proc_create_seq(name, mode, parent, ops) \
103	proc_create_seq_private(name, mode, parent, ops, 0, NULL)
104struct proc_dir_entry *proc_create_single_data(const char *name, umode_t mode,
105		struct proc_dir_entry *parent,
106		int (*show)(struct seq_file *, void *), void *data);
107#define proc_create_single(name, mode, parent, show) \
108	proc_create_single_data(name, mode, parent, show, NULL)
109 
110extern struct proc_dir_entry *proc_create_data(const char *, umode_t,
111					       struct proc_dir_entry *,
112					       const struct proc_ops *,
113					       void *);
114
115struct proc_dir_entry *proc_create(const char *name, umode_t mode, struct proc_dir_entry *parent, const struct proc_ops *proc_ops);
116extern void proc_set_size(struct proc_dir_entry *, loff_t);
117extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
118
119/*
120 * Obtain the private data passed by user through proc_create_data() or
121 * related.
122 */
123static inline void *pde_data(const struct inode *inode)
124{
125	return inode->i_private;
126}
127
128extern void *proc_get_parent_data(const struct inode *);
129extern void proc_remove(struct proc_dir_entry *);
130extern void remove_proc_entry(const char *, struct proc_dir_entry *);
131extern int remove_proc_subtree(const char *, struct proc_dir_entry *);
132
133struct proc_dir_entry *proc_create_net_data(const char *name, umode_t mode,
134		struct proc_dir_entry *parent, const struct seq_operations *ops,
135		unsigned int state_size, void *data);
136#define proc_create_net(name, mode, parent, ops, state_size) \
137	proc_create_net_data(name, mode, parent, ops, state_size, NULL)
138struct proc_dir_entry *proc_create_net_single(const char *name, umode_t mode,
139		struct proc_dir_entry *parent,
140		int (*show)(struct seq_file *, void *), void *data);
141struct proc_dir_entry *proc_create_net_data_write(const char *name, umode_t mode,
142						  struct proc_dir_entry *parent,
143						  const struct seq_operations *ops,
144						  proc_write_t write,
145						  unsigned int state_size, void *data);
146struct proc_dir_entry *proc_create_net_single_write(const char *name, umode_t mode,
147						    struct proc_dir_entry *parent,
148						    int (*show)(struct seq_file *, void *),
149						    proc_write_t write,
150						    void *data);
151extern struct pid *tgid_pidfd_to_pid(const struct file *file);
152
153struct bpf_iter_aux_info;
154extern int bpf_iter_init_seq_net(void *priv_data, struct bpf_iter_aux_info *aux);
155extern void bpf_iter_fini_seq_net(void *priv_data);
156
157#ifdef CONFIG_PROC_PID_ARCH_STATUS
158/*
159 * The architecture which selects CONFIG_PROC_PID_ARCH_STATUS must
160 * provide proc_pid_arch_status() definition.
161 */
162int proc_pid_arch_status(struct seq_file *m, struct pid_namespace *ns,
163			struct pid *pid, struct task_struct *task);
164#endif /* CONFIG_PROC_PID_ARCH_STATUS */
165
166void arch_report_meminfo(struct seq_file *m);
167void arch_proc_pid_thread_features(struct seq_file *m, struct task_struct *task);
168
169#else /* CONFIG_PROC_FS */
170
171static inline void proc_root_init(void)
172{
173}
174
175static inline void proc_flush_pid(struct pid *pid)
176{
177}
178
179static inline struct proc_dir_entry *proc_symlink(const char *name,
180		struct proc_dir_entry *parent,const char *dest) { return NULL;}
181static inline struct proc_dir_entry *proc_mkdir(const char *name,
182	struct proc_dir_entry *parent) {return NULL;}
183static inline struct proc_dir_entry *proc_create_mount_point(const char *name) { return NULL; }
184static inline struct proc_dir_entry *_proc_mkdir(const char *name, umode_t mode,
185		struct proc_dir_entry *parent, void *data, bool force_lookup)
186{
187	return NULL;
188}
189static inline struct proc_dir_entry *proc_mkdir_data(const char *name,
190	umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
191static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
192	umode_t mode, struct proc_dir_entry *parent) { return NULL; }
193#define proc_create_seq_private(name, mode, parent, ops, size, data) ({NULL;})
194#define proc_create_seq_data(name, mode, parent, ops, data) ({NULL;})
195#define proc_create_seq(name, mode, parent, ops) ({NULL;})
196#define proc_create_single(name, mode, parent, show) ({NULL;})
197#define proc_create_single_data(name, mode, parent, show, data) ({NULL;})
198
199static inline struct proc_dir_entry *
200proc_create(const char *name, umode_t mode, struct proc_dir_entry *parent,
201	    const struct proc_ops *proc_ops)
202{ return NULL; }
203
204static inline struct proc_dir_entry *
205proc_create_data(const char *name, umode_t mode, struct proc_dir_entry *parent,
206		 const struct proc_ops *proc_ops, void *data)
207{ return NULL; }
208
209static inline void proc_set_size(struct proc_dir_entry *de, loff_t size) {}
210static inline void proc_set_user(struct proc_dir_entry *de, kuid_t uid, kgid_t gid) {}
211static inline void *pde_data(const struct inode *inode) {BUG(); return NULL;}
212static inline void *proc_get_parent_data(const struct inode *inode) { BUG(); return NULL; }
213
214static inline void proc_remove(struct proc_dir_entry *de) {}
215#define remove_proc_entry(name, parent) do {} while (0)
216static inline int remove_proc_subtree(const char *name, struct proc_dir_entry *parent) { return 0; }
217
218#define proc_create_net_data(name, mode, parent, ops, state_size, data) ({NULL;})
219#define proc_create_net_data_write(name, mode, parent, ops, write, state_size, data) ({NULL;})
220#define proc_create_net(name, mode, parent, state_size, ops) ({NULL;})
221#define proc_create_net_single(name, mode, parent, show, data) ({NULL;})
222#define proc_create_net_single_write(name, mode, parent, show, write, data) ({NULL;})
223
224static inline struct pid *tgid_pidfd_to_pid(const struct file *file)
225{
226	return ERR_PTR(-EBADF);
227}
228
229#endif /* CONFIG_PROC_FS */
230
231struct net;
232
233static inline struct proc_dir_entry *proc_net_mkdir(
234	struct net *net, const char *name, struct proc_dir_entry *parent)
235{
236	return _proc_mkdir(name, 0, parent, net, true);
237}
238
239struct ns_common;
240int open_related_ns(struct ns_common *ns,
241		   struct ns_common *(*get_ns)(struct ns_common *ns));
242
243/* get the associated pid namespace for a file in procfs */
244static inline struct pid_namespace *proc_pid_ns(struct super_block *sb)
245{
246	return proc_sb_info(sb)->pid_ns;
247}
248
249bool proc_ns_file(const struct file *file);
250
251#endif /* _LINUX_PROC_FS_H */
~/ Read-only file preview.