xref: /haiku/src/add-ons/kernel/file_systems/btrfs/Volume.h (revision 820dca4df6c7bf955c46e8f6521b9408f50b2900)
1 /*
2  * Copyright 2011, Jérôme Duval, korli@users.berlios.de.
3  * Copyright 2008-2010, Axel Dörfler, axeld@pinc-software.de.
4  * This file may be used under the terms of the MIT License.
5  */
6 #ifndef VOLUME_H
7 #define VOLUME_H
8 
9 
10 #include <lock.h>
11 
12 #include "btrfs.h"
13 
14 
15 enum volume_flags {
16 	VOLUME_READ_ONLY	= 0x0001
17 };
18 
19 class BPlusTree;
20 class Chunk;
21 class Inode;
22 
23 
24 class Volume {
25 public:
26 								Volume(fs_volume* volume);
27 								~Volume();
28 
29 			status_t			Mount(const char* device, uint32 flags);
30 			status_t			Unmount();
31 
32 			bool				IsValidSuperBlock();
33 			bool				IsReadOnly() const
34 									{ return (fFlags & VOLUME_READ_ONLY) != 0; }
35 
36 			Inode*				RootNode() const { return fRootNode; }
37 			int					Device() const { return fDevice; }
38 
39 			dev_t				ID() const
40 									{ return fFSVolume ? fFSVolume->id : -1; }
41 			fs_volume*			FSVolume() const { return fFSVolume; }
42 			const char*			Name() const;
43 			BPlusTree*			FSTree() const { return fFSTree; }
44 			BPlusTree*			RootTree() const { return fRootTree; }
45 
46 			uint32				BlockSize() const { return fBlockSize; }
47 			btrfs_super_block&	SuperBlock() { return fSuperBlock; }
48 
49 			status_t			LoadSuperBlock();
50 
51 			// cache access
52 			void*				BlockCache() { return fBlockCache; }
53 
54 	static	status_t			Identify(int fd, btrfs_super_block* superBlock);
55 
56 			status_t			FindBlock(off_t logical, fsblock_t &physical);
57 			status_t			FindBlock(off_t logical, off_t &physical);
58 
59 private:
60 			mutex				fLock;
61 			fs_volume*			fFSVolume;
62 			int					fDevice;
63 			btrfs_super_block	fSuperBlock;
64 			char				fName[32];
65 
66 			uint32				fFlags;
67 			uint32				fBlockSize;
68 
69 			void*				fBlockCache;
70 			Inode*				fRootNode;
71 
72 			Chunk*				fChunk;
73 			BPlusTree*			fChunkTree;
74 			BPlusTree*			fRootTree;
75 			BPlusTree*			fDevTree;
76 			BPlusTree*			fExtentTree;
77 			BPlusTree*			fFSTree;
78 			BPlusTree*			fChecksumTree;
79 };
80 
81 #endif	// VOLUME_H
82 
83