fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.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/proc_fs.h>
28 #include <linux/ioport.h>
29 #include <linux/mm.h>
30 #include <linux/mmzone.h>
31 #include <linux/pagemap.h>
32 #include <linux/swap.h>
33 #include <linux/slab.h>
34 #include <linux/smp.h>
35 #include <linux/signal.h>
36 #include <linux/module.h>
37 #include <linux/init.h>
38 #include <linux/smp_lock.h>
39 #include <linux/seq_file.h>
40 #include <linux/times.h>
41 #include <linux/profile.h>
42 #include <linux/utsname.h>
43 #include <linux/blkdev.h>
44 #include <linux/hugetlb.h>
45 #include <linux/jiffies.h>
46 #include <linux/sysrq.h>
47 #include <linux/vmalloc.h>
48 #include <linux/crash_dump.h>
49 #include <linux/pid_namespace.h>
50 #include <asm/uaccess.h>
51 #include <asm/pgtable.h>
52 #include <asm/io.h>
53 #include <asm/tlb.h>
54 #include <asm/div64.h>
55 #include "internal.h"
56
57 #include <linux/vs_cvirt.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_filesystem_list(char *);
70 extern int get_exec_domain_list(char *);
71 extern int get_dma_list(char *);
72 extern int get_locks_status (char *, char **, off_t, int);
73
74 static int proc_calc_metrics(char *page, char **start, off_t off,
75                                  int count, int *eof, int len)
76 {
77         if (len <= off+count) *eof = 1;
78         *start = page + off;
79         len -= off;
80         if (len>count) len = count;
81         if (len<0) len = 0;
82         return len;
83 }
84
85 static int loadavg_read_proc(char *page, char **start, off_t off,
86                                  int count, int *eof, void *data)
87 {
88         unsigned int running, threads;
89         int a, b, c;
90         int len;
91
92         if (vx_flags(VXF_VIRT_LOAD, 0)) {
93                 struct vx_info *vxi = current->vx_info;
94
95                 a = vxi->cvirt.load[0] + (FIXED_1/200);
96                 b = vxi->cvirt.load[1] + (FIXED_1/200);
97                 c = vxi->cvirt.load[2] + (FIXED_1/200);
98
99                 running = atomic_read(&vxi->cvirt.nr_running);
100                 threads = atomic_read(&vxi->cvirt.nr_threads);
101         } else {
102                 a = avenrun[0] + (FIXED_1/200);
103                 b = avenrun[1] + (FIXED_1/200);
104                 c = avenrun[2] + (FIXED_1/200);
105
106                 running = nr_running();
107                 threads = nr_threads;
108         }
109         len = sprintf(page,"%d.%02d %d.%02d %d.%02d %d/%d %d\n",
110                 LOAD_INT(a), LOAD_FRAC(a),
111                 LOAD_INT(b), LOAD_FRAC(b),
112                 LOAD_INT(c), LOAD_FRAC(c),
113                 running, threads, current->nsproxy->pid_ns->last_pid);
114         return proc_calc_metrics(page, start, off, count, eof, len);
115 }
116
117 static int uptime_read_proc(char *page, char **start, off_t off,
118                                  int count, int *eof, void *data)
119 {
120         struct timespec uptime;
121         struct timespec idle;
122         int len;
123         cputime_t idletime = cputime_add(init_task.utime, init_task.stime);
124
125         do_posix_clock_monotonic_gettime(&uptime);
126         cputime_to_timespec(idletime, &idle);
127         if (vx_flags(VXF_VIRT_UPTIME, 0))
128                 vx_vsi_uptime(&uptime, &idle);
129
130         len = sprintf(page,"%lu.%02lu %lu.%02lu\n",
131                         (unsigned long) uptime.tv_sec,
132                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
133                         (unsigned long) idle.tv_sec,
134                         (idle.tv_nsec / (NSEC_PER_SEC / 100)));
135
136         return proc_calc_metrics(page, start, off, count, eof, len);
137 }
138
139 static int meminfo_read_proc(char *page, char **start, off_t off,
140                                  int count, int *eof, void *data)
141 {
142         struct sysinfo i;
143         int len;
144         unsigned long inactive;
145         unsigned long active;
146         unsigned long free;
147         unsigned long committed;
148         unsigned long allowed;
149         struct vmalloc_info vmi;
150         long cached;
151
152         get_zone_counts(&active, &inactive, &free);
153
154 /*
155  * display in kilobytes.
156  */
157 #define K(x) ((x) << (PAGE_SHIFT - 10))
158         si_meminfo(&i);
159         si_swapinfo(&i);
160         committed = atomic_read(&vm_committed_space);
161         allowed = ((totalram_pages - hugetlb_total_pages())
162                 * sysctl_overcommit_ratio / 100) + total_swap_pages;
163
164         cached = global_page_state(NR_FILE_PAGES) -
165                         total_swapcache_pages - i.bufferram;
166         if (cached < 0 || vx_flags(VXF_VIRT_MEM, 0))
167                 cached = 0;
168
169         get_vmalloc_info(&vmi);
170
171         /*
172          * Tagged format, for easy grepping and expansion.
173          */
174         len = sprintf(page,
175                 "MemTotal:     %8lu kB\n"
176                 "MemFree:      %8lu kB\n"
177                 "Buffers:      %8lu kB\n"
178                 "Cached:       %8lu kB\n"
179                 "SwapCached:   %8lu kB\n"
180                 "Active:       %8lu kB\n"
181                 "Inactive:     %8lu kB\n"
182 #ifdef CONFIG_HIGHMEM
183                 "HighTotal:    %8lu kB\n"
184                 "HighFree:     %8lu kB\n"
185                 "LowTotal:     %8lu kB\n"
186                 "LowFree:      %8lu kB\n"
187 #endif
188                 "SwapTotal:    %8lu kB\n"
189                 "SwapFree:     %8lu kB\n"
190                 "Dirty:        %8lu kB\n"
191                 "Writeback:    %8lu kB\n"
192                 "AnonPages:    %8lu kB\n"
193                 "Mapped:       %8lu kB\n"
194                 "Slab:         %8lu kB\n"
195                 "SReclaimable: %8lu kB\n"
196                 "SUnreclaim:   %8lu kB\n"
197                 "PageTables:   %8lu kB\n"
198                 "NFS_Unstable: %8lu kB\n"
199                 "Bounce:       %8lu kB\n"
200                 "CommitLimit:  %8lu kB\n"
201                 "Committed_AS: %8lu kB\n"
202                 "VmallocTotal: %8lu kB\n"
203                 "VmallocUsed:  %8lu kB\n"
204                 "VmallocChunk: %8lu kB\n",
205                 K(i.totalram),
206                 K(i.freeram),
207                 K(i.bufferram),
208                 K(cached),
209                 K(total_swapcache_pages),
210                 K(active),
211                 K(inactive),
212 #ifdef CONFIG_HIGHMEM
213                 K(i.totalhigh),
214                 K(i.freehigh),
215                 K(i.totalram-i.totalhigh),
216                 K(i.freeram-i.freehigh),
217 #endif
218                 K(i.totalswap),
219                 K(i.freeswap),
220                 K(global_page_state(NR_FILE_DIRTY)),
221                 K(global_page_state(NR_WRITEBACK)),
222                 K(global_page_state(NR_ANON_PAGES)),
223                 K(global_page_state(NR_FILE_MAPPED)),
224                 K(global_page_state(NR_SLAB_RECLAIMABLE) +
225                                 global_page_state(NR_SLAB_UNRECLAIMABLE)),
226                 K(global_page_state(NR_SLAB_RECLAIMABLE)),
227                 K(global_page_state(NR_SLAB_UNRECLAIMABLE)),
228                 K(global_page_state(NR_PAGETABLE)),
229                 K(global_page_state(NR_UNSTABLE_NFS)),
230                 K(global_page_state(NR_BOUNCE)),
231                 K(allowed),
232                 K(committed),
233                 (unsigned long)VMALLOC_TOTAL >> 10,
234                 vmi.used >> 10,
235                 vmi.largest_chunk >> 10
236                 );
237
238                 len += hugetlb_report_meminfo(page + len);
239
240         return proc_calc_metrics(page, start, off, count, eof, len);
241 #undef K
242 }
243
244 extern struct seq_operations fragmentation_op;
245 static int fragmentation_open(struct inode *inode, struct file *file)
246 {
247         (void)inode;
248         return seq_open(file, &fragmentation_op);
249 }
250
251 static struct file_operations fragmentation_file_operations = {
252         .open           = fragmentation_open,
253         .read           = seq_read,
254         .llseek         = seq_lseek,
255         .release        = seq_release,
256 };
257
258 extern struct seq_operations zoneinfo_op;
259 static int zoneinfo_open(struct inode *inode, struct file *file)
260 {
261         return seq_open(file, &zoneinfo_op);
262 }
263
264 static struct file_operations proc_zoneinfo_file_operations = {
265         .open           = zoneinfo_open,
266         .read           = seq_read,
267         .llseek         = seq_lseek,
268         .release        = seq_release,
269 };
270
271 static int version_read_proc(char *page, char **start, off_t off,
272                                  int count, int *eof, void *data)
273 {
274         int len;
275
276         len = snprintf(page, PAGE_SIZE, linux_proc_banner,
277                 utsname()->sysname,
278                 utsname()->release,
279                 utsname()->version);
280         return proc_calc_metrics(page, start, off, count, eof, len);
281 }
282
283 extern struct seq_operations cpuinfo_op;
284 static int cpuinfo_open(struct inode *inode, struct file *file)
285 {
286         return seq_open(file, &cpuinfo_op);
287 }
288
289 static struct file_operations proc_cpuinfo_operations = {
290         .open           = cpuinfo_open,
291         .read           = seq_read,
292         .llseek         = seq_lseek,
293         .release        = seq_release,
294 };
295
296 static int devinfo_show(struct seq_file *f, void *v)
297 {
298         int i = *(loff_t *) v;
299
300         if (i < CHRDEV_MAJOR_HASH_SIZE) {
301                 if (i == 0)
302                         seq_printf(f, "Character devices:\n");
303                 chrdev_show(f, i);
304         }
305 #ifdef CONFIG_BLOCK
306         else {
307                 i -= CHRDEV_MAJOR_HASH_SIZE;
308                 if (i == 0)
309                         seq_printf(f, "\nBlock devices:\n");
310                 blkdev_show(f, i);
311         }
312 #endif
313         return 0;
314 }
315
316 static void *devinfo_start(struct seq_file *f, loff_t *pos)
317 {
318         if (*pos < (BLKDEV_MAJOR_HASH_SIZE + CHRDEV_MAJOR_HASH_SIZE))
319                 return pos;
320         return NULL;
321 }
322
323 static void *devinfo_next(struct seq_file *f, void *v, loff_t *pos)
324 {
325         (*pos)++;
326         if (*pos >= (BLKDEV_MAJOR_HASH_SIZE + CHRDEV_MAJOR_HASH_SIZE))
327                 return NULL;
328         return pos;
329 }
330
331 static void devinfo_stop(struct seq_file *f, void *v)
332 {
333         /* Nothing to do */
334 }
335
336 static struct seq_operations devinfo_ops = {
337         .start = devinfo_start,
338         .next  = devinfo_next,
339         .stop  = devinfo_stop,
340         .show  = devinfo_show
341 };
342
343 static int devinfo_open(struct inode *inode, struct file *filp)
344 {
345         return seq_open(filp, &devinfo_ops);
346 }
347
348 static struct file_operations proc_devinfo_operations = {
349         .open           = devinfo_open,
350         .read           = seq_read,
351         .llseek         = seq_lseek,
352         .release        = seq_release,
353 };
354
355 extern struct seq_operations vmstat_op;
356 static int vmstat_open(struct inode *inode, struct file *file)
357 {
358         return seq_open(file, &vmstat_op);
359 }
360 static struct file_operations proc_vmstat_file_operations = {
361         .open           = vmstat_open,
362         .read           = seq_read,
363         .llseek         = seq_lseek,
364         .release        = seq_release,
365 };
366
367 #ifdef CONFIG_PROC_HARDWARE
368 static int hardware_read_proc(char *page, char **start, off_t off,
369                                  int count, int *eof, void *data)
370 {
371         int len = get_hardware_list(page);
372         return proc_calc_metrics(page, start, off, count, eof, len);
373 }
374 #endif
375
376 #ifdef CONFIG_STRAM_PROC
377 static int stram_read_proc(char *page, char **start, off_t off,
378                                  int count, int *eof, void *data)
379 {
380         int len = get_stram_list(page);
381         return proc_calc_metrics(page, start, off, count, eof, len);
382 }
383 #endif
384
385 #ifdef CONFIG_BLOCK
386 extern struct seq_operations partitions_op;
387 static int partitions_open(struct inode *inode, struct file *file)
388 {
389         return seq_open(file, &partitions_op);
390 }
391 static struct file_operations proc_partitions_operations = {
392         .open           = partitions_open,
393         .read           = seq_read,
394         .llseek         = seq_lseek,
395         .release        = seq_release,
396 };
397
398 extern struct seq_operations diskstats_op;
399 static int diskstats_open(struct inode *inode, struct file *file)
400 {
401         return seq_open(file, &diskstats_op);
402 }
403 static struct file_operations proc_diskstats_operations = {
404         .open           = diskstats_open,
405         .read           = seq_read,
406         .llseek         = seq_lseek,
407         .release        = seq_release,
408 };
409 #endif
410
411 #ifdef CONFIG_MODULES
412 extern struct seq_operations modules_op;
413 static int modules_open(struct inode *inode, struct file *file)
414 {
415         return seq_open(file, &modules_op);
416 }
417 static struct file_operations proc_modules_operations = {
418         .open           = modules_open,
419         .read           = seq_read,
420         .llseek         = seq_lseek,
421         .release        = seq_release,
422 };
423 #endif
424
425 #ifdef CONFIG_SLAB
426 extern struct seq_operations slabinfo_op;
427 extern ssize_t slabinfo_write(struct file *, const char __user *, size_t, loff_t *);
428 static int slabinfo_open(struct inode *inode, struct file *file)
429 {
430         return seq_open(file, &slabinfo_op);
431 }
432 static struct file_operations proc_slabinfo_operations = {
433         .open           = slabinfo_open,
434         .read           = seq_read,
435         .write          = slabinfo_write,
436         .llseek         = seq_lseek,
437         .release        = seq_release,
438 };
439
440 #ifdef CONFIG_DEBUG_SLAB_LEAK
441 extern struct seq_operations slabstats_op;
442 static int slabstats_open(struct inode *inode, struct file *file)
443 {
444         unsigned long *n = kzalloc(PAGE_SIZE, GFP_KERNEL);
445         int ret = -ENOMEM;
446         if (n) {
447                 ret = seq_open(file, &slabstats_op);
448                 if (!ret) {
449                         struct seq_file *m = file->private_data;
450                         *n = PAGE_SIZE / (2 * sizeof(unsigned long));
451                         m->private = n;
452                         n = NULL;
453                 }
454                 kfree(n);
455         }
456         return ret;
457 }
458
459 static int slabstats_release(struct inode *inode, struct file *file)
460 {
461         struct seq_file *m = file->private_data;
462         kfree(m->private);
463         return seq_release(inode, file);
464 }
465
466 static struct file_operations proc_slabstats_operations = {
467         .open           = slabstats_open,
468         .read           = seq_read,
469         .llseek         = seq_lseek,
470         .release        = slabstats_release,
471 };
472 #endif
473 #endif
474
475 static int show_stat(struct seq_file *p, void *v)
476 {
477         int i;
478         unsigned long jif;
479         cputime64_t user, nice, system, idle, iowait, irq, softirq, steal;
480         u64 sum = 0;
481
482         user = nice = system = idle = iowait =
483                 irq = softirq = steal = cputime64_zero;
484         jif = - wall_to_monotonic.tv_sec;
485         if (wall_to_monotonic.tv_nsec)
486                 --jif;
487
488         for_each_possible_cpu(i) {
489                 int j;
490
491                 user = cputime64_add(user, kstat_cpu(i).cpustat.user);
492                 nice = cputime64_add(nice, kstat_cpu(i).cpustat.nice);
493                 system = cputime64_add(system, kstat_cpu(i).cpustat.system);
494                 idle = cputime64_add(idle, kstat_cpu(i).cpustat.idle);
495                 iowait = cputime64_add(iowait, kstat_cpu(i).cpustat.iowait);
496                 irq = cputime64_add(irq, kstat_cpu(i).cpustat.irq);
497                 softirq = cputime64_add(softirq, kstat_cpu(i).cpustat.softirq);
498                 steal = cputime64_add(steal, kstat_cpu(i).cpustat.steal);
499                 for (j = 0 ; j < NR_IRQS ; j++)
500                         sum += kstat_cpu(i).irqs[j];
501         }
502
503         seq_printf(p, "cpu  %llu %llu %llu %llu %llu %llu %llu %llu\n",
504                 (unsigned long long)cputime64_to_clock_t(user),
505                 (unsigned long long)cputime64_to_clock_t(nice),
506                 (unsigned long long)cputime64_to_clock_t(system),
507                 (unsigned long long)cputime64_to_clock_t(idle),
508                 (unsigned long long)cputime64_to_clock_t(iowait),
509                 (unsigned long long)cputime64_to_clock_t(irq),
510                 (unsigned long long)cputime64_to_clock_t(softirq),
511                 (unsigned long long)cputime64_to_clock_t(steal));
512         for_each_online_cpu(i) {
513
514                 /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
515                 user = kstat_cpu(i).cpustat.user;
516                 nice = kstat_cpu(i).cpustat.nice;
517                 system = kstat_cpu(i).cpustat.system;
518                 idle = kstat_cpu(i).cpustat.idle;
519                 iowait = kstat_cpu(i).cpustat.iowait;
520                 irq = kstat_cpu(i).cpustat.irq;
521                 softirq = kstat_cpu(i).cpustat.softirq;
522                 steal = kstat_cpu(i).cpustat.steal;
523                 seq_printf(p, "cpu%d %llu %llu %llu %llu %llu %llu %llu %llu\n",
524                         i,
525                         (unsigned long long)cputime64_to_clock_t(user),
526                         (unsigned long long)cputime64_to_clock_t(nice),
527                         (unsigned long long)cputime64_to_clock_t(system),
528                         (unsigned long long)cputime64_to_clock_t(idle),
529                         (unsigned long long)cputime64_to_clock_t(iowait),
530                         (unsigned long long)cputime64_to_clock_t(irq),
531                         (unsigned long long)cputime64_to_clock_t(softirq),
532                         (unsigned long long)cputime64_to_clock_t(steal));
533         }
534         seq_printf(p, "intr %llu", (unsigned long long)sum);
535
536 #if !defined(CONFIG_PPC64) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
537         for (i = 0; i < NR_IRQS; i++)
538                 seq_printf(p, " %u", kstat_irqs(i));
539 #endif
540
541         seq_printf(p,
542                 "\nctxt %llu\n"
543                 "btime %lu\n"
544                 "processes %lu\n"
545                 "procs_running %lu\n"
546                 "procs_blocked %lu\n",
547                 nr_context_switches(),
548                 (unsigned long)jif,
549                 total_forks,
550                 nr_running(),
551                 nr_iowait());
552
553         return 0;
554 }
555
556 static int stat_open(struct inode *inode, struct file *file)
557 {
558         unsigned size = 4096 * (1 + num_possible_cpus() / 32);
559         char *buf;
560         struct seq_file *m;
561         int res;
562
563         /* don't ask for more than the kmalloc() max size, currently 128 KB */
564         if (size > 128 * 1024)
565                 size = 128 * 1024;
566         buf = kmalloc(size, GFP_KERNEL);
567         if (!buf)
568                 return -ENOMEM;
569
570         res = single_open(file, show_stat, NULL);
571         if (!res) {
572                 m = file->private_data;
573                 m->buf = buf;
574                 m->size = size;
575         } else
576                 kfree(buf);
577         return res;
578 }
579 static struct file_operations proc_stat_operations = {
580         .open           = stat_open,
581         .read           = seq_read,
582         .llseek         = seq_lseek,
583         .release        = single_release,
584 };
585
586 /*
587  * /proc/interrupts
588  */
589 static void *int_seq_start(struct seq_file *f, loff_t *pos)
590 {
591         return (*pos <= NR_IRQS) ? pos : NULL;
592 }
593
594 static void *int_seq_next(struct seq_file *f, void *v, loff_t *pos)
595 {
596         (*pos)++;
597         if (*pos > NR_IRQS)
598                 return NULL;
599         return pos;
600 }
601
602 static void int_seq_stop(struct seq_file *f, void *v)
603 {
604         /* Nothing to do */
605 }
606
607
608 extern int show_interrupts(struct seq_file *f, void *v); /* In arch code */
609 static struct seq_operations int_seq_ops = {
610         .start = int_seq_start,
611         .next  = int_seq_next,
612         .stop  = int_seq_stop,
613         .show  = show_interrupts
614 };
615
616 static int interrupts_open(struct inode *inode, struct file *filp)
617 {
618         return seq_open(filp, &int_seq_ops);
619 }
620
621 static struct file_operations proc_interrupts_operations = {
622         .open           = interrupts_open,
623         .read           = seq_read,
624         .llseek         = seq_lseek,
625         .release        = seq_release,
626 };
627
628 static int filesystems_read_proc(char *page, char **start, off_t off,
629                                  int count, int *eof, void *data)
630 {
631         int len = get_filesystem_list(page);
632         return proc_calc_metrics(page, start, off, count, eof, len);
633 }
634
635 static int cmdline_read_proc(char *page, char **start, off_t off,
636                                  int count, int *eof, void *data)
637 {
638         int len;
639
640         len = sprintf(page, "%s\n", saved_command_line);
641         return proc_calc_metrics(page, start, off, count, eof, len);
642 }
643
644 static int locks_read_proc(char *page, char **start, off_t off,
645                                  int count, int *eof, void *data)
646 {
647         int len = get_locks_status(page, start, off, count);
648
649         if (len < count)
650                 *eof = 1;
651         return len;
652 }
653
654 static int execdomains_read_proc(char *page, char **start, off_t off,
655                                  int count, int *eof, void *data)
656 {
657         int len = get_exec_domain_list(page);
658         return proc_calc_metrics(page, start, off, count, eof, len);
659 }
660
661 #ifdef CONFIG_MAGIC_SYSRQ
662 /*
663  * writing 'C' to /proc/sysrq-trigger is like sysrq-C
664  */
665 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
666                                    size_t count, loff_t *ppos)
667 {
668         if (count) {
669                 char c;
670
671                 if (get_user(c, buf))
672                         return -EFAULT;
673                 __handle_sysrq(c, NULL, 0);
674         }
675         return count;
676 }
677
678 static struct file_operations proc_sysrq_trigger_operations = {
679         .write          = write_sysrq_trigger,
680 };
681 #endif
682
683 struct proc_dir_entry *proc_root_kcore;
684
685 void create_seq_entry(char *name, mode_t mode, const struct file_operations *f)
686 {
687         struct proc_dir_entry *entry;
688         entry = create_proc_entry(name, mode, NULL);
689         if (entry)
690                 entry->proc_fops = f;
691 }
692
693 void __init proc_misc_init(void)
694 {
695         struct proc_dir_entry *entry;
696         static struct {
697                 char *name;
698                 int (*read_proc)(char*,char**,off_t,int,int*,void*);
699         } *p, simple_ones[] = {
700                 {"loadavg",     loadavg_read_proc},
701                 {"uptime",      uptime_read_proc},
702                 {"meminfo",     meminfo_read_proc},
703                 {"version",     version_read_proc},
704 #ifdef CONFIG_PROC_HARDWARE
705                 {"hardware",    hardware_read_proc},
706 #endif
707 #ifdef CONFIG_STRAM_PROC
708                 {"stram",       stram_read_proc},
709 #endif
710                 {"filesystems", filesystems_read_proc},
711                 {"cmdline",     cmdline_read_proc},
712                 {"locks",       locks_read_proc},
713                 {"execdomains", execdomains_read_proc},
714                 {NULL,}
715         };
716         for (p = simple_ones; p->name; p++)
717                 create_proc_read_entry(p->name, 0, NULL, p->read_proc, NULL);
718
719         proc_symlink("mounts", NULL, "self/mounts");
720
721         /* And now for trickier ones */
722 #ifdef CONFIG_PRINTK
723         entry = create_proc_entry("kmsg", S_IRUSR, &proc_root);
724         if (entry)
725                 entry->proc_fops = &proc_kmsg_operations;
726 #endif
727         create_seq_entry("devices", 0, &proc_devinfo_operations);
728         create_seq_entry("cpuinfo", 0, &proc_cpuinfo_operations);
729 #ifdef CONFIG_BLOCK
730         create_seq_entry("partitions", 0, &proc_partitions_operations);
731 #endif
732         create_seq_entry("stat", 0, &proc_stat_operations);
733         create_seq_entry("interrupts", 0, &proc_interrupts_operations);
734 #ifdef CONFIG_SLAB
735         create_seq_entry("slabinfo",S_IWUSR|S_IRUGO,&proc_slabinfo_operations);
736 #ifdef CONFIG_DEBUG_SLAB_LEAK
737         create_seq_entry("slab_allocators", 0 ,&proc_slabstats_operations);
738 #endif
739 #endif
740         create_seq_entry("buddyinfo",S_IRUGO, &fragmentation_file_operations);
741         create_seq_entry("vmstat",S_IRUGO, &proc_vmstat_file_operations);
742         create_seq_entry("zoneinfo",S_IRUGO, &proc_zoneinfo_file_operations);
743 #ifdef CONFIG_BLOCK
744         create_seq_entry("diskstats", 0, &proc_diskstats_operations);
745 #endif
746 #ifdef CONFIG_MODULES
747         create_seq_entry("modules", 0, &proc_modules_operations);
748 #endif
749 #ifdef CONFIG_SCHEDSTATS
750         create_seq_entry("schedstat", 0, &proc_schedstat_operations);
751 #endif
752 #ifdef CONFIG_PROC_KCORE
753         proc_root_kcore = create_proc_entry("kcore", S_IRUSR, NULL);
754         if (proc_root_kcore) {
755                 proc_root_kcore->proc_fops = &proc_kcore_operations;
756                 proc_root_kcore->size =
757                                 (size_t)high_memory - PAGE_OFFSET + PAGE_SIZE;
758         }
759 #endif
760 #ifdef CONFIG_PROC_VMCORE
761         proc_vmcore = create_proc_entry("vmcore", S_IRUSR, NULL);
762         if (proc_vmcore)
763                 proc_vmcore->proc_fops = &proc_vmcore_operations;
764 #endif
765 #ifdef CONFIG_MAGIC_SYSRQ
766         entry = create_proc_entry("sysrq-trigger", S_IWUSR, NULL);
767         if (entry)
768                 entry->proc_fops = &proc_sysrq_trigger_operations;
769 #endif
770 }