blob: 49539de9525bc7aa71f93b553b734497c22748fb [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Nathan Scott7b718762005-11-02 14:58:39 +11002 * Copyright (c) 2000,2002-2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Nathan Scott7b718762005-11-02 14:58:39 +11005 * 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 Torvalds1da177e2005-04-16 15:20:36 -07007 * published by the Free Software Foundation.
8 *
Nathan Scott7b718762005-11-02 14:58:39 +11009 * 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 Torvalds1da177e2005-04-16 15:20:36 -070013 *
Nathan Scott7b718762005-11-02 14:58:39 +110014 * 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 Torvalds1da177e2005-04-16 15:20:36 -070017 */
18#ifndef __XFS_BMAP_BTREE_H__
19#define __XFS_BMAP_BTREE_H__
20
21#define XFS_BMAP_MAGIC 0x424d4150 /* 'BMAP' */
22
23struct xfs_btree_cur;
24struct xfs_btree_lblock;
25struct xfs_mount;
26struct xfs_inode;
27
28/*
29 * Bmap root header, on-disk form only.
30 */
Christoph Hellwig16259e72005-11-02 15:11:25 +110031typedef struct xfs_bmdr_block {
32 __be16 bb_level; /* 0 is a leaf */
33 __be16 bb_numrecs; /* current # of data records */
Linus Torvalds1da177e2005-04-16 15:20:36 -070034} 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 Scottf016bad2005-09-08 15:30:05 +100050#ifndef XFS_NATIVE_HOST
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
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 Scottf016bad2005-09-08 15:30:05 +100075#endif /* XFS_NATIVE_HOST */
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
77
78#define BMBT_USE_64 1
79
80typedef struct xfs_bmbt_rec_32
81{
82 __uint32_t l0, l1, l2, l3;
83} xfs_bmbt_rec_32_t;
84typedef struct xfs_bmbt_rec_64
85{
86 __uint64_t l0, l1;
87} xfs_bmbt_rec_64_t;
88
89typedef __uint64_t xfs_bmbt_rec_base_t; /* use this for casts */
90typedef xfs_bmbt_rec_64_t xfs_bmbt_rec_t, xfs_bmdr_rec_t;
91
92/*
93 * Values and macros for delayed-allocation startblock fields.
94 */
95#define STARTBLOCKVALBITS 17
96#define STARTBLOCKMASKBITS (15 + XFS_BIG_BLKNOS * 20)
97#define DSTARTBLOCKMASKBITS (15 + 20)
98#define STARTBLOCKMASK \
99 (((((xfs_fsblock_t)1) << STARTBLOCKMASKBITS) - 1) << STARTBLOCKVALBITS)
100#define DSTARTBLOCKMASK \
101 (((((xfs_dfsbno_t)1) << DSTARTBLOCKMASKBITS) - 1) << STARTBLOCKVALBITS)
Nathan Scotta844f452005-11-02 14:38:42 +1100102
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103#define ISNULLSTARTBLOCK(x) isnullstartblock(x)
Nathan Scotta844f452005-11-02 14:38:42 +1100104static inline int isnullstartblock(xfs_fsblock_t x)
105{
106 return ((x) & STARTBLOCKMASK) == STARTBLOCKMASK;
107}
108
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109#define ISNULLDSTARTBLOCK(x) isnulldstartblock(x)
Nathan Scotta844f452005-11-02 14:38:42 +1100110static inline int isnulldstartblock(xfs_dfsbno_t x)
111{
112 return ((x) & DSTARTBLOCKMASK) == DSTARTBLOCKMASK;
113}
114
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115#define NULLSTARTBLOCK(k) nullstartblock(k)
Nathan Scotta844f452005-11-02 14:38:42 +1100116static inline xfs_fsblock_t nullstartblock(int k)
117{
118 ASSERT(k < (1 << STARTBLOCKVALBITS));
119 return STARTBLOCKMASK | (k);
120}
121
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122#define STARTBLOCKVAL(x) startblockval(x)
Nathan Scotta844f452005-11-02 14:38:42 +1100123static inline xfs_filblks_t startblockval(xfs_fsblock_t x)
124{
125 return (xfs_filblks_t)((x) & ~STARTBLOCKMASK);
126}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
128/*
129 * Possible extent formats.
130 */
131typedef enum {
132 XFS_EXTFMT_NOSTATE = 0,
133 XFS_EXTFMT_HASSTATE
134} xfs_exntfmt_t;
135
136/*
137 * Possible extent states.
138 */
139typedef enum {
140 XFS_EXT_NORM, XFS_EXT_UNWRITTEN,
141 XFS_EXT_DMAPI_OFFLINE, XFS_EXT_INVALID
142} xfs_exntst_t;
143
144/*
145 * Extent state and extent format macros.
146 */
Nathan Scotta844f452005-11-02 14:38:42 +1100147#define XFS_EXTFMT_INODE(x) \
148 (XFS_SB_VERSION_HASEXTFLGBIT(&((x)->i_mount->m_sb)) ? \
149 XFS_EXTFMT_HASSTATE : XFS_EXTFMT_NOSTATE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150#define ISUNWRITTEN(x) ((x)->br_state == XFS_EXT_UNWRITTEN)
151
152/*
153 * Incore version of above.
154 */
155typedef struct xfs_bmbt_irec
156{
157 xfs_fileoff_t br_startoff; /* starting file offset */
158 xfs_fsblock_t br_startblock; /* starting block number */
159 xfs_filblks_t br_blockcount; /* number of blocks */
160 xfs_exntst_t br_state; /* extent state */
161} xfs_bmbt_irec_t;
162
163/*
164 * Key structure for non-leaf levels of the tree.
165 */
Christoph Hellwig8801bb92006-09-28 10:58:17 +1000166typedef struct xfs_bmbt_key {
167 __be64 br_startoff; /* starting file offset */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168} xfs_bmbt_key_t, xfs_bmdr_key_t;
169
Christoph Hellwig397b5202006-09-28 10:57:52 +1000170/* btree pointer type */
171typedef __be64 xfs_bmbt_ptr_t, xfs_bmdr_ptr_t;
172
173/* btree block header type */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174typedef struct xfs_btree_lblock xfs_bmbt_block_t;
175
Nathan Scotta844f452005-11-02 14:38:42 +1100176#define XFS_BUF_TO_BMBT_BLOCK(bp) ((xfs_bmbt_block_t *)XFS_BUF_PTR(bp))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
Nathan Scotta844f452005-11-02 14:38:42 +1100178#define XFS_BMAP_IBLOCK_SIZE(lev,cur) (1 << (cur)->bc_blocklog)
179#define XFS_BMAP_RBLOCK_DSIZE(lev,cur) ((cur)->bc_private.b.forksize)
180#define XFS_BMAP_RBLOCK_ISIZE(lev,cur) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 ((int)XFS_IFORK_PTR((cur)->bc_private.b.ip, \
Nathan Scotta844f452005-11-02 14:38:42 +1100182 (cur)->bc_private.b.whichfork)->if_broot_bytes)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183
Nathan Scotta844f452005-11-02 14:38:42 +1100184#define XFS_BMAP_BLOCK_DSIZE(lev,cur) \
185 (((lev) == (cur)->bc_nlevels - 1 ? \
186 XFS_BMAP_RBLOCK_DSIZE(lev,cur) : XFS_BMAP_IBLOCK_SIZE(lev,cur)))
187#define XFS_BMAP_BLOCK_ISIZE(lev,cur) \
188 (((lev) == (cur)->bc_nlevels - 1 ? \
189 XFS_BMAP_RBLOCK_ISIZE(lev,cur) : XFS_BMAP_IBLOCK_SIZE(lev,cur)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191#define XFS_BMAP_BLOCK_DMAXRECS(lev,cur) \
Nathan Scotta844f452005-11-02 14:38:42 +1100192 (((lev) == (cur)->bc_nlevels - 1 ? \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 XFS_BTREE_BLOCK_MAXRECS(XFS_BMAP_RBLOCK_DSIZE(lev,cur), \
194 xfs_bmdr, (lev) == 0) : \
Nathan Scotta844f452005-11-02 14:38:42 +1100195 ((cur)->bc_mp->m_bmap_dmxr[(lev) != 0])))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196#define XFS_BMAP_BLOCK_IMAXRECS(lev,cur) \
Nathan Scotta844f452005-11-02 14:38:42 +1100197 (((lev) == (cur)->bc_nlevels - 1 ? \
198 XFS_BTREE_BLOCK_MAXRECS(XFS_BMAP_RBLOCK_ISIZE(lev,cur),\
199 xfs_bmbt, (lev) == 0) : \
200 ((cur)->bc_mp->m_bmap_dmxr[(lev) != 0])))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202#define XFS_BMAP_BLOCK_DMINRECS(lev,cur) \
Nathan Scotta844f452005-11-02 14:38:42 +1100203 (((lev) == (cur)->bc_nlevels - 1 ? \
204 XFS_BTREE_BLOCK_MINRECS(XFS_BMAP_RBLOCK_DSIZE(lev,cur),\
205 xfs_bmdr, (lev) == 0) : \
206 ((cur)->bc_mp->m_bmap_dmnr[(lev) != 0])))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207#define XFS_BMAP_BLOCK_IMINRECS(lev,cur) \
Nathan Scotta844f452005-11-02 14:38:42 +1100208 (((lev) == (cur)->bc_nlevels - 1 ? \
209 XFS_BTREE_BLOCK_MINRECS(XFS_BMAP_RBLOCK_ISIZE(lev,cur),\
210 xfs_bmbt, (lev) == 0) : \
211 ((cur)->bc_mp->m_bmap_dmnr[(lev) != 0])))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212
Nathan Scotta844f452005-11-02 14:38:42 +1100213#define XFS_BMAP_REC_DADDR(bb,i,cur) \
214 (XFS_BTREE_REC_ADDR(XFS_BMAP_BLOCK_DSIZE( \
Christoph Hellwig16259e72005-11-02 15:11:25 +1100215 be16_to_cpu((bb)->bb_level), cur), \
Nathan Scotta844f452005-11-02 14:38:42 +1100216 xfs_bmbt, bb, i, XFS_BMAP_BLOCK_DMAXRECS( \
Christoph Hellwig16259e72005-11-02 15:11:25 +1100217 be16_to_cpu((bb)->bb_level), cur)))
Nathan Scotta844f452005-11-02 14:38:42 +1100218#define XFS_BMAP_REC_IADDR(bb,i,cur) \
219 (XFS_BTREE_REC_ADDR(XFS_BMAP_BLOCK_ISIZE( \
Christoph Hellwig16259e72005-11-02 15:11:25 +1100220 be16_to_cpu((bb)->bb_level), cur), \
Nathan Scotta844f452005-11-02 14:38:42 +1100221 xfs_bmbt, bb, i, XFS_BMAP_BLOCK_IMAXRECS( \
Christoph Hellwig16259e72005-11-02 15:11:25 +1100222 be16_to_cpu((bb)->bb_level), cur)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223
Nathan Scotta844f452005-11-02 14:38:42 +1100224#define XFS_BMAP_KEY_DADDR(bb,i,cur) \
225 (XFS_BTREE_KEY_ADDR(XFS_BMAP_BLOCK_DSIZE( \
Christoph Hellwig16259e72005-11-02 15:11:25 +1100226 be16_to_cpu((bb)->bb_level), cur), \
Nathan Scotta844f452005-11-02 14:38:42 +1100227 xfs_bmbt, bb, i, XFS_BMAP_BLOCK_DMAXRECS( \
Christoph Hellwig16259e72005-11-02 15:11:25 +1100228 be16_to_cpu((bb)->bb_level), cur)))
Nathan Scotta844f452005-11-02 14:38:42 +1100229#define XFS_BMAP_KEY_IADDR(bb,i,cur) \
230 (XFS_BTREE_KEY_ADDR(XFS_BMAP_BLOCK_ISIZE( \
Christoph Hellwig16259e72005-11-02 15:11:25 +1100231 be16_to_cpu((bb)->bb_level), cur), \
Nathan Scotta844f452005-11-02 14:38:42 +1100232 xfs_bmbt, bb, i, XFS_BMAP_BLOCK_IMAXRECS( \
Christoph Hellwig16259e72005-11-02 15:11:25 +1100233 be16_to_cpu((bb)->bb_level), cur)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234
Nathan Scotta844f452005-11-02 14:38:42 +1100235#define XFS_BMAP_PTR_DADDR(bb,i,cur) \
236 (XFS_BTREE_PTR_ADDR(XFS_BMAP_BLOCK_DSIZE( \
Christoph Hellwig16259e72005-11-02 15:11:25 +1100237 be16_to_cpu((bb)->bb_level), cur), \
Nathan Scotta844f452005-11-02 14:38:42 +1100238 xfs_bmbt, bb, i, XFS_BMAP_BLOCK_DMAXRECS( \
Christoph Hellwig16259e72005-11-02 15:11:25 +1100239 be16_to_cpu((bb)->bb_level), cur)))
Nathan Scotta844f452005-11-02 14:38:42 +1100240#define XFS_BMAP_PTR_IADDR(bb,i,cur) \
241 (XFS_BTREE_PTR_ADDR(XFS_BMAP_BLOCK_ISIZE( \
Christoph Hellwig16259e72005-11-02 15:11:25 +1100242 be16_to_cpu((bb)->bb_level), cur), \
Nathan Scotta844f452005-11-02 14:38:42 +1100243 xfs_bmbt, bb, i, XFS_BMAP_BLOCK_IMAXRECS( \
Christoph Hellwig16259e72005-11-02 15:11:25 +1100244 be16_to_cpu((bb)->bb_level), cur)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245
246/*
247 * These are to be used when we know the size of the block and
248 * we don't have a cursor.
249 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250#define XFS_BMAP_BROOT_REC_ADDR(bb,i,sz) \
Nathan Scotta844f452005-11-02 14:38:42 +1100251 (XFS_BTREE_REC_ADDR(sz,xfs_bmbt,bb,i,XFS_BMAP_BROOT_MAXRECS(sz)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252#define XFS_BMAP_BROOT_KEY_ADDR(bb,i,sz) \
Nathan Scotta844f452005-11-02 14:38:42 +1100253 (XFS_BTREE_KEY_ADDR(sz,xfs_bmbt,bb,i,XFS_BMAP_BROOT_MAXRECS(sz)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254#define XFS_BMAP_BROOT_PTR_ADDR(bb,i,sz) \
Nathan Scotta844f452005-11-02 14:38:42 +1100255 (XFS_BTREE_PTR_ADDR(sz,xfs_bmbt,bb,i,XFS_BMAP_BROOT_MAXRECS(sz)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256
Christoph Hellwig16259e72005-11-02 15:11:25 +1100257#define XFS_BMAP_BROOT_NUMRECS(bb) be16_to_cpu((bb)->bb_numrecs)
Nathan Scotta844f452005-11-02 14:38:42 +1100258#define XFS_BMAP_BROOT_MAXRECS(sz) XFS_BTREE_BLOCK_MAXRECS(sz,xfs_bmbt,0)
259
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260#define XFS_BMAP_BROOT_SPACE_CALC(nrecs) \
Nathan Scotta844f452005-11-02 14:38:42 +1100261 (int)(sizeof(xfs_bmbt_block_t) + \
262 ((nrecs) * (sizeof(xfs_bmbt_key_t) + sizeof(xfs_bmbt_ptr_t))))
263
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264#define XFS_BMAP_BROOT_SPACE(bb) \
Christoph Hellwig16259e72005-11-02 15:11:25 +1100265 (XFS_BMAP_BROOT_SPACE_CALC(be16_to_cpu((bb)->bb_numrecs)))
Nathan Scotta844f452005-11-02 14:38:42 +1100266#define XFS_BMDR_SPACE_CALC(nrecs) \
267 (int)(sizeof(xfs_bmdr_block_t) + \
268 ((nrecs) * (sizeof(xfs_bmbt_key_t) + sizeof(xfs_bmbt_ptr_t))))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
270/*
271 * Maximum number of bmap btree levels.
272 */
Nathan Scotta844f452005-11-02 14:38:42 +1100273#define XFS_BM_MAXLEVELS(mp,w) ((mp)->m_bm_maxlevels[(w)])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274
Nathan Scotta844f452005-11-02 14:38:42 +1100275#define XFS_BMAP_SANITY_CHECK(mp,bb,level) \
Christoph Hellwig16259e72005-11-02 15:11:25 +1100276 (be32_to_cpu((bb)->bb_magic) == XFS_BMAP_MAGIC && \
277 be16_to_cpu((bb)->bb_level) == level && \
278 be16_to_cpu((bb)->bb_numrecs) > 0 && \
279 be16_to_cpu((bb)->bb_numrecs) <= (mp)->m_bmap_dmxr[(level) != 0])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280
281
282#ifdef __KERNEL__
283
284#if defined(XFS_BMBT_TRACE)
285/*
286 * Trace buffer entry types.
287 */
288#define XFS_BMBT_KTRACE_ARGBI 1
289#define XFS_BMBT_KTRACE_ARGBII 2
290#define XFS_BMBT_KTRACE_ARGFFFI 3
291#define XFS_BMBT_KTRACE_ARGI 4
292#define XFS_BMBT_KTRACE_ARGIFK 5
293#define XFS_BMBT_KTRACE_ARGIFR 6
294#define XFS_BMBT_KTRACE_ARGIK 7
295#define XFS_BMBT_KTRACE_CUR 8
296
297#define XFS_BMBT_TRACE_SIZE 4096 /* size of global trace buffer */
298#define XFS_BMBT_KTRACE_SIZE 32 /* size of per-inode trace buffer */
299extern ktrace_t *xfs_bmbt_trace_buf;
300#endif
301
302/*
303 * Prototypes for xfs_bmap.c to call.
304 */
Nathan Scotta844f452005-11-02 14:38:42 +1100305extern void xfs_bmdr_to_bmbt(xfs_bmdr_block_t *, int, xfs_bmbt_block_t *, int);
306extern int xfs_bmbt_decrement(struct xfs_btree_cur *, int, int *);
307extern int xfs_bmbt_delete(struct xfs_btree_cur *, int *);
308extern void xfs_bmbt_get_all(xfs_bmbt_rec_t *r, xfs_bmbt_irec_t *s);
309extern xfs_bmbt_block_t *xfs_bmbt_get_block(struct xfs_btree_cur *cur,
310 int, struct xfs_buf **bpp);
311extern xfs_filblks_t xfs_bmbt_get_blockcount(xfs_bmbt_rec_t *r);
312extern xfs_fsblock_t xfs_bmbt_get_startblock(xfs_bmbt_rec_t *r);
313extern xfs_fileoff_t xfs_bmbt_get_startoff(xfs_bmbt_rec_t *r);
314extern xfs_exntst_t xfs_bmbt_get_state(xfs_bmbt_rec_t *r);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315
Nathan Scottf016bad2005-09-08 15:30:05 +1000316#ifndef XFS_NATIVE_HOST
Nathan Scotta844f452005-11-02 14:38:42 +1100317extern void xfs_bmbt_disk_get_all(xfs_bmbt_rec_t *r, xfs_bmbt_irec_t *s);
318extern xfs_exntst_t xfs_bmbt_disk_get_state(xfs_bmbt_rec_t *r);
319extern xfs_filblks_t xfs_bmbt_disk_get_blockcount(xfs_bmbt_rec_t *r);
320extern xfs_fsblock_t xfs_bmbt_disk_get_startblock(xfs_bmbt_rec_t *r);
321extern xfs_fileoff_t xfs_bmbt_disk_get_startoff(xfs_bmbt_rec_t *r);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322#else
Nathan Scotta844f452005-11-02 14:38:42 +1100323#define xfs_bmbt_disk_get_all(r, s) xfs_bmbt_get_all(r, s)
324#define xfs_bmbt_disk_get_state(r) xfs_bmbt_get_state(r)
325#define xfs_bmbt_disk_get_blockcount(r) xfs_bmbt_get_blockcount(r)
326#define xfs_bmbt_disk_get_startblock(r) xfs_bmbt_get_blockcount(r)
327#define xfs_bmbt_disk_get_startoff(r) xfs_bmbt_get_startoff(r)
Nathan Scottf016bad2005-09-08 15:30:05 +1000328#endif /* XFS_NATIVE_HOST */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329
Nathan Scotta844f452005-11-02 14:38:42 +1100330extern int xfs_bmbt_increment(struct xfs_btree_cur *, int, int *);
331extern int xfs_bmbt_insert(struct xfs_btree_cur *, int *);
332extern void xfs_bmbt_log_block(struct xfs_btree_cur *, struct xfs_buf *, int);
333extern void xfs_bmbt_log_recs(struct xfs_btree_cur *, struct xfs_buf *, int,
334 int);
335extern int xfs_bmbt_lookup_eq(struct xfs_btree_cur *, xfs_fileoff_t,
336 xfs_fsblock_t, xfs_filblks_t, int *);
337extern int xfs_bmbt_lookup_ge(struct xfs_btree_cur *, xfs_fileoff_t,
338 xfs_fsblock_t, xfs_filblks_t, int *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340/*
341 * Give the bmap btree a new root block. Copy the old broot contents
342 * down into a real block and make the broot point to it.
343 */
Nathan Scotta844f452005-11-02 14:38:42 +1100344extern int xfs_bmbt_newroot(struct xfs_btree_cur *cur, int *lflags, int *stat);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345
Nathan Scotta844f452005-11-02 14:38:42 +1100346extern void xfs_bmbt_set_all(xfs_bmbt_rec_t *r, xfs_bmbt_irec_t *s);
347extern void xfs_bmbt_set_allf(xfs_bmbt_rec_t *r, xfs_fileoff_t o,
348 xfs_fsblock_t b, xfs_filblks_t c, xfs_exntst_t v);
349extern void xfs_bmbt_set_blockcount(xfs_bmbt_rec_t *r, xfs_filblks_t v);
350extern void xfs_bmbt_set_startblock(xfs_bmbt_rec_t *r, xfs_fsblock_t v);
351extern void xfs_bmbt_set_startoff(xfs_bmbt_rec_t *r, xfs_fileoff_t v);
352extern void xfs_bmbt_set_state(xfs_bmbt_rec_t *r, xfs_exntst_t v);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353
Nathan Scottf016bad2005-09-08 15:30:05 +1000354#ifndef XFS_NATIVE_HOST
Nathan Scotta844f452005-11-02 14:38:42 +1100355extern void xfs_bmbt_disk_set_all(xfs_bmbt_rec_t *r, xfs_bmbt_irec_t *s);
356extern void xfs_bmbt_disk_set_allf(xfs_bmbt_rec_t *r, xfs_fileoff_t o,
357 xfs_fsblock_t b, xfs_filblks_t c, xfs_exntst_t v);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358#else
Nathan Scotta844f452005-11-02 14:38:42 +1100359#define xfs_bmbt_disk_set_all(r, s) xfs_bmbt_set_all(r, s)
360#define xfs_bmbt_disk_set_allf(r, o, b, c, v) xfs_bmbt_set_allf(r, o, b, c, v)
Nathan Scottf016bad2005-09-08 15:30:05 +1000361#endif /* XFS_NATIVE_HOST */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362
Nathan Scotta844f452005-11-02 14:38:42 +1100363extern void xfs_bmbt_to_bmdr(xfs_bmbt_block_t *, int, xfs_bmdr_block_t *, int);
364extern int xfs_bmbt_update(struct xfs_btree_cur *, xfs_fileoff_t,
365 xfs_fsblock_t, xfs_filblks_t, xfs_exntst_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
367#ifdef DEBUG
368/*
369 * Get the data from the pointed-to record.
370 */
Nathan Scotta844f452005-11-02 14:38:42 +1100371extern int xfs_bmbt_get_rec(struct xfs_btree_cur *, xfs_fileoff_t *,
372 xfs_fsblock_t *, xfs_filblks_t *,
373 xfs_exntst_t *, int *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374#endif
375
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376#endif /* __KERNEL__ */
377
378#endif /* __XFS_BMAP_BTREE_H__ */