1 /* 2 * Copyright 2001-2017, Axel Dörfler, axeld@pinc-software.de. 3 * Copyright 2020, Shubham Bhagat, shubhambhagat111@yahoo.com 4 * All rights reserved. Distributed under the terms of the MIT License. 5 */ 6 7 /* 8 *Important: 9 *All fields in XFS metadata structures are in big-endian byte order 10 *except for log items which are formatted in host order. 11 * 12 *This file contains all global structure definitions. 13 */ 14 #ifndef _XFS_SB_H_ 15 #define _XFS_SB_H_ 16 17 18 #include "system_dependencies.h" 19 #include "xfs_types.h" 20 21 22 extern fs_vnode_ops gxfsVnodeOps; 23 extern fs_volume_ops gxfsVolumeOps; 24 25 26 #define XFS_SB_MAGIC 0x58465342 27 #define XFS_MIN_BLOCKSIZE_LOG 9 28 #define XFS_MAX_BLOCKSIZE_LOG 16 29 #define XFS_MIN_BLOCKSIZE (1 << XFS_MIN_BLOCKSIZE_LOG) 30 #define XFS_MAX_BLOCKSIZE (1 << XFS_MAX_BLOCKSIZE_LOG) 31 #define XFS_MIN_CRC_BLOCKSIZE (1 << (XFS_MIN_BLOCKSIZE_LOG + 1)) 32 #define XFS_MIN_SECTORSIZE_LOG 9 33 #define XFS_MAX_SECTORSIZE_LOG 15 34 #define XFS_MIN_SECTORSIZE (1 << XFS_MIN_SECTORSIZE_LOG) 35 #define XFS_MAX_SECTORSIZE (1 << XFS_MAX_SECTORSIZE_LOG) 36 #define XFS_SB_MAXSIZE 512 37 38 39 #define XFS_OPEN_MODE_USER_MASK 0x7fffffff 40 #define XFS_SB_VERSION_NUMBITS 0x000f 41 #define XFS_SB_VERSION_ALLFBITS 0xfff0 42 43 44 /* B+Tree related macros 45 */ 46 #define XFS_BMAP_MAGIC 0x424d4150 47 #define XFS_BMAP_CRC_MAGIC 0x424d4133 48 #define MAX_TREE_DEPTH 5 49 #define XFS_KEY_SIZE sizeof(xfs_fileoff_t) 50 #define XFS_PTR_SIZE sizeof(xfs_fsblock_t) 51 52 53 struct file_cookie { 54 bigtime_t last_notification; 55 off_t last_size; 56 int open_mode; 57 }; 58 59 60 class XfsSuperBlock { 61 public: 62 63 bool IsValid() const; 64 bool IsValidVersion() const; 65 bool IsValidFeatureMask() const; 66 bool IsVersion5() const; 67 bool XfsHasIncompatFeature() const; 68 bool UuidEquals(const uuid_t& u1); 69 const char* Name() const; 70 uint32 BlockSize() const; 71 uint8 BlockLog() const; 72 uint32 DirBlockSize() const; 73 // maximum 65536 74 uint32 DirBlockLog() const; 75 uint8 AgInodeBits() const; 76 uint8 InodesPerBlkLog() const; 77 uint8 AgBlocksLog() const; 78 xfs_rfsblock_t TotalBlocks() const; 79 xfs_rfsblock_t TotalBlocksWithLog() const; 80 uint64 FreeBlocks() const; 81 uint64 UsedBlocks() const; 82 uint32 Size() const; 83 uint16 InodeSize() const; 84 void SwapEndian(); 85 xfs_ino_t Root() const; 86 xfs_agnumber_t AgCount() const; 87 xfs_agblock_t AgBlocks() const; 88 uint8 Flags() const; 89 uint16 Version() const; 90 uint32 Features2() const; 91 uint32 Crc() const; 92 uint32 MagicNum() const; 93 static size_t Offset_crc() 94 { return offsetof(XfsSuperBlock, sb_crc);} 95 private: 96 97 uint32 sb_magicnum; 98 uint32 sb_blocksize; 99 xfs_rfsblock_t sb_dblocks; 100 xfs_rfsblock_t sb_rblocks; 101 xfs_rtblock_t sb_rextents; 102 uuid_t sb_uuid; 103 xfs_fsblock_t sb_logstart; 104 xfs_ino_t sb_rootino; 105 xfs_ino_t sb_rbmino; 106 xfs_ino_t sb_rsumino; 107 xfs_agblock_t sb_rextsize; 108 xfs_agblock_t sb_agblocks; 109 xfs_agnumber_t sb_agcount; 110 xfs_extlen_t sb_rbmblocks; 111 xfs_extlen_t sb_logblocks; 112 uint16 sb_versionnum; 113 uint16 sb_sectsize; 114 uint16 sb_inodesize; 115 uint16 sb_inopblock; 116 char sb_fname[12]; 117 uint8 sb_blocklog; 118 uint8 sb_sectlog; 119 uint8 sb_inodelog; 120 uint8 sb_inopblog; 121 uint8 sb_agblklog; 122 uint8 sb_rextslog; 123 uint8 sb_inprogress; 124 uint8 sb_imax_pct; 125 uint64 sb_icount; 126 uint64 sb_ifree; 127 uint64 sb_fdblocks; 128 uint64 sb_frextents; 129 xfs_ino_t sb_uquotino; 130 xfs_ino_t sb_gquotino; 131 uint16 sb_qflags; 132 uint8 sb_flags; 133 uint8 sb_shared_vn; 134 xfs_extlen_t sb_inoalignmt; 135 uint32 sb_unit; 136 uint32 sb_width; 137 uint8 sb_dirblklog; 138 uint8 sb_logsectlog; 139 uint16 sb_logsectsize; 140 uint32 sb_logsunit; 141 uint32 sb_features2; 142 uint32 sb_bad_features2; 143 144 // version 5 145 146 uint32 sb_features_compat; 147 uint32 sb_features_ro_compat; 148 uint32 sb_features_incompat; 149 uint32 sb_features_log_incompat; 150 uint32 sb_crc; 151 private: 152 xfs_extlen_t sb_spino_align; 153 154 xfs_ino_t sb_pquotino; 155 xfs_lsn_t sb_lsn; 156 uuid_t sb_meta_uuid; 157 }; 158 159 160 /* 161 *These flags indicate features introduced over time. 162 * 163 *If the lower nibble of sb_versionnum >=4 then the following features are 164 *checked. If it's equal to 5, it's version 5. 165 */ 166 167 #define XFS_SB_VERSION_ATTRBIT 0x0010 168 #define XFS_SB_VERSION_NLINKBIT 0x0020 169 #define XFS_SB_VERSION_QUOTABIT 0x0040 170 #define XFS_SB_VERSION_ALIGNBIT 0x0080 171 #define XFS_SB_VERSION_DALIGNBIT 0x0100 172 #define XFS_SB_VERSION_SHAREDBIT 0x0200 173 #define XFS_SB_VERSION_LOGV2BIT 0x0400 174 #define XFS_SB_VERSION_SECTORBIT 0x0800 175 #define XFS_SB_VERSION_EXTFLGBIT 0x1000 176 #define XFS_SB_VERSION_DIRV2BIT 0x2000 177 #define XFS_SB_VERSION_MOREBITSBIT 0x4000 178 179 #define XFS_SB_VERSION_OKBITS \ 180 ((XFS_SB_VERSION_NUMBITS | XFS_SB_VERSION_ALLFBITS) & \ 181 ~XFS_SB_VERSION_SHAREDBIT) 182 183 /* 184 Superblock quota flags - sb_qflags 185 */ 186 #define XFS_UQUOTA_ACCT 0x0001 187 #define XFS_UQUOTA_ENFD 0x0002 188 #define XFS_UQUOTA_CHKD 0x0004 189 #define XFS_PQUOTA_ACCT 0x0008 190 #define XFS_OQUOTA_ENFD 0x0010 191 #define XFS_OQUOTA_CHKD 0x0020 192 #define XFS_GQUOTA_ACCT 0x0040 193 #define XFS_GQUOTA_ENFD 0x0080 194 #define XFS_GQUOTA_CHKD 0x0100 195 #define XFS_PQUOTA_ENFD 0x0200 196 #define XFS_PQUOTA_CHKD 0x0400 197 198 199 /* 200 Superblock flags - sb_flags 201 */ 202 #define XFS_SBF_READONLY 0x1 203 204 205 /* 206 Extended v4 Superblock flags - sb_features2 207 */ 208 209 #define XFS_SB_VERSION2_LAZYSBCOUNTBIT 0x00000001 210 // update global free space and inode on clean unmount 211 #define XFS_SB_VERSION2_ATTR2BIT 0x00000002 212 // optimises the inode layout of ext-attr 213 #define XFS_SB_VERSION2_PARENTBIT 0x00000010 /* Parent pointers */ 214 #define XFS_SB_VERSION2_PROJID32BIT 0x00000080 /* 32-bit project id */ 215 #define XFS_SB_VERSION2_CRCBIT 0x00000100 /* Metadata checksumming */ 216 #define XFS_SB_VERSION2_FTYPE 0x00000200 217 218 #define XFS_SB_VERSION2_OKBITS \ 219 (XFS_SB_VERSION2_LAZYSBCOUNTBIT | \ 220 XFS_SB_VERSION2_ATTR2BIT | \ 221 XFS_SB_VERSION2_PROJID32BIT | \ 222 XFS_SB_VERSION2_FTYPE) 223 224 /* 225 Extended Version 5 Superblock Read-Only compatibility flags 226 */ 227 228 #define XFS_SB_FEAT_RO_COMPAT_FINOBT (1 << 0) /* free inode btree */ 229 #define XFS_SB_FEAT_RO_COMPAT_RMAPBT (1 << 1) /* reverse map btree */ 230 #define XFS_SB_FEAT_RO_COMPAT_REFLINK (1 << 2) /* reflinked files */ 231 #define XFS_SB_FEAT_RO_COMPAT_INOBTCNT (1 << 3) /* inobt block counts */ 232 233 /* 234 Extended Version 5 Superblock Read-Write incompatibility flags 235 */ 236 237 #define XFS_SB_FEAT_INCOMPAT_FTYPE (1 << 0) /* filetype in dirent */ 238 #define XFS_SB_FEAT_INCOMPAT_SPINODES (1 << 1) /* sparse inode chunks */ 239 #define XFS_SB_FEAT_INCOMPAT_META_UUID (1 << 2) /* metadata UUID */ 240 #define XFS_SB_FEAT_INCOMPAT_BIGTIME (1 << 3) /* large timestamps */ 241 242 /* 243 Extended v5 superblock feature masks. These are to be used for new v5 244 superblock features only. 245 */ 246 247 #define XFS_SB_FEAT_COMPAT_ALL 0 248 #define XFS_SB_FEAT_COMPAT_UNKNOWN ~XFS_SB_FEAT_COMPAT_ALL 249 250 #define XFS_SB_FEAT_RO_COMPAT_ALL \ 251 (XFS_SB_FEAT_RO_COMPAT_FINOBT | \ 252 XFS_SB_FEAT_RO_COMPAT_RMAPBT | \ 253 XFS_SB_FEAT_RO_COMPAT_REFLINK| \ 254 XFS_SB_FEAT_RO_COMPAT_INOBTCNT) 255 #define XFS_SB_FEAT_RO_COMPAT_UNKNOWN ~XFS_SB_FEAT_RO_COMPAT_ALL 256 257 #define XFS_SB_FEAT_INCOMPAT_ALL \ 258 (XFS_SB_FEAT_INCOMPAT_FTYPE| \ 259 XFS_SB_FEAT_INCOMPAT_SPINODES| \ 260 XFS_SB_FEAT_INCOMPAT_META_UUID| \ 261 XFS_SB_FEAT_INCOMPAT_BIGTIME) 262 263 #define XFS_SB_FEAT_INCOMPAT_UNKNOWN ~XFS_SB_FEAT_INCOMPAT_ALL 264 265 #endif 266