summaryrefslogtreecommitdiffstats
path: root/fs/proc/base.c
blob: c9b2d8649bf490370b69925ef43b0e0f65a5114e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/*
 *  linux/fs/proc/base.c
 *
 *  Copyright (C) 1991, 1992 Linus Torvalds
 *
 *  proc base directory handling functions
 */

#include <asm/uaccess.h>

#include <linux/config.h>
#include <linux/errno.h>
#include <linux/sched.h>
#include <linux/proc_fs.h>
#include <linux/stat.h>
#include <linux/init.h>

static struct file_operations proc_base_operations = {
	NULL,			/* lseek - default */
	NULL,			/* read - bad */
	NULL,			/* write - bad */
	proc_readdir,		/* readdir */
	NULL,			/* poll - default */
	NULL,			/* ioctl - default */
	NULL,			/* mmap */
	NULL,			/* no special open code */
	NULL,			/* flush */
	NULL,			/* no special release code */
	NULL			/* can't fsync */
};

/*
 * proc directories can do almost nothing..
 */
static struct inode_operations proc_base_inode_operations = {
	&proc_base_operations,	/* default base directory file-ops */
	NULL,			/* create */
	proc_lookup,		/* lookup */
	NULL,			/* link */
	NULL,			/* unlink */
	NULL,			/* symlink */
	NULL,			/* mkdir */
	NULL,			/* rmdir */
	NULL,			/* mknod */
	NULL,			/* rename */
	NULL,			/* readlink */
	NULL,			/* follow_link */
	NULL,			/* readpage */
	NULL,			/* writepage */
	NULL,			/* bmap */
	NULL,			/* truncate */
	NULL			/* permission */
};

/*
 * The fill argument is non-zero when the inode is being filled ...
 * we don't need to do anything when it's being deleted.
 */
static void proc_pid_fill_inode(struct inode * inode, int fill)
{
	struct task_struct *p;
	int pid = inode->i_ino >> 16;
	int ino = inode->i_ino & 0xffff;

	read_lock(&tasklist_lock);
	if (fill && (p = find_task_by_pid(pid)) != NULL) {
		uid_t uid = 0;
		gid_t gid = 0;
		if (p->dumpable || ino == PROC_PID_INO) {
			uid = p->euid;
			gid = p->egid;
		}
		inode->i_uid = uid;
		inode->i_gid = gid;
	}
	read_unlock(&tasklist_lock);
}

/*
 * This is really a pseudo-entry, and only links
 * backwards to the parent with no link from the
 * root directory to this. This way we can have just
 * one entry for every /proc/<pid>/ directory.
 */
struct proc_dir_entry proc_pid = {
	PROC_PID_INO, 5, "<pid>",
	S_IFDIR | S_IRUGO | S_IXUGO, 2, 0, 0,
	0, &proc_base_inode_operations,
	NULL, proc_pid_fill_inode,
	NULL, &proc_root, NULL
};

static struct proc_dir_entry proc_pid_status = {
	PROC_PID_STATUS, 6, "status",
	S_IFREG | S_IRUGO, 1, 0, 0,
	0, &proc_array_inode_operations,
	NULL, proc_pid_fill_inode,
};
static struct proc_dir_entry proc_pid_mem = {
	PROC_PID_MEM, 3, "mem",
	S_IFREG | S_IRUSR | S_IWUSR, 1, 0, 0,
	0, &proc_mem_inode_operations,
	NULL, proc_pid_fill_inode,
};
static struct proc_dir_entry proc_pid_cwd = {
	PROC_PID_CWD, 3, "cwd",
	S_IFLNK | S_IRWXU, 1, 0, 0,
	0, &proc_link_inode_operations,
	NULL, proc_pid_fill_inode,
};
static struct proc_dir_entry proc_pid_root = {
	PROC_PID_ROOT, 4, "root",
	S_IFLNK | S_IRWXU, 1, 0, 0,
	0, &proc_link_inode_operations,
	NULL, proc_pid_fill_inode,
};
static struct proc_dir_entry proc_pid_exe = {
	PROC_PID_EXE, 3, "exe",
	S_IFLNK | S_IRWXU, 1, 0, 0,
	0, &proc_link_inode_operations,
	NULL, proc_pid_fill_inode,
};
static struct proc_dir_entry proc_pid_fd = {
	PROC_PID_FD, 2, "fd",
	S_IFDIR | S_IRUSR | S_IXUSR, 2, 0, 0,
	0, &proc_fd_inode_operations,
	NULL, proc_pid_fill_inode,
};
static struct proc_dir_entry proc_pid_environ = {
	PROC_PID_ENVIRON, 7, "environ",
	S_IFREG | S_IRUSR, 1, 0, 0,
	0, &proc_array_inode_operations,
	NULL, proc_pid_fill_inode,
};
static struct proc_dir_entry proc_pid_cmdline = {
	PROC_PID_CMDLINE, 7, "cmdline",
	S_IFREG | S_IRUGO, 1, 0, 0,
	0, &proc_array_inode_operations,
	NULL, proc_pid_fill_inode,
};
static struct proc_dir_entry proc_pid_stat = {
	PROC_PID_STAT, 4, "stat",
	S_IFREG | S_IRUGO, 1, 0, 0,
	0, &proc_array_inode_operations,
	NULL, proc_pid_fill_inode,
};
static struct proc_dir_entry proc_pid_statm = {
	PROC_PID_STATM, 5, "statm",
	S_IFREG | S_IRUGO, 1, 0, 0,
	0, &proc_array_inode_operations,
	NULL, proc_pid_fill_inode,
};
static struct proc_dir_entry proc_pid_maps = {
	PROC_PID_MAPS, 4, "maps",
	S_IFIFO | S_IRUGO, 1, 0, 0,
	0, &proc_arraylong_inode_operations,
	NULL, proc_pid_fill_inode,
};

#if CONFIG_AP1000
static struct proc_dir_entry proc_pid_ringbuf = {
	PROC_PID_RINGBUF, 7, "ringbuf",
	S_IFREG | S_IRUGO | S_IWUSR, 1, 0, 0,
	0, &proc_ringbuf_inode_operations,
	NULL, proc_pid_fill_inode,
};
#endif

#ifdef __SMP__
static struct proc_dir_entry proc_pid_cpu = {
	PROC_PID_CPU, 3, "cpu",
	S_IFREG | S_IRUGO, 1, 0, 0,
	0, &proc_array_inode_operations,
	NULL, proc_pid_fill_inode,
};
#endif

__initfunc(void proc_base_init(void))
{
#if CONFIG_AP1000
	proc_register(&proc_pid, &proc_pid_ringbuf);
#endif
	proc_register(&proc_pid, &proc_pid_status);
	proc_register(&proc_pid, &proc_pid_mem);
	proc_register(&proc_pid, &proc_pid_cwd);
	proc_register(&proc_pid, &proc_pid_root);
	proc_register(&proc_pid, &proc_pid_exe);
	proc_register(&proc_pid, &proc_pid_fd);
	proc_register(&proc_pid, &proc_pid_environ);
	proc_register(&proc_pid, &proc_pid_cmdline);
	proc_register(&proc_pid, &proc_pid_stat);
	proc_register(&proc_pid, &proc_pid_statm);
	proc_register(&proc_pid, &proc_pid_maps);
#ifdef __SMP__	
	proc_register(&proc_pid, &proc_pid_cpu);
#endif	
};










logstatsplain -rw-r--r--SubmittingPatches54logstatsplain d---------accelerators36logstatsplain d---------accounting215logstatsplain d---------acpi898logstatsplain d---------admin-guide1527logstatsplain d---------aoe226logstatsplain d---------arm1170logstatsplain d---------arm64537logstatsplain -rw-r--r--atomic_bitops.txt1551logstatsplain -rw-r--r--atomic_t.txt5657logstatsplain d---------auxdisplay119logstatsplain d---------backlight45logstatsplain d---------block682logstatsplain d---------blockdev217logstatsplain d---------bpf126logstatsplain -rw-r--r--bt8xxgpio.txt4097logstatsplain -rw-r--r--btmrvl.txt2808logstatsplain d---------bus-devices39logstatsplain -rw-r--r--bus-virt-phys-mapping.txt8223logstatsplain d---------cdrom162logstatsplain d---------cgroup-v1523logstatsplain