debug.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  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.1.1 2007/06/12 07:27:13 eyryu 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 <linux/jffs2.h>
  18. #include <linux/mtd/mtd.h>
  19. #include "nodelist.h"
  20. #include "debug.h"
  21. #ifdef JFFS2_DBG_SANITY_CHECKS
  22. void
  23. __jffs2_dbg_acct_sanity_check_nolock(struct jffs2_sb_info *c,
  24. struct jffs2_eraseblock *jeb)
  25. {
  26. if (unlikely(jeb && jeb->used_size + jeb->dirty_size +
  27. jeb->free_size + jeb->wasted_size +
  28. jeb->unchecked_size != c->sector_size)) {
  29. JFFS2_ERROR("eeep, space accounting for block at 0x%08x is screwed.\n", jeb->offset);
  30. JFFS2_ERROR("free %#08x + dirty %#08x + used %#08x + wasted %#08x + unchecked %#08x != total %#08x.\n",
  31. jeb->free_size, jeb->dirty_size, jeb->used_size,
  32. jeb->wasted_size, jeb->unchecked_size, c->sector_size);
  33. BUG();
  34. }
  35. if (unlikely(c->used_size + c->dirty_size + c->free_size + c->erasing_size + c->bad_size
  36. + c->wasted_size + c->unchecked_size != c->flash_size)) {
  37. JFFS2_ERROR("eeep, space accounting superblock info is screwed.\n");
  38. JFFS2_ERROR("free %#08x + dirty %#08x + used %#08x + erasing %#08x + bad %#08x + wasted %#08x + unchecked %#08x != total %#08x.\n",
  39. c->free_size, c->dirty_size, c->used_size, c->erasing_size, c->bad_size,
  40. c->wasted_size, c->unchecked_size, c->flash_size);
  41. BUG();
  42. }
  43. }
  44. void
  45. __jffs2_dbg_acct_sanity_check(struct jffs2_sb_info *c,
  46. struct jffs2_eraseblock *jeb)
  47. {
  48. spin_lock(&c->erase_completion_lock);
  49. jffs2_dbg_acct_sanity_check_nolock(c, jeb);
  50. spin_unlock(&c->erase_completion_lock);
  51. }
  52. #endif /* JFFS2_DBG_SANITY_CHECKS */
  53. #ifdef JFFS2_DBG_PARANOIA_CHECKS
  54. /*
  55. * Check the fragtree.
  56. */
  57. void
  58. __jffs2_dbg_fragtree_paranoia_check(struct jffs2_inode_info *f)
  59. {
  60. down(&f->sem);
  61. __jffs2_dbg_fragtree_paranoia_check_nolock(f);
  62. up(&f->sem);
  63. }
  64. void
  65. __jffs2_dbg_fragtree_paranoia_check_nolock(struct jffs2_inode_info *f)
  66. {
  67. struct jffs2_node_frag *frag;
  68. int bitched = 0;
  69. for (frag = frag_first(&f->fragtree); frag; frag = frag_next(frag)) {
  70. struct jffs2_full_dnode *fn = frag->node;
  71. if (!fn || !fn->raw)
  72. continue;
  73. if (ref_flags(fn->raw) == REF_PRISTINE) {
  74. if (fn->frags > 1) {
  75. JFFS2_ERROR("REF_PRISTINE node at 0x%08x had %d frags. Tell dwmw2.\n",
  76. ref_offset(fn->raw), fn->frags);
  77. bitched = 1;
  78. }
  79. /* A hole node which isn't multi-page should be garbage-collected
  80. and merged anyway, so we just check for the frag size here,
  81. rather than mucking around with actually reading the node
  82. and checking the compression type, which is the real way
  83. to tell a hole node. */
  84. if (frag->ofs & (PAGE_CACHE_SIZE-1) && frag_prev(frag)
  85. && frag_prev(frag)->size < PAGE_CACHE_SIZE && frag_prev(frag)->node) {
  86. JFFS2_ERROR("REF_PRISTINE node at 0x%08x had a previous non-hole frag in the same page. Tell dwmw2.\n",
  87. ref_offset(fn->raw));
  88. bitched = 1;
  89. }
  90. if ((frag->ofs+frag->size) & (PAGE_CACHE_SIZE-1) && frag_next(frag)
  91. && frag_next(frag)->size < PAGE_CACHE_SIZE && frag_next(frag)->node) {
  92. JFFS2_ERROR("REF_PRISTINE node at 0x%08x (%08x-%08x) had a following non-hole frag in the same page. Tell dwmw2.\n",
  93. ref_offset(fn->raw), frag->ofs, frag->ofs+frag->size);
  94. bitched = 1;
  95. }
  96. }
  97. }
  98. if (bitched) {
  99. JFFS2_ERROR("fragtree is corrupted.\n");
  100. __jffs2_dbg_dump_fragtree_nolock(f);
  101. BUG();
  102. }
  103. }
  104. /*
  105. * Check if the flash contains all 0xFF before we start writing.
  106. */
  107. void
  108. __jffs2_dbg_prewrite_paranoia_check(struct jffs2_sb_info *c,
  109. uint32_t ofs, int len)
  110. {
  111. size_t retlen;
  112. int ret, i;
  113. unsigned char *buf;
  114. buf = kmalloc(len, GFP_KERNEL);
  115. if (!buf)
  116. return;
  117. ret = jffs2_flash_read(c, ofs, len, &retlen, buf);
  118. if (ret || (retlen != len)) {
  119. JFFS2_WARNING("read %d bytes failed or short. ret %d, retlen %zd.\n",
  120. len, ret, retlen);
  121. kfree(buf);
  122. return;
  123. }
  124. ret = 0;
  125. for (i = 0; i < len; i++)
  126. if (buf[i] != 0xff)
  127. ret = 1;
  128. if (ret) {
  129. JFFS2_ERROR("argh, about to write node to %#08x on flash, but there are data already there. The first corrupted byte is at %#08x offset.\n",
  130. ofs, ofs + i);
  131. __jffs2_dbg_dump_buffer(buf, len, ofs);
  132. kfree(buf);
  133. BUG();
  134. }
  135. kfree(buf);
  136. }
  137. /*
  138. * Check the space accounting and node_ref list correctness for the JFFS2 erasable block 'jeb'.
  139. */
  140. void
  141. __jffs2_dbg_acct_paranoia_check(struct jffs2_sb_info *c,
  142. struct jffs2_eraseblock *jeb)
  143. {
  144. spin_lock(&c->erase_completion_lock);
  145. __jffs2_dbg_acct_paranoia_check_nolock(c, jeb);
  146. spin_unlock(&c->erase_completion_lock);
  147. }
  148. void
  149. __jffs2_dbg_acct_paranoia_check_nolock(struct jffs2_sb_info *c,
  150. struct jffs2_eraseblock *jeb)
  151. {
  152. uint32_t my_used_size = 0;
  153. uint32_t my_unchecked_size = 0;
  154. uint32_t my_dirty_size = 0;
  155. struct jffs2_raw_node_ref *ref2 = jeb->first_node;
  156. while (ref2) {
  157. uint32_t totlen = ref_totlen(c, jeb, ref2);
  158. if (ref_offset(ref2) < jeb->offset ||
  159. ref_offset(ref2) > jeb->offset + c->sector_size) {
  160. JFFS2_ERROR("node_ref %#08x shouldn't be in block at %#08x.\n",
  161. ref_offset(ref2), jeb->offset);
  162. goto error;
  163. }
  164. if (ref_flags(ref2) == REF_UNCHECKED)
  165. my_unchecked_size += totlen;
  166. else if (!ref_obsolete(ref2))
  167. my_used_size += totlen;
  168. else
  169. my_dirty_size += totlen;
  170. if ((!ref_next(ref2)) != (ref2 == jeb->last_node)) {
  171. JFFS2_ERROR("node_ref for node at %#08x (mem %p) has next at %#08x (mem %p), last_node is at %#08x (mem %p).\n",
  172. ref_offset(ref2), ref2, ref_offset(ref_next(ref2)), ref_next(ref2),
  173. ref_offset(jeb->last_node), jeb->last_node);
  174. goto error;
  175. }
  176. ref2 = ref_next(ref2);
  177. }
  178. if (my_used_size != jeb->used_size) {
  179. JFFS2_ERROR("Calculated used size %#08x != stored used size %#08x.\n",
  180. my_used_size, jeb->used_size);
  181. goto error;
  182. }
  183. if (my_unchecked_size != jeb->unchecked_size) {
  184. JFFS2_ERROR("Calculated unchecked size %#08x != stored unchecked size %#08x.\n",
  185. my_unchecked_size, jeb->unchecked_size);
  186. goto error;
  187. }
  188. #if 0
  189. /* This should work when we implement ref->__totlen elemination */
  190. if (my_dirty_size != jeb->dirty_size + jeb->wasted_size) {
  191. JFFS2_ERROR("Calculated dirty+wasted size %#08x != stored dirty + wasted size %#08x\n",
  192. my_dirty_size, jeb->dirty_size + jeb->wasted_size);
  193. goto error;
  194. }
  195. if (jeb->free_size == 0
  196. && my_used_size + my_unchecked_size + my_dirty_size != c->sector_size) {
  197. JFFS2_ERROR("The sum of all nodes in block (%#x) != size of block (%#x)\n",
  198. my_used_size + my_unchecked_size + my_dirty_size,
  199. c->sector_size);
  200. goto error;
  201. }
  202. #endif
  203. return;
  204. error:
  205. __jffs2_dbg_dump_node_refs_nolock(c, jeb);
  206. __jffs2_dbg_dump_jeb_nolock(jeb);
  207. __jffs2_dbg_dump_block_lists_nolock(c);
  208. BUG();
  209. }
  210. #endif /* JFFS2_DBG_PARANOIA_CHECKS */
  211. #if defined(JFFS2_DBG_DUMPS) || defined(JFFS2_DBG_PARANOIA_CHECKS)
  212. /*
  213. * Dump the node_refs of the 'jeb' JFFS2 eraseblock.
  214. */
  215. void
  216. __jffs2_dbg_dump_node_refs(struct jffs2_sb_info *c,
  217. struct jffs2_eraseblock *jeb)
  218. {
  219. spin_lock(&c->erase_completion_lock);
  220. __jffs2_dbg_dump_node_refs_nolock(c, jeb);
  221. spin_unlock(&c->erase_completion_lock);
  222. }
  223. void
  224. __jffs2_dbg_dump_node_refs_nolock(struct jffs2_sb_info *c,
  225. struct jffs2_eraseblock *jeb)
  226. {
  227. struct jffs2_raw_node_ref *ref;
  228. int i = 0;
  229. printk(JFFS2_DBG_MSG_PREFIX " Dump node_refs of the eraseblock %#08x\n", jeb->offset);
  230. if (!jeb->first_node) {
  231. printk(JFFS2_DBG_MSG_PREFIX " no nodes in the eraseblock %#08x\n", jeb->offset);
  232. return;
  233. }
  234. printk(JFFS2_DBG);
  235. for (ref = jeb->first_node; ; ref = ref_next(ref)) {
  236. printk("%#08x(%#x)", ref_offset(ref), ref->__totlen);
  237. if (ref_next(ref))
  238. printk("->");
  239. else
  240. break;
  241. if (++i == 4) {
  242. i = 0;
  243. printk("\n" JFFS2_DBG);
  244. }
  245. }
  246. printk("\n");
  247. }
  248. /*
  249. * Dump an eraseblock's space accounting.
  250. */
  251. void
  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. void
  259. __jffs2_dbg_dump_jeb_nolock(struct jffs2_eraseblock *jeb)
  260. {
  261. if (!jeb)
  262. return;
  263. printk(JFFS2_DBG_MSG_PREFIX " dump space accounting for the eraseblock at %#08x:\n",
  264. jeb->offset);
  265. printk(JFFS2_DBG "used_size: %#08x\n", jeb->used_size);
  266. printk(JFFS2_DBG "dirty_size: %#08x\n", jeb->dirty_size);
  267. printk(JFFS2_DBG "wasted_size: %#08x\n", jeb->wasted_size);
  268. printk(JFFS2_DBG "unchecked_size: %#08x\n", jeb->unchecked_size);
  269. printk(JFFS2_DBG "free_size: %#08x\n", jeb->free_size);
  270. }
  271. void
  272. __jffs2_dbg_dump_block_lists(struct jffs2_sb_info *c)
  273. {
  274. spin_lock(&c->erase_completion_lock);
  275. __jffs2_dbg_dump_block_lists_nolock(c);
  276. spin_unlock(&c->erase_completion_lock);
  277. }
  278. void
  279. __jffs2_dbg_dump_block_lists_nolock(struct jffs2_sb_info *c)
  280. {
  281. printk(JFFS2_DBG_MSG_PREFIX " dump JFFS2 blocks lists:\n");
  282. printk(JFFS2_DBG "flash_size: %#08x\n", c->flash_size);
  283. printk(JFFS2_DBG "used_size: %#08x\n", c->used_size);
  284. printk(JFFS2_DBG "dirty_size: %#08x\n", c->dirty_size);
  285. printk(JFFS2_DBG "wasted_size: %#08x\n", c->wasted_size);
  286. printk(JFFS2_DBG "unchecked_size: %#08x\n", c->unchecked_size);
  287. printk(JFFS2_DBG "free_size: %#08x\n", c->free_size);
  288. printk(JFFS2_DBG "erasing_size: %#08x\n", c->erasing_size);
  289. printk(JFFS2_DBG "bad_size: %#08x\n", c->bad_size);
  290. printk(JFFS2_DBG "sector_size: %#08x\n", c->sector_size);
  291. printk(JFFS2_DBG "jffs2_reserved_blocks size: %#08x\n",
  292. c->sector_size * c->resv_blocks_write);
  293. if (c->nextblock)
  294. printk(JFFS2_DBG "nextblock: %#08x (used %#08x, dirty %#08x, wasted %#08x, unchecked %#08x, free %#08x)\n",
  295. c->nextblock->offset, c->nextblock->used_size,
  296. c->nextblock->dirty_size, c->nextblock->wasted_size,
  297. c->nextblock->unchecked_size, c->nextblock->free_size);
  298. else
  299. printk(JFFS2_DBG "nextblock: NULL\n");
  300. if (c->gcblock)
  301. printk(JFFS2_DBG "gcblock: %#08x (used %#08x, dirty %#08x, wasted %#08x, unchecked %#08x, free %#08x)\n",
  302. c->gcblock->offset, c->gcblock->used_size, c->gcblock->dirty_size,
  303. c->gcblock->wasted_size, c->gcblock->unchecked_size, c->gcblock->free_size);
  304. else
  305. printk(JFFS2_DBG "gcblock: NULL\n");
  306. if (list_empty(&c->clean_list)) {
  307. printk(JFFS2_DBG "clean_list: empty\n");
  308. } else {
  309. struct list_head *this;
  310. int numblocks = 0;
  311. uint32_t dirty = 0;
  312. list_for_each(this, &c->clean_list) {
  313. struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list);
  314. numblocks ++;
  315. dirty += jeb->wasted_size;
  316. if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) {
  317. printk(JFFS2_DBG "clean_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, unchecked %#08x, free %#08x)\n",
  318. jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size,
  319. jeb->unchecked_size, jeb->free_size);
  320. }
  321. }
  322. printk (JFFS2_DBG "Contains %d blocks with total wasted size %u, average wasted size: %u\n",
  323. numblocks, dirty, dirty / numblocks);
  324. }
  325. if (list_empty(&c->very_dirty_list)) {
  326. printk(JFFS2_DBG "very_dirty_list: empty\n");
  327. } else {
  328. struct list_head *this;
  329. int numblocks = 0;
  330. uint32_t dirty = 0;
  331. list_for_each(this, &c->very_dirty_list) {
  332. struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list);
  333. numblocks ++;
  334. dirty += jeb->dirty_size;
  335. if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) {
  336. printk(JFFS2_DBG "very_dirty_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, unchecked %#08x, free %#08x)\n",
  337. jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size,
  338. jeb->unchecked_size, jeb->free_size);
  339. }
  340. }
  341. printk (JFFS2_DBG "Contains %d blocks with total dirty size %u, average dirty size: %u\n",
  342. numblocks, dirty, dirty / numblocks);
  343. }
  344. if (list_empty(&c->dirty_list)) {
  345. printk(JFFS2_DBG "dirty_list: empty\n");
  346. } else {
  347. struct list_head *this;
  348. int numblocks = 0;
  349. uint32_t dirty = 0;
  350. list_for_each(this, &c->dirty_list) {
  351. struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list);
  352. numblocks ++;
  353. dirty += jeb->dirty_size;
  354. if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) {
  355. printk(JFFS2_DBG "dirty_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, unchecked %#08x, free %#08x)\n",
  356. jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size,
  357. jeb->unchecked_size, jeb->free_size);
  358. }
  359. }
  360. printk (JFFS2_DBG "contains %d blocks with total dirty size %u, average dirty size: %u\n",
  361. numblocks, dirty, dirty / numblocks);
  362. }
  363. if (list_empty(&c->erasable_list)) {
  364. printk(JFFS2_DBG "erasable_list: empty\n");
  365. } else {
  366. struct list_head *this;
  367. list_for_each(this, &c->erasable_list) {
  368. struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list);
  369. if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) {
  370. printk(JFFS2_DBG "erasable_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, unchecked %#08x, free %#08x)\n",
  371. jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size,
  372. jeb->unchecked_size, jeb->free_size);
  373. }
  374. }
  375. }
  376. if (list_empty(&c->erasing_list)) {
  377. printk(JFFS2_DBG "erasing_list: empty\n");
  378. } else {
  379. struct list_head *this;
  380. list_for_each(this, &c->erasing_list) {
  381. struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list);
  382. if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) {
  383. printk(JFFS2_DBG "erasing_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, unchecked %#08x, free %#08x)\n",
  384. jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size,
  385. jeb->unchecked_size, jeb->free_size);
  386. }
  387. }
  388. }
  389. if (list_empty(&c->erase_pending_list)) {
  390. printk(JFFS2_DBG "erase_pending_list: empty\n");
  391. } else {
  392. struct list_head *this;
  393. list_for_each(this, &c->erase_pending_list) {
  394. struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list);
  395. if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) {
  396. printk(JFFS2_DBG "erase_pending_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, unchecked %#08x, free %#08x)\n",
  397. jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size,
  398. jeb->unchecked_size, jeb->free_size);
  399. }
  400. }
  401. }
  402. if (list_empty(&c->erasable_pending_wbuf_list)) {
  403. printk(JFFS2_DBG "erasable_pending_wbuf_list: empty\n");
  404. } else {
  405. struct list_head *this;
  406. list_for_each(this, &c->erasable_pending_wbuf_list) {
  407. struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list);
  408. if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) {
  409. printk(JFFS2_DBG "erasable_pending_wbuf_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, unchecked %#08x, free %#08x)\n",
  410. jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size,
  411. jeb->unchecked_size, jeb->free_size);
  412. }
  413. }
  414. }
  415. if (list_empty(&c->free_list)) {
  416. printk(JFFS2_DBG "free_list: empty\n");
  417. } else {
  418. struct list_head *this;
  419. list_for_each(this, &c->free_list) {
  420. struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list);
  421. if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) {
  422. printk(JFFS2_DBG "free_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, unchecked %#08x, free %#08x)\n",
  423. jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size,
  424. jeb->unchecked_size, jeb->free_size);
  425. }
  426. }
  427. }
  428. if (list_empty(&c->bad_list)) {
  429. printk(JFFS2_DBG "bad_list: empty\n");
  430. } else {
  431. struct list_head *this;
  432. list_for_each(this, &c->bad_list) {
  433. struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list);
  434. if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) {
  435. printk(JFFS2_DBG "bad_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, unchecked %#08x, free %#08x)\n",
  436. jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size,
  437. jeb->unchecked_size, jeb->free_size);
  438. }
  439. }
  440. }
  441. if (list_empty(&c->bad_used_list)) {
  442. printk(JFFS2_DBG "bad_used_list: empty\n");
  443. } else {
  444. struct list_head *this;
  445. list_for_each(this, &c->bad_used_list) {
  446. struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list);
  447. if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) {
  448. printk(JFFS2_DBG "bad_used_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, unchecked %#08x, free %#08x)\n",
  449. jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size,
  450. jeb->unchecked_size, jeb->free_size);
  451. }
  452. }
  453. }
  454. }
  455. void
  456. __jffs2_dbg_dump_fragtree(struct jffs2_inode_info *f)
  457. {
  458. down(&f->sem);
  459. jffs2_dbg_dump_fragtree_nolock(f);
  460. up(&f->sem);
  461. }
  462. void
  463. __jffs2_dbg_dump_fragtree_nolock(struct jffs2_inode_info *f)
  464. {
  465. struct jffs2_node_frag *this = frag_first(&f->fragtree);
  466. uint32_t lastofs = 0;
  467. int buggy = 0;
  468. printk(JFFS2_DBG_MSG_PREFIX " dump fragtree of ino #%u\n", f->inocache->ino);
  469. while(this) {
  470. if (this->node)
  471. printk(JFFS2_DBG "frag %#04x-%#04x: %#08x(%d) on flash (*%p), left (%p), right (%p), parent (%p)\n",
  472. this->ofs, this->ofs+this->size, ref_offset(this->node->raw),
  473. ref_flags(this->node->raw), this, frag_left(this), frag_right(this),
  474. frag_parent(this));
  475. else
  476. printk(JFFS2_DBG "frag %#04x-%#04x: hole (*%p). left (%p), right (%p), parent (%p)\n",
  477. this->ofs, this->ofs+this->size, this, frag_left(this),
  478. frag_right(this), frag_parent(this));
  479. if (this->ofs != lastofs)
  480. buggy = 1;
  481. lastofs = this->ofs + this->size;
  482. this = frag_next(this);
  483. }
  484. if (f->metadata)
  485. printk(JFFS2_DBG "metadata at 0x%08x\n", ref_offset(f->metadata->raw));
  486. if (buggy) {
  487. JFFS2_ERROR("frag tree got a hole in it.\n");
  488. BUG();
  489. }
  490. }
  491. #define JFFS2_BUFDUMP_BYTES_PER_LINE 32
  492. void
  493. __jffs2_dbg_dump_buffer(unsigned char *buf, int len, uint32_t offs)
  494. {
  495. int skip;
  496. int i;
  497. printk(JFFS2_DBG_MSG_PREFIX " dump from offset %#08x to offset %#08x (%x bytes).\n",
  498. offs, offs + len, len);
  499. i = skip = offs % JFFS2_BUFDUMP_BYTES_PER_LINE;
  500. offs = offs & ~(JFFS2_BUFDUMP_BYTES_PER_LINE - 1);
  501. if (skip != 0)
  502. printk(JFFS2_DBG "%#08x: ", offs);
  503. while (skip--)
  504. printk(" ");
  505. while (i < len) {
  506. if ((i % JFFS2_BUFDUMP_BYTES_PER_LINE) == 0 && i != len -1) {
  507. if (i != 0)
  508. printk("\n");
  509. offs += JFFS2_BUFDUMP_BYTES_PER_LINE;
  510. printk(JFFS2_DBG "%0#8x: ", offs);
  511. }
  512. printk("%02x ", buf[i]);
  513. i += 1;
  514. }
  515. printk("\n");
  516. }
  517. /*
  518. * Dump a JFFS2 node.
  519. */
  520. void
  521. __jffs2_dbg_dump_node(struct jffs2_sb_info *c, uint32_t ofs)
  522. {
  523. union jffs2_node_union node;
  524. int len = sizeof(union jffs2_node_union);
  525. size_t retlen;
  526. uint32_t crc;
  527. int ret;
  528. printk(JFFS2_DBG_MSG_PREFIX " dump node at offset %#08x.\n", ofs);
  529. ret = jffs2_flash_read(c, ofs, len, &retlen, (unsigned char *)&node);
  530. if (ret || (retlen != len)) {
  531. JFFS2_ERROR("read %d bytes failed or short. ret %d, retlen %zd.\n",
  532. len, ret, retlen);
  533. return;
  534. }
  535. printk(JFFS2_DBG "magic:\t%#04x\n", je16_to_cpu(node.u.magic));
  536. printk(JFFS2_DBG "nodetype:\t%#04x\n", je16_to_cpu(node.u.nodetype));
  537. printk(JFFS2_DBG "totlen:\t%#08x\n", je32_to_cpu(node.u.totlen));
  538. printk(JFFS2_DBG "hdr_crc:\t%#08x\n", je32_to_cpu(node.u.hdr_crc));
  539. crc = crc32(0, &node.u, sizeof(node.u) - 4);
  540. if (crc != je32_to_cpu(node.u.hdr_crc)) {
  541. JFFS2_ERROR("wrong common header CRC.\n");
  542. return;
  543. }
  544. if (je16_to_cpu(node.u.magic) != JFFS2_MAGIC_BITMASK &&
  545. je16_to_cpu(node.u.magic) != JFFS2_OLD_MAGIC_BITMASK)
  546. {
  547. JFFS2_ERROR("wrong node magic: %#04x instead of %#04x.\n",
  548. je16_to_cpu(node.u.magic), JFFS2_MAGIC_BITMASK);
  549. return;
  550. }
  551. switch(je16_to_cpu(node.u.nodetype)) {
  552. case JFFS2_NODETYPE_INODE:
  553. printk(JFFS2_DBG "the node is inode node\n");
  554. printk(JFFS2_DBG "ino:\t%#08x\n", je32_to_cpu(node.i.ino));
  555. printk(JFFS2_DBG "version:\t%#08x\n", je32_to_cpu(node.i.version));
  556. printk(JFFS2_DBG "mode:\t%#08x\n", node.i.mode.m);
  557. printk(JFFS2_DBG "uid:\t%#04x\n", je16_to_cpu(node.i.uid));
  558. printk(JFFS2_DBG "gid:\t%#04x\n", je16_to_cpu(node.i.gid));
  559. printk(JFFS2_DBG "isize:\t%#08x\n", je32_to_cpu(node.i.isize));
  560. printk(JFFS2_DBG "atime:\t%#08x\n", je32_to_cpu(node.i.atime));
  561. printk(JFFS2_DBG "mtime:\t%#08x\n", je32_to_cpu(node.i.mtime));
  562. printk(JFFS2_DBG "ctime:\t%#08x\n", je32_to_cpu(node.i.ctime));
  563. printk(JFFS2_DBG "offset:\t%#08x\n", je32_to_cpu(node.i.offset));
  564. printk(JFFS2_DBG "csize:\t%#08x\n", je32_to_cpu(node.i.csize));
  565. printk(JFFS2_DBG "dsize:\t%#08x\n", je32_to_cpu(node.i.dsize));
  566. printk(JFFS2_DBG "compr:\t%#02x\n", node.i.compr);
  567. printk(JFFS2_DBG "usercompr:\t%#02x\n", node.i.usercompr);
  568. printk(JFFS2_DBG "flags:\t%#04x\n", je16_to_cpu(node.i.flags));
  569. printk(JFFS2_DBG "data_crc:\t%#08x\n", je32_to_cpu(node.i.data_crc));
  570. printk(JFFS2_DBG "node_crc:\t%#08x\n", je32_to_cpu(node.i.node_crc));
  571. crc = crc32(0, &node.i, sizeof(node.i) - 8);
  572. if (crc != je32_to_cpu(node.i.node_crc)) {
  573. JFFS2_ERROR("wrong node header CRC.\n");
  574. return;
  575. }
  576. break;
  577. case JFFS2_NODETYPE_DIRENT:
  578. printk(JFFS2_DBG "the node is dirent node\n");
  579. printk(JFFS2_DBG "pino:\t%#08x\n", je32_to_cpu(node.d.pino));
  580. printk(JFFS2_DBG "version:\t%#08x\n", je32_to_cpu(node.d.version));
  581. printk(JFFS2_DBG "ino:\t%#08x\n", je32_to_cpu(node.d.ino));
  582. printk(JFFS2_DBG "mctime:\t%#08x\n", je32_to_cpu(node.d.mctime));
  583. printk(JFFS2_DBG "nsize:\t%#02x\n", node.d.nsize);
  584. printk(JFFS2_DBG "type:\t%#02x\n", node.d.type);
  585. printk(JFFS2_DBG "node_crc:\t%#08x\n", je32_to_cpu(node.d.node_crc));
  586. printk(JFFS2_DBG "name_crc:\t%#08x\n", je32_to_cpu(node.d.name_crc));
  587. node.d.name[node.d.nsize] = '\0';
  588. printk(JFFS2_DBG "name:\t\"%s\"\n", node.d.name);
  589. crc = crc32(0, &node.d, sizeof(node.d) - 8);
  590. if (crc != je32_to_cpu(node.d.node_crc)) {
  591. JFFS2_ERROR("wrong node header CRC.\n");
  592. return;
  593. }
  594. break;
  595. default:
  596. printk(JFFS2_DBG "node type is unknown\n");
  597. break;
  598. }
  599. }
  600. #endif /* JFFS2_DBG_DUMPS || JFFS2_DBG_PARANOIA_CHECKS */