]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - fs/proc/proc_misc.c
proc: remove unused get_dma_list()
[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/interrupt.h>
34 #include <linux/swap.h>
35 #include <linux/slab.h>
36 #include <linux/genhd.h>
37 #include <linux/smp.h>
38 #include <linux/signal.h>
39 #include <linux/module.h>
40 #include <linux/init.h>
41 #include <linux/seq_file.h>
42 #include <linux/times.h>
43 #include <linux/profile.h>
44 #include <linux/utsname.h>
45 #include <linux/blkdev.h>
46 #include <linux/hugetlb.h>
47 #include <linux/jiffies.h>
48 #include <linux/sysrq.h>
49 #include <linux/vmalloc.h>
50 #include <linux/crash_dump.h>
51 #include <linux/pid_namespace.h>
52 #include <linux/bootmem.h>
53 #include <asm/uaccess.h>
54 #include <asm/pgtable.h>
55 #include <asm/io.h>
56 #include <asm/tlb.h>
57 #include <asm/div64.h>
58 #include "internal.h"
59
60 #define LOAD_INT(x) ((x) >> FSHIFT)
61 #define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100)
62 /*
63  * Warning: stuff below (imported functions) assumes that its output will fit
64  * into one page. For some of those functions it may be wrong. Moreover, we
65  * have a way to deal with that gracefully. Right now I used straightforward
66  * wrappers, but this needs further analysis wrt potential overflows.
67  */
68 extern int get_hardware_list(char *);
69 extern int get_stram_list(char *);
70 extern int get_exec_domain_list(char *);
71
72 static int proc_calc_metrics(char *page, char **start, off_t off,
73                                  int count, int *eof, int len)
74 {
75         if (len <= off+count) *eof = 1;
76         *start = page + off;
77         len -= off;
78         if (len>count) len = count;
79         if (len<0) len = 0;
80         return len;
81 }
82
83 static int loadavg_read_proc(char *page, char **start, off_t off,
84                                  int count, int *eof, void *data)
85 {
86         int a, b, c;
87         int len;
88         unsigned long seq;
89
90         do {
91                 seq = read_seqbegin(&xtime_lock);
92                 a = avenrun[0] + (FIXED_1/200);
93                 b = avenrun[1] + (FIXED_1/200);
94                 c = avenrun[2] + (FIXED_1/200);
95         } while (read_seqretry(&xtime_lock, seq));
96
97         len = sprintf(page,"%d.%02d %d.%02d %d.%02d %ld/%d %d\n",
98                 LOAD_INT(a), LOAD_FRAC(a),
99                 LOAD_INT(b), LOAD_FRAC(b),
100                 LOAD_INT(c), LOAD_FRAC(c),
101                 nr_running(), nr_threads,
102                 task_active_pid_ns(current)->last_pid);
103         return proc_calc_metrics(page, start, off, count, eof, len);
104 }
105
106 static int uptime_read_proc(char *page, char **start, off_t off,
107                                  int count, int *eof, void *data)
108 {
109         struct timespec uptime;
110         struct timespec idle;
111         int len;
112         cputime_t idletime = cputime_add(init_task.utime, init_task.stime);
113
114         do_posix_clock_monotonic_gettime(&uptime);
115         monotonic_to_bootbased(&uptime);
116         cputime_to_timespec(idletime, &idle);
117         len = sprintf(page,"%lu.%02lu %lu.%02lu\n",
118                         (unsigned long) uptime.tv_sec,
119                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
120                         (unsigned long) idle.tv_sec,
121                         (idle.tv_nsec / (NSEC_PER_SEC / 100)));
122
123         return proc_calc_metrics(page, start, off, count, eof, len);
124 }
125
126 int __attribute__((weak)) arch_report_meminfo(char *page)
127 {
128         return 0;
129 }
130
131 static int meminfo_read_proc(char *page, char **start, off_t off,
132                                  int count, int *eof, void *data)
133 {
134         struct sysinfo i;
135         int len;
136         unsigned long committed;
137         unsigned long allowed;
138         struct vmalloc_info vmi;
139         long cached;
140
141 /*
142  * display in kilobytes.
143  */
144 #define K(x) ((x) << (PAGE_SHIFT - 10))
145         si_meminfo(&i);
146         si_swapinfo(&i);
147         committed = atomic_long_read(&vm_committed_space);
148         allowed = ((totalram_pages - hugetlb_total_pages())
149                 * sysctl_overcommit_ratio / 100) + total_swap_pages;
150
151         cached = global_page_state(NR_FILE_PAGES) -
152                         total_swapcache_pages - i.bufferram;
153         if (cached < 0)
154                 cached = 0;
155
156         get_vmalloc_info(&vmi);
157
158         /*
159          * Tagged format, for easy grepping and expansion.
160          */
161         len = sprintf(page,
162                 "MemTotal:     %8lu kB\n"
163                 "MemFree:      %8lu kB\n"
164                 "Buffers:      %8lu kB\n"
165                 "Cached:       %8lu kB\n"
166                 "SwapCached:   %8lu kB\n"
167                 "Active:       %8lu kB\n"
168                 "Inactive:     %8lu kB\n"
169 #ifdef CONFIG_HIGHMEM
170                 "HighTotal:    %8lu kB\n"
171                 "HighFree:     %8lu kB\n"
172                 "LowTotal:     %8lu kB\n"
173                 "LowFree:      %8lu kB\n"
174 #endif
175                 "SwapTotal:    %8lu kB\n"
176                 "SwapFree:     %8lu kB\n"
177                 "Dirty:        %8lu kB\n"
178                 "Writeback:    %8lu kB\n"
179                 "AnonPages:    %8lu kB\n"
180                 "Mapped:       %8lu kB\n"
181                 "Slab:         %8lu kB\n"
182                 "SReclaimable: %8lu kB\n"
183                 "SUnreclaim:   %8lu kB\n"
184                 "PageTables:   %8lu kB\n"
185 #ifdef CONFIG_QUICKLIST
186                 "Quicklists:   %8lu kB\n"
187 #endif
188                 "NFS_Unstable: %8lu kB\n"
189                 "Bounce:       %8lu kB\n"
190                 "WritebackTmp: %8lu kB\n"
191                 "CommitLimit:  %8lu kB\n"
192                 "Committed_AS: %8lu kB\n"
193                 "VmallocTotal: %8lu kB\n"
194                 "VmallocUsed:  %8lu kB\n"
195                 "VmallocChunk: %8lu kB\n",
196                 K(i.totalram),
197                 K(i.freeram),
198                 K(i.bufferram),
199                 K(cached),
200                 K(total_swapcache_pages),
201                 K(global_page_state(NR_ACTIVE)),
202                 K(global_page_state(NR_INACTIVE)),
203 #ifdef CONFIG_HIGHMEM
204                 K(i.totalhigh),
205                 K(i.freehigh),
206                 K(i.totalram-i.totalhigh),
207                 K(i.freeram-i.freehigh),
208 #endif
209                 K(i.totalswap),
210                 K(i.freeswap),
211                 K(global_page_state(NR_FILE_DIRTY)),
212                 K(global_page_state(NR_WRITEBACK)),
213                 K(global_page_state(NR_ANON_PAGES)),
214                 K(global_page_state(NR_FILE_MAPPED)),
215                 K(global_page_state(NR_SLAB_RECLAIMABLE) +
216                                 global_page_state(NR_SLAB_UNRECLAIMABLE)),
217                 K(global_page_state(NR_SLAB_RECLAIMABLE)),
218                 K(global_page_state(NR_SLAB_UNRECLAIMABLE)),
219                 K(global_page_state(NR_PAGETABLE)),
220 #ifdef CONFIG_QUICKLIST
221                 K(quicklist_total_size()),
222 #endif
223                 K(global_page_state(NR_UNSTABLE_NFS)),
224                 K(global_page_state(NR_BOUNCE)),
225                 K(global_page_state(NR_WRITEBACK_TEMP)),
226                 K(allowed),
227                 K(committed),
228                 (unsigned long)VMALLOC_TOTAL >> 10,
229                 vmi.used >> 10,
230                 vmi.largest_chunk >> 10
231                 );
232
233                 len += hugetlb_report_meminfo(page + len);
234
235         len += arch_report_meminfo(page + len);
236
237         return proc_calc_metrics(page, start, off, count, eof, len);
238 #undef K
239 }
240
241 static int fragmentation_open(struct inode *inode, struct file *file)
242 {
243         (void)inode;
244         return seq_open(file, &fragmentation_op);
245 }
246
247 static const struct file_operations fragmentation_file_operations = {
248         .open           = fragmentation_open,
249         .read           = seq_read,
250         .llseek         = seq_lseek,
251         .release        = seq_release,
252 };
253
254 static int pagetypeinfo_open(struct inode *inode, struct file *file)
255 {
256         return seq_open(file, &pagetypeinfo_op);
257 }
258
259 static const struct file_operations pagetypeinfo_file_ops = {
260         .open           = pagetypeinfo_open,
261         .read           = seq_read,
262         .llseek         = seq_lseek,
263         .release        = seq_release,
264 };
265
266 static int zoneinfo_open(struct inode *inode, struct file *file)
267 {
268         return seq_open(file, &zoneinfo_op);
269 }
270
271 static const struct file_operations proc_zoneinfo_file_operations = {
272         .open           = zoneinfo_open,
273         .read           = seq_read,
274         .llseek         = seq_lseek,
275         .release        = seq_release,
276 };
277
278 static int version_read_proc(char *page, char **start, off_t off,
279                                  int count, int *eof, void *data)
280 {
281         int len;
282
283         len = snprintf(page, PAGE_SIZE, linux_proc_banner,
284                 utsname()->sysname,
285                 utsname()->release,
286                 utsname()->version);
287         return proc_calc_metrics(page, start, off, count, eof, len);
288 }
289
290 extern const struct seq_operations cpuinfo_op;
291 static int cpuinfo_open(struct inode *inode, struct file *file)
292 {
293         return seq_open(file, &cpuinfo_op);
294 }
295
296 static const struct file_operations proc_cpuinfo_operations = {
297         .open           = cpuinfo_open,
298         .read           = seq_read,
299         .llseek         = seq_lseek,
300         .release        = seq_release,
301 };
302
303 static int devinfo_show(struct seq_file *f, void *v)
304 {
305         int i = *(loff_t *) v;
306
307         if (i < CHRDEV_MAJOR_HASH_SIZE) {
308                 if (i == 0)
309                         seq_printf(f, "Character devices:\n");
310                 chrdev_show(f, i);
311         }
312 #ifdef CONFIG_BLOCK
313         else {
314                 i -= CHRDEV_MAJOR_HASH_SIZE;
315                 if (i == 0)
316                         seq_printf(f, "\nBlock devices:\n");
317                 blkdev_show(f, i);
318         }
319 #endif
320         return 0;
321 }
322
323 static void *devinfo_start(struct seq_file *f, loff_t *pos)
324 {
325         if (*pos < (BLKDEV_MAJOR_HASH_SIZE + CHRDEV_MAJOR_HASH_SIZE))
326                 return pos;
327         return NULL;
328 }
329
330 static void *devinfo_next(struct seq_file *f, void *v, loff_t *pos)
331 {
332         (*pos)++;
333         if (*pos >= (BLKDEV_MAJOR_HASH_SIZE + CHRDEV_MAJOR_HASH_SIZE))
334                 return NULL;
335         return pos;
336 }
337
338 static void devinfo_stop(struct seq_file *f, void *v)
339 {
340         /* Nothing to do */
341 }
342
343 static const struct seq_operations devinfo_ops = {
344         .start = devinfo_start,
345         .next  = devinfo_next,
346         .stop  = devinfo_stop,
347         .show  = devinfo_show
348 };
349
350 static int devinfo_open(struct inode *inode, struct file *filp)
351 {
352         return seq_open(filp, &devinfo_ops);
353 }
354
355 static const struct file_operations proc_devinfo_operations = {
356         .open           = devinfo_open,
357         .read           = seq_read,
358         .llseek         = seq_lseek,
359         .release        = seq_release,
360 };
361
362 static int vmstat_open(struct inode *inode, struct file *file)
363 {
364         return seq_open(file, &vmstat_op);
365 }
366 static const struct file_operations proc_vmstat_file_operations = {
367         .open           = vmstat_open,
368         .read           = seq_read,
369         .llseek         = seq_lseek,
370         .release        = seq_release,
371 };
372
373 #ifdef CONFIG_PROC_HARDWARE
374 static int hardware_read_proc(char *page, char **start, off_t off,
375                                  int count, int *eof, void *data)
376 {
377         int len = get_hardware_list(page);
378         return proc_calc_metrics(page, start, off, count, eof, len);
379 }
380 #endif
381
382 #ifdef CONFIG_STRAM_PROC
383 static int stram_read_proc(char *page, char **start, off_t off,
384                                  int count, int *eof, void *data)
385 {
386         int len = get_stram_list(page);
387         return proc_calc_metrics(page, start, off, count, eof, len);
388 }
389 #endif
390
391 #ifdef CONFIG_BLOCK
392 static int partitions_open(struct inode *inode, struct file *file)
393 {
394         return seq_open(file, &partitions_op);
395 }
396 static const struct file_operations proc_partitions_operations = {
397         .open           = partitions_open,
398         .read           = seq_read,
399         .llseek         = seq_lseek,
400         .release        = seq_release,
401 };
402
403 static int diskstats_open(struct inode *inode, struct file *file)
404 {
405         return seq_open(file, &diskstats_op);
406 }
407 static const struct file_operations proc_diskstats_operations = {
408         .open           = diskstats_open,
409         .read           = seq_read,
410         .llseek         = seq_lseek,
411         .release        = seq_release,
412 };
413 #endif
414
415 #ifdef CONFIG_MODULES
416 extern const struct seq_operations modules_op;
417 static int modules_open(struct inode *inode, struct file *file)
418 {
419         return seq_open(file, &modules_op);
420 }
421 static const struct file_operations proc_modules_operations = {
422         .open           = modules_open,
423         .read           = seq_read,
424         .llseek         = seq_lseek,
425         .release        = seq_release,
426 };
427 #endif
428
429 #ifdef CONFIG_SLABINFO
430 static int slabinfo_open(struct inode *inode, struct file *file)
431 {
432         return seq_open(file, &slabinfo_op);
433 }
434 static const struct file_operations proc_slabinfo_operations = {
435         .open           = slabinfo_open,
436         .read           = seq_read,
437         .write          = slabinfo_write,
438         .llseek         = seq_lseek,
439         .release        = seq_release,
440 };
441
442 #ifdef CONFIG_DEBUG_SLAB_LEAK
443 extern const struct seq_operations slabstats_op;
444 static int slabstats_open(struct inode *inode, struct file *file)
445 {
446         unsigned long *n = kzalloc(PAGE_SIZE, GFP_KERNEL);
447         int ret = -ENOMEM;
448         if (n) {
449                 ret = seq_open(file, &slabstats_op);
450                 if (!ret) {
451                         struct seq_file *m = file->private_data;
452                         *n = PAGE_SIZE / (2 * sizeof(unsigned long));
453                         m->private = n;
454                         n = NULL;
455                 }
456                 kfree(n);
457         }
458         return ret;
459 }
460
461 static const struct file_operations proc_slabstats_operations = {
462         .open           = slabstats_open,
463         .read           = seq_read,
464         .llseek         = seq_lseek,
465         .release        = seq_release_private,
466 };
467 #endif
468 #endif
469
470 #ifdef CONFIG_MMU
471 static int vmalloc_open(struct inode *inode, struct file *file)
472 {
473         unsigned int *ptr = NULL;
474         int ret;
475
476         if (NUMA_BUILD)
477                 ptr = kmalloc(nr_node_ids * sizeof(unsigned int), GFP_KERNEL);
478         ret = seq_open(file, &vmalloc_op);
479         if (!ret) {
480                 struct seq_file *m = file->private_data;
481                 m->private = ptr;
482         } else
483                 kfree(ptr);
484         return ret;
485 }
486
487 static const struct file_operations proc_vmalloc_operations = {
488         .open           = vmalloc_open,
489         .read           = seq_read,
490         .llseek         = seq_lseek,
491         .release        = seq_release_private,
492 };
493 #endif
494
495 #ifndef arch_irq_stat_cpu
496 #define arch_irq_stat_cpu(cpu) 0
497 #endif
498 #ifndef arch_irq_stat
499 #define arch_irq_stat() 0
500 #endif
501
502 static int show_stat(struct seq_file *p, void *v)
503 {
504         int i;
505         unsigned long jif;
506         cputime64_t user, nice, system, idle, iowait, irq, softirq, steal;
507         cputime64_t guest;
508         u64 sum = 0;
509         struct timespec boottime;
510         unsigned int *per_irq_sum;
511
512         per_irq_sum = kzalloc(sizeof(unsigned int)*NR_IRQS, GFP_KERNEL);
513         if (!per_irq_sum)
514                 return -ENOMEM;
515
516         user = nice = system = idle = iowait =
517                 irq = softirq = steal = cputime64_zero;
518         guest = cputime64_zero;
519         getboottime(&boottime);
520         jif = boottime.tv_sec;
521
522         for_each_possible_cpu(i) {
523                 int j;
524
525                 user = cputime64_add(user, kstat_cpu(i).cpustat.user);
526                 nice = cputime64_add(nice, kstat_cpu(i).cpustat.nice);
527                 system = cputime64_add(system, kstat_cpu(i).cpustat.system);
528                 idle = cputime64_add(idle, kstat_cpu(i).cpustat.idle);
529                 iowait = cputime64_add(iowait, kstat_cpu(i).cpustat.iowait);
530                 irq = cputime64_add(irq, kstat_cpu(i).cpustat.irq);
531                 softirq = cputime64_add(softirq, kstat_cpu(i).cpustat.softirq);
532                 steal = cputime64_add(steal, kstat_cpu(i).cpustat.steal);
533                 guest = cputime64_add(guest, kstat_cpu(i).cpustat.guest);
534                 for (j = 0; j < NR_IRQS; j++) {
535                         unsigned int temp = kstat_cpu(i).irqs[j];
536                         sum += temp;
537                         per_irq_sum[j] += temp;
538                 }
539                 sum += arch_irq_stat_cpu(i);
540         }
541         sum += arch_irq_stat();
542
543         seq_printf(p, "cpu  %llu %llu %llu %llu %llu %llu %llu %llu %llu\n",
544                 (unsigned long long)cputime64_to_clock_t(user),
545                 (unsigned long long)cputime64_to_clock_t(nice),
546                 (unsigned long long)cputime64_to_clock_t(system),
547                 (unsigned long long)cputime64_to_clock_t(idle),
548                 (unsigned long long)cputime64_to_clock_t(iowait),
549                 (unsigned long long)cputime64_to_clock_t(irq),
550                 (unsigned long long)cputime64_to_clock_t(softirq),
551                 (unsigned long long)cputime64_to_clock_t(steal),
552                 (unsigned long long)cputime64_to_clock_t(guest));
553         for_each_online_cpu(i) {
554
555                 /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
556                 user = kstat_cpu(i).cpustat.user;
557                 nice = kstat_cpu(i).cpustat.nice;
558                 system = kstat_cpu(i).cpustat.system;
559                 idle = kstat_cpu(i).cpustat.idle;
560                 iowait = kstat_cpu(i).cpustat.iowait;
561                 irq = kstat_cpu(i).cpustat.irq;
562                 softirq = kstat_cpu(i).cpustat.softirq;
563                 steal = kstat_cpu(i).cpustat.steal;
564                 guest = kstat_cpu(i).cpustat.guest;
565                 seq_printf(p,
566                         "cpu%d %llu %llu %llu %llu %llu %llu %llu %llu %llu\n",
567                         i,
568                         (unsigned long long)cputime64_to_clock_t(user),
569                         (unsigned long long)cputime64_to_clock_t(nice),
570                         (unsigned long long)cputime64_to_clock_t(system),
571                         (unsigned long long)cputime64_to_clock_t(idle),
572                         (unsigned long long)cputime64_to_clock_t(iowait),
573                         (unsigned long long)cputime64_to_clock_t(irq),
574                         (unsigned long long)cputime64_to_clock_t(softirq),
575                         (unsigned long long)cputime64_to_clock_t(steal),
576                         (unsigned long long)cputime64_to_clock_t(guest));
577         }
578         seq_printf(p, "intr %llu", (unsigned long long)sum);
579
580         for (i = 0; i < NR_IRQS; i++)
581                 seq_printf(p, " %u", per_irq_sum[i]);
582
583         seq_printf(p,
584                 "\nctxt %llu\n"
585                 "btime %lu\n"
586                 "processes %lu\n"
587                 "procs_running %lu\n"
588                 "procs_blocked %lu\n",
589                 nr_context_switches(),
590                 (unsigned long)jif,
591                 total_forks,
592                 nr_running(),
593                 nr_iowait());
594
595         kfree(per_irq_sum);
596         return 0;
597 }
598
599 static int stat_open(struct inode *inode, struct file *file)
600 {
601         unsigned size = 4096 * (1 + num_possible_cpus() / 32);
602         char *buf;
603         struct seq_file *m;
604         int res;
605
606         /* don't ask for more than the kmalloc() max size, currently 128 KB */
607         if (size > 128 * 1024)
608                 size = 128 * 1024;
609         buf = kmalloc(size, GFP_KERNEL);
610         if (!buf)
611                 return -ENOMEM;
612
613         res = single_open(file, show_stat, NULL);
614         if (!res) {
615                 m = file->private_data;
616                 m->buf = buf;
617                 m->size = size;
618         } else
619                 kfree(buf);
620         return res;
621 }
622 static const struct file_operations proc_stat_operations = {
623         .open           = stat_open,
624         .read           = seq_read,
625         .llseek         = seq_lseek,
626         .release        = single_release,
627 };
628
629 /*
630  * /proc/interrupts
631  */
632 static void *int_seq_start(struct seq_file *f, loff_t *pos)
633 {
634         return (*pos <= NR_IRQS) ? pos : NULL;
635 }
636
637 static void *int_seq_next(struct seq_file *f, void *v, loff_t *pos)
638 {
639         (*pos)++;
640         if (*pos > NR_IRQS)
641                 return NULL;
642         return pos;
643 }
644
645 static void int_seq_stop(struct seq_file *f, void *v)
646 {
647         /* Nothing to do */
648 }
649
650
651 static const struct seq_operations int_seq_ops = {
652         .start = int_seq_start,
653         .next  = int_seq_next,
654         .stop  = int_seq_stop,
655         .show  = show_interrupts
656 };
657
658 static int interrupts_open(struct inode *inode, struct file *filp)
659 {
660         return seq_open(filp, &int_seq_ops);
661 }
662
663 static const struct file_operations proc_interrupts_operations = {
664         .open           = interrupts_open,
665         .read           = seq_read,
666         .llseek         = seq_lseek,
667         .release        = seq_release,
668 };
669
670 static int filesystems_read_proc(char *page, char **start, off_t off,
671                                  int count, int *eof, void *data)
672 {
673         int len = get_filesystem_list(page);
674         return proc_calc_metrics(page, start, off, count, eof, len);
675 }
676
677 static int cmdline_read_proc(char *page, char **start, off_t off,
678                                  int count, int *eof, void *data)
679 {
680         int len;
681
682         len = sprintf(page, "%s\n", saved_command_line);
683         return proc_calc_metrics(page, start, off, count, eof, len);
684 }
685
686 static int locks_open(struct inode *inode, struct file *filp)
687 {
688         return seq_open(filp, &locks_seq_operations);
689 }
690
691 static const struct file_operations proc_locks_operations = {
692         .open           = locks_open,
693         .read           = seq_read,
694         .llseek         = seq_lseek,
695         .release        = seq_release,
696 };
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         proc_create("locks", 0, NULL, &proc_locks_operations);
891         proc_create("devices", 0, NULL, &proc_devinfo_operations);
892         proc_create("cpuinfo", 0, NULL, &proc_cpuinfo_operations);
893 #ifdef CONFIG_BLOCK
894         proc_create("partitions", 0, NULL, &proc_partitions_operations);
895 #endif
896         proc_create("stat", 0, NULL, &proc_stat_operations);
897         proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
898 #ifdef CONFIG_SLABINFO
899         proc_create("slabinfo",S_IWUSR|S_IRUGO,NULL,&proc_slabinfo_operations);
900 #ifdef CONFIG_DEBUG_SLAB_LEAK
901         proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
902 #endif
903 #endif
904 #ifdef CONFIG_MMU
905         proc_create("vmallocinfo", S_IRUSR, NULL, &proc_vmalloc_operations);
906 #endif
907         proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
908         proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
909         proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
910         proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
911 #ifdef CONFIG_BLOCK
912         proc_create("diskstats", 0, NULL, &proc_diskstats_operations);
913 #endif
914 #ifdef CONFIG_MODULES
915         proc_create("modules", 0, NULL, &proc_modules_operations);
916 #endif
917 #ifdef CONFIG_SCHEDSTATS
918         proc_create("schedstat", 0, NULL, &proc_schedstat_operations);
919 #endif
920 #ifdef CONFIG_PROC_KCORE
921         proc_root_kcore = proc_create("kcore", S_IRUSR, NULL, &proc_kcore_operations);
922         if (proc_root_kcore)
923                 proc_root_kcore->size =
924                                 (size_t)high_memory - PAGE_OFFSET + PAGE_SIZE;
925 #endif
926 #ifdef CONFIG_PROC_PAGE_MONITOR
927         proc_create("kpagecount", S_IRUSR, NULL, &proc_kpagecount_operations);
928         proc_create("kpageflags", S_IRUSR, NULL, &proc_kpageflags_operations);
929 #endif
930 #ifdef CONFIG_PROC_VMCORE
931         proc_vmcore = proc_create("vmcore", S_IRUSR, NULL, &proc_vmcore_operations);
932 #endif
933 #ifdef CONFIG_MAGIC_SYSRQ
934         proc_create("sysrq-trigger", S_IWUSR, NULL, &proc_sysrq_trigger_operations);
935 #endif
936 }