+/////////////////////// Short Read Cache ////////////////////////////////
+// In many siturations where there is no high level buffering a lot of
+// reads might be short sequential reads. eg. scanning a jpeg file.
+// In these cases, a shoprt read cache can provide a huge perfomance benefit
+// with dumb-as-a-rock code.
+// There are a limited number (~10) of cache chunks per device
+
+
+#ifdef CONFIG_YAFFS_SHORT_OP_CACHE
+
+// Invalidate all the cache pages associated with this object
+// Do this whenever ther file is modified... dumb as a rock remember!
+static void yaffs_InvalidateChunkCache(yaffs_Object *in)
+{
+ int i;
+ yaffs_Device *dev = in->myDev;
+ int id = in->objectId;
+
+ for(i = 0; i < YAFFS_N_CACHE_CHUNKS; i++)
+ {
+ if(dev->srCache[i].objectId == id)
+ {
+ dev->srCache[i].objectId = 0;
+ }
+ }
+}
+
+
+// Grab us a chunk for use.
+// First look for an empty one.
+// Then look for the least recently used one.
+static yaffs_ChunkCache *yaffs_GrabChunkCache(yaffs_Device *dev)
+{
+ int i;
+ int usage;
+ int theOne;
+
+ for(i = 0; i < YAFFS_N_CACHE_CHUNKS; i++)
+ {
+ if(dev->srCache[i].objectId == 0)
+ {
+ //T(("Grabbing empty %d\n",i));
+
+ return &dev->srCache[i];
+ }
+ }
+
+
+ usage = dev->srCache[i].lastUse;
+ theOne = 0;
+
+ for(i = 1; i < YAFFS_N_CACHE_CHUNKS; i++)
+ {
+ if(dev->srCache[i].lastUse < usage)
+ {
+ usage = dev->srCache[i].lastUse;
+ theOne = i;
+ }
+ }
+
+ //T(("Grabbing non-empty %d\n",theOne));
+ return &dev->srCache[theOne];
+
+}
+
+
+// Find a cached chunk
+static yaffs_ChunkCache *yaffs_FindChunkCache(yaffs_Device *dev, int objectId, int chunkId)
+{
+ int i;
+;
+
+ for(i = 0; i < YAFFS_N_CACHE_CHUNKS; i++)
+ {
+ if(dev->srCache[i].objectId == objectId &&
+ dev->srCache[i].chunkId == chunkId)
+ {
+ dev->cacheHits++;
+
+ return &dev->srCache[i];
+ }
+ }
+
+ return NULL;
+}
+
+// Mark the chunk for the least recently used algorithym
+static void yaffs_UseChunkCache(yaffs_Device *dev, yaffs_ChunkCache *cache)
+{
+ if( dev->srLastUse < 0 ||
+ dev->srLastUse > 1000000)
+ {
+ // Reset the cache usages
+ int i;
+ for(i = 1; i < YAFFS_N_CACHE_CHUNKS; i++)
+ {
+ dev->srCache[i].lastUse = 0;
+ }
+ dev->srLastUse = 0;
+ }
+
+ dev->srLastUse++;
+
+ cache->lastUse = dev->srLastUse;
+
+}
+
+
+
+#endif
+
+