LCOV - code coverage report
Current view: top level - include/linux - proc_fs.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 1 0.0 %
Date: 2023-04-06 08:38:28 Functions: 0 0 -

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

Generated by: LCOV version 1.14