((char *)hdr + xfs_dir3_data_first_offset());
 }
 
+static struct xfs_dir2_data_free *
+xfs_dir2_data_bestfree_p(struct xfs_dir2_data_hdr *hdr)
+{
+       return hdr->bestfree;
+}
+
+static struct xfs_dir2_data_free *
+xfs_dir3_data_bestfree_p(struct xfs_dir2_data_hdr *hdr)
+{
+       return ((struct xfs_dir3_data_hdr *)hdr)->best_free;
+}
+
+static size_t
+xfs_dir2_data_entry_offset(void)
+{
+       return sizeof(struct xfs_dir2_data_hdr);
+}
+
+static struct xfs_dir2_data_entry *
+xfs_dir2_data_entry_p(struct xfs_dir2_data_hdr *hdr)
+{
+       return (struct xfs_dir2_data_entry *)
+               ((char *)hdr + xfs_dir2_data_entry_offset());
+}
+
+static struct xfs_dir2_data_unused *
+xfs_dir2_data_unused_p(struct xfs_dir2_data_hdr *hdr)
+{
+       return (struct xfs_dir2_data_unused *)
+               ((char *)hdr + xfs_dir2_data_entry_offset());
+}
+
+static size_t
+xfs_dir3_data_entry_offset(void)
+{
+       return sizeof(struct xfs_dir3_data_hdr);
+}
+
+static struct xfs_dir2_data_entry *
+xfs_dir3_data_entry_p(struct xfs_dir2_data_hdr *hdr)
+{
+       return (struct xfs_dir2_data_entry *)
+               ((char *)hdr + xfs_dir3_data_entry_offset());
+}
+
+static struct xfs_dir2_data_unused *
+xfs_dir3_data_unused_p(struct xfs_dir2_data_hdr *hdr)
+{
+       return (struct xfs_dir2_data_unused *)
+               ((char *)hdr + xfs_dir3_data_entry_offset());
+}
+
 const struct xfs_dir_ops xfs_dir2_ops = {
        .sf_entsize = xfs_dir2_sf_entsize,
        .sf_nextentry = xfs_dir2_sf_nextentry,
        .data_get_ftype = xfs_dir2_data_get_ftype,
        .data_put_ftype = xfs_dir2_data_put_ftype,
        .data_entry_tag_p = xfs_dir2_data_entry_tag_p,
+       .data_bestfree_p = xfs_dir2_data_bestfree_p,
 
        .data_dot_offset = xfs_dir2_data_dot_offset,
        .data_dotdot_offset = xfs_dir2_data_dotdot_offset,
        .data_first_offset = xfs_dir2_data_first_offset,
+       .data_entry_offset = xfs_dir2_data_entry_offset,
+
        .data_dot_entry_p = xfs_dir2_data_dot_entry_p,
        .data_dotdot_entry_p = xfs_dir2_data_dotdot_entry_p,
        .data_first_entry_p = xfs_dir2_data_first_entry_p,
+       .data_entry_p = xfs_dir2_data_entry_p,
+       .data_unused_p = xfs_dir2_data_unused_p,
+
 };
 
 const struct xfs_dir_ops xfs_dir2_ftype_ops = {
        .data_get_ftype = xfs_dir3_data_get_ftype,
        .data_put_ftype = xfs_dir3_data_put_ftype,
        .data_entry_tag_p = xfs_dir3_data_entry_tag_p,
+       .data_bestfree_p = xfs_dir2_data_bestfree_p,
 
        .data_dot_offset = xfs_dir2_data_dot_offset,
        .data_dotdot_offset = xfs_dir2_data_dotdot_offset,
        .data_first_offset = xfs_dir2_data_first_offset,
+       .data_entry_offset = xfs_dir2_data_entry_offset,
+
        .data_dot_entry_p = xfs_dir2_data_dot_entry_p,
        .data_dotdot_entry_p = xfs_dir2_data_dotdot_entry_p,
        .data_first_entry_p = xfs_dir2_data_first_entry_p,
+       .data_entry_p = xfs_dir2_data_entry_p,
+       .data_unused_p = xfs_dir2_data_unused_p,
 };
 
 const struct xfs_dir_ops xfs_dir3_ops = {
        .data_get_ftype = xfs_dir3_data_get_ftype,
        .data_put_ftype = xfs_dir3_data_put_ftype,
        .data_entry_tag_p = xfs_dir3_data_entry_tag_p,
+       .data_bestfree_p = xfs_dir3_data_bestfree_p,
 
        .data_dot_offset = xfs_dir3_data_dot_offset,
        .data_dotdot_offset = xfs_dir3_data_dotdot_offset,
        .data_first_offset = xfs_dir3_data_first_offset,
+       .data_entry_offset = xfs_dir3_data_entry_offset,
+
        .data_dot_entry_p = xfs_dir3_data_dot_entry_p,
        .data_dotdot_entry_p = xfs_dir3_data_dotdot_entry_p,
        .data_first_entry_p = xfs_dir3_data_first_entry_p,
+       .data_entry_p = xfs_dir3_data_entry_p,
+       .data_unused_p = xfs_dir3_data_unused_p,
 };
 
 
 #define XFS_DIR3_DATA_CRC_OFF  offsetof(struct xfs_dir3_data_hdr, hdr.crc)
 
-static inline struct xfs_dir2_data_free *
-xfs_dir3_data_bestfree_p(struct xfs_dir2_data_hdr *hdr)
-{
-       if (hdr->magic == cpu_to_be32(XFS_DIR3_DATA_MAGIC) ||
-           hdr->magic == cpu_to_be32(XFS_DIR3_BLOCK_MAGIC)) {
-               struct xfs_dir3_data_hdr *hdr3 = (struct xfs_dir3_data_hdr *)hdr;
-               return hdr3->best_free;
-       }
-       return hdr->bestfree;
-}
-
 /*
  * Active entry in a data block.
  *
                        be16_to_cpu(dup->length) - sizeof(__be16));
 }
 
-static inline size_t
-xfs_dir3_data_hdr_size(bool dir3)
-{
-       if (dir3)
-               return sizeof(struct xfs_dir3_data_hdr);
-       return sizeof(struct xfs_dir2_data_hdr);
-}
-
-static inline size_t
-xfs_dir3_data_entry_offset(struct xfs_dir2_data_hdr *hdr)
-{
-       bool dir3 = hdr->magic == cpu_to_be32(XFS_DIR3_DATA_MAGIC) ||
-                   hdr->magic == cpu_to_be32(XFS_DIR3_BLOCK_MAGIC);
-       return xfs_dir3_data_hdr_size(dir3);
-}
-
-static inline struct xfs_dir2_data_entry *
-xfs_dir3_data_entry_p(struct xfs_dir2_data_hdr *hdr)
-{
-       return (struct xfs_dir2_data_entry *)
-               ((char *)hdr + xfs_dir3_data_entry_offset(hdr));
-}
-
-static inline struct xfs_dir2_data_unused *
-xfs_dir3_data_unused_p(struct xfs_dir2_data_hdr *hdr)
-{
-       return (struct xfs_dir2_data_unused *)
-               ((char *)hdr + xfs_dir3_data_entry_offset(hdr));
-}
-
 /*
  * Leaf block structures.
  *
 
        void    (*data_put_ftype)(struct xfs_dir2_data_entry *dep,
                                __uint8_t ftype);
        __be16 * (*data_entry_tag_p)(struct xfs_dir2_data_entry *dep);
+       struct xfs_dir2_data_free *
+               (*data_bestfree_p)(struct xfs_dir2_data_hdr *hdr);
 
        xfs_dir2_data_aoff_t (*data_dot_offset)(void);
        xfs_dir2_data_aoff_t (*data_dotdot_offset)(void);
        xfs_dir2_data_aoff_t (*data_first_offset)(void);
+       size_t  (*data_entry_offset)(void);
+
        struct xfs_dir2_data_entry *
                (*data_dot_entry_p)(struct xfs_dir2_data_hdr *hdr);
        struct xfs_dir2_data_entry *
                (*data_dotdot_entry_p)(struct xfs_dir2_data_hdr *hdr);
        struct xfs_dir2_data_entry *
                (*data_first_entry_p)(struct xfs_dir2_data_hdr *hdr);
+       struct xfs_dir2_data_entry *
+               (*data_entry_p)(struct xfs_dir2_data_hdr *hdr);
+       struct xfs_dir2_data_unused *
+               (*data_unused_p)(struct xfs_dir2_data_hdr *hdr);
 };
 
 extern const struct xfs_dir_ops xfs_dir2_ops;
                struct xfs_dir2_data_hdr *hdr, int *loghead);
 extern void xfs_dir2_data_log_entry(struct xfs_trans *tp, struct xfs_inode *dp,
                struct xfs_buf *bp, struct xfs_dir2_data_entry *dep);
-extern void xfs_dir2_data_log_header(struct xfs_trans *tp,
+extern void xfs_dir2_data_log_header(struct xfs_trans *tp, struct xfs_inode *dp,
                struct xfs_buf *bp);
 extern void xfs_dir2_data_log_unused(struct xfs_trans *tp, struct xfs_buf *bp,
                struct xfs_dir2_data_unused *dup);
-extern void xfs_dir2_data_make_free(struct xfs_trans *tp, struct xfs_buf *bp,
+extern void xfs_dir2_data_make_free(struct xfs_trans *tp, struct xfs_inode *dp,
+               struct xfs_buf *bp, xfs_dir2_data_aoff_t offset,
+               xfs_dir2_data_aoff_t len, int *needlogp, int *needscanp);
+extern void xfs_dir2_data_use_free(struct xfs_trans *tp, struct xfs_inode *dp,
+               struct xfs_buf *bp, struct xfs_dir2_data_unused *dup,
                xfs_dir2_data_aoff_t offset, xfs_dir2_data_aoff_t len,
                int *needlogp, int *needscanp);
-extern void xfs_dir2_data_use_free(struct xfs_trans *tp, struct xfs_buf *bp,
-               struct xfs_dir2_data_unused *dup, xfs_dir2_data_aoff_t offset,
-               xfs_dir2_data_aoff_t len, int *needlogp, int *needscanp);
 
 extern struct xfs_dir2_data_free *xfs_dir2_data_freefind(
-               struct xfs_dir2_data_hdr *hdr, struct xfs_dir2_data_unused *dup);
+               struct xfs_dir2_data_hdr *hdr, struct xfs_dir2_data_free *bf,
+               struct xfs_dir2_data_unused *dup);
 
 extern const struct xfs_buf_ops xfs_dir3_block_buf_ops;
 extern const struct xfs_buf_ops xfs_dir3_leafn_buf_ops;
 
 
 static void
 xfs_dir2_block_need_space(
+       struct xfs_inode                *dp,
        struct xfs_dir2_data_hdr        *hdr,
        struct xfs_dir2_block_tail      *btp,
        struct xfs_dir2_leaf_entry      *blp,
        struct xfs_dir2_data_unused     *enddup = NULL;
 
        *compact = 0;
-       bf = xfs_dir3_data_bestfree_p(hdr);
+       bf = dp->d_ops->data_bestfree_p(hdr);
 
        /*
         * If there are stale entries we'll use one for the leaf.
        *lfloglow = toidx + 1 - (be32_to_cpu(btp->stale) - 1);
        *lfloghigh -= be32_to_cpu(btp->stale) - 1;
        be32_add_cpu(&btp->count, -(be32_to_cpu(btp->stale) - 1));
-       xfs_dir2_data_make_free(tp, bp,
+       xfs_dir2_data_make_free(tp, dp, bp,
                (xfs_dir2_data_aoff_t)((char *)blp - (char *)hdr),
                (xfs_dir2_data_aoff_t)((be32_to_cpu(btp->stale) - 1) * sizeof(*blp)),
                needlog, &needscan);
         * Find out if we can reuse stale entries or whether we need extra
         * space for entry and new leaf.
         */
-       xfs_dir2_block_need_space(hdr, btp, blp, &tagp, &dup,
+       xfs_dir2_block_need_space(dp, hdr, btp, blp, &tagp, &dup,
                                  &enddup, &compact, len);
 
        /*
                /*
                 * Mark the space needed for the new leaf entry, now in use.
                 */
-               xfs_dir2_data_use_free(tp, bp, enddup,
+               xfs_dir2_data_use_free(tp, dp, bp, enddup,
                        (xfs_dir2_data_aoff_t)
                        ((char *)enddup - (char *)hdr + be16_to_cpu(enddup->length) -
                         sizeof(*blp)),
        /*
         * Mark space for the data entry used.
         */
-       xfs_dir2_data_use_free(tp, bp, dup,
+       xfs_dir2_data_use_free(tp, dp, bp, dup,
                (xfs_dir2_data_aoff_t)((char *)dup - (char *)hdr),
                (xfs_dir2_data_aoff_t)len, &needlog, &needscan);
        /*
        if (needscan)
                xfs_dir2_data_freescan(dp, hdr, &needlog);
        if (needlog)
-               xfs_dir2_data_log_header(tp, bp);
+               xfs_dir2_data_log_header(tp, dp, bp);
        xfs_dir2_block_log_tail(tp, bp);
        xfs_dir2_data_log_entry(tp, dp, bp, dep);
        xfs_dir3_data_check(dp, bp);
         * Mark the data entry's space free.
         */
        needlog = needscan = 0;
-       xfs_dir2_data_make_free(tp, bp,
+       xfs_dir2_data_make_free(tp, dp, bp,
                (xfs_dir2_data_aoff_t)((char *)dep - (char *)hdr),
                dp->d_ops->data_entsize(dep->namelen), &needlog, &needscan);
        /*
        if (needscan)
                xfs_dir2_data_freescan(dp, hdr, &needlog);
        if (needlog)
-               xfs_dir2_data_log_header(tp, bp);
+               xfs_dir2_data_log_header(tp, dp, bp);
        xfs_dir3_data_check(dp, bp);
        /*
         * See if the size as a shortform is good enough.
        while (dp->i_d.di_size > mp->m_dirblksize) {
                int hdrsz;
 
-               hdrsz = xfs_dir3_data_hdr_size(xfs_sb_version_hascrc(&mp->m_sb));
+               hdrsz = dp->d_ops->data_entry_offset();
                bestsp = xfs_dir2_leaf_bests_p(ltp);
                if (be16_to_cpu(bestsp[be32_to_cpu(ltp->bestcount) - 1]) ==
                                            mp->m_dirblksize - hdrsz) {
        /*
         * Use up the space at the end of the block (blp/btp).
         */
-       xfs_dir2_data_use_free(tp, dbp, dup, mp->m_dirblksize - size, size,
+       xfs_dir2_data_use_free(tp, dp, dbp, dup, mp->m_dirblksize - size, size,
                &needlog, &needscan);
        /*
         * Initialize the block tail.
        if (needscan)
                xfs_dir2_data_freescan(dp, hdr, &needlog);
        if (needlog)
-               xfs_dir2_data_log_header(tp, dbp);
+               xfs_dir2_data_log_header(tp, dp, dbp);
        /*
         * Pitch the old leaf block.
         */
         * The whole thing is initialized to free by the init routine.
         * Say we're using the leaf and tail area.
         */
-       dup = xfs_dir3_data_unused_p(hdr);
+       dup = dp->d_ops->data_unused_p(hdr);
        needlog = needscan = 0;
-       xfs_dir2_data_use_free(tp, bp, dup, mp->m_dirblksize - i, i, &needlog,
+       xfs_dir2_data_use_free(tp, dp, bp, dup, mp->m_dirblksize - i, i, &needlog,
                &needscan);
        ASSERT(needscan == 0);
        /*
        /*
         * Remove the freespace, we'll manage it.
         */
-       xfs_dir2_data_use_free(tp, bp, dup,
+       xfs_dir2_data_use_free(tp, dp, bp, dup,
                (xfs_dir2_data_aoff_t)((char *)dup - (char *)hdr),
                be16_to_cpu(dup->length), &needlog, &needscan);
        /*
                        *xfs_dir2_data_unused_tag_p(dup) = cpu_to_be16(
                                ((char *)dup - (char *)hdr));
                        xfs_dir2_data_log_unused(tp, bp, dup);
-                       xfs_dir2_data_freeinsert(hdr, dup, &dummy);
+                       xfs_dir2_data_freeinsert(hdr,
+                                                dp->d_ops->data_bestfree_p(hdr),
+                                                dup, &dummy);
                        offset += be16_to_cpu(dup->length);
                        continue;
                }
 
 
        mp = bp->b_target->bt_mount;
        hdr = bp->b_addr;
-       bf = xfs_dir3_data_bestfree_p(hdr);
-       p = (char *)xfs_dir3_data_entry_p(hdr);
 
        /*
         * We can be passed a null dp here from a verifier, so manually
                XFS_ERROR_REPORT("Bad Magic", XFS_ERRLEVEL_LOW, mp);
                return EFSCORRUPTED;
        }
+       bf = ops->data_bestfree_p(hdr);
+       p = (char *)ops->data_entry_p(hdr);
 
        count = lastfree = freeseen = 0;
        /*
                        XFS_WANT_CORRUPTED_RETURN(
                                be16_to_cpu(*xfs_dir2_data_unused_tag_p(dup)) ==
                                               (char *)dup - (char *)hdr);
-                       dfp = xfs_dir2_data_freefind(hdr, dup);
+                       dfp = xfs_dir2_data_freefind(hdr, bf, dup);
                        if (dfp) {
                                i = (int)(dfp - bf);
                                XFS_WANT_CORRUPTED_RETURN(
  */
 xfs_dir2_data_free_t *
 xfs_dir2_data_freefind(
-       xfs_dir2_data_hdr_t     *hdr,           /* data block */
-       xfs_dir2_data_unused_t  *dup)           /* data unused entry */
+       struct xfs_dir2_data_hdr *hdr,          /* data block header */
+       struct xfs_dir2_data_free *bf,          /* bestfree table pointer */
+       struct xfs_dir2_data_unused *dup)       /* unused space */
 {
        xfs_dir2_data_free_t    *dfp;           /* bestfree entry */
        xfs_dir2_data_aoff_t    off;            /* offset value needed */
-       struct xfs_dir2_data_free *bf;
 #ifdef DEBUG
        int                     matched;        /* matched the value */
        int                     seenzero;       /* saw a 0 bestfree entry */
 #endif
 
        off = (xfs_dir2_data_aoff_t)((char *)dup - (char *)hdr);
-       bf = xfs_dir3_data_bestfree_p(hdr);
 
 #ifdef DEBUG
        /*
  */
 xfs_dir2_data_free_t *                         /* entry inserted */
 xfs_dir2_data_freeinsert(
-       xfs_dir2_data_hdr_t     *hdr,           /* data block pointer */
-       xfs_dir2_data_unused_t  *dup,           /* unused space */
+       struct xfs_dir2_data_hdr *hdr,          /* data block pointer */
+       struct xfs_dir2_data_free *dfp,         /* bestfree table pointer */
+       struct xfs_dir2_data_unused *dup,       /* unused space */
        int                     *loghead)       /* log the data header (out) */
 {
-       xfs_dir2_data_free_t    *dfp;           /* bestfree table pointer */
        xfs_dir2_data_free_t    new;            /* new bestfree entry */
 
        ASSERT(hdr->magic == cpu_to_be32(XFS_DIR2_DATA_MAGIC) ||
               hdr->magic == cpu_to_be32(XFS_DIR3_DATA_MAGIC) ||
               hdr->magic == cpu_to_be32(XFS_DIR3_BLOCK_MAGIC));
 
-       dfp = xfs_dir3_data_bestfree_p(hdr);
        new.length = dup->length;
        new.offset = cpu_to_be16((char *)dup - (char *)hdr);
 
  */
 STATIC void
 xfs_dir2_data_freeremove(
-       xfs_dir2_data_hdr_t     *hdr,           /* data block header */
-       xfs_dir2_data_free_t    *dfp,           /* bestfree entry pointer */
+       struct xfs_dir2_data_hdr *hdr,          /* data block header */
+       struct xfs_dir2_data_free *bf,          /* bestfree table pointer */
+       struct xfs_dir2_data_free *dfp,         /* bestfree entry pointer */
        int                     *loghead)       /* out: log data header */
 {
-       struct xfs_dir2_data_free *bf;
 
        ASSERT(hdr->magic == cpu_to_be32(XFS_DIR2_DATA_MAGIC) ||
               hdr->magic == cpu_to_be32(XFS_DIR2_BLOCK_MAGIC) ||
        /*
         * It's the first entry, slide the next 2 up.
         */
-       bf = xfs_dir3_data_bestfree_p(hdr);
        if (dfp == &bf[0]) {
                bf[0] = bf[1];
                bf[1] = bf[2];
        /*
         * Start by clearing the table.
         */
-       bf = xfs_dir3_data_bestfree_p(hdr);
+       bf = dp->d_ops->data_bestfree_p(hdr);
        memset(bf, 0, sizeof(*bf) * XFS_DIR2_DATA_FD_COUNT);
        *loghead = 1;
        /*
         * Set up pointers.
         */
-       p = (char *)xfs_dir3_data_entry_p(hdr);
+       p = (char *)dp->d_ops->data_entry_p(hdr);
        if (hdr->magic == cpu_to_be32(XFS_DIR2_BLOCK_MAGIC) ||
            hdr->magic == cpu_to_be32(XFS_DIR3_BLOCK_MAGIC)) {
                btp = xfs_dir2_block_tail_p(dp->i_mount, hdr);
                if (be16_to_cpu(dup->freetag) == XFS_DIR2_DATA_FREE_TAG) {
                        ASSERT((char *)dup - (char *)hdr ==
                               be16_to_cpu(*xfs_dir2_data_unused_tag_p(dup)));
-                       xfs_dir2_data_freeinsert(hdr, dup, loghead);
+                       xfs_dir2_data_freeinsert(hdr, bf, dup, loghead);
                        p += be16_to_cpu(dup->length);
                }
                /*
        } else
                hdr->magic = cpu_to_be32(XFS_DIR2_DATA_MAGIC);
 
-       bf = xfs_dir3_data_bestfree_p(hdr);
-       bf[0].offset = cpu_to_be16(xfs_dir3_data_entry_offset(hdr));
+       bf = dp->d_ops->data_bestfree_p(hdr);
+       bf[0].offset = cpu_to_be16(dp->d_ops->data_entry_offset());
        for (i = 1; i < XFS_DIR2_DATA_FD_COUNT; i++) {
                bf[i].length = 0;
                bf[i].offset = 0;
        /*
         * Set up an unused entry for the block's body.
         */
-       dup = xfs_dir3_data_unused_p(hdr);
+       dup = dp->d_ops->data_unused_p(hdr);
        dup->freetag = cpu_to_be16(XFS_DIR2_DATA_FREE_TAG);
 
-       t = mp->m_dirblksize - (uint)xfs_dir3_data_entry_offset(hdr);
+       t = mp->m_dirblksize - (uint)dp->d_ops->data_entry_offset();
        bf[0].length = cpu_to_be16(t);
        dup->length = cpu_to_be16(t);
        *xfs_dir2_data_unused_tag_p(dup) = cpu_to_be16((char *)dup - (char *)hdr);
        /*
         * Log it and return it.
         */
-       xfs_dir2_data_log_header(tp, bp);
+       xfs_dir2_data_log_header(tp, dp, bp);
        xfs_dir2_data_log_unused(tp, bp, dup);
        *bpp = bp;
        return 0;
 void
 xfs_dir2_data_log_header(
        struct xfs_trans        *tp,
+       struct xfs_inode        *dp,
        struct xfs_buf          *bp)
 {
-       xfs_dir2_data_hdr_t     *hdr = bp->b_addr;
+#ifdef DEBUG
+       struct xfs_dir2_data_hdr *hdr = bp->b_addr;
 
        ASSERT(hdr->magic == cpu_to_be32(XFS_DIR2_DATA_MAGIC) ||
               hdr->magic == cpu_to_be32(XFS_DIR3_DATA_MAGIC) ||
               hdr->magic == cpu_to_be32(XFS_DIR2_BLOCK_MAGIC) ||
               hdr->magic == cpu_to_be32(XFS_DIR3_BLOCK_MAGIC));
+#endif
 
-       xfs_trans_log_buf(tp, bp, 0, xfs_dir3_data_entry_offset(hdr) - 1);
+       xfs_trans_log_buf(tp, bp, 0, dp->d_ops->data_entry_offset() - 1);
 }
 
 /*
 void
 xfs_dir2_data_make_free(
        struct xfs_trans        *tp,
+       struct xfs_inode        *dp,
        struct xfs_buf          *bp,
        xfs_dir2_data_aoff_t    offset,         /* starting byte offset */
        xfs_dir2_data_aoff_t    len,            /* length in bytes */
         * If this isn't the start of the block, then back up to
         * the previous entry and see if it's free.
         */
-       if (offset > xfs_dir3_data_entry_offset(hdr)) {
+       if (offset > dp->d_ops->data_entry_offset()) {
                __be16                  *tagp;  /* tag just before us */
 
                tagp = (__be16 *)((char *)hdr + offset) - 1;
         * Previous and following entries are both free,
         * merge everything into a single free entry.
         */
-       bf = xfs_dir3_data_bestfree_p(hdr);
+       bf = dp->d_ops->data_bestfree_p(hdr);
        if (prevdup && postdup) {
                xfs_dir2_data_free_t    *dfp2;  /* another bestfree pointer */
 
                /*
                 * See if prevdup and/or postdup are in bestfree table.
                 */
-               dfp = xfs_dir2_data_freefind(hdr, prevdup);
-               dfp2 = xfs_dir2_data_freefind(hdr, postdup);
+               dfp = xfs_dir2_data_freefind(hdr, bf, prevdup);
+               dfp2 = xfs_dir2_data_freefind(hdr, bf, postdup);
                /*
                 * We need a rescan unless there are exactly 2 free entries
                 * namely our two.  Then we know what's happening, otherwise
                                ASSERT(dfp2 == dfp);
                                dfp2 = &bf[1];
                        }
-                       xfs_dir2_data_freeremove(hdr, dfp2, needlogp);
-                       xfs_dir2_data_freeremove(hdr, dfp, needlogp);
+                       xfs_dir2_data_freeremove(hdr, bf, dfp2, needlogp);
+                       xfs_dir2_data_freeremove(hdr, bf, dfp, needlogp);
                        /*
                         * Now insert the new entry.
                         */
-                       dfp = xfs_dir2_data_freeinsert(hdr, prevdup, needlogp);
+                       dfp = xfs_dir2_data_freeinsert(hdr, bf, prevdup,
+                                                      needlogp);
                        ASSERT(dfp == &bf[0]);
                        ASSERT(dfp->length == prevdup->length);
                        ASSERT(!dfp[1].length);
         * The entry before us is free, merge with it.
         */
        else if (prevdup) {
-               dfp = xfs_dir2_data_freefind(hdr, prevdup);
+               dfp = xfs_dir2_data_freefind(hdr, bf, prevdup);
                be16_add_cpu(&prevdup->length, len);
                *xfs_dir2_data_unused_tag_p(prevdup) =
                        cpu_to_be16((char *)prevdup - (char *)hdr);
                 * the old one and add the new one.
                 */
                if (dfp) {
-                       xfs_dir2_data_freeremove(hdr, dfp, needlogp);
-                       xfs_dir2_data_freeinsert(hdr, prevdup, needlogp);
+                       xfs_dir2_data_freeremove(hdr, bf, dfp, needlogp);
+                       xfs_dir2_data_freeinsert(hdr, bf, prevdup, needlogp);
                }
                /*
                 * Otherwise we need a scan if the new entry is big enough.
         * The following entry is free, merge with it.
         */
        else if (postdup) {
-               dfp = xfs_dir2_data_freefind(hdr, postdup);
+               dfp = xfs_dir2_data_freefind(hdr, bf, postdup);
                newdup = (xfs_dir2_data_unused_t *)((char *)hdr + offset);
                newdup->freetag = cpu_to_be16(XFS_DIR2_DATA_FREE_TAG);
                newdup->length = cpu_to_be16(len + be16_to_cpu(postdup->length));
                 * the old one and add the new one.
                 */
                if (dfp) {
-                       xfs_dir2_data_freeremove(hdr, dfp, needlogp);
-                       xfs_dir2_data_freeinsert(hdr, newdup, needlogp);
+                       xfs_dir2_data_freeremove(hdr, bf, dfp, needlogp);
+                       xfs_dir2_data_freeinsert(hdr, bf, newdup, needlogp);
                }
                /*
                 * Otherwise we need a scan if the new entry is big enough.
                *xfs_dir2_data_unused_tag_p(newdup) =
                        cpu_to_be16((char *)newdup - (char *)hdr);
                xfs_dir2_data_log_unused(tp, bp, newdup);
-               xfs_dir2_data_freeinsert(hdr, newdup, needlogp);
+               xfs_dir2_data_freeinsert(hdr, bf, newdup, needlogp);
        }
        *needscanp = needscan;
 }
 void
 xfs_dir2_data_use_free(
        struct xfs_trans        *tp,
+       struct xfs_inode        *dp,
        struct xfs_buf          *bp,
        xfs_dir2_data_unused_t  *dup,           /* unused entry */
        xfs_dir2_data_aoff_t    offset,         /* starting offset to use */
        /*
         * Look up the entry in the bestfree table.
         */
-       dfp = xfs_dir2_data_freefind(hdr, dup);
        oldlen = be16_to_cpu(dup->length);
-       bf = xfs_dir3_data_bestfree_p(hdr);
+       bf = dp->d_ops->data_bestfree_p(hdr);
+       dfp = xfs_dir2_data_freefind(hdr, bf, dup);
        ASSERT(dfp || oldlen <= be16_to_cpu(bf[2].length));
        /*
         * Check for alignment with front and back of the entry.
                if (dfp) {
                        needscan = (bf[2].offset != 0);
                        if (!needscan)
-                               xfs_dir2_data_freeremove(hdr, dfp, needlogp);
+                               xfs_dir2_data_freeremove(hdr, bf, dfp,
+                                                        needlogp);
                }
        }
        /*
                 * If it was in the table, remove it and add the new one.
                 */
                if (dfp) {
-                       xfs_dir2_data_freeremove(hdr, dfp, needlogp);
-                       dfp = xfs_dir2_data_freeinsert(hdr, newdup, needlogp);
+                       xfs_dir2_data_freeremove(hdr, bf, dfp, needlogp);
+                       dfp = xfs_dir2_data_freeinsert(hdr, bf, newdup,
+                                                      needlogp);
                        ASSERT(dfp != NULL);
                        ASSERT(dfp->length == newdup->length);
                        ASSERT(be16_to_cpu(dfp->offset) == (char *)newdup - (char *)hdr);
                 * If it was in the table, remove it and add the new one.
                 */
                if (dfp) {
-                       xfs_dir2_data_freeremove(hdr, dfp, needlogp);
-                       dfp = xfs_dir2_data_freeinsert(hdr, newdup, needlogp);
+                       xfs_dir2_data_freeremove(hdr, bf, dfp, needlogp);
+                       dfp = xfs_dir2_data_freeinsert(hdr, bf, newdup,
+                                                      needlogp);
                        ASSERT(dfp != NULL);
                        ASSERT(dfp->length == newdup->length);
                        ASSERT(be16_to_cpu(dfp->offset) == (char *)newdup - (char *)hdr);
                if (dfp) {
                        needscan = (bf[2].length != 0);
                        if (!needscan) {
-                               xfs_dir2_data_freeremove(hdr, dfp, needlogp);
-                               xfs_dir2_data_freeinsert(hdr, newdup, needlogp);
-                               xfs_dir2_data_freeinsert(hdr, newdup2,
+                               xfs_dir2_data_freeremove(hdr, bf, dfp,
+                                                        needlogp);
+                               xfs_dir2_data_freeinsert(hdr, bf, newdup,
+                                                        needlogp);
+                               xfs_dir2_data_freeinsert(hdr, bf, newdup2,
                                                         needlogp);
                        }
                }
 
        xfs_dir3_data_check(dp, dbp);
        btp = xfs_dir2_block_tail_p(mp, hdr);
        blp = xfs_dir2_block_leaf_p(btp);
-       bf = xfs_dir3_data_bestfree_p(hdr);
+       bf = dp->d_ops->data_bestfree_p(hdr);
        ents = xfs_dir3_leaf_ents_p(leaf);
 
        /*
         * Make the space formerly occupied by the leaf entries and block
         * tail be free.
         */
-       xfs_dir2_data_make_free(tp, dbp,
+       xfs_dir2_data_make_free(tp, dp, dbp,
                (xfs_dir2_data_aoff_t)((char *)blp - (char *)hdr),
                (xfs_dir2_data_aoff_t)((char *)hdr + mp->m_dirblksize -
                                       (char *)blp),
         * Log the data header and leaf bests table.
         */
        if (needlog)
-               xfs_dir2_data_log_header(tp, dbp);
+               xfs_dir2_data_log_header(tp, dp, dbp);
        xfs_dir3_leaf_check(mp, lbp);
        xfs_dir3_data_check(dp, dbp);
        xfs_dir3_leaf_log_bests(tp, lbp, 0, 0);
                else
                        xfs_dir3_leaf_log_bests(tp, lbp, use_block, use_block);
                hdr = dbp->b_addr;
-               bf = xfs_dir3_data_bestfree_p(hdr);
+               bf = dp->d_ops->data_bestfree_p(hdr);
                bestsp[use_block] = bf[0].length;
                grown = 1;
        } else {
                        return error;
                }
                hdr = dbp->b_addr;
-               bf = xfs_dir3_data_bestfree_p(hdr);
+               bf = dp->d_ops->data_bestfree_p(hdr);
                grown = 0;
        }
        /*
        /*
         * Mark the initial part of our freespace in use for the new entry.
         */
-       xfs_dir2_data_use_free(tp, dbp, dup,
+       xfs_dir2_data_use_free(tp, dp, dbp, dup,
                (xfs_dir2_data_aoff_t)((char *)dup - (char *)hdr), length,
                &needlog, &needscan);
        /*
         * Need to log the data block's header.
         */
        if (needlog)
-               xfs_dir2_data_log_header(tp, dbp);
+               xfs_dir2_data_log_header(tp, dp, dbp);
        xfs_dir2_data_log_entry(tp, dp, dbp, dep);
        /*
         * If the bests table needs to be changed, do it.
        leaf = lbp->b_addr;
        hdr = dbp->b_addr;
        xfs_dir3_data_check(dp, dbp);
-       bf = xfs_dir3_data_bestfree_p(hdr);
+       bf = dp->d_ops->data_bestfree_p(hdr);
        xfs_dir3_leaf_hdr_from_disk(&leafhdr, leaf);
        ents = xfs_dir3_leaf_ents_p(leaf);
        /*
        /*
         * Mark the former data entry unused.
         */
-       xfs_dir2_data_make_free(tp, dbp,
+       xfs_dir2_data_make_free(tp, dp, dbp,
                (xfs_dir2_data_aoff_t)((char *)dep - (char *)hdr),
                dp->d_ops->data_entsize(dep->namelen), &needlog, &needscan);
        /*
        if (needscan)
                xfs_dir2_data_freescan(dp, hdr, &needlog);
        if (needlog)
-               xfs_dir2_data_log_header(tp, dbp);
+               xfs_dir2_data_log_header(tp, dp, dbp);
        /*
         * If the longest freespace in the data block has changed,
         * put the new value in the bests table and log that.
         * If the data block is now empty then get rid of the data block.
         */
        if (be16_to_cpu(bf[0].length) ==
-                       mp->m_dirblksize - xfs_dir3_data_entry_offset(hdr)) {
+                       mp->m_dirblksize - dp->d_ops->data_entry_offset()) {
                ASSERT(db != mp->m_dirdatablk);
                if ((error = xfs_dir2_shrink_inode(args, db, dbp))) {
                        /*
 #ifdef DEBUG
 {
        struct xfs_dir2_data_hdr *hdr = dbp->b_addr;
-       struct xfs_dir2_data_free *bf = xfs_dir3_data_bestfree_p(hdr);
+       struct xfs_dir2_data_free *bf = dp->d_ops->data_bestfree_p(hdr);
 
        ASSERT(hdr->magic == cpu_to_be32(XFS_DIR2_DATA_MAGIC) ||
               hdr->magic == cpu_to_be32(XFS_DIR3_DATA_MAGIC));
        ASSERT(be16_to_cpu(bf[0].length) ==
-              mp->m_dirblksize - xfs_dir3_data_entry_offset(hdr));
+              mp->m_dirblksize - dp->d_ops->data_entry_offset());
        ASSERT(db == be32_to_cpu(ltp->bestcount) - 1);
 }
 #endif
 
        dbp = dblk->bp;
        hdr = dbp->b_addr;
        dep = (xfs_dir2_data_entry_t *)((char *)hdr + off);
-       bf = xfs_dir3_data_bestfree_p(hdr);
+       bf = dp->d_ops->data_bestfree_p(hdr);
        longest = be16_to_cpu(bf[0].length);
        needlog = needscan = 0;
-       xfs_dir2_data_make_free(tp, dbp, off,
+       xfs_dir2_data_make_free(tp, dp, dbp, off,
                dp->d_ops->data_entsize(dep->namelen), &needlog, &needscan);
        /*
         * Rescan the data block freespaces for bestfree.
        if (needscan)
                xfs_dir2_data_freescan(dp, hdr, &needlog);
        if (needlog)
-               xfs_dir2_data_log_header(tp, dbp);
+               xfs_dir2_data_log_header(tp, dp, dbp);
        xfs_dir3_data_check(dp, dbp);
        /*
         * If the longest data block freespace changes, need to update
                 * (usually).
                 */
                if (longest == mp->m_dirblksize -
-                              xfs_dir3_data_entry_offset(hdr)) {
+                              dp->d_ops->data_entry_offset()) {
                        /*
                         * Try to punch out the data block.
                         */
                 * change again.
                 */
                hdr = dbp->b_addr;
-               bf = xfs_dir3_data_bestfree_p(hdr);
+               bf = dp->d_ops->data_bestfree_p(hdr);
                bests[findex] = bf[0].length;
                logfree = 1;
        }
                if (error)
                        return error;
                hdr = dbp->b_addr;
-               bf = xfs_dir3_data_bestfree_p(hdr);
+               bf = dp->d_ops->data_bestfree_p(hdr);
                logfree = 0;
        }
        ASSERT(be16_to_cpu(bf[0].length) >= length);
        /*
         * Mark the first part of the unused space, inuse for us.
         */
-       xfs_dir2_data_use_free(tp, dbp, dup,
+       xfs_dir2_data_use_free(tp, dp, dbp, dup,
                (xfs_dir2_data_aoff_t)((char *)dup - (char *)hdr), length,
                &needlog, &needscan);
        /*
         * Log the data block header if needed.
         */
        if (needlog)
-               xfs_dir2_data_log_header(tp, dbp);
+               xfs_dir2_data_log_header(tp, dp, dbp);
        /*
         * If the freespace entry is now wrong, update it.
         */
 
 
 extern struct xfs_dir2_data_free *
 xfs_dir2_data_freeinsert(struct xfs_dir2_data_hdr *hdr,
-               struct xfs_dir2_data_unused *dup, int *loghead);
+               struct xfs_dir2_data_free *bf, struct xfs_dir2_data_unused *dup,
+               int *loghead);
 extern int xfs_dir3_data_init(struct xfs_da_args *args, xfs_dir2_db_t blkno,
                struct xfs_buf **bpp);
 
 
         * Set up values for the loop.
         */
        btp = xfs_dir2_block_tail_p(mp, hdr);
-       ptr = (char *)xfs_dir3_data_entry_p(hdr);
+       ptr = (char *)dp->d_ops->data_entry_p(hdr);
        endptr = (char *)xfs_dir2_block_leaf_p(btp);
 
        /*
                        /*
                         * Find our position in the block.
                         */
-                       ptr = (char *)xfs_dir3_data_entry_p(hdr);
+                       ptr = (char *)dp->d_ops->data_entry_p(hdr);
                        byteoff = xfs_dir2_byte_to_off(mp, curoff);
                        /*
                         * Skip past the header.
                         */
                        if (byteoff == 0)
-                               curoff += xfs_dir3_data_entry_offset(hdr);
+                               curoff += dp->d_ops->data_entry_offset();
                        /*
                         * Skip past entries until we reach our offset.
                         */
 
         * Set up to loop over the block's entries.
         */
        btp = xfs_dir2_block_tail_p(mp, hdr);
-       ptr = (char *)xfs_dir3_data_entry_p(hdr);
+       ptr = (char *)dp->d_ops->data_entry_p(hdr);
        endptr = (char *)xfs_dir2_block_leaf_p(btp);
        sfep = xfs_dir2_sf_firstentry(sfp);
        /*