4 * provisions above, a recipient may use your version of this file
5 * under either the RHEPL or the GPL.
7 + * Modification for automatically cleaning the filesystem after
8 + * a specially marked block
9 + * Copyright (C) 2006 Felix Fietkau <nbd@openwrt.org>
11 * $Id: build.c,v 1.16.2.3 2003/04/30 09:43:32 dwmw2 Exp $
15 #include <linux/kernel.h>
16 #include <linux/jffs2.h>
17 #include <linux/slab.h>
18 +#include <linux/mtd/mtd.h>
21 int jffs2_build_inode_pass1(struct jffs2_sb_info *, struct jffs2_inode_cache *);
22 @@ -89,6 +94,18 @@ int jffs2_build_filesystem(struct jffs2_
26 + if (c->flags & (1 << 7)) {
27 + printk("%s(): unlocking the mtd device... ", __func__);
29 + c->mtd->unlock(c->mtd, 0, c->mtd->size);
32 + printk("%s(): erasing all blocks after the end marker... ", __func__);
33 + jffs2_erase_pending_blocks(c);
34 + jffs2_mark_erased_blocks(c);
38 D1(printk(KERN_DEBUG "Scanned flash completely\n"));
39 /* Now build the data map for each inode, marking obsoleted nodes
40 as such, and also increase nlink of any children. */
44 * provisions above, a recipient may use your version of this file
45 * under either the RHEPL or the GPL.
47 + * Modification for automatically cleaning the filesystem after
48 + * a specially marked block
49 + * Copyright (C) 2006 Felix Fietkau <nbd@openwrt.org>
51 * $Id: scan.c,v 1.51.2.4 2003/11/02 13:51:18 dwmw2 Exp $
54 @@ -88,7 +92,12 @@ int jffs2_scan_medium(struct jffs2_sb_in
55 for (i=0; i<c->nr_blocks; i++) {
56 struct jffs2_eraseblock *jeb = &c->blocks[i];
58 - ret = jffs2_scan_eraseblock(c, jeb);
60 + if (c->flags & (1 << 7))
63 + ret = jffs2_scan_eraseblock(c, jeb);
68 @@ -181,6 +190,7 @@ static int jffs2_scan_eraseblock (struct
70 while(ofs < jeb->offset + c->sector_size) {
72 + unsigned char *buf = (unsigned char *) &node;
73 ACCT_PARANOIA_CHECK(jeb);
76 @@ -202,8 +212,18 @@ static int jffs2_scan_eraseblock (struct
80 - err = c->mtd->read(c->mtd, ofs, sizeof(node), &retlen, (char *)&node);
81 + err = c->mtd->read(c->mtd, ofs, sizeof(node), &retlen, buf);
82 + if ((buf[0] == 0xde) &&
87 + /* end of filesystem. erase everything after this point */
88 + c->flags |= (1 << 7);
89 + printk("jffs2_scan_eraseblock(): End of filesystem marker found at 0x%x\n", jeb->offset);
94 D1(printk(KERN_WARNING "mtd->read(0x%x bytes from 0x%x) returned %d\n", sizeof(node), ofs, err));