proc_fs.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. #ifndef _LINUX_PROC_FS_H
  2. #define _LINUX_PROC_FS_H
  3. #include <linux/slab.h>
  4. #include <linux/fs.h>
  5. #include <linux/spinlock.h>
  6. #include <linux/magic.h>
  7. #include <linux/atomic.h>
  8. #include <linux/proc_ns.h>
  9. struct net;
  10. struct completion;
  11. struct mm_struct;
  12. /*
  13. * The proc filesystem constants/structures
  14. */
  15. /*
  16. * Offset of the first process in the /proc root directory..
  17. */
  18. #define FIRST_PROCESS_ENTRY 256
  19. /* Worst case buffer size needed for holding an integer. */
  20. #define PROC_NUMBUF 13
  21. /*
  22. * This is not completely implemented yet. The idea is to
  23. * create an in-memory tree (like the actual /proc filesystem
  24. * tree) of these proc_dir_entries, so that we can dynamically
  25. * add new files to /proc.
  26. *
  27. * The "next" pointer creates a linked list of one /proc directory,
  28. * while parent/subdir create the directory structure (every
  29. * /proc file has a parent, but "subdir" is NULL for all
  30. * non-directory entries).
  31. */
  32. struct proc_dir_entry {
  33. unsigned int low_ino;
  34. umode_t mode;
  35. nlink_t nlink;
  36. kuid_t uid;
  37. kgid_t gid;
  38. loff_t size;
  39. const struct inode_operations *proc_iops;
  40. const struct file_operations *proc_fops;
  41. struct proc_dir_entry *next, *parent, *subdir;
  42. void *data;
  43. atomic_t count; /* use count */
  44. atomic_t in_use; /* number of callers into module in progress; */
  45. /* negative -> it's going away RSN */
  46. struct completion *pde_unload_completion;
  47. struct list_head pde_openers; /* who did ->open, but not ->release */
  48. spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
  49. u8 namelen;
  50. char name[];
  51. };
  52. #ifdef CONFIG_PROC_FS
  53. extern void proc_root_init(void);
  54. void proc_flush_task(struct task_struct *task);
  55. struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
  56. struct proc_dir_entry *parent,
  57. const struct file_operations *proc_fops,
  58. void *data);
  59. extern void remove_proc_entry(const char *name, struct proc_dir_entry *parent);
  60. extern int remove_proc_subtree(const char *name, struct proc_dir_entry *parent);
  61. extern struct proc_dir_entry *proc_symlink(const char *,
  62. struct proc_dir_entry *, const char *);
  63. extern struct proc_dir_entry *proc_mkdir(const char *,struct proc_dir_entry *);
  64. extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
  65. struct proc_dir_entry *, void *);
  66. extern struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
  67. struct proc_dir_entry *parent);
  68. static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
  69. struct proc_dir_entry *parent, const struct file_operations *proc_fops)
  70. {
  71. return proc_create_data(name, mode, parent, proc_fops, NULL);
  72. }
  73. extern void proc_set_size(struct proc_dir_entry *, loff_t);
  74. extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
  75. #else
  76. static inline void proc_flush_task(struct task_struct *task)
  77. {
  78. }
  79. #define proc_create(name, mode, parent, fops) ({ (void)(mode), NULL; })
  80. static inline struct proc_dir_entry *proc_create_data(const char *name,
  81. umode_t mode, struct proc_dir_entry *parent,
  82. const struct file_operations *proc_fops, void *data)
  83. {
  84. return NULL;
  85. }
  86. #define remove_proc_entry(name, parent) do {} while (0)
  87. #define remove_proc_subtree(name, parent) do {} while (0)
  88. static inline struct proc_dir_entry *proc_symlink(const char *name,
  89. struct proc_dir_entry *parent,const char *dest) {return NULL;}
  90. static inline struct proc_dir_entry *proc_mkdir(const char *name,
  91. struct proc_dir_entry *parent) {return NULL;}
  92. static inline struct proc_dir_entry *proc_mkdir_data(const char *name,
  93. umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
  94. static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
  95. umode_t mode, struct proc_dir_entry *parent) { return NULL; }
  96. static inline void proc_set_size(struct proc_dir_entry *de, loff_t size) {}
  97. static inline void proc_set_user(struct proc_dir_entry *de, kuid_t uid, kgid_t gid) {}
  98. #endif /* CONFIG_PROC_FS */
  99. union proc_op {
  100. int (*proc_get_link)(struct dentry *, struct path *);
  101. int (*proc_read)(struct task_struct *task, char *page);
  102. int (*proc_show)(struct seq_file *m,
  103. struct pid_namespace *ns, struct pid *pid,
  104. struct task_struct *task);
  105. };
  106. struct ctl_table_header;
  107. struct ctl_table;
  108. struct proc_inode {
  109. struct pid *pid;
  110. int fd;
  111. union proc_op op;
  112. struct proc_dir_entry *pde;
  113. struct ctl_table_header *sysctl;
  114. struct ctl_table *sysctl_entry;
  115. struct proc_ns ns;
  116. struct inode vfs_inode;
  117. };
  118. static inline struct proc_inode *PROC_I(const struct inode *inode)
  119. {
  120. return container_of(inode, struct proc_inode, vfs_inode);
  121. }
  122. static inline struct proc_dir_entry *PDE(const struct inode *inode)
  123. {
  124. return PROC_I(inode)->pde;
  125. }
  126. static inline void *PDE_DATA(const struct inode *inode)
  127. {
  128. return PROC_I(inode)->pde->data;
  129. }
  130. static inline struct proc_dir_entry *proc_net_mkdir(
  131. struct net *net, const char *name, struct proc_dir_entry *parent)
  132. {
  133. return proc_mkdir_data(name, 0, parent, net);
  134. }
  135. #endif /* _LINUX_PROC_FS_H */