xref: /haiku/src/system/boot/loader/file_systems/bfs/Volume.h (revision 13581b3d2a71545960b98fefebc5225b5bf29072)
1 /*
2 ** Copyright 2003, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3 ** Distributed under the terms of the MIT License.
4 */
5 #ifndef VOLUME_H
6 #define VOLUME_H
7 
8 
9 #include <SupportDefs.h>
10 
11 namespace boot {
12 	class Partition;
13 }
14 
15 
16 #include "bfs.h"
17 
18 namespace BFS {
19 
20 class Directory;
21 
22 class Volume {
23 	public:
24 		Volume(boot::Partition *partition);
25 		~Volume();
26 
27 		status_t			InitCheck();
28 		bool				IsValidSuperBlock();
29 
30 		block_run			Root() const { return fSuperBlock.root_dir; }
31 		Directory			*RootNode() const { return fRootNode; }
32 		block_run			Indices() const { return fSuperBlock.indices; }
33 		const char			*Name() const { return fSuperBlock.name; }
34 
35 		int					Device() const { return fDevice; }
36 
37 		off_t				NumBlocks() const { return fSuperBlock.NumBlocks(); }
38 		off_t				UsedBlocks() const { return fSuperBlock.UsedBlocks(); }
39 		off_t				FreeBlocks() const { return NumBlocks() - UsedBlocks(); }
40 
41 		uint32				BlockSize() const { return fSuperBlock.BlockSize(); }
42 		uint32				BlockShift() const { return fSuperBlock.BlockShift(); }
43 		uint32				InodeSize() const { return fSuperBlock.InodeSize(); }
44 		uint32				AllocationGroups() const { return fSuperBlock.AllocationGroups(); }
45 		uint32				AllocationGroupShift() const { return fSuperBlock.AllocationGroupShift(); }
46 		disk_super_block	&SuperBlock() { return fSuperBlock; }
47 
48 		off_t				ToOffset(block_run run) const { return ToBlock(run) << BlockShift(); }
49 		off_t				ToOffset(off_t block) const { return block << BlockShift(); }
50 		off_t				ToBlock(block_run run) const { return ((off_t)run.AllocationGroup() << AllocationGroupShift()) | (uint32)run.Start(); }
51 		block_run			ToBlockRun(off_t block) const;
52 		status_t			ValidateBlockRun(block_run run);
53 
54 		off_t				ToVnode(block_run run) const { return ToBlock(run); }
55 		off_t				ToVnode(off_t block) const { return block; }
56 
57 	protected:
58 		int					fDevice;
59 		disk_super_block	fSuperBlock;
60 
61 		BFS::Directory		*fRootNode;
62 };
63 
64 }	// namespace BFS
65 
66 #endif	/* VOLUME_H */
67