proc_fs.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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. #include <linux/compiler.h>
  8. #include <linux/types.h>
  9. #include <linux/fs.h>
  10. struct proc_dir_entry;
  11. struct seq_file;
  12. struct seq_operations;
  13. enum {
  14. /*
  15. * All /proc entries using this ->proc_ops instance are never removed.
  16. *
  17. * If in doubt, ignore this flag.
  18. */
  19. #ifdef MODULE
  20. PROC_ENTRY_PERMANENT = 0U,
  21. #else
  22. PROC_ENTRY_PERMANENT = 1U << 0,
  23. #endif
  24. };
  25. struct proc_ops {
  26. unsigned int proc_flags;
  27. int (*proc_open)(struct inode *, struct file *);
  28. ssize_t (*proc_read)(struct file *, char __user *, size_t, loff_t *);
  29. ssize_t (*proc_read_iter)(struct kiocb *, struct iov_iter *);
  30. ssize_t (*proc_write)(struct file *, const char __user *, size_t, loff_t *);
  31. loff_t (*proc_lseek)(struct file *, loff_t, int);
  32. int (*proc_release)(struct inode *, struct file *);
  33. __poll_t (*proc_poll)(struct file *, struct poll_table_struct *);
  34. long (*proc_ioctl)(struct file *, unsigned int, unsigned long);
  35. #ifdef CONFIG_COMPAT
  36. long (*proc_compat_ioctl)(struct file *, unsigned int, unsigned long);
  37. #endif
  38. int (*proc_mmap)(struct file *, struct vm_area_struct *);
  39. unsigned long (*proc_get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
  40. } __randomize_layout;
  41. /* definitions for hide_pid field */
  42. enum proc_hidepid {
  43. HIDEPID_OFF = 0,
  44. HIDEPID_NO_ACCESS = 1,
  45. HIDEPID_INVISIBLE = 2,
  46. HIDEPID_NOT_PTRACEABLE = 4, /* Limit pids to only ptraceable pids */
  47. };
  48. /* definitions for proc mount option pidonly */
  49. enum proc_pidonly {
  50. PROC_PIDONLY_OFF = 0,
  51. PROC_PIDONLY_ON = 1,
  52. };
  53. struct proc_fs_info {
  54. struct pid_namespace *pid_ns;
  55. struct dentry *proc_self; /* For /proc/self */
  56. struct dentry *proc_thread_self; /* For /proc/thread-self */
  57. kgid_t pid_gid;
  58. enum proc_hidepid hide_pid;
  59. enum proc_pidonly pidonly;
  60. };
  61. static inline struct proc_fs_info *proc_sb_info(struct super_block *sb)
  62. {
  63. return sb->s_fs_info;
  64. }
  65. #ifdef CONFIG_PROC_FS
  66. typedef int (*proc_write_t)(struct file *, char *, size_t);
  67. extern void proc_root_init(void);
  68. extern void proc_flush_pid(struct pid *);
  69. extern struct proc_dir_entry *proc_symlink(const char *,
  70. struct proc_dir_entry *, const char *);
  71. struct proc_dir_entry *_proc_mkdir(const char *, umode_t, struct proc_dir_entry *, void *, bool);
  72. extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *);
  73. extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
  74. struct proc_dir_entry *, void *);
  75. extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
  76. struct proc_dir_entry *);
  77. struct proc_dir_entry *proc_create_mount_point(const char *name);
  78. struct proc_dir_entry *proc_create_seq_private(const char *name, umode_t mode,
  79. struct proc_dir_entry *parent, const struct seq_operations *ops,
  80. unsigned int state_size, void *data);
  81. #define proc_create_seq_data(name, mode, parent, ops, data) \
  82. proc_create_seq_private(name, mode, parent, ops, 0, data)
  83. #define proc_create_seq(name, mode, parent, ops) \
  84. proc_create_seq_private(name, mode, parent, ops, 0, NULL)
  85. struct proc_dir_entry *proc_create_single_data(const char *name, umode_t mode,
  86. struct proc_dir_entry *parent,
  87. int (*show)(struct seq_file *, void *), void *data);
  88. #define proc_create_single(name, mode, parent, show) \
  89. proc_create_single_data(name, mode, parent, show, NULL)
  90. extern struct proc_dir_entry *proc_create_data(const char *, umode_t,
  91. struct proc_dir_entry *,
  92. const struct proc_ops *,
  93. void *);
  94. struct proc_dir_entry *proc_create(const char *name, umode_t mode, struct proc_dir_entry *parent, const struct proc_ops *proc_ops);
  95. extern void proc_set_size(struct proc_dir_entry *, loff_t);
  96. extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
  97. extern void *PDE_DATA(const struct inode *);
  98. extern void *proc_get_parent_data(const struct inode *);
  99. extern void proc_remove(struct proc_dir_entry *);
  100. extern void remove_proc_entry(const char *, struct proc_dir_entry *);
  101. extern int remove_proc_subtree(const char *, struct proc_dir_entry *);
  102. struct proc_dir_entry *proc_create_net_data(const char *name, umode_t mode,
  103. struct proc_dir_entry *parent, const struct seq_operations *ops,
  104. unsigned int state_size, void *data);
  105. #define proc_create_net(name, mode, parent, ops, state_size) \
  106. proc_create_net_data(name, mode, parent, ops, state_size, NULL)
  107. struct proc_dir_entry *proc_create_net_single(const char *name, umode_t mode,
  108. struct proc_dir_entry *parent,
  109. int (*show)(struct seq_file *, void *), void *data);
  110. struct proc_dir_entry *proc_create_net_data_write(const char *name, umode_t mode,
  111. struct proc_dir_entry *parent,
  112. const struct seq_operations *ops,
  113. proc_write_t write,
  114. unsigned int state_size, void *data);
  115. struct proc_dir_entry *proc_create_net_single_write(const char *name, umode_t mode,
  116. struct proc_dir_entry *parent,
  117. int (*show)(struct seq_file *, void *),
  118. proc_write_t write,
  119. void *data);
  120. extern struct pid *tgid_pidfd_to_pid(const struct file *file);
  121. struct bpf_iter_aux_info;
  122. extern int bpf_iter_init_seq_net(void *priv_data, struct bpf_iter_aux_info *aux);
  123. extern void bpf_iter_fini_seq_net(void *priv_data);
  124. #ifdef CONFIG_PROC_PID_ARCH_STATUS
  125. /*
  126. * The architecture which selects CONFIG_PROC_PID_ARCH_STATUS must
  127. * provide proc_pid_arch_status() definition.
  128. */
  129. int proc_pid_arch_status(struct seq_file *m, struct pid_namespace *ns,
  130. struct pid *pid, struct task_struct *task);
  131. #endif /* CONFIG_PROC_PID_ARCH_STATUS */
  132. #else /* CONFIG_PROC_FS */
  133. static inline void proc_root_init(void)
  134. {
  135. }
  136. static inline void proc_flush_pid(struct pid *pid)
  137. {
  138. }
  139. static inline struct proc_dir_entry *proc_symlink(const char *name,
  140. struct proc_dir_entry *parent,const char *dest) { return NULL;}
  141. static inline struct proc_dir_entry *proc_mkdir(const char *name,
  142. struct proc_dir_entry *parent) {return NULL;}
  143. static inline struct proc_dir_entry *proc_create_mount_point(const char *name) { return NULL; }
  144. static inline struct proc_dir_entry *_proc_mkdir(const char *name, umode_t mode,
  145. struct proc_dir_entry *parent, void *data, bool force_lookup)
  146. {
  147. return NULL;
  148. }
  149. static inline struct proc_dir_entry *proc_mkdir_data(const char *name,
  150. umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
  151. static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
  152. umode_t mode, struct proc_dir_entry *parent) { return NULL; }
  153. #define proc_create_seq_private(name, mode, parent, ops, size, data) ({NULL;})
  154. #define proc_create_seq_data(name, mode, parent, ops, data) ({NULL;})
  155. #define proc_create_seq(name, mode, parent, ops) ({NULL;})
  156. #define proc_create_single(name, mode, parent, show) ({NULL;})
  157. #define proc_create_single_data(name, mode, parent, show, data) ({NULL;})
  158. #define proc_create(name, mode, parent, proc_ops) ({NULL;})
  159. #define proc_create_data(name, mode, parent, proc_ops, data) ({NULL;})
  160. static inline void proc_set_size(struct proc_dir_entry *de, loff_t size) {}
  161. static inline void proc_set_user(struct proc_dir_entry *de, kuid_t uid, kgid_t gid) {}
  162. static inline void *PDE_DATA(const struct inode *inode) {BUG(); return NULL;}
  163. static inline void *proc_get_parent_data(const struct inode *inode) { BUG(); return NULL; }
  164. static inline void proc_remove(struct proc_dir_entry *de) {}
  165. #define remove_proc_entry(name, parent) do {} while (0)
  166. static inline int remove_proc_subtree(const char *name, struct proc_dir_entry *parent) { return 0; }
  167. #define proc_create_net_data(name, mode, parent, ops, state_size, data) ({NULL;})
  168. #define proc_create_net(name, mode, parent, state_size, ops) ({NULL;})
  169. #define proc_create_net_single(name, mode, parent, show, data) ({NULL;})
  170. static inline struct pid *tgid_pidfd_to_pid(const struct file *file)
  171. {
  172. return ERR_PTR(-EBADF);
  173. }
  174. #endif /* CONFIG_PROC_FS */
  175. struct net;
  176. static inline struct proc_dir_entry *proc_net_mkdir(
  177. struct net *net, const char *name, struct proc_dir_entry *parent)
  178. {
  179. return _proc_mkdir(name, 0, parent, net, true);
  180. }
  181. struct ns_common;
  182. int open_related_ns(struct ns_common *ns,
  183. struct ns_common *(*get_ns)(struct ns_common *ns));
  184. /* get the associated pid namespace for a file in procfs */
  185. static inline struct pid_namespace *proc_pid_ns(struct super_block *sb)
  186. {
  187. return proc_sb_info(sb)->pid_ns;
  188. }
  189. bool proc_ns_file(const struct file *file);
  190. #endif /* _LINUX_PROC_FS_H */