1 /* BlockAllocator - block bitmap handling and allocation policies 2 * 3 * Copyright 2001-2004, Axel Dörfler, axeld@pinc-software.de. 4 * This file may be used under the terms of the MIT License. 5 */ 6 #ifndef BLOCK_ALLOCATOR_H 7 #define BLOCK_ALLOCATOR_H 8 9 10 #include "Lock.h" 11 12 13 class AllocationGroup; 14 class Transaction; 15 class Volume; 16 class Inode; 17 struct disk_super_block; 18 struct block_run; 19 struct check_control; 20 struct check_cookie; 21 22 23 class BlockAllocator { 24 public: 25 BlockAllocator(Volume *volume); 26 ~BlockAllocator(); 27 28 status_t Initialize(bool full = true); 29 status_t InitializeAndClearBitmap(Transaction &transaction); 30 31 status_t AllocateForInode(Transaction &transaction, const block_run *parent, 32 mode_t type, block_run &run); 33 status_t Allocate(Transaction &transaction, Inode *inode, off_t numBlocks, 34 block_run &run, uint16 minimum = 1); 35 status_t Free(Transaction &transaction, block_run run); 36 37 status_t AllocateBlocks(Transaction &transaction, int32 group, uint16 start, 38 uint16 numBlocks, uint16 minimum, block_run &run); 39 40 status_t StartChecking(check_control *control); 41 status_t StopChecking(check_control *control); 42 status_t CheckNextNode(check_control *control); 43 44 status_t CheckBlockRun(block_run run, const char *type = NULL, check_control *control = NULL, bool allocated = true); 45 status_t CheckInode(Inode *inode, check_control *control = NULL); 46 47 size_t BitmapSize() const; 48 49 private: 50 bool IsValidCheckControl(check_control *control); 51 bool CheckBitmapIsUsedAt(off_t block) const; 52 void SetCheckBitmapAt(off_t block); 53 54 static status_t initialize(BlockAllocator *); 55 56 Volume *fVolume; 57 Semaphore fLock; 58 AllocationGroup *fGroups; 59 int32 fNumGroups; 60 uint32 fBlocksPerGroup; 61 62 uint32 *fCheckBitmap; 63 check_cookie *fCheckCookie; 64 }; 65 66 #endif /* BLOCK_ALLOCATOR_H */ 67