proc_fs.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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/types.h>
  8. #include <linux/fs.h>
  9. struct proc_dir_entry;
  10. struct seq_file;
  11. struct seq_operations;
  12. #ifdef CONFIG_PROC_FS
  13. typedef int (*proc_write_t)(struct file *, char *, size_t);
  14. extern void proc_root_init(void);
  15. extern void proc_flush_task(struct task_struct *);
  16. extern struct proc_dir_entry *proc_symlink(const char *,
  17. struct proc_dir_entry *, const char *);
  18. extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *);
  19. extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
  20. struct proc_dir_entry *, void *);
  21. extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
  22. struct proc_dir_entry *);
  23. struct proc_dir_entry *proc_create_mount_point(const char *name);
  24. struct proc_dir_entry *proc_create_seq_private(const char *name, umode_t mode,
  25. struct proc_dir_entry *parent, const struct seq_operations *ops,
  26. unsigned int state_size, void *data);
  27. #define proc_create_seq_data(name, mode, parent, ops, data) \
  28. proc_create_seq_private(name, mode, parent, ops, 0, data)
  29. #define proc_create_seq(name, mode, parent, ops) \
  30. proc_create_seq_private(name, mode, parent, ops, 0, NULL)
  31. struct proc_dir_entry *proc_create_single_data(const char *name, umode_t mode,
  32. struct proc_dir_entry *parent,
  33. int (*show)(struct seq_file *, void *), void *data);
  34. #define proc_create_single(name, mode, parent, show) \
  35. proc_create_single_data(name, mode, parent, show, NULL)
  36. extern struct proc_dir_entry *proc_create_data(const char *, umode_t,
  37. struct proc_dir_entry *,
  38. const struct file_operations *,
  39. void *);
  40. struct proc_dir_entry *proc_create(const char *name, umode_t mode, struct proc_dir_entry *parent, const struct file_operations *proc_fops);
  41. extern void proc_set_size(struct proc_dir_entry *, loff_t);
  42. extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
  43. extern void *PDE_DATA(const struct inode *);
  44. extern void *proc_get_parent_data(const struct inode *);
  45. extern void proc_remove(struct proc_dir_entry *);
  46. extern void remove_proc_entry(const char *, struct proc_dir_entry *);
  47. extern int remove_proc_subtree(const char *, struct proc_dir_entry *);
  48. struct proc_dir_entry *proc_create_net_data(const char *name, umode_t mode,
  49. struct proc_dir_entry *parent, const struct seq_operations *ops,
  50. unsigned int state_size, void *data);
  51. #define proc_create_net(name, mode, parent, state_size, ops) \
  52. proc_create_net_data(name, mode, parent, state_size, ops, NULL)
  53. struct proc_dir_entry *proc_create_net_single(const char *name, umode_t mode,
  54. struct proc_dir_entry *parent,
  55. int (*show)(struct seq_file *, void *), void *data);
  56. struct proc_dir_entry *proc_create_net_data_write(const char *name, umode_t mode,
  57. struct proc_dir_entry *parent,
  58. const struct seq_operations *ops,
  59. proc_write_t write,
  60. unsigned int state_size, void *data);
  61. struct proc_dir_entry *proc_create_net_single_write(const char *name, umode_t mode,
  62. struct proc_dir_entry *parent,
  63. int (*show)(struct seq_file *, void *),
  64. proc_write_t write,
  65. void *data);
  66. #else /* CONFIG_PROC_FS */
  67. static inline void proc_root_init(void)
  68. {
  69. }
  70. static inline void proc_flush_task(struct task_struct *task)
  71. {
  72. }
  73. static inline struct proc_dir_entry *proc_symlink(const char *name,
  74. struct proc_dir_entry *parent,const char *dest) { return NULL;}
  75. static inline struct proc_dir_entry *proc_mkdir(const char *name,
  76. struct proc_dir_entry *parent) {return NULL;}
  77. static inline struct proc_dir_entry *proc_create_mount_point(const char *name) { return NULL; }
  78. static inline struct proc_dir_entry *proc_mkdir_data(const char *name,
  79. umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
  80. static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
  81. umode_t mode, struct proc_dir_entry *parent) { return NULL; }
  82. #define proc_create_seq_private(name, mode, parent, ops, size, data) ({NULL;})
  83. #define proc_create_seq_data(name, mode, parent, ops, data) ({NULL;})
  84. #define proc_create_seq(name, mode, parent, ops) ({NULL;})
  85. #define proc_create_single(name, mode, parent, show) ({NULL;})
  86. #define proc_create_single_data(name, mode, parent, show, data) ({NULL;})
  87. #define proc_create(name, mode, parent, proc_fops) ({NULL;})
  88. #define proc_create_data(name, mode, parent, proc_fops, data) ({NULL;})
  89. static inline void proc_set_size(struct proc_dir_entry *de, loff_t size) {}
  90. static inline void proc_set_user(struct proc_dir_entry *de, kuid_t uid, kgid_t gid) {}
  91. static inline void *PDE_DATA(const struct inode *inode) {BUG(); return NULL;}
  92. static inline void *proc_get_parent_data(const struct inode *inode) { BUG(); return NULL; }
  93. static inline void proc_remove(struct proc_dir_entry *de) {}
  94. #define remove_proc_entry(name, parent) do {} while (0)
  95. static inline int remove_proc_subtree(const char *name, struct proc_dir_entry *parent) { return 0; }
  96. #define proc_create_net_data(name, mode, parent, ops, state_size, data) ({NULL;})
  97. #define proc_create_net(name, mode, parent, state_size, ops) ({NULL;})
  98. #define proc_create_net_single(name, mode, parent, show, data) ({NULL;})
  99. #endif /* CONFIG_PROC_FS */
  100. struct net;
  101. static inline struct proc_dir_entry *proc_net_mkdir(
  102. struct net *net, const char *name, struct proc_dir_entry *parent)
  103. {
  104. return proc_mkdir_data(name, 0, parent, net);
  105. }
  106. struct ns_common;
  107. int open_related_ns(struct ns_common *ns,
  108. struct ns_common *(*get_ns)(struct ns_common *ns));
  109. /* get the associated pid namespace for a file in procfs */
  110. static inline struct pid_namespace *proc_pid_ns(const struct inode *inode)
  111. {
  112. return inode->i_sb->s_fs_info;
  113. }
  114. #endif /* _LINUX_PROC_FS_H */