debug.c 21 KB

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