proc_misc.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813
  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. struct page_state ps;
  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_page_state(&ps);
  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 = get_page_cache_size() - 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. "HighTotal: %8lu kB\n"
  149. "HighFree: %8lu kB\n"
  150. "LowTotal: %8lu kB\n"
  151. "LowFree: %8lu kB\n"
  152. "SwapTotal: %8lu kB\n"
  153. "SwapFree: %8lu kB\n"
  154. "Dirty: %8lu kB\n"
  155. "Writeback: %8lu kB\n"
  156. "Mapped: %8lu kB\n"
  157. "Slab: %8lu kB\n"
  158. "CommitLimit: %8lu kB\n"
  159. "Committed_AS: %8lu kB\n"
  160. "PageTables: %8lu kB\n"
  161. "VmallocTotal: %8lu kB\n"
  162. "VmallocUsed: %8lu kB\n"
  163. "VmallocChunk: %8lu kB\n",
  164. K(i.totalram),
  165. K(i.freeram),
  166. K(i.bufferram),
  167. K(cached),
  168. K(total_swapcache_pages),
  169. K(active),
  170. K(inactive),
  171. K(i.totalhigh),
  172. K(i.freehigh),
  173. K(i.totalram-i.totalhigh),
  174. K(i.freeram-i.freehigh),
  175. K(i.totalswap),
  176. K(i.freeswap),
  177. K(ps.nr_dirty),
  178. K(ps.nr_writeback),
  179. K(ps.nr_mapped),
  180. K(ps.nr_slab),
  181. K(allowed),
  182. K(committed),
  183. K(ps.nr_page_table_pages),
  184. (unsigned long)VMALLOC_TOTAL >> 10,
  185. vmi.used >> 10,
  186. vmi.largest_chunk >> 10
  187. );
  188. len += hugetlb_report_meminfo(page + len);
  189. return proc_calc_metrics(page, start, off, count, eof, len);
  190. #undef K
  191. }
  192. extern struct seq_operations fragmentation_op;
  193. static int fragmentation_open(struct inode *inode, struct file *file)
  194. {
  195. (void)inode;
  196. return seq_open(file, &fragmentation_op);
  197. }
  198. static struct file_operations fragmentation_file_operations = {
  199. .open = fragmentation_open,
  200. .read = seq_read,
  201. .llseek = seq_lseek,
  202. .release = seq_release,
  203. };
  204. extern struct seq_operations zoneinfo_op;
  205. static int zoneinfo_open(struct inode *inode, struct file *file)
  206. {
  207. return seq_open(file, &zoneinfo_op);
  208. }
  209. static struct file_operations proc_zoneinfo_file_operations = {
  210. .open = zoneinfo_open,
  211. .read = seq_read,
  212. .llseek = seq_lseek,
  213. .release = seq_release,
  214. };
  215. static int version_read_proc(char *page, char **start, off_t off,
  216. int count, int *eof, void *data)
  217. {
  218. int len;
  219. strcpy(page, linux_banner);
  220. len = strlen(page);
  221. return proc_calc_metrics(page, start, off, count, eof, len);
  222. }
  223. extern struct seq_operations cpuinfo_op;
  224. static int cpuinfo_open(struct inode *inode, struct file *file)
  225. {
  226. return seq_open(file, &cpuinfo_op);
  227. }
  228. enum devinfo_states {
  229. CHR_HDR,
  230. CHR_LIST,
  231. BLK_HDR,
  232. BLK_LIST,
  233. DEVINFO_DONE
  234. };
  235. struct devinfo_state {
  236. void *chrdev;
  237. void *blkdev;
  238. unsigned int num_records;
  239. unsigned int cur_record;
  240. enum devinfo_states state;
  241. };
  242. static void *devinfo_start(struct seq_file *f, loff_t *pos)
  243. {
  244. struct devinfo_state *info = f->private;
  245. if (*pos) {
  246. if ((info) && (*pos <= info->num_records))
  247. return info;
  248. return NULL;
  249. }
  250. info = kmalloc(sizeof(*info), GFP_KERNEL);
  251. f->private = info;
  252. info->chrdev = acquire_chrdev_list();
  253. info->blkdev = acquire_blkdev_list();
  254. info->state = CHR_HDR;
  255. info->num_records = count_chrdev_list();
  256. info->num_records += count_blkdev_list();
  257. info->num_records += 2; /* Character and Block headers */
  258. *pos = 1;
  259. info->cur_record = *pos;
  260. return info;
  261. }
  262. static void *devinfo_next(struct seq_file *f, void *v, loff_t *pos)
  263. {
  264. int idummy;
  265. char *ndummy;
  266. struct devinfo_state *info = f->private;
  267. switch (info->state) {
  268. case CHR_HDR:
  269. info->state = CHR_LIST;
  270. (*pos)++;
  271. /*fallthrough*/
  272. case CHR_LIST:
  273. if (get_chrdev_info(info->chrdev,&idummy,&ndummy)) {
  274. /*
  275. * The character dev list is complete
  276. */
  277. info->state = BLK_HDR;
  278. } else {
  279. info->chrdev = get_next_chrdev(info->chrdev);
  280. }
  281. (*pos)++;
  282. break;
  283. case BLK_HDR:
  284. info->state = BLK_LIST;
  285. (*pos)++;
  286. /*fallthrough*/
  287. case BLK_LIST:
  288. if (get_blkdev_info(info->blkdev,&idummy,&ndummy)) {
  289. /*
  290. * The block dev list is complete
  291. */
  292. info->state = DEVINFO_DONE;
  293. } else {
  294. info->blkdev = get_next_blkdev(info->blkdev);
  295. }
  296. (*pos)++;
  297. break;
  298. case DEVINFO_DONE:
  299. (*pos)++;
  300. info->cur_record = *pos;
  301. info = NULL;
  302. break;
  303. default:
  304. break;
  305. }
  306. if (info)
  307. info->cur_record = *pos;
  308. return info;
  309. }
  310. static void devinfo_stop(struct seq_file *f, void *v)
  311. {
  312. struct devinfo_state *info = f->private;
  313. if (info) {
  314. release_chrdev_list(info->chrdev);
  315. release_blkdev_list(info->blkdev);
  316. f->private = NULL;
  317. kfree(info);
  318. }
  319. }
  320. static int devinfo_show(struct seq_file *f, void *arg)
  321. {
  322. int major;
  323. char *name;
  324. struct devinfo_state *info = f->private;
  325. switch(info->state) {
  326. case CHR_HDR:
  327. seq_printf(f,"Character devices:\n");
  328. /* fallthrough */
  329. case CHR_LIST:
  330. if (!get_chrdev_info(info->chrdev,&major,&name))
  331. seq_printf(f,"%3d %s\n",major,name);
  332. break;
  333. case BLK_HDR:
  334. seq_printf(f,"\nBlock devices:\n");
  335. /* fallthrough */
  336. case BLK_LIST:
  337. if (!get_blkdev_info(info->blkdev,&major,&name))
  338. seq_printf(f,"%3d %s\n",major,name);
  339. break;
  340. default:
  341. break;
  342. }
  343. return 0;
  344. }
  345. static struct seq_operations devinfo_op = {
  346. .start = devinfo_start,
  347. .next = devinfo_next,
  348. .stop = devinfo_stop,
  349. .show = devinfo_show,
  350. };
  351. static int devinfo_open(struct inode *inode, struct file *file)
  352. {
  353. return seq_open(file, &devinfo_op);
  354. }
  355. static struct file_operations proc_devinfo_operations = {
  356. .open = devinfo_open,
  357. .read = seq_read,
  358. .llseek = seq_lseek,
  359. .release = seq_release,
  360. };
  361. static struct file_operations proc_cpuinfo_operations = {
  362. .open = cpuinfo_open,
  363. .read = seq_read,
  364. .llseek = seq_lseek,
  365. .release = seq_release,
  366. };
  367. extern struct seq_operations vmstat_op;
  368. static int vmstat_open(struct inode *inode, struct file *file)
  369. {
  370. return seq_open(file, &vmstat_op);
  371. }
  372. static struct file_operations proc_vmstat_file_operations = {
  373. .open = vmstat_open,
  374. .read = seq_read,
  375. .llseek = seq_lseek,
  376. .release = seq_release,
  377. };
  378. #ifdef CONFIG_PROC_HARDWARE
  379. static int hardware_read_proc(char *page, char **start, off_t off,
  380. int count, int *eof, void *data)
  381. {
  382. int len = get_hardware_list(page);
  383. return proc_calc_metrics(page, start, off, count, eof, len);
  384. }
  385. #endif
  386. #ifdef CONFIG_STRAM_PROC
  387. static int stram_read_proc(char *page, char **start, off_t off,
  388. int count, int *eof, void *data)
  389. {
  390. int len = get_stram_list(page);
  391. return proc_calc_metrics(page, start, off, count, eof, len);
  392. }
  393. #endif
  394. extern struct seq_operations partitions_op;
  395. static int partitions_open(struct inode *inode, struct file *file)
  396. {
  397. return seq_open(file, &partitions_op);
  398. }
  399. static struct file_operations proc_partitions_operations = {
  400. .open = partitions_open,
  401. .read = seq_read,
  402. .llseek = seq_lseek,
  403. .release = seq_release,
  404. };
  405. extern struct seq_operations diskstats_op;
  406. static int diskstats_open(struct inode *inode, struct file *file)
  407. {
  408. return seq_open(file, &diskstats_op);
  409. }
  410. static struct file_operations proc_diskstats_operations = {
  411. .open = diskstats_open,
  412. .read = seq_read,
  413. .llseek = seq_lseek,
  414. .release = seq_release,
  415. };
  416. #ifdef CONFIG_MODULES
  417. extern struct seq_operations modules_op;
  418. static int modules_open(struct inode *inode, struct file *file)
  419. {
  420. return seq_open(file, &modules_op);
  421. }
  422. static struct file_operations proc_modules_operations = {
  423. .open = modules_open,
  424. .read = seq_read,
  425. .llseek = seq_lseek,
  426. .release = seq_release,
  427. };
  428. #endif
  429. #ifdef CONFIG_SLAB
  430. extern struct seq_operations slabinfo_op;
  431. extern ssize_t slabinfo_write(struct file *, const char __user *, size_t, loff_t *);
  432. static int slabinfo_open(struct inode *inode, struct file *file)
  433. {
  434. return seq_open(file, &slabinfo_op);
  435. }
  436. static struct file_operations proc_slabinfo_operations = {
  437. .open = slabinfo_open,
  438. .read = seq_read,
  439. .write = slabinfo_write,
  440. .llseek = seq_lseek,
  441. .release = seq_release,
  442. };
  443. #ifdef CONFIG_DEBUG_SLAB_LEAK
  444. extern struct seq_operations slabstats_op;
  445. static int slabstats_open(struct inode *inode, struct file *file)
  446. {
  447. unsigned long *n = kzalloc(PAGE_SIZE, GFP_KERNEL);
  448. int ret = -ENOMEM;
  449. if (n) {
  450. ret = seq_open(file, &slabstats_op);
  451. if (!ret) {
  452. struct seq_file *m = file->private_data;
  453. *n = PAGE_SIZE / (2 * sizeof(unsigned long));
  454. m->private = n;
  455. n = NULL;
  456. }
  457. kfree(n);
  458. }
  459. return ret;
  460. }
  461. static int slabstats_release(struct inode *inode, struct file *file)
  462. {
  463. struct seq_file *m = file->private_data;
  464. kfree(m->private);
  465. return seq_release(inode, file);
  466. }
  467. static struct file_operations proc_slabstats_operations = {
  468. .open = slabstats_open,
  469. .read = seq_read,
  470. .llseek = seq_lseek,
  471. .release = slabstats_release,
  472. };
  473. #endif
  474. #endif
  475. static int show_stat(struct seq_file *p, void *v)
  476. {
  477. int i;
  478. unsigned long jif;
  479. cputime64_t user, nice, system, idle, iowait, irq, softirq, steal;
  480. u64 sum = 0;
  481. user = nice = system = idle = iowait =
  482. irq = softirq = steal = cputime64_zero;
  483. jif = - wall_to_monotonic.tv_sec;
  484. if (wall_to_monotonic.tv_nsec)
  485. --jif;
  486. for_each_possible_cpu(i) {
  487. int j;
  488. user = cputime64_add(user, kstat_cpu(i).cpustat.user);
  489. nice = cputime64_add(nice, kstat_cpu(i).cpustat.nice);
  490. system = cputime64_add(system, kstat_cpu(i).cpustat.system);
  491. idle = cputime64_add(idle, kstat_cpu(i).cpustat.idle);
  492. iowait = cputime64_add(iowait, kstat_cpu(i).cpustat.iowait);
  493. irq = cputime64_add(irq, kstat_cpu(i).cpustat.irq);
  494. softirq = cputime64_add(softirq, kstat_cpu(i).cpustat.softirq);
  495. steal = cputime64_add(steal, kstat_cpu(i).cpustat.steal);
  496. for (j = 0 ; j < NR_IRQS ; j++)
  497. sum += kstat_cpu(i).irqs[j];
  498. }
  499. seq_printf(p, "cpu %llu %llu %llu %llu %llu %llu %llu %llu\n",
  500. (unsigned long long)cputime64_to_clock_t(user),
  501. (unsigned long long)cputime64_to_clock_t(nice),
  502. (unsigned long long)cputime64_to_clock_t(system),
  503. (unsigned long long)cputime64_to_clock_t(idle),
  504. (unsigned long long)cputime64_to_clock_t(iowait),
  505. (unsigned long long)cputime64_to_clock_t(irq),
  506. (unsigned long long)cputime64_to_clock_t(softirq),
  507. (unsigned long long)cputime64_to_clock_t(steal));
  508. for_each_online_cpu(i) {
  509. /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
  510. user = kstat_cpu(i).cpustat.user;
  511. nice = kstat_cpu(i).cpustat.nice;
  512. system = kstat_cpu(i).cpustat.system;
  513. idle = kstat_cpu(i).cpustat.idle;
  514. iowait = kstat_cpu(i).cpustat.iowait;
  515. irq = kstat_cpu(i).cpustat.irq;
  516. softirq = kstat_cpu(i).cpustat.softirq;
  517. steal = kstat_cpu(i).cpustat.steal;
  518. seq_printf(p, "cpu%d %llu %llu %llu %llu %llu %llu %llu %llu\n",
  519. i,
  520. (unsigned long long)cputime64_to_clock_t(user),
  521. (unsigned long long)cputime64_to_clock_t(nice),
  522. (unsigned long long)cputime64_to_clock_t(system),
  523. (unsigned long long)cputime64_to_clock_t(idle),
  524. (unsigned long long)cputime64_to_clock_t(iowait),
  525. (unsigned long long)cputime64_to_clock_t(irq),
  526. (unsigned long long)cputime64_to_clock_t(softirq),
  527. (unsigned long long)cputime64_to_clock_t(steal));
  528. }
  529. seq_printf(p, "intr %llu", (unsigned long long)sum);
  530. #if !defined(CONFIG_PPC64) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
  531. for (i = 0; i < NR_IRQS; i++)
  532. seq_printf(p, " %u", kstat_irqs(i));
  533. #endif
  534. seq_printf(p,
  535. "\nctxt %llu\n"
  536. "btime %lu\n"
  537. "processes %lu\n"
  538. "procs_running %lu\n"
  539. "procs_blocked %lu\n",
  540. nr_context_switches(),
  541. (unsigned long)jif,
  542. total_forks,
  543. nr_running(),
  544. nr_iowait());
  545. return 0;
  546. }
  547. static int stat_open(struct inode *inode, struct file *file)
  548. {
  549. unsigned size = 4096 * (1 + num_possible_cpus() / 32);
  550. char *buf;
  551. struct seq_file *m;
  552. int res;
  553. /* don't ask for more than the kmalloc() max size, currently 128 KB */
  554. if (size > 128 * 1024)
  555. size = 128 * 1024;
  556. buf = kmalloc(size, GFP_KERNEL);
  557. if (!buf)
  558. return -ENOMEM;
  559. res = single_open(file, show_stat, NULL);
  560. if (!res) {
  561. m = file->private_data;
  562. m->buf = buf;
  563. m->size = size;
  564. } else
  565. kfree(buf);
  566. return res;
  567. }
  568. static struct file_operations proc_stat_operations = {
  569. .open = stat_open,
  570. .read = seq_read,
  571. .llseek = seq_lseek,
  572. .release = single_release,
  573. };
  574. /*
  575. * /proc/interrupts
  576. */
  577. static void *int_seq_start(struct seq_file *f, loff_t *pos)
  578. {
  579. return (*pos <= NR_IRQS) ? pos : NULL;
  580. }
  581. static void *int_seq_next(struct seq_file *f, void *v, loff_t *pos)
  582. {
  583. (*pos)++;
  584. if (*pos > NR_IRQS)
  585. return NULL;
  586. return pos;
  587. }
  588. static void int_seq_stop(struct seq_file *f, void *v)
  589. {
  590. /* Nothing to do */
  591. }
  592. extern int show_interrupts(struct seq_file *f, void *v); /* In arch code */
  593. static struct seq_operations int_seq_ops = {
  594. .start = int_seq_start,
  595. .next = int_seq_next,
  596. .stop = int_seq_stop,
  597. .show = show_interrupts
  598. };
  599. static int interrupts_open(struct inode *inode, struct file *filp)
  600. {
  601. return seq_open(filp, &int_seq_ops);
  602. }
  603. static struct file_operations proc_interrupts_operations = {
  604. .open = interrupts_open,
  605. .read = seq_read,
  606. .llseek = seq_lseek,
  607. .release = seq_release,
  608. };
  609. static int filesystems_read_proc(char *page, char **start, off_t off,
  610. int count, int *eof, void *data)
  611. {
  612. int len = get_filesystem_list(page);
  613. return proc_calc_metrics(page, start, off, count, eof, len);
  614. }
  615. static int cmdline_read_proc(char *page, char **start, off_t off,
  616. int count, int *eof, void *data)
  617. {
  618. int len;
  619. len = sprintf(page, "%s\n", saved_command_line);
  620. return proc_calc_metrics(page, start, off, count, eof, len);
  621. }
  622. static int locks_read_proc(char *page, char **start, off_t off,
  623. int count, int *eof, void *data)
  624. {
  625. int len = get_locks_status(page, start, off, count);
  626. if (len < count)
  627. *eof = 1;
  628. return len;
  629. }
  630. static int execdomains_read_proc(char *page, char **start, off_t off,
  631. int count, int *eof, void *data)
  632. {
  633. int len = get_exec_domain_list(page);
  634. return proc_calc_metrics(page, start, off, count, eof, len);
  635. }
  636. #ifdef CONFIG_MAGIC_SYSRQ
  637. /*
  638. * writing 'C' to /proc/sysrq-trigger is like sysrq-C
  639. */
  640. static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
  641. size_t count, loff_t *ppos)
  642. {
  643. if (count) {
  644. char c;
  645. if (get_user(c, buf))
  646. return -EFAULT;
  647. __handle_sysrq(c, NULL, NULL, 0);
  648. }
  649. return count;
  650. }
  651. static struct file_operations proc_sysrq_trigger_operations = {
  652. .write = write_sysrq_trigger,
  653. };
  654. #endif
  655. struct proc_dir_entry *proc_root_kcore;
  656. void create_seq_entry(char *name, mode_t mode, const struct file_operations *f)
  657. {
  658. struct proc_dir_entry *entry;
  659. entry = create_proc_entry(name, mode, NULL);
  660. if (entry)
  661. entry->proc_fops = f;
  662. }
  663. void __init proc_misc_init(void)
  664. {
  665. struct proc_dir_entry *entry;
  666. static struct {
  667. char *name;
  668. int (*read_proc)(char*,char**,off_t,int,int*,void*);
  669. } *p, simple_ones[] = {
  670. {"loadavg", loadavg_read_proc},
  671. {"uptime", uptime_read_proc},
  672. {"meminfo", meminfo_read_proc},
  673. {"version", version_read_proc},
  674. #ifdef CONFIG_PROC_HARDWARE
  675. {"hardware", hardware_read_proc},
  676. #endif
  677. #ifdef CONFIG_STRAM_PROC
  678. {"stram", stram_read_proc},
  679. #endif
  680. {"filesystems", filesystems_read_proc},
  681. {"cmdline", cmdline_read_proc},
  682. {"locks", locks_read_proc},
  683. {"execdomains", execdomains_read_proc},
  684. {NULL,}
  685. };
  686. for (p = simple_ones; p->name; p++)
  687. create_proc_read_entry(p->name, 0, NULL, p->read_proc, NULL);
  688. proc_symlink("mounts", NULL, "self/mounts");
  689. /* And now for trickier ones */
  690. entry = create_proc_entry("kmsg", S_IRUSR, &proc_root);
  691. if (entry)
  692. entry->proc_fops = &proc_kmsg_operations;
  693. create_seq_entry("devices", 0, &proc_devinfo_operations);
  694. create_seq_entry("cpuinfo", 0, &proc_cpuinfo_operations);
  695. create_seq_entry("partitions", 0, &proc_partitions_operations);
  696. create_seq_entry("stat", 0, &proc_stat_operations);
  697. create_seq_entry("interrupts", 0, &proc_interrupts_operations);
  698. #ifdef CONFIG_SLAB
  699. create_seq_entry("slabinfo",S_IWUSR|S_IRUGO,&proc_slabinfo_operations);
  700. #ifdef CONFIG_DEBUG_SLAB_LEAK
  701. create_seq_entry("slab_allocators", 0 ,&proc_slabstats_operations);
  702. #endif
  703. #endif
  704. create_seq_entry("buddyinfo",S_IRUGO, &fragmentation_file_operations);
  705. create_seq_entry("vmstat",S_IRUGO, &proc_vmstat_file_operations);
  706. create_seq_entry("zoneinfo",S_IRUGO, &proc_zoneinfo_file_operations);
  707. create_seq_entry("diskstats", 0, &proc_diskstats_operations);
  708. #ifdef CONFIG_MODULES
  709. create_seq_entry("modules", 0, &proc_modules_operations);
  710. #endif
  711. #ifdef CONFIG_SCHEDSTATS
  712. create_seq_entry("schedstat", 0, &proc_schedstat_operations);
  713. #endif
  714. #ifdef CONFIG_PROC_KCORE
  715. proc_root_kcore = create_proc_entry("kcore", S_IRUSR, NULL);
  716. if (proc_root_kcore) {
  717. proc_root_kcore->proc_fops = &proc_kcore_operations;
  718. proc_root_kcore->size =
  719. (size_t)high_memory - PAGE_OFFSET + PAGE_SIZE;
  720. }
  721. #endif
  722. #ifdef CONFIG_PROC_VMCORE
  723. proc_vmcore = create_proc_entry("vmcore", S_IRUSR, NULL);
  724. if (proc_vmcore)
  725. proc_vmcore->proc_fops = &proc_vmcore_operations;
  726. #endif
  727. #ifdef CONFIG_MAGIC_SYSRQ
  728. entry = create_proc_entry("sysrq-trigger", S_IWUSR, NULL);
  729. if (entry)
  730. entry->proc_fops = &proc_sysrq_trigger_operations;
  731. #endif
  732. }