xref: /haiku/src/add-ons/kernel/file_systems/ext2/DataStream.h (revision 45af882d0698d575ec1b4883a8ebff276c9519d8)
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 DATASTREAM_H
9 #define DATASTREAM_H
10 
11 
12 #include "ext2.h"
13 #include "Transaction.h"
14 
15 
16 class Volume;
17 
18 
19 class DataStream
20 {
21 public:
22 					DataStream(Volume* volume, ext2_data_stream* stream,
23 						off_t size);
24 					~DataStream();
25 
26 	status_t		FindBlock(off_t offset, fsblock_t& block,
27 						uint32 *_count = NULL);
28 	status_t		Enlarge(Transaction& transaction, off_t& numBlocks);
29 	status_t		Shrink(Transaction& transaction, off_t& numBlocks);
30 
31 private:
32 	uint32			_BlocksNeeded(off_t end);
33 
34 	status_t		_GetBlock(Transaction& transaction, uint32& block);
35 	status_t		_PrepareBlock(Transaction& transaction, uint32* pos,
36 						uint32& blockNum, bool& clear);
37 
38 	status_t		_AddBlocks(Transaction& transaction, uint32* block,
39 						off_t count);
40 	status_t		_AddBlocks(Transaction& transaction, uint32* block,
41 						off_t start, off_t end, int recursion);
42 
43 	status_t		_AddForDirectBlocks(Transaction& transaction,
44 						uint32 numBlocks);
45 	status_t		_AddForIndirectBlock(Transaction& transaction,
46 						uint32 numBlocks);
47 	status_t		_AddForDoubleIndirectBlock(Transaction& transaction,
48 						uint32 numBlocks);
49 	status_t		_AddForTripleIndirectBlock(Transaction& transaction,
50 						uint32 numBlocks);
51 
52 	status_t		_PerformFree(Transaction& transaction);
53 	status_t		_MarkBlockForRemoval(Transaction& transaction,
54 						uint32* block);
55 
56 	status_t		_FreeBlocks(Transaction& transaction, uint32* block,
57 						uint32 count);
58 	status_t		_FreeBlocks(Transaction& transaction, uint32* block,
59 						off_t start, off_t end, bool freeParent,
60 						int recursion);
61 
62 	status_t		_RemoveFromDirectBlocks(Transaction& transaction,
63 						uint32 numBlocks);
64 	status_t		_RemoveFromIndirectBlock(Transaction& transaction,
65 						uint32 numBlocks);
66 	status_t		_RemoveFromDoubleIndirectBlock(Transaction& transaction,
67 						uint32 numBlocks);
68 	status_t		_RemoveFromTripleIndirectBlock(Transaction& transaction,
69 						uint32 numBlocks);
70 
71 
72 	const uint32	kBlockSize;
73 	const uint32	kIndirectsPerBlock;
74 	const uint32	kIndirectsPerBlock2;
75 	const uint32	kIndirectsPerBlock3;
76 
77 	const uint32	kMaxDirect;
78 	const uint32	kMaxIndirect;
79 	const uint32	kMaxDoubleIndirect;
80 
81 	Volume*			fVolume;
82 	ext2_data_stream* fStream;
83 	uint32			fFirstBlock;
84 
85 	uint32			fAllocated;
86 	fsblock_t		fAllocatedPos;
87 	uint32			fWaiting;
88 
89 	uint32			fFreeStart;
90 	uint32			fFreeCount;
91 
92 	off_t			fNumBlocks;
93 	uint32			fRemovedBlocks;
94 	off_t			fSize;
95 };
96 
97 #endif	// DATASTREAM_H
98 
99