debug.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866
  1. /*
  2. * JFFS2 -- Journalling Flash File System, Version 2.
  3. *
  4. * Copyright © 2001-2007 Red Hat, Inc.
  5. * Copyright © 2004-2010 David Woodhouse <dwmw2@infradead.org>
  6. *
  7. * Created by David Woodhouse <dwmw2@infradead.org>
  8. *
  9. * For licensing information, see the file 'LICENCE' in this directory.
  10. *
  11. */
  12. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  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 <linux/slab.h>
  20. #include "nodelist.h"
  21. #include "debug.h"
  22. #ifdef JFFS2_DBG_SANITY_CHECKS
  23. void
  24. __jffs2_dbg_acct_sanity_check_nolock(struct jffs2_sb_info *c,
  25. struct jffs2_eraseblock *jeb)
  26. {
  27. if (unlikely(jeb && jeb->used_size + jeb->dirty_size +
  28. jeb->free_size + jeb->wasted_size +
  29. jeb->unchecked_size != c->sector_size)) {
  30. JFFS2_ERROR("eeep, space accounting for block at 0x%08x is screwed.\n", jeb->offset);
  31. JFFS2_ERROR("free %#08x + dirty %#08x + used %#08x + wasted %#08x + unchecked %#08x != total %#08x.\n",
  32. jeb->free_size, jeb->dirty_size, jeb->used_size,
  33. jeb->wasted_size, jeb->unchecked_size, c->sector_size);
  34. BUG();
  35. }
  36. if (unlikely(c->used_size + c->dirty_size + c->free_size + c->erasing_size + c->bad_size
  37. + c->wasted_size + c->unchecked_size != c->flash_size)) {
  38. JFFS2_ERROR("eeep, space accounting superblock info is screwed.\n");
  39. JFFS2_ERROR("free %#08x + dirty %#08x + used %#08x + erasing %#08x + bad %#08x + wasted %#08x + unchecked %#08x != total %#08x.\n",
  40. c->free_size, c->dirty_size, c->used_size, c->erasing_size, c->bad_size,
  41. c->wasted_size, c->unchecked_size, c->flash_size);
  42. BUG();
  43. }
  44. }
  45. void
  46. __jffs2_dbg_acct_sanity_check(struct jffs2_sb_info *c,
  47. struct jffs2_eraseblock *jeb)
  48. {
  49. spin_lock(&c->erase_completion_lock);
  50. jffs2_dbg_acct_sanity_check_nolock(c, jeb);
  51. spin_unlock(&c->erase_completion_lock);
  52. }
  53. #endif /* JFFS2_DBG_SANITY_CHECKS */
  54. #ifdef JFFS2_DBG_PARANOIA_CHECKS
  55. /*
  56. * Check the fragtree.
  57. */
  58. void
  59. __jffs2_dbg_fragtree_paranoia_check(struct jffs2_inode_info *f)
  60. {
  61. mutex_lock(&f->sem);
  62. __jffs2_dbg_fragtree_paranoia_check_nolock(f);
  63. mutex_unlock(&f->sem);
  64. }
  65. void
  66. __jffs2_dbg_fragtree_paranoia_check_nolock(struct jffs2_inode_info *f)
  67. {
  68. struct jffs2_node_frag *frag;
  69. int bitched = 0;
  70. for (frag = frag_first(&f->fragtree); frag; frag = frag_next(frag)) {
  71. struct jffs2_full_dnode *fn = frag->node;
  72. if (!fn || !fn->raw)
  73. continue;
  74. if (ref_flags(fn->raw) == REF_PRISTINE) {
  75. if (fn->frags > 1) {
  76. JFFS2_ERROR("REF_PRISTINE node at 0x%08x had %d frags. Tell dwmw2.\n",
  77. ref_offset(fn->raw), fn->frags);
  78. bitched = 1;
  79. }
  80. /* A hole node which isn't multi-page should be garbage-collected
  81. and merged anyway, so we just check for the frag size here,
  82. rather than mucking around with actually reading the node
  83. and checking the compression type, which is the real way
  84. to tell a hole node. */
  85. if (frag->ofs & (PAGE_CACHE_SIZE-1) && frag_prev(frag)
  86. && frag_prev(frag)->size < PAGE_CACHE_SIZE && frag_prev(frag)->node) {
  87. JFFS2_ERROR("REF_PRISTINE node at 0x%08x had a previous non-hole frag in the same page. Tell dwmw2.\n",
  88. ref_offset(fn->raw));
  89. bitched = 1;
  90. }
  91. if ((frag->ofs+frag->size) & (PAGE_CACHE_SIZE-1) && frag_next(frag)
  92. && frag_next(frag)->size < PAGE_CACHE_SIZE && frag_next(frag)->node) {
  93. JFFS2_ERROR("REF_PRISTINE node at 0x%08x (%08x-%08x) had a following non-hole frag in the same page. Tell dwmw2.\n",
  94. ref_offset(fn->raw), frag->ofs, frag->ofs+frag->size);
  95. bitched = 1;
  96. }
  97. }
  98. }
  99. if (bitched) {
  100. JFFS2_ERROR("fragtree is corrupted.\n");
  101. __jffs2_dbg_dump_fragtree_nolock(f);
  102. BUG();
  103. }
  104. }
  105. /*
  106. * Check if the flash contains all 0xFF before we start writing.
  107. */
  108. void
  109. __jffs2_dbg_prewrite_paranoia_check(struct jffs2_sb_info *c,
  110. uint32_t ofs, int len)
  111. {
  112. size_t retlen;
  113. int ret, i;
  114. unsigned char *buf;
  115. buf = kmalloc(len, GFP_KERNEL);
  116. if (!buf)
  117. return;
  118. ret = jffs2_flash_read(c, ofs, len, &retlen, buf);
  119. if (ret || (retlen != len)) {
  120. JFFS2_WARNING("read %d bytes failed or short. ret %d, retlen %zd.\n",
  121. len, ret, retlen);
  122. kfree(buf);
  123. return;
  124. }
  125. ret = 0;
  126. for (i = 0; i < len; i++)
  127. if (buf[i] != 0xff)
  128. ret = 1;
  129. if (ret) {
  130. 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",
  131. ofs, ofs + i);
  132. __jffs2_dbg_dump_buffer(buf, len, ofs);
  133. kfree(buf);
  134. BUG();
  135. }
  136. kfree(buf);
  137. }
  138. void __jffs2_dbg_superblock_counts(struct jffs2_sb_info *c)
  139. {
  140. struct jffs2_eraseblock *jeb;
  141. uint32_t free = 0, dirty = 0, used = 0, wasted = 0,
  142. erasing = 0, bad = 0, unchecked = 0;
  143. int nr_counted = 0;
  144. int dump = 0;
  145. if (c->gcblock) {
  146. nr_counted++;
  147. free += c->gcblock->free_size;
  148. dirty += c->gcblock->dirty_size;
  149. used += c->gcblock->used_size;
  150. wasted += c->gcblock->wasted_size;
  151. unchecked += c->gcblock->unchecked_size;
  152. }
  153. if (c->nextblock) {
  154. nr_counted++;
  155. free += c->nextblock->free_size;
  156. dirty += c->nextblock->dirty_size;
  157. used += c->nextblock->used_size;
  158. wasted += c->nextblock->wasted_size;
  159. unchecked += c->nextblock->unchecked_size;
  160. }
  161. list_for_each_entry(jeb, &c->clean_list, list) {
  162. nr_counted++;
  163. free += jeb->free_size;
  164. dirty += jeb->dirty_size;
  165. used += jeb->used_size;
  166. wasted += jeb->wasted_size;
  167. unchecked += jeb->unchecked_size;
  168. }
  169. list_for_each_entry(jeb, &c->very_dirty_list, list) {
  170. nr_counted++;
  171. free += jeb->free_size;
  172. dirty += jeb->dirty_size;
  173. used += jeb->used_size;
  174. wasted += jeb->wasted_size;
  175. unchecked += jeb->unchecked_size;
  176. }
  177. list_for_each_entry(jeb, &c->dirty_list, list) {
  178. nr_counted++;
  179. free += jeb->free_size;
  180. dirty += jeb->dirty_size;
  181. used += jeb->used_size;
  182. wasted += jeb->wasted_size;
  183. unchecked += jeb->unchecked_size;
  184. }
  185. list_for_each_entry(jeb, &c->erasable_list, list) {
  186. nr_counted++;
  187. free += jeb->free_size;
  188. dirty += jeb->dirty_size;
  189. used += jeb->used_size;
  190. wasted += jeb->wasted_size;
  191. unchecked += jeb->unchecked_size;
  192. }
  193. list_for_each_entry(jeb, &c->erasable_pending_wbuf_list, list) {
  194. nr_counted++;
  195. free += jeb->free_size;
  196. dirty += jeb->dirty_size;
  197. used += jeb->used_size;
  198. wasted += jeb->wasted_size;
  199. unchecked += jeb->unchecked_size;
  200. }
  201. list_for_each_entry(jeb, &c->erase_pending_list, list) {
  202. nr_counted++;
  203. free += jeb->free_size;
  204. dirty += jeb->dirty_size;
  205. used += jeb->used_size;
  206. wasted += jeb->wasted_size;
  207. unchecked += jeb->unchecked_size;
  208. }
  209. list_for_each_entry(jeb, &c->free_list, list) {
  210. nr_counted++;
  211. free += jeb->free_size;
  212. dirty += jeb->dirty_size;
  213. used += jeb->used_size;
  214. wasted += jeb->wasted_size;
  215. unchecked += jeb->unchecked_size;
  216. }
  217. list_for_each_entry(jeb, &c->bad_used_list, list) {
  218. nr_counted++;
  219. free += jeb->free_size;
  220. dirty += jeb->dirty_size;
  221. used += jeb->used_size;
  222. wasted += jeb->wasted_size;
  223. unchecked += jeb->unchecked_size;
  224. }
  225. list_for_each_entry(jeb, &c->erasing_list, list) {
  226. nr_counted++;
  227. erasing += c->sector_size;
  228. }
  229. list_for_each_entry(jeb, &c->erase_checking_list, list) {
  230. nr_counted++;
  231. erasing += c->sector_size;
  232. }
  233. list_for_each_entry(jeb, &c->erase_complete_list, list) {
  234. nr_counted++;
  235. erasing += c->sector_size;
  236. }
  237. list_for_each_entry(jeb, &c->bad_list, list) {
  238. nr_counted++;
  239. bad += c->sector_size;
  240. }
  241. #define check(sz) \
  242. do { \
  243. if (sz != c->sz##_size) { \
  244. pr_warn("%s_size mismatch counted 0x%x, c->%s_size 0x%x\n", \
  245. #sz, sz, #sz, c->sz##_size); \
  246. dump = 1; \
  247. } \
  248. } while (0)
  249. check(free);
  250. check(dirty);
  251. check(used);
  252. check(wasted);
  253. check(unchecked);
  254. check(bad);
  255. check(erasing);
  256. #undef check
  257. if (nr_counted != c->nr_blocks) {
  258. pr_warn("%s counted only 0x%x blocks of 0x%x. Where are the others?\n",
  259. __func__, nr_counted, c->nr_blocks);
  260. dump = 1;
  261. }
  262. if (dump) {
  263. __jffs2_dbg_dump_block_lists_nolock(c);
  264. BUG();
  265. }
  266. }
  267. /*
  268. * Check the space accounting and node_ref list correctness for the JFFS2 erasable block 'jeb'.
  269. */
  270. void
  271. __jffs2_dbg_acct_paranoia_check(struct jffs2_sb_info *c,
  272. struct jffs2_eraseblock *jeb)
  273. {
  274. spin_lock(&c->erase_completion_lock);
  275. __jffs2_dbg_acct_paranoia_check_nolock(c, jeb);
  276. spin_unlock(&c->erase_completion_lock);
  277. }
  278. void
  279. __jffs2_dbg_acct_paranoia_check_nolock(struct jffs2_sb_info *c,
  280. struct jffs2_eraseblock *jeb)
  281. {
  282. uint32_t my_used_size = 0;
  283. uint32_t my_unchecked_size = 0;
  284. uint32_t my_dirty_size = 0;
  285. struct jffs2_raw_node_ref *ref2 = jeb->first_node;
  286. while (ref2) {
  287. uint32_t totlen = ref_totlen(c, jeb, ref2);
  288. if (ref_offset(ref2) < jeb->offset ||
  289. ref_offset(ref2) > jeb->offset + c->sector_size) {
  290. JFFS2_ERROR("node_ref %#08x shouldn't be in block at %#08x.\n",
  291. ref_offset(ref2), jeb->offset);
  292. goto error;
  293. }
  294. if (ref_flags(ref2) == REF_UNCHECKED)
  295. my_unchecked_size += totlen;
  296. else if (!ref_obsolete(ref2))
  297. my_used_size += totlen;
  298. else
  299. my_dirty_size += totlen;
  300. if ((!ref_next(ref2)) != (ref2 == jeb->last_node)) {
  301. JFFS2_ERROR("node_ref for node at %#08x (mem %p) has next at %#08x (mem %p), last_node is at %#08x (mem %p).\n",
  302. ref_offset(ref2), ref2, ref_offset(ref_next(ref2)), ref_next(ref2),
  303. ref_offset(jeb->last_node), jeb->last_node);
  304. goto error;
  305. }
  306. ref2 = ref_next(ref2);
  307. }
  308. if (my_used_size != jeb->used_size) {
  309. JFFS2_ERROR("Calculated used size %#08x != stored used size %#08x.\n",
  310. my_used_size, jeb->used_size);
  311. goto error;
  312. }
  313. if (my_unchecked_size != jeb->unchecked_size) {
  314. JFFS2_ERROR("Calculated unchecked size %#08x != stored unchecked size %#08x.\n",
  315. my_unchecked_size, jeb->unchecked_size);
  316. goto error;
  317. }
  318. #if 0
  319. /* This should work when we implement ref->__totlen elemination */
  320. if (my_dirty_size != jeb->dirty_size + jeb->wasted_size) {
  321. JFFS2_ERROR("Calculated dirty+wasted size %#08x != stored dirty + wasted size %#08x\n",
  322. my_dirty_size, jeb->dirty_size + jeb->wasted_size);
  323. goto error;
  324. }
  325. if (jeb->free_size == 0
  326. && my_used_size + my_unchecked_size + my_dirty_size != c->sector_size) {
  327. JFFS2_ERROR("The sum of all nodes in block (%#x) != size of block (%#x)\n",
  328. my_used_size + my_unchecked_size + my_dirty_size,
  329. c->sector_size);
  330. goto error;
  331. }
  332. #endif
  333. if (!(c->flags & (JFFS2_SB_FLAG_BUILDING|JFFS2_SB_FLAG_SCANNING)))
  334. __jffs2_dbg_superblock_counts(c);
  335. return;
  336. error:
  337. __jffs2_dbg_dump_node_refs_nolock(c, jeb);
  338. __jffs2_dbg_dump_jeb_nolock(jeb);
  339. __jffs2_dbg_dump_block_lists_nolock(c);
  340. BUG();
  341. }
  342. #endif /* JFFS2_DBG_PARANOIA_CHECKS */
  343. #if defined(JFFS2_DBG_DUMPS) || defined(JFFS2_DBG_PARANOIA_CHECKS)
  344. /*
  345. * Dump the node_refs of the 'jeb' JFFS2 eraseblock.
  346. */
  347. void
  348. __jffs2_dbg_dump_node_refs(struct jffs2_sb_info *c,
  349. struct jffs2_eraseblock *jeb)
  350. {
  351. spin_lock(&c->erase_completion_lock);
  352. __jffs2_dbg_dump_node_refs_nolock(c, jeb);
  353. spin_unlock(&c->erase_completion_lock);
  354. }
  355. void
  356. __jffs2_dbg_dump_node_refs_nolock(struct jffs2_sb_info *c,
  357. struct jffs2_eraseblock *jeb)
  358. {
  359. struct jffs2_raw_node_ref *ref;
  360. int i = 0;
  361. printk(JFFS2_DBG_MSG_PREFIX " Dump node_refs of the eraseblock %#08x\n", jeb->offset);
  362. if (!jeb->first_node) {
  363. printk(JFFS2_DBG_MSG_PREFIX " no nodes in the eraseblock %#08x\n", jeb->offset);
  364. return;
  365. }
  366. printk(JFFS2_DBG);
  367. for (ref = jeb->first_node; ; ref = ref_next(ref)) {
  368. printk("%#08x", ref_offset(ref));
  369. #ifdef TEST_TOTLEN
  370. printk("(%x)", ref->__totlen);
  371. #endif
  372. if (ref_next(ref))
  373. printk("->");
  374. else
  375. break;
  376. if (++i == 4) {
  377. i = 0;
  378. printk("\n" JFFS2_DBG);
  379. }
  380. }
  381. printk("\n");
  382. }
  383. /*
  384. * Dump an eraseblock's space accounting.
  385. */
  386. void
  387. __jffs2_dbg_dump_jeb(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb)
  388. {
  389. spin_lock(&c->erase_completion_lock);
  390. __jffs2_dbg_dump_jeb_nolock(jeb);
  391. spin_unlock(&c->erase_completion_lock);
  392. }
  393. void
  394. __jffs2_dbg_dump_jeb_nolock(struct jffs2_eraseblock *jeb)
  395. {
  396. if (!jeb)
  397. return;
  398. printk(JFFS2_DBG_MSG_PREFIX " dump space accounting for the eraseblock at %#08x:\n",
  399. jeb->offset);
  400. printk(JFFS2_DBG "used_size: %#08x\n", jeb->used_size);
  401. printk(JFFS2_DBG "dirty_size: %#08x\n", jeb->dirty_size);
  402. printk(JFFS2_DBG "wasted_size: %#08x\n", jeb->wasted_size);
  403. printk(JFFS2_DBG "unchecked_size: %#08x\n", jeb->unchecked_size);
  404. printk(JFFS2_DBG "free_size: %#08x\n", jeb->free_size);
  405. }
  406. void
  407. __jffs2_dbg_dump_block_lists(struct jffs2_sb_info *c)
  408. {
  409. spin_lock(&c->erase_completion_lock);
  410. __jffs2_dbg_dump_block_lists_nolock(c);
  411. spin_unlock(&c->erase_completion_lock);
  412. }
  413. void
  414. __jffs2_dbg_dump_block_lists_nolock(struct jffs2_sb_info *c)
  415. {
  416. printk(JFFS2_DBG_MSG_PREFIX " dump JFFS2 blocks lists:\n");
  417. printk(JFFS2_DBG "flash_size: %#08x\n", c->flash_size);
  418. printk(JFFS2_DBG "used_size: %#08x\n", c->used_size);
  419. printk(JFFS2_DBG "dirty_size: %#08x\n", c->dirty_size);
  420. printk(JFFS2_DBG "wasted_size: %#08x\n", c->wasted_size);
  421. printk(JFFS2_DBG "unchecked_size: %#08x\n", c->unchecked_size);
  422. printk(JFFS2_DBG "free_size: %#08x\n", c->free_size);
  423. printk(JFFS2_DBG "erasing_size: %#08x\n", c->erasing_size);
  424. printk(JFFS2_DBG "bad_size: %#08x\n", c->bad_size);
  425. printk(JFFS2_DBG "sector_size: %#08x\n", c->sector_size);
  426. printk(JFFS2_DBG "jffs2_reserved_blocks size: %#08x\n",
  427. c->sector_size * c->resv_blocks_write);
  428. if (c->nextblock)
  429. printk(JFFS2_DBG "nextblock: %#08x (used %#08x, dirty %#08x, wasted %#08x, unchecked %#08x, free %#08x)\n",
  430. c->nextblock->offset, c->nextblock->used_size,
  431. c->nextblock->dirty_size, c->nextblock->wasted_size,
  432. c->nextblock->unchecked_size, c->nextblock->free_size);
  433. else
  434. printk(JFFS2_DBG "nextblock: NULL\n");
  435. if (c->gcblock)
  436. printk(JFFS2_DBG "gcblock: %#08x (used %#08x, dirty %#08x, wasted %#08x, unchecked %#08x, free %#08x)\n",
  437. c->gcblock->offset, c->gcblock->used_size, c->gcblock->dirty_size,
  438. c->gcblock->wasted_size, c->gcblock->unchecked_size, c->gcblock->free_size);
  439. else
  440. printk(JFFS2_DBG "gcblock: NULL\n");
  441. if (list_empty(&c->clean_list)) {
  442. printk(JFFS2_DBG "clean_list: empty\n");
  443. } else {
  444. struct list_head *this;
  445. int numblocks = 0;
  446. uint32_t dirty = 0;
  447. list_for_each(this, &c->clean_list) {
  448. struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list);
  449. numblocks ++;
  450. dirty += jeb->wasted_size;
  451. if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) {
  452. printk(JFFS2_DBG "clean_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, 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. printk (JFFS2_DBG "Contains %d blocks with total wasted size %u, average wasted size: %u\n",
  458. numblocks, dirty, dirty / numblocks);
  459. }
  460. if (list_empty(&c->very_dirty_list)) {
  461. printk(JFFS2_DBG "very_dirty_list: empty\n");
  462. } else {
  463. struct list_head *this;
  464. int numblocks = 0;
  465. uint32_t dirty = 0;
  466. list_for_each(this, &c->very_dirty_list) {
  467. struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list);
  468. numblocks ++;
  469. dirty += jeb->dirty_size;
  470. if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) {
  471. printk(JFFS2_DBG "very_dirty_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, 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. printk (JFFS2_DBG "Contains %d blocks with total dirty size %u, average dirty size: %u\n",
  477. numblocks, dirty, dirty / numblocks);
  478. }
  479. if (list_empty(&c->dirty_list)) {
  480. printk(JFFS2_DBG "dirty_list: empty\n");
  481. } else {
  482. struct list_head *this;
  483. int numblocks = 0;
  484. uint32_t dirty = 0;
  485. list_for_each(this, &c->dirty_list) {
  486. struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list);
  487. numblocks ++;
  488. dirty += jeb->dirty_size;
  489. if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) {
  490. printk(JFFS2_DBG "dirty_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, 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. printk (JFFS2_DBG "contains %d blocks with total dirty size %u, average dirty size: %u\n",
  496. numblocks, dirty, dirty / numblocks);
  497. }
  498. if (list_empty(&c->erasable_list)) {
  499. printk(JFFS2_DBG "erasable_list: empty\n");
  500. } else {
  501. struct list_head *this;
  502. list_for_each(this, &c->erasable_list) {
  503. struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list);
  504. if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) {
  505. printk(JFFS2_DBG "erasable_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, unchecked %#08x, free %#08x)\n",
  506. jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size,
  507. jeb->unchecked_size, jeb->free_size);
  508. }
  509. }
  510. }
  511. if (list_empty(&c->erasing_list)) {
  512. printk(JFFS2_DBG "erasing_list: empty\n");
  513. } else {
  514. struct list_head *this;
  515. list_for_each(this, &c->erasing_list) {
  516. struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list);
  517. if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) {
  518. printk(JFFS2_DBG "erasing_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, unchecked %#08x, free %#08x)\n",
  519. jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size,
  520. jeb->unchecked_size, jeb->free_size);
  521. }
  522. }
  523. }
  524. if (list_empty(&c->erase_checking_list)) {
  525. printk(JFFS2_DBG "erase_checking_list: empty\n");
  526. } else {
  527. struct list_head *this;
  528. list_for_each(this, &c->erase_checking_list) {
  529. struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list);
  530. if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) {
  531. printk(JFFS2_DBG "erase_checking_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, unchecked %#08x, free %#08x)\n",
  532. jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size,
  533. jeb->unchecked_size, jeb->free_size);
  534. }
  535. }
  536. }
  537. if (list_empty(&c->erase_pending_list)) {
  538. printk(JFFS2_DBG "erase_pending_list: empty\n");
  539. } else {
  540. struct list_head *this;
  541. list_for_each(this, &c->erase_pending_list) {
  542. struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list);
  543. if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) {
  544. printk(JFFS2_DBG "erase_pending_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, unchecked %#08x, free %#08x)\n",
  545. jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size,
  546. jeb->unchecked_size, jeb->free_size);
  547. }
  548. }
  549. }
  550. if (list_empty(&c->erasable_pending_wbuf_list)) {
  551. printk(JFFS2_DBG "erasable_pending_wbuf_list: empty\n");
  552. } else {
  553. struct list_head *this;
  554. list_for_each(this, &c->erasable_pending_wbuf_list) {
  555. struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list);
  556. if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) {
  557. printk(JFFS2_DBG "erasable_pending_wbuf_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, unchecked %#08x, free %#08x)\n",
  558. jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size,
  559. jeb->unchecked_size, jeb->free_size);
  560. }
  561. }
  562. }
  563. if (list_empty(&c->free_list)) {
  564. printk(JFFS2_DBG "free_list: empty\n");
  565. } else {
  566. struct list_head *this;
  567. list_for_each(this, &c->free_list) {
  568. struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list);
  569. if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) {
  570. printk(JFFS2_DBG "free_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, unchecked %#08x, free %#08x)\n",
  571. jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size,
  572. jeb->unchecked_size, jeb->free_size);
  573. }
  574. }
  575. }
  576. if (list_empty(&c->bad_list)) {
  577. printk(JFFS2_DBG "bad_list: empty\n");
  578. } else {
  579. struct list_head *this;
  580. list_for_each(this, &c->bad_list) {
  581. struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list);
  582. if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) {
  583. printk(JFFS2_DBG "bad_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, unchecked %#08x, free %#08x)\n",
  584. jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size,
  585. jeb->unchecked_size, jeb->free_size);
  586. }
  587. }
  588. }
  589. if (list_empty(&c->bad_used_list)) {
  590. printk(JFFS2_DBG "bad_used_list: empty\n");
  591. } else {
  592. struct list_head *this;
  593. list_for_each(this, &c->bad_used_list) {
  594. struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list);
  595. if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) {
  596. printk(JFFS2_DBG "bad_used_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, unchecked %#08x, free %#08x)\n",
  597. jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size,
  598. jeb->unchecked_size, jeb->free_size);
  599. }
  600. }
  601. }
  602. }
  603. void
  604. __jffs2_dbg_dump_fragtree(struct jffs2_inode_info *f)
  605. {
  606. mutex_lock(&f->sem);
  607. jffs2_dbg_dump_fragtree_nolock(f);
  608. mutex_unlock(&f->sem);
  609. }
  610. void
  611. __jffs2_dbg_dump_fragtree_nolock(struct jffs2_inode_info *f)
  612. {
  613. struct jffs2_node_frag *this = frag_first(&f->fragtree);
  614. uint32_t lastofs = 0;
  615. int buggy = 0;
  616. printk(JFFS2_DBG_MSG_PREFIX " dump fragtree of ino #%u\n", f->inocache->ino);
  617. while(this) {
  618. if (this->node)
  619. printk(JFFS2_DBG "frag %#04x-%#04x: %#08x(%d) on flash (*%p), left (%p), right (%p), parent (%p)\n",
  620. this->ofs, this->ofs+this->size, ref_offset(this->node->raw),
  621. ref_flags(this->node->raw), this, frag_left(this), frag_right(this),
  622. frag_parent(this));
  623. else
  624. printk(JFFS2_DBG "frag %#04x-%#04x: hole (*%p). left (%p), right (%p), parent (%p)\n",
  625. this->ofs, this->ofs+this->size, this, frag_left(this),
  626. frag_right(this), frag_parent(this));
  627. if (this->ofs != lastofs)
  628. buggy = 1;
  629. lastofs = this->ofs + this->size;
  630. this = frag_next(this);
  631. }
  632. if (f->metadata)
  633. printk(JFFS2_DBG "metadata at 0x%08x\n", ref_offset(f->metadata->raw));
  634. if (buggy) {
  635. JFFS2_ERROR("frag tree got a hole in it.\n");
  636. BUG();
  637. }
  638. }
  639. #define JFFS2_BUFDUMP_BYTES_PER_LINE 32
  640. void
  641. __jffs2_dbg_dump_buffer(unsigned char *buf, int len, uint32_t offs)
  642. {
  643. int skip;
  644. int i;
  645. printk(JFFS2_DBG_MSG_PREFIX " dump from offset %#08x to offset %#08x (%x bytes).\n",
  646. offs, offs + len, len);
  647. i = skip = offs % JFFS2_BUFDUMP_BYTES_PER_LINE;
  648. offs = offs & ~(JFFS2_BUFDUMP_BYTES_PER_LINE - 1);
  649. if (skip != 0)
  650. printk(JFFS2_DBG "%#08x: ", offs);
  651. while (skip--)
  652. printk(" ");
  653. while (i < len) {
  654. if ((i % JFFS2_BUFDUMP_BYTES_PER_LINE) == 0 && i != len -1) {
  655. if (i != 0)
  656. printk("\n");
  657. offs += JFFS2_BUFDUMP_BYTES_PER_LINE;
  658. printk(JFFS2_DBG "%0#8x: ", offs);
  659. }
  660. printk("%02x ", buf[i]);
  661. i += 1;
  662. }
  663. printk("\n");
  664. }
  665. /*
  666. * Dump a JFFS2 node.
  667. */
  668. void
  669. __jffs2_dbg_dump_node(struct jffs2_sb_info *c, uint32_t ofs)
  670. {
  671. union jffs2_node_union node;
  672. int len = sizeof(union jffs2_node_union);
  673. size_t retlen;
  674. uint32_t crc;
  675. int ret;
  676. printk(JFFS2_DBG_MSG_PREFIX " dump node at offset %#08x.\n", ofs);
  677. ret = jffs2_flash_read(c, ofs, len, &retlen, (unsigned char *)&node);
  678. if (ret || (retlen != len)) {
  679. JFFS2_ERROR("read %d bytes failed or short. ret %d, retlen %zd.\n",
  680. len, ret, retlen);
  681. return;
  682. }
  683. printk(JFFS2_DBG "magic:\t%#04x\n", je16_to_cpu(node.u.magic));
  684. printk(JFFS2_DBG "nodetype:\t%#04x\n", je16_to_cpu(node.u.nodetype));
  685. printk(JFFS2_DBG "totlen:\t%#08x\n", je32_to_cpu(node.u.totlen));
  686. printk(JFFS2_DBG "hdr_crc:\t%#08x\n", je32_to_cpu(node.u.hdr_crc));
  687. crc = crc32(0, &node.u, sizeof(node.u) - 4);
  688. if (crc != je32_to_cpu(node.u.hdr_crc)) {
  689. JFFS2_ERROR("wrong common header CRC.\n");
  690. return;
  691. }
  692. if (je16_to_cpu(node.u.magic) != JFFS2_MAGIC_BITMASK &&
  693. je16_to_cpu(node.u.magic) != JFFS2_OLD_MAGIC_BITMASK)
  694. {
  695. JFFS2_ERROR("wrong node magic: %#04x instead of %#04x.\n",
  696. je16_to_cpu(node.u.magic), JFFS2_MAGIC_BITMASK);
  697. return;
  698. }
  699. switch(je16_to_cpu(node.u.nodetype)) {
  700. case JFFS2_NODETYPE_INODE:
  701. printk(JFFS2_DBG "the node is inode node\n");
  702. printk(JFFS2_DBG "ino:\t%#08x\n", je32_to_cpu(node.i.ino));
  703. printk(JFFS2_DBG "version:\t%#08x\n", je32_to_cpu(node.i.version));
  704. printk(JFFS2_DBG "mode:\t%#08x\n", node.i.mode.m);
  705. printk(JFFS2_DBG "uid:\t%#04x\n", je16_to_cpu(node.i.uid));
  706. printk(JFFS2_DBG "gid:\t%#04x\n", je16_to_cpu(node.i.gid));
  707. printk(JFFS2_DBG "isize:\t%#08x\n", je32_to_cpu(node.i.isize));
  708. printk(JFFS2_DBG "atime:\t%#08x\n", je32_to_cpu(node.i.atime));
  709. printk(JFFS2_DBG "mtime:\t%#08x\n", je32_to_cpu(node.i.mtime));
  710. printk(JFFS2_DBG "ctime:\t%#08x\n", je32_to_cpu(node.i.ctime));
  711. printk(JFFS2_DBG "offset:\t%#08x\n", je32_to_cpu(node.i.offset));
  712. printk(JFFS2_DBG "csize:\t%#08x\n", je32_to_cpu(node.i.csize));
  713. printk(JFFS2_DBG "dsize:\t%#08x\n", je32_to_cpu(node.i.dsize));
  714. printk(JFFS2_DBG "compr:\t%#02x\n", node.i.compr);
  715. printk(JFFS2_DBG "usercompr:\t%#02x\n", node.i.usercompr);
  716. printk(JFFS2_DBG "flags:\t%#04x\n", je16_to_cpu(node.i.flags));
  717. printk(JFFS2_DBG "data_crc:\t%#08x\n", je32_to_cpu(node.i.data_crc));
  718. printk(JFFS2_DBG "node_crc:\t%#08x\n", je32_to_cpu(node.i.node_crc));
  719. crc = crc32(0, &node.i, sizeof(node.i) - 8);
  720. if (crc != je32_to_cpu(node.i.node_crc)) {
  721. JFFS2_ERROR("wrong node header CRC.\n");
  722. return;
  723. }
  724. break;
  725. case JFFS2_NODETYPE_DIRENT:
  726. printk(JFFS2_DBG "the node is dirent node\n");
  727. printk(JFFS2_DBG "pino:\t%#08x\n", je32_to_cpu(node.d.pino));
  728. printk(JFFS2_DBG "version:\t%#08x\n", je32_to_cpu(node.d.version));
  729. printk(JFFS2_DBG "ino:\t%#08x\n", je32_to_cpu(node.d.ino));
  730. printk(JFFS2_DBG "mctime:\t%#08x\n", je32_to_cpu(node.d.mctime));
  731. printk(JFFS2_DBG "nsize:\t%#02x\n", node.d.nsize);
  732. printk(JFFS2_DBG "type:\t%#02x\n", node.d.type);
  733. printk(JFFS2_DBG "node_crc:\t%#08x\n", je32_to_cpu(node.d.node_crc));
  734. printk(JFFS2_DBG "name_crc:\t%#08x\n", je32_to_cpu(node.d.name_crc));
  735. node.d.name[node.d.nsize] = '\0';
  736. printk(JFFS2_DBG "name:\t\"%s\"\n", node.d.name);
  737. crc = crc32(0, &node.d, sizeof(node.d) - 8);
  738. if (crc != je32_to_cpu(node.d.node_crc)) {
  739. JFFS2_ERROR("wrong node header CRC.\n");
  740. return;
  741. }
  742. break;
  743. default:
  744. printk(JFFS2_DBG "node type is unknown\n");
  745. break;
  746. }
  747. }
  748. #endif /* JFFS2_DBG_DUMPS || JFFS2_DBG_PARANOIA_CHECKS */