1 /* 2 * Copyright 2008, 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 off_t _GroupBlockOffset(uint32 blockIndex); 56 57 private: 58 mutex fLock; 59 fs_volume* fFSVolume; 60 int fDevice; 61 ext2_super_block fSuperBlock; 62 char fName[32]; 63 uint32 fFlags; 64 uint32 fBlockSize; 65 uint32 fBlockShift; 66 uint32 fFirstDataBlock; 67 uint32 fNumGroups; 68 uint32 fGroupsPerBlock; 69 ext2_block_group** fGroupBlocks; 70 uint32 fInodesPerBlock; 71 72 void* fBlockCache; 73 Inode* fRootNode; 74 }; 75 76 #endif // VOLUME_H 77