1/* 2 * Copyright 2010, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Distributed under the terms of the MIT License. 4 */ 5#ifndef BLOCK_H 6#define BLOCK_H 7 8 9#include <SupportDefs.h> 10 11 12class Transaction; 13class Volume; 14 15 16class Block { 17public: 18 inline Block(); 19 inline ~Block(); 20 21 void TransferFrom(Block& other); 22 23 bool GetReadable(Volume* volume, uint64 blockIndex); 24 bool GetWritable(Volume* volume, uint64 blockIndex, 25 Transaction& transaction); 26 bool GetZero(Volume* volume, uint64 blockIndex, 27 Transaction& transaction); 28 29 status_t MakeWritable(Transaction& transaction); 30 31 void Put(); 32 33 void* Data() const { return fData; } 34 uint64 Index() const { return fIndex; } 35 36private: 37 bool _Init(Volume* volume, uint64 blockIndex, 38 const void* data, Transaction* transaction); 39 40private: 41 Volume* fVolume; 42 void* fData; 43 uint64 fIndex; 44 Transaction* fTransaction; 45}; 46 47 48Block::Block() 49 : 50 fVolume(NULL), 51 fData(NULL) 52{ 53} 54 55 56Block::~Block() 57{ 58 Put(); 59} 60 61 62#endif // BLOCK_H 63