xref: /haiku/src/add-ons/kernel/file_systems/btrfs/Volume.h (revision 6aff37d1c79e20748c683ae224bd629f88a5b0be)
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 "btrfs.h"
11 
12 
13 enum volume_flags {
14 	VOLUME_READ_ONLY	= 0x0001
15 };
16 
17 class BTree;
18 class Chunk;
19 class Inode;
20 
21 
22 class Volume {
23 public:
24 								Volume(fs_volume* volume);
25 								~Volume();
26 
27 			status_t			Mount(const char* device, uint32 flags);
28 			status_t			Unmount();
29 
30 			bool				IsValidSuperBlock();
31 			bool				IsReadOnly() const
32 									{ return (fFlags & VOLUME_READ_ONLY) != 0; }
33 
34 			Inode*				RootNode() const { return fRootNode; }
35 			int					Device() const { return fDevice; }
36 
37 			dev_t				ID() const
38 									{ return fFSVolume ? fFSVolume->id : -1; }
39 			fs_volume*			FSVolume() const { return fFSVolume; }
40 			const char*			Name() const;
41 			BTree*				FSTree() const { return fFSTree; }
42 			BTree*				ExtentTree() const { return fExtentTree; }
43 			BTree*				RootTree() const { return fRootTree; }
44 
45 			uint32				SectorSize() const { return fSectorSize; }
46 			uint32				BlockSize() const { return fBlockSize; }
47 			Chunk*				SystemChunk() const { return fChunk; }
48 
49 			btrfs_super_block&	SuperBlock() { return fSuperBlock; }
50 
51 			status_t			LoadSuperBlock();
52 
53 			// cache access
54 			void*				BlockCache() { return fBlockCache; }
55 
56 	static	status_t			Identify(int fd, btrfs_super_block* superBlock);
57 
58 			status_t			FindBlock(off_t logical, fsblock_t& physical);
59 			status_t			FindBlock(off_t logical, off_t& physical);
60 
61 private:
62 			mutex				fLock;
63 			fs_volume*			fFSVolume;
64 			int					fDevice;
65 			btrfs_super_block	fSuperBlock;
66 			char				fName[32];
67 
68 			uint32				fFlags;
69 			uint32				fSectorSize;
70 			uint32				fBlockSize;
71 
72 			void*				fBlockCache;
73 			Inode*				fRootNode;
74 
75 			Chunk*				fChunk;
76 			BTree*				fChunkTree;
77 			BTree*				fRootTree;
78 			BTree*				fDevTree;
79 			BTree*				fExtentTree;
80 			BTree*				fFSTree;
81 			BTree*				fChecksumTree;
82 };
83 
84 
85 #endif	// VOLUME_H
86