xref: /haiku/src/add-ons/kernel/file_systems/xfs/xfs.h (revision 7a617f59fd64449167bb190666bd44fae7efbe0b)
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 
12 #ifndef _XFS_SB_H_
13 #define _XFS_SB_H_
14 
15 #include "system_dependencies.h"
16 #include "xfs_types.h"
17 
18 #define XFS_SB_MAGIC 0x58465342 /* Identifies XFS. "XFSB" */
19 #define XFS_SB_MAXSIZE 512
20 #define BBLOCKLOG 9		/* Log of block size should be 9 */
21 #define BBLOCKSIZE 1<<BBLOCKLOG		/* The size of a basic block should be 512 */
22 
23 
24 /*	Version 4 superblock definition	*/
25 class XfsSuperBlock
26 {
27 public:
28 
29 			bool 			IsValid();
30 			char*			Name();
31 			uint32			BlockSize();
32 			uint32			Size();
33 			void			SwapEndian();
34 
35 private:
36 
37 			uint32			sb_magicnum;
38 			uint32			sb_blocksize;
39 			xfs_rfsblock_t	sb_dblocks;
40 			xfs_rfsblock_t	sb_rblocks;
41 			xfs_rtblock_t	sb_rextents;
42 			uuid_t			sb_uuid;
43 			xfs_fsblock_t	sb_logstart;
44 			xfs_ino_t		sb_rootino;
45 			xfs_ino_t		sb_rbmino;
46 			xfs_ino_t		sb_rsumino;
47 			xfs_agblock_t	sb_rextsize;
48 			xfs_agblock_t	sb_agblocks;
49 			xfs_agnumber_t	sb_agcount;
50 			xfs_extlen_t	sb_rbmblocks;
51 			xfs_extlen_t	sb_logblocks;
52 			uint16			sb_versionnum;
53 			uint16			sb_sectsize;
54 			uint16			sb_inodesize;
55 			uint16			sb_inopblock;
56 			char			sb_fname[12];
57 			uint8			sb_blocklog;
58 			uint8			sb_sectlog;
59 			uint8			sb_inodelog;
60 			uint8			sb_inopblog;
61 			uint8			sb_agblklog;
62 			uint8			sb_rextslog;
63 			uint8			sb_inprogress;
64 			uint8			sb_imax_pct;
65 			uint64			sb_icount;
66 			uint64			sb_ifree;
67 			uint64			sb_fdblocks;
68 			uint64			sb_frextents;
69 			xfs_ino_t		sb_uquotino;
70 			xfs_ino_t		sb_gquotino;
71 			uint16			sb_qflags;
72 			uint8			sb_flags;
73 			uint8			sb_shared_vn;
74 			xfs_extlen_t	sb_inoalignmt;
75 			uint32			sb_unit;
76 			uint32			sb_width;
77 			uint8			sb_dirblklog;
78 			uint8			sb_logsectlog;
79 			uint16			sb_logsectsize;
80 			uint32			sb_logsunit;
81 			uint32			sb_features2;
82 };
83 
84 /*
85  These flags indicate features introduced over time.
86 
87  If the lower nibble of sb_versionnum >=4 then the following features are
88  checked. If it's equal to 5, it's version 5.
89 */
90 
91 #define XFS_SB_VERSION_ATTRBIT 0x0010
92 #define XFS_SB_VERSION_NLINKBIT 0x0020
93 #define XFS_SB_VERSION_QUOTABIT 0x0040
94 #define XFS_SB_VERSION_ALIGNBIT 0x0080
95 #define XFS_SB_VERSION_DALIGNBIT 0x0100
96 #define XFS_SB_VERSION_SHAREDBIT 0x0200
97 #define XFS_SB_VERSION_LOGV2BIT 0x0400
98 #define XFS_SB_VERSION_SECTORBIT 0x0800
99 #define XFS_SB_VERSION_EXTFLGBIT 0x1000
100 #define XFS_SB_VERSION_DIRV2BIT 0x2000
101 #define XFS_SB_VERSION_MOREBITSBIT 0x4000
102 
103 /*
104 Superblock quota flags - sb_qflags
105 */
106 #define XFS_UQUOTA_ACCT 0x0001
107 #define XFS_UQUOTA_ENFD 0x0002
108 #define XFS_UQUOTA_CHKD 0x0004
109 #define XFS_PQUOTA_ACCT 0x0008
110 #define XFS_OQUOTA_ENFD 0x0010
111 #define XFS_OQUOTA_CHKD 0x0020
112 #define XFS_GQUOTA_ACCT 0x0040
113 #define XFS_GQUOTA_ENFD 0x0080
114 #define XFS_GQUOTA_CHKD 0x0100
115 #define XFS_PQUOTA_ENFD 0x0200
116 #define XFS_PQUOTA_CHKD 0x0400
117 
118 /*
119 	Superblock flags - sb_flags
120 */
121 #define XFS_SBF_READONLY 0x1
122 
123 /*
124 	Extended v4 Superblock flags - sb_features2
125 */
126 
127 #define XFS_SB_VERSION2_LAZYSBCOUNTBIT											\
128 	0x0001	/*update global free space											\
129 			and inode on clean unmount*/
130 #define XFS_SB_VERSION2_ATTR2BIT												\
131 	0x0002	/* optimises the inode layout of ext-attr */
132 #define XFS_SB_VERSION2_PARENTBIT 0x0004	/* Parent pointers */
133 #define XFS_SB_VERSION2_PROJID32BIT 0x0008	/* 32-bit project id */
134 #define XFS_SB_VERSION2_CRCBIT 0x0010		/* Metadata checksumming */
135 #define XFS_SB_VERSION2_FTYPE 0x0020
136 
137 
138 /* AG Free Space Block */
139 
140 /*
141 index 0 for free space B+Tree indexed by block number
142 index 1 for free space B+Tree indexed by extent size
143 
144 Version 5 has XFS_BT_NUM_AGF defined as 3. This is because the index 2 is
145 for reverse-mapped B+Trees. I have spare0/1 defined here instead.
146 */
147 
148 #define XFS_BTNUM_AGF 2
149 #define XFS_AG_MAGICNUM 0x58414746
150 class AGFreeSpace{
151 	public:
152 			void			SwapEndian();
153 	private:
154 			uint32			magicnum;
155 			uint32			versionnum;		// should be set to 1
156 			uint32			seqno;	// defines the ag number for the sector
157 			uint32			length;	// size of ag in fs blocks
158 			uint32			roots[XFS_BTNUM_AGF];	// roots of trees
159 			uint32			spare0;		//spare
160 			uint32			levels[XFS_BTNUM_AGF];	// tree levels
161 			uint32			spare1;		//spare
162 			uint32			flfirst;	// index to first free list block
163 			uint32			fllast;		// index to last free list block
164 			uint32			flcount;	// number of blocks in freelist
165 			uint32			freeblks;	// current num of free blocks in AG
166 			uint32			longest;	// no.of blocks of longest
167 											// contiguous free space in the AG
168 
169 			/*number of blocks used for the free space B+trees.
170 			This is only used if the XFS_SB_VERSION2_LAZYSBCOUNTBIT
171 			bit is set in sb_features2
172 			*/
173 
174 			uint32			btreeblks;
175 }
176 
177 
178 #endif
179