blob: 94660b1a6cccd5c5570a8224cf03d3ca43d8ecb9 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Nathan Scott7b718762005-11-02 14:58:39 +11002 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Nathan Scott7b718762005-11-02 14:58:39 +11005 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * published by the Free Software Foundation.
8 *
Nathan Scott7b718762005-11-02 14:58:39 +11009 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 *
Nathan Scott7b718762005-11-02 14:58:39 +110014 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 */
18#ifndef __XFS_SB_H__
19#define __XFS_SB_H__
20
21/*
22 * Super block
23 * Fits into a sector-sized buffer at address 0 of each allocation group.
24 * Only the first of these is ever updated except during growfs.
25 */
26
27struct xfs_buf;
28struct xfs_mount;
29
30#define XFS_SB_MAGIC 0x58465342 /* 'XFSB' */
31#define XFS_SB_VERSION_1 1 /* 5.3, 6.0.1, 6.1 */
32#define XFS_SB_VERSION_2 2 /* 6.2 - attributes */
33#define XFS_SB_VERSION_3 3 /* 6.2 - new inode version */
34#define XFS_SB_VERSION_4 4 /* 6.2+ - bitmask version */
35#define XFS_SB_VERSION_NUMBITS 0x000f
36#define XFS_SB_VERSION_ALLFBITS 0xfff0
37#define XFS_SB_VERSION_SASHFBITS 0xf000
38#define XFS_SB_VERSION_REALFBITS 0x0ff0
39#define XFS_SB_VERSION_ATTRBIT 0x0010
40#define XFS_SB_VERSION_NLINKBIT 0x0020
41#define XFS_SB_VERSION_QUOTABIT 0x0040
42#define XFS_SB_VERSION_ALIGNBIT 0x0080
43#define XFS_SB_VERSION_DALIGNBIT 0x0100
44#define XFS_SB_VERSION_SHAREDBIT 0x0200
45#define XFS_SB_VERSION_LOGV2BIT 0x0400
46#define XFS_SB_VERSION_SECTORBIT 0x0800
47#define XFS_SB_VERSION_EXTFLGBIT 0x1000
48#define XFS_SB_VERSION_DIRV2BIT 0x2000
49#define XFS_SB_VERSION_MOREBITSBIT 0x8000
50#define XFS_SB_VERSION_OKSASHFBITS \
51 (XFS_SB_VERSION_EXTFLGBIT | \
52 XFS_SB_VERSION_DIRV2BIT)
53#define XFS_SB_VERSION_OKREALFBITS \
54 (XFS_SB_VERSION_ATTRBIT | \
55 XFS_SB_VERSION_NLINKBIT | \
56 XFS_SB_VERSION_QUOTABIT | \
57 XFS_SB_VERSION_ALIGNBIT | \
58 XFS_SB_VERSION_DALIGNBIT | \
59 XFS_SB_VERSION_SHAREDBIT | \
60 XFS_SB_VERSION_LOGV2BIT | \
Nathan Scottd8cc8902005-11-02 10:34:53 +110061 XFS_SB_VERSION_SECTORBIT | \
62 XFS_SB_VERSION_MOREBITSBIT)
Linus Torvalds1da177e2005-04-16 15:20:36 -070063#define XFS_SB_VERSION_OKREALBITS \
64 (XFS_SB_VERSION_NUMBITS | \
65 XFS_SB_VERSION_OKREALFBITS | \
66 XFS_SB_VERSION_OKSASHFBITS)
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
68/*
69 * There are two words to hold XFS "feature" bits: the original
70 * word, sb_versionnum, and sb_features2. Whenever a bit is set in
71 * sb_features2, the feature bit XFS_SB_VERSION_MOREBITSBIT must be set.
72 *
73 * These defines represent bits in sb_features2.
74 */
75#define XFS_SB_VERSION2_REALFBITS 0x00ffffff /* Mask: features */
76#define XFS_SB_VERSION2_RESERVED1BIT 0x00000001
David Chinner92821e22007-05-24 15:26:31 +100077#define XFS_SB_VERSION2_LAZYSBCOUNTBIT 0x00000002 /* Superblk counters */
Nathan Scottd8cc8902005-11-02 10:34:53 +110078#define XFS_SB_VERSION2_RESERVED4BIT 0x00000004
79#define XFS_SB_VERSION2_ATTR2BIT 0x00000008 /* Inline attr rework */
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
81#define XFS_SB_VERSION2_OKREALFBITS \
David Chinner92821e22007-05-24 15:26:31 +100082 (XFS_SB_VERSION2_LAZYSBCOUNTBIT | \
83 XFS_SB_VERSION2_ATTR2BIT)
Linus Torvalds1da177e2005-04-16 15:20:36 -070084#define XFS_SB_VERSION2_OKSASHFBITS \
85 (0)
86#define XFS_SB_VERSION2_OKREALBITS \
87 (XFS_SB_VERSION2_OKREALFBITS | \
88 XFS_SB_VERSION2_OKSASHFBITS )
89
Christoph Hellwig2bdf7cd2007-08-28 13:58:06 +100090/*
91 * Superblock - in core version. Must match the ondisk version below.
92 */
93typedef struct xfs_sb {
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 __uint32_t sb_magicnum; /* magic number == XFS_SB_MAGIC */
95 __uint32_t sb_blocksize; /* logical block size, bytes */
96 xfs_drfsbno_t sb_dblocks; /* number of data blocks */
97 xfs_drfsbno_t sb_rblocks; /* number of realtime blocks */
98 xfs_drtbno_t sb_rextents; /* number of realtime extents */
99 uuid_t sb_uuid; /* file system unique id */
100 xfs_dfsbno_t sb_logstart; /* starting block of log if internal */
101 xfs_ino_t sb_rootino; /* root inode number */
102 xfs_ino_t sb_rbmino; /* bitmap inode for realtime extents */
103 xfs_ino_t sb_rsumino; /* summary inode for rt bitmap */
104 xfs_agblock_t sb_rextsize; /* realtime extent size, blocks */
105 xfs_agblock_t sb_agblocks; /* size of an allocation group */
106 xfs_agnumber_t sb_agcount; /* number of allocation groups */
107 xfs_extlen_t sb_rbmblocks; /* number of rt bitmap blocks */
108 xfs_extlen_t sb_logblocks; /* number of log blocks */
109 __uint16_t sb_versionnum; /* header version == XFS_SB_VERSION */
110 __uint16_t sb_sectsize; /* volume sector size, bytes */
111 __uint16_t sb_inodesize; /* inode size, bytes */
112 __uint16_t sb_inopblock; /* inodes per block */
113 char sb_fname[12]; /* file system name */
114 __uint8_t sb_blocklog; /* log2 of sb_blocksize */
115 __uint8_t sb_sectlog; /* log2 of sb_sectsize */
116 __uint8_t sb_inodelog; /* log2 of sb_inodesize */
117 __uint8_t sb_inopblog; /* log2 of sb_inopblock */
118 __uint8_t sb_agblklog; /* log2 of sb_agblocks (rounded up) */
119 __uint8_t sb_rextslog; /* log2 of sb_rextents */
120 __uint8_t sb_inprogress; /* mkfs is in progress, don't mount */
121 __uint8_t sb_imax_pct; /* max % of fs for inode space */
122 /* statistics */
123 /*
124 * These fields must remain contiguous. If you really
125 * want to change their layout, make sure you fix the
126 * code in xfs_trans_apply_sb_deltas().
127 */
128 __uint64_t sb_icount; /* allocated inodes */
129 __uint64_t sb_ifree; /* free inodes */
130 __uint64_t sb_fdblocks; /* free data blocks */
131 __uint64_t sb_frextents; /* free realtime extents */
132 /*
133 * End contiguous fields.
134 */
135 xfs_ino_t sb_uquotino; /* user quota inode */
136 xfs_ino_t sb_gquotino; /* group quota inode */
137 __uint16_t sb_qflags; /* quota flags */
138 __uint8_t sb_flags; /* misc. flags */
139 __uint8_t sb_shared_vn; /* shared version number */
140 xfs_extlen_t sb_inoalignmt; /* inode chunk alignment, fsblocks */
141 __uint32_t sb_unit; /* stripe or raid unit */
142 __uint32_t sb_width; /* stripe or raid width */
143 __uint8_t sb_dirblklog; /* log2 of dir block size (fsbs) */
144 __uint8_t sb_logsectlog; /* log2 of the log sector size */
145 __uint16_t sb_logsectsize; /* sector size for the log, bytes */
146 __uint32_t sb_logsunit; /* stripe unit size for the log */
Nathan Scottd8cc8902005-11-02 10:34:53 +1100147 __uint32_t sb_features2; /* additional feature bits */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148} xfs_sb_t;
149
150/*
Christoph Hellwig2bdf7cd2007-08-28 13:58:06 +1000151 * Superblock - on disk version. Must match the in core version below.
152 */
153typedef struct xfs_dsb {
154 __be32 sb_magicnum; /* magic number == XFS_SB_MAGIC */
155 __be32 sb_blocksize; /* logical block size, bytes */
156 __be64 sb_dblocks; /* number of data blocks */
157 __be64 sb_rblocks; /* number of realtime blocks */
158 __be64 sb_rextents; /* number of realtime extents */
159 uuid_t sb_uuid; /* file system unique id */
160 __be64 sb_logstart; /* starting block of log if internal */
161 __be64 sb_rootino; /* root inode number */
162 __be64 sb_rbmino; /* bitmap inode for realtime extents */
163 __be64 sb_rsumino; /* summary inode for rt bitmap */
164 __be32 sb_rextsize; /* realtime extent size, blocks */
165 __be32 sb_agblocks; /* size of an allocation group */
166 __be32 sb_agcount; /* number of allocation groups */
167 __be32 sb_rbmblocks; /* number of rt bitmap blocks */
168 __be32 sb_logblocks; /* number of log blocks */
169 __be16 sb_versionnum; /* header version == XFS_SB_VERSION */
170 __be16 sb_sectsize; /* volume sector size, bytes */
171 __be16 sb_inodesize; /* inode size, bytes */
172 __be16 sb_inopblock; /* inodes per block */
173 char sb_fname[12]; /* file system name */
174 __u8 sb_blocklog; /* log2 of sb_blocksize */
175 __u8 sb_sectlog; /* log2 of sb_sectsize */
176 __u8 sb_inodelog; /* log2 of sb_inodesize */
177 __u8 sb_inopblog; /* log2 of sb_inopblock */
178 __u8 sb_agblklog; /* log2 of sb_agblocks (rounded up) */
179 __u8 sb_rextslog; /* log2 of sb_rextents */
180 __u8 sb_inprogress; /* mkfs is in progress, don't mount */
181 __u8 sb_imax_pct; /* max % of fs for inode space */
182 /* statistics */
183 /*
184 * These fields must remain contiguous. If you really
185 * want to change their layout, make sure you fix the
186 * code in xfs_trans_apply_sb_deltas().
187 */
188 __be64 sb_icount; /* allocated inodes */
189 __be64 sb_ifree; /* free inodes */
190 __be64 sb_fdblocks; /* free data blocks */
191 __be64 sb_frextents; /* free realtime extents */
192 /*
193 * End contiguous fields.
194 */
195 __be64 sb_uquotino; /* user quota inode */
196 __be64 sb_gquotino; /* group quota inode */
197 __be16 sb_qflags; /* quota flags */
198 __u8 sb_flags; /* misc. flags */
199 __u8 sb_shared_vn; /* shared version number */
200 __be32 sb_inoalignmt; /* inode chunk alignment, fsblocks */
201 __be32 sb_unit; /* stripe or raid unit */
202 __be32 sb_width; /* stripe or raid width */
203 __u8 sb_dirblklog; /* log2 of dir block size (fsbs) */
204 __u8 sb_logsectlog; /* log2 of the log sector size */
205 __be16 sb_logsectsize; /* sector size for the log, bytes */
206 __be32 sb_logsunit; /* stripe unit size for the log */
207 __be32 sb_features2; /* additional feature bits */
208} xfs_dsb_t;
209
210/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 * Sequence number values for the fields.
212 */
213typedef enum {
214 XFS_SBS_MAGICNUM, XFS_SBS_BLOCKSIZE, XFS_SBS_DBLOCKS, XFS_SBS_RBLOCKS,
215 XFS_SBS_REXTENTS, XFS_SBS_UUID, XFS_SBS_LOGSTART, XFS_SBS_ROOTINO,
216 XFS_SBS_RBMINO, XFS_SBS_RSUMINO, XFS_SBS_REXTSIZE, XFS_SBS_AGBLOCKS,
217 XFS_SBS_AGCOUNT, XFS_SBS_RBMBLOCKS, XFS_SBS_LOGBLOCKS,
218 XFS_SBS_VERSIONNUM, XFS_SBS_SECTSIZE, XFS_SBS_INODESIZE,
219 XFS_SBS_INOPBLOCK, XFS_SBS_FNAME, XFS_SBS_BLOCKLOG,
220 XFS_SBS_SECTLOG, XFS_SBS_INODELOG, XFS_SBS_INOPBLOG, XFS_SBS_AGBLKLOG,
221 XFS_SBS_REXTSLOG, XFS_SBS_INPROGRESS, XFS_SBS_IMAX_PCT, XFS_SBS_ICOUNT,
222 XFS_SBS_IFREE, XFS_SBS_FDBLOCKS, XFS_SBS_FREXTENTS, XFS_SBS_UQUOTINO,
223 XFS_SBS_GQUOTINO, XFS_SBS_QFLAGS, XFS_SBS_FLAGS, XFS_SBS_SHARED_VN,
224 XFS_SBS_INOALIGNMT, XFS_SBS_UNIT, XFS_SBS_WIDTH, XFS_SBS_DIRBLKLOG,
225 XFS_SBS_LOGSECTLOG, XFS_SBS_LOGSECTSIZE, XFS_SBS_LOGSUNIT,
226 XFS_SBS_FEATURES2,
227 XFS_SBS_FIELDCOUNT
228} xfs_sb_field_t;
229
230/*
231 * Mask values, defined based on the xfs_sb_field_t values.
232 * Only define the ones we're using.
233 */
234#define XFS_SB_MVAL(x) (1LL << XFS_SBS_ ## x)
235#define XFS_SB_UUID XFS_SB_MVAL(UUID)
236#define XFS_SB_FNAME XFS_SB_MVAL(FNAME)
237#define XFS_SB_ROOTINO XFS_SB_MVAL(ROOTINO)
238#define XFS_SB_RBMINO XFS_SB_MVAL(RBMINO)
239#define XFS_SB_RSUMINO XFS_SB_MVAL(RSUMINO)
240#define XFS_SB_VERSIONNUM XFS_SB_MVAL(VERSIONNUM)
241#define XFS_SB_UQUOTINO XFS_SB_MVAL(UQUOTINO)
242#define XFS_SB_GQUOTINO XFS_SB_MVAL(GQUOTINO)
243#define XFS_SB_QFLAGS XFS_SB_MVAL(QFLAGS)
244#define XFS_SB_SHARED_VN XFS_SB_MVAL(SHARED_VN)
245#define XFS_SB_UNIT XFS_SB_MVAL(UNIT)
246#define XFS_SB_WIDTH XFS_SB_MVAL(WIDTH)
David Chinner92821e22007-05-24 15:26:31 +1000247#define XFS_SB_ICOUNT XFS_SB_MVAL(ICOUNT)
248#define XFS_SB_IFREE XFS_SB_MVAL(IFREE)
249#define XFS_SB_FDBLOCKS XFS_SB_MVAL(FDBLOCKS)
Nathan Scottd8cc8902005-11-02 10:34:53 +1100250#define XFS_SB_FEATURES2 XFS_SB_MVAL(FEATURES2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251#define XFS_SB_NUM_BITS ((int)XFS_SBS_FIELDCOUNT)
252#define XFS_SB_ALL_BITS ((1LL << XFS_SB_NUM_BITS) - 1)
253#define XFS_SB_MOD_BITS \
254 (XFS_SB_UUID | XFS_SB_ROOTINO | XFS_SB_RBMINO | XFS_SB_RSUMINO | \
255 XFS_SB_VERSIONNUM | XFS_SB_UQUOTINO | XFS_SB_GQUOTINO | \
Nathan Scottd8cc8902005-11-02 10:34:53 +1100256 XFS_SB_QFLAGS | XFS_SB_SHARED_VN | XFS_SB_UNIT | XFS_SB_WIDTH | \
David Chinner92821e22007-05-24 15:26:31 +1000257 XFS_SB_ICOUNT | XFS_SB_IFREE | XFS_SB_FDBLOCKS | XFS_SB_FEATURES2)
Nathan Scottd8cc8902005-11-02 10:34:53 +1100258
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259
260/*
261 * Misc. Flags - warning - these will be cleared by xfs_repair unless
262 * a feature bit is set when the flag is used.
263 */
264#define XFS_SBF_NOFLAGS 0x00 /* no flags set */
265#define XFS_SBF_READONLY 0x01 /* only read-only mounts allowed */
266
267/*
268 * define max. shared version we can interoperate with
269 */
270#define XFS_SB_MAX_SHARED_VN 0
271
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272#define XFS_SB_VERSION_NUM(sbp) ((sbp)->sb_versionnum & XFS_SB_VERSION_NUMBITS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274#define XFS_SB_GOOD_VERSION(sbp) xfs_sb_good_version(sbp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275#ifdef __KERNEL__
Nathan Scotta844f452005-11-02 14:38:42 +1100276static inline int xfs_sb_good_version(xfs_sb_t *sbp)
277{
278 return (((sbp->sb_versionnum >= XFS_SB_VERSION_1) && \
279 (sbp->sb_versionnum <= XFS_SB_VERSION_3)) || \
280 ((XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) && \
281 !((sbp->sb_versionnum & ~XFS_SB_VERSION_OKREALBITS) || \
282 ((sbp->sb_versionnum & XFS_SB_VERSION_MOREBITSBIT) && \
283 (sbp->sb_features2 & ~XFS_SB_VERSION2_OKREALBITS))) && \
284 (sbp->sb_shared_vn <= XFS_SB_MAX_SHARED_VN)));
285}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286#else
Nathan Scotta844f452005-11-02 14:38:42 +1100287static inline int xfs_sb_good_version(xfs_sb_t *sbp)
288{
289 return (((sbp->sb_versionnum >= XFS_SB_VERSION_1) && \
290 (sbp->sb_versionnum <= XFS_SB_VERSION_3)) || \
291 ((XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) && \
292 !((sbp->sb_versionnum & ~XFS_SB_VERSION_OKREALBITS) || \
293 ((sbp->sb_versionnum & XFS_SB_VERSION_MOREBITSBIT) && \
294 (sbp->sb_features2 & ~XFS_SB_VERSION2_OKREALBITS))) && \
295 (!(sbp->sb_versionnum & XFS_SB_VERSION_SHAREDBIT) || \
296 (sbp->sb_shared_vn <= XFS_SB_MAX_SHARED_VN))));
297}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298#endif /* __KERNEL__ */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300#define XFS_SB_VERSION_TONEW(v) xfs_sb_version_tonew(v)
Nathan Scotta844f452005-11-02 14:38:42 +1100301static inline unsigned xfs_sb_version_tonew(unsigned v)
302{
303 return ((((v) == XFS_SB_VERSION_1) ? \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 0 : \
305 (((v) == XFS_SB_VERSION_2) ? \
306 XFS_SB_VERSION_ATTRBIT : \
307 (XFS_SB_VERSION_ATTRBIT | XFS_SB_VERSION_NLINKBIT))) | \
Nathan Scotta844f452005-11-02 14:38:42 +1100308 XFS_SB_VERSION_4);
309}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311#define XFS_SB_VERSION_TOOLD(v) xfs_sb_version_toold(v)
Nathan Scotta844f452005-11-02 14:38:42 +1100312static inline unsigned xfs_sb_version_toold(unsigned v)
313{
314 return (((v) & (XFS_SB_VERSION_QUOTABIT | XFS_SB_VERSION_ALIGNBIT)) ? \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 0 : \
316 (((v) & XFS_SB_VERSION_NLINKBIT) ? \
317 XFS_SB_VERSION_3 : \
318 (((v) & XFS_SB_VERSION_ATTRBIT) ? \
319 XFS_SB_VERSION_2 : \
Nathan Scotta844f452005-11-02 14:38:42 +1100320 XFS_SB_VERSION_1)));
321}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323#define XFS_SB_VERSION_HASATTR(sbp) xfs_sb_version_hasattr(sbp)
Nathan Scotta844f452005-11-02 14:38:42 +1100324static inline int xfs_sb_version_hasattr(xfs_sb_t *sbp)
325{
326 return ((sbp)->sb_versionnum == XFS_SB_VERSION_2) || \
327 ((sbp)->sb_versionnum == XFS_SB_VERSION_3) || \
328 ((XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) && \
329 ((sbp)->sb_versionnum & XFS_SB_VERSION_ATTRBIT));
330}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332#define XFS_SB_VERSION_ADDATTR(sbp) xfs_sb_version_addattr(sbp)
Nathan Scotta844f452005-11-02 14:38:42 +1100333static inline void xfs_sb_version_addattr(xfs_sb_t *sbp)
334{
335 (sbp)->sb_versionnum = (((sbp)->sb_versionnum == XFS_SB_VERSION_1) ? \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 XFS_SB_VERSION_2 : \
337 ((XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) ? \
338 ((sbp)->sb_versionnum | XFS_SB_VERSION_ATTRBIT) : \
Nathan Scotta844f452005-11-02 14:38:42 +1100339 (XFS_SB_VERSION_4 | XFS_SB_VERSION_ATTRBIT)));
340}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342#define XFS_SB_VERSION_HASNLINK(sbp) xfs_sb_version_hasnlink(sbp)
Nathan Scotta844f452005-11-02 14:38:42 +1100343static inline int xfs_sb_version_hasnlink(xfs_sb_t *sbp)
344{
345 return ((sbp)->sb_versionnum == XFS_SB_VERSION_3) || \
346 ((XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) && \
347 ((sbp)->sb_versionnum & XFS_SB_VERSION_NLINKBIT));
348}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350#define XFS_SB_VERSION_ADDNLINK(sbp) xfs_sb_version_addnlink(sbp)
Nathan Scotta844f452005-11-02 14:38:42 +1100351static inline void xfs_sb_version_addnlink(xfs_sb_t *sbp)
352{
353 (sbp)->sb_versionnum = ((sbp)->sb_versionnum <= XFS_SB_VERSION_2 ? \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 XFS_SB_VERSION_3 : \
Nathan Scotta844f452005-11-02 14:38:42 +1100355 ((sbp)->sb_versionnum | XFS_SB_VERSION_NLINKBIT));
356}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358#define XFS_SB_VERSION_HASQUOTA(sbp) xfs_sb_version_hasquota(sbp)
Nathan Scotta844f452005-11-02 14:38:42 +1100359static inline int xfs_sb_version_hasquota(xfs_sb_t *sbp)
360{
361 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) && \
362 ((sbp)->sb_versionnum & XFS_SB_VERSION_QUOTABIT);
363}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365#define XFS_SB_VERSION_ADDQUOTA(sbp) xfs_sb_version_addquota(sbp)
Nathan Scotta844f452005-11-02 14:38:42 +1100366static inline void xfs_sb_version_addquota(xfs_sb_t *sbp)
367{
368 (sbp)->sb_versionnum = \
369 (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 ? \
370 ((sbp)->sb_versionnum | XFS_SB_VERSION_QUOTABIT) : \
371 (XFS_SB_VERSION_TONEW((sbp)->sb_versionnum) | \
372 XFS_SB_VERSION_QUOTABIT));
373}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375#define XFS_SB_VERSION_HASALIGN(sbp) xfs_sb_version_hasalign(sbp)
Nathan Scotta844f452005-11-02 14:38:42 +1100376static inline int xfs_sb_version_hasalign(xfs_sb_t *sbp)
377{
378 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) && \
379 ((sbp)->sb_versionnum & XFS_SB_VERSION_ALIGNBIT);
380}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382#define XFS_SB_VERSION_SUBALIGN(sbp) xfs_sb_version_subalign(sbp)
Nathan Scotta844f452005-11-02 14:38:42 +1100383static inline void xfs_sb_version_subalign(xfs_sb_t *sbp)
384{
385 (sbp)->sb_versionnum = \
386 XFS_SB_VERSION_TOOLD((sbp)->sb_versionnum & ~XFS_SB_VERSION_ALIGNBIT);
387}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389#define XFS_SB_VERSION_HASDALIGN(sbp) xfs_sb_version_hasdalign(sbp)
Nathan Scotta844f452005-11-02 14:38:42 +1100390static inline int xfs_sb_version_hasdalign(xfs_sb_t *sbp)
391{
392 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) && \
393 ((sbp)->sb_versionnum & XFS_SB_VERSION_DALIGNBIT);
394}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396#define XFS_SB_VERSION_ADDDALIGN(sbp) xfs_sb_version_adddalign(sbp)
Nathan Scotta844f452005-11-02 14:38:42 +1100397static inline int xfs_sb_version_adddalign(xfs_sb_t *sbp)
398{
399 return (sbp)->sb_versionnum = \
400 ((sbp)->sb_versionnum | XFS_SB_VERSION_DALIGNBIT);
401}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403#define XFS_SB_VERSION_HASSHARED(sbp) xfs_sb_version_hasshared(sbp)
Nathan Scotta844f452005-11-02 14:38:42 +1100404static inline int xfs_sb_version_hasshared(xfs_sb_t *sbp)
405{
406 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) && \
407 ((sbp)->sb_versionnum & XFS_SB_VERSION_SHAREDBIT);
408}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410#define XFS_SB_VERSION_ADDSHARED(sbp) xfs_sb_version_addshared(sbp)
Nathan Scotta844f452005-11-02 14:38:42 +1100411static inline int xfs_sb_version_addshared(xfs_sb_t *sbp)
412{
413 return (sbp)->sb_versionnum = \
414 ((sbp)->sb_versionnum | XFS_SB_VERSION_SHAREDBIT);
415}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417#define XFS_SB_VERSION_SUBSHARED(sbp) xfs_sb_version_subshared(sbp)
Nathan Scotta844f452005-11-02 14:38:42 +1100418static inline int xfs_sb_version_subshared(xfs_sb_t *sbp)
419{
420 return (sbp)->sb_versionnum = \
421 ((sbp)->sb_versionnum & ~XFS_SB_VERSION_SHAREDBIT);
422}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424#define XFS_SB_VERSION_HASDIRV2(sbp) xfs_sb_version_hasdirv2(sbp)
Nathan Scotta844f452005-11-02 14:38:42 +1100425static inline int xfs_sb_version_hasdirv2(xfs_sb_t *sbp)
426{
427 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) && \
428 ((sbp)->sb_versionnum & XFS_SB_VERSION_DIRV2BIT);
429}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431#define XFS_SB_VERSION_HASLOGV2(sbp) xfs_sb_version_haslogv2(sbp)
Nathan Scotta844f452005-11-02 14:38:42 +1100432static inline int xfs_sb_version_haslogv2(xfs_sb_t *sbp)
433{
434 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) && \
435 ((sbp)->sb_versionnum & XFS_SB_VERSION_LOGV2BIT);
436}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438#define XFS_SB_VERSION_HASEXTFLGBIT(sbp) xfs_sb_version_hasextflgbit(sbp)
Nathan Scotta844f452005-11-02 14:38:42 +1100439static inline int xfs_sb_version_hasextflgbit(xfs_sb_t *sbp)
440{
441 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) && \
442 ((sbp)->sb_versionnum & XFS_SB_VERSION_EXTFLGBIT);
443}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445#define XFS_SB_VERSION_ADDEXTFLGBIT(sbp) xfs_sb_version_addextflgbit(sbp)
Nathan Scotta844f452005-11-02 14:38:42 +1100446static inline int xfs_sb_version_addextflgbit(xfs_sb_t *sbp)
447{
448 return (sbp)->sb_versionnum = \
449 ((sbp)->sb_versionnum | XFS_SB_VERSION_EXTFLGBIT);
450}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452#define XFS_SB_VERSION_SUBEXTFLGBIT(sbp) xfs_sb_version_subextflgbit(sbp)
Nathan Scotta844f452005-11-02 14:38:42 +1100453static inline int xfs_sb_version_subextflgbit(xfs_sb_t *sbp)
454{
455 return (sbp)->sb_versionnum = \
456 ((sbp)->sb_versionnum & ~XFS_SB_VERSION_EXTFLGBIT);
457}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459#define XFS_SB_VERSION_HASSECTOR(sbp) xfs_sb_version_hassector(sbp)
Nathan Scotta844f452005-11-02 14:38:42 +1100460static inline int xfs_sb_version_hassector(xfs_sb_t *sbp)
461{
462 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) && \
463 ((sbp)->sb_versionnum & XFS_SB_VERSION_SECTORBIT);
464}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466#define XFS_SB_VERSION_HASMOREBITS(sbp) xfs_sb_version_hasmorebits(sbp)
Nathan Scotta844f452005-11-02 14:38:42 +1100467static inline int xfs_sb_version_hasmorebits(xfs_sb_t *sbp)
468{
469 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) && \
470 ((sbp)->sb_versionnum & XFS_SB_VERSION_MOREBITSBIT);
471}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472
473/*
474 * sb_features2 bit version macros.
475 *
Nathan Scottd8cc8902005-11-02 10:34:53 +1100476 * For example, for a bit defined as XFS_SB_VERSION2_FUNBIT, has a macro:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 *
Nathan Scottd8cc8902005-11-02 10:34:53 +1100478 * SB_VERSION_HASFUNBIT(xfs_sb_t *sbp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 * ((XFS_SB_VERSION_HASMOREBITS(sbp) &&
Nathan Scottd8cc8902005-11-02 10:34:53 +1100480 * ((sbp)->sb_features2 & XFS_SB_VERSION2_FUNBIT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 */
482
David Chinner92821e22007-05-24 15:26:31 +1000483static inline int xfs_sb_version_haslazysbcount(xfs_sb_t *sbp)
484{
485 return (XFS_SB_VERSION_HASMOREBITS(sbp) && \
486 ((sbp)->sb_features2 & XFS_SB_VERSION2_LAZYSBCOUNTBIT));
487}
488
Nathan Scotta844f452005-11-02 14:38:42 +1100489#define XFS_SB_VERSION_HASATTR2(sbp) xfs_sb_version_hasattr2(sbp)
490static inline int xfs_sb_version_hasattr2(xfs_sb_t *sbp)
491{
492 return (XFS_SB_VERSION_HASMOREBITS(sbp)) && \
493 ((sbp)->sb_features2 & XFS_SB_VERSION2_ATTR2BIT);
494}
495
Nathan Scottd8cc8902005-11-02 10:34:53 +1100496#define XFS_SB_VERSION_ADDATTR2(sbp) xfs_sb_version_addattr2(sbp)
Nathan Scotta844f452005-11-02 14:38:42 +1100497static inline void xfs_sb_version_addattr2(xfs_sb_t *sbp)
498{
Nathan Scottd8cc8902005-11-02 10:34:53 +1100499 ((sbp)->sb_versionnum = \
500 ((sbp)->sb_versionnum | XFS_SB_VERSION_MOREBITSBIT), \
501 ((sbp)->sb_features2 = \
Nathan Scotta844f452005-11-02 14:38:42 +1100502 ((sbp)->sb_features2 | XFS_SB_VERSION2_ATTR2BIT)));
503}
504
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505/*
506 * end of superblock version macros
507 */
508
Nathan Scotta844f452005-11-02 14:38:42 +1100509#define XFS_SB_DADDR ((xfs_daddr_t)0) /* daddr in filesystem/ag */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510#define XFS_SB_BLOCK(mp) XFS_HDR_BLOCK(mp, XFS_SB_DADDR)
Christoph Hellwig2bdf7cd2007-08-28 13:58:06 +1000511#define XFS_BUF_TO_SBP(bp) ((xfs_dsb_t *)XFS_BUF_PTR(bp))
Nathan Scotta844f452005-11-02 14:38:42 +1100512
513#define XFS_HDR_BLOCK(mp,d) ((xfs_agblock_t)XFS_BB_TO_FSBT(mp,d))
514#define XFS_DADDR_TO_FSB(mp,d) XFS_AGB_TO_FSB(mp, \
515 XFS_DADDR_TO_AGNO(mp,d), XFS_DADDR_TO_AGBNO(mp,d))
516#define XFS_FSB_TO_DADDR(mp,fsbno) XFS_AGB_TO_DADDR(mp, \
517 XFS_FSB_TO_AGNO(mp,fsbno), XFS_FSB_TO_AGBNO(mp,fsbno))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518
519/*
520 * File system sector to basic block conversions.
521 */
522#define XFS_FSS_TO_BB(mp,sec) ((sec) << (mp)->m_sectbb_log)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523
524/*
525 * File system block to basic block conversions.
526 */
527#define XFS_FSB_TO_BB(mp,fsbno) ((fsbno) << (mp)->m_blkbb_log)
528#define XFS_BB_TO_FSB(mp,bb) \
529 (((bb) + (XFS_FSB_TO_BB(mp,1) - 1)) >> (mp)->m_blkbb_log)
530#define XFS_BB_TO_FSBT(mp,bb) ((bb) >> (mp)->m_blkbb_log)
531#define XFS_BB_FSB_OFFSET(mp,bb) ((bb) & ((mp)->m_bsize - 1))
532
533/*
534 * File system block to byte conversions.
535 */
536#define XFS_FSB_TO_B(mp,fsbno) ((xfs_fsize_t)(fsbno) << (mp)->m_sb.sb_blocklog)
537#define XFS_B_TO_FSB(mp,b) \
538 ((((__uint64_t)(b)) + (mp)->m_blockmask) >> (mp)->m_sb.sb_blocklog)
539#define XFS_B_TO_FSBT(mp,b) (((__uint64_t)(b)) >> (mp)->m_sb.sb_blocklog)
540#define XFS_B_FSB_OFFSET(mp,b) ((b) & (mp)->m_blockmask)
541
542#endif /* __XFS_SB_H__ */