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 15 class BitmapBlock : public CachedBlock { 16 public: 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 42 private: 43 bool _Check(uint32 start, uint32 length, bool marked); 44 void _FindNext(uint32& pos, bool marked); 45 bool _Update(uint32 start, uint32 length, bool mark, 46 bool force); 47 48 uint32* fData; 49 const uint32* fReadOnlyData; 50 51 uint32 fNumBits; 52 uint32 fMaxIndex; 53 }; 54 55 56 inline bool 57 BitmapBlock::CheckUnmarked(uint32 start, uint32 length) 58 { 59 return _Check(start, length, false); 60 } 61 62 63 inline bool 64 BitmapBlock::CheckMarked(uint32 start, uint32 length) 65 { 66 return _Check(start, length, true); 67 } 68 69 70 inline bool 71 BitmapBlock::Mark(uint32 start, uint32 length, bool force) 72 { 73 return _Update(start, length, true, force); 74 } 75 76 77 inline bool 78 BitmapBlock::Unmark(uint32 start, uint32 length, bool force) 79 { 80 return _Update(start, length, false, force); 81 } 82 83 84 inline void 85 BitmapBlock::FindNextMarked(uint32& pos) 86 { 87 _FindNext(pos, true); 88 } 89 90 91 inline void 92 BitmapBlock::FindNextUnmarked(uint32& pos) 93 { 94 _FindNext(pos, false); 95 } 96 97 98 #endif // BITMAPBLOCK_H 99