proc_fs.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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 proc_remove(struct proc_dir_entry *);
  60. extern void remove_proc_entry(const char *name, struct proc_dir_entry *parent);
  61. extern int remove_proc_subtree(const char *name, struct proc_dir_entry *parent);
  62. extern struct proc_dir_entry *proc_symlink(const char *,
  63. struct proc_dir_entry *, const char *);
  64. extern struct proc_dir_entry *proc_mkdir(const char *,struct proc_dir_entry *);
  65. extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
  66. struct proc_dir_entry *, void *);
  67. extern struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
  68. struct proc_dir_entry *parent);
  69. static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
  70. struct proc_dir_entry *parent, const struct file_operations *proc_fops)
  71. {
  72. return proc_create_data(name, mode, parent, proc_fops, NULL);
  73. }
  74. extern void proc_set_size(struct proc_dir_entry *, loff_t);
  75. extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
  76. extern void *proc_get_parent_data(const struct inode *);
  77. #else
  78. static inline void proc_flush_task(struct task_struct *task)
  79. {
  80. }
  81. #define proc_create(name, mode, parent, fops) ({ (void)(mode), NULL; })
  82. static inline struct proc_dir_entry *proc_create_data(const char *name,
  83. umode_t mode, struct proc_dir_entry *parent,
  84. const struct file_operations *proc_fops, void *data)
  85. {
  86. return NULL;
  87. }
  88. static inline void proc_remove(struct proc_dir_entry *de) {}
  89. #define remove_proc_entry(name, parent) do {} while (0)
  90. #define remove_proc_subtree(name, parent) do {} while (0)
  91. static inline struct proc_dir_entry *proc_symlink(const char *name,
  92. struct proc_dir_entry *parent,const char *dest) {return NULL;}
  93. static inline struct proc_dir_entry *proc_mkdir(const char *name,
  94. struct proc_dir_entry *parent) {return NULL;}
  95. static inline struct proc_dir_entry *proc_mkdir_data(const char *name,
  96. umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
  97. static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
  98. umode_t mode, struct proc_dir_entry *parent) { return NULL; }
  99. static inline void proc_set_size(struct proc_dir_entry *de, loff_t size) {}
  100. static inline void proc_set_user(struct proc_dir_entry *de, kuid_t uid, kgid_t gid) {}
  101. #endif /* CONFIG_PROC_FS */
  102. union proc_op {
  103. int (*proc_get_link)(struct dentry *, struct path *);
  104. int (*proc_read)(struct task_struct *task, char *page);
  105. int (*proc_show)(struct seq_file *m,
  106. struct pid_namespace *ns, struct pid *pid,
  107. struct task_struct *task);
  108. };
  109. struct ctl_table_header;
  110. struct ctl_table;
  111. struct proc_inode {
  112. struct pid *pid;
  113. int fd;
  114. union proc_op op;
  115. struct proc_dir_entry *pde;
  116. struct ctl_table_header *sysctl;
  117. struct ctl_table *sysctl_entry;
  118. struct proc_ns ns;
  119. struct inode vfs_inode;
  120. };
  121. static inline struct proc_inode *PROC_I(const struct inode *inode)
  122. {
  123. return container_of(inode, struct proc_inode, vfs_inode);
  124. }
  125. static inline struct proc_dir_entry *PDE(const struct inode *inode)
  126. {
  127. return PROC_I(inode)->pde;
  128. }
  129. static inline void *PDE_DATA(const struct inode *inode)
  130. {
  131. return PROC_I(inode)->pde->data;
  132. }
  133. static inline struct proc_dir_entry *proc_net_mkdir(
  134. struct net *net, const char *name, struct proc_dir_entry *parent)
  135. {
  136. return proc_mkdir_data(name, 0, parent, net);
  137. }
  138. #endif /* _LINUX_PROC_FS_H */