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