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