aboutsummaryrefslogtreecommitdiffstats
path: root/fs/xfs/xfs_ialloc_btree.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/xfs/xfs_ialloc_btree.c')
-rw-r--r--fs/xfs/xfs_ialloc_btree.c306
1 files changed, 146 insertions, 160 deletions
diff --git a/fs/xfs/xfs_ialloc_btree.c b/fs/xfs/xfs_ialloc_btree.c
index 2d4daecec990..60c65683462d 100644
--- a/fs/xfs/xfs_ialloc_btree.c
+++ b/fs/xfs/xfs_ialloc_btree.c
@@ -1,63 +1,46 @@
1/* 1/*
2 * Copyright (c) 2000-2001 Silicon Graphics, Inc. All Rights Reserved. 2 * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
3 * 4 *
4 * This program is free software; you can redistribute it and/or modify it 5 * This program is free software; you can redistribute it and/or
5 * under the terms of version 2 of the GNU General Public License as 6 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
7 * 8 *
8 * This program is distributed in the hope that it would be useful, but 9 * This program is distributed in the hope that it would be useful,
9 * WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
11 * 13 *
12 * Further, this software is distributed without any warranty that it is 14 * You should have received a copy of the GNU General Public License
13 * free of the rightful claim of any third person regarding infringement 15 * along with this program; if not, write the Free Software Foundation,
14 * or the like. Any license provided herein, whether implied or 16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
22 *
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
25 *
26 * http://www.sgi.com
27 *
28 * For further information regarding this notice, see:
29 *
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
31 */ 17 */
32
33#include "xfs.h" 18#include "xfs.h"
34 19#include "xfs_fs.h"
35#include "xfs_macros.h"
36#include "xfs_types.h" 20#include "xfs_types.h"
37#include "xfs_inum.h" 21#include "xfs_bit.h"
38#include "xfs_log.h" 22#include "xfs_log.h"
23#include "xfs_inum.h"
39#include "xfs_trans.h" 24#include "xfs_trans.h"
40#include "xfs_sb.h" 25#include "xfs_sb.h"
41#include "xfs_ag.h" 26#include "xfs_ag.h"
42#include "xfs_dir.h" 27#include "xfs_dir.h"
28#include "xfs_dir2.h"
43#include "xfs_dmapi.h" 29#include "xfs_dmapi.h"
44#include "xfs_mount.h" 30#include "xfs_mount.h"
45#include "xfs_alloc_btree.h"
46#include "xfs_bmap_btree.h" 31#include "xfs_bmap_btree.h"
32#include "xfs_alloc_btree.h"
47#include "xfs_ialloc_btree.h" 33#include "xfs_ialloc_btree.h"
34#include "xfs_dir_sf.h"
35#include "xfs_dir2_sf.h"
36#include "xfs_attr_sf.h"
37#include "xfs_dinode.h"
38#include "xfs_inode.h"
48#include "xfs_btree.h" 39#include "xfs_btree.h"
49#include "xfs_ialloc.h" 40#include "xfs_ialloc.h"
50#include "xfs_alloc.h" 41#include "xfs_alloc.h"
51#include "xfs_error.h" 42#include "xfs_error.h"
52 43
53/*
54 * Inode allocation management for XFS.
55 */
56
57/*
58 * Prototypes for internal functions.
59 */
60
61STATIC void xfs_inobt_log_block(xfs_trans_t *, xfs_buf_t *, int); 44STATIC void xfs_inobt_log_block(xfs_trans_t *, xfs_buf_t *, int);
62STATIC void xfs_inobt_log_keys(xfs_btree_cur_t *, xfs_buf_t *, int, int); 45STATIC void xfs_inobt_log_keys(xfs_btree_cur_t *, xfs_buf_t *, int, int);
63STATIC void xfs_inobt_log_ptrs(xfs_btree_cur_t *, xfs_buf_t *, int, int); 46STATIC void xfs_inobt_log_ptrs(xfs_btree_cur_t *, xfs_buf_t *, int, int);
@@ -70,10 +53,6 @@ STATIC int xfs_inobt_split(xfs_btree_cur_t *, int, xfs_agblock_t *,
70STATIC int xfs_inobt_updkey(xfs_btree_cur_t *, xfs_inobt_key_t *, int); 53STATIC int xfs_inobt_updkey(xfs_btree_cur_t *, xfs_inobt_key_t *, int);
71 54
72/* 55/*
73 * Internal functions.
74 */
75
76/*
77 * Single level of the xfs_inobt_delete record deletion routine. 56 * Single level of the xfs_inobt_delete record deletion routine.
78 * Delete record pointed to by cur/level. 57 * Delete record pointed to by cur/level.
79 * Remove the record from its block then rebalance the tree. 58 * Remove the record from its block then rebalance the tree.
@@ -139,7 +118,7 @@ xfs_inobt_delrec(
139 * Fail if we're off the end of the block. 118 * Fail if we're off the end of the block.
140 */ 119 */
141 120
142 numrecs = INT_GET(block->bb_numrecs, ARCH_CONVERT); 121 numrecs = be16_to_cpu(block->bb_numrecs);
143 if (ptr > numrecs) { 122 if (ptr > numrecs) {
144 *stat = 0; 123 *stat = 0;
145 return 0; 124 return 0;
@@ -154,7 +133,7 @@ xfs_inobt_delrec(
154 pp = XFS_INOBT_PTR_ADDR(block, 1, cur); 133 pp = XFS_INOBT_PTR_ADDR(block, 1, cur);
155#ifdef DEBUG 134#ifdef DEBUG
156 for (i = ptr; i < numrecs; i++) { 135 for (i = ptr; i < numrecs; i++) {
157 if ((error = xfs_btree_check_sptr(cur, INT_GET(pp[i], ARCH_CONVERT), level))) 136 if ((error = xfs_btree_check_sptr(cur, be32_to_cpu(pp[i]), level)))
158 return error; 137 return error;
159 } 138 }
160#endif 139#endif
@@ -191,7 +170,7 @@ xfs_inobt_delrec(
191 * Decrement and log the number of entries in the block. 170 * Decrement and log the number of entries in the block.
192 */ 171 */
193 numrecs--; 172 numrecs--;
194 INT_SET(block->bb_numrecs, ARCH_CONVERT, numrecs); 173 block->bb_numrecs = cpu_to_be16(numrecs);
195 xfs_inobt_log_block(cur->bc_tp, bp, XFS_BB_NUMRECS); 174 xfs_inobt_log_block(cur->bc_tp, bp, XFS_BB_NUMRECS);
196 /* 175 /*
197 * Is this the root level? If so, we're almost done. 176 * Is this the root level? If so, we're almost done.
@@ -210,9 +189,9 @@ xfs_inobt_delrec(
210 * pp is still set to the first pointer in the block. 189 * pp is still set to the first pointer in the block.
211 * Make it the new root of the btree. 190 * Make it the new root of the btree.
212 */ 191 */
213 bno = INT_GET(agi->agi_root, ARCH_CONVERT); 192 bno = be32_to_cpu(agi->agi_root);
214 agi->agi_root = *pp; 193 agi->agi_root = *pp;
215 INT_MOD(agi->agi_level, ARCH_CONVERT, -1); 194 be32_add(&agi->agi_level, -1);
216 /* 195 /*
217 * Free the block. 196 * Free the block.
218 */ 197 */
@@ -255,8 +234,8 @@ xfs_inobt_delrec(
255 * tree balanced. Look at the left and right sibling blocks to 234 * tree balanced. Look at the left and right sibling blocks to
256 * see if we can re-balance by moving only one record. 235 * see if we can re-balance by moving only one record.
257 */ 236 */
258 rbno = INT_GET(block->bb_rightsib, ARCH_CONVERT); 237 rbno = be32_to_cpu(block->bb_rightsib);
259 lbno = INT_GET(block->bb_leftsib, ARCH_CONVERT); 238 lbno = be32_to_cpu(block->bb_leftsib);
260 bno = NULLAGBLOCK; 239 bno = NULLAGBLOCK;
261 ASSERT(rbno != NULLAGBLOCK || lbno != NULLAGBLOCK); 240 ASSERT(rbno != NULLAGBLOCK || lbno != NULLAGBLOCK);
262 /* 241 /*
@@ -293,18 +272,18 @@ xfs_inobt_delrec(
293 /* 272 /*
294 * Grab the current block number, for future use. 273 * Grab the current block number, for future use.
295 */ 274 */
296 bno = INT_GET(right->bb_leftsib, ARCH_CONVERT); 275 bno = be32_to_cpu(right->bb_leftsib);
297 /* 276 /*
298 * If right block is full enough so that removing one entry 277 * If right block is full enough so that removing one entry
299 * won't make it too empty, and left-shifting an entry out 278 * won't make it too empty, and left-shifting an entry out
300 * of right to us works, we're done. 279 * of right to us works, we're done.
301 */ 280 */
302 if (INT_GET(right->bb_numrecs, ARCH_CONVERT) - 1 >= 281 if (be16_to_cpu(right->bb_numrecs) - 1 >=
303 XFS_INOBT_BLOCK_MINRECS(level, cur)) { 282 XFS_INOBT_BLOCK_MINRECS(level, cur)) {
304 if ((error = xfs_inobt_lshift(tcur, level, &i))) 283 if ((error = xfs_inobt_lshift(tcur, level, &i)))
305 goto error0; 284 goto error0;
306 if (i) { 285 if (i) {
307 ASSERT(INT_GET(block->bb_numrecs, ARCH_CONVERT) >= 286 ASSERT(be16_to_cpu(block->bb_numrecs) >=
308 XFS_INOBT_BLOCK_MINRECS(level, cur)); 287 XFS_INOBT_BLOCK_MINRECS(level, cur));
309 xfs_btree_del_cursor(tcur, 288 xfs_btree_del_cursor(tcur,
310 XFS_BTREE_NOERROR); 289 XFS_BTREE_NOERROR);
@@ -321,7 +300,7 @@ xfs_inobt_delrec(
321 * future reference, and fix up the temp cursor to point 300 * future reference, and fix up the temp cursor to point
322 * to our block again (last record). 301 * to our block again (last record).
323 */ 302 */
324 rrecs = INT_GET(right->bb_numrecs, ARCH_CONVERT); 303 rrecs = be16_to_cpu(right->bb_numrecs);
325 if (lbno != NULLAGBLOCK) { 304 if (lbno != NULLAGBLOCK) {
326 xfs_btree_firstrec(tcur, level); 305 xfs_btree_firstrec(tcur, level);
327 if ((error = xfs_inobt_decrement(tcur, level, &i))) 306 if ((error = xfs_inobt_decrement(tcur, level, &i)))
@@ -353,18 +332,18 @@ xfs_inobt_delrec(
353 /* 332 /*
354 * Grab the current block number, for future use. 333 * Grab the current block number, for future use.
355 */ 334 */
356 bno = INT_GET(left->bb_rightsib, ARCH_CONVERT); 335 bno = be32_to_cpu(left->bb_rightsib);
357 /* 336 /*
358 * If left block is full enough so that removing one entry 337 * If left block is full enough so that removing one entry
359 * won't make it too empty, and right-shifting an entry out 338 * won't make it too empty, and right-shifting an entry out
360 * of left to us works, we're done. 339 * of left to us works, we're done.
361 */ 340 */
362 if (INT_GET(left->bb_numrecs, ARCH_CONVERT) - 1 >= 341 if (be16_to_cpu(left->bb_numrecs) - 1 >=
363 XFS_INOBT_BLOCK_MINRECS(level, cur)) { 342 XFS_INOBT_BLOCK_MINRECS(level, cur)) {
364 if ((error = xfs_inobt_rshift(tcur, level, &i))) 343 if ((error = xfs_inobt_rshift(tcur, level, &i)))
365 goto error0; 344 goto error0;
366 if (i) { 345 if (i) {
367 ASSERT(INT_GET(block->bb_numrecs, ARCH_CONVERT) >= 346 ASSERT(be16_to_cpu(block->bb_numrecs) >=
368 XFS_INOBT_BLOCK_MINRECS(level, cur)); 347 XFS_INOBT_BLOCK_MINRECS(level, cur));
369 xfs_btree_del_cursor(tcur, 348 xfs_btree_del_cursor(tcur,
370 XFS_BTREE_NOERROR); 349 XFS_BTREE_NOERROR);
@@ -378,7 +357,7 @@ xfs_inobt_delrec(
378 * Otherwise, grab the number of records in right for 357 * Otherwise, grab the number of records in right for
379 * future reference. 358 * future reference.
380 */ 359 */
381 lrecs = INT_GET(left->bb_numrecs, ARCH_CONVERT); 360 lrecs = be16_to_cpu(left->bb_numrecs);
382 } 361 }
383 /* 362 /*
384 * Delete the temp cursor, we're done with it. 363 * Delete the temp cursor, we're done with it.
@@ -399,14 +378,14 @@ xfs_inobt_delrec(
399 */ 378 */
400 rbno = bno; 379 rbno = bno;
401 right = block; 380 right = block;
402 rrecs = INT_GET(right->bb_numrecs, ARCH_CONVERT); 381 rrecs = be16_to_cpu(right->bb_numrecs);
403 rbp = bp; 382 rbp = bp;
404 if ((error = xfs_btree_read_bufs(mp, cur->bc_tp, 383 if ((error = xfs_btree_read_bufs(mp, cur->bc_tp,
405 cur->bc_private.i.agno, lbno, 0, &lbp, 384 cur->bc_private.i.agno, lbno, 0, &lbp,
406 XFS_INO_BTREE_REF))) 385 XFS_INO_BTREE_REF)))
407 return error; 386 return error;
408 left = XFS_BUF_TO_INOBT_BLOCK(lbp); 387 left = XFS_BUF_TO_INOBT_BLOCK(lbp);
409 lrecs = INT_GET(left->bb_numrecs, ARCH_CONVERT); 388 lrecs = be16_to_cpu(left->bb_numrecs);
410 if ((error = xfs_btree_check_sblock(cur, left, level, lbp))) 389 if ((error = xfs_btree_check_sblock(cur, left, level, lbp)))
411 return error; 390 return error;
412 } 391 }
@@ -421,14 +400,14 @@ xfs_inobt_delrec(
421 */ 400 */
422 lbno = bno; 401 lbno = bno;
423 left = block; 402 left = block;
424 lrecs = INT_GET(left->bb_numrecs, ARCH_CONVERT); 403 lrecs = be16_to_cpu(left->bb_numrecs);
425 lbp = bp; 404 lbp = bp;
426 if ((error = xfs_btree_read_bufs(mp, cur->bc_tp, 405 if ((error = xfs_btree_read_bufs(mp, cur->bc_tp,
427 cur->bc_private.i.agno, rbno, 0, &rbp, 406 cur->bc_private.i.agno, rbno, 0, &rbp,
428 XFS_INO_BTREE_REF))) 407 XFS_INO_BTREE_REF)))
429 return error; 408 return error;
430 right = XFS_BUF_TO_INOBT_BLOCK(rbp); 409 right = XFS_BUF_TO_INOBT_BLOCK(rbp);
431 rrecs = INT_GET(right->bb_numrecs, ARCH_CONVERT); 410 rrecs = be16_to_cpu(right->bb_numrecs);
432 if ((error = xfs_btree_check_sblock(cur, right, level, rbp))) 411 if ((error = xfs_btree_check_sblock(cur, right, level, rbp)))
433 return error; 412 return error;
434 } 413 }
@@ -456,7 +435,7 @@ xfs_inobt_delrec(
456 rpp = XFS_INOBT_PTR_ADDR(right, 1, cur); 435 rpp = XFS_INOBT_PTR_ADDR(right, 1, cur);
457#ifdef DEBUG 436#ifdef DEBUG
458 for (i = 0; i < rrecs; i++) { 437 for (i = 0; i < rrecs; i++) {
459 if ((error = xfs_btree_check_sptr(cur, INT_GET(rpp[i], ARCH_CONVERT), level))) 438 if ((error = xfs_btree_check_sptr(cur, be32_to_cpu(rpp[i]), level)))
460 return error; 439 return error;
461 } 440 }
462#endif 441#endif
@@ -492,7 +471,7 @@ xfs_inobt_delrec(
492 * Fix up the number of records in the surviving block. 471 * Fix up the number of records in the surviving block.
493 */ 472 */
494 lrecs += rrecs; 473 lrecs += rrecs;
495 INT_SET(left->bb_numrecs, ARCH_CONVERT, lrecs); 474 left->bb_numrecs = cpu_to_be16(lrecs);
496 /* 475 /*
497 * Fix up the right block pointer in the surviving block, and log it. 476 * Fix up the right block pointer in the surviving block, and log it.
498 */ 477 */
@@ -502,18 +481,18 @@ xfs_inobt_delrec(
502 * If there is a right sibling now, make it point to the 481 * If there is a right sibling now, make it point to the
503 * remaining block. 482 * remaining block.
504 */ 483 */
505 if (INT_GET(left->bb_rightsib, ARCH_CONVERT) != NULLAGBLOCK) { 484 if (be32_to_cpu(left->bb_rightsib) != NULLAGBLOCK) {
506 xfs_inobt_block_t *rrblock; 485 xfs_inobt_block_t *rrblock;
507 xfs_buf_t *rrbp; 486 xfs_buf_t *rrbp;
508 487
509 if ((error = xfs_btree_read_bufs(mp, cur->bc_tp, 488 if ((error = xfs_btree_read_bufs(mp, cur->bc_tp,
510 cur->bc_private.i.agno, INT_GET(left->bb_rightsib, ARCH_CONVERT), 0, 489 cur->bc_private.i.agno, be32_to_cpu(left->bb_rightsib), 0,
511 &rrbp, XFS_INO_BTREE_REF))) 490 &rrbp, XFS_INO_BTREE_REF)))
512 return error; 491 return error;
513 rrblock = XFS_BUF_TO_INOBT_BLOCK(rrbp); 492 rrblock = XFS_BUF_TO_INOBT_BLOCK(rrbp);
514 if ((error = xfs_btree_check_sblock(cur, rrblock, level, rrbp))) 493 if ((error = xfs_btree_check_sblock(cur, rrblock, level, rrbp)))
515 return error; 494 return error;
516 INT_SET(rrblock->bb_leftsib, ARCH_CONVERT, lbno); 495 rrblock->bb_leftsib = cpu_to_be32(lbno);
517 xfs_inobt_log_block(cur->bc_tp, rrbp, XFS_BB_LEFTSIB); 496 xfs_inobt_log_block(cur->bc_tp, rrbp, XFS_BB_LEFTSIB);
518 } 497 }
519 /* 498 /*
@@ -572,6 +551,13 @@ xfs_inobt_insrec(
572 xfs_inobt_rec_t *rp=NULL; /* pointer to btree records */ 551 xfs_inobt_rec_t *rp=NULL; /* pointer to btree records */
573 552
574 /* 553 /*
554 * GCC doesn't understand the (arguably complex) control flow in
555 * this function and complains about uninitialized structure fields
556 * without this.
557 */
558 memset(&nrec, 0, sizeof(nrec));
559
560 /*
575 * If we made it to the root level, allocate a new root block 561 * If we made it to the root level, allocate a new root block
576 * and we're done. 562 * and we're done.
577 */ 563 */
@@ -598,7 +584,7 @@ xfs_inobt_insrec(
598 */ 584 */
599 bp = cur->bc_bufs[level]; 585 bp = cur->bc_bufs[level];
600 block = XFS_BUF_TO_INOBT_BLOCK(bp); 586 block = XFS_BUF_TO_INOBT_BLOCK(bp);
601 numrecs = INT_GET(block->bb_numrecs, ARCH_CONVERT); 587 numrecs = be16_to_cpu(block->bb_numrecs);
602#ifdef DEBUG 588#ifdef DEBUG
603 if ((error = xfs_btree_check_sblock(cur, block, level, bp))) 589 if ((error = xfs_btree_check_sblock(cur, block, level, bp)))
604 return error; 590 return error;
@@ -672,7 +658,7 @@ xfs_inobt_insrec(
672 * At this point we know there's room for our new entry in the block 658 * At this point we know there's room for our new entry in the block
673 * we're pointing at. 659 * we're pointing at.
674 */ 660 */
675 numrecs = INT_GET(block->bb_numrecs, ARCH_CONVERT); 661 numrecs = be16_to_cpu(block->bb_numrecs);
676 if (level > 0) { 662 if (level > 0) {
677 /* 663 /*
678 * It's a non-leaf entry. Make a hole for the new data 664 * It's a non-leaf entry. Make a hole for the new data
@@ -682,7 +668,7 @@ xfs_inobt_insrec(
682 pp = XFS_INOBT_PTR_ADDR(block, 1, cur); 668 pp = XFS_INOBT_PTR_ADDR(block, 1, cur);
683#ifdef DEBUG 669#ifdef DEBUG
684 for (i = numrecs; i >= ptr; i--) { 670 for (i = numrecs; i >= ptr; i--) {
685 if ((error = xfs_btree_check_sptr(cur, INT_GET(pp[i - 1], ARCH_CONVERT), level))) 671 if ((error = xfs_btree_check_sptr(cur, be32_to_cpu(pp[i - 1]), level)))
686 return error; 672 return error;
687 } 673 }
688#endif 674#endif
@@ -698,9 +684,9 @@ xfs_inobt_insrec(
698 return error; 684 return error;
699#endif 685#endif
700 kp[ptr - 1] = key; /* INT_: struct copy */ 686 kp[ptr - 1] = key; /* INT_: struct copy */
701 INT_SET(pp[ptr - 1], ARCH_CONVERT, *bnop); 687 pp[ptr - 1] = cpu_to_be32(*bnop);
702 numrecs++; 688 numrecs++;
703 INT_SET(block->bb_numrecs, ARCH_CONVERT, numrecs); 689 block->bb_numrecs = cpu_to_be16(numrecs);
704 xfs_inobt_log_keys(cur, bp, ptr, numrecs); 690 xfs_inobt_log_keys(cur, bp, ptr, numrecs);
705 xfs_inobt_log_ptrs(cur, bp, ptr, numrecs); 691 xfs_inobt_log_ptrs(cur, bp, ptr, numrecs);
706 } else { 692 } else {
@@ -716,7 +702,7 @@ xfs_inobt_insrec(
716 */ 702 */
717 rp[ptr - 1] = *recp; /* INT_: struct copy */ 703 rp[ptr - 1] = *recp; /* INT_: struct copy */
718 numrecs++; 704 numrecs++;
719 INT_SET(block->bb_numrecs, ARCH_CONVERT, numrecs); 705 block->bb_numrecs = cpu_to_be16(numrecs);
720 xfs_inobt_log_recs(cur, bp, ptr, numrecs); 706 xfs_inobt_log_recs(cur, bp, ptr, numrecs);
721 } 707 }
722 /* 708 /*
@@ -871,8 +857,8 @@ xfs_inobt_lookup(
871 xfs_agi_t *agi; /* a.g. inode header */ 857 xfs_agi_t *agi; /* a.g. inode header */
872 858
873 agi = XFS_BUF_TO_AGI(cur->bc_private.i.agbp); 859 agi = XFS_BUF_TO_AGI(cur->bc_private.i.agbp);
874 agno = INT_GET(agi->agi_seqno, ARCH_CONVERT); 860 agno = be32_to_cpu(agi->agi_seqno);
875 agbno = INT_GET(agi->agi_root, ARCH_CONVERT); 861 agbno = be32_to_cpu(agi->agi_root);
876 } 862 }
877 /* 863 /*
878 * Iterate over each level in the btree, starting at the root. 864 * Iterate over each level in the btree, starting at the root.
@@ -939,7 +925,7 @@ xfs_inobt_lookup(
939 * Set low and high entry numbers, 1-based. 925 * Set low and high entry numbers, 1-based.
940 */ 926 */
941 low = 1; 927 low = 1;
942 if (!(high = INT_GET(block->bb_numrecs, ARCH_CONVERT))) { 928 if (!(high = be16_to_cpu(block->bb_numrecs))) {
943 /* 929 /*
944 * If the block is empty, the tree must 930 * If the block is empty, the tree must
945 * be an empty leaf. 931 * be an empty leaf.
@@ -1006,7 +992,7 @@ xfs_inobt_lookup(
1006 */ 992 */
1007 if (diff > 0 && --keyno < 1) 993 if (diff > 0 && --keyno < 1)
1008 keyno = 1; 994 keyno = 1;
1009 agbno = INT_GET(*XFS_INOBT_PTR_ADDR(block, keyno, cur), ARCH_CONVERT); 995 agbno = be32_to_cpu(*XFS_INOBT_PTR_ADDR(block, keyno, cur));
1010#ifdef DEBUG 996#ifdef DEBUG
1011 if ((error = xfs_btree_check_sptr(cur, agbno, level))) 997 if ((error = xfs_btree_check_sptr(cur, agbno, level)))
1012 return error; 998 return error;
@@ -1025,8 +1011,8 @@ xfs_inobt_lookup(
1025 * not the last block, we're in the wrong block. 1011 * not the last block, we're in the wrong block.
1026 */ 1012 */
1027 if (dir == XFS_LOOKUP_GE && 1013 if (dir == XFS_LOOKUP_GE &&
1028 keyno > INT_GET(block->bb_numrecs, ARCH_CONVERT) && 1014 keyno > be16_to_cpu(block->bb_numrecs) &&
1029 INT_GET(block->bb_rightsib, ARCH_CONVERT) != NULLAGBLOCK) { 1015 be32_to_cpu(block->bb_rightsib) != NULLAGBLOCK) {
1030 int i; 1016 int i;
1031 1017
1032 cur->bc_ptrs[0] = keyno; 1018 cur->bc_ptrs[0] = keyno;
@@ -1043,7 +1029,7 @@ xfs_inobt_lookup(
1043 /* 1029 /*
1044 * Return if we succeeded or not. 1030 * Return if we succeeded or not.
1045 */ 1031 */
1046 if (keyno == 0 || keyno > INT_GET(block->bb_numrecs, ARCH_CONVERT)) 1032 if (keyno == 0 || keyno > be16_to_cpu(block->bb_numrecs))
1047 *stat = 0; 1033 *stat = 0;
1048 else 1034 else
1049 *stat = ((dir != XFS_LOOKUP_EQ) || (diff == 0)); 1035 *stat = ((dir != XFS_LOOKUP_EQ) || (diff == 0));
@@ -1089,7 +1075,7 @@ xfs_inobt_lshift(
1089 /* 1075 /*
1090 * If we've got no left sibling then we can't shift an entry left. 1076 * If we've got no left sibling then we can't shift an entry left.
1091 */ 1077 */
1092 if (INT_GET(right->bb_leftsib, ARCH_CONVERT) == NULLAGBLOCK) { 1078 if (be32_to_cpu(right->bb_leftsib) == NULLAGBLOCK) {
1093 *stat = 0; 1079 *stat = 0;
1094 return 0; 1080 return 0;
1095 } 1081 }
@@ -1105,8 +1091,8 @@ xfs_inobt_lshift(
1105 * Set up the left neighbor as "left". 1091 * Set up the left neighbor as "left".
1106 */ 1092 */
1107 if ((error = xfs_btree_read_bufs(cur->bc_mp, cur->bc_tp, 1093 if ((error = xfs_btree_read_bufs(cur->bc_mp, cur->bc_tp,
1108 cur->bc_private.i.agno, INT_GET(right->bb_leftsib, ARCH_CONVERT), 0, &lbp, 1094 cur->bc_private.i.agno, be32_to_cpu(right->bb_leftsib),
1109 XFS_INO_BTREE_REF))) 1095 0, &lbp, XFS_INO_BTREE_REF)))
1110 return error; 1096 return error;
1111 left = XFS_BUF_TO_INOBT_BLOCK(lbp); 1097 left = XFS_BUF_TO_INOBT_BLOCK(lbp);
1112 if ((error = xfs_btree_check_sblock(cur, left, level, lbp))) 1098 if ((error = xfs_btree_check_sblock(cur, left, level, lbp)))
@@ -1114,11 +1100,11 @@ xfs_inobt_lshift(
1114 /* 1100 /*
1115 * If it's full, it can't take another entry. 1101 * If it's full, it can't take another entry.
1116 */ 1102 */
1117 if (INT_GET(left->bb_numrecs, ARCH_CONVERT) == XFS_INOBT_BLOCK_MAXRECS(level, cur)) { 1103 if (be16_to_cpu(left->bb_numrecs) == XFS_INOBT_BLOCK_MAXRECS(level, cur)) {
1118 *stat = 0; 1104 *stat = 0;
1119 return 0; 1105 return 0;
1120 } 1106 }
1121 nrec = INT_GET(left->bb_numrecs, ARCH_CONVERT) + 1; 1107 nrec = be16_to_cpu(left->bb_numrecs) + 1;
1122 /* 1108 /*
1123 * If non-leaf, copy a key and a ptr to the left block. 1109 * If non-leaf, copy a key and a ptr to the left block.
1124 */ 1110 */
@@ -1130,7 +1116,7 @@ xfs_inobt_lshift(
1130 lpp = XFS_INOBT_PTR_ADDR(left, nrec, cur); 1116 lpp = XFS_INOBT_PTR_ADDR(left, nrec, cur);
1131 rpp = XFS_INOBT_PTR_ADDR(right, 1, cur); 1117 rpp = XFS_INOBT_PTR_ADDR(right, 1, cur);
1132#ifdef DEBUG 1118#ifdef DEBUG
1133 if ((error = xfs_btree_check_sptr(cur, INT_GET(*rpp, ARCH_CONVERT), level))) 1119 if ((error = xfs_btree_check_sptr(cur, be32_to_cpu(*rpp), level)))
1134 return error; 1120 return error;
1135#endif 1121#endif
1136 *lpp = *rpp; /* INT_: no-change copy */ 1122 *lpp = *rpp; /* INT_: no-change copy */
@@ -1148,7 +1134,7 @@ xfs_inobt_lshift(
1148 /* 1134 /*
1149 * Bump and log left's numrecs, decrement and log right's numrecs. 1135 * Bump and log left's numrecs, decrement and log right's numrecs.
1150 */ 1136 */
1151 INT_MOD(left->bb_numrecs, ARCH_CONVERT, +1); 1137 be16_add(&left->bb_numrecs, 1);
1152 xfs_inobt_log_block(cur->bc_tp, lbp, XFS_BB_NUMRECS); 1138 xfs_inobt_log_block(cur->bc_tp, lbp, XFS_BB_NUMRECS);
1153#ifdef DEBUG 1139#ifdef DEBUG
1154 if (level > 0) 1140 if (level > 0)
@@ -1156,26 +1142,26 @@ xfs_inobt_lshift(
1156 else 1142 else
1157 xfs_btree_check_rec(cur->bc_btnum, lrp - 1, lrp); 1143 xfs_btree_check_rec(cur->bc_btnum, lrp - 1, lrp);
1158#endif 1144#endif
1159 INT_MOD(right->bb_numrecs, ARCH_CONVERT, -1); 1145 be16_add(&right->bb_numrecs, -1);
1160 xfs_inobt_log_block(cur->bc_tp, rbp, XFS_BB_NUMRECS); 1146 xfs_inobt_log_block(cur->bc_tp, rbp, XFS_BB_NUMRECS);
1161 /* 1147 /*
1162 * Slide the contents of right down one entry. 1148 * Slide the contents of right down one entry.
1163 */ 1149 */
1164 if (level > 0) { 1150 if (level > 0) {
1165#ifdef DEBUG 1151#ifdef DEBUG
1166 for (i = 0; i < INT_GET(right->bb_numrecs, ARCH_CONVERT); i++) { 1152 for (i = 0; i < be16_to_cpu(right->bb_numrecs); i++) {
1167 if ((error = xfs_btree_check_sptr(cur, INT_GET(rpp[i + 1], ARCH_CONVERT), 1153 if ((error = xfs_btree_check_sptr(cur, be32_to_cpu(rpp[i + 1]),
1168 level))) 1154 level)))
1169 return error; 1155 return error;
1170 } 1156 }
1171#endif 1157#endif
1172 memmove(rkp, rkp + 1, INT_GET(right->bb_numrecs, ARCH_CONVERT) * sizeof(*rkp)); 1158 memmove(rkp, rkp + 1, be16_to_cpu(right->bb_numrecs) * sizeof(*rkp));
1173 memmove(rpp, rpp + 1, INT_GET(right->bb_numrecs, ARCH_CONVERT) * sizeof(*rpp)); 1159 memmove(rpp, rpp + 1, be16_to_cpu(right->bb_numrecs) * sizeof(*rpp));
1174 xfs_inobt_log_keys(cur, rbp, 1, INT_GET(right->bb_numrecs, ARCH_CONVERT)); 1160 xfs_inobt_log_keys(cur, rbp, 1, be16_to_cpu(right->bb_numrecs));
1175 xfs_inobt_log_ptrs(cur, rbp, 1, INT_GET(right->bb_numrecs, ARCH_CONVERT)); 1161 xfs_inobt_log_ptrs(cur, rbp, 1, be16_to_cpu(right->bb_numrecs));
1176 } else { 1162 } else {
1177 memmove(rrp, rrp + 1, INT_GET(right->bb_numrecs, ARCH_CONVERT) * sizeof(*rrp)); 1163 memmove(rrp, rrp + 1, be16_to_cpu(right->bb_numrecs) * sizeof(*rrp));
1178 xfs_inobt_log_recs(cur, rbp, 1, INT_GET(right->bb_numrecs, ARCH_CONVERT)); 1164 xfs_inobt_log_recs(cur, rbp, 1, be16_to_cpu(right->bb_numrecs));
1179 key.ir_startino = rrp->ir_startino; /* INT_: direct copy */ 1165 key.ir_startino = rrp->ir_startino; /* INT_: direct copy */
1180 rkp = &key; 1166 rkp = &key;
1181 } 1167 }
@@ -1227,7 +1213,7 @@ xfs_inobt_newroot(
1227 args.tp = cur->bc_tp; 1213 args.tp = cur->bc_tp;
1228 args.mp = cur->bc_mp; 1214 args.mp = cur->bc_mp;
1229 args.fsbno = XFS_AGB_TO_FSB(args.mp, cur->bc_private.i.agno, 1215 args.fsbno = XFS_AGB_TO_FSB(args.mp, cur->bc_private.i.agno,
1230 INT_GET(agi->agi_root, ARCH_CONVERT)); 1216 be32_to_cpu(agi->agi_root));
1231 args.mod = args.minleft = args.alignment = args.total = args.wasdel = 1217 args.mod = args.minleft = args.alignment = args.total = args.wasdel =
1232 args.isfl = args.userdata = args.minalignslop = 0; 1218 args.isfl = args.userdata = args.minalignslop = 0;
1233 args.minlen = args.maxlen = args.prod = 1; 1219 args.minlen = args.maxlen = args.prod = 1;
@@ -1247,8 +1233,8 @@ xfs_inobt_newroot(
1247 /* 1233 /*
1248 * Set the root data in the a.g. inode structure. 1234 * Set the root data in the a.g. inode structure.
1249 */ 1235 */
1250 INT_SET(agi->agi_root, ARCH_CONVERT, args.agbno); 1236 agi->agi_root = cpu_to_be32(args.agbno);
1251 INT_MOD(agi->agi_level, ARCH_CONVERT, 1); 1237 be32_add(&agi->agi_level, 1);
1252 xfs_ialloc_log_agi(args.tp, cur->bc_private.i.agbp, 1238 xfs_ialloc_log_agi(args.tp, cur->bc_private.i.agbp,
1253 XFS_AGI_ROOT | XFS_AGI_LEVEL); 1239 XFS_AGI_ROOT | XFS_AGI_LEVEL);
1254 /* 1240 /*
@@ -1263,14 +1249,14 @@ xfs_inobt_newroot(
1263 if ((error = xfs_btree_check_sblock(cur, block, cur->bc_nlevels - 1, bp))) 1249 if ((error = xfs_btree_check_sblock(cur, block, cur->bc_nlevels - 1, bp)))
1264 return error; 1250 return error;
1265#endif 1251#endif
1266 if (INT_GET(block->bb_rightsib, ARCH_CONVERT) != NULLAGBLOCK) { 1252 if (be32_to_cpu(block->bb_rightsib) != NULLAGBLOCK) {
1267 /* 1253 /*
1268 * Our block is left, pick up the right block. 1254 * Our block is left, pick up the right block.
1269 */ 1255 */
1270 lbp = bp; 1256 lbp = bp;
1271 lbno = XFS_DADDR_TO_AGBNO(args.mp, XFS_BUF_ADDR(lbp)); 1257 lbno = XFS_DADDR_TO_AGBNO(args.mp, XFS_BUF_ADDR(lbp));
1272 left = block; 1258 left = block;
1273 rbno = INT_GET(left->bb_rightsib, ARCH_CONVERT); 1259 rbno = be32_to_cpu(left->bb_rightsib);
1274 if ((error = xfs_btree_read_bufs(args.mp, args.tp, args.agno, 1260 if ((error = xfs_btree_read_bufs(args.mp, args.tp, args.agno,
1275 rbno, 0, &rbp, XFS_INO_BTREE_REF))) 1261 rbno, 0, &rbp, XFS_INO_BTREE_REF)))
1276 return error; 1262 return error;
@@ -1287,7 +1273,7 @@ xfs_inobt_newroot(
1287 rbp = bp; 1273 rbp = bp;
1288 rbno = XFS_DADDR_TO_AGBNO(args.mp, XFS_BUF_ADDR(rbp)); 1274 rbno = XFS_DADDR_TO_AGBNO(args.mp, XFS_BUF_ADDR(rbp));
1289 right = block; 1275 right = block;
1290 lbno = INT_GET(right->bb_leftsib, ARCH_CONVERT); 1276 lbno = be32_to_cpu(right->bb_leftsib);
1291 if ((error = xfs_btree_read_bufs(args.mp, args.tp, args.agno, 1277 if ((error = xfs_btree_read_bufs(args.mp, args.tp, args.agno,
1292 lbno, 0, &lbp, XFS_INO_BTREE_REF))) 1278 lbno, 0, &lbp, XFS_INO_BTREE_REF)))
1293 return error; 1279 return error;
@@ -1301,18 +1287,18 @@ xfs_inobt_newroot(
1301 /* 1287 /*
1302 * Fill in the new block's btree header and log it. 1288 * Fill in the new block's btree header and log it.
1303 */ 1289 */
1304 INT_SET(new->bb_magic, ARCH_CONVERT, xfs_magics[cur->bc_btnum]); 1290 new->bb_magic = cpu_to_be32(xfs_magics[cur->bc_btnum]);
1305 INT_SET(new->bb_level, ARCH_CONVERT, (__uint16_t)cur->bc_nlevels); 1291 new->bb_level = cpu_to_be16(cur->bc_nlevels);
1306 INT_SET(new->bb_numrecs, ARCH_CONVERT, 2); 1292 new->bb_numrecs = cpu_to_be16(2);
1307 INT_SET(new->bb_leftsib, ARCH_CONVERT, NULLAGBLOCK); 1293 new->bb_leftsib = cpu_to_be32(NULLAGBLOCK);
1308 INT_SET(new->bb_rightsib, ARCH_CONVERT, NULLAGBLOCK); 1294 new->bb_rightsib = cpu_to_be32(NULLAGBLOCK);
1309 xfs_inobt_log_block(args.tp, nbp, XFS_BB_ALL_BITS); 1295 xfs_inobt_log_block(args.tp, nbp, XFS_BB_ALL_BITS);
1310 ASSERT(lbno != NULLAGBLOCK && rbno != NULLAGBLOCK); 1296 ASSERT(lbno != NULLAGBLOCK && rbno != NULLAGBLOCK);
1311 /* 1297 /*
1312 * Fill in the key data in the new root. 1298 * Fill in the key data in the new root.
1313 */ 1299 */
1314 kp = XFS_INOBT_KEY_ADDR(new, 1, cur); 1300 kp = XFS_INOBT_KEY_ADDR(new, 1, cur);
1315 if (INT_GET(left->bb_level, ARCH_CONVERT) > 0) { 1301 if (be16_to_cpu(left->bb_level) > 0) {
1316 kp[0] = *XFS_INOBT_KEY_ADDR(left, 1, cur); /* INT_: struct copy */ 1302 kp[0] = *XFS_INOBT_KEY_ADDR(left, 1, cur); /* INT_: struct copy */
1317 kp[1] = *XFS_INOBT_KEY_ADDR(right, 1, cur); /* INT_: struct copy */ 1303 kp[1] = *XFS_INOBT_KEY_ADDR(right, 1, cur); /* INT_: struct copy */
1318 } else { 1304 } else {
@@ -1326,8 +1312,8 @@ xfs_inobt_newroot(
1326 * Fill in the pointer data in the new root. 1312 * Fill in the pointer data in the new root.
1327 */ 1313 */
1328 pp = XFS_INOBT_PTR_ADDR(new, 1, cur); 1314 pp = XFS_INOBT_PTR_ADDR(new, 1, cur);
1329 INT_SET(pp[0], ARCH_CONVERT, lbno); 1315 pp[0] = cpu_to_be32(lbno);
1330 INT_SET(pp[1], ARCH_CONVERT, rbno); 1316 pp[1] = cpu_to_be32(rbno);
1331 xfs_inobt_log_ptrs(cur, nbp, 1, 2); 1317 xfs_inobt_log_ptrs(cur, nbp, 1, 2);
1332 /* 1318 /*
1333 * Fix up the cursor. 1319 * Fix up the cursor.
@@ -1376,7 +1362,7 @@ xfs_inobt_rshift(
1376 /* 1362 /*
1377 * If we've got no right sibling then we can't shift an entry right. 1363 * If we've got no right sibling then we can't shift an entry right.
1378 */ 1364 */
1379 if (INT_GET(left->bb_rightsib, ARCH_CONVERT) == NULLAGBLOCK) { 1365 if (be32_to_cpu(left->bb_rightsib) == NULLAGBLOCK) {
1380 *stat = 0; 1366 *stat = 0;
1381 return 0; 1367 return 0;
1382 } 1368 }
@@ -1384,7 +1370,7 @@ xfs_inobt_rshift(
1384 * If the cursor entry is the one that would be moved, don't 1370 * If the cursor entry is the one that would be moved, don't
1385 * do it... it's too complicated. 1371 * do it... it's too complicated.
1386 */ 1372 */
1387 if (cur->bc_ptrs[level] >= INT_GET(left->bb_numrecs, ARCH_CONVERT)) { 1373 if (cur->bc_ptrs[level] >= be16_to_cpu(left->bb_numrecs)) {
1388 *stat = 0; 1374 *stat = 0;
1389 return 0; 1375 return 0;
1390 } 1376 }
@@ -1392,8 +1378,8 @@ xfs_inobt_rshift(
1392 * Set up the right neighbor as "right". 1378 * Set up the right neighbor as "right".
1393 */ 1379 */
1394 if ((error = xfs_btree_read_bufs(cur->bc_mp, cur->bc_tp, 1380 if ((error = xfs_btree_read_bufs(cur->bc_mp, cur->bc_tp,
1395 cur->bc_private.i.agno, INT_GET(left->bb_rightsib, ARCH_CONVERT), 0, &rbp, 1381 cur->bc_private.i.agno, be32_to_cpu(left->bb_rightsib),
1396 XFS_INO_BTREE_REF))) 1382 0, &rbp, XFS_INO_BTREE_REF)))
1397 return error; 1383 return error;
1398 right = XFS_BUF_TO_INOBT_BLOCK(rbp); 1384 right = XFS_BUF_TO_INOBT_BLOCK(rbp);
1399 if ((error = xfs_btree_check_sblock(cur, right, level, rbp))) 1385 if ((error = xfs_btree_check_sblock(cur, right, level, rbp)))
@@ -1401,7 +1387,7 @@ xfs_inobt_rshift(
1401 /* 1387 /*
1402 * If it's full, it can't take another entry. 1388 * If it's full, it can't take another entry.
1403 */ 1389 */
1404 if (INT_GET(right->bb_numrecs, ARCH_CONVERT) == XFS_INOBT_BLOCK_MAXRECS(level, cur)) { 1390 if (be16_to_cpu(right->bb_numrecs) == XFS_INOBT_BLOCK_MAXRECS(level, cur)) {
1405 *stat = 0; 1391 *stat = 0;
1406 return 0; 1392 return 0;
1407 } 1393 }
@@ -1410,41 +1396,41 @@ xfs_inobt_rshift(
1410 * copy the last left block entry to the hole. 1396 * copy the last left block entry to the hole.
1411 */ 1397 */
1412 if (level > 0) { 1398 if (level > 0) {
1413 lkp = XFS_INOBT_KEY_ADDR(left, INT_GET(left->bb_numrecs, ARCH_CONVERT), cur); 1399 lkp = XFS_INOBT_KEY_ADDR(left, be16_to_cpu(left->bb_numrecs), cur);
1414 lpp = XFS_INOBT_PTR_ADDR(left, INT_GET(left->bb_numrecs, ARCH_CONVERT), cur); 1400 lpp = XFS_INOBT_PTR_ADDR(left, be16_to_cpu(left->bb_numrecs), cur);
1415 rkp = XFS_INOBT_KEY_ADDR(right, 1, cur); 1401 rkp = XFS_INOBT_KEY_ADDR(right, 1, cur);
1416 rpp = XFS_INOBT_PTR_ADDR(right, 1, cur); 1402 rpp = XFS_INOBT_PTR_ADDR(right, 1, cur);
1417#ifdef DEBUG 1403#ifdef DEBUG
1418 for (i = INT_GET(right->bb_numrecs, ARCH_CONVERT) - 1; i >= 0; i--) { 1404 for (i = be16_to_cpu(right->bb_numrecs) - 1; i >= 0; i--) {
1419 if ((error = xfs_btree_check_sptr(cur, INT_GET(rpp[i], ARCH_CONVERT), level))) 1405 if ((error = xfs_btree_check_sptr(cur, be32_to_cpu(rpp[i]), level)))
1420 return error; 1406 return error;
1421 } 1407 }
1422#endif 1408#endif
1423 memmove(rkp + 1, rkp, INT_GET(right->bb_numrecs, ARCH_CONVERT) * sizeof(*rkp)); 1409 memmove(rkp + 1, rkp, be16_to_cpu(right->bb_numrecs) * sizeof(*rkp));
1424 memmove(rpp + 1, rpp, INT_GET(right->bb_numrecs, ARCH_CONVERT) * sizeof(*rpp)); 1410 memmove(rpp + 1, rpp, be16_to_cpu(right->bb_numrecs) * sizeof(*rpp));
1425#ifdef DEBUG 1411#ifdef DEBUG
1426 if ((error = xfs_btree_check_sptr(cur, INT_GET(*lpp, ARCH_CONVERT), level))) 1412 if ((error = xfs_btree_check_sptr(cur, be32_to_cpu(*lpp), level)))
1427 return error; 1413 return error;
1428#endif 1414#endif
1429 *rkp = *lkp; /* INT_: no change copy */ 1415 *rkp = *lkp; /* INT_: no change copy */
1430 *rpp = *lpp; /* INT_: no change copy */ 1416 *rpp = *lpp; /* INT_: no change copy */
1431 xfs_inobt_log_keys(cur, rbp, 1, INT_GET(right->bb_numrecs, ARCH_CONVERT) + 1); 1417 xfs_inobt_log_keys(cur, rbp, 1, be16_to_cpu(right->bb_numrecs) + 1);
1432 xfs_inobt_log_ptrs(cur, rbp, 1, INT_GET(right->bb_numrecs, ARCH_CONVERT) + 1); 1418 xfs_inobt_log_ptrs(cur, rbp, 1, be16_to_cpu(right->bb_numrecs) + 1);
1433 } else { 1419 } else {
1434 lrp = XFS_INOBT_REC_ADDR(left, INT_GET(left->bb_numrecs, ARCH_CONVERT), cur); 1420 lrp = XFS_INOBT_REC_ADDR(left, be16_to_cpu(left->bb_numrecs), cur);
1435 rrp = XFS_INOBT_REC_ADDR(right, 1, cur); 1421 rrp = XFS_INOBT_REC_ADDR(right, 1, cur);
1436 memmove(rrp + 1, rrp, INT_GET(right->bb_numrecs, ARCH_CONVERT) * sizeof(*rrp)); 1422 memmove(rrp + 1, rrp, be16_to_cpu(right->bb_numrecs) * sizeof(*rrp));
1437 *rrp = *lrp; 1423 *rrp = *lrp;
1438 xfs_inobt_log_recs(cur, rbp, 1, INT_GET(right->bb_numrecs, ARCH_CONVERT) + 1); 1424 xfs_inobt_log_recs(cur, rbp, 1, be16_to_cpu(right->bb_numrecs) + 1);
1439 key.ir_startino = rrp->ir_startino; /* INT_: direct copy */ 1425 key.ir_startino = rrp->ir_startino; /* INT_: direct copy */
1440 rkp = &key; 1426 rkp = &key;
1441 } 1427 }
1442 /* 1428 /*
1443 * Decrement and log left's numrecs, bump and log right's numrecs. 1429 * Decrement and log left's numrecs, bump and log right's numrecs.
1444 */ 1430 */
1445 INT_MOD(left->bb_numrecs, ARCH_CONVERT, -1); 1431 be16_add(&left->bb_numrecs, -1);
1446 xfs_inobt_log_block(cur->bc_tp, lbp, XFS_BB_NUMRECS); 1432 xfs_inobt_log_block(cur->bc_tp, lbp, XFS_BB_NUMRECS);
1447 INT_MOD(right->bb_numrecs, ARCH_CONVERT, +1); 1433 be16_add(&right->bb_numrecs, 1);
1448#ifdef DEBUG 1434#ifdef DEBUG
1449 if (level > 0) 1435 if (level > 0)
1450 xfs_btree_check_key(cur->bc_btnum, rkp, rkp + 1); 1436 xfs_btree_check_key(cur->bc_btnum, rkp, rkp + 1);
@@ -1536,17 +1522,17 @@ xfs_inobt_split(
1536 /* 1522 /*
1537 * Fill in the btree header for the new block. 1523 * Fill in the btree header for the new block.
1538 */ 1524 */
1539 INT_SET(right->bb_magic, ARCH_CONVERT, xfs_magics[cur->bc_btnum]); 1525 right->bb_magic = cpu_to_be32(xfs_magics[cur->bc_btnum]);
1540 right->bb_level = left->bb_level; /* INT_: direct copy */ 1526 right->bb_level = left->bb_level;
1541 INT_SET(right->bb_numrecs, ARCH_CONVERT, (__uint16_t)(INT_GET(left->bb_numrecs, ARCH_CONVERT) / 2)); 1527 right->bb_numrecs = cpu_to_be16(be16_to_cpu(left->bb_numrecs) / 2);
1542 /* 1528 /*
1543 * Make sure that if there's an odd number of entries now, that 1529 * Make sure that if there's an odd number of entries now, that
1544 * each new block will have the same number of entries. 1530 * each new block will have the same number of entries.
1545 */ 1531 */
1546 if ((INT_GET(left->bb_numrecs, ARCH_CONVERT) & 1) && 1532 if ((be16_to_cpu(left->bb_numrecs) & 1) &&
1547 cur->bc_ptrs[level] <= INT_GET(right->bb_numrecs, ARCH_CONVERT) + 1) 1533 cur->bc_ptrs[level] <= be16_to_cpu(right->bb_numrecs) + 1)
1548 INT_MOD(right->bb_numrecs, ARCH_CONVERT, +1); 1534 be16_add(&right->bb_numrecs, 1);
1549 i = INT_GET(left->bb_numrecs, ARCH_CONVERT) - INT_GET(right->bb_numrecs, ARCH_CONVERT) + 1; 1535 i = be16_to_cpu(left->bb_numrecs) - be16_to_cpu(right->bb_numrecs) + 1;
1550 /* 1536 /*
1551 * For non-leaf blocks, copy keys and addresses over to the new block. 1537 * For non-leaf blocks, copy keys and addresses over to the new block.
1552 */ 1538 */
@@ -1556,15 +1542,15 @@ xfs_inobt_split(
1556 rkp = XFS_INOBT_KEY_ADDR(right, 1, cur); 1542 rkp = XFS_INOBT_KEY_ADDR(right, 1, cur);
1557 rpp = XFS_INOBT_PTR_ADDR(right, 1, cur); 1543 rpp = XFS_INOBT_PTR_ADDR(right, 1, cur);
1558#ifdef DEBUG 1544#ifdef DEBUG
1559 for (i = 0; i < INT_GET(right->bb_numrecs, ARCH_CONVERT); i++) { 1545 for (i = 0; i < be16_to_cpu(right->bb_numrecs); i++) {
1560 if ((error = xfs_btree_check_sptr(cur, INT_GET(lpp[i], ARCH_CONVERT), level))) 1546 if ((error = xfs_btree_check_sptr(cur, be32_to_cpu(lpp[i]), level)))
1561 return error; 1547 return error;
1562 } 1548 }
1563#endif 1549#endif
1564 memcpy(rkp, lkp, INT_GET(right->bb_numrecs, ARCH_CONVERT) * sizeof(*rkp)); 1550 memcpy(rkp, lkp, be16_to_cpu(right->bb_numrecs) * sizeof(*rkp));
1565 memcpy(rpp, lpp, INT_GET(right->bb_numrecs, ARCH_CONVERT) * sizeof(*rpp)); 1551 memcpy(rpp, lpp, be16_to_cpu(right->bb_numrecs) * sizeof(*rpp));
1566 xfs_inobt_log_keys(cur, rbp, 1, INT_GET(right->bb_numrecs, ARCH_CONVERT)); 1552 xfs_inobt_log_keys(cur, rbp, 1, be16_to_cpu(right->bb_numrecs));
1567 xfs_inobt_log_ptrs(cur, rbp, 1, INT_GET(right->bb_numrecs, ARCH_CONVERT)); 1553 xfs_inobt_log_ptrs(cur, rbp, 1, be16_to_cpu(right->bb_numrecs));
1568 *keyp = *rkp; 1554 *keyp = *rkp;
1569 } 1555 }
1570 /* 1556 /*
@@ -1573,36 +1559,36 @@ xfs_inobt_split(
1573 else { 1559 else {
1574 lrp = XFS_INOBT_REC_ADDR(left, i, cur); 1560 lrp = XFS_INOBT_REC_ADDR(left, i, cur);
1575 rrp = XFS_INOBT_REC_ADDR(right, 1, cur); 1561 rrp = XFS_INOBT_REC_ADDR(right, 1, cur);
1576 memcpy(rrp, lrp, INT_GET(right->bb_numrecs, ARCH_CONVERT) * sizeof(*rrp)); 1562 memcpy(rrp, lrp, be16_to_cpu(right->bb_numrecs) * sizeof(*rrp));
1577 xfs_inobt_log_recs(cur, rbp, 1, INT_GET(right->bb_numrecs, ARCH_CONVERT)); 1563 xfs_inobt_log_recs(cur, rbp, 1, be16_to_cpu(right->bb_numrecs));
1578 keyp->ir_startino = rrp->ir_startino; /* INT_: direct copy */ 1564 keyp->ir_startino = rrp->ir_startino; /* INT_: direct copy */
1579 } 1565 }
1580 /* 1566 /*
1581 * Find the left block number by looking in the buffer. 1567 * Find the left block number by looking in the buffer.
1582 * Adjust numrecs, sibling pointers. 1568 * Adjust numrecs, sibling pointers.
1583 */ 1569 */
1584 INT_MOD(left->bb_numrecs, ARCH_CONVERT, -(INT_GET(right->bb_numrecs, ARCH_CONVERT))); 1570 be16_add(&left->bb_numrecs, -(be16_to_cpu(right->bb_numrecs)));
1585 right->bb_rightsib = left->bb_rightsib; /* INT_: direct copy */ 1571 right->bb_rightsib = left->bb_rightsib;
1586 INT_SET(left->bb_rightsib, ARCH_CONVERT, args.agbno); 1572 left->bb_rightsib = cpu_to_be32(args.agbno);
1587 INT_SET(right->bb_leftsib, ARCH_CONVERT, lbno); 1573 right->bb_leftsib = cpu_to_be32(lbno);
1588 xfs_inobt_log_block(args.tp, rbp, XFS_BB_ALL_BITS); 1574 xfs_inobt_log_block(args.tp, rbp, XFS_BB_ALL_BITS);
1589 xfs_inobt_log_block(args.tp, lbp, XFS_BB_NUMRECS | XFS_BB_RIGHTSIB); 1575 xfs_inobt_log_block(args.tp, lbp, XFS_BB_NUMRECS | XFS_BB_RIGHTSIB);
1590 /* 1576 /*
1591 * If there's a block to the new block's right, make that block 1577 * If there's a block to the new block's right, make that block
1592 * point back to right instead of to left. 1578 * point back to right instead of to left.
1593 */ 1579 */
1594 if (INT_GET(right->bb_rightsib, ARCH_CONVERT) != NULLAGBLOCK) { 1580 if (be32_to_cpu(right->bb_rightsib) != NULLAGBLOCK) {
1595 xfs_inobt_block_t *rrblock; /* rr btree block */ 1581 xfs_inobt_block_t *rrblock; /* rr btree block */
1596 xfs_buf_t *rrbp; /* buffer for rrblock */ 1582 xfs_buf_t *rrbp; /* buffer for rrblock */
1597 1583
1598 if ((error = xfs_btree_read_bufs(args.mp, args.tp, args.agno, 1584 if ((error = xfs_btree_read_bufs(args.mp, args.tp, args.agno,
1599 INT_GET(right->bb_rightsib, ARCH_CONVERT), 0, &rrbp, 1585 be32_to_cpu(right->bb_rightsib), 0, &rrbp,
1600 XFS_INO_BTREE_REF))) 1586 XFS_INO_BTREE_REF)))
1601 return error; 1587 return error;
1602 rrblock = XFS_BUF_TO_INOBT_BLOCK(rrbp); 1588 rrblock = XFS_BUF_TO_INOBT_BLOCK(rrbp);
1603 if ((error = xfs_btree_check_sblock(cur, rrblock, level, rrbp))) 1589 if ((error = xfs_btree_check_sblock(cur, rrblock, level, rrbp)))
1604 return error; 1590 return error;
1605 INT_SET(rrblock->bb_leftsib, ARCH_CONVERT, args.agbno); 1591 rrblock->bb_leftsib = cpu_to_be32(args.agbno);
1606 xfs_inobt_log_block(args.tp, rrbp, XFS_BB_LEFTSIB); 1592 xfs_inobt_log_block(args.tp, rrbp, XFS_BB_LEFTSIB);
1607 } 1593 }
1608 /* 1594 /*
@@ -1610,9 +1596,9 @@ xfs_inobt_split(
1610 * If it's just pointing past the last entry in left, then we'll 1596 * If it's just pointing past the last entry in left, then we'll
1611 * insert there, so don't change anything in that case. 1597 * insert there, so don't change anything in that case.
1612 */ 1598 */
1613 if (cur->bc_ptrs[level] > INT_GET(left->bb_numrecs, ARCH_CONVERT) + 1) { 1599 if (cur->bc_ptrs[level] > be16_to_cpu(left->bb_numrecs) + 1) {
1614 xfs_btree_setbuf(cur, level, rbp); 1600 xfs_btree_setbuf(cur, level, rbp);
1615 cur->bc_ptrs[level] -= INT_GET(left->bb_numrecs, ARCH_CONVERT); 1601 cur->bc_ptrs[level] -= be16_to_cpu(left->bb_numrecs);
1616 } 1602 }
1617 /* 1603 /*
1618 * If there are more levels, we'll need another cursor which refers 1604 * If there are more levels, we'll need another cursor which refers
@@ -1710,7 +1696,7 @@ xfs_inobt_decrement(
1710 /* 1696 /*
1711 * If we just went off the left edge of the tree, return failure. 1697 * If we just went off the left edge of the tree, return failure.
1712 */ 1698 */
1713 if (INT_GET(block->bb_leftsib, ARCH_CONVERT) == NULLAGBLOCK) { 1699 if (be32_to_cpu(block->bb_leftsib) == NULLAGBLOCK) {
1714 *stat = 0; 1700 *stat = 0;
1715 return 0; 1701 return 0;
1716 } 1702 }
@@ -1739,7 +1725,7 @@ xfs_inobt_decrement(
1739 xfs_agblock_t agbno; /* block number of btree block */ 1725 xfs_agblock_t agbno; /* block number of btree block */
1740 xfs_buf_t *bp; /* buffer containing btree block */ 1726 xfs_buf_t *bp; /* buffer containing btree block */
1741 1727
1742 agbno = INT_GET(*XFS_INOBT_PTR_ADDR(block, cur->bc_ptrs[lev], cur), ARCH_CONVERT); 1728 agbno = be32_to_cpu(*XFS_INOBT_PTR_ADDR(block, cur->bc_ptrs[lev], cur));
1743 if ((error = xfs_btree_read_bufs(cur->bc_mp, cur->bc_tp, 1729 if ((error = xfs_btree_read_bufs(cur->bc_mp, cur->bc_tp,
1744 cur->bc_private.i.agno, agbno, 0, &bp, 1730 cur->bc_private.i.agno, agbno, 0, &bp,
1745 XFS_INO_BTREE_REF))) 1731 XFS_INO_BTREE_REF)))
@@ -1749,7 +1735,7 @@ xfs_inobt_decrement(
1749 block = XFS_BUF_TO_INOBT_BLOCK(bp); 1735 block = XFS_BUF_TO_INOBT_BLOCK(bp);
1750 if ((error = xfs_btree_check_sblock(cur, block, lev, bp))) 1736 if ((error = xfs_btree_check_sblock(cur, block, lev, bp)))
1751 return error; 1737 return error;
1752 cur->bc_ptrs[lev] = INT_GET(block->bb_numrecs, ARCH_CONVERT); 1738 cur->bc_ptrs[lev] = be16_to_cpu(block->bb_numrecs);
1753 } 1739 }
1754 *stat = 1; 1740 *stat = 1;
1755 return 0; 1741 return 0;
@@ -1821,7 +1807,7 @@ xfs_inobt_get_rec(
1821 /* 1807 /*
1822 * Off the right end or left end, return failure. 1808 * Off the right end or left end, return failure.
1823 */ 1809 */
1824 if (ptr > INT_GET(block->bb_numrecs, ARCH_CONVERT) || ptr <= 0) { 1810 if (ptr > be16_to_cpu(block->bb_numrecs) || ptr <= 0) {
1825 *stat = 0; 1811 *stat = 0;
1826 return 0; 1812 return 0;
1827 } 1813 }
@@ -1869,14 +1855,14 @@ xfs_inobt_increment(
1869 * Increment the ptr at this level. If we're still in the block 1855 * Increment the ptr at this level. If we're still in the block
1870 * then we're done. 1856 * then we're done.
1871 */ 1857 */
1872 if (++cur->bc_ptrs[level] <= INT_GET(block->bb_numrecs, ARCH_CONVERT)) { 1858 if (++cur->bc_ptrs[level] <= be16_to_cpu(block->bb_numrecs)) {
1873 *stat = 1; 1859 *stat = 1;
1874 return 0; 1860 return 0;
1875 } 1861 }
1876 /* 1862 /*
1877 * If we just went off the right edge of the tree, return failure. 1863 * If we just went off the right edge of the tree, return failure.
1878 */ 1864 */
1879 if (INT_GET(block->bb_rightsib, ARCH_CONVERT) == NULLAGBLOCK) { 1865 if (be32_to_cpu(block->bb_rightsib) == NULLAGBLOCK) {
1880 *stat = 0; 1866 *stat = 0;
1881 return 0; 1867 return 0;
1882 } 1868 }
@@ -1891,7 +1877,7 @@ xfs_inobt_increment(
1891 if ((error = xfs_btree_check_sblock(cur, block, lev, bp))) 1877 if ((error = xfs_btree_check_sblock(cur, block, lev, bp)))
1892 return error; 1878 return error;
1893#endif 1879#endif
1894 if (++cur->bc_ptrs[lev] <= INT_GET(block->bb_numrecs, ARCH_CONVERT)) 1880 if (++cur->bc_ptrs[lev] <= be16_to_cpu(block->bb_numrecs))
1895 break; 1881 break;
1896 /* 1882 /*
1897 * Read-ahead the right block, we're going to read it 1883 * Read-ahead the right block, we're going to read it
@@ -1911,7 +1897,7 @@ xfs_inobt_increment(
1911 lev > level; ) { 1897 lev > level; ) {
1912 xfs_agblock_t agbno; /* block number of btree block */ 1898 xfs_agblock_t agbno; /* block number of btree block */
1913 1899
1914 agbno = INT_GET(*XFS_INOBT_PTR_ADDR(block, cur->bc_ptrs[lev], cur), ARCH_CONVERT); 1900 agbno = be32_to_cpu(*XFS_INOBT_PTR_ADDR(block, cur->bc_ptrs[lev], cur));
1915 if ((error = xfs_btree_read_bufs(cur->bc_mp, cur->bc_tp, 1901 if ((error = xfs_btree_read_bufs(cur->bc_mp, cur->bc_tp,
1916 cur->bc_private.i.agno, agbno, 0, &bp, 1902 cur->bc_private.i.agno, agbno, 0, &bp,
1917 XFS_INO_BTREE_REF))) 1903 XFS_INO_BTREE_REF)))