proc_misc.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749
  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/quicklist.h>
  27. #include <linux/proc_fs.h>
  28. #include <linux/ioport.h>
  29. #include <linux/mm.h>
  30. #include <linux/mmzone.h>
  31. #include <linux/pagemap.h>
  32. #include <linux/irq.h>
  33. #include <linux/interrupt.h>
  34. #include <linux/swap.h>
  35. #include <linux/slab.h>
  36. #include <linux/genhd.h>
  37. #include <linux/smp.h>
  38. #include <linux/signal.h>
  39. #include <linux/module.h>
  40. #include <linux/init.h>
  41. #include <linux/seq_file.h>
  42. #include <linux/times.h>
  43. #include <linux/profile.h>
  44. #include <linux/utsname.h>
  45. #include <linux/blkdev.h>
  46. #include <linux/hugetlb.h>
  47. #include <linux/jiffies.h>
  48. #include <linux/vmalloc.h>
  49. #include <linux/crash_dump.h>
  50. #include <linux/pid_namespace.h>
  51. #include <linux/bootmem.h>
  52. #include <asm/uaccess.h>
  53. #include <asm/pgtable.h>
  54. #include <asm/io.h>
  55. #include <asm/tlb.h>
  56. #include <asm/div64.h>
  57. #include "internal.h"
  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_exec_domain_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 fragmentation_open(struct inode *inode, struct file *file)
  78. {
  79. (void)inode;
  80. return seq_open(file, &fragmentation_op);
  81. }
  82. static const struct file_operations fragmentation_file_operations = {
  83. .open = fragmentation_open,
  84. .read = seq_read,
  85. .llseek = seq_lseek,
  86. .release = seq_release,
  87. };
  88. static int pagetypeinfo_open(struct inode *inode, struct file *file)
  89. {
  90. return seq_open(file, &pagetypeinfo_op);
  91. }
  92. static const struct file_operations pagetypeinfo_file_ops = {
  93. .open = pagetypeinfo_open,
  94. .read = seq_read,
  95. .llseek = seq_lseek,
  96. .release = seq_release,
  97. };
  98. static int zoneinfo_open(struct inode *inode, struct file *file)
  99. {
  100. return seq_open(file, &zoneinfo_op);
  101. }
  102. static const struct file_operations proc_zoneinfo_file_operations = {
  103. .open = zoneinfo_open,
  104. .read = seq_read,
  105. .llseek = seq_lseek,
  106. .release = seq_release,
  107. };
  108. static int version_read_proc(char *page, char **start, off_t off,
  109. int count, int *eof, void *data)
  110. {
  111. int len;
  112. len = snprintf(page, PAGE_SIZE, linux_proc_banner,
  113. utsname()->sysname,
  114. utsname()->release,
  115. utsname()->version);
  116. return proc_calc_metrics(page, start, off, count, eof, len);
  117. }
  118. extern const struct seq_operations cpuinfo_op;
  119. static int cpuinfo_open(struct inode *inode, struct file *file)
  120. {
  121. return seq_open(file, &cpuinfo_op);
  122. }
  123. static const struct file_operations proc_cpuinfo_operations = {
  124. .open = cpuinfo_open,
  125. .read = seq_read,
  126. .llseek = seq_lseek,
  127. .release = seq_release,
  128. };
  129. static int devinfo_show(struct seq_file *f, void *v)
  130. {
  131. int i = *(loff_t *) v;
  132. if (i < CHRDEV_MAJOR_HASH_SIZE) {
  133. if (i == 0)
  134. seq_printf(f, "Character devices:\n");
  135. chrdev_show(f, i);
  136. }
  137. #ifdef CONFIG_BLOCK
  138. else {
  139. i -= CHRDEV_MAJOR_HASH_SIZE;
  140. if (i == 0)
  141. seq_printf(f, "\nBlock devices:\n");
  142. blkdev_show(f, i);
  143. }
  144. #endif
  145. return 0;
  146. }
  147. static void *devinfo_start(struct seq_file *f, loff_t *pos)
  148. {
  149. if (*pos < (BLKDEV_MAJOR_HASH_SIZE + CHRDEV_MAJOR_HASH_SIZE))
  150. return pos;
  151. return NULL;
  152. }
  153. static void *devinfo_next(struct seq_file *f, void *v, loff_t *pos)
  154. {
  155. (*pos)++;
  156. if (*pos >= (BLKDEV_MAJOR_HASH_SIZE + CHRDEV_MAJOR_HASH_SIZE))
  157. return NULL;
  158. return pos;
  159. }
  160. static void devinfo_stop(struct seq_file *f, void *v)
  161. {
  162. /* Nothing to do */
  163. }
  164. static const struct seq_operations devinfo_ops = {
  165. .start = devinfo_start,
  166. .next = devinfo_next,
  167. .stop = devinfo_stop,
  168. .show = devinfo_show
  169. };
  170. static int devinfo_open(struct inode *inode, struct file *filp)
  171. {
  172. return seq_open(filp, &devinfo_ops);
  173. }
  174. static const struct file_operations proc_devinfo_operations = {
  175. .open = devinfo_open,
  176. .read = seq_read,
  177. .llseek = seq_lseek,
  178. .release = seq_release,
  179. };
  180. static int vmstat_open(struct inode *inode, struct file *file)
  181. {
  182. return seq_open(file, &vmstat_op);
  183. }
  184. static const struct file_operations proc_vmstat_file_operations = {
  185. .open = vmstat_open,
  186. .read = seq_read,
  187. .llseek = seq_lseek,
  188. .release = seq_release,
  189. };
  190. #ifdef CONFIG_PROC_HARDWARE
  191. static int hardware_read_proc(char *page, char **start, off_t off,
  192. int count, int *eof, void *data)
  193. {
  194. int len = get_hardware_list(page);
  195. return proc_calc_metrics(page, start, off, count, eof, len);
  196. }
  197. #endif
  198. #ifdef CONFIG_STRAM_PROC
  199. static int stram_read_proc(char *page, char **start, off_t off,
  200. int count, int *eof, void *data)
  201. {
  202. int len = get_stram_list(page);
  203. return proc_calc_metrics(page, start, off, count, eof, len);
  204. }
  205. #endif
  206. #ifdef CONFIG_BLOCK
  207. static int partitions_open(struct inode *inode, struct file *file)
  208. {
  209. return seq_open(file, &partitions_op);
  210. }
  211. static const struct file_operations proc_partitions_operations = {
  212. .open = partitions_open,
  213. .read = seq_read,
  214. .llseek = seq_lseek,
  215. .release = seq_release,
  216. };
  217. static int diskstats_open(struct inode *inode, struct file *file)
  218. {
  219. return seq_open(file, &diskstats_op);
  220. }
  221. static const struct file_operations proc_diskstats_operations = {
  222. .open = diskstats_open,
  223. .read = seq_read,
  224. .llseek = seq_lseek,
  225. .release = seq_release,
  226. };
  227. #endif
  228. #ifdef CONFIG_MODULES
  229. extern const struct seq_operations modules_op;
  230. static int modules_open(struct inode *inode, struct file *file)
  231. {
  232. return seq_open(file, &modules_op);
  233. }
  234. static const struct file_operations proc_modules_operations = {
  235. .open = modules_open,
  236. .read = seq_read,
  237. .llseek = seq_lseek,
  238. .release = seq_release,
  239. };
  240. #endif
  241. #ifdef CONFIG_SLABINFO
  242. static int slabinfo_open(struct inode *inode, struct file *file)
  243. {
  244. return seq_open(file, &slabinfo_op);
  245. }
  246. static const struct file_operations proc_slabinfo_operations = {
  247. .open = slabinfo_open,
  248. .read = seq_read,
  249. .write = slabinfo_write,
  250. .llseek = seq_lseek,
  251. .release = seq_release,
  252. };
  253. #ifdef CONFIG_DEBUG_SLAB_LEAK
  254. extern const struct seq_operations slabstats_op;
  255. static int slabstats_open(struct inode *inode, struct file *file)
  256. {
  257. unsigned long *n = kzalloc(PAGE_SIZE, GFP_KERNEL);
  258. int ret = -ENOMEM;
  259. if (n) {
  260. ret = seq_open(file, &slabstats_op);
  261. if (!ret) {
  262. struct seq_file *m = file->private_data;
  263. *n = PAGE_SIZE / (2 * sizeof(unsigned long));
  264. m->private = n;
  265. n = NULL;
  266. }
  267. kfree(n);
  268. }
  269. return ret;
  270. }
  271. static const struct file_operations proc_slabstats_operations = {
  272. .open = slabstats_open,
  273. .read = seq_read,
  274. .llseek = seq_lseek,
  275. .release = seq_release_private,
  276. };
  277. #endif
  278. #endif
  279. #ifdef CONFIG_MMU
  280. static int vmalloc_open(struct inode *inode, struct file *file)
  281. {
  282. unsigned int *ptr = NULL;
  283. int ret;
  284. if (NUMA_BUILD)
  285. ptr = kmalloc(nr_node_ids * sizeof(unsigned int), GFP_KERNEL);
  286. ret = seq_open(file, &vmalloc_op);
  287. if (!ret) {
  288. struct seq_file *m = file->private_data;
  289. m->private = ptr;
  290. } else
  291. kfree(ptr);
  292. return ret;
  293. }
  294. static const struct file_operations proc_vmalloc_operations = {
  295. .open = vmalloc_open,
  296. .read = seq_read,
  297. .llseek = seq_lseek,
  298. .release = seq_release_private,
  299. };
  300. #endif
  301. #ifndef arch_irq_stat_cpu
  302. #define arch_irq_stat_cpu(cpu) 0
  303. #endif
  304. #ifndef arch_irq_stat
  305. #define arch_irq_stat() 0
  306. #endif
  307. static int show_stat(struct seq_file *p, void *v)
  308. {
  309. int i, j;
  310. unsigned long jif;
  311. cputime64_t user, nice, system, idle, iowait, irq, softirq, steal;
  312. cputime64_t guest;
  313. u64 sum = 0;
  314. struct timespec boottime;
  315. unsigned int per_irq_sum;
  316. user = nice = system = idle = iowait =
  317. irq = softirq = steal = cputime64_zero;
  318. guest = cputime64_zero;
  319. getboottime(&boottime);
  320. jif = boottime.tv_sec;
  321. for_each_possible_cpu(i) {
  322. user = cputime64_add(user, kstat_cpu(i).cpustat.user);
  323. nice = cputime64_add(nice, kstat_cpu(i).cpustat.nice);
  324. system = cputime64_add(system, kstat_cpu(i).cpustat.system);
  325. idle = cputime64_add(idle, kstat_cpu(i).cpustat.idle);
  326. iowait = cputime64_add(iowait, kstat_cpu(i).cpustat.iowait);
  327. irq = cputime64_add(irq, kstat_cpu(i).cpustat.irq);
  328. softirq = cputime64_add(softirq, kstat_cpu(i).cpustat.softirq);
  329. steal = cputime64_add(steal, kstat_cpu(i).cpustat.steal);
  330. guest = cputime64_add(guest, kstat_cpu(i).cpustat.guest);
  331. for_each_irq_nr(j)
  332. sum += kstat_irqs_cpu(j, i);
  333. sum += arch_irq_stat_cpu(i);
  334. }
  335. sum += arch_irq_stat();
  336. seq_printf(p, "cpu %llu %llu %llu %llu %llu %llu %llu %llu %llu\n",
  337. (unsigned long long)cputime64_to_clock_t(user),
  338. (unsigned long long)cputime64_to_clock_t(nice),
  339. (unsigned long long)cputime64_to_clock_t(system),
  340. (unsigned long long)cputime64_to_clock_t(idle),
  341. (unsigned long long)cputime64_to_clock_t(iowait),
  342. (unsigned long long)cputime64_to_clock_t(irq),
  343. (unsigned long long)cputime64_to_clock_t(softirq),
  344. (unsigned long long)cputime64_to_clock_t(steal),
  345. (unsigned long long)cputime64_to_clock_t(guest));
  346. for_each_online_cpu(i) {
  347. /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
  348. user = kstat_cpu(i).cpustat.user;
  349. nice = kstat_cpu(i).cpustat.nice;
  350. system = kstat_cpu(i).cpustat.system;
  351. idle = kstat_cpu(i).cpustat.idle;
  352. iowait = kstat_cpu(i).cpustat.iowait;
  353. irq = kstat_cpu(i).cpustat.irq;
  354. softirq = kstat_cpu(i).cpustat.softirq;
  355. steal = kstat_cpu(i).cpustat.steal;
  356. guest = kstat_cpu(i).cpustat.guest;
  357. seq_printf(p,
  358. "cpu%d %llu %llu %llu %llu %llu %llu %llu %llu %llu\n",
  359. i,
  360. (unsigned long long)cputime64_to_clock_t(user),
  361. (unsigned long long)cputime64_to_clock_t(nice),
  362. (unsigned long long)cputime64_to_clock_t(system),
  363. (unsigned long long)cputime64_to_clock_t(idle),
  364. (unsigned long long)cputime64_to_clock_t(iowait),
  365. (unsigned long long)cputime64_to_clock_t(irq),
  366. (unsigned long long)cputime64_to_clock_t(softirq),
  367. (unsigned long long)cputime64_to_clock_t(steal),
  368. (unsigned long long)cputime64_to_clock_t(guest));
  369. }
  370. seq_printf(p, "intr %llu", (unsigned long long)sum);
  371. /* sum again ? it could be updated? */
  372. for_each_irq_nr(j) {
  373. per_irq_sum = 0;
  374. for_each_possible_cpu(i)
  375. per_irq_sum += kstat_irqs_cpu(j, i);
  376. seq_printf(p, " %u", per_irq_sum);
  377. }
  378. seq_printf(p,
  379. "\nctxt %llu\n"
  380. "btime %lu\n"
  381. "processes %lu\n"
  382. "procs_running %lu\n"
  383. "procs_blocked %lu\n",
  384. nr_context_switches(),
  385. (unsigned long)jif,
  386. total_forks,
  387. nr_running(),
  388. nr_iowait());
  389. return 0;
  390. }
  391. static int stat_open(struct inode *inode, struct file *file)
  392. {
  393. unsigned size = 4096 * (1 + num_possible_cpus() / 32);
  394. char *buf;
  395. struct seq_file *m;
  396. int res;
  397. /* don't ask for more than the kmalloc() max size, currently 128 KB */
  398. if (size > 128 * 1024)
  399. size = 128 * 1024;
  400. buf = kmalloc(size, GFP_KERNEL);
  401. if (!buf)
  402. return -ENOMEM;
  403. res = single_open(file, show_stat, NULL);
  404. if (!res) {
  405. m = file->private_data;
  406. m->buf = buf;
  407. m->size = size;
  408. } else
  409. kfree(buf);
  410. return res;
  411. }
  412. static const struct file_operations proc_stat_operations = {
  413. .open = stat_open,
  414. .read = seq_read,
  415. .llseek = seq_lseek,
  416. .release = single_release,
  417. };
  418. /*
  419. * /proc/interrupts
  420. */
  421. static void *int_seq_start(struct seq_file *f, loff_t *pos)
  422. {
  423. return (*pos <= nr_irqs) ? pos : NULL;
  424. }
  425. static void *int_seq_next(struct seq_file *f, void *v, loff_t *pos)
  426. {
  427. (*pos)++;
  428. return (*pos <= nr_irqs) ? pos : NULL;
  429. }
  430. static void int_seq_stop(struct seq_file *f, void *v)
  431. {
  432. /* Nothing to do */
  433. }
  434. static const struct seq_operations int_seq_ops = {
  435. .start = int_seq_start,
  436. .next = int_seq_next,
  437. .stop = int_seq_stop,
  438. .show = show_interrupts
  439. };
  440. static int interrupts_open(struct inode *inode, struct file *filp)
  441. {
  442. return seq_open(filp, &int_seq_ops);
  443. }
  444. static const struct file_operations proc_interrupts_operations = {
  445. .open = interrupts_open,
  446. .read = seq_read,
  447. .llseek = seq_lseek,
  448. .release = seq_release,
  449. };
  450. static int filesystems_read_proc(char *page, char **start, off_t off,
  451. int count, int *eof, void *data)
  452. {
  453. int len = get_filesystem_list(page);
  454. return proc_calc_metrics(page, start, off, count, eof, len);
  455. }
  456. static int cmdline_read_proc(char *page, char **start, off_t off,
  457. int count, int *eof, void *data)
  458. {
  459. int len;
  460. len = sprintf(page, "%s\n", saved_command_line);
  461. return proc_calc_metrics(page, start, off, count, eof, len);
  462. }
  463. #ifdef CONFIG_FILE_LOCKING
  464. static int locks_open(struct inode *inode, struct file *filp)
  465. {
  466. return seq_open(filp, &locks_seq_operations);
  467. }
  468. static const struct file_operations proc_locks_operations = {
  469. .open = locks_open,
  470. .read = seq_read,
  471. .llseek = seq_lseek,
  472. .release = seq_release,
  473. };
  474. #endif /* CONFIG_FILE_LOCKING */
  475. static int execdomains_read_proc(char *page, char **start, off_t off,
  476. int count, int *eof, void *data)
  477. {
  478. int len = get_exec_domain_list(page);
  479. return proc_calc_metrics(page, start, off, count, eof, len);
  480. }
  481. #ifdef CONFIG_PROC_PAGE_MONITOR
  482. #define KPMSIZE sizeof(u64)
  483. #define KPMMASK (KPMSIZE - 1)
  484. /* /proc/kpagecount - an array exposing page counts
  485. *
  486. * Each entry is a u64 representing the corresponding
  487. * physical page count.
  488. */
  489. static ssize_t kpagecount_read(struct file *file, char __user *buf,
  490. size_t count, loff_t *ppos)
  491. {
  492. u64 __user *out = (u64 __user *)buf;
  493. struct page *ppage;
  494. unsigned long src = *ppos;
  495. unsigned long pfn;
  496. ssize_t ret = 0;
  497. u64 pcount;
  498. pfn = src / KPMSIZE;
  499. count = min_t(size_t, count, (max_pfn * KPMSIZE) - src);
  500. if (src & KPMMASK || count & KPMMASK)
  501. return -EINVAL;
  502. while (count > 0) {
  503. ppage = NULL;
  504. if (pfn_valid(pfn))
  505. ppage = pfn_to_page(pfn);
  506. pfn++;
  507. if (!ppage)
  508. pcount = 0;
  509. else
  510. pcount = page_mapcount(ppage);
  511. if (put_user(pcount, out++)) {
  512. ret = -EFAULT;
  513. break;
  514. }
  515. count -= KPMSIZE;
  516. }
  517. *ppos += (char __user *)out - buf;
  518. if (!ret)
  519. ret = (char __user *)out - buf;
  520. return ret;
  521. }
  522. static struct file_operations proc_kpagecount_operations = {
  523. .llseek = mem_lseek,
  524. .read = kpagecount_read,
  525. };
  526. /* /proc/kpageflags - an array exposing page flags
  527. *
  528. * Each entry is a u64 representing the corresponding
  529. * physical page flags.
  530. */
  531. /* These macros are used to decouple internal flags from exported ones */
  532. #define KPF_LOCKED 0
  533. #define KPF_ERROR 1
  534. #define KPF_REFERENCED 2
  535. #define KPF_UPTODATE 3
  536. #define KPF_DIRTY 4
  537. #define KPF_LRU 5
  538. #define KPF_ACTIVE 6
  539. #define KPF_SLAB 7
  540. #define KPF_WRITEBACK 8
  541. #define KPF_RECLAIM 9
  542. #define KPF_BUDDY 10
  543. #define kpf_copy_bit(flags, srcpos, dstpos) (((flags >> srcpos) & 1) << dstpos)
  544. static ssize_t kpageflags_read(struct file *file, char __user *buf,
  545. size_t count, loff_t *ppos)
  546. {
  547. u64 __user *out = (u64 __user *)buf;
  548. struct page *ppage;
  549. unsigned long src = *ppos;
  550. unsigned long pfn;
  551. ssize_t ret = 0;
  552. u64 kflags, uflags;
  553. pfn = src / KPMSIZE;
  554. count = min_t(unsigned long, count, (max_pfn * KPMSIZE) - src);
  555. if (src & KPMMASK || count & KPMMASK)
  556. return -EINVAL;
  557. while (count > 0) {
  558. ppage = NULL;
  559. if (pfn_valid(pfn))
  560. ppage = pfn_to_page(pfn);
  561. pfn++;
  562. if (!ppage)
  563. kflags = 0;
  564. else
  565. kflags = ppage->flags;
  566. uflags = kpf_copy_bit(KPF_LOCKED, PG_locked, kflags) |
  567. kpf_copy_bit(kflags, KPF_ERROR, PG_error) |
  568. kpf_copy_bit(kflags, KPF_REFERENCED, PG_referenced) |
  569. kpf_copy_bit(kflags, KPF_UPTODATE, PG_uptodate) |
  570. kpf_copy_bit(kflags, KPF_DIRTY, PG_dirty) |
  571. kpf_copy_bit(kflags, KPF_LRU, PG_lru) |
  572. kpf_copy_bit(kflags, KPF_ACTIVE, PG_active) |
  573. kpf_copy_bit(kflags, KPF_SLAB, PG_slab) |
  574. kpf_copy_bit(kflags, KPF_WRITEBACK, PG_writeback) |
  575. kpf_copy_bit(kflags, KPF_RECLAIM, PG_reclaim) |
  576. kpf_copy_bit(kflags, KPF_BUDDY, PG_buddy);
  577. if (put_user(uflags, out++)) {
  578. ret = -EFAULT;
  579. break;
  580. }
  581. count -= KPMSIZE;
  582. }
  583. *ppos += (char __user *)out - buf;
  584. if (!ret)
  585. ret = (char __user *)out - buf;
  586. return ret;
  587. }
  588. static struct file_operations proc_kpageflags_operations = {
  589. .llseek = mem_lseek,
  590. .read = kpageflags_read,
  591. };
  592. #endif /* CONFIG_PROC_PAGE_MONITOR */
  593. struct proc_dir_entry *proc_root_kcore;
  594. void __init proc_misc_init(void)
  595. {
  596. static struct {
  597. char *name;
  598. int (*read_proc)(char*,char**,off_t,int,int*,void*);
  599. } *p, simple_ones[] = {
  600. {"version", version_read_proc},
  601. #ifdef CONFIG_PROC_HARDWARE
  602. {"hardware", hardware_read_proc},
  603. #endif
  604. #ifdef CONFIG_STRAM_PROC
  605. {"stram", stram_read_proc},
  606. #endif
  607. {"filesystems", filesystems_read_proc},
  608. {"cmdline", cmdline_read_proc},
  609. {"execdomains", execdomains_read_proc},
  610. {NULL,}
  611. };
  612. for (p = simple_ones; p->name; p++)
  613. create_proc_read_entry(p->name, 0, NULL, p->read_proc, NULL);
  614. proc_symlink("mounts", NULL, "self/mounts");
  615. /* And now for trickier ones */
  616. #ifdef CONFIG_PRINTK
  617. proc_create("kmsg", S_IRUSR, NULL, &proc_kmsg_operations);
  618. #endif
  619. #ifdef CONFIG_FILE_LOCKING
  620. proc_create("locks", 0, NULL, &proc_locks_operations);
  621. #endif
  622. proc_create("devices", 0, NULL, &proc_devinfo_operations);
  623. proc_create("cpuinfo", 0, NULL, &proc_cpuinfo_operations);
  624. #ifdef CONFIG_BLOCK
  625. proc_create("partitions", 0, NULL, &proc_partitions_operations);
  626. #endif
  627. proc_create("stat", 0, NULL, &proc_stat_operations);
  628. proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
  629. #ifdef CONFIG_SLABINFO
  630. proc_create("slabinfo",S_IWUSR|S_IRUGO,NULL,&proc_slabinfo_operations);
  631. #ifdef CONFIG_DEBUG_SLAB_LEAK
  632. proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
  633. #endif
  634. #endif
  635. #ifdef CONFIG_MMU
  636. proc_create("vmallocinfo", S_IRUSR, NULL, &proc_vmalloc_operations);
  637. #endif
  638. proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
  639. proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
  640. proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
  641. proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
  642. #ifdef CONFIG_BLOCK
  643. proc_create("diskstats", 0, NULL, &proc_diskstats_operations);
  644. #endif
  645. #ifdef CONFIG_MODULES
  646. proc_create("modules", 0, NULL, &proc_modules_operations);
  647. #endif
  648. #ifdef CONFIG_SCHEDSTATS
  649. proc_create("schedstat", 0, NULL, &proc_schedstat_operations);
  650. #endif
  651. #ifdef CONFIG_PROC_KCORE
  652. proc_root_kcore = proc_create("kcore", S_IRUSR, NULL, &proc_kcore_operations);
  653. if (proc_root_kcore)
  654. proc_root_kcore->size =
  655. (size_t)high_memory - PAGE_OFFSET + PAGE_SIZE;
  656. #endif
  657. #ifdef CONFIG_PROC_PAGE_MONITOR
  658. proc_create("kpagecount", S_IRUSR, NULL, &proc_kpagecount_operations);
  659. proc_create("kpageflags", S_IRUSR, NULL, &proc_kpageflags_operations);
  660. #endif
  661. #ifdef CONFIG_PROC_VMCORE
  662. proc_vmcore = proc_create("vmcore", S_IRUSR, NULL, &proc_vmcore_operations);
  663. #endif
  664. }