Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Neil Horman | 7170be5 | 2006-01-14 13:20:38 -0800 | [diff] [blame] | 23 | #include <linux/fs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <linux/mm.h> |
| 30 | #include <linux/mmzone.h> |
| 31 | #include <linux/pagemap.h> |
Adrian Bunk | f74596d | 2008-02-06 01:36:35 -0800 | [diff] [blame^] | 32 | #include <linux/interrupt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <linux/swap.h> |
| 34 | #include <linux/slab.h> |
| 35 | #include <linux/smp.h> |
| 36 | #include <linux/signal.h> |
| 37 | #include <linux/module.h> |
| 38 | #include <linux/init.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <linux/seq_file.h> |
| 40 | #include <linux/times.h> |
| 41 | #include <linux/profile.h> |
Andrew Morton | 7bf6538 | 2006-12-08 02:41:14 -0800 | [diff] [blame] | 42 | #include <linux/utsname.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Vivek Goyal | 666bfdd | 2005-06-25 14:58:21 -0700 | [diff] [blame] | 48 | #include <linux/crash_dump.h> |
Sukadev Bhattiprolu | 61a58c6 | 2006-12-08 02:37:58 -0800 | [diff] [blame] | 49 | #include <linux/pid_namespace.h> |
Matt Mackall | 161f47b | 2008-02-04 22:29:05 -0800 | [diff] [blame] | 50 | #include <linux/bootmem.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #include <asm/uaccess.h> |
| 52 | #include <asm/pgtable.h> |
| 53 | #include <asm/io.h> |
| 54 | #include <asm/tlb.h> |
| 55 | #include <asm/div64.h> |
| 56 | #include "internal.h" |
| 57 | |
| 58 | #define LOAD_INT(x) ((x) >> FSHIFT) |
| 59 | #define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100) |
| 60 | /* |
| 61 | * Warning: stuff below (imported functions) assumes that its output will fit |
| 62 | * into one page. For some of those functions it may be wrong. Moreover, we |
| 63 | * have a way to deal with that gracefully. Right now I used straightforward |
| 64 | * wrappers, but this needs further analysis wrt potential overflows. |
| 65 | */ |
| 66 | extern int get_hardware_list(char *); |
| 67 | extern int get_stram_list(char *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | extern int get_filesystem_list(char *); |
| 69 | extern int get_exec_domain_list(char *); |
| 70 | extern int get_dma_list(char *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
| 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), |
Sukadev Bhattiprolu | 2894d650 | 2007-10-18 23:39:49 -0700 | [diff] [blame] | 96 | nr_running(), nr_threads, |
| 97 | task_active_pid_ns(current)->last_pid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | return proc_calc_metrics(page, start, off, count, eof, len); |
| 99 | } |
| 100 | |
| 101 | static int uptime_read_proc(char *page, char **start, off_t off, |
| 102 | int count, int *eof, void *data) |
| 103 | { |
| 104 | struct timespec uptime; |
| 105 | struct timespec idle; |
| 106 | int len; |
| 107 | cputime_t idletime = cputime_add(init_task.utime, init_task.stime); |
| 108 | |
| 109 | do_posix_clock_monotonic_gettime(&uptime); |
Tomas Janousek | d621414 | 2007-07-15 23:39:42 -0700 | [diff] [blame] | 110 | monotonic_to_bootbased(&uptime); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | cputime_to_timespec(idletime, &idle); |
| 112 | len = sprintf(page,"%lu.%02lu %lu.%02lu\n", |
| 113 | (unsigned long) uptime.tv_sec, |
| 114 | (uptime.tv_nsec / (NSEC_PER_SEC / 100)), |
| 115 | (unsigned long) idle.tv_sec, |
| 116 | (idle.tv_nsec / (NSEC_PER_SEC / 100))); |
| 117 | |
| 118 | return proc_calc_metrics(page, start, off, count, eof, len); |
| 119 | } |
| 120 | |
| 121 | static int meminfo_read_proc(char *page, char **start, off_t off, |
| 122 | int count, int *eof, void *data) |
| 123 | { |
| 124 | struct sysinfo i; |
| 125 | int len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | unsigned long committed; |
| 127 | unsigned long allowed; |
| 128 | struct vmalloc_info vmi; |
Martin Hicks | 4c4c402 | 2005-04-16 15:24:08 -0700 | [diff] [blame] | 129 | long cached; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | /* |
| 132 | * display in kilobytes. |
| 133 | */ |
| 134 | #define K(x) ((x) << (PAGE_SHIFT - 10)) |
| 135 | si_meminfo(&i); |
| 136 | si_swapinfo(&i); |
| 137 | committed = atomic_read(&vm_committed_space); |
| 138 | allowed = ((totalram_pages - hugetlb_total_pages()) |
| 139 | * sysctl_overcommit_ratio / 100) + total_swap_pages; |
| 140 | |
Christoph Lameter | 347ce43 | 2006-06-30 01:55:35 -0700 | [diff] [blame] | 141 | cached = global_page_state(NR_FILE_PAGES) - |
| 142 | total_swapcache_pages - i.bufferram; |
Martin Hicks | 4c4c402 | 2005-04-16 15:24:08 -0700 | [diff] [blame] | 143 | if (cached < 0) |
| 144 | cached = 0; |
| 145 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | get_vmalloc_info(&vmi); |
| 147 | |
| 148 | /* |
| 149 | * Tagged format, for easy grepping and expansion. |
| 150 | */ |
| 151 | len = sprintf(page, |
| 152 | "MemTotal: %8lu kB\n" |
| 153 | "MemFree: %8lu kB\n" |
| 154 | "Buffers: %8lu kB\n" |
| 155 | "Cached: %8lu kB\n" |
| 156 | "SwapCached: %8lu kB\n" |
| 157 | "Active: %8lu kB\n" |
| 158 | "Inactive: %8lu kB\n" |
Christoph Lameter | 182e8e2 | 2006-09-25 23:31:10 -0700 | [diff] [blame] | 159 | #ifdef CONFIG_HIGHMEM |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | "HighTotal: %8lu kB\n" |
| 161 | "HighFree: %8lu kB\n" |
| 162 | "LowTotal: %8lu kB\n" |
| 163 | "LowFree: %8lu kB\n" |
Christoph Lameter | 182e8e2 | 2006-09-25 23:31:10 -0700 | [diff] [blame] | 164 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | "SwapTotal: %8lu kB\n" |
| 166 | "SwapFree: %8lu kB\n" |
| 167 | "Dirty: %8lu kB\n" |
| 168 | "Writeback: %8lu kB\n" |
Christoph Lameter | f3dbd34 | 2006-06-30 01:55:36 -0700 | [diff] [blame] | 169 | "AnonPages: %8lu kB\n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | "Mapped: %8lu kB\n" |
| 171 | "Slab: %8lu kB\n" |
Christoph Lameter | 972d1a7 | 2006-09-25 23:31:51 -0700 | [diff] [blame] | 172 | "SReclaimable: %8lu kB\n" |
| 173 | "SUnreclaim: %8lu kB\n" |
Christoph Lameter | df849a1 | 2006-06-30 01:55:38 -0700 | [diff] [blame] | 174 | "PageTables: %8lu kB\n" |
Andrew Morton | f5ef68d | 2006-08-27 01:23:58 -0700 | [diff] [blame] | 175 | "NFS_Unstable: %8lu kB\n" |
Christoph Lameter | d2c5e30 | 2006-06-30 01:55:41 -0700 | [diff] [blame] | 176 | "Bounce: %8lu kB\n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | "CommitLimit: %8lu kB\n" |
| 178 | "Committed_AS: %8lu kB\n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | "VmallocTotal: %8lu kB\n" |
| 180 | "VmallocUsed: %8lu kB\n" |
| 181 | "VmallocChunk: %8lu kB\n", |
| 182 | K(i.totalram), |
| 183 | K(i.freeram), |
| 184 | K(i.bufferram), |
Martin Hicks | 4c4c402 | 2005-04-16 15:24:08 -0700 | [diff] [blame] | 185 | K(cached), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | K(total_swapcache_pages), |
Christoph Lameter | 65e458d4 | 2007-02-10 01:43:05 -0800 | [diff] [blame] | 187 | K(global_page_state(NR_ACTIVE)), |
| 188 | K(global_page_state(NR_INACTIVE)), |
Christoph Lameter | 182e8e2 | 2006-09-25 23:31:10 -0700 | [diff] [blame] | 189 | #ifdef CONFIG_HIGHMEM |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | K(i.totalhigh), |
| 191 | K(i.freehigh), |
| 192 | K(i.totalram-i.totalhigh), |
| 193 | K(i.freeram-i.freehigh), |
Christoph Lameter | 182e8e2 | 2006-09-25 23:31:10 -0700 | [diff] [blame] | 194 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | K(i.totalswap), |
| 196 | K(i.freeswap), |
Christoph Lameter | b1e7a8f | 2006-06-30 01:55:39 -0700 | [diff] [blame] | 197 | K(global_page_state(NR_FILE_DIRTY)), |
Christoph Lameter | ce866b3 | 2006-06-30 01:55:40 -0700 | [diff] [blame] | 198 | K(global_page_state(NR_WRITEBACK)), |
Christoph Lameter | f3dbd34 | 2006-06-30 01:55:36 -0700 | [diff] [blame] | 199 | K(global_page_state(NR_ANON_PAGES)), |
Christoph Lameter | 65ba55f | 2006-06-30 01:55:34 -0700 | [diff] [blame] | 200 | K(global_page_state(NR_FILE_MAPPED)), |
Christoph Lameter | 972d1a7 | 2006-09-25 23:31:51 -0700 | [diff] [blame] | 201 | K(global_page_state(NR_SLAB_RECLAIMABLE) + |
| 202 | global_page_state(NR_SLAB_UNRECLAIMABLE)), |
| 203 | K(global_page_state(NR_SLAB_RECLAIMABLE)), |
| 204 | K(global_page_state(NR_SLAB_UNRECLAIMABLE)), |
Christoph Lameter | df849a1 | 2006-06-30 01:55:38 -0700 | [diff] [blame] | 205 | K(global_page_state(NR_PAGETABLE)), |
Christoph Lameter | fd39fc8 | 2006-06-30 01:55:40 -0700 | [diff] [blame] | 206 | K(global_page_state(NR_UNSTABLE_NFS)), |
Christoph Lameter | d2c5e30 | 2006-06-30 01:55:41 -0700 | [diff] [blame] | 207 | K(global_page_state(NR_BOUNCE)), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | K(allowed), |
| 209 | K(committed), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | (unsigned long)VMALLOC_TOTAL >> 10, |
| 211 | vmi.used >> 10, |
| 212 | vmi.largest_chunk >> 10 |
| 213 | ); |
| 214 | |
| 215 | len += hugetlb_report_meminfo(page + len); |
| 216 | |
| 217 | return proc_calc_metrics(page, start, off, count, eof, len); |
| 218 | #undef K |
| 219 | } |
| 220 | |
| 221 | extern struct seq_operations fragmentation_op; |
| 222 | static int fragmentation_open(struct inode *inode, struct file *file) |
| 223 | { |
| 224 | (void)inode; |
| 225 | return seq_open(file, &fragmentation_op); |
| 226 | } |
| 227 | |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 228 | static const struct file_operations fragmentation_file_operations = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | .open = fragmentation_open, |
| 230 | .read = seq_read, |
| 231 | .llseek = seq_lseek, |
| 232 | .release = seq_release, |
| 233 | }; |
| 234 | |
Mel Gorman | 467c996 | 2007-10-16 01:26:02 -0700 | [diff] [blame] | 235 | extern struct seq_operations pagetypeinfo_op; |
| 236 | static int pagetypeinfo_open(struct inode *inode, struct file *file) |
| 237 | { |
| 238 | return seq_open(file, &pagetypeinfo_op); |
| 239 | } |
| 240 | |
| 241 | static const struct file_operations pagetypeinfo_file_ops = { |
| 242 | .open = pagetypeinfo_open, |
| 243 | .read = seq_read, |
| 244 | .llseek = seq_lseek, |
| 245 | .release = seq_release, |
| 246 | }; |
| 247 | |
Nikita Danilov | 295ab93 | 2005-06-21 17:14:38 -0700 | [diff] [blame] | 248 | extern struct seq_operations zoneinfo_op; |
| 249 | static int zoneinfo_open(struct inode *inode, struct file *file) |
| 250 | { |
| 251 | return seq_open(file, &zoneinfo_op); |
| 252 | } |
| 253 | |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 254 | static const struct file_operations proc_zoneinfo_file_operations = { |
Nikita Danilov | 295ab93 | 2005-06-21 17:14:38 -0700 | [diff] [blame] | 255 | .open = zoneinfo_open, |
| 256 | .read = seq_read, |
| 257 | .llseek = seq_lseek, |
| 258 | .release = seq_release, |
| 259 | }; |
| 260 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | static int version_read_proc(char *page, char **start, off_t off, |
| 262 | int count, int *eof, void *data) |
| 263 | { |
| 264 | int len; |
| 265 | |
Roman Zippel | 3eb3c74 | 2007-01-10 14:45:28 +0100 | [diff] [blame] | 266 | len = snprintf(page, PAGE_SIZE, linux_proc_banner, |
Linus Torvalds | 8993780 | 2006-12-11 09:28:46 -0800 | [diff] [blame] | 267 | utsname()->sysname, |
| 268 | utsname()->release, |
| 269 | utsname()->version); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | return proc_calc_metrics(page, start, off, count, eof, len); |
| 271 | } |
| 272 | |
| 273 | extern struct seq_operations cpuinfo_op; |
| 274 | static int cpuinfo_open(struct inode *inode, struct file *file) |
| 275 | { |
| 276 | return seq_open(file, &cpuinfo_op); |
| 277 | } |
Neil Horman | 7170be5 | 2006-01-14 13:20:38 -0800 | [diff] [blame] | 278 | |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 279 | static const struct file_operations proc_cpuinfo_operations = { |
Joe Korty | 68eef3b | 2006-03-31 02:30:32 -0800 | [diff] [blame] | 280 | .open = cpuinfo_open, |
Neil Horman | 7170be5 | 2006-01-14 13:20:38 -0800 | [diff] [blame] | 281 | .read = seq_read, |
| 282 | .llseek = seq_lseek, |
| 283 | .release = seq_release, |
| 284 | }; |
| 285 | |
Joe Korty | 68eef3b | 2006-03-31 02:30:32 -0800 | [diff] [blame] | 286 | static int devinfo_show(struct seq_file *f, void *v) |
| 287 | { |
| 288 | int i = *(loff_t *) v; |
| 289 | |
| 290 | if (i < CHRDEV_MAJOR_HASH_SIZE) { |
| 291 | if (i == 0) |
| 292 | seq_printf(f, "Character devices:\n"); |
| 293 | chrdev_show(f, i); |
David Howells | 9361401 | 2006-09-30 20:45:40 +0200 | [diff] [blame] | 294 | } |
| 295 | #ifdef CONFIG_BLOCK |
| 296 | else { |
Joe Korty | 68eef3b | 2006-03-31 02:30:32 -0800 | [diff] [blame] | 297 | i -= CHRDEV_MAJOR_HASH_SIZE; |
| 298 | if (i == 0) |
| 299 | seq_printf(f, "\nBlock devices:\n"); |
| 300 | blkdev_show(f, i); |
| 301 | } |
David Howells | 9361401 | 2006-09-30 20:45:40 +0200 | [diff] [blame] | 302 | #endif |
Joe Korty | 68eef3b | 2006-03-31 02:30:32 -0800 | [diff] [blame] | 303 | return 0; |
| 304 | } |
| 305 | |
| 306 | static void *devinfo_start(struct seq_file *f, loff_t *pos) |
| 307 | { |
| 308 | if (*pos < (BLKDEV_MAJOR_HASH_SIZE + CHRDEV_MAJOR_HASH_SIZE)) |
| 309 | return pos; |
| 310 | return NULL; |
| 311 | } |
| 312 | |
| 313 | static void *devinfo_next(struct seq_file *f, void *v, loff_t *pos) |
| 314 | { |
| 315 | (*pos)++; |
| 316 | if (*pos >= (BLKDEV_MAJOR_HASH_SIZE + CHRDEV_MAJOR_HASH_SIZE)) |
| 317 | return NULL; |
| 318 | return pos; |
| 319 | } |
| 320 | |
| 321 | static void devinfo_stop(struct seq_file *f, void *v) |
| 322 | { |
| 323 | /* Nothing to do */ |
| 324 | } |
| 325 | |
| 326 | static struct seq_operations devinfo_ops = { |
| 327 | .start = devinfo_start, |
| 328 | .next = devinfo_next, |
| 329 | .stop = devinfo_stop, |
| 330 | .show = devinfo_show |
| 331 | }; |
| 332 | |
| 333 | static int devinfo_open(struct inode *inode, struct file *filp) |
| 334 | { |
| 335 | return seq_open(filp, &devinfo_ops); |
| 336 | } |
| 337 | |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 338 | static const struct file_operations proc_devinfo_operations = { |
Joe Korty | 68eef3b | 2006-03-31 02:30:32 -0800 | [diff] [blame] | 339 | .open = devinfo_open, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | .read = seq_read, |
| 341 | .llseek = seq_lseek, |
| 342 | .release = seq_release, |
| 343 | }; |
| 344 | |
| 345 | extern struct seq_operations vmstat_op; |
| 346 | static int vmstat_open(struct inode *inode, struct file *file) |
| 347 | { |
| 348 | return seq_open(file, &vmstat_op); |
| 349 | } |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 350 | static const struct file_operations proc_vmstat_file_operations = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | .open = vmstat_open, |
| 352 | .read = seq_read, |
| 353 | .llseek = seq_lseek, |
| 354 | .release = seq_release, |
| 355 | }; |
| 356 | |
| 357 | #ifdef CONFIG_PROC_HARDWARE |
| 358 | static int hardware_read_proc(char *page, char **start, off_t off, |
| 359 | int count, int *eof, void *data) |
| 360 | { |
| 361 | int len = get_hardware_list(page); |
| 362 | return proc_calc_metrics(page, start, off, count, eof, len); |
| 363 | } |
| 364 | #endif |
| 365 | |
| 366 | #ifdef CONFIG_STRAM_PROC |
| 367 | static int stram_read_proc(char *page, char **start, off_t off, |
| 368 | int count, int *eof, void *data) |
| 369 | { |
| 370 | int len = get_stram_list(page); |
| 371 | return proc_calc_metrics(page, start, off, count, eof, len); |
| 372 | } |
| 373 | #endif |
| 374 | |
David Howells | 9361401 | 2006-09-30 20:45:40 +0200 | [diff] [blame] | 375 | #ifdef CONFIG_BLOCK |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | extern struct seq_operations partitions_op; |
| 377 | static int partitions_open(struct inode *inode, struct file *file) |
| 378 | { |
| 379 | return seq_open(file, &partitions_op); |
| 380 | } |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 381 | static const struct file_operations proc_partitions_operations = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | .open = partitions_open, |
| 383 | .read = seq_read, |
| 384 | .llseek = seq_lseek, |
| 385 | .release = seq_release, |
| 386 | }; |
| 387 | |
| 388 | extern struct seq_operations diskstats_op; |
| 389 | static int diskstats_open(struct inode *inode, struct file *file) |
| 390 | { |
| 391 | return seq_open(file, &diskstats_op); |
| 392 | } |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 393 | static const struct file_operations proc_diskstats_operations = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | .open = diskstats_open, |
| 395 | .read = seq_read, |
| 396 | .llseek = seq_lseek, |
| 397 | .release = seq_release, |
| 398 | }; |
David Howells | 9361401 | 2006-09-30 20:45:40 +0200 | [diff] [blame] | 399 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | |
| 401 | #ifdef CONFIG_MODULES |
| 402 | extern struct seq_operations modules_op; |
| 403 | static int modules_open(struct inode *inode, struct file *file) |
| 404 | { |
| 405 | return seq_open(file, &modules_op); |
| 406 | } |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 407 | static const struct file_operations proc_modules_operations = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | .open = modules_open, |
| 409 | .read = seq_read, |
| 410 | .llseek = seq_lseek, |
| 411 | .release = seq_release, |
| 412 | }; |
| 413 | #endif |
| 414 | |
Linus Torvalds | 158a962 | 2008-01-02 13:04:48 -0800 | [diff] [blame] | 415 | #ifdef CONFIG_SLABINFO |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | static int slabinfo_open(struct inode *inode, struct file *file) |
| 417 | { |
| 418 | return seq_open(file, &slabinfo_op); |
| 419 | } |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 420 | static const struct file_operations proc_slabinfo_operations = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | .open = slabinfo_open, |
| 422 | .read = seq_read, |
| 423 | .write = slabinfo_write, |
| 424 | .llseek = seq_lseek, |
| 425 | .release = seq_release, |
| 426 | }; |
Al Viro | 871751e | 2006-03-25 03:06:39 -0800 | [diff] [blame] | 427 | |
| 428 | #ifdef CONFIG_DEBUG_SLAB_LEAK |
| 429 | extern struct seq_operations slabstats_op; |
| 430 | static int slabstats_open(struct inode *inode, struct file *file) |
| 431 | { |
| 432 | unsigned long *n = kzalloc(PAGE_SIZE, GFP_KERNEL); |
| 433 | int ret = -ENOMEM; |
| 434 | if (n) { |
| 435 | ret = seq_open(file, &slabstats_op); |
| 436 | if (!ret) { |
| 437 | struct seq_file *m = file->private_data; |
| 438 | *n = PAGE_SIZE / (2 * sizeof(unsigned long)); |
| 439 | m->private = n; |
| 440 | n = NULL; |
| 441 | } |
| 442 | kfree(n); |
| 443 | } |
| 444 | return ret; |
| 445 | } |
| 446 | |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 447 | static const struct file_operations proc_slabstats_operations = { |
Al Viro | 871751e | 2006-03-25 03:06:39 -0800 | [diff] [blame] | 448 | .open = slabstats_open, |
| 449 | .read = seq_read, |
| 450 | .llseek = seq_lseek, |
Martin Peschke | 09f0892 | 2007-05-08 00:29:26 -0700 | [diff] [blame] | 451 | .release = seq_release_private, |
Al Viro | 871751e | 2006-03-25 03:06:39 -0800 | [diff] [blame] | 452 | }; |
| 453 | #endif |
Matt Mackall | 10cef60 | 2006-01-08 01:01:45 -0800 | [diff] [blame] | 454 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | |
| 456 | static int show_stat(struct seq_file *p, void *v) |
| 457 | { |
| 458 | int i; |
| 459 | unsigned long jif; |
| 460 | cputime64_t user, nice, system, idle, iowait, irq, softirq, steal; |
Laurent Vivier | 5e84cfd | 2007-10-15 17:00:19 +0200 | [diff] [blame] | 461 | cputime64_t guest; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | u64 sum = 0; |
Tomas Janousek | 924b42d | 2007-07-15 23:39:42 -0700 | [diff] [blame] | 463 | struct timespec boottime; |
Ravikiran G Thirumalai | 4004c69 | 2007-07-19 01:47:53 -0700 | [diff] [blame] | 464 | unsigned int *per_irq_sum; |
| 465 | |
| 466 | per_irq_sum = kzalloc(sizeof(unsigned int)*NR_IRQS, GFP_KERNEL); |
| 467 | if (!per_irq_sum) |
| 468 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | |
| 470 | user = nice = system = idle = iowait = |
| 471 | irq = softirq = steal = cputime64_zero; |
Laurent Vivier | 5e84cfd | 2007-10-15 17:00:19 +0200 | [diff] [blame] | 472 | guest = cputime64_zero; |
Tomas Janousek | 924b42d | 2007-07-15 23:39:42 -0700 | [diff] [blame] | 473 | getboottime(&boottime); |
| 474 | jif = boottime.tv_sec; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | |
KAMEZAWA Hiroyuki | 0a94502 | 2006-03-28 01:56:37 -0800 | [diff] [blame] | 476 | for_each_possible_cpu(i) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | int j; |
| 478 | |
| 479 | user = cputime64_add(user, kstat_cpu(i).cpustat.user); |
| 480 | nice = cputime64_add(nice, kstat_cpu(i).cpustat.nice); |
| 481 | system = cputime64_add(system, kstat_cpu(i).cpustat.system); |
| 482 | idle = cputime64_add(idle, kstat_cpu(i).cpustat.idle); |
| 483 | iowait = cputime64_add(iowait, kstat_cpu(i).cpustat.iowait); |
| 484 | irq = cputime64_add(irq, kstat_cpu(i).cpustat.irq); |
| 485 | softirq = cputime64_add(softirq, kstat_cpu(i).cpustat.softirq); |
| 486 | steal = cputime64_add(steal, kstat_cpu(i).cpustat.steal); |
Laurent Vivier | 5e84cfd | 2007-10-15 17:00:19 +0200 | [diff] [blame] | 487 | guest = cputime64_add(guest, kstat_cpu(i).cpustat.guest); |
Ravikiran G Thirumalai | 4004c69 | 2007-07-19 01:47:53 -0700 | [diff] [blame] | 488 | for (j = 0; j < NR_IRQS; j++) { |
| 489 | unsigned int temp = kstat_cpu(i).irqs[j]; |
| 490 | sum += temp; |
| 491 | per_irq_sum[j] += temp; |
| 492 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | } |
| 494 | |
Laurent Vivier | 5e84cfd | 2007-10-15 17:00:19 +0200 | [diff] [blame] | 495 | seq_printf(p, "cpu %llu %llu %llu %llu %llu %llu %llu %llu %llu\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | (unsigned long long)cputime64_to_clock_t(user), |
| 497 | (unsigned long long)cputime64_to_clock_t(nice), |
| 498 | (unsigned long long)cputime64_to_clock_t(system), |
| 499 | (unsigned long long)cputime64_to_clock_t(idle), |
| 500 | (unsigned long long)cputime64_to_clock_t(iowait), |
| 501 | (unsigned long long)cputime64_to_clock_t(irq), |
| 502 | (unsigned long long)cputime64_to_clock_t(softirq), |
Laurent Vivier | 5e84cfd | 2007-10-15 17:00:19 +0200 | [diff] [blame] | 503 | (unsigned long long)cputime64_to_clock_t(steal), |
| 504 | (unsigned long long)cputime64_to_clock_t(guest)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | for_each_online_cpu(i) { |
| 506 | |
| 507 | /* Copy values here to work around gcc-2.95.3, gcc-2.96 */ |
| 508 | user = kstat_cpu(i).cpustat.user; |
| 509 | nice = kstat_cpu(i).cpustat.nice; |
| 510 | system = kstat_cpu(i).cpustat.system; |
| 511 | idle = kstat_cpu(i).cpustat.idle; |
| 512 | iowait = kstat_cpu(i).cpustat.iowait; |
| 513 | irq = kstat_cpu(i).cpustat.irq; |
| 514 | softirq = kstat_cpu(i).cpustat.softirq; |
| 515 | steal = kstat_cpu(i).cpustat.steal; |
Laurent Vivier | 5e84cfd | 2007-10-15 17:00:19 +0200 | [diff] [blame] | 516 | guest = kstat_cpu(i).cpustat.guest; |
| 517 | seq_printf(p, |
| 518 | "cpu%d %llu %llu %llu %llu %llu %llu %llu %llu %llu\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | i, |
| 520 | (unsigned long long)cputime64_to_clock_t(user), |
| 521 | (unsigned long long)cputime64_to_clock_t(nice), |
| 522 | (unsigned long long)cputime64_to_clock_t(system), |
| 523 | (unsigned long long)cputime64_to_clock_t(idle), |
| 524 | (unsigned long long)cputime64_to_clock_t(iowait), |
| 525 | (unsigned long long)cputime64_to_clock_t(irq), |
| 526 | (unsigned long long)cputime64_to_clock_t(softirq), |
Laurent Vivier | 5e84cfd | 2007-10-15 17:00:19 +0200 | [diff] [blame] | 527 | (unsigned long long)cputime64_to_clock_t(steal), |
| 528 | (unsigned long long)cputime64_to_clock_t(guest)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | } |
| 530 | seq_printf(p, "intr %llu", (unsigned long long)sum); |
| 531 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | for (i = 0; i < NR_IRQS; i++) |
Ravikiran G Thirumalai | 4004c69 | 2007-07-19 01:47:53 -0700 | [diff] [blame] | 533 | seq_printf(p, " %u", per_irq_sum[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | |
| 535 | seq_printf(p, |
| 536 | "\nctxt %llu\n" |
| 537 | "btime %lu\n" |
| 538 | "processes %lu\n" |
| 539 | "procs_running %lu\n" |
| 540 | "procs_blocked %lu\n", |
| 541 | nr_context_switches(), |
| 542 | (unsigned long)jif, |
| 543 | total_forks, |
| 544 | nr_running(), |
| 545 | nr_iowait()); |
| 546 | |
Ravikiran G Thirumalai | 4004c69 | 2007-07-19 01:47:53 -0700 | [diff] [blame] | 547 | kfree(per_irq_sum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | return 0; |
| 549 | } |
| 550 | |
| 551 | static int stat_open(struct inode *inode, struct file *file) |
| 552 | { |
| 553 | unsigned size = 4096 * (1 + num_possible_cpus() / 32); |
| 554 | char *buf; |
| 555 | struct seq_file *m; |
| 556 | int res; |
| 557 | |
| 558 | /* don't ask for more than the kmalloc() max size, currently 128 KB */ |
| 559 | if (size > 128 * 1024) |
| 560 | size = 128 * 1024; |
| 561 | buf = kmalloc(size, GFP_KERNEL); |
| 562 | if (!buf) |
| 563 | return -ENOMEM; |
| 564 | |
| 565 | res = single_open(file, show_stat, NULL); |
| 566 | if (!res) { |
| 567 | m = file->private_data; |
| 568 | m->buf = buf; |
| 569 | m->size = size; |
| 570 | } else |
| 571 | kfree(buf); |
| 572 | return res; |
| 573 | } |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 574 | static const struct file_operations proc_stat_operations = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | .open = stat_open, |
| 576 | .read = seq_read, |
| 577 | .llseek = seq_lseek, |
| 578 | .release = single_release, |
| 579 | }; |
| 580 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | /* |
| 582 | * /proc/interrupts |
| 583 | */ |
| 584 | static void *int_seq_start(struct seq_file *f, loff_t *pos) |
| 585 | { |
| 586 | return (*pos <= NR_IRQS) ? pos : NULL; |
| 587 | } |
| 588 | |
| 589 | static void *int_seq_next(struct seq_file *f, void *v, loff_t *pos) |
| 590 | { |
| 591 | (*pos)++; |
| 592 | if (*pos > NR_IRQS) |
| 593 | return NULL; |
| 594 | return pos; |
| 595 | } |
| 596 | |
| 597 | static void int_seq_stop(struct seq_file *f, void *v) |
| 598 | { |
| 599 | /* Nothing to do */ |
| 600 | } |
| 601 | |
| 602 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | static struct seq_operations int_seq_ops = { |
| 604 | .start = int_seq_start, |
| 605 | .next = int_seq_next, |
| 606 | .stop = int_seq_stop, |
| 607 | .show = show_interrupts |
| 608 | }; |
| 609 | |
| 610 | static int interrupts_open(struct inode *inode, struct file *filp) |
| 611 | { |
| 612 | return seq_open(filp, &int_seq_ops); |
| 613 | } |
| 614 | |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 615 | static const struct file_operations proc_interrupts_operations = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | .open = interrupts_open, |
| 617 | .read = seq_read, |
| 618 | .llseek = seq_lseek, |
| 619 | .release = seq_release, |
| 620 | }; |
| 621 | |
| 622 | static int filesystems_read_proc(char *page, char **start, off_t off, |
| 623 | int count, int *eof, void *data) |
| 624 | { |
| 625 | int len = get_filesystem_list(page); |
| 626 | return proc_calc_metrics(page, start, off, count, eof, len); |
| 627 | } |
| 628 | |
| 629 | static int cmdline_read_proc(char *page, char **start, off_t off, |
| 630 | int count, int *eof, void *data) |
| 631 | { |
| 632 | int len; |
| 633 | |
| 634 | len = sprintf(page, "%s\n", saved_command_line); |
| 635 | return proc_calc_metrics(page, start, off, count, eof, len); |
| 636 | } |
| 637 | |
Pavel Emelyanov | 7f8ada9 | 2007-10-01 14:41:15 -0700 | [diff] [blame] | 638 | static int locks_open(struct inode *inode, struct file *filp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | { |
Pavel Emelyanov | 7f8ada9 | 2007-10-01 14:41:15 -0700 | [diff] [blame] | 640 | return seq_open(filp, &locks_seq_operations); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | } |
| 642 | |
Pavel Emelyanov | 7f8ada9 | 2007-10-01 14:41:15 -0700 | [diff] [blame] | 643 | static const struct file_operations proc_locks_operations = { |
| 644 | .open = locks_open, |
| 645 | .read = seq_read, |
| 646 | .llseek = seq_lseek, |
| 647 | .release = seq_release, |
| 648 | }; |
| 649 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | static int execdomains_read_proc(char *page, char **start, off_t off, |
| 651 | int count, int *eof, void *data) |
| 652 | { |
| 653 | int len = get_exec_domain_list(page); |
| 654 | return proc_calc_metrics(page, start, off, count, eof, len); |
| 655 | } |
| 656 | |
| 657 | #ifdef CONFIG_MAGIC_SYSRQ |
| 658 | /* |
| 659 | * writing 'C' to /proc/sysrq-trigger is like sysrq-C |
| 660 | */ |
| 661 | static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf, |
| 662 | size_t count, loff_t *ppos) |
| 663 | { |
| 664 | if (count) { |
| 665 | char c; |
| 666 | |
| 667 | if (get_user(c, buf)) |
| 668 | return -EFAULT; |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 669 | __handle_sysrq(c, NULL, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | } |
| 671 | return count; |
| 672 | } |
| 673 | |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 674 | static const struct file_operations proc_sysrq_trigger_operations = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | .write = write_sysrq_trigger, |
| 676 | }; |
| 677 | #endif |
| 678 | |
Matt Mackall | 1e88328 | 2008-02-04 22:29:07 -0800 | [diff] [blame] | 679 | #ifdef CONFIG_PROC_PAGE_MONITOR |
Matt Mackall | 161f47b | 2008-02-04 22:29:05 -0800 | [diff] [blame] | 680 | #define KPMSIZE sizeof(u64) |
| 681 | #define KPMMASK (KPMSIZE - 1) |
| 682 | /* /proc/kpagecount - an array exposing page counts |
| 683 | * |
| 684 | * Each entry is a u64 representing the corresponding |
| 685 | * physical page count. |
| 686 | */ |
| 687 | static ssize_t kpagecount_read(struct file *file, char __user *buf, |
| 688 | size_t count, loff_t *ppos) |
| 689 | { |
| 690 | u64 __user *out = (u64 __user *)buf; |
| 691 | struct page *ppage; |
| 692 | unsigned long src = *ppos; |
| 693 | unsigned long pfn; |
| 694 | ssize_t ret = 0; |
| 695 | u64 pcount; |
| 696 | |
| 697 | pfn = src / KPMSIZE; |
| 698 | count = min_t(size_t, count, (max_pfn * KPMSIZE) - src); |
| 699 | if (src & KPMMASK || count & KPMMASK) |
| 700 | return -EIO; |
| 701 | |
| 702 | while (count > 0) { |
Matt Mackall | 304daa8 | 2008-02-04 22:29:06 -0800 | [diff] [blame] | 703 | ppage = NULL; |
| 704 | if (pfn_valid(pfn)) |
| 705 | ppage = pfn_to_page(pfn); |
| 706 | pfn++; |
Matt Mackall | 161f47b | 2008-02-04 22:29:05 -0800 | [diff] [blame] | 707 | if (!ppage) |
| 708 | pcount = 0; |
| 709 | else |
| 710 | pcount = atomic_read(&ppage->_count); |
| 711 | |
| 712 | if (put_user(pcount, out++)) { |
| 713 | ret = -EFAULT; |
| 714 | break; |
| 715 | } |
| 716 | |
| 717 | count -= KPMSIZE; |
| 718 | } |
| 719 | |
| 720 | *ppos += (char __user *)out - buf; |
| 721 | if (!ret) |
| 722 | ret = (char __user *)out - buf; |
| 723 | return ret; |
| 724 | } |
| 725 | |
| 726 | static struct file_operations proc_kpagecount_operations = { |
| 727 | .llseek = mem_lseek, |
| 728 | .read = kpagecount_read, |
| 729 | }; |
| 730 | |
Matt Mackall | 304daa8 | 2008-02-04 22:29:06 -0800 | [diff] [blame] | 731 | /* /proc/kpageflags - an array exposing page flags |
| 732 | * |
| 733 | * Each entry is a u64 representing the corresponding |
| 734 | * physical page flags. |
| 735 | */ |
| 736 | |
| 737 | /* These macros are used to decouple internal flags from exported ones */ |
| 738 | |
| 739 | #define KPF_LOCKED 0 |
| 740 | #define KPF_ERROR 1 |
| 741 | #define KPF_REFERENCED 2 |
| 742 | #define KPF_UPTODATE 3 |
| 743 | #define KPF_DIRTY 4 |
| 744 | #define KPF_LRU 5 |
| 745 | #define KPF_ACTIVE 6 |
| 746 | #define KPF_SLAB 7 |
| 747 | #define KPF_WRITEBACK 8 |
| 748 | #define KPF_RECLAIM 9 |
| 749 | #define KPF_BUDDY 10 |
| 750 | |
| 751 | #define kpf_copy_bit(flags, srcpos, dstpos) (((flags >> srcpos) & 1) << dstpos) |
| 752 | |
| 753 | static ssize_t kpageflags_read(struct file *file, char __user *buf, |
| 754 | size_t count, loff_t *ppos) |
| 755 | { |
| 756 | u64 __user *out = (u64 __user *)buf; |
| 757 | struct page *ppage; |
| 758 | unsigned long src = *ppos; |
| 759 | unsigned long pfn; |
| 760 | ssize_t ret = 0; |
| 761 | u64 kflags, uflags; |
| 762 | |
| 763 | pfn = src / KPMSIZE; |
| 764 | count = min_t(unsigned long, count, (max_pfn * KPMSIZE) - src); |
| 765 | if (src & KPMMASK || count & KPMMASK) |
| 766 | return -EIO; |
| 767 | |
| 768 | while (count > 0) { |
| 769 | ppage = NULL; |
| 770 | if (pfn_valid(pfn)) |
| 771 | ppage = pfn_to_page(pfn); |
| 772 | pfn++; |
| 773 | if (!ppage) |
| 774 | kflags = 0; |
| 775 | else |
| 776 | kflags = ppage->flags; |
| 777 | |
| 778 | uflags = kpf_copy_bit(KPF_LOCKED, PG_locked, kflags) | |
| 779 | kpf_copy_bit(kflags, KPF_ERROR, PG_error) | |
| 780 | kpf_copy_bit(kflags, KPF_REFERENCED, PG_referenced) | |
| 781 | kpf_copy_bit(kflags, KPF_UPTODATE, PG_uptodate) | |
| 782 | kpf_copy_bit(kflags, KPF_DIRTY, PG_dirty) | |
| 783 | kpf_copy_bit(kflags, KPF_LRU, PG_lru) | |
| 784 | kpf_copy_bit(kflags, KPF_ACTIVE, PG_active) | |
| 785 | kpf_copy_bit(kflags, KPF_SLAB, PG_slab) | |
| 786 | kpf_copy_bit(kflags, KPF_WRITEBACK, PG_writeback) | |
| 787 | kpf_copy_bit(kflags, KPF_RECLAIM, PG_reclaim) | |
| 788 | kpf_copy_bit(kflags, KPF_BUDDY, PG_buddy); |
| 789 | |
| 790 | if (put_user(uflags, out++)) { |
| 791 | ret = -EFAULT; |
| 792 | break; |
| 793 | } |
| 794 | |
| 795 | count -= KPMSIZE; |
| 796 | } |
| 797 | |
| 798 | *ppos += (char __user *)out - buf; |
| 799 | if (!ret) |
| 800 | ret = (char __user *)out - buf; |
| 801 | return ret; |
| 802 | } |
| 803 | |
| 804 | static struct file_operations proc_kpageflags_operations = { |
| 805 | .llseek = mem_lseek, |
| 806 | .read = kpageflags_read, |
| 807 | }; |
Matt Mackall | 1e88328 | 2008-02-04 22:29:07 -0800 | [diff] [blame] | 808 | #endif /* CONFIG_PROC_PAGE_MONITOR */ |
Matt Mackall | 304daa8 | 2008-02-04 22:29:06 -0800 | [diff] [blame] | 809 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | struct proc_dir_entry *proc_root_kcore; |
| 811 | |
Arjan van de Ven | 99ac48f | 2006-03-28 01:56:41 -0800 | [diff] [blame] | 812 | void create_seq_entry(char *name, mode_t mode, const struct file_operations *f) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | { |
| 814 | struct proc_dir_entry *entry; |
| 815 | entry = create_proc_entry(name, mode, NULL); |
| 816 | if (entry) |
| 817 | entry->proc_fops = f; |
| 818 | } |
| 819 | |
| 820 | void __init proc_misc_init(void) |
| 821 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | static struct { |
| 823 | char *name; |
| 824 | int (*read_proc)(char*,char**,off_t,int,int*,void*); |
| 825 | } *p, simple_ones[] = { |
| 826 | {"loadavg", loadavg_read_proc}, |
| 827 | {"uptime", uptime_read_proc}, |
| 828 | {"meminfo", meminfo_read_proc}, |
| 829 | {"version", version_read_proc}, |
| 830 | #ifdef CONFIG_PROC_HARDWARE |
| 831 | {"hardware", hardware_read_proc}, |
| 832 | #endif |
| 833 | #ifdef CONFIG_STRAM_PROC |
| 834 | {"stram", stram_read_proc}, |
| 835 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 836 | {"filesystems", filesystems_read_proc}, |
| 837 | {"cmdline", cmdline_read_proc}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | {"execdomains", execdomains_read_proc}, |
| 839 | {NULL,} |
| 840 | }; |
| 841 | for (p = simple_ones; p->name; p++) |
| 842 | create_proc_read_entry(p->name, 0, NULL, p->read_proc, NULL); |
| 843 | |
| 844 | proc_symlink("mounts", NULL, "self/mounts"); |
| 845 | |
| 846 | /* And now for trickier ones */ |
Mike Galbraith | c36264d | 2006-12-06 20:37:42 -0800 | [diff] [blame] | 847 | #ifdef CONFIG_PRINTK |
Andrew Morton | 100bb93 | 2007-02-10 01:45:51 -0800 | [diff] [blame] | 848 | { |
| 849 | struct proc_dir_entry *entry; |
| 850 | entry = create_proc_entry("kmsg", S_IRUSR, &proc_root); |
| 851 | if (entry) |
| 852 | entry->proc_fops = &proc_kmsg_operations; |
| 853 | } |
Mike Galbraith | c36264d | 2006-12-06 20:37:42 -0800 | [diff] [blame] | 854 | #endif |
Pavel Emelyanov | 7f8ada9 | 2007-10-01 14:41:15 -0700 | [diff] [blame] | 855 | create_seq_entry("locks", 0, &proc_locks_operations); |
Neil Horman | 7170be5 | 2006-01-14 13:20:38 -0800 | [diff] [blame] | 856 | create_seq_entry("devices", 0, &proc_devinfo_operations); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | create_seq_entry("cpuinfo", 0, &proc_cpuinfo_operations); |
David Howells | 9361401 | 2006-09-30 20:45:40 +0200 | [diff] [blame] | 858 | #ifdef CONFIG_BLOCK |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | create_seq_entry("partitions", 0, &proc_partitions_operations); |
David Howells | 9361401 | 2006-09-30 20:45:40 +0200 | [diff] [blame] | 860 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 | create_seq_entry("stat", 0, &proc_stat_operations); |
| 862 | create_seq_entry("interrupts", 0, &proc_interrupts_operations); |
Linus Torvalds | 158a962 | 2008-01-02 13:04:48 -0800 | [diff] [blame] | 863 | #ifdef CONFIG_SLABINFO |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | create_seq_entry("slabinfo",S_IWUSR|S_IRUGO,&proc_slabinfo_operations); |
Al Viro | 871751e | 2006-03-25 03:06:39 -0800 | [diff] [blame] | 865 | #ifdef CONFIG_DEBUG_SLAB_LEAK |
| 866 | create_seq_entry("slab_allocators", 0 ,&proc_slabstats_operations); |
| 867 | #endif |
Matt Mackall | 10cef60 | 2006-01-08 01:01:45 -0800 | [diff] [blame] | 868 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | create_seq_entry("buddyinfo",S_IRUGO, &fragmentation_file_operations); |
Mel Gorman | 467c996 | 2007-10-16 01:26:02 -0700 | [diff] [blame] | 870 | create_seq_entry("pagetypeinfo", S_IRUGO, &pagetypeinfo_file_ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 871 | create_seq_entry("vmstat",S_IRUGO, &proc_vmstat_file_operations); |
Nikita Danilov | 295ab93 | 2005-06-21 17:14:38 -0700 | [diff] [blame] | 872 | create_seq_entry("zoneinfo",S_IRUGO, &proc_zoneinfo_file_operations); |
David Howells | 9361401 | 2006-09-30 20:45:40 +0200 | [diff] [blame] | 873 | #ifdef CONFIG_BLOCK |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | create_seq_entry("diskstats", 0, &proc_diskstats_operations); |
David Howells | 9361401 | 2006-09-30 20:45:40 +0200 | [diff] [blame] | 875 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | #ifdef CONFIG_MODULES |
| 877 | create_seq_entry("modules", 0, &proc_modules_operations); |
| 878 | #endif |
| 879 | #ifdef CONFIG_SCHEDSTATS |
| 880 | create_seq_entry("schedstat", 0, &proc_schedstat_operations); |
| 881 | #endif |
| 882 | #ifdef CONFIG_PROC_KCORE |
| 883 | proc_root_kcore = create_proc_entry("kcore", S_IRUSR, NULL); |
| 884 | if (proc_root_kcore) { |
| 885 | proc_root_kcore->proc_fops = &proc_kcore_operations; |
| 886 | proc_root_kcore->size = |
| 887 | (size_t)high_memory - PAGE_OFFSET + PAGE_SIZE; |
| 888 | } |
| 889 | #endif |
Matt Mackall | 1e88328 | 2008-02-04 22:29:07 -0800 | [diff] [blame] | 890 | #ifdef CONFIG_PROC_PAGE_MONITOR |
Matt Mackall | 161f47b | 2008-02-04 22:29:05 -0800 | [diff] [blame] | 891 | create_seq_entry("kpagecount", S_IRUSR, &proc_kpagecount_operations); |
Matt Mackall | 304daa8 | 2008-02-04 22:29:06 -0800 | [diff] [blame] | 892 | create_seq_entry("kpageflags", S_IRUSR, &proc_kpageflags_operations); |
Matt Mackall | 1e88328 | 2008-02-04 22:29:07 -0800 | [diff] [blame] | 893 | #endif |
Vivek Goyal | 666bfdd | 2005-06-25 14:58:21 -0700 | [diff] [blame] | 894 | #ifdef CONFIG_PROC_VMCORE |
| 895 | proc_vmcore = create_proc_entry("vmcore", S_IRUSR, NULL); |
| 896 | if (proc_vmcore) |
| 897 | proc_vmcore->proc_fops = &proc_vmcore_operations; |
| 898 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | #ifdef CONFIG_MAGIC_SYSRQ |
Andrew Morton | 100bb93 | 2007-02-10 01:45:51 -0800 | [diff] [blame] | 900 | { |
| 901 | struct proc_dir_entry *entry; |
| 902 | entry = create_proc_entry("sysrq-trigger", S_IWUSR, NULL); |
| 903 | if (entry) |
| 904 | entry->proc_fops = &proc_sysrq_trigger_operations; |
| 905 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | } |