Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / fs / xfs / xfs_attr_leaf.c
index b11256e..9462be8 100644 (file)
@@ -1,46 +1,26 @@
 /*
- * Copyright (c) 2000-2003 Silicon Graphics, Inc.  All Rights Reserved.
+ * Copyright (c) 2000-2005 Silicon Graphics, Inc.
+ * All Rights Reserved.
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
  * published by the Free Software Foundation.
  *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
  *
- * Further, this software is distributed without any warranty that it is
- * free of the rightful claim of any third person regarding infringement
- * or the like.  Any license provided herein, whether implied or
- * otherwise, applies only to this software file.  Patent licenses, if
- * any, provided herein do not apply to combinations of this program with
- * other software, or any other product whatsoever.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc., 59
- * Temple Place - Suite 330, Boston MA 02111-1307, USA.
- *
- * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
- * Mountain View, CA  94043, or:
- *
- * http://www.sgi.com
- *
- * For further information regarding this notice, see:
- *
- * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software Foundation,
+ * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
-/*
- * xfs_attr_leaf.c
- *
- * GROT: figure out how to recover gracefully when bmap returns ENOSPC.
- */
-
 #include "xfs.h"
-
-#include "xfs_macros.h"
+#include "xfs_fs.h"
 #include "xfs_types.h"
-#include "xfs_inum.h"
+#include "xfs_bit.h"
 #include "xfs_log.h"
+#include "xfs_inum.h"
 #include "xfs_trans.h"
 #include "xfs_sb.h"
 #include "xfs_ag.h"
 #include "xfs_dir2.h"
 #include "xfs_dmapi.h"
 #include "xfs_mount.h"
-#include "xfs_alloc_btree.h"
+#include "xfs_da_btree.h"
 #include "xfs_bmap_btree.h"
+#include "xfs_alloc_btree.h"
 #include "xfs_ialloc_btree.h"
 #include "xfs_alloc.h"
 #include "xfs_btree.h"
-#include "xfs_attr_sf.h"
 #include "xfs_dir_sf.h"
 #include "xfs_dir2_sf.h"
+#include "xfs_attr_sf.h"
 #include "xfs_dinode.h"
-#include "xfs_inode_item.h"
 #include "xfs_inode.h"
+#include "xfs_inode_item.h"
 #include "xfs_bmap.h"
-#include "xfs_da_btree.h"
 #include "xfs_attr.h"
 #include "xfs_attr_leaf.h"
 #include "xfs_error.h"
-#include "xfs_bit.h"
 
 /*
  * xfs_attr_leaf.c
@@ -79,6 +58,8 @@
 /*
  * Routines used for growing the Btree.
  */
+STATIC int xfs_attr_leaf_create(xfs_da_args_t *args, xfs_dablk_t which_block,
+                                   xfs_dabuf_t **bpp);
 STATIC int xfs_attr_leaf_add_work(xfs_dabuf_t *leaf_buffer, xfs_da_args_t *args,
                                              int freemap_index);
 STATIC void xfs_attr_leaf_compact(xfs_trans_t *trans, xfs_dabuf_t *leaf_buffer);
@@ -91,6 +72,16 @@ STATIC int xfs_attr_leaf_figure_balance(xfs_da_state_t *state,
                                           int *number_entries_in_blk1,
                                           int *number_usedbytes_in_blk1);
 
+/*
+ * Routines used for shrinking the Btree.
+ */
+STATIC int xfs_attr_node_inactive(xfs_trans_t **trans, xfs_inode_t *dp,
+                                 xfs_dabuf_t *bp, int level);
+STATIC int xfs_attr_leaf_inactive(xfs_trans_t **trans, xfs_inode_t *dp,
+                                 xfs_dabuf_t *bp);
+STATIC int xfs_attr_leaf_freextent(xfs_trans_t **trans, xfs_inode_t *dp,
+                                  xfs_dablk_t blkno, int blkcnt);
+
 /*
  * Utility routines.
  */
@@ -99,16 +90,89 @@ STATIC void xfs_attr_leaf_moveents(xfs_attr_leafblock_t *src_leaf,
                                         xfs_attr_leafblock_t *dst_leaf,
                                         int dst_start, int move_count,
                                         xfs_mount_t *mp);
+STATIC int xfs_attr_leaf_entsize(xfs_attr_leafblock_t *leaf, int index);
+STATIC int xfs_attr_put_listent(xfs_attr_list_context_t *context,
+                            attrnames_t *, char *name, int namelen,
+                            int valuelen);
 
 
 /*========================================================================
- * External routines when dirsize < XFS_LITINO(mp).
+ * External routines when attribute fork size < XFS_LITINO(mp).
  *========================================================================*/
 
 /*
- * Create the initial contents of a shortform attribute list.
+ * Query whether the requested number of additional bytes of extended
+ * attribute space will be able to fit inline.
+ * Returns zero if not, else the di_forkoff fork offset to be used in the
+ * literal area for attribute data once the new bytes have been added.
+ *
+ * di_forkoff must be 8 byte aligned, hence is stored as a >>3 value;
+ * special case for dev/uuid inodes, they have fixed size data forks.
  */
 int
+xfs_attr_shortform_bytesfit(xfs_inode_t *dp, int bytes)
+{
+       int offset;
+       int minforkoff; /* lower limit on valid forkoff locations */
+       int maxforkoff; /* upper limit on valid forkoff locations */
+       xfs_mount_t *mp = dp->i_mount;
+
+       offset = (XFS_LITINO(mp) - bytes) >> 3; /* rounded down */
+
+       switch (dp->i_d.di_format) {
+       case XFS_DINODE_FMT_DEV:
+               minforkoff = roundup(sizeof(xfs_dev_t), 8) >> 3;
+               return (offset >= minforkoff) ? minforkoff : 0;
+       case XFS_DINODE_FMT_UUID:
+               minforkoff = roundup(sizeof(uuid_t), 8) >> 3;
+               return (offset >= minforkoff) ? minforkoff : 0;
+       }
+
+       if (!(mp->m_flags & XFS_MOUNT_ATTR2)) {
+               if (bytes <= XFS_IFORK_ASIZE(dp))
+                       return mp->m_attroffset >> 3;
+               return 0;
+       }
+
+       /* data fork btree root can have at least this many key/ptr pairs */
+       minforkoff = MAX(dp->i_df.if_bytes, XFS_BMDR_SPACE_CALC(MINDBTPTRS));
+       minforkoff = roundup(minforkoff, 8) >> 3;
+
+       /* 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 */
+
+       if (offset >= minforkoff && offset < maxforkoff)
+               return offset;
+       if (offset >= maxforkoff)
+               return maxforkoff;
+       return 0;
+}
+
+/*
+ * Switch on the ATTR2 superblock bit (implies also FEATURES2)
+ */
+STATIC void
+xfs_sbversion_add_attr2(xfs_mount_t *mp, xfs_trans_t *tp)
+{
+       unsigned long s;
+
+       if ((mp->m_flags & XFS_MOUNT_ATTR2) &&
+           !(XFS_SB_VERSION_HASATTR2(&mp->m_sb))) {
+               s = XFS_SB_LOCK(mp);
+               if (!XFS_SB_VERSION_HASATTR2(&mp->m_sb)) {
+                       XFS_SB_VERSION_ADDATTR2(&mp->m_sb);
+                       XFS_SB_UNLOCK(mp, s);
+                       xfs_mod_sb(tp, XFS_SB_VERSIONNUM | XFS_SB_FEATURES2);
+               } else
+                       XFS_SB_UNLOCK(mp, s);
+       }
+}
+
+/*
+ * Create the initial contents of a shortform attribute list.
+ */
+void
 xfs_attr_shortform_create(xfs_da_args_t *args)
 {
        xfs_attr_sf_hdr_t *hdr;
@@ -130,31 +194,38 @@ xfs_attr_shortform_create(xfs_da_args_t *args)
        xfs_idata_realloc(dp, sizeof(*hdr), XFS_ATTR_FORK);
        hdr = (xfs_attr_sf_hdr_t *)ifp->if_u1.if_data;
        hdr->count = 0;
-       INT_SET(hdr->totsize, ARCH_CONVERT, sizeof(*hdr));
+       hdr->totsize = cpu_to_be16(sizeof(*hdr));
        xfs_trans_log_inode(args->trans, dp, XFS_ILOG_CORE | XFS_ILOG_ADATA);
-       return(0);
 }
 
 /*
  * Add a name/value pair to the shortform attribute list.
  * Overflow from the inode has already been checked for.
  */
-int
-xfs_attr_shortform_add(xfs_da_args_t *args)
+void
+xfs_attr_shortform_add(xfs_da_args_t *args, int forkoff)
 {
        xfs_attr_shortform_t *sf;
        xfs_attr_sf_entry_t *sfe;
        int i, offset, size;
+       xfs_mount_t *mp;
        xfs_inode_t *dp;
        xfs_ifork_t *ifp;
 
        dp = args->dp;
+       mp = dp->i_mount;
+       dp->i_d.di_forkoff = forkoff;
+       dp->i_df.if_ext_max =
+               XFS_IFORK_DSIZE(dp) / (uint)sizeof(xfs_bmbt_rec_t);
+       dp->i_afp->if_ext_max =
+               XFS_IFORK_ASIZE(dp) / (uint)sizeof(xfs_bmbt_rec_t);
+
        ifp = dp->i_afp;
        ASSERT(ifp->if_flags & XFS_IFINLINE);
        sf = (xfs_attr_shortform_t *)ifp->if_u1.if_data;
        sfe = &sf->list[0];
-       for (i = 0; i < INT_GET(sf->hdr.count, ARCH_CONVERT);
-                               sfe = XFS_ATTR_SF_NEXTENTRY(sfe), i++) {
+       for (i = 0; i < sf->hdr.count; sfe = XFS_ATTR_SF_NEXTENTRY(sfe), i++) {
+#ifdef DEBUG
                if (sfe->namelen != args->namelen)
                        continue;
                if (memcmp(args->name, sfe->nameval, args->namelen) != 0)
@@ -165,7 +236,8 @@ xfs_attr_shortform_add(xfs_da_args_t *args)
                if (((args->flags & ATTR_ROOT) != 0) !=
                    ((sfe->flags & XFS_ATTR_ROOT) != 0))
                        continue;
-               return(XFS_ERROR(EEXIST));
+               ASSERT(0);
+#endif
        }
 
        offset = (char *)sfe - (char *)sf;
@@ -175,20 +247,20 @@ xfs_attr_shortform_add(xfs_da_args_t *args)
        sfe = (xfs_attr_sf_entry_t *)((char *)sf + offset);
 
        sfe->namelen = args->namelen;
-       INT_SET(sfe->valuelen, ARCH_CONVERT, args->valuelen);
+       sfe->valuelen = args->valuelen;
        sfe->flags = (args->flags & ATTR_SECURE) ? XFS_ATTR_SECURE :
                        ((args->flags & ATTR_ROOT) ? XFS_ATTR_ROOT : 0);
        memcpy(sfe->nameval, args->name, args->namelen);
        memcpy(&sfe->nameval[args->namelen], args->value, args->valuelen);
-       INT_MOD(sf->hdr.count, ARCH_CONVERT, 1);
-       INT_MOD(sf->hdr.totsize, ARCH_CONVERT, size);
+       sf->hdr.count++;
+       be16_add(&sf->hdr.totsize, size);
        xfs_trans_log_inode(args->trans, dp, XFS_ILOG_CORE | XFS_ILOG_ADATA);
 
-       return(0);
+       xfs_sbversion_add_attr2(mp, args->trans);
 }
 
 /*
- * Remove a name from the shortform attribute list structure.
+ * Remove an attribute from the shortform attribute list structure.
  */
 int
 xfs_attr_shortform_remove(xfs_da_args_t *args)
@@ -196,17 +268,16 @@ xfs_attr_shortform_remove(xfs_da_args_t *args)
        xfs_attr_shortform_t *sf;
        xfs_attr_sf_entry_t *sfe;
        int base, size=0, end, totsize, i;
+       xfs_mount_t *mp;
        xfs_inode_t *dp;
 
-       /*
-        * Remove the attribute.
-        */
        dp = args->dp;
+       mp = dp->i_mount;
        base = sizeof(xfs_attr_sf_hdr_t);
        sf = (xfs_attr_shortform_t *)dp->i_afp->if_u1.if_data;
        sfe = &sf->list[0];
-       for (i = 0; i < INT_GET(sf->hdr.count, ARCH_CONVERT);
-                               sfe = XFS_ATTR_SF_NEXTENTRY(sfe),
+       end = sf->hdr.count;
+       for (i = 0; i < end; sfe = XFS_ATTR_SF_NEXTENTRY(sfe),
                                        base += size, i++) {
                size = XFS_ATTR_SF_ENTSIZE(sfe);
                if (sfe->namelen != args->namelen)
@@ -221,19 +292,53 @@ xfs_attr_shortform_remove(xfs_da_args_t *args)
                        continue;
                break;
        }
-       if (i == INT_GET(sf->hdr.count, ARCH_CONVERT))
+       if (i == end)
                return(XFS_ERROR(ENOATTR));
 
+       /*
+        * Fix up the attribute fork data, covering the hole
+        */
        end = base + size;
-       totsize = INT_GET(sf->hdr.totsize, ARCH_CONVERT);
-       if (end != totsize) {
-               memmove(&((char *)sf)[base], &((char *)sf)[end],
-                                                       totsize - end);
+       totsize = be16_to_cpu(sf->hdr.totsize);
+       if (end != totsize)
+               memmove(&((char *)sf)[base], &((char *)sf)[end], totsize - end);
+       sf->hdr.count--;
+       be16_add(&sf->hdr.totsize, -size);
+
+       /*
+        * Fix up the start offset of the attribute fork
+        */
+       totsize -= size;
+       if (totsize == sizeof(xfs_attr_sf_hdr_t) && !args->addname &&
+           (mp->m_flags & XFS_MOUNT_ATTR2)) {
+               /*
+                * Last attribute now removed, revert to original
+                * inode format making all literal area available
+                * to the data fork once more.
+                */
+               xfs_idestroy_fork(dp, XFS_ATTR_FORK);
+               dp->i_d.di_forkoff = 0;
+               dp->i_d.di_aformat = XFS_DINODE_FMT_EXTENTS;
+               ASSERT(dp->i_d.di_anextents == 0);
+               ASSERT(dp->i_afp == NULL);
+               dp->i_df.if_ext_max =
+                       XFS_IFORK_DSIZE(dp) / (uint)sizeof(xfs_bmbt_rec_t);
+               xfs_trans_log_inode(args->trans, dp, XFS_ILOG_CORE);
+       } else {
+               xfs_idata_realloc(dp, -size, XFS_ATTR_FORK);
+               dp->i_d.di_forkoff = xfs_attr_shortform_bytesfit(dp, totsize);
+               ASSERT(dp->i_d.di_forkoff);
+               ASSERT(totsize > sizeof(xfs_attr_sf_hdr_t) || args->addname ||
+                       !(mp->m_flags & XFS_MOUNT_ATTR2));
+               dp->i_afp->if_ext_max =
+                       XFS_IFORK_ASIZE(dp) / (uint)sizeof(xfs_bmbt_rec_t);
+               dp->i_df.if_ext_max =
+                       XFS_IFORK_DSIZE(dp) / (uint)sizeof(xfs_bmbt_rec_t);
+               xfs_trans_log_inode(args->trans, dp,
+                                       XFS_ILOG_CORE | XFS_ILOG_ADATA);
        }
-       INT_MOD(sf->hdr.count, ARCH_CONVERT, -1);
-       INT_MOD(sf->hdr.totsize, ARCH_CONVERT, -size);
-       xfs_idata_realloc(dp, -size, XFS_ATTR_FORK);
-       xfs_trans_log_inode(args->trans, dp, XFS_ILOG_CORE | XFS_ILOG_ADATA);
+
+       xfs_sbversion_add_attr2(mp, args->trans);
 
        return(0);
 }
@@ -254,7 +359,7 @@ xfs_attr_shortform_lookup(xfs_da_args_t *args)
        ASSERT(ifp->if_flags & XFS_IFINLINE);
        sf = (xfs_attr_shortform_t *)ifp->if_u1.if_data;
        sfe = &sf->list[0];
-       for (i = 0; i < INT_GET(sf->hdr.count, ARCH_CONVERT);
+       for (i = 0; i < sf->hdr.count;
                                sfe = XFS_ATTR_SF_NEXTENTRY(sfe), i++) {
                if (sfe->namelen != args->namelen)
                        continue;
@@ -285,7 +390,7 @@ xfs_attr_shortform_getvalue(xfs_da_args_t *args)
        ASSERT(args->dp->i_d.di_aformat == XFS_IFINLINE);
        sf = (xfs_attr_shortform_t *)args->dp->i_afp->if_u1.if_data;
        sfe = &sf->list[0];
-       for (i = 0; i < INT_GET(sf->hdr.count, ARCH_CONVERT);
+       for (i = 0; i < sf->hdr.count;
                                sfe = XFS_ATTR_SF_NEXTENTRY(sfe), i++) {
                if (sfe->namelen != args->namelen)
                        continue;
@@ -298,14 +403,14 @@ xfs_attr_shortform_getvalue(xfs_da_args_t *args)
                    ((sfe->flags & XFS_ATTR_ROOT) != 0))
                        continue;
                if (args->flags & ATTR_KERNOVAL) {
-                       args->valuelen = INT_GET(sfe->valuelen, ARCH_CONVERT);
+                       args->valuelen = sfe->valuelen;
                        return(XFS_ERROR(EEXIST));
                }
-               if (args->valuelen < INT_GET(sfe->valuelen, ARCH_CONVERT)) {
-                       args->valuelen = INT_GET(sfe->valuelen, ARCH_CONVERT);
+               if (args->valuelen < sfe->valuelen) {
+                       args->valuelen = sfe->valuelen;
                        return(XFS_ERROR(ERANGE));
                }
-               args->valuelen = INT_GET(sfe->valuelen, ARCH_CONVERT);
+               args->valuelen = sfe->valuelen;
                memcpy(args->value, &sfe->nameval[args->namelen],
                                                    args->valuelen);
                return(XFS_ERROR(EEXIST));
@@ -332,7 +437,7 @@ xfs_attr_shortform_to_leaf(xfs_da_args_t *args)
        dp = args->dp;
        ifp = dp->i_afp;
        sf = (xfs_attr_shortform_t *)ifp->if_u1.if_data;
-       size = INT_GET(sf->hdr.totsize, ARCH_CONVERT);
+       size = be16_to_cpu(sf->hdr.totsize);
        tmpbuffer = kmem_alloc(size, KM_SLEEP);
        ASSERT(tmpbuffer != NULL);
        memcpy(tmpbuffer, ifp->if_u1.if_data, size);
@@ -375,11 +480,11 @@ xfs_attr_shortform_to_leaf(xfs_da_args_t *args)
        nargs.oknoent = 1;
 
        sfe = &sf->list[0];
-       for (i = 0; i < INT_GET(sf->hdr.count, ARCH_CONVERT); i++) {
+       for (i = 0; i < sf->hdr.count; i++) {
                nargs.name = (char *)sfe->nameval;
                nargs.namelen = sfe->namelen;
                nargs.value = (char *)&sfe->nameval[nargs.namelen];
-               nargs.valuelen = INT_GET(sfe->valuelen, ARCH_CONVERT);
+               nargs.valuelen = sfe->valuelen;
                nargs.hashval = xfs_da_hashname((char *)sfe->nameval,
                                                sfe->namelen);
                nargs.flags = (sfe->flags & XFS_ATTR_SECURE) ? ATTR_SECURE :
@@ -408,11 +513,9 @@ xfs_attr_shortform_compare(const void *a, const void *b)
 
        sa = (xfs_attr_sf_sort_t *)a;
        sb = (xfs_attr_sf_sort_t *)b;
-       if (INT_GET(sa->hash, ARCH_CONVERT)
-                               < INT_GET(sb->hash, ARCH_CONVERT)) {
+       if (sa->hash < sb->hash) {
                return(-1);
-       } else if (INT_GET(sa->hash, ARCH_CONVERT)
-                               > INT_GET(sb->hash, ARCH_CONVERT)) {
+       } else if (sa->hash > sb->hash) {
                return(1);
        } else {
                return(sa->entno - sb->entno);
@@ -421,7 +524,7 @@ xfs_attr_shortform_compare(const void *a, const void *b)
 
 /*
  * Copy out entries of shortform attribute lists for attr_list().
- * Shortform atrtribute lists are not stored in hashval sorted order.
+ * Shortform attribute lists are not stored in hashval sorted order.
  * If the output buffer is not large enough to hold them all, then we
  * we have to calculate each entries' hashvalue and sort them before
  * we can begin returning them to the user.
@@ -454,10 +557,8 @@ xfs_attr_shortform_list(xfs_attr_list_context_t *context)
         * If the buffer is large enough, do not bother with sorting.
         * Note the generous fudge factor of 16 overhead bytes per entry.
         */
-       if ((dp->i_afp->if_bytes + INT_GET(sf->hdr.count, ARCH_CONVERT) * 16)
-                                                       < context->bufsize) {
-               for (i = 0, sfe = &sf->list[0];
-                               i < INT_GET(sf->hdr.count, ARCH_CONVERT); i++) {
+       if ((dp->i_afp->if_bytes + sf->hdr.count * 16) < context->bufsize) {
+               for (i = 0, sfe = &sf->list[0]; i < sf->hdr.count; i++) {
                        attrnames_t     *namesp;
 
                        if (((context->flags & ATTR_SECURE) != 0) !=
@@ -478,14 +579,13 @@ xfs_attr_shortform_list(xfs_attr_list_context_t *context)
                        if (context->flags & ATTR_KERNOVAL) {
                                ASSERT(context->flags & ATTR_KERNAMELS);
                                context->count += namesp->attr_namelen +
-                                       INT_GET(sfe->namelen, ARCH_CONVERT) + 1;
+                                       sfe->namelen + 1;
                        }
                        else {
                                if (xfs_attr_put_listent(context, namesp,
                                                   (char *)sfe->nameval,
                                                   (int)sfe->namelen,
-                                                  (int)INT_GET(sfe->valuelen,
-                                                               ARCH_CONVERT)))
+                                                  (int)sfe->valuelen))
                                        break;
                        }
                        sfe = XFS_ATTR_SF_NEXTENTRY(sfe);
@@ -497,7 +597,7 @@ xfs_attr_shortform_list(xfs_attr_list_context_t *context)
        /*
         * It didn't all fit, so we have to sort everything on hashval.
         */
-       sbsize = INT_GET(sf->hdr.count, ARCH_CONVERT) * sizeof(*sbuf);
+       sbsize = sf->hdr.count * sizeof(*sbuf);
        sbp = sbuf = kmem_alloc(sbsize, KM_SLEEP);
 
        /*
@@ -505,8 +605,7 @@ xfs_attr_shortform_list(xfs_attr_list_context_t *context)
         * the relevant info from only those that match into a buffer.
         */
        nsbuf = 0;
-       for (i = 0, sfe = &sf->list[0];
-                       i < INT_GET(sf->hdr.count, ARCH_CONVERT); i++) {
+       for (i = 0, sfe = &sf->list[0]; i < sf->hdr.count; i++) {
                if (unlikely(
                    ((char *)sfe < (char *)sf) ||
                    ((char *)sfe >= ((char *)sf + dp->i_afp->if_bytes)))) {
@@ -530,8 +629,7 @@ xfs_attr_shortform_list(xfs_attr_list_context_t *context)
                        continue;
                }
                sbp->entno = i;
-               INT_SET(sbp->hash, ARCH_CONVERT,
-                       xfs_da_hashname((char *)sfe->nameval, sfe->namelen));
+               sbp->hash = xfs_da_hashname((char *)sfe->nameval, sfe->namelen);
                sbp->name = (char *)sfe->nameval;
                sbp->namelen = sfe->namelen;
                /* These are bytes, and both on-disk, don't endian-flip */
@@ -545,7 +643,7 @@ xfs_attr_shortform_list(xfs_attr_list_context_t *context)
        /*
         * Sort the entries on hash then entno.
         */
-       qsort(sbuf, nsbuf, sizeof(*sbuf), xfs_attr_shortform_compare);
+       xfs_sort(sbuf, nsbuf, sizeof(*sbuf), xfs_attr_shortform_compare);
 
        /*
         * Re-find our place IN THE SORTED LIST.
@@ -554,12 +652,12 @@ xfs_attr_shortform_list(xfs_attr_list_context_t *context)
        cursor->initted = 1;
        cursor->blkno = 0;
        for (sbp = sbuf, i = 0; i < nsbuf; i++, sbp++) {
-               if (INT_GET(sbp->hash, ARCH_CONVERT) == cursor->hashval) {
+               if (sbp->hash == cursor->hashval) {
                        if (cursor->offset == count) {
                                break;
                        }
                        count++;
-               } else if (INT_GET(sbp->hash, ARCH_CONVERT) > cursor->hashval) {
+               } else if (sbp->hash > cursor->hashval) {
                        break;
                }
        }
@@ -579,8 +677,8 @@ xfs_attr_shortform_list(xfs_attr_list_context_t *context)
                        ((sbp->flags & XFS_ATTR_ROOT) ? &attr_trusted :
                          &attr_user);
 
-               if (cursor->hashval != INT_GET(sbp->hash, ARCH_CONVERT)) {
-                       cursor->hashval = INT_GET(sbp->hash, ARCH_CONVERT);
+               if (cursor->hashval != sbp->hash) {
+                       cursor->hashval = sbp->hash;
                        cursor->offset = 0;
                }
                if (context->flags & ATTR_KERNOVAL) {
@@ -590,7 +688,7 @@ xfs_attr_shortform_list(xfs_attr_list_context_t *context)
                } else {
                        if (xfs_attr_put_listent(context, namesp,
                                        sbp->name, sbp->namelen,
-                                       INT_GET(sbp->valuelen, ARCH_CONVERT)))
+                                       sbp->valuelen))
                                break;
                }
                cursor->offset++;
@@ -614,12 +712,11 @@ xfs_attr_shortform_allfit(xfs_dabuf_t *bp, xfs_inode_t *dp)
        int bytes, i;
 
        leaf = bp->data;
-       ASSERT(INT_GET(leaf->hdr.info.magic, ARCH_CONVERT)
-                                               == XFS_ATTR_LEAF_MAGIC);
+       ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_ATTR_LEAF_MAGIC);
 
        entry = &leaf->entries[0];
        bytes = sizeof(struct xfs_attr_sf_hdr);
-       for (i = 0; i < INT_GET(leaf->hdr.count, ARCH_CONVERT); entry++, i++) {
+       for (i = 0; i < be16_to_cpu(leaf->hdr.count); entry++, i++) {
                if (entry->flags & XFS_ATTR_INCOMPLETE)
                        continue;               /* don't copy partial entries */
                if (!(entry->flags & XFS_ATTR_LOCAL))
@@ -627,20 +724,23 @@ xfs_attr_shortform_allfit(xfs_dabuf_t *bp, xfs_inode_t *dp)
                name_loc = XFS_ATTR_LEAF_NAME_LOCAL(leaf, i);
                if (name_loc->namelen >= XFS_ATTR_SF_ENTSIZE_MAX)
                        return(0);
-               if (INT_GET(name_loc->valuelen, ARCH_CONVERT) >= XFS_ATTR_SF_ENTSIZE_MAX)
+               if (be16_to_cpu(name_loc->valuelen) >= XFS_ATTR_SF_ENTSIZE_MAX)
                        return(0);
                bytes += sizeof(struct xfs_attr_sf_entry)-1
                                + name_loc->namelen
-                               + INT_GET(name_loc->valuelen, ARCH_CONVERT);
+                               + be16_to_cpu(name_loc->valuelen);
        }
-       return( bytes < XFS_IFORK_ASIZE(dp) );
+       if ((dp->i_mount->m_flags & XFS_MOUNT_ATTR2) &&
+           (bytes == sizeof(struct xfs_attr_sf_hdr)))
+               return(-1);
+       return(xfs_attr_shortform_bytesfit(dp, bytes));
 }
 
 /*
  * Convert a leaf attribute list to shortform attribute list
  */
 int
-xfs_attr_leaf_to_shortform(xfs_dabuf_t *bp, xfs_da_args_t *args)
+xfs_attr_leaf_to_shortform(xfs_dabuf_t *bp, xfs_da_args_t *args, int forkoff)
 {
        xfs_attr_leafblock_t *leaf;
        xfs_attr_leaf_entry_t *entry;
@@ -657,8 +757,7 @@ xfs_attr_leaf_to_shortform(xfs_dabuf_t *bp, xfs_da_args_t *args)
        ASSERT(bp != NULL);
        memcpy(tmpbuffer, bp->data, XFS_LBSIZE(dp->i_mount));
        leaf = (xfs_attr_leafblock_t *)tmpbuffer;
-       ASSERT(INT_GET(leaf->hdr.info.magic, ARCH_CONVERT)
-                                               == XFS_ATTR_LEAF_MAGIC);
+       ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_ATTR_LEAF_MAGIC);
        memset(bp->data, 0, XFS_LBSIZE(dp->i_mount));
 
        /*
@@ -667,9 +766,27 @@ xfs_attr_leaf_to_shortform(xfs_dabuf_t *bp, xfs_da_args_t *args)
        error = xfs_da_shrink_inode(args, 0, bp);
        if (error)
                goto out;
-       error = xfs_attr_shortform_create(args);
-       if (error)
+
+       if (forkoff == -1) {
+               ASSERT(dp->i_mount->m_flags & XFS_MOUNT_ATTR2);
+
+               /*
+                * Last attribute was removed, revert to original
+                * inode format making all literal area available
+                * to the data fork once more.
+                */
+               xfs_idestroy_fork(dp, XFS_ATTR_FORK);
+               dp->i_d.di_forkoff = 0;
+               dp->i_d.di_aformat = XFS_DINODE_FMT_EXTENTS;
+               ASSERT(dp->i_d.di_anextents == 0);
+               ASSERT(dp->i_afp == NULL);
+               dp->i_df.if_ext_max =
+                       XFS_IFORK_DSIZE(dp) / (uint)sizeof(xfs_bmbt_rec_t);
+               xfs_trans_log_inode(args->trans, dp, XFS_ILOG_CORE);
                goto out;
+       }
+
+       xfs_attr_shortform_create(args);
 
        /*
         * Copy the attributes
@@ -683,7 +800,7 @@ xfs_attr_leaf_to_shortform(xfs_dabuf_t *bp, xfs_da_args_t *args)
        nargs.trans = args->trans;
        nargs.oknoent = 1;
        entry = &leaf->entries[0];
-       for (i = 0; i < INT_GET(leaf->hdr.count, ARCH_CONVERT); entry++, i++) {
+       for (i = 0; i < be16_to_cpu(leaf->hdr.count); entry++, i++) {
                if (entry->flags & XFS_ATTR_INCOMPLETE)
                        continue;       /* don't copy partial entries */
                if (!entry->nameidx)
@@ -693,11 +810,11 @@ xfs_attr_leaf_to_shortform(xfs_dabuf_t *bp, xfs_da_args_t *args)
                nargs.name = (char *)name_loc->nameval;
                nargs.namelen = name_loc->namelen;
                nargs.value = (char *)&name_loc->nameval[nargs.namelen];
-               nargs.valuelen = INT_GET(name_loc->valuelen, ARCH_CONVERT);
-               nargs.hashval = INT_GET(entry->hashval, ARCH_CONVERT);
+               nargs.valuelen = be16_to_cpu(name_loc->valuelen);
+               nargs.hashval = be32_to_cpu(entry->hashval);
                nargs.flags = (entry->flags & XFS_ATTR_SECURE) ? ATTR_SECURE :
                              ((entry->flags & XFS_ATTR_ROOT) ? ATTR_ROOT : 0);
-               xfs_attr_shortform_add(&nargs);
+               xfs_attr_shortform_add(&nargs, forkoff);
        }
        error = 0;
 
@@ -748,13 +865,12 @@ xfs_attr_leaf_to_node(xfs_da_args_t *args)
                goto out;
        node = bp1->data;
        leaf = bp2->data;
-       ASSERT(INT_GET(leaf->hdr.info.magic, ARCH_CONVERT)
-                                               == XFS_ATTR_LEAF_MAGIC);
+       ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_ATTR_LEAF_MAGIC);
        /* both on-disk, don't endian-flip twice */
        node->btree[0].hashval =
-               leaf->entries[INT_GET(leaf->hdr.count, ARCH_CONVERT)-1 ].hashval;
-       INT_SET(node->btree[0].before, ARCH_CONVERT, blkno);
-       INT_SET(node->hdr.count, ARCH_CONVERT, 1);
+               leaf->entries[be16_to_cpu(leaf->hdr.count)-1 ].hashval;
+       node->btree[0].before = cpu_to_be32(blkno);
+       node->hdr.count = cpu_to_be16(1);
        xfs_da_log_buf(args->trans, bp1, 0, XFS_LBSIZE(dp->i_mount) - 1);
        error = 0;
 out:
@@ -774,7 +890,7 @@ out:
  * Create the initial contents of a leaf attribute list
  * or a leaf in a node attribute list.
  */
-int
+STATIC int
 xfs_attr_leaf_create(xfs_da_args_t *args, xfs_dablk_t blkno, xfs_dabuf_t **bpp)
 {
        xfs_attr_leafblock_t *leaf;
@@ -793,19 +909,16 @@ xfs_attr_leaf_create(xfs_da_args_t *args, xfs_dablk_t blkno, xfs_dabuf_t **bpp)
        leaf = bp->data;
        memset((char *)leaf, 0, XFS_LBSIZE(dp->i_mount));
        hdr = &leaf->hdr;
-       INT_SET(hdr->info.magic, ARCH_CONVERT, XFS_ATTR_LEAF_MAGIC);
-       INT_SET(hdr->firstused, ARCH_CONVERT, XFS_LBSIZE(dp->i_mount));
+       hdr->info.magic = cpu_to_be16(XFS_ATTR_LEAF_MAGIC);
+       hdr->firstused = cpu_to_be16(XFS_LBSIZE(dp->i_mount));
        if (!hdr->firstused) {
-               INT_SET(hdr->firstused, ARCH_CONVERT,
+               hdr->firstused = cpu_to_be16(
                        XFS_LBSIZE(dp->i_mount) - XFS_ATTR_LEAF_NAME_ALIGN);
        }
 
-       INT_SET(hdr->freemap[0].base, ARCH_CONVERT,
-                                               sizeof(xfs_attr_leaf_hdr_t));
-       INT_SET(hdr->freemap[0].size, ARCH_CONVERT,
-                                         INT_GET(hdr->firstused, ARCH_CONVERT)
-                                       - INT_GET(hdr->freemap[0].base,
-                                                               ARCH_CONVERT));
+       hdr->freemap[0].base = cpu_to_be16(sizeof(xfs_attr_leaf_hdr_t));
+       hdr->freemap[0].size = cpu_to_be16(be16_to_cpu(hdr->firstused) -
+                                          sizeof(xfs_attr_leaf_hdr_t));
 
        xfs_da_log_buf(args->trans, bp, 0, XFS_LBSIZE(dp->i_mount) - 1);
 
@@ -877,38 +990,36 @@ xfs_attr_leaf_add(xfs_dabuf_t *bp, xfs_da_args_t *args)
        int tablesize, entsize, sum, tmp, i;
 
        leaf = bp->data;
-       ASSERT(INT_GET(leaf->hdr.info.magic, ARCH_CONVERT)
-                                               == XFS_ATTR_LEAF_MAGIC);
+       ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_ATTR_LEAF_MAGIC);
        ASSERT((args->index >= 0)
-               && (args->index <= INT_GET(leaf->hdr.count, ARCH_CONVERT)));
+               && (args->index <= be16_to_cpu(leaf->hdr.count)));
        hdr = &leaf->hdr;
-       entsize = xfs_attr_leaf_newentsize(args,
+       entsize = xfs_attr_leaf_newentsize(args->namelen, args->valuelen,
                           args->trans->t_mountp->m_sb.sb_blocksize, NULL);
 
        /*
         * Search through freemap for first-fit on new name length.
         * (may need to figure in size of entry struct too)
         */
-       tablesize = (INT_GET(hdr->count, ARCH_CONVERT) + 1)
+       tablesize = (be16_to_cpu(hdr->count) + 1)
                                        * sizeof(xfs_attr_leaf_entry_t)
                                        + sizeof(xfs_attr_leaf_hdr_t);
        map = &hdr->freemap[XFS_ATTR_LEAF_MAPSIZE-1];
        for (sum = 0, i = XFS_ATTR_LEAF_MAPSIZE-1; i >= 0; map--, i--) {
-               if (tablesize > INT_GET(hdr->firstused, ARCH_CONVERT)) {
-                       sum += INT_GET(map->size, ARCH_CONVERT);
+               if (tablesize > be16_to_cpu(hdr->firstused)) {
+                       sum += be16_to_cpu(map->size);
                        continue;
                }
                if (!map->size)
                        continue;       /* no space in this map */
                tmp = entsize;
-               if (INT_GET(map->base, ARCH_CONVERT)
-                               < INT_GET(hdr->firstused, ARCH_CONVERT))
+               if (be16_to_cpu(map->base) < be16_to_cpu(hdr->firstused))
                        tmp += sizeof(xfs_attr_leaf_entry_t);
-               if (INT_GET(map->size, ARCH_CONVERT) >= tmp) {
+               if (be16_to_cpu(map->size) >= tmp) {
                        tmp = xfs_attr_leaf_add_work(bp, args, i);
                        return(tmp);
                }
-               sum += INT_GET(map->size, ARCH_CONVERT);
+               sum += be16_to_cpu(map->size);
        }
 
        /*
@@ -929,7 +1040,7 @@ xfs_attr_leaf_add(xfs_dabuf_t *bp, xfs_da_args_t *args)
         * After compaction, the block is guaranteed to have only one
         * free region, in freemap[0].  If it is not big enough, give up.
         */
-       if (INT_GET(hdr->freemap[0].size, ARCH_CONVERT)
+       if (be16_to_cpu(hdr->freemap[0].size)
                                < (entsize + sizeof(xfs_attr_leaf_entry_t)))
                return(XFS_ERROR(ENOSPC));
 
@@ -952,44 +1063,42 @@ xfs_attr_leaf_add_work(xfs_dabuf_t *bp, xfs_da_args_t *args, int mapindex)
        int tmp, i;
 
        leaf = bp->data;
-       ASSERT(INT_GET(leaf->hdr.info.magic, ARCH_CONVERT)
-                                               == XFS_ATTR_LEAF_MAGIC);
+       ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_ATTR_LEAF_MAGIC);
        hdr = &leaf->hdr;
        ASSERT((mapindex >= 0) && (mapindex < XFS_ATTR_LEAF_MAPSIZE));
-       ASSERT((args->index >= 0)
-               && (args->index <= INT_GET(hdr->count, ARCH_CONVERT)));
+       ASSERT((args->index >= 0) && (args->index <= be16_to_cpu(hdr->count)));
 
        /*
         * Force open some space in the entry array and fill it in.
         */
        entry = &leaf->entries[args->index];
-       if (args->index < INT_GET(hdr->count, ARCH_CONVERT)) {
-               tmp  = INT_GET(hdr->count, ARCH_CONVERT) - args->index;
+       if (args->index < be16_to_cpu(hdr->count)) {
+               tmp  = be16_to_cpu(hdr->count) - args->index;
                tmp *= sizeof(xfs_attr_leaf_entry_t);
                memmove((char *)(entry+1), (char *)entry, tmp);
                xfs_da_log_buf(args->trans, bp,
                    XFS_DA_LOGRANGE(leaf, entry, tmp + sizeof(*entry)));
        }
-       INT_MOD(hdr->count, ARCH_CONVERT, 1);
+       be16_add(&hdr->count, 1);
 
        /*
         * Allocate space for the new string (at the end of the run).
         */
        map = &hdr->freemap[mapindex];
        mp = args->trans->t_mountp;
-       ASSERT(INT_GET(map->base, ARCH_CONVERT) < XFS_LBSIZE(mp));
-       ASSERT((INT_GET(map->base, ARCH_CONVERT) & 0x3) == 0);
-       ASSERT(INT_GET(map->size, ARCH_CONVERT)
-                               >= xfs_attr_leaf_newentsize(args,
-                                            mp->m_sb.sb_blocksize, NULL));
-       ASSERT(INT_GET(map->size, ARCH_CONVERT) < XFS_LBSIZE(mp));
-       ASSERT((INT_GET(map->size, ARCH_CONVERT) & 0x3) == 0);
-       INT_MOD(map->size, ARCH_CONVERT,
-               -xfs_attr_leaf_newentsize(args, mp->m_sb.sb_blocksize, &tmp));
-       INT_SET(entry->nameidx, ARCH_CONVERT,
-                                       INT_GET(map->base, ARCH_CONVERT)
-                                     + INT_GET(map->size, ARCH_CONVERT));
-       INT_SET(entry->hashval, ARCH_CONVERT, args->hashval);
+       ASSERT(be16_to_cpu(map->base) < XFS_LBSIZE(mp));
+       ASSERT((be16_to_cpu(map->base) & 0x3) == 0);
+       ASSERT(be16_to_cpu(map->size) >=
+               xfs_attr_leaf_newentsize(args->namelen, args->valuelen,
+                                        mp->m_sb.sb_blocksize, NULL));
+       ASSERT(be16_to_cpu(map->size) < XFS_LBSIZE(mp));
+       ASSERT((be16_to_cpu(map->size) & 0x3) == 0);
+       be16_add(&map->size,
+               -xfs_attr_leaf_newentsize(args->namelen, args->valuelen,
+                                         mp->m_sb.sb_blocksize, &tmp));
+       entry->nameidx = cpu_to_be16(be16_to_cpu(map->base) +
+                                    be16_to_cpu(map->size));
+       entry->hashval = cpu_to_be32(args->hashval);
        entry->flags = tmp ? XFS_ATTR_LOCAL : 0;
        entry->flags |= (args->flags & ATTR_SECURE) ? XFS_ATTR_SECURE :
                        ((args->flags & ATTR_ROOT) ? XFS_ATTR_ROOT : 0);
@@ -1002,12 +1111,10 @@ xfs_attr_leaf_add_work(xfs_dabuf_t *bp, xfs_da_args_t *args, int mapindex)
        }
        xfs_da_log_buf(args->trans, bp,
                          XFS_DA_LOGRANGE(leaf, entry, sizeof(*entry)));
-       ASSERT((args->index == 0) || (INT_GET(entry->hashval, ARCH_CONVERT)
-                                               >= INT_GET((entry-1)->hashval,
-                                                           ARCH_CONVERT)));
-       ASSERT((args->index == INT_GET(hdr->count, ARCH_CONVERT)-1) ||
-              (INT_GET(entry->hashval, ARCH_CONVERT)
-                           <= (INT_GET((entry+1)->hashval, ARCH_CONVERT))));
+       ASSERT((args->index == 0) ||
+              (be32_to_cpu(entry->hashval) >= be32_to_cpu((entry-1)->hashval)));
+       ASSERT((args->index == be16_to_cpu(hdr->count)-1) ||
+              (be32_to_cpu(entry->hashval) <= be32_to_cpu((entry+1)->hashval)));
 
        /*
         * Copy the attribute name and value into the new space.
@@ -1021,10 +1128,10 @@ xfs_attr_leaf_add_work(xfs_dabuf_t *bp, xfs_da_args_t *args, int mapindex)
        if (entry->flags & XFS_ATTR_LOCAL) {
                name_loc = XFS_ATTR_LEAF_NAME_LOCAL(leaf, args->index);
                name_loc->namelen = args->namelen;
-               INT_SET(name_loc->valuelen, ARCH_CONVERT, args->valuelen);
+               name_loc->valuelen = cpu_to_be16(args->valuelen);
                memcpy((char *)name_loc->nameval, args->name, args->namelen);
                memcpy((char *)&name_loc->nameval[args->namelen], args->value,
-                                  INT_GET(name_loc->valuelen, ARCH_CONVERT));
+                                  be16_to_cpu(name_loc->valuelen));
        } else {
                name_rmt = XFS_ATTR_LEAF_NAME_REMOTE(leaf, args->index);
                name_rmt->namelen = args->namelen;
@@ -1043,28 +1150,23 @@ xfs_attr_leaf_add_work(xfs_dabuf_t *bp, xfs_da_args_t *args, int mapindex)
        /*
         * Update the control info for this leaf node
         */
-       if (INT_GET(entry->nameidx, ARCH_CONVERT)
-                               < INT_GET(hdr->firstused, ARCH_CONVERT)) {
+       if (be16_to_cpu(entry->nameidx) < be16_to_cpu(hdr->firstused)) {
                /* both on-disk, don't endian-flip twice */
                hdr->firstused = entry->nameidx;
        }
-       ASSERT(INT_GET(hdr->firstused, ARCH_CONVERT)
-                               >= ((INT_GET(hdr->count, ARCH_CONVERT)
-                                       * sizeof(*entry))+sizeof(*hdr)));
-       tmp = (INT_GET(hdr->count, ARCH_CONVERT)-1)
-                                       * sizeof(xfs_attr_leaf_entry_t)
+       ASSERT(be16_to_cpu(hdr->firstused) >=
+              ((be16_to_cpu(hdr->count) * sizeof(*entry)) + sizeof(*hdr)));
+       tmp = (be16_to_cpu(hdr->count)-1) * sizeof(xfs_attr_leaf_entry_t)
                                        + sizeof(xfs_attr_leaf_hdr_t);
        map = &hdr->freemap[0];
        for (i = 0; i < XFS_ATTR_LEAF_MAPSIZE; map++, i++) {
-               if (INT_GET(map->base, ARCH_CONVERT) == tmp) {
-                       INT_MOD(map->base, ARCH_CONVERT,
-                                       sizeof(xfs_attr_leaf_entry_t));
-                       INT_MOD(map->size, ARCH_CONVERT,
-                                       -sizeof(xfs_attr_leaf_entry_t));
+               if (be16_to_cpu(map->base) == tmp) {
+                       be16_add(&map->base, sizeof(xfs_attr_leaf_entry_t));
+                       be16_add(&map->size,
+                                -((int)sizeof(xfs_attr_leaf_entry_t)));
                }
        }
-       INT_MOD(hdr->usedbytes, ARCH_CONVERT,
-                               xfs_attr_leaf_entsize(leaf, args->index));
+       be16_add(&hdr->usedbytes, xfs_attr_leaf_entsize(leaf, args->index));
        xfs_da_log_buf(args->trans, bp,
                XFS_DA_LOGRANGE(leaf, hdr, sizeof(*hdr)));
        return(0);
@@ -1095,28 +1197,25 @@ xfs_attr_leaf_compact(xfs_trans_t *trans, xfs_dabuf_t *bp)
        hdr_s = &leaf_s->hdr;
        hdr_d = &leaf_d->hdr;
        hdr_d->info = hdr_s->info;      /* struct copy */
-       INT_SET(hdr_d->firstused, ARCH_CONVERT, XFS_LBSIZE(mp));
+       hdr_d->firstused = cpu_to_be16(XFS_LBSIZE(mp));
        /* handle truncation gracefully */
        if (!hdr_d->firstused) {
-               INT_SET(hdr_d->firstused, ARCH_CONVERT,
+               hdr_d->firstused = cpu_to_be16(
                                XFS_LBSIZE(mp) - XFS_ATTR_LEAF_NAME_ALIGN);
        }
        hdr_d->usedbytes = 0;
        hdr_d->count = 0;
        hdr_d->holes = 0;
-       INT_SET(hdr_d->freemap[0].base, ARCH_CONVERT,
-                                       sizeof(xfs_attr_leaf_hdr_t));
-       INT_SET(hdr_d->freemap[0].size, ARCH_CONVERT,
-                               INT_GET(hdr_d->firstused, ARCH_CONVERT)
-                             - INT_GET(hdr_d->freemap[0].base, ARCH_CONVERT));
+       hdr_d->freemap[0].base = cpu_to_be16(sizeof(xfs_attr_leaf_hdr_t));
+       hdr_d->freemap[0].size = cpu_to_be16(be16_to_cpu(hdr_d->firstused) -
+                                            sizeof(xfs_attr_leaf_hdr_t));
 
        /*
         * Copy all entry's in the same (sorted) order,
         * but allocate name/value pairs packed and in sequence.
         */
        xfs_attr_leaf_moveents(leaf_s, 0, leaf_d, 0,
-                               (int)INT_GET(hdr_s->count, ARCH_CONVERT), mp);
-
+                               be16_to_cpu(hdr_s->count), mp);
        xfs_da_log_buf(trans, bp, 0, XFS_LBSIZE(mp) - 1);
 
        kmem_free(tmpbuffer, XFS_LBSIZE(mp));
@@ -1151,10 +1250,8 @@ xfs_attr_leaf_rebalance(xfs_da_state_t *state, xfs_da_state_blk_t *blk1,
        ASSERT(blk2->magic == XFS_ATTR_LEAF_MAGIC);
        leaf1 = blk1->bp->data;
        leaf2 = blk2->bp->data;
-       ASSERT(INT_GET(leaf1->hdr.info.magic, ARCH_CONVERT)
-                                               == XFS_ATTR_LEAF_MAGIC);
-       ASSERT(INT_GET(leaf2->hdr.info.magic, ARCH_CONVERT)
-                                               == XFS_ATTR_LEAF_MAGIC);
+       ASSERT(be16_to_cpu(leaf1->hdr.info.magic) == XFS_ATTR_LEAF_MAGIC);
+       ASSERT(be16_to_cpu(leaf2->hdr.info.magic) == XFS_ATTR_LEAF_MAGIC);
        args = state->args;
 
        /*
@@ -1191,22 +1288,21 @@ xfs_attr_leaf_rebalance(xfs_da_state_t *state, xfs_da_state_blk_t *blk1,
        /*
         * Move any entries required from leaf to leaf:
         */
-       if (count < INT_GET(hdr1->count, ARCH_CONVERT)) {
+       if (count < be16_to_cpu(hdr1->count)) {
                /*
                 * Figure the total bytes to be added to the destination leaf.
                 */
                /* number entries being moved */
-               count = INT_GET(hdr1->count, ARCH_CONVERT) - count;
-               space  = INT_GET(hdr1->usedbytes, ARCH_CONVERT) - totallen;
+               count = be16_to_cpu(hdr1->count) - count;
+               space  = be16_to_cpu(hdr1->usedbytes) - totallen;
                space += count * sizeof(xfs_attr_leaf_entry_t);
 
                /*
                 * leaf2 is the destination, compact it if it looks tight.
                 */
-               max  = INT_GET(hdr2->firstused, ARCH_CONVERT)
+               max  = be16_to_cpu(hdr2->firstused)
                                                - sizeof(xfs_attr_leaf_hdr_t);
-               max -= INT_GET(hdr2->count, ARCH_CONVERT)
-                                       * sizeof(xfs_attr_leaf_entry_t);
+               max -= be16_to_cpu(hdr2->count) * sizeof(xfs_attr_leaf_entry_t);
                if (space > max) {
                        xfs_attr_leaf_compact(args->trans, blk2->bp);
                }
@@ -1214,13 +1310,12 @@ xfs_attr_leaf_rebalance(xfs_da_state_t *state, xfs_da_state_blk_t *blk1,
                /*
                 * Move high entries from leaf1 to low end of leaf2.
                 */
-               xfs_attr_leaf_moveents(leaf1,
-                               INT_GET(hdr1->count, ARCH_CONVERT)-count,
+               xfs_attr_leaf_moveents(leaf1, be16_to_cpu(hdr1->count) - count,
                                leaf2, 0, count, state->mp);
 
                xfs_da_log_buf(args->trans, blk1->bp, 0, state->blocksize-1);
                xfs_da_log_buf(args->trans, blk2->bp, 0, state->blocksize-1);
-       } else if (count > INT_GET(hdr1->count, ARCH_CONVERT)) {
+       } else if (count > be16_to_cpu(hdr1->count)) {
                /*
                 * I assert that since all callers pass in an empty
                 * second buffer, this code should never execute.
@@ -1230,17 +1325,16 @@ xfs_attr_leaf_rebalance(xfs_da_state_t *state, xfs_da_state_blk_t *blk1,
                 * Figure the total bytes to be added to the destination leaf.
                 */
                /* number entries being moved */
-               count -= INT_GET(hdr1->count, ARCH_CONVERT);
-               space  = totallen - INT_GET(hdr1->usedbytes, ARCH_CONVERT);
+               count -= be16_to_cpu(hdr1->count);
+               space  = totallen - be16_to_cpu(hdr1->usedbytes);
                space += count * sizeof(xfs_attr_leaf_entry_t);
 
                /*
                 * leaf1 is the destination, compact it if it looks tight.
                 */
-               max  = INT_GET(hdr1->firstused, ARCH_CONVERT)
+               max  = be16_to_cpu(hdr1->firstused)
                                                - sizeof(xfs_attr_leaf_hdr_t);
-               max -= INT_GET(hdr1->count, ARCH_CONVERT)
-                                       * sizeof(xfs_attr_leaf_entry_t);
+               max -= be16_to_cpu(hdr1->count) * sizeof(xfs_attr_leaf_entry_t);
                if (space > max) {
                        xfs_attr_leaf_compact(args->trans, blk1->bp);
                }
@@ -1249,8 +1343,7 @@ xfs_attr_leaf_rebalance(xfs_da_state_t *state, xfs_da_state_blk_t *blk1,
                 * Move low entries from leaf2 to high end of leaf1.
                 */
                xfs_attr_leaf_moveents(leaf2, 0, leaf1,
-                               (int)INT_GET(hdr1->count, ARCH_CONVERT), count,
-                               state->mp);
+                               be16_to_cpu(hdr1->count), count, state->mp);
 
                xfs_da_log_buf(args->trans, blk1->bp, 0, state->blocksize-1);
                xfs_da_log_buf(args->trans, blk2->bp, 0, state->blocksize-1);
@@ -1259,12 +1352,10 @@ xfs_attr_leaf_rebalance(xfs_da_state_t *state, xfs_da_state_blk_t *blk1,
        /*
         * Copy out last hashval in each block for B-tree code.
         */
-       blk1->hashval =
-           INT_GET(leaf1->entries[INT_GET(leaf1->hdr.count,
-                                   ARCH_CONVERT)-1].hashval, ARCH_CONVERT);
-       blk2->hashval =
-           INT_GET(leaf2->entries[INT_GET(leaf2->hdr.count,
-                                   ARCH_CONVERT)-1].hashval, ARCH_CONVERT);
+       blk1->hashval = be32_to_cpu(
+               leaf1->entries[be16_to_cpu(leaf1->hdr.count)-1].hashval);
+       blk2->hashval = be32_to_cpu(
+               leaf2->entries[be16_to_cpu(leaf2->hdr.count)-1].hashval);
 
        /*
         * Adjust the expected index for insertion.
@@ -1278,13 +1369,12 @@ xfs_attr_leaf_rebalance(xfs_da_state_t *state, xfs_da_state_blk_t *blk1,
         * inserting.  The index/blkno fields refer to the "old" entry,
         * while the index2/blkno2 fields refer to the "new" entry.
         */
-       if (blk1->index > INT_GET(leaf1->hdr.count, ARCH_CONVERT)) {
+       if (blk1->index > be16_to_cpu(leaf1->hdr.count)) {
                ASSERT(state->inleaf == 0);
-               blk2->index = blk1->index
-                               - INT_GET(leaf1->hdr.count, ARCH_CONVERT);
+               blk2->index = blk1->index - be16_to_cpu(leaf1->hdr.count);
                args->index = args->index2 = blk2->index;
                args->blkno = args->blkno2 = blk2->blkno;
-       } else if (blk1->index == INT_GET(leaf1->hdr.count, ARCH_CONVERT)) {
+       } else if (blk1->index == be16_to_cpu(leaf1->hdr.count)) {
                if (state->inleaf) {
                        args->index = blk1->index;
                        args->blkno = blk1->blkno;
@@ -1292,7 +1382,7 @@ xfs_attr_leaf_rebalance(xfs_da_state_t *state, xfs_da_state_blk_t *blk1,
                        args->blkno2 = blk2->blkno;
                } else {
                        blk2->index = blk1->index
-                                   - INT_GET(leaf1->hdr.count, ARCH_CONVERT);
+                                   - be16_to_cpu(leaf1->hdr.count);
                        args->index = args->index2 = blk2->index;
                        args->blkno = args->blkno2 = blk2->blkno;
                }
@@ -1336,13 +1426,14 @@ xfs_attr_leaf_figure_balance(xfs_da_state_t *state,
         * Examine entries until we reduce the absolute difference in
         * byte usage between the two blocks to a minimum.
         */
-       max = INT_GET(hdr1->count, ARCH_CONVERT)
-                       + INT_GET(hdr2->count, ARCH_CONVERT);
+       max = be16_to_cpu(hdr1->count) + be16_to_cpu(hdr2->count);
        half  = (max+1) * sizeof(*entry);
-       half += INT_GET(hdr1->usedbytes, ARCH_CONVERT)
-                               + INT_GET(hdr2->usedbytes, ARCH_CONVERT)
-                               + xfs_attr_leaf_newentsize(state->args,
-                                                    state->blocksize, NULL);
+       half += be16_to_cpu(hdr1->usedbytes) +
+               be16_to_cpu(hdr2->usedbytes) +
+               xfs_attr_leaf_newentsize(
+                               state->args->namelen,
+                               state->args->valuelen,
+                               state->blocksize, NULL);
        half /= 2;
        lastdelta = state->blocksize;
        entry = &leaf1->entries[0];
@@ -1354,9 +1445,10 @@ xfs_attr_leaf_figure_balance(xfs_da_state_t *state,
                 */
                if (count == blk1->index) {
                        tmp = totallen + sizeof(*entry) +
-                               xfs_attr_leaf_newentsize(state->args,
-                                                        state->blocksize,
-                                                        NULL);
+                               xfs_attr_leaf_newentsize(
+                                               state->args->namelen,
+                                               state->args->valuelen,
+                                               state->blocksize, NULL);
                        if (XFS_ATTR_ABS(half - tmp) > lastdelta)
                                break;
                        lastdelta = XFS_ATTR_ABS(half - tmp);
@@ -1367,7 +1459,7 @@ xfs_attr_leaf_figure_balance(xfs_da_state_t *state,
                /*
                 * Wrap around into the second block if necessary.
                 */
-               if (count == INT_GET(hdr1->count, ARCH_CONVERT)) {
+               if (count == be16_to_cpu(hdr1->count)) {
                        leaf1 = leaf2;
                        entry = &leaf1->entries[0];
                        index = 0;
@@ -1392,9 +1484,10 @@ xfs_attr_leaf_figure_balance(xfs_da_state_t *state,
        totallen -= count * sizeof(*entry);
        if (foundit) {
                totallen -= sizeof(*entry) +
-                               xfs_attr_leaf_newentsize(state->args,
-                                                        state->blocksize,
-                                                        NULL);
+                               xfs_attr_leaf_newentsize(
+                                               state->args->namelen,
+                                               state->args->valuelen,
+                                               state->blocksize, NULL);
        }
 
        *countarg = count;
@@ -1434,12 +1527,12 @@ xfs_attr_leaf_toosmall(xfs_da_state_t *state, int *action)
         */
        blk = &state->path.blk[ state->path.active-1 ];
        info = blk->bp->data;
-       ASSERT(INT_GET(info->magic, ARCH_CONVERT) == XFS_ATTR_LEAF_MAGIC);
+       ASSERT(be16_to_cpu(info->magic) == XFS_ATTR_LEAF_MAGIC);
        leaf = (xfs_attr_leafblock_t *)info;
-       count = INT_GET(leaf->hdr.count, ARCH_CONVERT);
+       count = be16_to_cpu(leaf->hdr.count);
        bytes = sizeof(xfs_attr_leaf_hdr_t) +
                count * sizeof(xfs_attr_leaf_entry_t) +
-               INT_GET(leaf->hdr.usedbytes, ARCH_CONVERT);
+               be16_to_cpu(leaf->hdr.usedbytes);
        if (bytes > (state->blocksize >> 1)) {
                *action = 0;    /* blk over 50%, don't try to join */
                return(0);
@@ -1448,7 +1541,7 @@ xfs_attr_leaf_toosmall(xfs_da_state_t *state, int *action)
        /*
         * Check for the degenerate case of the block being empty.
         * If the block is empty, we'll simply delete it, no need to
-        * coalesce it with a sibling block.  We choose (aribtrarily)
+        * coalesce it with a sibling block.  We choose (arbitrarily)
         * to merge with the forward block unless it is NULL.
         */
        if (count == 0) {
@@ -1456,7 +1549,7 @@ xfs_attr_leaf_toosmall(xfs_da_state_t *state, int *action)
                 * Make altpath point to the block we want to keep and
                 * path point to the block we want to drop (this one).
                 */
-               forward = info->forw;
+               forward = (info->forw != 0);
                memcpy(&state->altpath, &state->path, sizeof(state->path));
                error = xfs_da_path_shift(state, &state->altpath, forward,
                                                 0, &retval);
@@ -1478,13 +1571,12 @@ xfs_attr_leaf_toosmall(xfs_da_state_t *state, int *action)
         * to shrink an attribute list over time.
         */
        /* start with smaller blk num */
-       forward = (INT_GET(info->forw, ARCH_CONVERT)
-                                       < INT_GET(info->back, ARCH_CONVERT));
+       forward = (be32_to_cpu(info->forw) < be32_to_cpu(info->back));
        for (i = 0; i < 2; forward = !forward, i++) {
                if (forward)
-                       blkno = INT_GET(info->forw, ARCH_CONVERT);
+                       blkno = be32_to_cpu(info->forw);
                else
-                       blkno = INT_GET(info->back, ARCH_CONVERT);
+                       blkno = be32_to_cpu(info->back);
                if (blkno == 0)
                        continue;
                error = xfs_da_read_buf(state->args->trans, state->args->dp,
@@ -1494,14 +1586,13 @@ xfs_attr_leaf_toosmall(xfs_da_state_t *state, int *action)
                ASSERT(bp != NULL);
 
                leaf = (xfs_attr_leafblock_t *)info;
-               count  = INT_GET(leaf->hdr.count, ARCH_CONVERT);
+               count  = be16_to_cpu(leaf->hdr.count);
                bytes  = state->blocksize - (state->blocksize>>2);
-               bytes -= INT_GET(leaf->hdr.usedbytes, ARCH_CONVERT);
+               bytes -= be16_to_cpu(leaf->hdr.usedbytes);
                leaf = bp->data;
-               ASSERT(INT_GET(leaf->hdr.info.magic, ARCH_CONVERT)
-                                               == XFS_ATTR_LEAF_MAGIC);
-               count += INT_GET(leaf->hdr.count, ARCH_CONVERT);
-               bytes -= INT_GET(leaf->hdr.usedbytes, ARCH_CONVERT);
+               ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_ATTR_LEAF_MAGIC);
+               count += be16_to_cpu(leaf->hdr.count);
+               bytes -= be16_to_cpu(leaf->hdr.usedbytes);
                bytes -= count * sizeof(xfs_attr_leaf_entry_t);
                bytes -= sizeof(xfs_attr_leaf_hdr_t);
                xfs_da_brelse(state->args->trans, bp);
@@ -1553,21 +1644,18 @@ xfs_attr_leaf_remove(xfs_dabuf_t *bp, xfs_da_args_t *args)
        xfs_mount_t *mp;
 
        leaf = bp->data;
-       ASSERT(INT_GET(leaf->hdr.info.magic, ARCH_CONVERT)
-                                               == XFS_ATTR_LEAF_MAGIC);
+       ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_ATTR_LEAF_MAGIC);
        hdr = &leaf->hdr;
        mp = args->trans->t_mountp;
-       ASSERT((INT_GET(hdr->count, ARCH_CONVERT) > 0)
-               && (INT_GET(hdr->count, ARCH_CONVERT) < (XFS_LBSIZE(mp)/8)));
+       ASSERT((be16_to_cpu(hdr->count) > 0)
+               && (be16_to_cpu(hdr->count) < (XFS_LBSIZE(mp)/8)));
        ASSERT((args->index >= 0)
-               && (args->index < INT_GET(hdr->count, ARCH_CONVERT)));
-       ASSERT(INT_GET(hdr->firstused, ARCH_CONVERT)
-                               >= ((INT_GET(hdr->count, ARCH_CONVERT)
-                                       * sizeof(*entry))+sizeof(*hdr)));
+               && (args->index < be16_to_cpu(hdr->count)));
+       ASSERT(be16_to_cpu(hdr->firstused) >=
+              ((be16_to_cpu(hdr->count) * sizeof(*entry)) + sizeof(*hdr)));
        entry = &leaf->entries[args->index];
-       ASSERT(INT_GET(entry->nameidx, ARCH_CONVERT)
-                               >= INT_GET(hdr->firstused, ARCH_CONVERT));
-       ASSERT(INT_GET(entry->nameidx, ARCH_CONVERT) < XFS_LBSIZE(mp));
+       ASSERT(be16_to_cpu(entry->nameidx) >= be16_to_cpu(hdr->firstused));
+       ASSERT(be16_to_cpu(entry->nameidx) < XFS_LBSIZE(mp));
 
        /*
         * Scan through free region table:
@@ -1575,33 +1663,30 @@ xfs_attr_leaf_remove(xfs_dabuf_t *bp, xfs_da_args_t *args)
         *    find smallest free region in case we need to replace it,
         *    adjust any map that borders the entry table,
         */
-       tablesize = INT_GET(hdr->count, ARCH_CONVERT)
-                                       * sizeof(xfs_attr_leaf_entry_t)
+       tablesize = be16_to_cpu(hdr->count) * sizeof(xfs_attr_leaf_entry_t)
                                        + sizeof(xfs_attr_leaf_hdr_t);
        map = &hdr->freemap[0];
-       tmp = INT_GET(map->size, ARCH_CONVERT);
+       tmp = be16_to_cpu(map->size);
        before = after = -1;
        smallest = XFS_ATTR_LEAF_MAPSIZE - 1;
        entsize = xfs_attr_leaf_entsize(leaf, args->index);
        for (i = 0; i < XFS_ATTR_LEAF_MAPSIZE; map++, i++) {
-               ASSERT(INT_GET(map->base, ARCH_CONVERT) < XFS_LBSIZE(mp));
-               ASSERT(INT_GET(map->size, ARCH_CONVERT) < XFS_LBSIZE(mp));
-               if (INT_GET(map->base, ARCH_CONVERT) == tablesize) {
-                       INT_MOD(map->base, ARCH_CONVERT,
-                                       -sizeof(xfs_attr_leaf_entry_t));
-                       INT_MOD(map->size, ARCH_CONVERT,
-                                       sizeof(xfs_attr_leaf_entry_t));
+               ASSERT(be16_to_cpu(map->base) < XFS_LBSIZE(mp));
+               ASSERT(be16_to_cpu(map->size) < XFS_LBSIZE(mp));
+               if (be16_to_cpu(map->base) == tablesize) {
+                       be16_add(&map->base,
+                                -((int)sizeof(xfs_attr_leaf_entry_t)));
+                       be16_add(&map->size, sizeof(xfs_attr_leaf_entry_t));
                }
 
-               if ((INT_GET(map->base, ARCH_CONVERT)
-                                       + INT_GET(map->size, ARCH_CONVERT))
-                               == INT_GET(entry->nameidx, ARCH_CONVERT)) {
+               if ((be16_to_cpu(map->base) + be16_to_cpu(map->size))
+                               == be16_to_cpu(entry->nameidx)) {
                        before = i;
-               } else if (INT_GET(map->base, ARCH_CONVERT)
-                       == (INT_GET(entry->nameidx, ARCH_CONVERT) + entsize)) {
+               } else if (be16_to_cpu(map->base)
+                       == (be16_to_cpu(entry->nameidx) + entsize)) {
                        after = i;
-               } else if (INT_GET(map->size, ARCH_CONVERT) < tmp) {
-                       tmp = INT_GET(map->size, ARCH_CONVERT);
+               } else if (be16_to_cpu(map->size) < tmp) {
+                       tmp = be16_to_cpu(map->size);
                        smallest = i;
                }
        }
@@ -1613,38 +1698,35 @@ xfs_attr_leaf_remove(xfs_dabuf_t *bp, xfs_da_args_t *args)
        if ((before >= 0) || (after >= 0)) {
                if ((before >= 0) && (after >= 0)) {
                        map = &hdr->freemap[before];
-                       INT_MOD(map->size, ARCH_CONVERT, entsize);
-                       INT_MOD(map->size, ARCH_CONVERT,
-                               INT_GET(hdr->freemap[after].size,
-                                                       ARCH_CONVERT));
+                       be16_add(&map->size, entsize);
+                       be16_add(&map->size,
+                                be16_to_cpu(hdr->freemap[after].size));
                        hdr->freemap[after].base = 0;
                        hdr->freemap[after].size = 0;
                } else if (before >= 0) {
                        map = &hdr->freemap[before];
-                       INT_MOD(map->size, ARCH_CONVERT, entsize);
+                       be16_add(&map->size, entsize);
                } else {
                        map = &hdr->freemap[after];
                        /* both on-disk, don't endian flip twice */
                        map->base = entry->nameidx;
-                       INT_MOD(map->size, ARCH_CONVERT, entsize);
+                       be16_add(&map->size, entsize);
                }
        } else {
                /*
                 * Replace smallest region (if it is smaller than free'd entry)
                 */
                map = &hdr->freemap[smallest];
-               if (INT_GET(map->size, ARCH_CONVERT) < entsize) {
-                       INT_SET(map->base, ARCH_CONVERT,
-                                       INT_GET(entry->nameidx, ARCH_CONVERT));
-                       INT_SET(map->size, ARCH_CONVERT, entsize);
+               if (be16_to_cpu(map->size) < entsize) {
+                       map->base = cpu_to_be16(be16_to_cpu(entry->nameidx));
+                       map->size = cpu_to_be16(entsize);
                }
        }
 
        /*
         * Did we remove the first entry?
         */
-       if (INT_GET(entry->nameidx, ARCH_CONVERT)
-                               == INT_GET(hdr->firstused, ARCH_CONVERT))
+       if (be16_to_cpu(entry->nameidx) == be16_to_cpu(hdr->firstused))
                smallest = 1;
        else
                smallest = 0;
@@ -1653,18 +1735,18 @@ xfs_attr_leaf_remove(xfs_dabuf_t *bp, xfs_da_args_t *args)
         * Compress the remaining entries and zero out the removed stuff.
         */
        memset(XFS_ATTR_LEAF_NAME(leaf, args->index), 0, entsize);
-       INT_MOD(hdr->usedbytes, ARCH_CONVERT, -entsize);
+       be16_add(&hdr->usedbytes, -entsize);
        xfs_da_log_buf(args->trans, bp,
             XFS_DA_LOGRANGE(leaf, XFS_ATTR_LEAF_NAME(leaf, args->index),
                                   entsize));
 
-       tmp = (INT_GET(hdr->count, ARCH_CONVERT) - args->index)
+       tmp = (be16_to_cpu(hdr->count) - args->index)
                                        * sizeof(xfs_attr_leaf_entry_t);
        memmove((char *)entry, (char *)(entry+1), tmp);
-       INT_MOD(hdr->count, ARCH_CONVERT, -1);
+       be16_add(&hdr->count, -1);
        xfs_da_log_buf(args->trans, bp,
            XFS_DA_LOGRANGE(leaf, entry, tmp + sizeof(*entry)));
-       entry = &leaf->entries[INT_GET(hdr->count, ARCH_CONVERT)];
+       entry = &leaf->entries[be16_to_cpu(hdr->count)];
        memset((char *)entry, 0, sizeof(xfs_attr_leaf_entry_t));
 
        /*
@@ -1676,18 +1758,17 @@ xfs_attr_leaf_remove(xfs_dabuf_t *bp, xfs_da_args_t *args)
        if (smallest) {
                tmp = XFS_LBSIZE(mp);
                entry = &leaf->entries[0];
-               for (i = INT_GET(hdr->count, ARCH_CONVERT)-1;
-                                               i >= 0; entry++, i--) {
-                       ASSERT(INT_GET(entry->nameidx, ARCH_CONVERT)
-                               >= INT_GET(hdr->firstused, ARCH_CONVERT));
-                       ASSERT(INT_GET(entry->nameidx, ARCH_CONVERT)
-                                                       < XFS_LBSIZE(mp));
-                       if (INT_GET(entry->nameidx, ARCH_CONVERT) < tmp)
-                               tmp = INT_GET(entry->nameidx, ARCH_CONVERT);
+               for (i = be16_to_cpu(hdr->count)-1; i >= 0; entry++, i--) {
+                       ASSERT(be16_to_cpu(entry->nameidx) >=
+                              be16_to_cpu(hdr->firstused));
+                       ASSERT(be16_to_cpu(entry->nameidx) < XFS_LBSIZE(mp));
+
+                       if (be16_to_cpu(entry->nameidx) < tmp)
+                               tmp = be16_to_cpu(entry->nameidx);
                }
-               INT_SET(hdr->firstused, ARCH_CONVERT, tmp);
+               hdr->firstused = cpu_to_be16(tmp);
                if (!hdr->firstused) {
-                       INT_SET(hdr->firstused, ARCH_CONVERT,
+                       hdr->firstused = cpu_to_be16(
                                        tmp - XFS_ATTR_LEAF_NAME_ALIGN);
                }
        } else {
@@ -1701,9 +1782,8 @@ xfs_attr_leaf_remove(xfs_dabuf_t *bp, xfs_da_args_t *args)
         * "join" the leaf with a sibling if so.
         */
        tmp  = sizeof(xfs_attr_leaf_hdr_t);
-       tmp += INT_GET(leaf->hdr.count, ARCH_CONVERT)
-                                       * sizeof(xfs_attr_leaf_entry_t);
-       tmp += INT_GET(leaf->hdr.usedbytes, ARCH_CONVERT);
+       tmp += be16_to_cpu(leaf->hdr.count) * sizeof(xfs_attr_leaf_entry_t);
+       tmp += be16_to_cpu(leaf->hdr.usedbytes);
        return(tmp < mp->m_attr_magicpct); /* leaf is < 37% full */
 }
 
@@ -1727,20 +1807,16 @@ xfs_attr_leaf_unbalance(xfs_da_state_t *state, xfs_da_state_blk_t *drop_blk,
        ASSERT(save_blk->magic == XFS_ATTR_LEAF_MAGIC);
        drop_leaf = drop_blk->bp->data;
        save_leaf = save_blk->bp->data;
-       ASSERT(INT_GET(drop_leaf->hdr.info.magic, ARCH_CONVERT)
-                                               == XFS_ATTR_LEAF_MAGIC);
-       ASSERT(INT_GET(save_leaf->hdr.info.magic, ARCH_CONVERT)
-                                               == XFS_ATTR_LEAF_MAGIC);
+       ASSERT(be16_to_cpu(drop_leaf->hdr.info.magic) == XFS_ATTR_LEAF_MAGIC);
+       ASSERT(be16_to_cpu(save_leaf->hdr.info.magic) == XFS_ATTR_LEAF_MAGIC);
        drop_hdr = &drop_leaf->hdr;
        save_hdr = &save_leaf->hdr;
 
        /*
         * Save last hashval from dying block for later Btree fixup.
         */
-       drop_blk->hashval =
-               INT_GET(drop_leaf->entries[INT_GET(drop_leaf->hdr.count,
-                                               ARCH_CONVERT)-1].hashval,
-                                                               ARCH_CONVERT);
+       drop_blk->hashval = be32_to_cpu(
+               drop_leaf->entries[be16_to_cpu(drop_leaf->hdr.count)-1].hashval);
 
        /*
         * Check if we need a temp buffer, or can we do it in place.
@@ -1754,12 +1830,11 @@ xfs_attr_leaf_unbalance(xfs_da_state_t *state, xfs_da_state_blk_t *drop_blk,
                 */
                if (xfs_attr_leaf_order(save_blk->bp, drop_blk->bp)) {
                        xfs_attr_leaf_moveents(drop_leaf, 0, save_leaf, 0,
-                            (int)INT_GET(drop_hdr->count, ARCH_CONVERT), mp);
+                            be16_to_cpu(drop_hdr->count), mp);
                } else {
                        xfs_attr_leaf_moveents(drop_leaf, 0, save_leaf,
-                                 INT_GET(save_hdr->count, ARCH_CONVERT),
-                                 (int)INT_GET(drop_hdr->count, ARCH_CONVERT),
-                                 mp);
+                                 be16_to_cpu(save_hdr->count),
+                                 be16_to_cpu(drop_hdr->count), mp);
                }
        } else {
                /*
@@ -1773,28 +1848,24 @@ xfs_attr_leaf_unbalance(xfs_da_state_t *state, xfs_da_state_blk_t *drop_blk,
                tmp_hdr = &tmp_leaf->hdr;
                tmp_hdr->info = save_hdr->info; /* struct copy */
                tmp_hdr->count = 0;
-               INT_SET(tmp_hdr->firstused, ARCH_CONVERT, state->blocksize);
+               tmp_hdr->firstused = cpu_to_be16(state->blocksize);
                if (!tmp_hdr->firstused) {
-                       INT_SET(tmp_hdr->firstused, ARCH_CONVERT,
+                       tmp_hdr->firstused = cpu_to_be16(
                                state->blocksize - XFS_ATTR_LEAF_NAME_ALIGN);
                }
                tmp_hdr->usedbytes = 0;
                if (xfs_attr_leaf_order(save_blk->bp, drop_blk->bp)) {
                        xfs_attr_leaf_moveents(drop_leaf, 0, tmp_leaf, 0,
-                               (int)INT_GET(drop_hdr->count, ARCH_CONVERT),
-                               mp);
+                               be16_to_cpu(drop_hdr->count), mp);
                        xfs_attr_leaf_moveents(save_leaf, 0, tmp_leaf,
-                                 INT_GET(tmp_leaf->hdr.count, ARCH_CONVERT),
-                                (int)INT_GET(save_hdr->count, ARCH_CONVERT),
-                                mp);
+                                 be16_to_cpu(tmp_leaf->hdr.count),
+                                 be16_to_cpu(save_hdr->count), mp);
                } else {
                        xfs_attr_leaf_moveents(save_leaf, 0, tmp_leaf, 0,
-                               (int)INT_GET(save_hdr->count, ARCH_CONVERT),
-                               mp);
+                               be16_to_cpu(save_hdr->count), mp);
                        xfs_attr_leaf_moveents(drop_leaf, 0, tmp_leaf,
-                               INT_GET(tmp_leaf->hdr.count, ARCH_CONVERT),
-                               (int)INT_GET(drop_hdr->count, ARCH_CONVERT),
-                               mp);
+                               be16_to_cpu(tmp_leaf->hdr.count),
+                               be16_to_cpu(drop_hdr->count), mp);
                }
                memcpy((char *)save_leaf, (char *)tmp_leaf, state->blocksize);
                kmem_free(tmpbuffer, state->blocksize);
@@ -1806,10 +1877,8 @@ xfs_attr_leaf_unbalance(xfs_da_state_t *state, xfs_da_state_blk_t *drop_blk,
        /*
         * Copy out last hashval in each block for B-tree code.
         */
-       save_blk->hashval =
-               INT_GET(save_leaf->entries[INT_GET(save_leaf->hdr.count,
-                                               ARCH_CONVERT)-1].hashval,
-                                                               ARCH_CONVERT);
+       save_blk->hashval = be32_to_cpu(
+               save_leaf->entries[be16_to_cpu(save_leaf->hdr.count)-1].hashval);
 }
 
 /*========================================================================
@@ -1840,48 +1909,45 @@ xfs_attr_leaf_lookup_int(xfs_dabuf_t *bp, xfs_da_args_t *args)
        xfs_dahash_t hashval;
 
        leaf = bp->data;
-       ASSERT(INT_GET(leaf->hdr.info.magic, ARCH_CONVERT)
-                                               == XFS_ATTR_LEAF_MAGIC);
-       ASSERT(INT_GET(leaf->hdr.count, ARCH_CONVERT)
+       ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_ATTR_LEAF_MAGIC);
+       ASSERT(be16_to_cpu(leaf->hdr.count)
                                        < (XFS_LBSIZE(args->dp->i_mount)/8));
 
        /*
         * Binary search.  (note: small blocks will skip this loop)
         */
        hashval = args->hashval;
-       probe = span = INT_GET(leaf->hdr.count, ARCH_CONVERT) / 2;
+       probe = span = be16_to_cpu(leaf->hdr.count) / 2;
        for (entry = &leaf->entries[probe]; span > 4;
                   entry = &leaf->entries[probe]) {
                span /= 2;
-               if (INT_GET(entry->hashval, ARCH_CONVERT) < hashval)
+               if (be32_to_cpu(entry->hashval) < hashval)
                        probe += span;
-               else if (INT_GET(entry->hashval, ARCH_CONVERT) > hashval)
+               else if (be32_to_cpu(entry->hashval) > hashval)
                        probe -= span;
                else
                        break;
        }
        ASSERT((probe >= 0) && 
               (!leaf->hdr.count
-              || (probe < INT_GET(leaf->hdr.count, ARCH_CONVERT))));
-       ASSERT((span <= 4) || (INT_GET(entry->hashval, ARCH_CONVERT)
-                                                       == hashval));
+              || (probe < be16_to_cpu(leaf->hdr.count))));
+       ASSERT((span <= 4) || (be32_to_cpu(entry->hashval) == hashval));
 
        /*
         * Since we may have duplicate hashval's, find the first matching
         * hashval in the leaf.
         */
-       while ((probe > 0) && (INT_GET(entry->hashval, ARCH_CONVERT)
-                                                       >= hashval)) {
+       while ((probe > 0) && (be32_to_cpu(entry->hashval) >= hashval)) {
                entry--;
                probe--;
        }
-       while ((probe < INT_GET(leaf->hdr.count, ARCH_CONVERT))
-               && (INT_GET(entry->hashval, ARCH_CONVERT) < hashval)) {
+       while ((probe < be16_to_cpu(leaf->hdr.count)) &&
+              (be32_to_cpu(entry->hashval) < hashval)) {
                entry++;
                probe++;
        }
-       if ((probe == INT_GET(leaf->hdr.count, ARCH_CONVERT))
-                   || (INT_GET(entry->hashval, ARCH_CONVERT) != hashval)) {
+       if ((probe == be16_to_cpu(leaf->hdr.count)) ||
+           (be32_to_cpu(entry->hashval) != hashval)) {
                args->index = probe;
                return(XFS_ERROR(ENOATTR));
        }
@@ -1889,8 +1955,8 @@ xfs_attr_leaf_lookup_int(xfs_dabuf_t *bp, xfs_da_args_t *args)
        /*
         * Duplicate keys may be present, so search all of them for a match.
         */
-       for (  ; (probe < INT_GET(leaf->hdr.count, ARCH_CONVERT))
-                       && (INT_GET(entry->hashval, ARCH_CONVERT) == hashval);
+       for (  ; (probe < be16_to_cpu(leaf->hdr.count)) &&
+                       (be32_to_cpu(entry->hashval) == hashval);
                        entry++, probe++) {
 /*
  * GROT: Add code to remove incomplete entries.
@@ -1932,11 +1998,9 @@ xfs_attr_leaf_lookup_int(xfs_dabuf_t *bp, xfs_da_args_t *args)
                            ((entry->flags & XFS_ATTR_ROOT) != 0))
                                continue;
                        args->index = probe;
-                       args->rmtblkno
-                                 = INT_GET(name_rmt->valueblk, ARCH_CONVERT);
+                       args->rmtblkno = be32_to_cpu(name_rmt->valueblk);
                        args->rmtblkcnt = XFS_B_TO_FSB(args->dp->i_mount,
-                                                  INT_GET(name_rmt->valuelen,
-                                                               ARCH_CONVERT));
+                                                  be32_to_cpu(name_rmt->valuelen));
                        return(XFS_ERROR(EEXIST));
                }
        }
@@ -1958,18 +2022,17 @@ xfs_attr_leaf_getvalue(xfs_dabuf_t *bp, xfs_da_args_t *args)
        xfs_attr_leaf_name_remote_t *name_rmt;
 
        leaf = bp->data;
-       ASSERT(INT_GET(leaf->hdr.info.magic, ARCH_CONVERT)
-                                               == XFS_ATTR_LEAF_MAGIC);
-       ASSERT(INT_GET(leaf->hdr.count, ARCH_CONVERT)
+       ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_ATTR_LEAF_MAGIC);
+       ASSERT(be16_to_cpu(leaf->hdr.count)
                                        < (XFS_LBSIZE(args->dp->i_mount)/8));
-       ASSERT(args->index < ((int)INT_GET(leaf->hdr.count, ARCH_CONVERT)));
+       ASSERT(args->index < be16_to_cpu(leaf->hdr.count));
 
        entry = &leaf->entries[args->index];
        if (entry->flags & XFS_ATTR_LOCAL) {
                name_loc = XFS_ATTR_LEAF_NAME_LOCAL(leaf, args->index);
                ASSERT(name_loc->namelen == args->namelen);
                ASSERT(memcmp(args->name, name_loc->nameval, args->namelen) == 0);
-               valuelen = INT_GET(name_loc->valuelen, ARCH_CONVERT);
+               valuelen = be16_to_cpu(name_loc->valuelen);
                if (args->flags & ATTR_KERNOVAL) {
                        args->valuelen = valuelen;
                        return(0);
@@ -1984,8 +2047,8 @@ xfs_attr_leaf_getvalue(xfs_dabuf_t *bp, xfs_da_args_t *args)
                name_rmt = XFS_ATTR_LEAF_NAME_REMOTE(leaf, args->index);
                ASSERT(name_rmt->namelen == args->namelen);
                ASSERT(memcmp(args->name, name_rmt->name, args->namelen) == 0);
-               valuelen = INT_GET(name_rmt->valuelen, ARCH_CONVERT);
-               args->rmtblkno = INT_GET(name_rmt->valueblk, ARCH_CONVERT);
+               valuelen = be32_to_cpu(name_rmt->valuelen);
+               args->rmtblkno = be32_to_cpu(name_rmt->valueblk);
                args->rmtblkcnt = XFS_B_TO_FSB(args->dp->i_mount, valuelen);
                if (args->flags & ATTR_KERNOVAL) {
                        args->valuelen = valuelen;
@@ -2027,32 +2090,29 @@ xfs_attr_leaf_moveents(xfs_attr_leafblock_t *leaf_s, int start_s,
        /*
         * Set up environment.
         */
-       ASSERT(INT_GET(leaf_s->hdr.info.magic, ARCH_CONVERT)
-                                               == XFS_ATTR_LEAF_MAGIC);
-       ASSERT(INT_GET(leaf_d->hdr.info.magic, ARCH_CONVERT)
-                                               == XFS_ATTR_LEAF_MAGIC);
+       ASSERT(be16_to_cpu(leaf_s->hdr.info.magic) == XFS_ATTR_LEAF_MAGIC);
+       ASSERT(be16_to_cpu(leaf_d->hdr.info.magic) == XFS_ATTR_LEAF_MAGIC);
        hdr_s = &leaf_s->hdr;
        hdr_d = &leaf_d->hdr;
-       ASSERT((INT_GET(hdr_s->count, ARCH_CONVERT) > 0)
-                               && (INT_GET(hdr_s->count, ARCH_CONVERT)
-                                               < (XFS_LBSIZE(mp)/8)));
-       ASSERT(INT_GET(hdr_s->firstused, ARCH_CONVERT) >=
-               ((INT_GET(hdr_s->count, ARCH_CONVERT)
+       ASSERT((be16_to_cpu(hdr_s->count) > 0) &&
+              (be16_to_cpu(hdr_s->count) < (XFS_LBSIZE(mp)/8)));
+       ASSERT(be16_to_cpu(hdr_s->firstused) >=
+               ((be16_to_cpu(hdr_s->count)
                                        * sizeof(*entry_s))+sizeof(*hdr_s)));
-       ASSERT(INT_GET(hdr_d->count, ARCH_CONVERT) < (XFS_LBSIZE(mp)/8));
-       ASSERT(INT_GET(hdr_d->firstused, ARCH_CONVERT) >=
-               ((INT_GET(hdr_d->count, ARCH_CONVERT)
+       ASSERT(be16_to_cpu(hdr_d->count) < (XFS_LBSIZE(mp)/8));
+       ASSERT(be16_to_cpu(hdr_d->firstused) >=
+               ((be16_to_cpu(hdr_d->count)
                                        * sizeof(*entry_d))+sizeof(*hdr_d)));
 
-       ASSERT(start_s < INT_GET(hdr_s->count, ARCH_CONVERT));
-       ASSERT(start_d <= INT_GET(hdr_d->count, ARCH_CONVERT));
-       ASSERT(count <= INT_GET(hdr_s->count, ARCH_CONVERT));
+       ASSERT(start_s < be16_to_cpu(hdr_s->count));
+       ASSERT(start_d <= be16_to_cpu(hdr_d->count));
+       ASSERT(count <= be16_to_cpu(hdr_s->count));
 
        /*
         * Move the entries in the destination leaf up to make a hole?
         */
-       if (start_d < INT_GET(hdr_d->count, ARCH_CONVERT)) {
-               tmp  = INT_GET(hdr_d->count, ARCH_CONVERT) - start_d;
+       if (start_d < be16_to_cpu(hdr_d->count)) {
+               tmp  = be16_to_cpu(hdr_d->count) - start_d;
                tmp *= sizeof(xfs_attr_leaf_entry_t);
                entry_s = &leaf_d->entries[start_d];
                entry_d = &leaf_d->entries[start_d + count];
@@ -2067,8 +2127,8 @@ xfs_attr_leaf_moveents(xfs_attr_leafblock_t *leaf_s, int start_s,
        entry_d = &leaf_d->entries[start_d];
        desti = start_d;
        for (i = 0; i < count; entry_s++, entry_d++, desti++, i++) {
-               ASSERT(INT_GET(entry_s->nameidx, ARCH_CONVERT)
-                               >= INT_GET(hdr_s->firstused, ARCH_CONVERT));
+               ASSERT(be16_to_cpu(entry_s->nameidx)
+                               >= be16_to_cpu(hdr_s->firstused));
                tmp = xfs_attr_leaf_entsize(leaf_s, start_s + i);
 #ifdef GROT
                /*
@@ -2078,35 +2138,35 @@ xfs_attr_leaf_moveents(xfs_attr_leafblock_t *leaf_s, int start_s,
                 */
                if (entry_s->flags & XFS_ATTR_INCOMPLETE) { /* skip partials? */
                        memset(XFS_ATTR_LEAF_NAME(leaf_s, start_s + i), 0, tmp);
-                       INT_MOD(hdr_s->usedbytes, ARCH_CONVERT, -tmp);
-                       INT_MOD(hdr_s->count, ARCH_CONVERT, -1);
+                       be16_add(&hdr_s->usedbytes, -tmp);
+                       be16_add(&hdr_s->count, -1);
                        entry_d--;      /* to compensate for ++ in loop hdr */
                        desti--;
                        if ((start_s + i) < offset)
                                result++;       /* insertion index adjustment */
                } else {
 #endif /* GROT */
-                       INT_MOD(hdr_d->firstused, ARCH_CONVERT, -tmp);
+                       be16_add(&hdr_d->firstused, -tmp);
                        /* both on-disk, don't endian flip twice */
                        entry_d->hashval = entry_s->hashval;
                        /* both on-disk, don't endian flip twice */
                        entry_d->nameidx = hdr_d->firstused;
                        entry_d->flags = entry_s->flags;
-                       ASSERT(INT_GET(entry_d->nameidx, ARCH_CONVERT) + tmp
+                       ASSERT(be16_to_cpu(entry_d->nameidx) + tmp
                                                        <= XFS_LBSIZE(mp));
                        memmove(XFS_ATTR_LEAF_NAME(leaf_d, desti),
                                XFS_ATTR_LEAF_NAME(leaf_s, start_s + i), tmp);
-                       ASSERT(INT_GET(entry_s->nameidx, ARCH_CONVERT) + tmp
+                       ASSERT(be16_to_cpu(entry_s->nameidx) + tmp
                                                        <= XFS_LBSIZE(mp));
                        memset(XFS_ATTR_LEAF_NAME(leaf_s, start_s + i), 0, tmp);
-                       INT_MOD(hdr_s->usedbytes, ARCH_CONVERT, -tmp);
-                       INT_MOD(hdr_d->usedbytes, ARCH_CONVERT, tmp);
-                       INT_MOD(hdr_s->count, ARCH_CONVERT, -1);
-                       INT_MOD(hdr_d->count, ARCH_CONVERT, 1);
-                       tmp = INT_GET(hdr_d->count, ARCH_CONVERT)
+                       be16_add(&hdr_s->usedbytes, -tmp);
+                       be16_add(&hdr_d->usedbytes, tmp);
+                       be16_add(&hdr_s->count, -1);
+                       be16_add(&hdr_d->count, 1);
+                       tmp = be16_to_cpu(hdr_d->count)
                                                * sizeof(xfs_attr_leaf_entry_t)
                                                + sizeof(xfs_attr_leaf_hdr_t);
-                       ASSERT(INT_GET(hdr_d->firstused, ARCH_CONVERT) >= tmp);
+                       ASSERT(be16_to_cpu(hdr_d->firstused) >= tmp);
 #ifdef GROT
                }
 #endif /* GROT */
@@ -2115,7 +2175,7 @@ xfs_attr_leaf_moveents(xfs_attr_leafblock_t *leaf_s, int start_s,
        /*
         * Zero out the entries we just copied.
         */
-       if (start_s == INT_GET(hdr_s->count, ARCH_CONVERT)) {
+       if (start_s == be16_to_cpu(hdr_s->count)) {
                tmp = count * sizeof(xfs_attr_leaf_entry_t);
                entry_s = &leaf_s->entries[start_s];
                ASSERT(((char *)entry_s + tmp) <=
@@ -2126,15 +2186,14 @@ xfs_attr_leaf_moveents(xfs_attr_leafblock_t *leaf_s, int start_s,
                 * Move the remaining entries down to fill the hole,
                 * then zero the entries at the top.
                 */
-               tmp  = INT_GET(hdr_s->count, ARCH_CONVERT) - count;
+               tmp  = be16_to_cpu(hdr_s->count) - count;
                tmp *= sizeof(xfs_attr_leaf_entry_t);
                entry_s = &leaf_s->entries[start_s + count];
                entry_d = &leaf_s->entries[start_s];
                memmove((char *)entry_d, (char *)entry_s, tmp);
 
                tmp = count * sizeof(xfs_attr_leaf_entry_t);
-               entry_s = &leaf_s->entries[INT_GET(hdr_s->count,
-                                                       ARCH_CONVERT)];
+               entry_s = &leaf_s->entries[be16_to_cpu(hdr_s->count)];
                ASSERT(((char *)entry_s + tmp) <=
                       ((char *)leaf_s + XFS_LBSIZE(mp)));
                memset((char *)entry_s, 0, tmp);
@@ -2143,14 +2202,11 @@ xfs_attr_leaf_moveents(xfs_attr_leafblock_t *leaf_s, int start_s,
        /*
         * Fill in the freemap information
         */
-       INT_SET(hdr_d->freemap[0].base, ARCH_CONVERT,
-                                       sizeof(xfs_attr_leaf_hdr_t));
-       INT_MOD(hdr_d->freemap[0].base, ARCH_CONVERT,
-                               INT_GET(hdr_d->count, ARCH_CONVERT)
-                                       * sizeof(xfs_attr_leaf_entry_t));
-       INT_SET(hdr_d->freemap[0].size, ARCH_CONVERT,
-                               INT_GET(hdr_d->firstused, ARCH_CONVERT)
-                             - INT_GET(hdr_d->freemap[0].base, ARCH_CONVERT));
+       hdr_d->freemap[0].base = cpu_to_be16(sizeof(xfs_attr_leaf_hdr_t));
+       be16_add(&hdr_d->freemap[0].base, be16_to_cpu(hdr_d->count) *
+                       sizeof(xfs_attr_leaf_entry_t));
+       hdr_d->freemap[0].size = cpu_to_be16(be16_to_cpu(hdr_d->firstused)
+                             - be16_to_cpu(hdr_d->freemap[0].base));
        hdr_d->freemap[1].base = 0;
        hdr_d->freemap[2].base = 0;
        hdr_d->freemap[1].size = 0;
@@ -2169,18 +2225,16 @@ xfs_attr_leaf_order(xfs_dabuf_t *leaf1_bp, xfs_dabuf_t *leaf2_bp)
 
        leaf1 = leaf1_bp->data;
        leaf2 = leaf2_bp->data;
-       ASSERT((INT_GET(leaf1->hdr.info.magic, ARCH_CONVERT)
-                                               == XFS_ATTR_LEAF_MAGIC) &&
-              (INT_GET(leaf2->hdr.info.magic, ARCH_CONVERT)
-                                               == XFS_ATTR_LEAF_MAGIC));
-       if (   (INT_GET(leaf1->hdr.count, ARCH_CONVERT) > 0)
-           && (INT_GET(leaf2->hdr.count, ARCH_CONVERT) > 0)
-           && (   (INT_GET(leaf2->entries[ 0 ].hashval, ARCH_CONVERT) <
-                     INT_GET(leaf1->entries[ 0 ].hashval, ARCH_CONVERT))
-               || (INT_GET(leaf2->entries[INT_GET(leaf2->hdr.count,
-                               ARCH_CONVERT)-1].hashval, ARCH_CONVERT) <
-                     INT_GET(leaf1->entries[INT_GET(leaf1->hdr.count,
-                               ARCH_CONVERT)-1].hashval, ARCH_CONVERT))) ) {
+       ASSERT((be16_to_cpu(leaf1->hdr.info.magic) == XFS_ATTR_LEAF_MAGIC) &&
+              (be16_to_cpu(leaf2->hdr.info.magic) == XFS_ATTR_LEAF_MAGIC));
+       if ((be16_to_cpu(leaf1->hdr.count) > 0) &&
+           (be16_to_cpu(leaf2->hdr.count) > 0) &&
+           ((be32_to_cpu(leaf2->entries[0].hashval) <
+             be32_to_cpu(leaf1->entries[0].hashval)) ||
+            (be32_to_cpu(leaf2->entries[
+                       be16_to_cpu(leaf2->hdr.count)-1].hashval) <
+             be32_to_cpu(leaf1->entries[
+                       be16_to_cpu(leaf1->hdr.count)-1].hashval)))) {
                return(1);
        }
        return(0);
@@ -2195,34 +2249,30 @@ xfs_attr_leaf_lasthash(xfs_dabuf_t *bp, int *count)
        xfs_attr_leafblock_t *leaf;
 
        leaf = bp->data;
-       ASSERT(INT_GET(leaf->hdr.info.magic, ARCH_CONVERT)
-                                               == XFS_ATTR_LEAF_MAGIC);
+       ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_ATTR_LEAF_MAGIC);
        if (count)
-               *count = INT_GET(leaf->hdr.count, ARCH_CONVERT);
+               *count = be16_to_cpu(leaf->hdr.count);
        if (!leaf->hdr.count)
                return(0);
-       return(INT_GET(leaf->entries[INT_GET(leaf->hdr.count,
-                               ARCH_CONVERT)-1].hashval, ARCH_CONVERT));
+       return be32_to_cpu(leaf->entries[be16_to_cpu(leaf->hdr.count)-1].hashval);
 }
 
 /*
  * Calculate the number of bytes used to store the indicated attribute
  * (whether local or remote only calculate bytes in this block).
  */
-int
+STATIC int
 xfs_attr_leaf_entsize(xfs_attr_leafblock_t *leaf, int index)
 {
        xfs_attr_leaf_name_local_t *name_loc;
        xfs_attr_leaf_name_remote_t *name_rmt;
        int size;
 
-       ASSERT(INT_GET(leaf->hdr.info.magic, ARCH_CONVERT)
-                                               == XFS_ATTR_LEAF_MAGIC);
+       ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_ATTR_LEAF_MAGIC);
        if (leaf->entries[index].flags & XFS_ATTR_LOCAL) {
                name_loc = XFS_ATTR_LEAF_NAME_LOCAL(leaf, index);
                size = XFS_ATTR_LEAF_ENTSIZE_LOCAL(name_loc->namelen,
-                                                  INT_GET(name_loc->valuelen,
-                                                               ARCH_CONVERT));
+                                                  be16_to_cpu(name_loc->valuelen));
        } else {
                name_rmt = XFS_ATTR_LEAF_NAME_REMOTE(leaf, index);
                size = XFS_ATTR_LEAF_ENTSIZE_REMOTE(name_rmt->namelen);
@@ -2237,17 +2287,17 @@ xfs_attr_leaf_entsize(xfs_attr_leafblock_t *leaf, int index)
  * a "local" or a "remote" attribute.
  */
 int
-xfs_attr_leaf_newentsize(xfs_da_args_t *args, int blocksize, int *local)
+xfs_attr_leaf_newentsize(int namelen, int valuelen, int blocksize, int *local)
 {
        int size;
 
-       size = XFS_ATTR_LEAF_ENTSIZE_LOCAL(args->namelen, args->valuelen);
+       size = XFS_ATTR_LEAF_ENTSIZE_LOCAL(namelen, valuelen);
        if (size < XFS_ATTR_LEAF_ENTSIZE_LOCAL_MAX(blocksize)) {
                if (local) {
                        *local = 1;
                }
        } else {
-               size = XFS_ATTR_LEAF_ENTSIZE_REMOTE(args->namelen);
+               size = XFS_ATTR_LEAF_ENTSIZE_REMOTE(namelen);
                if (local) {
                        *local = 0;
                }
@@ -2280,22 +2330,20 @@ xfs_attr_leaf_list_int(xfs_dabuf_t *bp, xfs_attr_list_context_t *context)
         */
        if (context->resynch) {
                entry = &leaf->entries[0];
-               for (i = 0; i < INT_GET(leaf->hdr.count, ARCH_CONVERT);
-                                                       entry++, i++) {
-                       if (INT_GET(entry->hashval, ARCH_CONVERT)
-                                                       == cursor->hashval) {
+               for (i = 0; i < be16_to_cpu(leaf->hdr.count); entry++, i++) {
+                       if (be32_to_cpu(entry->hashval) == cursor->hashval) {
                                if (cursor->offset == context->dupcnt) {
                                        context->dupcnt = 0;
                                        break;
                                }
                                context->dupcnt++;
-                       } else if (INT_GET(entry->hashval, ARCH_CONVERT)
-                                                       > cursor->hashval) {
+                       } else if (be32_to_cpu(entry->hashval) >
+                                       cursor->hashval) {
                                context->dupcnt = 0;
                                break;
                        }
                }
-               if (i == INT_GET(leaf->hdr.count, ARCH_CONVERT)) {
+               if (i == be16_to_cpu(leaf->hdr.count)) {
                        xfs_attr_trace_l_c("not found", context);
                        return(0);
                }
@@ -2309,12 +2357,12 @@ xfs_attr_leaf_list_int(xfs_dabuf_t *bp, xfs_attr_list_context_t *context)
         * We have found our place, start copying out the new attributes.
         */
        retval = 0;
-       for (  ; (i < INT_GET(leaf->hdr.count, ARCH_CONVERT))
+       for (  ; (i < be16_to_cpu(leaf->hdr.count))
             && (retval == 0); entry++, i++) {
                attrnames_t     *namesp;
 
-               if (INT_GET(entry->hashval, ARCH_CONVERT) != cursor->hashval) {
-                       cursor->hashval = INT_GET(entry->hashval, ARCH_CONVERT);
+               if (be32_to_cpu(entry->hashval) != cursor->hashval) {
+                       cursor->hashval = be32_to_cpu(entry->hashval);
                        cursor->offset = 0;
                }
 
@@ -2343,8 +2391,7 @@ xfs_attr_leaf_list_int(xfs_dabuf_t *bp, xfs_attr_list_context_t *context)
                                retval = xfs_attr_put_listent(context, namesp,
                                        (char *)name_loc->nameval,
                                        (int)name_loc->namelen,
-                                       (int)INT_GET(name_loc->valuelen,
-                                                               ARCH_CONVERT));
+                                       be16_to_cpu(name_loc->valuelen));
                        }
                } else {
                        name_rmt = XFS_ATTR_LEAF_NAME_REMOTE(leaf, i);
@@ -2356,8 +2403,7 @@ xfs_attr_leaf_list_int(xfs_dabuf_t *bp, xfs_attr_list_context_t *context)
                                retval = xfs_attr_put_listent(context, namesp,
                                        (char *)name_rmt->name,
                                        (int)name_rmt->namelen,
-                                       (int)INT_GET(name_rmt->valuelen,
-                                                               ARCH_CONVERT));
+                                       be32_to_cpu(name_rmt->valuelen));
                        }
                }
                if (retval == 0) {
@@ -2380,7 +2426,7 @@ xfs_attr_leaf_list_int(xfs_dabuf_t *bp, xfs_attr_list_context_t *context)
  * we may be reading them directly out of a user buffer.
  */
 /*ARGSUSED*/
-int
+STATIC int
 xfs_attr_put_listent(xfs_attr_list_context_t *context,
                     attrnames_t *namesp, char *name, int namelen, int valuelen)
 {
@@ -2464,9 +2510,8 @@ xfs_attr_leaf_clearflag(xfs_da_args_t *args)
        ASSERT(bp != NULL);
 
        leaf = bp->data;
-       ASSERT(INT_GET(leaf->hdr.info.magic, ARCH_CONVERT)
-                                               == XFS_ATTR_LEAF_MAGIC);
-       ASSERT(args->index < INT_GET(leaf->hdr.count, ARCH_CONVERT));
+       ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_ATTR_LEAF_MAGIC);
+       ASSERT(args->index < be16_to_cpu(leaf->hdr.count));
        ASSERT(args->index >= 0);
        entry = &leaf->entries[ args->index ];
        ASSERT(entry->flags & XFS_ATTR_INCOMPLETE);
@@ -2481,7 +2526,7 @@ xfs_attr_leaf_clearflag(xfs_da_args_t *args)
                namelen = name_rmt->namelen;
                name = (char *)name_rmt->name;
        }
-       ASSERT(INT_GET(entry->hashval, ARCH_CONVERT) == args->hashval);
+       ASSERT(be32_to_cpu(entry->hashval) == args->hashval);
        ASSERT(namelen == args->namelen);
        ASSERT(memcmp(name, args->name, namelen) == 0);
 #endif /* DEBUG */
@@ -2493,8 +2538,8 @@ xfs_attr_leaf_clearflag(xfs_da_args_t *args)
        if (args->rmtblkno) {
                ASSERT((entry->flags & XFS_ATTR_LOCAL) == 0);
                name_rmt = XFS_ATTR_LEAF_NAME_REMOTE(leaf, args->index);
-               INT_SET(name_rmt->valueblk, ARCH_CONVERT, args->rmtblkno);
-               INT_SET(name_rmt->valuelen, ARCH_CONVERT, args->valuelen);
+               name_rmt->valueblk = cpu_to_be32(args->rmtblkno);
+               name_rmt->valuelen = cpu_to_be32(args->valuelen);
                xfs_da_log_buf(args->trans, bp,
                         XFS_DA_LOGRANGE(leaf, name_rmt, sizeof(*name_rmt)));
        }
@@ -2531,9 +2576,8 @@ xfs_attr_leaf_setflag(xfs_da_args_t *args)
        ASSERT(bp != NULL);
 
        leaf = bp->data;
-       ASSERT(INT_GET(leaf->hdr.info.magic, ARCH_CONVERT)
-                                               == XFS_ATTR_LEAF_MAGIC);
-       ASSERT(args->index < INT_GET(leaf->hdr.count, ARCH_CONVERT));
+       ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_ATTR_LEAF_MAGIC);
+       ASSERT(args->index < be16_to_cpu(leaf->hdr.count));
        ASSERT(args->index >= 0);
        entry = &leaf->entries[ args->index ];
 
@@ -2604,16 +2648,14 @@ xfs_attr_leaf_flipflags(xfs_da_args_t *args)
        }
 
        leaf1 = bp1->data;
-       ASSERT(INT_GET(leaf1->hdr.info.magic, ARCH_CONVERT)
-                                               == XFS_ATTR_LEAF_MAGIC);
-       ASSERT(args->index < INT_GET(leaf1->hdr.count, ARCH_CONVERT));
+       ASSERT(be16_to_cpu(leaf1->hdr.info.magic) == XFS_ATTR_LEAF_MAGIC);
+       ASSERT(args->index < be16_to_cpu(leaf1->hdr.count));
        ASSERT(args->index >= 0);
        entry1 = &leaf1->entries[ args->index ];
 
        leaf2 = bp2->data;
-       ASSERT(INT_GET(leaf2->hdr.info.magic, ARCH_CONVERT)
-                                               == XFS_ATTR_LEAF_MAGIC);
-       ASSERT(args->index2 < INT_GET(leaf2->hdr.count, ARCH_CONVERT));
+       ASSERT(be16_to_cpu(leaf2->hdr.info.magic) == XFS_ATTR_LEAF_MAGIC);
+       ASSERT(args->index2 < be16_to_cpu(leaf2->hdr.count));
        ASSERT(args->index2 >= 0);
        entry2 = &leaf2->entries[ args->index2 ];
 
@@ -2636,7 +2678,7 @@ xfs_attr_leaf_flipflags(xfs_da_args_t *args)
                namelen2 = name_rmt->namelen;
                name2 = (char *)name_rmt->name;
        }
-       ASSERT(INT_GET(entry1->hashval, ARCH_CONVERT) == INT_GET(entry2->hashval, ARCH_CONVERT));
+       ASSERT(be32_to_cpu(entry1->hashval) == be32_to_cpu(entry2->hashval));
        ASSERT(namelen1 == namelen2);
        ASSERT(memcmp(name1, name2, namelen1) == 0);
 #endif /* DEBUG */
@@ -2650,8 +2692,8 @@ xfs_attr_leaf_flipflags(xfs_da_args_t *args)
        if (args->rmtblkno) {
                ASSERT((entry1->flags & XFS_ATTR_LOCAL) == 0);
                name_rmt = XFS_ATTR_LEAF_NAME_REMOTE(leaf1, args->index);
-               INT_SET(name_rmt->valueblk, ARCH_CONVERT, args->rmtblkno);
-               INT_SET(name_rmt->valuelen, ARCH_CONVERT, args->valuelen);
+               name_rmt->valueblk = cpu_to_be32(args->rmtblkno);
+               name_rmt->valuelen = cpu_to_be32(args->valuelen);
                xfs_da_log_buf(args->trans, bp1,
                         XFS_DA_LOGRANGE(leaf1, name_rmt, sizeof(*name_rmt)));
        }
@@ -2710,9 +2752,9 @@ xfs_attr_root_inactive(xfs_trans_t **trans, xfs_inode_t *dp)
         * This is a depth-first traversal!
         */
        info = bp->data;
-       if (INT_GET(info->magic, ARCH_CONVERT) == XFS_DA_NODE_MAGIC) {
+       if (be16_to_cpu(info->magic) == XFS_DA_NODE_MAGIC) {
                error = xfs_attr_node_inactive(trans, dp, bp, 1);
-       } else if (INT_GET(info->magic, ARCH_CONVERT) == XFS_ATTR_LEAF_MAGIC) {
+       } else if (be16_to_cpu(info->magic) == XFS_ATTR_LEAF_MAGIC) {
                error = xfs_attr_leaf_inactive(trans, dp, bp);
        } else {
                error = XFS_ERROR(EIO);
@@ -2740,7 +2782,7 @@ xfs_attr_root_inactive(xfs_trans_t **trans, xfs_inode_t *dp)
  * Recurse (gasp!) through the attribute nodes until we find leaves.
  * We're doing a depth-first traversal in order to invalidate everything.
  */
-int
+STATIC int
 xfs_attr_node_inactive(xfs_trans_t **trans, xfs_inode_t *dp, xfs_dabuf_t *bp,
                                   int level)
 {
@@ -2760,15 +2802,14 @@ xfs_attr_node_inactive(xfs_trans_t **trans, xfs_inode_t *dp, xfs_dabuf_t *bp,
        }
 
        node = bp->data;
-       ASSERT(INT_GET(node->hdr.info.magic, ARCH_CONVERT)
-                                               == XFS_DA_NODE_MAGIC);
+       ASSERT(be16_to_cpu(node->hdr.info.magic) == XFS_DA_NODE_MAGIC);
        parent_blkno = xfs_da_blkno(bp);        /* save for re-read later */
-       count = INT_GET(node->hdr.count, ARCH_CONVERT);
+       count = be16_to_cpu(node->hdr.count);
        if (!count) {
                xfs_da_brelse(*trans, bp);
                return(0);
        }
-       child_fsb = INT_GET(node->btree[0].before, ARCH_CONVERT);
+       child_fsb = be32_to_cpu(node->btree[0].before);
        xfs_da_brelse(*trans, bp);      /* no locks for later trans */
 
        /*
@@ -2795,12 +2836,10 @@ xfs_attr_node_inactive(xfs_trans_t **trans, xfs_inode_t *dp, xfs_dabuf_t *bp,
                         * Invalidate the subtree, however we have to.
                         */
                        info = child_bp->data;
-                       if (INT_GET(info->magic, ARCH_CONVERT)
-                                                       == XFS_DA_NODE_MAGIC) {
+                       if (be16_to_cpu(info->magic) == XFS_DA_NODE_MAGIC) {
                                error = xfs_attr_node_inactive(trans, dp,
                                                child_bp, level+1);
-                       } else if (INT_GET(info->magic, ARCH_CONVERT)
-                                               == XFS_ATTR_LEAF_MAGIC) {
+                       } else if (be16_to_cpu(info->magic) == XFS_ATTR_LEAF_MAGIC) {
                                error = xfs_attr_leaf_inactive(trans, dp,
                                                child_bp);
                        } else {
@@ -2830,7 +2869,7 @@ xfs_attr_node_inactive(xfs_trans_t **trans, xfs_inode_t *dp, xfs_dabuf_t *bp,
                                &bp, XFS_ATTR_FORK);
                        if (error)
                                return(error);
-                       child_fsb = INT_GET(node->btree[i+1].before, ARCH_CONVERT);
+                       child_fsb = be32_to_cpu(node->btree[i+1].before);
                        xfs_da_brelse(*trans, bp);
                }
                /*
@@ -2849,7 +2888,7 @@ xfs_attr_node_inactive(xfs_trans_t **trans, xfs_inode_t *dp, xfs_dabuf_t *bp,
  * Note that we must release the lock on the buffer so that we are not
  * caught holding something that the logging code wants to flush to disk.
  */
-int
+STATIC int
 xfs_attr_leaf_inactive(xfs_trans_t **trans, xfs_inode_t *dp, xfs_dabuf_t *bp)
 {
        xfs_attr_leafblock_t *leaf;
@@ -2859,17 +2898,16 @@ xfs_attr_leaf_inactive(xfs_trans_t **trans, xfs_inode_t *dp, xfs_dabuf_t *bp)
        int error, count, size, tmp, i;
 
        leaf = bp->data;
-       ASSERT(INT_GET(leaf->hdr.info.magic, ARCH_CONVERT)
-                                               == XFS_ATTR_LEAF_MAGIC);
+       ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_ATTR_LEAF_MAGIC);
 
        /*
         * Count the number of "remote" value extents.
         */
        count = 0;
        entry = &leaf->entries[0];
-       for (i = 0; i < INT_GET(leaf->hdr.count, ARCH_CONVERT); entry++, i++) {
-               if (   INT_GET(entry->nameidx, ARCH_CONVERT)
-                   && ((entry->flags & XFS_ATTR_LOCAL) == 0)) {
+       for (i = 0; i < be16_to_cpu(leaf->hdr.count); entry++, i++) {
+               if (be16_to_cpu(entry->nameidx) &&
+                   ((entry->flags & XFS_ATTR_LOCAL) == 0)) {
                        name_rmt = XFS_ATTR_LEAF_NAME_REMOTE(leaf, i);
                        if (name_rmt->valueblk)
                                count++;
@@ -2895,17 +2933,14 @@ xfs_attr_leaf_inactive(xfs_trans_t **trans, xfs_inode_t *dp, xfs_dabuf_t *bp)
         */
        lp = list;
        entry = &leaf->entries[0];
-       for (i = 0; i < INT_GET(leaf->hdr.count, ARCH_CONVERT); entry++, i++) {
-               if (   INT_GET(entry->nameidx, ARCH_CONVERT)
-                   && ((entry->flags & XFS_ATTR_LOCAL) == 0)) {
+       for (i = 0; i < be16_to_cpu(leaf->hdr.count); entry++, i++) {
+               if (be16_to_cpu(entry->nameidx) &&
+                   ((entry->flags & XFS_ATTR_LOCAL) == 0)) {
                        name_rmt = XFS_ATTR_LEAF_NAME_REMOTE(leaf, i);
                        if (name_rmt->valueblk) {
-                               /* both on-disk, don't endian flip twice */
-                               lp->valueblk = name_rmt->valueblk;
-                               INT_SET(lp->valuelen, ARCH_CONVERT,
-                                               XFS_B_TO_FSB(dp->i_mount,
-                                                   INT_GET(name_rmt->valuelen,
-                                                             ARCH_CONVERT)));
+                               lp->valueblk = be32_to_cpu(name_rmt->valueblk);
+                               lp->valuelen = XFS_B_TO_FSB(dp->i_mount,
+                                                   be32_to_cpu(name_rmt->valuelen));
                                lp++;
                        }
                }
@@ -2918,10 +2953,8 @@ xfs_attr_leaf_inactive(xfs_trans_t **trans, xfs_inode_t *dp, xfs_dabuf_t *bp)
        error = 0;
        for (lp = list, i = 0; i < count; i++, lp++) {
                tmp = xfs_attr_leaf_freextent(trans, dp,
-                                                    INT_GET(lp->valueblk,
-                                                               ARCH_CONVERT),
-                                                    INT_GET(lp->valuelen,
-                                                               ARCH_CONVERT));
+                               lp->valueblk, lp->valuelen);
+
                if (error == 0)
                        error = tmp;    /* save only the 1st errno */
        }
@@ -2934,7 +2967,7 @@ xfs_attr_leaf_inactive(xfs_trans_t **trans, xfs_inode_t *dp, xfs_dabuf_t *bp)
  * Look at all the extents for this logical region,
  * invalidate any buffers that are incore/in transactions.
  */
-int
+STATIC int
 xfs_attr_leaf_freextent(xfs_trans_t **trans, xfs_inode_t *dp,
                                    xfs_dablk_t blkno, int blkcnt)
 {