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