jfs_debug.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. * Copyright (C) International Business Machines Corp., 2000-2004
  3. * Portions Copyright (C) Christoph Hellwig, 2001-2002
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  13. * the GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #include <linux/fs.h>
  20. #include <linux/ctype.h>
  21. #include <linux/module.h>
  22. #include <linux/proc_fs.h>
  23. #include <asm/uaccess.h>
  24. #include "jfs_incore.h"
  25. #include "jfs_filsys.h"
  26. #include "jfs_debug.h"
  27. #ifdef CONFIG_JFS_DEBUG
  28. void dump_mem(char *label, void *data, int length)
  29. {
  30. int i, j;
  31. int *intptr = data;
  32. char *charptr = data;
  33. char buf[10], line[80];
  34. printk("%s: dump of %d bytes of data at 0x%p\n\n", label, length,
  35. data);
  36. for (i = 0; i < length; i += 16) {
  37. line[0] = 0;
  38. for (j = 0; (j < 4) && (i + j * 4 < length); j++) {
  39. sprintf(buf, " %08x", intptr[i / 4 + j]);
  40. strcat(line, buf);
  41. }
  42. buf[0] = ' ';
  43. buf[2] = 0;
  44. for (j = 0; (j < 16) && (i + j < length); j++) {
  45. buf[1] =
  46. isprint(charptr[i + j]) ? charptr[i + j] : '.';
  47. strcat(line, buf);
  48. }
  49. printk("%s\n", line);
  50. }
  51. }
  52. #endif
  53. #ifdef PROC_FS_JFS /* see jfs_debug.h */
  54. static struct proc_dir_entry *base;
  55. #ifdef CONFIG_JFS_DEBUG
  56. static int loglevel_read(char *page, char **start, off_t off,
  57. int count, int *eof, void *data)
  58. {
  59. int len;
  60. len = sprintf(page, "%d\n", jfsloglevel);
  61. len -= off;
  62. *start = page + off;
  63. if (len > count)
  64. len = count;
  65. else
  66. *eof = 1;
  67. if (len < 0)
  68. len = 0;
  69. return len;
  70. }
  71. static int loglevel_write(struct file *file, const char __user *buffer,
  72. unsigned long count, void *data)
  73. {
  74. char c;
  75. if (get_user(c, buffer))
  76. return -EFAULT;
  77. /* yes, I know this is an ASCIIism. --hch */
  78. if (c < '0' || c > '9')
  79. return -EINVAL;
  80. jfsloglevel = c - '0';
  81. return count;
  82. }
  83. #endif
  84. static struct {
  85. const char *name;
  86. read_proc_t *read_fn;
  87. write_proc_t *write_fn;
  88. } Entries[] = {
  89. #ifdef CONFIG_JFS_STATISTICS
  90. { "lmstats", jfs_lmstats_read, },
  91. { "txstats", jfs_txstats_read, },
  92. { "xtstat", jfs_xtstat_read, },
  93. { "mpstat", jfs_mpstat_read, },
  94. #endif
  95. #ifdef CONFIG_JFS_DEBUG
  96. { "TxAnchor", jfs_txanchor_read, },
  97. { "loglevel", loglevel_read, loglevel_write }
  98. #endif
  99. };
  100. #define NPROCENT ARRAY_SIZE(Entries)
  101. void jfs_proc_init(void)
  102. {
  103. int i;
  104. if (!(base = proc_mkdir("jfs", proc_root_fs)))
  105. return;
  106. base->owner = THIS_MODULE;
  107. for (i = 0; i < NPROCENT; i++) {
  108. struct proc_dir_entry *p;
  109. if ((p = create_proc_entry(Entries[i].name, 0, base))) {
  110. p->read_proc = Entries[i].read_fn;
  111. p->write_proc = Entries[i].write_fn;
  112. }
  113. }
  114. }
  115. void jfs_proc_clean(void)
  116. {
  117. int i;
  118. if (base) {
  119. for (i = 0; i < NPROCENT; i++)
  120. remove_proc_entry(Entries[i].name, base);
  121. remove_proc_entry("jfs", proc_root_fs);
  122. }
  123. }
  124. #endif /* PROC_FS_JFS */