#ifndef __FILEHEAP_HPP #define __FILEHEAP_HPP typedef unsigned long BlockID; class FileHeap { public: enum createMode { create_fail, create_create, }; enum existMode { exist_open, exist_fail, exist_trunc }; FileHeap(const char *filename, createMode cm, existMode em); ~FileHeap(); operator int() const { return fd>=0; } BlockID alloc(unsigned long bytes, BlockID around=0); void free(BlockID bid); int readBlock(BlockID id, void *dst, unsigned bytes); int writeBlock(BlockID id, const void *src, unsigned bytes); enum blockType { heapEmpty = 1, heapOK = 2, freeBlock = 3, usedBlock = 4, heapEnd = 5, corruptHeap = -1, badBlock = -2 }; blockType checkBlock(BlockID id, unsigned long *bytes); blockType checkHeap(); struct heapInfo { BlockID bid; unsigned long size; int in_use; }; blockType heapWalk(heapInfo *hi); int setSpecialBlock(BlockID id); BlockID getSpecialBlock(); private: int fd; }; #endif