Changes to retirement handling
[yaffs2.git] / direct / yaffs_fileem2k.c
index dcb3e5fc7e85a73c1f6b28473f2987bb9a3e9723..47437d537887032b56d7615cb9239b352c4be305 100644 (file)
@@ -15,7 +15,7 @@
 // This provides a YAFFS nand emulation on a file for emulating 2kB pages.
 // THis is only intended as test code to test persistence etc.
 
-const char *yaffs_flashif_c_version = "$Id: yaffs_fileem2k.c,v 1.6 2006-10-03 10:13:03 charles Exp $";
+const char *yaffs_flashif_c_version = "$Id: yaffs_fileem2k.c,v 1.9 2006-11-08 09:49:47 charles Exp $";
 
 
 #include "yportenv.h"
@@ -32,7 +32,7 @@ const char *yaffs_flashif_c_version = "$Id: yaffs_fileem2k.c,v 1.6 2006-10-03 10
 #include "yaffs_fileem2k.h"
 #include "yaffs_packedtags2.h"
 
-
+#define SIMULATE_FAILURES
 
 typedef struct 
 {
@@ -145,6 +145,8 @@ int yflash_WriteChunkWithTagsToNAND(yaffs_Device *dev,int chunkInNAND,const __u8
        int pos;
        int h;
        
+       T(YAFFS_TRACE_MTD,(TSTR("write chunk %d data %x tags %x" TENDSTR),chunkInNAND,(unsigned)data, (unsigned)tags));
+
        CheckInit();
        
        
@@ -162,6 +164,15 @@ int yflash_WriteChunkWithTagsToNAND(yaffs_Device *dev,int chunkInNAND,const __u8
                        exit(1);
                }
                
+#ifdef SIMULATE_FAILURES
+                       if((chunkInNAND >> 6) == 100) 
+                         written = 0;
+
+                       if((chunkInNAND >> 6) == 110) 
+                         written = 0;
+#endif
+
+
                if(written != dev->nDataBytesPerChunk) return YAFFS_FAIL;
        }
        
@@ -204,12 +215,17 @@ int yaffs_CheckAllFF(const __u8 *ptr, int n)
 }
 
 
+static int fail300 = 1;
+static int fail320 = 1;
+
 int yflash_ReadChunkWithTagsFromNAND(yaffs_Device *dev,int chunkInNAND, __u8 *data, yaffs_ExtendedTags *tags)
 {
        int nread;
        int pos;
        int h;
        
+       T(YAFFS_TRACE_MTD,(TSTR("read chunk %d data %x tags %x" TENDSTR),chunkInNAND,(unsigned)data, (unsigned)tags));
+       
        CheckInit();
        
        
@@ -249,6 +265,21 @@ int yflash_ReadChunkWithTagsFromNAND(yaffs_Device *dev,int chunkInNAND, __u8 *da
                        yaffs_PackedTags2 pt;
                        nread= read(h,&pt,sizeof(pt));
                        yaffs_UnpackTags2(tags,&pt);
+#ifdef SIMULATE_FAILURES
+                       if((chunkInNAND >> 6) == 100) {
+                           if(fail300 && tags->eccResult == YAFFS_ECC_RESULT_NO_ERROR){
+                              tags->eccResult = YAFFS_ECC_RESULT_FIXED;
+                              fail300 = 0;
+                           }
+                           
+                       }
+                       if((chunkInNAND >> 6) == 110) {
+                           if(fail320 && tags->eccResult == YAFFS_ECC_RESULT_NO_ERROR){
+                              tags->eccResult = YAFFS_ECC_RESULT_FIXED;
+                              fail320 = 0;
+                           }
+                       }
+#endif
                        if(nread != sizeof(pt)) return YAFFS_FAIL;
                }
        }
@@ -288,6 +319,9 @@ int yflash_EraseBlockInNAND(yaffs_Device *dev, int blockNumber)
                
        CheckInit();
        
+       if(blockNumber == 320)
+               fail320 = 1;
+       
        if(blockNumber < 0 || blockNumber >= filedisk.nBlocks)
        {
                T(YAFFS_TRACE_ALWAYS,("Attempt to erase non-existant block %d\n",blockNumber));