1 diff -ur linux.old/fs/jffs2/scan.c linux.dev/fs/jffs2/scan.c
2 --- linux.old/fs/jffs2/scan.c 2003-11-28 19:26:21.000000000 +0100
3 +++ linux.dev/fs/jffs2/scan.c 2006-06-22 00:29:02.000000000 +0200
5 * provisions above, a recipient may use your version of this file
6 * under either the RHEPL or the GPL.
8 + * Modification for automatically cleaning the filesystem after
9 + * a specially marked block
10 + * Copyright (C) 2006 Felix Fietkau <nbd@openwrt.org>
12 * $Id: scan.c,v 1.51.2.4 2003/11/02 13:51:18 dwmw2 Exp $
16 for (i=0; i<c->nr_blocks; i++) {
17 struct jffs2_eraseblock *jeb = &c->blocks[i];
19 - ret = jffs2_scan_eraseblock(c, jeb);
21 + if (c->flags & (1 << 7))
24 + ret = jffs2_scan_eraseblock(c, jeb);
30 c->nr_erasing_blocks++;
33 - /* Rotate the lists by some number to ensure wear levelling */
34 - jffs2_rotate_lists(c);
36 - if (c->nr_erasing_blocks) {
37 - if (!c->used_size && empty_blocks != c->nr_blocks) {
38 - printk(KERN_NOTICE "Cowardly refusing to erase blocks on filesystem with no valid JFFS2 nodes\n");
40 + if (c->flags & (1 << 7)) {
41 + printk("jffs2_scan_medium(): erasing all blocks after the end marker...\n");
42 + jffs2_erase_pending_blocks(c);
43 + jffs2_mark_erased_blocks(c);
44 + printk("jffs2_scan_medium(): done.\n");
46 + /* Rotate the lists by some number to ensure wear levelling */
47 + jffs2_rotate_lists(c);
49 + if (c->nr_erasing_blocks) {
50 + if (!c->used_size && empty_blocks != c->nr_blocks) {
51 + printk(KERN_NOTICE "Cowardly refusing to erase blocks on filesystem with no valid JFFS2 nodes\n");
54 + jffs2_erase_pending_trigger(c);
56 - jffs2_erase_pending_trigger(c);
62 while(ofs < jeb->offset + c->sector_size) {
64 + unsigned char *buf = (unsigned char *) &node;
65 ACCT_PARANOIA_CHECK(jeb);
72 - err = c->mtd->read(c->mtd, ofs, sizeof(node), &retlen, (char *)&node);
73 + err = c->mtd->read(c->mtd, ofs, sizeof(node), &retlen, buf);
74 + if ((buf[0] == 0xde) &&
79 + /* end of filesystem. erase everything after this point */
80 + c->flags |= (1 << 7);
81 + printk("jffs2_scan_eraseblock(): End of filesystem marker found at 0x%x\n", jeb->offset);
86 D1(printk(KERN_WARNING "mtd->read(0x%x bytes from 0x%x) returned %d\n", sizeof(node), ofs, err));