xref: /haiku/src/add-ons/kernel/file_systems/bfs/BlockAllocator.h (revision e5430a086c769ea76c3944046b1f07cf049c1ae0)
1 #ifndef BLOCK_ALLOCATOR_H
2 #define BLOCK_ALLOCATOR_H
3 /* BlockAllocator - block bitmap handling and allocation policies
4 **
5 ** Initial version by Axel Dörfler, axeld@pinc-software.de
6 ** This file may be used under the terms of the OpenBeOS License.
7 */
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();
29 
30 		status_t AllocateForInode(Transaction *transaction, const block_run *parent,
31 					mode_t type, block_run &run);
32 		status_t Allocate(Transaction *transaction, const Inode *inode, off_t numBlocks,
33 					block_run &run, uint16 minimum = 1);
34 		status_t Free(Transaction *transaction, block_run run);
35 
36 		status_t AllocateBlocks(Transaction *transaction, int32 group, uint16 start,
37 					uint16 numBlocks, uint16 minimum, block_run &run);
38 
39 		status_t StartChecking(check_control *control);
40 		status_t StopChecking(check_control *control);
41 		status_t CheckNextNode(check_control *control);
42 
43 		status_t CheckBlockRun(block_run run, const char *type = NULL, check_control *control = NULL);
44 		status_t CheckInode(Inode *inode, check_control *control = NULL);
45 
46 	private:
47 		bool IsValidCheckControl(check_control *control);
48 		bool CheckBitmapIsUsedAt(off_t block) const;
49 		void SetCheckBitmapAt(off_t block);
50 
51 		static status_t initialize(BlockAllocator *);
52 
53 		Volume			*fVolume;
54 		Semaphore		fLock;
55 		AllocationGroup	*fGroups;
56 		int32			fNumGroups;
57 		uint32			fBlocksPerGroup;
58 		uint32			*fCheckBitmap;
59 		check_cookie	*fCheckCookie;
60 };
61 
62 #endif	/* BLOCK_ALLOCATOR_H */
63