| 51 | */ |
| 52 | |
| 53 | bool CachedBlockDevice::readBlock(void *dest,uint32_t blockIndex) { |
| 54 | |
| 55 | uint32_t i; |
| 56 | |
| 57 | // try to find in the cache index |
| 58 | |
| 59 | for(i=0;i<_numCachedBlocks&&_cacheIndex[i].BlockIndex!=FREE_CACHE_ENTRY;i++) { |
| 60 | |
| 61 | if(_cacheIndex[i].BlockIndex==blockIndex) { |
| 62 | |
| 63 | // cache hit |
| 64 | |
| 65 | memcpy(dest,_cachedBlocks[_cacheIndex[i].CacheIndex],_blockSize); |
| 66 | moveToFront(i); |
| 67 | return true; |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | // cache miss, read from device |
| 72 | |
| 73 | if(!_device.readBlock(dest,blockIndex)) |
| 74 | return false; |
| 75 | |
| 76 | // write to the cache |
| 77 | |
| 78 | writeToCache(dest,blockIndex); |
| 79 | return true; |
| 80 | } |
| 81 | |
| 82 | /* |
| 83 | * write a block |
no outgoing calls
no test coverage detected