More test clean ups
[yaffs2.git] / yaffs_guts.c
index 34e94a0a93942b2b931026beef9fa8e31624bc53..ae6e342502f40d585a39a47f74e771016316b95c 100644 (file)
@@ -12,7 +12,7 @@
  */
 
 const char *yaffs_guts_c_version =
-    "$Id: yaffs_guts.c,v 1.67 2008-11-27 02:46:45 charles Exp $";
+    "$Id: yaffs_guts.c,v 1.70 2009-01-09 02:52:28 charles Exp $";
 
 #include "yportenv.h"
 
@@ -406,14 +406,11 @@ static int yaffs_SkipVerification(yaffs_Device *dev)
        return !(yaffs_traceMask & (YAFFS_TRACE_VERIFY | YAFFS_TRACE_VERIFY_FULL));
 }
 
-#if 0
 static int yaffs_SkipFullVerification(yaffs_Device *dev)
 {
        return !(yaffs_traceMask & (YAFFS_TRACE_VERIFY_FULL));
 }
 
-#endif
-
 static int yaffs_SkipNANDVerification(yaffs_Device *dev)
 {
        return !(yaffs_traceMask & (YAFFS_TRACE_VERIFY_NAND));
@@ -485,9 +482,10 @@ static void yaffs_VerifyCollectedBlock(yaffs_Device *dev,yaffs_BlockInfo *bi,int
        yaffs_VerifyBlock(dev,bi,n);
        
        /* After collection the block should be in the erased state */
-       /* TODO: This will need to change if we do partial gc */
+       /* This will need to change if we do partial gc */
        
-       if(bi->blockState != YAFFS_BLOCK_STATE_EMPTY){
+       if(bi->blockState != YAFFS_BLOCK_STATE_COLLECTING &&
+          bi->blockState != YAFFS_BLOCK_STATE_EMPTY){
                T(YAFFS_TRACE_ERROR,(TSTR("Block %d is in state %d after gc, should be erased"TENDSTR),
                        n,bi->blockState));
        }
@@ -4849,7 +4847,8 @@ int yaffs_WriteDataToFile(yaffs_Object * in, const __u8 * buffer, loff_t offset,
         int nToWriteBack;
         int startOfWrite = offset;
         int chunkWritten = 0;
-        int nBytesRead;
+        __u32 nBytesRead;
+        __u32 chunkStart;
 
        yaffs_Device *dev;
 
@@ -4879,9 +4878,12 @@ int yaffs_WriteDataToFile(yaffs_Object * in, const __u8 * buffer, loff_t offset,
                         * we need to write back as much as was there before.
                         */
 
-                       nBytesRead =
-                           in->variant.fileVariant.fileSize -
-                           ((chunk - 1) * dev->nDataBytesPerChunk);
+                       chunkStart = ((chunk - 1) * dev->nDataBytesPerChunk);
+
+                       if(chunkStart > in->variant.fileVariant.fileSize)
+                               nBytesRead = 0; /* Past end of file */
+                       else
+                               nBytesRead = in->variant.fileVariant.fileSize - chunkStart;
 
                        if (nBytesRead > dev->nDataBytesPerChunk) {
                                nBytesRead = dev->nDataBytesPerChunk;
@@ -4889,7 +4891,10 @@ int yaffs_WriteDataToFile(yaffs_Object * in, const __u8 * buffer, loff_t offset,
 
                        nToWriteBack =
                            (nBytesRead >
-                            ((int)start + n)) ? nBytesRead : (start + n);
+                            (start + n)) ? nBytesRead : (start + n);
+                       
+                       if(nToWriteBack < 0 || nToWriteBack > dev->nDataBytesPerChunk)
+                               YBUG();
 
                } else {
                        nToCopy = dev->nDataBytesPerChunk - start;
@@ -6711,17 +6716,23 @@ static void yaffs_VerifyObjectInDirectory(yaffs_Object *obj)
         
         int count = 0;
 
-       if(!obj)
+       if(!obj){
+               T(YAFFS_TRACE_ALWAYS, (TSTR("No object to verify" TENDSTR)));
                YBUG();
+       }
 
         if(yaffs_SkipVerification(obj->myDev))
                 return;
 
-       if(!obj->parent)
+       if(!obj->parent){
+               T(YAFFS_TRACE_ALWAYS, (TSTR("Object does not have parent" TENDSTR)));
                YBUG();
+       }
                
-       if(obj->parent->variantType != YAFFS_OBJECT_TYPE_DIRECTORY)
+       if(obj->parent->variantType != YAFFS_OBJECT_TYPE_DIRECTORY){
+               T(YAFFS_TRACE_ALWAYS, (TSTR("Parent is not directory" TENDSTR)));
                YBUG();
+       }
        
         /* Iterate through the objects in each hash entry */
          
@@ -6734,9 +6745,10 @@ static void yaffs_VerifyObjectInDirectory(yaffs_Object *obj)
                 }
         }
         
-        if(count != 1)
-               YBUG();
-        
+        if(count != 1){
+               T(YAFFS_TRACE_ALWAYS, (TSTR("Object in directory %d times" TENDSTR),count));
+               YBUG();
+       }
 
 }
 
@@ -6749,20 +6761,24 @@ static void yaffs_VerifyDirectory(yaffs_Object *directory)
        if(!directory)
                YBUG();
 
-        if(yaffs_SkipVerification(directory->myDev))
+        if(yaffs_SkipFullVerification(directory->myDev))
                 return;
 
                
-       if(directory->variantType != YAFFS_OBJECT_TYPE_DIRECTORY)
+       if(directory->variantType != YAFFS_OBJECT_TYPE_DIRECTORY){
+               T(YAFFS_TRACE_ALWAYS, (TSTR("Directory has wrong type: %d" TENDSTR),directory->variantType));
                YBUG();
+       }
        
         /* Iterate through the objects in each hash entry */
          
         ylist_for_each(lh, &directory->variant.directoryVariant.children) {
                if (lh) {
                         listObj = ylist_entry(lh, yaffs_Object, siblings);
-                       if(listObj->parent != directory)
+                       if(listObj->parent != directory){
+                               T(YAFFS_TRACE_ALWAYS, (TSTR("Object in directory list has wrong parent %p" TENDSTR),listObj->parent));
                                YBUG();
+                       }
                        yaffs_VerifyObjectInDirectory(listObj);
                 }
         }