b675a49c182333eb6a38c321d288ca9ae6c4f46b
[deliverable/linux.git] / fs / proc / proc_misc.c
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>
23 #include <linux/fs.h>
24 #include <linux/tty.h>
25 #include <linux/string.h>
26 #include <linux/mman.h>
27 #include <linux/quicklist.h>
28 #include <linux/proc_fs.h>
29 #include <linux/ioport.h>
30 #include <linux/mm.h>
31 #include <linux/mmzone.h>
32 #include <linux/pagemap.h>
33 #include <linux/interrupt.h>
34 #include <linux/swap.h>
35 #include <linux/slab.h>
36 #include <linux/genhd.h>
37 #include <linux/smp.h>
38 #include <linux/signal.h>
39 #include <linux/module.h>
40 #include <linux/init.h>
41 #include <linux/seq_file.h>
42 #include <linux/times.h>
43 #include <linux/profile.h>
44 #include <linux/utsname.h>
45 #include <linux/blkdev.h>
46 #include <linux/hugetlb.h>
47 #include <linux/jiffies.h>
48 #include <linux/sysrq.h>
49 #include <linux/vmalloc.h>
50 #include <linux/crash_dump.h>
51 #include <linux/pid_namespace.h>
52 #include <linux/bootmem.h>
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
60 #define LOAD_INT(x) ((x) >> FSHIFT)
61 #define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100)
62 /*
63 * Warning: stuff below (imported functions) assumes that its output will fit
64 * into one page. For some of those functions it may be wrong. Moreover, we
65 * have a way to deal with that gracefully. Right now I used straightforward
66 * wrappers, but this needs further analysis wrt potential overflows.
67 */
68 extern int get_hardware_list(char *);
69 extern int get_stram_list(char *);
70 extern int get_exec_domain_list(char *);
71
72 static int proc_calc_metrics(char *page, char **start, off_t off,
73 int count, int *eof, int len)
74 {
75 if (len <= off+count) *eof = 1;
76 *start = page + off;
77 len -= off;
78 if (len>count) len = count;
79 if (len<0) len = 0;
80 return len;
81 }
82
83 static int loadavg_read_proc(char *page, char **start, off_t off,
84 int count, int *eof, void *data)
85 {
86 int a, b, c;
87 int len;
88 unsigned long seq;
89
90 do {
91 seq = read_seqbegin(&xtime_lock);
92 a = avenrun[0] + (FIXED_1/200);
93 b = avenrun[1] + (FIXED_1/200);
94 c = avenrun[2] + (FIXED_1/200);
95 } while (read_seqretry(&xtime_lock, seq));
96
97 len = sprintf(page,"%d.%02d %d.%02d %d.%02d %ld/%d %d\n",
98 LOAD_INT(a), LOAD_FRAC(a),
99 LOAD_INT(b), LOAD_FRAC(b),
100 LOAD_INT(c), LOAD_FRAC(c),
101 nr_running(), nr_threads,
102 task_active_pid_ns(current)->last_pid);
103 return proc_calc_metrics(page, start, off, count, eof, len);
104 }
105
106 static int uptime_read_proc(char *page, char **start, off_t off,
107 int count, int *eof, void *data)
108 {
109 struct timespec uptime;
110 struct timespec idle;
111 int len;
112 cputime_t idletime = cputime_add(init_task.utime, init_task.stime);
113
114 do_posix_clock_monotonic_gettime(&uptime);
115 monotonic_to_bootbased(&uptime);
116 cputime_to_timespec(idletime, &idle);
117 len = sprintf(page,"%lu.%02lu %lu.%02lu\n",
118 (unsigned long) uptime.tv_sec,
119 (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
120 (unsigned long) idle.tv_sec,
121 (idle.tv_nsec / (NSEC_PER_SEC / 100)));
122
123 return proc_calc_metrics(page, start, off, count, eof, len);
124 }
125
126 int __attribute__((weak)) arch_report_meminfo(char *page)
127 {
128 return 0;
129 }
130
131 static int meminfo_read_proc(char *page, char **start, off_t off,
132 int count, int *eof, void *data)
133 {
134 struct sysinfo i;
135 int len;
136 unsigned long committed;
137 unsigned long allowed;
138 struct vmalloc_info vmi;
139 long cached;
140
141 /*
142 * display in kilobytes.
143 */
144 #define K(x) ((x) << (PAGE_SHIFT - 10))
145 si_meminfo(&i);
146 si_swapinfo(&i);
147 committed = atomic_long_read(&vm_committed_space);
148 allowed = ((totalram_pages - hugetlb_total_pages())
149 * sysctl_overcommit_ratio / 100) + total_swap_pages;
150
151 cached = global_page_state(NR_FILE_PAGES) -
152 total_swapcache_pages - i.bufferram;
153 if (cached < 0)
154 cached = 0;
155
156 get_vmalloc_info(&vmi);
157
158 /*
159 * Tagged format, for easy grepping and expansion.
160 */
161 len = sprintf(page,
162 "MemTotal: %8lu kB\n"
163 "MemFree: %8lu kB\n"
164 "Buffers: %8lu kB\n"
165 "Cached: %8lu kB\n"
166 "SwapCached: %8lu kB\n"
167 "Active: %8lu kB\n"
168 "Inactive: %8lu kB\n"
169 #ifdef CONFIG_HIGHMEM
170 "HighTotal: %8lu kB\n"
171 "HighFree: %8lu kB\n"
172 "LowTotal: %8lu kB\n"
173 "LowFree: %8lu kB\n"
174 #endif
175 "SwapTotal: %8lu kB\n"
176 "SwapFree: %8lu kB\n"
177 "Dirty: %8lu kB\n"
178 "Writeback: %8lu kB\n"
179 "AnonPages: %8lu kB\n"
180 "Mapped: %8lu kB\n"
181 "Slab: %8lu kB\n"
182 "SReclaimable: %8lu kB\n"
183 "SUnreclaim: %8lu kB\n"
184 "PageTables: %8lu kB\n"
185 #ifdef CONFIG_QUICKLIST
186 "Quicklists: %8lu kB\n"
187 #endif
188 "NFS_Unstable: %8lu kB\n"
189 "Bounce: %8lu kB\n"
190 "WritebackTmp: %8lu kB\n"
191 "CommitLimit: %8lu kB\n"
192 "Committed_AS: %8lu kB\n"
193 "VmallocTotal: %8lu kB\n"
194 "VmallocUsed: %8lu kB\n"
195 "VmallocChunk: %8lu kB\n",
196 K(i.totalram),
197 K(i.freeram),
198 K(i.bufferram),
199 K(cached),
200 K(total_swapcache_pages),
201 K(global_page_state(NR_ACTIVE)),
202 K(global_page_state(NR_INACTIVE)),
203 #ifdef CONFIG_HIGHMEM
204 K(i.totalhigh),
205 K(i.freehigh),
206 K(i.totalram-i.totalhigh),
207 K(i.freeram-i.freehigh),
208 #endif
209 K(i.totalswap),
210 K(i.freeswap),
211 K(global_page_state(NR_FILE_DIRTY)),
212 K(global_page_state(NR_WRITEBACK)),
213 K(global_page_state(NR_ANON_PAGES)),
214 K(global_page_state(NR_FILE_MAPPED)),
215 K(global_page_state(NR_SLAB_RECLAIMABLE) +
216 global_page_state(NR_SLAB_UNRECLAIMABLE)),
217 K(global_page_state(NR_SLAB_RECLAIMABLE)),
218 K(global_page_state(NR_SLAB_UNRECLAIMABLE)),
219 K(global_page_state(NR_PAGETABLE)),
220 #ifdef CONFIG_QUICKLIST
221 K(quicklist_total_size()),
222 #endif
223 K(global_page_state(NR_UNSTABLE_NFS)),
224 K(global_page_state(NR_BOUNCE)),
225 K(global_page_state(NR_WRITEBACK_TEMP)),
226 K(allowed),
227 K(committed),
228 (unsigned long)VMALLOC_TOTAL >> 10,
229 vmi.used >> 10,
230 vmi.largest_chunk >> 10
231 );
232
233 len += hugetlb_report_meminfo(page + len);
234
235 len += arch_report_meminfo(page + len);
236
237 return proc_calc_metrics(page, start, off, count, eof, len);
238 #undef K
239 }
240
241 static int fragmentation_open(struct inode *inode, struct file *file)
242 {
243 (void)inode;
244 return seq_open(file, &fragmentation_op);
245 }
246
247 static const struct file_operations fragmentation_file_operations = {
248 .open = fragmentation_open,
249 .read = seq_read,
250 .llseek = seq_lseek,
251 .release = seq_release,
252 };
253
254 static int pagetypeinfo_open(struct inode *inode, struct file *file)
255 {
256 return seq_open(file, &pagetypeinfo_op);
257 }
258
259 static const struct file_operations pagetypeinfo_file_ops = {
260 .open = pagetypeinfo_open,
261 .read = seq_read,
262 .llseek = seq_lseek,
263 .release = seq_release,
264 };
265
266 static int zoneinfo_open(struct inode *inode, struct file *file)
267 {
268 return seq_open(file, &zoneinfo_op);
269 }
270
271 static const struct file_operations proc_zoneinfo_file_operations = {
272 .open = zoneinfo_open,
273 .read = seq_read,
274 .llseek = seq_lseek,
275 .release = seq_release,
276 };
277
278 static int version_read_proc(char *page, char **start, off_t off,
279 int count, int *eof, void *data)
280 {
281 int len;
282
283 len = snprintf(page, PAGE_SIZE, linux_proc_banner,
284 utsname()->sysname,
285 utsname()->release,
286 utsname()->version);
287 return proc_calc_metrics(page, start, off, count, eof, len);
288 }
289
290 extern const struct seq_operations cpuinfo_op;
291 static int cpuinfo_open(struct inode *inode, struct file *file)
292 {
293 return seq_open(file, &cpuinfo_op);
294 }
295
296 static const struct file_operations proc_cpuinfo_operations = {
297 .open = cpuinfo_open,
298 .read = seq_read,
299 .llseek = seq_lseek,
300 .release = seq_release,
301 };
302
303 static int devinfo_show(struct seq_file *f, void *v)
304 {
305 int i = *(loff_t *) v;
306
307 if (i < CHRDEV_MAJOR_HASH_SIZE) {
308 if (i == 0)
309 seq_printf(f, "Character devices:\n");
310 chrdev_show(f, i);
311 }
312 #ifdef CONFIG_BLOCK
313 else {
314 i -= CHRDEV_MAJOR_HASH_SIZE;
315 if (i == 0)
316 seq_printf(f, "\nBlock devices:\n");
317 blkdev_show(f, i);
318 }
319 #endif
320 return 0;
321 }
322
323 static void *devinfo_start(struct seq_file *f, loff_t *pos)
324 {
325 if (*pos < (BLKDEV_MAJOR_HASH_SIZE + CHRDEV_MAJOR_HASH_SIZE))
326 return pos;
327 return NULL;
328 }
329
330 static void *devinfo_next(struct seq_file *f, void *v, loff_t *pos)
331 {
332 (*pos)++;
333 if (*pos >= (BLKDEV_MAJOR_HASH_SIZE + CHRDEV_MAJOR_HASH_SIZE))
334 return NULL;
335 return pos;
336 }
337
338 static void devinfo_stop(struct seq_file *f, void *v)
339 {
340 /* Nothing to do */
341 }
342
343 static const struct seq_operations devinfo_ops = {
344 .start = devinfo_start,
345 .next = devinfo_next,
346 .stop = devinfo_stop,
347 .show = devinfo_show
348 };
349
350 static int devinfo_open(struct inode *inode, struct file *filp)
351 {
352 return seq_open(filp, &devinfo_ops);
353 }
354
355 static const struct file_operations proc_devinfo_operations = {
356 .open = devinfo_open,
357 .read = seq_read,
358 .llseek = seq_lseek,
359 .release = seq_release,
360 };
361
362 static int vmstat_open(struct inode *inode, struct file *file)
363 {
364 return seq_open(file, &vmstat_op);
365 }
366 static const struct file_operations proc_vmstat_file_operations = {
367 .open = vmstat_open,
368 .read = seq_read,
369 .llseek = seq_lseek,
370 .release = seq_release,
371 };
372
373 #ifdef CONFIG_PROC_HARDWARE
374 static int hardware_read_proc(char *page, char **start, off_t off,
375 int count, int *eof, void *data)
376 {
377 int len = get_hardware_list(page);
378 return proc_calc_metrics(page, start, off, count, eof, len);
379 }
380 #endif
381
382 #ifdef CONFIG_STRAM_PROC
383 static int stram_read_proc(char *page, char **start, off_t off,
384 int count, int *eof, void *data)
385 {
386 int len = get_stram_list(page);
387 return proc_calc_metrics(page, start, off, count, eof, len);
388 }
389 #endif
390
391 #ifdef CONFIG_BLOCK
392 static int partitions_open(struct inode *inode, struct file *file)
393 {
394 return seq_open(file, &partitions_op);
395 }
396 static const struct file_operations proc_partitions_operations = {
397 .open = partitions_open,
398 .read = seq_read,
399 .llseek = seq_lseek,
400 .release = seq_release,
401 };
402
403 static int diskstats_open(struct inode *inode, struct file *file)
404 {
405 return seq_open(file, &diskstats_op);
406 }
407 static const struct file_operations proc_diskstats_operations = {
408 .open = diskstats_open,
409 .read = seq_read,
410 .llseek = seq_lseek,
411 .release = seq_release,
412 };
413 #endif
414
415 #ifdef CONFIG_MODULES
416 extern const struct seq_operations modules_op;
417 static int modules_open(struct inode *inode, struct file *file)
418 {
419 return seq_open(file, &modules_op);
420 }
421 static const struct file_operations proc_modules_operations = {
422 .open = modules_open,
423 .read = seq_read,
424 .llseek = seq_lseek,
425 .release = seq_release,
426 };
427 #endif
428
429 #ifdef CONFIG_SLABINFO
430 static int slabinfo_open(struct inode *inode, struct file *file)
431 {
432 return seq_open(file, &slabinfo_op);
433 }
434 static const struct file_operations proc_slabinfo_operations = {
435 .open = slabinfo_open,
436 .read = seq_read,
437 .write = slabinfo_write,
438 .llseek = seq_lseek,
439 .release = seq_release,
440 };
441
442 #ifdef CONFIG_DEBUG_SLAB_LEAK
443 extern const struct seq_operations slabstats_op;
444 static int slabstats_open(struct inode *inode, struct file *file)
445 {
446 unsigned long *n = kzalloc(PAGE_SIZE, GFP_KERNEL);
447 int ret = -ENOMEM;
448 if (n) {
449 ret = seq_open(file, &slabstats_op);
450 if (!ret) {
451 struct seq_file *m = file->private_data;
452 *n = PAGE_SIZE / (2 * sizeof(unsigned long));
453 m->private = n;
454 n = NULL;
455 }
456 kfree(n);
457 }
458 return ret;
459 }
460
461 static const struct file_operations proc_slabstats_operations = {
462 .open = slabstats_open,
463 .read = seq_read,
464 .llseek = seq_lseek,
465 .release = seq_release_private,
466 };
467 #endif
468 #endif
469
470 #ifdef CONFIG_MMU
471 static int vmalloc_open(struct inode *inode, struct file *file)
472 {
473 unsigned int *ptr = NULL;
474 int ret;
475
476 if (NUMA_BUILD)
477 ptr = kmalloc(nr_node_ids * sizeof(unsigned int), GFP_KERNEL);
478 ret = seq_open(file, &vmalloc_op);
479 if (!ret) {
480 struct seq_file *m = file->private_data;
481 m->private = ptr;
482 } else
483 kfree(ptr);
484 return ret;
485 }
486
487 static const struct file_operations proc_vmalloc_operations = {
488 .open = vmalloc_open,
489 .read = seq_read,
490 .llseek = seq_lseek,
491 .release = seq_release_private,
492 };
493 #endif
494
495 #ifndef arch_irq_stat_cpu
496 #define arch_irq_stat_cpu(cpu) 0
497 #endif
498 #ifndef arch_irq_stat
499 #define arch_irq_stat() 0
500 #endif
501
502 static int show_stat(struct seq_file *p, void *v)
503 {
504 int i;
505 unsigned long jif;
506 cputime64_t user, nice, system, idle, iowait, irq, softirq, steal;
507 cputime64_t guest;
508 u64 sum = 0;
509 struct timespec boottime;
510 unsigned int *per_irq_sum;
511
512 per_irq_sum = kzalloc(sizeof(unsigned int)*NR_IRQS, GFP_KERNEL);
513 if (!per_irq_sum)
514 return -ENOMEM;
515
516 user = nice = system = idle = iowait =
517 irq = softirq = steal = cputime64_zero;
518 guest = cputime64_zero;
519 getboottime(&boottime);
520 jif = boottime.tv_sec;
521
522 for_each_possible_cpu(i) {
523 int j;
524
525 user = cputime64_add(user, kstat_cpu(i).cpustat.user);
526 nice = cputime64_add(nice, kstat_cpu(i).cpustat.nice);
527 system = cputime64_add(system, kstat_cpu(i).cpustat.system);
528 idle = cputime64_add(idle, kstat_cpu(i).cpustat.idle);
529 iowait = cputime64_add(iowait, kstat_cpu(i).cpustat.iowait);
530 irq = cputime64_add(irq, kstat_cpu(i).cpustat.irq);
531 softirq = cputime64_add(softirq, kstat_cpu(i).cpustat.softirq);
532 steal = cputime64_add(steal, kstat_cpu(i).cpustat.steal);
533 guest = cputime64_add(guest, kstat_cpu(i).cpustat.guest);
534 for (j = 0; j < NR_IRQS; j++) {
535 unsigned int temp = kstat_cpu(i).irqs[j];
536 sum += temp;
537 per_irq_sum[j] += temp;
538 }
539 sum += arch_irq_stat_cpu(i);
540 }
541 sum += arch_irq_stat();
542
543 seq_printf(p, "cpu %llu %llu %llu %llu %llu %llu %llu %llu %llu\n",
544 (unsigned long long)cputime64_to_clock_t(user),
545 (unsigned long long)cputime64_to_clock_t(nice),
546 (unsigned long long)cputime64_to_clock_t(system),
547 (unsigned long long)cputime64_to_clock_t(idle),
548 (unsigned long long)cputime64_to_clock_t(iowait),
549 (unsigned long long)cputime64_to_clock_t(irq),
550 (unsigned long long)cputime64_to_clock_t(softirq),
551 (unsigned long long)cputime64_to_clock_t(steal),
552 (unsigned long long)cputime64_to_clock_t(guest));
553 for_each_online_cpu(i) {
554
555 /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
556 user = kstat_cpu(i).cpustat.user;
557 nice = kstat_cpu(i).cpustat.nice;
558 system = kstat_cpu(i).cpustat.system;
559 idle = kstat_cpu(i).cpustat.idle;
560 iowait = kstat_cpu(i).cpustat.iowait;
561 irq = kstat_cpu(i).cpustat.irq;
562 softirq = kstat_cpu(i).cpustat.softirq;
563 steal = kstat_cpu(i).cpustat.steal;
564 guest = kstat_cpu(i).cpustat.guest;
565 seq_printf(p,
566 "cpu%d %llu %llu %llu %llu %llu %llu %llu %llu %llu\n",
567 i,
568 (unsigned long long)cputime64_to_clock_t(user),
569 (unsigned long long)cputime64_to_clock_t(nice),
570 (unsigned long long)cputime64_to_clock_t(system),
571 (unsigned long long)cputime64_to_clock_t(idle),
572 (unsigned long long)cputime64_to_clock_t(iowait),
573 (unsigned long long)cputime64_to_clock_t(irq),
574 (unsigned long long)cputime64_to_clock_t(softirq),
575 (unsigned long long)cputime64_to_clock_t(steal),
576 (unsigned long long)cputime64_to_clock_t(guest));
577 }
578 seq_printf(p, "intr %llu", (unsigned long long)sum);
579
580 for (i = 0; i < NR_IRQS; i++)
581 seq_printf(p, " %u", per_irq_sum[i]);
582
583 seq_printf(p,
584 "\nctxt %llu\n"
585 "btime %lu\n"
586 "processes %lu\n"
587 "procs_running %lu\n"
588 "procs_blocked %lu\n",
589 nr_context_switches(),
590 (unsigned long)jif,
591 total_forks,
592 nr_running(),
593 nr_iowait());
594
595 kfree(per_irq_sum);
596 return 0;
597 }
598
599 static int stat_open(struct inode *inode, struct file *file)
600 {
601 unsigned size = 4096 * (1 + num_possible_cpus() / 32);
602 char *buf;
603 struct seq_file *m;
604 int res;
605
606 /* don't ask for more than the kmalloc() max size, currently 128 KB */
607 if (size > 128 * 1024)
608 size = 128 * 1024;
609 buf = kmalloc(size, GFP_KERNEL);
610 if (!buf)
611 return -ENOMEM;
612
613 res = single_open(file, show_stat, NULL);
614 if (!res) {
615 m = file->private_data;
616 m->buf = buf;
617 m->size = size;
618 } else
619 kfree(buf);
620 return res;
621 }
622 static const struct file_operations proc_stat_operations = {
623 .open = stat_open,
624 .read = seq_read,
625 .llseek = seq_lseek,
626 .release = single_release,
627 };
628
629 /*
630 * /proc/interrupts
631 */
632 static void *int_seq_start(struct seq_file *f, loff_t *pos)
633 {
634 return (*pos <= NR_IRQS) ? pos : NULL;
635 }
636
637 static void *int_seq_next(struct seq_file *f, void *v, loff_t *pos)
638 {
639 (*pos)++;
640 if (*pos > NR_IRQS)
641 return NULL;
642 return pos;
643 }
644
645 static void int_seq_stop(struct seq_file *f, void *v)
646 {
647 /* Nothing to do */
648 }
649
650
651 static const struct seq_operations int_seq_ops = {
652 .start = int_seq_start,
653 .next = int_seq_next,
654 .stop = int_seq_stop,
655 .show = show_interrupts
656 };
657
658 static int interrupts_open(struct inode *inode, struct file *filp)
659 {
660 return seq_open(filp, &int_seq_ops);
661 }
662
663 static const struct file_operations proc_interrupts_operations = {
664 .open = interrupts_open,
665 .read = seq_read,
666 .llseek = seq_lseek,
667 .release = seq_release,
668 };
669
670 static int filesystems_read_proc(char *page, char **start, off_t off,
671 int count, int *eof, void *data)
672 {
673 int len = get_filesystem_list(page);
674 return proc_calc_metrics(page, start, off, count, eof, len);
675 }
676
677 static int cmdline_read_proc(char *page, char **start, off_t off,
678 int count, int *eof, void *data)
679 {
680 int len;
681
682 len = sprintf(page, "%s\n", saved_command_line);
683 return proc_calc_metrics(page, start, off, count, eof, len);
684 }
685
686 #ifdef CONFIG_FILE_LOCKING
687 static int locks_open(struct inode *inode, struct file *filp)
688 {
689 return seq_open(filp, &locks_seq_operations);
690 }
691
692 static const struct file_operations proc_locks_operations = {
693 .open = locks_open,
694 .read = seq_read,
695 .llseek = seq_lseek,
696 .release = seq_release,
697 };
698 #endif /* CONFIG_FILE_LOCKING */
699
700 static int execdomains_read_proc(char *page, char **start, off_t off,
701 int count, int *eof, void *data)
702 {
703 int len = get_exec_domain_list(page);
704 return proc_calc_metrics(page, start, off, count, eof, len);
705 }
706
707 #ifdef CONFIG_MAGIC_SYSRQ
708 /*
709 * writing 'C' to /proc/sysrq-trigger is like sysrq-C
710 */
711 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
712 size_t count, loff_t *ppos)
713 {
714 if (count) {
715 char c;
716
717 if (get_user(c, buf))
718 return -EFAULT;
719 __handle_sysrq(c, NULL, 0);
720 }
721 return count;
722 }
723
724 static const struct file_operations proc_sysrq_trigger_operations = {
725 .write = write_sysrq_trigger,
726 };
727 #endif
728
729 #ifdef CONFIG_PROC_PAGE_MONITOR
730 #define KPMSIZE sizeof(u64)
731 #define KPMMASK (KPMSIZE - 1)
732 /* /proc/kpagecount - an array exposing page counts
733 *
734 * Each entry is a u64 representing the corresponding
735 * physical page count.
736 */
737 static ssize_t kpagecount_read(struct file *file, char __user *buf,
738 size_t count, loff_t *ppos)
739 {
740 u64 __user *out = (u64 __user *)buf;
741 struct page *ppage;
742 unsigned long src = *ppos;
743 unsigned long pfn;
744 ssize_t ret = 0;
745 u64 pcount;
746
747 pfn = src / KPMSIZE;
748 count = min_t(size_t, count, (max_pfn * KPMSIZE) - src);
749 if (src & KPMMASK || count & KPMMASK)
750 return -EINVAL;
751
752 while (count > 0) {
753 ppage = NULL;
754 if (pfn_valid(pfn))
755 ppage = pfn_to_page(pfn);
756 pfn++;
757 if (!ppage)
758 pcount = 0;
759 else
760 pcount = page_mapcount(ppage);
761
762 if (put_user(pcount, out++)) {
763 ret = -EFAULT;
764 break;
765 }
766
767 count -= KPMSIZE;
768 }
769
770 *ppos += (char __user *)out - buf;
771 if (!ret)
772 ret = (char __user *)out - buf;
773 return ret;
774 }
775
776 static struct file_operations proc_kpagecount_operations = {
777 .llseek = mem_lseek,
778 .read = kpagecount_read,
779 };
780
781 /* /proc/kpageflags - an array exposing page flags
782 *
783 * Each entry is a u64 representing the corresponding
784 * physical page flags.
785 */
786
787 /* These macros are used to decouple internal flags from exported ones */
788
789 #define KPF_LOCKED 0
790 #define KPF_ERROR 1
791 #define KPF_REFERENCED 2
792 #define KPF_UPTODATE 3
793 #define KPF_DIRTY 4
794 #define KPF_LRU 5
795 #define KPF_ACTIVE 6
796 #define KPF_SLAB 7
797 #define KPF_WRITEBACK 8
798 #define KPF_RECLAIM 9
799 #define KPF_BUDDY 10
800
801 #define kpf_copy_bit(flags, srcpos, dstpos) (((flags >> srcpos) & 1) << dstpos)
802
803 static ssize_t kpageflags_read(struct file *file, char __user *buf,
804 size_t count, loff_t *ppos)
805 {
806 u64 __user *out = (u64 __user *)buf;
807 struct page *ppage;
808 unsigned long src = *ppos;
809 unsigned long pfn;
810 ssize_t ret = 0;
811 u64 kflags, uflags;
812
813 pfn = src / KPMSIZE;
814 count = min_t(unsigned long, count, (max_pfn * KPMSIZE) - src);
815 if (src & KPMMASK || count & KPMMASK)
816 return -EINVAL;
817
818 while (count > 0) {
819 ppage = NULL;
820 if (pfn_valid(pfn))
821 ppage = pfn_to_page(pfn);
822 pfn++;
823 if (!ppage)
824 kflags = 0;
825 else
826 kflags = ppage->flags;
827
828 uflags = kpf_copy_bit(KPF_LOCKED, PG_locked, kflags) |
829 kpf_copy_bit(kflags, KPF_ERROR, PG_error) |
830 kpf_copy_bit(kflags, KPF_REFERENCED, PG_referenced) |
831 kpf_copy_bit(kflags, KPF_UPTODATE, PG_uptodate) |
832 kpf_copy_bit(kflags, KPF_DIRTY, PG_dirty) |
833 kpf_copy_bit(kflags, KPF_LRU, PG_lru) |
834 kpf_copy_bit(kflags, KPF_ACTIVE, PG_active) |
835 kpf_copy_bit(kflags, KPF_SLAB, PG_slab) |
836 kpf_copy_bit(kflags, KPF_WRITEBACK, PG_writeback) |
837 kpf_copy_bit(kflags, KPF_RECLAIM, PG_reclaim) |
838 kpf_copy_bit(kflags, KPF_BUDDY, PG_buddy);
839
840 if (put_user(uflags, out++)) {
841 ret = -EFAULT;
842 break;
843 }
844
845 count -= KPMSIZE;
846 }
847
848 *ppos += (char __user *)out - buf;
849 if (!ret)
850 ret = (char __user *)out - buf;
851 return ret;
852 }
853
854 static struct file_operations proc_kpageflags_operations = {
855 .llseek = mem_lseek,
856 .read = kpageflags_read,
857 };
858 #endif /* CONFIG_PROC_PAGE_MONITOR */
859
860 struct proc_dir_entry *proc_root_kcore;
861
862 void __init proc_misc_init(void)
863 {
864 static struct {
865 char *name;
866 int (*read_proc)(char*,char**,off_t,int,int*,void*);
867 } *p, simple_ones[] = {
868 {"loadavg", loadavg_read_proc},
869 {"uptime", uptime_read_proc},
870 {"meminfo", meminfo_read_proc},
871 {"version", version_read_proc},
872 #ifdef CONFIG_PROC_HARDWARE
873 {"hardware", hardware_read_proc},
874 #endif
875 #ifdef CONFIG_STRAM_PROC
876 {"stram", stram_read_proc},
877 #endif
878 {"filesystems", filesystems_read_proc},
879 {"cmdline", cmdline_read_proc},
880 {"execdomains", execdomains_read_proc},
881 {NULL,}
882 };
883 for (p = simple_ones; p->name; p++)
884 create_proc_read_entry(p->name, 0, NULL, p->read_proc, NULL);
885
886 proc_symlink("mounts", NULL, "self/mounts");
887
888 /* And now for trickier ones */
889 #ifdef CONFIG_PRINTK
890 proc_create("kmsg", S_IRUSR, NULL, &proc_kmsg_operations);
891 #endif
892 #ifdef CONFIG_FILE_LOCKING
893 proc_create("locks", 0, NULL, &proc_locks_operations);
894 #endif
895 proc_create("devices", 0, NULL, &proc_devinfo_operations);
896 proc_create("cpuinfo", 0, NULL, &proc_cpuinfo_operations);
897 #ifdef CONFIG_BLOCK
898 proc_create("partitions", 0, NULL, &proc_partitions_operations);
899 #endif
900 proc_create("stat", 0, NULL, &proc_stat_operations);
901 proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
902 #ifdef CONFIG_SLABINFO
903 proc_create("slabinfo",S_IWUSR|S_IRUGO,NULL,&proc_slabinfo_operations);
904 #ifdef CONFIG_DEBUG_SLAB_LEAK
905 proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
906 #endif
907 #endif
908 #ifdef CONFIG_MMU
909 proc_create("vmallocinfo", S_IRUSR, NULL, &proc_vmalloc_operations);
910 #endif
911 proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
912 proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
913 proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
914 proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
915 #ifdef CONFIG_BLOCK
916 proc_create("diskstats", 0, NULL, &proc_diskstats_operations);
917 #endif
918 #ifdef CONFIG_MODULES
919 proc_create("modules", 0, NULL, &proc_modules_operations);
920 #endif
921 #ifdef CONFIG_SCHEDSTATS
922 proc_create("schedstat", 0, NULL, &proc_schedstat_operations);
923 #endif
924 #ifdef CONFIG_PROC_KCORE
925 proc_root_kcore = proc_create("kcore", S_IRUSR, NULL, &proc_kcore_operations);
926 if (proc_root_kcore)
927 proc_root_kcore->size =
928 (size_t)high_memory - PAGE_OFFSET + PAGE_SIZE;
929 #endif
930 #ifdef CONFIG_PROC_PAGE_MONITOR
931 proc_create("kpagecount", S_IRUSR, NULL, &proc_kpagecount_operations);
932 proc_create("kpageflags", S_IRUSR, NULL, &proc_kpageflags_operations);
933 #endif
934 #ifdef CONFIG_PROC_VMCORE
935 proc_vmcore = proc_create("vmcore", S_IRUSR, NULL, &proc_vmcore_operations);
936 #endif
937 #ifdef CONFIG_MAGIC_SYSRQ
938 proc_create("sysrq-trigger", S_IWUSR, NULL, &proc_sysrq_trigger_operations);
939 #endif
940 }
This page took 0.047883 seconds and 4 git commands to generate.