Linux 2.2.0
[davej-history.git] / fs / proc / base.c
blobc9b2d8649bf490370b69925ef43b0e0f65a5114e
1 /*
2 * linux/fs/proc/base.c
4 * Copyright (C) 1991, 1992 Linus Torvalds
6 * proc base directory handling functions
7 */
9 #include <asm/uaccess.h>
11 #include <linux/config.h>
12 #include <linux/errno.h>
13 #include <linux/sched.h>
14 #include <linux/proc_fs.h>
15 #include <linux/stat.h>
16 #include <linux/init.h>
18 static struct file_operations proc_base_operations = {
19 NULL, /* lseek - default */
20 NULL, /* read - bad */
21 NULL, /* write - bad */
22 proc_readdir, /* readdir */
23 NULL, /* poll - default */
24 NULL, /* ioctl - default */
25 NULL, /* mmap */
26 NULL, /* no special open code */
27 NULL, /* flush */
28 NULL, /* no special release code */
29 NULL /* can't fsync */
33 * proc directories can do almost nothing..
35 static struct inode_operations proc_base_inode_operations = {
36 &proc_base_operations, /* default base directory file-ops */
37 NULL, /* create */
38 proc_lookup, /* lookup */
39 NULL, /* link */
40 NULL, /* unlink */
41 NULL, /* symlink */
42 NULL, /* mkdir */
43 NULL, /* rmdir */
44 NULL, /* mknod */
45 NULL, /* rename */
46 NULL, /* readlink */
47 NULL, /* follow_link */
48 NULL, /* readpage */
49 NULL, /* writepage */
50 NULL, /* bmap */
51 NULL, /* truncate */
52 NULL /* permission */
56 * The fill argument is non-zero when the inode is being filled ...
57 * we don't need to do anything when it's being deleted.
59 static void proc_pid_fill_inode(struct inode * inode, int fill)
61 struct task_struct *p;
62 int pid = inode->i_ino >> 16;
63 int ino = inode->i_ino & 0xffff;
65 read_lock(&tasklist_lock);
66 if (fill && (p = find_task_by_pid(pid)) != NULL) {
67 uid_t uid = 0;
68 gid_t gid = 0;
69 if (p->dumpable || ino == PROC_PID_INO) {
70 uid = p->euid;
71 gid = p->egid;
73 inode->i_uid = uid;
74 inode->i_gid = gid;
76 read_unlock(&tasklist_lock);
80 * This is really a pseudo-entry, and only links
81 * backwards to the parent with no link from the
82 * root directory to this. This way we can have just
83 * one entry for every /proc/<pid>/ directory.
85 struct proc_dir_entry proc_pid = {
86 PROC_PID_INO, 5, "<pid>",
87 S_IFDIR | S_IRUGO | S_IXUGO, 2, 0, 0,
88 0, &proc_base_inode_operations,
89 NULL, proc_pid_fill_inode,
90 NULL, &proc_root, NULL
93 static struct proc_dir_entry proc_pid_status = {
94 PROC_PID_STATUS, 6, "status",
95 S_IFREG | S_IRUGO, 1, 0, 0,
96 0, &proc_array_inode_operations,
97 NULL, proc_pid_fill_inode,
99 static struct proc_dir_entry proc_pid_mem = {
100 PROC_PID_MEM, 3, "mem",
101 S_IFREG | S_IRUSR | S_IWUSR, 1, 0, 0,
102 0, &proc_mem_inode_operations,
103 NULL, proc_pid_fill_inode,
105 static struct proc_dir_entry proc_pid_cwd = {
106 PROC_PID_CWD, 3, "cwd",
107 S_IFLNK | S_IRWXU, 1, 0, 0,
108 0, &proc_link_inode_operations,
109 NULL, proc_pid_fill_inode,
111 static struct proc_dir_entry proc_pid_root = {
112 PROC_PID_ROOT, 4, "root",
113 S_IFLNK | S_IRWXU, 1, 0, 0,
114 0, &proc_link_inode_operations,
115 NULL, proc_pid_fill_inode,
117 static struct proc_dir_entry proc_pid_exe = {
118 PROC_PID_EXE, 3, "exe",
119 S_IFLNK | S_IRWXU, 1, 0, 0,
120 0, &proc_link_inode_operations,
121 NULL, proc_pid_fill_inode,
123 static struct proc_dir_entry proc_pid_fd = {
124 PROC_PID_FD, 2, "fd",
125 S_IFDIR | S_IRUSR | S_IXUSR, 2, 0, 0,
126 0, &proc_fd_inode_operations,
127 NULL, proc_pid_fill_inode,
129 static struct proc_dir_entry proc_pid_environ = {
130 PROC_PID_ENVIRON, 7, "environ",
131 S_IFREG | S_IRUSR, 1, 0, 0,
132 0, &proc_array_inode_operations,
133 NULL, proc_pid_fill_inode,
135 static struct proc_dir_entry proc_pid_cmdline = {
136 PROC_PID_CMDLINE, 7, "cmdline",
137 S_IFREG | S_IRUGO, 1, 0, 0,
138 0, &proc_array_inode_operations,
139 NULL, proc_pid_fill_inode,
141 static struct proc_dir_entry proc_pid_stat = {
142 PROC_PID_STAT, 4, "stat",
143 S_IFREG | S_IRUGO, 1, 0, 0,
144 0, &proc_array_inode_operations,
145 NULL, proc_pid_fill_inode,
147 static struct proc_dir_entry proc_pid_statm = {
148 PROC_PID_STATM, 5, "statm",
149 S_IFREG | S_IRUGO, 1, 0, 0,
150 0, &proc_array_inode_operations,
151 NULL, proc_pid_fill_inode,
153 static struct proc_dir_entry proc_pid_maps = {
154 PROC_PID_MAPS, 4, "maps",
155 S_IFIFO | S_IRUGO, 1, 0, 0,
156 0, &proc_arraylong_inode_operations,
157 NULL, proc_pid_fill_inode,
160 #if CONFIG_AP1000
161 static struct proc_dir_entry proc_pid_ringbuf = {
162 PROC_PID_RINGBUF, 7, "ringbuf",
163 S_IFREG | S_IRUGO | S_IWUSR, 1, 0, 0,
164 0, &proc_ringbuf_inode_operations,
165 NULL, proc_pid_fill_inode,
167 #endif
169 #ifdef __SMP__
170 static struct proc_dir_entry proc_pid_cpu = {
171 PROC_PID_CPU, 3, "cpu",
172 S_IFREG | S_IRUGO, 1, 0, 0,
173 0, &proc_array_inode_operations,
174 NULL, proc_pid_fill_inode,
176 #endif
178 __initfunc(void proc_base_init(void))
180 #if CONFIG_AP1000
181 proc_register(&proc_pid, &proc_pid_ringbuf);
182 #endif
183 proc_register(&proc_pid, &proc_pid_status);
184 proc_register(&proc_pid, &proc_pid_mem);
185 proc_register(&proc_pid, &proc_pid_cwd);
186 proc_register(&proc_pid, &proc_pid_root);
187 proc_register(&proc_pid, &proc_pid_exe);
188 proc_register(&proc_pid, &proc_pid_fd);
189 proc_register(&proc_pid, &proc_pid_environ);
190 proc_register(&proc_pid, &proc_pid_cmdline);
191 proc_register(&proc_pid, &proc_pid_stat);
192 proc_register(&proc_pid, &proc_pid_statm);
193 proc_register(&proc_pid, &proc_pid_maps);
194 #ifdef __SMP__
195 proc_register(&proc_pid, &proc_pid_cpu);
196 #endif