xref: /haiku/src/add-ons/kernel/file_systems/bfs/BlockAllocator.h (revision 7120e97489acbf17d86d3f33e3b2e68974fd4b23)
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 CheckBitmapIsUsedAt(off_t block) const;
48 		void SetCheckBitmapAt(off_t block);
49 
50 		static status_t initialize(BlockAllocator *);
51 
52 		Volume			*fVolume;
53 		Semaphore		fLock;
54 		AllocationGroup	*fGroups;
55 		int32			fNumGroups, fBlocksPerGroup;
56 		uint32			*fCheckBitmap;
57 		check_cookie	*fCheckCookie;
58 };
59 
60 #endif	/* BLOCK_ALLOCATOR_H */
61