blob: 3f8cf1587f4cc09521ad17815160af4ad7395cd8 [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
Barry Naujok189f4bf2008-05-21 16:58:55 +100049#define XFS_SB_VERSION_BORGBIT 0x4000 /* ASCII only case-insens. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#define XFS_SB_VERSION_MOREBITSBIT 0x8000
51#define XFS_SB_VERSION_OKSASHFBITS \
52 (XFS_SB_VERSION_EXTFLGBIT | \
Barry Naujok189f4bf2008-05-21 16:58:55 +100053 XFS_SB_VERSION_DIRV2BIT | \
54 XFS_SB_VERSION_BORGBIT)
Linus Torvalds1da177e2005-04-16 15:20:36 -070055#define XFS_SB_VERSION_OKREALFBITS \
56 (XFS_SB_VERSION_ATTRBIT | \
57 XFS_SB_VERSION_NLINKBIT | \
58 XFS_SB_VERSION_QUOTABIT | \
59 XFS_SB_VERSION_ALIGNBIT | \
60 XFS_SB_VERSION_DALIGNBIT | \
61 XFS_SB_VERSION_SHAREDBIT | \
62 XFS_SB_VERSION_LOGV2BIT | \
Nathan Scottd8cc8902005-11-02 10:34:53 +110063 XFS_SB_VERSION_SECTORBIT | \
64 XFS_SB_VERSION_MOREBITSBIT)
Linus Torvalds1da177e2005-04-16 15:20:36 -070065#define XFS_SB_VERSION_OKREALBITS \
66 (XFS_SB_VERSION_NUMBITS | \
67 XFS_SB_VERSION_OKREALFBITS | \
68 XFS_SB_VERSION_OKSASHFBITS)
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
70/*
71 * There are two words to hold XFS "feature" bits: the original
72 * word, sb_versionnum, and sb_features2. Whenever a bit is set in
73 * sb_features2, the feature bit XFS_SB_VERSION_MOREBITSBIT must be set.
74 *
75 * These defines represent bits in sb_features2.
76 */
77#define XFS_SB_VERSION2_REALFBITS 0x00ffffff /* Mask: features */
78#define XFS_SB_VERSION2_RESERVED1BIT 0x00000001
David Chinner92821e22007-05-24 15:26:31 +100079#define XFS_SB_VERSION2_LAZYSBCOUNTBIT 0x00000002 /* Superblk counters */
Nathan Scottd8cc8902005-11-02 10:34:53 +110080#define XFS_SB_VERSION2_RESERVED4BIT 0x00000004
81#define XFS_SB_VERSION2_ATTR2BIT 0x00000008 /* Inline attr rework */
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
83#define XFS_SB_VERSION2_OKREALFBITS \
David Chinner92821e22007-05-24 15:26:31 +100084 (XFS_SB_VERSION2_LAZYSBCOUNTBIT | \
85 XFS_SB_VERSION2_ATTR2BIT)
Linus Torvalds1da177e2005-04-16 15:20:36 -070086#define XFS_SB_VERSION2_OKSASHFBITS \
87 (0)
88#define XFS_SB_VERSION2_OKREALBITS \
89 (XFS_SB_VERSION2_OKREALFBITS | \
90 XFS_SB_VERSION2_OKSASHFBITS )
91
Christoph Hellwig2bdf7cd2007-08-28 13:58:06 +100092/*
93 * Superblock - in core version. Must match the ondisk version below.
David Chinneree1c0902008-03-06 13:45:50 +110094 * Must be padded to 64 bit alignment.
Christoph Hellwig2bdf7cd2007-08-28 13:58:06 +100095 */
96typedef struct xfs_sb {
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 __uint32_t sb_magicnum; /* magic number == XFS_SB_MAGIC */
98 __uint32_t sb_blocksize; /* logical block size, bytes */
99 xfs_drfsbno_t sb_dblocks; /* number of data blocks */
100 xfs_drfsbno_t sb_rblocks; /* number of realtime blocks */
101 xfs_drtbno_t sb_rextents; /* number of realtime extents */
102 uuid_t sb_uuid; /* file system unique id */
103 xfs_dfsbno_t sb_logstart; /* starting block of log if internal */
104 xfs_ino_t sb_rootino; /* root inode number */
105 xfs_ino_t sb_rbmino; /* bitmap inode for realtime extents */
106 xfs_ino_t sb_rsumino; /* summary inode for rt bitmap */
107 xfs_agblock_t sb_rextsize; /* realtime extent size, blocks */
108 xfs_agblock_t sb_agblocks; /* size of an allocation group */
109 xfs_agnumber_t sb_agcount; /* number of allocation groups */
110 xfs_extlen_t sb_rbmblocks; /* number of rt bitmap blocks */
111 xfs_extlen_t sb_logblocks; /* number of log blocks */
112 __uint16_t sb_versionnum; /* header version == XFS_SB_VERSION */
113 __uint16_t sb_sectsize; /* volume sector size, bytes */
114 __uint16_t sb_inodesize; /* inode size, bytes */
115 __uint16_t sb_inopblock; /* inodes per block */
116 char sb_fname[12]; /* file system name */
117 __uint8_t sb_blocklog; /* log2 of sb_blocksize */
118 __uint8_t sb_sectlog; /* log2 of sb_sectsize */
119 __uint8_t sb_inodelog; /* log2 of sb_inodesize */
120 __uint8_t sb_inopblog; /* log2 of sb_inopblock */
121 __uint8_t sb_agblklog; /* log2 of sb_agblocks (rounded up) */
122 __uint8_t sb_rextslog; /* log2 of sb_rextents */
123 __uint8_t sb_inprogress; /* mkfs is in progress, don't mount */
124 __uint8_t sb_imax_pct; /* max % of fs for inode space */
125 /* statistics */
126 /*
127 * These fields must remain contiguous. If you really
128 * want to change their layout, make sure you fix the
129 * code in xfs_trans_apply_sb_deltas().
130 */
131 __uint64_t sb_icount; /* allocated inodes */
132 __uint64_t sb_ifree; /* free inodes */
133 __uint64_t sb_fdblocks; /* free data blocks */
134 __uint64_t sb_frextents; /* free realtime extents */
135 /*
136 * End contiguous fields.
137 */
138 xfs_ino_t sb_uquotino; /* user quota inode */
139 xfs_ino_t sb_gquotino; /* group quota inode */
140 __uint16_t sb_qflags; /* quota flags */
141 __uint8_t sb_flags; /* misc. flags */
142 __uint8_t sb_shared_vn; /* shared version number */
143 xfs_extlen_t sb_inoalignmt; /* inode chunk alignment, fsblocks */
144 __uint32_t sb_unit; /* stripe or raid unit */
145 __uint32_t sb_width; /* stripe or raid width */
146 __uint8_t sb_dirblklog; /* log2 of dir block size (fsbs) */
147 __uint8_t sb_logsectlog; /* log2 of the log sector size */
148 __uint16_t sb_logsectsize; /* sector size for the log, bytes */
149 __uint32_t sb_logsunit; /* stripe unit size for the log */
Nathan Scottd8cc8902005-11-02 10:34:53 +1100150 __uint32_t sb_features2; /* additional feature bits */
David Chinneree1c0902008-03-06 13:45:50 +1100151
152 /*
153 * bad features2 field as a result of failing to pad the sb
154 * structure to 64 bits. Some machines will be using this field
155 * for features2 bits. Easiest just to mark it bad and not use
156 * it for anything else.
157 */
158 __uint32_t sb_bad_features2;
159
160 /* must be padded to 64 bit alignment */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161} xfs_sb_t;
162
163/*
David Chinneree1c0902008-03-06 13:45:50 +1100164 * Superblock - on disk version. Must match the in core version above.
165 * Must be padded to 64 bit alignment.
Christoph Hellwig2bdf7cd2007-08-28 13:58:06 +1000166 */
167typedef struct xfs_dsb {
168 __be32 sb_magicnum; /* magic number == XFS_SB_MAGIC */
169 __be32 sb_blocksize; /* logical block size, bytes */
170 __be64 sb_dblocks; /* number of data blocks */
171 __be64 sb_rblocks; /* number of realtime blocks */
172 __be64 sb_rextents; /* number of realtime extents */
173 uuid_t sb_uuid; /* file system unique id */
174 __be64 sb_logstart; /* starting block of log if internal */
175 __be64 sb_rootino; /* root inode number */
176 __be64 sb_rbmino; /* bitmap inode for realtime extents */
177 __be64 sb_rsumino; /* summary inode for rt bitmap */
178 __be32 sb_rextsize; /* realtime extent size, blocks */
179 __be32 sb_agblocks; /* size of an allocation group */
180 __be32 sb_agcount; /* number of allocation groups */
181 __be32 sb_rbmblocks; /* number of rt bitmap blocks */
182 __be32 sb_logblocks; /* number of log blocks */
183 __be16 sb_versionnum; /* header version == XFS_SB_VERSION */
184 __be16 sb_sectsize; /* volume sector size, bytes */
185 __be16 sb_inodesize; /* inode size, bytes */
186 __be16 sb_inopblock; /* inodes per block */
187 char sb_fname[12]; /* file system name */
188 __u8 sb_blocklog; /* log2 of sb_blocksize */
189 __u8 sb_sectlog; /* log2 of sb_sectsize */
190 __u8 sb_inodelog; /* log2 of sb_inodesize */
191 __u8 sb_inopblog; /* log2 of sb_inopblock */
192 __u8 sb_agblklog; /* log2 of sb_agblocks (rounded up) */
193 __u8 sb_rextslog; /* log2 of sb_rextents */
194 __u8 sb_inprogress; /* mkfs is in progress, don't mount */
195 __u8 sb_imax_pct; /* max % of fs for inode space */
196 /* statistics */
197 /*
198 * These fields must remain contiguous. If you really
199 * want to change their layout, make sure you fix the
200 * code in xfs_trans_apply_sb_deltas().
201 */
202 __be64 sb_icount; /* allocated inodes */
203 __be64 sb_ifree; /* free inodes */
204 __be64 sb_fdblocks; /* free data blocks */
205 __be64 sb_frextents; /* free realtime extents */
206 /*
207 * End contiguous fields.
208 */
209 __be64 sb_uquotino; /* user quota inode */
210 __be64 sb_gquotino; /* group quota inode */
211 __be16 sb_qflags; /* quota flags */
212 __u8 sb_flags; /* misc. flags */
213 __u8 sb_shared_vn; /* shared version number */
214 __be32 sb_inoalignmt; /* inode chunk alignment, fsblocks */
215 __be32 sb_unit; /* stripe or raid unit */
216 __be32 sb_width; /* stripe or raid width */
217 __u8 sb_dirblklog; /* log2 of dir block size (fsbs) */
218 __u8 sb_logsectlog; /* log2 of the log sector size */
219 __be16 sb_logsectsize; /* sector size for the log, bytes */
220 __be32 sb_logsunit; /* stripe unit size for the log */
221 __be32 sb_features2; /* additional feature bits */
David Chinneree1c0902008-03-06 13:45:50 +1100222 /*
223 * bad features2 field as a result of failing to pad the sb
224 * structure to 64 bits. Some machines will be using this field
225 * for features2 bits. Easiest just to mark it bad and not use
226 * it for anything else.
227 */
228 __be32 sb_bad_features2;
229
230 /* must be padded to 64 bit alignment */
Christoph Hellwig2bdf7cd2007-08-28 13:58:06 +1000231} xfs_dsb_t;
232
233/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 * Sequence number values for the fields.
235 */
236typedef enum {
237 XFS_SBS_MAGICNUM, XFS_SBS_BLOCKSIZE, XFS_SBS_DBLOCKS, XFS_SBS_RBLOCKS,
238 XFS_SBS_REXTENTS, XFS_SBS_UUID, XFS_SBS_LOGSTART, XFS_SBS_ROOTINO,
239 XFS_SBS_RBMINO, XFS_SBS_RSUMINO, XFS_SBS_REXTSIZE, XFS_SBS_AGBLOCKS,
240 XFS_SBS_AGCOUNT, XFS_SBS_RBMBLOCKS, XFS_SBS_LOGBLOCKS,
241 XFS_SBS_VERSIONNUM, XFS_SBS_SECTSIZE, XFS_SBS_INODESIZE,
242 XFS_SBS_INOPBLOCK, XFS_SBS_FNAME, XFS_SBS_BLOCKLOG,
243 XFS_SBS_SECTLOG, XFS_SBS_INODELOG, XFS_SBS_INOPBLOG, XFS_SBS_AGBLKLOG,
244 XFS_SBS_REXTSLOG, XFS_SBS_INPROGRESS, XFS_SBS_IMAX_PCT, XFS_SBS_ICOUNT,
245 XFS_SBS_IFREE, XFS_SBS_FDBLOCKS, XFS_SBS_FREXTENTS, XFS_SBS_UQUOTINO,
246 XFS_SBS_GQUOTINO, XFS_SBS_QFLAGS, XFS_SBS_FLAGS, XFS_SBS_SHARED_VN,
247 XFS_SBS_INOALIGNMT, XFS_SBS_UNIT, XFS_SBS_WIDTH, XFS_SBS_DIRBLKLOG,
248 XFS_SBS_LOGSECTLOG, XFS_SBS_LOGSECTSIZE, XFS_SBS_LOGSUNIT,
David Chinneree1c0902008-03-06 13:45:50 +1100249 XFS_SBS_FEATURES2, XFS_SBS_BAD_FEATURES2,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 XFS_SBS_FIELDCOUNT
251} xfs_sb_field_t;
252
253/*
254 * Mask values, defined based on the xfs_sb_field_t values.
255 * Only define the ones we're using.
256 */
257#define XFS_SB_MVAL(x) (1LL << XFS_SBS_ ## x)
258#define XFS_SB_UUID XFS_SB_MVAL(UUID)
259#define XFS_SB_FNAME XFS_SB_MVAL(FNAME)
260#define XFS_SB_ROOTINO XFS_SB_MVAL(ROOTINO)
261#define XFS_SB_RBMINO XFS_SB_MVAL(RBMINO)
262#define XFS_SB_RSUMINO XFS_SB_MVAL(RSUMINO)
263#define XFS_SB_VERSIONNUM XFS_SB_MVAL(VERSIONNUM)
264#define XFS_SB_UQUOTINO XFS_SB_MVAL(UQUOTINO)
265#define XFS_SB_GQUOTINO XFS_SB_MVAL(GQUOTINO)
266#define XFS_SB_QFLAGS XFS_SB_MVAL(QFLAGS)
267#define XFS_SB_SHARED_VN XFS_SB_MVAL(SHARED_VN)
268#define XFS_SB_UNIT XFS_SB_MVAL(UNIT)
269#define XFS_SB_WIDTH XFS_SB_MVAL(WIDTH)
David Chinner92821e22007-05-24 15:26:31 +1000270#define XFS_SB_ICOUNT XFS_SB_MVAL(ICOUNT)
271#define XFS_SB_IFREE XFS_SB_MVAL(IFREE)
272#define XFS_SB_FDBLOCKS XFS_SB_MVAL(FDBLOCKS)
Nathan Scottd8cc8902005-11-02 10:34:53 +1100273#define XFS_SB_FEATURES2 XFS_SB_MVAL(FEATURES2)
David Chinneree1c0902008-03-06 13:45:50 +1100274#define XFS_SB_BAD_FEATURES2 XFS_SB_MVAL(BAD_FEATURES2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275#define XFS_SB_NUM_BITS ((int)XFS_SBS_FIELDCOUNT)
276#define XFS_SB_ALL_BITS ((1LL << XFS_SB_NUM_BITS) - 1)
277#define XFS_SB_MOD_BITS \
278 (XFS_SB_UUID | XFS_SB_ROOTINO | XFS_SB_RBMINO | XFS_SB_RSUMINO | \
279 XFS_SB_VERSIONNUM | XFS_SB_UQUOTINO | XFS_SB_GQUOTINO | \
Nathan Scottd8cc8902005-11-02 10:34:53 +1100280 XFS_SB_QFLAGS | XFS_SB_SHARED_VN | XFS_SB_UNIT | XFS_SB_WIDTH | \
David Chinneree1c0902008-03-06 13:45:50 +1100281 XFS_SB_ICOUNT | XFS_SB_IFREE | XFS_SB_FDBLOCKS | XFS_SB_FEATURES2 | \
282 XFS_SB_BAD_FEATURES2)
Nathan Scottd8cc8902005-11-02 10:34:53 +1100283
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284
285/*
286 * Misc. Flags - warning - these will be cleared by xfs_repair unless
287 * a feature bit is set when the flag is used.
288 */
289#define XFS_SBF_NOFLAGS 0x00 /* no flags set */
290#define XFS_SBF_READONLY 0x01 /* only read-only mounts allowed */
291
292/*
293 * define max. shared version we can interoperate with
294 */
295#define XFS_SB_MAX_SHARED_VN 0
296
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297#define XFS_SB_VERSION_NUM(sbp) ((sbp)->sb_versionnum & XFS_SB_VERSION_NUMBITS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299#ifdef __KERNEL__
Nathan Scotta844f452005-11-02 14:38:42 +1100300static inline int xfs_sb_good_version(xfs_sb_t *sbp)
301{
302 return (((sbp->sb_versionnum >= XFS_SB_VERSION_1) && \
303 (sbp->sb_versionnum <= XFS_SB_VERSION_3)) || \
304 ((XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) && \
305 !((sbp->sb_versionnum & ~XFS_SB_VERSION_OKREALBITS) || \
306 ((sbp->sb_versionnum & XFS_SB_VERSION_MOREBITSBIT) && \
307 (sbp->sb_features2 & ~XFS_SB_VERSION2_OKREALBITS))) && \
308 (sbp->sb_shared_vn <= XFS_SB_MAX_SHARED_VN)));
309}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310#else
Nathan Scotta844f452005-11-02 14:38:42 +1100311static inline int xfs_sb_good_version(xfs_sb_t *sbp)
312{
313 return (((sbp->sb_versionnum >= XFS_SB_VERSION_1) && \
314 (sbp->sb_versionnum <= XFS_SB_VERSION_3)) || \
315 ((XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) && \
316 !((sbp->sb_versionnum & ~XFS_SB_VERSION_OKREALBITS) || \
317 ((sbp->sb_versionnum & XFS_SB_VERSION_MOREBITSBIT) && \
318 (sbp->sb_features2 & ~XFS_SB_VERSION2_OKREALBITS))) && \
319 (!(sbp->sb_versionnum & XFS_SB_VERSION_SHAREDBIT) || \
320 (sbp->sb_shared_vn <= XFS_SB_MAX_SHARED_VN))));
321}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322#endif /* __KERNEL__ */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
David Chinneree1c0902008-03-06 13:45:50 +1100324/*
Eric Sandeene6957ea2008-04-10 12:19:34 +1000325 * Detect a mismatched features2 field. Older kernels read/wrote
326 * this into the wrong slot, so to be safe we keep them in sync.
David Chinneree1c0902008-03-06 13:45:50 +1100327 */
Eric Sandeene6957ea2008-04-10 12:19:34 +1000328static inline int xfs_sb_has_mismatched_features2(xfs_sb_t *sbp)
David Chinneree1c0902008-03-06 13:45:50 +1100329{
Eric Sandeene6957ea2008-04-10 12:19:34 +1000330 return (sbp->sb_bad_features2 != sbp->sb_features2);
David Chinneree1c0902008-03-06 13:45:50 +1100331}
332
Nathan Scotta844f452005-11-02 14:38:42 +1100333static inline unsigned xfs_sb_version_tonew(unsigned v)
334{
335 return ((((v) == XFS_SB_VERSION_1) ? \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 0 : \
337 (((v) == XFS_SB_VERSION_2) ? \
338 XFS_SB_VERSION_ATTRBIT : \
339 (XFS_SB_VERSION_ATTRBIT | XFS_SB_VERSION_NLINKBIT))) | \
Nathan Scotta844f452005-11-02 14:38:42 +1100340 XFS_SB_VERSION_4);
341}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342
Nathan Scotta844f452005-11-02 14:38:42 +1100343static inline unsigned xfs_sb_version_toold(unsigned v)
344{
345 return (((v) & (XFS_SB_VERSION_QUOTABIT | XFS_SB_VERSION_ALIGNBIT)) ? \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 0 : \
347 (((v) & XFS_SB_VERSION_NLINKBIT) ? \
348 XFS_SB_VERSION_3 : \
349 (((v) & XFS_SB_VERSION_ATTRBIT) ? \
350 XFS_SB_VERSION_2 : \
Nathan Scotta844f452005-11-02 14:38:42 +1100351 XFS_SB_VERSION_1)));
352}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353
Nathan Scotta844f452005-11-02 14:38:42 +1100354static inline int xfs_sb_version_hasattr(xfs_sb_t *sbp)
355{
356 return ((sbp)->sb_versionnum == XFS_SB_VERSION_2) || \
357 ((sbp)->sb_versionnum == XFS_SB_VERSION_3) || \
358 ((XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) && \
359 ((sbp)->sb_versionnum & XFS_SB_VERSION_ATTRBIT));
360}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361
Nathan Scotta844f452005-11-02 14:38:42 +1100362static inline void xfs_sb_version_addattr(xfs_sb_t *sbp)
363{
364 (sbp)->sb_versionnum = (((sbp)->sb_versionnum == XFS_SB_VERSION_1) ? \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 XFS_SB_VERSION_2 : \
366 ((XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) ? \
367 ((sbp)->sb_versionnum | XFS_SB_VERSION_ATTRBIT) : \
Nathan Scotta844f452005-11-02 14:38:42 +1100368 (XFS_SB_VERSION_4 | XFS_SB_VERSION_ATTRBIT)));
369}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370
Nathan Scotta844f452005-11-02 14:38:42 +1100371static inline int xfs_sb_version_hasnlink(xfs_sb_t *sbp)
372{
373 return ((sbp)->sb_versionnum == XFS_SB_VERSION_3) || \
374 ((XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) && \
375 ((sbp)->sb_versionnum & XFS_SB_VERSION_NLINKBIT));
376}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377
Nathan Scotta844f452005-11-02 14:38:42 +1100378static inline void xfs_sb_version_addnlink(xfs_sb_t *sbp)
379{
380 (sbp)->sb_versionnum = ((sbp)->sb_versionnum <= XFS_SB_VERSION_2 ? \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 XFS_SB_VERSION_3 : \
Nathan Scotta844f452005-11-02 14:38:42 +1100382 ((sbp)->sb_versionnum | XFS_SB_VERSION_NLINKBIT));
383}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384
Nathan Scotta844f452005-11-02 14:38:42 +1100385static inline int xfs_sb_version_hasquota(xfs_sb_t *sbp)
386{
387 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) && \
388 ((sbp)->sb_versionnum & XFS_SB_VERSION_QUOTABIT);
389}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390
Nathan Scotta844f452005-11-02 14:38:42 +1100391static inline void xfs_sb_version_addquota(xfs_sb_t *sbp)
392{
393 (sbp)->sb_versionnum = \
394 (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 ? \
395 ((sbp)->sb_versionnum | XFS_SB_VERSION_QUOTABIT) : \
Eric Sandeen62118702008-03-06 13:44:28 +1100396 (xfs_sb_version_tonew((sbp)->sb_versionnum) | \
Nathan Scotta844f452005-11-02 14:38:42 +1100397 XFS_SB_VERSION_QUOTABIT));
398}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399
Nathan Scotta844f452005-11-02 14:38:42 +1100400static inline int xfs_sb_version_hasalign(xfs_sb_t *sbp)
401{
402 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) && \
403 ((sbp)->sb_versionnum & XFS_SB_VERSION_ALIGNBIT);
404}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
Nathan Scotta844f452005-11-02 14:38:42 +1100406static inline int xfs_sb_version_hasdalign(xfs_sb_t *sbp)
407{
408 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) && \
409 ((sbp)->sb_versionnum & XFS_SB_VERSION_DALIGNBIT);
410}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411
Nathan Scotta844f452005-11-02 14:38:42 +1100412static inline int xfs_sb_version_hasshared(xfs_sb_t *sbp)
413{
414 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) && \
415 ((sbp)->sb_versionnum & XFS_SB_VERSION_SHAREDBIT);
416}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417
Nathan Scotta844f452005-11-02 14:38:42 +1100418static inline int xfs_sb_version_hasdirv2(xfs_sb_t *sbp)
419{
420 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) && \
421 ((sbp)->sb_versionnum & XFS_SB_VERSION_DIRV2BIT);
422}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423
Nathan Scotta844f452005-11-02 14:38:42 +1100424static inline int xfs_sb_version_haslogv2(xfs_sb_t *sbp)
425{
426 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) && \
427 ((sbp)->sb_versionnum & XFS_SB_VERSION_LOGV2BIT);
428}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429
Nathan Scotta844f452005-11-02 14:38:42 +1100430static inline int xfs_sb_version_hasextflgbit(xfs_sb_t *sbp)
431{
432 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) && \
433 ((sbp)->sb_versionnum & XFS_SB_VERSION_EXTFLGBIT);
434}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435
Nathan Scotta844f452005-11-02 14:38:42 +1100436static inline int xfs_sb_version_hassector(xfs_sb_t *sbp)
437{
438 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) && \
439 ((sbp)->sb_versionnum & XFS_SB_VERSION_SECTORBIT);
440}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441
Barry Naujok189f4bf2008-05-21 16:58:55 +1000442static inline int xfs_sb_version_hasasciici(xfs_sb_t *sbp)
443{
444 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) && \
445 (sbp->sb_versionnum & XFS_SB_VERSION_BORGBIT);
446}
447
Nathan Scotta844f452005-11-02 14:38:42 +1100448static inline int xfs_sb_version_hasmorebits(xfs_sb_t *sbp)
449{
450 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) && \
451 ((sbp)->sb_versionnum & XFS_SB_VERSION_MOREBITSBIT);
452}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453
454/*
455 * sb_features2 bit version macros.
456 *
Nathan Scottd8cc8902005-11-02 10:34:53 +1100457 * For example, for a bit defined as XFS_SB_VERSION2_FUNBIT, has a macro:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 *
Nathan Scottd8cc8902005-11-02 10:34:53 +1100459 * SB_VERSION_HASFUNBIT(xfs_sb_t *sbp)
Eric Sandeen62118702008-03-06 13:44:28 +1100460 * ((xfs_sb_version_hasmorebits(sbp) &&
Nathan Scottd8cc8902005-11-02 10:34:53 +1100461 * ((sbp)->sb_features2 & XFS_SB_VERSION2_FUNBIT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 */
463
David Chinner92821e22007-05-24 15:26:31 +1000464static inline int xfs_sb_version_haslazysbcount(xfs_sb_t *sbp)
465{
Eric Sandeen62118702008-03-06 13:44:28 +1100466 return (xfs_sb_version_hasmorebits(sbp) && \
David Chinner92821e22007-05-24 15:26:31 +1000467 ((sbp)->sb_features2 & XFS_SB_VERSION2_LAZYSBCOUNTBIT));
468}
469
Nathan Scotta844f452005-11-02 14:38:42 +1100470static inline int xfs_sb_version_hasattr2(xfs_sb_t *sbp)
471{
Eric Sandeen62118702008-03-06 13:44:28 +1100472 return (xfs_sb_version_hasmorebits(sbp)) && \
Nathan Scotta844f452005-11-02 14:38:42 +1100473 ((sbp)->sb_features2 & XFS_SB_VERSION2_ATTR2BIT);
474}
475
Nathan Scotta844f452005-11-02 14:38:42 +1100476static inline void xfs_sb_version_addattr2(xfs_sb_t *sbp)
477{
Nathan Scottd8cc8902005-11-02 10:34:53 +1100478 ((sbp)->sb_versionnum = \
479 ((sbp)->sb_versionnum | XFS_SB_VERSION_MOREBITSBIT), \
480 ((sbp)->sb_features2 = \
Nathan Scotta844f452005-11-02 14:38:42 +1100481 ((sbp)->sb_features2 | XFS_SB_VERSION2_ATTR2BIT)));
482}
483
Tim Shimmin7c12f292008-04-30 18:15:28 +1000484static inline void xfs_sb_version_removeattr2(xfs_sb_t *sbp)
485{
486 sbp->sb_features2 &= ~XFS_SB_VERSION2_ATTR2BIT;
487 if (!sbp->sb_features2)
488 sbp->sb_versionnum &= ~XFS_SB_VERSION_MOREBITSBIT;
489}
490
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491/*
492 * end of superblock version macros
493 */
494
Nathan Scotta844f452005-11-02 14:38:42 +1100495#define XFS_SB_DADDR ((xfs_daddr_t)0) /* daddr in filesystem/ag */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496#define XFS_SB_BLOCK(mp) XFS_HDR_BLOCK(mp, XFS_SB_DADDR)
Christoph Hellwig2bdf7cd2007-08-28 13:58:06 +1000497#define XFS_BUF_TO_SBP(bp) ((xfs_dsb_t *)XFS_BUF_PTR(bp))
Nathan Scotta844f452005-11-02 14:38:42 +1100498
499#define XFS_HDR_BLOCK(mp,d) ((xfs_agblock_t)XFS_BB_TO_FSBT(mp,d))
500#define XFS_DADDR_TO_FSB(mp,d) XFS_AGB_TO_FSB(mp, \
501 XFS_DADDR_TO_AGNO(mp,d), XFS_DADDR_TO_AGBNO(mp,d))
502#define XFS_FSB_TO_DADDR(mp,fsbno) XFS_AGB_TO_DADDR(mp, \
503 XFS_FSB_TO_AGNO(mp,fsbno), XFS_FSB_TO_AGBNO(mp,fsbno))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504
505/*
506 * File system sector to basic block conversions.
507 */
508#define XFS_FSS_TO_BB(mp,sec) ((sec) << (mp)->m_sectbb_log)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509
510/*
511 * File system block to basic block conversions.
512 */
513#define XFS_FSB_TO_BB(mp,fsbno) ((fsbno) << (mp)->m_blkbb_log)
514#define XFS_BB_TO_FSB(mp,bb) \
515 (((bb) + (XFS_FSB_TO_BB(mp,1) - 1)) >> (mp)->m_blkbb_log)
516#define XFS_BB_TO_FSBT(mp,bb) ((bb) >> (mp)->m_blkbb_log)
517#define XFS_BB_FSB_OFFSET(mp,bb) ((bb) & ((mp)->m_bsize - 1))
518
519/*
520 * File system block to byte conversions.
521 */
522#define XFS_FSB_TO_B(mp,fsbno) ((xfs_fsize_t)(fsbno) << (mp)->m_sb.sb_blocklog)
523#define XFS_B_TO_FSB(mp,b) \
524 ((((__uint64_t)(b)) + (mp)->m_blockmask) >> (mp)->m_sb.sb_blocklog)
525#define XFS_B_TO_FSBT(mp,b) (((__uint64_t)(b)) >> (mp)->m_sb.sb_blocklog)
526#define XFS_B_FSB_OFFSET(mp,b) ((b) & (mp)->m_blockmask)
527
528#endif /* __XFS_SB_H__ */