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