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 uint32 DirBlockLog() const; 45 uint8 AgInodeBits() const; 46 uint8 InodesPerBlkLog() const; 47 uint8 AgBlocksLog() const; 48 xfs_rfsblock_t TotalBlocks() const; 49 xfs_rfsblock_t TotalBlocksWithLog() const; 50 uint64 FreeBlocks() const; 51 uint64 UsedBlocks() const; 52 uint32 Size() const; 53 uint16 InodeSize() const; 54 void SwapEndian(); 55 xfs_ino_t Root() const; 56 xfs_agnumber_t AgCount() const; 57 xfs_agblock_t AgBlocks() const; 58 uint8 Flags() const; 59 uint16 Version() const; 60 uint32 Features2() const; 61 private: 62 63 uint32 sb_magicnum; 64 uint32 sb_blocksize; 65 xfs_rfsblock_t sb_dblocks; 66 xfs_rfsblock_t sb_rblocks; 67 xfs_rtblock_t sb_rextents; 68 uuid_t sb_uuid; 69 xfs_fsblock_t sb_logstart; 70 xfs_ino_t sb_rootino; 71 xfs_ino_t sb_rbmino; 72 xfs_ino_t sb_rsumino; 73 xfs_agblock_t sb_rextsize; 74 xfs_agblock_t sb_agblocks; 75 xfs_agnumber_t sb_agcount; 76 xfs_extlen_t sb_rbmblocks; 77 xfs_extlen_t sb_logblocks; 78 uint16 sb_versionnum; 79 uint16 sb_sectsize; 80 uint16 sb_inodesize; 81 uint16 sb_inopblock; 82 char sb_fname[12]; 83 uint8 sb_blocklog; 84 uint8 sb_sectlog; 85 uint8 sb_inodelog; 86 uint8 sb_inopblog; 87 uint8 sb_agblklog; 88 uint8 sb_rextslog; 89 uint8 sb_inprogress; 90 uint8 sb_imax_pct; 91 uint64 sb_icount; 92 uint64 sb_ifree; 93 uint64 sb_fdblocks; 94 uint64 sb_frextents; 95 xfs_ino_t sb_uquotino; 96 xfs_ino_t sb_gquotino; 97 uint16 sb_qflags; 98 uint8 sb_flags; 99 uint8 sb_shared_vn; 100 xfs_extlen_t sb_inoalignmt; 101 uint32 sb_unit; 102 uint32 sb_width; 103 uint8 sb_dirblklog; 104 uint8 sb_logsectlog; 105 uint16 sb_logsectsize; 106 uint32 sb_logsunit; 107 uint32 sb_features2; 108 }; 109 110 111 /* 112 *These flags indicate features introduced over time. 113 * 114 *If the lower nibble of sb_versionnum >=4 then the following features are 115 *checked. If it's equal to 5, it's version 5. 116 */ 117 118 #define XFS_SB_VERSION_ATTRBIT 0x0010 119 #define XFS_SB_VERSION_NLINKBIT 0x0020 120 #define XFS_SB_VERSION_QUOTABIT 0x0040 121 #define XFS_SB_VERSION_ALIGNBIT 0x0080 122 #define XFS_SB_VERSION_DALIGNBIT 0x0100 123 #define XFS_SB_VERSION_SHAREDBIT 0x0200 124 #define XFS_SB_VERSION_LOGV2BIT 0x0400 125 #define XFS_SB_VERSION_SECTORBIT 0x0800 126 #define XFS_SB_VERSION_EXTFLGBIT 0x1000 127 #define XFS_SB_VERSION_DIRV2BIT 0x2000 128 #define XFS_SB_VERSION_MOREBITSBIT 0x4000 129 130 131 /* 132 Superblock quota flags - sb_qflags 133 */ 134 #define XFS_UQUOTA_ACCT 0x0001 135 #define XFS_UQUOTA_ENFD 0x0002 136 #define XFS_UQUOTA_CHKD 0x0004 137 #define XFS_PQUOTA_ACCT 0x0008 138 #define XFS_OQUOTA_ENFD 0x0010 139 #define XFS_OQUOTA_CHKD 0x0020 140 #define XFS_GQUOTA_ACCT 0x0040 141 #define XFS_GQUOTA_ENFD 0x0080 142 #define XFS_GQUOTA_CHKD 0x0100 143 #define XFS_PQUOTA_ENFD 0x0200 144 #define XFS_PQUOTA_CHKD 0x0400 145 146 147 /* 148 Superblock flags - sb_flags 149 */ 150 #define XFS_SBF_READONLY 0x1 151 152 153 /* 154 Extended v4 Superblock flags - sb_features2 155 */ 156 157 #define XFS_SB_VERSION2_LAZYSBCOUNTBIT 0x00000001 158 // update global free space and inode on clean unmount 159 #define XFS_SB_VERSION2_ATTR2BIT 0x00000002 160 // optimises the inode layout of ext-attr 161 #define XFS_SB_VERSION2_PARENTBIT 0x00000010 /* Parent pointers */ 162 #define XFS_SB_VERSION2_PROJID32BIT 0x00000080 /* 32-bit project id */ 163 #define XFS_SB_VERSION2_CRCBIT 0x00000100 /* Metadata checksumming */ 164 #define XFS_SB_VERSION2_FTYPE 0x00000200 165 166 #endif 167