proc_misc.c 19 KB

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