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
13class AllocationGroup;
14class Transaction;
15class Volume;
16class Inode;
17struct disk_super_block;
18struct block_run;
19struct check_control;
20struct check_cookie;
21
22
23class 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, const 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