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 168 #define XFS_SB_VERSION_SHAREDBIT 0x0200 169 #define XFS_SB_VERSION_EXTFLGBIT 0x1000 170 #define XFS_SB_VERSION_DIRV2BIT 0x2000 171 #define XFS_SB_VERSION_MOREBITSBIT 0x4000 172 173 #define XFS_SB_VERSION_OKBITS \ 174 ((XFS_SB_VERSION_NUMBITS | XFS_SB_VERSION_ALLFBITS) & \ 175 ~XFS_SB_VERSION_SHAREDBIT) 176 177 178 /* 179 Superblock quota flags - sb_qflags 180 */ 181 #define XFS_OQUOTA_ENFD 0x0010 182 #define XFS_OQUOTA_CHKD 0x0020 183 #define XFS_GQUOTA_ENFD 0x0080 184 #define XFS_GQUOTA_CHKD 0x0100 185 #define XFS_PQUOTA_ENFD 0x0200 186 #define XFS_PQUOTA_CHKD 0x0400 187 188 189 /* 190 Extended v4 Superblock flags - sb_features2 191 */ 192 193 #define XFS_SB_VERSION2_LAZYSBCOUNTBIT 0x00000001 194 // update global free space and inode on clean unmount 195 #define XFS_SB_VERSION2_ATTR2BIT 0x00000002 196 // optimises the inode layout of ext-attr 197 #define XFS_SB_VERSION2_PROJID32BIT 0x00000080 /* 32-bit project id */ 198 #define XFS_SB_VERSION2_FTYPE 0x00000200 199 200 #define XFS_SB_VERSION2_OKBITS \ 201 (XFS_SB_VERSION2_LAZYSBCOUNTBIT | \ 202 XFS_SB_VERSION2_ATTR2BIT | \ 203 XFS_SB_VERSION2_PROJID32BIT | \ 204 XFS_SB_VERSION2_FTYPE) 205 206 /* 207 Extended Version 5 Superblock Read-Only compatibility flags 208 */ 209 210 #define XFS_SB_FEAT_RO_COMPAT_FINOBT (1 << 0) /* free inode btree */ 211 #define XFS_SB_FEAT_RO_COMPAT_RMAPBT (1 << 1) /* reverse map btree */ 212 #define XFS_SB_FEAT_RO_COMPAT_REFLINK (1 << 2) /* reflinked files */ 213 #define XFS_SB_FEAT_RO_COMPAT_INOBTCNT (1 << 3) /* inobt block counts */ 214 215 /* 216 Extended Version 5 Superblock Read-Write incompatibility flags 217 */ 218 219 #define XFS_SB_FEAT_INCOMPAT_FTYPE (1 << 0) /* filetype in dirent */ 220 #define XFS_SB_FEAT_INCOMPAT_SPINODES (1 << 1) /* sparse inode chunks */ 221 #define XFS_SB_FEAT_INCOMPAT_META_UUID (1 << 2) /* metadata UUID */ 222 #define XFS_SB_FEAT_INCOMPAT_BIGTIME (1 << 3) /* large timestamps */ 223 224 /* 225 Extended v5 superblock feature masks. These are to be used for new v5 226 superblock features only. 227 */ 228 229 #define XFS_SB_FEAT_COMPAT_ALL 0 230 #define XFS_SB_FEAT_COMPAT_UNKNOWN ~XFS_SB_FEAT_COMPAT_ALL 231 232 #define XFS_SB_FEAT_RO_COMPAT_ALL \ 233 (XFS_SB_FEAT_RO_COMPAT_FINOBT | \ 234 XFS_SB_FEAT_RO_COMPAT_RMAPBT | \ 235 XFS_SB_FEAT_RO_COMPAT_REFLINK| \ 236 XFS_SB_FEAT_RO_COMPAT_INOBTCNT) 237 #define XFS_SB_FEAT_RO_COMPAT_UNKNOWN ~XFS_SB_FEAT_RO_COMPAT_ALL 238 239 #define XFS_SB_FEAT_INCOMPAT_ALL \ 240 (XFS_SB_FEAT_INCOMPAT_FTYPE| \ 241 XFS_SB_FEAT_INCOMPAT_SPINODES| \ 242 XFS_SB_FEAT_INCOMPAT_META_UUID| \ 243 XFS_SB_FEAT_INCOMPAT_BIGTIME) 244 245 #define XFS_SB_FEAT_INCOMPAT_UNKNOWN ~XFS_SB_FEAT_INCOMPAT_ALL 246 247 #endif