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_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);
39 long (*proc_compat_ioctl)(struct file *, unsigned int, unsigned long);
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);
45 /* definitions for hide_pid field */
48 HIDEPID_NO_ACCESS = 1,
49 HIDEPID_INVISIBLE = 2,
50 HIDEPID_NOT_PTRACEABLE = 4, /* Limit pids to only ptraceable pids */
53 /* definitions for proc mount option pidonly */
60 struct pid_namespace *pid_ns;
61 struct dentry *proc_self; /* For /proc/self */
62 struct dentry *proc_thread_self; /* For /proc/thread-self */
64 enum proc_hidepid hide_pid;
65 enum proc_pidonly pidonly;
68 static inline struct proc_fs_info *proc_sb_info(struct super_block *sb)
75 typedef int (*proc_write_t)(struct file *, char *, size_t);
77 extern void proc_root_init(void);
78 extern void proc_flush_pid(struct pid *);
80 extern struct proc_dir_entry *proc_symlink(const char *,
81 struct proc_dir_entry *, const char *);
82 extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *);
83 extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
84 struct proc_dir_entry *, void *);
85 extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
86 struct proc_dir_entry *);
87 struct proc_dir_entry *proc_create_mount_point(const char *name);
89 struct proc_dir_entry *proc_create_seq_private(const char *name, umode_t mode,
90 struct proc_dir_entry *parent, const struct seq_operations *ops,
91 unsigned int state_size, void *data);
92 #define proc_create_seq_data(name, mode, parent, ops, data) \
93 proc_create_seq_private(name, mode, parent, ops, 0, data)
94 #define proc_create_seq(name, mode, parent, ops) \
95 proc_create_seq_private(name, mode, parent, ops, 0, NULL)
96 struct proc_dir_entry *proc_create_single_data(const char *name, umode_t mode,
97 struct proc_dir_entry *parent,
98 int (*show)(struct seq_file *, void *), void *data);
99 #define proc_create_single(name, mode, parent, show) \
100 proc_create_single_data(name, mode, parent, show, NULL)
102 extern struct proc_dir_entry *proc_create_data(const char *, umode_t,
103 struct proc_dir_entry *,
104 const struct proc_ops *,
107 struct proc_dir_entry *proc_create(const char *name, umode_t mode, struct proc_dir_entry *parent, const struct proc_ops *proc_ops);
108 extern void proc_set_size(struct proc_dir_entry *, loff_t);
109 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
110 extern void *PDE_DATA(const struct inode *);
111 extern void *proc_get_parent_data(const struct inode *);
112 extern void proc_remove(struct proc_dir_entry *);
113 extern void remove_proc_entry(const char *, struct proc_dir_entry *);
114 extern int remove_proc_subtree(const char *, struct proc_dir_entry *);
116 struct proc_dir_entry *proc_create_net_data(const char *name, umode_t mode,
117 struct proc_dir_entry *parent, const struct seq_operations *ops,
118 unsigned int state_size, void *data);
119 #define proc_create_net(name, mode, parent, ops, state_size) \
120 proc_create_net_data(name, mode, parent, ops, state_size, NULL)
121 struct proc_dir_entry *proc_create_net_single(const char *name, umode_t mode,
122 struct proc_dir_entry *parent,
123 int (*show)(struct seq_file *, void *), void *data);
124 struct proc_dir_entry *proc_create_net_data_write(const char *name, umode_t mode,
125 struct proc_dir_entry *parent,
126 const struct seq_operations *ops,
128 unsigned int state_size, void *data);
129 struct proc_dir_entry *proc_create_net_single_write(const char *name, umode_t mode,
130 struct proc_dir_entry *parent,
131 int (*show)(struct seq_file *, void *),
134 extern struct pid *tgid_pidfd_to_pid(const struct file *file);
136 struct bpf_iter_aux_info;
137 extern int bpf_iter_init_seq_net(void *priv_data, struct bpf_iter_aux_info *aux);
138 extern void bpf_iter_fini_seq_net(void *priv_data);
140 #ifdef CONFIG_PROC_PID_ARCH_STATUS
142 * The architecture which selects CONFIG_PROC_PID_ARCH_STATUS must
143 * provide proc_pid_arch_status() definition.
145 int proc_pid_arch_status(struct seq_file *m, struct pid_namespace *ns,
146 struct pid *pid, struct task_struct *task);
147 #endif /* CONFIG_PROC_PID_ARCH_STATUS */
149 #else /* CONFIG_PROC_FS */
151 static inline void proc_root_init(void)
155 static inline void proc_flush_pid(struct pid *pid)
159 static inline struct proc_dir_entry *proc_symlink(const char *name,
160 struct proc_dir_entry *parent,const char *dest) { return NULL;}
161 static inline struct proc_dir_entry *proc_mkdir(const char *name,
162 struct proc_dir_entry *parent) {return NULL;}
163 static inline struct proc_dir_entry *proc_create_mount_point(const char *name) { return NULL; }
164 static inline struct proc_dir_entry *proc_mkdir_data(const char *name,
165 umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
166 static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
167 umode_t mode, struct proc_dir_entry *parent) { return NULL; }
168 #define proc_create_seq_private(name, mode, parent, ops, size, data) ({NULL;})
169 #define proc_create_seq_data(name, mode, parent, ops, data) ({NULL;})
170 #define proc_create_seq(name, mode, parent, ops) ({NULL;})
171 #define proc_create_single(name, mode, parent, show) ({NULL;})
172 #define proc_create_single_data(name, mode, parent, show, data) ({NULL;})
173 #define proc_create(name, mode, parent, proc_ops) ({NULL;})
174 #define proc_create_data(name, mode, parent, proc_ops, data) ({NULL;})
176 static inline void proc_set_size(struct proc_dir_entry *de, loff_t size) {}
177 static inline void proc_set_user(struct proc_dir_entry *de, kuid_t uid, kgid_t gid) {}
178 static inline void *PDE_DATA(const struct inode *inode) {BUG(); return NULL;}
179 static inline void *proc_get_parent_data(const struct inode *inode) { BUG(); return NULL; }
181 static inline void proc_remove(struct proc_dir_entry *de) {}
182 #define remove_proc_entry(name, parent) do {} while (0)
183 static inline int remove_proc_subtree(const char *name, struct proc_dir_entry *parent) { return 0; }
185 #define proc_create_net_data(name, mode, parent, ops, state_size, data) ({NULL;})
186 #define proc_create_net(name, mode, parent, state_size, ops) ({NULL;})
187 #define proc_create_net_single(name, mode, parent, show, data) ({NULL;})
189 static inline struct pid *tgid_pidfd_to_pid(const struct file *file)
191 return ERR_PTR(-EBADF);
194 #endif /* CONFIG_PROC_FS */
198 static inline struct proc_dir_entry *proc_net_mkdir(
199 struct net *net, const char *name, struct proc_dir_entry *parent)
201 return proc_mkdir_data(name, 0, parent, net);
205 int open_related_ns(struct ns_common *ns,
206 struct ns_common *(*get_ns)(struct ns_common *ns));
208 /* get the associated pid namespace for a file in procfs */
209 static inline struct pid_namespace *proc_pid_ns(struct super_block *sb)
211 return proc_sb_info(sb)->pid_ns;
214 bool proc_ns_file(const struct file *file);
216 #endif /* _LINUX_PROC_FS_H */