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 - XFS_MIN_BLOCKSIZE_LOG); 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 IsVersion5() const 35 { return fSuperBlock.IsVersion5(); } 36 bool IsReadOnly() const 37 { return 38 (fFlags & VOLUME_READ_ONLY) != 0; } 39 40 dev_t ID() const 41 { return fFSVolume ? fFSVolume->id : -1; } 42 fs_volume* FSVolume() const 43 { return fFSVolume; } 44 const char* Name() const 45 { return fSuperBlock.Name(); } 46 47 XfsSuperBlock& SuperBlock() { return fSuperBlock; } 48 int Device() const { return fDevice; } 49 50 static status_t Identify(int fd, XfsSuperBlock *superBlock); 51 52 uint32 BlockSize() const 53 { return fSuperBlock.BlockSize(); } 54 55 uint8 BlockLog() const 56 { return fSuperBlock.BlockLog(); } 57 58 uint32 DirBlockSize() const 59 { return fSuperBlock.DirBlockSize(); } 60 61 uint32 DirBlockLog() const 62 { return fSuperBlock.DirBlockLog(); } 63 64 uint8 AgInodeBits() const 65 { return fSuperBlock.AgInodeBits(); } 66 67 uint8 AgBlocksLog() const 68 { return fSuperBlock.AgBlocksLog(); } 69 70 uint8 InodesPerBlkLog() const 71 { return fSuperBlock.InodesPerBlkLog(); } 72 73 off_t Root() const { return fSuperBlock.Root(); } 74 75 uint16 InodeSize() const 76 { return fSuperBlock.InodeSize(); } 77 78 xfs_agnumber_t AgCount() const 79 { return fSuperBlock.AgCount(); } 80 81 xfs_agblock_t AgBlocks() const 82 { return fSuperBlock.AgBlocks(); } 83 84 uint8 SuperBlockFlags() const 85 { return fSuperBlock.Flags(); } 86 87 uint32 SuperBlockFeatures2() const 88 { return fSuperBlock.Features2(); } 89 90 bool XfsHasIncompatFeature() const 91 { return fSuperBlock.XfsHasIncompatFeature(); } 92 93 bool UuidEquals(const uuid_t *u1) 94 { return fSuperBlock.UuidEquals(u1); } 95 96 #if 0 97 off_t NumBlocks() const 98 { return fSuperBlock.NumBlocks(); } 99 #endif 100 101 protected: 102 fs_volume* fFSVolume; 103 int fDevice; 104 XfsSuperBlock fSuperBlock; 105 char fName[32]; 106 // Filesystem name 107 108 uint32 fDeviceBlockSize; 109 mutex fLock; 110 111 uint32 fFlags; 112 }; 113 114 #endif 115