xref: /haiku/src/add-ons/kernel/file_systems/xfs/Volume.h (revision 38eb9fb0eb050aefd2ca57bd87210a1cce158aa4)
1 /*
2  * Copyright 2020, Shubham Bhagat, shubhambhagat111@yahoo.com
3  * All rights reserved. Distributed under the terms of the MIT License.
4  */
5 #ifndef _VOLUME_H_
6 #define _VOLUME_H_
7 
8 
9 #include <DeviceOpener.h>
10 
11 #include "xfs.h"
12 
13 
14 #define FSBLOCK_SHIFT(fsBlockLog) (fsBlockLog - BASICBLOCKLOG);
15 #define FSBLOCKS_TO_BASICBLOCKS(fsBlockLog, x) x << FSBLOCK_SHIFT(fsBlockLog);
16 	// Converting the FS Blocks to Basic Blocks
17 
18 enum volume_flags {
19 	VOLUME_READ_ONLY	= 0x0001
20 };
21 
22 
23 class Volume {
24 public:
25 								Volume(fs_volume *volume);
26 								~Volume();
27 
28 			status_t			Mount(const char *device, uint32 flags);
29 			status_t			Unmount();
30 			status_t 			Initialize(int fd, const char *label,
31 									uint32 blockSize, uint32 sectorSize);
32 
33 			bool				IsValidSuperBlock() const;
34 			bool				IsReadOnly() const
35 									{ return
36 										(fFlags & VOLUME_READ_ONLY) != 0; }
37 
38 			dev_t 				ID() const
39 									{ return fFSVolume ? fFSVolume->id : -1; }
40 			fs_volume* 			FSVolume() const
41 									{ return fFSVolume; }
42 			const char*			Name() const
43 									{ return fSuperBlock.Name(); }
44 
45 			XfsSuperBlock&		SuperBlock() { return fSuperBlock; }
46 			int					Device() const { return fDevice; }
47 
48 			static	status_t	Identify(int fd, XfsSuperBlock *superBlock);
49 
50 			uint32				BlockSize() const
51 									{ return fSuperBlock.BlockSize(); }
52 
53 			uint8				BlockLog() const
54 									{ return fSuperBlock.BlockLog(); }
55 
56 			uint32				DirBlockSize() const
57 									{ return fSuperBlock.DirBlockSize(); }
58 
59 			uint32				DirBlockLog() const
60 									{ return fSuperBlock.DirBlockLog(); }
61 
62 			uint8				AgInodeBits() const
63 									{ return fSuperBlock.AgInodeBits(); }
64 
65 			uint8				AgBlocksLog() const
66 									{ return fSuperBlock.AgBlocksLog(); }
67 
68 			uint8				InodesPerBlkLog() const
69 									{ return fSuperBlock.InodesPerBlkLog(); }
70 
71 			off_t				Root() const { return fSuperBlock.Root(); }
72 
73 			uint16				InodeSize() const
74 									{ return fSuperBlock.InodeSize(); }
75 
76 			xfs_agnumber_t		AgCount() const
77 									{ return fSuperBlock.AgCount(); }
78 
79 			xfs_agblock_t		AgBlocks() const
80 									{ return fSuperBlock.AgBlocks(); }
81 
82 			uint8				SuperBlockFlags() const
83 									{ return fSuperBlock.Flags(); }
84 
85 			uint32				SuperBlockFeatures2() const
86 									{ return fSuperBlock.Features2(); }
87 
88 	#if 0
89 			off_t				NumBlocks() const
90 									{ return fSuperBlock.NumBlocks(); }
91 	#endif
92 
93 protected:
94 			fs_volume*			fFSVolume;
95 			int					fDevice;
96 			XfsSuperBlock		fSuperBlock;
97 			char				fName[32];
98 				// Filesystem name
99 
100 			uint32				fDeviceBlockSize;
101 			mutex 				fLock;
102 
103 			uint32				fFlags;
104 };
105 
106 #endif
107