Home | History | Annotate | Download | only in extlinux
      1 /*
      2  * Taken from Linux kernel tree (linux/fs/xfs)
      3  *
      4  * Copyright (c) 2000-2005 Silicon Graphics, Inc.
      5  * All Rights Reserved.
      6  *
      7  * Copyright (c) 2012 Paulo Alcantara <pcacjr (at) zytor.com>
      8  *
      9  * This program is free software; you can redistribute it and/or
     10  * modify it under the terms of the GNU General Public License as
     11  * published by the Free Software Foundation.
     12  *
     13  * This program is distributed in the hope that it would be useful,
     14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16  * GNU General Public License for more details.
     17  *
     18  * You should have received a copy of the GNU General Public License
     19  * along with this program; if not, write the Free Software Foundation,
     20  * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
     21  */
     22 #ifndef XFS_SB_H_
     23 #define	XFS_SB_H__
     24 
     25 #include <stddef.h>
     26 
     27 #include <sys/types.h>
     28 #include <uuid/uuid.h>
     29 
     30 /*
     31  * Super block
     32  * Fits into a sector-sized buffer at address 0 of each allocation group.
     33  * Only the first of these is ever updated except during growfs.
     34  */
     35 
     36 struct xfs_buf;
     37 struct xfs_mount;
     38 
     39 #define	XFS_SB_MAGIC		"XFSB"		/* 'XFSB' */
     40 #define	XFS_SB_VERSION_1	1		/* 5.3, 6.0.1, 6.1 */
     41 #define	XFS_SB_VERSION_2	2		/* 6.2 - attributes */
     42 #define	XFS_SB_VERSION_3	3		/* 6.2 - new inode version */
     43 #define	XFS_SB_VERSION_4	4		/* 6.2+ - bitmask version */
     44 #define	XFS_SB_VERSION_NUMBITS		0x000f
     45 #define	XFS_SB_VERSION_ALLFBITS		0xfff0
     46 #define	XFS_SB_VERSION_SASHFBITS	0xf000
     47 #define	XFS_SB_VERSION_REALFBITS	0x0ff0
     48 #define	XFS_SB_VERSION_ATTRBIT		0x0010
     49 #define	XFS_SB_VERSION_NLINKBIT		0x0020
     50 #define	XFS_SB_VERSION_QUOTABIT		0x0040
     51 #define	XFS_SB_VERSION_ALIGNBIT		0x0080
     52 #define	XFS_SB_VERSION_DALIGNBIT	0x0100
     53 #define	XFS_SB_VERSION_SHAREDBIT	0x0200
     54 #define XFS_SB_VERSION_LOGV2BIT		0x0400
     55 #define XFS_SB_VERSION_SECTORBIT	0x0800
     56 #define	XFS_SB_VERSION_EXTFLGBIT	0x1000
     57 #define	XFS_SB_VERSION_DIRV2BIT		0x2000
     58 #define	XFS_SB_VERSION_BORGBIT		0x4000	/* ASCII only case-insens. */
     59 #define	XFS_SB_VERSION_MOREBITSBIT	0x8000
     60 #define	XFS_SB_VERSION_OKSASHFBITS	\
     61 	(XFS_SB_VERSION_EXTFLGBIT | \
     62 	 XFS_SB_VERSION_DIRV2BIT | \
     63 	 XFS_SB_VERSION_BORGBIT)
     64 #define	XFS_SB_VERSION_OKREALFBITS	\
     65 	(XFS_SB_VERSION_ATTRBIT | \
     66 	 XFS_SB_VERSION_NLINKBIT | \
     67 	 XFS_SB_VERSION_QUOTABIT | \
     68 	 XFS_SB_VERSION_ALIGNBIT | \
     69 	 XFS_SB_VERSION_DALIGNBIT | \
     70 	 XFS_SB_VERSION_SHAREDBIT | \
     71 	 XFS_SB_VERSION_LOGV2BIT | \
     72 	 XFS_SB_VERSION_SECTORBIT | \
     73 	 XFS_SB_VERSION_MOREBITSBIT)
     74 #define	XFS_SB_VERSION_OKREALBITS	\
     75 	(XFS_SB_VERSION_NUMBITS | \
     76 	 XFS_SB_VERSION_OKREALFBITS | \
     77 	 XFS_SB_VERSION_OKSASHFBITS)
     78 
     79 /*
     80  * There are two words to hold XFS "feature" bits: the original
     81  * word, sb_versionnum, and sb_features2.  Whenever a bit is set in
     82  * sb_features2, the feature bit XFS_SB_VERSION_MOREBITSBIT must be set.
     83  *
     84  * These defines represent bits in sb_features2.
     85  */
     86 #define XFS_SB_VERSION2_REALFBITS	0x00ffffff	/* Mask: features */
     87 #define XFS_SB_VERSION2_RESERVED1BIT	0x00000001
     88 #define XFS_SB_VERSION2_LAZYSBCOUNTBIT	0x00000002	/* Superblk counters */
     89 #define XFS_SB_VERSION2_RESERVED4BIT	0x00000004
     90 #define XFS_SB_VERSION2_ATTR2BIT	0x00000008	/* Inline attr rework */
     91 #define XFS_SB_VERSION2_PARENTBIT	0x00000010	/* parent pointers */
     92 #define XFS_SB_VERSION2_PROJID32BIT	0x00000080	/* 32 bit project id */
     93 
     94 #define	XFS_SB_VERSION2_OKREALFBITS	\
     95 	(XFS_SB_VERSION2_LAZYSBCOUNTBIT	| \
     96 	 XFS_SB_VERSION2_ATTR2BIT	| \
     97 	 XFS_SB_VERSION2_PROJID32BIT)
     98 #define	XFS_SB_VERSION2_OKSASHFBITS	\
     99 	(0)
    100 #define XFS_SB_VERSION2_OKREALBITS	\
    101 	(XFS_SB_VERSION2_OKREALFBITS |	\
    102 	 XFS_SB_VERSION2_OKSASHFBITS )
    103 
    104 /*
    105  * Superblock - in core version.  Must match the ondisk version below.
    106  * Must be padded to 64 bit alignment.
    107  */
    108 typedef struct xfs_sb {
    109 	uint32_t	sb_magicnum;	/* magic number == XFS_SB_MAGIC */
    110 	uint32_t	sb_blocksize;	/* logical block size, bytes */
    111 	xfs_drfsbno_t	sb_dblocks;	/* number of data blocks */
    112 	xfs_drfsbno_t	sb_rblocks;	/* number of realtime blocks */
    113 	xfs_drtbno_t	sb_rextents;	/* number of realtime extents */
    114 	uuid_t		sb_uuid;	/* file system unique id */
    115 	xfs_dfsbno_t	sb_logstart;	/* starting block of log if internal */
    116 	xfs_ino_t	sb_rootino;	/* root inode number */
    117 	xfs_ino_t	sb_rbmino;	/* bitmap inode for realtime extents */
    118 	xfs_ino_t	sb_rsumino;	/* summary inode for rt bitmap */
    119 	xfs_agblock_t	sb_rextsize;	/* realtime extent size, blocks */
    120 	xfs_agblock_t	sb_agblocks;	/* size of an allocation group */
    121 	xfs_agnumber_t	sb_agcount;	/* number of allocation groups */
    122 	xfs_extlen_t	sb_rbmblocks;	/* number of rt bitmap blocks */
    123 	xfs_extlen_t	sb_logblocks;	/* number of log blocks */
    124 	uint16_t	sb_versionnum;	/* header version == XFS_SB_VERSION */
    125 	uint16_t	sb_sectsize;	/* volume sector size, bytes */
    126 	uint16_t	sb_inodesize;	/* inode size, bytes */
    127 	uint16_t	sb_inopblock;	/* inodes per block */
    128 	char		sb_fname[12];	/* file system name */
    129 	uint8_t	sb_blocklog;	/* log2 of sb_blocksize */
    130 	uint8_t	sb_sectlog;	/* log2 of sb_sectsize */
    131 	uint8_t	sb_inodelog;	/* log2 of sb_inodesize */
    132 	uint8_t	sb_inopblog;	/* log2 of sb_inopblock */
    133 	uint8_t	sb_agblklog;	/* log2 of sb_agblocks (rounded up) */
    134 	uint8_t	sb_rextslog;	/* log2 of sb_rextents */
    135 	uint8_t	sb_inprogress;	/* mkfs is in progress, don't mount */
    136 	uint8_t	sb_imax_pct;	/* max % of fs for inode space */
    137 					/* statistics */
    138 	/*
    139 	 * These fields must remain contiguous.  If you really
    140 	 * want to change their layout, make sure you fix the
    141 	 * code in xfs_trans_apply_sb_deltas().
    142 	 */
    143 	uint64_t	sb_icount;	/* allocated inodes */
    144 	uint64_t	sb_ifree;	/* free inodes */
    145 	uint64_t	sb_fdblocks;	/* free data blocks */
    146 	uint64_t	sb_frextents;	/* free realtime extents */
    147 	/*
    148 	 * End contiguous fields.
    149 	 */
    150 	xfs_ino_t	sb_uquotino;	/* user quota inode */
    151 	xfs_ino_t	sb_gquotino;	/* group quota inode */
    152 	uint16_t	sb_qflags;	/* quota flags */
    153 	uint8_t	sb_flags;	/* misc. flags */
    154 	uint8_t	sb_shared_vn;	/* shared version number */
    155 	xfs_extlen_t	sb_inoalignmt;	/* inode chunk alignment, fsblocks */
    156 	uint32_t	sb_unit;	/* stripe or raid unit */
    157 	uint32_t	sb_width;	/* stripe or raid width */
    158 	uint8_t	sb_dirblklog;	/* log2 of dir block size (fsbs) */
    159 	uint8_t	sb_logsectlog;	/* log2 of the log sector size */
    160 	uint16_t	sb_logsectsize;	/* sector size for the log, bytes */
    161 	uint32_t	sb_logsunit;	/* stripe unit size for the log */
    162 	uint32_t	sb_features2;	/* additional feature bits */
    163 
    164 	/*
    165 	 * bad features2 field as a result of failing to pad the sb
    166 	 * structure to 64 bits. Some machines will be using this field
    167 	 * for features2 bits. Easiest just to mark it bad and not use
    168 	 * it for anything else.
    169 	 */
    170 	uint32_t	sb_bad_features2;
    171 
    172 	/* must be padded to 64 bit alignment */
    173 } xfs_sb_t;
    174 
    175 /*
    176  * Sequence number values for the fields.
    177  */
    178 typedef enum {
    179 	XFS_SBS_MAGICNUM, XFS_SBS_BLOCKSIZE, XFS_SBS_DBLOCKS, XFS_SBS_RBLOCKS,
    180 	XFS_SBS_REXTENTS, XFS_SBS_UUID, XFS_SBS_LOGSTART, XFS_SBS_ROOTINO,
    181 	XFS_SBS_RBMINO, XFS_SBS_RSUMINO, XFS_SBS_REXTSIZE, XFS_SBS_AGBLOCKS,
    182 	XFS_SBS_AGCOUNT, XFS_SBS_RBMBLOCKS, XFS_SBS_LOGBLOCKS,
    183 	XFS_SBS_VERSIONNUM, XFS_SBS_SECTSIZE, XFS_SBS_INODESIZE,
    184 	XFS_SBS_INOPBLOCK, XFS_SBS_FNAME, XFS_SBS_BLOCKLOG,
    185 	XFS_SBS_SECTLOG, XFS_SBS_INODELOG, XFS_SBS_INOPBLOG, XFS_SBS_AGBLKLOG,
    186 	XFS_SBS_REXTSLOG, XFS_SBS_INPROGRESS, XFS_SBS_IMAX_PCT, XFS_SBS_ICOUNT,
    187 	XFS_SBS_IFREE, XFS_SBS_FDBLOCKS, XFS_SBS_FREXTENTS, XFS_SBS_UQUOTINO,
    188 	XFS_SBS_GQUOTINO, XFS_SBS_QFLAGS, XFS_SBS_FLAGS, XFS_SBS_SHARED_VN,
    189 	XFS_SBS_INOALIGNMT, XFS_SBS_UNIT, XFS_SBS_WIDTH, XFS_SBS_DIRBLKLOG,
    190 	XFS_SBS_LOGSECTLOG, XFS_SBS_LOGSECTSIZE, XFS_SBS_LOGSUNIT,
    191 	XFS_SBS_FEATURES2, XFS_SBS_BAD_FEATURES2,
    192 	XFS_SBS_FIELDCOUNT
    193 } xfs_sb_field_t;
    194 
    195 /*
    196  * Mask values, defined based on the xfs_sb_field_t values.
    197  * Only define the ones we're using.
    198  */
    199 #define	XFS_SB_MVAL(x)		(1LL << XFS_SBS_ ## x)
    200 #define	XFS_SB_UUID		XFS_SB_MVAL(UUID)
    201 #define	XFS_SB_FNAME		XFS_SB_MVAL(FNAME)
    202 #define	XFS_SB_ROOTINO		XFS_SB_MVAL(ROOTINO)
    203 #define	XFS_SB_RBMINO		XFS_SB_MVAL(RBMINO)
    204 #define	XFS_SB_RSUMINO		XFS_SB_MVAL(RSUMINO)
    205 #define	XFS_SB_VERSIONNUM	XFS_SB_MVAL(VERSIONNUM)
    206 #define XFS_SB_UQUOTINO		XFS_SB_MVAL(UQUOTINO)
    207 #define XFS_SB_GQUOTINO		XFS_SB_MVAL(GQUOTINO)
    208 #define XFS_SB_QFLAGS		XFS_SB_MVAL(QFLAGS)
    209 #define XFS_SB_SHARED_VN	XFS_SB_MVAL(SHARED_VN)
    210 #define XFS_SB_UNIT		XFS_SB_MVAL(UNIT)
    211 #define XFS_SB_WIDTH		XFS_SB_MVAL(WIDTH)
    212 #define XFS_SB_ICOUNT		XFS_SB_MVAL(ICOUNT)
    213 #define XFS_SB_IFREE		XFS_SB_MVAL(IFREE)
    214 #define XFS_SB_FDBLOCKS		XFS_SB_MVAL(FDBLOCKS)
    215 #define XFS_SB_FEATURES2	XFS_SB_MVAL(FEATURES2)
    216 #define XFS_SB_BAD_FEATURES2	XFS_SB_MVAL(BAD_FEATURES2)
    217 #define	XFS_SB_NUM_BITS		((int)XFS_SBS_FIELDCOUNT)
    218 #define	XFS_SB_ALL_BITS		((1LL << XFS_SB_NUM_BITS) - 1)
    219 #define	XFS_SB_MOD_BITS		\
    220 	(XFS_SB_UUID | XFS_SB_ROOTINO | XFS_SB_RBMINO | XFS_SB_RSUMINO | \
    221 	 XFS_SB_VERSIONNUM | XFS_SB_UQUOTINO | XFS_SB_GQUOTINO | \
    222 	 XFS_SB_QFLAGS | XFS_SB_SHARED_VN | XFS_SB_UNIT | XFS_SB_WIDTH | \
    223 	 XFS_SB_ICOUNT | XFS_SB_IFREE | XFS_SB_FDBLOCKS | XFS_SB_FEATURES2 | \
    224 	 XFS_SB_BAD_FEATURES2)
    225 
    226 
    227 /*
    228  * Misc. Flags - warning - these will be cleared by xfs_repair unless
    229  * a feature bit is set when the flag is used.
    230  */
    231 #define XFS_SBF_NOFLAGS		0x00	/* no flags set */
    232 #define XFS_SBF_READONLY	0x01	/* only read-only mounts allowed */
    233 
    234 /*
    235  * define max. shared version we can interoperate with
    236  */
    237 #define XFS_SB_MAX_SHARED_VN	0
    238 
    239 #define	XFS_SB_VERSION_NUM(sbp)	((sbp)->sb_versionnum & XFS_SB_VERSION_NUMBITS)
    240 
    241 static inline int xfs_sb_good_version(xfs_sb_t *sbp)
    242 {
    243 	/* We always support version 1-3 */
    244 	if (sbp->sb_versionnum >= XFS_SB_VERSION_1 &&
    245 	    sbp->sb_versionnum <= XFS_SB_VERSION_3)
    246 		return 1;
    247 
    248 	/* We support version 4 if all feature bits are supported */
    249 	if (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) {
    250 		if ((sbp->sb_versionnum & ~XFS_SB_VERSION_OKREALBITS) ||
    251 		    ((sbp->sb_versionnum & XFS_SB_VERSION_MOREBITSBIT) &&
    252 		     (sbp->sb_features2 & ~XFS_SB_VERSION2_OKREALBITS)))
    253 			return 0;
    254 
    255 		if ((sbp->sb_versionnum & XFS_SB_VERSION_SHAREDBIT) &&
    256 		    sbp->sb_shared_vn > XFS_SB_MAX_SHARED_VN)
    257 			return 0;
    258 
    259 		return 1;
    260 	}
    261 
    262 	return 0;
    263 }
    264 
    265 /*
    266  * Detect a mismatched features2 field.  Older kernels read/wrote
    267  * this into the wrong slot, so to be safe we keep them in sync.
    268  */
    269 static inline int xfs_sb_has_mismatched_features2(xfs_sb_t *sbp)
    270 {
    271 	return (sbp->sb_bad_features2 != sbp->sb_features2);
    272 }
    273 
    274 static inline unsigned xfs_sb_version_tonew(unsigned v)
    275 {
    276 	if (v == XFS_SB_VERSION_1)
    277 		return XFS_SB_VERSION_4;
    278 
    279 	if (v == XFS_SB_VERSION_2)
    280 		return XFS_SB_VERSION_4 | XFS_SB_VERSION_ATTRBIT;
    281 
    282 	return XFS_SB_VERSION_4 | XFS_SB_VERSION_ATTRBIT |
    283 		XFS_SB_VERSION_NLINKBIT;
    284 }
    285 
    286 static inline unsigned xfs_sb_version_toold(unsigned v)
    287 {
    288 	if (v & (XFS_SB_VERSION_QUOTABIT | XFS_SB_VERSION_ALIGNBIT))
    289 		return 0;
    290 	if (v & XFS_SB_VERSION_NLINKBIT)
    291 		return XFS_SB_VERSION_3;
    292 	if (v & XFS_SB_VERSION_ATTRBIT)
    293 		return XFS_SB_VERSION_2;
    294 	return XFS_SB_VERSION_1;
    295 }
    296 
    297 static inline int xfs_sb_version_hasattr(xfs_sb_t *sbp)
    298 {
    299 	return sbp->sb_versionnum == XFS_SB_VERSION_2 ||
    300 		sbp->sb_versionnum == XFS_SB_VERSION_3 ||
    301 		(XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 &&
    302 		 (sbp->sb_versionnum & XFS_SB_VERSION_ATTRBIT));
    303 }
    304 
    305 static inline void xfs_sb_version_addattr(xfs_sb_t *sbp)
    306 {
    307 	if (sbp->sb_versionnum == XFS_SB_VERSION_1)
    308 		sbp->sb_versionnum = XFS_SB_VERSION_2;
    309 	else if (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4)
    310 		sbp->sb_versionnum |= XFS_SB_VERSION_ATTRBIT;
    311 	else
    312 		sbp->sb_versionnum = XFS_SB_VERSION_4 | XFS_SB_VERSION_ATTRBIT;
    313 }
    314 
    315 static inline int xfs_sb_version_hasnlink(xfs_sb_t *sbp)
    316 {
    317 	return sbp->sb_versionnum == XFS_SB_VERSION_3 ||
    318 		 (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 &&
    319 		  (sbp->sb_versionnum & XFS_SB_VERSION_NLINKBIT));
    320 }
    321 
    322 static inline void xfs_sb_version_addnlink(xfs_sb_t *sbp)
    323 {
    324 	if (sbp->sb_versionnum <= XFS_SB_VERSION_2)
    325 		sbp->sb_versionnum = XFS_SB_VERSION_3;
    326 	else
    327 		sbp->sb_versionnum |= XFS_SB_VERSION_NLINKBIT;
    328 }
    329 
    330 static inline int xfs_sb_version_hasquota(xfs_sb_t *sbp)
    331 {
    332 	return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 &&
    333 		(sbp->sb_versionnum & XFS_SB_VERSION_QUOTABIT);
    334 }
    335 
    336 static inline void xfs_sb_version_addquota(xfs_sb_t *sbp)
    337 {
    338 	if (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4)
    339 		sbp->sb_versionnum |= XFS_SB_VERSION_QUOTABIT;
    340 	else
    341 		sbp->sb_versionnum = xfs_sb_version_tonew(sbp->sb_versionnum) |
    342 					XFS_SB_VERSION_QUOTABIT;
    343 }
    344 
    345 static inline int xfs_sb_version_hasalign(xfs_sb_t *sbp)
    346 {
    347 	return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 &&
    348 		(sbp->sb_versionnum & XFS_SB_VERSION_ALIGNBIT);
    349 }
    350 
    351 static inline int xfs_sb_version_hasdalign(xfs_sb_t *sbp)
    352 {
    353 	return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 &&
    354 		(sbp->sb_versionnum & XFS_SB_VERSION_DALIGNBIT);
    355 }
    356 
    357 static inline int xfs_sb_version_hasshared(xfs_sb_t *sbp)
    358 {
    359 	return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 &&
    360 		(sbp->sb_versionnum & XFS_SB_VERSION_SHAREDBIT);
    361 }
    362 
    363 static 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 }
    368 
    369 static inline int xfs_sb_version_haslogv2(xfs_sb_t *sbp)
    370 {
    371 	return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 &&
    372 		(sbp->sb_versionnum & XFS_SB_VERSION_LOGV2BIT);
    373 }
    374 
    375 static inline int xfs_sb_version_hasextflgbit(xfs_sb_t *sbp)
    376 {
    377 	return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 &&
    378 		(sbp->sb_versionnum & XFS_SB_VERSION_EXTFLGBIT);
    379 }
    380 
    381 static inline int xfs_sb_version_hassector(xfs_sb_t *sbp)
    382 {
    383 	return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 &&
    384 		(sbp->sb_versionnum & XFS_SB_VERSION_SECTORBIT);
    385 }
    386 
    387 static inline int xfs_sb_version_hasasciici(xfs_sb_t *sbp)
    388 {
    389 	return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 &&
    390 		(sbp->sb_versionnum & XFS_SB_VERSION_BORGBIT);
    391 }
    392 
    393 static inline int xfs_sb_version_hasmorebits(xfs_sb_t *sbp)
    394 {
    395 	return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 &&
    396 		(sbp->sb_versionnum & XFS_SB_VERSION_MOREBITSBIT);
    397 }
    398 
    399 /*
    400  * sb_features2 bit version macros.
    401  *
    402  * For example, for a bit defined as XFS_SB_VERSION2_FUNBIT, has a macro:
    403  *
    404  * SB_VERSION_HASFUNBIT(xfs_sb_t *sbp)
    405  *	((xfs_sb_version_hasmorebits(sbp) &&
    406  *	 ((sbp)->sb_features2 & XFS_SB_VERSION2_FUNBIT)
    407  */
    408 
    409 static inline int xfs_sb_version_haslazysbcount(xfs_sb_t *sbp)
    410 {
    411 	return xfs_sb_version_hasmorebits(sbp) &&
    412 		(sbp->sb_features2 & XFS_SB_VERSION2_LAZYSBCOUNTBIT);
    413 }
    414 
    415 static inline int xfs_sb_version_hasattr2(xfs_sb_t *sbp)
    416 {
    417 	return xfs_sb_version_hasmorebits(sbp) &&
    418 		(sbp->sb_features2 & XFS_SB_VERSION2_ATTR2BIT);
    419 }
    420 
    421 static inline void xfs_sb_version_addattr2(xfs_sb_t *sbp)
    422 {
    423 	sbp->sb_versionnum |= XFS_SB_VERSION_MOREBITSBIT;
    424 	sbp->sb_features2 |= XFS_SB_VERSION2_ATTR2BIT;
    425 }
    426 
    427 static inline void xfs_sb_version_removeattr2(xfs_sb_t *sbp)
    428 {
    429 	sbp->sb_features2 &= ~XFS_SB_VERSION2_ATTR2BIT;
    430 	if (!sbp->sb_features2)
    431 		sbp->sb_versionnum &= ~XFS_SB_VERSION_MOREBITSBIT;
    432 }
    433 
    434 static inline int xfs_sb_version_hasprojid32bit(xfs_sb_t *sbp)
    435 {
    436 	return xfs_sb_version_hasmorebits(sbp) &&
    437 		(sbp->sb_features2 & XFS_SB_VERSION2_PROJID32BIT);
    438 }
    439 
    440 /*
    441  * end of superblock version macros
    442  */
    443 
    444 #define XFS_SB_DADDR		((xfs_daddr_t)0) /* daddr in filesystem/ag */
    445 #define	XFS_SB_BLOCK(mp)	XFS_HDR_BLOCK(mp, XFS_SB_DADDR)
    446 #define XFS_BUF_TO_SBP(bp)	((xfs_dsb_t *)((bp)->b_addr))
    447 
    448 #define	XFS_HDR_BLOCK(mp,d)	((xfs_agblock_t)XFS_BB_TO_FSBT(mp,d))
    449 #define	XFS_DADDR_TO_FSB(mp,d)	XFS_AGB_TO_FSB(mp, \
    450 			xfs_daddr_to_agno(mp,d), xfs_daddr_to_agbno(mp,d))
    451 #define	XFS_FSB_TO_DADDR(mp,fsbno)	XFS_AGB_TO_DADDR(mp, \
    452 			XFS_FSB_TO_AGNO(mp,fsbno), XFS_FSB_TO_AGBNO(mp,fsbno))
    453 
    454 /*
    455  * File system sector to basic block conversions.
    456  */
    457 #define XFS_FSS_TO_BB(mp,sec)	((sec) << (mp)->m_sectbb_log)
    458 
    459 /*
    460  * File system block to basic block conversions.
    461  */
    462 #define	XFS_FSB_TO_BB(mp,fsbno)	((fsbno) << (mp)->m_blkbb_log)
    463 #define	XFS_BB_TO_FSB(mp,bb)	\
    464 	(((bb) + (XFS_FSB_TO_BB(mp,1) - 1)) >> (mp)->m_blkbb_log)
    465 #define	XFS_BB_TO_FSBT(mp,bb)	((bb) >> (mp)->m_blkbb_log)
    466 
    467 /*
    468  * File system block to byte conversions.
    469  */
    470 #define XFS_FSB_TO_B(mp,fsbno)	((xfs_fsize_t)(fsbno) << (mp)->m_sb.sb_blocklog)
    471 #define XFS_B_TO_FSB(mp,b)	\
    472 	((((uint64_t)(b)) + (mp)->m_blockmask) >> (mp)->m_sb.sb_blocklog)
    473 #define XFS_B_TO_FSBT(mp,b)	(((uint64_t)(b)) >> (mp)->m_sb.sb_blocklog)
    474 #define XFS_B_FSB_OFFSET(mp,b)	((b) & (mp)->m_blockmask)
    475 
    476 #endif	/* XFS_SB_H_ */
    477