204-jffs2_eofdetect.patch 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. --- a/fs/jffs2/build.c
  2. +++ b/fs/jffs2/build.c
  3. @@ -112,6 +112,17 @@ static int jffs2_build_filesystem(struct
  4. dbg_fsbuild("scanned flash completely\n");
  5. jffs2_dbg_dump_block_lists_nolock(c);
  6. + if (c->flags & (1 << 7)) {
  7. + printk("%s(): unlocking the mtd device... ", __func__);
  8. + if (c->mtd->unlock)
  9. + c->mtd->unlock(c->mtd, 0, c->mtd->size);
  10. + printk("done.\n");
  11. +
  12. + printk("%s(): erasing all blocks after the end marker... ", __func__);
  13. + jffs2_erase_pending_blocks(c, -1);
  14. + printk("done.\n");
  15. + }
  16. +
  17. dbg_fsbuild("pass 1 starting\n");
  18. c->flags |= JFFS2_SB_FLAG_BUILDING;
  19. /* Now scan the directory tree, increasing nlink according to every dirent found. */
  20. --- a/fs/jffs2/scan.c
  21. +++ b/fs/jffs2/scan.c
  22. @@ -72,7 +72,7 @@ static int file_dirty(struct jffs2_sb_in
  23. return ret;
  24. if ((ret = jffs2_scan_dirty_space(c, jeb, jeb->free_size)))
  25. return ret;
  26. - /* Turned wasted size into dirty, since we apparently
  27. + /* Turned wasted size into dirty, since we apparently
  28. think it's recoverable now. */
  29. jeb->dirty_size += jeb->wasted_size;
  30. c->dirty_size += jeb->wasted_size;
  31. @@ -144,8 +144,11 @@ int jffs2_scan_medium(struct jffs2_sb_in
  32. /* reset summary info for next eraseblock scan */
  33. jffs2_sum_reset_collected(s);
  34. - ret = jffs2_scan_eraseblock(c, jeb, buf_size?flashbuf:(flashbuf+jeb->offset),
  35. - buf_size, s);
  36. + if (c->flags & (1 << 7))
  37. + ret = BLK_STATE_ALLFF;
  38. + else
  39. + ret = jffs2_scan_eraseblock(c, jeb, buf_size?flashbuf:(flashbuf+jeb->offset),
  40. + buf_size, s);
  41. if (ret < 0)
  42. goto out;
  43. @@ -402,7 +405,7 @@ static int jffs2_scan_xref_node(struct j
  44. if (!ref)
  45. return -ENOMEM;
  46. - /* BEFORE jffs2_build_xattr_subsystem() called,
  47. + /* BEFORE jffs2_build_xattr_subsystem() called,
  48. * and AFTER xattr_ref is marked as a dead xref,
  49. * ref->xid is used to store 32bit xid, xd is not used
  50. * ref->ino is used to store 32bit inode-number, ic is not used
  51. @@ -475,7 +478,7 @@ static int jffs2_scan_eraseblock (struct
  52. struct jffs2_sum_marker *sm;
  53. void *sumptr = NULL;
  54. uint32_t sumlen;
  55. -
  56. +
  57. if (!buf_size) {
  58. /* XIP case. Just look, point at the summary if it's there */
  59. sm = (void *)buf + c->sector_size - sizeof(*sm);
  60. @@ -491,9 +494,9 @@ static int jffs2_scan_eraseblock (struct
  61. buf_len = sizeof(*sm);
  62. /* Read as much as we want into the _end_ of the preallocated buffer */
  63. - err = jffs2_fill_scan_buf(c, buf + buf_size - buf_len,
  64. + err = jffs2_fill_scan_buf(c, buf + buf_size - buf_len,
  65. jeb->offset + c->sector_size - buf_len,
  66. - buf_len);
  67. + buf_len);
  68. if (err)
  69. return err;
  70. @@ -512,9 +515,9 @@ static int jffs2_scan_eraseblock (struct
  71. }
  72. if (buf_len < sumlen) {
  73. /* Need to read more so that the entire summary node is present */
  74. - err = jffs2_fill_scan_buf(c, sumptr,
  75. + err = jffs2_fill_scan_buf(c, sumptr,
  76. jeb->offset + c->sector_size - sumlen,
  77. - sumlen - buf_len);
  78. + sumlen - buf_len);
  79. if (err)
  80. return err;
  81. }
  82. @@ -527,7 +530,7 @@ static int jffs2_scan_eraseblock (struct
  83. if (buf_size && sumlen > buf_size)
  84. kfree(sumptr);
  85. - /* If it returns with a real error, bail.
  86. + /* If it returns with a real error, bail.
  87. If it returns positive, that's a block classification
  88. (i.e. BLK_STATE_xxx) so return that too.
  89. If it returns zero, fall through to full scan. */
  90. @@ -548,6 +551,17 @@ static int jffs2_scan_eraseblock (struct
  91. return err;
  92. }
  93. + if ((buf[0] == 0xde) &&
  94. + (buf[1] == 0xad) &&
  95. + (buf[2] == 0xc0) &&
  96. + (buf[3] == 0xde)) {
  97. + /* end of filesystem. erase everything after this point */
  98. + printk("%s(): End of filesystem marker found at 0x%x\n", __func__, jeb->offset);
  99. + c->flags |= (1 << 7);
  100. +
  101. + return BLK_STATE_ALLFF;
  102. + }
  103. +
  104. /* We temporarily use 'ofs' as a pointer into the buffer/jeb */
  105. ofs = 0;
  106. max_ofs = EMPTY_SCAN_SIZE(c->sector_size);
  107. @@ -673,7 +687,7 @@ scan_more:
  108. scan_end = buf_len;
  109. goto more_empty;
  110. }
  111. -
  112. +
  113. /* See how much more there is to read in this eraseblock... */
  114. buf_len = min_t(uint32_t, buf_size, jeb->offset + c->sector_size - ofs);
  115. if (!buf_len) {
  116. @@ -909,7 +923,7 @@ scan_more:
  117. D1(printk(KERN_DEBUG "Block at 0x%08x: free 0x%08x, dirty 0x%08x, unchecked 0x%08x, used 0x%08x, wasted 0x%08x\n",
  118. jeb->offset,jeb->free_size, jeb->dirty_size, jeb->unchecked_size, jeb->used_size, jeb->wasted_size));
  119. -
  120. +
  121. /* mark_node_obsolete can add to wasted !! */
  122. if (jeb->wasted_size) {
  123. jeb->dirty_size += jeb->wasted_size;