mtd/fs/jffs2 wbuf.c,1.61,1.62
gleixner at infradead.org
gleixner at infradead.org
Wed May 26 08:25:53 EDT 2004
Update of /home/cvs/mtd/fs/jffs2
In directory phoenix.infradead.org:/tmp/cvs-serv10632
Modified Files:
wbuf.c
Log Message:
use mtd functions for bad block checking and marking. change failcount policy to: if it failes twice per mount then its bad. Add a copyright notice.
Index: wbuf.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/wbuf.c,v
retrieving revision 1.61
retrieving revision 1.62
diff -u -r1.61 -r1.62
--- wbuf.c 14 Apr 2004 19:01:51 -0000 1.61
+++ wbuf.c 26 May 2004 12:25:50 -0000 1.62
@@ -2,8 +2,10 @@
* JFFS2 -- Journalling Flash File System, Version 2.
*
* Copyright (C) 2001-2003 Red Hat, Inc.
+ * Copyright (C) 2004 Thomas Gleixner <tglx at linutronix.de>
*
* Created by David Woodhouse <dwmw2 at redhat.com>
+ * Modified debugged and enhanced by Thomas Gleixner <tglx at linutronix.de>
*
* For licensing information, see the file 'LICENCE' in this directory.
*
@@ -27,7 +29,7 @@
#endif
/* max. erase failures before we mark a block bad */
-#define MAX_ERASE_FAILURES 5
+#define MAX_ERASE_FAILURES 2
/* two seconds timeout for timed wbuf-flushing */
#define WBUF_FLUSH_TIMEOUT 2 * HZ
@@ -932,6 +934,11 @@
/* Loop through the physical blocks */
for (cnt = 0; cnt < (c->sector_size / c->mtd->erasesize); cnt++) {
+ /* Check first if the block is bad. */
+ if (c->mtd->block_isbad (c->mtd, offset)) {
+ D1 (printk (KERN_WARNING "jffs2_check_nand_cleanmarker(): Bad block at %08x\n", jeb->offset));
+ return 2;
+ }
/*
* We read oob data from page 0 and 1 of the block.
* page 0 contains cleanmarker and badblock info
@@ -948,19 +955,6 @@
return -EIO;
}
- /* Check for bad block marker */
- if (buf[c->badblock_pos] != 0xff) {
- D1 (printk (KERN_WARNING "jffs2_check_nand_cleanmarker(): Bad block at %08x (has %02x %02x in badblock_pos %d\n",
- jeb->offset, buf[c->badblock_pos], buf[c->badblock_pos + oob_size], c->badblock_pos));
- return 2;
- }
-
- /* Check for failure counter in the second page */
- if (buf[c->badblock_pos + oob_size] != 0xff) {
- D1 (printk (KERN_WARNING "jffs2_check_nand_cleanmarker(): Block marked as failed at %08x, fail count:%d\n", jeb->offset, buf[c->badblock_pos + oob_size]));
- return 3;
- }
-
/* Check cleanmarker only on the first physical block */
if (!cnt) {
n.magic = cpu_to_je16 (JFFS2_MAGIC_BITMASK);
@@ -1011,38 +1005,8 @@
}
/*
- * We try to get the failure count of this block.
- */
-int jffs2_nand_read_failcnt(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb) {
-
- unsigned char buf[NAND_MAX_OOBSIZE];
- int ret;
- size_t retlen;
- int oob_size;
-
- oob_size = c->mtd->oobsize;
-
- ret = c->mtd->read_oob(c->mtd, jeb->offset + c->mtd->oobblock, oob_size , &retlen, buf);
-
- if (ret) {
- D1(printk(KERN_WARNING "jffs2_nand_read_failcnt(): Read OOB failed %d for block at %08x\n", ret, jeb->offset));
- return ret;
- }
-
- if (retlen < oob_size) {
- D1(printk(KERN_WARNING "jffs2_nand_read_failcnt(): Read OOB return short read (%zd bytes not %d) for block at %08x\n", retlen, oob_size, jeb->offset));
- return -EIO;
- }
-
- jeb->bad_count = buf[c->badblock_pos];
- return 0;
-}
-
-/*
- * On NAND we try to mark this block bad. We try to write how often
- * the block was erased and mark it finaly bad, if the count
- * is > MAX_ERASE_FAILURES. We read this information on mount !
- * jeb->bad_count contains the count before this erase.
+ * On NAND we try to mark this block bad. If the block was erased more
+ * than MAX_ERASE_FAILURES we mark it finaly bad.
* Don't care about failures. This block remains on the erase-pending
* or badblock list as long as nobody manipulates the flash with
* a bootloader or something like that.
@@ -1052,22 +1016,15 @@
{
unsigned char buf = 0x0;
int ret;
- size_t retlen;
/* if the count is < max, we try to write the counter to the 2nd page oob area */
- if( ++jeb->bad_count < MAX_ERASE_FAILURES) {
- buf = (unsigned char)jeb->bad_count;
- c->badblock_pos += c->mtd->oobblock;
- }
-
- ret = jffs2_flash_write_oob(c, jeb->offset + c->badblock_pos, 1, &retlen, &buf);
+ if( ++jeb->bad_count < MAX_ERASE_FAILURES)
+ return 0;
+
+ ret = c->mtd->block_markbad(c->mtd, jeb->offset);
if (ret) {
D1(printk(KERN_WARNING "jffs2_write_nand_badblock(): Write failed for block at %08x: error %d\n", jeb->offset, ret));
- return ret;
- }
- if (retlen != 1) {
- D1(printk(KERN_WARNING "jffs2_write_nand_badblock(): Short write for block at %08x: %zd not 1\n", jeb->offset, retlen));
return ret;
}
return 0;
More information about the linux-mtd-cvs
mailing list