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