blob: dc3e580d1dcaa817b59dd1c1955db1ded46bb0e2 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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>
Neil Horman7170be52006-01-14 13:20:38 -080023#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#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>
Andrew Morton7bf65382006-12-08 02:41:14 -080042#include <linux/utsname.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#include <linux/blkdev.h>
44#include <linux/hugetlb.h>
45#include <linux/jiffies.h>
46#include <linux/sysrq.h>
47#include <linux/vmalloc.h>
Vivek Goyal666bfdd2005-06-25 14:58:21 -070048#include <linux/crash_dump.h>
Sukadev Bhattiprolu61a58c62006-12-08 02:37:58 -080049#include <linux/pid_namespace.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#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#define LOAD_INT(x) ((x) >> FSHIFT)
58#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100)
59/*
60 * Warning: stuff below (imported functions) assumes that its output will fit
61 * into one page. For some of those functions it may be wrong. Moreover, we
62 * have a way to deal with that gracefully. Right now I used straightforward
63 * wrappers, but this needs further analysis wrt potential overflows.
64 */
65extern int get_hardware_list(char *);
66extern int get_stram_list(char *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070067extern int get_filesystem_list(char *);
68extern int get_exec_domain_list(char *);
69extern int get_dma_list(char *);
70extern int get_locks_status (char *, char **, off_t, int);
71
72static 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
83static 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
89 a = avenrun[0] + (FIXED_1/200);
90 b = avenrun[1] + (FIXED_1/200);
91 c = avenrun[2] + (FIXED_1/200);
92 len = sprintf(page,"%d.%02d %d.%02d %d.%02d %ld/%d %d\n",
93 LOAD_INT(a), LOAD_FRAC(a),
94 LOAD_INT(b), LOAD_FRAC(b),
95 LOAD_INT(c), LOAD_FRAC(c),
Cedric Le Goater6cc1b222006-12-08 02:38:00 -080096 nr_running(), nr_threads, current->nsproxy->pid_ns->last_pid);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 return proc_calc_metrics(page, start, off, count, eof, len);
98}
99
100static int uptime_read_proc(char *page, char **start, off_t off,
101 int count, int *eof, void *data)
102{
103 struct timespec uptime;
104 struct timespec idle;
105 int len;
106 cputime_t idletime = cputime_add(init_task.utime, init_task.stime);
107
108 do_posix_clock_monotonic_gettime(&uptime);
109 cputime_to_timespec(idletime, &idle);
110 len = sprintf(page,"%lu.%02lu %lu.%02lu\n",
111 (unsigned long) uptime.tv_sec,
112 (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
113 (unsigned long) idle.tv_sec,
114 (idle.tv_nsec / (NSEC_PER_SEC / 100)));
115
116 return proc_calc_metrics(page, start, off, count, eof, len);
117}
118
119static int meminfo_read_proc(char *page, char **start, off_t off,
120 int count, int *eof, void *data)
121{
122 struct sysinfo i;
123 int len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 unsigned long inactive;
125 unsigned long active;
126 unsigned long free;
127 unsigned long committed;
128 unsigned long allowed;
129 struct vmalloc_info vmi;
Martin Hicks4c4c4022005-04-16 15:24:08 -0700130 long cached;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 get_zone_counts(&active, &inactive, &free);
133
134/*
135 * display in kilobytes.
136 */
137#define K(x) ((x) << (PAGE_SHIFT - 10))
138 si_meminfo(&i);
139 si_swapinfo(&i);
140 committed = atomic_read(&vm_committed_space);
141 allowed = ((totalram_pages - hugetlb_total_pages())
142 * sysctl_overcommit_ratio / 100) + total_swap_pages;
143
Christoph Lameter347ce432006-06-30 01:55:35 -0700144 cached = global_page_state(NR_FILE_PAGES) -
145 total_swapcache_pages - i.bufferram;
Martin Hicks4c4c4022005-04-16 15:24:08 -0700146 if (cached < 0)
147 cached = 0;
148
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 get_vmalloc_info(&vmi);
150
151 /*
152 * Tagged format, for easy grepping and expansion.
153 */
154 len = sprintf(page,
155 "MemTotal: %8lu kB\n"
156 "MemFree: %8lu kB\n"
157 "Buffers: %8lu kB\n"
158 "Cached: %8lu kB\n"
159 "SwapCached: %8lu kB\n"
160 "Active: %8lu kB\n"
161 "Inactive: %8lu kB\n"
Christoph Lameter182e8e22006-09-25 23:31:10 -0700162#ifdef CONFIG_HIGHMEM
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 "HighTotal: %8lu kB\n"
164 "HighFree: %8lu kB\n"
165 "LowTotal: %8lu kB\n"
166 "LowFree: %8lu kB\n"
Christoph Lameter182e8e22006-09-25 23:31:10 -0700167#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 "SwapTotal: %8lu kB\n"
169 "SwapFree: %8lu kB\n"
170 "Dirty: %8lu kB\n"
171 "Writeback: %8lu kB\n"
Christoph Lameterf3dbd342006-06-30 01:55:36 -0700172 "AnonPages: %8lu kB\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 "Mapped: %8lu kB\n"
174 "Slab: %8lu kB\n"
Christoph Lameter972d1a72006-09-25 23:31:51 -0700175 "SReclaimable: %8lu kB\n"
176 "SUnreclaim: %8lu kB\n"
Christoph Lameterdf849a12006-06-30 01:55:38 -0700177 "PageTables: %8lu kB\n"
Andrew Mortonf5ef68d2006-08-27 01:23:58 -0700178 "NFS_Unstable: %8lu kB\n"
Christoph Lameterd2c5e302006-06-30 01:55:41 -0700179 "Bounce: %8lu kB\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 "CommitLimit: %8lu kB\n"
181 "Committed_AS: %8lu kB\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 "VmallocTotal: %8lu kB\n"
183 "VmallocUsed: %8lu kB\n"
184 "VmallocChunk: %8lu kB\n",
185 K(i.totalram),
186 K(i.freeram),
187 K(i.bufferram),
Martin Hicks4c4c4022005-04-16 15:24:08 -0700188 K(cached),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 K(total_swapcache_pages),
190 K(active),
191 K(inactive),
Christoph Lameter182e8e22006-09-25 23:31:10 -0700192#ifdef CONFIG_HIGHMEM
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 K(i.totalhigh),
194 K(i.freehigh),
195 K(i.totalram-i.totalhigh),
196 K(i.freeram-i.freehigh),
Christoph Lameter182e8e22006-09-25 23:31:10 -0700197#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 K(i.totalswap),
199 K(i.freeswap),
Christoph Lameterb1e7a8f2006-06-30 01:55:39 -0700200 K(global_page_state(NR_FILE_DIRTY)),
Christoph Lameterce866b32006-06-30 01:55:40 -0700201 K(global_page_state(NR_WRITEBACK)),
Christoph Lameterf3dbd342006-06-30 01:55:36 -0700202 K(global_page_state(NR_ANON_PAGES)),
Christoph Lameter65ba55f2006-06-30 01:55:34 -0700203 K(global_page_state(NR_FILE_MAPPED)),
Christoph Lameter972d1a72006-09-25 23:31:51 -0700204 K(global_page_state(NR_SLAB_RECLAIMABLE) +
205 global_page_state(NR_SLAB_UNRECLAIMABLE)),
206 K(global_page_state(NR_SLAB_RECLAIMABLE)),
207 K(global_page_state(NR_SLAB_UNRECLAIMABLE)),
Christoph Lameterdf849a12006-06-30 01:55:38 -0700208 K(global_page_state(NR_PAGETABLE)),
Christoph Lameterfd39fc82006-06-30 01:55:40 -0700209 K(global_page_state(NR_UNSTABLE_NFS)),
Christoph Lameterd2c5e302006-06-30 01:55:41 -0700210 K(global_page_state(NR_BOUNCE)),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 K(allowed),
212 K(committed),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 (unsigned long)VMALLOC_TOTAL >> 10,
214 vmi.used >> 10,
215 vmi.largest_chunk >> 10
216 );
217
218 len += hugetlb_report_meminfo(page + len);
219
220 return proc_calc_metrics(page, start, off, count, eof, len);
221#undef K
222}
223
224extern struct seq_operations fragmentation_op;
225static int fragmentation_open(struct inode *inode, struct file *file)
226{
227 (void)inode;
228 return seq_open(file, &fragmentation_op);
229}
230
231static struct file_operations fragmentation_file_operations = {
232 .open = fragmentation_open,
233 .read = seq_read,
234 .llseek = seq_lseek,
235 .release = seq_release,
236};
237
Nikita Danilov295ab932005-06-21 17:14:38 -0700238extern struct seq_operations zoneinfo_op;
239static int zoneinfo_open(struct inode *inode, struct file *file)
240{
241 return seq_open(file, &zoneinfo_op);
242}
243
244static struct file_operations proc_zoneinfo_file_operations = {
245 .open = zoneinfo_open,
246 .read = seq_read,
247 .llseek = seq_lseek,
248 .release = seq_release,
249};
250
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251static int version_read_proc(char *page, char **start, off_t off,
252 int count, int *eof, void *data)
253{
254 int len;
255
Herbert Poetzla2ee8642006-12-08 02:36:00 -0800256 len = sprintf(page, linux_banner,
257 utsname()->release, utsname()->version);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 return proc_calc_metrics(page, start, off, count, eof, len);
259}
260
261extern struct seq_operations cpuinfo_op;
262static int cpuinfo_open(struct inode *inode, struct file *file)
263{
264 return seq_open(file, &cpuinfo_op);
265}
Neil Horman7170be52006-01-14 13:20:38 -0800266
Joe Korty68eef3b2006-03-31 02:30:32 -0800267static struct file_operations proc_cpuinfo_operations = {
268 .open = cpuinfo_open,
Neil Horman7170be52006-01-14 13:20:38 -0800269 .read = seq_read,
270 .llseek = seq_lseek,
271 .release = seq_release,
272};
273
Joe Korty68eef3b2006-03-31 02:30:32 -0800274static int devinfo_show(struct seq_file *f, void *v)
275{
276 int i = *(loff_t *) v;
277
278 if (i < CHRDEV_MAJOR_HASH_SIZE) {
279 if (i == 0)
280 seq_printf(f, "Character devices:\n");
281 chrdev_show(f, i);
David Howells93614012006-09-30 20:45:40 +0200282 }
283#ifdef CONFIG_BLOCK
284 else {
Joe Korty68eef3b2006-03-31 02:30:32 -0800285 i -= CHRDEV_MAJOR_HASH_SIZE;
286 if (i == 0)
287 seq_printf(f, "\nBlock devices:\n");
288 blkdev_show(f, i);
289 }
David Howells93614012006-09-30 20:45:40 +0200290#endif
Joe Korty68eef3b2006-03-31 02:30:32 -0800291 return 0;
292}
293
294static void *devinfo_start(struct seq_file *f, loff_t *pos)
295{
296 if (*pos < (BLKDEV_MAJOR_HASH_SIZE + CHRDEV_MAJOR_HASH_SIZE))
297 return pos;
298 return NULL;
299}
300
301static void *devinfo_next(struct seq_file *f, void *v, loff_t *pos)
302{
303 (*pos)++;
304 if (*pos >= (BLKDEV_MAJOR_HASH_SIZE + CHRDEV_MAJOR_HASH_SIZE))
305 return NULL;
306 return pos;
307}
308
309static void devinfo_stop(struct seq_file *f, void *v)
310{
311 /* Nothing to do */
312}
313
314static struct seq_operations devinfo_ops = {
315 .start = devinfo_start,
316 .next = devinfo_next,
317 .stop = devinfo_stop,
318 .show = devinfo_show
319};
320
321static int devinfo_open(struct inode *inode, struct file *filp)
322{
323 return seq_open(filp, &devinfo_ops);
324}
325
326static struct file_operations proc_devinfo_operations = {
327 .open = devinfo_open,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 .read = seq_read,
329 .llseek = seq_lseek,
330 .release = seq_release,
331};
332
333extern struct seq_operations vmstat_op;
334static int vmstat_open(struct inode *inode, struct file *file)
335{
336 return seq_open(file, &vmstat_op);
337}
338static struct file_operations proc_vmstat_file_operations = {
339 .open = vmstat_open,
340 .read = seq_read,
341 .llseek = seq_lseek,
342 .release = seq_release,
343};
344
345#ifdef CONFIG_PROC_HARDWARE
346static int hardware_read_proc(char *page, char **start, off_t off,
347 int count, int *eof, void *data)
348{
349 int len = get_hardware_list(page);
350 return proc_calc_metrics(page, start, off, count, eof, len);
351}
352#endif
353
354#ifdef CONFIG_STRAM_PROC
355static int stram_read_proc(char *page, char **start, off_t off,
356 int count, int *eof, void *data)
357{
358 int len = get_stram_list(page);
359 return proc_calc_metrics(page, start, off, count, eof, len);
360}
361#endif
362
David Howells93614012006-09-30 20:45:40 +0200363#ifdef CONFIG_BLOCK
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364extern struct seq_operations partitions_op;
365static int partitions_open(struct inode *inode, struct file *file)
366{
367 return seq_open(file, &partitions_op);
368}
369static struct file_operations proc_partitions_operations = {
370 .open = partitions_open,
371 .read = seq_read,
372 .llseek = seq_lseek,
373 .release = seq_release,
374};
375
376extern struct seq_operations diskstats_op;
377static int diskstats_open(struct inode *inode, struct file *file)
378{
379 return seq_open(file, &diskstats_op);
380}
381static struct file_operations proc_diskstats_operations = {
382 .open = diskstats_open,
383 .read = seq_read,
384 .llseek = seq_lseek,
385 .release = seq_release,
386};
David Howells93614012006-09-30 20:45:40 +0200387#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388
389#ifdef CONFIG_MODULES
390extern struct seq_operations modules_op;
391static int modules_open(struct inode *inode, struct file *file)
392{
393 return seq_open(file, &modules_op);
394}
395static struct file_operations proc_modules_operations = {
396 .open = modules_open,
397 .read = seq_read,
398 .llseek = seq_lseek,
399 .release = seq_release,
400};
401#endif
402
Matt Mackall10cef602006-01-08 01:01:45 -0800403#ifdef CONFIG_SLAB
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404extern struct seq_operations slabinfo_op;
405extern ssize_t slabinfo_write(struct file *, const char __user *, size_t, loff_t *);
406static int slabinfo_open(struct inode *inode, struct file *file)
407{
408 return seq_open(file, &slabinfo_op);
409}
410static struct file_operations proc_slabinfo_operations = {
411 .open = slabinfo_open,
412 .read = seq_read,
413 .write = slabinfo_write,
414 .llseek = seq_lseek,
415 .release = seq_release,
416};
Al Viro871751e2006-03-25 03:06:39 -0800417
418#ifdef CONFIG_DEBUG_SLAB_LEAK
419extern struct seq_operations slabstats_op;
420static int slabstats_open(struct inode *inode, struct file *file)
421{
422 unsigned long *n = kzalloc(PAGE_SIZE, GFP_KERNEL);
423 int ret = -ENOMEM;
424 if (n) {
425 ret = seq_open(file, &slabstats_op);
426 if (!ret) {
427 struct seq_file *m = file->private_data;
428 *n = PAGE_SIZE / (2 * sizeof(unsigned long));
429 m->private = n;
430 n = NULL;
431 }
432 kfree(n);
433 }
434 return ret;
435}
436
437static int slabstats_release(struct inode *inode, struct file *file)
438{
439 struct seq_file *m = file->private_data;
440 kfree(m->private);
441 return seq_release(inode, file);
442}
443
444static struct file_operations proc_slabstats_operations = {
445 .open = slabstats_open,
446 .read = seq_read,
447 .llseek = seq_lseek,
448 .release = slabstats_release,
449};
450#endif
Matt Mackall10cef602006-01-08 01:01:45 -0800451#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452
453static int show_stat(struct seq_file *p, void *v)
454{
455 int i;
456 unsigned long jif;
457 cputime64_t user, nice, system, idle, iowait, irq, softirq, steal;
458 u64 sum = 0;
459
460 user = nice = system = idle = iowait =
461 irq = softirq = steal = cputime64_zero;
462 jif = - wall_to_monotonic.tv_sec;
463 if (wall_to_monotonic.tv_nsec)
464 --jif;
465
KAMEZAWA Hiroyuki0a945022006-03-28 01:56:37 -0800466 for_each_possible_cpu(i) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 int j;
468
469 user = cputime64_add(user, kstat_cpu(i).cpustat.user);
470 nice = cputime64_add(nice, kstat_cpu(i).cpustat.nice);
471 system = cputime64_add(system, kstat_cpu(i).cpustat.system);
472 idle = cputime64_add(idle, kstat_cpu(i).cpustat.idle);
473 iowait = cputime64_add(iowait, kstat_cpu(i).cpustat.iowait);
474 irq = cputime64_add(irq, kstat_cpu(i).cpustat.irq);
475 softirq = cputime64_add(softirq, kstat_cpu(i).cpustat.softirq);
476 steal = cputime64_add(steal, kstat_cpu(i).cpustat.steal);
477 for (j = 0 ; j < NR_IRQS ; j++)
478 sum += kstat_cpu(i).irqs[j];
479 }
480
481 seq_printf(p, "cpu %llu %llu %llu %llu %llu %llu %llu %llu\n",
482 (unsigned long long)cputime64_to_clock_t(user),
483 (unsigned long long)cputime64_to_clock_t(nice),
484 (unsigned long long)cputime64_to_clock_t(system),
485 (unsigned long long)cputime64_to_clock_t(idle),
486 (unsigned long long)cputime64_to_clock_t(iowait),
487 (unsigned long long)cputime64_to_clock_t(irq),
488 (unsigned long long)cputime64_to_clock_t(softirq),
489 (unsigned long long)cputime64_to_clock_t(steal));
490 for_each_online_cpu(i) {
491
492 /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
493 user = kstat_cpu(i).cpustat.user;
494 nice = kstat_cpu(i).cpustat.nice;
495 system = kstat_cpu(i).cpustat.system;
496 idle = kstat_cpu(i).cpustat.idle;
497 iowait = kstat_cpu(i).cpustat.iowait;
498 irq = kstat_cpu(i).cpustat.irq;
499 softirq = kstat_cpu(i).cpustat.softirq;
500 steal = kstat_cpu(i).cpustat.steal;
501 seq_printf(p, "cpu%d %llu %llu %llu %llu %llu %llu %llu %llu\n",
502 i,
503 (unsigned long long)cputime64_to_clock_t(user),
504 (unsigned long long)cputime64_to_clock_t(nice),
505 (unsigned long long)cputime64_to_clock_t(system),
506 (unsigned long long)cputime64_to_clock_t(idle),
507 (unsigned long long)cputime64_to_clock_t(iowait),
508 (unsigned long long)cputime64_to_clock_t(irq),
509 (unsigned long long)cputime64_to_clock_t(softirq),
510 (unsigned long long)cputime64_to_clock_t(steal));
511 }
512 seq_printf(p, "intr %llu", (unsigned long long)sum);
513
schwab@suse.dea1854612006-02-03 03:04:24 -0800514#if !defined(CONFIG_PPC64) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 for (i = 0; i < NR_IRQS; i++)
516 seq_printf(p, " %u", kstat_irqs(i));
517#endif
518
519 seq_printf(p,
520 "\nctxt %llu\n"
521 "btime %lu\n"
522 "processes %lu\n"
523 "procs_running %lu\n"
524 "procs_blocked %lu\n",
525 nr_context_switches(),
526 (unsigned long)jif,
527 total_forks,
528 nr_running(),
529 nr_iowait());
530
531 return 0;
532}
533
534static int stat_open(struct inode *inode, struct file *file)
535{
536 unsigned size = 4096 * (1 + num_possible_cpus() / 32);
537 char *buf;
538 struct seq_file *m;
539 int res;
540
541 /* don't ask for more than the kmalloc() max size, currently 128 KB */
542 if (size > 128 * 1024)
543 size = 128 * 1024;
544 buf = kmalloc(size, GFP_KERNEL);
545 if (!buf)
546 return -ENOMEM;
547
548 res = single_open(file, show_stat, NULL);
549 if (!res) {
550 m = file->private_data;
551 m->buf = buf;
552 m->size = size;
553 } else
554 kfree(buf);
555 return res;
556}
557static struct file_operations proc_stat_operations = {
558 .open = stat_open,
559 .read = seq_read,
560 .llseek = seq_lseek,
561 .release = single_release,
562};
563
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564/*
565 * /proc/interrupts
566 */
567static void *int_seq_start(struct seq_file *f, loff_t *pos)
568{
569 return (*pos <= NR_IRQS) ? pos : NULL;
570}
571
572static void *int_seq_next(struct seq_file *f, void *v, loff_t *pos)
573{
574 (*pos)++;
575 if (*pos > NR_IRQS)
576 return NULL;
577 return pos;
578}
579
580static void int_seq_stop(struct seq_file *f, void *v)
581{
582 /* Nothing to do */
583}
584
585
586extern int show_interrupts(struct seq_file *f, void *v); /* In arch code */
587static struct seq_operations int_seq_ops = {
588 .start = int_seq_start,
589 .next = int_seq_next,
590 .stop = int_seq_stop,
591 .show = show_interrupts
592};
593
594static int interrupts_open(struct inode *inode, struct file *filp)
595{
596 return seq_open(filp, &int_seq_ops);
597}
598
599static struct file_operations proc_interrupts_operations = {
600 .open = interrupts_open,
601 .read = seq_read,
602 .llseek = seq_lseek,
603 .release = seq_release,
604};
605
606static int filesystems_read_proc(char *page, char **start, off_t off,
607 int count, int *eof, void *data)
608{
609 int len = get_filesystem_list(page);
610 return proc_calc_metrics(page, start, off, count, eof, len);
611}
612
613static int cmdline_read_proc(char *page, char **start, off_t off,
614 int count, int *eof, void *data)
615{
616 int len;
617
618 len = sprintf(page, "%s\n", saved_command_line);
619 return proc_calc_metrics(page, start, off, count, eof, len);
620}
621
622static int locks_read_proc(char *page, char **start, off_t off,
623 int count, int *eof, void *data)
624{
625 int len = get_locks_status(page, start, off, count);
626
627 if (len < count)
628 *eof = 1;
629 return len;
630}
631
632static int execdomains_read_proc(char *page, char **start, off_t off,
633 int count, int *eof, void *data)
634{
635 int len = get_exec_domain_list(page);
636 return proc_calc_metrics(page, start, off, count, eof, len);
637}
638
639#ifdef CONFIG_MAGIC_SYSRQ
640/*
641 * writing 'C' to /proc/sysrq-trigger is like sysrq-C
642 */
643static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
644 size_t count, loff_t *ppos)
645{
646 if (count) {
647 char c;
648
649 if (get_user(c, buf))
650 return -EFAULT;
David Howells7d12e782006-10-05 14:55:46 +0100651 __handle_sysrq(c, NULL, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 }
653 return count;
654}
655
656static struct file_operations proc_sysrq_trigger_operations = {
657 .write = write_sysrq_trigger,
658};
659#endif
660
661struct proc_dir_entry *proc_root_kcore;
662
Arjan van de Ven99ac48f2006-03-28 01:56:41 -0800663void create_seq_entry(char *name, mode_t mode, const struct file_operations *f)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664{
665 struct proc_dir_entry *entry;
666 entry = create_proc_entry(name, mode, NULL);
667 if (entry)
668 entry->proc_fops = f;
669}
670
671void __init proc_misc_init(void)
672{
673 struct proc_dir_entry *entry;
674 static struct {
675 char *name;
676 int (*read_proc)(char*,char**,off_t,int,int*,void*);
677 } *p, simple_ones[] = {
678 {"loadavg", loadavg_read_proc},
679 {"uptime", uptime_read_proc},
680 {"meminfo", meminfo_read_proc},
681 {"version", version_read_proc},
682#ifdef CONFIG_PROC_HARDWARE
683 {"hardware", hardware_read_proc},
684#endif
685#ifdef CONFIG_STRAM_PROC
686 {"stram", stram_read_proc},
687#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 {"filesystems", filesystems_read_proc},
689 {"cmdline", cmdline_read_proc},
690 {"locks", locks_read_proc},
691 {"execdomains", execdomains_read_proc},
692 {NULL,}
693 };
694 for (p = simple_ones; p->name; p++)
695 create_proc_read_entry(p->name, 0, NULL, p->read_proc, NULL);
696
697 proc_symlink("mounts", NULL, "self/mounts");
698
699 /* And now for trickier ones */
Mike Galbraithc36264d2006-12-06 20:37:42 -0800700#ifdef CONFIG_PRINTK
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 entry = create_proc_entry("kmsg", S_IRUSR, &proc_root);
702 if (entry)
703 entry->proc_fops = &proc_kmsg_operations;
Mike Galbraithc36264d2006-12-06 20:37:42 -0800704#endif
Neil Horman7170be52006-01-14 13:20:38 -0800705 create_seq_entry("devices", 0, &proc_devinfo_operations);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 create_seq_entry("cpuinfo", 0, &proc_cpuinfo_operations);
David Howells93614012006-09-30 20:45:40 +0200707#ifdef CONFIG_BLOCK
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 create_seq_entry("partitions", 0, &proc_partitions_operations);
David Howells93614012006-09-30 20:45:40 +0200709#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 create_seq_entry("stat", 0, &proc_stat_operations);
711 create_seq_entry("interrupts", 0, &proc_interrupts_operations);
Matt Mackall10cef602006-01-08 01:01:45 -0800712#ifdef CONFIG_SLAB
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 create_seq_entry("slabinfo",S_IWUSR|S_IRUGO,&proc_slabinfo_operations);
Al Viro871751e2006-03-25 03:06:39 -0800714#ifdef CONFIG_DEBUG_SLAB_LEAK
715 create_seq_entry("slab_allocators", 0 ,&proc_slabstats_operations);
716#endif
Matt Mackall10cef602006-01-08 01:01:45 -0800717#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 create_seq_entry("buddyinfo",S_IRUGO, &fragmentation_file_operations);
719 create_seq_entry("vmstat",S_IRUGO, &proc_vmstat_file_operations);
Nikita Danilov295ab932005-06-21 17:14:38 -0700720 create_seq_entry("zoneinfo",S_IRUGO, &proc_zoneinfo_file_operations);
David Howells93614012006-09-30 20:45:40 +0200721#ifdef CONFIG_BLOCK
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 create_seq_entry("diskstats", 0, &proc_diskstats_operations);
David Howells93614012006-09-30 20:45:40 +0200723#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724#ifdef CONFIG_MODULES
725 create_seq_entry("modules", 0, &proc_modules_operations);
726#endif
727#ifdef CONFIG_SCHEDSTATS
728 create_seq_entry("schedstat", 0, &proc_schedstat_operations);
729#endif
730#ifdef CONFIG_PROC_KCORE
731 proc_root_kcore = create_proc_entry("kcore", S_IRUSR, NULL);
732 if (proc_root_kcore) {
733 proc_root_kcore->proc_fops = &proc_kcore_operations;
734 proc_root_kcore->size =
735 (size_t)high_memory - PAGE_OFFSET + PAGE_SIZE;
736 }
737#endif
Vivek Goyal666bfdd2005-06-25 14:58:21 -0700738#ifdef CONFIG_PROC_VMCORE
739 proc_vmcore = create_proc_entry("vmcore", S_IRUSR, NULL);
740 if (proc_vmcore)
741 proc_vmcore->proc_fops = &proc_vmcore_operations;
742#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743#ifdef CONFIG_MAGIC_SYSRQ
744 entry = create_proc_entry("sysrq-trigger", S_IWUSR, NULL);
745 if (entry)
746 entry->proc_fops = &proc_sysrq_trigger_operations;
747#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748}