Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * The proc filesystem constants/structures
0004  */
0005 #ifndef _LINUX_PROC_FS_H
0006 #define _LINUX_PROC_FS_H
0007 
0008 #include <linux/compiler.h>
0009 #include <linux/types.h>
0010 #include <linux/fs.h>
0011 
0012 struct proc_dir_entry;
0013 struct seq_file;
0014 struct seq_operations;
0015 
0016 enum {
0017     /*
0018      * All /proc entries using this ->proc_ops instance are never removed.
0019      *
0020      * If in doubt, ignore this flag.
0021      */
0022 #ifdef MODULE
0023     PROC_ENTRY_PERMANENT = 0U,
0024 #else
0025     PROC_ENTRY_PERMANENT = 1U << 0,
0026 #endif
0027 };
0028 
0029 struct proc_ops {
0030     unsigned int proc_flags;
0031     int (*proc_open)(struct inode *, struct file *);
0032     ssize_t (*proc_read)(struct file *, char __user *, size_t, loff_t *);
0033     ssize_t (*proc_read_iter)(struct kiocb *, struct iov_iter *);
0034     ssize_t (*proc_write)(struct file *, const char __user *, size_t, loff_t *);
0035     /* mandatory unless nonseekable_open() or equivalent is used */
0036     loff_t  (*proc_lseek)(struct file *, loff_t, int);
0037     int (*proc_release)(struct inode *, struct file *);
0038     __poll_t (*proc_poll)(struct file *, struct poll_table_struct *);
0039     long    (*proc_ioctl)(struct file *, unsigned int, unsigned long);
0040 #ifdef CONFIG_COMPAT
0041     long    (*proc_compat_ioctl)(struct file *, unsigned int, unsigned long);
0042 #endif
0043     int (*proc_mmap)(struct file *, struct vm_area_struct *);
0044     unsigned long (*proc_get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
0045 } __randomize_layout;
0046 
0047 /* definitions for hide_pid field */
0048 enum proc_hidepid {
0049     HIDEPID_OFF   = 0,
0050     HIDEPID_NO_ACCESS = 1,
0051     HIDEPID_INVISIBLE = 2,
0052     HIDEPID_NOT_PTRACEABLE = 4, /* Limit pids to only ptraceable pids */
0053 };
0054 
0055 /* definitions for proc mount option pidonly */
0056 enum proc_pidonly {
0057     PROC_PIDONLY_OFF = 0,
0058     PROC_PIDONLY_ON  = 1,
0059 };
0060 
0061 struct proc_fs_info {
0062     struct pid_namespace *pid_ns;
0063     struct dentry *proc_self;        /* For /proc/self */
0064     struct dentry *proc_thread_self; /* For /proc/thread-self */
0065     kgid_t pid_gid;
0066     enum proc_hidepid hide_pid;
0067     enum proc_pidonly pidonly;
0068 };
0069 
0070 static inline struct proc_fs_info *proc_sb_info(struct super_block *sb)
0071 {
0072     return sb->s_fs_info;
0073 }
0074 
0075 #ifdef CONFIG_PROC_FS
0076 
0077 typedef int (*proc_write_t)(struct file *, char *, size_t);
0078 
0079 extern void proc_root_init(void);
0080 extern void proc_flush_pid(struct pid *);
0081 
0082 extern struct proc_dir_entry *proc_symlink(const char *,
0083         struct proc_dir_entry *, const char *);
0084 struct proc_dir_entry *_proc_mkdir(const char *, umode_t, struct proc_dir_entry *, void *, bool);
0085 extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *);
0086 extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
0087                           struct proc_dir_entry *, void *);
0088 extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
0089                           struct proc_dir_entry *);
0090 struct proc_dir_entry *proc_create_mount_point(const char *name);
0091 
0092 struct proc_dir_entry *proc_create_seq_private(const char *name, umode_t mode,
0093         struct proc_dir_entry *parent, const struct seq_operations *ops,
0094         unsigned int state_size, void *data);
0095 #define proc_create_seq_data(name, mode, parent, ops, data) \
0096     proc_create_seq_private(name, mode, parent, ops, 0, data)
0097 #define proc_create_seq(name, mode, parent, ops) \
0098     proc_create_seq_private(name, mode, parent, ops, 0, NULL)
0099 struct proc_dir_entry *proc_create_single_data(const char *name, umode_t mode,
0100         struct proc_dir_entry *parent,
0101         int (*show)(struct seq_file *, void *), void *data);
0102 #define proc_create_single(name, mode, parent, show) \
0103     proc_create_single_data(name, mode, parent, show, NULL)
0104  
0105 extern struct proc_dir_entry *proc_create_data(const char *, umode_t,
0106                            struct proc_dir_entry *,
0107                            const struct proc_ops *,
0108                            void *);
0109 
0110 struct proc_dir_entry *proc_create(const char *name, umode_t mode, struct proc_dir_entry *parent, const struct proc_ops *proc_ops);
0111 extern void proc_set_size(struct proc_dir_entry *, loff_t);
0112 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
0113 
0114 /*
0115  * Obtain the private data passed by user through proc_create_data() or
0116  * related.
0117  */
0118 static inline void *pde_data(const struct inode *inode)
0119 {
0120     return inode->i_private;
0121 }
0122 
0123 extern void *proc_get_parent_data(const struct inode *);
0124 extern void proc_remove(struct proc_dir_entry *);
0125 extern void remove_proc_entry(const char *, struct proc_dir_entry *);
0126 extern int remove_proc_subtree(const char *, struct proc_dir_entry *);
0127 
0128 struct proc_dir_entry *proc_create_net_data(const char *name, umode_t mode,
0129         struct proc_dir_entry *parent, const struct seq_operations *ops,
0130         unsigned int state_size, void *data);
0131 #define proc_create_net(name, mode, parent, ops, state_size) \
0132     proc_create_net_data(name, mode, parent, ops, state_size, NULL)
0133 struct proc_dir_entry *proc_create_net_single(const char *name, umode_t mode,
0134         struct proc_dir_entry *parent,
0135         int (*show)(struct seq_file *, void *), void *data);
0136 struct proc_dir_entry *proc_create_net_data_write(const char *name, umode_t mode,
0137                           struct proc_dir_entry *parent,
0138                           const struct seq_operations *ops,
0139                           proc_write_t write,
0140                           unsigned int state_size, void *data);
0141 struct proc_dir_entry *proc_create_net_single_write(const char *name, umode_t mode,
0142                             struct proc_dir_entry *parent,
0143                             int (*show)(struct seq_file *, void *),
0144                             proc_write_t write,
0145                             void *data);
0146 extern struct pid *tgid_pidfd_to_pid(const struct file *file);
0147 
0148 struct bpf_iter_aux_info;
0149 extern int bpf_iter_init_seq_net(void *priv_data, struct bpf_iter_aux_info *aux);
0150 extern void bpf_iter_fini_seq_net(void *priv_data);
0151 
0152 #ifdef CONFIG_PROC_PID_ARCH_STATUS
0153 /*
0154  * The architecture which selects CONFIG_PROC_PID_ARCH_STATUS must
0155  * provide proc_pid_arch_status() definition.
0156  */
0157 int proc_pid_arch_status(struct seq_file *m, struct pid_namespace *ns,
0158             struct pid *pid, struct task_struct *task);
0159 #endif /* CONFIG_PROC_PID_ARCH_STATUS */
0160 
0161 #else /* CONFIG_PROC_FS */
0162 
0163 static inline void proc_root_init(void)
0164 {
0165 }
0166 
0167 static inline void proc_flush_pid(struct pid *pid)
0168 {
0169 }
0170 
0171 static inline struct proc_dir_entry *proc_symlink(const char *name,
0172         struct proc_dir_entry *parent,const char *dest) { return NULL;}
0173 static inline struct proc_dir_entry *proc_mkdir(const char *name,
0174     struct proc_dir_entry *parent) {return NULL;}
0175 static inline struct proc_dir_entry *proc_create_mount_point(const char *name) { return NULL; }
0176 static inline struct proc_dir_entry *_proc_mkdir(const char *name, umode_t mode,
0177         struct proc_dir_entry *parent, void *data, bool force_lookup)
0178 {
0179     return NULL;
0180 }
0181 static inline struct proc_dir_entry *proc_mkdir_data(const char *name,
0182     umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
0183 static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
0184     umode_t mode, struct proc_dir_entry *parent) { return NULL; }
0185 #define proc_create_seq_private(name, mode, parent, ops, size, data) ({NULL;})
0186 #define proc_create_seq_data(name, mode, parent, ops, data) ({NULL;})
0187 #define proc_create_seq(name, mode, parent, ops) ({NULL;})
0188 #define proc_create_single(name, mode, parent, show) ({NULL;})
0189 #define proc_create_single_data(name, mode, parent, show, data) ({NULL;})
0190 
0191 static inline struct proc_dir_entry *
0192 proc_create(const char *name, umode_t mode, struct proc_dir_entry *parent,
0193         const struct proc_ops *proc_ops)
0194 { return NULL; }
0195 
0196 static inline struct proc_dir_entry *
0197 proc_create_data(const char *name, umode_t mode, struct proc_dir_entry *parent,
0198          const struct proc_ops *proc_ops, void *data)
0199 { return NULL; }
0200 
0201 static inline void proc_set_size(struct proc_dir_entry *de, loff_t size) {}
0202 static inline void proc_set_user(struct proc_dir_entry *de, kuid_t uid, kgid_t gid) {}
0203 static inline void *pde_data(const struct inode *inode) {BUG(); return NULL;}
0204 static inline void *proc_get_parent_data(const struct inode *inode) { BUG(); return NULL; }
0205 
0206 static inline void proc_remove(struct proc_dir_entry *de) {}
0207 #define remove_proc_entry(name, parent) do {} while (0)
0208 static inline int remove_proc_subtree(const char *name, struct proc_dir_entry *parent) { return 0; }
0209 
0210 #define proc_create_net_data(name, mode, parent, ops, state_size, data) ({NULL;})
0211 #define proc_create_net(name, mode, parent, state_size, ops) ({NULL;})
0212 #define proc_create_net_single(name, mode, parent, show, data) ({NULL;})
0213 
0214 static inline struct pid *tgid_pidfd_to_pid(const struct file *file)
0215 {
0216     return ERR_PTR(-EBADF);
0217 }
0218 
0219 #endif /* CONFIG_PROC_FS */
0220 
0221 struct net;
0222 
0223 static inline struct proc_dir_entry *proc_net_mkdir(
0224     struct net *net, const char *name, struct proc_dir_entry *parent)
0225 {
0226     return _proc_mkdir(name, 0, parent, net, true);
0227 }
0228 
0229 struct ns_common;
0230 int open_related_ns(struct ns_common *ns,
0231            struct ns_common *(*get_ns)(struct ns_common *ns));
0232 
0233 /* get the associated pid namespace for a file in procfs */
0234 static inline struct pid_namespace *proc_pid_ns(struct super_block *sb)
0235 {
0236     return proc_sb_info(sb)->pid_ns;
0237 }
0238 
0239 bool proc_ns_file(const struct file *file);
0240 
0241 #endif /* _LINUX_PROC_FS_H */