diff options
Diffstat (limited to 'fs/xfs/xfs_btree.h')
| -rw-r--r-- | fs/xfs/xfs_btree.h | 211 |
1 files changed, 51 insertions, 160 deletions
diff --git a/fs/xfs/xfs_btree.h b/fs/xfs/xfs_btree.h index 09b4e1532a35..44f1bd98064a 100644 --- a/fs/xfs/xfs_btree.h +++ b/fs/xfs/xfs_btree.h | |||
| @@ -1,33 +1,19 @@ | |||
| 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 | #ifndef __XFS_BTREE_H__ | 18 | #ifndef __XFS_BTREE_H__ |
| 33 | #define __XFS_BTREE_H__ | 19 | #define __XFS_BTREE_H__ |
| @@ -53,25 +39,23 @@ struct xfs_trans; | |||
| 53 | /* | 39 | /* |
| 54 | * Short form header: space allocation btrees. | 40 | * Short form header: space allocation btrees. |
| 55 | */ | 41 | */ |
| 56 | typedef struct xfs_btree_sblock | 42 | typedef struct xfs_btree_sblock { |
| 57 | { | 43 | __be32 bb_magic; /* magic number for block type */ |
| 58 | __uint32_t bb_magic; /* magic number for block type */ | 44 | __be16 bb_level; /* 0 is a leaf */ |
| 59 | __uint16_t bb_level; /* 0 is a leaf */ | 45 | __be16 bb_numrecs; /* current # of data records */ |
| 60 | __uint16_t bb_numrecs; /* current # of data records */ | 46 | __be32 bb_leftsib; /* left sibling block or NULLAGBLOCK */ |
| 61 | xfs_agblock_t bb_leftsib; /* left sibling block or NULLAGBLOCK */ | 47 | __be32 bb_rightsib; /* right sibling block or NULLAGBLOCK */ |
| 62 | xfs_agblock_t bb_rightsib; /* right sibling block or NULLAGBLOCK */ | ||
| 63 | } xfs_btree_sblock_t; | 48 | } xfs_btree_sblock_t; |
| 64 | 49 | ||
| 65 | /* | 50 | /* |
| 66 | * Long form header: bmap btrees. | 51 | * Long form header: bmap btrees. |
| 67 | */ | 52 | */ |
| 68 | typedef struct xfs_btree_lblock | 53 | typedef struct xfs_btree_lblock { |
| 69 | { | 54 | __be32 bb_magic; /* magic number for block type */ |
| 70 | __uint32_t bb_magic; /* magic number for block type */ | 55 | __be16 bb_level; /* 0 is a leaf */ |
| 71 | __uint16_t bb_level; /* 0 is a leaf */ | 56 | __be16 bb_numrecs; /* current # of data records */ |
| 72 | __uint16_t bb_numrecs; /* current # of data records */ | 57 | __be64 bb_leftsib; /* left sibling block or NULLDFSBNO */ |
| 73 | xfs_dfsbno_t bb_leftsib; /* left sibling block or NULLDFSBNO */ | 58 | __be64 bb_rightsib; /* right sibling block or NULLDFSBNO */ |
| 74 | xfs_dfsbno_t bb_rightsib; /* right sibling block or NULLDFSBNO */ | ||
| 75 | } xfs_btree_lblock_t; | 59 | } xfs_btree_lblock_t; |
| 76 | 60 | ||
| 77 | /* | 61 | /* |
| @@ -79,24 +63,23 @@ typedef struct xfs_btree_lblock | |||
| 79 | */ | 63 | */ |
| 80 | typedef struct xfs_btree_hdr | 64 | typedef struct xfs_btree_hdr |
| 81 | { | 65 | { |
| 82 | __uint32_t bb_magic; /* magic number for block type */ | 66 | __be32 bb_magic; /* magic number for block type */ |
| 83 | __uint16_t bb_level; /* 0 is a leaf */ | 67 | __be16 bb_level; /* 0 is a leaf */ |
| 84 | __uint16_t bb_numrecs; /* current # of data records */ | 68 | __be16 bb_numrecs; /* current # of data records */ |
| 85 | } xfs_btree_hdr_t; | 69 | } xfs_btree_hdr_t; |
| 86 | 70 | ||
| 87 | typedef struct xfs_btree_block | 71 | typedef struct xfs_btree_block { |
| 88 | { | ||
| 89 | xfs_btree_hdr_t bb_h; /* header */ | 72 | xfs_btree_hdr_t bb_h; /* header */ |
| 90 | union { | 73 | union { |
| 91 | struct { | 74 | struct { |
| 92 | xfs_agblock_t bb_leftsib; | 75 | __be32 bb_leftsib; |
| 93 | xfs_agblock_t bb_rightsib; | 76 | __be32 bb_rightsib; |
| 94 | } s; /* short form pointers */ | 77 | } s; /* short form pointers */ |
| 95 | struct { | 78 | struct { |
| 96 | xfs_dfsbno_t bb_leftsib; | 79 | __be64 bb_leftsib; |
| 97 | xfs_dfsbno_t bb_rightsib; | 80 | __be64 bb_rightsib; |
| 98 | } l; /* long form pointers */ | 81 | } l; /* long form pointers */ |
| 99 | } bb_u; /* rest */ | 82 | } bb_u; /* rest */ |
| 100 | } xfs_btree_block_t; | 83 | } xfs_btree_block_t; |
| 101 | 84 | ||
| 102 | /* | 85 | /* |
| @@ -113,12 +96,7 @@ typedef struct xfs_btree_block | |||
| 113 | /* | 96 | /* |
| 114 | * Boolean to select which form of xfs_btree_block_t.bb_u to use. | 97 | * Boolean to select which form of xfs_btree_block_t.bb_u to use. |
| 115 | */ | 98 | */ |
| 116 | #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_BTREE_LONG_PTRS) | ||
| 117 | int xfs_btree_long_ptrs(xfs_btnum_t btnum); | ||
| 118 | #define XFS_BTREE_LONG_PTRS(btnum) ((btnum) == XFS_BTNUM_BMAP) | ||
| 119 | #else | ||
| 120 | #define XFS_BTREE_LONG_PTRS(btnum) ((btnum) == XFS_BTNUM_BMAP) | 99 | #define XFS_BTREE_LONG_PTRS(btnum) ((btnum) == XFS_BTNUM_BMAP) |
| 121 | #endif | ||
| 122 | 100 | ||
| 123 | /* | 101 | /* |
| 124 | * Magic numbers for btree blocks. | 102 | * Magic numbers for btree blocks. |
| @@ -165,7 +143,7 @@ typedef struct xfs_btree_cur | |||
| 165 | struct xfs_trans *bc_tp; /* transaction we're in, if any */ | 143 | struct xfs_trans *bc_tp; /* transaction we're in, if any */ |
| 166 | struct xfs_mount *bc_mp; /* file system mount struct */ | 144 | struct xfs_mount *bc_mp; /* file system mount struct */ |
| 167 | union { | 145 | union { |
| 168 | xfs_alloc_rec_t a; | 146 | xfs_alloc_rec_incore_t a; |
| 169 | xfs_bmbt_irec_t b; | 147 | xfs_bmbt_irec_t b; |
| 170 | xfs_inobt_rec_t i; | 148 | xfs_inobt_rec_t i; |
| 171 | } bc_rec; /* current insert/search record value */ | 149 | } bc_rec; /* current insert/search record value */ |
| @@ -205,24 +183,10 @@ typedef struct xfs_btree_cur | |||
| 205 | /* | 183 | /* |
| 206 | * Convert from buffer to btree block header. | 184 | * Convert from buffer to btree block header. |
| 207 | */ | 185 | */ |
| 208 | #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_BUF_TO_BLOCK) | 186 | #define XFS_BUF_TO_BLOCK(bp) ((xfs_btree_block_t *)XFS_BUF_PTR(bp)) |
| 209 | xfs_btree_block_t *xfs_buf_to_block(struct xfs_buf *bp); | 187 | #define XFS_BUF_TO_LBLOCK(bp) ((xfs_btree_lblock_t *)XFS_BUF_PTR(bp)) |
| 210 | #define XFS_BUF_TO_BLOCK(bp) xfs_buf_to_block(bp) | 188 | #define XFS_BUF_TO_SBLOCK(bp) ((xfs_btree_sblock_t *)XFS_BUF_PTR(bp)) |
| 211 | #else | 189 | |
| 212 | #define XFS_BUF_TO_BLOCK(bp) ((xfs_btree_block_t *)(XFS_BUF_PTR(bp))) | ||
| 213 | #endif | ||
| 214 | #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_BUF_TO_LBLOCK) | ||
| 215 | xfs_btree_lblock_t *xfs_buf_to_lblock(struct xfs_buf *bp); | ||
| 216 | #define XFS_BUF_TO_LBLOCK(bp) xfs_buf_to_lblock(bp) | ||
| 217 | #else | ||
| 218 | #define XFS_BUF_TO_LBLOCK(bp) ((xfs_btree_lblock_t *)(XFS_BUF_PTR(bp))) | ||
| 219 | #endif | ||
| 220 | #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_BUF_TO_SBLOCK) | ||
| 221 | xfs_btree_sblock_t *xfs_buf_to_sblock(struct xfs_buf *bp); | ||
| 222 | #define XFS_BUF_TO_SBLOCK(bp) xfs_buf_to_sblock(bp) | ||
| 223 | #else | ||
| 224 | #define XFS_BUF_TO_SBLOCK(bp) ((xfs_btree_sblock_t *)(XFS_BUF_PTR(bp))) | ||
| 225 | #endif | ||
| 226 | 190 | ||
| 227 | #ifdef __KERNEL__ | 191 | #ifdef __KERNEL__ |
| 228 | 192 | ||
| @@ -477,106 +441,33 @@ xfs_btree_setbuf( | |||
| 477 | /* | 441 | /* |
| 478 | * Min and max functions for extlen, agblock, fileoff, and filblks types. | 442 | * Min and max functions for extlen, agblock, fileoff, and filblks types. |
| 479 | */ | 443 | */ |
| 480 | #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_EXTLEN_MIN) | ||
| 481 | xfs_extlen_t xfs_extlen_min(xfs_extlen_t a, xfs_extlen_t b); | ||
| 482 | #define XFS_EXTLEN_MIN(a,b) xfs_extlen_min(a,b) | ||
| 483 | #else | ||
| 484 | #define XFS_EXTLEN_MIN(a,b) \ | 444 | #define XFS_EXTLEN_MIN(a,b) \ |
| 485 | ((xfs_extlen_t)(a) < (xfs_extlen_t)(b) ? \ | 445 | ((xfs_extlen_t)(a) < (xfs_extlen_t)(b) ? \ |
| 486 | (xfs_extlen_t)(a) : (xfs_extlen_t)(b)) | 446 | (xfs_extlen_t)(a) : (xfs_extlen_t)(b)) |
| 487 | #endif | ||
| 488 | #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_EXTLEN_MAX) | ||
| 489 | xfs_extlen_t xfs_extlen_max(xfs_extlen_t a, xfs_extlen_t b); | ||
| 490 | #define XFS_EXTLEN_MAX(a,b) xfs_extlen_max(a,b) | ||
| 491 | #else | ||
| 492 | #define XFS_EXTLEN_MAX(a,b) \ | 447 | #define XFS_EXTLEN_MAX(a,b) \ |
| 493 | ((xfs_extlen_t)(a) > (xfs_extlen_t)(b) ? \ | 448 | ((xfs_extlen_t)(a) > (xfs_extlen_t)(b) ? \ |
| 494 | (xfs_extlen_t)(a) : (xfs_extlen_t)(b)) | 449 | (xfs_extlen_t)(a) : (xfs_extlen_t)(b)) |
| 495 | #endif | ||
| 496 | |||
| 497 | #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_AGBLOCK_MIN) | ||
| 498 | xfs_agblock_t xfs_agblock_min(xfs_agblock_t a, xfs_agblock_t b); | ||
| 499 | #define XFS_AGBLOCK_MIN(a,b) xfs_agblock_min(a,b) | ||
| 500 | #else | ||
| 501 | #define XFS_AGBLOCK_MIN(a,b) \ | 450 | #define XFS_AGBLOCK_MIN(a,b) \ |
| 502 | ((xfs_agblock_t)(a) < (xfs_agblock_t)(b) ? \ | 451 | ((xfs_agblock_t)(a) < (xfs_agblock_t)(b) ? \ |
| 503 | (xfs_agblock_t)(a) : (xfs_agblock_t)(b)) | 452 | (xfs_agblock_t)(a) : (xfs_agblock_t)(b)) |
| 504 | #endif | ||
| 505 | #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_AGBLOCK_MAX) | ||
| 506 | xfs_agblock_t xfs_agblock_max(xfs_agblock_t a, xfs_agblock_t b); | ||
| 507 | #define XFS_AGBLOCK_MAX(a,b) xfs_agblock_max(a,b) | ||
| 508 | #else | ||
| 509 | #define XFS_AGBLOCK_MAX(a,b) \ | 453 | #define XFS_AGBLOCK_MAX(a,b) \ |
| 510 | ((xfs_agblock_t)(a) > (xfs_agblock_t)(b) ? \ | 454 | ((xfs_agblock_t)(a) > (xfs_agblock_t)(b) ? \ |
| 511 | (xfs_agblock_t)(a) : (xfs_agblock_t)(b)) | 455 | (xfs_agblock_t)(a) : (xfs_agblock_t)(b)) |
| 512 | #endif | ||
| 513 | |||
| 514 | #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_FILEOFF_MIN) | ||
| 515 | xfs_fileoff_t xfs_fileoff_min(xfs_fileoff_t a, xfs_fileoff_t b); | ||
| 516 | #define XFS_FILEOFF_MIN(a,b) xfs_fileoff_min(a,b) | ||
| 517 | #else | ||
| 518 | #define XFS_FILEOFF_MIN(a,b) \ | 456 | #define XFS_FILEOFF_MIN(a,b) \ |
| 519 | ((xfs_fileoff_t)(a) < (xfs_fileoff_t)(b) ? \ | 457 | ((xfs_fileoff_t)(a) < (xfs_fileoff_t)(b) ? \ |
| 520 | (xfs_fileoff_t)(a) : (xfs_fileoff_t)(b)) | 458 | (xfs_fileoff_t)(a) : (xfs_fileoff_t)(b)) |
| 521 | #endif | ||
| 522 | #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_FILEOFF_MAX) | ||
| 523 | xfs_fileoff_t xfs_fileoff_max(xfs_fileoff_t a, xfs_fileoff_t b); | ||
| 524 | #define XFS_FILEOFF_MAX(a,b) xfs_fileoff_max(a,b) | ||
| 525 | #else | ||
| 526 | #define XFS_FILEOFF_MAX(a,b) \ | 459 | #define XFS_FILEOFF_MAX(a,b) \ |
| 527 | ((xfs_fileoff_t)(a) > (xfs_fileoff_t)(b) ? \ | 460 | ((xfs_fileoff_t)(a) > (xfs_fileoff_t)(b) ? \ |
| 528 | (xfs_fileoff_t)(a) : (xfs_fileoff_t)(b)) | 461 | (xfs_fileoff_t)(a) : (xfs_fileoff_t)(b)) |
| 529 | #endif | ||
| 530 | |||
| 531 | #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_FILBLKS_MIN) | ||
| 532 | xfs_filblks_t xfs_filblks_min(xfs_filblks_t a, xfs_filblks_t b); | ||
| 533 | #define XFS_FILBLKS_MIN(a,b) xfs_filblks_min(a,b) | ||
| 534 | #else | ||
| 535 | #define XFS_FILBLKS_MIN(a,b) \ | 462 | #define XFS_FILBLKS_MIN(a,b) \ |
| 536 | ((xfs_filblks_t)(a) < (xfs_filblks_t)(b) ? \ | 463 | ((xfs_filblks_t)(a) < (xfs_filblks_t)(b) ? \ |
| 537 | (xfs_filblks_t)(a) : (xfs_filblks_t)(b)) | 464 | (xfs_filblks_t)(a) : (xfs_filblks_t)(b)) |
| 538 | #endif | ||
| 539 | #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_FILBLKS_MAX) | ||
| 540 | xfs_filblks_t xfs_filblks_max(xfs_filblks_t a, xfs_filblks_t b); | ||
| 541 | #define XFS_FILBLKS_MAX(a,b) xfs_filblks_max(a,b) | ||
| 542 | #else | ||
| 543 | #define XFS_FILBLKS_MAX(a,b) \ | 465 | #define XFS_FILBLKS_MAX(a,b) \ |
| 544 | ((xfs_filblks_t)(a) > (xfs_filblks_t)(b) ? \ | 466 | ((xfs_filblks_t)(a) > (xfs_filblks_t)(b) ? \ |
| 545 | (xfs_filblks_t)(a) : (xfs_filblks_t)(b)) | 467 | (xfs_filblks_t)(a) : (xfs_filblks_t)(b)) |
| 546 | #endif | 468 | |
| 547 | #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_FSB_SANITY_CHECK) | ||
| 548 | int xfs_fsb_sanity_check(struct xfs_mount *mp, xfs_fsblock_t fsb); | ||
| 549 | #define XFS_FSB_SANITY_CHECK(mp,fsb) xfs_fsb_sanity_check(mp,fsb) | ||
| 550 | #else | ||
| 551 | #define XFS_FSB_SANITY_CHECK(mp,fsb) \ | 469 | #define XFS_FSB_SANITY_CHECK(mp,fsb) \ |
| 552 | (XFS_FSB_TO_AGNO(mp, fsb) < mp->m_sb.sb_agcount && \ | 470 | (XFS_FSB_TO_AGNO(mp, fsb) < mp->m_sb.sb_agcount && \ |
| 553 | XFS_FSB_TO_AGBNO(mp, fsb) < mp->m_sb.sb_agblocks) | 471 | XFS_FSB_TO_AGBNO(mp, fsb) < mp->m_sb.sb_agblocks) |
| 554 | #endif | ||
| 555 | |||
| 556 | /* | ||
| 557 | * Macros to set EFSCORRUPTED & return/branch. | ||
| 558 | */ | ||
| 559 | #define XFS_WANT_CORRUPTED_GOTO(x,l) \ | ||
| 560 | { \ | ||
| 561 | int fs_is_ok = (x); \ | ||
| 562 | ASSERT(fs_is_ok); \ | ||
| 563 | if (unlikely(!fs_is_ok)) { \ | ||
| 564 | XFS_ERROR_REPORT("XFS_WANT_CORRUPTED_GOTO", \ | ||
| 565 | XFS_ERRLEVEL_LOW, NULL); \ | ||
| 566 | error = XFS_ERROR(EFSCORRUPTED); \ | ||
| 567 | goto l; \ | ||
| 568 | } \ | ||
| 569 | } | ||
| 570 | |||
| 571 | #define XFS_WANT_CORRUPTED_RETURN(x) \ | ||
| 572 | { \ | ||
| 573 | int fs_is_ok = (x); \ | ||
| 574 | ASSERT(fs_is_ok); \ | ||
| 575 | if (unlikely(!fs_is_ok)) { \ | ||
| 576 | XFS_ERROR_REPORT("XFS_WANT_CORRUPTED_RETURN", \ | ||
| 577 | XFS_ERRLEVEL_LOW, NULL); \ | ||
| 578 | return XFS_ERROR(EFSCORRUPTED); \ | ||
| 579 | } \ | ||
| 580 | } | ||
| 581 | 472 | ||
| 582 | #endif /* __XFS_BTREE_H__ */ | 473 | #endif /* __XFS_BTREE_H__ */ |
