proc_misc.c 20 KB

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