From: charles Date: Tue, 28 Jul 2009 03:04:54 +0000 (+0000) Subject: Fix problem where object creation fills flash X-Git-Tag: pre-name-change~203 X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs2.git;a=commitdiff_plain;h=870a75229102c3d8922a465f0edcbb20ea4e996e Fix problem where object creation fills flash --- diff --git a/direct/dtest.c b/direct/dtest.c index 36152cb..06a190e 100644 --- a/direct/dtest.c +++ b/direct/dtest.c @@ -434,7 +434,6 @@ void fill_files(char *path,int flags, int maxIterations,int siz) do{ sprintf(str,"%s/%d",path,i); h = yaffs_open(str, O_CREAT | O_TRUNC | O_RDWR,S_IREAD | S_IWRITE); - yaffs_close(h); if(h >= 0) { @@ -1398,6 +1397,50 @@ void fill_disk_test(const char *mountpt) } +void fill_files_test(const char *mountpt) +{ + int i; + yaffs_StartUp(); + + for(i = 0; i < 5; i++) + { + yaffs_mount(mountpt); + fill_files(mountpt,2,3,100); + yaffs_unmount(mountpt); + } + +} + +void fill_empty_files_test(const char *mountpt) +{ + int i; + yaffs_StartUp(); + char name[100]; + int result = 0; + + int d,f; + + for(i = 0; i < 5; i++) + { + yaffs_mount(mountpt); + for(d = 0; result >= 0 && d < 1000; d++){ + sprintf(name,"%s/%d",mountpt,d); + result= yaffs_mkdir(name,0); + printf("creating directory %s result %d\n",name,result); + + for(f = 0; result >= 0 && f < 100; f++){ + sprintf(name,"%s/%d/%d",mountpt,d,f); + result= yaffs_open(name,O_CREAT, 0); + yaffs_close(result); + printf("creating file %s result %d\n",name,result); + } + } + yaffs_unmount(mountpt); + } + +} + + void lookup_test(const char *mountpt) { @@ -2317,7 +2360,7 @@ int main(int argc, char *argv[]) //rename_over_test("//////////////////flash///////////////////yaffs1///////////"); - rmdir_test("/M18-1"); + fill_empty_files_test("/yaffs2/"); //scan_pattern_test("/flash",10000,10); //short_scan_test("/flash/flash",40000,200); diff --git a/yaffs_guts.c b/yaffs_guts.c index 33ba5e6..81ae37a 100644 --- a/yaffs_guts.c +++ b/yaffs_guts.c @@ -12,7 +12,7 @@ */ const char *yaffs_guts_c_version = - "$Id: yaffs_guts.c,v 1.85 2009-06-08 23:50:44 charles Exp $"; + "$Id: yaffs_guts.c,v 1.86 2009-07-28 03:04:54 charles Exp $"; #include "yportenv.h" @@ -760,7 +760,7 @@ static void yaffs_VerifyObject(yaffs_Object *obj) chunkMax = (dev->internalEndBlock+1) * dev->nChunksPerBlock - 1; chunkInRange = (((unsigned)(obj->hdrChunk)) >= chunkMin && ((unsigned)(obj->hdrChunk)) <= chunkMax); - chunkIdOk = chunkInRange || obj->hdrChunk == 0; + chunkIdOk = chunkInRange || (obj->hdrChunk == 0); chunkValid = chunkInRange && yaffs_CheckChunkBit(dev, obj->hdrChunk / dev->nChunksPerBlock, @@ -3630,7 +3630,7 @@ static int yaffs_WriteChunkDataToObject(yaffs_Object *in, int chunkInInode, newTags.chunkId = chunkInInode; newTags.objectId = in->objectId; newTags.serialNumber = - (prevChunkId >= 0) ? prevTags.serialNumber + 1 : 1; + (prevChunkId > 0) ? prevTags.serialNumber + 1 : 1; newTags.byteCount = nBytes; if (nBytes < 1 || nBytes > dev->totalBytesPerChunk) { @@ -3646,7 +3646,7 @@ static int yaffs_WriteChunkDataToObject(yaffs_Object *in, int chunkInInode, if (newChunkId >= 0) { yaffs_PutChunkIntoFile(in, chunkInInode, newChunkId, 0); - if (prevChunkId >= 0) + if (prevChunkId > 0) yaffs_DeleteChunk(dev, prevChunkId, 1, __LINE__); yaffs_CheckFileSanity(in); @@ -3732,7 +3732,7 @@ int yaffs_UpdateObjectHeader(yaffs_Object *in, const YCHAR *name, int force, if (name && *name) { memset(oh->name, 0, sizeof(oh->name)); yaffs_strncpy(oh->name, name, YAFFS_MAX_NAME_LENGTH); - } else if (prevChunkId >= 0) + } else if (prevChunkId > 0) memcpy(oh->name, oldName, sizeof(oh->name)); else memset(oh->name, 0, sizeof(oh->name)); @@ -3790,13 +3790,13 @@ int yaffs_UpdateObjectHeader(yaffs_Object *in, const YCHAR *name, int force, /* Create new chunk in NAND */ newChunkId = yaffs_WriteNewChunkWithTagsToNAND(dev, buffer, &newTags, - (prevChunkId >= 0) ? 1 : 0); + (prevChunkId > 0) ? 1 : 0); if (newChunkId >= 0) { in->hdrChunk = newChunkId; - if (prevChunkId >= 0) { + if (prevChunkId > 0) { yaffs_DeleteChunk(dev, prevChunkId, 1, __LINE__); }