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 */
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
) {
69 if (p
->dumpable
|| ino
== PROC_PID_INO
) {
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
,
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
,
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
,
178 __initfunc(void proc_base_init(void))
181 proc_register(&proc_pid
, &proc_pid_ringbuf
);
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
);
195 proc_register(&proc_pid
, &proc_pid_cpu
);