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