ext4_debug.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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_DFS_EXT (1ul << 18)
  72. #define DEBUG_BLK_DEVICE (1ul << 19)
  73. #define DEBUG_EXT_GPT (1ul << 20)
  74. #define DEBUG_NOPREFIX (1ul << 31)
  75. #define DEBUG_ALL (0xFFFFFFFF)
  76. static inline const char *ext4_dmask_id2str(uint32_t m)
  77. {
  78. switch(m) {
  79. case DEBUG_BALLOC:
  80. return "ext4_balloc: ";
  81. case DEBUG_BCACHE:
  82. return "ext4_bcache: ";
  83. case DEBUG_BITMAP:
  84. return "ext4_bitmap: ";
  85. case DEBUG_BLOCK_GROUP:
  86. return "ext4_block_group: ";
  87. case DEBUG_BLOCKDEV:
  88. return "ext4_blockdev: ";
  89. case DEBUG_DIR_IDX:
  90. return "ext4_dir_idx: ";
  91. case DEBUG_DIR:
  92. return "ext4_dir: ";
  93. case DEBUG_EXTENT:
  94. return "ext4_extent: ";
  95. case DEBUG_FS:
  96. return "ext4_fs: ";
  97. case DEBUG_HASH:
  98. return "ext4_hash: ";
  99. case DEBUG_IALLOC:
  100. return "ext4_ialloc: ";
  101. case DEBUG_INODE:
  102. return "ext4_inode: ";
  103. case DEBUG_SUPER:
  104. return "ext4_super: ";
  105. case DEBUG_XATTR:
  106. return "ext4_xattr: ";
  107. case DEBUG_MKFS:
  108. return "ext4_mkfs: ";
  109. case DEBUG_JBD:
  110. return "ext4_jbd: ";
  111. case DEBUG_MBR:
  112. return "ext4_mbr: ";
  113. case DEBUG_EXT4:
  114. return "ext4: ";
  115. case DEBUG_DFS_EXT:
  116. return "dfs_ext: ";
  117. case DEBUG_BLK_DEVICE:
  118. return "blk_device: ";
  119. case DEBUG_EXT_GPT:
  120. return "ext_gpt: ";
  121. }
  122. return "";
  123. }
  124. #define DBG_NONE ""
  125. #define DBG_INFO "[info] "
  126. #define DBG_WARN "[warn] "
  127. #define DBG_ERROR "[error] "
  128. /**@brief Global mask debug set.
  129. * @param m new debug mask.*/
  130. void ext4_dmask_set(uint32_t m);
  131. /**@brief Global mask debug clear.
  132. * @param m new debug mask.*/
  133. void ext4_dmask_clr(uint32_t m);
  134. /**@brief Global debug mask get.
  135. * @return debug mask*/
  136. uint32_t ext4_dmask_get(void);
  137. #if CONFIG_DEBUG_PRINTF
  138. #include <stdio.h>
  139. /**@brief Debug printf.*/
  140. #define ext4_dbg(m, ...) \
  141. do { \
  142. if ((m) & ext4_dmask_get()) { \
  143. if (!((m) & DEBUG_NOPREFIX)) { \
  144. printf("%s", ext4_dmask_id2str(m)); \
  145. printf("l: %d ", __LINE__); \
  146. } \
  147. printf(__VA_ARGS__); \
  148. /*fflush(stdout);*/ \
  149. } \
  150. } while (0)
  151. #else
  152. #define ext4_dbg(m, ...) do { } while (0)
  153. #endif
  154. #if CONFIG_DEBUG_ASSERT
  155. /**@brief Debug assertion.*/
  156. #if CONFIG_HAVE_OWN_ASSERT
  157. #include <stdio.h>
  158. #define ext4_assert(_v) \
  159. do { \
  160. if (!(_v)) { \
  161. printf("assertion failed:\nfile: %s\nline: %d\n", \
  162. __FILE__, __LINE__); \
  163. while (1) \
  164. ; \
  165. } \
  166. } while (0)
  167. #else
  168. #define ext4_assert(_v) assert(_v)
  169. #endif
  170. #else
  171. #define ext4_assert(_v) ((void)(_v))
  172. #endif
  173. #ifdef __cplusplus
  174. }
  175. #endif
  176. #endif /* EXT4_DEBUG_H_ */
  177. /**
  178. * @}
  179. */