debug.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. /*
  2. * JFFS2 -- Journalling Flash File System, Version 2.
  3. *
  4. * Copyright © 2001-2007 Red Hat, Inc.
  5. * Copyright © 2004-2010 David Woodhouse <dwmw2@infradead.org>
  6. *
  7. * Created by David Woodhouse <dwmw2@infradead.org>
  8. *
  9. * For licensing information, see the file 'LICENCE' in this directory.
  10. *
  11. */
  12. #ifndef _JFFS2_DEBUG_H_
  13. #define _JFFS2_DEBUG_H_
  14. #include <linux/sched.h>
  15. #ifndef CONFIG_JFFS2_FS_DEBUG
  16. #define CONFIG_JFFS2_FS_DEBUG 0
  17. #endif
  18. #if CONFIG_JFFS2_FS_DEBUG > 0
  19. /* Enable "paranoia" checks and dumps */
  20. #define JFFS2_DBG_PARANOIA_CHECKS
  21. #define JFFS2_DBG_DUMPS
  22. /*
  23. * By defining/undefining the below macros one may select debugging messages
  24. * fro specific JFFS2 subsystems.
  25. */
  26. #define JFFS2_DBG_READINODE_MESSAGES
  27. #define JFFS2_DBG_FRAGTREE_MESSAGES
  28. #define JFFS2_DBG_DENTLIST_MESSAGES
  29. #define JFFS2_DBG_NODEREF_MESSAGES
  30. #define JFFS2_DBG_INOCACHE_MESSAGES
  31. #define JFFS2_DBG_SUMMARY_MESSAGES
  32. #define JFFS2_DBG_FSBUILD_MESSAGES
  33. #endif
  34. #if CONFIG_JFFS2_FS_DEBUG > 1
  35. #define JFFS2_DBG_FRAGTREE2_MESSAGES
  36. #define JFFS2_DBG_READINODE2_MESSAGES
  37. #define JFFS2_DBG_MEMALLOC_MESSAGES
  38. #endif
  39. /* Sanity checks are supposed to be light-weight and enabled by default */
  40. #define JFFS2_DBG_SANITY_CHECKS
  41. /*
  42. * Dx() are mainly used for debugging messages, they must go away and be
  43. * superseded by nicer dbg_xxx() macros...
  44. */
  45. #if CONFIG_JFFS2_FS_DEBUG > 0
  46. #define DEBUG
  47. #define D1(x) x
  48. #else
  49. #define D1(x)
  50. #endif
  51. #if CONFIG_JFFS2_FS_DEBUG > 1
  52. #define D2(x) x
  53. #else
  54. #define D2(x)
  55. #endif
  56. #define jffs2_dbg(level, fmt, ...) \
  57. do { \
  58. if (CONFIG_JFFS2_FS_DEBUG >= level) \
  59. pr_debug(fmt, ##__VA_ARGS__); \
  60. } while (0)
  61. /* The prefixes of JFFS2 messages */
  62. #define JFFS2_DBG KERN_DEBUG
  63. #define JFFS2_DBG_PREFIX "[JFFS2 DBG]"
  64. #define JFFS2_DBG_MSG_PREFIX JFFS2_DBG JFFS2_DBG_PREFIX
  65. /* JFFS2 message macros */
  66. #define JFFS2_ERROR(fmt, ...) \
  67. pr_err("error: (%d) %s: " fmt, \
  68. task_pid_nr(current), __func__, ##__VA_ARGS__)
  69. #define JFFS2_WARNING(fmt, ...) \
  70. pr_warn("warning: (%d) %s: " fmt, \
  71. task_pid_nr(current), __func__, ##__VA_ARGS__)
  72. #define JFFS2_NOTICE(fmt, ...) \
  73. pr_notice("notice: (%d) %s: " fmt, \
  74. task_pid_nr(current), __func__, ##__VA_ARGS__)
  75. #define JFFS2_DEBUG(fmt, ...) \
  76. printk(KERN_DEBUG "[JFFS2 DBG] (%d) %s: " fmt, \
  77. task_pid_nr(current), __func__, ##__VA_ARGS__)
  78. /*
  79. * We split our debugging messages on several parts, depending on the JFFS2
  80. * subsystem the message belongs to.
  81. */
  82. /* Read inode debugging messages */
  83. #ifdef JFFS2_DBG_READINODE_MESSAGES
  84. #define dbg_readinode(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
  85. #else
  86. #define dbg_readinode(fmt, ...)
  87. #endif
  88. #ifdef JFFS2_DBG_READINODE2_MESSAGES
  89. #define dbg_readinode2(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
  90. #else
  91. #define dbg_readinode2(fmt, ...)
  92. #endif
  93. /* Fragtree build debugging messages */
  94. #ifdef JFFS2_DBG_FRAGTREE_MESSAGES
  95. #define dbg_fragtree(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
  96. #else
  97. #define dbg_fragtree(fmt, ...)
  98. #endif
  99. #ifdef JFFS2_DBG_FRAGTREE2_MESSAGES
  100. #define dbg_fragtree2(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
  101. #else
  102. #define dbg_fragtree2(fmt, ...)
  103. #endif
  104. /* Directory entry list manilulation debugging messages */
  105. #ifdef JFFS2_DBG_DENTLIST_MESSAGES
  106. #define dbg_dentlist(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
  107. #else
  108. #define dbg_dentlist(fmt, ...)
  109. #endif
  110. /* Print the messages about manipulating node_refs */
  111. #ifdef JFFS2_DBG_NODEREF_MESSAGES
  112. #define dbg_noderef(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
  113. #else
  114. #define dbg_noderef(fmt, ...)
  115. #endif
  116. /* Manipulations with the list of inodes (JFFS2 inocache) */
  117. #ifdef JFFS2_DBG_INOCACHE_MESSAGES
  118. #define dbg_inocache(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
  119. #else
  120. #define dbg_inocache(fmt, ...)
  121. #endif
  122. /* Summary debugging messages */
  123. #ifdef JFFS2_DBG_SUMMARY_MESSAGES
  124. #define dbg_summary(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
  125. #else
  126. #define dbg_summary(fmt, ...)
  127. #endif
  128. /* File system build messages */
  129. #ifdef JFFS2_DBG_FSBUILD_MESSAGES
  130. #define dbg_fsbuild(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
  131. #else
  132. #define dbg_fsbuild(fmt, ...)
  133. #endif
  134. /* Watch the object allocations */
  135. #ifdef JFFS2_DBG_MEMALLOC_MESSAGES
  136. #define dbg_memalloc(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
  137. #else
  138. #define dbg_memalloc(fmt, ...)
  139. #endif
  140. /* Watch the XATTR subsystem */
  141. #ifdef JFFS2_DBG_XATTR_MESSAGES
  142. #define dbg_xattr(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
  143. #else
  144. #define dbg_xattr(fmt, ...)
  145. #endif
  146. /* "Sanity" checks */
  147. void
  148. __jffs2_dbg_acct_sanity_check_nolock(struct jffs2_sb_info *c,
  149. struct jffs2_eraseblock *jeb);
  150. void
  151. __jffs2_dbg_acct_sanity_check(struct jffs2_sb_info *c,
  152. struct jffs2_eraseblock *jeb);
  153. /* "Paranoia" checks */
  154. void
  155. __jffs2_dbg_fragtree_paranoia_check(struct jffs2_inode_info *f);
  156. void
  157. __jffs2_dbg_fragtree_paranoia_check_nolock(struct jffs2_inode_info *f);
  158. void
  159. __jffs2_dbg_acct_paranoia_check(struct jffs2_sb_info *c,
  160. struct jffs2_eraseblock *jeb);
  161. void
  162. __jffs2_dbg_acct_paranoia_check_nolock(struct jffs2_sb_info *c,
  163. struct jffs2_eraseblock *jeb);
  164. void
  165. __jffs2_dbg_prewrite_paranoia_check(struct jffs2_sb_info *c,
  166. uint32_t ofs, int len);
  167. /* "Dump" functions */
  168. void
  169. __jffs2_dbg_dump_jeb(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb);
  170. void
  171. __jffs2_dbg_dump_jeb_nolock(struct jffs2_eraseblock *jeb);
  172. void
  173. __jffs2_dbg_dump_block_lists(struct jffs2_sb_info *c);
  174. void
  175. __jffs2_dbg_dump_block_lists_nolock(struct jffs2_sb_info *c);
  176. void
  177. __jffs2_dbg_dump_node_refs(struct jffs2_sb_info *c,
  178. struct jffs2_eraseblock *jeb);
  179. void
  180. __jffs2_dbg_dump_node_refs_nolock(struct jffs2_sb_info *c,
  181. struct jffs2_eraseblock *jeb);
  182. void
  183. __jffs2_dbg_dump_fragtree(struct jffs2_inode_info *f);
  184. void
  185. __jffs2_dbg_dump_fragtree_nolock(struct jffs2_inode_info *f);
  186. void
  187. __jffs2_dbg_dump_buffer(unsigned char *buf, int len, uint32_t offs);
  188. void
  189. __jffs2_dbg_dump_node(struct jffs2_sb_info *c, uint32_t ofs);
  190. #ifdef JFFS2_DBG_PARANOIA_CHECKS
  191. #define jffs2_dbg_fragtree_paranoia_check(f) \
  192. __jffs2_dbg_fragtree_paranoia_check(f)
  193. #define jffs2_dbg_fragtree_paranoia_check_nolock(f) \
  194. __jffs2_dbg_fragtree_paranoia_check_nolock(f)
  195. #define jffs2_dbg_acct_paranoia_check(c, jeb) \
  196. __jffs2_dbg_acct_paranoia_check(c,jeb)
  197. #define jffs2_dbg_acct_paranoia_check_nolock(c, jeb) \
  198. __jffs2_dbg_acct_paranoia_check_nolock(c,jeb)
  199. #define jffs2_dbg_prewrite_paranoia_check(c, ofs, len) \
  200. __jffs2_dbg_prewrite_paranoia_check(c, ofs, len)
  201. #else
  202. #define jffs2_dbg_fragtree_paranoia_check(f)
  203. #define jffs2_dbg_fragtree_paranoia_check_nolock(f)
  204. #define jffs2_dbg_acct_paranoia_check(c, jeb)
  205. #define jffs2_dbg_acct_paranoia_check_nolock(c, jeb)
  206. #define jffs2_dbg_prewrite_paranoia_check(c, ofs, len)
  207. #endif /* !JFFS2_PARANOIA_CHECKS */
  208. #ifdef JFFS2_DBG_DUMPS
  209. #define jffs2_dbg_dump_jeb(c, jeb) \
  210. __jffs2_dbg_dump_jeb(c, jeb);
  211. #define jffs2_dbg_dump_jeb_nolock(jeb) \
  212. __jffs2_dbg_dump_jeb_nolock(jeb);
  213. #define jffs2_dbg_dump_block_lists(c) \
  214. __jffs2_dbg_dump_block_lists(c)
  215. #define jffs2_dbg_dump_block_lists_nolock(c) \
  216. __jffs2_dbg_dump_block_lists_nolock(c)
  217. #define jffs2_dbg_dump_fragtree(f) \
  218. __jffs2_dbg_dump_fragtree(f);
  219. #define jffs2_dbg_dump_fragtree_nolock(f) \
  220. __jffs2_dbg_dump_fragtree_nolock(f);
  221. #define jffs2_dbg_dump_buffer(buf, len, offs) \
  222. __jffs2_dbg_dump_buffer(*buf, len, offs);
  223. #define jffs2_dbg_dump_node(c, ofs) \
  224. __jffs2_dbg_dump_node(c, ofs);
  225. #else
  226. #define jffs2_dbg_dump_jeb(c, jeb)
  227. #define jffs2_dbg_dump_jeb_nolock(jeb)
  228. #define jffs2_dbg_dump_block_lists(c)
  229. #define jffs2_dbg_dump_block_lists_nolock(c)
  230. #define jffs2_dbg_dump_fragtree(f)
  231. #define jffs2_dbg_dump_fragtree_nolock(f)
  232. #define jffs2_dbg_dump_buffer(buf, len, offs)
  233. #define jffs2_dbg_dump_node(c, ofs)
  234. #endif /* !JFFS2_DBG_DUMPS */
  235. #ifdef JFFS2_DBG_SANITY_CHECKS
  236. #define jffs2_dbg_acct_sanity_check(c, jeb) \
  237. __jffs2_dbg_acct_sanity_check(c, jeb)
  238. #define jffs2_dbg_acct_sanity_check_nolock(c, jeb) \
  239. __jffs2_dbg_acct_sanity_check_nolock(c, jeb)
  240. #else
  241. #define jffs2_dbg_acct_sanity_check(c, jeb)
  242. #define jffs2_dbg_acct_sanity_check_nolock(c, jeb)
  243. #endif /* !JFFS2_DBG_SANITY_CHECKS */
  244. #endif /* _JFFS2_DEBUG_H_ */