proc_misc.c 19 KB

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