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 BLOCKALLOCATOR_H 9 #define BLOCKALLOCATOR_H 10 11 12 #include <lock.h> 13 14 #include "ext2.h" 15 #include "Transaction.h" 16 17 18 class AllocationBlockGroup; 19 class Inode; 20 class Volume; 21 22 23 class BlockAllocator { 24 public: 25 BlockAllocator(Volume* volume); 26 ~BlockAllocator(); 27 28 status_t Initialize(); 29 30 status_t AllocateBlocks(Transaction& transaction, 31 uint32 minimum, uint32 maximum, uint32& blockGroup, 32 fsblock_t& start, uint32& length); 33 status_t Allocate(Transaction& transaction, Inode* inode, 34 off_t numBlocks, uint32 minimum, fsblock_t& start, 35 uint32& length); 36 status_t Free(Transaction& transaction, fsblock_t start, 37 uint32 length); 38 39 uint32 FreeBlocks(); 40 41 protected: 42 static status_t _Initialize(BlockAllocator* allocator); 43 44 45 Volume* fVolume; 46 mutex fLock; 47 48 AllocationBlockGroup* fGroups; 49 uint32 fBlocksPerGroup; 50 fsblock_t fNumBlocks; 51 uint32 fNumGroups; 52 fsblock_t fFirstBlock; 53 }; 54 55 #endif // BLOCKALLOCATOR_H 56