1/* 2 * Copyright 2001-2010, Haiku Inc. All rights reserved. 3 * This file may be used under the terms of the MIT License. 4 * 5 * Authors: 6 * Janito V. Ferreira Filho 7 */ 8#ifndef BITMAPBLOCK_H 9#define BITMAPBLOCK_H 10 11 12#include "CachedBlock.h" 13 14 15class BitmapBlock : public CachedBlock { 16public: 17 BitmapBlock(Volume* volume, uint32 numBits); 18 ~BitmapBlock(); 19 20 bool SetTo(off_t block); 21 bool SetToWritable(Transaction& transaction, 22 off_t block, bool empty = false); 23 24 bool CheckMarked(uint32 start, uint32 length); 25 bool CheckUnmarked(uint32 start, uint32 length); 26 27 bool Mark(uint32 start, uint32 length, 28 bool force = false); 29 bool Unmark(uint32 start, uint32 length, 30 bool force = false); 31 32 void FindNextMarked(uint32& pos); 33 void FindNextUnmarked(uint32& pos); 34 35 void FindPreviousMarked(uint32& pos); 36 37 void FindLargestUnmarkedRange(uint32& start, 38 uint32& length); 39 40 uint32 NumBits() const { return fNumBits; } 41 uint32 Checksum(uint32 unitsPerGroup) const; 42 43private: 44 bool _Check(uint32 start, uint32 length, bool marked); 45 void _FindNext(uint32& pos, bool marked); 46 bool _Update(uint32 start, uint32 length, bool mark, 47 bool force); 48 49 Volume* fVolume; 50 uint32* fData; 51 const uint32* fReadOnlyData; 52 53 uint32 fNumBits; 54 uint32 fMaxIndex; 55}; 56 57 58inline bool 59BitmapBlock::CheckUnmarked(uint32 start, uint32 length) 60{ 61 return _Check(start, length, false); 62} 63 64 65inline bool 66BitmapBlock::CheckMarked(uint32 start, uint32 length) 67{ 68 return _Check(start, length, true); 69} 70 71 72inline bool 73BitmapBlock::Mark(uint32 start, uint32 length, bool force) 74{ 75 return _Update(start, length, true, force); 76} 77 78 79inline bool 80BitmapBlock::Unmark(uint32 start, uint32 length, bool force) 81{ 82 return _Update(start, length, false, force); 83} 84 85 86inline void 87BitmapBlock::FindNextMarked(uint32& pos) 88{ 89 _FindNext(pos, true); 90} 91 92 93inline void 94BitmapBlock::FindNextUnmarked(uint32& pos) 95{ 96 _FindNext(pos, false); 97} 98 99 100#endif // BITMAPBLOCK_H 101