2009-12-08 00:01:24 +00:00
|
|
|
#ifndef __BLOCKCACHE_H__
|
|
|
|
#define __BLOCKCACHE_H__
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace ProFUSE {
|
|
|
|
|
|
|
|
class BlockDevice;
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-12-11 00:59:53 +00:00
|
|
|
class AbstractBlockCache {
|
|
|
|
public:
|
|
|
|
virtual ~AbstractBlockCache();
|
|
|
|
|
|
|
|
virtual void write() = 0;
|
|
|
|
|
2009-12-11 02:04:27 +00:00
|
|
|
virtual void *load(unsigned block) = 0;
|
|
|
|
virtual void unload(unsigned block, bool dirty) = 0;
|
2009-12-11 00:59:53 +00:00
|
|
|
|
|
|
|
void unload(unsigned block) { unload(block, false); }
|
|
|
|
};
|
|
|
|
|
2009-12-08 00:01:24 +00:00
|
|
|
|
2009-12-11 00:59:53 +00:00
|
|
|
class BlockCache : public AbstractBlockCache {
|
|
|
|
public:
|
|
|
|
BlockCache(BlockDevice *device, unsigned size = 16);
|
2009-12-08 00:01:24 +00:00
|
|
|
~BlockCache();
|
|
|
|
|
2009-12-11 00:59:53 +00:00
|
|
|
virtual void write();
|
2009-12-08 00:01:24 +00:00
|
|
|
|
2009-12-11 00:59:53 +00:00
|
|
|
virtual void *load(unsigned block);
|
|
|
|
virtual void unload(unsigned block, bool dirty);
|
|
|
|
|
|
|
|
|
2009-12-08 00:01:24 +00:00
|
|
|
private:
|
2009-12-11 00:59:53 +00:00
|
|
|
|
|
|
|
struct BlockDescriptor {
|
|
|
|
unsigned block;
|
|
|
|
unsigned count;
|
|
|
|
unsigned ts;
|
|
|
|
bool dirty;
|
|
|
|
uint8_t *data;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-12-08 00:01:24 +00:00
|
|
|
std::vector<BlockDescriptor> _blocks;
|
|
|
|
BlockDevice *_device;
|
|
|
|
unsigned _ts;
|
2009-12-11 00:59:53 +00:00
|
|
|
unsigned _cacheSize;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class MappedBlockCache : public AbstractBlockCache {
|
|
|
|
public:
|
|
|
|
|
|
|
|
MappedBlockCache(void *data, unsigned blocks);
|
|
|
|
|
|
|
|
virtual void write();
|
|
|
|
|
|
|
|
virtual void *load(unsigned block);
|
|
|
|
virtual void unload(unsigned block, bool dirty);
|
|
|
|
|
|
|
|
private:
|
|
|
|
unsigned _blocks;
|
|
|
|
uint8_t * _data;
|
2009-12-08 00:01:24 +00:00
|
|
|
};
|
|
|
|
|
2009-12-11 00:59:53 +00:00
|
|
|
} // namespace
|
2009-12-08 00:01:24 +00:00
|
|
|
|
|
|
|
#endif
|