X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=yaffsdev.c;h=c44715b32f9d062b2bf69578ef37a0c8666d0a10;hb=ce96b5b9742c81cad6d902eaf793b792c1b8943b;hp=ff4b7e6f8f29e8dcad3fc5e3d2a1402a347756c0;hpb=daffb0c61b90abbfc5fd8c335c5b79b0feeff2ab;p=yaffs%2F.git diff --git a/yaffsdev.c b/yaffsdev.c index ff4b7e6..c44715b 100644 --- a/yaffsdev.c +++ b/yaffsdev.c @@ -27,8 +27,13 @@ #include #include +#include +#include + +unsigned yaffs_traceMask = 0xFFFFFFFF; + yaffs_Device device; @@ -129,6 +134,110 @@ void TestTimeasasas(yaffs_Device *dev) +} + +void TestTimeBigDeletes(yaffs_Device *dev) +{ + yaffs_Object *f; + yaffs_Object *sl; + yaffs_Object *lnf; + + yaffs_Object *hl1; + yaffs_Object *hl2; + yaffs_Object *hl3; + yaffs_Object *d, *df; + + int x; + int i; + int b; + char data[200]; + + char * alias; + 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"); + + + + 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"); + } + + for(i = 0; i < 100000; i+=20) + { + + b++; + if(b & 1) + written = yaffs_WriteDataToFile(f,testStr,i,strlen(testStr)); + else + written = yaffs_WriteDataToFile(f,testStr2,i,strlen(testStr2)); + } + + yaffs_FlushFile(f); + yaffs_DeleteFile(f); + + 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"); + } + + for(i = 0; i < 100000; i+=20) + { + + b++; + if(b & 1) + written = yaffs_WriteDataToFile(f,testStr,i,strlen(testStr)); + else + written = yaffs_WriteDataToFile(f,testStr2,i,strlen(testStr2)); + } + + yaffs_FlushFile(f); + yaffs_DeleteFile(f); + + 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"); + } + + for(i = 0; i < 100000; i+=20) + { + + b++; + if(b & 1) + written = yaffs_WriteDataToFile(f,testStr,i,strlen(testStr)); + else + written = yaffs_WriteDataToFile(f,testStr2,i,strlen(testStr2)); + } + + yaffs_FlushFile(f); + yaffs_DeleteFile(f); + } void TestTime(yaffs_Device *dev) @@ -209,16 +318,67 @@ 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) + { + yaffs_ReadDataFromFile(f,data,i,20); + } + + yaffs_ReadDataFromFile(f,data,1000,50); data[50] = 0; @@ -288,6 +448,8 @@ void TestTime(yaffs_Device *dev) printf("Unlink file: %d\n",yaffs_Unlink(yaffs_Root(dev),"Rename")); + yaffs_DeleteFile(f); + yaffs_ApplyToDirectoryChildren(yaffs_Root(dev),yaffs_DumpObject); // Create a directory and play with it @@ -354,7 +516,10 @@ void TestTime(yaffs_Device *dev) yaffs_ApplyToDirectoryChildren(yaffs_Root(dev),yaffs_DumpObject); f = yaffs_MknodFile(yaffs_Root(dev),"pfile",0,0,0); - yaffs_WriteDataToFile(f,testStr,0,strlen(testStr)); + if(f) + { + yaffs_WriteDataToFile(f,testStr,0,strlen(testStr)); + } yaffs_Link(yaffs_Root(dev),"phl4",f); } @@ -469,8 +634,10 @@ void TestTimeTnodeFocussed(yaffs_Device *dev) int main(int argc,char *argv[]) { + int nBlocks; + #if YAFFS_FILEEM - device.nBlocks = (64 * 1024 * 1024) / (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK); + nBlocks =(4 * 1024 * 1024) / (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK) ; device.writeChunkToNAND = yaffs_FEWriteChunkToNAND; device.readChunkFromNAND = yaffs_FEReadChunkFromNAND; device.eraseBlockInNAND = yaffs_FEEraseBlockInNAND; @@ -478,7 +645,7 @@ int main(int argc,char *argv[]) printf("Testing on file emulation\n"); #else - device.nBlocks = (2 * 1024 * 1024) / (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK); + nBlocks = (2 * 1024 * 1024) / (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK); device.writeChunkToNAND = nandemul_WriteChunkToNAND; device.readChunkFromNAND = nandemul_ReadChunkFromNAND; device.eraseBlockInNAND = nandemul_EraseBlockInNAND; @@ -487,8 +654,13 @@ int main(int argc,char *argv[]) printf("Testing on RAM emulation\n"); #endif +#ifdef YAFFS_START + device.startBlock = YAFFS_START; // Don't use block 0 + device.endBlock = YAFFS_END; +#else device.startBlock = 1; // Don't use block 0 - device.endBlock = device.nBlocks - 1; + device.endBlock = nBlocks; +#endif yaffs_GutsInitialise(&device); @@ -496,5 +668,8 @@ int main(int argc,char *argv[]) TestTime(&device); + printf("Cache hits %d\n",device.cacheHits); + printf("Retired blocks %d\n",device.nRetiredBlocks); + exit(0); }