xref: /haiku/src/system/boot/loader/file_systems/fat/CachedBlock.h (revision 2b76973fa2401f7a5edf68e6470f3d3210cbcff3)
1 /*
2  * Copyright 2008, Haiku, Inc.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		François Revol <revol@free.fr>
7  */
8 #ifndef CACHED_BLOCK_H
9 #define CACHED_BLOCK_H
10 
11 
12 #include "Volume.h"
13 
14 
15 namespace FATFS {
16 
17 
18 class CachedBlock {
19 	public:
20 		enum {
21 			READ	= 0x01,
22 			CLEAR	= 0x02,
23 			FORCE	= 0x04,
24 		};
25 
26 	public:
27 		CachedBlock(Volume &volume);
28 		CachedBlock(Volume &volume, off_t block);
29 		~CachedBlock();
30 
31 		uint8 *SetTo(off_t block);
32 		status_t SetTo(off_t blockNumber, uint32 flags);
33 		status_t Flush();
34 
35 		void Unset();
36 
37 		uint8 *Block() const { return fBlock; }
38 		off_t BlockNumber() const { return fBlockNumber; }
39 		uint32 BlockSize() const { return fVolume.BlockSize(); }
40 		uint32 BlockShift() const { return fVolume.BlockShift(); }
41 
42 	private:
43 		Volume	&fVolume;
44 		off_t	fBlockNumber;
45 		uint8	*fBlock;
46 };
47 
48 
49 inline void
50 CachedBlock::Unset()
51 {
52 	fBlockNumber = -1;
53 }
54 
55 
56 }	// namespace FATFS
57 
58 
59 #endif	/* CACHED_BLOCK_H */
60