media: staging: media: use relevant lock
[linux-2.6-block.git] / fs / proc / internal.h
CommitLineData
59d8053f 1/* Internal procfs definitions
1da177e4
LT
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
12#include <linux/proc_fs.h>
59d8053f 13#include <linux/proc_ns.h>
9cdd83e3 14#include <linux/refcount.h>
59d8053f
DH
15#include <linux/spinlock.h>
16#include <linux/atomic.h>
e579d2c2 17#include <linux/binfmts.h>
f7ccbae4 18#include <linux/sched/coredump.h>
f719ff9b 19#include <linux/sched/task.h>
1da177e4 20
59d8053f
DH
21struct ctl_table_header;
22struct mempolicy;
77b14db5 23
59d8053f
DH
24/*
25 * This is not completely implemented yet. The idea is to
26 * create an in-memory tree (like the actual /proc filesystem
27 * tree) of these proc_dir_entries, so that we can dynamically
28 * add new files to /proc.
29 *
710585d4
ND
30 * parent/subdir are used for the directory structure (every /proc file has a
31 * parent, but "subdir" is empty for all non-directory entries).
32 * subdir_node is used to build the rb tree "subdir" of the parent.
59d8053f
DH
33 */
34struct proc_dir_entry {
163cf548
AD
35 /*
36 * number of callers into module in progress;
37 * negative -> it's going away RSN
38 */
39 atomic_t in_use;
9cdd83e3 40 refcount_t refcnt;
163cf548 41 struct list_head pde_openers; /* who did ->open, but not ->release */
53f63345
AD
42 /* protects ->pde_openers and all struct pde_opener instances */
43 spinlock_t pde_unload_lock;
163cf548
AD
44 struct completion *pde_unload_completion;
45 const struct inode_operations *proc_iops;
46 const struct file_operations *proc_fops;
47 void *data;
59d8053f 48 unsigned int low_ino;
59d8053f
DH
49 nlink_t nlink;
50 kuid_t uid;
51 kgid_t gid;
52 loff_t size;
710585d4 53 struct proc_dir_entry *parent;
4f113437 54 struct rb_root subdir;
710585d4 55 struct rb_node subdir_node;
b4884f23 56 char *name;
163cf548 57 umode_t mode;
59d8053f 58 u8 namelen;
b4884f23 59#ifdef CONFIG_64BIT
4f113437 60#define SIZEOF_PDE_INLINE_NAME (192-139)
b4884f23 61#else
4f113437 62#define SIZEOF_PDE_INLINE_NAME (128-87)
b4884f23
AD
63#endif
64 char inline_name[SIZEOF_PDE_INLINE_NAME];
3859a271 65} __randomize_layout;
1da177e4 66
b4884f23
AD
67extern struct kmem_cache *proc_dir_entry_cache;
68void pde_free(struct proc_dir_entry *pde);
69
59d8053f
DH
70union proc_op {
71 int (*proc_get_link)(struct dentry *, struct path *);
59d8053f
DH
72 int (*proc_show)(struct seq_file *m,
73 struct pid_namespace *ns, struct pid *pid,
74 struct task_struct *task);
75};
99f89551 76
59d8053f 77struct proc_inode {
f2beb798 78 struct pid *pid;
771187d6 79 unsigned int fd;
59d8053f
DH
80 union proc_op op;
81 struct proc_dir_entry *pde;
82 struct ctl_table_header *sysctl;
83 struct ctl_table *sysctl_entry;
2fd1d2c4 84 struct hlist_node sysctl_inodes;
3d3d35b1 85 const struct proc_ns_operations *ns_ops;
59d8053f 86 struct inode vfs_inode;
3859a271 87} __randomize_layout;
f2beb798 88
c30480b9
DH
89/*
90 * General functions
91 */
92static inline struct proc_inode *PROC_I(const struct inode *inode)
93{
94 return container_of(inode, struct proc_inode, vfs_inode);
95}
96
97static inline struct proc_dir_entry *PDE(const struct inode *inode)
98{
99 return PROC_I(inode)->pde;
100}
101
102static inline void *__PDE_DATA(const struct inode *inode)
103{
104 return PDE(inode)->data;
105}
fee781e6 106
13b41b09 107static inline struct pid *proc_pid(struct inode *inode)
99f89551 108{
13b41b09 109 return PROC_I(inode)->pid;
99f89551
EB
110}
111
112static inline struct task_struct *get_proc_task(struct inode *inode)
1da177e4 113{
13b41b09 114 return get_pid_task(proc_pid(inode), PIDTYPE_PID);
1da177e4
LT
115}
116
c6eb50d2 117void task_dump_owner(struct task_struct *task, umode_t mode,
68eb94f1 118 kuid_t *ruid, kgid_t *rgid);
faf60af1 119
3ee2a199 120unsigned name_to_int(const struct qstr *qstr);
1dd704b6 121/*
59d8053f 122 * Offset of the first process in the /proc root directory..
1dd704b6 123 */
59d8053f 124#define FIRST_PROCESS_ENTRY 256
1dd704b6 125
59d8053f
DH
126/* Worst case buffer size needed for holding an integer. */
127#define PROC_NUMBUF 13
881adb85 128
59d8053f
DH
129/*
130 * array.c
131 */
132extern const struct file_operations proc_tid_children_operations;
3174c21b 133
59d8053f
DH
134extern int proc_tid_stat(struct seq_file *, struct pid_namespace *,
135 struct pid *, struct task_struct *);
136extern int proc_tgid_stat(struct seq_file *, struct pid_namespace *,
137 struct pid *, struct task_struct *);
138extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
139 struct pid *, struct task_struct *);
140extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
141 struct pid *, struct task_struct *);
142
143/*
144 * base.c
145 */
146extern const struct dentry_operations pid_dentry_operations;
a528d35e 147extern int pid_getattr(const struct path *, struct kstat *, u32, unsigned int);
59d8053f 148extern int proc_setattr(struct dentry *, struct iattr *);
db978da8 149extern struct inode *proc_pid_make_inode(struct super_block *, struct task_struct *, umode_t);
59d8053f
DH
150extern int pid_revalidate(struct dentry *, unsigned int);
151extern int pid_delete_dentry(const struct dentry *);
f0c3b509 152extern int proc_pid_readdir(struct file *, struct dir_context *);
59d8053f
DH
153extern struct dentry *proc_pid_lookup(struct inode *, struct dentry *, unsigned int);
154extern loff_t mem_lseek(struct file *, loff_t, int);
866ad9a7 155
59d8053f 156/* Lookups */
c52a47ac 157typedef int instantiate_t(struct inode *, struct dentry *,
59d8053f 158 struct task_struct *, const void *);
f0c3b509 159extern bool proc_fill_cache(struct file *, struct dir_context *, const char *, int,
59d8053f 160 instantiate_t, struct task_struct *, const void *);
3174c21b 161
59d8053f
DH
162/*
163 * generic.c
164 */
59d8053f 165extern struct dentry *proc_lookup(struct inode *, struct dentry *, unsigned int);
93ad5bc6 166struct dentry *proc_lookup_de(struct inode *, struct dentry *, struct proc_dir_entry *);
f0c3b509 167extern int proc_readdir(struct file *, struct dir_context *);
93ad5bc6 168int proc_readdir_de(struct file *, struct dir_context *, struct proc_dir_entry *);
3174c21b 169
135d5655
AD
170static inline struct proc_dir_entry *pde_get(struct proc_dir_entry *pde)
171{
9cdd83e3 172 refcount_inc(&pde->refcnt);
135d5655
AD
173 return pde;
174}
59d8053f 175extern void pde_put(struct proc_dir_entry *);
3174c21b 176
eb6d38d5
EB
177static inline bool is_empty_pde(const struct proc_dir_entry *pde)
178{
179 return S_ISDIR(pde->mode) && !pde->proc_iops;
180}
eb6d38d5 181
3174c21b 182/*
59d8053f 183 * inode.c
3174c21b 184 */
59d8053f
DH
185struct pde_opener {
186 struct file *file;
187 struct list_head lh;
f5887c71 188 bool closing;
59d8053f 189 struct completion *c;
a9fabc3d 190} __randomize_layout;
7e0e953b 191extern const struct inode_operations proc_link_inode_operations;
6b4e306a 192
59d8053f 193extern const struct inode_operations proc_pid_link_inode_operations;
6b4e306a 194
195b8cf0 195void proc_init_kmemcache(void);
1270dd8d 196void set_proc_pid_nlink(void);
59d8053f 197extern struct inode *proc_get_inode(struct super_block *, struct proc_dir_entry *);
e94591d0 198extern int proc_fill_super(struct super_block *, void *data, int flags);
59d8053f 199extern void proc_entry_rundown(struct proc_dir_entry *);
6b4e306a 200
59d8053f
DH
201/*
202 * proc_namespaces.c
203 */
6b4e306a
EB
204extern const struct inode_operations proc_ns_dir_inode_operations;
205extern const struct file_operations proc_ns_dir_operations;
206
59d8053f
DH
207/*
208 * proc_net.c
209 */
210extern const struct file_operations proc_net_operations;
211extern const struct inode_operations proc_net_inode_operations;
212
213#ifdef CONFIG_NET
214extern int proc_net_init(void);
215#else
216static inline int proc_net_init(void) { return 0; }
217#endif
218
219/*
220 * proc_self.c
221 */
021ada7d 222extern int proc_setup_self(struct super_block *);
34db8aaf 223
0097875b
EB
224/*
225 * proc_thread_self.c
226 */
227extern int proc_setup_thread_self(struct super_block *);
228extern void proc_thread_self_init(void);
229
34db8aaf 230/*
59d8053f 231 * proc_sysctl.c
34db8aaf 232 */
59d8053f
DH
233#ifdef CONFIG_PROC_SYSCTL
234extern int proc_sys_init(void);
d6cffbbe
KK
235extern void proc_sys_evict_inode(struct inode *inode,
236 struct ctl_table_header *head);
59d8053f
DH
237#else
238static inline void proc_sys_init(void) { }
d6cffbbe
KK
239static inline void proc_sys_evict_inode(struct inode *inode,
240 struct ctl_table_header *head) { }
59d8053f 241#endif
34db8aaf
DH
242
243/*
244 * proc_tty.c
245 */
246#ifdef CONFIG_TTY
247extern void proc_tty_init(void);
248#else
249static inline void proc_tty_init(void) {}
250#endif
59d8053f
DH
251
252/*
253 * root.c
254 */
255extern struct proc_dir_entry proc_root;
e94591d0 256extern int proc_parse_options(char *options, struct pid_namespace *pid);
59d8053f
DH
257
258extern void proc_self_init(void);
259extern int proc_remount(struct super_block *, int *, char *);
260
261/*
262 * task_[no]mmu.c
263 */
493b0e9d 264struct mem_size_stats;
59d8053f 265struct proc_maps_private {
2c03376d 266 struct inode *inode;
59d8053f 267 struct task_struct *task;
29a40ace 268 struct mm_struct *mm;
493b0e9d 269 struct mem_size_stats *rollup;
59d8053f
DH
270#ifdef CONFIG_MMU
271 struct vm_area_struct *tail_vma;
272#endif
273#ifdef CONFIG_NUMA
274 struct mempolicy *task_mempolicy;
275#endif
3859a271 276} __randomize_layout;
59d8053f 277
5381e169
ON
278struct mm_struct *proc_mem_open(struct inode *inode, unsigned int mode);
279
59d8053f
DH
280extern const struct file_operations proc_pid_maps_operations;
281extern const struct file_operations proc_tid_maps_operations;
282extern const struct file_operations proc_pid_numa_maps_operations;
283extern const struct file_operations proc_tid_numa_maps_operations;
284extern const struct file_operations proc_pid_smaps_operations;
493b0e9d 285extern const struct file_operations proc_pid_smaps_rollup_operations;
59d8053f
DH
286extern const struct file_operations proc_tid_smaps_operations;
287extern const struct file_operations proc_clear_refs_operations;
288extern const struct file_operations proc_pagemap_operations;
289
290extern unsigned long task_vsize(struct mm_struct *);
291extern unsigned long task_statm(struct mm_struct *,
292 unsigned long *, unsigned long *,
293 unsigned long *, unsigned long *);
294extern void task_mem(struct seq_file *, struct mm_struct *);