Remove oldestDirtySequence from checkpoint
[yaffs2.git] / yaffs_guts.c
index dc9742ba84be4baeb92b830fc6ea20d95a52680b..e9cda9c55b6d9c60109c9b6637cfec421d013b1c 100644 (file)
@@ -12,7 +12,7 @@
  */
 
 const char *yaffs_guts_c_version =
-    "$Id: yaffs_guts.c,v 1.110 2010-02-25 22:41:46 charles Exp $";
+    "$Id: yaffs_guts.c,v 1.112 2010-03-05 01:49:00 charles Exp $";
 
 #include "yportenv.h"
 #include "yaffs_trace.h"
@@ -2129,33 +2129,21 @@ static void yaffs_InitialiseObjects(yaffs_Device *dev)
 
 static int yaffs_FindNiceObjectBucket(yaffs_Device *dev)
 {
-       static int x;
        int i;
        int l = 999;
        int lowest = 999999;
 
-       /* First let's see if we can find one that's empty. */
 
-       for (i = 0; i < 10 && lowest > 0; i++) {
-               x++;
-               x %= YAFFS_NOBJECT_BUCKETS;
-               if (dev->objectBucket[x].count < lowest) {
-                       lowest = dev->objectBucket[x].count;
-                       l = x;
-               }
-
-       }
-
-       /* If we didn't find an empty list, then try
-        * looking a bit further for a short one
+       /* Search for the shortest list or one that
+        * isn't too long.
         */
 
-       for (i = 0; i < 10 && lowest > 3; i++) {
-               x++;
-               x %= YAFFS_NOBJECT_BUCKETS;
-               if (dev->objectBucket[x].count < lowest) {
-                       lowest = dev->objectBucket[x].count;
-                       l = x;
+       for (i = 0; i < 10 && lowest > 4; i++) {
+               dev->bucketFinder++;
+               dev->bucketFinder %= YAFFS_NOBJECT_BUCKETS;
+               if (dev->objectBucket[dev->bucketFinder].count < lowest) {
+                       lowest = dev->objectBucket[dev->bucketFinder].count;
+                       l = dev->bucketFinder;
                }
 
        }
@@ -3818,9 +3806,9 @@ static int yaffs_WriteChunkDataToObject(yaffs_Object *in, int chunkInInode,
         * the tnode now, rather than later when it is harder to clean up.
         */
        prevChunkId = yaffs_FindChunkInFile(in, chunkInInode, &prevTags);
-       if(prevChunkId <= 0 &&
-               !yaffs_PutChunkIntoFile(in, chunkInInode, 0, 0)){
-       }
+       if(prevChunkId < 1 &&
+               !yaffs_PutChunkIntoFile(in, chunkInInode, 0, 0))
+               return 0;
 
        /* Set up new tags */
        yaffs_InitialiseTags(&newTags);
@@ -3837,13 +3825,6 @@ static int yaffs_WriteChunkDataToObject(yaffs_Object *in, int chunkInInode,
                YBUG();
        }
        
-       /*
-        * If there isn't already a chunk there then do a dummy
-        * insert to make sue we have the desired tnode structure.
-        */
-       if(prevChunkId < 1 &&
-               yaffs_PutChunkIntoFile(in, chunkInInode, 0, 0) != YAFFS_OK)
-               return -1;
                
        newChunkId =
            yaffs_WriteNewChunkWithTagsToNAND(dev, buffer, &newTags,
@@ -4334,7 +4315,6 @@ static void yaffs_DeviceToCheckpointDevice(yaffs_CheckpointDevice *cp,
        cp->nUnlinkedFiles = dev->nUnlinkedFiles;
        cp->nBackgroundDeletions = dev->nBackgroundDeletions;
        cp->sequenceNumber = dev->sequenceNumber;
-       cp->oldestDirtySequence = dev->oldestDirtySequence;
 
 }
 
@@ -4350,7 +4330,6 @@ static void yaffs_CheckpointDeviceToDevice(yaffs_Device *dev,
        dev->nUnlinkedFiles = cp->nUnlinkedFiles;
        dev->nBackgroundDeletions = cp->nBackgroundDeletions;
        dev->sequenceNumber = cp->sequenceNumber;
-       dev->oldestDirtySequence = cp->oldestDirtySequence;
 }
 
 
@@ -5226,7 +5205,6 @@ int yaffs_ResizeFile(yaffs_Object *in, loff_t newSize)
                in->variant.fileVariant.fileSize = newSize;
        }
 
-
        /* Write a new object header to reflect the resize.
         * show we've shrunk the file, if need be
         * Do this only if the file is not in the deleted directories
@@ -7622,6 +7600,7 @@ int yaffs_GutsInitialise(yaffs_Device *dev)
        dev->nErasedBlocks = 0;
        dev->isDoingGC = 0;
        dev->hasPendingPrioritisedGCs = 1; /* Assume the worst for now, will get fixed on first GC */
+       dev->oldestDirtySequence = 0;
 
        /* Initialise temporary buffers and caches. */
        if (!yaffs_InitialiseTempBuffers(dev))
@@ -7704,7 +7683,6 @@ int yaffs_GutsInitialise(yaffs_Device *dev)
                                dev->nDeletedFiles = 0;
                                dev->nUnlinkedFiles = 0;
                                dev->nBackgroundDeletions = 0;
-                               dev->oldestDirtySequence = 0;
 
                                if (!init_failed && !yaffs_InitialiseBlocks(dev))
                                        init_failed = 1;