MCPcopy Create free account
hub / github.com/andysworkshop/stm32plus / readBlock

Method readBlock

lib/src/device/CachedBlockDevice.cpp:53–80  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 3

checkFillBufferMethod · 0.45
skipMethod · 0.45
requireBytesMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected