xref: /haiku/src/add-ons/kernel/file_systems/xfs/xfs.h (revision 4a55cc230cf7566cadcbb23b1928eefff8aea9a2)
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 private:
94 
95 			uint32				sb_magicnum;
96 			uint32				sb_blocksize;
97 			xfs_rfsblock_t		sb_dblocks;
98 			xfs_rfsblock_t		sb_rblocks;
99 			xfs_rtblock_t		sb_rextents;
100 			uuid_t				sb_uuid;
101 			xfs_fsblock_t		sb_logstart;
102 			xfs_ino_t			sb_rootino;
103 			xfs_ino_t			sb_rbmino;
104 			xfs_ino_t			sb_rsumino;
105 			xfs_agblock_t		sb_rextsize;
106 			xfs_agblock_t		sb_agblocks;
107 			xfs_agnumber_t		sb_agcount;
108 			xfs_extlen_t		sb_rbmblocks;
109 			xfs_extlen_t		sb_logblocks;
110 			uint16				sb_versionnum;
111 			uint16				sb_sectsize;
112 			uint16				sb_inodesize;
113 			uint16				sb_inopblock;
114 			char				sb_fname[12];
115 			uint8				sb_blocklog;
116 			uint8				sb_sectlog;
117 			uint8				sb_inodelog;
118 			uint8				sb_inopblog;
119 			uint8				sb_agblklog;
120 			uint8				sb_rextslog;
121 			uint8				sb_inprogress;
122 			uint8				sb_imax_pct;
123 			uint64				sb_icount;
124 			uint64				sb_ifree;
125 			uint64				sb_fdblocks;
126 			uint64				sb_frextents;
127 			xfs_ino_t			sb_uquotino;
128 			xfs_ino_t			sb_gquotino;
129 			uint16				sb_qflags;
130 			uint8				sb_flags;
131 			uint8				sb_shared_vn;
132 			xfs_extlen_t		sb_inoalignmt;
133 			uint32				sb_unit;
134 			uint32				sb_width;
135 			uint8				sb_dirblklog;
136 			uint8				sb_logsectlog;
137 			uint16				sb_logsectsize;
138 			uint32				sb_logsunit;
139 			uint32				sb_features2;
140 			uint32				sb_bad_features2;
141 
142 			// version 5
143 
144 			uint32				sb_features_compat;
145 			uint32				sb_features_ro_compat;
146 			uint32				sb_features_incompat;
147 			uint32				sb_features_log_incompat;
148 public:
149 			uint32				sb_crc;
150 private:
151 			xfs_extlen_t		sb_spino_align;
152 
153 			xfs_ino_t			sb_pquotino;
154 			xfs_lsn_t			sb_lsn;
155 			uuid_t				sb_meta_uuid;
156 };
157 
158 
159 /*
160 *These flags indicate features introduced over time.
161 *
162 *If the lower nibble of sb_versionnum >=4 then the following features are
163 *checked. If it's equal to 5, it's version 5.
164 */
165 
166 #define XFS_SB_VERSION_ATTRBIT 0x0010
167 #define XFS_SB_VERSION_NLINKBIT 0x0020
168 #define XFS_SB_VERSION_QUOTABIT 0x0040
169 #define XFS_SB_VERSION_ALIGNBIT 0x0080
170 #define XFS_SB_VERSION_DALIGNBIT 0x0100
171 #define XFS_SB_VERSION_SHAREDBIT 0x0200
172 #define XFS_SB_VERSION_LOGV2BIT 0x0400
173 #define XFS_SB_VERSION_SECTORBIT 0x0800
174 #define XFS_SB_VERSION_EXTFLGBIT 0x1000
175 #define XFS_SB_VERSION_DIRV2BIT 0x2000
176 #define XFS_SB_VERSION_MOREBITSBIT 0x4000
177 
178 #define	XFS_SB_VERSION_OKBITS		\
179 	((XFS_SB_VERSION_NUMBITS | XFS_SB_VERSION_ALLFBITS) & \
180 		~XFS_SB_VERSION_SHAREDBIT)
181 
182 /*
183 Superblock quota flags - sb_qflags
184 */
185 #define XFS_UQUOTA_ACCT 0x0001
186 #define XFS_UQUOTA_ENFD 0x0002
187 #define XFS_UQUOTA_CHKD 0x0004
188 #define XFS_PQUOTA_ACCT 0x0008
189 #define XFS_OQUOTA_ENFD 0x0010
190 #define XFS_OQUOTA_CHKD 0x0020
191 #define XFS_GQUOTA_ACCT 0x0040
192 #define XFS_GQUOTA_ENFD 0x0080
193 #define XFS_GQUOTA_CHKD 0x0100
194 #define XFS_PQUOTA_ENFD 0x0200
195 #define XFS_PQUOTA_CHKD 0x0400
196 
197 
198 /*
199 	Superblock flags - sb_flags
200 */
201 #define XFS_SBF_READONLY 0x1
202 
203 
204 /*
205 	Extended v4 Superblock flags - sb_features2
206 */
207 
208 #define XFS_SB_VERSION2_LAZYSBCOUNTBIT	0x00000001
209 	// update global free space and inode on clean unmount
210 #define XFS_SB_VERSION2_ATTR2BIT	0x00000002
211 	// optimises the inode layout of ext-attr
212 #define XFS_SB_VERSION2_PARENTBIT 0x00000010	/* Parent pointers */
213 #define XFS_SB_VERSION2_PROJID32BIT 0x00000080	/* 32-bit project id */
214 #define XFS_SB_VERSION2_CRCBIT 0x00000100		/* Metadata checksumming */
215 #define XFS_SB_VERSION2_FTYPE 0x00000200
216 
217 #define	XFS_SB_VERSION2_OKBITS		\
218 	(XFS_SB_VERSION2_LAZYSBCOUNTBIT	| \
219 	 XFS_SB_VERSION2_ATTR2BIT	| \
220 	 XFS_SB_VERSION2_PROJID32BIT	| \
221 	 XFS_SB_VERSION2_FTYPE)
222 
223 /*
224 	Extended Version 5 Superblock Read-Only compatibility flags
225 */
226 
227 #define XFS_SB_FEAT_RO_COMPAT_FINOBT   (1 << 0)		/* free inode btree */
228 #define XFS_SB_FEAT_RO_COMPAT_RMAPBT   (1 << 1)		/* reverse map btree */
229 #define XFS_SB_FEAT_RO_COMPAT_REFLINK  (1 << 2)		/* reflinked files */
230 #define XFS_SB_FEAT_RO_COMPAT_INOBTCNT (1 << 3)		/* inobt block counts */
231 
232 /*
233 	Extended Version 5 Superblock Read-Write incompatibility flags
234 */
235 
236 #define XFS_SB_FEAT_INCOMPAT_FTYPE	(1 << 0)	/* filetype in dirent */
237 #define XFS_SB_FEAT_INCOMPAT_SPINODES	(1 << 1)	/* sparse inode chunks */
238 #define XFS_SB_FEAT_INCOMPAT_META_UUID	(1 << 2)	/* metadata UUID */
239 #define XFS_SB_FEAT_INCOMPAT_BIGTIME	(1 << 3)	/* large timestamps */
240 
241 /*
242 	 Extended v5 superblock feature masks. These are to be used for new v5
243  	 superblock features only.
244 */
245 
246 #define XFS_SB_FEAT_COMPAT_ALL 0
247 #define XFS_SB_FEAT_COMPAT_UNKNOWN	~XFS_SB_FEAT_COMPAT_ALL
248 
249 #define XFS_SB_FEAT_RO_COMPAT_ALL \
250 		(XFS_SB_FEAT_RO_COMPAT_FINOBT | \
251 		 XFS_SB_FEAT_RO_COMPAT_RMAPBT | \
252 		 XFS_SB_FEAT_RO_COMPAT_REFLINK| \
253 		 XFS_SB_FEAT_RO_COMPAT_INOBTCNT)
254 #define XFS_SB_FEAT_RO_COMPAT_UNKNOWN	~XFS_SB_FEAT_RO_COMPAT_ALL
255 
256 #define XFS_SB_FEAT_INCOMPAT_ALL \
257 		(XFS_SB_FEAT_INCOMPAT_FTYPE|	\
258 		 XFS_SB_FEAT_INCOMPAT_SPINODES|	\
259 		 XFS_SB_FEAT_INCOMPAT_META_UUID| \
260 		 XFS_SB_FEAT_INCOMPAT_BIGTIME)
261 
262 #define XFS_SB_FEAT_INCOMPAT_UNKNOWN	~XFS_SB_FEAT_INCOMPAT_ALL
263 
264 #endif
265