]>
git.proxmox.com Git - mirror_ubuntu-kernels.git/blob - include/linux/proc_fs.h
1 /* SPDX-License-Identifier: GPL-2.0 */
3 * The proc filesystem constants/structures
5 #ifndef _LINUX_PROC_FS_H
6 #define _LINUX_PROC_FS_H
8 #include <linux/compiler.h>
9 #include <linux/types.h>
12 struct proc_dir_entry
;
14 struct seq_operations
;
18 * All /proc entries using this ->proc_ops instance are never removed.
20 * If in doubt, ignore this flag.
23 PROC_ENTRY_PERMANENT
= 0U,
25 PROC_ENTRY_PERMANENT
= 1U << 0,
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 loff_t (*proc_lseek
)(struct file
*, loff_t
, int);
36 int (*proc_release
)(struct inode
*, struct file
*);
37 __poll_t (*proc_poll
)(struct file
*, struct poll_table_struct
*);
38 long (*proc_ioctl
)(struct file
*, unsigned int, unsigned long);
40 long (*proc_compat_ioctl
)(struct file
*, unsigned int, unsigned long);
42 int (*proc_mmap
)(struct file
*, struct vm_area_struct
*);
43 unsigned long (*proc_get_unmapped_area
)(struct file
*, unsigned long, unsigned long, unsigned long, unsigned long);
46 /* definitions for hide_pid field */
49 HIDEPID_NO_ACCESS
= 1,
50 HIDEPID_INVISIBLE
= 2,
51 HIDEPID_NOT_PTRACEABLE
= 4, /* Limit pids to only ptraceable pids */
54 /* definitions for proc mount option pidonly */
61 struct pid_namespace
*pid_ns
;
62 struct dentry
*proc_self
; /* For /proc/self */
63 struct dentry
*proc_thread_self
; /* For /proc/thread-self */
65 enum proc_hidepid hide_pid
;
66 enum proc_pidonly pidonly
;
69 static inline struct proc_fs_info
*proc_sb_info(struct super_block
*sb
)
76 typedef int (*proc_write_t
)(struct file
*, char *, size_t);
78 extern void proc_root_init(void);
79 extern void proc_flush_pid(struct pid
*);
81 extern struct proc_dir_entry
*proc_symlink(const char *,
82 struct proc_dir_entry
*, const char *);
83 struct proc_dir_entry
*_proc_mkdir(const char *, umode_t
, struct proc_dir_entry
*, void *, bool);
84 extern struct proc_dir_entry
*proc_mkdir(const char *, struct proc_dir_entry
*);
85 extern struct proc_dir_entry
*proc_mkdir_data(const char *, umode_t
,
86 struct proc_dir_entry
*, void *);
87 extern struct proc_dir_entry
*proc_mkdir_mode(const char *, umode_t
,
88 struct proc_dir_entry
*);
89 struct proc_dir_entry
*proc_create_mount_point(const char *name
);
91 struct proc_dir_entry
*proc_create_seq_private(const char *name
, umode_t mode
,
92 struct proc_dir_entry
*parent
, const struct seq_operations
*ops
,
93 unsigned int state_size
, void *data
);
94 #define proc_create_seq_data(name, mode, parent, ops, data) \
95 proc_create_seq_private(name, mode, parent, ops, 0, data)
96 #define proc_create_seq(name, mode, parent, ops) \
97 proc_create_seq_private(name, mode, parent, ops, 0, NULL)
98 struct proc_dir_entry
*proc_create_single_data(const char *name
, umode_t mode
,
99 struct proc_dir_entry
*parent
,
100 int (*show
)(struct seq_file
*, void *), void *data
);
101 #define proc_create_single(name, mode, parent, show) \
102 proc_create_single_data(name, mode, parent, show, NULL)
104 extern struct proc_dir_entry
*proc_create_data(const char *, umode_t
,
105 struct proc_dir_entry
*,
106 const struct proc_ops
*,
109 struct proc_dir_entry
*proc_create(const char *name
, umode_t mode
, struct proc_dir_entry
*parent
, const struct proc_ops
*proc_ops
);
110 extern void proc_set_size(struct proc_dir_entry
*, loff_t
);
111 extern void proc_set_user(struct proc_dir_entry
*, kuid_t
, kgid_t
);
112 extern void *PDE_DATA(const struct inode
*);
113 extern void *proc_get_parent_data(const struct inode
*);
114 extern void proc_remove(struct proc_dir_entry
*);
115 extern void remove_proc_entry(const char *, struct proc_dir_entry
*);
116 extern int remove_proc_subtree(const char *, struct proc_dir_entry
*);
118 struct proc_dir_entry
*proc_create_net_data(const char *name
, umode_t mode
,
119 struct proc_dir_entry
*parent
, const struct seq_operations
*ops
,
120 unsigned int state_size
, void *data
);
121 #define proc_create_net(name, mode, parent, ops, state_size) \
122 proc_create_net_data(name, mode, parent, ops, state_size, NULL)
123 struct proc_dir_entry
*proc_create_net_single(const char *name
, umode_t mode
,
124 struct proc_dir_entry
*parent
,
125 int (*show
)(struct seq_file
*, void *), void *data
);
126 struct proc_dir_entry
*proc_create_net_data_write(const char *name
, umode_t mode
,
127 struct proc_dir_entry
*parent
,
128 const struct seq_operations
*ops
,
130 unsigned int state_size
, void *data
);
131 struct proc_dir_entry
*proc_create_net_single_write(const char *name
, umode_t mode
,
132 struct proc_dir_entry
*parent
,
133 int (*show
)(struct seq_file
*, void *),
136 extern struct pid
*tgid_pidfd_to_pid(const struct file
*file
);
138 struct bpf_iter_aux_info
;
139 extern int bpf_iter_init_seq_net(void *priv_data
, struct bpf_iter_aux_info
*aux
);
140 extern void bpf_iter_fini_seq_net(void *priv_data
);
142 #ifdef CONFIG_PROC_PID_ARCH_STATUS
144 * The architecture which selects CONFIG_PROC_PID_ARCH_STATUS must
145 * provide proc_pid_arch_status() definition.
147 int proc_pid_arch_status(struct seq_file
*m
, struct pid_namespace
*ns
,
148 struct pid
*pid
, struct task_struct
*task
);
149 #endif /* CONFIG_PROC_PID_ARCH_STATUS */
151 #else /* CONFIG_PROC_FS */
153 static inline void proc_root_init(void)
157 static inline void proc_flush_pid(struct pid
*pid
)
161 static inline struct proc_dir_entry
*proc_symlink(const char *name
,
162 struct proc_dir_entry
*parent
,const char *dest
) { return NULL
;}
163 static inline struct proc_dir_entry
*proc_mkdir(const char *name
,
164 struct proc_dir_entry
*parent
) {return NULL
;}
165 static inline struct proc_dir_entry
*proc_create_mount_point(const char *name
) { return NULL
; }
166 static inline struct proc_dir_entry
*_proc_mkdir(const char *name
, umode_t mode
,
167 struct proc_dir_entry
*parent
, void *data
, bool force_lookup
)
171 static inline struct proc_dir_entry
*proc_mkdir_data(const char *name
,
172 umode_t mode
, struct proc_dir_entry
*parent
, void *data
) { return NULL
; }
173 static inline struct proc_dir_entry
*proc_mkdir_mode(const char *name
,
174 umode_t mode
, struct proc_dir_entry
*parent
) { return NULL
; }
175 #define proc_create_seq_private(name, mode, parent, ops, size, data) ({NULL;})
176 #define proc_create_seq_data(name, mode, parent, ops, data) ({NULL;})
177 #define proc_create_seq(name, mode, parent, ops) ({NULL;})
178 #define proc_create_single(name, mode, parent, show) ({NULL;})
179 #define proc_create_single_data(name, mode, parent, show, data) ({NULL;})
180 #define proc_create(name, mode, parent, proc_ops) ({NULL;})
181 #define proc_create_data(name, mode, parent, proc_ops, data) ({NULL;})
183 static inline void proc_set_size(struct proc_dir_entry
*de
, loff_t size
) {}
184 static inline void proc_set_user(struct proc_dir_entry
*de
, kuid_t uid
, kgid_t gid
) {}
185 static inline void *PDE_DATA(const struct inode
*inode
) {BUG(); return NULL
;}
186 static inline void *proc_get_parent_data(const struct inode
*inode
) { BUG(); return NULL
; }
188 static inline void proc_remove(struct proc_dir_entry
*de
) {}
189 #define remove_proc_entry(name, parent) do {} while (0)
190 static inline int remove_proc_subtree(const char *name
, struct proc_dir_entry
*parent
) { return 0; }
192 #define proc_create_net_data(name, mode, parent, ops, state_size, data) ({NULL;})
193 #define proc_create_net(name, mode, parent, state_size, ops) ({NULL;})
194 #define proc_create_net_single(name, mode, parent, show, data) ({NULL;})
196 static inline struct pid
*tgid_pidfd_to_pid(const struct file
*file
)
198 return ERR_PTR(-EBADF
);
201 #endif /* CONFIG_PROC_FS */
205 static inline struct proc_dir_entry
*proc_net_mkdir(
206 struct net
*net
, const char *name
, struct proc_dir_entry
*parent
)
208 return _proc_mkdir(name
, 0, parent
, net
, true);
212 int open_related_ns(struct ns_common
*ns
,
213 struct ns_common
*(*get_ns
)(struct ns_common
*ns
));
215 /* get the associated pid namespace for a file in procfs */
216 static inline struct pid_namespace
*proc_pid_ns(struct super_block
*sb
)
218 return proc_sb_info(sb
)->pid_ns
;
221 bool proc_ns_file(const struct file
*file
);
223 #endif /* _LINUX_PROC_FS_H */