proc: switch /proc/loadavg to seq_file
[linux-2.6/verdex.git] / fs / proc / proc_misc.c
blobff42206c8aed297b816a17f8c177688ea97f05c0
1 /*
2 * linux/fs/proc/proc_misc.c
4 * linux/fs/proc/array.c
5 * Copyright (C) 1992 by Linus Torvalds
6 * based on ideas by Darren Senn
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.
13 * Changes:
14 * Fulton Green : Encapsulated position metric calculations.
15 * <kernel@FultonGreen.com>
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/irq.h>
34 #include <linux/interrupt.h>
35 #include <linux/swap.h>
36 #include <linux/slab.h>
37 #include <linux/genhd.h>
38 #include <linux/smp.h>
39 #include <linux/signal.h>
40 #include <linux/module.h>
41 #include <linux/init.h>
42 #include <linux/seq_file.h>
43 #include <linux/times.h>
44 #include <linux/profile.h>
45 #include <linux/utsname.h>
46 #include <linux/blkdev.h>
47 #include <linux/hugetlb.h>
48 #include <linux/jiffies.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"
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.
66 extern int get_hardware_list(char *);
67 extern int get_stram_list(char *);
68 extern int get_exec_domain_list(char *);
70 static int proc_calc_metrics(char *page, char **start, off_t off,
71 int count, int *eof, int len)
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;
81 static int uptime_read_proc(char *page, char **start, off_t off,
82 int count, int *eof, void *data)
84 struct timespec uptime;
85 struct timespec idle;
86 int len;
87 cputime_t idletime = cputime_add(init_task.utime, init_task.stime);
89 do_posix_clock_monotonic_gettime(&uptime);
90 monotonic_to_bootbased(&uptime);
91 cputime_to_timespec(idletime, &idle);
92 len = sprintf(page,"%lu.%02lu %lu.%02lu\n",
93 (unsigned long) uptime.tv_sec,
94 (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
95 (unsigned long) idle.tv_sec,
96 (idle.tv_nsec / (NSEC_PER_SEC / 100)));
98 return proc_calc_metrics(page, start, off, count, eof, len);
101 int __attribute__((weak)) arch_report_meminfo(char *page)
103 return 0;
106 static int meminfo_read_proc(char *page, char **start, off_t off,
107 int count, int *eof, void *data)
109 struct sysinfo i;
110 int len;
111 unsigned long committed;
112 unsigned long allowed;
113 struct vmalloc_info vmi;
114 long cached;
115 unsigned long pages[NR_LRU_LISTS];
116 int lru;
119 * display in kilobytes.
121 #define K(x) ((x) << (PAGE_SHIFT - 10))
122 si_meminfo(&i);
123 si_swapinfo(&i);
124 committed = atomic_long_read(&vm_committed_space);
125 allowed = ((totalram_pages - hugetlb_total_pages())
126 * sysctl_overcommit_ratio / 100) + total_swap_pages;
128 cached = global_page_state(NR_FILE_PAGES) -
129 total_swapcache_pages - i.bufferram;
130 if (cached < 0)
131 cached = 0;
133 get_vmalloc_info(&vmi);
135 for (lru = LRU_BASE; lru < NR_LRU_LISTS; lru++)
136 pages[lru] = global_page_state(NR_LRU_BASE + lru);
139 * Tagged format, for easy grepping and expansion.
141 len = sprintf(page,
142 "MemTotal: %8lu kB\n"
143 "MemFree: %8lu kB\n"
144 "Buffers: %8lu kB\n"
145 "Cached: %8lu kB\n"
146 "SwapCached: %8lu kB\n"
147 "Active: %8lu kB\n"
148 "Inactive: %8lu kB\n"
149 "Active(anon): %8lu kB\n"
150 "Inactive(anon): %8lu kB\n"
151 "Active(file): %8lu kB\n"
152 "Inactive(file): %8lu kB\n"
153 #ifdef CONFIG_UNEVICTABLE_LRU
154 "Unevictable: %8lu kB\n"
155 "Mlocked: %8lu kB\n"
156 #endif
157 #ifdef CONFIG_HIGHMEM
158 "HighTotal: %8lu kB\n"
159 "HighFree: %8lu kB\n"
160 "LowTotal: %8lu kB\n"
161 "LowFree: %8lu kB\n"
162 #endif
163 "SwapTotal: %8lu kB\n"
164 "SwapFree: %8lu kB\n"
165 "Dirty: %8lu kB\n"
166 "Writeback: %8lu kB\n"
167 "AnonPages: %8lu kB\n"
168 "Mapped: %8lu kB\n"
169 "Slab: %8lu kB\n"
170 "SReclaimable: %8lu kB\n"
171 "SUnreclaim: %8lu kB\n"
172 "PageTables: %8lu kB\n"
173 #ifdef CONFIG_QUICKLIST
174 "Quicklists: %8lu kB\n"
175 #endif
176 "NFS_Unstable: %8lu kB\n"
177 "Bounce: %8lu kB\n"
178 "WritebackTmp: %8lu kB\n"
179 "CommitLimit: %8lu kB\n"
180 "Committed_AS: %8lu kB\n"
181 "VmallocTotal: %8lu kB\n"
182 "VmallocUsed: %8lu kB\n"
183 "VmallocChunk: %8lu kB\n",
184 K(i.totalram),
185 K(i.freeram),
186 K(i.bufferram),
187 K(cached),
188 K(total_swapcache_pages),
189 K(pages[LRU_ACTIVE_ANON] + pages[LRU_ACTIVE_FILE]),
190 K(pages[LRU_INACTIVE_ANON] + pages[LRU_INACTIVE_FILE]),
191 K(pages[LRU_ACTIVE_ANON]),
192 K(pages[LRU_INACTIVE_ANON]),
193 K(pages[LRU_ACTIVE_FILE]),
194 K(pages[LRU_INACTIVE_FILE]),
195 #ifdef CONFIG_UNEVICTABLE_LRU
196 K(pages[LRU_UNEVICTABLE]),
197 K(global_page_state(NR_MLOCK)),
198 #endif
199 #ifdef CONFIG_HIGHMEM
200 K(i.totalhigh),
201 K(i.freehigh),
202 K(i.totalram-i.totalhigh),
203 K(i.freeram-i.freehigh),
204 #endif
205 K(i.totalswap),
206 K(i.freeswap),
207 K(global_page_state(NR_FILE_DIRTY)),
208 K(global_page_state(NR_WRITEBACK)),
209 K(global_page_state(NR_ANON_PAGES)),
210 K(global_page_state(NR_FILE_MAPPED)),
211 K(global_page_state(NR_SLAB_RECLAIMABLE) +
212 global_page_state(NR_SLAB_UNRECLAIMABLE)),
213 K(global_page_state(NR_SLAB_RECLAIMABLE)),
214 K(global_page_state(NR_SLAB_UNRECLAIMABLE)),
215 K(global_page_state(NR_PAGETABLE)),
216 #ifdef CONFIG_QUICKLIST
217 K(quicklist_total_size()),
218 #endif
219 K(global_page_state(NR_UNSTABLE_NFS)),
220 K(global_page_state(NR_BOUNCE)),
221 K(global_page_state(NR_WRITEBACK_TEMP)),
222 K(allowed),
223 K(committed),
224 (unsigned long)VMALLOC_TOTAL >> 10,
225 vmi.used >> 10,
226 vmi.largest_chunk >> 10
229 len += hugetlb_report_meminfo(page + len);
231 len += arch_report_meminfo(page + len);
233 return proc_calc_metrics(page, start, off, count, eof, len);
234 #undef K
237 static int fragmentation_open(struct inode *inode, struct file *file)
239 (void)inode;
240 return seq_open(file, &fragmentation_op);
243 static const struct file_operations fragmentation_file_operations = {
244 .open = fragmentation_open,
245 .read = seq_read,
246 .llseek = seq_lseek,
247 .release = seq_release,
250 static int pagetypeinfo_open(struct inode *inode, struct file *file)
252 return seq_open(file, &pagetypeinfo_op);
255 static const struct file_operations pagetypeinfo_file_ops = {
256 .open = pagetypeinfo_open,
257 .read = seq_read,
258 .llseek = seq_lseek,
259 .release = seq_release,
262 static int zoneinfo_open(struct inode *inode, struct file *file)
264 return seq_open(file, &zoneinfo_op);
267 static const struct file_operations proc_zoneinfo_file_operations = {
268 .open = zoneinfo_open,
269 .read = seq_read,
270 .llseek = seq_lseek,
271 .release = seq_release,
274 static int version_read_proc(char *page, char **start, off_t off,
275 int count, int *eof, void *data)
277 int len;
279 len = snprintf(page, PAGE_SIZE, linux_proc_banner,
280 utsname()->sysname,
281 utsname()->release,
282 utsname()->version);
283 return proc_calc_metrics(page, start, off, count, eof, len);
286 extern const struct seq_operations cpuinfo_op;
287 static int cpuinfo_open(struct inode *inode, struct file *file)
289 return seq_open(file, &cpuinfo_op);
292 static const struct file_operations proc_cpuinfo_operations = {
293 .open = cpuinfo_open,
294 .read = seq_read,
295 .llseek = seq_lseek,
296 .release = seq_release,
299 static int devinfo_show(struct seq_file *f, void *v)
301 int i = *(loff_t *) v;
303 if (i < CHRDEV_MAJOR_HASH_SIZE) {
304 if (i == 0)
305 seq_printf(f, "Character devices:\n");
306 chrdev_show(f, i);
308 #ifdef CONFIG_BLOCK
309 else {
310 i -= CHRDEV_MAJOR_HASH_SIZE;
311 if (i == 0)
312 seq_printf(f, "\nBlock devices:\n");
313 blkdev_show(f, i);
315 #endif
316 return 0;
319 static void *devinfo_start(struct seq_file *f, loff_t *pos)
321 if (*pos < (BLKDEV_MAJOR_HASH_SIZE + CHRDEV_MAJOR_HASH_SIZE))
322 return pos;
323 return NULL;
326 static void *devinfo_next(struct seq_file *f, void *v, loff_t *pos)
328 (*pos)++;
329 if (*pos >= (BLKDEV_MAJOR_HASH_SIZE + CHRDEV_MAJOR_HASH_SIZE))
330 return NULL;
331 return pos;
334 static void devinfo_stop(struct seq_file *f, void *v)
336 /* Nothing to do */
339 static const struct seq_operations devinfo_ops = {
340 .start = devinfo_start,
341 .next = devinfo_next,
342 .stop = devinfo_stop,
343 .show = devinfo_show
346 static int devinfo_open(struct inode *inode, struct file *filp)
348 return seq_open(filp, &devinfo_ops);
351 static const struct file_operations proc_devinfo_operations = {
352 .open = devinfo_open,
353 .read = seq_read,
354 .llseek = seq_lseek,
355 .release = seq_release,
358 static int vmstat_open(struct inode *inode, struct file *file)
360 return seq_open(file, &vmstat_op);
362 static const struct file_operations proc_vmstat_file_operations = {
363 .open = vmstat_open,
364 .read = seq_read,
365 .llseek = seq_lseek,
366 .release = seq_release,
369 #ifdef CONFIG_PROC_HARDWARE
370 static int hardware_read_proc(char *page, char **start, off_t off,
371 int count, int *eof, void *data)
373 int len = get_hardware_list(page);
374 return proc_calc_metrics(page, start, off, count, eof, len);
376 #endif
378 #ifdef CONFIG_STRAM_PROC
379 static int stram_read_proc(char *page, char **start, off_t off,
380 int count, int *eof, void *data)
382 int len = get_stram_list(page);
383 return proc_calc_metrics(page, start, off, count, eof, len);
385 #endif
387 #ifdef CONFIG_BLOCK
388 static int partitions_open(struct inode *inode, struct file *file)
390 return seq_open(file, &partitions_op);
392 static const struct file_operations proc_partitions_operations = {
393 .open = partitions_open,
394 .read = seq_read,
395 .llseek = seq_lseek,
396 .release = seq_release,
399 static int diskstats_open(struct inode *inode, struct file *file)
401 return seq_open(file, &diskstats_op);
403 static const struct file_operations proc_diskstats_operations = {
404 .open = diskstats_open,
405 .read = seq_read,
406 .llseek = seq_lseek,
407 .release = seq_release,
409 #endif
411 #ifdef CONFIG_MODULES
412 extern const struct seq_operations modules_op;
413 static int modules_open(struct inode *inode, struct file *file)
415 return seq_open(file, &modules_op);
417 static const struct file_operations proc_modules_operations = {
418 .open = modules_open,
419 .read = seq_read,
420 .llseek = seq_lseek,
421 .release = seq_release,
423 #endif
425 #ifdef CONFIG_SLABINFO
426 static int slabinfo_open(struct inode *inode, struct file *file)
428 return seq_open(file, &slabinfo_op);
430 static const struct file_operations proc_slabinfo_operations = {
431 .open = slabinfo_open,
432 .read = seq_read,
433 .write = slabinfo_write,
434 .llseek = seq_lseek,
435 .release = seq_release,
438 #ifdef CONFIG_DEBUG_SLAB_LEAK
439 extern const struct seq_operations slabstats_op;
440 static int slabstats_open(struct inode *inode, struct file *file)
442 unsigned long *n = kzalloc(PAGE_SIZE, GFP_KERNEL);
443 int ret = -ENOMEM;
444 if (n) {
445 ret = seq_open(file, &slabstats_op);
446 if (!ret) {
447 struct seq_file *m = file->private_data;
448 *n = PAGE_SIZE / (2 * sizeof(unsigned long));
449 m->private = n;
450 n = NULL;
452 kfree(n);
454 return ret;
457 static const struct file_operations proc_slabstats_operations = {
458 .open = slabstats_open,
459 .read = seq_read,
460 .llseek = seq_lseek,
461 .release = seq_release_private,
463 #endif
464 #endif
466 #ifdef CONFIG_MMU
467 static int vmalloc_open(struct inode *inode, struct file *file)
469 unsigned int *ptr = NULL;
470 int ret;
472 if (NUMA_BUILD)
473 ptr = kmalloc(nr_node_ids * sizeof(unsigned int), GFP_KERNEL);
474 ret = seq_open(file, &vmalloc_op);
475 if (!ret) {
476 struct seq_file *m = file->private_data;
477 m->private = ptr;
478 } else
479 kfree(ptr);
480 return ret;
483 static const struct file_operations proc_vmalloc_operations = {
484 .open = vmalloc_open,
485 .read = seq_read,
486 .llseek = seq_lseek,
487 .release = seq_release_private,
489 #endif
491 #ifndef arch_irq_stat_cpu
492 #define arch_irq_stat_cpu(cpu) 0
493 #endif
494 #ifndef arch_irq_stat
495 #define arch_irq_stat() 0
496 #endif
498 static int show_stat(struct seq_file *p, void *v)
500 int i, j;
501 unsigned long jif;
502 cputime64_t user, nice, system, idle, iowait, irq, softirq, steal;
503 cputime64_t guest;
504 u64 sum = 0;
505 struct timespec boottime;
506 unsigned int per_irq_sum;
508 user = nice = system = idle = iowait =
509 irq = softirq = steal = cputime64_zero;
510 guest = cputime64_zero;
511 getboottime(&boottime);
512 jif = boottime.tv_sec;
514 for_each_possible_cpu(i) {
515 user = cputime64_add(user, kstat_cpu(i).cpustat.user);
516 nice = cputime64_add(nice, kstat_cpu(i).cpustat.nice);
517 system = cputime64_add(system, kstat_cpu(i).cpustat.system);
518 idle = cputime64_add(idle, kstat_cpu(i).cpustat.idle);
519 iowait = cputime64_add(iowait, kstat_cpu(i).cpustat.iowait);
520 irq = cputime64_add(irq, kstat_cpu(i).cpustat.irq);
521 softirq = cputime64_add(softirq, kstat_cpu(i).cpustat.softirq);
522 steal = cputime64_add(steal, kstat_cpu(i).cpustat.steal);
523 guest = cputime64_add(guest, kstat_cpu(i).cpustat.guest);
525 for_each_irq_nr(j)
526 sum += kstat_irqs_cpu(j, i);
528 sum += arch_irq_stat_cpu(i);
530 sum += arch_irq_stat();
532 seq_printf(p, "cpu %llu %llu %llu %llu %llu %llu %llu %llu %llu\n",
533 (unsigned long long)cputime64_to_clock_t(user),
534 (unsigned long long)cputime64_to_clock_t(nice),
535 (unsigned long long)cputime64_to_clock_t(system),
536 (unsigned long long)cputime64_to_clock_t(idle),
537 (unsigned long long)cputime64_to_clock_t(iowait),
538 (unsigned long long)cputime64_to_clock_t(irq),
539 (unsigned long long)cputime64_to_clock_t(softirq),
540 (unsigned long long)cputime64_to_clock_t(steal),
541 (unsigned long long)cputime64_to_clock_t(guest));
542 for_each_online_cpu(i) {
544 /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
545 user = kstat_cpu(i).cpustat.user;
546 nice = kstat_cpu(i).cpustat.nice;
547 system = kstat_cpu(i).cpustat.system;
548 idle = kstat_cpu(i).cpustat.idle;
549 iowait = kstat_cpu(i).cpustat.iowait;
550 irq = kstat_cpu(i).cpustat.irq;
551 softirq = kstat_cpu(i).cpustat.softirq;
552 steal = kstat_cpu(i).cpustat.steal;
553 guest = kstat_cpu(i).cpustat.guest;
554 seq_printf(p,
555 "cpu%d %llu %llu %llu %llu %llu %llu %llu %llu %llu\n",
557 (unsigned long long)cputime64_to_clock_t(user),
558 (unsigned long long)cputime64_to_clock_t(nice),
559 (unsigned long long)cputime64_to_clock_t(system),
560 (unsigned long long)cputime64_to_clock_t(idle),
561 (unsigned long long)cputime64_to_clock_t(iowait),
562 (unsigned long long)cputime64_to_clock_t(irq),
563 (unsigned long long)cputime64_to_clock_t(softirq),
564 (unsigned long long)cputime64_to_clock_t(steal),
565 (unsigned long long)cputime64_to_clock_t(guest));
567 seq_printf(p, "intr %llu", (unsigned long long)sum);
569 /* sum again ? it could be updated? */
570 for_each_irq_nr(j) {
571 per_irq_sum = 0;
573 for_each_possible_cpu(i)
574 per_irq_sum += kstat_irqs_cpu(j, i);
576 seq_printf(p, " %u", per_irq_sum);
579 seq_printf(p,
580 "\nctxt %llu\n"
581 "btime %lu\n"
582 "processes %lu\n"
583 "procs_running %lu\n"
584 "procs_blocked %lu\n",
585 nr_context_switches(),
586 (unsigned long)jif,
587 total_forks,
588 nr_running(),
589 nr_iowait());
591 return 0;
594 static int stat_open(struct inode *inode, struct file *file)
596 unsigned size = 4096 * (1 + num_possible_cpus() / 32);
597 char *buf;
598 struct seq_file *m;
599 int res;
601 /* don't ask for more than the kmalloc() max size, currently 128 KB */
602 if (size > 128 * 1024)
603 size = 128 * 1024;
604 buf = kmalloc(size, GFP_KERNEL);
605 if (!buf)
606 return -ENOMEM;
608 res = single_open(file, show_stat, NULL);
609 if (!res) {
610 m = file->private_data;
611 m->buf = buf;
612 m->size = size;
613 } else
614 kfree(buf);
615 return res;
617 static const struct file_operations proc_stat_operations = {
618 .open = stat_open,
619 .read = seq_read,
620 .llseek = seq_lseek,
621 .release = single_release,
625 * /proc/interrupts
627 static void *int_seq_start(struct seq_file *f, loff_t *pos)
629 return (*pos <= nr_irqs) ? pos : NULL;
633 static void *int_seq_next(struct seq_file *f, void *v, loff_t *pos)
635 (*pos)++;
636 return (*pos <= nr_irqs) ? pos : NULL;
639 static void int_seq_stop(struct seq_file *f, void *v)
641 /* Nothing to do */
644 static const struct seq_operations int_seq_ops = {
645 .start = int_seq_start,
646 .next = int_seq_next,
647 .stop = int_seq_stop,
648 .show = show_interrupts
651 static int interrupts_open(struct inode *inode, struct file *filp)
653 return seq_open(filp, &int_seq_ops);
656 static const struct file_operations proc_interrupts_operations = {
657 .open = interrupts_open,
658 .read = seq_read,
659 .llseek = seq_lseek,
660 .release = seq_release,
663 static int filesystems_read_proc(char *page, char **start, off_t off,
664 int count, int *eof, void *data)
666 int len = get_filesystem_list(page);
667 return proc_calc_metrics(page, start, off, count, eof, len);
670 static int cmdline_read_proc(char *page, char **start, off_t off,
671 int count, int *eof, void *data)
673 int len;
675 len = sprintf(page, "%s\n", saved_command_line);
676 return proc_calc_metrics(page, start, off, count, eof, len);
679 #ifdef CONFIG_FILE_LOCKING
680 static int locks_open(struct inode *inode, struct file *filp)
682 return seq_open(filp, &locks_seq_operations);
685 static const struct file_operations proc_locks_operations = {
686 .open = locks_open,
687 .read = seq_read,
688 .llseek = seq_lseek,
689 .release = seq_release,
691 #endif /* CONFIG_FILE_LOCKING */
693 static int execdomains_read_proc(char *page, char **start, off_t off,
694 int count, int *eof, void *data)
696 int len = get_exec_domain_list(page);
697 return proc_calc_metrics(page, start, off, count, eof, len);
700 #ifdef CONFIG_PROC_PAGE_MONITOR
701 #define KPMSIZE sizeof(u64)
702 #define KPMMASK (KPMSIZE - 1)
703 /* /proc/kpagecount - an array exposing page counts
705 * Each entry is a u64 representing the corresponding
706 * physical page count.
708 static ssize_t kpagecount_read(struct file *file, char __user *buf,
709 size_t count, loff_t *ppos)
711 u64 __user *out = (u64 __user *)buf;
712 struct page *ppage;
713 unsigned long src = *ppos;
714 unsigned long pfn;
715 ssize_t ret = 0;
716 u64 pcount;
718 pfn = src / KPMSIZE;
719 count = min_t(size_t, count, (max_pfn * KPMSIZE) - src);
720 if (src & KPMMASK || count & KPMMASK)
721 return -EINVAL;
723 while (count > 0) {
724 ppage = NULL;
725 if (pfn_valid(pfn))
726 ppage = pfn_to_page(pfn);
727 pfn++;
728 if (!ppage)
729 pcount = 0;
730 else
731 pcount = page_mapcount(ppage);
733 if (put_user(pcount, out++)) {
734 ret = -EFAULT;
735 break;
738 count -= KPMSIZE;
741 *ppos += (char __user *)out - buf;
742 if (!ret)
743 ret = (char __user *)out - buf;
744 return ret;
747 static struct file_operations proc_kpagecount_operations = {
748 .llseek = mem_lseek,
749 .read = kpagecount_read,
752 /* /proc/kpageflags - an array exposing page flags
754 * Each entry is a u64 representing the corresponding
755 * physical page flags.
758 /* These macros are used to decouple internal flags from exported ones */
760 #define KPF_LOCKED 0
761 #define KPF_ERROR 1
762 #define KPF_REFERENCED 2
763 #define KPF_UPTODATE 3
764 #define KPF_DIRTY 4
765 #define KPF_LRU 5
766 #define KPF_ACTIVE 6
767 #define KPF_SLAB 7
768 #define KPF_WRITEBACK 8
769 #define KPF_RECLAIM 9
770 #define KPF_BUDDY 10
772 #define kpf_copy_bit(flags, srcpos, dstpos) (((flags >> srcpos) & 1) << dstpos)
774 static ssize_t kpageflags_read(struct file *file, char __user *buf,
775 size_t count, loff_t *ppos)
777 u64 __user *out = (u64 __user *)buf;
778 struct page *ppage;
779 unsigned long src = *ppos;
780 unsigned long pfn;
781 ssize_t ret = 0;
782 u64 kflags, uflags;
784 pfn = src / KPMSIZE;
785 count = min_t(unsigned long, count, (max_pfn * KPMSIZE) - src);
786 if (src & KPMMASK || count & KPMMASK)
787 return -EINVAL;
789 while (count > 0) {
790 ppage = NULL;
791 if (pfn_valid(pfn))
792 ppage = pfn_to_page(pfn);
793 pfn++;
794 if (!ppage)
795 kflags = 0;
796 else
797 kflags = ppage->flags;
799 uflags = kpf_copy_bit(KPF_LOCKED, PG_locked, kflags) |
800 kpf_copy_bit(kflags, KPF_ERROR, PG_error) |
801 kpf_copy_bit(kflags, KPF_REFERENCED, PG_referenced) |
802 kpf_copy_bit(kflags, KPF_UPTODATE, PG_uptodate) |
803 kpf_copy_bit(kflags, KPF_DIRTY, PG_dirty) |
804 kpf_copy_bit(kflags, KPF_LRU, PG_lru) |
805 kpf_copy_bit(kflags, KPF_ACTIVE, PG_active) |
806 kpf_copy_bit(kflags, KPF_SLAB, PG_slab) |
807 kpf_copy_bit(kflags, KPF_WRITEBACK, PG_writeback) |
808 kpf_copy_bit(kflags, KPF_RECLAIM, PG_reclaim) |
809 kpf_copy_bit(kflags, KPF_BUDDY, PG_buddy);
811 if (put_user(uflags, out++)) {
812 ret = -EFAULT;
813 break;
816 count -= KPMSIZE;
819 *ppos += (char __user *)out - buf;
820 if (!ret)
821 ret = (char __user *)out - buf;
822 return ret;
825 static struct file_operations proc_kpageflags_operations = {
826 .llseek = mem_lseek,
827 .read = kpageflags_read,
829 #endif /* CONFIG_PROC_PAGE_MONITOR */
831 struct proc_dir_entry *proc_root_kcore;
833 void __init proc_misc_init(void)
835 static struct {
836 char *name;
837 int (*read_proc)(char*,char**,off_t,int,int*,void*);
838 } *p, simple_ones[] = {
839 {"uptime", uptime_read_proc},
840 {"meminfo", meminfo_read_proc},
841 {"version", version_read_proc},
842 #ifdef CONFIG_PROC_HARDWARE
843 {"hardware", hardware_read_proc},
844 #endif
845 #ifdef CONFIG_STRAM_PROC
846 {"stram", stram_read_proc},
847 #endif
848 {"filesystems", filesystems_read_proc},
849 {"cmdline", cmdline_read_proc},
850 {"execdomains", execdomains_read_proc},
851 {NULL,}
853 for (p = simple_ones; p->name; p++)
854 create_proc_read_entry(p->name, 0, NULL, p->read_proc, NULL);
856 proc_symlink("mounts", NULL, "self/mounts");
858 /* And now for trickier ones */
859 #ifdef CONFIG_PRINTK
860 proc_create("kmsg", S_IRUSR, NULL, &proc_kmsg_operations);
861 #endif
862 #ifdef CONFIG_FILE_LOCKING
863 proc_create("locks", 0, NULL, &proc_locks_operations);
864 #endif
865 proc_create("devices", 0, NULL, &proc_devinfo_operations);
866 proc_create("cpuinfo", 0, NULL, &proc_cpuinfo_operations);
867 #ifdef CONFIG_BLOCK
868 proc_create("partitions", 0, NULL, &proc_partitions_operations);
869 #endif
870 proc_create("stat", 0, NULL, &proc_stat_operations);
871 proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
872 #ifdef CONFIG_SLABINFO
873 proc_create("slabinfo",S_IWUSR|S_IRUGO,NULL,&proc_slabinfo_operations);
874 #ifdef CONFIG_DEBUG_SLAB_LEAK
875 proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
876 #endif
877 #endif
878 #ifdef CONFIG_MMU
879 proc_create("vmallocinfo", S_IRUSR, NULL, &proc_vmalloc_operations);
880 #endif
881 proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
882 proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
883 proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
884 proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
885 #ifdef CONFIG_BLOCK
886 proc_create("diskstats", 0, NULL, &proc_diskstats_operations);
887 #endif
888 #ifdef CONFIG_MODULES
889 proc_create("modules", 0, NULL, &proc_modules_operations);
890 #endif
891 #ifdef CONFIG_SCHEDSTATS
892 proc_create("schedstat", 0, NULL, &proc_schedstat_operations);
893 #endif
894 #ifdef CONFIG_PROC_KCORE
895 proc_root_kcore = proc_create("kcore", S_IRUSR, NULL, &proc_kcore_operations);
896 if (proc_root_kcore)
897 proc_root_kcore->size =
898 (size_t)high_memory - PAGE_OFFSET + PAGE_SIZE;
899 #endif
900 #ifdef CONFIG_PROC_PAGE_MONITOR
901 proc_create("kpagecount", S_IRUSR, NULL, &proc_kpagecount_operations);
902 proc_create("kpageflags", S_IRUSR, NULL, &proc_kpageflags_operations);
903 #endif
904 #ifdef CONFIG_PROC_VMCORE
905 proc_vmcore = proc_create("vmcore", S_IRUSR, NULL, &proc_vmcore_operations);
906 #endif