blob: cb6ae715814a8f87026b26f701abe419aa3ed6c7 [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 */
Christoph Hellwig6d73cf12008-12-09 04:47:32 -050082#define XFS_SB_VERSION2_PARENTBIT 0x00000010 /* parent pointers */
Arkadiusz Mi?kiewicz67430992010-09-26 06:10:18 +000083#define XFS_SB_VERSION2_PROJID32BIT 0x00000080 /* 32 bit project id */
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
85#define XFS_SB_VERSION2_OKREALFBITS \
David Chinner92821e22007-05-24 15:26:31 +100086 (XFS_SB_VERSION2_LAZYSBCOUNTBIT | \
Arkadiusz Mi?kiewicz67430992010-09-26 06:10:18 +000087 XFS_SB_VERSION2_ATTR2BIT | \
88 XFS_SB_VERSION2_PROJID32BIT)
Linus Torvalds1da177e2005-04-16 15:20:36 -070089#define XFS_SB_VERSION2_OKSASHFBITS \
90 (0)
91#define XFS_SB_VERSION2_OKREALBITS \
92 (XFS_SB_VERSION2_OKREALFBITS | \
93 XFS_SB_VERSION2_OKSASHFBITS )
94
Christoph Hellwig2bdf7cd2007-08-28 13:58:06 +100095/*
96 * Superblock - in core version. Must match the ondisk version below.
David Chinneree1c0902008-03-06 13:45:50 +110097 * Must be padded to 64 bit alignment.
Christoph Hellwig2bdf7cd2007-08-28 13:58:06 +100098 */
99typedef struct xfs_sb {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 __uint32_t sb_magicnum; /* magic number == XFS_SB_MAGIC */
101 __uint32_t sb_blocksize; /* logical block size, bytes */
102 xfs_drfsbno_t sb_dblocks; /* number of data blocks */
103 xfs_drfsbno_t sb_rblocks; /* number of realtime blocks */
104 xfs_drtbno_t sb_rextents; /* number of realtime extents */
105 uuid_t sb_uuid; /* file system unique id */
106 xfs_dfsbno_t sb_logstart; /* starting block of log if internal */
107 xfs_ino_t sb_rootino; /* root inode number */
108 xfs_ino_t sb_rbmino; /* bitmap inode for realtime extents */
109 xfs_ino_t sb_rsumino; /* summary inode for rt bitmap */
110 xfs_agblock_t sb_rextsize; /* realtime extent size, blocks */
111 xfs_agblock_t sb_agblocks; /* size of an allocation group */
112 xfs_agnumber_t sb_agcount; /* number of allocation groups */
113 xfs_extlen_t sb_rbmblocks; /* number of rt bitmap blocks */
114 xfs_extlen_t sb_logblocks; /* number of log blocks */
115 __uint16_t sb_versionnum; /* header version == XFS_SB_VERSION */
116 __uint16_t sb_sectsize; /* volume sector size, bytes */
117 __uint16_t sb_inodesize; /* inode size, bytes */
118 __uint16_t sb_inopblock; /* inodes per block */
119 char sb_fname[12]; /* file system name */
120 __uint8_t sb_blocklog; /* log2 of sb_blocksize */
121 __uint8_t sb_sectlog; /* log2 of sb_sectsize */
122 __uint8_t sb_inodelog; /* log2 of sb_inodesize */
123 __uint8_t sb_inopblog; /* log2 of sb_inopblock */
124 __uint8_t sb_agblklog; /* log2 of sb_agblocks (rounded up) */
125 __uint8_t sb_rextslog; /* log2 of sb_rextents */
126 __uint8_t sb_inprogress; /* mkfs is in progress, don't mount */
127 __uint8_t sb_imax_pct; /* max % of fs for inode space */
128 /* statistics */
129 /*
130 * These fields must remain contiguous. If you really
131 * want to change their layout, make sure you fix the
132 * code in xfs_trans_apply_sb_deltas().
133 */
134 __uint64_t sb_icount; /* allocated inodes */
135 __uint64_t sb_ifree; /* free inodes */
136 __uint64_t sb_fdblocks; /* free data blocks */
137 __uint64_t sb_frextents; /* free realtime extents */
138 /*
139 * End contiguous fields.
140 */
141 xfs_ino_t sb_uquotino; /* user quota inode */
142 xfs_ino_t sb_gquotino; /* group quota inode */
143 __uint16_t sb_qflags; /* quota flags */
144 __uint8_t sb_flags; /* misc. flags */
145 __uint8_t sb_shared_vn; /* shared version number */
146 xfs_extlen_t sb_inoalignmt; /* inode chunk alignment, fsblocks */
147 __uint32_t sb_unit; /* stripe or raid unit */
148 __uint32_t sb_width; /* stripe or raid width */
149 __uint8_t sb_dirblklog; /* log2 of dir block size (fsbs) */
150 __uint8_t sb_logsectlog; /* log2 of the log sector size */
151 __uint16_t sb_logsectsize; /* sector size for the log, bytes */
152 __uint32_t sb_logsunit; /* stripe unit size for the log */
Nathan Scottd8cc8902005-11-02 10:34:53 +1100153 __uint32_t sb_features2; /* additional feature bits */
David Chinneree1c0902008-03-06 13:45:50 +1100154
155 /*
156 * bad features2 field as a result of failing to pad the sb
157 * structure to 64 bits. Some machines will be using this field
158 * for features2 bits. Easiest just to mark it bad and not use
159 * it for anything else.
160 */
161 __uint32_t sb_bad_features2;
162
163 /* must be padded to 64 bit alignment */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164} xfs_sb_t;
165
166/*
David Chinneree1c0902008-03-06 13:45:50 +1100167 * Superblock - on disk version. Must match the in core version above.
168 * Must be padded to 64 bit alignment.
Christoph Hellwig2bdf7cd2007-08-28 13:58:06 +1000169 */
170typedef struct xfs_dsb {
171 __be32 sb_magicnum; /* magic number == XFS_SB_MAGIC */
172 __be32 sb_blocksize; /* logical block size, bytes */
173 __be64 sb_dblocks; /* number of data blocks */
174 __be64 sb_rblocks; /* number of realtime blocks */
175 __be64 sb_rextents; /* number of realtime extents */
176 uuid_t sb_uuid; /* file system unique id */
177 __be64 sb_logstart; /* starting block of log if internal */
178 __be64 sb_rootino; /* root inode number */
179 __be64 sb_rbmino; /* bitmap inode for realtime extents */
180 __be64 sb_rsumino; /* summary inode for rt bitmap */
181 __be32 sb_rextsize; /* realtime extent size, blocks */
182 __be32 sb_agblocks; /* size of an allocation group */
183 __be32 sb_agcount; /* number of allocation groups */
184 __be32 sb_rbmblocks; /* number of rt bitmap blocks */
185 __be32 sb_logblocks; /* number of log blocks */
186 __be16 sb_versionnum; /* header version == XFS_SB_VERSION */
187 __be16 sb_sectsize; /* volume sector size, bytes */
188 __be16 sb_inodesize; /* inode size, bytes */
189 __be16 sb_inopblock; /* inodes per block */
190 char sb_fname[12]; /* file system name */
191 __u8 sb_blocklog; /* log2 of sb_blocksize */
192 __u8 sb_sectlog; /* log2 of sb_sectsize */
193 __u8 sb_inodelog; /* log2 of sb_inodesize */
194 __u8 sb_inopblog; /* log2 of sb_inopblock */
195 __u8 sb_agblklog; /* log2 of sb_agblocks (rounded up) */
196 __u8 sb_rextslog; /* log2 of sb_rextents */
197 __u8 sb_inprogress; /* mkfs is in progress, don't mount */
198 __u8 sb_imax_pct; /* max % of fs for inode space */
199 /* statistics */
200 /*
201 * These fields must remain contiguous. If you really
202 * want to change their layout, make sure you fix the
203 * code in xfs_trans_apply_sb_deltas().
204 */
205 __be64 sb_icount; /* allocated inodes */
206 __be64 sb_ifree; /* free inodes */
207 __be64 sb_fdblocks; /* free data blocks */
208 __be64 sb_frextents; /* free realtime extents */
209 /*
210 * End contiguous fields.
211 */
212 __be64 sb_uquotino; /* user quota inode */
213 __be64 sb_gquotino; /* group quota inode */
214 __be16 sb_qflags; /* quota flags */
215 __u8 sb_flags; /* misc. flags */
216 __u8 sb_shared_vn; /* shared version number */
217 __be32 sb_inoalignmt; /* inode chunk alignment, fsblocks */
218 __be32 sb_unit; /* stripe or raid unit */
219 __be32 sb_width; /* stripe or raid width */
220 __u8 sb_dirblklog; /* log2 of dir block size (fsbs) */
221 __u8 sb_logsectlog; /* log2 of the log sector size */
222 __be16 sb_logsectsize; /* sector size for the log, bytes */
223 __be32 sb_logsunit; /* stripe unit size for the log */
224 __be32 sb_features2; /* additional feature bits */
David Chinneree1c0902008-03-06 13:45:50 +1100225 /*
226 * bad features2 field as a result of failing to pad the sb
227 * structure to 64 bits. Some machines will be using this field
228 * for features2 bits. Easiest just to mark it bad and not use
229 * it for anything else.
230 */
231 __be32 sb_bad_features2;
232
233 /* must be padded to 64 bit alignment */
Christoph Hellwig2bdf7cd2007-08-28 13:58:06 +1000234} xfs_dsb_t;
235
236/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 * Sequence number values for the fields.
238 */
239typedef enum {
240 XFS_SBS_MAGICNUM, XFS_SBS_BLOCKSIZE, XFS_SBS_DBLOCKS, XFS_SBS_RBLOCKS,
241 XFS_SBS_REXTENTS, XFS_SBS_UUID, XFS_SBS_LOGSTART, XFS_SBS_ROOTINO,
242 XFS_SBS_RBMINO, XFS_SBS_RSUMINO, XFS_SBS_REXTSIZE, XFS_SBS_AGBLOCKS,
243 XFS_SBS_AGCOUNT, XFS_SBS_RBMBLOCKS, XFS_SBS_LOGBLOCKS,
244 XFS_SBS_VERSIONNUM, XFS_SBS_SECTSIZE, XFS_SBS_INODESIZE,
245 XFS_SBS_INOPBLOCK, XFS_SBS_FNAME, XFS_SBS_BLOCKLOG,
246 XFS_SBS_SECTLOG, XFS_SBS_INODELOG, XFS_SBS_INOPBLOG, XFS_SBS_AGBLKLOG,
247 XFS_SBS_REXTSLOG, XFS_SBS_INPROGRESS, XFS_SBS_IMAX_PCT, XFS_SBS_ICOUNT,
248 XFS_SBS_IFREE, XFS_SBS_FDBLOCKS, XFS_SBS_FREXTENTS, XFS_SBS_UQUOTINO,
249 XFS_SBS_GQUOTINO, XFS_SBS_QFLAGS, XFS_SBS_FLAGS, XFS_SBS_SHARED_VN,
250 XFS_SBS_INOALIGNMT, XFS_SBS_UNIT, XFS_SBS_WIDTH, XFS_SBS_DIRBLKLOG,
251 XFS_SBS_LOGSECTLOG, XFS_SBS_LOGSECTSIZE, XFS_SBS_LOGSUNIT,
David Chinneree1c0902008-03-06 13:45:50 +1100252 XFS_SBS_FEATURES2, XFS_SBS_BAD_FEATURES2,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 XFS_SBS_FIELDCOUNT
254} xfs_sb_field_t;
255
256/*
257 * Mask values, defined based on the xfs_sb_field_t values.
258 * Only define the ones we're using.
259 */
260#define XFS_SB_MVAL(x) (1LL << XFS_SBS_ ## x)
261#define XFS_SB_UUID XFS_SB_MVAL(UUID)
262#define XFS_SB_FNAME XFS_SB_MVAL(FNAME)
263#define XFS_SB_ROOTINO XFS_SB_MVAL(ROOTINO)
264#define XFS_SB_RBMINO XFS_SB_MVAL(RBMINO)
265#define XFS_SB_RSUMINO XFS_SB_MVAL(RSUMINO)
266#define XFS_SB_VERSIONNUM XFS_SB_MVAL(VERSIONNUM)
267#define XFS_SB_UQUOTINO XFS_SB_MVAL(UQUOTINO)
268#define XFS_SB_GQUOTINO XFS_SB_MVAL(GQUOTINO)
269#define XFS_SB_QFLAGS XFS_SB_MVAL(QFLAGS)
270#define XFS_SB_SHARED_VN XFS_SB_MVAL(SHARED_VN)
271#define XFS_SB_UNIT XFS_SB_MVAL(UNIT)
272#define XFS_SB_WIDTH XFS_SB_MVAL(WIDTH)
David Chinner92821e22007-05-24 15:26:31 +1000273#define XFS_SB_ICOUNT XFS_SB_MVAL(ICOUNT)
274#define XFS_SB_IFREE XFS_SB_MVAL(IFREE)
275#define XFS_SB_FDBLOCKS XFS_SB_MVAL(FDBLOCKS)
Nathan Scottd8cc8902005-11-02 10:34:53 +1100276#define XFS_SB_FEATURES2 XFS_SB_MVAL(FEATURES2)
David Chinneree1c0902008-03-06 13:45:50 +1100277#define XFS_SB_BAD_FEATURES2 XFS_SB_MVAL(BAD_FEATURES2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278#define XFS_SB_NUM_BITS ((int)XFS_SBS_FIELDCOUNT)
279#define XFS_SB_ALL_BITS ((1LL << XFS_SB_NUM_BITS) - 1)
280#define XFS_SB_MOD_BITS \
281 (XFS_SB_UUID | XFS_SB_ROOTINO | XFS_SB_RBMINO | XFS_SB_RSUMINO | \
282 XFS_SB_VERSIONNUM | XFS_SB_UQUOTINO | XFS_SB_GQUOTINO | \
Nathan Scottd8cc8902005-11-02 10:34:53 +1100283 XFS_SB_QFLAGS | XFS_SB_SHARED_VN | XFS_SB_UNIT | XFS_SB_WIDTH | \
David Chinneree1c0902008-03-06 13:45:50 +1100284 XFS_SB_ICOUNT | XFS_SB_IFREE | XFS_SB_FDBLOCKS | XFS_SB_FEATURES2 | \
285 XFS_SB_BAD_FEATURES2)
Nathan Scottd8cc8902005-11-02 10:34:53 +1100286
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287
288/*
289 * Misc. Flags - warning - these will be cleared by xfs_repair unless
290 * a feature bit is set when the flag is used.
291 */
292#define XFS_SBF_NOFLAGS 0x00 /* no flags set */
293#define XFS_SBF_READONLY 0x01 /* only read-only mounts allowed */
294
295/*
296 * define max. shared version we can interoperate with
297 */
298#define XFS_SB_MAX_SHARED_VN 0
299
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300#define XFS_SB_VERSION_NUM(sbp) ((sbp)->sb_versionnum & XFS_SB_VERSION_NUMBITS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301
Christoph Hellwig5efcbb82008-12-03 12:20:31 +0100302static inline int xfs_sb_good_version(xfs_sb_t *sbp)
303{
304 /* We always support version 1-3 */
305 if (sbp->sb_versionnum >= XFS_SB_VERSION_1 &&
306 sbp->sb_versionnum <= XFS_SB_VERSION_3)
307 return 1;
308
309 /* We support version 4 if all feature bits are supported */
310 if (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) {
311 if ((sbp->sb_versionnum & ~XFS_SB_VERSION_OKREALBITS) ||
312 ((sbp->sb_versionnum & XFS_SB_VERSION_MOREBITSBIT) &&
313 (sbp->sb_features2 & ~XFS_SB_VERSION2_OKREALBITS)))
314 return 0;
315
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316#ifdef __KERNEL__
Christoph Hellwig5efcbb82008-12-03 12:20:31 +0100317 if (sbp->sb_shared_vn > XFS_SB_MAX_SHARED_VN)
318 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319#else
Christoph Hellwig5efcbb82008-12-03 12:20:31 +0100320 if ((sbp->sb_versionnum & XFS_SB_VERSION_SHAREDBIT) &&
321 sbp->sb_shared_vn > XFS_SB_MAX_SHARED_VN)
322 return 0;
323#endif
324
325 return 1;
326 }
327
328 return 0;
Nathan Scotta844f452005-11-02 14:38:42 +1100329}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330
David Chinneree1c0902008-03-06 13:45:50 +1100331/*
Eric Sandeene6957ea2008-04-10 12:19:34 +1000332 * Detect a mismatched features2 field. Older kernels read/wrote
333 * this into the wrong slot, so to be safe we keep them in sync.
David Chinneree1c0902008-03-06 13:45:50 +1100334 */
Eric Sandeene6957ea2008-04-10 12:19:34 +1000335static inline int xfs_sb_has_mismatched_features2(xfs_sb_t *sbp)
David Chinneree1c0902008-03-06 13:45:50 +1100336{
Eric Sandeene6957ea2008-04-10 12:19:34 +1000337 return (sbp->sb_bad_features2 != sbp->sb_features2);
David Chinneree1c0902008-03-06 13:45:50 +1100338}
339
Nathan Scotta844f452005-11-02 14:38:42 +1100340static inline unsigned xfs_sb_version_tonew(unsigned v)
341{
Christoph Hellwig5efcbb82008-12-03 12:20:31 +0100342 if (v == XFS_SB_VERSION_1)
343 return XFS_SB_VERSION_4;
344
345 if (v == XFS_SB_VERSION_2)
346 return XFS_SB_VERSION_4 | XFS_SB_VERSION_ATTRBIT;
347
348 return XFS_SB_VERSION_4 | XFS_SB_VERSION_ATTRBIT |
349 XFS_SB_VERSION_NLINKBIT;
Nathan Scotta844f452005-11-02 14:38:42 +1100350}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351
Nathan Scotta844f452005-11-02 14:38:42 +1100352static inline unsigned xfs_sb_version_toold(unsigned v)
353{
Christoph Hellwig5efcbb82008-12-03 12:20:31 +0100354 if (v & (XFS_SB_VERSION_QUOTABIT | XFS_SB_VERSION_ALIGNBIT))
355 return 0;
356 if (v & XFS_SB_VERSION_NLINKBIT)
357 return XFS_SB_VERSION_3;
358 if (v & XFS_SB_VERSION_ATTRBIT)
359 return XFS_SB_VERSION_2;
360 return XFS_SB_VERSION_1;
Nathan Scotta844f452005-11-02 14:38:42 +1100361}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362
Nathan Scotta844f452005-11-02 14:38:42 +1100363static inline int xfs_sb_version_hasattr(xfs_sb_t *sbp)
364{
Christoph Hellwig5efcbb82008-12-03 12:20:31 +0100365 return sbp->sb_versionnum == XFS_SB_VERSION_2 ||
366 sbp->sb_versionnum == XFS_SB_VERSION_3 ||
367 (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 &&
368 (sbp->sb_versionnum & XFS_SB_VERSION_ATTRBIT));
Nathan Scotta844f452005-11-02 14:38:42 +1100369}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370
Nathan Scotta844f452005-11-02 14:38:42 +1100371static inline void xfs_sb_version_addattr(xfs_sb_t *sbp)
372{
Christoph Hellwig5efcbb82008-12-03 12:20:31 +0100373 if (sbp->sb_versionnum == XFS_SB_VERSION_1)
374 sbp->sb_versionnum = XFS_SB_VERSION_2;
375 else if (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4)
376 sbp->sb_versionnum |= XFS_SB_VERSION_ATTRBIT;
377 else
378 sbp->sb_versionnum = XFS_SB_VERSION_4 | XFS_SB_VERSION_ATTRBIT;
Nathan Scotta844f452005-11-02 14:38:42 +1100379}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380
Nathan Scotta844f452005-11-02 14:38:42 +1100381static inline int xfs_sb_version_hasnlink(xfs_sb_t *sbp)
382{
Christoph Hellwig5efcbb82008-12-03 12:20:31 +0100383 return sbp->sb_versionnum == XFS_SB_VERSION_3 ||
384 (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 &&
385 (sbp->sb_versionnum & XFS_SB_VERSION_NLINKBIT));
Nathan Scotta844f452005-11-02 14:38:42 +1100386}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387
Nathan Scotta844f452005-11-02 14:38:42 +1100388static inline void xfs_sb_version_addnlink(xfs_sb_t *sbp)
389{
Christoph Hellwig5efcbb82008-12-03 12:20:31 +0100390 if (sbp->sb_versionnum <= XFS_SB_VERSION_2)
391 sbp->sb_versionnum = XFS_SB_VERSION_3;
392 else
393 sbp->sb_versionnum |= XFS_SB_VERSION_NLINKBIT;
Nathan Scotta844f452005-11-02 14:38:42 +1100394}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395
Nathan Scotta844f452005-11-02 14:38:42 +1100396static inline int xfs_sb_version_hasquota(xfs_sb_t *sbp)
397{
Christoph Hellwig5efcbb82008-12-03 12:20:31 +0100398 return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 &&
399 (sbp->sb_versionnum & XFS_SB_VERSION_QUOTABIT);
Nathan Scotta844f452005-11-02 14:38:42 +1100400}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401
Nathan Scotta844f452005-11-02 14:38:42 +1100402static inline void xfs_sb_version_addquota(xfs_sb_t *sbp)
403{
Christoph Hellwig5efcbb82008-12-03 12:20:31 +0100404 if (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4)
405 sbp->sb_versionnum |= XFS_SB_VERSION_QUOTABIT;
406 else
407 sbp->sb_versionnum = xfs_sb_version_tonew(sbp->sb_versionnum) |
408 XFS_SB_VERSION_QUOTABIT;
Nathan Scotta844f452005-11-02 14:38:42 +1100409}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410
Nathan Scotta844f452005-11-02 14:38:42 +1100411static inline int xfs_sb_version_hasalign(xfs_sb_t *sbp)
412{
Christoph Hellwig5efcbb82008-12-03 12:20:31 +0100413 return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 &&
414 (sbp->sb_versionnum & XFS_SB_VERSION_ALIGNBIT);
Nathan Scotta844f452005-11-02 14:38:42 +1100415}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416
Nathan Scotta844f452005-11-02 14:38:42 +1100417static inline int xfs_sb_version_hasdalign(xfs_sb_t *sbp)
418{
Christoph Hellwig5efcbb82008-12-03 12:20:31 +0100419 return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 &&
420 (sbp->sb_versionnum & XFS_SB_VERSION_DALIGNBIT);
Nathan Scotta844f452005-11-02 14:38:42 +1100421}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
Nathan Scotta844f452005-11-02 14:38:42 +1100423static inline int xfs_sb_version_hasshared(xfs_sb_t *sbp)
424{
Christoph Hellwig5efcbb82008-12-03 12:20:31 +0100425 return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 &&
426 (sbp->sb_versionnum & XFS_SB_VERSION_SHAREDBIT);
Nathan Scotta844f452005-11-02 14:38:42 +1100427}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428
Nathan Scotta844f452005-11-02 14:38:42 +1100429static inline int xfs_sb_version_hasdirv2(xfs_sb_t *sbp)
430{
Christoph Hellwig5efcbb82008-12-03 12:20:31 +0100431 return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 &&
432 (sbp->sb_versionnum & XFS_SB_VERSION_DIRV2BIT);
Nathan Scotta844f452005-11-02 14:38:42 +1100433}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434
Nathan Scotta844f452005-11-02 14:38:42 +1100435static inline int xfs_sb_version_haslogv2(xfs_sb_t *sbp)
436{
Christoph Hellwig5efcbb82008-12-03 12:20:31 +0100437 return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 &&
438 (sbp->sb_versionnum & XFS_SB_VERSION_LOGV2BIT);
Nathan Scotta844f452005-11-02 14:38:42 +1100439}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440
Nathan Scotta844f452005-11-02 14:38:42 +1100441static inline int xfs_sb_version_hasextflgbit(xfs_sb_t *sbp)
442{
Christoph Hellwig5efcbb82008-12-03 12:20:31 +0100443 return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 &&
444 (sbp->sb_versionnum & XFS_SB_VERSION_EXTFLGBIT);
Nathan Scotta844f452005-11-02 14:38:42 +1100445}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446
Nathan Scotta844f452005-11-02 14:38:42 +1100447static inline int xfs_sb_version_hassector(xfs_sb_t *sbp)
448{
Christoph Hellwig5efcbb82008-12-03 12:20:31 +0100449 return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 &&
450 (sbp->sb_versionnum & XFS_SB_VERSION_SECTORBIT);
Nathan Scotta844f452005-11-02 14:38:42 +1100451}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452
Barry Naujok189f4bf2008-05-21 16:58:55 +1000453static inline int xfs_sb_version_hasasciici(xfs_sb_t *sbp)
454{
Christoph Hellwig5efcbb82008-12-03 12:20:31 +0100455 return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 &&
Barry Naujok189f4bf2008-05-21 16:58:55 +1000456 (sbp->sb_versionnum & XFS_SB_VERSION_BORGBIT);
457}
458
Nathan Scotta844f452005-11-02 14:38:42 +1100459static inline int xfs_sb_version_hasmorebits(xfs_sb_t *sbp)
460{
Christoph Hellwig5efcbb82008-12-03 12:20:31 +0100461 return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 &&
462 (sbp->sb_versionnum & XFS_SB_VERSION_MOREBITSBIT);
Nathan Scotta844f452005-11-02 14:38:42 +1100463}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464
465/*
466 * sb_features2 bit version macros.
467 *
Nathan Scottd8cc8902005-11-02 10:34:53 +1100468 * For example, for a bit defined as XFS_SB_VERSION2_FUNBIT, has a macro:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 *
Nathan Scottd8cc8902005-11-02 10:34:53 +1100470 * SB_VERSION_HASFUNBIT(xfs_sb_t *sbp)
Eric Sandeen62118702008-03-06 13:44:28 +1100471 * ((xfs_sb_version_hasmorebits(sbp) &&
Nathan Scottd8cc8902005-11-02 10:34:53 +1100472 * ((sbp)->sb_features2 & XFS_SB_VERSION2_FUNBIT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 */
474
David Chinner92821e22007-05-24 15:26:31 +1000475static inline int xfs_sb_version_haslazysbcount(xfs_sb_t *sbp)
476{
Christoph Hellwig5efcbb82008-12-03 12:20:31 +0100477 return xfs_sb_version_hasmorebits(sbp) &&
478 (sbp->sb_features2 & XFS_SB_VERSION2_LAZYSBCOUNTBIT);
David Chinner92821e22007-05-24 15:26:31 +1000479}
480
Nathan Scotta844f452005-11-02 14:38:42 +1100481static inline int xfs_sb_version_hasattr2(xfs_sb_t *sbp)
482{
Christoph Hellwig5efcbb82008-12-03 12:20:31 +0100483 return xfs_sb_version_hasmorebits(sbp) &&
484 (sbp->sb_features2 & XFS_SB_VERSION2_ATTR2BIT);
Nathan Scotta844f452005-11-02 14:38:42 +1100485}
486
Nathan Scotta844f452005-11-02 14:38:42 +1100487static inline void xfs_sb_version_addattr2(xfs_sb_t *sbp)
488{
Christoph Hellwig5efcbb82008-12-03 12:20:31 +0100489 sbp->sb_versionnum |= XFS_SB_VERSION_MOREBITSBIT;
490 sbp->sb_features2 |= XFS_SB_VERSION2_ATTR2BIT;
Nathan Scotta844f452005-11-02 14:38:42 +1100491}
492
Tim Shimmin7c12f292008-04-30 18:15:28 +1000493static inline void xfs_sb_version_removeattr2(xfs_sb_t *sbp)
494{
495 sbp->sb_features2 &= ~XFS_SB_VERSION2_ATTR2BIT;
496 if (!sbp->sb_features2)
497 sbp->sb_versionnum &= ~XFS_SB_VERSION_MOREBITSBIT;
498}
499
Arkadiusz Mi?kiewicz67430992010-09-26 06:10:18 +0000500static inline int xfs_sb_version_hasprojid32bit(xfs_sb_t *sbp)
501{
502 return xfs_sb_version_hasmorebits(sbp) &&
503 (sbp->sb_features2 & XFS_SB_VERSION2_PROJID32BIT);
504}
505
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506/*
507 * end of superblock version macros
508 */
509
Nathan Scotta844f452005-11-02 14:38:42 +1100510#define XFS_SB_DADDR ((xfs_daddr_t)0) /* daddr in filesystem/ag */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511#define XFS_SB_BLOCK(mp) XFS_HDR_BLOCK(mp, XFS_SB_DADDR)
Chandra Seetharaman62926042011-07-22 23:40:15 +0000512#define XFS_BUF_TO_SBP(bp) ((xfs_dsb_t *)((bp)->b_addr))
Nathan Scotta844f452005-11-02 14:38:42 +1100513
514#define XFS_HDR_BLOCK(mp,d) ((xfs_agblock_t)XFS_BB_TO_FSBT(mp,d))
515#define XFS_DADDR_TO_FSB(mp,d) XFS_AGB_TO_FSB(mp, \
Eric Sandeenb6e32222009-01-14 23:22:07 -0600516 xfs_daddr_to_agno(mp,d), xfs_daddr_to_agbno(mp,d))
Nathan Scotta844f452005-11-02 14:38:42 +1100517#define XFS_FSB_TO_DADDR(mp,fsbno) XFS_AGB_TO_DADDR(mp, \
518 XFS_FSB_TO_AGNO(mp,fsbno), XFS_FSB_TO_AGBNO(mp,fsbno))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519
520/*
521 * File system sector to basic block conversions.
522 */
523#define XFS_FSS_TO_BB(mp,sec) ((sec) << (mp)->m_sectbb_log)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524
525/*
526 * File system block to basic block conversions.
527 */
528#define XFS_FSB_TO_BB(mp,fsbno) ((fsbno) << (mp)->m_blkbb_log)
529#define XFS_BB_TO_FSB(mp,bb) \
530 (((bb) + (XFS_FSB_TO_BB(mp,1) - 1)) >> (mp)->m_blkbb_log)
531#define XFS_BB_TO_FSBT(mp,bb) ((bb) >> (mp)->m_blkbb_log)
532#define XFS_BB_FSB_OFFSET(mp,bb) ((bb) & ((mp)->m_bsize - 1))
533
534/*
535 * File system block to byte conversions.
536 */
537#define XFS_FSB_TO_B(mp,fsbno) ((xfs_fsize_t)(fsbno) << (mp)->m_sb.sb_blocklog)
538#define XFS_B_TO_FSB(mp,b) \
539 ((((__uint64_t)(b)) + (mp)->m_blockmask) >> (mp)->m_sb.sb_blocklog)
540#define XFS_B_TO_FSBT(mp,b) (((__uint64_t)(b)) >> (mp)->m_sb.sb_blocklog)
541#define XFS_B_FSB_OFFSET(mp,b) ((b) & (mp)->m_blockmask)
542
543#endif /* __XFS_SB_H__ */