debug.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  22. #include "debug.h"
  23. /**
  24. * __ntfs_warning - output a warning to the syslog
  25. * @function: name of function outputting the warning
  26. * @sb: super block of mounted ntfs filesystem
  27. * @fmt: warning string containing format specifications
  28. * @...: a variable number of arguments specified in @fmt
  29. *
  30. * Outputs a warning to the syslog for the mounted ntfs filesystem described
  31. * by @sb.
  32. *
  33. * @fmt and the corresponding @... is printf style format string containing
  34. * the warning string and the corresponding format arguments, respectively.
  35. *
  36. * @function is the name of the function from which __ntfs_warning is being
  37. * called.
  38. *
  39. * Note, you should be using debug.h::ntfs_warning(@sb, @fmt, @...) instead
  40. * as this provides the @function parameter automatically.
  41. */
  42. void __ntfs_warning(const char *function, const struct super_block *sb,
  43. const char *fmt, ...)
  44. {
  45. struct va_format vaf;
  46. va_list args;
  47. int flen = 0;
  48. #ifndef DEBUG
  49. if (!printk_ratelimit())
  50. return;
  51. #endif
  52. if (function)
  53. flen = strlen(function);
  54. va_start(args, fmt);
  55. vaf.fmt = fmt;
  56. vaf.va = &args;
  57. if (sb)
  58. pr_warn("(device %s): %s(): %pV\n",
  59. sb->s_id, flen ? function : "", &vaf);
  60. else
  61. pr_warn("%s(): %pV\n", flen ? function : "", &vaf);
  62. va_end(args);
  63. }
  64. /**
  65. * __ntfs_error - output an error to the syslog
  66. * @function: name of function outputting the error
  67. * @sb: super block of mounted ntfs filesystem
  68. * @fmt: error string containing format specifications
  69. * @...: a variable number of arguments specified in @fmt
  70. *
  71. * Outputs an error to the syslog for the mounted ntfs filesystem described
  72. * by @sb.
  73. *
  74. * @fmt and the corresponding @... is printf style format string containing
  75. * the error string and the corresponding format arguments, respectively.
  76. *
  77. * @function is the name of the function from which __ntfs_error is being
  78. * called.
  79. *
  80. * Note, you should be using debug.h::ntfs_error(@sb, @fmt, @...) instead
  81. * as this provides the @function parameter automatically.
  82. */
  83. void __ntfs_error(const char *function, const struct super_block *sb,
  84. const char *fmt, ...)
  85. {
  86. struct va_format vaf;
  87. va_list args;
  88. int flen = 0;
  89. #ifndef DEBUG
  90. if (!printk_ratelimit())
  91. return;
  92. #endif
  93. if (function)
  94. flen = strlen(function);
  95. va_start(args, fmt);
  96. vaf.fmt = fmt;
  97. vaf.va = &args;
  98. if (sb)
  99. pr_err("(device %s): %s(): %pV\n",
  100. sb->s_id, flen ? function : "", &vaf);
  101. else
  102. pr_err("%s(): %pV\n", flen ? function : "", &vaf);
  103. va_end(args);
  104. }
  105. #ifdef DEBUG
  106. /* If 1, output debug messages, and if 0, don't. */
  107. int debug_msgs = 0;
  108. void __ntfs_debug(const char *file, int line, const char *function,
  109. const char *fmt, ...)
  110. {
  111. struct va_format vaf;
  112. va_list args;
  113. int flen = 0;
  114. if (!debug_msgs)
  115. return;
  116. if (function)
  117. flen = strlen(function);
  118. va_start(args, fmt);
  119. vaf.fmt = fmt;
  120. vaf.va = &args;
  121. pr_debug("(%s, %d): %s(): %pV", file, line, flen ? function : "", &vaf);
  122. va_end(args);
  123. }
  124. /* Dump a runlist. Caller has to provide synchronisation for @rl. */
  125. void ntfs_debug_dump_runlist(const runlist_element *rl)
  126. {
  127. int i;
  128. const char *lcn_str[5] = { "LCN_HOLE ", "LCN_RL_NOT_MAPPED",
  129. "LCN_ENOENT ", "LCN_unknown " };
  130. if (!debug_msgs)
  131. return;
  132. pr_debug("Dumping runlist (values in hex):\n");
  133. if (!rl) {
  134. pr_debug("Run list not present.\n");
  135. return;
  136. }
  137. pr_debug("VCN LCN Run length\n");
  138. for (i = 0; ; i++) {
  139. LCN lcn = (rl + i)->lcn;
  140. if (lcn < (LCN)0) {
  141. int index = -lcn - 1;
  142. if (index > -LCN_ENOENT - 1)
  143. index = 3;
  144. pr_debug("%-16Lx %s %-16Lx%s\n",
  145. (long long)(rl + i)->vcn, lcn_str[index],
  146. (long long)(rl + i)->length,
  147. (rl + i)->length ? "" :
  148. " (runlist end)");
  149. } else
  150. pr_debug("%-16Lx %-16Lx %-16Lx%s\n",
  151. (long long)(rl + i)->vcn,
  152. (long long)(rl + i)->lcn,
  153. (long long)(rl + i)->length,
  154. (rl + i)->length ? "" :
  155. " (runlist end)");
  156. if (!(rl + i)->length)
  157. break;
  158. }
  159. }
  160. #endif