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