ad0ac0c23ee4c2cb24ea7c19654e58ab7fe3de90
[openwrt.git] / target / linux / generic-2.4 / patches / 227-jffs2_eofdetect.patch
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
4 @@ -31,6 +31,10 @@
5   * provisions above, a recipient may use your version of this file
6   * under either the RHEPL or the GPL.
7   *
8 + * Modification for automatically cleaning the filesystem after
9 + * a specially marked block
10 + * Copyright (C) 2006 Felix Fietkau <nbd@openwrt.org>
11 + *
12   * $Id: scan.c,v 1.51.2.4 2003/11/02 13:51:18 dwmw2 Exp $
13   *
14   */
15 @@ -88,7 +92,12 @@
16         for (i=0; i<c->nr_blocks; i++) {
17                 struct jffs2_eraseblock *jeb = &c->blocks[i];
18  
19 -               ret = jffs2_scan_eraseblock(c, jeb);
20 +
21 +               if (c->flags & (1 << 7))
22 +                       ret = 1;
23 +               else
24 +                       ret = jffs2_scan_eraseblock(c, jeb);
25 +
26                 if (ret < 0)
27                         return ret;
28  
29 @@ -145,15 +154,23 @@
30                         c->nr_erasing_blocks++;
31                 }
32         }
33 -       /* Rotate the lists by some number to ensure wear levelling */
34 -       jffs2_rotate_lists(c);
35  
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");
39 -                       return -EIO;
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");
45 +       } else {
46 +               /* Rotate the lists by some number to ensure wear levelling */
47 +               jffs2_rotate_lists(c);
48 +
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");
52 +                               return -EIO;
53 +                       }
54 +                       jffs2_erase_pending_trigger(c);
55                 }
56 -               jffs2_erase_pending_trigger(c);
57         }
58         return 0;
59  }
60 @@ -181,6 +197,7 @@
61  
62         while(ofs < jeb->offset + c->sector_size) {
63                 ssize_t retlen;
64 +               unsigned char *buf = (unsigned char *) &node;
65                 ACCT_PARANOIA_CHECK(jeb);
66                 
67                 if (ofs & 3) {
68 @@ -202,8 +219,18 @@
69                         break;
70                 }
71  
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) &&
75 +                       (buf[1] == 0xad) &&
76 +                       (buf[2] == 0xc0) &&
77 +                       (buf[3] == 0xde)) {
78 +                               
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);
82                 
83 +                       return 1;
84 +               }
85                 if (err) {
86                         D1(printk(KERN_WARNING "mtd->read(0x%x bytes from 0x%x) returned %d\n", sizeof(node), ofs, err));
87                         return err;
88