ext4_debug.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /*
  2. * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. *
  9. * - Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * - Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * - The name of the author may not be used to endorse or promote products
  15. * derived from this software without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  18. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  19. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  20. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  21. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  22. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  23. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  24. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. */
  28. /** @addtogroup lwext4
  29. * @{
  30. */
  31. /**
  32. * @file ext4_debug.c
  33. * @brief Debug printf and assert macros.
  34. */
  35. #ifndef EXT4_DEBUG_H_
  36. #define EXT4_DEBUG_H_
  37. #ifdef __cplusplus
  38. extern "C" {
  39. #endif
  40. #include <ext4_config.h>
  41. #include <ext4_errno.h>
  42. #if !CONFIG_HAVE_OWN_ASSERT
  43. #include <assert.h>
  44. #endif
  45. #include <stdint.h>
  46. #include <inttypes.h>
  47. #ifndef PRIu64
  48. #define PRIu64 "llu"
  49. #endif
  50. #ifndef PRId64
  51. #define PRId64 "lld"
  52. #endif
  53. #define DEBUG_BALLOC (1ul << 0)
  54. #define DEBUG_BCACHE (1ul << 1)
  55. #define DEBUG_BITMAP (1ul << 2)
  56. #define DEBUG_BLOCK_GROUP (1ul << 3)
  57. #define DEBUG_BLOCKDEV (1ul << 4)
  58. #define DEBUG_DIR_IDX (1ul << 5)
  59. #define DEBUG_DIR (1ul << 6)
  60. #define DEBUG_EXTENT (1ul << 7)
  61. #define DEBUG_FS (1ul << 8)
  62. #define DEBUG_HASH (1ul << 9)
  63. #define DEBUG_IALLOC (1ul << 10)
  64. #define DEBUG_INODE (1ul << 11)
  65. #define DEBUG_SUPER (1ul << 12)
  66. #define DEBUG_XATTR (1ul << 13)
  67. #define DEBUG_MKFS (1ul << 14)
  68. #define DEBUG_EXT4 (1ul << 15)
  69. #define DEBUG_JBD (1ul << 16)
  70. #define DEBUG_MBR (1ul << 17)
  71. #define DEBUG_NOPREFIX (1ul << 31)
  72. #define DEBUG_ALL (0xFFFFFFFF)
  73. static inline const char *ext4_dmask_id2str(uint32_t m)
  74. {
  75. switch(m) {
  76. case DEBUG_BALLOC:
  77. return "ext4_balloc: ";
  78. case DEBUG_BCACHE:
  79. return "ext4_bcache: ";
  80. case DEBUG_BITMAP:
  81. return "ext4_bitmap: ";
  82. case DEBUG_BLOCK_GROUP:
  83. return "ext4_block_group: ";
  84. case DEBUG_BLOCKDEV:
  85. return "ext4_blockdev: ";
  86. case DEBUG_DIR_IDX:
  87. return "ext4_dir_idx: ";
  88. case DEBUG_DIR:
  89. return "ext4_dir: ";
  90. case DEBUG_EXTENT:
  91. return "ext4_extent: ";
  92. case DEBUG_FS:
  93. return "ext4_fs: ";
  94. case DEBUG_HASH:
  95. return "ext4_hash: ";
  96. case DEBUG_IALLOC:
  97. return "ext4_ialloc: ";
  98. case DEBUG_INODE:
  99. return "ext4_inode: ";
  100. case DEBUG_SUPER:
  101. return "ext4_super: ";
  102. case DEBUG_XATTR:
  103. return "ext4_xattr: ";
  104. case DEBUG_MKFS:
  105. return "ext4_mkfs: ";
  106. case DEBUG_JBD:
  107. return "ext4_jbd: ";
  108. case DEBUG_MBR:
  109. return "ext4_mbr: ";
  110. case DEBUG_EXT4:
  111. return "ext4: ";
  112. }
  113. return "";
  114. }
  115. #define DBG_NONE ""
  116. #define DBG_INFO "[info] "
  117. #define DBG_WARN "[warn] "
  118. #define DBG_ERROR "[error] "
  119. /**@brief Global mask debug set.
  120. * @brief m new debug mask.*/
  121. void ext4_dmask_set(uint32_t m);
  122. /**@brief Global mask debug clear.
  123. * @brief m new debug mask.*/
  124. void ext4_dmask_clr(uint32_t m);
  125. /**@brief Global debug mask get.
  126. * @return debug mask*/
  127. uint32_t ext4_dmask_get(void);
  128. #if CONFIG_DEBUG_PRINTF
  129. #include <stdio.h>
  130. /**@brief Debug printf.*/
  131. #define ext4_dbg(m, ...) \
  132. do { \
  133. if ((m) & ext4_dmask_get()) { \
  134. if (!((m) & DEBUG_NOPREFIX)) { \
  135. printf("%s", ext4_dmask_id2str(m)); \
  136. printf("l: %d ", __LINE__); \
  137. } \
  138. printf(__VA_ARGS__); \
  139. /*fflush(stdout);*/ \
  140. } \
  141. } while (0)
  142. #else
  143. #define ext4_dbg(m, ...) do { } while (0)
  144. #endif
  145. #if CONFIG_DEBUG_ASSERT
  146. /**@brief Debug assertion.*/
  147. #if CONFIG_HAVE_OWN_ASSERT
  148. #include <stdio.h>
  149. #define ext4_assert(_v) \
  150. do { \
  151. if (!(_v)) { \
  152. printf("assertion failed:\nfile: %s\nline: %d\n", \
  153. __FILE__, __LINE__); \
  154. while (1) \
  155. ; \
  156. } \
  157. } while (0)
  158. #else
  159. #define ext4_assert(_v) assert(_v)
  160. #endif
  161. #else
  162. #define ext4_assert(_v) ((void)(_v))
  163. #endif
  164. #ifdef __cplusplus
  165. }
  166. #endif
  167. #endif /* EXT4_DEBUG_H_ */
  168. /**
  169. * @}
  170. */