]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - fs/proc/proc_misc.c
proc: move /proc/diskstats boilerplate to block/genhd.c
[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/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 #ifdef CONFIG_MODULES
61 extern const struct seq_operations modules_op;
62 static int modules_open(struct inode *inode, struct file *file)
63 {
64         return seq_open(file, &modules_op);
65 }
66 static const struct file_operations proc_modules_operations = {
67         .open           = modules_open,
68         .read           = seq_read,
69         .llseek         = seq_lseek,
70         .release        = seq_release,
71 };
72 #endif
73
74 #ifdef CONFIG_PROC_PAGE_MONITOR
75 #define KPMSIZE sizeof(u64)
76 #define KPMMASK (KPMSIZE - 1)
77 /* /proc/kpagecount - an array exposing page counts
78  *
79  * Each entry is a u64 representing the corresponding
80  * physical page count.
81  */
82 static ssize_t kpagecount_read(struct file *file, char __user *buf,
83                              size_t count, loff_t *ppos)
84 {
85         u64 __user *out = (u64 __user *)buf;
86         struct page *ppage;
87         unsigned long src = *ppos;
88         unsigned long pfn;
89         ssize_t ret = 0;
90         u64 pcount;
91
92         pfn = src / KPMSIZE;
93         count = min_t(size_t, count, (max_pfn * KPMSIZE) - src);
94         if (src & KPMMASK || count & KPMMASK)
95                 return -EINVAL;
96
97         while (count > 0) {
98                 ppage = NULL;
99                 if (pfn_valid(pfn))
100                         ppage = pfn_to_page(pfn);
101                 pfn++;
102                 if (!ppage)
103                         pcount = 0;
104                 else
105                         pcount = page_mapcount(ppage);
106
107                 if (put_user(pcount, out++)) {
108                         ret = -EFAULT;
109                         break;
110                 }
111
112                 count -= KPMSIZE;
113         }
114
115         *ppos += (char __user *)out - buf;
116         if (!ret)
117                 ret = (char __user *)out - buf;
118         return ret;
119 }
120
121 static struct file_operations proc_kpagecount_operations = {
122         .llseek = mem_lseek,
123         .read = kpagecount_read,
124 };
125
126 /* /proc/kpageflags - an array exposing page flags
127  *
128  * Each entry is a u64 representing the corresponding
129  * physical page flags.
130  */
131
132 /* These macros are used to decouple internal flags from exported ones */
133
134 #define KPF_LOCKED     0
135 #define KPF_ERROR      1
136 #define KPF_REFERENCED 2
137 #define KPF_UPTODATE   3
138 #define KPF_DIRTY      4
139 #define KPF_LRU        5
140 #define KPF_ACTIVE     6
141 #define KPF_SLAB       7
142 #define KPF_WRITEBACK  8
143 #define KPF_RECLAIM    9
144 #define KPF_BUDDY     10
145
146 #define kpf_copy_bit(flags, srcpos, dstpos) (((flags >> srcpos) & 1) << dstpos)
147
148 static ssize_t kpageflags_read(struct file *file, char __user *buf,
149                              size_t count, loff_t *ppos)
150 {
151         u64 __user *out = (u64 __user *)buf;
152         struct page *ppage;
153         unsigned long src = *ppos;
154         unsigned long pfn;
155         ssize_t ret = 0;
156         u64 kflags, uflags;
157
158         pfn = src / KPMSIZE;
159         count = min_t(unsigned long, count, (max_pfn * KPMSIZE) - src);
160         if (src & KPMMASK || count & KPMMASK)
161                 return -EINVAL;
162
163         while (count > 0) {
164                 ppage = NULL;
165                 if (pfn_valid(pfn))
166                         ppage = pfn_to_page(pfn);
167                 pfn++;
168                 if (!ppage)
169                         kflags = 0;
170                 else
171                         kflags = ppage->flags;
172
173                 uflags = kpf_copy_bit(KPF_LOCKED, PG_locked, kflags) |
174                         kpf_copy_bit(kflags, KPF_ERROR, PG_error) |
175                         kpf_copy_bit(kflags, KPF_REFERENCED, PG_referenced) |
176                         kpf_copy_bit(kflags, KPF_UPTODATE, PG_uptodate) |
177                         kpf_copy_bit(kflags, KPF_DIRTY, PG_dirty) |
178                         kpf_copy_bit(kflags, KPF_LRU, PG_lru) |
179                         kpf_copy_bit(kflags, KPF_ACTIVE, PG_active) |
180                         kpf_copy_bit(kflags, KPF_SLAB, PG_slab) |
181                         kpf_copy_bit(kflags, KPF_WRITEBACK, PG_writeback) |
182                         kpf_copy_bit(kflags, KPF_RECLAIM, PG_reclaim) |
183                         kpf_copy_bit(kflags, KPF_BUDDY, PG_buddy);
184
185                 if (put_user(uflags, out++)) {
186                         ret = -EFAULT;
187                         break;
188                 }
189
190                 count -= KPMSIZE;
191         }
192
193         *ppos += (char __user *)out - buf;
194         if (!ret)
195                 ret = (char __user *)out - buf;
196         return ret;
197 }
198
199 static struct file_operations proc_kpageflags_operations = {
200         .llseek = mem_lseek,
201         .read = kpageflags_read,
202 };
203 #endif /* CONFIG_PROC_PAGE_MONITOR */
204
205 struct proc_dir_entry *proc_root_kcore;
206
207 void __init proc_misc_init(void)
208 {
209         proc_symlink("mounts", NULL, "self/mounts");
210
211         /* And now for trickier ones */
212 #ifdef CONFIG_MODULES
213         proc_create("modules", 0, NULL, &proc_modules_operations);
214 #endif
215 #ifdef CONFIG_SCHEDSTATS
216         proc_create("schedstat", 0, NULL, &proc_schedstat_operations);
217 #endif
218 #ifdef CONFIG_PROC_KCORE
219         proc_root_kcore = proc_create("kcore", S_IRUSR, NULL, &proc_kcore_operations);
220         if (proc_root_kcore)
221                 proc_root_kcore->size =
222                                 (size_t)high_memory - PAGE_OFFSET + PAGE_SIZE;
223 #endif
224 #ifdef CONFIG_PROC_PAGE_MONITOR
225         proc_create("kpagecount", S_IRUSR, NULL, &proc_kpagecount_operations);
226         proc_create("kpageflags", S_IRUSR, NULL, &proc_kpageflags_operations);
227 #endif
228 #ifdef CONFIG_PROC_VMCORE
229         proc_vmcore = proc_create("vmcore", S_IRUSR, NULL, &proc_vmcore_operations);
230 #endif
231 }