Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[wrt350n-kernel.git] / fs / proc / proc_misc.c
blob669dc54d93433d40a08a990a02696acbe4129fbf
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/proc_fs.h>
28 #include <linux/ioport.h>
29 #include <linux/mm.h>
30 #include <linux/mmzone.h>
31 #include <linux/pagemap.h>
32 #include <linux/interrupt.h>
33 #include <linux/swap.h>
34 #include <linux/slab.h>
35 <<<<<<< HEAD:fs/proc/proc_misc.c
36 =======
37 #include <linux/genhd.h>
38 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:fs/proc/proc_misc.c
39 #include <linux/smp.h>
40 #include <linux/signal.h>
41 #include <linux/module.h>
42 #include <linux/init.h>
43 #include <linux/seq_file.h>
44 #include <linux/times.h>
45 #include <linux/profile.h>
46 #include <linux/utsname.h>
47 #include <linux/blkdev.h>
48 #include <linux/hugetlb.h>
49 #include <linux/jiffies.h>
50 #include <linux/sysrq.h>
51 #include <linux/vmalloc.h>
52 #include <linux/crash_dump.h>
53 #include <linux/pid_namespace.h>
54 #include <linux/bootmem.h>
55 #include <asm/uaccess.h>
56 #include <asm/pgtable.h>
57 #include <asm/io.h>
58 #include <asm/tlb.h>
59 #include <asm/div64.h>
60 #include "internal.h"
62 #define LOAD_INT(x) ((x) >> FSHIFT)
63 #define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100)
65 * Warning: stuff below (imported functions) assumes that its output will fit
66 * into one page. For some of those functions it may be wrong. Moreover, we
67 * have a way to deal with that gracefully. Right now I used straightforward
68 * wrappers, but this needs further analysis wrt potential overflows.
70 extern int get_hardware_list(char *);
71 extern int get_stram_list(char *);
72 extern int get_exec_domain_list(char *);
73 extern int get_dma_list(char *);
75 static int proc_calc_metrics(char *page, char **start, off_t off,
76 int count, int *eof, int len)
78 if (len <= off+count) *eof = 1;
79 *start = page + off;
80 len -= off;
81 if (len>count) len = count;
82 if (len<0) len = 0;
83 return len;
86 static int loadavg_read_proc(char *page, char **start, off_t off,
87 int count, int *eof, void *data)
89 int a, b, c;
90 int len;
91 unsigned long seq;
93 do {
94 seq = read_seqbegin(&xtime_lock);
95 a = avenrun[0] + (FIXED_1/200);
96 b = avenrun[1] + (FIXED_1/200);
97 c = avenrun[2] + (FIXED_1/200);
98 } while (read_seqretry(&xtime_lock, seq));
100 len = sprintf(page,"%d.%02d %d.%02d %d.%02d %ld/%d %d\n",
101 LOAD_INT(a), LOAD_FRAC(a),
102 LOAD_INT(b), LOAD_FRAC(b),
103 LOAD_INT(c), LOAD_FRAC(c),
104 nr_running(), nr_threads,
105 task_active_pid_ns(current)->last_pid);
106 return proc_calc_metrics(page, start, off, count, eof, len);
109 static int uptime_read_proc(char *page, char **start, off_t off,
110 int count, int *eof, void *data)
112 struct timespec uptime;
113 struct timespec idle;
114 int len;
115 cputime_t idletime = cputime_add(init_task.utime, init_task.stime);
117 do_posix_clock_monotonic_gettime(&uptime);
118 monotonic_to_bootbased(&uptime);
119 cputime_to_timespec(idletime, &idle);
120 len = sprintf(page,"%lu.%02lu %lu.%02lu\n",
121 (unsigned long) uptime.tv_sec,
122 (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
123 (unsigned long) idle.tv_sec,
124 (idle.tv_nsec / (NSEC_PER_SEC / 100)));
126 return proc_calc_metrics(page, start, off, count, eof, len);
129 static int meminfo_read_proc(char *page, char **start, off_t off,
130 int count, int *eof, void *data)
132 struct sysinfo i;
133 int len;
134 unsigned long committed;
135 unsigned long allowed;
136 struct vmalloc_info vmi;
137 long cached;
140 * display in kilobytes.
142 #define K(x) ((x) << (PAGE_SHIFT - 10))
143 si_meminfo(&i);
144 si_swapinfo(&i);
145 committed = atomic_read(&vm_committed_space);
146 allowed = ((totalram_pages - hugetlb_total_pages())
147 * sysctl_overcommit_ratio / 100) + total_swap_pages;
149 cached = global_page_state(NR_FILE_PAGES) -
150 total_swapcache_pages - i.bufferram;
151 if (cached < 0)
152 cached = 0;
154 get_vmalloc_info(&vmi);
157 * Tagged format, for easy grepping and expansion.
159 len = sprintf(page,
160 "MemTotal: %8lu kB\n"
161 "MemFree: %8lu kB\n"
162 "Buffers: %8lu kB\n"
163 "Cached: %8lu kB\n"
164 "SwapCached: %8lu kB\n"
165 "Active: %8lu kB\n"
166 "Inactive: %8lu kB\n"
167 #ifdef CONFIG_HIGHMEM
168 "HighTotal: %8lu kB\n"
169 "HighFree: %8lu kB\n"
170 "LowTotal: %8lu kB\n"
171 "LowFree: %8lu kB\n"
172 #endif
173 "SwapTotal: %8lu kB\n"
174 "SwapFree: %8lu kB\n"
175 "Dirty: %8lu kB\n"
176 "Writeback: %8lu kB\n"
177 "AnonPages: %8lu kB\n"
178 "Mapped: %8lu kB\n"
179 "Slab: %8lu kB\n"
180 "SReclaimable: %8lu kB\n"
181 "SUnreclaim: %8lu kB\n"
182 "PageTables: %8lu kB\n"
183 "NFS_Unstable: %8lu kB\n"
184 "Bounce: %8lu kB\n"
185 "CommitLimit: %8lu kB\n"
186 "Committed_AS: %8lu kB\n"
187 "VmallocTotal: %8lu kB\n"
188 "VmallocUsed: %8lu kB\n"
189 "VmallocChunk: %8lu kB\n",
190 K(i.totalram),
191 K(i.freeram),
192 K(i.bufferram),
193 K(cached),
194 K(total_swapcache_pages),
195 K(global_page_state(NR_ACTIVE)),
196 K(global_page_state(NR_INACTIVE)),
197 #ifdef CONFIG_HIGHMEM
198 K(i.totalhigh),
199 K(i.freehigh),
200 K(i.totalram-i.totalhigh),
201 K(i.freeram-i.freehigh),
202 #endif
203 K(i.totalswap),
204 K(i.freeswap),
205 K(global_page_state(NR_FILE_DIRTY)),
206 K(global_page_state(NR_WRITEBACK)),
207 K(global_page_state(NR_ANON_PAGES)),
208 K(global_page_state(NR_FILE_MAPPED)),
209 K(global_page_state(NR_SLAB_RECLAIMABLE) +
210 global_page_state(NR_SLAB_UNRECLAIMABLE)),
211 K(global_page_state(NR_SLAB_RECLAIMABLE)),
212 K(global_page_state(NR_SLAB_UNRECLAIMABLE)),
213 K(global_page_state(NR_PAGETABLE)),
214 K(global_page_state(NR_UNSTABLE_NFS)),
215 K(global_page_state(NR_BOUNCE)),
216 K(allowed),
217 K(committed),
218 (unsigned long)VMALLOC_TOTAL >> 10,
219 vmi.used >> 10,
220 vmi.largest_chunk >> 10
223 len += hugetlb_report_meminfo(page + len);
225 return proc_calc_metrics(page, start, off, count, eof, len);
226 #undef K
229 extern const struct seq_operations fragmentation_op;
230 static int fragmentation_open(struct inode *inode, struct file *file)
232 (void)inode;
233 return seq_open(file, &fragmentation_op);
236 static const struct file_operations fragmentation_file_operations = {
237 .open = fragmentation_open,
238 .read = seq_read,
239 .llseek = seq_lseek,
240 .release = seq_release,
243 extern const struct seq_operations pagetypeinfo_op;
244 static int pagetypeinfo_open(struct inode *inode, struct file *file)
246 return seq_open(file, &pagetypeinfo_op);
249 static const struct file_operations pagetypeinfo_file_ops = {
250 .open = pagetypeinfo_open,
251 .read = seq_read,
252 .llseek = seq_lseek,
253 .release = seq_release,
256 extern const struct seq_operations zoneinfo_op;
257 static int zoneinfo_open(struct inode *inode, struct file *file)
259 return seq_open(file, &zoneinfo_op);
262 static const struct file_operations proc_zoneinfo_file_operations = {
263 .open = zoneinfo_open,
264 .read = seq_read,
265 .llseek = seq_lseek,
266 .release = seq_release,
269 static int version_read_proc(char *page, char **start, off_t off,
270 int count, int *eof, void *data)
272 int len;
274 len = snprintf(page, PAGE_SIZE, linux_proc_banner,
275 utsname()->sysname,
276 utsname()->release,
277 utsname()->version);
278 return proc_calc_metrics(page, start, off, count, eof, len);
281 extern const struct seq_operations cpuinfo_op;
282 static int cpuinfo_open(struct inode *inode, struct file *file)
284 return seq_open(file, &cpuinfo_op);
287 static const struct file_operations proc_cpuinfo_operations = {
288 .open = cpuinfo_open,
289 .read = seq_read,
290 .llseek = seq_lseek,
291 .release = seq_release,
294 static int devinfo_show(struct seq_file *f, void *v)
296 int i = *(loff_t *) v;
298 if (i < CHRDEV_MAJOR_HASH_SIZE) {
299 if (i == 0)
300 seq_printf(f, "Character devices:\n");
301 chrdev_show(f, i);
303 #ifdef CONFIG_BLOCK
304 else {
305 i -= CHRDEV_MAJOR_HASH_SIZE;
306 if (i == 0)
307 seq_printf(f, "\nBlock devices:\n");
308 blkdev_show(f, i);
310 #endif
311 return 0;
314 static void *devinfo_start(struct seq_file *f, loff_t *pos)
316 if (*pos < (BLKDEV_MAJOR_HASH_SIZE + CHRDEV_MAJOR_HASH_SIZE))
317 return pos;
318 return NULL;
321 static void *devinfo_next(struct seq_file *f, void *v, loff_t *pos)
323 (*pos)++;
324 if (*pos >= (BLKDEV_MAJOR_HASH_SIZE + CHRDEV_MAJOR_HASH_SIZE))
325 return NULL;
326 return pos;
329 static void devinfo_stop(struct seq_file *f, void *v)
331 /* Nothing to do */
334 static const struct seq_operations devinfo_ops = {
335 .start = devinfo_start,
336 .next = devinfo_next,
337 .stop = devinfo_stop,
338 .show = devinfo_show
341 static int devinfo_open(struct inode *inode, struct file *filp)
343 return seq_open(filp, &devinfo_ops);
346 static const struct file_operations proc_devinfo_operations = {
347 .open = devinfo_open,
348 .read = seq_read,
349 .llseek = seq_lseek,
350 .release = seq_release,
353 extern const struct seq_operations vmstat_op;
354 static int vmstat_open(struct inode *inode, struct file *file)
356 return seq_open(file, &vmstat_op);
358 static const struct file_operations proc_vmstat_file_operations = {
359 .open = vmstat_open,
360 .read = seq_read,
361 .llseek = seq_lseek,
362 .release = seq_release,
365 #ifdef CONFIG_PROC_HARDWARE
366 static int hardware_read_proc(char *page, char **start, off_t off,
367 int count, int *eof, void *data)
369 int len = get_hardware_list(page);
370 return proc_calc_metrics(page, start, off, count, eof, len);
372 #endif
374 #ifdef CONFIG_STRAM_PROC
375 static int stram_read_proc(char *page, char **start, off_t off,
376 int count, int *eof, void *data)
378 int len = get_stram_list(page);
379 return proc_calc_metrics(page, start, off, count, eof, len);
381 #endif
383 #ifdef CONFIG_BLOCK
384 <<<<<<< HEAD:fs/proc/proc_misc.c
385 extern const struct seq_operations partitions_op;
386 =======
387 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:fs/proc/proc_misc.c
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 <<<<<<< HEAD:fs/proc/proc_misc.c
400 extern const struct seq_operations diskstats_op;
401 =======
402 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:fs/proc/proc_misc.c
403 static int diskstats_open(struct inode *inode, struct file *file)
405 return seq_open(file, &diskstats_op);
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,
413 #endif
415 #ifdef CONFIG_MODULES
416 extern const struct seq_operations modules_op;
417 static int modules_open(struct inode *inode, struct file *file)
419 return seq_open(file, &modules_op);
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,
427 #endif
429 #ifdef CONFIG_SLABINFO
430 static int slabinfo_open(struct inode *inode, struct file *file)
432 return seq_open(file, &slabinfo_op);
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,
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)
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;
456 kfree(n);
458 return ret;
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,
467 #endif
468 #endif
470 static int show_stat(struct seq_file *p, void *v)
472 int i;
473 unsigned long jif;
474 cputime64_t user, nice, system, idle, iowait, irq, softirq, steal;
475 cputime64_t guest;
476 u64 sum = 0;
477 struct timespec boottime;
478 unsigned int *per_irq_sum;
480 per_irq_sum = kzalloc(sizeof(unsigned int)*NR_IRQS, GFP_KERNEL);
481 if (!per_irq_sum)
482 return -ENOMEM;
484 user = nice = system = idle = iowait =
485 irq = softirq = steal = cputime64_zero;
486 guest = cputime64_zero;
487 getboottime(&boottime);
488 jif = boottime.tv_sec;
490 for_each_possible_cpu(i) {
491 int j;
493 user = cputime64_add(user, kstat_cpu(i).cpustat.user);
494 nice = cputime64_add(nice, kstat_cpu(i).cpustat.nice);
495 system = cputime64_add(system, kstat_cpu(i).cpustat.system);
496 idle = cputime64_add(idle, kstat_cpu(i).cpustat.idle);
497 iowait = cputime64_add(iowait, kstat_cpu(i).cpustat.iowait);
498 irq = cputime64_add(irq, kstat_cpu(i).cpustat.irq);
499 softirq = cputime64_add(softirq, kstat_cpu(i).cpustat.softirq);
500 steal = cputime64_add(steal, kstat_cpu(i).cpustat.steal);
501 guest = cputime64_add(guest, kstat_cpu(i).cpustat.guest);
502 for (j = 0; j < NR_IRQS; j++) {
503 unsigned int temp = kstat_cpu(i).irqs[j];
504 sum += temp;
505 per_irq_sum[j] += temp;
509 seq_printf(p, "cpu %llu %llu %llu %llu %llu %llu %llu %llu %llu\n",
510 (unsigned long long)cputime64_to_clock_t(user),
511 (unsigned long long)cputime64_to_clock_t(nice),
512 (unsigned long long)cputime64_to_clock_t(system),
513 (unsigned long long)cputime64_to_clock_t(idle),
514 (unsigned long long)cputime64_to_clock_t(iowait),
515 (unsigned long long)cputime64_to_clock_t(irq),
516 (unsigned long long)cputime64_to_clock_t(softirq),
517 (unsigned long long)cputime64_to_clock_t(steal),
518 (unsigned long long)cputime64_to_clock_t(guest));
519 for_each_online_cpu(i) {
521 /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
522 user = kstat_cpu(i).cpustat.user;
523 nice = kstat_cpu(i).cpustat.nice;
524 system = kstat_cpu(i).cpustat.system;
525 idle = kstat_cpu(i).cpustat.idle;
526 iowait = kstat_cpu(i).cpustat.iowait;
527 irq = kstat_cpu(i).cpustat.irq;
528 softirq = kstat_cpu(i).cpustat.softirq;
529 steal = kstat_cpu(i).cpustat.steal;
530 guest = kstat_cpu(i).cpustat.guest;
531 seq_printf(p,
532 "cpu%d %llu %llu %llu %llu %llu %llu %llu %llu %llu\n",
534 (unsigned long long)cputime64_to_clock_t(user),
535 (unsigned long long)cputime64_to_clock_t(nice),
536 (unsigned long long)cputime64_to_clock_t(system),
537 (unsigned long long)cputime64_to_clock_t(idle),
538 (unsigned long long)cputime64_to_clock_t(iowait),
539 (unsigned long long)cputime64_to_clock_t(irq),
540 (unsigned long long)cputime64_to_clock_t(softirq),
541 (unsigned long long)cputime64_to_clock_t(steal),
542 (unsigned long long)cputime64_to_clock_t(guest));
544 seq_printf(p, "intr %llu", (unsigned long long)sum);
546 for (i = 0; i < NR_IRQS; i++)
547 seq_printf(p, " %u", per_irq_sum[i]);
549 seq_printf(p,
550 "\nctxt %llu\n"
551 "btime %lu\n"
552 "processes %lu\n"
553 "procs_running %lu\n"
554 "procs_blocked %lu\n",
555 nr_context_switches(),
556 (unsigned long)jif,
557 total_forks,
558 nr_running(),
559 nr_iowait());
561 kfree(per_irq_sum);
562 return 0;
565 static int stat_open(struct inode *inode, struct file *file)
567 unsigned size = 4096 * (1 + num_possible_cpus() / 32);
568 char *buf;
569 struct seq_file *m;
570 int res;
572 /* don't ask for more than the kmalloc() max size, currently 128 KB */
573 if (size > 128 * 1024)
574 size = 128 * 1024;
575 buf = kmalloc(size, GFP_KERNEL);
576 if (!buf)
577 return -ENOMEM;
579 res = single_open(file, show_stat, NULL);
580 if (!res) {
581 m = file->private_data;
582 m->buf = buf;
583 m->size = size;
584 } else
585 kfree(buf);
586 return res;
588 static const struct file_operations proc_stat_operations = {
589 .open = stat_open,
590 .read = seq_read,
591 .llseek = seq_lseek,
592 .release = single_release,
596 * /proc/interrupts
598 static void *int_seq_start(struct seq_file *f, loff_t *pos)
600 return (*pos <= NR_IRQS) ? pos : NULL;
603 static void *int_seq_next(struct seq_file *f, void *v, loff_t *pos)
605 (*pos)++;
606 if (*pos > NR_IRQS)
607 return NULL;
608 return pos;
611 static void int_seq_stop(struct seq_file *f, void *v)
613 /* Nothing to do */
617 static const struct seq_operations int_seq_ops = {
618 .start = int_seq_start,
619 .next = int_seq_next,
620 .stop = int_seq_stop,
621 .show = show_interrupts
624 static int interrupts_open(struct inode *inode, struct file *filp)
626 return seq_open(filp, &int_seq_ops);
629 static const struct file_operations proc_interrupts_operations = {
630 .open = interrupts_open,
631 .read = seq_read,
632 .llseek = seq_lseek,
633 .release = seq_release,
636 static int filesystems_read_proc(char *page, char **start, off_t off,
637 int count, int *eof, void *data)
639 int len = get_filesystem_list(page);
640 return proc_calc_metrics(page, start, off, count, eof, len);
643 static int cmdline_read_proc(char *page, char **start, off_t off,
644 int count, int *eof, void *data)
646 int len;
648 len = sprintf(page, "%s\n", saved_command_line);
649 return proc_calc_metrics(page, start, off, count, eof, len);
652 static int locks_open(struct inode *inode, struct file *filp)
654 return seq_open(filp, &locks_seq_operations);
657 static const struct file_operations proc_locks_operations = {
658 .open = locks_open,
659 .read = seq_read,
660 .llseek = seq_lseek,
661 .release = seq_release,
664 static int execdomains_read_proc(char *page, char **start, off_t off,
665 int count, int *eof, void *data)
667 int len = get_exec_domain_list(page);
668 return proc_calc_metrics(page, start, off, count, eof, len);
671 #ifdef CONFIG_MAGIC_SYSRQ
673 * writing 'C' to /proc/sysrq-trigger is like sysrq-C
675 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
676 size_t count, loff_t *ppos)
678 if (count) {
679 char c;
681 if (get_user(c, buf))
682 return -EFAULT;
683 __handle_sysrq(c, NULL, 0);
685 return count;
688 static const struct file_operations proc_sysrq_trigger_operations = {
689 .write = write_sysrq_trigger,
691 #endif
693 #ifdef CONFIG_PROC_PAGE_MONITOR
694 #define KPMSIZE sizeof(u64)
695 #define KPMMASK (KPMSIZE - 1)
696 /* /proc/kpagecount - an array exposing page counts
698 * Each entry is a u64 representing the corresponding
699 * physical page count.
701 static ssize_t kpagecount_read(struct file *file, char __user *buf,
702 size_t count, loff_t *ppos)
704 u64 __user *out = (u64 __user *)buf;
705 struct page *ppage;
706 unsigned long src = *ppos;
707 unsigned long pfn;
708 ssize_t ret = 0;
709 u64 pcount;
711 pfn = src / KPMSIZE;
712 count = min_t(size_t, count, (max_pfn * KPMSIZE) - src);
713 if (src & KPMMASK || count & KPMMASK)
714 return -EIO;
716 while (count > 0) {
717 ppage = NULL;
718 if (pfn_valid(pfn))
719 ppage = pfn_to_page(pfn);
720 pfn++;
721 if (!ppage)
722 pcount = 0;
723 else
724 pcount = atomic_read(&ppage->_count);
726 if (put_user(pcount, out++)) {
727 ret = -EFAULT;
728 break;
731 count -= KPMSIZE;
734 *ppos += (char __user *)out - buf;
735 if (!ret)
736 ret = (char __user *)out - buf;
737 return ret;
740 static struct file_operations proc_kpagecount_operations = {
741 .llseek = mem_lseek,
742 .read = kpagecount_read,
745 /* /proc/kpageflags - an array exposing page flags
747 * Each entry is a u64 representing the corresponding
748 * physical page flags.
751 /* These macros are used to decouple internal flags from exported ones */
753 #define KPF_LOCKED 0
754 #define KPF_ERROR 1
755 #define KPF_REFERENCED 2
756 #define KPF_UPTODATE 3
757 #define KPF_DIRTY 4
758 #define KPF_LRU 5
759 #define KPF_ACTIVE 6
760 #define KPF_SLAB 7
761 #define KPF_WRITEBACK 8
762 #define KPF_RECLAIM 9
763 #define KPF_BUDDY 10
765 #define kpf_copy_bit(flags, srcpos, dstpos) (((flags >> srcpos) & 1) << dstpos)
767 static ssize_t kpageflags_read(struct file *file, char __user *buf,
768 size_t count, loff_t *ppos)
770 u64 __user *out = (u64 __user *)buf;
771 struct page *ppage;
772 unsigned long src = *ppos;
773 unsigned long pfn;
774 ssize_t ret = 0;
775 u64 kflags, uflags;
777 pfn = src / KPMSIZE;
778 count = min_t(unsigned long, count, (max_pfn * KPMSIZE) - src);
779 if (src & KPMMASK || count & KPMMASK)
780 return -EIO;
782 while (count > 0) {
783 ppage = NULL;
784 if (pfn_valid(pfn))
785 ppage = pfn_to_page(pfn);
786 pfn++;
787 if (!ppage)
788 kflags = 0;
789 else
790 kflags = ppage->flags;
792 uflags = kpf_copy_bit(KPF_LOCKED, PG_locked, kflags) |
793 kpf_copy_bit(kflags, KPF_ERROR, PG_error) |
794 kpf_copy_bit(kflags, KPF_REFERENCED, PG_referenced) |
795 kpf_copy_bit(kflags, KPF_UPTODATE, PG_uptodate) |
796 kpf_copy_bit(kflags, KPF_DIRTY, PG_dirty) |
797 kpf_copy_bit(kflags, KPF_LRU, PG_lru) |
798 kpf_copy_bit(kflags, KPF_ACTIVE, PG_active) |
799 kpf_copy_bit(kflags, KPF_SLAB, PG_slab) |
800 kpf_copy_bit(kflags, KPF_WRITEBACK, PG_writeback) |
801 kpf_copy_bit(kflags, KPF_RECLAIM, PG_reclaim) |
802 kpf_copy_bit(kflags, KPF_BUDDY, PG_buddy);
804 if (put_user(uflags, out++)) {
805 ret = -EFAULT;
806 break;
809 count -= KPMSIZE;
812 *ppos += (char __user *)out - buf;
813 if (!ret)
814 ret = (char __user *)out - buf;
815 return ret;
818 static struct file_operations proc_kpageflags_operations = {
819 .llseek = mem_lseek,
820 .read = kpageflags_read,
822 #endif /* CONFIG_PROC_PAGE_MONITOR */
824 struct proc_dir_entry *proc_root_kcore;
826 void create_seq_entry(char *name, mode_t mode, const struct file_operations *f)
828 struct proc_dir_entry *entry;
829 entry = create_proc_entry(name, mode, NULL);
830 if (entry)
831 entry->proc_fops = f;
834 void __init proc_misc_init(void)
836 static struct {
837 char *name;
838 int (*read_proc)(char*,char**,off_t,int,int*,void*);
839 } *p, simple_ones[] = {
840 {"loadavg", loadavg_read_proc},
841 {"uptime", uptime_read_proc},
842 {"meminfo", meminfo_read_proc},
843 {"version", version_read_proc},
844 #ifdef CONFIG_PROC_HARDWARE
845 {"hardware", hardware_read_proc},
846 #endif
847 #ifdef CONFIG_STRAM_PROC
848 {"stram", stram_read_proc},
849 #endif
850 {"filesystems", filesystems_read_proc},
851 {"cmdline", cmdline_read_proc},
852 {"execdomains", execdomains_read_proc},
853 {NULL,}
855 for (p = simple_ones; p->name; p++)
856 create_proc_read_entry(p->name, 0, NULL, p->read_proc, NULL);
858 proc_symlink("mounts", NULL, "self/mounts");
860 /* And now for trickier ones */
861 #ifdef CONFIG_PRINTK
863 struct proc_dir_entry *entry;
864 entry = create_proc_entry("kmsg", S_IRUSR, &proc_root);
865 if (entry)
866 entry->proc_fops = &proc_kmsg_operations;
868 #endif
869 create_seq_entry("locks", 0, &proc_locks_operations);
870 create_seq_entry("devices", 0, &proc_devinfo_operations);
871 create_seq_entry("cpuinfo", 0, &proc_cpuinfo_operations);
872 #ifdef CONFIG_BLOCK
873 create_seq_entry("partitions", 0, &proc_partitions_operations);
874 #endif
875 create_seq_entry("stat", 0, &proc_stat_operations);
876 create_seq_entry("interrupts", 0, &proc_interrupts_operations);
877 #ifdef CONFIG_SLABINFO
878 create_seq_entry("slabinfo",S_IWUSR|S_IRUGO,&proc_slabinfo_operations);
879 #ifdef CONFIG_DEBUG_SLAB_LEAK
880 create_seq_entry("slab_allocators", 0 ,&proc_slabstats_operations);
881 #endif
882 #endif
883 create_seq_entry("buddyinfo",S_IRUGO, &fragmentation_file_operations);
884 create_seq_entry("pagetypeinfo", S_IRUGO, &pagetypeinfo_file_ops);
885 create_seq_entry("vmstat",S_IRUGO, &proc_vmstat_file_operations);
886 create_seq_entry("zoneinfo",S_IRUGO, &proc_zoneinfo_file_operations);
887 #ifdef CONFIG_BLOCK
888 create_seq_entry("diskstats", 0, &proc_diskstats_operations);
889 #endif
890 #ifdef CONFIG_MODULES
891 create_seq_entry("modules", 0, &proc_modules_operations);
892 #endif
893 #ifdef CONFIG_SCHEDSTATS
894 create_seq_entry("schedstat", 0, &proc_schedstat_operations);
895 #endif
896 #ifdef CONFIG_PROC_KCORE
897 proc_root_kcore = create_proc_entry("kcore", S_IRUSR, NULL);
898 if (proc_root_kcore) {
899 proc_root_kcore->proc_fops = &proc_kcore_operations;
900 proc_root_kcore->size =
901 (size_t)high_memory - PAGE_OFFSET + PAGE_SIZE;
903 #endif
904 #ifdef CONFIG_PROC_PAGE_MONITOR
905 create_seq_entry("kpagecount", S_IRUSR, &proc_kpagecount_operations);
906 create_seq_entry("kpageflags", S_IRUSR, &proc_kpageflags_operations);
907 #endif
908 #ifdef CONFIG_PROC_VMCORE
909 proc_vmcore = create_proc_entry("vmcore", S_IRUSR, NULL);
910 if (proc_vmcore)
911 proc_vmcore->proc_fops = &proc_vmcore_operations;
912 #endif
913 #ifdef CONFIG_MAGIC_SYSRQ
915 struct proc_dir_entry *entry;
916 entry = create_proc_entry("sysrq-trigger", S_IWUSR, NULL);
917 if (entry)
918 entry->proc_fops = &proc_sysrq_trigger_operations;
920 #endif