227-jffs2_eofdetect.patch 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. Index: linux-2.4.35.4/fs/jffs2/build.c
  2. ===================================================================
  3. --- linux-2.4.35.4.orig/fs/jffs2/build.c
  4. +++ linux-2.4.35.4/fs/jffs2/build.c
  5. @@ -31,6 +31,10 @@
  6. * provisions above, a recipient may use your version of this file
  7. * under either the RHEPL or the GPL.
  8. *
  9. + * Modification for automatically cleaning the filesystem after
  10. + * a specially marked block
  11. + * Copyright (C) 2006 Felix Fietkau <[email protected]>
  12. + *
  13. * $Id: build.c,v 1.16.2.3 2003/04/30 09:43:32 dwmw2 Exp $
  14. *
  15. */
  16. @@ -38,6 +42,7 @@
  17. #include <linux/kernel.h>
  18. #include <linux/jffs2.h>
  19. #include <linux/slab.h>
  20. +#include <linux/mtd/mtd.h>
  21. #include "nodelist.h"
  22. int jffs2_build_inode_pass1(struct jffs2_sb_info *, struct jffs2_inode_cache *);
  23. @@ -89,6 +94,18 @@ int jffs2_build_filesystem(struct jffs2_
  24. if (ret)
  25. return ret;
  26. + if (c->flags & (1 << 7)) {
  27. + printk("%s(): unlocking the mtd device... ", __func__);
  28. + if (c->mtd->unlock)
  29. + c->mtd->unlock(c->mtd, 0, c->mtd->size);
  30. + printk("done.\n");
  31. +
  32. + printk("%s(): erasing all blocks after the end marker... ", __func__);
  33. + jffs2_erase_pending_blocks(c);
  34. + jffs2_mark_erased_blocks(c);
  35. + printk("done.\n");
  36. + }
  37. +
  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. */
  41. Index: linux-2.4.35.4/fs/jffs2/scan.c
  42. ===================================================================
  43. --- linux-2.4.35.4.orig/fs/jffs2/scan.c
  44. +++ linux-2.4.35.4/fs/jffs2/scan.c
  45. @@ -31,6 +31,10 @@
  46. * provisions above, a recipient may use your version of this file
  47. * under either the RHEPL or the GPL.
  48. *
  49. + * Modification for automatically cleaning the filesystem after
  50. + * a specially marked block
  51. + * Copyright (C) 2006 Felix Fietkau <[email protected]>
  52. + *
  53. * $Id: scan.c,v 1.51.2.4 2003/11/02 13:51:18 dwmw2 Exp $
  54. *
  55. */
  56. @@ -88,7 +92,12 @@ int jffs2_scan_medium(struct jffs2_sb_in
  57. for (i=0; i<c->nr_blocks; i++) {
  58. struct jffs2_eraseblock *jeb = &c->blocks[i];
  59. - ret = jffs2_scan_eraseblock(c, jeb);
  60. +
  61. + if (c->flags & (1 << 7))
  62. + ret = 1;
  63. + else
  64. + ret = jffs2_scan_eraseblock(c, jeb);
  65. +
  66. if (ret < 0)
  67. return ret;
  68. @@ -181,6 +190,7 @@ static int jffs2_scan_eraseblock (struct
  69. while(ofs < jeb->offset + c->sector_size) {
  70. ssize_t retlen;
  71. + unsigned char *buf = (unsigned char *) &node;
  72. ACCT_PARANOIA_CHECK(jeb);
  73. if (ofs & 3) {
  74. @@ -202,8 +212,18 @@ static int jffs2_scan_eraseblock (struct
  75. break;
  76. }
  77. - err = c->mtd->read(c->mtd, ofs, sizeof(node), &retlen, (char *)&node);
  78. + err = c->mtd->read(c->mtd, ofs, sizeof(node), &retlen, buf);
  79. + if ((buf[0] == 0xde) &&
  80. + (buf[1] == 0xad) &&
  81. + (buf[2] == 0xc0) &&
  82. + (buf[3] == 0xde)) {
  83. +
  84. + /* end of filesystem. erase everything after this point */
  85. + c->flags |= (1 << 7);
  86. + printk("jffs2_scan_eraseblock(): End of filesystem marker found at 0x%x\n", jeb->offset);
  87. + return 1;
  88. + }
  89. if (err) {
  90. D1(printk(KERN_WARNING "mtd->read(0x%x bytes from 0x%x) returned %d\n", sizeof(node), ofs, err));
  91. return err;