Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * linux/fs/proc/proc_misc.c | |
3 | * | |
4 | * linux/fs/proc/array.c | |
5 | * Copyright (C) 1992 by Linus Torvalds | |
6 | * based on ideas by Darren Senn | |
7 | * | |
8 | * This used to be the part of array.c. See the rest of history and credits | |
9 | * there. I took this into a separate file and switched the thing to generic | |
10 | * proc_file_inode_operations, leaving in array.c only per-process stuff. | |
11 | * Inumbers allocation made dynamic (via create_proc_entry()). AV, May 1999. | |
12 | * | |
13 | * Changes: | |
14 | * Fulton Green : Encapsulated position metric calculations. | |
15 | * <kernel@FultonGreen.com> | |
16 | */ | |
17 | ||
18 | #include <linux/types.h> | |
19 | #include <linux/errno.h> | |
20 | #include <linux/time.h> | |
21 | #include <linux/kernel.h> | |
22 | #include <linux/kernel_stat.h> | |
7170be5f | 23 | #include <linux/fs.h> |
1da177e4 LT |
24 | #include <linux/tty.h> |
25 | #include <linux/string.h> | |
26 | #include <linux/mman.h> | |
4b856152 | 27 | #include <linux/quicklist.h> |
1da177e4 LT |
28 | #include <linux/proc_fs.h> |
29 | #include <linux/ioport.h> | |
1da177e4 LT |
30 | #include <linux/mm.h> |
31 | #include <linux/mmzone.h> | |
32 | #include <linux/pagemap.h> | |
c7fb03a4 | 33 | #include <linux/irq.h> |
f74596d0 | 34 | #include <linux/interrupt.h> |
1da177e4 LT |
35 | #include <linux/swap.h> |
36 | #include <linux/slab.h> | |
a0db701a | 37 | #include <linux/genhd.h> |
1da177e4 LT |
38 | #include <linux/smp.h> |
39 | #include <linux/signal.h> | |
40 | #include <linux/module.h> | |
41 | #include <linux/init.h> | |
1da177e4 LT |
42 | #include <linux/seq_file.h> |
43 | #include <linux/times.h> | |
44 | #include <linux/profile.h> | |
7bf65382 | 45 | #include <linux/utsname.h> |
1da177e4 LT |
46 | #include <linux/blkdev.h> |
47 | #include <linux/hugetlb.h> | |
48 | #include <linux/jiffies.h> | |
1da177e4 | 49 | #include <linux/vmalloc.h> |
666bfddb | 50 | #include <linux/crash_dump.h> |
61a58c6c | 51 | #include <linux/pid_namespace.h> |
161f47bf | 52 | #include <linux/bootmem.h> |
1da177e4 LT |
53 | #include <asm/uaccess.h> |
54 | #include <asm/pgtable.h> | |
55 | #include <asm/io.h> | |
56 | #include <asm/tlb.h> | |
57 | #include <asm/div64.h> | |
58 | #include "internal.h" | |
59 | ||
1da177e4 LT |
60 | /* |
61 | * Warning: stuff below (imported functions) assumes that its output will fit | |
62 | * into one page. For some of those functions it may be wrong. Moreover, we | |
63 | * have a way to deal with that gracefully. Right now I used straightforward | |
64 | * wrappers, but this needs further analysis wrt potential overflows. | |
65 | */ | |
66 | extern int get_hardware_list(char *); | |
67 | extern int get_stram_list(char *); | |
1da177e4 | 68 | extern int get_exec_domain_list(char *); |
1da177e4 LT |
69 | |
70 | static int proc_calc_metrics(char *page, char **start, off_t off, | |
71 | int count, int *eof, int len) | |
72 | { | |
73 | if (len <= off+count) *eof = 1; | |
74 | *start = page + off; | |
75 | len -= off; | |
76 | if (len>count) len = count; | |
77 | if (len<0) len = 0; | |
78 | return len; | |
79 | } | |
80 | ||
1da177e4 LT |
81 | static int fragmentation_open(struct inode *inode, struct file *file) |
82 | { | |
83 | (void)inode; | |
84 | return seq_open(file, &fragmentation_op); | |
85 | } | |
86 | ||
00977a59 | 87 | static const struct file_operations fragmentation_file_operations = { |
1da177e4 LT |
88 | .open = fragmentation_open, |
89 | .read = seq_read, | |
90 | .llseek = seq_lseek, | |
91 | .release = seq_release, | |
92 | }; | |
93 | ||
467c996c MG |
94 | static int pagetypeinfo_open(struct inode *inode, struct file *file) |
95 | { | |
96 | return seq_open(file, &pagetypeinfo_op); | |
97 | } | |
98 | ||
99 | static const struct file_operations pagetypeinfo_file_ops = { | |
100 | .open = pagetypeinfo_open, | |
101 | .read = seq_read, | |
102 | .llseek = seq_lseek, | |
103 | .release = seq_release, | |
104 | }; | |
105 | ||
295ab934 ND |
106 | static int zoneinfo_open(struct inode *inode, struct file *file) |
107 | { | |
108 | return seq_open(file, &zoneinfo_op); | |
109 | } | |
110 | ||
00977a59 | 111 | static const struct file_operations proc_zoneinfo_file_operations = { |
295ab934 ND |
112 | .open = zoneinfo_open, |
113 | .read = seq_read, | |
114 | .llseek = seq_lseek, | |
115 | .release = seq_release, | |
116 | }; | |
117 | ||
1da177e4 LT |
118 | static int version_read_proc(char *page, char **start, off_t off, |
119 | int count, int *eof, void *data) | |
120 | { | |
121 | int len; | |
122 | ||
3eb3c740 | 123 | len = snprintf(page, PAGE_SIZE, linux_proc_banner, |
8993780a LT |
124 | utsname()->sysname, |
125 | utsname()->release, | |
126 | utsname()->version); | |
1da177e4 LT |
127 | return proc_calc_metrics(page, start, off, count, eof, len); |
128 | } | |
129 | ||
03a44825 | 130 | extern const struct seq_operations cpuinfo_op; |
1da177e4 LT |
131 | static int cpuinfo_open(struct inode *inode, struct file *file) |
132 | { | |
133 | return seq_open(file, &cpuinfo_op); | |
134 | } | |
7170be5f | 135 | |
00977a59 | 136 | static const struct file_operations proc_cpuinfo_operations = { |
68eef3b4 JK |
137 | .open = cpuinfo_open, |
138 | .read = seq_read, | |
139 | .llseek = seq_lseek, | |
140 | .release = seq_release, | |
7170be5f NH |
141 | }; |
142 | ||
68eef3b4 | 143 | static int devinfo_show(struct seq_file *f, void *v) |
7170be5f | 144 | { |
68eef3b4 JK |
145 | int i = *(loff_t *) v; |
146 | ||
147 | if (i < CHRDEV_MAJOR_HASH_SIZE) { | |
148 | if (i == 0) | |
149 | seq_printf(f, "Character devices:\n"); | |
150 | chrdev_show(f, i); | |
9361401e DH |
151 | } |
152 | #ifdef CONFIG_BLOCK | |
153 | else { | |
68eef3b4 JK |
154 | i -= CHRDEV_MAJOR_HASH_SIZE; |
155 | if (i == 0) | |
156 | seq_printf(f, "\nBlock devices:\n"); | |
157 | blkdev_show(f, i); | |
7170be5f | 158 | } |
9361401e | 159 | #endif |
68eef3b4 | 160 | return 0; |
7170be5f NH |
161 | } |
162 | ||
68eef3b4 | 163 | static void *devinfo_start(struct seq_file *f, loff_t *pos) |
7170be5f | 164 | { |
68eef3b4 JK |
165 | if (*pos < (BLKDEV_MAJOR_HASH_SIZE + CHRDEV_MAJOR_HASH_SIZE)) |
166 | return pos; | |
167 | return NULL; | |
7170be5f NH |
168 | } |
169 | ||
68eef3b4 | 170 | static void *devinfo_next(struct seq_file *f, void *v, loff_t *pos) |
7170be5f | 171 | { |
68eef3b4 JK |
172 | (*pos)++; |
173 | if (*pos >= (BLKDEV_MAJOR_HASH_SIZE + CHRDEV_MAJOR_HASH_SIZE)) | |
174 | return NULL; | |
175 | return pos; | |
7170be5f NH |
176 | } |
177 | ||
68eef3b4 | 178 | static void devinfo_stop(struct seq_file *f, void *v) |
7170be5f | 179 | { |
68eef3b4 | 180 | /* Nothing to do */ |
7170be5f NH |
181 | } |
182 | ||
03a44825 | 183 | static const struct seq_operations devinfo_ops = { |
68eef3b4 JK |
184 | .start = devinfo_start, |
185 | .next = devinfo_next, | |
186 | .stop = devinfo_stop, | |
187 | .show = devinfo_show | |
7170be5f NH |
188 | }; |
189 | ||
68eef3b4 | 190 | static int devinfo_open(struct inode *inode, struct file *filp) |
7170be5f | 191 | { |
68eef3b4 | 192 | return seq_open(filp, &devinfo_ops); |
7170be5f NH |
193 | } |
194 | ||
00977a59 | 195 | static const struct file_operations proc_devinfo_operations = { |
7170be5f NH |
196 | .open = devinfo_open, |
197 | .read = seq_read, | |
198 | .llseek = seq_lseek, | |
199 | .release = seq_release, | |
200 | }; | |
201 | ||
1da177e4 LT |
202 | static int vmstat_open(struct inode *inode, struct file *file) |
203 | { | |
204 | return seq_open(file, &vmstat_op); | |
205 | } | |
00977a59 | 206 | static const struct file_operations proc_vmstat_file_operations = { |
1da177e4 LT |
207 | .open = vmstat_open, |
208 | .read = seq_read, | |
209 | .llseek = seq_lseek, | |
210 | .release = seq_release, | |
211 | }; | |
212 | ||
213 | #ifdef CONFIG_PROC_HARDWARE | |
214 | static int hardware_read_proc(char *page, char **start, off_t off, | |
215 | int count, int *eof, void *data) | |
216 | { | |
217 | int len = get_hardware_list(page); | |
218 | return proc_calc_metrics(page, start, off, count, eof, len); | |
219 | } | |
220 | #endif | |
221 | ||
222 | #ifdef CONFIG_STRAM_PROC | |
223 | static int stram_read_proc(char *page, char **start, off_t off, | |
224 | int count, int *eof, void *data) | |
225 | { | |
226 | int len = get_stram_list(page); | |
227 | return proc_calc_metrics(page, start, off, count, eof, len); | |
228 | } | |
229 | #endif | |
230 | ||
9361401e | 231 | #ifdef CONFIG_BLOCK |
1da177e4 LT |
232 | static int partitions_open(struct inode *inode, struct file *file) |
233 | { | |
234 | return seq_open(file, &partitions_op); | |
235 | } | |
00977a59 | 236 | static const struct file_operations proc_partitions_operations = { |
1da177e4 LT |
237 | .open = partitions_open, |
238 | .read = seq_read, | |
239 | .llseek = seq_lseek, | |
240 | .release = seq_release, | |
241 | }; | |
242 | ||
1da177e4 LT |
243 | static int diskstats_open(struct inode *inode, struct file *file) |
244 | { | |
245 | return seq_open(file, &diskstats_op); | |
246 | } | |
00977a59 | 247 | static const struct file_operations proc_diskstats_operations = { |
1da177e4 LT |
248 | .open = diskstats_open, |
249 | .read = seq_read, | |
250 | .llseek = seq_lseek, | |
251 | .release = seq_release, | |
252 | }; | |
9361401e | 253 | #endif |
1da177e4 LT |
254 | |
255 | #ifdef CONFIG_MODULES | |
03a44825 | 256 | extern const struct seq_operations modules_op; |
1da177e4 LT |
257 | static int modules_open(struct inode *inode, struct file *file) |
258 | { | |
259 | return seq_open(file, &modules_op); | |
260 | } | |
00977a59 | 261 | static const struct file_operations proc_modules_operations = { |
1da177e4 LT |
262 | .open = modules_open, |
263 | .read = seq_read, | |
264 | .llseek = seq_lseek, | |
265 | .release = seq_release, | |
266 | }; | |
267 | #endif | |
268 | ||
158a9624 | 269 | #ifdef CONFIG_SLABINFO |
1da177e4 LT |
270 | static int slabinfo_open(struct inode *inode, struct file *file) |
271 | { | |
272 | return seq_open(file, &slabinfo_op); | |
273 | } | |
00977a59 | 274 | static const struct file_operations proc_slabinfo_operations = { |
1da177e4 LT |
275 | .open = slabinfo_open, |
276 | .read = seq_read, | |
277 | .write = slabinfo_write, | |
278 | .llseek = seq_lseek, | |
279 | .release = seq_release, | |
280 | }; | |
871751e2 AV |
281 | |
282 | #ifdef CONFIG_DEBUG_SLAB_LEAK | |
03a44825 | 283 | extern const struct seq_operations slabstats_op; |
871751e2 AV |
284 | static int slabstats_open(struct inode *inode, struct file *file) |
285 | { | |
286 | unsigned long *n = kzalloc(PAGE_SIZE, GFP_KERNEL); | |
287 | int ret = -ENOMEM; | |
288 | if (n) { | |
289 | ret = seq_open(file, &slabstats_op); | |
290 | if (!ret) { | |
291 | struct seq_file *m = file->private_data; | |
292 | *n = PAGE_SIZE / (2 * sizeof(unsigned long)); | |
293 | m->private = n; | |
294 | n = NULL; | |
295 | } | |
296 | kfree(n); | |
297 | } | |
298 | return ret; | |
299 | } | |
300 | ||
00977a59 | 301 | static const struct file_operations proc_slabstats_operations = { |
871751e2 AV |
302 | .open = slabstats_open, |
303 | .read = seq_read, | |
304 | .llseek = seq_lseek, | |
09f0892e | 305 | .release = seq_release_private, |
871751e2 AV |
306 | }; |
307 | #endif | |
10cef602 | 308 | #endif |
1da177e4 | 309 | |
a10aa579 CL |
310 | #ifdef CONFIG_MMU |
311 | static int vmalloc_open(struct inode *inode, struct file *file) | |
312 | { | |
a47a126a ED |
313 | unsigned int *ptr = NULL; |
314 | int ret; | |
315 | ||
316 | if (NUMA_BUILD) | |
317 | ptr = kmalloc(nr_node_ids * sizeof(unsigned int), GFP_KERNEL); | |
318 | ret = seq_open(file, &vmalloc_op); | |
319 | if (!ret) { | |
320 | struct seq_file *m = file->private_data; | |
321 | m->private = ptr; | |
322 | } else | |
323 | kfree(ptr); | |
324 | return ret; | |
a10aa579 CL |
325 | } |
326 | ||
327 | static const struct file_operations proc_vmalloc_operations = { | |
328 | .open = vmalloc_open, | |
329 | .read = seq_read, | |
330 | .llseek = seq_lseek, | |
a47a126a | 331 | .release = seq_release_private, |
a10aa579 CL |
332 | }; |
333 | #endif | |
334 | ||
a2eddfa9 JB |
335 | #ifndef arch_irq_stat_cpu |
336 | #define arch_irq_stat_cpu(cpu) 0 | |
337 | #endif | |
338 | #ifndef arch_irq_stat | |
339 | #define arch_irq_stat() 0 | |
340 | #endif | |
341 | ||
1da177e4 LT |
342 | static int show_stat(struct seq_file *p, void *v) |
343 | { | |
c7fb03a4 | 344 | int i, j; |
1da177e4 LT |
345 | unsigned long jif; |
346 | cputime64_t user, nice, system, idle, iowait, irq, softirq, steal; | |
5e84cfde | 347 | cputime64_t guest; |
1da177e4 | 348 | u64 sum = 0; |
924b42d5 | 349 | struct timespec boottime; |
c7fb03a4 | 350 | unsigned int per_irq_sum; |
1da177e4 LT |
351 | |
352 | user = nice = system = idle = iowait = | |
353 | irq = softirq = steal = cputime64_zero; | |
5e84cfde | 354 | guest = cputime64_zero; |
924b42d5 TJ |
355 | getboottime(&boottime); |
356 | jif = boottime.tv_sec; | |
1da177e4 | 357 | |
0a945022 | 358 | for_each_possible_cpu(i) { |
1da177e4 LT |
359 | user = cputime64_add(user, kstat_cpu(i).cpustat.user); |
360 | nice = cputime64_add(nice, kstat_cpu(i).cpustat.nice); | |
361 | system = cputime64_add(system, kstat_cpu(i).cpustat.system); | |
362 | idle = cputime64_add(idle, kstat_cpu(i).cpustat.idle); | |
363 | iowait = cputime64_add(iowait, kstat_cpu(i).cpustat.iowait); | |
364 | irq = cputime64_add(irq, kstat_cpu(i).cpustat.irq); | |
365 | softirq = cputime64_add(softirq, kstat_cpu(i).cpustat.softirq); | |
366 | steal = cputime64_add(steal, kstat_cpu(i).cpustat.steal); | |
5e84cfde | 367 | guest = cputime64_add(guest, kstat_cpu(i).cpustat.guest); |
2cc21ef8 | 368 | |
2be3b52a | 369 | for_each_irq_nr(j) |
2cc21ef8 | 370 | sum += kstat_irqs_cpu(j, i); |
c7fb03a4 | 371 | |
a2eddfa9 | 372 | sum += arch_irq_stat_cpu(i); |
1da177e4 | 373 | } |
a2eddfa9 | 374 | sum += arch_irq_stat(); |
1da177e4 | 375 | |
5e84cfde | 376 | seq_printf(p, "cpu %llu %llu %llu %llu %llu %llu %llu %llu %llu\n", |
1da177e4 LT |
377 | (unsigned long long)cputime64_to_clock_t(user), |
378 | (unsigned long long)cputime64_to_clock_t(nice), | |
379 | (unsigned long long)cputime64_to_clock_t(system), | |
380 | (unsigned long long)cputime64_to_clock_t(idle), | |
381 | (unsigned long long)cputime64_to_clock_t(iowait), | |
382 | (unsigned long long)cputime64_to_clock_t(irq), | |
383 | (unsigned long long)cputime64_to_clock_t(softirq), | |
5e84cfde LV |
384 | (unsigned long long)cputime64_to_clock_t(steal), |
385 | (unsigned long long)cputime64_to_clock_t(guest)); | |
1da177e4 LT |
386 | for_each_online_cpu(i) { |
387 | ||
388 | /* Copy values here to work around gcc-2.95.3, gcc-2.96 */ | |
389 | user = kstat_cpu(i).cpustat.user; | |
390 | nice = kstat_cpu(i).cpustat.nice; | |
391 | system = kstat_cpu(i).cpustat.system; | |
392 | idle = kstat_cpu(i).cpustat.idle; | |
393 | iowait = kstat_cpu(i).cpustat.iowait; | |
394 | irq = kstat_cpu(i).cpustat.irq; | |
395 | softirq = kstat_cpu(i).cpustat.softirq; | |
396 | steal = kstat_cpu(i).cpustat.steal; | |
5e84cfde LV |
397 | guest = kstat_cpu(i).cpustat.guest; |
398 | seq_printf(p, | |
399 | "cpu%d %llu %llu %llu %llu %llu %llu %llu %llu %llu\n", | |
1da177e4 LT |
400 | i, |
401 | (unsigned long long)cputime64_to_clock_t(user), | |
402 | (unsigned long long)cputime64_to_clock_t(nice), | |
403 | (unsigned long long)cputime64_to_clock_t(system), | |
404 | (unsigned long long)cputime64_to_clock_t(idle), | |
405 | (unsigned long long)cputime64_to_clock_t(iowait), | |
406 | (unsigned long long)cputime64_to_clock_t(irq), | |
407 | (unsigned long long)cputime64_to_clock_t(softirq), | |
5e84cfde LV |
408 | (unsigned long long)cputime64_to_clock_t(steal), |
409 | (unsigned long long)cputime64_to_clock_t(guest)); | |
1da177e4 LT |
410 | } |
411 | seq_printf(p, "intr %llu", (unsigned long long)sum); | |
412 | ||
c7fb03a4 | 413 | /* sum again ? it could be updated? */ |
2be3b52a | 414 | for_each_irq_nr(j) { |
c7fb03a4 | 415 | per_irq_sum = 0; |
c7fb03a4 | 416 | |
2cc21ef8 TG |
417 | for_each_possible_cpu(i) |
418 | per_irq_sum += kstat_irqs_cpu(j, i); | |
c7fb03a4 | 419 | |
c7fb03a4 | 420 | seq_printf(p, " %u", per_irq_sum); |
c7fb03a4 | 421 | } |
1da177e4 LT |
422 | |
423 | seq_printf(p, | |
424 | "\nctxt %llu\n" | |
425 | "btime %lu\n" | |
426 | "processes %lu\n" | |
427 | "procs_running %lu\n" | |
428 | "procs_blocked %lu\n", | |
429 | nr_context_switches(), | |
430 | (unsigned long)jif, | |
431 | total_forks, | |
432 | nr_running(), | |
433 | nr_iowait()); | |
434 | ||
435 | return 0; | |
436 | } | |
437 | ||
438 | static int stat_open(struct inode *inode, struct file *file) | |
439 | { | |
440 | unsigned size = 4096 * (1 + num_possible_cpus() / 32); | |
441 | char *buf; | |
442 | struct seq_file *m; | |
443 | int res; | |
444 | ||
445 | /* don't ask for more than the kmalloc() max size, currently 128 KB */ | |
446 | if (size > 128 * 1024) | |
447 | size = 128 * 1024; | |
448 | buf = kmalloc(size, GFP_KERNEL); | |
449 | if (!buf) | |
450 | return -ENOMEM; | |
451 | ||
452 | res = single_open(file, show_stat, NULL); | |
453 | if (!res) { | |
454 | m = file->private_data; | |
455 | m->buf = buf; | |
456 | m->size = size; | |
457 | } else | |
458 | kfree(buf); | |
459 | return res; | |
460 | } | |
00977a59 | 461 | static const struct file_operations proc_stat_operations = { |
1da177e4 LT |
462 | .open = stat_open, |
463 | .read = seq_read, | |
464 | .llseek = seq_lseek, | |
465 | .release = single_release, | |
466 | }; | |
467 | ||
1da177e4 LT |
468 | /* |
469 | * /proc/interrupts | |
470 | */ | |
471 | static void *int_seq_start(struct seq_file *f, loff_t *pos) | |
472 | { | |
da27c118 | 473 | return (*pos <= nr_irqs) ? pos : NULL; |
1da177e4 LT |
474 | } |
475 | ||
52b17329 | 476 | |
1da177e4 LT |
477 | static void *int_seq_next(struct seq_file *f, void *v, loff_t *pos) |
478 | { | |
479 | (*pos)++; | |
52b17329 | 480 | return (*pos <= nr_irqs) ? pos : NULL; |
1da177e4 LT |
481 | } |
482 | ||
483 | static void int_seq_stop(struct seq_file *f, void *v) | |
484 | { | |
485 | /* Nothing to do */ | |
486 | } | |
487 | ||
03a44825 | 488 | static const struct seq_operations int_seq_ops = { |
1da177e4 LT |
489 | .start = int_seq_start, |
490 | .next = int_seq_next, | |
491 | .stop = int_seq_stop, | |
492 | .show = show_interrupts | |
493 | }; | |
494 | ||
495 | static int interrupts_open(struct inode *inode, struct file *filp) | |
496 | { | |
497 | return seq_open(filp, &int_seq_ops); | |
498 | } | |
499 | ||
00977a59 | 500 | static const struct file_operations proc_interrupts_operations = { |
1da177e4 LT |
501 | .open = interrupts_open, |
502 | .read = seq_read, | |
503 | .llseek = seq_lseek, | |
504 | .release = seq_release, | |
505 | }; | |
506 | ||
507 | static int filesystems_read_proc(char *page, char **start, off_t off, | |
508 | int count, int *eof, void *data) | |
509 | { | |
510 | int len = get_filesystem_list(page); | |
511 | return proc_calc_metrics(page, start, off, count, eof, len); | |
512 | } | |
513 | ||
514 | static int cmdline_read_proc(char *page, char **start, off_t off, | |
515 | int count, int *eof, void *data) | |
516 | { | |
517 | int len; | |
518 | ||
519 | len = sprintf(page, "%s\n", saved_command_line); | |
520 | return proc_calc_metrics(page, start, off, count, eof, len); | |
521 | } | |
522 | ||
bfcd17a6 | 523 | #ifdef CONFIG_FILE_LOCKING |
7f8ada98 | 524 | static int locks_open(struct inode *inode, struct file *filp) |
1da177e4 | 525 | { |
7f8ada98 | 526 | return seq_open(filp, &locks_seq_operations); |
1da177e4 LT |
527 | } |
528 | ||
7f8ada98 PE |
529 | static const struct file_operations proc_locks_operations = { |
530 | .open = locks_open, | |
531 | .read = seq_read, | |
532 | .llseek = seq_lseek, | |
533 | .release = seq_release, | |
534 | }; | |
bfcd17a6 | 535 | #endif /* CONFIG_FILE_LOCKING */ |
7f8ada98 | 536 | |
1da177e4 LT |
537 | static int execdomains_read_proc(char *page, char **start, off_t off, |
538 | int count, int *eof, void *data) | |
539 | { | |
540 | int len = get_exec_domain_list(page); | |
541 | return proc_calc_metrics(page, start, off, count, eof, len); | |
542 | } | |
543 | ||
1e883281 | 544 | #ifdef CONFIG_PROC_PAGE_MONITOR |
161f47bf MM |
545 | #define KPMSIZE sizeof(u64) |
546 | #define KPMMASK (KPMSIZE - 1) | |
547 | /* /proc/kpagecount - an array exposing page counts | |
548 | * | |
549 | * Each entry is a u64 representing the corresponding | |
550 | * physical page count. | |
551 | */ | |
552 | static ssize_t kpagecount_read(struct file *file, char __user *buf, | |
553 | size_t count, loff_t *ppos) | |
554 | { | |
555 | u64 __user *out = (u64 __user *)buf; | |
556 | struct page *ppage; | |
557 | unsigned long src = *ppos; | |
558 | unsigned long pfn; | |
559 | ssize_t ret = 0; | |
560 | u64 pcount; | |
561 | ||
562 | pfn = src / KPMSIZE; | |
563 | count = min_t(size_t, count, (max_pfn * KPMSIZE) - src); | |
564 | if (src & KPMMASK || count & KPMMASK) | |
4710d1ac | 565 | return -EINVAL; |
161f47bf MM |
566 | |
567 | while (count > 0) { | |
304daa81 MM |
568 | ppage = NULL; |
569 | if (pfn_valid(pfn)) | |
570 | ppage = pfn_to_page(pfn); | |
571 | pfn++; | |
161f47bf MM |
572 | if (!ppage) |
573 | pcount = 0; | |
574 | else | |
bbcdac0c | 575 | pcount = page_mapcount(ppage); |
161f47bf MM |
576 | |
577 | if (put_user(pcount, out++)) { | |
578 | ret = -EFAULT; | |
579 | break; | |
580 | } | |
581 | ||
582 | count -= KPMSIZE; | |
583 | } | |
584 | ||
585 | *ppos += (char __user *)out - buf; | |
586 | if (!ret) | |
587 | ret = (char __user *)out - buf; | |
588 | return ret; | |
589 | } | |
590 | ||
591 | static struct file_operations proc_kpagecount_operations = { | |
592 | .llseek = mem_lseek, | |
593 | .read = kpagecount_read, | |
594 | }; | |
595 | ||
304daa81 MM |
596 | /* /proc/kpageflags - an array exposing page flags |
597 | * | |
598 | * Each entry is a u64 representing the corresponding | |
599 | * physical page flags. | |
600 | */ | |
601 | ||
602 | /* These macros are used to decouple internal flags from exported ones */ | |
603 | ||
604 | #define KPF_LOCKED 0 | |
605 | #define KPF_ERROR 1 | |
606 | #define KPF_REFERENCED 2 | |
607 | #define KPF_UPTODATE 3 | |
608 | #define KPF_DIRTY 4 | |
609 | #define KPF_LRU 5 | |
610 | #define KPF_ACTIVE 6 | |
611 | #define KPF_SLAB 7 | |
612 | #define KPF_WRITEBACK 8 | |
613 | #define KPF_RECLAIM 9 | |
614 | #define KPF_BUDDY 10 | |
615 | ||
616 | #define kpf_copy_bit(flags, srcpos, dstpos) (((flags >> srcpos) & 1) << dstpos) | |
617 | ||
618 | static ssize_t kpageflags_read(struct file *file, char __user *buf, | |
619 | size_t count, loff_t *ppos) | |
620 | { | |
621 | u64 __user *out = (u64 __user *)buf; | |
622 | struct page *ppage; | |
623 | unsigned long src = *ppos; | |
624 | unsigned long pfn; | |
625 | ssize_t ret = 0; | |
626 | u64 kflags, uflags; | |
627 | ||
628 | pfn = src / KPMSIZE; | |
629 | count = min_t(unsigned long, count, (max_pfn * KPMSIZE) - src); | |
630 | if (src & KPMMASK || count & KPMMASK) | |
4710d1ac | 631 | return -EINVAL; |
304daa81 MM |
632 | |
633 | while (count > 0) { | |
634 | ppage = NULL; | |
635 | if (pfn_valid(pfn)) | |
636 | ppage = pfn_to_page(pfn); | |
637 | pfn++; | |
638 | if (!ppage) | |
639 | kflags = 0; | |
640 | else | |
641 | kflags = ppage->flags; | |
642 | ||
643 | uflags = kpf_copy_bit(KPF_LOCKED, PG_locked, kflags) | | |
644 | kpf_copy_bit(kflags, KPF_ERROR, PG_error) | | |
645 | kpf_copy_bit(kflags, KPF_REFERENCED, PG_referenced) | | |
646 | kpf_copy_bit(kflags, KPF_UPTODATE, PG_uptodate) | | |
647 | kpf_copy_bit(kflags, KPF_DIRTY, PG_dirty) | | |
648 | kpf_copy_bit(kflags, KPF_LRU, PG_lru) | | |
649 | kpf_copy_bit(kflags, KPF_ACTIVE, PG_active) | | |
650 | kpf_copy_bit(kflags, KPF_SLAB, PG_slab) | | |
651 | kpf_copy_bit(kflags, KPF_WRITEBACK, PG_writeback) | | |
652 | kpf_copy_bit(kflags, KPF_RECLAIM, PG_reclaim) | | |
653 | kpf_copy_bit(kflags, KPF_BUDDY, PG_buddy); | |
654 | ||
655 | if (put_user(uflags, out++)) { | |
656 | ret = -EFAULT; | |
657 | break; | |
658 | } | |
659 | ||
660 | count -= KPMSIZE; | |
661 | } | |
662 | ||
663 | *ppos += (char __user *)out - buf; | |
664 | if (!ret) | |
665 | ret = (char __user *)out - buf; | |
666 | return ret; | |
667 | } | |
668 | ||
669 | static struct file_operations proc_kpageflags_operations = { | |
670 | .llseek = mem_lseek, | |
671 | .read = kpageflags_read, | |
672 | }; | |
1e883281 | 673 | #endif /* CONFIG_PROC_PAGE_MONITOR */ |
304daa81 | 674 | |
1da177e4 LT |
675 | struct proc_dir_entry *proc_root_kcore; |
676 | ||
1da177e4 LT |
677 | void __init proc_misc_init(void) |
678 | { | |
1da177e4 LT |
679 | static struct { |
680 | char *name; | |
681 | int (*read_proc)(char*,char**,off_t,int,int*,void*); | |
682 | } *p, simple_ones[] = { | |
1da177e4 LT |
683 | {"version", version_read_proc}, |
684 | #ifdef CONFIG_PROC_HARDWARE | |
685 | {"hardware", hardware_read_proc}, | |
686 | #endif | |
687 | #ifdef CONFIG_STRAM_PROC | |
688 | {"stram", stram_read_proc}, | |
689 | #endif | |
1da177e4 LT |
690 | {"filesystems", filesystems_read_proc}, |
691 | {"cmdline", cmdline_read_proc}, | |
1da177e4 LT |
692 | {"execdomains", execdomains_read_proc}, |
693 | {NULL,} | |
694 | }; | |
695 | for (p = simple_ones; p->name; p++) | |
696 | create_proc_read_entry(p->name, 0, NULL, p->read_proc, NULL); | |
697 | ||
698 | proc_symlink("mounts", NULL, "self/mounts"); | |
699 | ||
700 | /* And now for trickier ones */ | |
c36264df | 701 | #ifdef CONFIG_PRINTK |
c74c120a | 702 | proc_create("kmsg", S_IRUSR, NULL, &proc_kmsg_operations); |
c36264df | 703 | #endif |
bfcd17a6 | 704 | #ifdef CONFIG_FILE_LOCKING |
0d5c9f5f | 705 | proc_create("locks", 0, NULL, &proc_locks_operations); |
bfcd17a6 | 706 | #endif |
0d5c9f5f AD |
707 | proc_create("devices", 0, NULL, &proc_devinfo_operations); |
708 | proc_create("cpuinfo", 0, NULL, &proc_cpuinfo_operations); | |
9361401e | 709 | #ifdef CONFIG_BLOCK |
0d5c9f5f | 710 | proc_create("partitions", 0, NULL, &proc_partitions_operations); |
9361401e | 711 | #endif |
0d5c9f5f AD |
712 | proc_create("stat", 0, NULL, &proc_stat_operations); |
713 | proc_create("interrupts", 0, NULL, &proc_interrupts_operations); | |
158a9624 | 714 | #ifdef CONFIG_SLABINFO |
0d5c9f5f | 715 | proc_create("slabinfo",S_IWUSR|S_IRUGO,NULL,&proc_slabinfo_operations); |
871751e2 | 716 | #ifdef CONFIG_DEBUG_SLAB_LEAK |
0d5c9f5f | 717 | proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations); |
871751e2 | 718 | #endif |
a10aa579 CL |
719 | #endif |
720 | #ifdef CONFIG_MMU | |
721 | proc_create("vmallocinfo", S_IRUSR, NULL, &proc_vmalloc_operations); | |
10cef602 | 722 | #endif |
0d5c9f5f AD |
723 | proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations); |
724 | proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops); | |
725 | proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations); | |
726 | proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations); | |
9361401e | 727 | #ifdef CONFIG_BLOCK |
0d5c9f5f | 728 | proc_create("diskstats", 0, NULL, &proc_diskstats_operations); |
9361401e | 729 | #endif |
1da177e4 | 730 | #ifdef CONFIG_MODULES |
0d5c9f5f | 731 | proc_create("modules", 0, NULL, &proc_modules_operations); |
1da177e4 LT |
732 | #endif |
733 | #ifdef CONFIG_SCHEDSTATS | |
0d5c9f5f | 734 | proc_create("schedstat", 0, NULL, &proc_schedstat_operations); |
1da177e4 LT |
735 | #endif |
736 | #ifdef CONFIG_PROC_KCORE | |
0d5c9f5f AD |
737 | proc_root_kcore = proc_create("kcore", S_IRUSR, NULL, &proc_kcore_operations); |
738 | if (proc_root_kcore) | |
1da177e4 LT |
739 | proc_root_kcore->size = |
740 | (size_t)high_memory - PAGE_OFFSET + PAGE_SIZE; | |
1da177e4 | 741 | #endif |
1e883281 | 742 | #ifdef CONFIG_PROC_PAGE_MONITOR |
0d5c9f5f AD |
743 | proc_create("kpagecount", S_IRUSR, NULL, &proc_kpagecount_operations); |
744 | proc_create("kpageflags", S_IRUSR, NULL, &proc_kpageflags_operations); | |
1e883281 | 745 | #endif |
666bfddb | 746 | #ifdef CONFIG_PROC_VMCORE |
0d5c9f5f | 747 | proc_vmcore = proc_create("vmcore", S_IRUSR, NULL, &proc_vmcore_operations); |
666bfddb | 748 | #endif |
1da177e4 | 749 | } |