xref: /haiku/src/add-ons/kernel/file_systems/bfs/BlockAllocator.h (revision 746cac055adc6ac3308c7bc2d29040fb95689cc9)
1 /*
2  * Copyright 2001-2008, Axel Dörfler, axeld@pinc-software.de.
3  * This file may be used under the terms of the MIT License.
4  */
5 #ifndef BLOCK_ALLOCATOR_H
6 #define BLOCK_ALLOCATOR_H
7 
8 
9 #include "system_dependencies.h"
10 
11 
12 class AllocationGroup;
13 class Transaction;
14 class Volume;
15 class Inode;
16 struct disk_super_block;
17 struct block_run;
18 struct check_control;
19 struct check_cookie;
20 
21 
22 class BlockAllocator {
23 public:
24 							BlockAllocator(Volume* volume);
25 							~BlockAllocator();
26 
27 			status_t		Initialize(bool full = true);
28 			status_t		InitializeAndClearBitmap(Transaction& transaction);
29 
30 			void			Uninitialize();
31 
32 			status_t		AllocateForInode(Transaction& transaction,
33 								const block_run* parent, mode_t type,
34 								block_run& run);
35 			status_t		Allocate(Transaction& transaction, Inode* inode,
36 								off_t numBlocks, block_run& run,
37 								uint16 minimum = 1);
38 			status_t		Free(Transaction& transaction, block_run run);
39 
40 			status_t		AllocateBlocks(Transaction& transaction,
41 								int32 group, uint16 start, uint16 numBlocks,
42 								uint16 minimum, block_run& run);
43 
44 			status_t		StartChecking(check_control* control);
45 			status_t		StopChecking(check_control* control);
46 			status_t		CheckNextNode(check_control* control);
47 
48 			status_t		CheckBlockRun(block_run run,
49 								const char* type = NULL,
50 								check_control* control = NULL,
51 								bool allocated = true);
52 			status_t		CheckInode(Inode* inode,
53 								check_control* control = NULL);
54 
55 			size_t			BitmapSize() const;
56 
57 #ifdef BFS_DEBUGGER_COMMANDS
58 			void			Dump(int32 index);
59 #endif
60 
61 private:
62 			bool			_IsValidCheckControl(check_control* control);
63 			bool			_CheckBitmapIsUsedAt(off_t block) const;
64 			void			_SetCheckBitmapAt(off_t block);
65 
66 	static	status_t		_Initialize(BlockAllocator* self);
67 
68 			Volume*			fVolume;
69 			mutex			fLock;
70 			AllocationGroup* fGroups;
71 			int32			fNumGroups;
72 			uint32			fBlocksPerGroup;
73 
74 			uint32*			fCheckBitmap;
75 			check_cookie*	fCheckCookie;
76 };
77 
78 #ifdef BFS_DEBUGGER_COMMANDS
79 int dump_block_allocator(int argc, char** argv);
80 #endif
81 
82 #endif	// BLOCK_ALLOCATOR_H
83