backport jffs2 eofdetect patch to linux 2.4
[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,22 @@
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 + printk("jffs2_scan_medium(): done.\n");
44 + } else {
45 + /* Rotate the lists by some number to ensure wear levelling */
46 + jffs2_rotate_lists(c);
47 +
48 + if (c->nr_erasing_blocks) {
49 + if (!c->used_size && empty_blocks != c->nr_blocks) {
50 + printk(KERN_NOTICE "Cowardly refusing to erase blocks on filesystem with no valid JFFS2 nodes\n");
51 + return -EIO;
52 + }
53 + jffs2_erase_pending_trigger(c);
54 }
55 - jffs2_erase_pending_trigger(c);
56 }
57 return 0;
58 }
59 @@ -181,6 +197,7 @@
60
61 while(ofs < jeb->offset + c->sector_size) {
62 ssize_t retlen;
63 + unsigned char *buf = (unsigned char *) &node;
64 ACCT_PARANOIA_CHECK(jeb);
65
66 if (ofs & 3) {
67 @@ -202,8 +219,18 @@
68 break;
69 }
70
71 - err = c->mtd->read(c->mtd, ofs, sizeof(node), &retlen, (char *)&node);
72 + err = c->mtd->read(c->mtd, ofs, sizeof(node), &retlen, buf);
73 + if ((buf[0] == 0xde) &&
74 + (buf[1] == 0xad) &&
75 + (buf[2] == 0xc0) &&
76 + (buf[3] == 0xde)) {
77 +
78 + /* end of filesystem. erase everything after this point */
79 + c->flags |= (1 << 7);
80 + printk("jffs2_scan_eraseblock(): End of filesystem marker found at 0x%x\n", jeb->offset);
81
82 + return 1;
83 + }
84 if (err) {
85 D1(printk(KERN_WARNING "mtd->read(0x%x bytes from 0x%x) returned %d\n", sizeof(node), ofs, err));
86 return err;
87
This page took 0.048385 seconds and 5 git commands to generate.