proc_misc.c 19 KB

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