debug.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*
  2. * debug.c - NTFS kernel debug support. Part of the Linux-NTFS project.
  3. *
  4. * Copyright (c) 2001-2004 Anton Altaparmakov
  5. *
  6. * This program/include file is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as published
  8. * by the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program/include file is distributed in the hope that it will be
  12. * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
  13. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program (in the main directory of the Linux-NTFS
  18. * distribution in the file COPYING); if not, write to the Free Software
  19. * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. #include "debug.h"
  22. /*
  23. * A static buffer to hold the error string being displayed and a spinlock
  24. * to protect concurrent accesses to it.
  25. */
  26. static char err_buf[1024];
  27. static DEFINE_SPINLOCK(err_buf_lock);
  28. /**
  29. * __ntfs_warning - output a warning to the syslog
  30. * @function: name of function outputting the warning
  31. * @sb: super block of mounted ntfs filesystem
  32. * @fmt: warning string containing format specifications
  33. * @...: a variable number of arguments specified in @fmt
  34. *
  35. * Outputs a warning to the syslog for the mounted ntfs filesystem described
  36. * by @sb.
  37. *
  38. * @fmt and the corresponding @... is printf style format string containing
  39. * the warning string and the corresponding format arguments, respectively.
  40. *
  41. * @function is the name of the function from which __ntfs_warning is being
  42. * called.
  43. *
  44. * Note, you should be using debug.h::ntfs_warning(@sb, @fmt, @...) instead
  45. * as this provides the @function parameter automatically.
  46. */
  47. void __ntfs_warning(const char *function, const struct super_block *sb,
  48. const char *fmt, ...)
  49. {
  50. va_list args;
  51. int flen = 0;
  52. #ifndef DEBUG
  53. if (!printk_ratelimit())
  54. return;
  55. #endif
  56. if (function)
  57. flen = strlen(function);
  58. spin_lock(&err_buf_lock);
  59. va_start(args, fmt);
  60. vsnprintf(err_buf, sizeof(err_buf), fmt, args);
  61. va_end(args);
  62. if (sb)
  63. printk(KERN_ERR "NTFS-fs warning (device %s): %s(): %s\n",
  64. sb->s_id, flen ? function : "", err_buf);
  65. else
  66. printk(KERN_ERR "NTFS-fs warning: %s(): %s\n",
  67. flen ? function : "", err_buf);
  68. spin_unlock(&err_buf_lock);
  69. }
  70. /**
  71. * __ntfs_error - output an error to the syslog
  72. * @function: name of function outputting the error
  73. * @sb: super block of mounted ntfs filesystem
  74. * @fmt: error string containing format specifications
  75. * @...: a variable number of arguments specified in @fmt
  76. *
  77. * Outputs an error to the syslog for the mounted ntfs filesystem described
  78. * by @sb.
  79. *
  80. * @fmt and the corresponding @... is printf style format string containing
  81. * the error string and the corresponding format arguments, respectively.
  82. *
  83. * @function is the name of the function from which __ntfs_error is being
  84. * called.
  85. *
  86. * Note, you should be using debug.h::ntfs_error(@sb, @fmt, @...) instead
  87. * as this provides the @function parameter automatically.
  88. */
  89. void __ntfs_error(const char *function, const struct super_block *sb,
  90. const char *fmt, ...)
  91. {
  92. va_list args;
  93. int flen = 0;
  94. #ifndef DEBUG
  95. if (!printk_ratelimit())
  96. return;
  97. #endif
  98. if (function)
  99. flen = strlen(function);
  100. spin_lock(&err_buf_lock);
  101. va_start(args, fmt);
  102. vsnprintf(err_buf, sizeof(err_buf), fmt, args);
  103. va_end(args);
  104. if (sb)
  105. printk(KERN_ERR "NTFS-fs error (device %s): %s(): %s\n",
  106. sb->s_id, flen ? function : "", err_buf);
  107. else
  108. printk(KERN_ERR "NTFS-fs error: %s(): %s\n",
  109. flen ? function : "", err_buf);
  110. spin_unlock(&err_buf_lock);
  111. }
  112. #ifdef DEBUG
  113. /* If 1, output debug messages, and if 0, don't. */
  114. int debug_msgs = 0;
  115. void __ntfs_debug (const char *file, int line, const char *function,
  116. const char *fmt, ...)
  117. {
  118. va_list args;
  119. int flen = 0;
  120. if (!debug_msgs)
  121. return;
  122. if (function)
  123. flen = strlen(function);
  124. spin_lock(&err_buf_lock);
  125. va_start(args, fmt);
  126. vsnprintf(err_buf, sizeof(err_buf), fmt, args);
  127. va_end(args);
  128. printk(KERN_DEBUG "NTFS-fs DEBUG (%s, %d): %s(): %s\n", file, line,
  129. flen ? function : "", err_buf);
  130. spin_unlock(&err_buf_lock);
  131. }
  132. /* Dump a runlist. Caller has to provide synchronisation for @rl. */
  133. void ntfs_debug_dump_runlist(const runlist_element *rl)
  134. {
  135. int i;
  136. const char *lcn_str[5] = { "LCN_HOLE ", "LCN_RL_NOT_MAPPED",
  137. "LCN_ENOENT ", "LCN_unknown " };
  138. if (!debug_msgs)
  139. return;
  140. printk(KERN_DEBUG "NTFS-fs DEBUG: Dumping runlist (values in hex):\n");
  141. if (!rl) {
  142. printk(KERN_DEBUG "Run list not present.\n");
  143. return;
  144. }
  145. printk(KERN_DEBUG "VCN LCN Run length\n");
  146. for (i = 0; ; i++) {
  147. LCN lcn = (rl + i)->lcn;
  148. if (lcn < (LCN)0) {
  149. int index = -lcn - 1;
  150. if (index > -LCN_ENOENT - 1)
  151. index = 3;
  152. printk(KERN_DEBUG "%-16Lx %s %-16Lx%s\n",
  153. (long long)(rl + i)->vcn, lcn_str[index],
  154. (long long)(rl + i)->length,
  155. (rl + i)->length ? "" :
  156. " (runlist end)");
  157. } else
  158. printk(KERN_DEBUG "%-16Lx %-16Lx %-16Lx%s\n",
  159. (long long)(rl + i)->vcn,
  160. (long long)(rl + i)->lcn,
  161. (long long)(rl + i)->length,
  162. (rl + i)->length ? "" :
  163. " (runlist end)");
  164. if (!(rl + i)->length)
  165. break;
  166. }
  167. }
  168. #endif