xref: /haiku/src/add-ons/kernel/file_systems/btrfs/Volume.h (revision 15fb7d88e971c4d6c787c6a3a5c159afb1ebf77b)
1 /*
2  * Copyright 2017, Chế Vũ Gia Hy, cvghy116@gmail.com.
3  * Copyright 2011, Jérôme Duval, korli@users.berlios.de.
4  * Copyright 2008-2010, Axel Dörfler, axeld@pinc-software.de.
5  * This file may be used under the terms of the MIT License.
6  */
7 #ifndef VOLUME_H
8 #define VOLUME_H
9 
10 
11 #include "btrfs.h"
12 
13 
14 enum volume_flags {
15 	VOLUME_READ_ONLY	= 0x0001
16 };
17 
18 class BTree;
19 class Chunk;
20 class Inode;
21 class Journal;
22 class Transaction;
23 class ExtentAllocator;
24 
25 
26 class Volume {
27 public:
28 								Volume(fs_volume* volume);
29 								~Volume();
30 
31 			status_t			Mount(const char* device, uint32 flags);
32 			status_t			Unmount();
33 			status_t			Initialize(int fd, const char* label,
34 									uint32 blockSize, uint32 sectorSize);
35 
36 			bool				IsValidSuperBlock();
37 			bool				IsReadOnly() const
38 									{ return (fFlags & VOLUME_READ_ONLY) != 0; }
39 
40 			Inode*				RootNode() const { return fRootNode; }
41 			int					Device() const { return fDevice; }
42 
43 			dev_t				ID() const
44 									{ return fFSVolume ? fFSVolume->id : -1; }
45 			fs_volume*			FSVolume() const { return fFSVolume; }
46 			const char*			Name() const;
47 			BTree*				FSTree() const { return fFSTree; }
48 			BTree*				ExtentTree() const { return fExtentTree; }
49 			BTree*				RootTree() const { return fRootTree; }
50 
51 			uint32				SectorSize() const { return fSectorSize; }
52 			uint32				MaxInlineSize() const
53 									{ return fSectorSize / 2; }
54 			uint32				BlockSize() const { return fBlockSize; }
55 			ino_t				GetNextInodeID() { return ++fLargestInodeID; }
56 			Chunk*				SystemChunk() const { return fChunk; }
57 			Journal*			GetJournal() const { return fJournal; }
58 			ExtentAllocator*	GetAllocator() const { return fExtentAllocator; }
59 
60 			btrfs_super_block&	SuperBlock() { return fSuperBlock; }
61 
62 			status_t			LoadSuperBlock();
63 			status_t			WriteSuperBlock();
64 
65 			// cache access
66 			void*				BlockCache() { return fBlockCache; }
67 
68 	static	status_t			Identify(int fd, btrfs_super_block* superBlock);
69 
70 			status_t			FindBlock(off_t logical, fsblock_t& physical);
71 			status_t			FindBlock(off_t logical, off_t& physical);
72 			status_t			GetNewBlock(uint64& logical, fsblock_t& physical,
73 									uint64 start = (uint64)-1,
74 									uint64 flags = BTRFS_BLOCKGROUP_FLAG_METADATA);
75 
76 private:
77 			mutex				fLock;
78 			fs_volume*			fFSVolume;
79 			int					fDevice;
80 			ino_t				fLargestInodeID;
81 			btrfs_super_block	fSuperBlock;
82 			char				fName[32];
83 
84 			uint32				fFlags;
85 			uint32				fSectorSize;
86 			uint32				fBlockSize;
87 
88 			void*				fBlockCache;
89 			Inode*				fRootNode;
90 
91 			ExtentAllocator*	fExtentAllocator;
92 			Chunk*				fChunk;
93 			Journal*			fJournal;
94 			BTree*				fChunkTree;
95 			BTree*				fRootTree;
96 			BTree*				fDevTree;
97 			BTree*				fExtentTree;
98 			BTree*				fFSTree;
99 			BTree*				fChecksumTree;
100 };
101 
102 
103 #endif	// VOLUME_H
104