Merge pull request #580 from wigyori/cc-libpcap
[15.05/openwrt.git] / target / linux / generic / patches-3.18 / 532-jffs2_eofdetect.patch
1 --- a/fs/jffs2/build.c
2 +++ b/fs/jffs2/build.c
3 @@ -114,6 +114,16 @@ static int jffs2_build_filesystem(struct
4         dbg_fsbuild("scanned flash completely\n");
5         jffs2_dbg_dump_block_lists_nolock(c);
6  
7 +       if (c->flags & (1 << 7)) {
8 +               printk("%s(): unlocking the mtd device... ", __func__);
9 +               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 @@ -148,8 +148,14 @@ int jffs2_scan_medium(struct jffs2_sb_in
23                 /* reset summary info for next eraseblock scan */
24                 jffs2_sum_reset_collected(s);
25  
26 -               ret = jffs2_scan_eraseblock(c, jeb, buf_size?flashbuf:(flashbuf+jeb->offset),
27 -                                               buf_size, s);
28 +               if (c->flags & (1 << 7)) {
29 +                       if (mtd_block_isbad(c->mtd, jeb->offset))
30 +                               ret = BLK_STATE_BADBLOCK;
31 +                       else
32 +                               ret = BLK_STATE_ALLFF;
33 +               } else
34 +                       ret = jffs2_scan_eraseblock(c, jeb, buf_size?flashbuf:(flashbuf+jeb->offset),
35 +                                                       buf_size, s);
36  
37                 if (ret < 0)
38                         goto out;
39 @@ -561,6 +567,17 @@ full_scan:
40                         return err;
41         }
42  
43 +       if ((buf[0] == 0xde) &&
44 +               (buf[1] == 0xad) &&
45 +               (buf[2] == 0xc0) &&
46 +               (buf[3] == 0xde)) {
47 +               /* end of filesystem. erase everything after this point */
48 +               printk("%s(): End of filesystem marker found at 0x%x\n", __func__, jeb->offset);
49 +               c->flags |= (1 << 7);
50 +
51 +               return BLK_STATE_ALLFF;
52 +       }
53 +
54         /* We temporarily use 'ofs' as a pointer into the buffer/jeb */
55         ofs = 0;
56         max_ofs = EMPTY_SCAN_SIZE(c->sector_size);