~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/include/linux/proc_fs.h

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  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         struct rcu_head rcu;
 69 };
 70 
 71 static inline struct proc_fs_info *proc_sb_info(struct super_block *sb)
 72 {
 73         return sb->s_fs_info;
 74 }
 75 
 76 #ifdef CONFIG_PROC_FS
 77 
 78 typedef int (*proc_write_t)(struct file *, char *, size_t);
 79 
 80 extern void proc_root_init(void);
 81 extern void proc_flush_pid(struct pid *);
 82 
 83 extern struct proc_dir_entry *proc_symlink(const char *,
 84                 struct proc_dir_entry *, const char *);
 85 struct proc_dir_entry *_proc_mkdir(const char *, umode_t, struct proc_dir_entry *, void *, bool);
 86 extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *);
 87 extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
 88                                               struct proc_dir_entry *, void *);
 89 extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
 90                                               struct proc_dir_entry *);
 91 struct proc_dir_entry *proc_create_mount_point(const char *name);
 92 
 93 struct proc_dir_entry *proc_create_seq_private(const char *name, umode_t mode,
 94                 struct proc_dir_entry *parent, const struct seq_operations *ops,
 95                 unsigned int state_size, void *data);
 96 #define proc_create_seq_data(name, mode, parent, ops, data) \
 97         proc_create_seq_private(name, mode, parent, ops, 0, data)
 98 #define proc_create_seq(name, mode, parent, ops) \
 99         proc_create_seq_private(name, mode, parent, ops, 0, NULL)
100 struct proc_dir_entry *proc_create_single_data(const char *name, umode_t mode,
101                 struct proc_dir_entry *parent,
102                 int (*show)(struct seq_file *, void *), void *data);
103 #define proc_create_single(name, mode, parent, show) \
104         proc_create_single_data(name, mode, parent, show, NULL)
105  
106 extern struct proc_dir_entry *proc_create_data(const char *, umode_t,
107                                                struct proc_dir_entry *,
108                                                const struct proc_ops *,
109                                                void *);
110 
111 struct proc_dir_entry *proc_create(const char *name, umode_t mode, struct proc_dir_entry *parent, const struct proc_ops *proc_ops);
112 extern void proc_set_size(struct proc_dir_entry *, loff_t);
113 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
114 
115 /*
116  * Obtain the private data passed by user through proc_create_data() or
117  * related.
118  */
119 static inline void *pde_data(const struct inode *inode)
120 {
121         return inode->i_private;
122 }
123 
124 extern void *proc_get_parent_data(const struct inode *);
125 extern void proc_remove(struct proc_dir_entry *);
126 extern void remove_proc_entry(const char *, struct proc_dir_entry *);
127 extern int remove_proc_subtree(const char *, struct proc_dir_entry *);
128 
129 struct proc_dir_entry *proc_create_net_data(const char *name, umode_t mode,
130                 struct proc_dir_entry *parent, const struct seq_operations *ops,
131                 unsigned int state_size, void *data);
132 #define proc_create_net(name, mode, parent, ops, state_size) \
133         proc_create_net_data(name, mode, parent, ops, state_size, NULL)
134 struct proc_dir_entry *proc_create_net_single(const char *name, umode_t mode,
135                 struct proc_dir_entry *parent,
136                 int (*show)(struct seq_file *, void *), void *data);
137 struct proc_dir_entry *proc_create_net_data_write(const char *name, umode_t mode,
138                                                   struct proc_dir_entry *parent,
139                                                   const struct seq_operations *ops,
140                                                   proc_write_t write,
141                                                   unsigned int state_size, void *data);
142 struct proc_dir_entry *proc_create_net_single_write(const char *name, umode_t mode,
143                                                     struct proc_dir_entry *parent,
144                                                     int (*show)(struct seq_file *, void *),
145                                                     proc_write_t write,
146                                                     void *data);
147 extern struct pid *tgid_pidfd_to_pid(const struct file *file);
148 
149 struct bpf_iter_aux_info;
150 extern int bpf_iter_init_seq_net(void *priv_data, struct bpf_iter_aux_info *aux);
151 extern void bpf_iter_fini_seq_net(void *priv_data);
152 
153 #ifdef CONFIG_PROC_PID_ARCH_STATUS
154 /*
155  * The architecture which selects CONFIG_PROC_PID_ARCH_STATUS must
156  * provide proc_pid_arch_status() definition.
157  */
158 int proc_pid_arch_status(struct seq_file *m, struct pid_namespace *ns,
159                         struct pid *pid, struct task_struct *task);
160 #endif /* CONFIG_PROC_PID_ARCH_STATUS */
161 
162 void arch_report_meminfo(struct seq_file *m);
163 void arch_proc_pid_thread_features(struct seq_file *m, struct task_struct *task);
164 
165 #else /* CONFIG_PROC_FS */
166 
167 static inline void proc_root_init(void)
168 {
169 }
170 
171 static inline void proc_flush_pid(struct pid *pid)
172 {
173 }
174 
175 static inline struct proc_dir_entry *proc_symlink(const char *name,
176                 struct proc_dir_entry *parent,const char *dest) { return NULL;}
177 static inline struct proc_dir_entry *proc_mkdir(const char *name,
178         struct proc_dir_entry *parent) {return NULL;}
179 static inline struct proc_dir_entry *proc_create_mount_point(const char *name) { return NULL; }
180 static inline struct proc_dir_entry *_proc_mkdir(const char *name, umode_t mode,
181                 struct proc_dir_entry *parent, void *data, bool force_lookup)
182 {
183         return NULL;
184 }
185 static inline struct proc_dir_entry *proc_mkdir_data(const char *name,
186         umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
187 static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
188         umode_t mode, struct proc_dir_entry *parent) { return NULL; }
189 #define proc_create_seq_private(name, mode, parent, ops, size, data) ({NULL;})
190 #define proc_create_seq_data(name, mode, parent, ops, data) ({NULL;})
191 #define proc_create_seq(name, mode, parent, ops) ({NULL;})
192 #define proc_create_single(name, mode, parent, show) ({NULL;})
193 #define proc_create_single_data(name, mode, parent, show, data) ({NULL;})
194 
195 static inline struct proc_dir_entry *
196 proc_create(const char *name, umode_t mode, struct proc_dir_entry *parent,
197             const struct proc_ops *proc_ops)
198 { return NULL; }
199 
200 static inline struct proc_dir_entry *
201 proc_create_data(const char *name, umode_t mode, struct proc_dir_entry *parent,
202                  const struct proc_ops *proc_ops, void *data)
203 { return NULL; }
204 
205 static inline void proc_set_size(struct proc_dir_entry *de, loff_t size) {}
206 static inline void proc_set_user(struct proc_dir_entry *de, kuid_t uid, kgid_t gid) {}
207 static inline void *pde_data(const struct inode *inode) {BUG(); return NULL;}
208 static inline void *proc_get_parent_data(const struct inode *inode) { BUG(); return NULL; }
209 
210 static inline void proc_remove(struct proc_dir_entry *de) {}
211 #define remove_proc_entry(name, parent) do {} while (0)
212 static inline int remove_proc_subtree(const char *name, struct proc_dir_entry *parent) { return 0; }
213 
214 #define proc_create_net_data(name, mode, parent, ops, state_size, data) ({NULL;})
215 #define proc_create_net_data_write(name, mode, parent, ops, write, state_size, data) ({NULL;})
216 #define proc_create_net(name, mode, parent, state_size, ops) ({NULL;})
217 #define proc_create_net_single(name, mode, parent, show, data) ({NULL;})
218 #define proc_create_net_single_write(name, mode, parent, show, write, data) ({NULL;})
219 
220 static inline struct pid *tgid_pidfd_to_pid(const struct file *file)
221 {
222         return ERR_PTR(-EBADF);
223 }
224 
225 #endif /* CONFIG_PROC_FS */
226 
227 struct net;
228 
229 static inline struct proc_dir_entry *proc_net_mkdir(
230         struct net *net, const char *name, struct proc_dir_entry *parent)
231 {
232         return _proc_mkdir(name, 0, parent, net, true);
233 }
234 
235 struct ns_common;
236 int open_related_ns(struct ns_common *ns,
237                    struct ns_common *(*get_ns)(struct ns_common *ns));
238 
239 /* get the associated pid namespace for a file in procfs */
240 static inline struct pid_namespace *proc_pid_ns(struct super_block *sb)
241 {
242         return proc_sb_info(sb)->pid_ns;
243 }
244 
245 bool proc_ns_file(const struct file *file);
246 
247 #endif /* _LINUX_PROC_FS_H */
248 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php