4 * Copyright (C) 1991, 1992 Linus Torvalds
6 * proc base directory handling functions
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 */
26 NULL
, /* no special open code */
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 */
38 proc_lookup
, /* lookup */
47 NULL
, /* follow_link */
53 NULL
, /* permission */
59 * The fill argument is non-zero when the inode is being filled ...
60 * we don't need to do anything when it's being deleted.
62 static void proc_pid_fill_inode(struct inode
* inode
, int fill
)
64 struct task_struct
*p
;
65 int pid
= inode
->i_ino
>> 16;
66 int ino
= inode
->i_ino
& 0xffff;
68 read_lock(&tasklist_lock
);
69 if (fill
&& (p
= find_task_by_pid(pid
)) != NULL
) {
72 if (p
->dumpable
|| ino
== PROC_PID_INO
) {
79 read_unlock(&tasklist_lock
);
83 * This is really a pseudo-entry, and only links
84 * backwards to the parent with no link from the
85 * root directory to this. This way we can have just
86 * one entry for every /proc/<pid>/ directory.
88 struct proc_dir_entry proc_pid
= {
89 PROC_PID_INO
, 5, "<pid>",
90 S_IFDIR
| S_IRUGO
| S_IXUGO
, 2, 0, 0,
91 0, &proc_base_inode_operations
,
92 NULL
, proc_pid_fill_inode
,
93 NULL
, &proc_root
, NULL
96 static struct proc_dir_entry proc_pid_status
= {
97 PROC_PID_STATUS
, 6, "status",
98 S_IFREG
| S_IRUGO
, 1, 0, 0,
99 0, &proc_array_inode_operations
,
100 NULL
, proc_pid_fill_inode
,
102 static struct proc_dir_entry proc_pid_mem
= {
103 PROC_PID_MEM
, 3, "mem",
104 S_IFREG
| S_IRUSR
| S_IWUSR
, 1, 0, 0,
105 0, &proc_mem_inode_operations
,
106 NULL
, proc_pid_fill_inode
,
108 static struct proc_dir_entry proc_pid_cwd
= {
109 PROC_PID_CWD
, 3, "cwd",
110 S_IFLNK
| S_IRWXU
, 1, 0, 0,
111 0, &proc_link_inode_operations
,
112 NULL
, proc_pid_fill_inode
,
114 static struct proc_dir_entry proc_pid_root
= {
115 PROC_PID_ROOT
, 4, "root",
116 S_IFLNK
| S_IRWXU
, 1, 0, 0,
117 0, &proc_link_inode_operations
,
118 NULL
, proc_pid_fill_inode
,
120 static struct proc_dir_entry proc_pid_exe
= {
121 PROC_PID_EXE
, 3, "exe",
122 S_IFLNK
| S_IRWXU
, 1, 0, 0,
123 0, &proc_link_inode_operations
,
124 NULL
, proc_pid_fill_inode
,
126 static struct proc_dir_entry proc_pid_fd
= {
127 PROC_PID_FD
, 2, "fd",
128 S_IFDIR
| S_IRUSR
| S_IXUSR
, 2, 0, 0,
129 0, &proc_fd_inode_operations
,
130 NULL
, proc_pid_fill_inode
,
132 static struct proc_dir_entry proc_pid_environ
= {
133 PROC_PID_ENVIRON
, 7, "environ",
134 S_IFREG
| S_IRUSR
, 1, 0, 0,
135 0, &proc_array_inode_operations
,
136 NULL
, proc_pid_fill_inode
,
138 static struct proc_dir_entry proc_pid_cmdline
= {
139 PROC_PID_CMDLINE
, 7, "cmdline",
140 S_IFREG
| S_IRUGO
, 1, 0, 0,
141 0, &proc_array_inode_operations
,
142 NULL
, proc_pid_fill_inode
,
144 static struct proc_dir_entry proc_pid_stat
= {
145 PROC_PID_STAT
, 4, "stat",
146 S_IFREG
| S_IRUGO
, 1, 0, 0,
147 0, &proc_array_inode_operations
,
148 NULL
, proc_pid_fill_inode
,
150 static struct proc_dir_entry proc_pid_statm
= {
151 PROC_PID_STATM
, 5, "statm",
152 S_IFREG
| S_IRUGO
, 1, 0, 0,
153 0, &proc_array_inode_operations
,
154 NULL
, proc_pid_fill_inode
,
156 static struct proc_dir_entry proc_pid_maps
= {
157 PROC_PID_MAPS
, 4, "maps",
158 S_IFIFO
| S_IRUGO
, 1, 0, 0,
159 0, &proc_arraylong_inode_operations
,
160 NULL
, proc_pid_fill_inode
,
164 static struct proc_dir_entry proc_pid_ringbuf
= {
165 PROC_PID_RINGBUF
, 7, "ringbuf",
166 S_IFREG
| S_IRUGO
| S_IWUSR
, 1, 0, 0,
167 0, &proc_ringbuf_inode_operations
,
168 NULL
, proc_pid_fill_inode
,
173 static struct proc_dir_entry proc_pid_cpu
= {
174 PROC_PID_CPU
, 3, "cpu",
175 S_IFREG
| S_IRUGO
, 1, 0, 0,
176 0, &proc_array_inode_operations
,
177 NULL
, proc_pid_fill_inode
,
181 void __init
proc_base_init(void)
184 proc_register(&proc_pid
, &proc_pid_ringbuf
);
186 proc_register(&proc_pid
, &proc_pid_status
);
187 proc_register(&proc_pid
, &proc_pid_mem
);
188 proc_register(&proc_pid
, &proc_pid_cwd
);
189 proc_register(&proc_pid
, &proc_pid_root
);
190 proc_register(&proc_pid
, &proc_pid_exe
);
191 proc_register(&proc_pid
, &proc_pid_fd
);
192 proc_register(&proc_pid
, &proc_pid_environ
);
193 proc_register(&proc_pid
, &proc_pid_cmdline
);
194 proc_register(&proc_pid
, &proc_pid_stat
);
195 proc_register(&proc_pid
, &proc_pid_statm
);
196 proc_register(&proc_pid
, &proc_pid_maps
);
198 proc_register(&proc_pid
, &proc_pid_cpu
);