#ifndef EXTENTMANAGER_H
#define EXTENTMANAGER_H
#include <list>
#include <vector>
#include <algorithm>
#include <sys/types.h>
#include <sys/errno.h>
#include <cstdio>
#include <cassert>
using namespace std;
struct ExtentInfo {
off_t blockAddr;
off_t numBlocks;
};
inline bool BeforeExtent(const ExtentInfo &a, const ExtentInfo &b)
{
return (a.blockAddr + a.numBlocks) < b.blockAddr;
}
typedef list<ExtentInfo>::iterator ListExtIt;
class ExtentManager {
public:
ExtentManager() : blockSize(0), totalBytes(0), totalBlocks(0) {};
~ExtentManager() {};
void Init(uint32_t theBlockSize, uint32_t theNativeBlockSize, off_t theTotalBytes);
void AddBlockRangeExtent(off_t blockAddr, off_t numBlocks);
void AddByteRangeExtent(off_t byteAddr, off_t numBytes);
void RemoveBlockRangeExtent(off_t blockAddr, off_t numBlocks);
void DebugPrint();
protected:
void MergeExtent(const ExtentInfo &a, const ExtentInfo &b, ExtentInfo *c);
public:
size_t blockSize;
size_t nativeBlockSize;
off_t totalBytes;
off_t totalBlocks;
list<ExtentInfo> extentList;
};
#endif // #ifndef EXTENTMANAGER_H