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