embox

Форк
0
/
debug.c 
696 строк · 20.2 Кб
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.c,v 1.1 2005/07/30 15:30:42 asl Exp $
11
 *
12
 */
13
#include <linux/kernel.h>
14
#include <linux/types.h>
15
#include <linux/pagemap.h>
16
#include <linux/crc32.h>
17
#include <fs/jffs2.h>
18
#include "nodelist.h"
19
#include "debug.h"
20

21
#ifdef JFFS2_DBG_PARANOIA_CHECKS
22
/*
23
 * Check the fragtree.
24
 */
25
void __jffs2_dbg_fragtree_paranoia_check(struct jffs2_inode_info *f) {
26
	down(&f->sem);
27
	__jffs2_dbg_fragtree_paranoia_check_nolock(f);
28
	up(&f->sem);
29
}
30

31
void __jffs2_dbg_fragtree_paranoia_check_nolock(struct jffs2_inode_info *f) {
32
	struct jffs2_node_frag *frag;
33
	int bitched = 0;
34

35
	for (frag = frag_first(&f->fragtree); frag; frag = frag_next(frag)) {
36
		struct jffs2_full_dnode *fn = frag->node;
37

38
		if (!fn || !fn->raw) {
39
			continue;
40
		}
41

42
		if (ref_flags(fn->raw) == REF_PRISTINE) {
43
			if (fn->frags > 1) {
44
				JFFS2_ERROR("REF_PRISTINE node at 0x%08x had %d frags. Tell dwmw2.\n",
45
						ref_offset(fn->raw), fn->frags);
46
				bitched = 1;
47
			}
48

49
			/* A hole node which isn't multi-page should be garbage-collected
50
			 * and merged anyway, so we just check for the frag size here,
51
			 * rather than mucking around with actually reading the node
52
			 * and checking the compression type, which is the real way
53
			 * to tell a hole node.
54
			 */
55
			if (frag->ofs & (PAGE_CACHE_SIZE-1) && frag_prev(frag)
56
					&& frag_prev(frag)->size < PAGE_CACHE_SIZE
57
					&& frag_prev(frag)->node) {
58
				JFFS2_ERROR("REF_PRISTINE node at 0x%08x had a previous non-hole frag "
59
						"in the same page. Tell dwmw2.\n", ref_offset(fn->raw));
60
				bitched = 1;
61
			}
62

63
			if ((frag->ofs+frag->size) & (PAGE_CACHE_SIZE-1) && frag_next(frag)
64
					&& frag_next(frag)->size < PAGE_CACHE_SIZE
65
					&& frag_next(frag)->node) {
66
				JFFS2_ERROR("REF_PRISTINE node at 0x%08x (%08x-%08x) had a following "
67
						"non-hole frag in the same page. Tell dwmw2.\n",
68
					       ref_offset(fn->raw), frag->ofs, frag->ofs+frag->size);
69
				bitched = 1;
70
			}
71
		}
72
	}
73

74
	if (bitched) {
75
		JFFS2_ERROR("fragtree is corrupted.\n");
76
		__jffs2_dbg_dump_fragtree_nolock(f);
77
		BUG();
78
	}
79
}
80

81
/*
82
 * Check if the flash contains all 0xFF before we start writing.
83
 */
84
void __jffs2_dbg_prewrite_paranoia_check(struct jffs2_sb_info *c,
85
				    uint32_t ofs, int len) {
86
	size_t retlen;
87
	int ret, i;
88
	unsigned char *buf;
89

90
	buf = sysmalloc(len);
91
	if (!buf) {
92
		return;
93
	}
94

95
	ret = jffs2_flash_read(c, ofs, len, &retlen, buf);
96
	if (ret || (retlen != len)) {
97
		JFFS2_WARNING("read %d bytes failed or short. ret %d, retlen %zd.\n",
98
				len, ret, retlen);
99
		sysfree(buf);
100
		return;
101
	}
102

103
	ret = 0;
104
	for (i = 0; i < len; i++) {
105
		if (buf[i] != 0xff) {
106
			ret = 1;
107
		}
108
	}
109
	if (ret) {
110
		JFFS2_ERROR("argh, about to write node to %#08x on flash, but there are data "
111
			"already there. The first corrupted byte is at %#08x offset.\n", ofs, ofs + i);
112
		__jffs2_dbg_dump_buffer(buf, len, ofs);
113
		sysfree(buf);
114
		BUG();
115
	}
116

117
	free(buf);
118
}
119

120
/*
121
 * Check the space accounting and node_ref list correctness for the JFFS2 erasable block 'jeb'.
122
 */
123
void __jffs2_dbg_acct_paranoia_check(struct jffs2_sb_info *c,
124
				struct jffs2_eraseblock *jeb) {
125
	spin_lock(&c->erase_completion_lock);
126
	__jffs2_dbg_acct_paranoia_check_nolock(c, jeb);
127
	spin_unlock(&c->erase_completion_lock);
128
}
129

130
void __jffs2_dbg_acct_paranoia_check_nolock(struct jffs2_sb_info *c,
131
				       struct jffs2_eraseblock *jeb) {
132
	uint32_t my_used_size = 0;
133
	uint32_t my_unchecked_size = 0;
134
	uint32_t my_dirty_size = 0;
135
	struct jffs2_raw_node_ref *ref2 = jeb->first_node;
136

137
	while (ref2) {
138
		uint32_t totlen = ref_totlen(c, jeb, ref2);
139

140
		if (ref2->flash_offset < jeb->offset ||
141
				ref2->flash_offset > jeb->offset + c->sector_size) {
142
			JFFS2_ERROR("node_ref %#08x shouldn't be in block at %#08x.\n",
143
				ref_offset(ref2), jeb->offset);
144
			goto error;
145

146
		}
147
		if (ref_flags(ref2) == REF_UNCHECKED) {
148
			my_unchecked_size += totlen;
149
		} else if (!ref_obsolete(ref2)) {
150
			my_used_size += totlen;
151
		} else {
152
			my_dirty_size += totlen;
153
		}
154

155
		if ((!ref2->next_phys) != (ref2 == jeb->last_node)) {
156
			JFFS2_ERROR("node_ref for node at %#08x (mem %p) has next_phys at %#08x (mem %p), "
157
				"last_node is at %#08x (mem %p).\n",
158
				ref_offset(ref2), ref2, ref_offset(ref2->next_phys), ref2->next_phys,
159
				ref_offset(jeb->last_node), jeb->last_node);
160
			goto error;
161
		}
162
		ref2 = ref2->next_phys;
163
	}
164

165
	if (my_used_size != jeb->used_size) {
166
		JFFS2_ERROR("Calculated used size %#08x != stored used size %#08x.\n",
167
			my_used_size, jeb->used_size);
168
		goto error;
169
	}
170

171
	if (my_unchecked_size != jeb->unchecked_size) {
172
		JFFS2_ERROR("Calculated unchecked size %#08x != stored unchecked size %#08x.\n",
173
			my_unchecked_size, jeb->unchecked_size);
174
		goto error;
175
	}
176

177
	return;
178

179
error:
180
	__jffs2_dbg_dump_node_refs_nolock(c, jeb);
181
	__jffs2_dbg_dump_jeb_nolock(jeb);
182
	__jffs2_dbg_dump_block_lists_nolock(c);
183
	BUG();
184

185
}
186
#endif /* JFFS2_DBG_PARANOIA_CHECKS */
187

188
#if defined(JFFS2_DBG_DUMPS) || defined(JFFS2_DBG_PARANOIA_CHECKS)
189
/*
190
 * Dump the node_refs of the 'jeb' JFFS2 eraseblock.
191
 */
192
void __jffs2_dbg_dump_node_refs(struct jffs2_sb_info *c,
193
			   struct jffs2_eraseblock *jeb) {
194
	spin_lock(&c->erase_completion_lock);
195
	__jffs2_dbg_dump_node_refs_nolock(c, jeb);
196
	spin_unlock(&c->erase_completion_lock);
197
}
198

199
void __jffs2_dbg_dump_node_refs_nolock(struct jffs2_sb_info *c,
200
				  struct jffs2_eraseblock *jeb) {
201
	struct jffs2_raw_node_ref *ref;
202
	int i = 0;
203

204
	JFFS2_DEBUG("Dump node_refs of the eraseblock %#08x\n", jeb->offset);
205
	if (!jeb->first_node) {
206
		JFFS2_DEBUG("no nodes in the eraseblock %#08x\n", jeb->offset);
207
		return;
208
	}
209

210
	for (ref = jeb->first_node; ; ref = ref->next_phys) {
211
		printk("%#08x(%#x)", ref_offset(ref), ref->__totlen);
212
		if (ref->next_phys) {
213
			printk("->");
214
		} else {
215
			break;
216
		}
217
		if (++i == 4) {
218
			i = 0;
219
		}
220
	}
221
	printk("\n");
222
}
223

224
/*
225
 * Dump an eraseblock's space accounting.
226
 */
227
void __jffs2_dbg_dump_jeb(struct jffs2_sb_info *c,
228
		struct jffs2_eraseblock *jeb) {
229
	spin_lock(&c->erase_completion_lock);
230
	__jffs2_dbg_dump_jeb_nolock(jeb);
231
	spin_unlock(&c->erase_completion_lock);
232
}
233

234
void __jffs2_dbg_dump_jeb_nolock(struct jffs2_eraseblock *jeb) {
235
	if (!jeb) {
236
		return;
237
	}
238

239
	JFFS2_DEBUG("dump space accounting for the eraseblock at %#08x:\n",
240
			jeb->offset);
241

242
	printk(JFFS2_DBG_LVL "used_size: %#08x\n",	jeb->used_size);
243
	printk(JFFS2_DBG_LVL "dirty_size: %#08x\n",	jeb->dirty_size);
244
	printk(JFFS2_DBG_LVL "wasted_size: %#08x\n",	jeb->wasted_size);
245
	printk(JFFS2_DBG_LVL "unchecked_size: %#08x\n",	jeb->unchecked_size);
246
	printk(JFFS2_DBG_LVL "free_size: %#08x\n",	jeb->free_size);
247
}
248

249
void  __jffs2_dbg_dump_block_lists(struct jffs2_sb_info *c) {
250
	spin_lock(&c->erase_completion_lock);
251
	__jffs2_dbg_dump_block_lists_nolock(c);
252
	spin_unlock(&c->erase_completion_lock);
253
}
254

255
void __jffs2_dbg_dump_block_lists_nolock(struct jffs2_sb_info *c) {
256
	JFFS2_DEBUG("dump JFFS2 blocks lists:\n");
257

258
	printk(JFFS2_DBG_LVL "flash_size: %#08x\n",	c->flash_size);
259
	printk(JFFS2_DBG_LVL "used_size: %#08x\n",	c->used_size);
260
	printk(JFFS2_DBG_LVL "dirty_size: %#08x\n",	c->dirty_size);
261
	printk(JFFS2_DBG_LVL "wasted_size: %#08x\n",	c->wasted_size);
262
	printk(JFFS2_DBG_LVL "unchecked_size: %#08x\n",	c->unchecked_size);
263
	printk(JFFS2_DBG_LVL "free_size: %#08x\n",	c->free_size);
264
	printk(JFFS2_DBG_LVL "erasing_size: %#08x\n",	c->erasing_size);
265
	printk(JFFS2_DBG_LVL "bad_size: %#08x\n",	c->bad_size);
266
	printk(JFFS2_DBG_LVL "sector_size: %#08x\n",	c->sector_size);
267
	printk(JFFS2_DBG_LVL "jffs2_reserved_blocks size: %#08x\n",
268
				c->sector_size * c->resv_blocks_write);
269

270
	if (c->nextblock) {
271
		printk(JFFS2_DBG_LVL "nextblock: %#08x (used %#08x, dirty %#08x, wasted %#08x, "
272
			"unchecked %#08x, free %#08x)\n",
273
			c->nextblock->offset, c->nextblock->used_size,
274
			c->nextblock->dirty_size, c->nextblock->wasted_size,
275
			c->nextblock->unchecked_size, c->nextblock->free_size);
276
	} else {
277
		printk(JFFS2_DBG_LVL "nextblock: NULL\n");
278
	}
279

280
	if (c->gcblock) {
281
		printk(JFFS2_DBG_LVL "gcblock: %#08x (used %#08x, dirty %#08x, wasted %#08x, "
282
			"unchecked %#08x, free %#08x)\n",
283
			c->gcblock->offset, c->gcblock->used_size, c->gcblock->dirty_size,
284
			c->gcblock->wasted_size, c->gcblock->unchecked_size, c->gcblock->free_size);
285
	} else {
286
		printk(JFFS2_DBG_LVL "gcblock: NULL\n");
287
	}
288
	if (list_empty(&c->clean_list)) {
289
		printk(JFFS2_DBG_LVL "clean_list: empty\n");
290
	} else {
291
		struct list_head *this;
292
		int numblocks = 0;
293
		uint32_t dirty = 0;
294

295
		list_for_each(this, &c->clean_list) {
296
			struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list);
297
			numblocks ++;
298
			dirty += jeb->wasted_size;
299
			if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) {
300
				printk(JFFS2_DBG_LVL "clean_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, "
301
					"unchecked %#08x, free %#08x)\n",
302
					jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size,
303
					jeb->unchecked_size, jeb->free_size);
304
			}
305
		}
306

307
		printk (JFFS2_DBG_LVL "Contains %d blocks with total wasted size %u, average wasted size: %u\n",
308
			numblocks, dirty, dirty / numblocks);
309
	}
310

311
	if (list_empty(&c->very_dirty_list)) {
312
		printk(JFFS2_DBG_LVL "very_dirty_list: empty\n");
313
	} else {
314
		struct list_head *this;
315
		int numblocks = 0;
316
		uint32_t dirty = 0;
317

318
		list_for_each(this, &c->very_dirty_list) {
319
			struct jffs2_eraseblock *jeb =
320
					list_entry(this, struct jffs2_eraseblock, list);
321

322
			numblocks ++;
323
			dirty += jeb->dirty_size;
324
			if (!(jeb->used_size == 0
325
					&& jeb->dirty_size == 0
326
					&& jeb->wasted_size == 0)) {
327
				printk(JFFS2_DBG_LVL "very_dirty_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, "
328
					"unchecked %#08x, free %#08x)\n",
329
					jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size,
330
					jeb->unchecked_size, jeb->free_size);
331
			}
332
		}
333

334
		printk (JFFS2_DBG_LVL "Contains %d blocks with total dirty size %u, average dirty size: %u\n",
335
			numblocks, dirty, dirty / numblocks);
336
	}
337

338
	if (list_empty(&c->dirty_list)) {
339
		printk(JFFS2_DBG_LVL "dirty_list: empty\n");
340
	} else {
341
		struct list_head *this;
342
		int numblocks = 0;
343
		uint32_t dirty = 0;
344

345
		list_for_each(this, &c->dirty_list) {
346
			struct jffs2_eraseblock *jeb = list_entry(this,
347
					struct jffs2_eraseblock, list);
348

349
			numblocks ++;
350
			dirty += jeb->dirty_size;
351
			if (!(jeb->used_size == 0 &&
352
					jeb->dirty_size == 0 && jeb->wasted_size == 0)) {
353
				printk(JFFS2_DBG_LVL "dirty_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, "
354
					"unchecked %#08x, free %#08x)\n",
355
					jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size,
356
					jeb->unchecked_size, jeb->free_size);
357
			}
358
		}
359

360
		printk (JFFS2_DBG_LVL "contains %d blocks with total dirty size %u, average dirty size: %u\n",
361
			numblocks, dirty, dirty / numblocks);
362
	}
363

364
	if (list_empty(&c->erasable_list)) {
365
		printk(JFFS2_DBG_LVL "erasable_list: empty\n");
366
	} else {
367
		struct list_head *this;
368

369
		list_for_each(this, &c->erasable_list) {
370
			struct jffs2_eraseblock *jeb = list_entry(this,
371
					struct jffs2_eraseblock, list);
372

373
			if (!(jeb->used_size == 0 &&
374
					jeb->dirty_size == 0 && jeb->wasted_size == 0)) {
375
				printk(JFFS2_DBG_LVL "erasable_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, "
376
					"unchecked %#08x, free %#08x)\n",
377
					jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size,
378
					jeb->unchecked_size, jeb->free_size);
379
			}
380
		}
381
	}
382

383
	if (list_empty(&c->erasing_list)) {
384
		printk(JFFS2_DBG_LVL "erasing_list: empty\n");
385
	} else {
386
		struct list_head *this;
387

388
		list_for_each(this, &c->erasing_list) {
389
			struct jffs2_eraseblock *jeb = list_entry(this,
390
					struct jffs2_eraseblock, list);
391

392
			if (!(jeb->used_size == 0 &&
393
					jeb->dirty_size == 0 && jeb->wasted_size == 0)) {
394
				printk(JFFS2_DBG_LVL "erasing_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, "
395
					"unchecked %#08x, free %#08x)\n",
396
					jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size,
397
					jeb->unchecked_size, jeb->free_size);
398
			}
399
		}
400
	}
401

402
	if (list_empty(&c->erase_pending_list)) {
403
		printk(JFFS2_DBG_LVL "erase_pending_list: empty\n");
404
	} else {
405
		struct list_head *this;
406

407
		list_for_each(this, &c->erase_pending_list) {
408
			struct jffs2_eraseblock *jeb = list_entry(this,
409
					struct jffs2_eraseblock, list);
410

411
			if (!(jeb->used_size == 0 &&
412
					jeb->dirty_size == 0 && jeb->wasted_size == 0)) {
413
				printk(JFFS2_DBG_LVL "erase_pending_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, "
414
					"unchecked %#08x, free %#08x)\n",
415
					jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size,
416
					jeb->unchecked_size, jeb->free_size);
417
			}
418
		}
419
	}
420

421
	if (list_empty(&c->erasable_pending_wbuf_list)) {
422
		printk(JFFS2_DBG_LVL "erasable_pending_wbuf_list: empty\n");
423
	} else {
424
		struct list_head *this;
425

426
		list_for_each(this, &c->erasable_pending_wbuf_list) {
427
			struct jffs2_eraseblock *jeb = list_entry(this,
428
					struct jffs2_eraseblock, list);
429

430
			if (!(jeb->used_size == 0 &&
431
					jeb->dirty_size == 0 && jeb->wasted_size == 0)) {
432
				printk(JFFS2_DBG_LVL "erasable_pending_wbuf_list: %#08x (used %#08x, dirty %#08x, "
433
					"wasted %#08x, unchecked %#08x, free %#08x)\n",
434
					jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size,
435
					jeb->unchecked_size, jeb->free_size);
436
			}
437
		}
438
	}
439

440
	if (list_empty(&c->free_list)) {
441
		printk(JFFS2_DBG_LVL "free_list: empty\n");
442
	} else {
443
		struct list_head *this;
444

445
		list_for_each(this, &c->free_list) {
446
			struct jffs2_eraseblock *jeb = list_entry(this,
447
					struct jffs2_eraseblock, list);
448

449
			if (!(jeb->used_size == 0 &&
450
					jeb->dirty_size == 0 && jeb->wasted_size == 0)) {
451
				printk(JFFS2_DBG_LVL "free_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, "
452
					"unchecked %#08x, free %#08x)\n",
453
					jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size,
454
					jeb->unchecked_size, jeb->free_size);
455
			}
456
		}
457
	}
458

459
	if (list_empty(&c->bad_list)) {
460
		printk(JFFS2_DBG_LVL "bad_list: empty\n");
461
	} else {
462
		struct list_head *this;
463

464
		list_for_each(this, &c->bad_list) {
465
			struct jffs2_eraseblock *jeb = list_entry(this,
466
					struct jffs2_eraseblock, list);
467

468
			if (!(jeb->used_size == 0 &&
469
					jeb->dirty_size == 0 && jeb->wasted_size == 0)) {
470
				printk(JFFS2_DBG_LVL "bad_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, "
471
					"unchecked %#08x, free %#08x)\n",
472
					jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size,
473
					jeb->unchecked_size, jeb->free_size);
474
			}
475
		}
476
	}
477

478
	if (list_empty(&c->bad_used_list)) {
479
		printk(JFFS2_DBG_LVL "bad_used_list: empty\n");
480
	} else {
481
		struct list_head *this;
482

483
		list_for_each(this, &c->bad_used_list) {
484
			struct jffs2_eraseblock *jeb = list_entry(this,
485
					struct jffs2_eraseblock, list);
486

487
			if (!(jeb->used_size == 0 &&
488
					jeb->dirty_size == 0 && jeb->wasted_size == 0)) {
489
				printk(JFFS2_DBG_LVL "bad_used_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, "
490
					"unchecked %#08x, free %#08x)\n",
491
					jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size,
492
					jeb->unchecked_size, jeb->free_size);
493
			}
494
		}
495
	}
496
}
497

498
void __jffs2_dbg_dump_fragtree(struct jffs2_inode_info *f) {
499
	down(&f->sem);
500
	jffs2_dbg_dump_fragtree_nolock(f);
501
	up(&f->sem);
502
}
503

504
void __jffs2_dbg_dump_fragtree_nolock(struct jffs2_inode_info *f) {
505
	struct jffs2_node_frag *this = frag_first(&f->fragtree);
506
	uint32_t lastofs = 0;
507
	int buggy = 0;
508

509
	JFFS2_DEBUG("dump fragtree of ino #%u\n", f->inocache->ino);
510
	while(this) {
511
		if (this->node) {
512
			printk(JFFS2_DBG_LVL "frag %#04x-%#04x: %#08x(%d) on flash (*%p), left (%p), "
513
				"right (%p), parent (%p)\n",
514
				this->ofs, this->ofs+this->size, ref_offset(this->node->raw),
515
				ref_flags(this->node->raw), this, frag_left(this), frag_right(this),
516
				frag_parent(this));
517
		} else {
518
			printk(JFFS2_DBG_LVL "frag %#04x-%#04x: hole (*%p). left (%p), right (%p), parent (%p)\n",
519
				this->ofs, this->ofs+this->size, this, frag_left(this),
520
				frag_right(this), frag_parent(this));
521
		}
522
		if (this->ofs != lastofs) {
523
			buggy = 1;
524
		}
525
		lastofs = this->ofs + this->size;
526
		this = frag_next(this);
527
	}
528

529
	if (f->metadata) {
530
		printk(JFFS2_DBG_LVL "metadata at 0x%08x\n", ref_offset(f->metadata->raw));
531
	}
532
	if (buggy) {
533
		JFFS2_ERROR("frag tree got a hole in it.\n");
534
		BUG();
535
	}
536
}
537

538
#define JFFS2_BUFDUMP_BYTES_PER_LINE	32
539
void __jffs2_dbg_dump_buffer(unsigned char *buf, int len, uint32_t offs) {
540
	int skip;
541
	int i;
542

543
	JFFS2_DEBUG("dump from offset %#08x to offset %#08x (%x bytes).\n",
544
		offs, offs + len, len);
545
	i = skip = offs % JFFS2_BUFDUMP_BYTES_PER_LINE;
546
	offs = offs & ~(JFFS2_BUFDUMP_BYTES_PER_LINE - 1);
547

548
	if (skip != 0) {
549
		printk(JFFS2_DBG_LVL "%#08x: ", offs);
550
	}
551

552
	while (skip--) {
553
		printk("   ");
554
	}
555

556
	while (i < len) {
557
		if ((i % JFFS2_BUFDUMP_BYTES_PER_LINE) == 0 && i != len -1) {
558
			if (i != 0) {
559
				printk("\n");
560
			}
561
			offs += JFFS2_BUFDUMP_BYTES_PER_LINE;
562
			printk(JFFS2_DBG_LVL "%0#8x: ", offs);
563
		}
564

565
		printk("%02x ", buf[i]);
566

567
		i += 1;
568
	}
569

570
	printk("\n");
571
}
572

573
/*
574
 * Dump a JFFS2 node.
575
 */
576
void __jffs2_dbg_dump_node(struct jffs2_sb_info *c, uint32_t ofs) {
577
	union jffs2_node_union node;
578
	int len = sizeof(union jffs2_node_union);
579
	size_t retlen;
580
	uint32_t crc;
581
	int ret;
582

583
	JFFS2_DEBUG("dump node at offset %#08x.\n", ofs);
584

585
	ret = jffs2_flash_read(c, ofs, len, &retlen, (unsigned char *)&node);
586
	if (ret || (retlen != len)) {
587
		JFFS2_ERROR("read %d bytes failed or short. ret %d, retlen %zd.\n",
588
			len, ret, retlen);
589
		return;
590
	}
591

592
	printk(JFFS2_DBG_LVL "magic:\t%#04x\n",
593
		je16_to_cpu(node.u.magic));
594
	printk(JFFS2_DBG_LVL "nodetype:\t%#04x\n",
595
		je16_to_cpu(node.u.nodetype));
596
	printk(JFFS2_DBG_LVL "totlen:\t%#08x\n",
597
		je32_to_cpu(node.u.totlen));
598
	printk(JFFS2_DBG_LVL "hdr_crc:\t%#08x\n",
599
		je32_to_cpu(node.u.hdr_crc));
600

601
	crc = crc32(0, &node.u, sizeof(node.u) - 4);
602
	if (crc != je32_to_cpu(node.u.hdr_crc)) {
603
		JFFS2_ERROR("wrong common header CRC.\n");
604
		return;
605
	}
606

607
	if (je16_to_cpu(node.u.magic) != JFFS2_MAGIC_BITMASK &&
608
		je16_to_cpu(node.u.magic) != JFFS2_OLD_MAGIC_BITMASK)
609
	{
610
		JFFS2_ERROR("wrong node magic: %#04x instead of %#04x.\n",
611
			je16_to_cpu(node.u.magic), JFFS2_MAGIC_BITMASK);
612
		return;
613
	}
614

615
	switch(je16_to_cpu(node.u.nodetype)) {
616

617
	case JFFS2_NODETYPE_INODE:
618

619
		printk(JFFS2_DBG_LVL "the node is inode node\n");
620
		printk(JFFS2_DBG_LVL "ino:\t%#08x\n",
621
				je32_to_cpu(node.i.ino));
622
		printk(JFFS2_DBG_LVL "version:\t%#08x\n",
623
				je32_to_cpu(node.i.version));
624
		printk(JFFS2_DBG_LVL "mode:\t%#08x\n",
625
				node.i.mode.m);
626
		printk(JFFS2_DBG_LVL "uid:\t%#04x\n",
627
				je16_to_cpu(node.i.uid));
628
		printk(JFFS2_DBG_LVL "gid:\t%#04x\n",
629
				je16_to_cpu(node.i.gid));
630
		printk(JFFS2_DBG_LVL "isize:\t%#08x\n",
631
				je32_to_cpu(node.i.isize));
632
		printk(JFFS2_DBG_LVL "atime:\t%#08x\n",
633
				je32_to_cpu(node.i.atime));
634
		printk(JFFS2_DBG_LVL "mtime:\t%#08x\n",
635
				je32_to_cpu(node.i.mtime));
636
		printk(JFFS2_DBG_LVL "ctime:\t%#08x\n",
637
				je32_to_cpu(node.i.ctime));
638
		printk(JFFS2_DBG_LVL "offset:\t%#08x\n",
639
				je32_to_cpu(node.i.offset));
640
		printk(JFFS2_DBG_LVL "csize:\t%#08x\n",
641
				je32_to_cpu(node.i.csize));
642
		printk(JFFS2_DBG_LVL "dsize:\t%#08x\n",
643
				je32_to_cpu(node.i.dsize));
644
		printk(JFFS2_DBG_LVL "compr:\t%#02x\n",
645
				node.i.compr);
646
		printk(JFFS2_DBG_LVL "usercompr:\t%#02x\n",
647
				node.i.usercompr);
648
		printk(JFFS2_DBG_LVL "flags:\t%#04x\n",
649
				je16_to_cpu(node.i.flags));
650
		printk(JFFS2_DBG_LVL "data_crc:\t%#08x\n",
651
				je32_to_cpu(node.i.data_crc));
652
		printk(JFFS2_DBG_LVL "node_crc:\t%#08x\n",
653
				je32_to_cpu(node.i.node_crc));
654
		crc = crc32(0, &node.i, sizeof(node.i) - 8);
655
		if (crc != je32_to_cpu(node.i.node_crc)) {
656
			JFFS2_ERROR("wrong node header CRC.\n");
657
			return;
658
		}
659
		break;
660

661
	case JFFS2_NODETYPE_DIRENT:
662

663
		printk(JFFS2_DBG_LVL "the node is dirent node\n");
664
		printk(JFFS2_DBG_LVL "pino:\t%#08x\n",
665
				je32_to_cpu(node.d.pino));
666
		printk(JFFS2_DBG_LVL "version:\t%#08x\n",
667
				je32_to_cpu(node.d.version));
668
		printk(JFFS2_DBG_LVL "ino:\t%#08x\n",
669
				je32_to_cpu(node.d.ino));
670
		printk(JFFS2_DBG_LVL "mctime:\t%#08x\n",
671
				je32_to_cpu(node.d.mctime));
672
		printk(JFFS2_DBG_LVL "nsize:\t%#02x\n",
673
				node.d.nsize);
674
		printk(JFFS2_DBG_LVL "type:\t%#02x\n",
675
				node.d.type);
676
		printk(JFFS2_DBG_LVL "node_crc:\t%#08x\n",
677
				je32_to_cpu(node.d.node_crc));
678
		printk(JFFS2_DBG_LVL "name_crc:\t%#08x\n",
679
				je32_to_cpu(node.d.name_crc));
680

681
		node.d.name[node.d.nsize] = '\0';
682
		printk(JFFS2_DBG_LVL "name:\t\"%s\"\n", node.d.name);
683

684
		crc = crc32(0, &node.d, sizeof(node.d) - 8);
685
		if (crc != je32_to_cpu(node.d.node_crc)) {
686
			JFFS2_ERROR("wrong node header CRC.\n");
687
			return;
688
		}
689
		break;
690

691
	default:
692
		printk(JFFS2_DBG_LVL "node type is unknown\n");
693
		break;
694
	}
695
}
696
#endif /* JFFS2_DBG_DUMPS || JFFS2_DBG_PARANOIA_CHECKS */
697

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.