1 /* 2 * Copyright 2020, Shubham Bhagat, shubhambhagat111@yahoo.com 3 * All rights reserved. Distributed under the terms of the MIT License. 4 */ 5 6 /* 7 *Important: 8 *All fields in XFS metadata structures are in big-endian byte order 9 *except for log items which are formatted in host order. 10 * 11 *This file contains all global structure definitions. 12 */ 13 #ifndef _XFS_SB_H_ 14 #define _XFS_SB_H_ 15 16 17 #include "system_dependencies.h" 18 #include "xfs_types.h" 19 20 21 extern fs_vnode_ops gxfsVnodeOps; 22 extern fs_volume_ops gxfsVolumeOps; 23 24 25 #define XFS_SB_MAGIC 0x58465342 26 // Identifies XFS. "XFSB" 27 #define XFS_SB_MAXSIZE 512 28 #define BASICBLOCKLOG 9 29 // Log of block size should be 9 30 #define BASICBLOCKSIZE 1 << BASICBLOCKLOG 31 // The size of a basic block should be 512 32 33 34 /* Version 4 superblock definition */ 35 class XfsSuperBlock { 36 public: 37 38 bool IsValid() const; 39 const char* Name() const; 40 uint32 BlockSize() const; 41 uint8 BlockLog() const; 42 uint32 DirBlockSize() const; 43 // maximum 65536 44 uint8 AgInodeBits() const; 45 uint8 InodesPerBlkLog() const; 46 uint8 AgBlocksLog() const; 47 xfs_rfsblock_t TotalBlocks() const; 48 xfs_rfsblock_t TotalBlocksWithLog() const; 49 uint64 FreeBlocks() const; 50 uint64 UsedBlocks() const; 51 uint32 Size() const; 52 uint16 InodeSize() const; 53 void SwapEndian(); 54 xfs_ino_t Root() const; 55 xfs_agnumber_t AgCount() const; 56 xfs_agblock_t AgBlocks() const; 57 uint8 Flags() const; 58 private: 59 60 uint32 sb_magicnum; 61 uint32 sb_blocksize; 62 xfs_rfsblock_t sb_dblocks; 63 xfs_rfsblock_t sb_rblocks; 64 xfs_rtblock_t sb_rextents; 65 uuid_t sb_uuid; 66 xfs_fsblock_t sb_logstart; 67 xfs_ino_t sb_rootino; 68 xfs_ino_t sb_rbmino; 69 xfs_ino_t sb_rsumino; 70 xfs_agblock_t sb_rextsize; 71 xfs_agblock_t sb_agblocks; 72 xfs_agnumber_t sb_agcount; 73 xfs_extlen_t sb_rbmblocks; 74 xfs_extlen_t sb_logblocks; 75 uint16 sb_versionnum; 76 uint16 sb_sectsize; 77 uint16 sb_inodesize; 78 uint16 sb_inopblock; 79 char sb_fname[12]; 80 uint8 sb_blocklog; 81 uint8 sb_sectlog; 82 uint8 sb_inodelog; 83 uint8 sb_inopblog; 84 uint8 sb_agblklog; 85 uint8 sb_rextslog; 86 uint8 sb_inprogress; 87 uint8 sb_imax_pct; 88 uint64 sb_icount; 89 uint64 sb_ifree; 90 uint64 sb_fdblocks; 91 uint64 sb_frextents; 92 xfs_ino_t sb_uquotino; 93 xfs_ino_t sb_gquotino; 94 uint16 sb_qflags; 95 uint8 sb_flags; 96 uint8 sb_shared_vn; 97 xfs_extlen_t sb_inoalignmt; 98 uint32 sb_unit; 99 uint32 sb_width; 100 uint8 sb_dirblklog; 101 uint8 sb_logsectlog; 102 uint16 sb_logsectsize; 103 uint32 sb_logsunit; 104 uint32 sb_features2; 105 }; 106 107 108 /* 109 *These flags indicate features introduced over time. 110 * 111 *If the lower nibble of sb_versionnum >=4 then the following features are 112 *checked. If it's equal to 5, it's version 5. 113 */ 114 115 #define XFS_SB_VERSION_ATTRBIT 0x0010 116 #define XFS_SB_VERSION_NLINKBIT 0x0020 117 #define XFS_SB_VERSION_QUOTABIT 0x0040 118 #define XFS_SB_VERSION_ALIGNBIT 0x0080 119 #define XFS_SB_VERSION_DALIGNBIT 0x0100 120 #define XFS_SB_VERSION_SHAREDBIT 0x0200 121 #define XFS_SB_VERSION_LOGV2BIT 0x0400 122 #define XFS_SB_VERSION_SECTORBIT 0x0800 123 #define XFS_SB_VERSION_EXTFLGBIT 0x1000 124 #define XFS_SB_VERSION_DIRV2BIT 0x2000 125 #define XFS_SB_VERSION_MOREBITSBIT 0x4000 126 127 128 /* 129 Superblock quota flags - sb_qflags 130 */ 131 #define XFS_UQUOTA_ACCT 0x0001 132 #define XFS_UQUOTA_ENFD 0x0002 133 #define XFS_UQUOTA_CHKD 0x0004 134 #define XFS_PQUOTA_ACCT 0x0008 135 #define XFS_OQUOTA_ENFD 0x0010 136 #define XFS_OQUOTA_CHKD 0x0020 137 #define XFS_GQUOTA_ACCT 0x0040 138 #define XFS_GQUOTA_ENFD 0x0080 139 #define XFS_GQUOTA_CHKD 0x0100 140 #define XFS_PQUOTA_ENFD 0x0200 141 #define XFS_PQUOTA_CHKD 0x0400 142 143 144 /* 145 Superblock flags - sb_flags 146 */ 147 #define XFS_SBF_READONLY 0x1 148 149 150 /* 151 Extended v4 Superblock flags - sb_features2 152 */ 153 154 #define XFS_SB_VERSION2_LAZYSBCOUNTBIT 0x0001 155 // update global free space and inode on clean unmount 156 #define XFS_SB_VERSION2_ATTR2BIT 0x0002 157 // optimises the inode layout of ext-attr 158 #define XFS_SB_VERSION2_PARENTBIT 0x0004 /* Parent pointers */ 159 #define XFS_SB_VERSION2_PROJID32BIT 0x0008 /* 32-bit project id */ 160 #define XFS_SB_VERSION2_CRCBIT 0x0010 /* Metadata checksumming */ 161 #define XFS_SB_VERSION2_FTYPE 0x0020 162 163 #endif 164