blob: 45c05fd9c99dc67bfacd75560fc2499b3cc4f1ca [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * The proc filesystem constants/structures
4 */
David Howells59d80532013-04-11 13:34:43 +01005#ifndef _LINUX_PROC_FS_H
6#define _LINUX_PROC_FS_H
Linus Torvalds1da177e2005-04-16 15:20:36 -07007
Alexey Dobriyand919b332020-04-06 20:09:01 -07008#include <linux/compiler.h>
David Howells59d80532013-04-11 13:34:43 +01009#include <linux/types.h>
10#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011
David Howells59d80532013-04-11 13:34:43 +010012struct proc_dir_entry;
Christoph Hellwig3f3942a2018-05-15 15:57:23 +020013struct seq_file;
Christoph Hellwigfddda2b2018-04-13 19:44:18 +020014struct seq_operations;
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
Alexey Dobriyand919b332020-04-06 20:09:01 -070016enum {
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
Alexey Dobriyand56c0d42020-02-03 17:37:14 -080029struct proc_ops {
Alexey Dobriyand919b332020-04-06 20:09:01 -070030 unsigned int proc_flags;
Alexey Dobriyand56c0d42020-02-03 17:37:14 -080031 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);
Alexey Dobriyand919b332020-04-06 20:09:01 -070043} __randomize_layout;
Alexey Dobriyand56c0d42020-02-03 17:37:14 -080044
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#ifdef CONFIG_PROC_FS
46
David Howells564def72018-05-18 11:46:15 +010047typedef int (*proc_write_t)(struct file *, char *, size_t);
48
Linus Torvalds1da177e2005-04-16 15:20:36 -070049extern void proc_root_init(void);
Eric W. Biederman7bc3e6e2020-02-19 18:22:26 -060050extern void proc_flush_pid(struct pid *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
Linus Torvalds1da177e2005-04-16 15:20:36 -070052extern struct proc_dir_entry *proc_symlink(const char *,
53 struct proc_dir_entry *, const char *);
David Howells59d80532013-04-11 13:34:43 +010054extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *);
David Howells270b5ac2013-04-12 02:48:30 +010055extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
56 struct proc_dir_entry *, void *);
David Howells59d80532013-04-11 13:34:43 +010057extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
58 struct proc_dir_entry *);
Seth Forsheef97df702016-11-14 11:12:56 +000059struct proc_dir_entry *proc_create_mount_point(const char *name);
Christoph Hellwigfddda2b2018-04-13 19:44:18 +020060
Christoph Hellwig44414d82018-04-24 17:05:17 +020061struct proc_dir_entry *proc_create_seq_private(const char *name, umode_t mode,
Christoph Hellwigfddda2b2018-04-13 19:44:18 +020062 struct proc_dir_entry *parent, const struct seq_operations *ops,
Christoph Hellwig44414d82018-04-24 17:05:17 +020063 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)
Christoph Hellwigfddda2b2018-04-13 19:44:18 +020066#define proc_create_seq(name, mode, parent, ops) \
Christoph Hellwig44414d82018-04-24 17:05:17 +020067 proc_create_seq_private(name, mode, parent, ops, 0, NULL)
Christoph Hellwig3f3942a2018-05-15 15:57:23 +020068struct 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)
David Howells59d80532013-04-11 13:34:43 +010073
74extern struct proc_dir_entry *proc_create_data(const char *, umode_t,
75 struct proc_dir_entry *,
Alexey Dobriyand56c0d42020-02-03 17:37:14 -080076 const struct proc_ops *,
David Howells59d80532013-04-11 13:34:43 +010077 void *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
Alexey Dobriyand56c0d42020-02-03 17:37:14 -080079struct proc_dir_entry *proc_create(const char *name, umode_t mode, struct proc_dir_entry *parent, const struct proc_ops *proc_ops);
David Howells271a15e2013-04-12 00:38:51 +010080extern void proc_set_size(struct proc_dir_entry *, loff_t);
81extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
David Howellsc30480b2013-04-12 18:03:36 +010082extern void *PDE_DATA(const struct inode *);
David Howells4a520d22013-04-12 14:06:01 +010083extern void *proc_get_parent_data(const struct inode *);
David Howells59d80532013-04-11 13:34:43 +010084extern 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
Christoph Hellwigc3506372018-04-10 19:42:55 +020088struct 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);
Miaohe Lin9573e8f2019-12-04 16:50:08 -080091#define proc_create_net(name, mode, parent, ops, state_size) \
92 proc_create_net_data(name, mode, parent, ops, state_size, NULL)
Christoph Hellwig3617d942018-04-13 20:38:35 +020093struct 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);
David Howells564def72018-05-18 11:46:15 +010096struct 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);
Christian Brauner3eb39f42018-11-19 00:51:56 +0100106extern struct pid *tgid_pidfd_to_pid(const struct file *file);
Christoph Hellwigc3506372018-04-10 19:42:55 +0200107
Aubrey Li68bc30b2019-06-06 09:22:34 +0800108#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
David Howells59d80532013-04-11 13:34:43 +0100117#else /* CONFIG_PROC_FS */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
Andrew Morton647f0102014-06-04 16:12:20 -0700119static inline void proc_root_init(void)
120{
121}
122
Eric W. Biederman7bc3e6e2020-02-19 18:22:26 -0600123static inline void proc_flush_pid(struct pid *pid)
Pavel Emelyanov60347f62007-10-18 23:40:03 -0700124{
125}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127static inline struct proc_dir_entry *proc_symlink(const char *name,
David Howells59d80532013-04-11 13:34:43 +0100128 struct proc_dir_entry *parent,const char *dest) { return NULL;}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129static inline struct proc_dir_entry *proc_mkdir(const char *name,
130 struct proc_dir_entry *parent) {return NULL;}
Seth Forsheef97df702016-11-14 11:12:56 +0000131static inline struct proc_dir_entry *proc_create_mount_point(const char *name) { return NULL; }
David Howells270b5ac2013-04-12 02:48:30 +0100132static inline struct proc_dir_entry *proc_mkdir_data(const char *name,
133 umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
Randy Dunlapf12a20f2011-05-17 15:44:12 -0700134static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
Al Virod161a132011-07-24 03:36:29 -0400135 umode_t mode, struct proc_dir_entry *parent) { return NULL; }
Christoph Hellwig3f3942a2018-05-15 15:57:23 +0200136#define proc_create_seq_private(name, mode, parent, ops, size, data) ({NULL;})
Christoph Hellwigfddda2b2018-04-13 19:44:18 +0200137#define proc_create_seq_data(name, mode, parent, ops, data) ({NULL;})
138#define proc_create_seq(name, mode, parent, ops) ({NULL;})
Christoph Hellwig3f3942a2018-05-15 15:57:23 +0200139#define proc_create_single(name, mode, parent, show) ({NULL;})
140#define proc_create_single_data(name, mode, parent, show, data) ({NULL;})
Alexey Dobriyand56c0d42020-02-03 17:37:14 -0800141#define proc_create(name, mode, parent, proc_ops) ({NULL;})
142#define proc_create_data(name, mode, parent, proc_ops, data) ({NULL;})
David Howells59d80532013-04-11 13:34:43 +0100143
David Howells271a15e2013-04-12 00:38:51 +0100144static 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) {}
David Howellsc30480b2013-04-12 18:03:36 +0100146static inline void *PDE_DATA(const struct inode *inode) {BUG(); return NULL;}
David Howells59d80532013-04-11 13:34:43 +0100147static inline void *proc_get_parent_data(const struct inode *inode) { BUG(); return NULL; }
148
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; }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
Christoph Hellwigc3506372018-04-10 19:42:55 +0200153#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;})
Christoph Hellwig3617d942018-04-13 20:38:35 +0200155#define proc_create_net_single(name, mode, parent, show, data) ({NULL;})
Christoph Hellwigc3506372018-04-10 19:42:55 +0200156
Christian Brauner3eb39f42018-11-19 00:51:56 +0100157static inline struct pid *tgid_pidfd_to_pid(const struct file *file)
158{
159 return ERR_PTR(-EBADF);
160}
161
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162#endif /* CONFIG_PROC_FS */
163
Jeff Laytonf7790022014-09-12 16:40:20 -0400164struct net;
165
David Howells270b5ac2013-04-12 02:48:30 +0100166static 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
Andrey Vaginc62cce22016-10-24 18:29:13 -0700172struct ns_common;
173int open_related_ns(struct ns_common *ns,
174 struct ns_common *(*get_ns)(struct ns_common *ns));
175
Christoph Hellwig76f668b2018-05-16 07:19:01 +0200176/* get the associated pid namespace for a file in procfs */
Alexey Dobriyan891ae712018-08-21 21:54:37 -0700177static inline struct pid_namespace *proc_pid_ns(const struct inode *inode)
Christoph Hellwig76f668b2018-05-16 07:19:01 +0200178{
179 return inode->i_sb->s_fs_info;
180}
181
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182#endif /* _LINUX_PROC_FS_H */