JFFS2: use MTD_OOB_AUTO
RFC PATCH 1/1 JFFS2: use MTD_OOB_AUTO
From: Artem Bityutskiy <[email protected]>
Date: Wed, 31 Jan 2007 11:38:53 +0200
Subject: [PATCH] [JFFS2] use MTD_OOB_AUTO
Nowadays MTD supports an MTD_OOB_AUTO option which allows users to access free bytes in NAND's OOB as a contiguous buffer, although it may be highly discontinuous.
This patch teaches JFFS2 to use this nice feature instead of the old MTD_OOB_PLACE option. This for example caused problems with OneNAND. Now JFFS2 does not care how are the free bytes situated.
This may change position of the clean marker on some flashes, but this is not a problem. JFFS2 will just re-erase the empty eraseblocks and write the new (correct) clean marker.
--- fs/jffs2/jffs2_fs_sb.h | 12 +-- fs/jffs2/scan.c | 10 ++- fs/jffs2/wbuf.c | 206 +++++++++++++++++------------------------------- 3 files changed, 84 insertions(+), 144 deletions(-)
fs/jffs2/jffs2_fs_sb.h +3 -9
@@ -98,20 +98,14 @@ struct jffs2_sb_info {uint32_t wbuf_pagesize;/* 0 for NOR and other flashes with no wbuf */ #ifdef CONFIG_JFFS2_FS_WRITEBUFFER -/* Write-behind buffer for NAND flash */ -unsigned char *wbuf; -unsigned char *oobbuf; +unsigned char *wbuf;/* Write-behind buffer for NAND flash */ uint32_t wbuf_ofs;uint32_t wbuf_len;struct jffs2_inodirty *wbuf_inodes; -struct rw_semaphore wbuf_sem;/* Protects the write buffer */ -/* Information about out-of-band area usage... */ -struct nand_ecclayout *ecclayout; -uint32_t badblock_pos; -uint32_t fsdata_pos; -uint32_t fsdata_len; +unsigned char *oobbuf; +int oobavail;/* How many bytes are available for JFFS2 in OOB */ #endif struct jffs2_summary *summary;/* Summary information */
fs/jffs2/scan.c +7 -3
@@ -450,16 +450,20 @@ static int jffs2_scan_eraseblock (struct#ifdef CONFIG_JFFS2_FS_WRITEBUFFER if (jffs2_cleanmarker_oob (c)) { -int ret =jffs2_check_nand_cleanmarker (c, jeb); +int ret; + +if (c->mtd->block_isbad (c->mtd, jeb->offset)) +return BLK_STATE_BADBLOCK ; + + ret =jffs2_check_nand_cleanmarker (c, jeb);D2 (printk (KERN_NOTICE "jffs_check_nand_cleanmarker returned %d\n" ,ret)); +/* Even if it's not found, we still scan to see if the block is empty. We use this information to decide whether to erase it or not. */ switch (ret) {case 0 : cleanmarkerfound =1 ;break ;case 1 :break ; -case 2 :return BLK_STATE_BADBLOCK ; -case 3 :return BLK_STATE_ALLDIRTY ;/* Block has failed to erase min. once */ default :return ret; } }
fs/jffs2/wbuf.c +74 -132
291 lines not on this page · raw message
Quoted 8 lines
fs/jffs2/wbuf.c +3
-1-#define NR_OOB_SCAN_PAGES 4 +#define NR_OOB_SCAN_PAGES 4 + +/* For historical reasons we use only 12 bytes for OOB clean marker */
fs/jffs2/wbuf.c exit: · line 970
Quoted 7 lines
fs/jffs2/wbuf.c +7
-0+#define OOB_CM_SIZE 12 + +static struct jffs2_unknown_node oob_cleanmarker = { + .magic =cpu_to_je16 (JFFS2_MAGIC_BITMASK ), + .nodetype =cpu_to_je16 (JFFS2_NODETYPE_CLEANMARKER ), + .totlen =cpu_to_je32 (8 ) +};
Looks good, how about make it const?
-
Quoted 6 lines
fs/jffs2/wbuf.c +1
-5- n.magic =cpu_to_je16 (JFFS2_MAGIC_BITMASK ); - n.nodetype =cpu_to_je16 (JFFS2_NODETYPE_CLEANMARKER ); - n.totlen =cpu_to_je32 (8 ); - p = (unsigned char *) &n; - b = c->oobbuf + c->fsdata_pos; + p = (unsigned char *)&oob_cleanmarker;
fs/jffs2/wbuf.c int jffs2_check_oob_empty(struct jffs2_s · line 1051
Quoted 10 lines
fs/jffs2/wbuf.c +5
-3+ b = c->oobbuf; -for (i = c->fsdata_len; i; i--) { -if (*b++ != *p++) +for (i =0 ; i < cmlen; i++) +if (*b++ != *p++) { ret =1 ; - } +break ; + }
Why we compare it with character pointer? just use memcmp
if (memcmp(p, b, cmlen))
ret = 1;
Are there any reasons?
Thank you,
Kyungmin Park
Quoted 1 line
Looks good, how about make it const?
Ok.
Quoted 1 line
Why we compare it with character pointer? just use memcmp
Ok, thanks
I'll send updated patch. We've tested it with our device - works like a charm. May you please try it on NAND and confirm it is OK?
Signature · 2 lines
Best regards, Artem Bityutskiy (Битюцкий Артём)