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);
7 + if (c->flags & (1 << 7)) {
8 + printk("%s(): unlocking the mtd device... ", __func__);
10 + c->mtd->unlock(c->mtd, 0, c->mtd->size);
13 + printk("%s(): erasing all blocks after the end marker... ", __func__);
14 + jffs2_erase_pending_blocks(c, -1);
18 dbg_fsbuild("pass 1 starting\n");
19 c->flags |= JFFS2_SB_FLAG_BUILDING;
20 /* Now scan the directory tree, increasing nlink according to every dirent found. */
23 @@ -72,7 +72,7 @@ static int file_dirty(struct jffs2_sb_in
25 if ((ret = jffs2_scan_dirty_space(c, jeb, jeb->free_size)))
27 - /* Turned wasted size into dirty, since we apparently
28 + /* Turned wasted size into dirty, since we apparently
29 think it's recoverable now. */
30 jeb->dirty_size += jeb->wasted_size;
31 c->dirty_size += jeb->wasted_size;
32 @@ -147,8 +147,11 @@ int jffs2_scan_medium(struct jffs2_sb_in
33 /* reset summary info for next eraseblock scan */
34 jffs2_sum_reset_collected(s);
36 - ret = jffs2_scan_eraseblock(c, jeb, buf_size?flashbuf:(flashbuf+jeb->offset),
38 + if (c->flags & (1 << 7))
39 + ret = BLK_STATE_ALLFF;
41 + ret = jffs2_scan_eraseblock(c, jeb, buf_size?flashbuf:(flashbuf+jeb->offset),
46 @@ -403,7 +406,7 @@ static int jffs2_scan_xref_node(struct j
50 - /* BEFORE jffs2_build_xattr_subsystem() called,
51 + /* BEFORE jffs2_build_xattr_subsystem() called,
52 * and AFTER xattr_ref is marked as a dead xref,
53 * ref->xid is used to store 32bit xid, xd is not used
54 * ref->ino is used to store 32bit inode-number, ic is not used
55 @@ -476,7 +479,7 @@ static int jffs2_scan_eraseblock (struct
56 struct jffs2_sum_marker *sm;
62 /* XIP case. Just look, point at the summary if it's there */
63 sm = (void *)buf + c->sector_size - sizeof(*sm);
64 @@ -492,9 +495,9 @@ static int jffs2_scan_eraseblock (struct
65 buf_len = sizeof(*sm);
67 /* Read as much as we want into the _end_ of the preallocated buffer */
68 - err = jffs2_fill_scan_buf(c, buf + buf_size - buf_len,
69 + err = jffs2_fill_scan_buf(c, buf + buf_size - buf_len,
70 jeb->offset + c->sector_size - buf_len,
76 @@ -513,9 +516,9 @@ static int jffs2_scan_eraseblock (struct
78 if (buf_len < sumlen) {
79 /* Need to read more so that the entire summary node is present */
80 - err = jffs2_fill_scan_buf(c, sumptr,
81 + err = jffs2_fill_scan_buf(c, sumptr,
82 jeb->offset + c->sector_size - sumlen,
88 @@ -528,7 +531,7 @@ static int jffs2_scan_eraseblock (struct
90 if (buf_size && sumlen > buf_size)
92 - /* If it returns with a real error, bail.
93 + /* If it returns with a real error, bail.
94 If it returns positive, that's a block classification
95 (i.e. BLK_STATE_xxx) so return that too.
96 If it returns zero, fall through to full scan. */
97 @@ -549,6 +552,17 @@ static int jffs2_scan_eraseblock (struct
101 + if ((buf[0] == 0xde) &&
102 + (buf[1] == 0xad) &&
103 + (buf[2] == 0xc0) &&
104 + (buf[3] == 0xde)) {
105 + /* end of filesystem. erase everything after this point */
106 + printk("%s(): End of filesystem marker found at 0x%x\n", __func__, jeb->offset);
107 + c->flags |= (1 << 7);
109 + return BLK_STATE_ALLFF;
112 /* We temporarily use 'ofs' as a pointer into the buffer/jeb */
114 max_ofs = EMPTY_SCAN_SIZE(c->sector_size);
115 @@ -674,7 +688,7 @@ scan_more:
121 /* See how much more there is to read in this eraseblock... */
122 buf_len = min_t(uint32_t, buf_size, jeb->offset + c->sector_size - ofs);
124 @@ -910,7 +924,7 @@ scan_more:
126 D1(printk(KERN_DEBUG "Block at 0x%08x: free 0x%08x, dirty 0x%08x, unchecked 0x%08x, used 0x%08x, wasted 0x%08x\n",
127 jeb->offset,jeb->free_size, jeb->dirty_size, jeb->unchecked_size, jeb->used_size, jeb->wasted_size));
130 /* mark_node_obsolete can add to wasted !! */
131 if (jeb->wasted_size) {
132 jeb->dirty_size += jeb->wasted_size;