aboutsummaryrefslogtreecommitdiffstats
path: root/fs/xfs
diff options
context:
space:
mode:
Diffstat (limited to 'fs/xfs')
-rw-r--r--fs/xfs/xfs_da_btree.c2
-rw-r--r--fs/xfs/xfs_dir.c11
-rw-r--r--fs/xfs/xfs_dir_leaf.c326
-rw-r--r--fs/xfs/xfs_dir_leaf.h14
4 files changed, 182 insertions, 171 deletions
diff --git a/fs/xfs/xfs_da_btree.c b/fs/xfs/xfs_da_btree.c
index 47b86f9f69f9..296aa525ac42 100644
--- a/fs/xfs/xfs_da_btree.c
+++ b/fs/xfs/xfs_da_btree.c
@@ -1786,7 +1786,7 @@ xfs_da_swap_lastblock(xfs_da_args_t *args, xfs_dablk_t *dead_blknop,
1786 dead_leaf = (xfs_dir_leafblock_t *)dead_info; 1786 dead_leaf = (xfs_dir_leafblock_t *)dead_info;
1787 dead_level = 0; 1787 dead_level = 0;
1788 dead_hash = 1788 dead_hash =
1789 INT_GET(dead_leaf->entries[INT_GET(dead_leaf->hdr.count, ARCH_CONVERT) - 1].hashval, ARCH_CONVERT); 1789 INT_GET(dead_leaf->entries[be16_to_cpu(dead_leaf->hdr.count) - 1].hashval, ARCH_CONVERT);
1790 } else if (be16_to_cpu(dead_info->magic) == XFS_DIR2_LEAFN_MAGIC) { 1790 } else if (be16_to_cpu(dead_info->magic) == XFS_DIR2_LEAFN_MAGIC) {
1791 ASSERT(XFS_DIR_IS_V2(mp)); 1791 ASSERT(XFS_DIR_IS_V2(mp));
1792 dead_leaf2 = (xfs_dir2_leaf_t *)dead_info; 1792 dead_leaf2 = (xfs_dir2_leaf_t *)dead_info;
diff --git a/fs/xfs/xfs_dir.c b/fs/xfs/xfs_dir.c
index 9cc702a839a3..a3b0e97dbf96 100644
--- a/fs/xfs/xfs_dir.c
+++ b/fs/xfs/xfs_dir.c
@@ -638,8 +638,8 @@ xfs_dir_leaf_removename(xfs_da_args_t *args, int *count, int *totallen)
638 retval = xfs_dir_leaf_lookup_int(bp, args, &index); 638 retval = xfs_dir_leaf_lookup_int(bp, args, &index);
639 if (retval == EEXIST) { 639 if (retval == EEXIST) {
640 (void)xfs_dir_leaf_remove(args->trans, bp, index); 640 (void)xfs_dir_leaf_remove(args->trans, bp, index);
641 *count = INT_GET(leaf->hdr.count, ARCH_CONVERT); 641 *count = be16_to_cpu(leaf->hdr.count);
642 *totallen = INT_GET(leaf->hdr.namebytes, ARCH_CONVERT); 642 *totallen = be16_to_cpu(leaf->hdr.namebytes);
643 retval = 0; 643 retval = 0;
644 } 644 }
645 xfs_da_buf_done(bp); 645 xfs_da_buf_done(bp);
@@ -925,7 +925,7 @@ xfs_dir_node_getdents(xfs_trans_t *trans, xfs_inode_t *dp, uio_t *uio,
925 bp = NULL; 925 bp = NULL;
926 } 926 }
927 if (bp && 927 if (bp &&
928 cookhash > INT_GET(leaf->entries[INT_GET(leaf->hdr.count, ARCH_CONVERT) - 1].hashval, ARCH_CONVERT)) { 928 cookhash > INT_GET(leaf->entries[be16_to_cpu(leaf->hdr.count) - 1].hashval, ARCH_CONVERT)) {
929 xfs_dir_trace_g_dub("node: leaf hash too small", 929 xfs_dir_trace_g_dub("node: leaf hash too small",
930 dp, uio, bno); 930 dp, uio, bno);
931 xfs_da_brelse(trans, bp); 931 xfs_da_brelse(trans, bp);
@@ -1142,7 +1142,7 @@ void
1142xfs_dir_trace_g_dul(char *where, xfs_inode_t *dp, uio_t *uio, 1142xfs_dir_trace_g_dul(char *where, xfs_inode_t *dp, uio_t *uio,
1143 xfs_dir_leafblock_t *leaf) 1143 xfs_dir_leafblock_t *leaf)
1144{ 1144{
1145 int last = INT_GET(leaf->hdr.count, ARCH_CONVERT) - 1; 1145 int last = be16_to_cpu(leaf->hdr.count) - 1;
1146 1146
1147 xfs_dir_trace_enter(XFS_DIR_KTRACE_G_DUL, where, 1147 xfs_dir_trace_enter(XFS_DIR_KTRACE_G_DUL, where,
1148 (void *)dp, (void *)dp->i_mount, 1148 (void *)dp, (void *)dp->i_mount,
@@ -1150,8 +1150,7 @@ xfs_dir_trace_g_dul(char *where, xfs_inode_t *dp, uio_t *uio,
1150 (void *)((unsigned long)(uio->uio_offset & 0xFFFFFFFF)), 1150 (void *)((unsigned long)(uio->uio_offset & 0xFFFFFFFF)),
1151 (void *)(unsigned long)uio->uio_resid, 1151 (void *)(unsigned long)uio->uio_resid,
1152 (void *)(unsigned long)be32_to_cpu(leaf->hdr.info.forw), 1152 (void *)(unsigned long)be32_to_cpu(leaf->hdr.info.forw),
1153 (void *)(unsigned long) 1153 (void *)(unsigned long)be16_to_cpu(leaf->hdr.count),
1154 INT_GET(leaf->hdr.count, ARCH_CONVERT),
1155 (void *)(unsigned long) 1154 (void *)(unsigned long)
1156 INT_GET(leaf->entries[0].hashval, ARCH_CONVERT), 1155 INT_GET(leaf->entries[0].hashval, ARCH_CONVERT),
1157 (void *)(unsigned long) 1156 (void *)(unsigned long)
diff --git a/fs/xfs/xfs_dir_leaf.c b/fs/xfs/xfs_dir_leaf.c
index 6d711869262f..6a4d8caaba7b 100644
--- a/fs/xfs/xfs_dir_leaf.c
+++ b/fs/xfs/xfs_dir_leaf.c
@@ -651,7 +651,7 @@ xfs_dir_leaf_to_shortform(xfs_da_args_t *iargs)
651 */ 651 */
652 hdr = &leaf->hdr; 652 hdr = &leaf->hdr;
653 entry = &leaf->entries[0]; 653 entry = &leaf->entries[0];
654 for (i = INT_GET(hdr->count, ARCH_CONVERT)-1; i >= 0; entry++, i--) { 654 for (i = be16_to_cpu(hdr->count)-1; i >= 0; entry++, i--) {
655 namest = XFS_DIR_LEAF_NAMESTRUCT(leaf, INT_GET(entry->nameidx, ARCH_CONVERT)); 655 namest = XFS_DIR_LEAF_NAMESTRUCT(leaf, INT_GET(entry->nameidx, ARCH_CONVERT));
656 if ((entry->namelen == 2) && 656 if ((entry->namelen == 2) &&
657 (namest->name[0] == '.') && 657 (namest->name[0] == '.') &&
@@ -681,7 +681,7 @@ xfs_dir_leaf_to_shortform(xfs_da_args_t *iargs)
681 args.trans = iargs->trans; 681 args.trans = iargs->trans;
682 args.justcheck = 0; 682 args.justcheck = 0;
683 args.addname = args.oknoent = 1; 683 args.addname = args.oknoent = 1;
684 for (i = 0; i < INT_GET(hdr->count, ARCH_CONVERT); entry++, i++) { 684 for (i = 0; i < be16_to_cpu(hdr->count); entry++, i++) {
685 if (!entry->nameidx) 685 if (!entry->nameidx)
686 continue; 686 continue;
687 namest = XFS_DIR_LEAF_NAMESTRUCT(leaf, INT_GET(entry->nameidx, ARCH_CONVERT)); 687 namest = XFS_DIR_LEAF_NAMESTRUCT(leaf, INT_GET(entry->nameidx, ARCH_CONVERT));
@@ -744,7 +744,7 @@ xfs_dir_leaf_to_node(xfs_da_args_t *args)
744 ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_DIR_LEAF_MAGIC); 744 ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_DIR_LEAF_MAGIC);
745 node->btree[0].hashval = cpu_to_be32( 745 node->btree[0].hashval = cpu_to_be32(
746 INT_GET(leaf->entries[ 746 INT_GET(leaf->entries[
747 INT_GET(leaf->hdr.count, ARCH_CONVERT)-1].hashval, ARCH_CONVERT)); 747 be16_to_cpu(leaf->hdr.count)-1].hashval, ARCH_CONVERT));
748 xfs_da_buf_done(bp2); 748 xfs_da_buf_done(bp2);
749 node->btree[0].before = cpu_to_be32(blkno); 749 node->btree[0].before = cpu_to_be32(blkno);
750 node->hdr.count = cpu_to_be16(1); 750 node->hdr.count = cpu_to_be16(1);
@@ -783,11 +783,12 @@ xfs_dir_leaf_create(xfs_da_args_t *args, xfs_dablk_t blkno, xfs_dabuf_t **bpp)
783 memset((char *)leaf, 0, XFS_LBSIZE(dp->i_mount)); 783 memset((char *)leaf, 0, XFS_LBSIZE(dp->i_mount));
784 hdr = &leaf->hdr; 784 hdr = &leaf->hdr;
785 hdr->info.magic = cpu_to_be16(XFS_DIR_LEAF_MAGIC); 785 hdr->info.magic = cpu_to_be16(XFS_DIR_LEAF_MAGIC);
786 INT_SET(hdr->firstused, ARCH_CONVERT, XFS_LBSIZE(dp->i_mount)); 786 hdr->firstused = cpu_to_be16(XFS_LBSIZE(dp->i_mount));
787 if (!hdr->firstused) 787 if (!hdr->firstused)
788 INT_SET(hdr->firstused, ARCH_CONVERT, XFS_LBSIZE(dp->i_mount) - 1); 788 hdr->firstused = cpu_to_be16(XFS_LBSIZE(dp->i_mount) - 1);
789 INT_SET(hdr->freemap[0].base, ARCH_CONVERT, sizeof(xfs_dir_leaf_hdr_t)); 789 hdr->freemap[0].base = cpu_to_be16(sizeof(xfs_dir_leaf_hdr_t));
790 INT_SET(hdr->freemap[0].size, ARCH_CONVERT, INT_GET(hdr->firstused, ARCH_CONVERT) - INT_GET(hdr->freemap[0].base, ARCH_CONVERT)); 790 hdr->freemap[0].size = cpu_to_be16(be16_to_cpu(hdr->firstused) -
791 be16_to_cpu(hdr->freemap[0].base));
791 792
792 xfs_da_log_buf(args->trans, bp, 0, XFS_LBSIZE(dp->i_mount) - 1); 793 xfs_da_log_buf(args->trans, bp, 0, XFS_LBSIZE(dp->i_mount) - 1);
793 794
@@ -862,7 +863,7 @@ xfs_dir_leaf_add(xfs_dabuf_t *bp, xfs_da_args_t *args, int index)
862 863
863 leaf = bp->data; 864 leaf = bp->data;
864 ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_DIR_LEAF_MAGIC); 865 ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_DIR_LEAF_MAGIC);
865 ASSERT((index >= 0) && (index <= INT_GET(leaf->hdr.count, ARCH_CONVERT))); 866 ASSERT((index >= 0) && (index <= be16_to_cpu(leaf->hdr.count)));
866 hdr = &leaf->hdr; 867 hdr = &leaf->hdr;
867 entsize = XFS_DIR_LEAF_ENTSIZE_BYNAME(args->namelen); 868 entsize = XFS_DIR_LEAF_ENTSIZE_BYNAME(args->namelen);
868 869
@@ -870,25 +871,25 @@ xfs_dir_leaf_add(xfs_dabuf_t *bp, xfs_da_args_t *args, int index)
870 * Search through freemap for first-fit on new name length. 871 * Search through freemap for first-fit on new name length.
871 * (may need to figure in size of entry struct too) 872 * (may need to figure in size of entry struct too)
872 */ 873 */
873 tablesize = (INT_GET(hdr->count, ARCH_CONVERT) + 1) * (uint)sizeof(xfs_dir_leaf_entry_t) 874 tablesize = (be16_to_cpu(hdr->count) + 1) *
874 + (uint)sizeof(xfs_dir_leaf_hdr_t); 875 sizeof(xfs_dir_leaf_entry_t) + sizeof(xfs_dir_leaf_hdr_t);
875 map = &hdr->freemap[XFS_DIR_LEAF_MAPSIZE-1]; 876 map = &hdr->freemap[XFS_DIR_LEAF_MAPSIZE-1];
876 for (sum = 0, i = XFS_DIR_LEAF_MAPSIZE-1; i >= 0; map--, i--) { 877 for (sum = 0, i = XFS_DIR_LEAF_MAPSIZE-1; i >= 0; map--, i--) {
877 if (tablesize > INT_GET(hdr->firstused, ARCH_CONVERT)) { 878 if (tablesize > be16_to_cpu(hdr->firstused)) {
878 sum += INT_GET(map->size, ARCH_CONVERT); 879 sum += be16_to_cpu(map->size);
879 continue; 880 continue;
880 } 881 }
881 if (!map->size) 882 if (!map->size)
882 continue; /* no space in this map */ 883 continue; /* no space in this map */
883 tmp = entsize; 884 tmp = entsize;
884 if (INT_GET(map->base, ARCH_CONVERT) < INT_GET(hdr->firstused, ARCH_CONVERT)) 885 if (be16_to_cpu(map->base) < be16_to_cpu(hdr->firstused))
885 tmp += (uint)sizeof(xfs_dir_leaf_entry_t); 886 tmp += (uint)sizeof(xfs_dir_leaf_entry_t);
886 if (INT_GET(map->size, ARCH_CONVERT) >= tmp) { 887 if (be16_to_cpu(map->size) >= tmp) {
887 if (!args->justcheck) 888 if (!args->justcheck)
888 xfs_dir_leaf_add_work(bp, args, index, i); 889 xfs_dir_leaf_add_work(bp, args, index, i);
889 return 0; 890 return 0;
890 } 891 }
891 sum += INT_GET(map->size, ARCH_CONVERT); 892 sum += be16_to_cpu(map->size);
892 } 893 }
893 894
894 /* 895 /*
@@ -915,7 +916,7 @@ xfs_dir_leaf_add(xfs_dabuf_t *bp, xfs_da_args_t *args, int index)
915 * After compaction, the block is guaranteed to have only one 916 * After compaction, the block is guaranteed to have only one
916 * free region, in freemap[0]. If it is not big enough, give up. 917 * free region, in freemap[0]. If it is not big enough, give up.
917 */ 918 */
918 if (INT_GET(hdr->freemap[0].size, ARCH_CONVERT) < 919 if (be16_to_cpu(hdr->freemap[0].size) <
919 (entsize + (uint)sizeof(xfs_dir_leaf_entry_t))) 920 (entsize + (uint)sizeof(xfs_dir_leaf_entry_t)))
920 return XFS_ERROR(ENOSPC); 921 return XFS_ERROR(ENOSPC);
921 922
@@ -944,31 +945,32 @@ xfs_dir_leaf_add_work(xfs_dabuf_t *bp, xfs_da_args_t *args, int index,
944 ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_DIR_LEAF_MAGIC); 945 ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_DIR_LEAF_MAGIC);
945 hdr = &leaf->hdr; 946 hdr = &leaf->hdr;
946 ASSERT((mapindex >= 0) && (mapindex < XFS_DIR_LEAF_MAPSIZE)); 947 ASSERT((mapindex >= 0) && (mapindex < XFS_DIR_LEAF_MAPSIZE));
947 ASSERT((index >= 0) && (index <= INT_GET(hdr->count, ARCH_CONVERT))); 948 ASSERT((index >= 0) && (index <= be16_to_cpu(hdr->count)));
948 949
949 /* 950 /*
950 * Force open some space in the entry array and fill it in. 951 * Force open some space in the entry array and fill it in.
951 */ 952 */
952 entry = &leaf->entries[index]; 953 entry = &leaf->entries[index];
953 if (index < INT_GET(hdr->count, ARCH_CONVERT)) { 954 if (index < be16_to_cpu(hdr->count)) {
954 tmp = INT_GET(hdr->count, ARCH_CONVERT) - index; 955 tmp = be16_to_cpu(hdr->count) - index;
955 tmp *= (uint)sizeof(xfs_dir_leaf_entry_t); 956 tmp *= (uint)sizeof(xfs_dir_leaf_entry_t);
956 memmove(entry + 1, entry, tmp); 957 memmove(entry + 1, entry, tmp);
957 xfs_da_log_buf(args->trans, bp, 958 xfs_da_log_buf(args->trans, bp,
958 XFS_DA_LOGRANGE(leaf, entry, tmp + (uint)sizeof(*entry))); 959 XFS_DA_LOGRANGE(leaf, entry, tmp + (uint)sizeof(*entry)));
959 } 960 }
960 INT_MOD(hdr->count, ARCH_CONVERT, +1); 961 be16_add(&hdr->count, 1);
961 962
962 /* 963 /*
963 * Allocate space for the new string (at the end of the run). 964 * Allocate space for the new string (at the end of the run).
964 */ 965 */
965 map = &hdr->freemap[mapindex]; 966 map = &hdr->freemap[mapindex];
966 mp = args->trans->t_mountp; 967 mp = args->trans->t_mountp;
967 ASSERT(INT_GET(map->base, ARCH_CONVERT) < XFS_LBSIZE(mp)); 968 ASSERT(be16_to_cpu(map->base) < XFS_LBSIZE(mp));
968 ASSERT(INT_GET(map->size, ARCH_CONVERT) >= XFS_DIR_LEAF_ENTSIZE_BYNAME(args->namelen)); 969 ASSERT(be16_to_cpu(map->size) >= XFS_DIR_LEAF_ENTSIZE_BYNAME(args->namelen));
969 ASSERT(INT_GET(map->size, ARCH_CONVERT) < XFS_LBSIZE(mp)); 970 ASSERT(be16_to_cpu(map->size) < XFS_LBSIZE(mp));
970 INT_MOD(map->size, ARCH_CONVERT, -(XFS_DIR_LEAF_ENTSIZE_BYNAME(args->namelen))); 971
971 INT_SET(entry->nameidx, ARCH_CONVERT, INT_GET(map->base, ARCH_CONVERT) + INT_GET(map->size, ARCH_CONVERT)); 972 be16_add(&map->size, -(XFS_DIR_LEAF_ENTSIZE_BYNAME(args->namelen)));
973 INT_SET(entry->nameidx, ARCH_CONVERT, be16_to_cpu(map->base) + be16_to_cpu(map->size));
972 INT_SET(entry->hashval, ARCH_CONVERT, args->hashval); 974 INT_SET(entry->hashval, ARCH_CONVERT, args->hashval);
973 entry->namelen = args->namelen; 975 entry->namelen = args->namelen;
974 xfs_da_log_buf(args->trans, bp, 976 xfs_da_log_buf(args->trans, bp,
@@ -986,19 +988,21 @@ xfs_dir_leaf_add_work(xfs_dabuf_t *bp, xfs_da_args_t *args, int index,
986 /* 988 /*
987 * Update the control info for this leaf node 989 * Update the control info for this leaf node
988 */ 990 */
989 if (INT_GET(entry->nameidx, ARCH_CONVERT) < INT_GET(hdr->firstused, ARCH_CONVERT)) 991 if (INT_GET(entry->nameidx, ARCH_CONVERT) < be16_to_cpu(hdr->firstused))
990 INT_COPY(hdr->firstused, entry->nameidx, ARCH_CONVERT); 992 hdr->firstused = entry->nameidx;
991 ASSERT(INT_GET(hdr->firstused, ARCH_CONVERT) >= ((INT_GET(hdr->count, ARCH_CONVERT)*sizeof(*entry))+sizeof(*hdr))); 993 ASSERT(be16_to_cpu(hdr->firstused) >=
992 tmp = (INT_GET(hdr->count, ARCH_CONVERT)-1) * (uint)sizeof(xfs_dir_leaf_entry_t) 994 ((be16_to_cpu(hdr->count)*sizeof(*entry))+sizeof(*hdr)));
995 tmp = (be16_to_cpu(hdr->count)-1) * (uint)sizeof(xfs_dir_leaf_entry_t)
993 + (uint)sizeof(xfs_dir_leaf_hdr_t); 996 + (uint)sizeof(xfs_dir_leaf_hdr_t);
994 map = &hdr->freemap[0]; 997 map = &hdr->freemap[0];
995 for (i = 0; i < XFS_DIR_LEAF_MAPSIZE; map++, i++) { 998 for (i = 0; i < XFS_DIR_LEAF_MAPSIZE; map++, i++) {
996 if (INT_GET(map->base, ARCH_CONVERT) == tmp) { 999 if (be16_to_cpu(map->base) == tmp) {
997 INT_MOD(map->base, ARCH_CONVERT, (uint)sizeof(xfs_dir_leaf_entry_t)); 1000 int entry_size = sizeof(xfs_dir_leaf_entry_t);
998 INT_MOD(map->size, ARCH_CONVERT, -((uint)sizeof(xfs_dir_leaf_entry_t))); 1001 be16_add(&map->base, entry_size);
1002 be16_add(&map->size, -entry_size);
999 } 1003 }
1000 } 1004 }
1001 INT_MOD(hdr->namebytes, ARCH_CONVERT, args->namelen); 1005 be16_add(&hdr->namebytes, args->namelen);
1002 xfs_da_log_buf(args->trans, bp, 1006 xfs_da_log_buf(args->trans, bp,
1003 XFS_DA_LOGRANGE(leaf, hdr, sizeof(*hdr))); 1007 XFS_DA_LOGRANGE(leaf, hdr, sizeof(*hdr)));
1004} 1008}
@@ -1042,23 +1046,24 @@ xfs_dir_leaf_compact(xfs_trans_t *trans, xfs_dabuf_t *bp, int musthave,
1042 hdr_s = &leaf_s->hdr; 1046 hdr_s = &leaf_s->hdr;
1043 hdr_d = &leaf_d->hdr; 1047 hdr_d = &leaf_d->hdr;
1044 hdr_d->info = hdr_s->info; /* struct copy */ 1048 hdr_d->info = hdr_s->info; /* struct copy */
1045 INT_SET(hdr_d->firstused, ARCH_CONVERT, lbsize); 1049 hdr_d->firstused = cpu_to_be16(lbsize);
1046 if (!hdr_d->firstused) 1050 if (!hdr_d->firstused)
1047 INT_SET(hdr_d->firstused, ARCH_CONVERT, lbsize - 1); 1051 hdr_d->firstused = cpu_to_be16(lbsize - 1);
1048 hdr_d->namebytes = 0; 1052 hdr_d->namebytes = 0;
1049 hdr_d->count = 0; 1053 hdr_d->count = 0;
1050 hdr_d->holes = 0; 1054 hdr_d->holes = 0;
1051 INT_SET(hdr_d->freemap[0].base, ARCH_CONVERT, sizeof(xfs_dir_leaf_hdr_t)); 1055 hdr_d->freemap[0].base = cpu_to_be16(sizeof(xfs_dir_leaf_hdr_t));
1052 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)); 1056 hdr_d->freemap[0].size = cpu_to_be16(be16_to_cpu(hdr_d->firstused) -
1057 be16_to_cpu(hdr_d->freemap[0].base));
1053 1058
1054 /* 1059 /*
1055 * Copy all entry's in the same (sorted) order, 1060 * Copy all entry's in the same (sorted) order,
1056 * but allocate filenames packed and in sequence. 1061 * but allocate filenames packed and in sequence.
1057 * This changes the source (leaf_s) as well. 1062 * This changes the source (leaf_s) as well.
1058 */ 1063 */
1059 xfs_dir_leaf_moveents(leaf_s, 0, leaf_d, 0, (int)INT_GET(hdr_s->count, ARCH_CONVERT), mp); 1064 xfs_dir_leaf_moveents(leaf_s, 0, leaf_d, 0, be16_to_cpu(hdr_s->count), mp);
1060 1065
1061 if (musthave && INT_GET(hdr_d->freemap[0].size, ARCH_CONVERT) < musthave) 1066 if (musthave && be16_to_cpu(hdr_d->freemap[0].size) < musthave)
1062 rval = XFS_ERROR(ENOSPC); 1067 rval = XFS_ERROR(ENOSPC);
1063 else 1068 else
1064 rval = 0; 1069 rval = 0;
@@ -1129,20 +1134,20 @@ xfs_dir_leaf_rebalance(xfs_da_state_t *state, xfs_da_state_blk_t *blk1,
1129 /* 1134 /*
1130 * Move any entries required from leaf to leaf: 1135 * Move any entries required from leaf to leaf:
1131 */ 1136 */
1132 if (count < INT_GET(hdr1->count, ARCH_CONVERT)) { 1137 if (count < be16_to_cpu(hdr1->count)) {
1133 /* 1138 /*
1134 * Figure the total bytes to be added to the destination leaf. 1139 * Figure the total bytes to be added to the destination leaf.
1135 */ 1140 */
1136 count = INT_GET(hdr1->count, ARCH_CONVERT) - count; /* number entries being moved */ 1141 count = be16_to_cpu(hdr1->count) - count; /* number entries being moved */
1137 space = INT_GET(hdr1->namebytes, ARCH_CONVERT) - totallen; 1142 space = be16_to_cpu(hdr1->namebytes) - totallen;
1138 space += count * ((uint)sizeof(xfs_dir_leaf_name_t)-1); 1143 space += count * ((uint)sizeof(xfs_dir_leaf_name_t)-1);
1139 space += count * (uint)sizeof(xfs_dir_leaf_entry_t); 1144 space += count * (uint)sizeof(xfs_dir_leaf_entry_t);
1140 1145
1141 /* 1146 /*
1142 * leaf2 is the destination, compact it if it looks tight. 1147 * leaf2 is the destination, compact it if it looks tight.
1143 */ 1148 */
1144 max = INT_GET(hdr2->firstused, ARCH_CONVERT) - (uint)sizeof(xfs_dir_leaf_hdr_t); 1149 max = be16_to_cpu(hdr2->firstused) - (uint)sizeof(xfs_dir_leaf_hdr_t);
1145 max -= INT_GET(hdr2->count, ARCH_CONVERT) * (uint)sizeof(xfs_dir_leaf_entry_t); 1150 max -= be16_to_cpu(hdr2->count) * (uint)sizeof(xfs_dir_leaf_entry_t);
1146 if (space > max) { 1151 if (space > max) {
1147 xfs_dir_leaf_compact(state->args->trans, blk2->bp, 1152 xfs_dir_leaf_compact(state->args->trans, blk2->bp,
1148 0, 0); 1153 0, 0);
@@ -1151,7 +1156,7 @@ xfs_dir_leaf_rebalance(xfs_da_state_t *state, xfs_da_state_blk_t *blk1,
1151 /* 1156 /*
1152 * Move high entries from leaf1 to low end of leaf2. 1157 * Move high entries from leaf1 to low end of leaf2.
1153 */ 1158 */
1154 xfs_dir_leaf_moveents(leaf1, INT_GET(hdr1->count, ARCH_CONVERT) - count, 1159 xfs_dir_leaf_moveents(leaf1, be16_to_cpu(hdr1->count) - count,
1155 leaf2, 0, count, state->mp); 1160 leaf2, 0, count, state->mp);
1156 1161
1157 xfs_da_log_buf(state->args->trans, blk1->bp, 0, 1162 xfs_da_log_buf(state->args->trans, blk1->bp, 0,
@@ -1159,20 +1164,20 @@ xfs_dir_leaf_rebalance(xfs_da_state_t *state, xfs_da_state_blk_t *blk1,
1159 xfs_da_log_buf(state->args->trans, blk2->bp, 0, 1164 xfs_da_log_buf(state->args->trans, blk2->bp, 0,
1160 state->blocksize-1); 1165 state->blocksize-1);
1161 1166
1162 } else if (count > INT_GET(hdr1->count, ARCH_CONVERT)) { 1167 } else if (count > be16_to_cpu(hdr1->count)) {
1163 /* 1168 /*
1164 * Figure the total bytes to be added to the destination leaf. 1169 * Figure the total bytes to be added to the destination leaf.
1165 */ 1170 */
1166 count -= INT_GET(hdr1->count, ARCH_CONVERT); /* number entries being moved */ 1171 count -= be16_to_cpu(hdr1->count); /* number entries being moved */
1167 space = totallen - INT_GET(hdr1->namebytes, ARCH_CONVERT); 1172 space = totallen - be16_to_cpu(hdr1->namebytes);
1168 space += count * ((uint)sizeof(xfs_dir_leaf_name_t)-1); 1173 space += count * ((uint)sizeof(xfs_dir_leaf_name_t)-1);
1169 space += count * (uint)sizeof(xfs_dir_leaf_entry_t); 1174 space += count * (uint)sizeof(xfs_dir_leaf_entry_t);
1170 1175
1171 /* 1176 /*
1172 * leaf1 is the destination, compact it if it looks tight. 1177 * leaf1 is the destination, compact it if it looks tight.
1173 */ 1178 */
1174 max = INT_GET(hdr1->firstused, ARCH_CONVERT) - (uint)sizeof(xfs_dir_leaf_hdr_t); 1179 max = be16_to_cpu(hdr1->firstused) - (uint)sizeof(xfs_dir_leaf_hdr_t);
1175 max -= INT_GET(hdr1->count, ARCH_CONVERT) * (uint)sizeof(xfs_dir_leaf_entry_t); 1180 max -= be16_to_cpu(hdr1->count) * (uint)sizeof(xfs_dir_leaf_entry_t);
1176 if (space > max) { 1181 if (space > max) {
1177 xfs_dir_leaf_compact(state->args->trans, blk1->bp, 1182 xfs_dir_leaf_compact(state->args->trans, blk1->bp,
1178 0, 0); 1183 0, 0);
@@ -1181,7 +1186,7 @@ xfs_dir_leaf_rebalance(xfs_da_state_t *state, xfs_da_state_blk_t *blk1,
1181 /* 1186 /*
1182 * Move low entries from leaf2 to high end of leaf1. 1187 * Move low entries from leaf2 to high end of leaf1.
1183 */ 1188 */
1184 xfs_dir_leaf_moveents(leaf2, 0, leaf1, (int)INT_GET(hdr1->count, ARCH_CONVERT), 1189 xfs_dir_leaf_moveents(leaf2, 0, leaf1, be16_to_cpu(hdr1->count),
1185 count, state->mp); 1190 count, state->mp);
1186 1191
1187 xfs_da_log_buf(state->args->trans, blk1->bp, 0, 1192 xfs_da_log_buf(state->args->trans, blk1->bp, 0,
@@ -1193,15 +1198,15 @@ xfs_dir_leaf_rebalance(xfs_da_state_t *state, xfs_da_state_blk_t *blk1,
1193 /* 1198 /*
1194 * Copy out last hashval in each block for B-tree code. 1199 * Copy out last hashval in each block for B-tree code.
1195 */ 1200 */
1196 blk1->hashval = INT_GET(leaf1->entries[ INT_GET(leaf1->hdr.count, ARCH_CONVERT)-1 ].hashval, ARCH_CONVERT); 1201 blk1->hashval = INT_GET(leaf1->entries[be16_to_cpu(leaf1->hdr.count)-1].hashval, ARCH_CONVERT);
1197 blk2->hashval = INT_GET(leaf2->entries[ INT_GET(leaf2->hdr.count, ARCH_CONVERT)-1 ].hashval, ARCH_CONVERT); 1202 blk2->hashval = INT_GET(leaf2->entries[be16_to_cpu(leaf2->hdr.count)-1].hashval, ARCH_CONVERT);
1198 1203
1199 /* 1204 /*
1200 * Adjust the expected index for insertion. 1205 * Adjust the expected index for insertion.
1201 * GROT: this doesn't work unless blk2 was originally empty. 1206 * GROT: this doesn't work unless blk2 was originally empty.
1202 */ 1207 */
1203 if (!state->inleaf) { 1208 if (!state->inleaf) {
1204 blk2->index = blk1->index - INT_GET(leaf1->hdr.count, ARCH_CONVERT); 1209 blk2->index = blk1->index - be16_to_cpu(leaf1->hdr.count);
1205 } 1210 }
1206} 1211}
1207 1212
@@ -1238,9 +1243,10 @@ xfs_dir_leaf_figure_balance(xfs_da_state_t *state,
1238 * Examine entries until we reduce the absolute difference in 1243 * Examine entries until we reduce the absolute difference in
1239 * byte usage between the two blocks to a minimum. 1244 * byte usage between the two blocks to a minimum.
1240 */ 1245 */
1241 max = INT_GET(hdr1->count, ARCH_CONVERT) + INT_GET(hdr2->count, ARCH_CONVERT); 1246 max = be16_to_cpu(hdr1->count) + be16_to_cpu(hdr2->count);
1242 half = (max+1) * (uint)(sizeof(*entry)+sizeof(xfs_dir_leaf_entry_t)-1); 1247 half = (max+1) * (uint)(sizeof(*entry)+sizeof(xfs_dir_leaf_entry_t)-1);
1243 half += INT_GET(hdr1->namebytes, ARCH_CONVERT) + INT_GET(hdr2->namebytes, ARCH_CONVERT) + state->args->namelen; 1248 half += be16_to_cpu(hdr1->namebytes) + be16_to_cpu(hdr2->namebytes) +
1249 state->args->namelen;
1244 half /= 2; 1250 half /= 2;
1245 lastdelta = state->blocksize; 1251 lastdelta = state->blocksize;
1246 entry = &leaf1->entries[0]; 1252 entry = &leaf1->entries[0];
@@ -1263,7 +1269,7 @@ xfs_dir_leaf_figure_balance(xfs_da_state_t *state,
1263 /* 1269 /*
1264 * Wrap around into the second block if necessary. 1270 * Wrap around into the second block if necessary.
1265 */ 1271 */
1266 if (count == INT_GET(hdr1->count, ARCH_CONVERT)) { 1272 if (count == be16_to_cpu(hdr1->count)) {
1267 leaf1 = leaf2; 1273 leaf1 = leaf2;
1268 entry = &leaf1->entries[0]; 1274 entry = &leaf1->entries[0];
1269 } 1275 }
@@ -1328,11 +1334,11 @@ xfs_dir_leaf_toosmall(xfs_da_state_t *state, int *action)
1328 info = blk->bp->data; 1334 info = blk->bp->data;
1329 ASSERT(be16_to_cpu(info->magic) == XFS_DIR_LEAF_MAGIC); 1335 ASSERT(be16_to_cpu(info->magic) == XFS_DIR_LEAF_MAGIC);
1330 leaf = (xfs_dir_leafblock_t *)info; 1336 leaf = (xfs_dir_leafblock_t *)info;
1331 count = INT_GET(leaf->hdr.count, ARCH_CONVERT); 1337 count = be16_to_cpu(leaf->hdr.count);
1332 bytes = (uint)sizeof(xfs_dir_leaf_hdr_t) + 1338 bytes = (uint)sizeof(xfs_dir_leaf_hdr_t) +
1333 count * (uint)sizeof(xfs_dir_leaf_entry_t) + 1339 count * (uint)sizeof(xfs_dir_leaf_entry_t) +
1334 count * ((uint)sizeof(xfs_dir_leaf_name_t)-1) + 1340 count * ((uint)sizeof(xfs_dir_leaf_name_t)-1) +
1335 INT_GET(leaf->hdr.namebytes, ARCH_CONVERT); 1341 be16_to_cpu(leaf->hdr.namebytes);
1336 if (bytes > (state->blocksize >> 1)) { 1342 if (bytes > (state->blocksize >> 1)) {
1337 *action = 0; /* blk over 50%, don't try to join */ 1343 *action = 0; /* blk over 50%, don't try to join */
1338 return 0; 1344 return 0;
@@ -1386,13 +1392,13 @@ xfs_dir_leaf_toosmall(xfs_da_state_t *state, int *action)
1386 ASSERT(bp != NULL); 1392 ASSERT(bp != NULL);
1387 1393
1388 leaf = (xfs_dir_leafblock_t *)info; 1394 leaf = (xfs_dir_leafblock_t *)info;
1389 count = INT_GET(leaf->hdr.count, ARCH_CONVERT); 1395 count = be16_to_cpu(leaf->hdr.count);
1390 bytes = state->blocksize - (state->blocksize>>2); 1396 bytes = state->blocksize - (state->blocksize>>2);
1391 bytes -= INT_GET(leaf->hdr.namebytes, ARCH_CONVERT); 1397 bytes -= be16_to_cpu(leaf->hdr.namebytes);
1392 leaf = bp->data; 1398 leaf = bp->data;
1393 ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_DIR_LEAF_MAGIC); 1399 ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_DIR_LEAF_MAGIC);
1394 count += INT_GET(leaf->hdr.count, ARCH_CONVERT); 1400 count += be16_to_cpu(leaf->hdr.count);
1395 bytes -= INT_GET(leaf->hdr.namebytes, ARCH_CONVERT); 1401 bytes -= be16_to_cpu(leaf->hdr.namebytes);
1396 bytes -= count * ((uint)sizeof(xfs_dir_leaf_name_t) - 1); 1402 bytes -= count * ((uint)sizeof(xfs_dir_leaf_name_t) - 1);
1397 bytes -= count * (uint)sizeof(xfs_dir_leaf_entry_t); 1403 bytes -= count * (uint)sizeof(xfs_dir_leaf_entry_t);
1398 bytes -= (uint)sizeof(xfs_dir_leaf_hdr_t); 1404 bytes -= (uint)sizeof(xfs_dir_leaf_hdr_t);
@@ -1451,11 +1457,12 @@ xfs_dir_leaf_remove(xfs_trans_t *trans, xfs_dabuf_t *bp, int index)
1451 ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_DIR_LEAF_MAGIC); 1457 ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_DIR_LEAF_MAGIC);
1452 hdr = &leaf->hdr; 1458 hdr = &leaf->hdr;
1453 mp = trans->t_mountp; 1459 mp = trans->t_mountp;
1454 ASSERT((INT_GET(hdr->count, ARCH_CONVERT) > 0) && (INT_GET(hdr->count, ARCH_CONVERT) < (XFS_LBSIZE(mp)/8))); 1460 ASSERT(hdr->count && (be16_to_cpu(hdr->count) < (XFS_LBSIZE(mp)/8)));
1455 ASSERT((index >= 0) && (index < INT_GET(hdr->count, ARCH_CONVERT))); 1461 ASSERT((index >= 0) && (index < be16_to_cpu(hdr->count)));
1456 ASSERT(INT_GET(hdr->firstused, ARCH_CONVERT) >= ((INT_GET(hdr->count, ARCH_CONVERT)*sizeof(*entry))+sizeof(*hdr))); 1462 ASSERT(be16_to_cpu(hdr->firstused) >=
1463 ((be16_to_cpu(hdr->count)*sizeof(*entry))+sizeof(*hdr)));
1457 entry = &leaf->entries[index]; 1464 entry = &leaf->entries[index];
1458 ASSERT(INT_GET(entry->nameidx, ARCH_CONVERT) >= INT_GET(hdr->firstused, ARCH_CONVERT)); 1465 ASSERT(INT_GET(entry->nameidx, ARCH_CONVERT) >= be16_to_cpu(hdr->firstused));
1459 ASSERT(INT_GET(entry->nameidx, ARCH_CONVERT) < XFS_LBSIZE(mp)); 1466 ASSERT(INT_GET(entry->nameidx, ARCH_CONVERT) < XFS_LBSIZE(mp));
1460 1467
1461 /* 1468 /*
@@ -1464,27 +1471,28 @@ xfs_dir_leaf_remove(xfs_trans_t *trans, xfs_dabuf_t *bp, int index)
1464 * find smallest free region in case we need to replace it, 1471 * find smallest free region in case we need to replace it,
1465 * adjust any map that borders the entry table, 1472 * adjust any map that borders the entry table,
1466 */ 1473 */
1467 tablesize = INT_GET(hdr->count, ARCH_CONVERT) * (uint)sizeof(xfs_dir_leaf_entry_t) 1474 tablesize = be16_to_cpu(hdr->count) * (uint)sizeof(xfs_dir_leaf_entry_t)
1468 + (uint)sizeof(xfs_dir_leaf_hdr_t); 1475 + (uint)sizeof(xfs_dir_leaf_hdr_t);
1469 map = &hdr->freemap[0]; 1476 map = &hdr->freemap[0];
1470 tmp = INT_GET(map->size, ARCH_CONVERT); 1477 tmp = be16_to_cpu(map->size);
1471 before = after = -1; 1478 before = after = -1;
1472 smallest = XFS_DIR_LEAF_MAPSIZE - 1; 1479 smallest = XFS_DIR_LEAF_MAPSIZE - 1;
1473 entsize = XFS_DIR_LEAF_ENTSIZE_BYENTRY(entry); 1480 entsize = XFS_DIR_LEAF_ENTSIZE_BYENTRY(entry);
1474 for (i = 0; i < XFS_DIR_LEAF_MAPSIZE; map++, i++) { 1481 for (i = 0; i < XFS_DIR_LEAF_MAPSIZE; map++, i++) {
1475 ASSERT(INT_GET(map->base, ARCH_CONVERT) < XFS_LBSIZE(mp)); 1482 ASSERT(be16_to_cpu(map->base) < XFS_LBSIZE(mp));
1476 ASSERT(INT_GET(map->size, ARCH_CONVERT) < XFS_LBSIZE(mp)); 1483 ASSERT(be16_to_cpu(map->size) < XFS_LBSIZE(mp));
1477 if (INT_GET(map->base, ARCH_CONVERT) == tablesize) { 1484 if (be16_to_cpu(map->base) == tablesize) {
1478 INT_MOD(map->base, ARCH_CONVERT, -((uint)sizeof(xfs_dir_leaf_entry_t))); 1485 int entry_size = sizeof(xfs_dir_leaf_entry_t);
1479 INT_MOD(map->size, ARCH_CONVERT, (uint)sizeof(xfs_dir_leaf_entry_t)); 1486 be16_add(&map->base, -entry_size);
1487 be16_add(&map->size, entry_size);
1480 } 1488 }
1481 1489
1482 if ((INT_GET(map->base, ARCH_CONVERT) + INT_GET(map->size, ARCH_CONVERT)) == INT_GET(entry->nameidx, ARCH_CONVERT)) { 1490 if ((be16_to_cpu(map->base) + be16_to_cpu(map->size)) == INT_GET(entry->nameidx, ARCH_CONVERT)) {
1483 before = i; 1491 before = i;
1484 } else if (INT_GET(map->base, ARCH_CONVERT) == (INT_GET(entry->nameidx, ARCH_CONVERT) + entsize)) { 1492 } else if (be16_to_cpu(map->base) == (INT_GET(entry->nameidx, ARCH_CONVERT) + entsize)) {
1485 after = i; 1493 after = i;
1486 } else if (INT_GET(map->size, ARCH_CONVERT) < tmp) { 1494 } else if (be16_to_cpu(map->size) < tmp) {
1487 tmp = INT_GET(map->size, ARCH_CONVERT); 1495 tmp = be16_to_cpu(map->size);
1488 smallest = i; 1496 smallest = i;
1489 } 1497 }
1490 } 1498 }
@@ -1496,33 +1504,33 @@ xfs_dir_leaf_remove(xfs_trans_t *trans, xfs_dabuf_t *bp, int index)
1496 if ((before >= 0) || (after >= 0)) { 1504 if ((before >= 0) || (after >= 0)) {
1497 if ((before >= 0) && (after >= 0)) { 1505 if ((before >= 0) && (after >= 0)) {
1498 map = &hdr->freemap[before]; 1506 map = &hdr->freemap[before];
1499 INT_MOD(map->size, ARCH_CONVERT, entsize); 1507 be16_add(&map->size, entsize);
1500 INT_MOD(map->size, ARCH_CONVERT, INT_GET(hdr->freemap[after].size, ARCH_CONVERT)); 1508 be16_add(&map->size, be16_to_cpu(hdr->freemap[after].size));
1501 hdr->freemap[after].base = 0; 1509 hdr->freemap[after].base = 0;
1502 hdr->freemap[after].size = 0; 1510 hdr->freemap[after].size = 0;
1503 } else if (before >= 0) { 1511 } else if (before >= 0) {
1504 map = &hdr->freemap[before]; 1512 map = &hdr->freemap[before];
1505 INT_MOD(map->size, ARCH_CONVERT, entsize); 1513 be16_add(&map->size, entsize);
1506 } else { 1514 } else {
1507 map = &hdr->freemap[after]; 1515 map = &hdr->freemap[after];
1508 INT_COPY(map->base, entry->nameidx, ARCH_CONVERT); 1516 map->base = entry->nameidx;
1509 INT_MOD(map->size, ARCH_CONVERT, entsize); 1517 be16_add(&map->size, entsize);
1510 } 1518 }
1511 } else { 1519 } else {
1512 /* 1520 /*
1513 * Replace smallest region (if it is smaller than free'd entry) 1521 * Replace smallest region (if it is smaller than free'd entry)
1514 */ 1522 */
1515 map = &hdr->freemap[smallest]; 1523 map = &hdr->freemap[smallest];
1516 if (INT_GET(map->size, ARCH_CONVERT) < entsize) { 1524 if (be16_to_cpu(map->size) < entsize) {
1517 INT_COPY(map->base, entry->nameidx, ARCH_CONVERT); 1525 map->base = entry->nameidx;
1518 INT_SET(map->size, ARCH_CONVERT, entsize); 1526 map->size = cpu_to_be16(entsize);
1519 } 1527 }
1520 } 1528 }
1521 1529
1522 /* 1530 /*
1523 * Did we remove the first entry? 1531 * Did we remove the first entry?
1524 */ 1532 */
1525 if (INT_GET(entry->nameidx, ARCH_CONVERT) == INT_GET(hdr->firstused, ARCH_CONVERT)) 1533 if (INT_GET(entry->nameidx, ARCH_CONVERT) == be16_to_cpu(hdr->firstused))
1526 smallest = 1; 1534 smallest = 1;
1527 else 1535 else
1528 smallest = 0; 1536 smallest = 0;
@@ -1534,13 +1542,13 @@ xfs_dir_leaf_remove(xfs_trans_t *trans, xfs_dabuf_t *bp, int index)
1534 memset((char *)namest, 0, entsize); 1542 memset((char *)namest, 0, entsize);
1535 xfs_da_log_buf(trans, bp, XFS_DA_LOGRANGE(leaf, namest, entsize)); 1543 xfs_da_log_buf(trans, bp, XFS_DA_LOGRANGE(leaf, namest, entsize));
1536 1544
1537 INT_MOD(hdr->namebytes, ARCH_CONVERT, -(entry->namelen)); 1545 be16_add(&hdr->namebytes, -(entry->namelen));
1538 tmp = (INT_GET(hdr->count, ARCH_CONVERT) - index) * (uint)sizeof(xfs_dir_leaf_entry_t); 1546 tmp = (be16_to_cpu(hdr->count) - index) * (uint)sizeof(xfs_dir_leaf_entry_t);
1539 memmove(entry, entry + 1, tmp); 1547 memmove(entry, entry + 1, tmp);
1540 INT_MOD(hdr->count, ARCH_CONVERT, -1); 1548 be16_add(&hdr->count, -1);
1541 xfs_da_log_buf(trans, bp, 1549 xfs_da_log_buf(trans, bp,
1542 XFS_DA_LOGRANGE(leaf, entry, tmp + (uint)sizeof(*entry))); 1550 XFS_DA_LOGRANGE(leaf, entry, tmp + (uint)sizeof(*entry)));
1543 entry = &leaf->entries[INT_GET(hdr->count, ARCH_CONVERT)]; 1551 entry = &leaf->entries[be16_to_cpu(hdr->count)];
1544 memset((char *)entry, 0, sizeof(xfs_dir_leaf_entry_t)); 1552 memset((char *)entry, 0, sizeof(xfs_dir_leaf_entry_t));
1545 1553
1546 /* 1554 /*
@@ -1552,15 +1560,16 @@ xfs_dir_leaf_remove(xfs_trans_t *trans, xfs_dabuf_t *bp, int index)
1552 if (smallest) { 1560 if (smallest) {
1553 tmp = XFS_LBSIZE(mp); 1561 tmp = XFS_LBSIZE(mp);
1554 entry = &leaf->entries[0]; 1562 entry = &leaf->entries[0];
1555 for (i = INT_GET(hdr->count, ARCH_CONVERT)-1; i >= 0; entry++, i--) { 1563 for (i = be16_to_cpu(hdr->count)-1; i >= 0; entry++, i--) {
1556 ASSERT(INT_GET(entry->nameidx, ARCH_CONVERT) >= INT_GET(hdr->firstused, ARCH_CONVERT)); 1564 ASSERT(INT_GET(entry->nameidx, ARCH_CONVERT) >=
1565 be16_to_cpu(hdr->firstused));
1557 ASSERT(INT_GET(entry->nameidx, ARCH_CONVERT) < XFS_LBSIZE(mp)); 1566 ASSERT(INT_GET(entry->nameidx, ARCH_CONVERT) < XFS_LBSIZE(mp));
1558 if (INT_GET(entry->nameidx, ARCH_CONVERT) < tmp) 1567 if (INT_GET(entry->nameidx, ARCH_CONVERT) < tmp)
1559 tmp = INT_GET(entry->nameidx, ARCH_CONVERT); 1568 tmp = INT_GET(entry->nameidx, ARCH_CONVERT);
1560 } 1569 }
1561 INT_SET(hdr->firstused, ARCH_CONVERT, tmp); 1570 hdr->firstused = cpu_to_be16(tmp);
1562 if (!hdr->firstused) 1571 if (!hdr->firstused)
1563 INT_SET(hdr->firstused, ARCH_CONVERT, tmp - 1); 1572 hdr->firstused = cpu_to_be16(tmp - 1);
1564 } else { 1573 } else {
1565 hdr->holes = 1; /* mark as needing compaction */ 1574 hdr->holes = 1; /* mark as needing compaction */
1566 } 1575 }
@@ -1572,9 +1581,9 @@ xfs_dir_leaf_remove(xfs_trans_t *trans, xfs_dabuf_t *bp, int index)
1572 * "join" the leaf with a sibling if so. 1581 * "join" the leaf with a sibling if so.
1573 */ 1582 */
1574 tmp = (uint)sizeof(xfs_dir_leaf_hdr_t); 1583 tmp = (uint)sizeof(xfs_dir_leaf_hdr_t);
1575 tmp += INT_GET(leaf->hdr.count, ARCH_CONVERT) * (uint)sizeof(xfs_dir_leaf_entry_t); 1584 tmp += be16_to_cpu(leaf->hdr.count) * (uint)sizeof(xfs_dir_leaf_entry_t);
1576 tmp += INT_GET(leaf->hdr.count, ARCH_CONVERT) * ((uint)sizeof(xfs_dir_leaf_name_t) - 1); 1585 tmp += be16_to_cpu(leaf->hdr.count) * ((uint)sizeof(xfs_dir_leaf_name_t) - 1);
1577 tmp += INT_GET(leaf->hdr.namebytes, ARCH_CONVERT); 1586 tmp += be16_to_cpu(leaf->hdr.namebytes);
1578 if (tmp < mp->m_dir_magicpct) 1587 if (tmp < mp->m_dir_magicpct)
1579 return 1; /* leaf is < 37% full */ 1588 return 1; /* leaf is < 37% full */
1580 return 0; 1589 return 0;
@@ -1608,7 +1617,7 @@ xfs_dir_leaf_unbalance(xfs_da_state_t *state, xfs_da_state_blk_t *drop_blk,
1608 /* 1617 /*
1609 * Save last hashval from dying block for later Btree fixup. 1618 * Save last hashval from dying block for later Btree fixup.
1610 */ 1619 */
1611 drop_blk->hashval = INT_GET(drop_leaf->entries[ drop_leaf->hdr.count-1 ].hashval, ARCH_CONVERT); 1620 drop_blk->hashval = INT_GET(drop_leaf->entries[be16_to_cpu(drop_leaf->hdr.count)-1].hashval, ARCH_CONVERT);
1612 1621
1613 /* 1622 /*
1614 * Check if we need a temp buffer, or can we do it in place. 1623 * Check if we need a temp buffer, or can we do it in place.
@@ -1622,11 +1631,11 @@ xfs_dir_leaf_unbalance(xfs_da_state_t *state, xfs_da_state_blk_t *drop_blk,
1622 */ 1631 */
1623 if (xfs_dir_leaf_order(save_blk->bp, drop_blk->bp)) { 1632 if (xfs_dir_leaf_order(save_blk->bp, drop_blk->bp)) {
1624 xfs_dir_leaf_moveents(drop_leaf, 0, save_leaf, 0, 1633 xfs_dir_leaf_moveents(drop_leaf, 0, save_leaf, 0,
1625 (int)INT_GET(drop_hdr->count, ARCH_CONVERT), mp); 1634 be16_to_cpu(drop_hdr->count), mp);
1626 } else { 1635 } else {
1627 xfs_dir_leaf_moveents(drop_leaf, 0, 1636 xfs_dir_leaf_moveents(drop_leaf, 0,
1628 save_leaf, INT_GET(save_hdr->count, ARCH_CONVERT), 1637 save_leaf, be16_to_cpu(save_hdr->count),
1629 (int)INT_GET(drop_hdr->count, ARCH_CONVERT), mp); 1638 be16_to_cpu(drop_hdr->count), mp);
1630 } 1639 }
1631 } else { 1640 } else {
1632 /* 1641 /*
@@ -1640,22 +1649,22 @@ xfs_dir_leaf_unbalance(xfs_da_state_t *state, xfs_da_state_blk_t *drop_blk,
1640 tmp_hdr = &tmp_leaf->hdr; 1649 tmp_hdr = &tmp_leaf->hdr;
1641 tmp_hdr->info = save_hdr->info; /* struct copy */ 1650 tmp_hdr->info = save_hdr->info; /* struct copy */
1642 tmp_hdr->count = 0; 1651 tmp_hdr->count = 0;
1643 INT_SET(tmp_hdr->firstused, ARCH_CONVERT, state->blocksize); 1652 tmp_hdr->firstused = cpu_to_be16(state->blocksize);
1644 if (!tmp_hdr->firstused) 1653 if (!tmp_hdr->firstused)
1645 INT_SET(tmp_hdr->firstused, ARCH_CONVERT, state->blocksize - 1); 1654 tmp_hdr->firstused = cpu_to_be16(state->blocksize - 1);
1646 tmp_hdr->namebytes = 0; 1655 tmp_hdr->namebytes = 0;
1647 if (xfs_dir_leaf_order(save_blk->bp, drop_blk->bp)) { 1656 if (xfs_dir_leaf_order(save_blk->bp, drop_blk->bp)) {
1648 xfs_dir_leaf_moveents(drop_leaf, 0, tmp_leaf, 0, 1657 xfs_dir_leaf_moveents(drop_leaf, 0, tmp_leaf, 0,
1649 (int)INT_GET(drop_hdr->count, ARCH_CONVERT), mp); 1658 be16_to_cpu(drop_hdr->count), mp);
1650 xfs_dir_leaf_moveents(save_leaf, 0, 1659 xfs_dir_leaf_moveents(save_leaf, 0,
1651 tmp_leaf, INT_GET(tmp_leaf->hdr.count, ARCH_CONVERT), 1660 tmp_leaf, be16_to_cpu(tmp_leaf->hdr.count),
1652 (int)INT_GET(save_hdr->count, ARCH_CONVERT), mp); 1661 be16_to_cpu(save_hdr->count), mp);
1653 } else { 1662 } else {
1654 xfs_dir_leaf_moveents(save_leaf, 0, tmp_leaf, 0, 1663 xfs_dir_leaf_moveents(save_leaf, 0, tmp_leaf, 0,
1655 (int)INT_GET(save_hdr->count, ARCH_CONVERT), mp); 1664 be16_to_cpu(save_hdr->count), mp);
1656 xfs_dir_leaf_moveents(drop_leaf, 0, 1665 xfs_dir_leaf_moveents(drop_leaf, 0,
1657 tmp_leaf, INT_GET(tmp_leaf->hdr.count, ARCH_CONVERT), 1666 tmp_leaf, be16_to_cpu(tmp_leaf->hdr.count),
1658 (int)INT_GET(drop_hdr->count, ARCH_CONVERT), mp); 1667 be16_to_cpu(drop_hdr->count), mp);
1659 } 1668 }
1660 memcpy(save_leaf, tmp_leaf, state->blocksize); 1669 memcpy(save_leaf, tmp_leaf, state->blocksize);
1661 kmem_free(tmpbuffer, state->blocksize); 1670 kmem_free(tmpbuffer, state->blocksize);
@@ -1667,7 +1676,7 @@ xfs_dir_leaf_unbalance(xfs_da_state_t *state, xfs_da_state_blk_t *drop_blk,
1667 /* 1676 /*
1668 * Copy out last hashval in each block for B-tree code. 1677 * Copy out last hashval in each block for B-tree code.
1669 */ 1678 */
1670 save_blk->hashval = INT_GET(save_leaf->entries[ INT_GET(save_leaf->hdr.count, ARCH_CONVERT)-1 ].hashval, ARCH_CONVERT); 1679 save_blk->hashval = INT_GET(save_leaf->entries[be16_to_cpu(save_leaf->hdr.count)-1 ].hashval, ARCH_CONVERT);
1671} 1680}
1672 1681
1673/*======================================================================== 1682/*========================================================================
@@ -1697,13 +1706,13 @@ xfs_dir_leaf_lookup_int(xfs_dabuf_t *bp, xfs_da_args_t *args, int *index)
1697 1706
1698 leaf = bp->data; 1707 leaf = bp->data;
1699 ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_DIR_LEAF_MAGIC); 1708 ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_DIR_LEAF_MAGIC);
1700 ASSERT(INT_GET(leaf->hdr.count, ARCH_CONVERT) < (XFS_LBSIZE(args->dp->i_mount)/8)); 1709 ASSERT(be16_to_cpu(leaf->hdr.count) < (XFS_LBSIZE(args->dp->i_mount)/8));
1701 1710
1702 /* 1711 /*
1703 * Binary search. (note: small blocks will skip this loop) 1712 * Binary search. (note: small blocks will skip this loop)
1704 */ 1713 */
1705 hashval = args->hashval; 1714 hashval = args->hashval;
1706 probe = span = INT_GET(leaf->hdr.count, ARCH_CONVERT) / 2; 1715 probe = span = be16_to_cpu(leaf->hdr.count) / 2;
1707 for (entry = &leaf->entries[probe]; span > 4; 1716 for (entry = &leaf->entries[probe]; span > 4;
1708 entry = &leaf->entries[probe]) { 1717 entry = &leaf->entries[probe]) {
1709 span /= 2; 1718 span /= 2;
@@ -1715,7 +1724,7 @@ xfs_dir_leaf_lookup_int(xfs_dabuf_t *bp, xfs_da_args_t *args, int *index)
1715 break; 1724 break;
1716 } 1725 }
1717 ASSERT((probe >= 0) && \ 1726 ASSERT((probe >= 0) && \
1718 ((!leaf->hdr.count) || (probe < INT_GET(leaf->hdr.count, ARCH_CONVERT)))); 1727 ((!leaf->hdr.count) || (probe < be16_to_cpu(leaf->hdr.count))));
1719 ASSERT((span <= 4) || (INT_GET(entry->hashval, ARCH_CONVERT) == hashval)); 1728 ASSERT((span <= 4) || (INT_GET(entry->hashval, ARCH_CONVERT) == hashval));
1720 1729
1721 /* 1730 /*
@@ -1726,11 +1735,11 @@ xfs_dir_leaf_lookup_int(xfs_dabuf_t *bp, xfs_da_args_t *args, int *index)
1726 entry--; 1735 entry--;
1727 probe--; 1736 probe--;
1728 } 1737 }
1729 while ((probe < INT_GET(leaf->hdr.count, ARCH_CONVERT)) && (INT_GET(entry->hashval, ARCH_CONVERT) < hashval)) { 1738 while ((probe < be16_to_cpu(leaf->hdr.count)) && (INT_GET(entry->hashval, ARCH_CONVERT) < hashval)) {
1730 entry++; 1739 entry++;
1731 probe++; 1740 probe++;
1732 } 1741 }
1733 if ((probe == INT_GET(leaf->hdr.count, ARCH_CONVERT)) || (INT_GET(entry->hashval, ARCH_CONVERT) != hashval)) { 1742 if ((probe == be16_to_cpu(leaf->hdr.count)) || (INT_GET(entry->hashval, ARCH_CONVERT) != hashval)) {
1734 *index = probe; 1743 *index = probe;
1735 ASSERT(args->oknoent); 1744 ASSERT(args->oknoent);
1736 return XFS_ERROR(ENOENT); 1745 return XFS_ERROR(ENOENT);
@@ -1739,7 +1748,7 @@ xfs_dir_leaf_lookup_int(xfs_dabuf_t *bp, xfs_da_args_t *args, int *index)
1739 /* 1748 /*
1740 * Duplicate keys may be present, so search all of them for a match. 1749 * Duplicate keys may be present, so search all of them for a match.
1741 */ 1750 */
1742 while ((probe < INT_GET(leaf->hdr.count, ARCH_CONVERT)) && (INT_GET(entry->hashval, ARCH_CONVERT) == hashval)) { 1751 while ((probe < be16_to_cpu(leaf->hdr.count)) && (INT_GET(entry->hashval, ARCH_CONVERT) == hashval)) {
1743 namest = XFS_DIR_LEAF_NAMESTRUCT(leaf, INT_GET(entry->nameidx, ARCH_CONVERT)); 1752 namest = XFS_DIR_LEAF_NAMESTRUCT(leaf, INT_GET(entry->nameidx, ARCH_CONVERT));
1744 if (entry->namelen == args->namelen && 1753 if (entry->namelen == args->namelen &&
1745 namest->name[0] == args->name[0] && 1754 namest->name[0] == args->name[0] &&
@@ -1752,7 +1761,7 @@ xfs_dir_leaf_lookup_int(xfs_dabuf_t *bp, xfs_da_args_t *args, int *index)
1752 probe++; 1761 probe++;
1753 } 1762 }
1754 *index = probe; 1763 *index = probe;
1755 ASSERT(probe == INT_GET(leaf->hdr.count, ARCH_CONVERT) || args->oknoent); 1764 ASSERT(probe == be16_to_cpu(leaf->hdr.count) || args->oknoent);
1756 return XFS_ERROR(ENOENT); 1765 return XFS_ERROR(ENOENT);
1757} 1766}
1758 1767
@@ -1787,22 +1796,22 @@ xfs_dir_leaf_moveents(xfs_dir_leafblock_t *leaf_s, int start_s,
1787 ASSERT(be16_to_cpu(leaf_d->hdr.info.magic) == XFS_DIR_LEAF_MAGIC); 1796 ASSERT(be16_to_cpu(leaf_d->hdr.info.magic) == XFS_DIR_LEAF_MAGIC);
1788 hdr_s = &leaf_s->hdr; 1797 hdr_s = &leaf_s->hdr;
1789 hdr_d = &leaf_d->hdr; 1798 hdr_d = &leaf_d->hdr;
1790 ASSERT((INT_GET(hdr_s->count, ARCH_CONVERT) > 0) && (INT_GET(hdr_s->count, ARCH_CONVERT) < (XFS_LBSIZE(mp)/8))); 1799 ASSERT(hdr_s->count && (be16_to_cpu(hdr_s->count) < (XFS_LBSIZE(mp)/8)));
1791 ASSERT(INT_GET(hdr_s->firstused, ARCH_CONVERT) >= 1800 ASSERT(be16_to_cpu(hdr_s->firstused) >=
1792 ((INT_GET(hdr_s->count, ARCH_CONVERT)*sizeof(*entry_s))+sizeof(*hdr_s))); 1801 ((be16_to_cpu(hdr_s->count)*sizeof(*entry_s))+sizeof(*hdr_s)));
1793 ASSERT(INT_GET(hdr_d->count, ARCH_CONVERT) < (XFS_LBSIZE(mp)/8)); 1802 ASSERT(be16_to_cpu(hdr_d->count) < (XFS_LBSIZE(mp)/8));
1794 ASSERT(INT_GET(hdr_d->firstused, ARCH_CONVERT) >= 1803 ASSERT(be16_to_cpu(hdr_d->firstused) >=
1795 ((INT_GET(hdr_d->count, ARCH_CONVERT)*sizeof(*entry_d))+sizeof(*hdr_d))); 1804 ((be16_to_cpu(hdr_d->count)*sizeof(*entry_d))+sizeof(*hdr_d)));
1796 1805
1797 ASSERT(start_s < INT_GET(hdr_s->count, ARCH_CONVERT)); 1806 ASSERT(start_s < be16_to_cpu(hdr_s->count));
1798 ASSERT(start_d <= INT_GET(hdr_d->count, ARCH_CONVERT)); 1807 ASSERT(start_d <= be16_to_cpu(hdr_d->count));
1799 ASSERT(count <= INT_GET(hdr_s->count, ARCH_CONVERT)); 1808 ASSERT(count <= be16_to_cpu(hdr_s->count));
1800 1809
1801 /* 1810 /*
1802 * Move the entries in the destination leaf up to make a hole? 1811 * Move the entries in the destination leaf up to make a hole?
1803 */ 1812 */
1804 if (start_d < INT_GET(hdr_d->count, ARCH_CONVERT)) { 1813 if (start_d < be16_to_cpu(hdr_d->count)) {
1805 tmp = INT_GET(hdr_d->count, ARCH_CONVERT) - start_d; 1814 tmp = be16_to_cpu(hdr_d->count) - start_d;
1806 tmp *= (uint)sizeof(xfs_dir_leaf_entry_t); 1815 tmp *= (uint)sizeof(xfs_dir_leaf_entry_t);
1807 entry_s = &leaf_d->entries[start_d]; 1816 entry_s = &leaf_d->entries[start_d];
1808 entry_d = &leaf_d->entries[start_d + count]; 1817 entry_d = &leaf_d->entries[start_d + count];
@@ -1816,11 +1825,12 @@ xfs_dir_leaf_moveents(xfs_dir_leafblock_t *leaf_s, int start_s,
1816 entry_s = &leaf_s->entries[start_s]; 1825 entry_s = &leaf_s->entries[start_s];
1817 entry_d = &leaf_d->entries[start_d]; 1826 entry_d = &leaf_d->entries[start_d];
1818 for (i = 0; i < count; entry_s++, entry_d++, i++) { 1827 for (i = 0; i < count; entry_s++, entry_d++, i++) {
1819 ASSERT(INT_GET(entry_s->nameidx, ARCH_CONVERT) >= INT_GET(hdr_s->firstused, ARCH_CONVERT)); 1828 ASSERT(INT_GET(entry_s->nameidx, ARCH_CONVERT) >=
1829 be16_to_cpu(hdr_s->firstused));
1820 tmp = XFS_DIR_LEAF_ENTSIZE_BYENTRY(entry_s); 1830 tmp = XFS_DIR_LEAF_ENTSIZE_BYENTRY(entry_s);
1821 INT_MOD(hdr_d->firstused, ARCH_CONVERT, -(tmp)); 1831 be16_add(&hdr_d->firstused, -(tmp));
1822 entry_d->hashval = entry_s->hashval; /* INT_: direct copy */ 1832 entry_d->hashval = entry_s->hashval;
1823 INT_COPY(entry_d->nameidx, hdr_d->firstused, ARCH_CONVERT); 1833 entry_d->nameidx = hdr_d->firstused;
1824 entry_d->namelen = entry_s->namelen; 1834 entry_d->namelen = entry_s->namelen;
1825 ASSERT(INT_GET(entry_d->nameidx, ARCH_CONVERT) + tmp <= XFS_LBSIZE(mp)); 1835 ASSERT(INT_GET(entry_d->nameidx, ARCH_CONVERT) + tmp <= XFS_LBSIZE(mp));
1826 memcpy(XFS_DIR_LEAF_NAMESTRUCT(leaf_d, INT_GET(entry_d->nameidx, ARCH_CONVERT)), 1836 memcpy(XFS_DIR_LEAF_NAMESTRUCT(leaf_d, INT_GET(entry_d->nameidx, ARCH_CONVERT)),
@@ -1828,20 +1838,20 @@ xfs_dir_leaf_moveents(xfs_dir_leafblock_t *leaf_s, int start_s,
1828 ASSERT(INT_GET(entry_s->nameidx, ARCH_CONVERT) + tmp <= XFS_LBSIZE(mp)); 1838 ASSERT(INT_GET(entry_s->nameidx, ARCH_CONVERT) + tmp <= XFS_LBSIZE(mp));
1829 memset((char *)XFS_DIR_LEAF_NAMESTRUCT(leaf_s, INT_GET(entry_s->nameidx, ARCH_CONVERT)), 1839 memset((char *)XFS_DIR_LEAF_NAMESTRUCT(leaf_s, INT_GET(entry_s->nameidx, ARCH_CONVERT)),
1830 0, tmp); 1840 0, tmp);
1831 INT_MOD(hdr_s->namebytes, ARCH_CONVERT, -(entry_d->namelen)); 1841 be16_add(&hdr_s->namebytes, -(entry_d->namelen));
1832 INT_MOD(hdr_d->namebytes, ARCH_CONVERT, entry_d->namelen); 1842 be16_add(&hdr_d->namebytes, entry_d->namelen);
1833 INT_MOD(hdr_s->count, ARCH_CONVERT, -1); 1843 be16_add(&hdr_s->count, -1);
1834 INT_MOD(hdr_d->count, ARCH_CONVERT, +1); 1844 be16_add(&hdr_d->count, +1);
1835 tmp = INT_GET(hdr_d->count, ARCH_CONVERT) * (uint)sizeof(xfs_dir_leaf_entry_t) 1845 tmp = be16_to_cpu(hdr_d->count) * (uint)sizeof(xfs_dir_leaf_entry_t)
1836 + (uint)sizeof(xfs_dir_leaf_hdr_t); 1846 + (uint)sizeof(xfs_dir_leaf_hdr_t);
1837 ASSERT(INT_GET(hdr_d->firstused, ARCH_CONVERT) >= tmp); 1847 ASSERT(be16_to_cpu(hdr_d->firstused) >= tmp);
1838 1848
1839 } 1849 }
1840 1850
1841 /* 1851 /*
1842 * Zero out the entries we just copied. 1852 * Zero out the entries we just copied.
1843 */ 1853 */
1844 if (start_s == INT_GET(hdr_s->count, ARCH_CONVERT)) { 1854 if (start_s == be16_to_cpu(hdr_s->count)) {
1845 tmp = count * (uint)sizeof(xfs_dir_leaf_entry_t); 1855 tmp = count * (uint)sizeof(xfs_dir_leaf_entry_t);
1846 entry_s = &leaf_s->entries[start_s]; 1856 entry_s = &leaf_s->entries[start_s];
1847 ASSERT((char *)entry_s + tmp <= (char *)leaf_s + XFS_LBSIZE(mp)); 1857 ASSERT((char *)entry_s + tmp <= (char *)leaf_s + XFS_LBSIZE(mp));
@@ -1851,14 +1861,14 @@ xfs_dir_leaf_moveents(xfs_dir_leafblock_t *leaf_s, int start_s,
1851 * Move the remaining entries down to fill the hole, 1861 * Move the remaining entries down to fill the hole,
1852 * then zero the entries at the top. 1862 * then zero the entries at the top.
1853 */ 1863 */
1854 tmp = INT_GET(hdr_s->count, ARCH_CONVERT) - count; 1864 tmp = be16_to_cpu(hdr_s->count) - count;
1855 tmp *= (uint)sizeof(xfs_dir_leaf_entry_t); 1865 tmp *= (uint)sizeof(xfs_dir_leaf_entry_t);
1856 entry_s = &leaf_s->entries[start_s + count]; 1866 entry_s = &leaf_s->entries[start_s + count];
1857 entry_d = &leaf_s->entries[start_s]; 1867 entry_d = &leaf_s->entries[start_s];
1858 memcpy(entry_d, entry_s, tmp); 1868 memcpy(entry_d, entry_s, tmp);
1859 1869
1860 tmp = count * (uint)sizeof(xfs_dir_leaf_entry_t); 1870 tmp = count * (uint)sizeof(xfs_dir_leaf_entry_t);
1861 entry_s = &leaf_s->entries[INT_GET(hdr_s->count, ARCH_CONVERT)]; 1871 entry_s = &leaf_s->entries[be16_to_cpu(hdr_s->count)];
1862 ASSERT((char *)entry_s + tmp <= (char *)leaf_s + XFS_LBSIZE(mp)); 1872 ASSERT((char *)entry_s + tmp <= (char *)leaf_s + XFS_LBSIZE(mp));
1863 memset((char *)entry_s, 0, tmp); 1873 memset((char *)entry_s, 0, tmp);
1864 } 1874 }
@@ -1866,11 +1876,14 @@ xfs_dir_leaf_moveents(xfs_dir_leafblock_t *leaf_s, int start_s,
1866 /* 1876 /*
1867 * Fill in the freemap information 1877 * Fill in the freemap information
1868 */ 1878 */
1869 INT_SET(hdr_d->freemap[0].base, ARCH_CONVERT, (uint)sizeof(xfs_dir_leaf_hdr_t)); 1879 hdr_d->freemap[0].base = cpu_to_be16(sizeof(xfs_dir_leaf_hdr_t) +
1870 INT_MOD(hdr_d->freemap[0].base, ARCH_CONVERT, INT_GET(hdr_d->count, ARCH_CONVERT) * (uint)sizeof(xfs_dir_leaf_entry_t)); 1880 be16_to_cpu(hdr_d->count) * sizeof(xfs_dir_leaf_entry_t));
1871 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)); 1881 hdr_d->freemap[0].size = cpu_to_be16(be16_to_cpu(hdr_d->firstused) -
1872 INT_SET(hdr_d->freemap[1].base, ARCH_CONVERT, (hdr_d->freemap[2].base = 0)); 1882 be16_to_cpu(hdr_d->freemap[0].base));
1873 INT_SET(hdr_d->freemap[1].size, ARCH_CONVERT, (hdr_d->freemap[2].size = 0)); 1883 hdr_d->freemap[1].base = 0;
1884 hdr_d->freemap[1].size = 0;
1885 hdr_d->freemap[2].base = 0;
1886 hdr_d->freemap[2].size = 0;
1874 hdr_s->holes = 1; /* leaf may not be compact */ 1887 hdr_s->holes = 1; /* leaf may not be compact */
1875} 1888}
1876 1889
@@ -1886,11 +1899,11 @@ xfs_dir_leaf_order(xfs_dabuf_t *leaf1_bp, xfs_dabuf_t *leaf2_bp)
1886 leaf2 = leaf2_bp->data; 1899 leaf2 = leaf2_bp->data;
1887 ASSERT((be16_to_cpu(leaf1->hdr.info.magic) == XFS_DIR_LEAF_MAGIC) && 1900 ASSERT((be16_to_cpu(leaf1->hdr.info.magic) == XFS_DIR_LEAF_MAGIC) &&
1888 (be16_to_cpu(leaf2->hdr.info.magic) == XFS_DIR_LEAF_MAGIC)); 1901 (be16_to_cpu(leaf2->hdr.info.magic) == XFS_DIR_LEAF_MAGIC));
1889 if ((INT_GET(leaf1->hdr.count, ARCH_CONVERT) > 0) && (INT_GET(leaf2->hdr.count, ARCH_CONVERT) > 0) && 1902 if (leaf1->hdr.count && leaf2->hdr.count &&
1890 ((INT_GET(leaf2->entries[ 0 ].hashval, ARCH_CONVERT) < 1903 ((INT_GET(leaf2->entries[ 0 ].hashval, ARCH_CONVERT) <
1891 INT_GET(leaf1->entries[ 0 ].hashval, ARCH_CONVERT)) || 1904 INT_GET(leaf1->entries[ 0 ].hashval, ARCH_CONVERT)) ||
1892 (INT_GET(leaf2->entries[ INT_GET(leaf2->hdr.count, ARCH_CONVERT)-1 ].hashval, ARCH_CONVERT) < 1905 (INT_GET(leaf2->entries[be16_to_cpu(leaf2->hdr.count)-1].hashval, ARCH_CONVERT) <
1893 INT_GET(leaf1->entries[ INT_GET(leaf1->hdr.count, ARCH_CONVERT)-1 ].hashval, ARCH_CONVERT)))) { 1906 INT_GET(leaf1->entries[be16_to_cpu(leaf1->hdr.count)-1].hashval, ARCH_CONVERT)))) {
1894 return 1; 1907 return 1;
1895 } 1908 }
1896 return 0; 1909 return 0;
@@ -1907,10 +1920,10 @@ xfs_dir_leaf_lasthash(xfs_dabuf_t *bp, int *count)
1907 leaf = bp->data; 1920 leaf = bp->data;
1908 ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_DIR_LEAF_MAGIC); 1921 ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_DIR_LEAF_MAGIC);
1909 if (count) 1922 if (count)
1910 *count = INT_GET(leaf->hdr.count, ARCH_CONVERT); 1923 *count = be16_to_cpu(leaf->hdr.count);
1911 if (!leaf->hdr.count) 1924 if (!leaf->hdr.count)
1912 return(0); 1925 return(0);
1913 return(INT_GET(leaf->entries[ INT_GET(leaf->hdr.count, ARCH_CONVERT)-1 ].hashval, ARCH_CONVERT)); 1926 return(INT_GET(leaf->entries[be16_to_cpu(leaf->hdr.count)-1].hashval, ARCH_CONVERT));
1914} 1927}
1915 1928
1916/* 1929/*
@@ -1956,8 +1969,7 @@ xfs_dir_leaf_getdents_int(
1956 * Re-find our place. 1969 * Re-find our place.
1957 */ 1970 */
1958 for (i = entno = 0, entry = &leaf->entries[0]; 1971 for (i = entno = 0, entry = &leaf->entries[0];
1959 i < INT_GET(leaf->hdr.count, ARCH_CONVERT); 1972 i < be16_to_cpu(leaf->hdr.count); entry++, i++) {
1960 entry++, i++) {
1961 1973
1962 namest = XFS_DIR_LEAF_NAMESTRUCT(leaf, 1974 namest = XFS_DIR_LEAF_NAMESTRUCT(leaf,
1963 INT_GET(entry->nameidx, ARCH_CONVERT)); 1975 INT_GET(entry->nameidx, ARCH_CONVERT));
@@ -1991,7 +2003,7 @@ xfs_dir_leaf_getdents_int(
1991 } 2003 }
1992 } 2004 }
1993 2005
1994 if (i == INT_GET(leaf->hdr.count, ARCH_CONVERT)) { 2006 if (i == be16_to_cpu(leaf->hdr.count)) {
1995 xfs_dir_trace_g_du("leaf: hash not found", dp, uio); 2007 xfs_dir_trace_g_du("leaf: hash not found", dp, uio);
1996 if (!leaf->hdr.info.forw) 2008 if (!leaf->hdr.info.forw)
1997 uio->uio_offset = 2009 uio->uio_offset =
@@ -2012,7 +2024,7 @@ xfs_dir_leaf_getdents_int(
2012 /* 2024 /*
2013 * We're synchronized, start copying entries out to the user. 2025 * We're synchronized, start copying entries out to the user.
2014 */ 2026 */
2015 for (; entno >= 0 && i < INT_GET(leaf->hdr.count, ARCH_CONVERT); 2027 for (; entno >= 0 && i < be16_to_cpu(leaf->hdr.count);
2016 entry++, i++, (entno = nextentno)) { 2028 entry++, i++, (entno = nextentno)) {
2017 int lastresid=0, retval; 2029 int lastresid=0, retval;
2018 xfs_dircook_t lastoffset; 2030 xfs_dircook_t lastoffset;
@@ -2037,7 +2049,7 @@ xfs_dir_leaf_getdents_int(
2037 xfs_dir_trace_g_duc("leaf: middle cookie ", 2049 xfs_dir_trace_g_duc("leaf: middle cookie ",
2038 dp, uio, p.cook.o); 2050 dp, uio, p.cook.o);
2039 2051
2040 if (i < (INT_GET(leaf->hdr.count, ARCH_CONVERT) - 1)) { 2052 if (i < (be16_to_cpu(leaf->hdr.count) - 1)) {
2041 nexthash = INT_GET(entry[1].hashval, ARCH_CONVERT); 2053 nexthash = INT_GET(entry[1].hashval, ARCH_CONVERT);
2042 2054
2043 if (nexthash == INT_GET(entry->hashval, ARCH_CONVERT)) 2055 if (nexthash == INT_GET(entry->hashval, ARCH_CONVERT))
diff --git a/fs/xfs/xfs_dir_leaf.h b/fs/xfs/xfs_dir_leaf.h
index eb8cd9a4667f..c6979ab829cb 100644
--- a/fs/xfs/xfs_dir_leaf.h
+++ b/fs/xfs/xfs_dir_leaf.h
@@ -68,17 +68,17 @@ struct xfs_trans;
68#define XFS_DIR_LEAF_MAPSIZE 3 /* how many freespace slots */ 68#define XFS_DIR_LEAF_MAPSIZE 3 /* how many freespace slots */
69 69
70typedef struct xfs_dir_leaf_map { /* RLE map of free bytes */ 70typedef struct xfs_dir_leaf_map { /* RLE map of free bytes */
71 __uint16_t base; /* base of free region */ 71 __be16 base; /* base of free region */
72 __uint16_t size; /* run length of free region */ 72 __be16 size; /* run length of free region */
73} xfs_dir_leaf_map_t; 73} xfs_dir_leaf_map_t;
74 74
75typedef struct xfs_dir_leaf_hdr { /* constant-structure header block */ 75typedef struct xfs_dir_leaf_hdr { /* constant-structure header block */
76 xfs_da_blkinfo_t info; /* block type, links, etc. */ 76 xfs_da_blkinfo_t info; /* block type, links, etc. */
77 __uint16_t count; /* count of active leaf_entry's */ 77 __be16 count; /* count of active leaf_entry's */
78 __uint16_t namebytes; /* num bytes of name strings stored */ 78 __be16 namebytes; /* num bytes of name strings stored */
79 __uint16_t firstused; /* first used byte in name area */ 79 __be16 firstused; /* first used byte in name area */
80 __uint8_t holes; /* != 0 if blk needs compaction */ 80 __u8 holes; /* != 0 if blk needs compaction */
81 __uint8_t pad1; 81 __u8 pad1;
82 xfs_dir_leaf_map_t freemap[XFS_DIR_LEAF_MAPSIZE]; 82 xfs_dir_leaf_map_t freemap[XFS_DIR_LEAF_MAPSIZE];
83} xfs_dir_leaf_hdr_t; 83} xfs_dir_leaf_hdr_t;
84 84