1 /* SPDX-License-Identifier: GPL-2.0 */
3 * The proc filesystem constants/structures
5 #ifndef _LINUX_PROC_FS_H
6 #define _LINUX_PROC_FS_H
8 #include <linux/compiler.h>
9 #include <linux/types.h>
12 struct proc_dir_entry;
14 struct seq_operations;
18 * All /proc entries using this ->proc_ops instance are never removed.
20 * If in doubt, ignore this flag.
23 PROC_ENTRY_PERMANENT = 0U,
25 PROC_ENTRY_PERMANENT = 1U << 0,
30 unsigned int proc_flags;
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_read_iter)(struct kiocb *, struct iov_iter *);
34 ssize_t (*proc_write)(struct file *, const char __user *, size_t, loff_t *);
35 /* mandatory unless nonseekable_open() or equivalent is used */
36 loff_t (*proc_lseek)(struct file *, loff_t, int);
37 int (*proc_release)(struct inode *, struct file *);
38 __poll_t (*proc_poll)(struct file *, struct poll_table_struct *);
39 long (*proc_ioctl)(struct file *, unsigned int, unsigned long);
41 long (*proc_compat_ioctl)(struct file *, unsigned int, unsigned long);
43 int (*proc_mmap)(struct file *, struct vm_area_struct *);
44 unsigned long (*proc_get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
47 /* definitions for hide_pid field */
50 HIDEPID_NO_ACCESS = 1,
51 HIDEPID_INVISIBLE = 2,
52 HIDEPID_NOT_PTRACEABLE = 4, /* Limit pids to only ptraceable pids */
55 /* definitions for proc mount option pidonly */
62 struct pid_namespace *pid_ns;
63 struct dentry *proc_self; /* For /proc/self */
64 struct dentry *proc_thread_self; /* For /proc/thread-self */
66 enum proc_hidepid hide_pid;
67 enum proc_pidonly pidonly;
70 static inline struct proc_fs_info *proc_sb_info(struct super_block *sb)
77 typedef int (*proc_write_t)(struct file *, char *, size_t);
79 extern void proc_root_init(void);
80 extern void proc_flush_pid(struct pid *);
82 extern struct proc_dir_entry *proc_symlink(const char *,
83 struct proc_dir_entry *, const char *);
84 struct proc_dir_entry *_proc_mkdir(const char *, umode_t, struct proc_dir_entry *, void *, bool);
85 extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *);
86 extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
87 struct proc_dir_entry *, void *);
88 extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
89 struct proc_dir_entry *);
90 struct proc_dir_entry *proc_create_mount_point(const char *name);
92 struct proc_dir_entry *proc_create_seq_private(const char *name, umode_t mode,
93 struct proc_dir_entry *parent, const struct seq_operations *ops,
94 unsigned int state_size, void *data);
95 #define proc_create_seq_data(name, mode, parent, ops, data) \
96 proc_create_seq_private(name, mode, parent, ops, 0, data)
97 #define proc_create_seq(name, mode, parent, ops) \
98 proc_create_seq_private(name, mode, parent, ops, 0, NULL)
99 struct proc_dir_entry *proc_create_single_data(const char *name, umode_t mode,
100 struct proc_dir_entry *parent,
101 int (*show)(struct seq_file *, void *), void *data);
102 #define proc_create_single(name, mode, parent, show) \
103 proc_create_single_data(name, mode, parent, show, NULL)
105 extern struct proc_dir_entry *proc_create_data(const char *, umode_t,
106 struct proc_dir_entry *,
107 const struct proc_ops *,
110 struct proc_dir_entry *proc_create(const char *name, umode_t mode, struct proc_dir_entry *parent, const struct proc_ops *proc_ops);
111 extern void proc_set_size(struct proc_dir_entry *, loff_t);
112 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
113 extern void *PDE_DATA(const struct inode *);
114 extern void *proc_get_parent_data(const struct inode *);
115 extern void proc_remove(struct proc_dir_entry *);
116 extern void remove_proc_entry(const char *, struct proc_dir_entry *);
117 extern int remove_proc_subtree(const char *, struct proc_dir_entry *);
119 struct proc_dir_entry *proc_create_net_data(const char *name, umode_t mode,
120 struct proc_dir_entry *parent, const struct seq_operations *ops,
121 unsigned int state_size, void *data);
122 #define proc_create_net(name, mode, parent, ops, state_size) \
123 proc_create_net_data(name, mode, parent, ops, state_size, NULL)
124 struct proc_dir_entry *proc_create_net_single(const char *name, umode_t mode,
125 struct proc_dir_entry *parent,
126 int (*show)(struct seq_file *, void *), void *data);
127 struct proc_dir_entry *proc_create_net_data_write(const char *name, umode_t mode,
128 struct proc_dir_entry *parent,
129 const struct seq_operations *ops,
131 unsigned int state_size, void *data);
132 struct proc_dir_entry *proc_create_net_single_write(const char *name, umode_t mode,
133 struct proc_dir_entry *parent,
134 int (*show)(struct seq_file *, void *),
137 extern struct pid *tgid_pidfd_to_pid(const struct file *file);
139 struct bpf_iter_aux_info;
140 extern int bpf_iter_init_seq_net(void *priv_data, struct bpf_iter_aux_info *aux);
141 extern void bpf_iter_fini_seq_net(void *priv_data);
143 #ifdef CONFIG_PROC_PID_ARCH_STATUS
145 * The architecture which selects CONFIG_PROC_PID_ARCH_STATUS must
146 * provide proc_pid_arch_status() definition.
148 int proc_pid_arch_status(struct seq_file *m, struct pid_namespace *ns,
149 struct pid *pid, struct task_struct *task);
150 #endif /* CONFIG_PROC_PID_ARCH_STATUS */
152 #else /* CONFIG_PROC_FS */
154 static inline void proc_root_init(void)
158 static inline void proc_flush_pid(struct pid *pid)
162 static inline struct proc_dir_entry *proc_symlink(const char *name,
163 struct proc_dir_entry *parent,const char *dest) { return NULL;}
164 static inline struct proc_dir_entry *proc_mkdir(const char *name,
165 struct proc_dir_entry *parent) {return NULL;}
166 static inline struct proc_dir_entry *proc_create_mount_point(const char *name) { return NULL; }
167 static inline struct proc_dir_entry *_proc_mkdir(const char *name, umode_t mode,
168 struct proc_dir_entry *parent, void *data, bool force_lookup)
172 static inline struct proc_dir_entry *proc_mkdir_data(const char *name,
173 umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
174 static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
175 umode_t mode, struct proc_dir_entry *parent) { return NULL; }
176 #define proc_create_seq_private(name, mode, parent, ops, size, data) ({NULL;})
177 #define proc_create_seq_data(name, mode, parent, ops, data) ({NULL;})
178 #define proc_create_seq(name, mode, parent, ops) ({NULL;})
179 #define proc_create_single(name, mode, parent, show) ({NULL;})
180 #define proc_create_single_data(name, mode, parent, show, data) ({NULL;})
181 #define proc_create(name, mode, parent, proc_ops) ({NULL;})
182 #define proc_create_data(name, mode, parent, proc_ops, data) ({NULL;})
184 static inline void proc_set_size(struct proc_dir_entry *de, loff_t size) {}
185 static inline void proc_set_user(struct proc_dir_entry *de, kuid_t uid, kgid_t gid) {}
186 static inline void *PDE_DATA(const struct inode *inode) {BUG(); return NULL;}
187 static inline void *proc_get_parent_data(const struct inode *inode) { BUG(); return NULL; }
189 static inline void proc_remove(struct proc_dir_entry *de) {}
190 #define remove_proc_entry(name, parent) do {} while (0)
191 static inline int remove_proc_subtree(const char *name, struct proc_dir_entry *parent) { return 0; }
193 #define proc_create_net_data(name, mode, parent, ops, state_size, data) ({NULL;})
194 #define proc_create_net(name, mode, parent, state_size, ops) ({NULL;})
195 #define proc_create_net_single(name, mode, parent, show, data) ({NULL;})
197 static inline struct pid *tgid_pidfd_to_pid(const struct file *file)
199 return ERR_PTR(-EBADF);
202 #endif /* CONFIG_PROC_FS */
206 static inline struct proc_dir_entry *proc_net_mkdir(
207 struct net *net, const char *name, struct proc_dir_entry *parent)
209 return _proc_mkdir(name, 0, parent, net, true);
213 int open_related_ns(struct ns_common *ns,
214 struct ns_common *(*get_ns)(struct ns_common *ns));
216 /* get the associated pid namespace for a file in procfs */
217 static inline struct pid_namespace *proc_pid_ns(struct super_block *sb)
219 return proc_sb_info(sb)->pid_ns;
222 bool proc_ns_file(const struct file *file);
224 #endif /* _LINUX_PROC_FS_H */