aboutsummaryrefslogtreecommitdiffstats
path: root/fs/jffs2
diff options
context:
space:
mode:
Diffstat (limited to 'fs/jffs2')
-rw-r--r--fs/jffs2/build.c6
-rw-r--r--fs/jffs2/debug.c526
-rw-r--r--fs/jffs2/debug.h251
-rw-r--r--fs/jffs2/erase.c9
-rw-r--r--fs/jffs2/fs.c8
-rw-r--r--fs/jffs2/gc.c8
-rw-r--r--fs/jffs2/nodelist.c4
-rw-r--r--fs/jffs2/nodelist.h4
-rw-r--r--fs/jffs2/nodemgmt.c13
-rw-r--r--fs/jffs2/read.c3
-rw-r--r--fs/jffs2/readinode.c8
-rw-r--r--fs/jffs2/scan.c6
-rw-r--r--fs/jffs2/wbuf.c17
-rw-r--r--fs/jffs2/write.c6
14 files changed, 630 insertions, 239 deletions
diff --git a/fs/jffs2/build.c b/fs/jffs2/build.c
index b87d4010d36f..f08984a64a5a 100644
--- a/fs/jffs2/build.c
+++ b/fs/jffs2/build.c
@@ -7,7 +7,7 @@
7 * 7 *
8 * For licensing information, see the file 'LICENCE' in this directory. 8 * For licensing information, see the file 'LICENCE' in this directory.
9 * 9 *
10 * $Id: build.c,v 1.74 2005/07/17 12:01:42 dedekind Exp $ 10 * $Id: build.c,v 1.75 2005/07/22 10:32:07 dedekind Exp $
11 * 11 *
12 */ 12 */
13 13
@@ -104,7 +104,7 @@ static int jffs2_build_filesystem(struct jffs2_sb_info *c)
104 goto exit; 104 goto exit;
105 105
106 D1(printk(KERN_DEBUG "Scanned flash completely\n")); 106 D1(printk(KERN_DEBUG "Scanned flash completely\n"));
107 D2(jffs2_dbg_dump_block_lists(c)); 107 jffs2_dbg_dump_block_lists_nolock(c);
108 108
109 c->flags |= JFFS2_SB_FLAG_BUILDING; 109 c->flags |= JFFS2_SB_FLAG_BUILDING;
110 /* Now scan the directory tree, increasing nlink according to every dirent found. */ 110 /* Now scan the directory tree, increasing nlink according to every dirent found. */
@@ -168,7 +168,7 @@ static int jffs2_build_filesystem(struct jffs2_sb_info *c)
168 c->flags &= ~JFFS2_SB_FLAG_BUILDING; 168 c->flags &= ~JFFS2_SB_FLAG_BUILDING;
169 169
170 D1(printk(KERN_DEBUG "Pass 3 complete\n")); 170 D1(printk(KERN_DEBUG "Pass 3 complete\n"));
171 jffs2_dbg_dump_block_lists(c); 171 jffs2_dbg_dump_block_lists_nolock(c);
172 172
173 /* Rotate the lists by some number to ensure wear levelling */ 173 /* Rotate the lists by some number to ensure wear levelling */
174 jffs2_rotate_lists(c); 174 jffs2_rotate_lists(c);
diff --git a/fs/jffs2/debug.c b/fs/jffs2/debug.c
index 9da524ca4e66..fb88eb19711b 100644
--- a/fs/jffs2/debug.c
+++ b/fs/jffs2/debug.c
@@ -7,18 +7,30 @@
7 * 7 *
8 * For licensing information, see the file 'LICENCE' in this directory. 8 * For licensing information, see the file 'LICENCE' in this directory.
9 * 9 *
10 * $Id: debug.c,v 1.1 2005/07/17 06:56:20 dedekind Exp $ 10 * $Id: debug.c,v 1.7 2005/07/24 15:14:14 dedekind Exp $
11 * 11 *
12 */ 12 */
13#include <linux/kernel.h> 13#include <linux/kernel.h>
14#include <linux/pagemap.h> 14#include <linux/pagemap.h>
15#include <linux/crc32.h>
16#include <linux/jffs2.h>
15#include "nodelist.h" 17#include "nodelist.h"
16#include "debug.h" 18#include "debug.h"
17 19
18#ifdef JFFS2_DBG_PARANOIA_CHECKS 20#ifdef JFFS2_DBG_PARANOIA_CHECKS
19 21/*
22 * Check the fragtree.
23 */
20void 24void
21jffs2_dbg_fragtree_paranoia_check(struct jffs2_inode_info *f) 25__jffs2_dbg_fragtree_paranoia_check(struct jffs2_inode_info *f)
26{
27 down(&f->sem);
28 __jffs2_dbg_fragtree_paranoia_check_nolock(f);
29 up(&f->sem);
30}
31
32void
33__jffs2_dbg_fragtree_paranoia_check_nolock(struct jffs2_inode_info *f)
22{ 34{
23 struct jffs2_node_frag *frag; 35 struct jffs2_node_frag *frag;
24 int bitched = 0; 36 int bitched = 0;
@@ -31,7 +43,7 @@ jffs2_dbg_fragtree_paranoia_check(struct jffs2_inode_info *f)
31 43
32 if (ref_flags(fn->raw) == REF_PRISTINE) { 44 if (ref_flags(fn->raw) == REF_PRISTINE) {
33 if (fn->frags > 1) { 45 if (fn->frags > 1) {
34 printk(KERN_ERR "REF_PRISTINE node at 0x%08x had %d frags. Tell dwmw2\n", 46 JFFS2_ERROR("REF_PRISTINE node at 0x%08x had %d frags. Tell dwmw2.\n",
35 ref_offset(fn->raw), fn->frags); 47 ref_offset(fn->raw), fn->frags);
36 bitched = 1; 48 bitched = 1;
37 } 49 }
@@ -43,15 +55,15 @@ jffs2_dbg_fragtree_paranoia_check(struct jffs2_inode_info *f)
43 to tell a hole node. */ 55 to tell a hole node. */
44 if (frag->ofs & (PAGE_CACHE_SIZE-1) && frag_prev(frag) 56 if (frag->ofs & (PAGE_CACHE_SIZE-1) && frag_prev(frag)
45 && frag_prev(frag)->size < PAGE_CACHE_SIZE && frag_prev(frag)->node) { 57 && frag_prev(frag)->size < PAGE_CACHE_SIZE && frag_prev(frag)->node) {
46 printk(KERN_ERR "REF_PRISTINE node at 0x%08x had a previous non-hole frag " 58 JFFS2_ERROR("REF_PRISTINE node at 0x%08x had a previous non-hole frag "
47 "in the same page. Tell dwmw2\n", ref_offset(fn->raw)); 59 "in the same page. Tell dwmw2.\n", ref_offset(fn->raw));
48 bitched = 1; 60 bitched = 1;
49 } 61 }
50 62
51 if ((frag->ofs+frag->size) & (PAGE_CACHE_SIZE-1) && frag_next(frag) 63 if ((frag->ofs+frag->size) & (PAGE_CACHE_SIZE-1) && frag_next(frag)
52 && frag_next(frag)->size < PAGE_CACHE_SIZE && frag_next(frag)->node) { 64 && frag_next(frag)->size < PAGE_CACHE_SIZE && frag_next(frag)->node) {
53 printk(KERN_ERR "REF_PRISTINE node at 0x%08x (%08x-%08x) had a following " 65 JFFS2_ERROR("REF_PRISTINE node at 0x%08x (%08x-%08x) had a following "
54 "non-hole frag in the same page. Tell dwmw2\n", 66 "non-hole frag in the same page. Tell dwmw2.\n",
55 ref_offset(fn->raw), frag->ofs, frag->ofs+frag->size); 67 ref_offset(fn->raw), frag->ofs, frag->ofs+frag->size);
56 bitched = 1; 68 bitched = 1;
57 } 69 }
@@ -59,8 +71,8 @@ jffs2_dbg_fragtree_paranoia_check(struct jffs2_inode_info *f)
59 } 71 }
60 72
61 if (bitched) { 73 if (bitched) {
62 printk(KERN_ERR "Fragtree is corrupted. Fragtree dump:\n"); 74 JFFS2_ERROR("fragtree is corrupted.\n");
63 jffs2_dbg_dump_fragtree(f); 75 __jffs2_dbg_dump_fragtree_nolock(f);
64 BUG(); 76 BUG();
65 } 77 }
66} 78}
@@ -69,7 +81,8 @@ jffs2_dbg_fragtree_paranoia_check(struct jffs2_inode_info *f)
69 * Check if the flash contains all 0xFF before we start writing. 81 * Check if the flash contains all 0xFF before we start writing.
70 */ 82 */
71void 83void
72jffs2_dbg_prewrite_paranoia_check(struct jffs2_sb_info *c, uint32_t ofs, int len) 84__jffs2_dbg_prewrite_paranoia_check(struct jffs2_sb_info *c,
85 uint32_t ofs, int len)
73{ 86{
74 size_t retlen; 87 size_t retlen;
75 int ret, i; 88 int ret, i;
@@ -81,8 +94,8 @@ jffs2_dbg_prewrite_paranoia_check(struct jffs2_sb_info *c, uint32_t ofs, int len
81 94
82 ret = jffs2_flash_read(c, ofs, len, &retlen, buf); 95 ret = jffs2_flash_read(c, ofs, len, &retlen, buf);
83 if (ret || (retlen != len)) { 96 if (ret || (retlen != len)) {
84 printk(KERN_WARNING "read %d bytes failed or short in %s(). ret %d, retlen %zd\n", 97 JFFS2_WARNING("read %d bytes failed or short. ret %d, retlen %zd.\n",
85 len, __FUNCTION__, ret, retlen); 98 len, ret, retlen);
86 kfree(buf); 99 kfree(buf);
87 return; 100 return;
88 } 101 }
@@ -93,9 +106,9 @@ jffs2_dbg_prewrite_paranoia_check(struct jffs2_sb_info *c, uint32_t ofs, int len
93 ret = 1; 106 ret = 1;
94 107
95 if (ret) { 108 if (ret) {
96 printk(KERN_ERR "ARGH. About to write node to %#08x on flash, but there are data " 109 JFFS2_ERROR("argh, about to write node to %#08x on flash, but there are data "
97 "already there. The first corrupted byte is at %#08x.\n", ofs, ofs + i); 110 "already there. The first corrupted byte is at %#08x offset.\n", ofs, ofs + i);
98 jffs2_dbg_dump_buffer(buf, len, ofs); 111 __jffs2_dbg_dump_buffer(buf, len, ofs);
99 kfree(buf); 112 kfree(buf);
100 BUG(); 113 BUG();
101 } 114 }
@@ -107,7 +120,17 @@ jffs2_dbg_prewrite_paranoia_check(struct jffs2_sb_info *c, uint32_t ofs, int len
107 * Check the space accounting and node_ref list correctness for the JFFS2 erasable block 'jeb'. 120 * Check the space accounting and node_ref list correctness for the JFFS2 erasable block 'jeb'.
108 */ 121 */
109void 122void
110jffs2_dbg_acct_paranoia_check(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb) 123__jffs2_dbg_acct_paranoia_check(struct jffs2_sb_info *c,
124 struct jffs2_eraseblock *jeb)
125{
126 spin_lock(&c->erase_completion_lock);
127 __jffs2_dbg_acct_paranoia_check_nolock(c, jeb);
128 spin_unlock(&c->erase_completion_lock);
129}
130
131void
132__jffs2_dbg_acct_paranoia_check_nolock(struct jffs2_sb_info *c,
133 struct jffs2_eraseblock *jeb)
111{ 134{
112 uint32_t my_used_size = 0; 135 uint32_t my_used_size = 0;
113 uint32_t my_unchecked_size = 0; 136 uint32_t my_unchecked_size = 0;
@@ -119,11 +142,9 @@ jffs2_dbg_acct_paranoia_check(struct jffs2_sb_info *c, struct jffs2_eraseblock *
119 142
120 if (ref2->flash_offset < jeb->offset || 143 if (ref2->flash_offset < jeb->offset ||
121 ref2->flash_offset > jeb->offset + c->sector_size) { 144 ref2->flash_offset > jeb->offset + c->sector_size) {
122 printk(KERN_ERR "node_ref %#08x shouldn't be in block at %#08x!\n", 145 JFFS2_ERROR("node_ref %#08x shouldn't be in block at %#08x.\n",
123 ref_offset(ref2), jeb->offset); 146 ref_offset(ref2), jeb->offset);
124 jffs2_dbg_dump_node_refs(c, jeb); 147 goto error;
125 jffs2_dbg_dump_block_lists(c);
126 BUG();
127 148
128 } 149 }
129 if (ref_flags(ref2) == REF_UNCHECKED) 150 if (ref_flags(ref2) == REF_UNCHECKED)
@@ -134,69 +155,82 @@ jffs2_dbg_acct_paranoia_check(struct jffs2_sb_info *c, struct jffs2_eraseblock *
134 my_dirty_size += totlen; 155 my_dirty_size += totlen;
135 156
136 if ((!ref2->next_phys) != (ref2 == jeb->last_node)) { 157 if ((!ref2->next_phys) != (ref2 == jeb->last_node)) {
137 printk(KERN_ERR "node_ref for node at %#08x (mem %p) has next_phys at %#08x (mem %p), " 158 JFFS2_ERROR("node_ref for node at %#08x (mem %p) has next_phys at %#08x (mem %p), "
138 "last_node is at %#08x (mem %p)\n", 159 "last_node is at %#08x (mem %p).\n",
139 ref_offset(ref2), ref2, ref_offset(ref2->next_phys), ref2->next_phys, 160 ref_offset(ref2), ref2, ref_offset(ref2->next_phys), ref2->next_phys,
140 ref_offset(jeb->last_node), jeb->last_node); 161 ref_offset(jeb->last_node), jeb->last_node);
141 jffs2_dbg_dump_node_refs(c, jeb); 162 goto error;
142 jffs2_dbg_dump_block_lists(c);
143 BUG();
144 } 163 }
145 ref2 = ref2->next_phys; 164 ref2 = ref2->next_phys;
146 } 165 }
147 166
148 if (my_used_size != jeb->used_size) { 167 if (my_used_size != jeb->used_size) {
149 printk(KERN_ERR "Calculated used size %#08x != stored used size %#08x\n", 168 JFFS2_ERROR("Calculated used size %#08x != stored used size %#08x.\n",
150 my_used_size, jeb->used_size); 169 my_used_size, jeb->used_size);
151 jffs2_dbg_dump_node_refs(c, jeb); 170 goto error;
152 jffs2_dbg_dump_block_lists(c);
153 BUG();
154 } 171 }
155 172
156 if (my_unchecked_size != jeb->unchecked_size) { 173 if (my_unchecked_size != jeb->unchecked_size) {
157 printk(KERN_ERR "Calculated unchecked size %#08x != stored unchecked size %#08x\n", 174 JFFS2_ERROR("Calculated unchecked size %#08x != stored unchecked size %#08x.\n",
158 my_unchecked_size, jeb->unchecked_size); 175 my_unchecked_size, jeb->unchecked_size);
159 jffs2_dbg_dump_node_refs(c, jeb); 176 goto error;
160 jffs2_dbg_dump_block_lists(c);
161 BUG();
162 } 177 }
163 178
179#if 0
180 /* This should work when we implement ref->__totlen elemination */
164 if (my_dirty_size != jeb->dirty_size + jeb->wasted_size) { 181 if (my_dirty_size != jeb->dirty_size + jeb->wasted_size) {
165 printk(KERN_ERR "Calculated dirty+wasted size %#08x != stored dirty + wasted size %#08x\n", 182 JFFS2_ERROR("Calculated dirty+wasted size %#08x != stored dirty + wasted size %#08x\n",
166 my_dirty_size, jeb->dirty_size + jeb->wasted_size); 183 my_dirty_size, jeb->dirty_size + jeb->wasted_size);
167 jffs2_dbg_dump_node_refs(c, jeb); 184 goto error;
168 jffs2_dbg_dump_block_lists(c);
169 BUG();
170 } 185 }
171 186
172 if (jeb->free_size == 0 187 if (jeb->free_size == 0
173 && my_used_size + my_unchecked_size + my_dirty_size != c->sector_size) { 188 && my_used_size + my_unchecked_size + my_dirty_size != c->sector_size) {
174 printk(KERN_ERR "The sum of all nodes in block (%#x) != size of block (%#x)\n", 189 JFFS2_ERROR("The sum of all nodes in block (%#x) != size of block (%#x)\n",
175 my_used_size + my_unchecked_size + my_dirty_size, 190 my_used_size + my_unchecked_size + my_dirty_size,
176 c->sector_size); 191 c->sector_size);
177 jffs2_dbg_dump_node_refs(c, jeb); 192 goto error;
178 jffs2_dbg_dump_block_lists(c);
179 BUG();
180 } 193 }
194#endif
195
196 return;
197
198error:
199 __jffs2_dbg_dump_node_refs_nolock(c, jeb);
200 __jffs2_dbg_dump_jeb_nolock(jeb);
201 __jffs2_dbg_dump_block_lists_nolock(c);
202 BUG();
203
181} 204}
182#endif /* JFFS2_PARANOIA_CHECKS */ 205#endif /* JFFS2_DBG_PARANOIA_CHECKS */
183 206
184#if defined(JFFS2_PARANOIA_CHECKS) || (CONFIG_JFFS2_FS_DEBUG > 0) 207#if defined(JFFS2_DBG_DUMPS) || defined(JFFS2_DBG_PARANOIA_CHECKS)
185/* 208/*
186 * Dump the node_refs of the 'jeb' JFFS2 eraseblock. 209 * Dump the node_refs of the 'jeb' JFFS2 eraseblock.
187 */ 210 */
188void 211void
189jffs2_dbg_dump_node_refs(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb) 212__jffs2_dbg_dump_node_refs(struct jffs2_sb_info *c,
213 struct jffs2_eraseblock *jeb)
214{
215 spin_lock(&c->erase_completion_lock);
216 __jffs2_dbg_dump_node_refs_nolock(c, jeb);
217 spin_unlock(&c->erase_completion_lock);
218}
219
220void
221__jffs2_dbg_dump_node_refs_nolock(struct jffs2_sb_info *c,
222 struct jffs2_eraseblock *jeb)
190{ 223{
191 struct jffs2_raw_node_ref *ref; 224 struct jffs2_raw_node_ref *ref;
192 int i = 0; 225 int i = 0;
193 226
227 JFFS2_DEBUG("Dump node_refs of the eraseblock %#08x\n", jeb->offset);
194 if (!jeb->first_node) { 228 if (!jeb->first_node) {
195 printk(KERN_DEBUG "no nodes in block %#08x\n", jeb->offset); 229 JFFS2_DEBUG("no nodes in the eraseblock %#08x\n", jeb->offset);
196 return; 230 return;
197 } 231 }
198 232
199 printk(KERN_DEBUG); 233 printk(JFFS2_DBG_LVL);
200 for (ref = jeb->first_node; ; ref = ref->next_phys) { 234 for (ref = jeb->first_node; ; ref = ref->next_phys) {
201 printk("%#08x(%#x)", ref_offset(ref), ref->__totlen); 235 printk("%#08x(%#x)", ref_offset(ref), ref->__totlen);
202 if (ref->next_phys) 236 if (ref->next_phys)
@@ -205,46 +239,83 @@ jffs2_dbg_dump_node_refs(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb)
205 break; 239 break;
206 if (++i == 4) { 240 if (++i == 4) {
207 i = 0; 241 i = 0;
208 printk("\n" KERN_DEBUG); 242 printk("\n" JFFS2_DBG_LVL);
209 } 243 }
210 } 244 }
211 printk("\n"); 245 printk("\n");
212} 246}
213 247
248/*
249 * Dump an eraseblock's space accounting.
250 */
251void
252__jffs2_dbg_dump_jeb(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb)
253{
254 spin_lock(&c->erase_completion_lock);
255 __jffs2_dbg_dump_jeb_nolock(jeb);
256 spin_unlock(&c->erase_completion_lock);
257}
258
214void 259void
215jffs2_dbg_dump_block_lists(struct jffs2_sb_info *c) 260__jffs2_dbg_dump_jeb_nolock(struct jffs2_eraseblock *jeb)
216{ 261{
217 printk(KERN_DEBUG "flash_size: %#08x\n", c->flash_size); 262 if (!jeb)
218 printk(KERN_DEBUG "used_size: %#08x\n", c->used_size); 263 return;
219 printk(KERN_DEBUG "dirty_size: %#08x\n", c->dirty_size); 264
220 printk(KERN_DEBUG "wasted_size: %#08x\n", c->wasted_size); 265 JFFS2_DEBUG("dump space accounting for the eraseblock at %#08x:\n",
221 printk(KERN_DEBUG "unchecked_size: %#08x\n", c->unchecked_size); 266 jeb->offset);
222 printk(KERN_DEBUG "free_size: %#08x\n", c->free_size); 267
223 printk(KERN_DEBUG "erasing_size: %#08x\n", c->erasing_size); 268 printk(JFFS2_DBG_LVL "used_size: %#08x\n", jeb->used_size);
224 printk(KERN_DEBUG "bad_size: %#08x\n", c->bad_size); 269 printk(JFFS2_DBG_LVL "dirty_size: %#08x\n", jeb->dirty_size);
225 printk(KERN_DEBUG "sector_size: %#08x\n", c->sector_size); 270 printk(JFFS2_DBG_LVL "wasted_size: %#08x\n", jeb->wasted_size);
226 printk(KERN_DEBUG "jffs2_reserved_blocks size: %#08x\n", 271 printk(JFFS2_DBG_LVL "unchecked_size: %#08x\n", jeb->unchecked_size);
272 printk(JFFS2_DBG_LVL "free_size: %#08x\n", jeb->free_size);
273}
274
275void
276__jffs2_dbg_dump_block_lists(struct jffs2_sb_info *c)
277{
278 spin_lock(&c->erase_completion_lock);
279 __jffs2_dbg_dump_block_lists_nolock(c);
280 spin_unlock(&c->erase_completion_lock);
281}
282
283void
284__jffs2_dbg_dump_block_lists_nolock(struct jffs2_sb_info *c)
285{
286 JFFS2_DEBUG("dump JFFS2 blocks lists:\n");
287
288 printk(JFFS2_DBG_LVL "flash_size: %#08x\n", c->flash_size);
289 printk(JFFS2_DBG_LVL "used_size: %#08x\n", c->used_size);
290 printk(JFFS2_DBG_LVL "dirty_size: %#08x\n", c->dirty_size);
291 printk(JFFS2_DBG_LVL "wasted_size: %#08x\n", c->wasted_size);
292 printk(JFFS2_DBG_LVL "unchecked_size: %#08x\n", c->unchecked_size);
293 printk(JFFS2_DBG_LVL "free_size: %#08x\n", c->free_size);
294 printk(JFFS2_DBG_LVL "erasing_size: %#08x\n", c->erasing_size);
295 printk(JFFS2_DBG_LVL "bad_size: %#08x\n", c->bad_size);
296 printk(JFFS2_DBG_LVL "sector_size: %#08x\n", c->sector_size);
297 printk(JFFS2_DBG_LVL "jffs2_reserved_blocks size: %#08x\n",
227 c->sector_size * c->resv_blocks_write); 298 c->sector_size * c->resv_blocks_write);
228 299
229 if (c->nextblock) 300 if (c->nextblock)
230 printk(KERN_DEBUG "nextblock: %#08x (used %#08x, dirty %#08x, wasted %#08x, " 301 printk(JFFS2_DBG_LVL "nextblock: %#08x (used %#08x, dirty %#08x, wasted %#08x, "
231 "unchecked %#08x, free %#08x)\n", 302 "unchecked %#08x, free %#08x)\n",
232 c->nextblock->offset, c->nextblock->used_size, 303 c->nextblock->offset, c->nextblock->used_size,
233 c->nextblock->dirty_size, c->nextblock->wasted_size, 304 c->nextblock->dirty_size, c->nextblock->wasted_size,
234 c->nextblock->unchecked_size, c->nextblock->free_size); 305 c->nextblock->unchecked_size, c->nextblock->free_size);
235 else 306 else
236 printk(KERN_DEBUG "nextblock: NULL\n"); 307 printk(JFFS2_DBG_LVL "nextblock: NULL\n");
237 308
238 if (c->gcblock) 309 if (c->gcblock)
239 printk(KERN_DEBUG "gcblock: %#08x (used %#08x, dirty %#08x, wasted %#08x, " 310 printk(JFFS2_DBG_LVL "gcblock: %#08x (used %#08x, dirty %#08x, wasted %#08x, "
240 "unchecked %#08x, free %#08x)\n", 311 "unchecked %#08x, free %#08x)\n",
241 c->gcblock->offset, c->gcblock->used_size, c->gcblock->dirty_size, 312 c->gcblock->offset, c->gcblock->used_size, c->gcblock->dirty_size,
242 c->gcblock->wasted_size, c->gcblock->unchecked_size, c->gcblock->free_size); 313 c->gcblock->wasted_size, c->gcblock->unchecked_size, c->gcblock->free_size);
243 else 314 else
244 printk(KERN_DEBUG "gcblock: NULL\n"); 315 printk(JFFS2_DBG_LVL "gcblock: NULL\n");
245 316
246 if (list_empty(&c->clean_list)) { 317 if (list_empty(&c->clean_list)) {
247 printk(KERN_DEBUG "clean_list: empty\n"); 318 printk(JFFS2_DBG_LVL "clean_list: empty\n");
248 } else { 319 } else {
249 struct list_head *this; 320 struct list_head *this;
250 int numblocks = 0; 321 int numblocks = 0;
@@ -255,19 +326,19 @@ jffs2_dbg_dump_block_lists(struct jffs2_sb_info *c)
255 numblocks ++; 326 numblocks ++;
256 dirty += jeb->wasted_size; 327 dirty += jeb->wasted_size;
257 if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) { 328 if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) {
258 printk(KERN_DEBUG "clean_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, " 329 printk(JFFS2_DBG_LVL "clean_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, "
259 "unchecked %#08x, free %#08x)\n", 330 "unchecked %#08x, free %#08x)\n",
260 jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size, 331 jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size,
261 jeb->unchecked_size, jeb->free_size); 332 jeb->unchecked_size, jeb->free_size);
262 } 333 }
263 } 334 }
264 335
265 printk (KERN_DEBUG "Contains %d blocks with total wasted size %u, average wasted size: %u\n", 336 printk (JFFS2_DBG_LVL "Contains %d blocks with total wasted size %u, average wasted size: %u\n",
266 numblocks, dirty, dirty / numblocks); 337 numblocks, dirty, dirty / numblocks);
267 } 338 }
268 339
269 if (list_empty(&c->very_dirty_list)) { 340 if (list_empty(&c->very_dirty_list)) {
270 printk(KERN_DEBUG "very_dirty_list: empty\n"); 341 printk(JFFS2_DBG_LVL "very_dirty_list: empty\n");
271 } else { 342 } else {
272 struct list_head *this; 343 struct list_head *this;
273 int numblocks = 0; 344 int numblocks = 0;
@@ -279,19 +350,19 @@ jffs2_dbg_dump_block_lists(struct jffs2_sb_info *c)
279 numblocks ++; 350 numblocks ++;
280 dirty += jeb->dirty_size; 351 dirty += jeb->dirty_size;
281 if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) { 352 if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) {
282 printk(KERN_DEBUG "very_dirty_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, " 353 printk(JFFS2_DBG_LVL "very_dirty_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, "
283 "unchecked %#08x, free %#08x)\n", 354 "unchecked %#08x, free %#08x)\n",
284 jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size, 355 jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size,
285 jeb->unchecked_size, jeb->free_size); 356 jeb->unchecked_size, jeb->free_size);
286 } 357 }
287 } 358 }
288 359
289 printk (KERN_DEBUG "Contains %d blocks with total dirty size %u, average dirty size: %u\n", 360 printk (JFFS2_DBG_LVL "Contains %d blocks with total dirty size %u, average dirty size: %u\n",
290 numblocks, dirty, dirty / numblocks); 361 numblocks, dirty, dirty / numblocks);
291 } 362 }
292 363
293 if (list_empty(&c->dirty_list)) { 364 if (list_empty(&c->dirty_list)) {
294 printk(KERN_DEBUG "dirty_list: empty\n"); 365 printk(JFFS2_DBG_LVL "dirty_list: empty\n");
295 } else { 366 } else {
296 struct list_head *this; 367 struct list_head *this;
297 int numblocks = 0; 368 int numblocks = 0;
@@ -303,19 +374,19 @@ jffs2_dbg_dump_block_lists(struct jffs2_sb_info *c)
303 numblocks ++; 374 numblocks ++;
304 dirty += jeb->dirty_size; 375 dirty += jeb->dirty_size;
305 if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) { 376 if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) {
306 printk(KERN_DEBUG "dirty_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, " 377 printk(JFFS2_DBG_LVL "dirty_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, "
307 "unchecked %#08x, free %#08x)\n", 378 "unchecked %#08x, free %#08x)\n",
308 jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size, 379 jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size,
309 jeb->unchecked_size, jeb->free_size); 380 jeb->unchecked_size, jeb->free_size);
310 } 381 }
311 } 382 }
312 383
313 printk (KERN_DEBUG "Contains %d blocks with total dirty size %u, average dirty size: %u\n", 384 printk (JFFS2_DBG_LVL "contains %d blocks with total dirty size %u, average dirty size: %u\n",
314 numblocks, dirty, dirty / numblocks); 385 numblocks, dirty, dirty / numblocks);
315 } 386 }
316 387
317 if (list_empty(&c->erasable_list)) { 388 if (list_empty(&c->erasable_list)) {
318 printk(KERN_DEBUG "erasable_list: empty\n"); 389 printk(JFFS2_DBG_LVL "erasable_list: empty\n");
319 } else { 390 } else {
320 struct list_head *this; 391 struct list_head *this;
321 392
@@ -323,16 +394,16 @@ jffs2_dbg_dump_block_lists(struct jffs2_sb_info *c)
323 struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list); 394 struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list);
324 395
325 if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) { 396 if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) {
326 printk(KERN_DEBUG "erasable_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, " 397 printk(JFFS2_DBG_LVL "erasable_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, "
327 "unchecked %#08x, free %#08x)\n", 398 "unchecked %#08x, free %#08x)\n",
328 jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size, 399 jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size,
329 jeb->unchecked_size, jeb->free_size); 400 jeb->unchecked_size, jeb->free_size);
330 } 401 }
331 } 402 }
332 } 403 }
333 404
334 if (list_empty(&c->erasing_list)) { 405 if (list_empty(&c->erasing_list)) {
335 printk(KERN_DEBUG "erasing_list: empty\n"); 406 printk(JFFS2_DBG_LVL "erasing_list: empty\n");
336 } else { 407 } else {
337 struct list_head *this; 408 struct list_head *this;
338 409
@@ -340,16 +411,16 @@ jffs2_dbg_dump_block_lists(struct jffs2_sb_info *c)
340 struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list); 411 struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list);
341 412
342 if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) { 413 if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) {
343 printk(KERN_DEBUG "erasing_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, " 414 printk(JFFS2_DBG_LVL "erasing_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, "
344 "unchecked %#08x, free %#08x)\n", 415 "unchecked %#08x, free %#08x)\n",
345 jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size, 416 jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size,
346 jeb->unchecked_size, jeb->free_size); 417 jeb->unchecked_size, jeb->free_size);
347 } 418 }
348 } 419 }
349 } 420 }
350 421
351 if (list_empty(&c->erase_pending_list)) { 422 if (list_empty(&c->erase_pending_list)) {
352 printk(KERN_DEBUG "erase_pending_list: empty\n"); 423 printk(JFFS2_DBG_LVL "erase_pending_list: empty\n");
353 } else { 424 } else {
354 struct list_head *this; 425 struct list_head *this;
355 426
@@ -357,16 +428,16 @@ jffs2_dbg_dump_block_lists(struct jffs2_sb_info *c)
357 struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list); 428 struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list);
358 429
359 if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) { 430 if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) {
360 printk(KERN_DEBUG "erase_pending_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, " 431 printk(JFFS2_DBG_LVL "erase_pending_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, "
361 "unchecked %#08x, free %#08x)\n", 432 "unchecked %#08x, free %#08x)\n",
362 jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size, 433 jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size,
363 jeb->unchecked_size, jeb->free_size); 434 jeb->unchecked_size, jeb->free_size);
364 } 435 }
365 } 436 }
366 } 437 }
367 438
368 if (list_empty(&c->erasable_pending_wbuf_list)) { 439 if (list_empty(&c->erasable_pending_wbuf_list)) {
369 printk(KERN_DEBUG "erasable_pending_wbuf_list: empty\n"); 440 printk(JFFS2_DBG_LVL "erasable_pending_wbuf_list: empty\n");
370 } else { 441 } else {
371 struct list_head *this; 442 struct list_head *this;
372 443
@@ -374,16 +445,16 @@ jffs2_dbg_dump_block_lists(struct jffs2_sb_info *c)
374 struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list); 445 struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list);
375 446
376 if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) { 447 if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) {
377 printk(KERN_DEBUG "erasable_pending_wbuf_list: %#08x (used %#08x, dirty %#08x, " 448 printk(JFFS2_DBG_LVL "erasable_pending_wbuf_list: %#08x (used %#08x, dirty %#08x, "
378 "wasted %#08x, unchecked %#08x, free %#08x)\n", 449 "wasted %#08x, unchecked %#08x, free %#08x)\n",
379 jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size, 450 jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size,
380 jeb->unchecked_size, jeb->free_size); 451 jeb->unchecked_size, jeb->free_size);
381 } 452 }
382 } 453 }
383 } 454 }
384 455
385 if (list_empty(&c->free_list)) { 456 if (list_empty(&c->free_list)) {
386 printk(KERN_DEBUG "free_list: empty\n"); 457 printk(JFFS2_DBG_LVL "free_list: empty\n");
387 } else { 458 } else {
388 struct list_head *this; 459 struct list_head *this;
389 460
@@ -391,16 +462,16 @@ jffs2_dbg_dump_block_lists(struct jffs2_sb_info *c)
391 struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list); 462 struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list);
392 463
393 if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) { 464 if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) {
394 printk(KERN_DEBUG "free_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, " 465 printk(JFFS2_DBG_LVL "free_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, "
395 "unchecked %#08x, free %#08x)\n", 466 "unchecked %#08x, free %#08x)\n",
396 jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size, 467 jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size,
397 jeb->unchecked_size, jeb->free_size); 468 jeb->unchecked_size, jeb->free_size);
398 } 469 }
399 } 470 }
400 } 471 }
401 472
402 if (list_empty(&c->bad_list)) { 473 if (list_empty(&c->bad_list)) {
403 printk(KERN_DEBUG "bad_list: empty\n"); 474 printk(JFFS2_DBG_LVL "bad_list: empty\n");
404 } else { 475 } else {
405 struct list_head *this; 476 struct list_head *this;
406 477
@@ -408,16 +479,16 @@ jffs2_dbg_dump_block_lists(struct jffs2_sb_info *c)
408 struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list); 479 struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list);
409 480
410 if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) { 481 if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) {
411 printk(KERN_DEBUG "bad_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, " 482 printk(JFFS2_DBG_LVL "bad_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, "
412 "unchecked %#08x, free %#08x)\n", 483 "unchecked %#08x, free %#08x)\n",
413 jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size, 484 jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size,
414 jeb->unchecked_size, jeb->free_size); 485 jeb->unchecked_size, jeb->free_size);
415 } 486 }
416 } 487 }
417 } 488 }
418 489
419 if (list_empty(&c->bad_used_list)) { 490 if (list_empty(&c->bad_used_list)) {
420 printk(KERN_DEBUG "bad_used_list: empty\n"); 491 printk(JFFS2_DBG_LVL "bad_used_list: empty\n");
421 } else { 492 } else {
422 struct list_head *this; 493 struct list_head *this;
423 494
@@ -425,34 +496,42 @@ jffs2_dbg_dump_block_lists(struct jffs2_sb_info *c)
425 struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list); 496 struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list);
426 497
427 if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) { 498 if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) {
428 printk(KERN_DEBUG "bad_used_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, " 499 printk(JFFS2_DBG_LVL "bad_used_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, "
429 "unchecked %#08x, free %#08x)\n", 500 "unchecked %#08x, free %#08x)\n",
430 jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size, 501 jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size,
431 jeb->unchecked_size, jeb->free_size); 502 jeb->unchecked_size, jeb->free_size);
432 } 503 }
433 } 504 }
434 } 505 }
435} 506}
436 507
437void 508void
438jffs2_dbg_dump_fragtree(struct jffs2_inode_info *f) 509__jffs2_dbg_dump_fragtree(struct jffs2_inode_info *f)
510{
511 down(&f->sem);
512 jffs2_dbg_dump_fragtree_nolock(f);
513 up(&f->sem);
514}
515
516void
517__jffs2_dbg_dump_fragtree_nolock(struct jffs2_inode_info *f)
439{ 518{
440 struct jffs2_node_frag *this = frag_first(&f->fragtree); 519 struct jffs2_node_frag *this = frag_first(&f->fragtree);
441 uint32_t lastofs = 0; 520 uint32_t lastofs = 0;
442 int buggy = 0; 521 int buggy = 0;
443 522
444 printk(KERN_DEBUG "inode is ino #%u\n", f->inocache->ino); 523 JFFS2_DEBUG("dump fragtree of ino #%u\n", f->inocache->ino);
445 while(this) { 524 while(this) {
446 if (this->node) 525 if (this->node)
447 printk(KERN_DEBUG "frag %#04x-%#04x: %#08x(%d) on flash (*%p), left (%p), " 526 printk(JFFS2_DBG_LVL "frag %#04x-%#04x: %#08x(%d) on flash (*%p), left (%p), "
448 "right (%p), parent (%p)\n", 527 "right (%p), parent (%p)\n",
449 this->ofs, this->ofs+this->size, ref_offset(this->node->raw), 528 this->ofs, this->ofs+this->size, ref_offset(this->node->raw),
450 ref_flags(this->node->raw), this, frag_left(this), frag_right(this), 529 ref_flags(this->node->raw), this, frag_left(this), frag_right(this),
451 frag_parent(this)); 530 frag_parent(this));
452 else 531 else
453 printk(KERN_DEBUG "frag %#04x-%#04x: hole (*%p). left (%p), right (%p), parent (%p)\n", 532 printk(JFFS2_DBG_LVL "frag %#04x-%#04x: hole (*%p). left (%p), right (%p), parent (%p)\n",
454 this->ofs, this->ofs+this->size, this, frag_left(this), 533 this->ofs, this->ofs+this->size, this, frag_left(this),
455 frag_right(this), frag_parent(this)); 534 frag_right(this), frag_parent(this));
456 if (this->ofs != lastofs) 535 if (this->ofs != lastofs)
457 buggy = 1; 536 buggy = 1;
458 lastofs = this->ofs + this->size; 537 lastofs = this->ofs + this->size;
@@ -460,36 +539,171 @@ jffs2_dbg_dump_fragtree(struct jffs2_inode_info *f)
460 } 539 }
461 540
462 if (f->metadata) 541 if (f->metadata)
463 printk(KERN_DEBUG "metadata at 0x%08x\n", ref_offset(f->metadata->raw)); 542 printk(JFFS2_DBG_LVL "metadata at 0x%08x\n", ref_offset(f->metadata->raw));
464 543
465 if (buggy) { 544 if (buggy) {
466 printk(KERN_ERR "Error! %s(): Frag tree got a hole in it\n", __FUNCTION__); 545 JFFS2_ERROR("frag tree got a hole in it.\n");
467 BUG(); 546 BUG();
468 } 547 }
469} 548}
470 549
471#define JFFS3_BUFDUMP_BYTES_PER_LINE 8 550#define JFFS2_BUFDUMP_BYTES_PER_LINE 32
472void 551void
473jffs2_dbg_dump_buffer(char *buf, int len, uint32_t offs) 552__jffs2_dbg_dump_buffer(unsigned char *buf, int len, uint32_t offs)
474{ 553{
475 int i = 0; 554 int skip;
476 int skip = offs & ~(JFFS3_BUFDUMP_BYTES_PER_LINE - 1); 555 int i;
556
557 JFFS2_DEBUG("dump from offset %#08x to offset %#08x (%x bytes).\n",
558 offs, offs + len, len);
559 i = skip = offs % JFFS2_BUFDUMP_BYTES_PER_LINE;
560 offs = offs & ~(JFFS2_BUFDUMP_BYTES_PER_LINE - 1);
561
562 if (skip != 0)
563 printk(JFFS2_DBG_LVL "%#08x: ", offs);
564
565 while (skip--)
566 printk(" ");
477 567
478 while (i < len) { 568 while (i < len) {
479 int j = 0; 569 if ((i % JFFS2_BUFDUMP_BYTES_PER_LINE) == 0 && i != len -1) {
480 570 if (i != 0)
481 printk(KERN_DEBUG "0x#x: \n"); 571 printk("\n");
482 while (skip) { 572 offs += JFFS2_BUFDUMP_BYTES_PER_LINE;
483 printk(" "); 573 printk(JFFS2_DBG_LVL "%0#8x: ", offs);
484 skip -= 1;
485 } 574 }
486 575
487 while (j < JFFS3_BUFDUMP_BYTES_PER_LINE) { 576 printk("%02x ", buf[i]);
488 if (i + j < len) 577
489 printk(" %#02x", buf[i + j++]); 578 i += 1;
579 }
580
581 printk("\n");
582}
583
584/*
585 * Dump a JFFS2 node.
586 */
587void
588__jffs2_dbg_dump_node(struct jffs2_sb_info *c, uint32_t ofs)
589{
590 union jffs2_node_union node;
591 int len = sizeof(union jffs2_node_union);
592 size_t retlen;
593 uint32_t crc;
594 int ret;
595
596 JFFS2_DEBUG("dump node at offset %#08x.\n", ofs);
597
598 ret = jffs2_flash_read(c, ofs, len, &retlen, (unsigned char *)&node);
599 if (ret || (retlen != len)) {
600 JFFS2_ERROR("read %d bytes failed or short. ret %d, retlen %zd.\n",
601 len, ret, retlen);
602 return;
603 }
604
605 printk(JFFS2_DBG_LVL "magic:\t%#04x\n",
606 je16_to_cpu(node.u.magic));
607 printk(JFFS2_DBG_LVL "nodetype:\t%#04x\n",
608 je16_to_cpu(node.u.nodetype));
609 printk(JFFS2_DBG_LVL "totlen:\t%#08x\n",
610 je32_to_cpu(node.u.totlen));
611 printk(JFFS2_DBG_LVL "hdr_crc:\t%#08x\n",
612 je32_to_cpu(node.u.hdr_crc));
613
614 crc = crc32(0, &node.u, sizeof(node.u) - 4);
615 if (crc != je32_to_cpu(node.u.hdr_crc)) {
616 JFFS2_ERROR("wrong common header CRC.\n");
617 return;
618 }
619
620 if (je16_to_cpu(node.u.magic) != JFFS2_MAGIC_BITMASK &&
621 je16_to_cpu(node.u.magic) != JFFS2_OLD_MAGIC_BITMASK)
622 {
623 JFFS2_ERROR("wrong node magic: %#04x instead of %#04x.\n",
624 je16_to_cpu(node.u.magic), JFFS2_MAGIC_BITMASK);
625 return;
626 }
627
628 switch(je16_to_cpu(node.u.nodetype)) {
629
630 case JFFS2_NODETYPE_INODE:
631
632 printk(JFFS2_DBG_LVL "the node is inode node\n");
633 printk(JFFS2_DBG_LVL "ino:\t%#08x\n",
634 je32_to_cpu(node.i.ino));
635 printk(JFFS2_DBG_LVL "version:\t%#08x\n",
636 je32_to_cpu(node.i.version));
637 printk(JFFS2_DBG_LVL "mode:\t%#08x\n",
638 node.i.mode.m);
639 printk(JFFS2_DBG_LVL "uid:\t%#04x\n",
640 je16_to_cpu(node.i.uid));
641 printk(JFFS2_DBG_LVL "gid:\t%#04x\n",
642 je16_to_cpu(node.i.gid));
643 printk(JFFS2_DBG_LVL "isize:\t%#08x\n",
644 je32_to_cpu(node.i.isize));
645 printk(JFFS2_DBG_LVL "atime:\t%#08x\n",
646 je32_to_cpu(node.i.atime));
647 printk(JFFS2_DBG_LVL "mtime:\t%#08x\n",
648 je32_to_cpu(node.i.mtime));
649 printk(JFFS2_DBG_LVL "ctime:\t%#08x\n",
650 je32_to_cpu(node.i.ctime));
651 printk(JFFS2_DBG_LVL "offset:\t%#08x\n",
652 je32_to_cpu(node.i.offset));
653 printk(JFFS2_DBG_LVL "csize:\t%#08x\n",
654 je32_to_cpu(node.i.csize));
655 printk(JFFS2_DBG_LVL "dsize:\t%#08x\n",
656 je32_to_cpu(node.i.dsize));
657 printk(JFFS2_DBG_LVL "compr:\t%#02x\n",
658 node.i.compr);
659 printk(JFFS2_DBG_LVL "usercompr:\t%#02x\n",
660 node.i.usercompr);
661 printk(JFFS2_DBG_LVL "flags:\t%#04x\n",
662 je16_to_cpu(node.i.flags));
663 printk(JFFS2_DBG_LVL "data_crc:\t%#08x\n",
664 je32_to_cpu(node.i.data_crc));
665 printk(JFFS2_DBG_LVL "node_crc:\t%#08x\n",
666 je32_to_cpu(node.i.node_crc));
667 crc = crc32(0, &node.i, sizeof(node.i) - 8);
668 if (crc != je32_to_cpu(node.i.node_crc)) {
669 JFFS2_ERROR("wrong node header CRC.\n");
670 return;
671 }
672 break;
673
674 case JFFS2_NODETYPE_DIRENT:
675
676 printk(JFFS2_DBG_LVL "the node is dirent node\n");
677 printk(JFFS2_DBG_LVL "pino:\t%#08x\n",
678 je32_to_cpu(node.d.pino));
679 printk(JFFS2_DBG_LVL "version:\t%#08x\n",
680 je32_to_cpu(node.d.version));
681 printk(JFFS2_DBG_LVL "ino:\t%#08x\n",
682 je32_to_cpu(node.d.ino));
683 printk(JFFS2_DBG_LVL "mctime:\t%#08x\n",
684 je32_to_cpu(node.d.mctime));
685 printk(JFFS2_DBG_LVL "nsize:\t%#02x\n",
686 node.d.nsize);
687 printk(JFFS2_DBG_LVL "type:\t%#02x\n",
688 node.d.type);
689 printk(JFFS2_DBG_LVL "node_crc:\t%#08x\n",
690 je32_to_cpu(node.d.node_crc));
691 printk(JFFS2_DBG_LVL "name_crc:\t%#08x\n",
692 je32_to_cpu(node.d.name_crc));
693
694 node.d.name[node.d.nsize] = '\0';
695 printk(JFFS2_DBG_LVL "name:\t\"%s\"\n", node.d.name);
696
697 crc = crc32(0, &node.d, sizeof(node.d) - 8);
698 if (crc != je32_to_cpu(node.d.node_crc)) {
699 JFFS2_ERROR("wrong node header CRC.\n");
700 return;
490 } 701 }
702 break;
491 703
492 i += JFFS3_BUFDUMP_BYTES_PER_LINE; 704 default:
705 printk(JFFS2_DBG_LVL "node type is unknown\n");
706 break;
493 } 707 }
494} 708}
495#endif /* JFFS2_PARANOIA_CHECKS || CONFIG_JFFS2_FS_DEBUG > 0 */ 709#endif /* JFFS2_DBG_DUMPS || JFFS2_DBG_PARANOIA_CHECKS */
diff --git a/fs/jffs2/debug.h b/fs/jffs2/debug.h
index 7d14f7b01397..51ff099a6502 100644
--- a/fs/jffs2/debug.h
+++ b/fs/jffs2/debug.h
@@ -7,7 +7,7 @@
7 * 7 *
8 * For licensing information, see the file 'LICENCE' in this directory. 8 * For licensing information, see the file 'LICENCE' in this directory.
9 * 9 *
10 * $Id: debug.h,v 1.1 2005/07/17 06:56:20 dedekind Exp $ 10 * $Id: debug.h,v 1.5 2005/07/24 15:14:14 dedekind Exp $
11 * 11 *
12 */ 12 */
13#ifndef _JFFS2_DEBUG_H_ 13#ifndef _JFFS2_DEBUG_H_
@@ -15,12 +15,52 @@
15 15
16#include <linux/config.h> 16#include <linux/config.h>
17 17
18/* ------------------------------------------------ */
19/* TODO: remove */
20#undef CONFIG_JFFS2_FS_DEBUG
21#define CONFIG_JFFS2_FS_DEBUG 0
22//#define JFFS2_DBG_PARANOIA_CHECKS
23//#define JFFS2_DBG_DUMPS
24#define JFFS2_DBG_READINODE_MESSAGES
25//#define JFFS2_DBG_FRAGTREE_MESSAGES
26//#define JFFS2_DBG_FRAGTREE2_MESSAGES
27#undef KERN_DEBUG
28#undef KERN_WARNING
29#undef KERN_NOTICE
30#undef KERN_ERR
31#define KERN_DEBUG KERN_CRIT
32#define KERN_WARNING KERN_CRIT
33#define KERN_NOTICE KERN_CRIT
34#define KERN_ERR KERN_CRIT
35/* ------------------------------------------------ */
36
18#ifndef CONFIG_JFFS2_FS_DEBUG 37#ifndef CONFIG_JFFS2_FS_DEBUG
19#define CONFIG_JFFS2_FS_DEBUG 1 38#define CONFIG_JFFS2_FS_DEBUG 1
20#endif 39#endif
21 40
22#if CONFIG_JFFS2_FS_DEBUG > 0 41#if CONFIG_JFFS2_FS_DEBUG == 1
42/* Enable "paranoia" checks and dumps */
23#define JFFS2_DBG_PARANOIA_CHECKS 43#define JFFS2_DBG_PARANOIA_CHECKS
44#define JFFS2_DBG_DUMPS
45#define JFFS2_DBG_READINODE_MESSAGES
46#define JFFS2_DBG_FRAGTREE_MESSAGES
47#define JFFS2_DBG_DENTLIST_MESSAGES
48#define JFFS2_DBG_NODEREF_MESSAGES
49#define JFFS2_DBG_INOCACHE_MESSAGES
50#endif
51
52#if CONFIG_JFFS2_FS_DEBUG == 2
53#define JFFS2_DBG_FRAGTREE2_MESSAGES
54#endif
55
56/* Enable JFFS2 sanity checks by default */
57#define JFFS2_DBG_SANITY_CHECKS
58
59/*
60 * Dx() are mainly used for debugging messages, they must go away and be
61 * superseded by nicer JFFS2_DBG_XXX() macros...
62 */
63#if CONFIG_JFFS2_FS_DEBUG > 0
24#define D1(x) x 64#define D1(x) x
25#else 65#else
26#define D1(x) 66#define D1(x)
@@ -32,73 +72,216 @@
32#define D2(x) 72#define D2(x)
33#endif 73#endif
34 74
35/* Enable JFFS2 sanity checks */ 75/* The prefixes of JFFS2 messages */
36#define JFFS2_DBG_SANITY_CHECKS 76#define JFFS2_DBG_MSG_PREFIX "[JFFS2 DBG]"
77#define JFFS2_ERR_MSG_PREFIX "JFFS2 error: "
78#define JFFS2_WARN_MSG_PREFIX "JFFS2 warning: "
79#define JFFS2_NOTICE_MSG_PREFIX "JFFS2 notice: "
37 80
38#if CONFIG_JFFS2_FS_DEBUG > 0 81#define JFFS2_ERR_LVL KERN_ERR
39void 82#define JFFS2_WARN_LVL KERN_WARNING
40jffs2_dbg_dump_block_lists(struct jffs2_sb_info *c); 83#define JFFS2_NOTICE_LVL KERN_NOTICE
84#define JFFS2_DBG_LVL KERN_DEBUG
41 85
42void 86/* JFFS2 message macros */
43jffs2_dbg_dump_node_refs(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb); 87#define JFFS2_ERROR(fmt, ...) \
88 do { \
89 printk(JFFS2_ERR_LVL JFFS2_ERR_MSG_PREFIX " %s: " \
90 fmt, __FUNCTION__, ##__VA_ARGS__); \
91 } while(0)
44 92
45void 93#define JFFS2_WARNING(fmt, ...) \
46jffs2_dbg_dump_fragtree(struct jffs2_inode_info *f); 94 do { \
95 printk(JFFS2_WARN_LVL JFFS2_WARN_MSG_PREFIX " %s: " \
96 fmt, __FUNCTION__, ##__VA_ARGS__); \
97 } while(0)
98
99#define JFFS2_NOTICE(fmt, ...) \
100 do { \
101 printk(JFFS2_NOTICE_LVL JFFS2_NOTICE_MSG_PREFIX " %s: " \
102 fmt, __FUNCTION__, ##__VA_ARGS__); \
103 } while(0)
47 104
48void 105#define JFFS2_DEBUG(fmt, ...) \
49jffs2_dbg_dump_buffer(char *buf, int len, uint32_t offs); 106 do { \
107 printk(JFFS2_DBG_LVL JFFS2_DBG_MSG_PREFIX " %s: " \
108 fmt, __FUNCTION__, ##__VA_ARGS__); \
109 } while(0)
110
111/*
112 * We split our debugging messages on several parts, depending on the JFFS2
113 * subsystem the message belongs to.
114 */
115/* Read inode debugging messages */
116#ifdef JFFS2_DBG_READINODE_MESSAGES
117#define JFFS2_DBG_READINODE(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
118#else
119#define JFFS2_DBG_READINODE(fmt, ...)
50#endif 120#endif
51 121
52#ifdef JFFS2_DBG_PARANOIA_CHECKS 122/* Fragtree build debugging messages */
53void 123#ifdef JFFS2_DBG_FRAGTREE_MESSAGES
54jffs2_dbg_fragtree_paranoia_check(struct jffs2_inode_info *f); 124#define JFFS2_DBG_FRAGTREE(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
125#else
126#define JFFS2_DBG_FRAGTREE(fmt, ...)
127#endif
128
129/* Directory entry list manilulation debugging messages */
130#ifdef JFFS2_DBG_DENTLIST_MESSAGES
131#define JFFS2_DBG_DENTLIST(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
132#else
133#define JFFS2_DBG_DENTLIST(fmt, ...)
134#endif
135#ifdef JFFS2_DBG_FRAGTREE2_MESSAGES
136#define JFFS2_DBG_FRAGTREE2(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
137#else
138#define JFFS2_DBG_FRAGTREE2(fmt, ...)
139#endif
140
141/* Plays with node_refs */
142#ifdef JFFS2_DBG_NODEREF_MESSAGES
143#define JFFS2_DBG_NODEREF(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
144#else
145#define JFFS2_DBG_NODEREF(fmt, ...)
146#endif
55 147
148/* Plays with the list of inodes (JFFS2 inocache) */
149#ifdef JFFS2_DBG_INOCACHE_MESSAGES
150#define JFFS2_DBG_INOCACHE(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
151#else
152#define JFFS2_DBG_INOCACHE(fmt, ...)
153#endif
154
155/* "Paranoia" checks */
156void
157__jffs2_dbg_fragtree_paranoia_check(struct jffs2_inode_info *f);
56void 158void
57jffs2_dbg_acct_paranoia_check(struct jffs2_sb_info *c, 159__jffs2_dbg_fragtree_paranoia_check_nolock(struct jffs2_inode_info *f);
58 struct jffs2_eraseblock *jeb); 160void
161__jffs2_dbg_acct_paranoia_check(struct jffs2_sb_info *c,
162 struct jffs2_eraseblock *jeb);
163void
164__jffs2_dbg_acct_paranoia_check_nolock(struct jffs2_sb_info *c,
165 struct jffs2_eraseblock *jeb);
166void
167__jffs2_dbg_prewrite_paranoia_check(struct jffs2_sb_info *c,
168 uint32_t ofs, int len);
59 169
170/* "Dump" functions */
171void
172__jffs2_dbg_dump_jeb(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb);
173void
174__jffs2_dbg_dump_jeb_nolock(struct jffs2_eraseblock *jeb);
175void
176__jffs2_dbg_dump_block_lists(struct jffs2_sb_info *c);
177void
178__jffs2_dbg_dump_block_lists_nolock(struct jffs2_sb_info *c);
179void
180__jffs2_dbg_dump_node_refs(struct jffs2_sb_info *c,
181 struct jffs2_eraseblock *jeb);
182void
183__jffs2_dbg_dump_node_refs_nolock(struct jffs2_sb_info *c,
184 struct jffs2_eraseblock *jeb);
185void
186__jffs2_dbg_dump_fragtree(struct jffs2_inode_info *f);
187void
188__jffs2_dbg_dump_fragtree_nolock(struct jffs2_inode_info *f);
60void 189void
61jffs2_dbg_prewrite_paranoia_check(struct jffs2_sb_info *c, 190__jffs2_dbg_dump_buffer(unsigned char *buf, int len, uint32_t offs);
62 uint32_t ofs, int len); 191void
192__jffs2_dbg_dump_node(struct jffs2_sb_info *c, uint32_t ofs);
193
194#ifdef JFFS2_DBG_PARANOIA_CHECKS
195#define jffs2_dbg_fragtree_paranoia_check(f) \
196 __jffs2_dbg_fragtree_paranoia_check(f)
197#define jffs2_dbg_fragtree_paranoia_check_nolock(f) \
198 __jffs2_dbg_fragtree_paranoia_check_nolock(f)
199#define jffs2_dbg_acct_paranoia_check(c, jeb) \
200 __jffs2_dbg_acct_paranoia_check(c,jeb)
201#define jffs2_dbg_acct_paranoia_check_nolock(c, jeb) \
202 __jffs2_dbg_acct_paranoia_check_nolock(c,jeb)
203#define jffs2_dbg_prewrite_paranoia_check(c, ofs, len) \
204 __jffs2_dbg_prewrite_paranoia_check(c, ofs, len)
63#else 205#else
64#define jffs2_dbg_fragtree_paranoia_check(f) 206#define jffs2_dbg_fragtree_paranoia_check(f)
207#define jffs2_dbg_fragtree_paranoia_check_nolock(f)
65#define jffs2_dbg_acct_paranoia_check(c, jeb) 208#define jffs2_dbg_acct_paranoia_check(c, jeb)
209#define jffs2_dbg_acct_paranoia_check_nolock(c, jeb)
66#define jffs2_dbg_prewrite_paranoia_check(c, ofs, len) 210#define jffs2_dbg_prewrite_paranoia_check(c, ofs, len)
67#endif /* !JFFS2_PARANOIA_CHECKS */ 211#endif /* !JFFS2_PARANOIA_CHECKS */
68 212
213#ifdef JFFS2_DBG_DUMPS
214#define jffs2_dbg_dump_jeb(c, jeb) \
215 __jffs2_dbg_dump_jeb(c, jeb);
216#define jffs2_dbg_dump_jeb_nolock(jeb) \
217 __jffs2_dbg_dump_jeb_nolock(jeb);
218#define jffs2_dbg_dump_block_lists(c) \
219 __jffs2_dbg_dump_block_lists(c)
220#define jffs2_dbg_dump_block_lists_nolock(c) \
221 __jffs2_dbg_dump_block_lists_nolock(c)
222#define jffs2_dbg_dump_fragtree(f) \
223 __jffs2_dbg_dump_fragtree(f);
224#define jffs2_dbg_dump_fragtree_nolock(f) \
225 __jffs2_dbg_dump_fragtree_nolock(f);
226#define jffs2_dbg_dump_buffer(buf, len, offs) \
227 __jffs2_dbg_dump_buffer(*buf, len, offs);
228#define jffs2_dbg_dump_node(c, ofs) \
229 __jffs2_dbg_dump_node(c, ofs);
230#else
231#define jffs2_dbg_dump_jeb(c, jeb)
232#define jffs2_dbg_dump_jeb_nolock(jeb)
233#define jffs2_dbg_dump_block_lists(c)
234#define jffs2_dbg_dump_block_lists_nolock(c)
235#define jffs2_dbg_dump_fragtree(f)
236#define jffs2_dbg_dump_fragtree_nolock(f)
237#define jffs2_dbg_dump_buffer(buf, len, offs)
238#define jffs2_dbg_dump_node(c, ofs)
239#endif /* !JFFS2_DBG_DUMPS */
240
241/*
242 * Sanity checks are supposed to be light-weight and enabled by default.
243 */
69#ifdef JFFS2_DBG_SANITY_CHECKS 244#ifdef JFFS2_DBG_SANITY_CHECKS
70/* 245/*
71 * Check the space accounting of the file system and of 246 * Check the space accounting of the file system and of
72 * the JFFS3 erasable block 'jeb'. 247 * the JFFS2 erasable block 'jeb'.
73 */ 248 */
74static inline void 249static inline void
75jffs2_dbg_acct_sanity_check(struct jffs2_sb_info *c, 250jffs2_dbg_acct_sanity_check_nolock(struct jffs2_sb_info *c,
76 struct jffs2_eraseblock *jeb) 251 struct jffs2_eraseblock *jeb)
77{ 252{
78 if (unlikely(jeb && jeb->used_size + jeb->dirty_size + 253 if (unlikely(jeb && jeb->used_size + jeb->dirty_size +
79 jeb->free_size + jeb->wasted_size + 254 jeb->free_size + jeb->wasted_size +
80 jeb->unchecked_size != c->sector_size)) { 255 jeb->unchecked_size != c->sector_size)) {
81 printk(KERN_ERR "Eeep. Space accounting for block at 0x%08x is screwed\n", jeb->offset); 256 JFFS2_ERROR("eeep, space accounting for block at 0x%08x is screwed.\n", jeb->offset);
82 printk(KERN_ERR "free %#08x + dirty %#08x + used %#08x + wasted %#08x + unchecked " 257 JFFS2_ERROR("free %#08x + dirty %#08x + used %#08x + wasted %#08x + unchecked "
83 "%#08x != total %#08x\n", jeb->free_size, jeb->dirty_size, jeb->used_size, 258 "%#08x != total %#08x.\n", jeb->free_size, jeb->dirty_size, jeb->used_size,
84 jeb->wasted_size, jeb->unchecked_size, c->sector_size); 259 jeb->wasted_size, jeb->unchecked_size, c->sector_size);
85 BUG(); 260 BUG();
86 } 261 }
87 262
88 if (unlikely(c->used_size + c->dirty_size + c->free_size + c->erasing_size + c->bad_size 263 if (unlikely(c->used_size + c->dirty_size + c->free_size + c->erasing_size + c->bad_size
89 + c->wasted_size + c->unchecked_size != c->flash_size)) { 264 + c->wasted_size + c->unchecked_size != c->flash_size)) {
90 printk(KERN_ERR "Eeep. Space accounting superblock info is screwed\n"); 265 JFFS2_ERROR("eeep, space accounting superblock info is screwed.\n");
91 printk(KERN_ERR "free %#08x + dirty %#08x + used %#08x + erasing %#08x + bad %#08x + " 266 JFFS2_ERROR("free %#08x + dirty %#08x + used %#08x + erasing %#08x + bad %#08x + "
92 "wasted %#08x + unchecked %#08x != total %#08x\n", 267 "wasted %#08x + unchecked %#08x != total %#08x.\n",
93 c->free_size, c->dirty_size, c->used_size, c->erasing_size, c->bad_size, 268 c->free_size, c->dirty_size, c->used_size, c->erasing_size, c->bad_size,
94 c->wasted_size, c->unchecked_size, c->flash_size); 269 c->wasted_size, c->unchecked_size, c->flash_size);
95 BUG(); 270 BUG();
96 } 271 }
97} 272}
98#else 273
99static inline void 274static inline void
100jffs2_dbg_acct_sanity_check(struct jffs2_sb_info *c, 275jffs2_dbg_acct_sanity_check(struct jffs2_sb_info *c,
101 struct jffs2_eraseblock *jeb); 276 struct jffs2_eraseblock *jeb)
277{
278 spin_lock(&c->erase_completion_lock);
279 jffs2_dbg_acct_sanity_check_nolock(c, jeb);
280 spin_unlock(&c->erase_completion_lock);
281}
282#else
283#define jffs2_dbg_acct_sanity_check(c, jeb)
284#define jffs2_dbg_acct_sanity_check_nolock(c, jeb)
102#endif /* !JFFS2_DBG_SANITY_CHECKS */ 285#endif /* !JFFS2_DBG_SANITY_CHECKS */
103 286
104#endif /* _JFFS2_DEBUG_H_ */ 287#endif /* _JFFS2_DEBUG_H_ */
diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
index af0c7d431883..a8a0908142d9 100644
--- a/fs/jffs2/erase.c
+++ b/fs/jffs2/erase.c
@@ -7,7 +7,7 @@
7 * 7 *
8 * For licensing information, see the file 'LICENCE' in this directory. 8 * For licensing information, see the file 'LICENCE' in this directory.
9 * 9 *
10 * $Id: erase.c,v 1.81 2005/07/17 06:56:20 dedekind Exp $ 10 * $Id: erase.c,v 1.83 2005/07/22 10:32:08 dedekind Exp $
11 * 11 *
12 */ 12 */
13 13
@@ -48,7 +48,8 @@ static void jffs2_erase_block(struct jffs2_sb_info *c,
48#else /* Linux */ 48#else /* Linux */
49 struct erase_info *instr; 49 struct erase_info *instr;
50 50
51 D1(printk(KERN_DEBUG "jffs2_erase_block(): erase block %#x (range %#x-%#x)\n", jeb->offset, jeb->offset, jeb->offset + c->sector_size)); 51 D1(printk(KERN_DEBUG "jffs2_erase_block(): erase block %#08x (range %#08x-%#08x)\n",
52 jeb->offset, jeb->offset, jeb->offset + c->sector_size));
52 instr = kmalloc(sizeof(struct erase_info) + sizeof(struct erase_priv_struct), GFP_KERNEL); 53 instr = kmalloc(sizeof(struct erase_info) + sizeof(struct erase_priv_struct), GFP_KERNEL);
53 if (!instr) { 54 if (!instr) {
54 printk(KERN_WARNING "kmalloc for struct erase_info in jffs2_erase_block failed. Refiling block for later\n"); 55 printk(KERN_WARNING "kmalloc for struct erase_info in jffs2_erase_block failed. Refiling block for later\n");
@@ -429,8 +430,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
429 c->free_size += jeb->free_size; 430 c->free_size += jeb->free_size;
430 c->used_size += jeb->used_size; 431 c->used_size += jeb->used_size;
431 432
432 jffs2_dbg_acct_sanity_check(c,jeb); 433 jffs2_dbg_acct_sanity_check_nolock(c,jeb);
433 jffs2_dbg_acct_paranoia_check(c, jeb); 434 jffs2_dbg_acct_paranoia_check_nolock(c, jeb);
434 435
435 list_add_tail(&jeb->list, &c->free_list); 436 list_add_tail(&jeb->list, &c->free_list);
436 c->nr_erasing_blocks--; 437 c->nr_erasing_blocks--;
diff --git a/fs/jffs2/fs.c b/fs/jffs2/fs.c
index a6661e8be25a..34731614b57a 100644
--- a/fs/jffs2/fs.c
+++ b/fs/jffs2/fs.c
@@ -7,7 +7,7 @@
7 * 7 *
8 * For licensing information, see the file 'LICENCE' in this directory. 8 * For licensing information, see the file 'LICENCE' in this directory.
9 * 9 *
10 * $Id: fs.c,v 1.59 2005/07/18 11:21:19 dedekind Exp $ 10 * $Id: fs.c,v 1.60 2005/07/22 10:32:08 dedekind Exp $
11 * 11 *
12 */ 12 */
13 13
@@ -194,19 +194,15 @@ int jffs2_statfs(struct super_block *sb, struct kstatfs *buf)
194 buf->f_namelen = JFFS2_MAX_NAME_LEN; 194 buf->f_namelen = JFFS2_MAX_NAME_LEN;
195 195
196 spin_lock(&c->erase_completion_lock); 196 spin_lock(&c->erase_completion_lock);
197
198 avail = c->dirty_size + c->free_size; 197 avail = c->dirty_size + c->free_size;
199 if (avail > c->sector_size * c->resv_blocks_write) 198 if (avail > c->sector_size * c->resv_blocks_write)
200 avail -= c->sector_size * c->resv_blocks_write; 199 avail -= c->sector_size * c->resv_blocks_write;
201 else 200 else
202 avail = 0; 201 avail = 0;
202 spin_unlock(&c->erase_completion_lock);
203 203
204 buf->f_bavail = buf->f_bfree = avail >> PAGE_SHIFT; 204 buf->f_bavail = buf->f_bfree = avail >> PAGE_SHIFT;
205 205
206 jffs2_dbg_dump_block_lists(c);
207
208 spin_unlock(&c->erase_completion_lock);
209
210 return 0; 206 return 0;
211} 207}
212 208
diff --git a/fs/jffs2/gc.c b/fs/jffs2/gc.c
index 6b5da0a1d319..362cfeed7327 100644
--- a/fs/jffs2/gc.c
+++ b/fs/jffs2/gc.c
@@ -7,7 +7,7 @@
7 * 7 *
8 * For licensing information, see the file 'LICENCE' in this directory. 8 * For licensing information, see the file 'LICENCE' in this directory.
9 * 9 *
10 * $Id: gc.c,v 1.150 2005/07/17 12:01:43 dedekind Exp $ 10 * $Id: gc.c,v 1.152 2005/07/24 15:14:14 dedekind Exp $
11 * 11 *
12 */ 12 */
13 13
@@ -111,7 +111,6 @@ again:
111 ret->wasted_size = 0; 111 ret->wasted_size = 0;
112 } 112 }
113 113
114 jffs2_dbg_dump_block_lists(c);
115 return ret; 114 return ret;
116} 115}
117 116
@@ -142,7 +141,7 @@ int jffs2_garbage_collect_pass(struct jffs2_sb_info *c)
142 if (c->checked_ino > c->highest_ino) { 141 if (c->checked_ino > c->highest_ino) {
143 printk(KERN_CRIT "Checked all inodes but still 0x%x bytes of unchecked space?\n", 142 printk(KERN_CRIT "Checked all inodes but still 0x%x bytes of unchecked space?\n",
144 c->unchecked_size); 143 c->unchecked_size);
145 jffs2_dbg_dump_block_lists(c); 144 jffs2_dbg_dump_block_lists_nolock(c);
146 spin_unlock(&c->erase_completion_lock); 145 spin_unlock(&c->erase_completion_lock);
147 BUG(); 146 BUG();
148 } 147 }
@@ -485,7 +484,8 @@ static int jffs2_garbage_collect_live(struct jffs2_sb_info *c, struct jffs2_era
485 if (ref_obsolete(raw)) { 484 if (ref_obsolete(raw)) {
486 printk(KERN_WARNING "But it's obsolete so we don't mind too much\n"); 485 printk(KERN_WARNING "But it's obsolete so we don't mind too much\n");
487 } else { 486 } else {
488 ret = -EIO; 487 jffs2_dbg_dump_node(c, ref_offset(raw));
488 BUG();
489 } 489 }
490 } 490 }
491 upnout: 491 upnout:
diff --git a/fs/jffs2/nodelist.c b/fs/jffs2/nodelist.c
index a04111530f4d..9d08d3388186 100644
--- a/fs/jffs2/nodelist.c
+++ b/fs/jffs2/nodelist.c
@@ -7,7 +7,7 @@
7 * 7 *
8 * For licensing information, see the file 'LICENCE' in this directory. 8 * For licensing information, see the file 'LICENCE' in this directory.
9 * 9 *
10 * $Id: nodelist.c,v 1.99 2005/07/15 10:13:54 dedekind Exp $ 10 * $Id: nodelist.c,v 1.100 2005/07/22 10:32:08 dedekind Exp $
11 * 11 *
12 */ 12 */
13 13
@@ -203,7 +203,7 @@ read_direntry(struct jffs2_sb_info *c,
203 return -EIO; 203 return -EIO;
204 204
205 if (unlikely(err)) { 205 if (unlikely(err)) {
206 printk(KERN_WARNING "Read remainder of name in jffs2_get_inode_nodes(): error %d\n", err); 206 printk(KERN_WARNING "Read remainder of name: error %d\n", err);
207 jffs2_free_full_dirent(fd); 207 jffs2_free_full_dirent(fd);
208 return -EIO; 208 return -EIO;
209 } 209 }
diff --git a/fs/jffs2/nodelist.h b/fs/jffs2/nodelist.h
index 6802e0968d3e..dde9b86e43b5 100644
--- a/fs/jffs2/nodelist.h
+++ b/fs/jffs2/nodelist.h
@@ -7,7 +7,7 @@
7 * 7 *
8 * For licensing information, see the file 'LICENCE' in this directory. 8 * For licensing information, see the file 'LICENCE' in this directory.
9 * 9 *
10 * $Id: nodelist.h,v 1.132 2005/07/17 06:56:21 dedekind Exp $ 10 * $Id: nodelist.h,v 1.133 2005/07/22 10:32:08 dedekind Exp $
11 * 11 *
12 */ 12 */
13 13
@@ -236,7 +236,7 @@ static inline uint32_t ref_totlen(struct jffs2_sb_info *c,
236 ret, ref->__totlen); 236 ret, ref->__totlen);
237 if (!jeb) 237 if (!jeb)
238 jeb = &c->blocks[ref->flash_offset / c->sector_size]; 238 jeb = &c->blocks[ref->flash_offset / c->sector_size];
239 jffs2_dbg_dump_node_refs(c, jeb); 239 jffs2_dbg_dump_node_refs_nolock(c, jeb);
240 BUG(); 240 BUG();
241 } 241 }
242#endif 242#endif
diff --git a/fs/jffs2/nodemgmt.c b/fs/jffs2/nodemgmt.c
index 424be1e1ca92..fe7e70a4055b 100644
--- a/fs/jffs2/nodemgmt.c
+++ b/fs/jffs2/nodemgmt.c
@@ -7,7 +7,7 @@
7 * 7 *
8 * For licensing information, see the file 'LICENCE' in this directory. 8 * For licensing information, see the file 'LICENCE' in this directory.
9 * 9 *
10 * $Id: nodemgmt.c,v 1.123 2005/07/17 06:56:21 dedekind Exp $ 10 * $Id: nodemgmt.c,v 1.124 2005/07/20 15:32:28 dedekind Exp $
11 * 11 *
12 */ 12 */
13 13
@@ -349,8 +349,8 @@ int jffs2_add_physical_node_ref(struct jffs2_sb_info *c, struct jffs2_raw_node_r
349 list_add_tail(&jeb->list, &c->clean_list); 349 list_add_tail(&jeb->list, &c->clean_list);
350 c->nextblock = NULL; 350 c->nextblock = NULL;
351 } 351 }
352 jffs2_dbg_acct_sanity_check(c,jeb); 352 jffs2_dbg_acct_sanity_check_nolock(c,jeb);
353 jffs2_dbg_acct_paranoia_check(c, jeb); 353 jffs2_dbg_acct_paranoia_check_nolock(c, jeb);
354 354
355 spin_unlock(&c->erase_completion_lock); 355 spin_unlock(&c->erase_completion_lock);
356 356
@@ -430,7 +430,7 @@ void jffs2_mark_node_obsolete(struct jffs2_sb_info *c, struct jffs2_raw_node_ref
430 ref_totlen(c, jeb, ref), blocknr, ref->flash_offset, jeb->used_size); 430 ref_totlen(c, jeb, ref), blocknr, ref->flash_offset, jeb->used_size);
431 BUG(); 431 BUG();
432 }) 432 })
433 D1(printk(KERN_DEBUG "Obsoleting node at 0x%08x of len %x: ", ref_offset(ref), ref_totlen(c, jeb, ref))); 433 D1(printk(KERN_DEBUG "Obsoleting node at 0x%08x of len %#x: ", ref_offset(ref), ref_totlen(c, jeb, ref)));
434 jeb->used_size -= ref_totlen(c, jeb, ref); 434 jeb->used_size -= ref_totlen(c, jeb, ref);
435 c->used_size -= ref_totlen(c, jeb, ref); 435 c->used_size -= ref_totlen(c, jeb, ref);
436 } 436 }
@@ -466,9 +466,8 @@ void jffs2_mark_node_obsolete(struct jffs2_sb_info *c, struct jffs2_raw_node_ref
466 } 466 }
467 ref->flash_offset = ref_offset(ref) | REF_OBSOLETE; 467 ref->flash_offset = ref_offset(ref) | REF_OBSOLETE;
468 468
469 jffs2_dbg_acct_sanity_check(c, jeb); 469 jffs2_dbg_acct_sanity_check_nolock(c, jeb);
470 470 jffs2_dbg_acct_paranoia_check_nolock(c, jeb);
471 jffs2_dbg_acct_paranoia_check(c, jeb);
472 471
473 if (c->flags & JFFS2_SB_FLAG_SCANNING) { 472 if (c->flags & JFFS2_SB_FLAG_SCANNING) {
474 /* Flash scanning is in progress. Don't muck about with the block 473 /* Flash scanning is in progress. Don't muck about with the block
diff --git a/fs/jffs2/read.c b/fs/jffs2/read.c
index 9706534786ec..e38e6c5f143a 100644
--- a/fs/jffs2/read.c
+++ b/fs/jffs2/read.c
@@ -7,7 +7,7 @@
7 * 7 *
8 * For licensing information, see the file 'LICENCE' in this directory. 8 * For licensing information, see the file 'LICENCE' in this directory.
9 * 9 *
10 * $Id: read.c,v 1.40 2005/07/17 06:56:21 dedekind Exp $ 10 * $Id: read.c,v 1.41 2005/07/22 10:32:08 dedekind Exp $
11 * 11 *
12 */ 12 */
13 13
@@ -174,7 +174,6 @@ int jffs2_read_inode_range(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
174 if (frag) { 174 if (frag) {
175 D1(printk(KERN_NOTICE "Eep. Hole in ino #%u fraglist. frag->ofs = 0x%08x, offset = 0x%08x\n", f->inocache->ino, frag->ofs, offset)); 175 D1(printk(KERN_NOTICE "Eep. Hole in ino #%u fraglist. frag->ofs = 0x%08x, offset = 0x%08x\n", f->inocache->ino, frag->ofs, offset));
176 holesize = min(holesize, frag->ofs - offset); 176 holesize = min(holesize, frag->ofs - offset);
177 D2(jffs2_dbg_dump_fragtree(f));
178 } 177 }
179 D1(printk(KERN_DEBUG "Filling non-frag hole from %d-%d\n", offset, offset+holesize)); 178 D1(printk(KERN_DEBUG "Filling non-frag hole from %d-%d\n", offset, offset+holesize));
180 memset(buf, 0, holesize); 179 memset(buf, 0, holesize);
diff --git a/fs/jffs2/readinode.c b/fs/jffs2/readinode.c
index 02a20d7b4d5f..02b02c1146bf 100644
--- a/fs/jffs2/readinode.c
+++ b/fs/jffs2/readinode.c
@@ -7,7 +7,7 @@
7 * 7 *
8 * For licensing information, see the file 'LICENCE' in this directory. 8 * For licensing information, see the file 'LICENCE' in this directory.
9 * 9 *
10 * $Id: readinode.c,v 1.128 2005/07/17 12:01:43 dedekind Exp $ 10 * $Id: readinode.c,v 1.129 2005/07/22 10:32:08 dedekind Exp $
11 * 11 *
12 */ 12 */
13 13
@@ -92,8 +92,8 @@ int jffs2_add_full_dnode_to_inode(struct jffs2_sb_info *c, struct jffs2_inode_in
92 mark_ref_normal(next->node->raw); 92 mark_ref_normal(next->node->raw);
93 } 93 }
94 } 94 }
95 jffs2_dbg_fragtree_paranoia_check(f); 95 jffs2_dbg_fragtree_paranoia_check_nolock(f);
96 jffs2_dbg_dump_fragtree(f); 96 jffs2_dbg_dump_fragtree_nolock(f);
97 return 0; 97 return 0;
98} 98}
99 99
@@ -480,7 +480,7 @@ static int jffs2_do_read_inode_internal(struct jffs2_sb_info *c,
480 480
481 jffs2_free_tmp_dnode_info(tn); 481 jffs2_free_tmp_dnode_info(tn);
482 } 482 }
483 jffs2_dbg_fragtree_paranoia_check(f); 483 jffs2_dbg_fragtree_paranoia_check_nolock(f);
484 484
485 if (!fn) { 485 if (!fn) {
486 /* No data nodes for this inode. */ 486 /* No data nodes for this inode. */
diff --git a/fs/jffs2/scan.c b/fs/jffs2/scan.c
index a2a51b7c2fd9..fcd6314cf179 100644
--- a/fs/jffs2/scan.c
+++ b/fs/jffs2/scan.c
@@ -7,7 +7,7 @@
7 * 7 *
8 * For licensing information, see the file 'LICENCE' in this directory. 8 * For licensing information, see the file 'LICENCE' in this directory.
9 * 9 *
10 * $Id: scan.c,v 1.120 2005/07/17 06:56:21 dedekind Exp $ 10 * $Id: scan.c,v 1.121 2005/07/20 15:32:28 dedekind Exp $
11 * 11 *
12 */ 12 */
13#include <linux/kernel.h> 13#include <linux/kernel.h>
@@ -130,7 +130,7 @@ int jffs2_scan_medium(struct jffs2_sb_info *c)
130 if (ret < 0) 130 if (ret < 0)
131 goto out; 131 goto out;
132 132
133 jffs2_dbg_acct_paranoia_check(c, jeb); 133 jffs2_dbg_acct_paranoia_check_nolock(c, jeb);
134 134
135 /* Now decide which list to put it on */ 135 /* Now decide which list to put it on */
136 switch(ret) { 136 switch(ret) {
@@ -370,7 +370,7 @@ static int jffs2_scan_eraseblock (struct jffs2_sb_info *c, struct jffs2_eraseblo
370scan_more: 370scan_more:
371 while(ofs < jeb->offset + c->sector_size) { 371 while(ofs < jeb->offset + c->sector_size) {
372 372
373 jffs2_dbg_acct_paranoia_check(c, jeb); 373 jffs2_dbg_acct_paranoia_check_nolock(c, jeb);
374 374
375 cond_resched(); 375 cond_resched();
376 376
diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
index 5a820f4ea358..251ac3d86f99 100644
--- a/fs/jffs2/wbuf.c
+++ b/fs/jffs2/wbuf.c
@@ -9,7 +9,7 @@
9 * 9 *
10 * For licensing information, see the file 'LICENCE' in this directory. 10 * For licensing information, see the file 'LICENCE' in this directory.
11 * 11 *
12 * $Id: wbuf.c,v 1.94 2005/07/17 12:01:43 dedekind Exp $ 12 * $Id: wbuf.c,v 1.96 2005/07/22 10:32:08 dedekind Exp $
13 * 13 *
14 */ 14 */
15 15
@@ -139,7 +139,6 @@ static void jffs2_block_refile(struct jffs2_sb_info *c, struct jffs2_eraseblock
139{ 139{
140 D1(printk("About to refile bad block at %08x\n", jeb->offset)); 140 D1(printk("About to refile bad block at %08x\n", jeb->offset));
141 141
142 jffs2_dbg_dump_block_lists(c);
143 /* File the existing block on the bad_used_list.... */ 142 /* File the existing block on the bad_used_list.... */
144 if (c->nextblock == jeb) 143 if (c->nextblock == jeb)
145 c->nextblock = NULL; 144 c->nextblock = NULL;
@@ -156,7 +155,6 @@ static void jffs2_block_refile(struct jffs2_sb_info *c, struct jffs2_eraseblock
156 c->nr_erasing_blocks++; 155 c->nr_erasing_blocks++;
157 jffs2_erase_pending_trigger(c); 156 jffs2_erase_pending_trigger(c);
158 } 157 }
159 jffs2_dbg_dump_block_lists(c);
160 158
161 /* Adjust its size counts accordingly */ 159 /* Adjust its size counts accordingly */
162 c->wasted_size += jeb->free_size; 160 c->wasted_size += jeb->free_size;
@@ -164,8 +162,9 @@ static void jffs2_block_refile(struct jffs2_sb_info *c, struct jffs2_eraseblock
164 jeb->wasted_size += jeb->free_size; 162 jeb->wasted_size += jeb->free_size;
165 jeb->free_size = 0; 163 jeb->free_size = 0;
166 164
167 jffs2_dbg_acct_sanity_check(c,jeb); 165 jffs2_dbg_dump_block_lists_nolock(c);
168 jffs2_dbg_acct_paranoia_check(c, jeb); 166 jffs2_dbg_acct_sanity_check_nolock(c,jeb);
167 jffs2_dbg_acct_paranoia_check_nolock(c, jeb);
169} 168}
170 169
171/* Recover from failure to write wbuf. Recover the nodes up to the 170/* Recover from failure to write wbuf. Recover the nodes up to the
@@ -392,11 +391,11 @@ static void jffs2_wbuf_recover(struct jffs2_sb_info *c)
392 else 391 else
393 jeb->last_node = container_of(first_raw, struct jffs2_raw_node_ref, next_phys); 392 jeb->last_node = container_of(first_raw, struct jffs2_raw_node_ref, next_phys);
394 393
395 jffs2_dbg_acct_sanity_check(c,jeb); 394 jffs2_dbg_acct_sanity_check_nolock(c, jeb);
396 jffs2_dbg_acct_paranoia_check(c, jeb); 395 jffs2_dbg_acct_paranoia_check_nolock(c, jeb);
397 396
398 jffs2_dbg_acct_sanity_check(c,new_jeb); 397 jffs2_dbg_acct_sanity_check_nolock(c, new_jeb);
399 jffs2_dbg_acct_paranoia_check(c, new_jeb); 398 jffs2_dbg_acct_paranoia_check_nolock(c, new_jeb);
400 399
401 spin_unlock(&c->erase_completion_lock); 400 spin_unlock(&c->erase_completion_lock);
402 401
diff --git a/fs/jffs2/write.c b/fs/jffs2/write.c
index b6a53e5aaa00..4c418e69cfc6 100644
--- a/fs/jffs2/write.c
+++ b/fs/jffs2/write.c
@@ -7,7 +7,7 @@
7 * 7 *
8 * For licensing information, see the file 'LICENCE' in this directory. 8 * For licensing information, see the file 'LICENCE' in this directory.
9 * 9 *
10 * $Id: write.c,v 1.93 2005/07/17 06:56:21 dedekind Exp $ 10 * $Id: write.c,v 1.94 2005/07/20 15:50:51 dedekind Exp $
11 * 11 *
12 */ 12 */
13 13
@@ -223,8 +223,6 @@ struct jffs2_full_dirent *jffs2_write_dirent(struct jffs2_sb_info *c, struct jff
223 je32_to_cpu(rd->pino), name, name, je32_to_cpu(rd->ino), 223 je32_to_cpu(rd->pino), name, name, je32_to_cpu(rd->ino),
224 je32_to_cpu(rd->name_crc))); 224 je32_to_cpu(rd->name_crc)));
225 225
226 jffs2_dbg_prewrite_paranoia_check(c, flash_ofs, vecs[0].iov_len + vecs[1].iov_len);
227
228 D1(if(je32_to_cpu(rd->hdr_crc) != crc32(0, rd, sizeof(struct jffs2_unknown_node)-4)) { 226 D1(if(je32_to_cpu(rd->hdr_crc) != crc32(0, rd, sizeof(struct jffs2_unknown_node)-4)) {
229 printk(KERN_CRIT "Eep. CRC not correct in jffs2_write_dirent()\n"); 227 printk(KERN_CRIT "Eep. CRC not correct in jffs2_write_dirent()\n");
230 BUG(); 228 BUG();
@@ -236,6 +234,8 @@ struct jffs2_full_dirent *jffs2_write_dirent(struct jffs2_sb_info *c, struct jff
236 vecs[1].iov_base = (unsigned char *)name; 234 vecs[1].iov_base = (unsigned char *)name;
237 vecs[1].iov_len = namelen; 235 vecs[1].iov_len = namelen;
238 236
237 jffs2_dbg_prewrite_paranoia_check(c, flash_ofs, vecs[0].iov_len + vecs[1].iov_len);
238
239 raw = jffs2_alloc_raw_node_ref(); 239 raw = jffs2_alloc_raw_node_ref();
240 240
241 if (!raw) 241 if (!raw)