xref: /haiku/src/add-ons/kernel/file_systems/ext2/Volume.h (revision 239222b2369c39dc52df52b0a7cdd6cc0a91bc92)
1 /*
2  * Copyright 2008-2009, Axel Dörfler, axeld@pinc-software.de.
3  * This file may be used under the terms of the MIT License.
4  */
5 #ifndef VOLUME_H
6 #define VOLUME_H
7 
8 
9 #include <lock.h>
10 
11 #include "ext2.h"
12 
13 class Inode;
14 
15 enum volume_flags {
16 	VOLUME_READ_ONLY	= 0x0001
17 };
18 
19 class Volume {
20 public:
21 						Volume(fs_volume* volume);
22 						~Volume();
23 
24 			status_t	Mount(const char* device, uint32 flags);
25 			status_t	Unmount();
26 
27 			bool		IsValidSuperBlock();
28 			bool		IsReadOnly() const { return fFlags & VOLUME_READ_ONLY; }
29 
30 			Inode*		RootNode() const { return fRootNode; }
31 			int			Device() const { return fDevice; }
32 
33 			dev_t		ID() const { return fFSVolume ? fFSVolume->id : -1; }
34 			fs_volume*	FSVolume() const { return fFSVolume; }
35 			const char*	Name() const;
36 
37 			off_t		NumBlocks() const { return fSuperBlock.NumBlocks(); }
38 			off_t		FreeBlocks() const { return fSuperBlock.FreeBlocks(); }
39 
40 			uint32		BlockSize() const { return fBlockSize; }
41 			uint32		BlockShift() const { return fBlockShift; }
42 			uint32		InodeSize() const { return fSuperBlock.InodeSize(); }
43 			ext2_super_block& SuperBlock() { return fSuperBlock; }
44 
45 			status_t	GetInodeBlock(ino_t id, uint32& block);
46 			uint32		InodeBlockIndex(ino_t id) const;
47 			status_t	GetBlockGroup(int32 index, ext2_block_group** _group);
48 
49 			// cache access
50 			void*		BlockCache() { return fBlockCache; }
51 
52 	static	status_t	Identify(int fd, ext2_super_block* superBlock);
53 
54 private:
55 	static uint32		_UnsupportedIncompatibleFeatures(
56 							ext2_super_block& superBlock);
57 			off_t		_GroupBlockOffset(uint32 blockIndex);
58 
59 private:
60 	mutex				fLock;
61 	fs_volume*			fFSVolume;
62 	int					fDevice;
63 	ext2_super_block	fSuperBlock;
64 	char				fName[32];
65 	uint32				fFlags;
66 	uint32				fBlockSize;
67 	uint32				fBlockShift;
68 	uint32				fFirstDataBlock;
69 	uint32				fNumGroups;
70 	uint32				fGroupsPerBlock;
71 	ext2_block_group**	fGroupBlocks;
72 	uint32				fInodesPerBlock;
73 
74 	void*				fBlockCache;
75 	Inode*				fRootNode;
76 };
77 
78 #endif	// VOLUME_H
79