aboutsummaryrefslogtreecommitdiffstats
path: root/fs/xfs/xfs_attr_leaf.c
diff options
context:
space:
mode:
authorNathan Scott <nathans@sgi.com>2006-03-17 01:28:54 -0500
committerNathan Scott <nathans@sgi.com>2006-03-17 01:28:54 -0500
commit918ae424e18666249cf32f16ba2803061bf1ebb7 (patch)
tree6a2d6c00a53480b6848245e653635f8152669633 /fs/xfs/xfs_attr_leaf.c
parent8f44e047a044df613bbc29837b9556e0c2e42e6b (diff)
[XFS] endianess annotations for xfs_attr_leaf_hdr_t
SGI-PV: 943272 SGI-Modid: xfs-linux-melb:xfs-kern:25497a Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Nathan Scott <nathans@sgi.com>
Diffstat (limited to 'fs/xfs/xfs_attr_leaf.c')
-rw-r--r--fs/xfs/xfs_attr_leaf.c414
1 files changed, 188 insertions, 226 deletions
diff --git a/fs/xfs/xfs_attr_leaf.c b/fs/xfs/xfs_attr_leaf.c
index d279d944e03d..31b55e58e2cf 100644
--- a/fs/xfs/xfs_attr_leaf.c
+++ b/fs/xfs/xfs_attr_leaf.c
@@ -724,7 +724,7 @@ xfs_attr_shortform_allfit(xfs_dabuf_t *bp, xfs_inode_t *dp)
724 724
725 entry = &leaf->entries[0]; 725 entry = &leaf->entries[0];
726 bytes = sizeof(struct xfs_attr_sf_hdr); 726 bytes = sizeof(struct xfs_attr_sf_hdr);
727 for (i = 0; i < INT_GET(leaf->hdr.count, ARCH_CONVERT); entry++, i++) { 727 for (i = 0; i < be16_to_cpu(leaf->hdr.count); entry++, i++) {
728 if (entry->flags & XFS_ATTR_INCOMPLETE) 728 if (entry->flags & XFS_ATTR_INCOMPLETE)
729 continue; /* don't copy partial entries */ 729 continue; /* don't copy partial entries */
730 if (!(entry->flags & XFS_ATTR_LOCAL)) 730 if (!(entry->flags & XFS_ATTR_LOCAL))
@@ -808,7 +808,7 @@ xfs_attr_leaf_to_shortform(xfs_dabuf_t *bp, xfs_da_args_t *args, int forkoff)
808 nargs.trans = args->trans; 808 nargs.trans = args->trans;
809 nargs.oknoent = 1; 809 nargs.oknoent = 1;
810 entry = &leaf->entries[0]; 810 entry = &leaf->entries[0];
811 for (i = 0; i < INT_GET(leaf->hdr.count, ARCH_CONVERT); entry++, i++) { 811 for (i = 0; i < be16_to_cpu(leaf->hdr.count); entry++, i++) {
812 if (entry->flags & XFS_ATTR_INCOMPLETE) 812 if (entry->flags & XFS_ATTR_INCOMPLETE)
813 continue; /* don't copy partial entries */ 813 continue; /* don't copy partial entries */
814 if (!entry->nameidx) 814 if (!entry->nameidx)
@@ -876,7 +876,7 @@ xfs_attr_leaf_to_node(xfs_da_args_t *args)
876 ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_ATTR_LEAF_MAGIC); 876 ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_ATTR_LEAF_MAGIC);
877 /* both on-disk, don't endian-flip twice */ 877 /* both on-disk, don't endian-flip twice */
878 node->btree[0].hashval = 878 node->btree[0].hashval =
879 leaf->entries[INT_GET(leaf->hdr.count, ARCH_CONVERT)-1 ].hashval; 879 leaf->entries[be16_to_cpu(leaf->hdr.count)-1 ].hashval;
880 INT_SET(node->btree[0].before, ARCH_CONVERT, blkno); 880 INT_SET(node->btree[0].before, ARCH_CONVERT, blkno);
881 INT_SET(node->hdr.count, ARCH_CONVERT, 1); 881 INT_SET(node->hdr.count, ARCH_CONVERT, 1);
882 xfs_da_log_buf(args->trans, bp1, 0, XFS_LBSIZE(dp->i_mount) - 1); 882 xfs_da_log_buf(args->trans, bp1, 0, XFS_LBSIZE(dp->i_mount) - 1);
@@ -918,18 +918,15 @@ xfs_attr_leaf_create(xfs_da_args_t *args, xfs_dablk_t blkno, xfs_dabuf_t **bpp)
918 memset((char *)leaf, 0, XFS_LBSIZE(dp->i_mount)); 918 memset((char *)leaf, 0, XFS_LBSIZE(dp->i_mount));
919 hdr = &leaf->hdr; 919 hdr = &leaf->hdr;
920 hdr->info.magic = cpu_to_be16(XFS_ATTR_LEAF_MAGIC); 920 hdr->info.magic = cpu_to_be16(XFS_ATTR_LEAF_MAGIC);
921 INT_SET(hdr->firstused, ARCH_CONVERT, XFS_LBSIZE(dp->i_mount)); 921 hdr->firstused = cpu_to_be16(XFS_LBSIZE(dp->i_mount));
922 if (!hdr->firstused) { 922 if (!hdr->firstused) {
923 INT_SET(hdr->firstused, ARCH_CONVERT, 923 hdr->firstused = cpu_to_be16(
924 XFS_LBSIZE(dp->i_mount) - XFS_ATTR_LEAF_NAME_ALIGN); 924 XFS_LBSIZE(dp->i_mount) - XFS_ATTR_LEAF_NAME_ALIGN);
925 } 925 }
926 926
927 INT_SET(hdr->freemap[0].base, ARCH_CONVERT, 927 hdr->freemap[0].base = cpu_to_be16(sizeof(xfs_attr_leaf_hdr_t));
928 sizeof(xfs_attr_leaf_hdr_t)); 928 hdr->freemap[0].size = cpu_to_be16(be16_to_cpu(hdr->firstused) -
929 INT_SET(hdr->freemap[0].size, ARCH_CONVERT, 929 sizeof(xfs_attr_leaf_hdr_t));
930 INT_GET(hdr->firstused, ARCH_CONVERT)
931 - INT_GET(hdr->freemap[0].base,
932 ARCH_CONVERT));
933 930
934 xfs_da_log_buf(args->trans, bp, 0, XFS_LBSIZE(dp->i_mount) - 1); 931 xfs_da_log_buf(args->trans, bp, 0, XFS_LBSIZE(dp->i_mount) - 1);
935 932
@@ -1003,7 +1000,7 @@ xfs_attr_leaf_add(xfs_dabuf_t *bp, xfs_da_args_t *args)
1003 leaf = bp->data; 1000 leaf = bp->data;
1004 ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_ATTR_LEAF_MAGIC); 1001 ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_ATTR_LEAF_MAGIC);
1005 ASSERT((args->index >= 0) 1002 ASSERT((args->index >= 0)
1006 && (args->index <= INT_GET(leaf->hdr.count, ARCH_CONVERT))); 1003 && (args->index <= be16_to_cpu(leaf->hdr.count)));
1007 hdr = &leaf->hdr; 1004 hdr = &leaf->hdr;
1008 entsize = xfs_attr_leaf_newentsize(args->namelen, args->valuelen, 1005 entsize = xfs_attr_leaf_newentsize(args->namelen, args->valuelen,
1009 args->trans->t_mountp->m_sb.sb_blocksize, NULL); 1006 args->trans->t_mountp->m_sb.sb_blocksize, NULL);
@@ -1012,26 +1009,25 @@ xfs_attr_leaf_add(xfs_dabuf_t *bp, xfs_da_args_t *args)
1012 * Search through freemap for first-fit on new name length. 1009 * Search through freemap for first-fit on new name length.
1013 * (may need to figure in size of entry struct too) 1010 * (may need to figure in size of entry struct too)
1014 */ 1011 */
1015 tablesize = (INT_GET(hdr->count, ARCH_CONVERT) + 1) 1012 tablesize = (be16_to_cpu(hdr->count) + 1)
1016 * sizeof(xfs_attr_leaf_entry_t) 1013 * sizeof(xfs_attr_leaf_entry_t)
1017 + sizeof(xfs_attr_leaf_hdr_t); 1014 + sizeof(xfs_attr_leaf_hdr_t);
1018 map = &hdr->freemap[XFS_ATTR_LEAF_MAPSIZE-1]; 1015 map = &hdr->freemap[XFS_ATTR_LEAF_MAPSIZE-1];
1019 for (sum = 0, i = XFS_ATTR_LEAF_MAPSIZE-1; i >= 0; map--, i--) { 1016 for (sum = 0, i = XFS_ATTR_LEAF_MAPSIZE-1; i >= 0; map--, i--) {
1020 if (tablesize > INT_GET(hdr->firstused, ARCH_CONVERT)) { 1017 if (tablesize > be16_to_cpu(hdr->firstused)) {
1021 sum += INT_GET(map->size, ARCH_CONVERT); 1018 sum += be16_to_cpu(map->size);
1022 continue; 1019 continue;
1023 } 1020 }
1024 if (!map->size) 1021 if (!map->size)
1025 continue; /* no space in this map */ 1022 continue; /* no space in this map */
1026 tmp = entsize; 1023 tmp = entsize;
1027 if (INT_GET(map->base, ARCH_CONVERT) 1024 if (be16_to_cpu(map->base) < be16_to_cpu(hdr->firstused))
1028 < INT_GET(hdr->firstused, ARCH_CONVERT))
1029 tmp += sizeof(xfs_attr_leaf_entry_t); 1025 tmp += sizeof(xfs_attr_leaf_entry_t);
1030 if (INT_GET(map->size, ARCH_CONVERT) >= tmp) { 1026 if (be16_to_cpu(map->size) >= tmp) {
1031 tmp = xfs_attr_leaf_add_work(bp, args, i); 1027 tmp = xfs_attr_leaf_add_work(bp, args, i);
1032 return(tmp); 1028 return(tmp);
1033 } 1029 }
1034 sum += INT_GET(map->size, ARCH_CONVERT); 1030 sum += be16_to_cpu(map->size);
1035 } 1031 }
1036 1032
1037 /* 1033 /*
@@ -1052,7 +1048,7 @@ xfs_attr_leaf_add(xfs_dabuf_t *bp, xfs_da_args_t *args)
1052 * After compaction, the block is guaranteed to have only one 1048 * After compaction, the block is guaranteed to have only one
1053 * free region, in freemap[0]. If it is not big enough, give up. 1049 * free region, in freemap[0]. If it is not big enough, give up.
1054 */ 1050 */
1055 if (INT_GET(hdr->freemap[0].size, ARCH_CONVERT) 1051 if (be16_to_cpu(hdr->freemap[0].size)
1056 < (entsize + sizeof(xfs_attr_leaf_entry_t))) 1052 < (entsize + sizeof(xfs_attr_leaf_entry_t)))
1057 return(XFS_ERROR(ENOSPC)); 1053 return(XFS_ERROR(ENOSPC));
1058 1054
@@ -1078,40 +1074,39 @@ xfs_attr_leaf_add_work(xfs_dabuf_t *bp, xfs_da_args_t *args, int mapindex)
1078 ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_ATTR_LEAF_MAGIC); 1074 ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_ATTR_LEAF_MAGIC);
1079 hdr = &leaf->hdr; 1075 hdr = &leaf->hdr;
1080 ASSERT((mapindex >= 0) && (mapindex < XFS_ATTR_LEAF_MAPSIZE)); 1076 ASSERT((mapindex >= 0) && (mapindex < XFS_ATTR_LEAF_MAPSIZE));
1081 ASSERT((args->index >= 0) 1077 ASSERT((args->index >= 0) && (args->index <= be16_to_cpu(hdr->count)));
1082 && (args->index <= INT_GET(hdr->count, ARCH_CONVERT)));
1083 1078
1084 /* 1079 /*
1085 * Force open some space in the entry array and fill it in. 1080 * Force open some space in the entry array and fill it in.
1086 */ 1081 */
1087 entry = &leaf->entries[args->index]; 1082 entry = &leaf->entries[args->index];
1088 if (args->index < INT_GET(hdr->count, ARCH_CONVERT)) { 1083 if (args->index < be16_to_cpu(hdr->count)) {
1089 tmp = INT_GET(hdr->count, ARCH_CONVERT) - args->index; 1084 tmp = be16_to_cpu(hdr->count) - args->index;
1090 tmp *= sizeof(xfs_attr_leaf_entry_t); 1085 tmp *= sizeof(xfs_attr_leaf_entry_t);
1091 memmove((char *)(entry+1), (char *)entry, tmp); 1086 memmove((char *)(entry+1), (char *)entry, tmp);
1092 xfs_da_log_buf(args->trans, bp, 1087 xfs_da_log_buf(args->trans, bp,
1093 XFS_DA_LOGRANGE(leaf, entry, tmp + sizeof(*entry))); 1088 XFS_DA_LOGRANGE(leaf, entry, tmp + sizeof(*entry)));
1094 } 1089 }
1095 INT_MOD(hdr->count, ARCH_CONVERT, 1); 1090 be16_add(&hdr->count, 1);
1096 1091
1097 /* 1092 /*
1098 * Allocate space for the new string (at the end of the run). 1093 * Allocate space for the new string (at the end of the run).
1099 */ 1094 */
1100 map = &hdr->freemap[mapindex]; 1095 map = &hdr->freemap[mapindex];
1101 mp = args->trans->t_mountp; 1096 mp = args->trans->t_mountp;
1102 ASSERT(INT_GET(map->base, ARCH_CONVERT) < XFS_LBSIZE(mp)); 1097 ASSERT(be16_to_cpu(map->base) < XFS_LBSIZE(mp));
1103 ASSERT((INT_GET(map->base, ARCH_CONVERT) & 0x3) == 0); 1098 ASSERT((be16_to_cpu(map->base) & 0x3) == 0);
1104 ASSERT(INT_GET(map->size, ARCH_CONVERT) >= 1099 ASSERT(be16_to_cpu(map->size) >=
1105 xfs_attr_leaf_newentsize(args->namelen, args->valuelen, 1100 xfs_attr_leaf_newentsize(args->namelen, args->valuelen,
1106 mp->m_sb.sb_blocksize, NULL)); 1101 mp->m_sb.sb_blocksize, NULL));
1107 ASSERT(INT_GET(map->size, ARCH_CONVERT) < XFS_LBSIZE(mp)); 1102 ASSERT(be16_to_cpu(map->size) < XFS_LBSIZE(mp));
1108 ASSERT((INT_GET(map->size, ARCH_CONVERT) & 0x3) == 0); 1103 ASSERT((be16_to_cpu(map->size) & 0x3) == 0);
1109 INT_MOD(map->size, ARCH_CONVERT, 1104 be16_add(&map->size,
1110 -xfs_attr_leaf_newentsize(args->namelen, args->valuelen, 1105 -xfs_attr_leaf_newentsize(args->namelen, args->valuelen,
1111 mp->m_sb.sb_blocksize, &tmp)); 1106 mp->m_sb.sb_blocksize, &tmp));
1112 INT_SET(entry->nameidx, ARCH_CONVERT, 1107 INT_SET(entry->nameidx, ARCH_CONVERT,
1113 INT_GET(map->base, ARCH_CONVERT) 1108 be16_to_cpu(map->base)
1114 + INT_GET(map->size, ARCH_CONVERT)); 1109 + be16_to_cpu(map->size));
1115 INT_SET(entry->hashval, ARCH_CONVERT, args->hashval); 1110 INT_SET(entry->hashval, ARCH_CONVERT, args->hashval);
1116 entry->flags = tmp ? XFS_ATTR_LOCAL : 0; 1111 entry->flags = tmp ? XFS_ATTR_LOCAL : 0;
1117 entry->flags |= (args->flags & ATTR_SECURE) ? XFS_ATTR_SECURE : 1112 entry->flags |= (args->flags & ATTR_SECURE) ? XFS_ATTR_SECURE :
@@ -1128,7 +1123,7 @@ xfs_attr_leaf_add_work(xfs_dabuf_t *bp, xfs_da_args_t *args, int mapindex)
1128 ASSERT((args->index == 0) || (INT_GET(entry->hashval, ARCH_CONVERT) 1123 ASSERT((args->index == 0) || (INT_GET(entry->hashval, ARCH_CONVERT)
1129 >= INT_GET((entry-1)->hashval, 1124 >= INT_GET((entry-1)->hashval,
1130 ARCH_CONVERT))); 1125 ARCH_CONVERT)));
1131 ASSERT((args->index == INT_GET(hdr->count, ARCH_CONVERT)-1) || 1126 ASSERT((args->index == be16_to_cpu(hdr->count)-1) ||
1132 (INT_GET(entry->hashval, ARCH_CONVERT) 1127 (INT_GET(entry->hashval, ARCH_CONVERT)
1133 <= (INT_GET((entry+1)->hashval, ARCH_CONVERT)))); 1128 <= (INT_GET((entry+1)->hashval, ARCH_CONVERT))));
1134 1129
@@ -1167,27 +1162,23 @@ xfs_attr_leaf_add_work(xfs_dabuf_t *bp, xfs_da_args_t *args, int mapindex)
1167 * Update the control info for this leaf node 1162 * Update the control info for this leaf node
1168 */ 1163 */
1169 if (INT_GET(entry->nameidx, ARCH_CONVERT) 1164 if (INT_GET(entry->nameidx, ARCH_CONVERT)
1170 < INT_GET(hdr->firstused, ARCH_CONVERT)) { 1165 < be16_to_cpu(hdr->firstused)) {
1171 /* both on-disk, don't endian-flip twice */ 1166 /* both on-disk, don't endian-flip twice */
1172 hdr->firstused = entry->nameidx; 1167 hdr->firstused = entry->nameidx;
1173 } 1168 }
1174 ASSERT(INT_GET(hdr->firstused, ARCH_CONVERT) 1169 ASSERT(be16_to_cpu(hdr->firstused) >=
1175 >= ((INT_GET(hdr->count, ARCH_CONVERT) 1170 ((be16_to_cpu(hdr->count) * sizeof(*entry)) + sizeof(*hdr)));
1176 * sizeof(*entry))+sizeof(*hdr))); 1171 tmp = (be16_to_cpu(hdr->count)-1) * sizeof(xfs_attr_leaf_entry_t)
1177 tmp = (INT_GET(hdr->count, ARCH_CONVERT)-1)
1178 * sizeof(xfs_attr_leaf_entry_t)
1179 + sizeof(xfs_attr_leaf_hdr_t); 1172 + sizeof(xfs_attr_leaf_hdr_t);
1180 map = &hdr->freemap[0]; 1173 map = &hdr->freemap[0];
1181 for (i = 0; i < XFS_ATTR_LEAF_MAPSIZE; map++, i++) { 1174 for (i = 0; i < XFS_ATTR_LEAF_MAPSIZE; map++, i++) {
1182 if (INT_GET(map->base, ARCH_CONVERT) == tmp) { 1175 if (be16_to_cpu(map->base) == tmp) {
1183 INT_MOD(map->base, ARCH_CONVERT, 1176 be16_add(&map->base, sizeof(xfs_attr_leaf_entry_t));
1184 sizeof(xfs_attr_leaf_entry_t)); 1177 be16_add(&map->size,
1185 INT_MOD(map->size, ARCH_CONVERT, 1178 -((int)sizeof(xfs_attr_leaf_entry_t)));
1186 -sizeof(xfs_attr_leaf_entry_t));
1187 } 1179 }
1188 } 1180 }
1189 INT_MOD(hdr->usedbytes, ARCH_CONVERT, 1181 be16_add(&hdr->usedbytes, xfs_attr_leaf_entsize(leaf, args->index));
1190 xfs_attr_leaf_entsize(leaf, args->index));
1191 xfs_da_log_buf(args->trans, bp, 1182 xfs_da_log_buf(args->trans, bp,
1192 XFS_DA_LOGRANGE(leaf, hdr, sizeof(*hdr))); 1183 XFS_DA_LOGRANGE(leaf, hdr, sizeof(*hdr)));
1193 return(0); 1184 return(0);
@@ -1218,28 +1209,25 @@ xfs_attr_leaf_compact(xfs_trans_t *trans, xfs_dabuf_t *bp)
1218 hdr_s = &leaf_s->hdr; 1209 hdr_s = &leaf_s->hdr;
1219 hdr_d = &leaf_d->hdr; 1210 hdr_d = &leaf_d->hdr;
1220 hdr_d->info = hdr_s->info; /* struct copy */ 1211 hdr_d->info = hdr_s->info; /* struct copy */
1221 INT_SET(hdr_d->firstused, ARCH_CONVERT, XFS_LBSIZE(mp)); 1212 hdr_d->firstused = cpu_to_be16(XFS_LBSIZE(mp));
1222 /* handle truncation gracefully */ 1213 /* handle truncation gracefully */
1223 if (!hdr_d->firstused) { 1214 if (!hdr_d->firstused) {
1224 INT_SET(hdr_d->firstused, ARCH_CONVERT, 1215 hdr_d->firstused = cpu_to_be16(
1225 XFS_LBSIZE(mp) - XFS_ATTR_LEAF_NAME_ALIGN); 1216 XFS_LBSIZE(mp) - XFS_ATTR_LEAF_NAME_ALIGN);
1226 } 1217 }
1227 hdr_d->usedbytes = 0; 1218 hdr_d->usedbytes = 0;
1228 hdr_d->count = 0; 1219 hdr_d->count = 0;
1229 hdr_d->holes = 0; 1220 hdr_d->holes = 0;
1230 INT_SET(hdr_d->freemap[0].base, ARCH_CONVERT, 1221 hdr_d->freemap[0].base = cpu_to_be16(sizeof(xfs_attr_leaf_hdr_t));
1231 sizeof(xfs_attr_leaf_hdr_t)); 1222 hdr_d->freemap[0].size = cpu_to_be16(be16_to_cpu(hdr_d->firstused) -
1232 INT_SET(hdr_d->freemap[0].size, ARCH_CONVERT, 1223 sizeof(xfs_attr_leaf_hdr_t));
1233 INT_GET(hdr_d->firstused, ARCH_CONVERT)
1234 - INT_GET(hdr_d->freemap[0].base, ARCH_CONVERT));
1235 1224
1236 /* 1225 /*
1237 * Copy all entry's in the same (sorted) order, 1226 * Copy all entry's in the same (sorted) order,
1238 * but allocate name/value pairs packed and in sequence. 1227 * but allocate name/value pairs packed and in sequence.
1239 */ 1228 */
1240 xfs_attr_leaf_moveents(leaf_s, 0, leaf_d, 0, 1229 xfs_attr_leaf_moveents(leaf_s, 0, leaf_d, 0,
1241 (int)INT_GET(hdr_s->count, ARCH_CONVERT), mp); 1230 be16_to_cpu(hdr_s->count), mp);
1242
1243 xfs_da_log_buf(trans, bp, 0, XFS_LBSIZE(mp) - 1); 1231 xfs_da_log_buf(trans, bp, 0, XFS_LBSIZE(mp) - 1);
1244 1232
1245 kmem_free(tmpbuffer, XFS_LBSIZE(mp)); 1233 kmem_free(tmpbuffer, XFS_LBSIZE(mp));
@@ -1312,22 +1300,21 @@ xfs_attr_leaf_rebalance(xfs_da_state_t *state, xfs_da_state_blk_t *blk1,
1312 /* 1300 /*
1313 * Move any entries required from leaf to leaf: 1301 * Move any entries required from leaf to leaf:
1314 */ 1302 */
1315 if (count < INT_GET(hdr1->count, ARCH_CONVERT)) { 1303 if (count < be16_to_cpu(hdr1->count)) {
1316 /* 1304 /*
1317 * Figure the total bytes to be added to the destination leaf. 1305 * Figure the total bytes to be added to the destination leaf.
1318 */ 1306 */
1319 /* number entries being moved */ 1307 /* number entries being moved */
1320 count = INT_GET(hdr1->count, ARCH_CONVERT) - count; 1308 count = be16_to_cpu(hdr1->count) - count;
1321 space = INT_GET(hdr1->usedbytes, ARCH_CONVERT) - totallen; 1309 space = be16_to_cpu(hdr1->usedbytes) - totallen;
1322 space += count * sizeof(xfs_attr_leaf_entry_t); 1310 space += count * sizeof(xfs_attr_leaf_entry_t);
1323 1311
1324 /* 1312 /*
1325 * leaf2 is the destination, compact it if it looks tight. 1313 * leaf2 is the destination, compact it if it looks tight.
1326 */ 1314 */
1327 max = INT_GET(hdr2->firstused, ARCH_CONVERT) 1315 max = be16_to_cpu(hdr2->firstused)
1328 - sizeof(xfs_attr_leaf_hdr_t); 1316 - sizeof(xfs_attr_leaf_hdr_t);
1329 max -= INT_GET(hdr2->count, ARCH_CONVERT) 1317 max -= be16_to_cpu(hdr2->count) * sizeof(xfs_attr_leaf_entry_t);
1330 * sizeof(xfs_attr_leaf_entry_t);
1331 if (space > max) { 1318 if (space > max) {
1332 xfs_attr_leaf_compact(args->trans, blk2->bp); 1319 xfs_attr_leaf_compact(args->trans, blk2->bp);
1333 } 1320 }
@@ -1335,13 +1322,12 @@ xfs_attr_leaf_rebalance(xfs_da_state_t *state, xfs_da_state_blk_t *blk1,
1335 /* 1322 /*
1336 * Move high entries from leaf1 to low end of leaf2. 1323 * Move high entries from leaf1 to low end of leaf2.
1337 */ 1324 */
1338 xfs_attr_leaf_moveents(leaf1, 1325 xfs_attr_leaf_moveents(leaf1, be16_to_cpu(hdr1->count) - count,
1339 INT_GET(hdr1->count, ARCH_CONVERT)-count,
1340 leaf2, 0, count, state->mp); 1326 leaf2, 0, count, state->mp);
1341 1327
1342 xfs_da_log_buf(args->trans, blk1->bp, 0, state->blocksize-1); 1328 xfs_da_log_buf(args->trans, blk1->bp, 0, state->blocksize-1);
1343 xfs_da_log_buf(args->trans, blk2->bp, 0, state->blocksize-1); 1329 xfs_da_log_buf(args->trans, blk2->bp, 0, state->blocksize-1);
1344 } else if (count > INT_GET(hdr1->count, ARCH_CONVERT)) { 1330 } else if (count > be16_to_cpu(hdr1->count)) {
1345 /* 1331 /*
1346 * I assert that since all callers pass in an empty 1332 * I assert that since all callers pass in an empty
1347 * second buffer, this code should never execute. 1333 * second buffer, this code should never execute.
@@ -1351,17 +1337,16 @@ xfs_attr_leaf_rebalance(xfs_da_state_t *state, xfs_da_state_blk_t *blk1,
1351 * Figure the total bytes to be added to the destination leaf. 1337 * Figure the total bytes to be added to the destination leaf.
1352 */ 1338 */
1353 /* number entries being moved */ 1339 /* number entries being moved */
1354 count -= INT_GET(hdr1->count, ARCH_CONVERT); 1340 count -= be16_to_cpu(hdr1->count);
1355 space = totallen - INT_GET(hdr1->usedbytes, ARCH_CONVERT); 1341 space = totallen - be16_to_cpu(hdr1->usedbytes);
1356 space += count * sizeof(xfs_attr_leaf_entry_t); 1342 space += count * sizeof(xfs_attr_leaf_entry_t);
1357 1343
1358 /* 1344 /*
1359 * leaf1 is the destination, compact it if it looks tight. 1345 * leaf1 is the destination, compact it if it looks tight.
1360 */ 1346 */
1361 max = INT_GET(hdr1->firstused, ARCH_CONVERT) 1347 max = be16_to_cpu(hdr1->firstused)
1362 - sizeof(xfs_attr_leaf_hdr_t); 1348 - sizeof(xfs_attr_leaf_hdr_t);
1363 max -= INT_GET(hdr1->count, ARCH_CONVERT) 1349 max -= be16_to_cpu(hdr1->count) * sizeof(xfs_attr_leaf_entry_t);
1364 * sizeof(xfs_attr_leaf_entry_t);
1365 if (space > max) { 1350 if (space > max) {
1366 xfs_attr_leaf_compact(args->trans, blk1->bp); 1351 xfs_attr_leaf_compact(args->trans, blk1->bp);
1367 } 1352 }
@@ -1370,8 +1355,7 @@ xfs_attr_leaf_rebalance(xfs_da_state_t *state, xfs_da_state_blk_t *blk1,
1370 * Move low entries from leaf2 to high end of leaf1. 1355 * Move low entries from leaf2 to high end of leaf1.
1371 */ 1356 */
1372 xfs_attr_leaf_moveents(leaf2, 0, leaf1, 1357 xfs_attr_leaf_moveents(leaf2, 0, leaf1,
1373 (int)INT_GET(hdr1->count, ARCH_CONVERT), count, 1358 be16_to_cpu(hdr1->count), count, state->mp);
1374 state->mp);
1375 1359
1376 xfs_da_log_buf(args->trans, blk1->bp, 0, state->blocksize-1); 1360 xfs_da_log_buf(args->trans, blk1->bp, 0, state->blocksize-1);
1377 xfs_da_log_buf(args->trans, blk2->bp, 0, state->blocksize-1); 1361 xfs_da_log_buf(args->trans, blk2->bp, 0, state->blocksize-1);
@@ -1381,11 +1365,11 @@ xfs_attr_leaf_rebalance(xfs_da_state_t *state, xfs_da_state_blk_t *blk1,
1381 * Copy out last hashval in each block for B-tree code. 1365 * Copy out last hashval in each block for B-tree code.
1382 */ 1366 */
1383 blk1->hashval = 1367 blk1->hashval =
1384 INT_GET(leaf1->entries[INT_GET(leaf1->hdr.count, 1368 INT_GET(leaf1->entries[be16_to_cpu(leaf1->hdr.count)-1].hashval,
1385 ARCH_CONVERT)-1].hashval, ARCH_CONVERT); 1369 ARCH_CONVERT);
1386 blk2->hashval = 1370 blk2->hashval =
1387 INT_GET(leaf2->entries[INT_GET(leaf2->hdr.count, 1371 INT_GET(leaf2->entries[be16_to_cpu(leaf2->hdr.count)-1].hashval,
1388 ARCH_CONVERT)-1].hashval, ARCH_CONVERT); 1372 ARCH_CONVERT);
1389 1373
1390 /* 1374 /*
1391 * Adjust the expected index for insertion. 1375 * Adjust the expected index for insertion.
@@ -1399,13 +1383,12 @@ xfs_attr_leaf_rebalance(xfs_da_state_t *state, xfs_da_state_blk_t *blk1,
1399 * inserting. The index/blkno fields refer to the "old" entry, 1383 * inserting. The index/blkno fields refer to the "old" entry,
1400 * while the index2/blkno2 fields refer to the "new" entry. 1384 * while the index2/blkno2 fields refer to the "new" entry.
1401 */ 1385 */
1402 if (blk1->index > INT_GET(leaf1->hdr.count, ARCH_CONVERT)) { 1386 if (blk1->index > be16_to_cpu(leaf1->hdr.count)) {
1403 ASSERT(state->inleaf == 0); 1387 ASSERT(state->inleaf == 0);
1404 blk2->index = blk1->index 1388 blk2->index = blk1->index - be16_to_cpu(leaf1->hdr.count);
1405 - INT_GET(leaf1->hdr.count, ARCH_CONVERT);
1406 args->index = args->index2 = blk2->index; 1389 args->index = args->index2 = blk2->index;
1407 args->blkno = args->blkno2 = blk2->blkno; 1390 args->blkno = args->blkno2 = blk2->blkno;
1408 } else if (blk1->index == INT_GET(leaf1->hdr.count, ARCH_CONVERT)) { 1391 } else if (blk1->index == be16_to_cpu(leaf1->hdr.count)) {
1409 if (state->inleaf) { 1392 if (state->inleaf) {
1410 args->index = blk1->index; 1393 args->index = blk1->index;
1411 args->blkno = blk1->blkno; 1394 args->blkno = blk1->blkno;
@@ -1413,7 +1396,7 @@ xfs_attr_leaf_rebalance(xfs_da_state_t *state, xfs_da_state_blk_t *blk1,
1413 args->blkno2 = blk2->blkno; 1396 args->blkno2 = blk2->blkno;
1414 } else { 1397 } else {
1415 blk2->index = blk1->index 1398 blk2->index = blk1->index
1416 - INT_GET(leaf1->hdr.count, ARCH_CONVERT); 1399 - be16_to_cpu(leaf1->hdr.count);
1417 args->index = args->index2 = blk2->index; 1400 args->index = args->index2 = blk2->index;
1418 args->blkno = args->blkno2 = blk2->blkno; 1401 args->blkno = args->blkno2 = blk2->blkno;
1419 } 1402 }
@@ -1457,15 +1440,14 @@ xfs_attr_leaf_figure_balance(xfs_da_state_t *state,
1457 * Examine entries until we reduce the absolute difference in 1440 * Examine entries until we reduce the absolute difference in
1458 * byte usage between the two blocks to a minimum. 1441 * byte usage between the two blocks to a minimum.
1459 */ 1442 */
1460 max = INT_GET(hdr1->count, ARCH_CONVERT) 1443 max = be16_to_cpu(hdr1->count) + be16_to_cpu(hdr2->count);
1461 + INT_GET(hdr2->count, ARCH_CONVERT);
1462 half = (max+1) * sizeof(*entry); 1444 half = (max+1) * sizeof(*entry);
1463 half += INT_GET(hdr1->usedbytes, ARCH_CONVERT) 1445 half += be16_to_cpu(hdr1->usedbytes) +
1464 + INT_GET(hdr2->usedbytes, ARCH_CONVERT) 1446 be16_to_cpu(hdr2->usedbytes) +
1465 + xfs_attr_leaf_newentsize( 1447 xfs_attr_leaf_newentsize(
1466 state->args->namelen, 1448 state->args->namelen,
1467 state->args->valuelen, 1449 state->args->valuelen,
1468 state->blocksize, NULL); 1450 state->blocksize, NULL);
1469 half /= 2; 1451 half /= 2;
1470 lastdelta = state->blocksize; 1452 lastdelta = state->blocksize;
1471 entry = &leaf1->entries[0]; 1453 entry = &leaf1->entries[0];
@@ -1491,7 +1473,7 @@ xfs_attr_leaf_figure_balance(xfs_da_state_t *state,
1491 /* 1473 /*
1492 * Wrap around into the second block if necessary. 1474 * Wrap around into the second block if necessary.
1493 */ 1475 */
1494 if (count == INT_GET(hdr1->count, ARCH_CONVERT)) { 1476 if (count == be16_to_cpu(hdr1->count)) {
1495 leaf1 = leaf2; 1477 leaf1 = leaf2;
1496 entry = &leaf1->entries[0]; 1478 entry = &leaf1->entries[0];
1497 index = 0; 1479 index = 0;
@@ -1561,10 +1543,10 @@ xfs_attr_leaf_toosmall(xfs_da_state_t *state, int *action)
1561 info = blk->bp->data; 1543 info = blk->bp->data;
1562 ASSERT(be16_to_cpu(info->magic) == XFS_ATTR_LEAF_MAGIC); 1544 ASSERT(be16_to_cpu(info->magic) == XFS_ATTR_LEAF_MAGIC);
1563 leaf = (xfs_attr_leafblock_t *)info; 1545 leaf = (xfs_attr_leafblock_t *)info;
1564 count = INT_GET(leaf->hdr.count, ARCH_CONVERT); 1546 count = be16_to_cpu(leaf->hdr.count);
1565 bytes = sizeof(xfs_attr_leaf_hdr_t) + 1547 bytes = sizeof(xfs_attr_leaf_hdr_t) +
1566 count * sizeof(xfs_attr_leaf_entry_t) + 1548 count * sizeof(xfs_attr_leaf_entry_t) +
1567 INT_GET(leaf->hdr.usedbytes, ARCH_CONVERT); 1549 be16_to_cpu(leaf->hdr.usedbytes);
1568 if (bytes > (state->blocksize >> 1)) { 1550 if (bytes > (state->blocksize >> 1)) {
1569 *action = 0; /* blk over 50%, don't try to join */ 1551 *action = 0; /* blk over 50%, don't try to join */
1570 return(0); 1552 return(0);
@@ -1618,13 +1600,13 @@ xfs_attr_leaf_toosmall(xfs_da_state_t *state, int *action)
1618 ASSERT(bp != NULL); 1600 ASSERT(bp != NULL);
1619 1601
1620 leaf = (xfs_attr_leafblock_t *)info; 1602 leaf = (xfs_attr_leafblock_t *)info;
1621 count = INT_GET(leaf->hdr.count, ARCH_CONVERT); 1603 count = be16_to_cpu(leaf->hdr.count);
1622 bytes = state->blocksize - (state->blocksize>>2); 1604 bytes = state->blocksize - (state->blocksize>>2);
1623 bytes -= INT_GET(leaf->hdr.usedbytes, ARCH_CONVERT); 1605 bytes -= be16_to_cpu(leaf->hdr.usedbytes);
1624 leaf = bp->data; 1606 leaf = bp->data;
1625 ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_ATTR_LEAF_MAGIC); 1607 ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_ATTR_LEAF_MAGIC);
1626 count += INT_GET(leaf->hdr.count, ARCH_CONVERT); 1608 count += be16_to_cpu(leaf->hdr.count);
1627 bytes -= INT_GET(leaf->hdr.usedbytes, ARCH_CONVERT); 1609 bytes -= be16_to_cpu(leaf->hdr.usedbytes);
1628 bytes -= count * sizeof(xfs_attr_leaf_entry_t); 1610 bytes -= count * sizeof(xfs_attr_leaf_entry_t);
1629 bytes -= sizeof(xfs_attr_leaf_hdr_t); 1611 bytes -= sizeof(xfs_attr_leaf_hdr_t);
1630 xfs_da_brelse(state->args->trans, bp); 1612 xfs_da_brelse(state->args->trans, bp);
@@ -1679,16 +1661,15 @@ xfs_attr_leaf_remove(xfs_dabuf_t *bp, xfs_da_args_t *args)
1679 ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_ATTR_LEAF_MAGIC); 1661 ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_ATTR_LEAF_MAGIC);
1680 hdr = &leaf->hdr; 1662 hdr = &leaf->hdr;
1681 mp = args->trans->t_mountp; 1663 mp = args->trans->t_mountp;
1682 ASSERT((INT_GET(hdr->count, ARCH_CONVERT) > 0) 1664 ASSERT((be16_to_cpu(hdr->count) > 0)
1683 && (INT_GET(hdr->count, ARCH_CONVERT) < (XFS_LBSIZE(mp)/8))); 1665 && (be16_to_cpu(hdr->count) < (XFS_LBSIZE(mp)/8)));
1684 ASSERT((args->index >= 0) 1666 ASSERT((args->index >= 0)
1685 && (args->index < INT_GET(hdr->count, ARCH_CONVERT))); 1667 && (args->index < be16_to_cpu(hdr->count)));
1686 ASSERT(INT_GET(hdr->firstused, ARCH_CONVERT) 1668 ASSERT(be16_to_cpu(hdr->firstused) >=
1687 >= ((INT_GET(hdr->count, ARCH_CONVERT) 1669 ((be16_to_cpu(hdr->count) * sizeof(*entry)) + sizeof(*hdr)));
1688 * sizeof(*entry))+sizeof(*hdr)));
1689 entry = &leaf->entries[args->index]; 1670 entry = &leaf->entries[args->index];
1690 ASSERT(INT_GET(entry->nameidx, ARCH_CONVERT) 1671 ASSERT(INT_GET(entry->nameidx, ARCH_CONVERT)
1691 >= INT_GET(hdr->firstused, ARCH_CONVERT)); 1672 >= be16_to_cpu(hdr->firstused));
1692 ASSERT(INT_GET(entry->nameidx, ARCH_CONVERT) < XFS_LBSIZE(mp)); 1673 ASSERT(INT_GET(entry->nameidx, ARCH_CONVERT) < XFS_LBSIZE(mp));
1693 1674
1694 /* 1675 /*
@@ -1697,33 +1678,30 @@ xfs_attr_leaf_remove(xfs_dabuf_t *bp, xfs_da_args_t *args)
1697 * find smallest free region in case we need to replace it, 1678 * find smallest free region in case we need to replace it,
1698 * adjust any map that borders the entry table, 1679 * adjust any map that borders the entry table,
1699 */ 1680 */
1700 tablesize = INT_GET(hdr->count, ARCH_CONVERT) 1681 tablesize = be16_to_cpu(hdr->count) * sizeof(xfs_attr_leaf_entry_t)
1701 * sizeof(xfs_attr_leaf_entry_t)
1702 + sizeof(xfs_attr_leaf_hdr_t); 1682 + sizeof(xfs_attr_leaf_hdr_t);
1703 map = &hdr->freemap[0]; 1683 map = &hdr->freemap[0];
1704 tmp = INT_GET(map->size, ARCH_CONVERT); 1684 tmp = be16_to_cpu(map->size);
1705 before = after = -1; 1685 before = after = -1;
1706 smallest = XFS_ATTR_LEAF_MAPSIZE - 1; 1686 smallest = XFS_ATTR_LEAF_MAPSIZE - 1;
1707 entsize = xfs_attr_leaf_entsize(leaf, args->index); 1687 entsize = xfs_attr_leaf_entsize(leaf, args->index);
1708 for (i = 0; i < XFS_ATTR_LEAF_MAPSIZE; map++, i++) { 1688 for (i = 0; i < XFS_ATTR_LEAF_MAPSIZE; map++, i++) {
1709 ASSERT(INT_GET(map->base, ARCH_CONVERT) < XFS_LBSIZE(mp)); 1689 ASSERT(be16_to_cpu(map->base) < XFS_LBSIZE(mp));
1710 ASSERT(INT_GET(map->size, ARCH_CONVERT) < XFS_LBSIZE(mp)); 1690 ASSERT(be16_to_cpu(map->size) < XFS_LBSIZE(mp));
1711 if (INT_GET(map->base, ARCH_CONVERT) == tablesize) { 1691 if (be16_to_cpu(map->base) == tablesize) {
1712 INT_MOD(map->base, ARCH_CONVERT, 1692 be16_add(&map->base,
1713 -sizeof(xfs_attr_leaf_entry_t)); 1693 -((int)sizeof(xfs_attr_leaf_entry_t)));
1714 INT_MOD(map->size, ARCH_CONVERT, 1694 be16_add(&map->size, sizeof(xfs_attr_leaf_entry_t));
1715 sizeof(xfs_attr_leaf_entry_t));
1716 } 1695 }
1717 1696
1718 if ((INT_GET(map->base, ARCH_CONVERT) 1697 if ((be16_to_cpu(map->base) + be16_to_cpu(map->size))
1719 + INT_GET(map->size, ARCH_CONVERT))
1720 == INT_GET(entry->nameidx, ARCH_CONVERT)) { 1698 == INT_GET(entry->nameidx, ARCH_CONVERT)) {
1721 before = i; 1699 before = i;
1722 } else if (INT_GET(map->base, ARCH_CONVERT) 1700 } else if (be16_to_cpu(map->base)
1723 == (INT_GET(entry->nameidx, ARCH_CONVERT) + entsize)) { 1701 == (INT_GET(entry->nameidx, ARCH_CONVERT) + entsize)) {
1724 after = i; 1702 after = i;
1725 } else if (INT_GET(map->size, ARCH_CONVERT) < tmp) { 1703 } else if (be16_to_cpu(map->size) < tmp) {
1726 tmp = INT_GET(map->size, ARCH_CONVERT); 1704 tmp = be16_to_cpu(map->size);
1727 smallest = i; 1705 smallest = i;
1728 } 1706 }
1729 } 1707 }
@@ -1735,30 +1713,29 @@ xfs_attr_leaf_remove(xfs_dabuf_t *bp, xfs_da_args_t *args)
1735 if ((before >= 0) || (after >= 0)) { 1713 if ((before >= 0) || (after >= 0)) {
1736 if ((before >= 0) && (after >= 0)) { 1714 if ((before >= 0) && (after >= 0)) {
1737 map = &hdr->freemap[before]; 1715 map = &hdr->freemap[before];
1738 INT_MOD(map->size, ARCH_CONVERT, entsize); 1716 be16_add(&map->size, entsize);
1739 INT_MOD(map->size, ARCH_CONVERT, 1717 be16_add(&map->size,
1740 INT_GET(hdr->freemap[after].size, 1718 be16_to_cpu(hdr->freemap[after].size));
1741 ARCH_CONVERT));
1742 hdr->freemap[after].base = 0; 1719 hdr->freemap[after].base = 0;
1743 hdr->freemap[after].size = 0; 1720 hdr->freemap[after].size = 0;
1744 } else if (before >= 0) { 1721 } else if (before >= 0) {
1745 map = &hdr->freemap[before]; 1722 map = &hdr->freemap[before];
1746 INT_MOD(map->size, ARCH_CONVERT, entsize); 1723 be16_add(&map->size, entsize);
1747 } else { 1724 } else {
1748 map = &hdr->freemap[after]; 1725 map = &hdr->freemap[after];
1749 /* both on-disk, don't endian flip twice */ 1726 /* both on-disk, don't endian flip twice */
1750 map->base = entry->nameidx; 1727 map->base = entry->nameidx;
1751 INT_MOD(map->size, ARCH_CONVERT, entsize); 1728 be16_add(&map->size, entsize);
1752 } 1729 }
1753 } else { 1730 } else {
1754 /* 1731 /*
1755 * Replace smallest region (if it is smaller than free'd entry) 1732 * Replace smallest region (if it is smaller than free'd entry)
1756 */ 1733 */
1757 map = &hdr->freemap[smallest]; 1734 map = &hdr->freemap[smallest];
1758 if (INT_GET(map->size, ARCH_CONVERT) < entsize) { 1735 if (be16_to_cpu(map->size) < entsize) {
1759 INT_SET(map->base, ARCH_CONVERT, 1736 map->base = cpu_to_be16(
1760 INT_GET(entry->nameidx, ARCH_CONVERT)); 1737 INT_GET(entry->nameidx, ARCH_CONVERT));
1761 INT_SET(map->size, ARCH_CONVERT, entsize); 1738 map->size = cpu_to_be16(entsize);
1762 } 1739 }
1763 } 1740 }
1764 1741
@@ -1766,7 +1743,7 @@ xfs_attr_leaf_remove(xfs_dabuf_t *bp, xfs_da_args_t *args)
1766 * Did we remove the first entry? 1743 * Did we remove the first entry?
1767 */ 1744 */
1768 if (INT_GET(entry->nameidx, ARCH_CONVERT) 1745 if (INT_GET(entry->nameidx, ARCH_CONVERT)
1769 == INT_GET(hdr->firstused, ARCH_CONVERT)) 1746 == be16_to_cpu(hdr->firstused))
1770 smallest = 1; 1747 smallest = 1;
1771 else 1748 else
1772 smallest = 0; 1749 smallest = 0;
@@ -1775,18 +1752,18 @@ xfs_attr_leaf_remove(xfs_dabuf_t *bp, xfs_da_args_t *args)
1775 * Compress the remaining entries and zero out the removed stuff. 1752 * Compress the remaining entries and zero out the removed stuff.
1776 */ 1753 */
1777 memset(XFS_ATTR_LEAF_NAME(leaf, args->index), 0, entsize); 1754 memset(XFS_ATTR_LEAF_NAME(leaf, args->index), 0, entsize);
1778 INT_MOD(hdr->usedbytes, ARCH_CONVERT, -entsize); 1755 be16_add(&hdr->usedbytes, -entsize);
1779 xfs_da_log_buf(args->trans, bp, 1756 xfs_da_log_buf(args->trans, bp,
1780 XFS_DA_LOGRANGE(leaf, XFS_ATTR_LEAF_NAME(leaf, args->index), 1757 XFS_DA_LOGRANGE(leaf, XFS_ATTR_LEAF_NAME(leaf, args->index),
1781 entsize)); 1758 entsize));
1782 1759
1783 tmp = (INT_GET(hdr->count, ARCH_CONVERT) - args->index) 1760 tmp = (be16_to_cpu(hdr->count) - args->index)
1784 * sizeof(xfs_attr_leaf_entry_t); 1761 * sizeof(xfs_attr_leaf_entry_t);
1785 memmove((char *)entry, (char *)(entry+1), tmp); 1762 memmove((char *)entry, (char *)(entry+1), tmp);
1786 INT_MOD(hdr->count, ARCH_CONVERT, -1); 1763 be16_add(&hdr->count, -1);
1787 xfs_da_log_buf(args->trans, bp, 1764 xfs_da_log_buf(args->trans, bp,
1788 XFS_DA_LOGRANGE(leaf, entry, tmp + sizeof(*entry))); 1765 XFS_DA_LOGRANGE(leaf, entry, tmp + sizeof(*entry)));
1789 entry = &leaf->entries[INT_GET(hdr->count, ARCH_CONVERT)]; 1766 entry = &leaf->entries[be16_to_cpu(hdr->count)];
1790 memset((char *)entry, 0, sizeof(xfs_attr_leaf_entry_t)); 1767 memset((char *)entry, 0, sizeof(xfs_attr_leaf_entry_t));
1791 1768
1792 /* 1769 /*
@@ -1798,18 +1775,17 @@ xfs_attr_leaf_remove(xfs_dabuf_t *bp, xfs_da_args_t *args)
1798 if (smallest) { 1775 if (smallest) {
1799 tmp = XFS_LBSIZE(mp); 1776 tmp = XFS_LBSIZE(mp);
1800 entry = &leaf->entries[0]; 1777 entry = &leaf->entries[0];
1801 for (i = INT_GET(hdr->count, ARCH_CONVERT)-1; 1778 for (i = be16_to_cpu(hdr->count)-1; i >= 0; entry++, i--) {
1802 i >= 0; entry++, i--) {
1803 ASSERT(INT_GET(entry->nameidx, ARCH_CONVERT) 1779 ASSERT(INT_GET(entry->nameidx, ARCH_CONVERT)
1804 >= INT_GET(hdr->firstused, ARCH_CONVERT)); 1780 >= be16_to_cpu(hdr->firstused));
1805 ASSERT(INT_GET(entry->nameidx, ARCH_CONVERT) 1781 ASSERT(INT_GET(entry->nameidx, ARCH_CONVERT)
1806 < XFS_LBSIZE(mp)); 1782 < XFS_LBSIZE(mp));
1807 if (INT_GET(entry->nameidx, ARCH_CONVERT) < tmp) 1783 if (INT_GET(entry->nameidx, ARCH_CONVERT) < tmp)
1808 tmp = INT_GET(entry->nameidx, ARCH_CONVERT); 1784 tmp = INT_GET(entry->nameidx, ARCH_CONVERT);
1809 } 1785 }
1810 INT_SET(hdr->firstused, ARCH_CONVERT, tmp); 1786 hdr->firstused = cpu_to_be16(tmp);
1811 if (!hdr->firstused) { 1787 if (!hdr->firstused) {
1812 INT_SET(hdr->firstused, ARCH_CONVERT, 1788 hdr->firstused = cpu_to_be16(
1813 tmp - XFS_ATTR_LEAF_NAME_ALIGN); 1789 tmp - XFS_ATTR_LEAF_NAME_ALIGN);
1814 } 1790 }
1815 } else { 1791 } else {
@@ -1823,9 +1799,8 @@ xfs_attr_leaf_remove(xfs_dabuf_t *bp, xfs_da_args_t *args)
1823 * "join" the leaf with a sibling if so. 1799 * "join" the leaf with a sibling if so.
1824 */ 1800 */
1825 tmp = sizeof(xfs_attr_leaf_hdr_t); 1801 tmp = sizeof(xfs_attr_leaf_hdr_t);
1826 tmp += INT_GET(leaf->hdr.count, ARCH_CONVERT) 1802 tmp += be16_to_cpu(leaf->hdr.count) * sizeof(xfs_attr_leaf_entry_t);
1827 * sizeof(xfs_attr_leaf_entry_t); 1803 tmp += be16_to_cpu(leaf->hdr.usedbytes);
1828 tmp += INT_GET(leaf->hdr.usedbytes, ARCH_CONVERT);
1829 return(tmp < mp->m_attr_magicpct); /* leaf is < 37% full */ 1804 return(tmp < mp->m_attr_magicpct); /* leaf is < 37% full */
1830} 1805}
1831 1806
@@ -1858,9 +1833,8 @@ xfs_attr_leaf_unbalance(xfs_da_state_t *state, xfs_da_state_blk_t *drop_blk,
1858 * Save last hashval from dying block for later Btree fixup. 1833 * Save last hashval from dying block for later Btree fixup.
1859 */ 1834 */
1860 drop_blk->hashval = 1835 drop_blk->hashval =
1861 INT_GET(drop_leaf->entries[INT_GET(drop_leaf->hdr.count, 1836 INT_GET(drop_leaf->entries[be16_to_cpu(drop_leaf->hdr.count)-1]
1862 ARCH_CONVERT)-1].hashval, 1837 .hashval, ARCH_CONVERT);
1863 ARCH_CONVERT);
1864 1838
1865 /* 1839 /*
1866 * Check if we need a temp buffer, or can we do it in place. 1840 * Check if we need a temp buffer, or can we do it in place.
@@ -1874,12 +1848,11 @@ xfs_attr_leaf_unbalance(xfs_da_state_t *state, xfs_da_state_blk_t *drop_blk,
1874 */ 1848 */
1875 if (xfs_attr_leaf_order(save_blk->bp, drop_blk->bp)) { 1849 if (xfs_attr_leaf_order(save_blk->bp, drop_blk->bp)) {
1876 xfs_attr_leaf_moveents(drop_leaf, 0, save_leaf, 0, 1850 xfs_attr_leaf_moveents(drop_leaf, 0, save_leaf, 0,
1877 (int)INT_GET(drop_hdr->count, ARCH_CONVERT), mp); 1851 be16_to_cpu(drop_hdr->count), mp);
1878 } else { 1852 } else {
1879 xfs_attr_leaf_moveents(drop_leaf, 0, save_leaf, 1853 xfs_attr_leaf_moveents(drop_leaf, 0, save_leaf,
1880 INT_GET(save_hdr->count, ARCH_CONVERT), 1854 be16_to_cpu(save_hdr->count),
1881 (int)INT_GET(drop_hdr->count, ARCH_CONVERT), 1855 be16_to_cpu(drop_hdr->count), mp);
1882 mp);
1883 } 1856 }
1884 } else { 1857 } else {
1885 /* 1858 /*
@@ -1893,28 +1866,24 @@ xfs_attr_leaf_unbalance(xfs_da_state_t *state, xfs_da_state_blk_t *drop_blk,
1893 tmp_hdr = &tmp_leaf->hdr; 1866 tmp_hdr = &tmp_leaf->hdr;
1894 tmp_hdr->info = save_hdr->info; /* struct copy */ 1867 tmp_hdr->info = save_hdr->info; /* struct copy */
1895 tmp_hdr->count = 0; 1868 tmp_hdr->count = 0;
1896 INT_SET(tmp_hdr->firstused, ARCH_CONVERT, state->blocksize); 1869 tmp_hdr->firstused = cpu_to_be16(state->blocksize);
1897 if (!tmp_hdr->firstused) { 1870 if (!tmp_hdr->firstused) {
1898 INT_SET(tmp_hdr->firstused, ARCH_CONVERT, 1871 tmp_hdr->firstused = cpu_to_be16(
1899 state->blocksize - XFS_ATTR_LEAF_NAME_ALIGN); 1872 state->blocksize - XFS_ATTR_LEAF_NAME_ALIGN);
1900 } 1873 }
1901 tmp_hdr->usedbytes = 0; 1874 tmp_hdr->usedbytes = 0;
1902 if (xfs_attr_leaf_order(save_blk->bp, drop_blk->bp)) { 1875 if (xfs_attr_leaf_order(save_blk->bp, drop_blk->bp)) {
1903 xfs_attr_leaf_moveents(drop_leaf, 0, tmp_leaf, 0, 1876 xfs_attr_leaf_moveents(drop_leaf, 0, tmp_leaf, 0,
1904 (int)INT_GET(drop_hdr->count, ARCH_CONVERT), 1877 be16_to_cpu(drop_hdr->count), mp);
1905 mp);
1906 xfs_attr_leaf_moveents(save_leaf, 0, tmp_leaf, 1878 xfs_attr_leaf_moveents(save_leaf, 0, tmp_leaf,
1907 INT_GET(tmp_leaf->hdr.count, ARCH_CONVERT), 1879 be16_to_cpu(tmp_leaf->hdr.count),
1908 (int)INT_GET(save_hdr->count, ARCH_CONVERT), 1880 be16_to_cpu(save_hdr->count), mp);
1909 mp);
1910 } else { 1881 } else {
1911 xfs_attr_leaf_moveents(save_leaf, 0, tmp_leaf, 0, 1882 xfs_attr_leaf_moveents(save_leaf, 0, tmp_leaf, 0,
1912 (int)INT_GET(save_hdr->count, ARCH_CONVERT), 1883 be16_to_cpu(save_hdr->count), mp);
1913 mp);
1914 xfs_attr_leaf_moveents(drop_leaf, 0, tmp_leaf, 1884 xfs_attr_leaf_moveents(drop_leaf, 0, tmp_leaf,
1915 INT_GET(tmp_leaf->hdr.count, ARCH_CONVERT), 1885 be16_to_cpu(tmp_leaf->hdr.count),
1916 (int)INT_GET(drop_hdr->count, ARCH_CONVERT), 1886 be16_to_cpu(drop_hdr->count), mp);
1917 mp);
1918 } 1887 }
1919 memcpy((char *)save_leaf, (char *)tmp_leaf, state->blocksize); 1888 memcpy((char *)save_leaf, (char *)tmp_leaf, state->blocksize);
1920 kmem_free(tmpbuffer, state->blocksize); 1889 kmem_free(tmpbuffer, state->blocksize);
@@ -1927,9 +1896,8 @@ xfs_attr_leaf_unbalance(xfs_da_state_t *state, xfs_da_state_blk_t *drop_blk,
1927 * Copy out last hashval in each block for B-tree code. 1896 * Copy out last hashval in each block for B-tree code.
1928 */ 1897 */
1929 save_blk->hashval = 1898 save_blk->hashval =
1930 INT_GET(save_leaf->entries[INT_GET(save_leaf->hdr.count, 1899 INT_GET(save_leaf->entries[be16_to_cpu(save_leaf->hdr.count)-1]
1931 ARCH_CONVERT)-1].hashval, 1900 .hashval, ARCH_CONVERT);
1932 ARCH_CONVERT);
1933} 1901}
1934 1902
1935/*======================================================================== 1903/*========================================================================
@@ -1961,14 +1929,14 @@ xfs_attr_leaf_lookup_int(xfs_dabuf_t *bp, xfs_da_args_t *args)
1961 1929
1962 leaf = bp->data; 1930 leaf = bp->data;
1963 ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_ATTR_LEAF_MAGIC); 1931 ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_ATTR_LEAF_MAGIC);
1964 ASSERT(INT_GET(leaf->hdr.count, ARCH_CONVERT) 1932 ASSERT(be16_to_cpu(leaf->hdr.count)
1965 < (XFS_LBSIZE(args->dp->i_mount)/8)); 1933 < (XFS_LBSIZE(args->dp->i_mount)/8));
1966 1934
1967 /* 1935 /*
1968 * Binary search. (note: small blocks will skip this loop) 1936 * Binary search. (note: small blocks will skip this loop)
1969 */ 1937 */
1970 hashval = args->hashval; 1938 hashval = args->hashval;
1971 probe = span = INT_GET(leaf->hdr.count, ARCH_CONVERT) / 2; 1939 probe = span = be16_to_cpu(leaf->hdr.count) / 2;
1972 for (entry = &leaf->entries[probe]; span > 4; 1940 for (entry = &leaf->entries[probe]; span > 4;
1973 entry = &leaf->entries[probe]) { 1941 entry = &leaf->entries[probe]) {
1974 span /= 2; 1942 span /= 2;
@@ -1981,7 +1949,7 @@ xfs_attr_leaf_lookup_int(xfs_dabuf_t *bp, xfs_da_args_t *args)
1981 } 1949 }
1982 ASSERT((probe >= 0) && 1950 ASSERT((probe >= 0) &&
1983 (!leaf->hdr.count 1951 (!leaf->hdr.count
1984 || (probe < INT_GET(leaf->hdr.count, ARCH_CONVERT)))); 1952 || (probe < be16_to_cpu(leaf->hdr.count))));
1985 ASSERT((span <= 4) || (INT_GET(entry->hashval, ARCH_CONVERT) 1953 ASSERT((span <= 4) || (INT_GET(entry->hashval, ARCH_CONVERT)
1986 == hashval)); 1954 == hashval));
1987 1955
@@ -1994,12 +1962,12 @@ xfs_attr_leaf_lookup_int(xfs_dabuf_t *bp, xfs_da_args_t *args)
1994 entry--; 1962 entry--;
1995 probe--; 1963 probe--;
1996 } 1964 }
1997 while ((probe < INT_GET(leaf->hdr.count, ARCH_CONVERT)) 1965 while ((probe < be16_to_cpu(leaf->hdr.count))
1998 && (INT_GET(entry->hashval, ARCH_CONVERT) < hashval)) { 1966 && (INT_GET(entry->hashval, ARCH_CONVERT) < hashval)) {
1999 entry++; 1967 entry++;
2000 probe++; 1968 probe++;
2001 } 1969 }
2002 if ((probe == INT_GET(leaf->hdr.count, ARCH_CONVERT)) 1970 if ((probe == be16_to_cpu(leaf->hdr.count))
2003 || (INT_GET(entry->hashval, ARCH_CONVERT) != hashval)) { 1971 || (INT_GET(entry->hashval, ARCH_CONVERT) != hashval)) {
2004 args->index = probe; 1972 args->index = probe;
2005 return(XFS_ERROR(ENOATTR)); 1973 return(XFS_ERROR(ENOATTR));
@@ -2008,7 +1976,7 @@ xfs_attr_leaf_lookup_int(xfs_dabuf_t *bp, xfs_da_args_t *args)
2008 /* 1976 /*
2009 * Duplicate keys may be present, so search all of them for a match. 1977 * Duplicate keys may be present, so search all of them for a match.
2010 */ 1978 */
2011 for ( ; (probe < INT_GET(leaf->hdr.count, ARCH_CONVERT)) 1979 for ( ; (probe < be16_to_cpu(leaf->hdr.count))
2012 && (INT_GET(entry->hashval, ARCH_CONVERT) == hashval); 1980 && (INT_GET(entry->hashval, ARCH_CONVERT) == hashval);
2013 entry++, probe++) { 1981 entry++, probe++) {
2014/* 1982/*
@@ -2078,9 +2046,9 @@ xfs_attr_leaf_getvalue(xfs_dabuf_t *bp, xfs_da_args_t *args)
2078 2046
2079 leaf = bp->data; 2047 leaf = bp->data;
2080 ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_ATTR_LEAF_MAGIC); 2048 ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_ATTR_LEAF_MAGIC);
2081 ASSERT(INT_GET(leaf->hdr.count, ARCH_CONVERT) 2049 ASSERT(be16_to_cpu(leaf->hdr.count)
2082 < (XFS_LBSIZE(args->dp->i_mount)/8)); 2050 < (XFS_LBSIZE(args->dp->i_mount)/8));
2083 ASSERT(args->index < ((int)INT_GET(leaf->hdr.count, ARCH_CONVERT))); 2051 ASSERT(args->index < be16_to_cpu(leaf->hdr.count));
2084 2052
2085 entry = &leaf->entries[args->index]; 2053 entry = &leaf->entries[args->index];
2086 if (entry->flags & XFS_ATTR_LOCAL) { 2054 if (entry->flags & XFS_ATTR_LOCAL) {
@@ -2149,26 +2117,25 @@ xfs_attr_leaf_moveents(xfs_attr_leafblock_t *leaf_s, int start_s,
2149 ASSERT(be16_to_cpu(leaf_d->hdr.info.magic) == XFS_ATTR_LEAF_MAGIC); 2117 ASSERT(be16_to_cpu(leaf_d->hdr.info.magic) == XFS_ATTR_LEAF_MAGIC);
2150 hdr_s = &leaf_s->hdr; 2118 hdr_s = &leaf_s->hdr;
2151 hdr_d = &leaf_d->hdr; 2119 hdr_d = &leaf_d->hdr;
2152 ASSERT((INT_GET(hdr_s->count, ARCH_CONVERT) > 0) 2120 ASSERT((be16_to_cpu(hdr_s->count) > 0) &&
2153 && (INT_GET(hdr_s->count, ARCH_CONVERT) 2121 (be16_to_cpu(hdr_s->count) < (XFS_LBSIZE(mp)/8)));
2154 < (XFS_LBSIZE(mp)/8))); 2122 ASSERT(be16_to_cpu(hdr_s->firstused) >=
2155 ASSERT(INT_GET(hdr_s->firstused, ARCH_CONVERT) >= 2123 ((be16_to_cpu(hdr_s->count)
2156 ((INT_GET(hdr_s->count, ARCH_CONVERT)
2157 * sizeof(*entry_s))+sizeof(*hdr_s))); 2124 * sizeof(*entry_s))+sizeof(*hdr_s)));
2158 ASSERT(INT_GET(hdr_d->count, ARCH_CONVERT) < (XFS_LBSIZE(mp)/8)); 2125 ASSERT(be16_to_cpu(hdr_d->count) < (XFS_LBSIZE(mp)/8));
2159 ASSERT(INT_GET(hdr_d->firstused, ARCH_CONVERT) >= 2126 ASSERT(be16_to_cpu(hdr_d->firstused) >=
2160 ((INT_GET(hdr_d->count, ARCH_CONVERT) 2127 ((be16_to_cpu(hdr_d->count)
2161 * sizeof(*entry_d))+sizeof(*hdr_d))); 2128 * sizeof(*entry_d))+sizeof(*hdr_d)));
2162 2129
2163 ASSERT(start_s < INT_GET(hdr_s->count, ARCH_CONVERT)); 2130 ASSERT(start_s < be16_to_cpu(hdr_s->count));
2164 ASSERT(start_d <= INT_GET(hdr_d->count, ARCH_CONVERT)); 2131 ASSERT(start_d <= be16_to_cpu(hdr_d->count));
2165 ASSERT(count <= INT_GET(hdr_s->count, ARCH_CONVERT)); 2132 ASSERT(count <= be16_to_cpu(hdr_s->count));
2166 2133
2167 /* 2134 /*
2168 * Move the entries in the destination leaf up to make a hole? 2135 * Move the entries in the destination leaf up to make a hole?
2169 */ 2136 */
2170 if (start_d < INT_GET(hdr_d->count, ARCH_CONVERT)) { 2137 if (start_d < be16_to_cpu(hdr_d->count)) {
2171 tmp = INT_GET(hdr_d->count, ARCH_CONVERT) - start_d; 2138 tmp = be16_to_cpu(hdr_d->count) - start_d;
2172 tmp *= sizeof(xfs_attr_leaf_entry_t); 2139 tmp *= sizeof(xfs_attr_leaf_entry_t);
2173 entry_s = &leaf_d->entries[start_d]; 2140 entry_s = &leaf_d->entries[start_d];
2174 entry_d = &leaf_d->entries[start_d + count]; 2141 entry_d = &leaf_d->entries[start_d + count];
@@ -2184,7 +2151,7 @@ xfs_attr_leaf_moveents(xfs_attr_leafblock_t *leaf_s, int start_s,
2184 desti = start_d; 2151 desti = start_d;
2185 for (i = 0; i < count; entry_s++, entry_d++, desti++, i++) { 2152 for (i = 0; i < count; entry_s++, entry_d++, desti++, i++) {
2186 ASSERT(INT_GET(entry_s->nameidx, ARCH_CONVERT) 2153 ASSERT(INT_GET(entry_s->nameidx, ARCH_CONVERT)
2187 >= INT_GET(hdr_s->firstused, ARCH_CONVERT)); 2154 >= be16_to_cpu(hdr_s->firstused));
2188 tmp = xfs_attr_leaf_entsize(leaf_s, start_s + i); 2155 tmp = xfs_attr_leaf_entsize(leaf_s, start_s + i);
2189#ifdef GROT 2156#ifdef GROT
2190 /* 2157 /*
@@ -2194,15 +2161,15 @@ xfs_attr_leaf_moveents(xfs_attr_leafblock_t *leaf_s, int start_s,
2194 */ 2161 */
2195 if (entry_s->flags & XFS_ATTR_INCOMPLETE) { /* skip partials? */ 2162 if (entry_s->flags & XFS_ATTR_INCOMPLETE) { /* skip partials? */
2196 memset(XFS_ATTR_LEAF_NAME(leaf_s, start_s + i), 0, tmp); 2163 memset(XFS_ATTR_LEAF_NAME(leaf_s, start_s + i), 0, tmp);
2197 INT_MOD(hdr_s->usedbytes, ARCH_CONVERT, -tmp); 2164 be16_add(&hdr_s->usedbytes, -tmp);
2198 INT_MOD(hdr_s->count, ARCH_CONVERT, -1); 2165 be16_add(&hdr_s->count, -1);
2199 entry_d--; /* to compensate for ++ in loop hdr */ 2166 entry_d--; /* to compensate for ++ in loop hdr */
2200 desti--; 2167 desti--;
2201 if ((start_s + i) < offset) 2168 if ((start_s + i) < offset)
2202 result++; /* insertion index adjustment */ 2169 result++; /* insertion index adjustment */
2203 } else { 2170 } else {
2204#endif /* GROT */ 2171#endif /* GROT */
2205 INT_MOD(hdr_d->firstused, ARCH_CONVERT, -tmp); 2172 be16_add(&hdr_d->firstused, -tmp);
2206 /* both on-disk, don't endian flip twice */ 2173 /* both on-disk, don't endian flip twice */
2207 entry_d->hashval = entry_s->hashval; 2174 entry_d->hashval = entry_s->hashval;
2208 /* both on-disk, don't endian flip twice */ 2175 /* both on-disk, don't endian flip twice */
@@ -2215,14 +2182,14 @@ xfs_attr_leaf_moveents(xfs_attr_leafblock_t *leaf_s, int start_s,
2215 ASSERT(INT_GET(entry_s->nameidx, ARCH_CONVERT) + tmp 2182 ASSERT(INT_GET(entry_s->nameidx, ARCH_CONVERT) + tmp
2216 <= XFS_LBSIZE(mp)); 2183 <= XFS_LBSIZE(mp));
2217 memset(XFS_ATTR_LEAF_NAME(leaf_s, start_s + i), 0, tmp); 2184 memset(XFS_ATTR_LEAF_NAME(leaf_s, start_s + i), 0, tmp);
2218 INT_MOD(hdr_s->usedbytes, ARCH_CONVERT, -tmp); 2185 be16_add(&hdr_s->usedbytes, -tmp);
2219 INT_MOD(hdr_d->usedbytes, ARCH_CONVERT, tmp); 2186 be16_add(&hdr_d->usedbytes, tmp);
2220 INT_MOD(hdr_s->count, ARCH_CONVERT, -1); 2187 be16_add(&hdr_s->count, -1);
2221 INT_MOD(hdr_d->count, ARCH_CONVERT, 1); 2188 be16_add(&hdr_d->count, 1);
2222 tmp = INT_GET(hdr_d->count, ARCH_CONVERT) 2189 tmp = be16_to_cpu(hdr_d->count)
2223 * sizeof(xfs_attr_leaf_entry_t) 2190 * sizeof(xfs_attr_leaf_entry_t)
2224 + sizeof(xfs_attr_leaf_hdr_t); 2191 + sizeof(xfs_attr_leaf_hdr_t);
2225 ASSERT(INT_GET(hdr_d->firstused, ARCH_CONVERT) >= tmp); 2192 ASSERT(be16_to_cpu(hdr_d->firstused) >= tmp);
2226#ifdef GROT 2193#ifdef GROT
2227 } 2194 }
2228#endif /* GROT */ 2195#endif /* GROT */
@@ -2231,7 +2198,7 @@ xfs_attr_leaf_moveents(xfs_attr_leafblock_t *leaf_s, int start_s,
2231 /* 2198 /*
2232 * Zero out the entries we just copied. 2199 * Zero out the entries we just copied.
2233 */ 2200 */
2234 if (start_s == INT_GET(hdr_s->count, ARCH_CONVERT)) { 2201 if (start_s == be16_to_cpu(hdr_s->count)) {
2235 tmp = count * sizeof(xfs_attr_leaf_entry_t); 2202 tmp = count * sizeof(xfs_attr_leaf_entry_t);
2236 entry_s = &leaf_s->entries[start_s]; 2203 entry_s = &leaf_s->entries[start_s];
2237 ASSERT(((char *)entry_s + tmp) <= 2204 ASSERT(((char *)entry_s + tmp) <=
@@ -2242,15 +2209,14 @@ xfs_attr_leaf_moveents(xfs_attr_leafblock_t *leaf_s, int start_s,
2242 * Move the remaining entries down to fill the hole, 2209 * Move the remaining entries down to fill the hole,
2243 * then zero the entries at the top. 2210 * then zero the entries at the top.
2244 */ 2211 */
2245 tmp = INT_GET(hdr_s->count, ARCH_CONVERT) - count; 2212 tmp = be16_to_cpu(hdr_s->count) - count;
2246 tmp *= sizeof(xfs_attr_leaf_entry_t); 2213 tmp *= sizeof(xfs_attr_leaf_entry_t);
2247 entry_s = &leaf_s->entries[start_s + count]; 2214 entry_s = &leaf_s->entries[start_s + count];
2248 entry_d = &leaf_s->entries[start_s]; 2215 entry_d = &leaf_s->entries[start_s];
2249 memmove((char *)entry_d, (char *)entry_s, tmp); 2216 memmove((char *)entry_d, (char *)entry_s, tmp);
2250 2217
2251 tmp = count * sizeof(xfs_attr_leaf_entry_t); 2218 tmp = count * sizeof(xfs_attr_leaf_entry_t);
2252 entry_s = &leaf_s->entries[INT_GET(hdr_s->count, 2219 entry_s = &leaf_s->entries[be16_to_cpu(hdr_s->count)];
2253 ARCH_CONVERT)];
2254 ASSERT(((char *)entry_s + tmp) <= 2220 ASSERT(((char *)entry_s + tmp) <=
2255 ((char *)leaf_s + XFS_LBSIZE(mp))); 2221 ((char *)leaf_s + XFS_LBSIZE(mp)));
2256 memset((char *)entry_s, 0, tmp); 2222 memset((char *)entry_s, 0, tmp);
@@ -2259,14 +2225,11 @@ xfs_attr_leaf_moveents(xfs_attr_leafblock_t *leaf_s, int start_s,
2259 /* 2225 /*
2260 * Fill in the freemap information 2226 * Fill in the freemap information
2261 */ 2227 */
2262 INT_SET(hdr_d->freemap[0].base, ARCH_CONVERT, 2228 hdr_d->freemap[0].base = cpu_to_be16(sizeof(xfs_attr_leaf_hdr_t));
2263 sizeof(xfs_attr_leaf_hdr_t)); 2229 be16_add(&hdr_d->freemap[0].base, be16_to_cpu(hdr_d->count) *
2264 INT_MOD(hdr_d->freemap[0].base, ARCH_CONVERT, 2230 sizeof(xfs_attr_leaf_entry_t));
2265 INT_GET(hdr_d->count, ARCH_CONVERT) 2231 hdr_d->freemap[0].size = cpu_to_be16(be16_to_cpu(hdr_d->firstused)
2266 * sizeof(xfs_attr_leaf_entry_t)); 2232 - be16_to_cpu(hdr_d->freemap[0].base));
2267 INT_SET(hdr_d->freemap[0].size, ARCH_CONVERT,
2268 INT_GET(hdr_d->firstused, ARCH_CONVERT)
2269 - INT_GET(hdr_d->freemap[0].base, ARCH_CONVERT));
2270 hdr_d->freemap[1].base = 0; 2233 hdr_d->freemap[1].base = 0;
2271 hdr_d->freemap[2].base = 0; 2234 hdr_d->freemap[2].base = 0;
2272 hdr_d->freemap[1].size = 0; 2235 hdr_d->freemap[1].size = 0;
@@ -2287,14 +2250,14 @@ xfs_attr_leaf_order(xfs_dabuf_t *leaf1_bp, xfs_dabuf_t *leaf2_bp)
2287 leaf2 = leaf2_bp->data; 2250 leaf2 = leaf2_bp->data;
2288 ASSERT((be16_to_cpu(leaf1->hdr.info.magic) == XFS_ATTR_LEAF_MAGIC) && 2251 ASSERT((be16_to_cpu(leaf1->hdr.info.magic) == XFS_ATTR_LEAF_MAGIC) &&
2289 (be16_to_cpu(leaf2->hdr.info.magic) == XFS_ATTR_LEAF_MAGIC)); 2252 (be16_to_cpu(leaf2->hdr.info.magic) == XFS_ATTR_LEAF_MAGIC));
2290 if ( (INT_GET(leaf1->hdr.count, ARCH_CONVERT) > 0) 2253 if ((be16_to_cpu(leaf1->hdr.count) > 0) &&
2291 && (INT_GET(leaf2->hdr.count, ARCH_CONVERT) > 0) 2254 (be16_to_cpu(leaf2->hdr.count) > 0) &&
2292 && ( (INT_GET(leaf2->entries[ 0 ].hashval, ARCH_CONVERT) < 2255 ((INT_GET(leaf2->entries[0].hashval, ARCH_CONVERT) <
2293 INT_GET(leaf1->entries[ 0 ].hashval, ARCH_CONVERT)) 2256 INT_GET(leaf1->entries[0].hashval, ARCH_CONVERT)) ||
2294 || (INT_GET(leaf2->entries[INT_GET(leaf2->hdr.count, 2257 (INT_GET(leaf2->entries[be16_to_cpu(leaf2->hdr.count)-1].hashval,
2295 ARCH_CONVERT)-1].hashval, ARCH_CONVERT) < 2258 ARCH_CONVERT) <
2296 INT_GET(leaf1->entries[INT_GET(leaf1->hdr.count, 2259 INT_GET(leaf1->entries[be16_to_cpu(leaf1->hdr.count)-1].hashval,
2297 ARCH_CONVERT)-1].hashval, ARCH_CONVERT))) ) { 2260 ARCH_CONVERT)))) {
2298 return(1); 2261 return(1);
2299 } 2262 }
2300 return(0); 2263 return(0);
@@ -2311,11 +2274,11 @@ xfs_attr_leaf_lasthash(xfs_dabuf_t *bp, int *count)
2311 leaf = bp->data; 2274 leaf = bp->data;
2312 ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_ATTR_LEAF_MAGIC); 2275 ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_ATTR_LEAF_MAGIC);
2313 if (count) 2276 if (count)
2314 *count = INT_GET(leaf->hdr.count, ARCH_CONVERT); 2277 *count = be16_to_cpu(leaf->hdr.count);
2315 if (!leaf->hdr.count) 2278 if (!leaf->hdr.count)
2316 return(0); 2279 return(0);
2317 return(INT_GET(leaf->entries[INT_GET(leaf->hdr.count, 2280 return (INT_GET(leaf->entries[be16_to_cpu(leaf->hdr.count)-1].hashval,
2318 ARCH_CONVERT)-1].hashval, ARCH_CONVERT)); 2281 ARCH_CONVERT));
2319} 2282}
2320 2283
2321/* 2284/*
@@ -2392,8 +2355,7 @@ xfs_attr_leaf_list_int(xfs_dabuf_t *bp, xfs_attr_list_context_t *context)
2392 */ 2355 */
2393 if (context->resynch) { 2356 if (context->resynch) {
2394 entry = &leaf->entries[0]; 2357 entry = &leaf->entries[0];
2395 for (i = 0; i < INT_GET(leaf->hdr.count, ARCH_CONVERT); 2358 for (i = 0; i < be16_to_cpu(leaf->hdr.count); entry++, i++) {
2396 entry++, i++) {
2397 if (INT_GET(entry->hashval, ARCH_CONVERT) 2359 if (INT_GET(entry->hashval, ARCH_CONVERT)
2398 == cursor->hashval) { 2360 == cursor->hashval) {
2399 if (cursor->offset == context->dupcnt) { 2361 if (cursor->offset == context->dupcnt) {
@@ -2407,7 +2369,7 @@ xfs_attr_leaf_list_int(xfs_dabuf_t *bp, xfs_attr_list_context_t *context)
2407 break; 2369 break;
2408 } 2370 }
2409 } 2371 }
2410 if (i == INT_GET(leaf->hdr.count, ARCH_CONVERT)) { 2372 if (i == be16_to_cpu(leaf->hdr.count)) {
2411 xfs_attr_trace_l_c("not found", context); 2373 xfs_attr_trace_l_c("not found", context);
2412 return(0); 2374 return(0);
2413 } 2375 }
@@ -2421,7 +2383,7 @@ xfs_attr_leaf_list_int(xfs_dabuf_t *bp, xfs_attr_list_context_t *context)
2421 * We have found our place, start copying out the new attributes. 2383 * We have found our place, start copying out the new attributes.
2422 */ 2384 */
2423 retval = 0; 2385 retval = 0;
2424 for ( ; (i < INT_GET(leaf->hdr.count, ARCH_CONVERT)) 2386 for ( ; (i < be16_to_cpu(leaf->hdr.count))
2425 && (retval == 0); entry++, i++) { 2387 && (retval == 0); entry++, i++) {
2426 attrnames_t *namesp; 2388 attrnames_t *namesp;
2427 2389
@@ -2577,7 +2539,7 @@ xfs_attr_leaf_clearflag(xfs_da_args_t *args)
2577 2539
2578 leaf = bp->data; 2540 leaf = bp->data;
2579 ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_ATTR_LEAF_MAGIC); 2541 ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_ATTR_LEAF_MAGIC);
2580 ASSERT(args->index < INT_GET(leaf->hdr.count, ARCH_CONVERT)); 2542 ASSERT(args->index < be16_to_cpu(leaf->hdr.count));
2581 ASSERT(args->index >= 0); 2543 ASSERT(args->index >= 0);
2582 entry = &leaf->entries[ args->index ]; 2544 entry = &leaf->entries[ args->index ];
2583 ASSERT(entry->flags & XFS_ATTR_INCOMPLETE); 2545 ASSERT(entry->flags & XFS_ATTR_INCOMPLETE);
@@ -2643,7 +2605,7 @@ xfs_attr_leaf_setflag(xfs_da_args_t *args)
2643 2605
2644 leaf = bp->data; 2606 leaf = bp->data;
2645 ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_ATTR_LEAF_MAGIC); 2607 ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_ATTR_LEAF_MAGIC);
2646 ASSERT(args->index < INT_GET(leaf->hdr.count, ARCH_CONVERT)); 2608 ASSERT(args->index < be16_to_cpu(leaf->hdr.count));
2647 ASSERT(args->index >= 0); 2609 ASSERT(args->index >= 0);
2648 entry = &leaf->entries[ args->index ]; 2610 entry = &leaf->entries[ args->index ];
2649 2611
@@ -2715,13 +2677,13 @@ xfs_attr_leaf_flipflags(xfs_da_args_t *args)
2715 2677
2716 leaf1 = bp1->data; 2678 leaf1 = bp1->data;
2717 ASSERT(be16_to_cpu(leaf1->hdr.info.magic) == XFS_ATTR_LEAF_MAGIC); 2679 ASSERT(be16_to_cpu(leaf1->hdr.info.magic) == XFS_ATTR_LEAF_MAGIC);
2718 ASSERT(args->index < INT_GET(leaf1->hdr.count, ARCH_CONVERT)); 2680 ASSERT(args->index < be16_to_cpu(leaf1->hdr.count));
2719 ASSERT(args->index >= 0); 2681 ASSERT(args->index >= 0);
2720 entry1 = &leaf1->entries[ args->index ]; 2682 entry1 = &leaf1->entries[ args->index ];
2721 2683
2722 leaf2 = bp2->data; 2684 leaf2 = bp2->data;
2723 ASSERT(be16_to_cpu(leaf2->hdr.info.magic) == XFS_ATTR_LEAF_MAGIC); 2685 ASSERT(be16_to_cpu(leaf2->hdr.info.magic) == XFS_ATTR_LEAF_MAGIC);
2724 ASSERT(args->index2 < INT_GET(leaf2->hdr.count, ARCH_CONVERT)); 2686 ASSERT(args->index2 < be16_to_cpu(leaf2->hdr.count));
2725 ASSERT(args->index2 >= 0); 2687 ASSERT(args->index2 >= 0);
2726 entry2 = &leaf2->entries[ args->index2 ]; 2688 entry2 = &leaf2->entries[ args->index2 ];
2727 2689
@@ -2971,7 +2933,7 @@ xfs_attr_leaf_inactive(xfs_trans_t **trans, xfs_inode_t *dp, xfs_dabuf_t *bp)
2971 */ 2933 */
2972 count = 0; 2934 count = 0;
2973 entry = &leaf->entries[0]; 2935 entry = &leaf->entries[0];
2974 for (i = 0; i < INT_GET(leaf->hdr.count, ARCH_CONVERT); entry++, i++) { 2936 for (i = 0; i < be16_to_cpu(leaf->hdr.count); entry++, i++) {
2975 if ( INT_GET(entry->nameidx, ARCH_CONVERT) 2937 if ( INT_GET(entry->nameidx, ARCH_CONVERT)
2976 && ((entry->flags & XFS_ATTR_LOCAL) == 0)) { 2938 && ((entry->flags & XFS_ATTR_LOCAL) == 0)) {
2977 name_rmt = XFS_ATTR_LEAF_NAME_REMOTE(leaf, i); 2939 name_rmt = XFS_ATTR_LEAF_NAME_REMOTE(leaf, i);
@@ -2999,7 +2961,7 @@ xfs_attr_leaf_inactive(xfs_trans_t **trans, xfs_inode_t *dp, xfs_dabuf_t *bp)
2999 */ 2961 */
3000 lp = list; 2962 lp = list;
3001 entry = &leaf->entries[0]; 2963 entry = &leaf->entries[0];
3002 for (i = 0; i < INT_GET(leaf->hdr.count, ARCH_CONVERT); entry++, i++) { 2964 for (i = 0; i < be16_to_cpu(leaf->hdr.count); entry++, i++) {
3003 if ( INT_GET(entry->nameidx, ARCH_CONVERT) 2965 if ( INT_GET(entry->nameidx, ARCH_CONVERT)
3004 && ((entry->flags & XFS_ATTR_LOCAL) == 0)) { 2966 && ((entry->flags & XFS_ATTR_LOCAL) == 0)) {
3005 name_rmt = XFS_ATTR_LEAF_NAME_REMOTE(leaf, i); 2967 name_rmt = XFS_ATTR_LEAF_NAME_REMOTE(leaf, i);