Merge branch 'master' of ssh://www.aleph1.co.uk/home/aleph1/git/yaffs2
[yaffs2.git] / yaffs_guts.c
index df66ec89860585636ffbfdaf0c80e7b90186493c..feade2aff1044b208adf2647a924f374d79b52b4 100644 (file)
@@ -12,7 +12,7 @@
  */
 
 const char *yaffs_guts_c_version =
-    "$Id: yaffs_guts.c,v 1.119 2010-03-12 02:48:34 charles Exp $";
+    "$Id: yaffs_guts.c,v 1.120 2010-03-15 23:10:34 charles Exp $";
 
 #include "yportenv.h"
 #include "yaffs_trace.h"
@@ -2943,6 +2943,10 @@ static void yaffs_BlockBecameDirty(yaffs_Device *dev, int blockNo)
 
        bi->blockState = YAFFS_BLOCK_STATE_DIRTY;
 
+       /* If this is the block being garbage collected then stop gc'ing this block */
+       if(blockNo == dev->gcBlock)
+               dev->gcBlock = -1;
+
        if (!bi->needsRetiring) {
                yaffs_InvalidateCheckpoint(dev);
                erasedOk = yaffs_EraseBlockInNAND(dev, blockNo);
@@ -3215,12 +3219,6 @@ static int yaffs_GarbageCollectBlock(yaffs_Device *dev, int block,
        
        bi->hasShrinkHeader = 0;        /* clear the flag so that the block can erase */
 
-       /* Take off the number of soft deleted entries because
-        * they're going to get really deleted during GC.
-        */
-       if(dev->gcChunk == 0) /* first time through for this block */
-               dev->nFreeChunks -= bi->softDeletions;
-
        dev->isDoingGC = 1;
 
        if (isCheckpointBlock ||
@@ -3300,6 +3298,13 @@ static int yaffs_GarbageCollectBlock(yaffs_Device *dev, int block,
                                         * No need to copy this, just forget about it and
                                         * fix up the object.
                                         */
+                                        
+                                       /* Free chunks already includes softdeleted chunks.
+                                        * How ever this chunk is going to soon be really deleted
+                                        * which will increment free chunks.
+                                        * We have to decrement free chunks so this works out properly.
+                                        */
+                                       dev->nFreeChunks--;
 
                                        object->nDataChunks--;
 
@@ -3420,8 +3425,14 @@ static int yaffs_GarbageCollectBlock(yaffs_Device *dev, int block,
 
 
 
-       /* If the gc completed then clear the current gcBlock so that we find another. */
-       if (bi->blockState != YAFFS_BLOCK_STATE_COLLECTING) {
+       if (bi->blockState == YAFFS_BLOCK_STATE_COLLECTING) {
+               /*
+                * The gc did not complete. Set block state back to FULL
+                * because checkpointing does not restore gc.
+                */
+               bi->blockState = YAFFS_BLOCK_STATE_FULL;
+       } else {
+               /* The gc completed. */
                chunksAfter = yaffs_GetErasedChunks(dev);
                if (chunksBefore >= chunksAfter) {
                        T(YAFFS_TRACE_GC,
@@ -3456,6 +3467,10 @@ static int yaffs_CheckGarbageCollection(yaffs_Device *dev)
 
        int checkpointBlockAdjust;
 
+       if(dev->param.gcControl &&
+               (dev->param.gcControl(dev) & 1) == 0)
+               return YAFFS_OK;
+
        if (dev->isDoingGC) {
                /* Bail out so we don't get recursive gc */
                return YAFFS_OK;
@@ -5474,6 +5489,7 @@ static int yaffs_UnlinkFileIfNeeded(yaffs_Object *in)
 
        int retVal;
        int immediateDeletion = 0;
+       yaffs_Device *dev = in->myDev;
 
        if (!in->myInode)
                immediateDeletion = 1;
@@ -5487,7 +5503,7 @@ static int yaffs_UnlinkFileIfNeeded(yaffs_Object *in)
                   in->objectId));
                in->deleted = 1;
                in->myDev->nDeletedFiles++;
-               if (1 || in->myDev->param.isYaffs2)
+               if (dev->param.disableSoftDelete || dev->param.isYaffs2)
                        yaffs_ResizeFile(in, 0);
                yaffs_SoftDeleteFile(in);
        } else {
@@ -5504,8 +5520,10 @@ int yaffs_DeleteFile(yaffs_Object *in)
 {
        int retVal = YAFFS_OK;
        int deleted = in->deleted;
+       yaffs_Device *dev = in->myDev;
 
-       yaffs_ResizeFile(in, 0);
+       if (dev->param.disableSoftDelete || dev->param.isYaffs2)
+               yaffs_ResizeFile(in, 0);
 
        if (in->nDataChunks > 0) {
                /* Use soft deletion if there is data in the file.