1//----------------------------------------------------------------------
2//  This software is part of the OpenBeOS distribution and is covered
3//  by the MIT License.
4//
5//  Copyright (c) 2003 Tyler Dauwalder, tyler@dauwalder.net
6//----------------------------------------------------------------------
7
8/*! \file Allocator.h
9
10	Physical block allocator class declarations.
11*/
12
13#ifndef _UDF_ALLOCATOR_H
14#define _UDF_ALLOCATOR_H
15
16#include <list>
17using std::list;
18
19#include "UdfStructures.h"
20
21/*! \brief This class keeps track of allocated and unallocated
22	blocks in the range of 0 to 2^32.
23
24	By default, all blocks are unallocated.
25*/
26class Allocator {
27public:
28	Allocator(uint32 blockSize);
29	status_t InitCheck() const;
30
31	status_t GetBlock(uint32 block);
32	status_t GetExtent(extent_address extent);
33
34	status_t GetNextBlock(uint32 &block, uint32 minimumBlock = 0);
35	status_t GetNextExtent(uint32 length, bool contiguous,
36	                       extent_address &extent,
37	                       uint32 minimumStartingBlock = 0);
38
39	uint32 Length() const { return fLength; }
40	uint32 Tail() const { return fLength; }	//!< Returns the first unallocated block in the tail
41	uint32 BlockSize() const { return fBlockSize; }
42	uint32 BlockShift() const { return fBlockShift; }
43
44	uint32 BlocksFor(off_t bytes);
45private:
46	list<extent_address> fChunkList;
47	uint32 fLength;	//!< Length of allocation so far, in blocks.
48	uint32 fBlockSize;
49	uint32 fBlockShift;
50	status_t fInitStatus;
51};
52
53#endif	// _UDF_ALLOCATOR_H
54