xref: /haiku/src/add-ons/kernel/file_systems/ext2/DataStream.h (revision 45af882d0698d575ec1b4883a8ebff276c9519d8)
1a1b0ec30SJérôme Duval /*
2a1b0ec30SJérôme Duval  * Copyright 2001-2010, Haiku Inc. All rights reserved.
3a1b0ec30SJérôme Duval  * This file may be used under the terms of the MIT License.
4a1b0ec30SJérôme Duval  *
5a1b0ec30SJérôme Duval  * Authors:
6a1b0ec30SJérôme Duval  *		Janito V. Ferreira Filho
7a1b0ec30SJérôme Duval  */
8a1b0ec30SJérôme Duval #ifndef DATASTREAM_H
9a1b0ec30SJérôme Duval #define DATASTREAM_H
10a1b0ec30SJérôme Duval 
11*45af882dSJérôme Duval 
12a1b0ec30SJérôme Duval #include "ext2.h"
13a1b0ec30SJérôme Duval #include "Transaction.h"
14a1b0ec30SJérôme Duval 
15a1b0ec30SJérôme Duval 
16a1b0ec30SJérôme Duval class Volume;
17a1b0ec30SJérôme Duval 
18a1b0ec30SJérôme Duval 
19a1b0ec30SJérôme Duval class DataStream
20a1b0ec30SJérôme Duval {
21a1b0ec30SJérôme Duval public:
22a1b0ec30SJérôme Duval 					DataStream(Volume* volume, ext2_data_stream* stream,
23a1b0ec30SJérôme Duval 						off_t size);
24a1b0ec30SJérôme Duval 					~DataStream();
25a1b0ec30SJérôme Duval 
26*45af882dSJérôme Duval 	status_t		FindBlock(off_t offset, fsblock_t& block,
279637baaeSJérôme Duval 						uint32 *_count = NULL);
28d8772e0cSJérôme Duval 	status_t		Enlarge(Transaction& transaction, off_t& numBlocks);
29d8772e0cSJérôme Duval 	status_t		Shrink(Transaction& transaction, off_t& numBlocks);
30a1b0ec30SJérôme Duval 
31a1b0ec30SJérôme Duval private:
32d8772e0cSJérôme Duval 	uint32			_BlocksNeeded(off_t end);
33a1b0ec30SJérôme Duval 
34a1b0ec30SJérôme Duval 	status_t		_GetBlock(Transaction& transaction, uint32& block);
35a1b0ec30SJérôme Duval 	status_t		_PrepareBlock(Transaction& transaction, uint32* pos,
36a1b0ec30SJérôme Duval 						uint32& blockNum, bool& clear);
37a1b0ec30SJérôme Duval 
38a1b0ec30SJérôme Duval 	status_t		_AddBlocks(Transaction& transaction, uint32* block,
39d8772e0cSJérôme Duval 						off_t count);
40a1b0ec30SJérôme Duval 	status_t		_AddBlocks(Transaction& transaction, uint32* block,
41d8772e0cSJérôme Duval 						off_t start, off_t end, int recursion);
42a1b0ec30SJérôme Duval 
43a1b0ec30SJérôme Duval 	status_t		_AddForDirectBlocks(Transaction& transaction,
44a1b0ec30SJérôme Duval 						uint32 numBlocks);
45a1b0ec30SJérôme Duval 	status_t		_AddForIndirectBlock(Transaction& transaction,
46a1b0ec30SJérôme Duval 						uint32 numBlocks);
47a1b0ec30SJérôme Duval 	status_t		_AddForDoubleIndirectBlock(Transaction& transaction,
48a1b0ec30SJérôme Duval 						uint32 numBlocks);
49a1b0ec30SJérôme Duval 	status_t		_AddForTripleIndirectBlock(Transaction& transaction,
50a1b0ec30SJérôme Duval 						uint32 numBlocks);
51a1b0ec30SJérôme Duval 
52a1b0ec30SJérôme Duval 	status_t		_PerformFree(Transaction& transaction);
53a1b0ec30SJérôme Duval 	status_t		_MarkBlockForRemoval(Transaction& transaction,
54a1b0ec30SJérôme Duval 						uint32* block);
55a1b0ec30SJérôme Duval 
56a1b0ec30SJérôme Duval 	status_t		_FreeBlocks(Transaction& transaction, uint32* block,
57a1b0ec30SJérôme Duval 						uint32 count);
58a1b0ec30SJérôme Duval 	status_t		_FreeBlocks(Transaction& transaction, uint32* block,
59d8772e0cSJérôme Duval 						off_t start, off_t end, bool freeParent,
60a1b0ec30SJérôme Duval 						int recursion);
61a1b0ec30SJérôme Duval 
62a1b0ec30SJérôme Duval 	status_t		_RemoveFromDirectBlocks(Transaction& transaction,
63a1b0ec30SJérôme Duval 						uint32 numBlocks);
64a1b0ec30SJérôme Duval 	status_t		_RemoveFromIndirectBlock(Transaction& transaction,
65a1b0ec30SJérôme Duval 						uint32 numBlocks);
66a1b0ec30SJérôme Duval 	status_t		_RemoveFromDoubleIndirectBlock(Transaction& transaction,
67a1b0ec30SJérôme Duval 						uint32 numBlocks);
68a1b0ec30SJérôme Duval 	status_t		_RemoveFromTripleIndirectBlock(Transaction& transaction,
69a1b0ec30SJérôme Duval 						uint32 numBlocks);
70a1b0ec30SJérôme Duval 
71a1b0ec30SJérôme Duval 
72a1b0ec30SJérôme Duval 	const uint32	kBlockSize;
73a1b0ec30SJérôme Duval 	const uint32	kIndirectsPerBlock;
74a1b0ec30SJérôme Duval 	const uint32	kIndirectsPerBlock2;
75a1b0ec30SJérôme Duval 	const uint32	kIndirectsPerBlock3;
76a1b0ec30SJérôme Duval 
77a1b0ec30SJérôme Duval 	const uint32	kMaxDirect;
78a1b0ec30SJérôme Duval 	const uint32	kMaxIndirect;
79a1b0ec30SJérôme Duval 	const uint32	kMaxDoubleIndirect;
80a1b0ec30SJérôme Duval 
81a1b0ec30SJérôme Duval 	Volume*			fVolume;
82a1b0ec30SJérôme Duval 	ext2_data_stream* fStream;
83a1b0ec30SJérôme Duval 	uint32			fFirstBlock;
84a1b0ec30SJérôme Duval 
85a1b0ec30SJérôme Duval 	uint32			fAllocated;
86*45af882dSJérôme Duval 	fsblock_t		fAllocatedPos;
87a1b0ec30SJérôme Duval 	uint32			fWaiting;
88a1b0ec30SJérôme Duval 
89a1b0ec30SJérôme Duval 	uint32			fFreeStart;
90a1b0ec30SJérôme Duval 	uint32			fFreeCount;
91a1b0ec30SJérôme Duval 
92d8772e0cSJérôme Duval 	off_t			fNumBlocks;
93a1b0ec30SJérôme Duval 	uint32			fRemovedBlocks;
949637baaeSJérôme Duval 	off_t			fSize;
95a1b0ec30SJérôme Duval };
96a1b0ec30SJérôme Duval 
97a1b0ec30SJérôme Duval #endif	// DATASTREAM_H
98a1b0ec30SJérôme Duval 
99