internal.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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. * parent/subdir are used for the directory structure (every /proc file has a
  25. * parent, but "subdir" is empty for all non-directory entries).
  26. * subdir_node is used to build the rb tree "subdir" of the parent.
  27. */
  28. struct proc_dir_entry {
  29. unsigned int low_ino;
  30. umode_t mode;
  31. nlink_t nlink;
  32. kuid_t uid;
  33. kgid_t gid;
  34. loff_t size;
  35. const struct inode_operations *proc_iops;
  36. const struct file_operations *proc_fops;
  37. struct proc_dir_entry *parent;
  38. struct rb_root subdir;
  39. struct rb_node subdir_node;
  40. void *data;
  41. atomic_t count; /* use count */
  42. atomic_t in_use; /* number of callers into module in progress; */
  43. /* negative -> it's going away RSN */
  44. struct completion *pde_unload_completion;
  45. struct list_head pde_openers; /* who did ->open, but not ->release */
  46. spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
  47. u8 namelen;
  48. char name[];
  49. };
  50. union proc_op {
  51. int (*proc_get_link)(struct dentry *, struct path *);
  52. int (*proc_show)(struct seq_file *m,
  53. struct pid_namespace *ns, struct pid *pid,
  54. struct task_struct *task);
  55. };
  56. struct proc_inode {
  57. struct pid *pid;
  58. unsigned int fd;
  59. union proc_op op;
  60. struct proc_dir_entry *pde;
  61. struct ctl_table_header *sysctl;
  62. struct ctl_table *sysctl_entry;
  63. struct hlist_node sysctl_inodes;
  64. const struct proc_ns_operations *ns_ops;
  65. struct inode vfs_inode;
  66. };
  67. /*
  68. * General functions
  69. */
  70. static inline struct proc_inode *PROC_I(const struct inode *inode)
  71. {
  72. return container_of(inode, struct proc_inode, vfs_inode);
  73. }
  74. static inline struct proc_dir_entry *PDE(const struct inode *inode)
  75. {
  76. return PROC_I(inode)->pde;
  77. }
  78. static inline void *__PDE_DATA(const struct inode *inode)
  79. {
  80. return PDE(inode)->data;
  81. }
  82. static inline struct pid *proc_pid(struct inode *inode)
  83. {
  84. return PROC_I(inode)->pid;
  85. }
  86. static inline struct task_struct *get_proc_task(struct inode *inode)
  87. {
  88. return get_pid_task(proc_pid(inode), PIDTYPE_PID);
  89. }
  90. static inline int task_dumpable(struct task_struct *task)
  91. {
  92. int dumpable = 0;
  93. struct mm_struct *mm;
  94. task_lock(task);
  95. mm = task->mm;
  96. if (mm)
  97. dumpable = get_dumpable(mm);
  98. task_unlock(task);
  99. if (dumpable == SUID_DUMP_USER)
  100. return 1;
  101. return 0;
  102. }
  103. static inline unsigned name_to_int(const struct qstr *qstr)
  104. {
  105. const char *name = qstr->name;
  106. int len = qstr->len;
  107. unsigned n = 0;
  108. if (len > 1 && *name == '0')
  109. goto out;
  110. while (len-- > 0) {
  111. unsigned c = *name++ - '0';
  112. if (c > 9)
  113. goto out;
  114. if (n >= (~0U-9)/10)
  115. goto out;
  116. n *= 10;
  117. n += c;
  118. }
  119. return n;
  120. out:
  121. return ~0U;
  122. }
  123. /*
  124. * Offset of the first process in the /proc root directory..
  125. */
  126. #define FIRST_PROCESS_ENTRY 256
  127. /* Worst case buffer size needed for holding an integer. */
  128. #define PROC_NUMBUF 13
  129. /*
  130. * array.c
  131. */
  132. extern const struct file_operations proc_tid_children_operations;
  133. extern int proc_tid_stat(struct seq_file *, struct pid_namespace *,
  134. struct pid *, struct task_struct *);
  135. extern int proc_tgid_stat(struct seq_file *, struct pid_namespace *,
  136. struct pid *, struct task_struct *);
  137. extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
  138. struct pid *, struct task_struct *);
  139. extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
  140. struct pid *, struct task_struct *);
  141. /*
  142. * base.c
  143. */
  144. extern const struct dentry_operations pid_dentry_operations;
  145. extern int pid_getattr(struct vfsmount *, struct dentry *, struct kstat *);
  146. extern int proc_setattr(struct dentry *, struct iattr *);
  147. extern struct inode *proc_pid_make_inode(struct super_block *, struct task_struct *);
  148. extern int pid_revalidate(struct dentry *, unsigned int);
  149. extern int pid_delete_dentry(const struct dentry *);
  150. extern int proc_pid_readdir(struct file *, struct dir_context *);
  151. extern struct dentry *proc_pid_lookup(struct inode *, struct dentry *, unsigned int);
  152. extern loff_t mem_lseek(struct file *, loff_t, int);
  153. /* Lookups */
  154. typedef int instantiate_t(struct inode *, struct dentry *,
  155. struct task_struct *, const void *);
  156. extern bool proc_fill_cache(struct file *, struct dir_context *, const char *, int,
  157. instantiate_t, struct task_struct *, const void *);
  158. /*
  159. * generic.c
  160. */
  161. extern struct dentry *proc_lookup(struct inode *, struct dentry *, unsigned int);
  162. extern struct dentry *proc_lookup_de(struct proc_dir_entry *, struct inode *,
  163. struct dentry *);
  164. extern int proc_readdir(struct file *, struct dir_context *);
  165. extern int proc_readdir_de(struct proc_dir_entry *, struct file *, struct dir_context *);
  166. static inline struct proc_dir_entry *pde_get(struct proc_dir_entry *pde)
  167. {
  168. atomic_inc(&pde->count);
  169. return pde;
  170. }
  171. extern void pde_put(struct proc_dir_entry *);
  172. static inline bool is_empty_pde(const struct proc_dir_entry *pde)
  173. {
  174. return S_ISDIR(pde->mode) && !pde->proc_iops;
  175. }
  176. struct proc_dir_entry *proc_create_mount_point(const char *name);
  177. /*
  178. * inode.c
  179. */
  180. struct pde_opener {
  181. struct file *file;
  182. struct list_head lh;
  183. int closing;
  184. struct completion *c;
  185. };
  186. extern const struct inode_operations proc_link_inode_operations;
  187. extern const struct inode_operations proc_pid_link_inode_operations;
  188. extern void proc_init_inodecache(void);
  189. extern struct inode *proc_get_inode(struct super_block *, struct proc_dir_entry *);
  190. extern int proc_fill_super(struct super_block *, void *data, int flags);
  191. extern void proc_entry_rundown(struct proc_dir_entry *);
  192. /*
  193. * proc_namespaces.c
  194. */
  195. extern const struct inode_operations proc_ns_dir_inode_operations;
  196. extern const struct file_operations proc_ns_dir_operations;
  197. /*
  198. * proc_net.c
  199. */
  200. extern const struct file_operations proc_net_operations;
  201. extern const struct inode_operations proc_net_inode_operations;
  202. #ifdef CONFIG_NET
  203. extern int proc_net_init(void);
  204. #else
  205. static inline int proc_net_init(void) { return 0; }
  206. #endif
  207. /*
  208. * proc_self.c
  209. */
  210. extern int proc_setup_self(struct super_block *);
  211. /*
  212. * proc_thread_self.c
  213. */
  214. extern int proc_setup_thread_self(struct super_block *);
  215. extern void proc_thread_self_init(void);
  216. /*
  217. * proc_sysctl.c
  218. */
  219. #ifdef CONFIG_PROC_SYSCTL
  220. extern int proc_sys_init(void);
  221. extern void proc_sys_evict_inode(struct inode *inode,
  222. struct ctl_table_header *head);
  223. #else
  224. static inline void proc_sys_init(void) { }
  225. static inline void proc_sys_evict_inode(struct inode *inode,
  226. struct ctl_table_header *head) { }
  227. #endif
  228. /*
  229. * proc_tty.c
  230. */
  231. #ifdef CONFIG_TTY
  232. extern void proc_tty_init(void);
  233. #else
  234. static inline void proc_tty_init(void) {}
  235. #endif
  236. /*
  237. * root.c
  238. */
  239. extern struct proc_dir_entry proc_root;
  240. extern int proc_parse_options(char *options, struct pid_namespace *pid);
  241. extern void proc_self_init(void);
  242. extern int proc_remount(struct super_block *, int *, char *);
  243. /*
  244. * task_[no]mmu.c
  245. */
  246. struct proc_maps_private {
  247. struct inode *inode;
  248. struct task_struct *task;
  249. struct mm_struct *mm;
  250. #ifdef CONFIG_MMU
  251. struct vm_area_struct *tail_vma;
  252. #endif
  253. #ifdef CONFIG_NUMA
  254. struct mempolicy *task_mempolicy;
  255. #endif
  256. };
  257. struct mm_struct *proc_mem_open(struct inode *inode, unsigned int mode);
  258. extern const struct file_operations proc_pid_maps_operations;
  259. extern const struct file_operations proc_tid_maps_operations;
  260. extern const struct file_operations proc_pid_numa_maps_operations;
  261. extern const struct file_operations proc_tid_numa_maps_operations;
  262. extern const struct file_operations proc_pid_smaps_operations;
  263. extern const struct file_operations proc_tid_smaps_operations;
  264. extern const struct file_operations proc_clear_refs_operations;
  265. extern const struct file_operations proc_pagemap_operations;
  266. extern unsigned long task_vsize(struct mm_struct *);
  267. extern unsigned long task_statm(struct mm_struct *,
  268. unsigned long *, unsigned long *,
  269. unsigned long *, unsigned long *);
  270. extern void task_mem(struct seq_file *, struct mm_struct *);