532-jffs2_eofdetect.patch 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. From: Felix Fietkau <nbd@nbd.name>
  2. Subject: fs: jffs2: EOF marker
  3. Signed-off-by: Felix Fietkau <nbd@nbd.name>
  4. ---
  5. fs/jffs2/build.c | 10 ++++++++++
  6. fs/jffs2/scan.c | 21 +++++++++++++++++++--
  7. 2 files changed, 29 insertions(+), 2 deletions(-)
  8. --- a/fs/jffs2/build.c
  9. +++ b/fs/jffs2/build.c
  10. @@ -117,6 +117,16 @@ static int jffs2_build_filesystem(struct
  11. dbg_fsbuild("scanned flash completely\n");
  12. jffs2_dbg_dump_block_lists_nolock(c);
  13. + if (c->flags & (1 << 7)) {
  14. + printk("%s(): unlocking the mtd device... ", __func__);
  15. + mtd_unlock(c->mtd, 0, c->mtd->size);
  16. + printk("done.\n");
  17. +
  18. + printk("%s(): erasing all blocks after the end marker... ", __func__);
  19. + jffs2_erase_pending_blocks(c, -1);
  20. + printk("done.\n");
  21. + }
  22. +
  23. dbg_fsbuild("pass 1 starting\n");
  24. c->flags |= JFFS2_SB_FLAG_BUILDING;
  25. /* Now scan the directory tree, increasing nlink according to every dirent found. */
  26. --- a/fs/jffs2/scan.c
  27. +++ b/fs/jffs2/scan.c
  28. @@ -148,8 +148,14 @@ int jffs2_scan_medium(struct jffs2_sb_in
  29. /* reset summary info for next eraseblock scan */
  30. jffs2_sum_reset_collected(s);
  31. - ret = jffs2_scan_eraseblock(c, jeb, buf_size?flashbuf:(flashbuf+jeb->offset),
  32. - buf_size, s);
  33. + if (c->flags & (1 << 7)) {
  34. + if (mtd_block_isbad(c->mtd, jeb->offset))
  35. + ret = BLK_STATE_BADBLOCK;
  36. + else
  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. @@ -561,6 +567,17 @@ full_scan:
  44. return err;
  45. }
  46. + if ((buf[0] == 0xde) &&
  47. + (buf[1] == 0xad) &&
  48. + (buf[2] == 0xc0) &&
  49. + (buf[3] == 0xde)) {
  50. + /* end of filesystem. erase everything after this point */
  51. + printk("%s(): End of filesystem marker found at 0x%x\n", __func__, jeb->offset);
  52. + c->flags |= (1 << 7);
  53. +
  54. + return BLK_STATE_ALLFF;
  55. + }
  56. +
  57. /* We temporarily use 'ofs' as a pointer into the buffer/jeb */
  58. ofs = 0;
  59. max_ofs = EMPTY_SCAN_SIZE(c->sector_size);