proc_misc.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752
  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/seq_file.h>
  38. #include <linux/times.h>
  39. #include <linux/profile.h>
  40. #include <linux/utsname.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 <linux/pid_namespace.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. 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, current->nsproxy->pid_ns->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. monotonic_to_bootbased(&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 committed;
  115. unsigned long allowed;
  116. struct vmalloc_info vmi;
  117. long cached;
  118. /*
  119. * display in kilobytes.
  120. */
  121. #define K(x) ((x) << (PAGE_SHIFT - 10))
  122. si_meminfo(&i);
  123. si_swapinfo(&i);
  124. committed = atomic_read(&vm_committed_space);
  125. allowed = ((totalram_pages - hugetlb_total_pages())
  126. * sysctl_overcommit_ratio / 100) + total_swap_pages;
  127. cached = global_page_state(NR_FILE_PAGES) -
  128. total_swapcache_pages - i.bufferram;
  129. if (cached < 0)
  130. cached = 0;
  131. get_vmalloc_info(&vmi);
  132. /*
  133. * Tagged format, for easy grepping and expansion.
  134. */
  135. len = sprintf(page,
  136. "MemTotal: %8lu kB\n"
  137. "MemFree: %8lu kB\n"
  138. "Buffers: %8lu kB\n"
  139. "Cached: %8lu kB\n"
  140. "SwapCached: %8lu kB\n"
  141. "Active: %8lu kB\n"
  142. "Inactive: %8lu kB\n"
  143. #ifdef CONFIG_HIGHMEM
  144. "HighTotal: %8lu kB\n"
  145. "HighFree: %8lu kB\n"
  146. "LowTotal: %8lu kB\n"
  147. "LowFree: %8lu kB\n"
  148. #endif
  149. "SwapTotal: %8lu kB\n"
  150. "SwapFree: %8lu kB\n"
  151. "Dirty: %8lu kB\n"
  152. "Writeback: %8lu kB\n"
  153. "AnonPages: %8lu kB\n"
  154. "Mapped: %8lu kB\n"
  155. "Slab: %8lu kB\n"
  156. "SReclaimable: %8lu kB\n"
  157. "SUnreclaim: %8lu kB\n"
  158. "PageTables: %8lu kB\n"
  159. "NFS_Unstable: %8lu kB\n"
  160. "Bounce: %8lu kB\n"
  161. "CommitLimit: %8lu kB\n"
  162. "Committed_AS: %8lu kB\n"
  163. "VmallocTotal: %8lu kB\n"
  164. "VmallocUsed: %8lu kB\n"
  165. "VmallocChunk: %8lu kB\n",
  166. K(i.totalram),
  167. K(i.freeram),
  168. K(i.bufferram),
  169. K(cached),
  170. K(total_swapcache_pages),
  171. K(global_page_state(NR_ACTIVE)),
  172. K(global_page_state(NR_INACTIVE)),
  173. #ifdef CONFIG_HIGHMEM
  174. K(i.totalhigh),
  175. K(i.freehigh),
  176. K(i.totalram-i.totalhigh),
  177. K(i.freeram-i.freehigh),
  178. #endif
  179. K(i.totalswap),
  180. K(i.freeswap),
  181. K(global_page_state(NR_FILE_DIRTY)),
  182. K(global_page_state(NR_WRITEBACK)),
  183. K(global_page_state(NR_ANON_PAGES)),
  184. K(global_page_state(NR_FILE_MAPPED)),
  185. K(global_page_state(NR_SLAB_RECLAIMABLE) +
  186. global_page_state(NR_SLAB_UNRECLAIMABLE)),
  187. K(global_page_state(NR_SLAB_RECLAIMABLE)),
  188. K(global_page_state(NR_SLAB_UNRECLAIMABLE)),
  189. K(global_page_state(NR_PAGETABLE)),
  190. K(global_page_state(NR_UNSTABLE_NFS)),
  191. K(global_page_state(NR_BOUNCE)),
  192. K(allowed),
  193. K(committed),
  194. (unsigned long)VMALLOC_TOTAL >> 10,
  195. vmi.used >> 10,
  196. vmi.largest_chunk >> 10
  197. );
  198. len += hugetlb_report_meminfo(page + len);
  199. return proc_calc_metrics(page, start, off, count, eof, len);
  200. #undef K
  201. }
  202. extern struct seq_operations fragmentation_op;
  203. static int fragmentation_open(struct inode *inode, struct file *file)
  204. {
  205. (void)inode;
  206. return seq_open(file, &fragmentation_op);
  207. }
  208. static const struct file_operations fragmentation_file_operations = {
  209. .open = fragmentation_open,
  210. .read = seq_read,
  211. .llseek = seq_lseek,
  212. .release = seq_release,
  213. };
  214. extern struct seq_operations zoneinfo_op;
  215. static int zoneinfo_open(struct inode *inode, struct file *file)
  216. {
  217. return seq_open(file, &zoneinfo_op);
  218. }
  219. static const struct file_operations proc_zoneinfo_file_operations = {
  220. .open = zoneinfo_open,
  221. .read = seq_read,
  222. .llseek = seq_lseek,
  223. .release = seq_release,
  224. };
  225. static int version_read_proc(char *page, char **start, off_t off,
  226. int count, int *eof, void *data)
  227. {
  228. int len;
  229. len = snprintf(page, PAGE_SIZE, linux_proc_banner,
  230. utsname()->sysname,
  231. utsname()->release,
  232. utsname()->version);
  233. return proc_calc_metrics(page, start, off, count, eof, len);
  234. }
  235. extern struct seq_operations cpuinfo_op;
  236. static int cpuinfo_open(struct inode *inode, struct file *file)
  237. {
  238. return seq_open(file, &cpuinfo_op);
  239. }
  240. static const struct file_operations proc_cpuinfo_operations = {
  241. .open = cpuinfo_open,
  242. .read = seq_read,
  243. .llseek = seq_lseek,
  244. .release = seq_release,
  245. };
  246. static int devinfo_show(struct seq_file *f, void *v)
  247. {
  248. int i = *(loff_t *) v;
  249. if (i < CHRDEV_MAJOR_HASH_SIZE) {
  250. if (i == 0)
  251. seq_printf(f, "Character devices:\n");
  252. chrdev_show(f, i);
  253. }
  254. #ifdef CONFIG_BLOCK
  255. else {
  256. i -= CHRDEV_MAJOR_HASH_SIZE;
  257. if (i == 0)
  258. seq_printf(f, "\nBlock devices:\n");
  259. blkdev_show(f, i);
  260. }
  261. #endif
  262. return 0;
  263. }
  264. static void *devinfo_start(struct seq_file *f, loff_t *pos)
  265. {
  266. if (*pos < (BLKDEV_MAJOR_HASH_SIZE + CHRDEV_MAJOR_HASH_SIZE))
  267. return pos;
  268. return NULL;
  269. }
  270. static void *devinfo_next(struct seq_file *f, void *v, loff_t *pos)
  271. {
  272. (*pos)++;
  273. if (*pos >= (BLKDEV_MAJOR_HASH_SIZE + CHRDEV_MAJOR_HASH_SIZE))
  274. return NULL;
  275. return pos;
  276. }
  277. static void devinfo_stop(struct seq_file *f, void *v)
  278. {
  279. /* Nothing to do */
  280. }
  281. static struct seq_operations devinfo_ops = {
  282. .start = devinfo_start,
  283. .next = devinfo_next,
  284. .stop = devinfo_stop,
  285. .show = devinfo_show
  286. };
  287. static int devinfo_open(struct inode *inode, struct file *filp)
  288. {
  289. return seq_open(filp, &devinfo_ops);
  290. }
  291. static const struct file_operations proc_devinfo_operations = {
  292. .open = devinfo_open,
  293. .read = seq_read,
  294. .llseek = seq_lseek,
  295. .release = seq_release,
  296. };
  297. extern struct seq_operations vmstat_op;
  298. static int vmstat_open(struct inode *inode, struct file *file)
  299. {
  300. return seq_open(file, &vmstat_op);
  301. }
  302. static const struct file_operations proc_vmstat_file_operations = {
  303. .open = vmstat_open,
  304. .read = seq_read,
  305. .llseek = seq_lseek,
  306. .release = seq_release,
  307. };
  308. #ifdef CONFIG_PROC_HARDWARE
  309. static int hardware_read_proc(char *page, char **start, off_t off,
  310. int count, int *eof, void *data)
  311. {
  312. int len = get_hardware_list(page);
  313. return proc_calc_metrics(page, start, off, count, eof, len);
  314. }
  315. #endif
  316. #ifdef CONFIG_STRAM_PROC
  317. static int stram_read_proc(char *page, char **start, off_t off,
  318. int count, int *eof, void *data)
  319. {
  320. int len = get_stram_list(page);
  321. return proc_calc_metrics(page, start, off, count, eof, len);
  322. }
  323. #endif
  324. #ifdef CONFIG_BLOCK
  325. extern struct seq_operations partitions_op;
  326. static int partitions_open(struct inode *inode, struct file *file)
  327. {
  328. return seq_open(file, &partitions_op);
  329. }
  330. static const struct file_operations proc_partitions_operations = {
  331. .open = partitions_open,
  332. .read = seq_read,
  333. .llseek = seq_lseek,
  334. .release = seq_release,
  335. };
  336. extern struct seq_operations diskstats_op;
  337. static int diskstats_open(struct inode *inode, struct file *file)
  338. {
  339. return seq_open(file, &diskstats_op);
  340. }
  341. static const struct file_operations proc_diskstats_operations = {
  342. .open = diskstats_open,
  343. .read = seq_read,
  344. .llseek = seq_lseek,
  345. .release = seq_release,
  346. };
  347. #endif
  348. #ifdef CONFIG_MODULES
  349. extern struct seq_operations modules_op;
  350. static int modules_open(struct inode *inode, struct file *file)
  351. {
  352. return seq_open(file, &modules_op);
  353. }
  354. static const struct file_operations proc_modules_operations = {
  355. .open = modules_open,
  356. .read = seq_read,
  357. .llseek = seq_lseek,
  358. .release = seq_release,
  359. };
  360. #endif
  361. #ifdef CONFIG_SLAB
  362. static int slabinfo_open(struct inode *inode, struct file *file)
  363. {
  364. return seq_open(file, &slabinfo_op);
  365. }
  366. static const struct file_operations proc_slabinfo_operations = {
  367. .open = slabinfo_open,
  368. .read = seq_read,
  369. .write = slabinfo_write,
  370. .llseek = seq_lseek,
  371. .release = seq_release,
  372. };
  373. #ifdef CONFIG_DEBUG_SLAB_LEAK
  374. extern struct seq_operations slabstats_op;
  375. static int slabstats_open(struct inode *inode, struct file *file)
  376. {
  377. unsigned long *n = kzalloc(PAGE_SIZE, GFP_KERNEL);
  378. int ret = -ENOMEM;
  379. if (n) {
  380. ret = seq_open(file, &slabstats_op);
  381. if (!ret) {
  382. struct seq_file *m = file->private_data;
  383. *n = PAGE_SIZE / (2 * sizeof(unsigned long));
  384. m->private = n;
  385. n = NULL;
  386. }
  387. kfree(n);
  388. }
  389. return ret;
  390. }
  391. static const struct file_operations proc_slabstats_operations = {
  392. .open = slabstats_open,
  393. .read = seq_read,
  394. .llseek = seq_lseek,
  395. .release = seq_release_private,
  396. };
  397. #endif
  398. #endif
  399. static int show_stat(struct seq_file *p, void *v)
  400. {
  401. int i;
  402. unsigned long jif;
  403. cputime64_t user, nice, system, idle, iowait, irq, softirq, steal;
  404. u64 sum = 0;
  405. struct timespec boottime;
  406. unsigned int *per_irq_sum;
  407. per_irq_sum = kzalloc(sizeof(unsigned int)*NR_IRQS, GFP_KERNEL);
  408. if (!per_irq_sum)
  409. return -ENOMEM;
  410. user = nice = system = idle = iowait =
  411. irq = softirq = steal = cputime64_zero;
  412. getboottime(&boottime);
  413. jif = boottime.tv_sec;
  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. unsigned int temp = kstat_cpu(i).irqs[j];
  426. sum += temp;
  427. per_irq_sum[j] += temp;
  428. }
  429. }
  430. seq_printf(p, "cpu %llu %llu %llu %llu %llu %llu %llu %llu\n",
  431. (unsigned long long)cputime64_to_clock_t(user),
  432. (unsigned long long)cputime64_to_clock_t(nice),
  433. (unsigned long long)cputime64_to_clock_t(system),
  434. (unsigned long long)cputime64_to_clock_t(idle),
  435. (unsigned long long)cputime64_to_clock_t(iowait),
  436. (unsigned long long)cputime64_to_clock_t(irq),
  437. (unsigned long long)cputime64_to_clock_t(softirq),
  438. (unsigned long long)cputime64_to_clock_t(steal));
  439. for_each_online_cpu(i) {
  440. /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
  441. user = kstat_cpu(i).cpustat.user;
  442. nice = kstat_cpu(i).cpustat.nice;
  443. system = kstat_cpu(i).cpustat.system;
  444. idle = kstat_cpu(i).cpustat.idle;
  445. iowait = kstat_cpu(i).cpustat.iowait;
  446. irq = kstat_cpu(i).cpustat.irq;
  447. softirq = kstat_cpu(i).cpustat.softirq;
  448. steal = kstat_cpu(i).cpustat.steal;
  449. seq_printf(p, "cpu%d %llu %llu %llu %llu %llu %llu %llu %llu\n",
  450. i,
  451. (unsigned long long)cputime64_to_clock_t(user),
  452. (unsigned long long)cputime64_to_clock_t(nice),
  453. (unsigned long long)cputime64_to_clock_t(system),
  454. (unsigned long long)cputime64_to_clock_t(idle),
  455. (unsigned long long)cputime64_to_clock_t(iowait),
  456. (unsigned long long)cputime64_to_clock_t(irq),
  457. (unsigned long long)cputime64_to_clock_t(softirq),
  458. (unsigned long long)cputime64_to_clock_t(steal));
  459. }
  460. seq_printf(p, "intr %llu", (unsigned long long)sum);
  461. #ifndef CONFIG_SMP
  462. /* Touches too many cache lines on SMP setups */
  463. for (i = 0; i < NR_IRQS; i++)
  464. seq_printf(p, " %u", per_irq_sum[i]);
  465. #endif
  466. seq_printf(p,
  467. "\nctxt %llu\n"
  468. "btime %lu\n"
  469. "processes %lu\n"
  470. "procs_running %lu\n"
  471. "procs_blocked %lu\n",
  472. nr_context_switches(),
  473. (unsigned long)jif,
  474. total_forks,
  475. nr_running(),
  476. nr_iowait());
  477. kfree(per_irq_sum);
  478. return 0;
  479. }
  480. static int stat_open(struct inode *inode, struct file *file)
  481. {
  482. unsigned size = 4096 * (1 + num_possible_cpus() / 32);
  483. char *buf;
  484. struct seq_file *m;
  485. int res;
  486. /* don't ask for more than the kmalloc() max size, currently 128 KB */
  487. if (size > 128 * 1024)
  488. size = 128 * 1024;
  489. buf = kmalloc(size, GFP_KERNEL);
  490. if (!buf)
  491. return -ENOMEM;
  492. res = single_open(file, show_stat, NULL);
  493. if (!res) {
  494. m = file->private_data;
  495. m->buf = buf;
  496. m->size = size;
  497. } else
  498. kfree(buf);
  499. return res;
  500. }
  501. static const struct file_operations proc_stat_operations = {
  502. .open = stat_open,
  503. .read = seq_read,
  504. .llseek = seq_lseek,
  505. .release = single_release,
  506. };
  507. /*
  508. * /proc/interrupts
  509. */
  510. static void *int_seq_start(struct seq_file *f, loff_t *pos)
  511. {
  512. return (*pos <= NR_IRQS) ? pos : NULL;
  513. }
  514. static void *int_seq_next(struct seq_file *f, void *v, loff_t *pos)
  515. {
  516. (*pos)++;
  517. if (*pos > NR_IRQS)
  518. return NULL;
  519. return pos;
  520. }
  521. static void int_seq_stop(struct seq_file *f, void *v)
  522. {
  523. /* Nothing to do */
  524. }
  525. extern int show_interrupts(struct seq_file *f, void *v); /* In arch code */
  526. static struct seq_operations int_seq_ops = {
  527. .start = int_seq_start,
  528. .next = int_seq_next,
  529. .stop = int_seq_stop,
  530. .show = show_interrupts
  531. };
  532. static int interrupts_open(struct inode *inode, struct file *filp)
  533. {
  534. return seq_open(filp, &int_seq_ops);
  535. }
  536. static const struct file_operations proc_interrupts_operations = {
  537. .open = interrupts_open,
  538. .read = seq_read,
  539. .llseek = seq_lseek,
  540. .release = seq_release,
  541. };
  542. static int filesystems_read_proc(char *page, char **start, off_t off,
  543. int count, int *eof, void *data)
  544. {
  545. int len = get_filesystem_list(page);
  546. return proc_calc_metrics(page, start, off, count, eof, len);
  547. }
  548. static int cmdline_read_proc(char *page, char **start, off_t off,
  549. int count, int *eof, void *data)
  550. {
  551. int len;
  552. len = sprintf(page, "%s\n", saved_command_line);
  553. return proc_calc_metrics(page, start, off, count, eof, len);
  554. }
  555. static int locks_open(struct inode *inode, struct file *filp)
  556. {
  557. return seq_open(filp, &locks_seq_operations);
  558. }
  559. static const struct file_operations proc_locks_operations = {
  560. .open = locks_open,
  561. .read = seq_read,
  562. .llseek = seq_lseek,
  563. .release = seq_release,
  564. };
  565. static int execdomains_read_proc(char *page, char **start, off_t off,
  566. int count, int *eof, void *data)
  567. {
  568. int len = get_exec_domain_list(page);
  569. return proc_calc_metrics(page, start, off, count, eof, len);
  570. }
  571. #ifdef CONFIG_MAGIC_SYSRQ
  572. /*
  573. * writing 'C' to /proc/sysrq-trigger is like sysrq-C
  574. */
  575. static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
  576. size_t count, loff_t *ppos)
  577. {
  578. if (count) {
  579. char c;
  580. if (get_user(c, buf))
  581. return -EFAULT;
  582. __handle_sysrq(c, NULL, 0);
  583. }
  584. return count;
  585. }
  586. static const struct file_operations proc_sysrq_trigger_operations = {
  587. .write = write_sysrq_trigger,
  588. };
  589. #endif
  590. struct proc_dir_entry *proc_root_kcore;
  591. void create_seq_entry(char *name, mode_t mode, const struct file_operations *f)
  592. {
  593. struct proc_dir_entry *entry;
  594. entry = create_proc_entry(name, mode, NULL);
  595. if (entry)
  596. entry->proc_fops = f;
  597. }
  598. void __init proc_misc_init(void)
  599. {
  600. static struct {
  601. char *name;
  602. int (*read_proc)(char*,char**,off_t,int,int*,void*);
  603. } *p, simple_ones[] = {
  604. {"loadavg", loadavg_read_proc},
  605. {"uptime", uptime_read_proc},
  606. {"meminfo", meminfo_read_proc},
  607. {"version", version_read_proc},
  608. #ifdef CONFIG_PROC_HARDWARE
  609. {"hardware", hardware_read_proc},
  610. #endif
  611. #ifdef CONFIG_STRAM_PROC
  612. {"stram", stram_read_proc},
  613. #endif
  614. {"filesystems", filesystems_read_proc},
  615. {"cmdline", cmdline_read_proc},
  616. {"execdomains", execdomains_read_proc},
  617. {NULL,}
  618. };
  619. for (p = simple_ones; p->name; p++)
  620. create_proc_read_entry(p->name, 0, NULL, p->read_proc, NULL);
  621. proc_symlink("mounts", NULL, "self/mounts");
  622. /* And now for trickier ones */
  623. #ifdef CONFIG_PRINTK
  624. {
  625. struct proc_dir_entry *entry;
  626. entry = create_proc_entry("kmsg", S_IRUSR, &proc_root);
  627. if (entry)
  628. entry->proc_fops = &proc_kmsg_operations;
  629. }
  630. #endif
  631. create_seq_entry("locks", 0, &proc_locks_operations);
  632. create_seq_entry("devices", 0, &proc_devinfo_operations);
  633. create_seq_entry("cpuinfo", 0, &proc_cpuinfo_operations);
  634. #ifdef CONFIG_BLOCK
  635. create_seq_entry("partitions", 0, &proc_partitions_operations);
  636. #endif
  637. create_seq_entry("stat", 0, &proc_stat_operations);
  638. create_seq_entry("interrupts", 0, &proc_interrupts_operations);
  639. #ifdef CONFIG_SLAB
  640. create_seq_entry("slabinfo",S_IWUSR|S_IRUGO,&proc_slabinfo_operations);
  641. #ifdef CONFIG_DEBUG_SLAB_LEAK
  642. create_seq_entry("slab_allocators", 0 ,&proc_slabstats_operations);
  643. #endif
  644. #endif
  645. create_seq_entry("buddyinfo",S_IRUGO, &fragmentation_file_operations);
  646. create_seq_entry("vmstat",S_IRUGO, &proc_vmstat_file_operations);
  647. create_seq_entry("zoneinfo",S_IRUGO, &proc_zoneinfo_file_operations);
  648. #ifdef CONFIG_BLOCK
  649. create_seq_entry("diskstats", 0, &proc_diskstats_operations);
  650. #endif
  651. #ifdef CONFIG_MODULES
  652. create_seq_entry("modules", 0, &proc_modules_operations);
  653. #endif
  654. #ifdef CONFIG_SCHEDSTATS
  655. create_seq_entry("schedstat", 0, &proc_schedstat_operations);
  656. #endif
  657. #ifdef CONFIG_PROC_KCORE
  658. proc_root_kcore = create_proc_entry("kcore", S_IRUSR, NULL);
  659. if (proc_root_kcore) {
  660. proc_root_kcore->proc_fops = &proc_kcore_operations;
  661. proc_root_kcore->size =
  662. (size_t)high_memory - PAGE_OFFSET + PAGE_SIZE;
  663. }
  664. #endif
  665. #ifdef CONFIG_PROC_VMCORE
  666. proc_vmcore = create_proc_entry("vmcore", S_IRUSR, NULL);
  667. if (proc_vmcore)
  668. proc_vmcore->proc_fops = &proc_vmcore_operations;
  669. #endif
  670. #ifdef CONFIG_MAGIC_SYSRQ
  671. {
  672. struct proc_dir_entry *entry;
  673. entry = create_proc_entry("sysrq-trigger", S_IWUSR, NULL);
  674. if (entry)
  675. entry->proc_fops = &proc_sysrq_trigger_operations;
  676. }
  677. #endif
  678. }