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