debug.c 4.0 KB

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