internal.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. /* Internal procfs definitions
  2. *
  3. * Copyright (C) 2004 Red Hat, Inc. All Rights Reserved.
  4. * Written by David Howells (dhowells@redhat.com)
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. */
  11. #include <linux/proc_fs.h>
  12. #include <linux/proc_ns.h>
  13. #include <linux/spinlock.h>
  14. #include <linux/atomic.h>
  15. #include <linux/binfmts.h>
  16. struct ctl_table_header;
  17. struct mempolicy;
  18. /*
  19. * This is not completely implemented yet. The idea is to
  20. * create an in-memory tree (like the actual /proc filesystem
  21. * tree) of these proc_dir_entries, so that we can dynamically
  22. * add new files to /proc.
  23. *
  24. * The "next" pointer creates a linked list of one /proc directory,
  25. * while parent/subdir create the directory structure (every
  26. * /proc file has a parent, but "subdir" is NULL for all
  27. * non-directory entries).
  28. */
  29. struct proc_dir_entry {
  30. unsigned int low_ino;
  31. umode_t mode;
  32. nlink_t nlink;
  33. kuid_t uid;
  34. kgid_t gid;
  35. loff_t size;
  36. const struct inode_operations *proc_iops;
  37. const struct file_operations *proc_fops;
  38. struct proc_dir_entry *next, *parent, *subdir;
  39. void *data;
  40. atomic_t count; /* use count */
  41. atomic_t in_use; /* number of callers into module in progress; */
  42. /* negative -> it's going away RSN */
  43. struct completion *pde_unload_completion;
  44. struct list_head pde_openers; /* who did ->open, but not ->release */
  45. spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
  46. u8 namelen;
  47. char name[];
  48. };
  49. union proc_op {
  50. int (*proc_get_link)(struct dentry *, struct path *);
  51. int (*proc_show)(struct seq_file *m,
  52. struct pid_namespace *ns, struct pid *pid,
  53. struct task_struct *task);
  54. };
  55. struct proc_inode {
  56. struct pid *pid;
  57. int fd;
  58. union proc_op op;
  59. struct proc_dir_entry *pde;
  60. struct ctl_table_header *sysctl;
  61. struct ctl_table *sysctl_entry;
  62. struct proc_ns ns;
  63. struct inode vfs_inode;
  64. };
  65. /*
  66. * General functions
  67. */
  68. static inline struct proc_inode *PROC_I(const struct inode *inode)
  69. {
  70. return container_of(inode, struct proc_inode, vfs_inode);
  71. }
  72. static inline struct proc_dir_entry *PDE(const struct inode *inode)
  73. {
  74. return PROC_I(inode)->pde;
  75. }
  76. static inline void *__PDE_DATA(const struct inode *inode)
  77. {
  78. return PDE(inode)->data;
  79. }
  80. static inline struct pid *proc_pid(struct inode *inode)
  81. {
  82. return PROC_I(inode)->pid;
  83. }
  84. static inline struct task_struct *get_proc_task(struct inode *inode)
  85. {
  86. return get_pid_task(proc_pid(inode), PIDTYPE_PID);
  87. }
  88. static inline int task_dumpable(struct task_struct *task)
  89. {
  90. int dumpable = 0;
  91. struct mm_struct *mm;
  92. task_lock(task);
  93. mm = task->mm;
  94. if (mm)
  95. dumpable = get_dumpable(mm);
  96. task_unlock(task);
  97. if (dumpable == SUID_DUMP_USER)
  98. return 1;
  99. return 0;
  100. }
  101. static inline unsigned name_to_int(const struct qstr *qstr)
  102. {
  103. const char *name = qstr->name;
  104. int len = qstr->len;
  105. unsigned n = 0;
  106. if (len > 1 && *name == '0')
  107. goto out;
  108. while (len-- > 0) {
  109. unsigned c = *name++ - '0';
  110. if (c > 9)
  111. goto out;
  112. if (n >= (~0U-9)/10)
  113. goto out;
  114. n *= 10;
  115. n += c;
  116. }
  117. return n;
  118. out:
  119. return ~0U;
  120. }
  121. /*
  122. * Offset of the first process in the /proc root directory..
  123. */
  124. #define FIRST_PROCESS_ENTRY 256
  125. /* Worst case buffer size needed for holding an integer. */
  126. #define PROC_NUMBUF 13
  127. /*
  128. * array.c
  129. */
  130. extern const struct file_operations proc_tid_children_operations;
  131. extern int proc_tid_stat(struct seq_file *, struct pid_namespace *,
  132. struct pid *, struct task_struct *);
  133. extern int proc_tgid_stat(struct seq_file *, struct pid_namespace *,
  134. struct pid *, struct task_struct *);
  135. extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
  136. struct pid *, struct task_struct *);
  137. extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
  138. struct pid *, struct task_struct *);
  139. /*
  140. * base.c
  141. */
  142. extern const struct dentry_operations pid_dentry_operations;
  143. extern int pid_getattr(struct vfsmount *, struct dentry *, struct kstat *);
  144. extern int proc_setattr(struct dentry *, struct iattr *);
  145. extern struct inode *proc_pid_make_inode(struct super_block *, struct task_struct *);
  146. extern int pid_revalidate(struct dentry *, unsigned int);
  147. extern int pid_delete_dentry(const struct dentry *);
  148. extern int proc_pid_readdir(struct file *, struct dir_context *);
  149. extern struct dentry *proc_pid_lookup(struct inode *, struct dentry *, unsigned int);
  150. extern loff_t mem_lseek(struct file *, loff_t, int);
  151. /* Lookups */
  152. typedef int instantiate_t(struct inode *, struct dentry *,
  153. struct task_struct *, const void *);
  154. extern bool proc_fill_cache(struct file *, struct dir_context *, const char *, int,
  155. instantiate_t, struct task_struct *, const void *);
  156. /*
  157. * generic.c
  158. */
  159. extern struct dentry *proc_lookup(struct inode *, struct dentry *, unsigned int);
  160. extern struct dentry *proc_lookup_de(struct proc_dir_entry *, struct inode *,
  161. struct dentry *);
  162. extern int proc_readdir(struct file *, struct dir_context *);
  163. extern int proc_readdir_de(struct proc_dir_entry *, struct file *, struct dir_context *);
  164. static inline struct proc_dir_entry *pde_get(struct proc_dir_entry *pde)
  165. {
  166. atomic_inc(&pde->count);
  167. return pde;
  168. }
  169. extern void pde_put(struct proc_dir_entry *);
  170. /*
  171. * inode.c
  172. */
  173. struct pde_opener {
  174. struct file *file;
  175. struct list_head lh;
  176. int closing;
  177. struct completion *c;
  178. };
  179. extern const struct inode_operations proc_pid_link_inode_operations;
  180. extern void proc_init_inodecache(void);
  181. extern struct inode *proc_get_inode(struct super_block *, struct proc_dir_entry *);
  182. extern int proc_fill_super(struct super_block *);
  183. extern void proc_entry_rundown(struct proc_dir_entry *);
  184. /*
  185. * proc_namespaces.c
  186. */
  187. extern const struct inode_operations proc_ns_dir_inode_operations;
  188. extern const struct file_operations proc_ns_dir_operations;
  189. /*
  190. * proc_net.c
  191. */
  192. extern const struct file_operations proc_net_operations;
  193. extern const struct inode_operations proc_net_inode_operations;
  194. #ifdef CONFIG_NET
  195. extern int proc_net_init(void);
  196. #else
  197. static inline int proc_net_init(void) { return 0; }
  198. #endif
  199. /*
  200. * proc_self.c
  201. */
  202. extern int proc_setup_self(struct super_block *);
  203. /*
  204. * proc_thread_self.c
  205. */
  206. extern int proc_setup_thread_self(struct super_block *);
  207. extern void proc_thread_self_init(void);
  208. /*
  209. * proc_sysctl.c
  210. */
  211. #ifdef CONFIG_PROC_SYSCTL
  212. extern int proc_sys_init(void);
  213. extern void sysctl_head_put(struct ctl_table_header *);
  214. #else
  215. static inline void proc_sys_init(void) { }
  216. static inline void sysctl_head_put(struct ctl_table_header *head) { }
  217. #endif
  218. /*
  219. * proc_tty.c
  220. */
  221. #ifdef CONFIG_TTY
  222. extern void proc_tty_init(void);
  223. #else
  224. static inline void proc_tty_init(void) {}
  225. #endif
  226. /*
  227. * root.c
  228. */
  229. extern struct proc_dir_entry proc_root;
  230. extern void proc_self_init(void);
  231. extern int proc_remount(struct super_block *, int *, char *);
  232. /*
  233. * task_[no]mmu.c
  234. */
  235. struct proc_maps_private {
  236. struct pid *pid;
  237. struct task_struct *task;
  238. #ifdef CONFIG_MMU
  239. struct vm_area_struct *tail_vma;
  240. #endif
  241. #ifdef CONFIG_NUMA
  242. struct mempolicy *task_mempolicy;
  243. #endif
  244. };
  245. extern const struct file_operations proc_pid_maps_operations;
  246. extern const struct file_operations proc_tid_maps_operations;
  247. extern const struct file_operations proc_pid_numa_maps_operations;
  248. extern const struct file_operations proc_tid_numa_maps_operations;
  249. extern const struct file_operations proc_pid_smaps_operations;
  250. extern const struct file_operations proc_tid_smaps_operations;
  251. extern const struct file_operations proc_clear_refs_operations;
  252. extern const struct file_operations proc_pagemap_operations;
  253. extern unsigned long task_vsize(struct mm_struct *);
  254. extern unsigned long task_statm(struct mm_struct *,
  255. unsigned long *, unsigned long *,
  256. unsigned long *, unsigned long *);
  257. extern void task_mem(struct seq_file *, struct mm_struct *);