Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 2 | * Copyright (c) 2000,2002-2005 Silicon Graphics, Inc. |
| 3 | * All Rights Reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License as |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * published by the Free Software Foundation. |
| 8 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 9 | * This program is distributed in the hope that it would be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write the Free Software Foundation, |
| 16 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | */ |
| 18 | #ifndef __XFS_BMAP_BTREE_H__ |
| 19 | #define __XFS_BMAP_BTREE_H__ |
| 20 | |
| 21 | #define XFS_BMAP_MAGIC 0x424d4150 /* 'BMAP' */ |
| 22 | |
| 23 | struct xfs_btree_cur; |
| 24 | struct xfs_btree_lblock; |
| 25 | struct xfs_mount; |
| 26 | struct xfs_inode; |
| 27 | |
| 28 | /* |
| 29 | * Bmap root header, on-disk form only. |
| 30 | */ |
Christoph Hellwig | 16259e7 | 2005-11-02 15:11:25 +1100 | [diff] [blame] | 31 | typedef struct xfs_bmdr_block { |
| 32 | __be16 bb_level; /* 0 is a leaf */ |
| 33 | __be16 bb_numrecs; /* current # of data records */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | } xfs_bmdr_block_t; |
| 35 | |
| 36 | /* |
| 37 | * Bmap btree record and extent descriptor. |
| 38 | * For 32-bit kernels, |
| 39 | * l0:31 is an extent flag (value 1 indicates non-normal). |
| 40 | * l0:0-30 and l1:9-31 are startoff. |
| 41 | * l1:0-8, l2:0-31, and l3:21-31 are startblock. |
| 42 | * l3:0-20 are blockcount. |
| 43 | * For 64-bit kernels, |
| 44 | * l0:63 is an extent flag (value 1 indicates non-normal). |
| 45 | * l0:9-62 are startoff. |
| 46 | * l0:0-8 and l1:21-63 are startblock. |
| 47 | * l1:0-20 are blockcount. |
| 48 | */ |
| 49 | |
Nathan Scott | f016bad | 2005-09-08 15:30:05 +1000 | [diff] [blame] | 50 | #ifndef XFS_NATIVE_HOST |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
| 52 | #define BMBT_TOTAL_BITLEN 128 /* 128 bits, 16 bytes */ |
| 53 | #define BMBT_EXNTFLAG_BITOFF 0 |
| 54 | #define BMBT_EXNTFLAG_BITLEN 1 |
| 55 | #define BMBT_STARTOFF_BITOFF (BMBT_EXNTFLAG_BITOFF + BMBT_EXNTFLAG_BITLEN) |
| 56 | #define BMBT_STARTOFF_BITLEN 54 |
| 57 | #define BMBT_STARTBLOCK_BITOFF (BMBT_STARTOFF_BITOFF + BMBT_STARTOFF_BITLEN) |
| 58 | #define BMBT_STARTBLOCK_BITLEN 52 |
| 59 | #define BMBT_BLOCKCOUNT_BITOFF \ |
| 60 | (BMBT_STARTBLOCK_BITOFF + BMBT_STARTBLOCK_BITLEN) |
| 61 | #define BMBT_BLOCKCOUNT_BITLEN (BMBT_TOTAL_BITLEN - BMBT_BLOCKCOUNT_BITOFF) |
| 62 | |
| 63 | #else |
| 64 | |
| 65 | #define BMBT_TOTAL_BITLEN 128 /* 128 bits, 16 bytes */ |
| 66 | #define BMBT_EXNTFLAG_BITOFF 63 |
| 67 | #define BMBT_EXNTFLAG_BITLEN 1 |
| 68 | #define BMBT_STARTOFF_BITOFF (BMBT_EXNTFLAG_BITOFF - BMBT_STARTOFF_BITLEN) |
| 69 | #define BMBT_STARTOFF_BITLEN 54 |
| 70 | #define BMBT_STARTBLOCK_BITOFF 85 /* 128 - 43 (other 9 is in first word) */ |
| 71 | #define BMBT_STARTBLOCK_BITLEN 52 |
| 72 | #define BMBT_BLOCKCOUNT_BITOFF 64 /* Start of second 64 bit container */ |
| 73 | #define BMBT_BLOCKCOUNT_BITLEN 21 |
| 74 | |
Nathan Scott | f016bad | 2005-09-08 15:30:05 +1000 | [diff] [blame] | 75 | #endif /* XFS_NATIVE_HOST */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | |
| 77 | |
| 78 | #define BMBT_USE_64 1 |
| 79 | |
| 80 | typedef struct xfs_bmbt_rec_32 |
| 81 | { |
| 82 | __uint32_t l0, l1, l2, l3; |
| 83 | } xfs_bmbt_rec_32_t; |
| 84 | typedef struct xfs_bmbt_rec_64 |
| 85 | { |
| 86 | __uint64_t l0, l1; |
| 87 | } xfs_bmbt_rec_64_t; |
| 88 | |
| 89 | typedef __uint64_t xfs_bmbt_rec_base_t; /* use this for casts */ |
| 90 | typedef xfs_bmbt_rec_64_t xfs_bmbt_rec_t, xfs_bmdr_rec_t; |
| 91 | |
Christoph Hellwig | a6f64d4 | 2007-08-16 16:23:40 +1000 | [diff] [blame^] | 92 | typedef struct xfs_bmbt_rec_host { |
| 93 | __uint64_t l0, l1; |
| 94 | } xfs_bmbt_rec_host_t; |
| 95 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | /* |
| 97 | * Values and macros for delayed-allocation startblock fields. |
| 98 | */ |
| 99 | #define STARTBLOCKVALBITS 17 |
| 100 | #define STARTBLOCKMASKBITS (15 + XFS_BIG_BLKNOS * 20) |
| 101 | #define DSTARTBLOCKMASKBITS (15 + 20) |
| 102 | #define STARTBLOCKMASK \ |
| 103 | (((((xfs_fsblock_t)1) << STARTBLOCKMASKBITS) - 1) << STARTBLOCKVALBITS) |
| 104 | #define DSTARTBLOCKMASK \ |
| 105 | (((((xfs_dfsbno_t)1) << DSTARTBLOCKMASKBITS) - 1) << STARTBLOCKVALBITS) |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 106 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | #define ISNULLSTARTBLOCK(x) isnullstartblock(x) |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 108 | static inline int isnullstartblock(xfs_fsblock_t x) |
| 109 | { |
| 110 | return ((x) & STARTBLOCKMASK) == STARTBLOCKMASK; |
| 111 | } |
| 112 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | #define ISNULLDSTARTBLOCK(x) isnulldstartblock(x) |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 114 | static inline int isnulldstartblock(xfs_dfsbno_t x) |
| 115 | { |
| 116 | return ((x) & DSTARTBLOCKMASK) == DSTARTBLOCKMASK; |
| 117 | } |
| 118 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | #define NULLSTARTBLOCK(k) nullstartblock(k) |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 120 | static inline xfs_fsblock_t nullstartblock(int k) |
| 121 | { |
| 122 | ASSERT(k < (1 << STARTBLOCKVALBITS)); |
| 123 | return STARTBLOCKMASK | (k); |
| 124 | } |
| 125 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | #define STARTBLOCKVAL(x) startblockval(x) |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 127 | static inline xfs_filblks_t startblockval(xfs_fsblock_t x) |
| 128 | { |
| 129 | return (xfs_filblks_t)((x) & ~STARTBLOCKMASK); |
| 130 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | |
| 132 | /* |
| 133 | * Possible extent formats. |
| 134 | */ |
| 135 | typedef enum { |
| 136 | XFS_EXTFMT_NOSTATE = 0, |
| 137 | XFS_EXTFMT_HASSTATE |
| 138 | } xfs_exntfmt_t; |
| 139 | |
| 140 | /* |
| 141 | * Possible extent states. |
| 142 | */ |
| 143 | typedef enum { |
| 144 | XFS_EXT_NORM, XFS_EXT_UNWRITTEN, |
| 145 | XFS_EXT_DMAPI_OFFLINE, XFS_EXT_INVALID |
| 146 | } xfs_exntst_t; |
| 147 | |
| 148 | /* |
| 149 | * Extent state and extent format macros. |
| 150 | */ |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 151 | #define XFS_EXTFMT_INODE(x) \ |
| 152 | (XFS_SB_VERSION_HASEXTFLGBIT(&((x)->i_mount->m_sb)) ? \ |
| 153 | XFS_EXTFMT_HASSTATE : XFS_EXTFMT_NOSTATE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | #define ISUNWRITTEN(x) ((x)->br_state == XFS_EXT_UNWRITTEN) |
| 155 | |
| 156 | /* |
| 157 | * Incore version of above. |
| 158 | */ |
| 159 | typedef struct xfs_bmbt_irec |
| 160 | { |
| 161 | xfs_fileoff_t br_startoff; /* starting file offset */ |
| 162 | xfs_fsblock_t br_startblock; /* starting block number */ |
| 163 | xfs_filblks_t br_blockcount; /* number of blocks */ |
| 164 | xfs_exntst_t br_state; /* extent state */ |
| 165 | } xfs_bmbt_irec_t; |
| 166 | |
| 167 | /* |
| 168 | * Key structure for non-leaf levels of the tree. |
| 169 | */ |
Christoph Hellwig | 8801bb9 | 2006-09-28 10:58:17 +1000 | [diff] [blame] | 170 | typedef struct xfs_bmbt_key { |
| 171 | __be64 br_startoff; /* starting file offset */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | } xfs_bmbt_key_t, xfs_bmdr_key_t; |
| 173 | |
Christoph Hellwig | 397b520 | 2006-09-28 10:57:52 +1000 | [diff] [blame] | 174 | /* btree pointer type */ |
| 175 | typedef __be64 xfs_bmbt_ptr_t, xfs_bmdr_ptr_t; |
| 176 | |
| 177 | /* btree block header type */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | typedef struct xfs_btree_lblock xfs_bmbt_block_t; |
| 179 | |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 180 | #define XFS_BUF_TO_BMBT_BLOCK(bp) ((xfs_bmbt_block_t *)XFS_BUF_PTR(bp)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 182 | #define XFS_BMAP_RBLOCK_DSIZE(lev,cur) ((cur)->bc_private.b.forksize) |
| 183 | #define XFS_BMAP_RBLOCK_ISIZE(lev,cur) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | ((int)XFS_IFORK_PTR((cur)->bc_private.b.ip, \ |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 185 | (cur)->bc_private.b.whichfork)->if_broot_bytes) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | #define XFS_BMAP_BLOCK_DMAXRECS(lev,cur) \ |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 188 | (((lev) == (cur)->bc_nlevels - 1 ? \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | XFS_BTREE_BLOCK_MAXRECS(XFS_BMAP_RBLOCK_DSIZE(lev,cur), \ |
| 190 | xfs_bmdr, (lev) == 0) : \ |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 191 | ((cur)->bc_mp->m_bmap_dmxr[(lev) != 0]))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | #define XFS_BMAP_BLOCK_IMAXRECS(lev,cur) \ |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 193 | (((lev) == (cur)->bc_nlevels - 1 ? \ |
| 194 | XFS_BTREE_BLOCK_MAXRECS(XFS_BMAP_RBLOCK_ISIZE(lev,cur),\ |
| 195 | xfs_bmbt, (lev) == 0) : \ |
| 196 | ((cur)->bc_mp->m_bmap_dmxr[(lev) != 0]))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | #define XFS_BMAP_BLOCK_DMINRECS(lev,cur) \ |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 199 | (((lev) == (cur)->bc_nlevels - 1 ? \ |
| 200 | XFS_BTREE_BLOCK_MINRECS(XFS_BMAP_RBLOCK_DSIZE(lev,cur),\ |
| 201 | xfs_bmdr, (lev) == 0) : \ |
| 202 | ((cur)->bc_mp->m_bmap_dmnr[(lev) != 0]))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | #define XFS_BMAP_BLOCK_IMINRECS(lev,cur) \ |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 204 | (((lev) == (cur)->bc_nlevels - 1 ? \ |
| 205 | XFS_BTREE_BLOCK_MINRECS(XFS_BMAP_RBLOCK_ISIZE(lev,cur),\ |
| 206 | xfs_bmbt, (lev) == 0) : \ |
| 207 | ((cur)->bc_mp->m_bmap_dmnr[(lev) != 0]))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | |
Eric Sandeen | 2c36dde | 2007-02-10 18:37:33 +1100 | [diff] [blame] | 209 | #define XFS_BMAP_REC_DADDR(bb,i,cur) (XFS_BTREE_REC_ADDR(xfs_bmbt, bb, i)) |
| 210 | |
| 211 | #define XFS_BMAP_REC_IADDR(bb,i,cur) (XFS_BTREE_REC_ADDR(xfs_bmbt, bb, i)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 213 | #define XFS_BMAP_KEY_DADDR(bb,i,cur) \ |
Eric Sandeen | 2c36dde | 2007-02-10 18:37:33 +1100 | [diff] [blame] | 214 | (XFS_BTREE_KEY_ADDR(xfs_bmbt, bb, i)) |
| 215 | |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 216 | #define XFS_BMAP_KEY_IADDR(bb,i,cur) \ |
Eric Sandeen | 2c36dde | 2007-02-10 18:37:33 +1100 | [diff] [blame] | 217 | (XFS_BTREE_KEY_ADDR(xfs_bmbt, bb, i)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 219 | #define XFS_BMAP_PTR_DADDR(bb,i,cur) \ |
Eric Sandeen | 2c36dde | 2007-02-10 18:37:33 +1100 | [diff] [blame] | 220 | (XFS_BTREE_PTR_ADDR(xfs_bmbt, bb, i, XFS_BMAP_BLOCK_DMAXRECS( \ |
Christoph Hellwig | 16259e7 | 2005-11-02 15:11:25 +1100 | [diff] [blame] | 221 | be16_to_cpu((bb)->bb_level), cur))) |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 222 | #define XFS_BMAP_PTR_IADDR(bb,i,cur) \ |
Eric Sandeen | 2c36dde | 2007-02-10 18:37:33 +1100 | [diff] [blame] | 223 | (XFS_BTREE_PTR_ADDR(xfs_bmbt, bb, i, XFS_BMAP_BLOCK_IMAXRECS( \ |
Christoph Hellwig | 16259e7 | 2005-11-02 15:11:25 +1100 | [diff] [blame] | 224 | be16_to_cpu((bb)->bb_level), cur))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | |
| 226 | /* |
| 227 | * These are to be used when we know the size of the block and |
| 228 | * we don't have a cursor. |
| 229 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | #define XFS_BMAP_BROOT_REC_ADDR(bb,i,sz) \ |
Eric Sandeen | 2c36dde | 2007-02-10 18:37:33 +1100 | [diff] [blame] | 231 | (XFS_BTREE_REC_ADDR(xfs_bmbt,bb,i)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | #define XFS_BMAP_BROOT_KEY_ADDR(bb,i,sz) \ |
Eric Sandeen | 2c36dde | 2007-02-10 18:37:33 +1100 | [diff] [blame] | 233 | (XFS_BTREE_KEY_ADDR(xfs_bmbt,bb,i)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | #define XFS_BMAP_BROOT_PTR_ADDR(bb,i,sz) \ |
Eric Sandeen | 2c36dde | 2007-02-10 18:37:33 +1100 | [diff] [blame] | 235 | (XFS_BTREE_PTR_ADDR(xfs_bmbt,bb,i,XFS_BMAP_BROOT_MAXRECS(sz))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | |
Christoph Hellwig | 16259e7 | 2005-11-02 15:11:25 +1100 | [diff] [blame] | 237 | #define XFS_BMAP_BROOT_NUMRECS(bb) be16_to_cpu((bb)->bb_numrecs) |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 238 | #define XFS_BMAP_BROOT_MAXRECS(sz) XFS_BTREE_BLOCK_MAXRECS(sz,xfs_bmbt,0) |
| 239 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | #define XFS_BMAP_BROOT_SPACE_CALC(nrecs) \ |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 241 | (int)(sizeof(xfs_bmbt_block_t) + \ |
| 242 | ((nrecs) * (sizeof(xfs_bmbt_key_t) + sizeof(xfs_bmbt_ptr_t)))) |
| 243 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | #define XFS_BMAP_BROOT_SPACE(bb) \ |
Christoph Hellwig | 16259e7 | 2005-11-02 15:11:25 +1100 | [diff] [blame] | 245 | (XFS_BMAP_BROOT_SPACE_CALC(be16_to_cpu((bb)->bb_numrecs))) |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 246 | #define XFS_BMDR_SPACE_CALC(nrecs) \ |
| 247 | (int)(sizeof(xfs_bmdr_block_t) + \ |
| 248 | ((nrecs) * (sizeof(xfs_bmbt_key_t) + sizeof(xfs_bmbt_ptr_t)))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | |
| 250 | /* |
| 251 | * Maximum number of bmap btree levels. |
| 252 | */ |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 253 | #define XFS_BM_MAXLEVELS(mp,w) ((mp)->m_bm_maxlevels[(w)]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 255 | #define XFS_BMAP_SANITY_CHECK(mp,bb,level) \ |
Christoph Hellwig | 16259e7 | 2005-11-02 15:11:25 +1100 | [diff] [blame] | 256 | (be32_to_cpu((bb)->bb_magic) == XFS_BMAP_MAGIC && \ |
| 257 | be16_to_cpu((bb)->bb_level) == level && \ |
| 258 | be16_to_cpu((bb)->bb_numrecs) > 0 && \ |
| 259 | be16_to_cpu((bb)->bb_numrecs) <= (mp)->m_bmap_dmxr[(level) != 0]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | |
| 261 | |
| 262 | #ifdef __KERNEL__ |
| 263 | |
| 264 | #if defined(XFS_BMBT_TRACE) |
| 265 | /* |
| 266 | * Trace buffer entry types. |
| 267 | */ |
| 268 | #define XFS_BMBT_KTRACE_ARGBI 1 |
| 269 | #define XFS_BMBT_KTRACE_ARGBII 2 |
| 270 | #define XFS_BMBT_KTRACE_ARGFFFI 3 |
| 271 | #define XFS_BMBT_KTRACE_ARGI 4 |
| 272 | #define XFS_BMBT_KTRACE_ARGIFK 5 |
| 273 | #define XFS_BMBT_KTRACE_ARGIFR 6 |
| 274 | #define XFS_BMBT_KTRACE_ARGIK 7 |
| 275 | #define XFS_BMBT_KTRACE_CUR 8 |
| 276 | |
| 277 | #define XFS_BMBT_TRACE_SIZE 4096 /* size of global trace buffer */ |
| 278 | #define XFS_BMBT_KTRACE_SIZE 32 /* size of per-inode trace buffer */ |
| 279 | extern ktrace_t *xfs_bmbt_trace_buf; |
| 280 | #endif |
| 281 | |
| 282 | /* |
| 283 | * Prototypes for xfs_bmap.c to call. |
| 284 | */ |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 285 | extern void xfs_bmdr_to_bmbt(xfs_bmdr_block_t *, int, xfs_bmbt_block_t *, int); |
| 286 | extern int xfs_bmbt_decrement(struct xfs_btree_cur *, int, int *); |
| 287 | extern int xfs_bmbt_delete(struct xfs_btree_cur *, int *); |
Christoph Hellwig | a6f64d4 | 2007-08-16 16:23:40 +1000 | [diff] [blame^] | 288 | extern void xfs_bmbt_get_all(xfs_bmbt_rec_host_t *r, xfs_bmbt_irec_t *s); |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 289 | extern xfs_bmbt_block_t *xfs_bmbt_get_block(struct xfs_btree_cur *cur, |
| 290 | int, struct xfs_buf **bpp); |
Christoph Hellwig | a6f64d4 | 2007-08-16 16:23:40 +1000 | [diff] [blame^] | 291 | extern xfs_filblks_t xfs_bmbt_get_blockcount(xfs_bmbt_rec_host_t *r); |
| 292 | extern xfs_fsblock_t xfs_bmbt_get_startblock(xfs_bmbt_rec_host_t *r); |
| 293 | extern xfs_fileoff_t xfs_bmbt_get_startoff(xfs_bmbt_rec_host_t *r); |
| 294 | extern xfs_exntst_t xfs_bmbt_get_state(xfs_bmbt_rec_host_t *r); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | |
Nathan Scott | f016bad | 2005-09-08 15:30:05 +1000 | [diff] [blame] | 296 | #ifndef XFS_NATIVE_HOST |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 297 | extern void xfs_bmbt_disk_get_all(xfs_bmbt_rec_t *r, xfs_bmbt_irec_t *s); |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 298 | extern xfs_filblks_t xfs_bmbt_disk_get_blockcount(xfs_bmbt_rec_t *r); |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 299 | extern xfs_fileoff_t xfs_bmbt_disk_get_startoff(xfs_bmbt_rec_t *r); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | #else |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 301 | #define xfs_bmbt_disk_get_all(r, s) xfs_bmbt_get_all(r, s) |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 302 | #define xfs_bmbt_disk_get_blockcount(r) xfs_bmbt_get_blockcount(r) |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 303 | #define xfs_bmbt_disk_get_startoff(r) xfs_bmbt_get_startoff(r) |
Nathan Scott | f016bad | 2005-09-08 15:30:05 +1000 | [diff] [blame] | 304 | #endif /* XFS_NATIVE_HOST */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 306 | extern int xfs_bmbt_increment(struct xfs_btree_cur *, int, int *); |
| 307 | extern int xfs_bmbt_insert(struct xfs_btree_cur *, int *); |
| 308 | extern void xfs_bmbt_log_block(struct xfs_btree_cur *, struct xfs_buf *, int); |
| 309 | extern void xfs_bmbt_log_recs(struct xfs_btree_cur *, struct xfs_buf *, int, |
| 310 | int); |
| 311 | extern int xfs_bmbt_lookup_eq(struct xfs_btree_cur *, xfs_fileoff_t, |
| 312 | xfs_fsblock_t, xfs_filblks_t, int *); |
| 313 | extern int xfs_bmbt_lookup_ge(struct xfs_btree_cur *, xfs_fileoff_t, |
| 314 | xfs_fsblock_t, xfs_filblks_t, int *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | /* |
| 317 | * Give the bmap btree a new root block. Copy the old broot contents |
| 318 | * down into a real block and make the broot point to it. |
| 319 | */ |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 320 | extern int xfs_bmbt_newroot(struct xfs_btree_cur *cur, int *lflags, int *stat); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | |
Christoph Hellwig | a6f64d4 | 2007-08-16 16:23:40 +1000 | [diff] [blame^] | 322 | extern void xfs_bmbt_set_all(xfs_bmbt_rec_host_t *r, xfs_bmbt_irec_t *s); |
| 323 | extern void xfs_bmbt_set_allf(xfs_bmbt_rec_host_t *r, xfs_fileoff_t o, |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 324 | xfs_fsblock_t b, xfs_filblks_t c, xfs_exntst_t v); |
Christoph Hellwig | a6f64d4 | 2007-08-16 16:23:40 +1000 | [diff] [blame^] | 325 | extern void xfs_bmbt_set_blockcount(xfs_bmbt_rec_host_t *r, xfs_filblks_t v); |
| 326 | extern void xfs_bmbt_set_startblock(xfs_bmbt_rec_host_t *r, xfs_fsblock_t v); |
| 327 | extern void xfs_bmbt_set_startoff(xfs_bmbt_rec_host_t *r, xfs_fileoff_t v); |
| 328 | extern void xfs_bmbt_set_state(xfs_bmbt_rec_host_t *r, xfs_exntst_t v); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | |
Nathan Scott | f016bad | 2005-09-08 15:30:05 +1000 | [diff] [blame] | 330 | #ifndef XFS_NATIVE_HOST |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 331 | extern void xfs_bmbt_disk_set_all(xfs_bmbt_rec_t *r, xfs_bmbt_irec_t *s); |
| 332 | extern void xfs_bmbt_disk_set_allf(xfs_bmbt_rec_t *r, xfs_fileoff_t o, |
| 333 | xfs_fsblock_t b, xfs_filblks_t c, xfs_exntst_t v); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | #else |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 335 | #define xfs_bmbt_disk_set_all(r, s) xfs_bmbt_set_all(r, s) |
| 336 | #define xfs_bmbt_disk_set_allf(r, o, b, c, v) xfs_bmbt_set_allf(r, o, b, c, v) |
Nathan Scott | f016bad | 2005-09-08 15:30:05 +1000 | [diff] [blame] | 337 | #endif /* XFS_NATIVE_HOST */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 339 | extern void xfs_bmbt_to_bmdr(xfs_bmbt_block_t *, int, xfs_bmdr_block_t *, int); |
| 340 | extern int xfs_bmbt_update(struct xfs_btree_cur *, xfs_fileoff_t, |
| 341 | xfs_fsblock_t, xfs_filblks_t, xfs_exntst_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | #endif /* __KERNEL__ */ |
| 344 | |
| 345 | #endif /* __XFS_BMAP_BTREE_H__ */ |