diff --git a/fs/xfs/libxfs/xfs_attr_leaf.c b/fs/xfs/libxfs/xfs_attr_leaf.c index 02ca50442b46..6068fad9dc9e 100644 --- a/fs/xfs/libxfs/xfs_attr_leaf.c +++ b/fs/xfs/libxfs/xfs_attr_leaf.c @@ -733,10 +733,10 @@ xfs_attr_shortform_bytesfit( return 0; /* rounded down */ - offset = (XFS_LITINO(mp) - bytes) >> 3; + offset = XFS_B_TO_FORKOFFT(XFS_LITINO(mp) - bytes); if (dp->i_df.if_format == XFS_DINODE_FMT_DEV) { - minforkoff = roundup(sizeof(xfs_dev_t), 8) >> 3; + minforkoff = XFS_B_TO_FORKOFF(sizeof(xfs_dev_t)); return (offset >= minforkoff) ? minforkoff : 0; } @@ -792,12 +792,12 @@ xfs_attr_shortform_bytesfit( * A data fork btree root must have space for at least * MINDBTPTRS key/ptr pairs if the data fork is small or empty. */ - minforkoff = max_t(int64_t, dsize, xfs_bmdr_space_calc(MINDBTPTRS)); - minforkoff = roundup(minforkoff, 8) >> 3; + minforkoff = XFS_B_TO_FORKOFF( + max_t(int64_t, dsize, xfs_bmdr_space_calc(MINDBTPTRS))); /* attr fork btree root can have at least this many key/ptr pairs */ - maxforkoff = XFS_LITINO(mp) - xfs_bmdr_space_calc(MINABTPTRS); - maxforkoff = maxforkoff >> 3; /* rounded down */ + maxforkoff = XFS_B_TO_FORKOFFT( + XFS_LITINO(mp) - xfs_bmdr_space_calc(MINABTPTRS)); if (offset >= maxforkoff) return maxforkoff; diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index 9bffde1484a7..ca49bf4a50c5 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -221,7 +221,7 @@ xfs_bmap_forkoff_reset( if (whichfork == XFS_ATTR_FORK && ip->i_df.if_format != XFS_DINODE_FMT_DEV && ip->i_df.if_format != XFS_DINODE_FMT_BTREE) { - uint dfl_forkoff = xfs_default_attroffset(ip) >> 3; + uint dfl_forkoff = xfs_inode_default_forkoff(ip); if (dfl_forkoff > ip->i_forkoff) ip->i_forkoff = dfl_forkoff; @@ -997,7 +997,7 @@ xfs_bmap_set_attrforkoff( struct xfs_inode *ip, int size) { - int default_size = xfs_default_attroffset(ip) >> 3; + int default_size = xfs_inode_default_forkoff(ip); switch (ip->i_df.if_format) { case XFS_DINODE_FMT_DEV: diff --git a/fs/xfs/libxfs/xfs_bmap.h b/fs/xfs/libxfs/xfs_bmap.h index 60f6df4ce057..e9f5416e4c05 100644 --- a/fs/xfs/libxfs/xfs_bmap.h +++ b/fs/xfs/libxfs/xfs_bmap.h @@ -213,6 +213,12 @@ void xfs_bmap_del_extent_cow(struct xfs_inode *ip, struct xfs_iext_cursor *cur, struct xfs_bmbt_irec *got, struct xfs_bmbt_irec *del); uint xfs_default_attroffset(struct xfs_inode *ip); + +static inline uint xfs_inode_default_forkoff(struct xfs_inode *ip) +{ + return XFS_B_TO_FORKOFFT(xfs_default_attroffset(ip)); +} + int xfs_bmap_collapse_extents(struct xfs_trans *tp, struct xfs_inode *ip, xfs_fileoff_t *next_fsb, xfs_fileoff_t offset_shift_fsb, bool *done); diff --git a/fs/xfs/libxfs/xfs_format.h b/fs/xfs/libxfs/xfs_format.h index 1a7a7e60a170..469e879149ac 100644 --- a/fs/xfs/libxfs/xfs_format.h +++ b/fs/xfs/libxfs/xfs_format.h @@ -1096,7 +1096,11 @@ enum xfs_dinode_fmt { /* * Inode data & attribute fork sizes, per inode. */ -#define XFS_DFORK_BOFF(dip) ((int)((dip)->di_forkoff << 3)) +#define XFS_B_TO_FORKOFFT(b) ((b) >> 3) +#define XFS_B_TO_FORKOFF(b) XFS_B_TO_FORKOFFT((b) + 7) +#define XFS_FORKOFF_TO_B(f) ((int)(f) << 3) + +#define XFS_DFORK_BOFF(dip) XFS_FORKOFF_TO_B((dip)->di_forkoff) #define XFS_DFORK_DSIZE(dip,mp) \ ((dip)->di_forkoff ? XFS_DFORK_BOFF(dip) : XFS_LITINO(mp)) diff --git a/fs/xfs/libxfs/xfs_inode_buf.c b/fs/xfs/libxfs/xfs_inode_buf.c index 282e78e5e3e8..8c9d296ebfe9 100644 --- a/fs/xfs/libxfs/xfs_inode_buf.c +++ b/fs/xfs/libxfs/xfs_inode_buf.c @@ -487,7 +487,7 @@ xfs_dinode_verify_forkoff( switch (dip->di_format) { case XFS_DINODE_FMT_DEV: - if (dip->di_forkoff != (roundup(sizeof(xfs_dev_t), 8) >> 3)) + if (dip->di_forkoff != XFS_B_TO_FORKOFF(sizeof(xfs_dev_t))) return __this_address; break; case XFS_DINODE_FMT_META_BTREE: @@ -497,7 +497,7 @@ xfs_dinode_verify_forkoff( case XFS_DINODE_FMT_LOCAL: /* fall through ... */ case XFS_DINODE_FMT_EXTENTS: /* fall through ... */ case XFS_DINODE_FMT_BTREE: - if (dip->di_forkoff >= (XFS_LITINO(mp) >> 3)) + if (dip->di_forkoff >= XFS_B_TO_FORKOFFT(XFS_LITINO(mp))) return __this_address; break; default: diff --git a/fs/xfs/libxfs/xfs_inode_util.c b/fs/xfs/libxfs/xfs_inode_util.c index 16c4c2ccdbb8..f486b23a9b52 100644 --- a/fs/xfs/libxfs/xfs_inode_util.c +++ b/fs/xfs/libxfs/xfs_inode_util.c @@ -345,7 +345,7 @@ xfs_inode_init( } if (xfs_icreate_want_attrfork(mp, args)) { - ip->i_forkoff = xfs_default_attroffset(ip) >> 3; + ip->i_forkoff = xfs_inode_default_forkoff(ip); xfs_ifork_init_attr(ip, XFS_DINODE_FMT_EXTENTS, 0); if (!xfs_has_attr(mp)) { diff --git a/fs/xfs/scrub/inode.c b/fs/xfs/scrub/inode.c index 6cded1eb6c2b..bb8d2bc008e0 100644 --- a/fs/xfs/scrub/inode.c +++ b/fs/xfs/scrub/inode.c @@ -607,7 +607,7 @@ xchk_dinode( } /* di_forkoff */ - if (dip->di_forkoff >= (XFS_LITINO(mp) >> 3)) + if (dip->di_forkoff >= XFS_B_TO_FORKOFFT(XFS_LITINO(mp))) xchk_ino_set_corrupt(sc, ino); if (naextents != 0 && dip->di_forkoff == 0) xchk_ino_set_corrupt(sc, ino); diff --git a/fs/xfs/scrub/inode_repair.c b/fs/xfs/scrub/inode_repair.c index b961fe94301e..a9ccf763c059 100644 --- a/fs/xfs/scrub/inode_repair.c +++ b/fs/xfs/scrub/inode_repair.c @@ -1490,7 +1490,7 @@ xrep_dinode_ensure_forkoff( /* Otherwise, just slide the attr fork up. */ before = XFS_DFORK_APTR(dip); - dip->di_forkoff = bmdr_minsz >> 3; + dip->di_forkoff = XFS_B_TO_FORKOFFT(bmdr_minsz); after = XFS_DFORK_APTR(dip); memmove(after, before, XFS_DFORK_ASIZE(dip, sc->mp)); } @@ -1522,7 +1522,7 @@ xrep_dinode_ensure_forkoff( * fork is empty, so we don't have any old contents to * move here. */ - dip->di_forkoff = (lit_sz - bmdr_minsz) >> 3; + dip->di_forkoff = XFS_B_TO_FORKOFFT(lit_sz - bmdr_minsz); } } } diff --git a/fs/xfs/xfs_inode.h b/fs/xfs/xfs_inode.h index 1602027cd0aa..53a1997b9866 100644 --- a/fs/xfs/xfs_inode.h +++ b/fs/xfs/xfs_inode.h @@ -132,7 +132,7 @@ xfs_ifork_ptr( static inline unsigned int xfs_inode_fork_boff(struct xfs_inode *ip) { - return ip->i_forkoff << 3; + return XFS_FORKOFF_TO_B(ip->i_forkoff); } static inline unsigned int xfs_inode_data_fork_size(struct xfs_inode *ip)