Add more info to python test
[yaffs2.git] / yaffs_checkptrw.c
index 40d792366f76268e44a6759cdc38f4a1531b989f..ce44f1ee18bca9ca08258ba6f49ab281a61bb8f4 100644 (file)
@@ -12,7 +12,7 @@
  */
 
 const char *yaffs_checkptrw_c_version =
-       "$Id: yaffs_checkptrw.c,v 1.18 2009-03-06 17:20:49 wookey Exp $";
+       "$Id: yaffs_checkptrw.c,v 1.22 2009-11-03 02:36:30 charles Exp $";
 
 
 #include "yaffs_checkptrw.h"
@@ -43,6 +43,9 @@ static int yaffs_CheckpointErase(yaffs_Device *dev)
                yaffs_BlockInfo *bi = yaffs_GetBlockInfo(dev, i);
                if (bi->blockState == YAFFS_BLOCK_STATE_CHECKPOINT) {
                        T(YAFFS_TRACE_CHECKPOINT, (TSTR("erasing checkpt block %d"TENDSTR), i));
+
+                       dev->nBlockErasures++;
+
                        if (dev->eraseBlockInNAND(dev, i - dev->blockOffset /* realign */)) {
                                bi->blockState = YAFFS_BLOCK_STATE_EMPTY;
                                dev->nErasedBlocks++;
@@ -127,6 +130,9 @@ static void yaffs_CheckpointFindNextCheckpointBlock(yaffs_Device *dev)
 int yaffs_CheckpointOpen(yaffs_Device *dev, int forWriting)
 {
 
+
+       dev->checkpointOpenForWrite = forWriting;
+
        /* Got the functions we need? */
        if (!dev->writeChunkWithTagsToNAND ||
                        !dev->readChunkWithTagsFromNAND ||
@@ -144,9 +150,6 @@ int yaffs_CheckpointOpen(yaffs_Device *dev, int forWriting)
 
 
        dev->checkpointPageSequence = 0;
-
-       dev->checkpointOpenForWrite = forWriting;
-
        dev->checkpointByteCount = 0;
        dev->checkpointSum = 0;
        dev->checkpointXor = 0;
@@ -168,6 +171,9 @@ int yaffs_CheckpointOpen(yaffs_Device *dev, int forWriting)
                dev->blocksInCheckpoint = 0;
                dev->checkpointMaxBlocks = (dev->internalEndBlock - dev->internalStartBlock)/16 + 2;
                dev->checkpointBlockList = YMALLOC(sizeof(int) * dev->checkpointMaxBlocks);
+               if(!dev->checkpointBlockList)
+                       return 0;
+
                for (i = 0; i < dev->checkpointMaxBlocks; i++)
                        dev->checkpointBlockList[i] = -1;
        }
@@ -219,6 +225,8 @@ static int yaffs_CheckpointFlushBuffer(yaffs_Device *dev)
 
        realignedChunk = chunk - dev->chunkOffset;
 
+       dev->nPageWrites++;
+
        dev->writeChunkWithTagsToNAND(dev, realignedChunk,
                        dev->checkpointBuffer, &tags);
        dev->checkpointByteOffset = 0;
@@ -306,6 +314,8 @@ int yaffs_CheckpointRead(yaffs_Device *dev, void *data, int nBytes)
                                        dev->checkpointCurrentChunk;
 
                                realignedChunk = chunk - dev->chunkOffset;
+                               
+                               dev->nPageReads++;
 
                                /* read in the next chunk */
                                /* printf("read checkpoint page %d\n",dev->checkpointPage); */
@@ -348,11 +358,14 @@ int yaffs_CheckpointClose(yaffs_Device *dev)
        if (dev->checkpointOpenForWrite) {
                if (dev->checkpointByteOffset != 0)
                        yaffs_CheckpointFlushBuffer(dev);
-       } else {
+       } else if(dev->checkpointBlockList){
                int i;
                for (i = 0; i < dev->blocksInCheckpoint && dev->checkpointBlockList[i] >= 0; i++) {
-                       yaffs_BlockInfo *bi = yaffs_GetBlockInfo(dev, dev->checkpointBlockList[i]);
-                       if (bi->blockState == YAFFS_BLOCK_STATE_EMPTY)
+                       int blk = dev->checkpointBlockList[i];
+                       yaffs_BlockInfo *bi = NULL;
+                       if( dev->internalStartBlock <= blk && blk <= dev->internalEndBlock)
+                               bi = yaffs_GetBlockInfo(dev, blk);
+                       if (bi && bi->blockState == YAFFS_BLOCK_STATE_EMPTY)
                                bi->blockState = YAFFS_BLOCK_STATE_CHECKPOINT;
                        else {
                                /* Todo this looks odd... */
@@ -380,12 +393,10 @@ int yaffs_CheckpointClose(yaffs_Device *dev)
 
 int yaffs_CheckpointInvalidateStream(yaffs_Device *dev)
 {
-       /* Erase the first checksum block */
-
-       T(YAFFS_TRACE_CHECKPOINT, (TSTR("checkpoint invalidate"TENDSTR)));
+       /* Erase the checkpoint data */
 
-       if (!yaffs_CheckpointSpaceOk(dev))
-               return 0;
+       T(YAFFS_TRACE_CHECKPOINT, (TSTR("checkpoint invalidate of %d blocks"TENDSTR),
+               dev->blocksInCheckpoint));
 
        return yaffs_CheckpointErase(dev);
 }