diff -auNrp mtd_9_28_EBH_1:1/fs/jffs2/erase.c mtd_9_28_EBH_1:1_ect/fs/jffs2/erase.c --- mtd_9_28_EBH_1:1/fs/jffs2/erase.c 2005-09-28 14:47:33.000000000 +0800 +++ mtd_9_28_EBH_1:1_ect/fs/jffs2/erase.c 2005-09-29 11:41:19.000000000 +0800 @@ -176,7 +176,21 @@ static void jffs2_erase_succeeded(struct list_del(&jeb->list); list_add_tail(&jeb->list, &c->erase_complete_list); spin_unlock(&c->erase_completion_lock); - SET_EBFLAGS_HAS_EBH(jeb); + if (!EBFLAGS_HAS_EBH(jeb)) { + if (c->nr_blocks_with_ebh != 0) { + jeb->erase_count = c->total_erase_count/c->nr_blocks_with_ebh; + } else { + jeb->erase_count = 0; + } + SET_EBFLAGS_HAS_EBH(jeb); + c->nr_blocks_with_ebh++; + c->total_erase_count += jeb->erase_count; + } + jeb->erase_count++; + if (jeb->erase_count > c->max_erase_count) { + c->max_erase_count = jeb->erase_count; + } + c->total_erase_count++; /* Ensure that kupdated calls us again to mark them clean */ jffs2_erase_pending_trigger(c); } diff -auNrp mtd_9_28_EBH_1:1/fs/jffs2/nodelist.h mtd_9_28_EBH_1:1_ect/fs/jffs2/nodelist.h --- mtd_9_28_EBH_1:1/fs/jffs2/nodelist.h 2005-09-28 15:05:58.000000000 +0800 +++ mtd_9_28_EBH_1:1_ect/fs/jffs2/nodelist.h 2005-09-29 11:51:43.000000000 +0800 @@ -301,6 +301,15 @@ static inline struct jffs2_node_frag *fr return rb_entry(node, struct jffs2_node_frag, rb); } +static inline void record_erase_count(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb) +{ + c->total_erase_count += jeb->erase_count; + c->nr_blocks_with_ebh++; + if (jeb->erase_count > c->max_erase_count) { + c->max_erase_count = jeb->erase_count; + } +} + #define rb_parent(rb) ((rb)->rb_parent) #define frag_next(frag) rb_entry(rb_next(&(frag)->rb), struct jffs2_node_frag, rb) #define frag_prev(frag) rb_entry(rb_prev(&(frag)->rb), struct jffs2_node_frag, rb) diff -auNrp mtd_9_28_EBH_1:1/fs/jffs2/scan.c mtd_9_28_EBH_1:1_ect/fs/jffs2/scan.c --- mtd_9_28_EBH_1:1/fs/jffs2/scan.c 2005-09-28 14:48:32.000000000 +0800 +++ mtd_9_28_EBH_1:1_ect/fs/jffs2/scan.c 2005-09-29 11:52:39.000000000 +0800 @@ -956,6 +956,7 @@ static int jffs2_scan_eraseblock_header( SET_EBFLAGS_HAS_EBH(jeb); jeb->erase_count = je32_to_cpu(eh->erase_count); + record_erase_count(c, jeb); raw->next_in_ino = NULL; raw->next_phys = NULL; diff -auNrp mtd_9_28_EBH_1:1/fs/jffs2/summary.c mtd_9_28_EBH_1:1_ect/fs/jffs2/summary.c --- mtd_9_28_EBH_1:1/fs/jffs2/summary.c 2005-09-28 14:48:32.000000000 +0800 +++ mtd_9_28_EBH_1:1_ect/fs/jffs2/summary.c 2005-09-29 11:53:16.000000000 +0800 @@ -504,6 +504,8 @@ static int jffs2_sum_process_sum_data(st } SET_EBFLAGS_HAS_EBH(jeb); jeb->erase_count = je32_to_cpu(speh->erase_count); + record_erase_count(c, jeb); + raw->next_in_ino = NULL; raw->next_phys = NULL; raw->flash_offset = (jeb->offset + je32_to_cpu(speh->offset)) | REF_NORMAL; diff -auNrp mtd_9_28_EBH_1:1/fs/jffs2/wbuf.c mtd_9_28_EBH_1:1_ect/fs/jffs2/wbuf.c --- mtd_9_28_EBH_1:1/fs/jffs2/wbuf.c 2005-09-28 14:48:32.000000000 +0800 +++ mtd_9_28_EBH_1:1_ect/fs/jffs2/wbuf.c 2005-09-29 11:53:49.000000000 +0800 @@ -1054,6 +1054,7 @@ int jffs2_check_nand_cleanmarker_ebh (st SET_EBFLAGS_HAS_EBH(jeb); jeb->erase_count = je32_to_cpu(eh.erase_count); + record_erase_count(c, jeb); *data_len = je32_to_cpu(eh.totlen); ret = 0; }else { diff -auNrp mtd_9_28_EBH_1:1/include/linux/jffs2_fs_sb.h mtd_9_28_EBH_1:1_ect/include/linux/jffs2_fs_sb.h --- mtd_9_28_EBH_1:1/include/linux/jffs2_fs_sb.h 2005-09-28 14:48:32.000000000 +0800 +++ mtd_9_28_EBH_1:1_ect/include/linux/jffs2_fs_sb.h 2005-09-29 11:40:59.000000000 +0800 @@ -117,6 +117,9 @@ struct jffs2_sb_info { uint32_t ebh_size; /* This is the space size occupied by eraseblock_header on flash */ + uint32_t total_erase_count; /* The summary erase count of all erase blocks */ + uint32_t nr_blocks_with_ebh; /* The number of erase blocks, which has eraseblock header on it */ + uint32_t max_erase_count; /* The maximum erase count of all erase blocks */ /* OS-private pointer for getting back to master superblock info */ void *os_priv; };