From 1611f6f850584af2a33e790f2e7e652d77ec6526 Mon Sep 17 00:00:00 2001 From: charles Date: Sun, 3 Jul 2005 10:32:40 +0000 Subject: [PATCH 1/1] Add cache write through and some benign fixes --- yaffs_fs.c | 6 +++--- yaffs_guts.c | 31 +++++++++++++++++++++---------- yaffs_guts.h | 8 ++++---- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/yaffs_fs.c b/yaffs_fs.c index 7b4a8b0..8c9fdfb 100644 --- a/yaffs_fs.c +++ b/yaffs_fs.c @@ -29,7 +29,7 @@ */ -const char *yaffs_fs_c_version = "$Id: yaffs_fs.c,v 1.5 2005-04-29 07:01:18 charles Exp $"; +const char *yaffs_fs_c_version = "$Id: yaffs_fs.c,v 1.6 2005-07-03 10:32:40 charles Exp $"; extern const char *yaffs_guts_c_version; @@ -548,7 +548,7 @@ static int yaffs_writepage(struct page *page) yaffs_GrossLock(obj->myDev); - nWritten = yaffs_WriteDataToFile(obj,buffer,page->index << PAGE_CACHE_SHIFT,nBytes); + nWritten = yaffs_WriteDataToFile(obj,buffer,page->index << PAGE_CACHE_SHIFT,nBytes,0); yaffs_GrossUnlock(obj->myDev); @@ -786,7 +786,7 @@ static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n, loff_ T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_write about to write writing %d bytes to object %d at %d\n",n,obj->objectId,ipos)); } - nWritten = yaffs_WriteDataToFile(obj,buf,ipos,n); + nWritten = yaffs_WriteDataToFile(obj,buf,ipos,n,0); T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_write writing %d bytes, %d written at %d\n",n,nWritten,ipos)); if(nWritten > 0) diff --git a/yaffs_guts.c b/yaffs_guts.c index deac258..c24c3fe 100644 --- a/yaffs_guts.c +++ b/yaffs_guts.c @@ -14,7 +14,7 @@ */ //yaffs_guts.c -const char *yaffs_guts_c_version="$Id: yaffs_guts.c,v 1.6 2005-04-24 09:57:06 charles Exp $"; +const char *yaffs_guts_c_version="$Id: yaffs_guts.c,v 1.7 2005-07-03 10:32:40 charles Exp $"; #include "yportenv.h" @@ -3076,7 +3076,7 @@ static int yaffs_CheckFileSanity(yaffs_Object *in) static int yaffs_PutChunkIntoFile(yaffs_Object *in,int chunkInInode, int chunkInNAND, int inScan) { - // NB inScan is zero unless scanning. For forward scanning, inScan is > 0 for backward scanning inScan is < 0 + // NB inScan is zero unless scanning. For forward scanning, inScan is > 0; for backward scanning inScan is < 0 yaffs_Tnode *tn; yaffs_Device *dev = in->myDev; int existingChunk; @@ -3114,6 +3114,8 @@ static int yaffs_PutChunkIntoFile(yaffs_Object *in,int chunkInInode, int chunkIn // chunk should ever be affected. // // Correction for YAFFS2: This could happen quite a lot and we need to think about efficiency! TODO + // Update: For backward scanning we don't need to re-read tags so this is quite cheap. + if(existingChunk != 0) @@ -3129,9 +3131,9 @@ static int yaffs_PutChunkIntoFile(yaffs_Object *in,int chunkInInode, int chunkIn // // - if(inScan >= 0) + if(inScan > 0) { - // No need to do this for backward scanning + // Only do this for forward scanning yaffs_ReadChunkWithTagsFromNAND(dev,chunkInNAND, NULL,&newTags); @@ -3154,13 +3156,12 @@ static int yaffs_PutChunkIntoFile(yaffs_Object *in,int chunkInInode, int chunkIn newSerial = newTags.serialNumber; existingSerial = existingTags.serialNumber; - if( (inScan >= 0) && + if( (inScan > 0) && ( in->myDev->isYaffs2 || existingChunk <= 0 || ((existingSerial+1) & 3) == newSerial)) { - // Forward scanning or not during scanning - + // Forward scanning. // Use new // Delete the old one and drop through to update the tnode yaffs_DeleteChunk(dev,existingChunk,1,__LINE__); @@ -3918,7 +3919,7 @@ int yaffs_ReadDataFromFile(yaffs_Object *in, __u8 * buffer, __u32 offset, int nB -int yaffs_WriteDataToFile(yaffs_Object *in,const __u8 * buffer, __u32 offset, int nBytes) +int yaffs_WriteDataToFile(yaffs_Object *in,const __u8 * buffer, __u32 offset, int nBytes, int writeThrough) { int chunk; @@ -3945,7 +3946,7 @@ int yaffs_WriteDataToFile(yaffs_Object *in,const __u8 * buffer, __u32 offset, in // OK now check for the curveball where the start and end are in // the same chunk. - if( (start + n) < dev->nBytesPerChunk) + if((start + n) < dev->nBytesPerChunk) { nToCopy = n; @@ -3973,7 +3974,7 @@ int yaffs_WriteDataToFile(yaffs_Object *in,const __u8 * buffer, __u32 offset, in { // An incomplete start or end chunk (or maybe both start and end chunk) if(dev->nShortOpCaches > 0) - { + { yaffs_ChunkCache *cache; // If we can't find the data in the cache, then load it up. cache = yaffs_FindChunkCache(in,chunk); @@ -4002,6 +4003,16 @@ int yaffs_WriteDataToFile(yaffs_Object *in,const __u8 * buffer, __u32 offset, in #endif cache->locked = 0; cache->nBytes = nToWriteBack; + + if(writeThrough) + { + chunkWritten = yaffs_WriteChunkDataToObject(cache->object, + cache->chunkId, + cache->data, + cache->nBytes,1); + cache->dirty = 0; + } + } else { diff --git a/yaffs_guts.h b/yaffs_guts.h index c222c09..b770bde 100644 --- a/yaffs_guts.h +++ b/yaffs_guts.h @@ -14,7 +14,7 @@ * * Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL. * - * $Id: yaffs_guts.h,v 1.4 2005-04-24 09:57:06 charles Exp $ + * $Id: yaffs_guts.h,v 1.5 2005-07-03 10:32:40 charles Exp $ */ #ifndef __YAFFS_GUTS_H__ @@ -424,10 +424,10 @@ struct yaffs_ObjectStruct struct list_head siblings; // siblings in a directory // also used for linking up the free list - // Where's my data in NAND? + // Where's my object header in NAND? int chunkId; // where it lives - int nDataChunks; + int nDataChunks; // Number of data chunks attached to the file. __u32 objectId; // the object id value @@ -686,7 +686,7 @@ int yaffs_GetAttributes(yaffs_Object *obj, struct iattr *attr); // File operations int yaffs_ReadDataFromFile(yaffs_Object *obj, __u8 *buffer, __u32 offset, int nBytes); -int yaffs_WriteDataToFile(yaffs_Object *obj, const __u8 *buffer, __u32 offset, int nBytes); +int yaffs_WriteDataToFile(yaffs_Object *obj, const __u8 *buffer, __u32 offset, int nBytes, int writeThrough); int yaffs_ResizeFile(yaffs_Object *obj, int newSize); yaffs_Object *yaffs_MknodFile(yaffs_Object *parent,const YCHAR *name, __u32 mode, __u32 uid, __u32 gid); -- 2.30.2