1 From: Felix Fietkau <nbd@nbd.name>
2 Subject: fs: jffs2: EOF marker
4 Signed-off-by: Felix Fietkau <nbd@nbd.name>
6 fs/jffs2/build.c | 10 ++++++++++
7 fs/jffs2/scan.c | 21 +++++++++++++++++++--
8 2 files changed, 29 insertions(+), 2 deletions(-)
10 diff --git a/fs/jffs2/build.c b/fs/jffs2/build.c
11 index b288c8ae1236..e768f9d41661 100644
12 --- a/fs/jffs2/build.c
13 +++ b/fs/jffs2/build.c
14 @@ -117,6 +117,16 @@ static int jffs2_build_filesystem(struct jffs2_sb_info *c)
15 dbg_fsbuild("scanned flash completely\n");
16 jffs2_dbg_dump_block_lists_nolock(c);
18 + if (c->flags & (1 << 7)) {
19 + printk("%s(): unlocking the mtd device... ", __func__);
20 + mtd_unlock(c->mtd, 0, c->mtd->size);
23 + printk("%s(): erasing all blocks after the end marker... ", __func__);
24 + jffs2_erase_pending_blocks(c, -1);
28 dbg_fsbuild("pass 1 starting\n");
29 c->flags |= JFFS2_SB_FLAG_BUILDING;
30 /* Now scan the directory tree, increasing nlink according to every dirent found. */
31 diff --git a/fs/jffs2/scan.c b/fs/jffs2/scan.c
32 index 90431dd613b8..8c78ab19cdab 100644
35 @@ -148,8 +148,14 @@ int jffs2_scan_medium(struct jffs2_sb_info *c)
36 /* reset summary info for next eraseblock scan */
37 jffs2_sum_reset_collected(s);
39 - ret = jffs2_scan_eraseblock(c, jeb, buf_size?flashbuf:(flashbuf+jeb->offset),
41 + if (c->flags & (1 << 7)) {
42 + if (mtd_block_isbad(c->mtd, jeb->offset))
43 + ret = BLK_STATE_BADBLOCK;
45 + ret = BLK_STATE_ALLFF;
47 + ret = jffs2_scan_eraseblock(c, jeb, buf_size?flashbuf:(flashbuf+jeb->offset),
52 @@ -561,6 +567,17 @@ static int jffs2_scan_eraseblock (struct jffs2_sb_info *c, struct jffs2_eraseblo
56 + if ((buf[0] == 0xde) &&
60 + /* end of filesystem. erase everything after this point */
61 + printk("%s(): End of filesystem marker found at 0x%x\n", __func__, jeb->offset);
62 + c->flags |= (1 << 7);
64 + return BLK_STATE_ALLFF;
67 /* We temporarily use 'ofs' as a pointer into the buffer/jeb */
69 max_ofs = EMPTY_SCAN_SIZE(c->sector_size);