mtd/fs/jffs2 wbuf.c,1.63,1.64

gleixner at infradead.org gleixner at infradead.org
Thu Jun 17 12:05:04 EDT 2004


Update of /home/cvs/mtd/fs/jffs2
In directory phoenix.infradead.org:/tmp/cvs-serv10381

Modified Files:
	wbuf.c 
Log Message:
Use autoplacement for oob

Index: wbuf.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/wbuf.c,v
retrieving revision 1.63
retrieving revision 1.64
diff -u -r1.63 -r1.64
--- wbuf.c	26 May 2004 18:03:05 -0000	1.63
+++ wbuf.c	17 Jun 2004 16:05:01 -0000	1.64
@@ -1067,61 +1067,63 @@
 };
 
 
-
-int jffs2_nand_flash_setup(struct jffs2_sb_info *c)
+int jffs2_nand_set_oobinfo(struct jffs2_sb_info *c)
 {
+	struct nand_oobinfo *oinfo = &c->mtd->oobinfo;
+
+	/* Do this only, if we have an oob buffer */
+	if (!c->mtd->oobsize)
+		return 0;
+	
 	/* Cleanmarker is out-of-band, so inline size zero */
 	c->cleanmarker_size = 0;
 
-	/* Initialise write buffer */
-	c->wbuf_pagesize = c->mtd->oobblock;
-	c->wbuf_ofs = 0xFFFFFFFF;
-
-	/* FIXME: If we had a generic way of describing the hardware's
-	   use of OOB area, we could perhaps make this generic too. */
-	switch(c->mtd->ecctype) {
-	case MTD_ECC_SW:
-		D1(printk(KERN_DEBUG "JFFS2 using software ECC\n"));
-		switch (c->mtd->oobsize) {
-		case 8:
-			c->fsdata_pos = NAND_JFFS2_OOB8_FSDAPOS;
-			c->fsdata_len = NAND_JFFS2_OOB8_FSDALEN;
-			c->oobinfo = &jffs2_oobinfo_swecc_8;
-			c->badblock_pos = 5;
-			break;
-		case 16:
-			c->fsdata_pos = NAND_JFFS2_OOB16_FSDAPOS;
+	/* Should we use autoplacement ? */
+	if (oinfo && oinfo->useecc == MTD_NANDECC_AUTOPLACE) {
+		D1(printk(KERN_DEBUG "JFFS2 using autoplace on NAND\n"));
+		/* Get the position of the free bytes */
+		if (!oinfo->oobfree[0][0]) {
+			printk (KERN_WARNING "jffs2_nand_set_oobinfo(): Eeep. Autoplacement selected and no empty space in oob\n");
+			return -ENOSPC;
+		}
+		c->fsdata_pos = oinfo->oobfree[0][0];
+		c->fsdata_len = oinfo->oobfree[0][1];
+		if (c->fsdata_len > 8)
+			c->fsdata_len = 8;
+	} else {
+		/* This is just a legacy fallback and should go away soon */
+		switch(c->mtd->ecctype) {
+		case MTD_ECC_RS_DiskOnChip:
+			D1(printk(KERN_DEBUG "JFFS2 using DiskOnChip hardware ECC\n"));
+			c->oobinfo = &jffs2_oobinfo_docecc;
+			c->fsdata_pos = 6;
 			c->fsdata_len = NAND_JFFS2_OOB16_FSDALEN;
-			c->oobinfo = &jffs2_oobinfo_swecc_16;
-			c->badblock_pos = 5;
-			break;
-		case 64:
-			c->fsdata_pos = NAND_JFFS2_OOB64_FSDAPOS;
-			c->fsdata_len = NAND_JFFS2_OOB64_FSDALEN;
-			c->oobinfo = &jffs2_oobinfo_autoplace;
-			c->badblock_pos = 0;
+			c->badblock_pos = 15;
 			break;
-		}	
-		break;
-
-	case MTD_ECC_RS_DiskOnChip:
-		D1(printk(KERN_DEBUG "JFFS2 using DiskOnChip hardware ECC\n"));
-		c->oobinfo = &jffs2_oobinfo_docecc;
-		c->fsdata_pos = 6;
-		c->fsdata_len = NAND_JFFS2_OOB16_FSDALEN;
-		c->badblock_pos = 15;
-		break;
-
-	default:
-		printk("JFFS2 doesn't yet know how to handle ECC type %d\n",
-		       c->mtd->ecctype);
-		return -EINVAL;
+	
+		default:
+			D1(printk(KERN_DEBUG "JFFS2 on NAND. No autoplacment info found\n"));
+			return -EINVAL;
+		}
 	}
+	return 0;
+}
+
+int jffs2_nand_flash_setup(struct jffs2_sb_info *c)
+{
+	int res;
+
+	/* Initialise write buffer */
+	c->wbuf_pagesize = c->mtd->oobblock;
+	c->wbuf_ofs = 0xFFFFFFFF;
 
+	
 	c->wbuf = kmalloc(c->wbuf_pagesize, GFP_KERNEL);
 	if (!c->wbuf)
 		return -ENOMEM;
 
+	res = jffs2_nand_set_oobinfo(c);
+
 #ifdef BREAKME
 	if (!brokenbuf)
 		brokenbuf = kmalloc(c->wbuf_pagesize, GFP_KERNEL);
@@ -1131,7 +1133,7 @@
 	}
 	memset(brokenbuf, 0xdb, c->wbuf_pagesize);
 #endif
-	return 0;
+	return res;
 }
 
 void jffs2_nand_flash_cleanup(struct jffs2_sb_info *c)





More information about the linux-mtd-cvs mailing list