1/*
2 * Copyright 2001-2010, Haiku Inc. All rights reserved.
3 * This file may be used under the terms of the MIT License.
4 *
5 * Authors:
6 *		Janito V. Ferreira Filho
7 */
8#ifndef INODEALLOCATOR_H
9#define INODEALLOCATOR_H
10
11#include <lock.h>
12
13#include "ext2.h"
14#include "Transaction.h"
15
16
17class Inode;
18class Volume;
19
20
21class InodeAllocator {
22public:
23						InodeAllocator(Volume* volume);
24	virtual				~InodeAllocator();
25
26	virtual	status_t	New(Transaction& transaction, Inode* parent,
27							int32 mode, ino_t& id);
28	virtual	status_t	Free(Transaction& transaction, ino_t id,
29							bool isDirectory);
30
31private:
32			status_t	_Allocate(Transaction& transaction,
33							uint32 preferredBlockGroup, bool isDirectory,
34							ino_t& id);
35			status_t	_AllocateInGroup(Transaction& transaction,
36							uint32 blockGroup, bool isDirectory,
37							ino_t& id, uint32 numInodes);
38			status_t	_MarkInBitmap(Transaction& transaction,
39							fsblock_t bitmapBlock, uint32 blockGroup,
40							uint32 numInodes, uint32& pos);
41			status_t	_UnmarkInBitmap(Transaction& transaction,
42							fsblock_t bitmapBlock, uint32 numInodes, ino_t id);
43			status_t	_InitGroup(Transaction& transaction,
44							ext2_block_group* group, fsblock_t bitmapBlock,
45							uint32 numInodes);
46
47
48			Volume*		fVolume;
49			mutex		fLock;
50};
51
52#endif	// INODEALLOCATOR_H
53