xref: /haiku/src/add-ons/kernel/file_systems/xfs/xfs.h (revision 02354704729d38c3b078c696adc1bbbd33cbcf72)
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 	// Identifies XFS. "XFSB"
28 #define XFS_SB_MAXSIZE 512
29 #define BASICBLOCKLOG 9
30 	// Log of block size should be 9
31 #define BASICBLOCKSIZE (1 << BASICBLOCKLOG)
32 	// The size of a basic block should be 512
33 #define XFS_OPEN_MODE_USER_MASK 0x7fffffff
34 
35 /* B+Tree related macros
36 */
37 #define XFS_BTREE_SBLOCK_SIZE	18
38 	// Header for Short Format btree
39 #define XFS_BTREE_LBLOCK_SIZE	24
40 	// Header for Long Format btree
41 #define XFS_BMAP_MAGIC 0x424d4150
42 #define MAX_TREE_DEPTH 5
43 #define XFS_KEY_SIZE sizeof(xfs_fileoff_t)
44 #define XFS_PTR_SIZE sizeof(xfs_fsblock_t)
45 
46 struct file_cookie {
47 	bigtime_t last_notification;
48 	off_t	last_size;
49 	int		open_mode;
50 };
51 
52 
53 /*	Version 4 superblock definition	*/
54 class XfsSuperBlock {
55 public:
56 
57 			bool 				IsValid() const;
58 			const char*			Name() const;
59 			uint32				BlockSize() const;
60 			uint8				BlockLog() const;
61 			uint32				DirBlockSize() const;
62 				// maximum 65536
63 			uint32				DirBlockLog() const;
64 			uint8				AgInodeBits() const;
65 			uint8				InodesPerBlkLog() const;
66 			uint8				AgBlocksLog() const;
67 			xfs_rfsblock_t		TotalBlocks() const;
68 			xfs_rfsblock_t		TotalBlocksWithLog() const;
69 			uint64				FreeBlocks() const;
70 			uint64				UsedBlocks() const;
71 			uint32				Size() const;
72 			uint16				InodeSize() const;
73 			void				SwapEndian();
74 			xfs_ino_t			Root() const;
75 			xfs_agnumber_t		AgCount() const;
76 			xfs_agblock_t		AgBlocks() const;
77 			uint8				Flags() const;
78 			uint16				Version() const;
79 			uint32				Features2() const;
80 private:
81 
82 			uint32				sb_magicnum;
83 			uint32				sb_blocksize;
84 			xfs_rfsblock_t		sb_dblocks;
85 			xfs_rfsblock_t		sb_rblocks;
86 			xfs_rtblock_t		sb_rextents;
87 			uuid_t				sb_uuid;
88 			xfs_fsblock_t		sb_logstart;
89 			xfs_ino_t			sb_rootino;
90 			xfs_ino_t			sb_rbmino;
91 			xfs_ino_t			sb_rsumino;
92 			xfs_agblock_t		sb_rextsize;
93 			xfs_agblock_t		sb_agblocks;
94 			xfs_agnumber_t		sb_agcount;
95 			xfs_extlen_t		sb_rbmblocks;
96 			xfs_extlen_t		sb_logblocks;
97 			uint16				sb_versionnum;
98 			uint16				sb_sectsize;
99 			uint16				sb_inodesize;
100 			uint16				sb_inopblock;
101 			char				sb_fname[12];
102 			uint8				sb_blocklog;
103 			uint8				sb_sectlog;
104 			uint8				sb_inodelog;
105 			uint8				sb_inopblog;
106 			uint8				sb_agblklog;
107 			uint8				sb_rextslog;
108 			uint8				sb_inprogress;
109 			uint8				sb_imax_pct;
110 			uint64				sb_icount;
111 			uint64				sb_ifree;
112 			uint64				sb_fdblocks;
113 			uint64				sb_frextents;
114 			xfs_ino_t			sb_uquotino;
115 			xfs_ino_t			sb_gquotino;
116 			uint16				sb_qflags;
117 			uint8				sb_flags;
118 			uint8				sb_shared_vn;
119 			xfs_extlen_t		sb_inoalignmt;
120 			uint32				sb_unit;
121 			uint32				sb_width;
122 			uint8				sb_dirblklog;
123 			uint8				sb_logsectlog;
124 			uint16				sb_logsectsize;
125 			uint32				sb_logsunit;
126 			uint32				sb_features2;
127 };
128 
129 
130 /*
131 *These flags indicate features introduced over time.
132 *
133 *If the lower nibble of sb_versionnum >=4 then the following features are
134 *checked. If it's equal to 5, it's version 5.
135 */
136 
137 #define XFS_SB_VERSION_ATTRBIT 0x0010
138 #define XFS_SB_VERSION_NLINKBIT 0x0020
139 #define XFS_SB_VERSION_QUOTABIT 0x0040
140 #define XFS_SB_VERSION_ALIGNBIT 0x0080
141 #define XFS_SB_VERSION_DALIGNBIT 0x0100
142 #define XFS_SB_VERSION_SHAREDBIT 0x0200
143 #define XFS_SB_VERSION_LOGV2BIT 0x0400
144 #define XFS_SB_VERSION_SECTORBIT 0x0800
145 #define XFS_SB_VERSION_EXTFLGBIT 0x1000
146 #define XFS_SB_VERSION_DIRV2BIT 0x2000
147 #define XFS_SB_VERSION_MOREBITSBIT 0x4000
148 
149 
150 /*
151 Superblock quota flags - sb_qflags
152 */
153 #define XFS_UQUOTA_ACCT 0x0001
154 #define XFS_UQUOTA_ENFD 0x0002
155 #define XFS_UQUOTA_CHKD 0x0004
156 #define XFS_PQUOTA_ACCT 0x0008
157 #define XFS_OQUOTA_ENFD 0x0010
158 #define XFS_OQUOTA_CHKD 0x0020
159 #define XFS_GQUOTA_ACCT 0x0040
160 #define XFS_GQUOTA_ENFD 0x0080
161 #define XFS_GQUOTA_CHKD 0x0100
162 #define XFS_PQUOTA_ENFD 0x0200
163 #define XFS_PQUOTA_CHKD 0x0400
164 
165 
166 /*
167 	Superblock flags - sb_flags
168 */
169 #define XFS_SBF_READONLY 0x1
170 
171 
172 /*
173 	Extended v4 Superblock flags - sb_features2
174 */
175 
176 #define XFS_SB_VERSION2_LAZYSBCOUNTBIT	0x00000001
177 	// update global free space and inode on clean unmount
178 #define XFS_SB_VERSION2_ATTR2BIT	0x00000002
179 	// optimises the inode layout of ext-attr
180 #define XFS_SB_VERSION2_PARENTBIT 0x00000010	/* Parent pointers */
181 #define XFS_SB_VERSION2_PROJID32BIT 0x00000080	/* 32-bit project id */
182 #define XFS_SB_VERSION2_CRCBIT 0x00000100		/* Metadata checksumming */
183 #define XFS_SB_VERSION2_FTYPE 0x00000200
184 
185 #endif
186