YAFFS2在执行读写操作可能需要申请dev->srCache。
static yaffs_ChunkCache *yaffs_GrabChunkCache(yaffs_Device * dev) { yaffs_ChunkCache *cache; yaffs_Object *theObj; int usage; int i; /*int pushout;*/ //首先调用yaffs_GrabChunkCacheWorker查找一空闲块, //如果没有空闲块,查找最久使用块,得到这块的文件对象,并调用yaffs_FlushFilesChunkCache将该属于文件的Cache写入FLASH。 //再查找空闲块并返回。 if (dev->nShortOpCaches > 0) { /* Try find a non-dirty one... */ cache = yaffs_GrabChunkCacheWorker(dev); if (!cache) { /* They were all dirty, find the last recently used object and flush * its cache, then find again. * NB what's here is not very accurate, we actually flush the object * the last recently used page. */ /* With locking we can't assume we can use entry zero */ theObj = NULL; usage = -1; cache = NULL; /*pushout = -1;*/ for (i = 0; i < dev->nShortOpCaches; i++) { if (dev->srCache[i].object && !dev->srCache[i].locked && (dev->srCache[i].lastUse < usage || !cache)) { usage = dev->srCache[i].lastUse; theObj = dev->srCache[i].object; cache = &dev->srCache[i]; /*pushout = i;*/ } } if (!cache || cache->dirty) { /* Flush and try again */ yaffs_FlushFilesChunkCache(theObj); cache = yaffs_GrabChunkCacheWorker(dev); } } return cache; } else return NULL; }