xref: /haiku/src/add-ons/kernel/file_systems/btrfs/Volume.h (revision b08627f310bb2e80bca50176e7a758182384735a)
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 
34 			bool				IsValidSuperBlock();
35 			bool				IsReadOnly() const
36 									{ return (fFlags & VOLUME_READ_ONLY) != 0; }
37 
38 			Inode*				RootNode() const { return fRootNode; }
39 			int					Device() const { return fDevice; }
40 
41 			dev_t				ID() const
42 									{ return fFSVolume ? fFSVolume->id : -1; }
43 			fs_volume*			FSVolume() const { return fFSVolume; }
44 			const char*			Name() const;
45 			BTree*				FSTree() const { return fFSTree; }
46 			BTree*				ExtentTree() const { return fExtentTree; }
47 			BTree*				RootTree() const { return fRootTree; }
48 
49 			uint32				SectorSize() const { return fSectorSize; }
50 			uint32				MaxInlineSize() const
51 									{ return fSectorSize / 2; }
52 			uint32				BlockSize() const { return fBlockSize; }
53 			ino_t				GetNextInodeID() { return ++fLargestInodeID; }
54 			Chunk*				SystemChunk() const { return fChunk; }
55 			Journal*			GetJournal() const { return fJournal; }
56 			ExtentAllocator*	GetAllocator() const { return fExtentAllocator; }
57 
58 			btrfs_super_block&	SuperBlock() { return fSuperBlock; }
59 
60 			status_t			LoadSuperBlock();
61 
62 			// cache access
63 			void*				BlockCache() { return fBlockCache; }
64 
65 	static	status_t			Identify(int fd, btrfs_super_block* superBlock);
66 
67 			status_t			FindBlock(off_t logical, fsblock_t& physical);
68 			status_t			FindBlock(off_t logical, off_t& physical);
69 			status_t			GetNewBlock(uint64& logical, fsblock_t& physical,
70 									uint64 start = (uint64)-1,
71 									uint64 flags = BTRFS_BLOCKGROUP_FLAG_METADATA);
72 
73 private:
74 			mutex				fLock;
75 			fs_volume*			fFSVolume;
76 			int					fDevice;
77 			ino_t				fLargestInodeID;
78 			btrfs_super_block	fSuperBlock;
79 			char				fName[32];
80 
81 			uint32				fFlags;
82 			uint32				fSectorSize;
83 			uint32				fBlockSize;
84 
85 			void*				fBlockCache;
86 			Inode*				fRootNode;
87 
88 			ExtentAllocator*	fExtentAllocator;
89 			Chunk*				fChunk;
90 			Journal*			fJournal;
91 			BTree*				fChunkTree;
92 			BTree*				fRootTree;
93 			BTree*				fDevTree;
94 			BTree*				fExtentTree;
95 			BTree*				fFSTree;
96 			BTree*				fChecksumTree;
97 };
98 
99 
100 #endif	// VOLUME_H
101