proc_fs.h 4.8 KB

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