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/types.h> 9 #include <linux/fs.h> 10 11 struct proc_dir_entry; 12 struct seq_file; 13 struct seq_operations; 14 15 struct proc_ops { 16 int (*proc_open)(struct inode *, struct file *); 17 ssize_t (*proc_read)(struct file *, char __user *, size_t, loff_t *); 18 ssize_t (*proc_write)(struct file *, const char __user *, size_t, loff_t *); 19 loff_t (*proc_lseek)(struct file *, loff_t, int); 20 int (*proc_release)(struct inode *, struct file *); 21 __poll_t (*proc_poll)(struct file *, struct poll_table_struct *); 22 long (*proc_ioctl)(struct file *, unsigned int, unsigned long); 23 #ifdef CONFIG_COMPAT 24 long (*proc_compat_ioctl)(struct file *, unsigned int, unsigned long); 25 #endif 26 int (*proc_mmap)(struct file *, struct vm_area_struct *); 27 unsigned long (*proc_get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long); 28 }; 29 30 #ifdef CONFIG_PROC_FS 31 32 typedef int (*proc_write_t)(struct file *, char *, size_t); 33 34 extern void proc_root_init(void); 35 extern void proc_flush_task(struct task_struct *); 36 37 extern struct proc_dir_entry *proc_symlink(const char *, 38 struct proc_dir_entry *, const char *); 39 extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *); 40 extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t, 41 struct proc_dir_entry *, void *); 42 extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t, 43 struct proc_dir_entry *); 44 struct proc_dir_entry *proc_create_mount_point(const char *name); 45 46 struct proc_dir_entry *proc_create_seq_private(const char *name, umode_t mode, 47 struct proc_dir_entry *parent, const struct seq_operations *ops, 48 unsigned int state_size, void *data); 49 #define proc_create_seq_data(name, mode, parent, ops, data) \ 50 proc_create_seq_private(name, mode, parent, ops, 0, data) 51 #define proc_create_seq(name, mode, parent, ops) \ 52 proc_create_seq_private(name, mode, parent, ops, 0, NULL) 53 struct proc_dir_entry *proc_create_single_data(const char *name, umode_t mode, 54 struct proc_dir_entry *parent, 55 int (*show)(struct seq_file *, void *), void *data); 56 #define proc_create_single(name, mode, parent, show) \ 57 proc_create_single_data(name, mode, parent, show, NULL) 58 59 extern struct proc_dir_entry *proc_create_data(const char *, umode_t, 60 struct proc_dir_entry *, 61 const struct proc_ops *, 62 void *); 63 64 struct proc_dir_entry *proc_create(const char *name, umode_t mode, struct proc_dir_entry *parent, const struct proc_ops *proc_ops); 65 extern void proc_set_size(struct proc_dir_entry *, loff_t); 66 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t); 67 extern void *PDE_DATA(const struct inode *); 68 extern void *proc_get_parent_data(const struct inode *); 69 extern void proc_remove(struct proc_dir_entry *); 70 extern void remove_proc_entry(const char *, struct proc_dir_entry *); 71 extern int remove_proc_subtree(const char *, struct proc_dir_entry *); 72 73 struct proc_dir_entry *proc_create_net_data(const char *name, umode_t mode, 74 struct proc_dir_entry *parent, const struct seq_operations *ops, 75 unsigned int state_size, void *data); 76 #define proc_create_net(name, mode, parent, ops, state_size) \ 77 proc_create_net_data(name, mode, parent, ops, state_size, NULL) 78 struct proc_dir_entry *proc_create_net_single(const char *name, umode_t mode, 79 struct proc_dir_entry *parent, 80 int (*show)(struct seq_file *, void *), void *data); 81 struct proc_dir_entry *proc_create_net_data_write(const char *name, umode_t mode, 82 struct proc_dir_entry *parent, 83 const struct seq_operations *ops, 84 proc_write_t write, 85 unsigned int state_size, void *data); 86 struct proc_dir_entry *proc_create_net_single_write(const char *name, umode_t mode, 87 struct proc_dir_entry *parent, 88 int (*show)(struct seq_file *, void *), 89 proc_write_t write, 90 void *data); 91 extern struct pid *tgid_pidfd_to_pid(const struct file *file); 92 93 #ifdef CONFIG_PROC_PID_ARCH_STATUS 94 /* 95 * The architecture which selects CONFIG_PROC_PID_ARCH_STATUS must 96 * provide proc_pid_arch_status() definition. 97 */ 98 int proc_pid_arch_status(struct seq_file *m, struct pid_namespace *ns, 99 struct pid *pid, struct task_struct *task); 100 #endif /* CONFIG_PROC_PID_ARCH_STATUS */ 101 102 #else /* CONFIG_PROC_FS */ 103 104 static inline void proc_root_init(void) 105 { 106 } 107 108 static inline void proc_flush_task(struct task_struct *task) 109 { 110 } 111 112 static inline struct proc_dir_entry *proc_symlink(const char *name, 113 struct proc_dir_entry *parent,const char *dest) { return NULL;} 114 static inline struct proc_dir_entry *proc_mkdir(const char *name, 115 struct proc_dir_entry *parent) {return NULL;} 116 static inline struct proc_dir_entry *proc_create_mount_point(const char *name) { return NULL; } 117 static inline struct proc_dir_entry *proc_mkdir_data(const char *name, 118 umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; } 119 static inline struct proc_dir_entry *proc_mkdir_mode(const char *name, 120 umode_t mode, struct proc_dir_entry *parent) { return NULL; } 121 #define proc_create_seq_private(name, mode, parent, ops, size, data) ({NULL;}) 122 #define proc_create_seq_data(name, mode, parent, ops, data) ({NULL;}) 123 #define proc_create_seq(name, mode, parent, ops) ({NULL;}) 124 #define proc_create_single(name, mode, parent, show) ({NULL;}) 125 #define proc_create_single_data(name, mode, parent, show, data) ({NULL;}) 126 #define proc_create(name, mode, parent, proc_ops) ({NULL;}) 127 #define proc_create_data(name, mode, parent, proc_ops, data) ({NULL;}) 128 129 static inline void proc_set_size(struct proc_dir_entry *de, loff_t size) {} 130 static inline void proc_set_user(struct proc_dir_entry *de, kuid_t uid, kgid_t gid) {} 131 static inline void *PDE_DATA(const struct inode *inode) {BUG(); return NULL;} 132 static inline void *proc_get_parent_data(const struct inode *inode) { BUG(); return NULL; } 133 134 static inline void proc_remove(struct proc_dir_entry *de) {} 135 #define remove_proc_entry(name, parent) do {} while (0) 136 static inline int remove_proc_subtree(const char *name, struct proc_dir_entry *parent) { return 0; } 137 138 #define proc_create_net_data(name, mode, parent, ops, state_size, data) ({NULL;}) 139 #define proc_create_net(name, mode, parent, state_size, ops) ({NULL;}) 140 #define proc_create_net_single(name, mode, parent, show, data) ({NULL;}) 141 142 static inline struct pid *tgid_pidfd_to_pid(const struct file *file) 143 { 144 return ERR_PTR(-EBADF); 145 } 146 147 #endif /* CONFIG_PROC_FS */ 148 149 struct net; 150 151 static inline struct proc_dir_entry *proc_net_mkdir( 152 struct net *net, const char *name, struct proc_dir_entry *parent) 153 { 154 return proc_mkdir_data(name, 0, parent, net); 155 } 156 157 struct ns_common; 158 int open_related_ns(struct ns_common *ns, 159 struct ns_common *(*get_ns)(struct ns_common *ns)); 160 161 /* get the associated pid namespace for a file in procfs */ 162 static inline struct pid_namespace *proc_pid_ns(const struct inode *inode) 163 { 164 return inode->i_sb->s_fs_info; 165 } 166 167 #endif /* _LINUX_PROC_FS_H */ 168