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