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