proc_misc.c 19 KB

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