blob: ef42537a607a683196c6abde7450a87cda13735b [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
Linus Torvalds1da177e2005-04-16 15:20:36 -070090typedef struct xfs_sb
91{
92 __uint32_t sb_magicnum; /* magic number == XFS_SB_MAGIC */
93 __uint32_t sb_blocksize; /* logical block size, bytes */
94 xfs_drfsbno_t sb_dblocks; /* number of data blocks */
95 xfs_drfsbno_t sb_rblocks; /* number of realtime blocks */
96 xfs_drtbno_t sb_rextents; /* number of realtime extents */
97 uuid_t sb_uuid; /* file system unique id */
98 xfs_dfsbno_t sb_logstart; /* starting block of log if internal */
99 xfs_ino_t sb_rootino; /* root inode number */
100 xfs_ino_t sb_rbmino; /* bitmap inode for realtime extents */
101 xfs_ino_t sb_rsumino; /* summary inode for rt bitmap */
102 xfs_agblock_t sb_rextsize; /* realtime extent size, blocks */
103 xfs_agblock_t sb_agblocks; /* size of an allocation group */
104 xfs_agnumber_t sb_agcount; /* number of allocation groups */
105 xfs_extlen_t sb_rbmblocks; /* number of rt bitmap blocks */
106 xfs_extlen_t sb_logblocks; /* number of log blocks */
107 __uint16_t sb_versionnum; /* header version == XFS_SB_VERSION */
108 __uint16_t sb_sectsize; /* volume sector size, bytes */
109 __uint16_t sb_inodesize; /* inode size, bytes */
110 __uint16_t sb_inopblock; /* inodes per block */
111 char sb_fname[12]; /* file system name */
112 __uint8_t sb_blocklog; /* log2 of sb_blocksize */
113 __uint8_t sb_sectlog; /* log2 of sb_sectsize */
114 __uint8_t sb_inodelog; /* log2 of sb_inodesize */
115 __uint8_t sb_inopblog; /* log2 of sb_inopblock */
116 __uint8_t sb_agblklog; /* log2 of sb_agblocks (rounded up) */
117 __uint8_t sb_rextslog; /* log2 of sb_rextents */
118 __uint8_t sb_inprogress; /* mkfs is in progress, don't mount */
119 __uint8_t sb_imax_pct; /* max % of fs for inode space */
120 /* statistics */
121 /*
122 * These fields must remain contiguous. If you really
123 * want to change their layout, make sure you fix the
124 * code in xfs_trans_apply_sb_deltas().
125 */
126 __uint64_t sb_icount; /* allocated inodes */
127 __uint64_t sb_ifree; /* free inodes */
128 __uint64_t sb_fdblocks; /* free data blocks */
129 __uint64_t sb_frextents; /* free realtime extents */
130 /*
131 * End contiguous fields.
132 */
133 xfs_ino_t sb_uquotino; /* user quota inode */
134 xfs_ino_t sb_gquotino; /* group quota inode */
135 __uint16_t sb_qflags; /* quota flags */
136 __uint8_t sb_flags; /* misc. flags */
137 __uint8_t sb_shared_vn; /* shared version number */
138 xfs_extlen_t sb_inoalignmt; /* inode chunk alignment, fsblocks */
139 __uint32_t sb_unit; /* stripe or raid unit */
140 __uint32_t sb_width; /* stripe or raid width */
141 __uint8_t sb_dirblklog; /* log2 of dir block size (fsbs) */
142 __uint8_t sb_logsectlog; /* log2 of the log sector size */
143 __uint16_t sb_logsectsize; /* sector size for the log, bytes */
144 __uint32_t sb_logsunit; /* stripe unit size for the log */
Nathan Scottd8cc8902005-11-02 10:34:53 +1100145 __uint32_t sb_features2; /* additional feature bits */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146} xfs_sb_t;
147
148/*
149 * Sequence number values for the fields.
150 */
151typedef enum {
152 XFS_SBS_MAGICNUM, XFS_SBS_BLOCKSIZE, XFS_SBS_DBLOCKS, XFS_SBS_RBLOCKS,
153 XFS_SBS_REXTENTS, XFS_SBS_UUID, XFS_SBS_LOGSTART, XFS_SBS_ROOTINO,
154 XFS_SBS_RBMINO, XFS_SBS_RSUMINO, XFS_SBS_REXTSIZE, XFS_SBS_AGBLOCKS,
155 XFS_SBS_AGCOUNT, XFS_SBS_RBMBLOCKS, XFS_SBS_LOGBLOCKS,
156 XFS_SBS_VERSIONNUM, XFS_SBS_SECTSIZE, XFS_SBS_INODESIZE,
157 XFS_SBS_INOPBLOCK, XFS_SBS_FNAME, XFS_SBS_BLOCKLOG,
158 XFS_SBS_SECTLOG, XFS_SBS_INODELOG, XFS_SBS_INOPBLOG, XFS_SBS_AGBLKLOG,
159 XFS_SBS_REXTSLOG, XFS_SBS_INPROGRESS, XFS_SBS_IMAX_PCT, XFS_SBS_ICOUNT,
160 XFS_SBS_IFREE, XFS_SBS_FDBLOCKS, XFS_SBS_FREXTENTS, XFS_SBS_UQUOTINO,
161 XFS_SBS_GQUOTINO, XFS_SBS_QFLAGS, XFS_SBS_FLAGS, XFS_SBS_SHARED_VN,
162 XFS_SBS_INOALIGNMT, XFS_SBS_UNIT, XFS_SBS_WIDTH, XFS_SBS_DIRBLKLOG,
163 XFS_SBS_LOGSECTLOG, XFS_SBS_LOGSECTSIZE, XFS_SBS_LOGSUNIT,
164 XFS_SBS_FEATURES2,
165 XFS_SBS_FIELDCOUNT
166} xfs_sb_field_t;
167
168/*
169 * Mask values, defined based on the xfs_sb_field_t values.
170 * Only define the ones we're using.
171 */
172#define XFS_SB_MVAL(x) (1LL << XFS_SBS_ ## x)
173#define XFS_SB_UUID XFS_SB_MVAL(UUID)
174#define XFS_SB_FNAME XFS_SB_MVAL(FNAME)
175#define XFS_SB_ROOTINO XFS_SB_MVAL(ROOTINO)
176#define XFS_SB_RBMINO XFS_SB_MVAL(RBMINO)
177#define XFS_SB_RSUMINO XFS_SB_MVAL(RSUMINO)
178#define XFS_SB_VERSIONNUM XFS_SB_MVAL(VERSIONNUM)
179#define XFS_SB_UQUOTINO XFS_SB_MVAL(UQUOTINO)
180#define XFS_SB_GQUOTINO XFS_SB_MVAL(GQUOTINO)
181#define XFS_SB_QFLAGS XFS_SB_MVAL(QFLAGS)
182#define XFS_SB_SHARED_VN XFS_SB_MVAL(SHARED_VN)
183#define XFS_SB_UNIT XFS_SB_MVAL(UNIT)
184#define XFS_SB_WIDTH XFS_SB_MVAL(WIDTH)
David Chinner92821e22007-05-24 15:26:31 +1000185#define XFS_SB_ICOUNT XFS_SB_MVAL(ICOUNT)
186#define XFS_SB_IFREE XFS_SB_MVAL(IFREE)
187#define XFS_SB_FDBLOCKS XFS_SB_MVAL(FDBLOCKS)
Nathan Scottd8cc8902005-11-02 10:34:53 +1100188#define XFS_SB_FEATURES2 XFS_SB_MVAL(FEATURES2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189#define XFS_SB_NUM_BITS ((int)XFS_SBS_FIELDCOUNT)
190#define XFS_SB_ALL_BITS ((1LL << XFS_SB_NUM_BITS) - 1)
191#define XFS_SB_MOD_BITS \
192 (XFS_SB_UUID | XFS_SB_ROOTINO | XFS_SB_RBMINO | XFS_SB_RSUMINO | \
193 XFS_SB_VERSIONNUM | XFS_SB_UQUOTINO | XFS_SB_GQUOTINO | \
Nathan Scottd8cc8902005-11-02 10:34:53 +1100194 XFS_SB_QFLAGS | XFS_SB_SHARED_VN | XFS_SB_UNIT | XFS_SB_WIDTH | \
David Chinner92821e22007-05-24 15:26:31 +1000195 XFS_SB_ICOUNT | XFS_SB_IFREE | XFS_SB_FDBLOCKS | XFS_SB_FEATURES2)
Nathan Scottd8cc8902005-11-02 10:34:53 +1100196
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197
198/*
199 * Misc. Flags - warning - these will be cleared by xfs_repair unless
200 * a feature bit is set when the flag is used.
201 */
202#define XFS_SBF_NOFLAGS 0x00 /* no flags set */
203#define XFS_SBF_READONLY 0x01 /* only read-only mounts allowed */
204
205/*
206 * define max. shared version we can interoperate with
207 */
208#define XFS_SB_MAX_SHARED_VN 0
209
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210#define XFS_SB_VERSION_NUM(sbp) ((sbp)->sb_versionnum & XFS_SB_VERSION_NUMBITS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212#define XFS_SB_GOOD_VERSION(sbp) xfs_sb_good_version(sbp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213#ifdef __KERNEL__
Nathan Scotta844f452005-11-02 14:38:42 +1100214static inline int xfs_sb_good_version(xfs_sb_t *sbp)
215{
216 return (((sbp->sb_versionnum >= XFS_SB_VERSION_1) && \
217 (sbp->sb_versionnum <= XFS_SB_VERSION_3)) || \
218 ((XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) && \
219 !((sbp->sb_versionnum & ~XFS_SB_VERSION_OKREALBITS) || \
220 ((sbp->sb_versionnum & XFS_SB_VERSION_MOREBITSBIT) && \
221 (sbp->sb_features2 & ~XFS_SB_VERSION2_OKREALBITS))) && \
222 (sbp->sb_shared_vn <= XFS_SB_MAX_SHARED_VN)));
223}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224#else
Nathan Scotta844f452005-11-02 14:38:42 +1100225static inline int xfs_sb_good_version(xfs_sb_t *sbp)
226{
227 return (((sbp->sb_versionnum >= XFS_SB_VERSION_1) && \
228 (sbp->sb_versionnum <= XFS_SB_VERSION_3)) || \
229 ((XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) && \
230 !((sbp->sb_versionnum & ~XFS_SB_VERSION_OKREALBITS) || \
231 ((sbp->sb_versionnum & XFS_SB_VERSION_MOREBITSBIT) && \
232 (sbp->sb_features2 & ~XFS_SB_VERSION2_OKREALBITS))) && \
233 (!(sbp->sb_versionnum & XFS_SB_VERSION_SHAREDBIT) || \
234 (sbp->sb_shared_vn <= XFS_SB_MAX_SHARED_VN))));
235}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236#endif /* __KERNEL__ */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238#define XFS_SB_VERSION_TONEW(v) xfs_sb_version_tonew(v)
Nathan Scotta844f452005-11-02 14:38:42 +1100239static inline unsigned xfs_sb_version_tonew(unsigned v)
240{
241 return ((((v) == XFS_SB_VERSION_1) ? \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 0 : \
243 (((v) == XFS_SB_VERSION_2) ? \
244 XFS_SB_VERSION_ATTRBIT : \
245 (XFS_SB_VERSION_ATTRBIT | XFS_SB_VERSION_NLINKBIT))) | \
Nathan Scotta844f452005-11-02 14:38:42 +1100246 XFS_SB_VERSION_4);
247}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249#define XFS_SB_VERSION_TOOLD(v) xfs_sb_version_toold(v)
Nathan Scotta844f452005-11-02 14:38:42 +1100250static inline unsigned xfs_sb_version_toold(unsigned v)
251{
252 return (((v) & (XFS_SB_VERSION_QUOTABIT | XFS_SB_VERSION_ALIGNBIT)) ? \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 0 : \
254 (((v) & XFS_SB_VERSION_NLINKBIT) ? \
255 XFS_SB_VERSION_3 : \
256 (((v) & XFS_SB_VERSION_ATTRBIT) ? \
257 XFS_SB_VERSION_2 : \
Nathan Scotta844f452005-11-02 14:38:42 +1100258 XFS_SB_VERSION_1)));
259}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261#define XFS_SB_VERSION_HASATTR(sbp) xfs_sb_version_hasattr(sbp)
Nathan Scotta844f452005-11-02 14:38:42 +1100262static inline int xfs_sb_version_hasattr(xfs_sb_t *sbp)
263{
264 return ((sbp)->sb_versionnum == XFS_SB_VERSION_2) || \
265 ((sbp)->sb_versionnum == XFS_SB_VERSION_3) || \
266 ((XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) && \
267 ((sbp)->sb_versionnum & XFS_SB_VERSION_ATTRBIT));
268}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270#define XFS_SB_VERSION_ADDATTR(sbp) xfs_sb_version_addattr(sbp)
Nathan Scotta844f452005-11-02 14:38:42 +1100271static inline void xfs_sb_version_addattr(xfs_sb_t *sbp)
272{
273 (sbp)->sb_versionnum = (((sbp)->sb_versionnum == XFS_SB_VERSION_1) ? \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 XFS_SB_VERSION_2 : \
275 ((XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) ? \
276 ((sbp)->sb_versionnum | XFS_SB_VERSION_ATTRBIT) : \
Nathan Scotta844f452005-11-02 14:38:42 +1100277 (XFS_SB_VERSION_4 | XFS_SB_VERSION_ATTRBIT)));
278}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280#define XFS_SB_VERSION_HASNLINK(sbp) xfs_sb_version_hasnlink(sbp)
Nathan Scotta844f452005-11-02 14:38:42 +1100281static inline int xfs_sb_version_hasnlink(xfs_sb_t *sbp)
282{
283 return ((sbp)->sb_versionnum == XFS_SB_VERSION_3) || \
284 ((XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) && \
285 ((sbp)->sb_versionnum & XFS_SB_VERSION_NLINKBIT));
286}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288#define XFS_SB_VERSION_ADDNLINK(sbp) xfs_sb_version_addnlink(sbp)
Nathan Scotta844f452005-11-02 14:38:42 +1100289static inline void xfs_sb_version_addnlink(xfs_sb_t *sbp)
290{
291 (sbp)->sb_versionnum = ((sbp)->sb_versionnum <= XFS_SB_VERSION_2 ? \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 XFS_SB_VERSION_3 : \
Nathan Scotta844f452005-11-02 14:38:42 +1100293 ((sbp)->sb_versionnum | XFS_SB_VERSION_NLINKBIT));
294}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296#define XFS_SB_VERSION_HASQUOTA(sbp) xfs_sb_version_hasquota(sbp)
Nathan Scotta844f452005-11-02 14:38:42 +1100297static inline int xfs_sb_version_hasquota(xfs_sb_t *sbp)
298{
299 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) && \
300 ((sbp)->sb_versionnum & XFS_SB_VERSION_QUOTABIT);
301}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303#define XFS_SB_VERSION_ADDQUOTA(sbp) xfs_sb_version_addquota(sbp)
Nathan Scotta844f452005-11-02 14:38:42 +1100304static inline void xfs_sb_version_addquota(xfs_sb_t *sbp)
305{
306 (sbp)->sb_versionnum = \
307 (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 ? \
308 ((sbp)->sb_versionnum | XFS_SB_VERSION_QUOTABIT) : \
309 (XFS_SB_VERSION_TONEW((sbp)->sb_versionnum) | \
310 XFS_SB_VERSION_QUOTABIT));
311}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313#define XFS_SB_VERSION_HASALIGN(sbp) xfs_sb_version_hasalign(sbp)
Nathan Scotta844f452005-11-02 14:38:42 +1100314static inline int xfs_sb_version_hasalign(xfs_sb_t *sbp)
315{
316 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) && \
317 ((sbp)->sb_versionnum & XFS_SB_VERSION_ALIGNBIT);
318}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320#define XFS_SB_VERSION_SUBALIGN(sbp) xfs_sb_version_subalign(sbp)
Nathan Scotta844f452005-11-02 14:38:42 +1100321static inline void xfs_sb_version_subalign(xfs_sb_t *sbp)
322{
323 (sbp)->sb_versionnum = \
324 XFS_SB_VERSION_TOOLD((sbp)->sb_versionnum & ~XFS_SB_VERSION_ALIGNBIT);
325}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327#define XFS_SB_VERSION_HASDALIGN(sbp) xfs_sb_version_hasdalign(sbp)
Nathan Scotta844f452005-11-02 14:38:42 +1100328static inline int xfs_sb_version_hasdalign(xfs_sb_t *sbp)
329{
330 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) && \
331 ((sbp)->sb_versionnum & XFS_SB_VERSION_DALIGNBIT);
332}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334#define XFS_SB_VERSION_ADDDALIGN(sbp) xfs_sb_version_adddalign(sbp)
Nathan Scotta844f452005-11-02 14:38:42 +1100335static inline int xfs_sb_version_adddalign(xfs_sb_t *sbp)
336{
337 return (sbp)->sb_versionnum = \
338 ((sbp)->sb_versionnum | XFS_SB_VERSION_DALIGNBIT);
339}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341#define XFS_SB_VERSION_HASSHARED(sbp) xfs_sb_version_hasshared(sbp)
Nathan Scotta844f452005-11-02 14:38:42 +1100342static inline int xfs_sb_version_hasshared(xfs_sb_t *sbp)
343{
344 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) && \
345 ((sbp)->sb_versionnum & XFS_SB_VERSION_SHAREDBIT);
346}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348#define XFS_SB_VERSION_ADDSHARED(sbp) xfs_sb_version_addshared(sbp)
Nathan Scotta844f452005-11-02 14:38:42 +1100349static inline int xfs_sb_version_addshared(xfs_sb_t *sbp)
350{
351 return (sbp)->sb_versionnum = \
352 ((sbp)->sb_versionnum | XFS_SB_VERSION_SHAREDBIT);
353}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355#define XFS_SB_VERSION_SUBSHARED(sbp) xfs_sb_version_subshared(sbp)
Nathan Scotta844f452005-11-02 14:38:42 +1100356static inline int xfs_sb_version_subshared(xfs_sb_t *sbp)
357{
358 return (sbp)->sb_versionnum = \
359 ((sbp)->sb_versionnum & ~XFS_SB_VERSION_SHAREDBIT);
360}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362#define XFS_SB_VERSION_HASDIRV2(sbp) xfs_sb_version_hasdirv2(sbp)
Nathan Scotta844f452005-11-02 14:38:42 +1100363static inline int xfs_sb_version_hasdirv2(xfs_sb_t *sbp)
364{
365 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) && \
366 ((sbp)->sb_versionnum & XFS_SB_VERSION_DIRV2BIT);
367}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369#define XFS_SB_VERSION_HASLOGV2(sbp) xfs_sb_version_haslogv2(sbp)
Nathan Scotta844f452005-11-02 14:38:42 +1100370static inline int xfs_sb_version_haslogv2(xfs_sb_t *sbp)
371{
372 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) && \
373 ((sbp)->sb_versionnum & XFS_SB_VERSION_LOGV2BIT);
374}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376#define XFS_SB_VERSION_HASEXTFLGBIT(sbp) xfs_sb_version_hasextflgbit(sbp)
Nathan Scotta844f452005-11-02 14:38:42 +1100377static inline int xfs_sb_version_hasextflgbit(xfs_sb_t *sbp)
378{
379 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) && \
380 ((sbp)->sb_versionnum & XFS_SB_VERSION_EXTFLGBIT);
381}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383#define XFS_SB_VERSION_ADDEXTFLGBIT(sbp) xfs_sb_version_addextflgbit(sbp)
Nathan Scotta844f452005-11-02 14:38:42 +1100384static inline int xfs_sb_version_addextflgbit(xfs_sb_t *sbp)
385{
386 return (sbp)->sb_versionnum = \
387 ((sbp)->sb_versionnum | XFS_SB_VERSION_EXTFLGBIT);
388}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390#define XFS_SB_VERSION_SUBEXTFLGBIT(sbp) xfs_sb_version_subextflgbit(sbp)
Nathan Scotta844f452005-11-02 14:38:42 +1100391static inline int xfs_sb_version_subextflgbit(xfs_sb_t *sbp)
392{
393 return (sbp)->sb_versionnum = \
394 ((sbp)->sb_versionnum & ~XFS_SB_VERSION_EXTFLGBIT);
395}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397#define XFS_SB_VERSION_HASSECTOR(sbp) xfs_sb_version_hassector(sbp)
Nathan Scotta844f452005-11-02 14:38:42 +1100398static inline int xfs_sb_version_hassector(xfs_sb_t *sbp)
399{
400 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) && \
401 ((sbp)->sb_versionnum & XFS_SB_VERSION_SECTORBIT);
402}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404#define XFS_SB_VERSION_HASMOREBITS(sbp) xfs_sb_version_hasmorebits(sbp)
Nathan Scotta844f452005-11-02 14:38:42 +1100405static inline int xfs_sb_version_hasmorebits(xfs_sb_t *sbp)
406{
407 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) && \
408 ((sbp)->sb_versionnum & XFS_SB_VERSION_MOREBITSBIT);
409}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410
411/*
412 * sb_features2 bit version macros.
413 *
Nathan Scottd8cc8902005-11-02 10:34:53 +1100414 * For example, for a bit defined as XFS_SB_VERSION2_FUNBIT, has a macro:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 *
Nathan Scottd8cc8902005-11-02 10:34:53 +1100416 * SB_VERSION_HASFUNBIT(xfs_sb_t *sbp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 * ((XFS_SB_VERSION_HASMOREBITS(sbp) &&
Nathan Scottd8cc8902005-11-02 10:34:53 +1100418 * ((sbp)->sb_features2 & XFS_SB_VERSION2_FUNBIT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 */
420
David Chinner92821e22007-05-24 15:26:31 +1000421static inline int xfs_sb_version_haslazysbcount(xfs_sb_t *sbp)
422{
423 return (XFS_SB_VERSION_HASMOREBITS(sbp) && \
424 ((sbp)->sb_features2 & XFS_SB_VERSION2_LAZYSBCOUNTBIT));
425}
426
Nathan Scotta844f452005-11-02 14:38:42 +1100427#define XFS_SB_VERSION_HASATTR2(sbp) xfs_sb_version_hasattr2(sbp)
428static inline int xfs_sb_version_hasattr2(xfs_sb_t *sbp)
429{
430 return (XFS_SB_VERSION_HASMOREBITS(sbp)) && \
431 ((sbp)->sb_features2 & XFS_SB_VERSION2_ATTR2BIT);
432}
433
Nathan Scottd8cc8902005-11-02 10:34:53 +1100434#define XFS_SB_VERSION_ADDATTR2(sbp) xfs_sb_version_addattr2(sbp)
Nathan Scotta844f452005-11-02 14:38:42 +1100435static inline void xfs_sb_version_addattr2(xfs_sb_t *sbp)
436{
Nathan Scottd8cc8902005-11-02 10:34:53 +1100437 ((sbp)->sb_versionnum = \
438 ((sbp)->sb_versionnum | XFS_SB_VERSION_MOREBITSBIT), \
439 ((sbp)->sb_features2 = \
Nathan Scotta844f452005-11-02 14:38:42 +1100440 ((sbp)->sb_features2 | XFS_SB_VERSION2_ATTR2BIT)));
441}
442
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443/*
444 * end of superblock version macros
445 */
446
Nathan Scotta844f452005-11-02 14:38:42 +1100447#define XFS_SB_DADDR ((xfs_daddr_t)0) /* daddr in filesystem/ag */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448#define XFS_SB_BLOCK(mp) XFS_HDR_BLOCK(mp, XFS_SB_DADDR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449#define XFS_BUF_TO_SBP(bp) ((xfs_sb_t *)XFS_BUF_PTR(bp))
Nathan Scotta844f452005-11-02 14:38:42 +1100450
451#define XFS_HDR_BLOCK(mp,d) ((xfs_agblock_t)XFS_BB_TO_FSBT(mp,d))
452#define XFS_DADDR_TO_FSB(mp,d) XFS_AGB_TO_FSB(mp, \
453 XFS_DADDR_TO_AGNO(mp,d), XFS_DADDR_TO_AGBNO(mp,d))
454#define XFS_FSB_TO_DADDR(mp,fsbno) XFS_AGB_TO_DADDR(mp, \
455 XFS_FSB_TO_AGNO(mp,fsbno), XFS_FSB_TO_AGBNO(mp,fsbno))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456
457/*
458 * File system sector to basic block conversions.
459 */
460#define XFS_FSS_TO_BB(mp,sec) ((sec) << (mp)->m_sectbb_log)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461
462/*
463 * File system block to basic block conversions.
464 */
465#define XFS_FSB_TO_BB(mp,fsbno) ((fsbno) << (mp)->m_blkbb_log)
466#define XFS_BB_TO_FSB(mp,bb) \
467 (((bb) + (XFS_FSB_TO_BB(mp,1) - 1)) >> (mp)->m_blkbb_log)
468#define XFS_BB_TO_FSBT(mp,bb) ((bb) >> (mp)->m_blkbb_log)
469#define XFS_BB_FSB_OFFSET(mp,bb) ((bb) & ((mp)->m_bsize - 1))
470
471/*
472 * File system block to byte conversions.
473 */
474#define XFS_FSB_TO_B(mp,fsbno) ((xfs_fsize_t)(fsbno) << (mp)->m_sb.sb_blocklog)
475#define XFS_B_TO_FSB(mp,b) \
476 ((((__uint64_t)(b)) + (mp)->m_blockmask) >> (mp)->m_sb.sb_blocklog)
477#define XFS_B_TO_FSBT(mp,b) (((__uint64_t)(b)) >> (mp)->m_sb.sb_blocklog)
478#define XFS_B_FSB_OFFSET(mp,b) ((b) & (mp)->m_blockmask)
479
480#endif /* __XFS_SB_H__ */