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