*** empty log message ***
[yaffs/.git] / yaffsdev.c
index 3fb6a62e39ee13af9795f1a2b961e71dde0c84b8..f325b78c1099972b23056c2b2c13429499b268d0 100644 (file)
 
 #include <stdio.h>
 #include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
 
 
+
+unsigned yaffs_traceMask = 0xFFFFFFFF;
+
 yaffs_Device device;
 
 
@@ -106,7 +111,7 @@ void TestTimeasasas(yaffs_Device *dev)
        
        printf("Flush\n");
        
-       yaffs_FlushFile(f);
+       yaffs_FlushFile(f,1);
 
        yaffs_ApplyToDirectoryChildren(yaffs_Root(dev),yaffs_DumpObject);
        
@@ -124,7 +129,7 @@ void TestTimeasasas(yaffs_Device *dev)
        
        yaffs_DumpObject(f);
 
-       yaffs_FlushFile(f);
+       yaffs_FlushFile(f,1);
        
        
                
@@ -182,7 +187,7 @@ void TestTimeBigDeletes(yaffs_Device *dev)
                        written = yaffs_WriteDataToFile(f,testStr2,i,strlen(testStr2));
        }
        
-       yaffs_FlushFile(f);
+       yaffs_FlushFile(f,1);
        yaffs_DeleteFile(f);
 
        f = yaffs_FindObjectByName(yaffs_Root(dev),"Name1");
@@ -206,7 +211,7 @@ void TestTimeBigDeletes(yaffs_Device *dev)
                        written = yaffs_WriteDataToFile(f,testStr2,i,strlen(testStr2));
        }
        
-       yaffs_FlushFile(f);
+       yaffs_FlushFile(f,1);
        yaffs_DeleteFile(f);
 
        f = yaffs_FindObjectByName(yaffs_Root(dev),"Name1");
@@ -230,7 +235,7 @@ void TestTimeBigDeletes(yaffs_Device *dev)
                        written = yaffs_WriteDataToFile(f,testStr2,i,strlen(testStr2));
        }
        
-       yaffs_FlushFile(f);
+       yaffs_FlushFile(f,1);
        yaffs_DeleteFile(f);
        
 }
@@ -313,15 +318,60 @@ void TestTime(yaffs_Device *dev)
        
        x = yaffs_RenameObject(yaffs_Root(dev),"Name1",NULL,"Rename");
        
-       for(i = 0; i < 100000; i+=20)
+// Write a file with overwrite, then read it back and save outside yaffs
+// This is to test that write caching works.
+
+       for(i = 0; i < 100; i++)
        { 
+               unsigned char x[500];
        
-               b++;
-               if(b & 1)
-                       written = yaffs_WriteDataToFile(f,testStr,i,strlen(testStr));
-               else
-                       written = yaffs_WriteDataToFile(f,testStr2,i,strlen(testStr2));
+               memset(x,i,500);
+               
+               written = yaffs_WriteDataToFile(f,x,i*500,500);         
+       }
+
+       for(i = 0; i < 100; i++)
+       { 
+               unsigned char x;
+       
+               x = i+5;
+               
+               written = yaffs_WriteDataToFile(f,&x,i*500 + 2,1);              
+       }
+       
+       
+       {
+               int h;
+               
+               h = open("bork",O_RDWR | O_CREAT | O_TRUNC,0666);
+               for(i = 0; i < 100; i++)
+               { 
+                       unsigned char x[500];
+       
+                       yaffs_ReadDataFromFile(f,x,i*500,500);
+                       write(h,x,500);
+               }
+               close(h);
+               
+               
+       }
+       
+// Big write to fill disk
+
+       written = 1;
+       for(i = 0; i < 1000000 && written > 0; i++)
+       { 
+               unsigned char x[500];
+       
+               memset(x,i,500);
+               
+               written = yaffs_WriteDataToFile(f,x,i*500,500);         
        }
+       if(written <= 0)
+       {
+               printf("YAFFS full\n");
+       }
+       
        // some short reads
        for(i = 1000; i < 50000; i+=2)
        { 
@@ -342,7 +392,7 @@ void TestTime(yaffs_Device *dev)
        
        printf("Flush\n");
        
-       yaffs_FlushFile(f);
+       yaffs_FlushFile(f,1);
        yaffs_ReadDataFromFile(f,data,1000,50);
        data[50] = 0;
        
@@ -393,7 +443,7 @@ void TestTime(yaffs_Device *dev)
        
        
 
-       yaffs_FlushFile(f);
+       yaffs_FlushFile(f,1);
                
 
        printf("Unlink file: %d\n",yaffs_Unlink(yaffs_Root(dev),"Rename"));
@@ -523,7 +573,7 @@ void TestTimeDeleteFocussed(yaffs_Device *dev)
        
        
 
-       yaffs_FlushFile(f);
+       yaffs_FlushFile(f,1);
                
 
        printf("Unlink file: %d\n",yaffs_Unlink(yaffs_Root(dev),"Rename"));
@@ -579,6 +629,56 @@ void TestTimeTnodeFocussed(yaffs_Device *dev)
                        written = yaffs_WriteDataToFile(f,testStr2,0,strlen(testStr2));
        }
        
+}
+void TestTimeBackgroundDeleteFocussed(yaffs_Device *dev)
+{
+       yaffs_Object *f;
+       yaffs_Object *lnf;
+       
+       
+       int x;
+       int i,j;
+       int b;
+       int written;
+       
+       
+       printf("Exisiting objects\n");
+       yaffs_ApplyToDirectoryChildren(yaffs_Root(dev),yaffs_DumpObject);
+       printf("Exisiting objects in lost+found\n");
+       lnf = yaffs_FindObjectByName(yaffs_Root(dev),YAFFS_LOSTNFOUND_NAME);
+       yaffs_ApplyToDirectoryChildren(lnf,yaffs_DumpObject);
+
+       printf("Start\n");
+       
+       
+       for(j = 0; j < 20; j++)
+       {
+               printf("Run %d\n",j);
+
+               f = yaffs_FindObjectByName(yaffs_Root(dev),"Name1");
+               if(f)
+               {
+                       printf("Found\n");
+               }
+               else
+               {
+                       f = yaffs_MknodFile(yaffs_Root(dev),"Name1",0,0,0);
+                       printf("Created\n");
+               }
+       
+               printf("@@@@@@@ Run %d, object %d\n",j,f->objectId);
+       
+               for(i = 0; i < 1000000; i+=20)
+               {
+       
+                       written = yaffs_WriteDataToFile(f,testStr,i,100);
+               }
+               
+               yaffs_FlushFile(f,1);
+               
+               yaffs_DeleteFile(f);
+       }
+       
 }
 
 int main(int argc,char *argv[])
@@ -587,7 +687,7 @@ int main(int argc,char *argv[])
        int nBlocks;
        
 #if YAFFS_FILEEM       
-       nBlocks =(32 * 1024 * 1024) / (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK) ;
+       nBlocks =(2 * 1024 * 1024) / (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK) ;
        device.writeChunkToNAND = yaffs_FEWriteChunkToNAND;
        device.readChunkFromNAND = yaffs_FEReadChunkFromNAND;
        device.eraseBlockInNAND = yaffs_FEEraseBlockInNAND;
@@ -612,14 +712,20 @@ int main(int argc,char *argv[])
        device.endBlock = nBlocks;
 #endif
 
+       device.nShortOpCaches = 10;
+
+
        yaffs_GutsInitialise(&device);
        
        // yaffs_GutsTest();
        
-       TestTimeBigDeletes(&device);
+       TestTimeBackgroundDeleteFocussed(&device);
        
        printf("Cache hits %d\n",device.cacheHits);
        printf("Retired blocks %d\n",device.nRetiredBlocks);
        
+       printf("Deletions %d\n",device.nDeletions);
+       printf("Unmarked deletions %d\n",device.nUnmarkedDeletions);
+       
        exit(0);
 }