blob: 865d02c224adad12c118247d29833172856db6fb [file] [log] [blame]
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001/* 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/types.h>
9#include <linux/fs.h>
10
11struct proc_dir_entry;
12struct seq_file;
13struct seq_operations;
14
15#ifdef CONFIG_PROC_FS
16
17typedef int (*proc_write_t)(struct file *, char *, size_t);
18
19extern void proc_root_init(void);
20extern void proc_flush_task(struct task_struct *);
21
22extern struct proc_dir_entry *proc_symlink(const char *,
23 struct proc_dir_entry *, const char *);
Olivier Deprez0e641232021-09-23 10:07:05 +020024struct proc_dir_entry *_proc_mkdir(const char *, umode_t, struct proc_dir_entry *, void *, bool);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000025extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *);
26extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
27 struct proc_dir_entry *, void *);
28extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
29 struct proc_dir_entry *);
30struct proc_dir_entry *proc_create_mount_point(const char *name);
31
32struct proc_dir_entry *proc_create_seq_private(const char *name, umode_t mode,
33 struct proc_dir_entry *parent, const struct seq_operations *ops,
34 unsigned int state_size, void *data);
35#define proc_create_seq_data(name, mode, parent, ops, data) \
36 proc_create_seq_private(name, mode, parent, ops, 0, data)
37#define proc_create_seq(name, mode, parent, ops) \
38 proc_create_seq_private(name, mode, parent, ops, 0, NULL)
39struct proc_dir_entry *proc_create_single_data(const char *name, umode_t mode,
40 struct proc_dir_entry *parent,
41 int (*show)(struct seq_file *, void *), void *data);
42#define proc_create_single(name, mode, parent, show) \
43 proc_create_single_data(name, mode, parent, show, NULL)
44
45extern struct proc_dir_entry *proc_create_data(const char *, umode_t,
46 struct proc_dir_entry *,
47 const struct file_operations *,
48 void *);
49
50struct proc_dir_entry *proc_create(const char *name, umode_t mode, struct proc_dir_entry *parent, const struct file_operations *proc_fops);
51extern void proc_set_size(struct proc_dir_entry *, loff_t);
52extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
53extern void *PDE_DATA(const struct inode *);
54extern void *proc_get_parent_data(const struct inode *);
55extern void proc_remove(struct proc_dir_entry *);
56extern void remove_proc_entry(const char *, struct proc_dir_entry *);
57extern int remove_proc_subtree(const char *, struct proc_dir_entry *);
58
59struct proc_dir_entry *proc_create_net_data(const char *name, umode_t mode,
60 struct proc_dir_entry *parent, const struct seq_operations *ops,
61 unsigned int state_size, void *data);
62#define proc_create_net(name, mode, parent, state_size, ops) \
63 proc_create_net_data(name, mode, parent, state_size, ops, NULL)
64struct proc_dir_entry *proc_create_net_single(const char *name, umode_t mode,
65 struct proc_dir_entry *parent,
66 int (*show)(struct seq_file *, void *), void *data);
67struct proc_dir_entry *proc_create_net_data_write(const char *name, umode_t mode,
68 struct proc_dir_entry *parent,
69 const struct seq_operations *ops,
70 proc_write_t write,
71 unsigned int state_size, void *data);
72struct proc_dir_entry *proc_create_net_single_write(const char *name, umode_t mode,
73 struct proc_dir_entry *parent,
74 int (*show)(struct seq_file *, void *),
75 proc_write_t write,
76 void *data);
David Brazdil0f672f62019-12-10 10:32:29 +000077extern struct pid *tgid_pidfd_to_pid(const struct file *file);
78
79#ifdef CONFIG_PROC_PID_ARCH_STATUS
80/*
81 * The architecture which selects CONFIG_PROC_PID_ARCH_STATUS must
82 * provide proc_pid_arch_status() definition.
83 */
84int proc_pid_arch_status(struct seq_file *m, struct pid_namespace *ns,
85 struct pid *pid, struct task_struct *task);
86#endif /* CONFIG_PROC_PID_ARCH_STATUS */
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000087
88#else /* CONFIG_PROC_FS */
89
90static inline void proc_root_init(void)
91{
92}
93
94static inline void proc_flush_task(struct task_struct *task)
95{
96}
97
98static inline struct proc_dir_entry *proc_symlink(const char *name,
99 struct proc_dir_entry *parent,const char *dest) { return NULL;}
100static inline struct proc_dir_entry *proc_mkdir(const char *name,
101 struct proc_dir_entry *parent) {return NULL;}
102static inline struct proc_dir_entry *proc_create_mount_point(const char *name) { return NULL; }
Olivier Deprez0e641232021-09-23 10:07:05 +0200103static inline struct proc_dir_entry *_proc_mkdir(const char *name, umode_t mode,
104 struct proc_dir_entry *parent, void *data, bool force_lookup)
105{
106 return NULL;
107}
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000108static inline struct proc_dir_entry *proc_mkdir_data(const char *name,
109 umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
110static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
111 umode_t mode, struct proc_dir_entry *parent) { return NULL; }
112#define proc_create_seq_private(name, mode, parent, ops, size, data) ({NULL;})
113#define proc_create_seq_data(name, mode, parent, ops, data) ({NULL;})
114#define proc_create_seq(name, mode, parent, ops) ({NULL;})
115#define proc_create_single(name, mode, parent, show) ({NULL;})
116#define proc_create_single_data(name, mode, parent, show, data) ({NULL;})
117#define proc_create(name, mode, parent, proc_fops) ({NULL;})
118#define proc_create_data(name, mode, parent, proc_fops, data) ({NULL;})
119
120static inline void proc_set_size(struct proc_dir_entry *de, loff_t size) {}
121static inline void proc_set_user(struct proc_dir_entry *de, kuid_t uid, kgid_t gid) {}
122static inline void *PDE_DATA(const struct inode *inode) {BUG(); return NULL;}
123static inline void *proc_get_parent_data(const struct inode *inode) { BUG(); return NULL; }
124
125static inline void proc_remove(struct proc_dir_entry *de) {}
126#define remove_proc_entry(name, parent) do {} while (0)
127static inline int remove_proc_subtree(const char *name, struct proc_dir_entry *parent) { return 0; }
128
129#define proc_create_net_data(name, mode, parent, ops, state_size, data) ({NULL;})
130#define proc_create_net(name, mode, parent, state_size, ops) ({NULL;})
131#define proc_create_net_single(name, mode, parent, show, data) ({NULL;})
132
David Brazdil0f672f62019-12-10 10:32:29 +0000133static inline struct pid *tgid_pidfd_to_pid(const struct file *file)
134{
135 return ERR_PTR(-EBADF);
136}
137
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000138#endif /* CONFIG_PROC_FS */
139
140struct net;
141
142static inline struct proc_dir_entry *proc_net_mkdir(
143 struct net *net, const char *name, struct proc_dir_entry *parent)
144{
Olivier Deprez0e641232021-09-23 10:07:05 +0200145 return _proc_mkdir(name, 0, parent, net, true);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000146}
147
148struct ns_common;
149int open_related_ns(struct ns_common *ns,
150 struct ns_common *(*get_ns)(struct ns_common *ns));
151
152/* get the associated pid namespace for a file in procfs */
153static inline struct pid_namespace *proc_pid_ns(const struct inode *inode)
154{
155 return inode->i_sb->s_fs_info;
156}
157
158#endif /* _LINUX_PROC_FS_H */