1 /*
2 * JFFS2 -- Journalling Flash File System, Version 2.
3 *
4 * Copyright (C) 2001-2003 Red Hat, Inc.
5 *
6 * Created by David Woodhouse <[email protected]>
7 *
8 * For licensing information, see the file 'LICENCE' in this directory.
9 *
10 * $Id: debug.h,v 1.1 2005/07/30 15:30:42 asl Exp $
11 *
12 */
13 #ifndef _JFFS2_DEBUG_H_
14 #define _JFFS2_DEBUG_H_
15 #include "jffs2_config.h"
16 #include <linux/config.h>
17
18 #ifndef CONFIG_JFFS2_FS_DEBUG
19 #define CONFIG_JFFS2_FS_DEBUG 0
20 #endif
21
22 #if CONFIG_JFFS2_FS_DEBUG == 1
23 /* Enable "paranoia" checks and dumps */
24 #define JFFS2_DBG_PARANOIA_CHECKS
25 #define JFFS2_DBG_DUMPS
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 #endif
32
33 #if CONFIG_JFFS2_FS_DEBUG == 2
34 #define JFFS2_DBG_FRAGTREE2_MESSAGES
35 #endif
36
37 /* Enable JFFS2 sanity checks by default */
38 #define JFFS2_DBG_SANITY_CHECKS
39
40 /*
41 * Dx() are mainly used for debugging messages, they must go away and be
42 * superseded by nicer JFFS2_DBG_XXX() macros...
43 */
44 #if CONFIG_JFFS2_FS_DEBUG > 0
45 #define D1(x) x
46 #else
47 #define D1(x)
48 #endif
49
50 #if CONFIG_JFFS2_FS_DEBUG > 1
51 #define D2(x) x
52 #else
53 #define D2(x)
54 #endif
55
56 /* The prefixes of JFFS2 messages */
57 #define JFFS2_DBG_MSG_PREFIX "[JFFS2 DBG]"
58 #define JFFS2_ERR_MSG_PREFIX "JFFS2 error: "
59 #define JFFS2_WARN_MSG_PREFIX "JFFS2 warning: "
60 #define JFFS2_NOTICE_MSG_PREFIX "JFFS2 notice: "
61
62 #define JFFS2_ERR_LVL KERN_ERR
63 #define JFFS2_WARN_LVL KERN_WARNING
64 #define JFFS2_NOTICE_LVL KERN_NOTICE
65 #define JFFS2_DBG_LVL KERN_DEBUG
66
67 /* JFFS2 message macros */
68 #define JFFS2_ERROR(fmt, ...) \
69 do { \
70 printk(JFFS2_ERR_LVL JFFS2_ERR_MSG_PREFIX " %s: " \
71 fmt, __FUNCTION__, ##__VA_ARGS__); \
72 } while(0)
73
74 #define JFFS2_WARNING(fmt, ...) \
75 do { \
76 printk(JFFS2_WARN_LVL JFFS2_WARN_MSG_PREFIX " %s: " \
77 fmt, __FUNCTION__, ##__VA_ARGS__); \
78 } while(0)
79
80 #define JFFS2_NOTICE(fmt, ...) \
81 do { \
82 printk(JFFS2_NOTICE_LVL JFFS2_NOTICE_MSG_PREFIX " %s: " \
83 fmt, __FUNCTION__, ##__VA_ARGS__); \
84 } while(0)
85
86 #define JFFS2_DEBUG(fmt, ...) \
87 do { \
88 printk(JFFS2_DBG_LVL JFFS2_DBG_MSG_PREFIX " %s: " \
89 fmt, __FUNCTION__, ##__VA_ARGS__); \
90 } while(0)
91
92 /*
93 * We split our debugging messages on several parts, depending on the JFFS2
94 * subsystem the message belongs to.
95 */
96 /* Read inode debugging messages */
97 #ifdef JFFS2_DBG_READINODE_MESSAGES
98 #define JFFS2_DBG_READINODE(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
99 #else
100 #define JFFS2_DBG_READINODE(fmt, ...)
101 #endif
102
103 /* Fragtree build debugging messages */
104 #ifdef JFFS2_DBG_FRAGTREE_MESSAGES
105 #define JFFS2_DBG_FRAGTREE(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
106 #else
107 #define JFFS2_DBG_FRAGTREE(fmt, ...)
108 #endif
109
110 /* Directory entry list manilulation debugging messages */
111 #ifdef JFFS2_DBG_DENTLIST_MESSAGES
112 #define JFFS2_DBG_DENTLIST(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
113 #else
114 #define JFFS2_DBG_DENTLIST(fmt, ...)
115 #endif
116 #ifdef JFFS2_DBG_FRAGTREE2_MESSAGES
117 #define JFFS2_DBG_FRAGTREE2(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
118 #else
119 #define JFFS2_DBG_FRAGTREE2(fmt, ...)
120 #endif
121
122 /* Print the messages about manipulating node_refs */
123 #ifdef JFFS2_DBG_NODEREF_MESSAGES
124 #define JFFS2_DBG_NODEREF(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
125 #else
126 #define JFFS2_DBG_NODEREF(fmt, ...)
127 #endif
128
129 /* Manipulations with the list of inodes (JFFS2 inocache) */
130 #ifdef JFFS2_DBG_INOCACHE_MESSAGES
131 #define JFFS2_DBG_INOCACHE(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
132 #else
133 #define JFFS2_DBG_INOCACHE(fmt, ...)
134 #endif
135
136 /* Watch the object allocations */
137 #ifdef JFFS2_DBG_MEMALLOC_MESSAGES
138 #define JFFS2_DBG_MEMALLOC(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
139 #else
140 #define JFFS2_DBG_MEMALLOC(fmt, ...)
141 #endif
142
143
144 /* "Paranoia" checks */
145 void
146 __jffs2_dbg_fragtree_paranoia_check(struct jffs2_inode_info *f);
147 void
148 __jffs2_dbg_fragtree_paranoia_check_nolock(struct jffs2_inode_info *f);
149 void
150 __jffs2_dbg_acct_paranoia_check(struct jffs2_sb_info *c,
151 struct jffs2_eraseblock *jeb);
152 void
153 __jffs2_dbg_acct_paranoia_check_nolock(struct jffs2_sb_info *c,
154 struct jffs2_eraseblock *jeb);
155 void
156 __jffs2_dbg_prewrite_paranoia_check(struct jffs2_sb_info *c,
157 uint32_t ofs, int len);
158
159 /* "Dump" functions */
160 void
161 __jffs2_dbg_dump_jeb(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb);
162 void
163 __jffs2_dbg_dump_jeb_nolock(struct jffs2_eraseblock *jeb);
164 void
165 __jffs2_dbg_dump_block_lists(struct jffs2_sb_info *c);
166 void
167 __jffs2_dbg_dump_block_lists_nolock(struct jffs2_sb_info *c);
168 void
169 __jffs2_dbg_dump_node_refs(struct jffs2_sb_info *c,
170 struct jffs2_eraseblock *jeb);
171 void
172 __jffs2_dbg_dump_node_refs_nolock(struct jffs2_sb_info *c,
173 struct jffs2_eraseblock *jeb);
174 void
175 __jffs2_dbg_dump_fragtree(struct jffs2_inode_info *f);
176 void
177 __jffs2_dbg_dump_fragtree_nolock(struct jffs2_inode_info *f);
178 void
179 __jffs2_dbg_dump_buffer(unsigned char *buf, int len, uint32_t offs);
180 void
181 __jffs2_dbg_dump_node(struct jffs2_sb_info *c, uint32_t ofs);
182
183 #ifdef JFFS2_DBG_PARANOIA_CHECKS
184 #define jffs2_dbg_fragtree_paranoia_check(f) \
185 __jffs2_dbg_fragtree_paranoia_check(f)
186 #define jffs2_dbg_fragtree_paranoia_check_nolock(f) \
187 __jffs2_dbg_fragtree_paranoia_check_nolock(f)
188 #define jffs2_dbg_acct_paranoia_check(c, jeb) \
189 __jffs2_dbg_acct_paranoia_check(c,jeb)
190 #define jffs2_dbg_acct_paranoia_check_nolock(c, jeb) \
191 __jffs2_dbg_acct_paranoia_check_nolock(c,jeb)
192 #define jffs2_dbg_prewrite_paranoia_check(c, ofs, len) \
193 __jffs2_dbg_prewrite_paranoia_check(c, ofs, len)
194 #else
195 #define jffs2_dbg_fragtree_paranoia_check(f)
196 #define jffs2_dbg_fragtree_paranoia_check_nolock(f)
197 #define jffs2_dbg_acct_paranoia_check(c, jeb)
198 #define jffs2_dbg_acct_paranoia_check_nolock(c, jeb)
199 #define jffs2_dbg_prewrite_paranoia_check(c, ofs, len)
200 #endif /* !JFFS2_PARANOIA_CHECKS */
201
202 #ifdef JFFS2_DBG_DUMPS
203 #define jffs2_dbg_dump_jeb(c, jeb) \
204 __jffs2_dbg_dump_jeb(c, jeb);
205 #define jffs2_dbg_dump_jeb_nolock(jeb) \
206 __jffs2_dbg_dump_jeb_nolock(jeb);
207 #define jffs2_dbg_dump_block_lists(c) \
208 __jffs2_dbg_dump_block_lists(c)
209 #define jffs2_dbg_dump_block_lists_nolock(c) \
210 __jffs2_dbg_dump_block_lists_nolock(c)
211 #define jffs2_dbg_dump_fragtree(f) \
212 __jffs2_dbg_dump_fragtree(f);
213 #define jffs2_dbg_dump_fragtree_nolock(f) \
214 __jffs2_dbg_dump_fragtree_nolock(f);
215 #define jffs2_dbg_dump_buffer(buf, len, offs) \
216 __jffs2_dbg_dump_buffer(*buf, len, offs);
217 #define jffs2_dbg_dump_node(c, ofs) \
218 __jffs2_dbg_dump_node(c, ofs);
219 #else
220 #define jffs2_dbg_dump_jeb(c, jeb)
221 #define jffs2_dbg_dump_jeb_nolock(jeb)
222 #define jffs2_dbg_dump_block_lists(c)
223 #define jffs2_dbg_dump_block_lists_nolock(c)
224 #define jffs2_dbg_dump_fragtree(f)
225 #define jffs2_dbg_dump_fragtree_nolock(f)
226 #define jffs2_dbg_dump_buffer(buf, len, offs)
227 #define jffs2_dbg_dump_node(c, ofs)
228 #endif /* !JFFS2_DBG_DUMPS */
229
230 /*
231 * Sanity checks are supposed to be light-weight and enabled by default.
232 */
233 #ifdef JFFS2_DBG_SANITY_CHECKS
234 /*
235 * Check the space accounting of the file system and of
236 * the JFFS2 erasable block 'jeb'.
237 */
238 static inline void
jffs2_dbg_acct_sanity_check_nolock(struct jffs2_sb_info * c,struct jffs2_eraseblock * jeb)239 jffs2_dbg_acct_sanity_check_nolock(struct jffs2_sb_info *c,
240 struct jffs2_eraseblock *jeb)
241 {
242 if (unlikely(jeb && jeb->used_size + jeb->dirty_size +
243 jeb->free_size + jeb->wasted_size +
244 jeb->unchecked_size != c->sector_size)) {
245 JFFS2_ERROR("eeep, space accounting for block at 0x%08x is screwed.\n", jeb->offset);
246 JFFS2_ERROR("free %#08x + dirty %#08x + used %#08x + wasted %#08x + unchecked "
247 "%#08x != total %#08x.\n", jeb->free_size, jeb->dirty_size, jeb->used_size,
248 jeb->wasted_size, jeb->unchecked_size, c->sector_size);
249 BUG();
250 }
251
252 if (unlikely(c->used_size + c->dirty_size + c->free_size + c->erasing_size + c->bad_size
253 + c->wasted_size + c->unchecked_size != c->flash_size)) {
254 JFFS2_ERROR("eeep, space accounting superblock info is screwed.\n");
255 JFFS2_ERROR("free %#08x + dirty %#08x + used %#08x + erasing %#08x + bad %#08x + "
256 "wasted %#08x + unchecked %#08x != total %#08x.\n",
257 c->free_size, c->dirty_size, c->used_size, c->erasing_size, c->bad_size,
258 c->wasted_size, c->unchecked_size, c->flash_size);
259 BUG();
260 }
261 }
262
263 static inline void
jffs2_dbg_acct_sanity_check(struct jffs2_sb_info * c,struct jffs2_eraseblock * jeb)264 jffs2_dbg_acct_sanity_check(struct jffs2_sb_info *c,
265 struct jffs2_eraseblock *jeb)
266 {
267 spin_lock(&c->erase_completion_lock);
268 jffs2_dbg_acct_sanity_check_nolock(c, jeb);
269 spin_unlock(&c->erase_completion_lock);
270 }
271 #else
272 #define jffs2_dbg_acct_sanity_check(c, jeb)
273 #define jffs2_dbg_acct_sanity_check_nolock(c, jeb)
274 #endif /* !JFFS2_DBG_SANITY_CHECKS */
275
276 #endif /* _JFFS2_DEBUG_H_ */
277