2 * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
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
7 * published by the Free Software Foundation.
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.
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
21 * Determine the extent state.
30 ASSERT(blks
!= 0); /* saved for DMIG */
31 return XFS_EXT_UNWRITTEN
;
37 * Convert on-disk form of btree root to in-memory form.
42 xfs_bmdr_block_t
*dblock
,
44 struct xfs_btree_block
*rblock
,
53 rblock
->bb_magic
= cpu_to_be32(XFS_BMAP_MAGIC
);
54 rblock
->bb_level
= dblock
->bb_level
;
55 ASSERT(be16_to_cpu(rblock
->bb_level
) > 0);
56 rblock
->bb_numrecs
= dblock
->bb_numrecs
;
57 rblock
->bb_u
.l
.bb_leftsib
= cpu_to_be64(NULLDFSBNO
);
58 rblock
->bb_u
.l
.bb_rightsib
= cpu_to_be64(NULLDFSBNO
);
59 dmxr
= xfs_bmdr_maxrecs(mp
, dblocklen
, 0);
60 fkp
= XFS_BMDR_KEY_ADDR(dblock
, 1);
61 tkp
= XFS_BMBT_KEY_ADDR(mp
, rblock
, 1);
62 fpp
= XFS_BMDR_PTR_ADDR(dblock
, 1, dmxr
);
63 tpp
= XFS_BMAP_BROOT_PTR_ADDR(mp
, rblock
, 1, rblocklen
);
64 dmxr
= be16_to_cpu(dblock
->bb_numrecs
);
65 memcpy(tkp
, fkp
, sizeof(*fkp
) * dmxr
);
66 memcpy(tpp
, fpp
, sizeof(*fpp
) * dmxr
);
70 * Convert a compressed bmap extent record to an uncompressed form.
71 * This code must be in sync with the routines xfs_bmbt_get_startoff,
72 * xfs_bmbt_get_startblock, xfs_bmbt_get_blockcount and xfs_bmbt_get_state.
84 ext_flag
= (int)(l0
>> (64 - BMBT_EXNTFLAG_BITLEN
));
85 s
->br_startoff
= ((xfs_fileoff_t
)l0
&
86 XFS_MASK64LO(64 - BMBT_EXNTFLAG_BITLEN
)) >> 9;
88 s
->br_startblock
= (((xfs_fsblock_t
)l0
& XFS_MASK64LO(9)) << 43) |
89 (((xfs_fsblock_t
)l1
) >> 21);
95 b
= (((xfs_dfsbno_t
)l0
& XFS_MASK64LO(9)) << 43) |
96 (((xfs_dfsbno_t
)l1
) >> 21);
97 ASSERT((b
>> 32) == 0 || ISNULLDSTARTBLOCK(b
));
98 s
->br_startblock
= (xfs_fsblock_t
)b
;
101 s
->br_startblock
= (xfs_fsblock_t
)(((xfs_dfsbno_t
)l1
) >> 21);
103 #endif /* XFS_BIG_BLKNOS */
104 s
->br_blockcount
= (xfs_filblks_t
)(l1
& XFS_MASK64LO(21));
105 /* This is xfs_extent_state() in-line */
107 ASSERT(s
->br_blockcount
!= 0); /* saved for DMIG */
108 st
= XFS_EXT_UNWRITTEN
;
116 xfs_bmbt_rec_host_t
*r
,
119 __xfs_bmbt_get_all(r
->l0
, r
->l1
, s
);
123 * Extract the blockcount field from an in memory bmap extent record.
126 xfs_bmbt_get_blockcount(
127 xfs_bmbt_rec_host_t
*r
)
129 return (xfs_filblks_t
)(r
->l1
& XFS_MASK64LO(21));
133 * Extract the startblock field from an in memory bmap extent record.
136 xfs_bmbt_get_startblock(
137 xfs_bmbt_rec_host_t
*r
)
140 return (((xfs_fsblock_t
)r
->l0
& XFS_MASK64LO(9)) << 43) |
141 (((xfs_fsblock_t
)r
->l1
) >> 21);
146 b
= (((xfs_dfsbno_t
)r
->l0
& XFS_MASK64LO(9)) << 43) |
147 (((xfs_dfsbno_t
)r
->l1
) >> 21);
148 ASSERT((b
>> 32) == 0 || ISNULLDSTARTBLOCK(b
));
149 return (xfs_fsblock_t
)b
;
151 return (xfs_fsblock_t
)(((xfs_dfsbno_t
)r
->l1
) >> 21);
153 #endif /* XFS_BIG_BLKNOS */
157 * Extract the startoff field from an in memory bmap extent record.
160 xfs_bmbt_get_startoff(
161 xfs_bmbt_rec_host_t
*r
)
163 return ((xfs_fileoff_t
)r
->l0
&
164 XFS_MASK64LO(64 - BMBT_EXNTFLAG_BITLEN
)) >> 9;
169 xfs_bmbt_rec_host_t
*r
)
173 ext_flag
= (int)((r
->l0
) >> (64 - BMBT_EXNTFLAG_BITLEN
));
174 return xfs_extent_state(xfs_bmbt_get_blockcount(r
),
178 /* Endian flipping versions of the bmbt extraction functions */
180 xfs_bmbt_disk_get_all(
184 __xfs_bmbt_get_all(be64_to_cpu(r
->l0
), be64_to_cpu(r
->l1
), s
);
188 * Extract the blockcount field from an on disk bmap extent record.
191 xfs_bmbt_disk_get_blockcount(
194 return (xfs_filblks_t
)(be64_to_cpu(r
->l1
) & XFS_MASK64LO(21));
198 * Extract the startoff field from a disk format bmap extent record.
201 xfs_bmbt_disk_get_startoff(
204 return ((xfs_fileoff_t
)be64_to_cpu(r
->l0
) &
205 XFS_MASK64LO(64 - BMBT_EXNTFLAG_BITLEN
)) >> 9;
210 * Set all the fields in a bmap extent record from the arguments.
214 xfs_bmbt_rec_host_t
*r
,
215 xfs_fileoff_t startoff
,
216 xfs_fsblock_t startblock
,
217 xfs_filblks_t blockcount
,
220 int extent_flag
= (state
== XFS_EXT_NORM
) ? 0 : 1;
222 ASSERT(state
== XFS_EXT_NORM
|| state
== XFS_EXT_UNWRITTEN
);
223 ASSERT((startoff
& XFS_MASK64HI(64-BMBT_STARTOFF_BITLEN
)) == 0);
224 ASSERT((blockcount
& XFS_MASK64HI(64-BMBT_BLOCKCOUNT_BITLEN
)) == 0);
227 ASSERT((startblock
& XFS_MASK64HI(64-BMBT_STARTBLOCK_BITLEN
)) == 0);
229 r
->l0
= ((xfs_bmbt_rec_base_t
)extent_flag
<< 63) |
230 ((xfs_bmbt_rec_base_t
)startoff
<< 9) |
231 ((xfs_bmbt_rec_base_t
)startblock
>> 43);
232 r
->l1
= ((xfs_bmbt_rec_base_t
)startblock
<< 21) |
233 ((xfs_bmbt_rec_base_t
)blockcount
&
234 (xfs_bmbt_rec_base_t
)XFS_MASK64LO(21));
235 #else /* !XFS_BIG_BLKNOS */
236 if (ISNULLSTARTBLOCK(startblock
)) {
237 r
->l0
= ((xfs_bmbt_rec_base_t
)extent_flag
<< 63) |
238 ((xfs_bmbt_rec_base_t
)startoff
<< 9) |
239 (xfs_bmbt_rec_base_t
)XFS_MASK64LO(9);
240 r
->l1
= XFS_MASK64HI(11) |
241 ((xfs_bmbt_rec_base_t
)startblock
<< 21) |
242 ((xfs_bmbt_rec_base_t
)blockcount
&
243 (xfs_bmbt_rec_base_t
)XFS_MASK64LO(21));
245 r
->l0
= ((xfs_bmbt_rec_base_t
)extent_flag
<< 63) |
246 ((xfs_bmbt_rec_base_t
)startoff
<< 9);
247 r
->l1
= ((xfs_bmbt_rec_base_t
)startblock
<< 21) |
248 ((xfs_bmbt_rec_base_t
)blockcount
&
249 (xfs_bmbt_rec_base_t
)XFS_MASK64LO(21));
251 #endif /* XFS_BIG_BLKNOS */
255 * Set all the fields in a bmap extent record from the uncompressed form.
259 xfs_bmbt_rec_host_t
*r
,
262 xfs_bmbt_set_allf(r
, s
->br_startoff
, s
->br_startblock
,
263 s
->br_blockcount
, s
->br_state
);
268 * Set all the fields in a disk format bmap extent record from the arguments.
271 xfs_bmbt_disk_set_allf(
273 xfs_fileoff_t startoff
,
274 xfs_fsblock_t startblock
,
275 xfs_filblks_t blockcount
,
278 int extent_flag
= (state
== XFS_EXT_NORM
) ? 0 : 1;
280 ASSERT(state
== XFS_EXT_NORM
|| state
== XFS_EXT_UNWRITTEN
);
281 ASSERT((startoff
& XFS_MASK64HI(64-BMBT_STARTOFF_BITLEN
)) == 0);
282 ASSERT((blockcount
& XFS_MASK64HI(64-BMBT_BLOCKCOUNT_BITLEN
)) == 0);
285 ASSERT((startblock
& XFS_MASK64HI(64-BMBT_STARTBLOCK_BITLEN
)) == 0);
288 ((xfs_bmbt_rec_base_t
)extent_flag
<< 63) |
289 ((xfs_bmbt_rec_base_t
)startoff
<< 9) |
290 ((xfs_bmbt_rec_base_t
)startblock
>> 43));
292 ((xfs_bmbt_rec_base_t
)startblock
<< 21) |
293 ((xfs_bmbt_rec_base_t
)blockcount
&
294 (xfs_bmbt_rec_base_t
)XFS_MASK64LO(21)));
295 #else /* !XFS_BIG_BLKNOS */
296 if (ISNULLSTARTBLOCK(startblock
)) {
298 ((xfs_bmbt_rec_base_t
)extent_flag
<< 63) |
299 ((xfs_bmbt_rec_base_t
)startoff
<< 9) |
300 (xfs_bmbt_rec_base_t
)XFS_MASK64LO(9));
301 r
->l1
= cpu_to_be64(XFS_MASK64HI(11) |
302 ((xfs_bmbt_rec_base_t
)startblock
<< 21) |
303 ((xfs_bmbt_rec_base_t
)blockcount
&
304 (xfs_bmbt_rec_base_t
)XFS_MASK64LO(21)));
307 ((xfs_bmbt_rec_base_t
)extent_flag
<< 63) |
308 ((xfs_bmbt_rec_base_t
)startoff
<< 9));
310 ((xfs_bmbt_rec_base_t
)startblock
<< 21) |
311 ((xfs_bmbt_rec_base_t
)blockcount
&
312 (xfs_bmbt_rec_base_t
)XFS_MASK64LO(21)));
314 #endif /* XFS_BIG_BLKNOS */
318 * Set all the fields in a bmap extent record from the uncompressed form.
321 xfs_bmbt_disk_set_all(
325 xfs_bmbt_disk_set_allf(r
, s
->br_startoff
, s
->br_startblock
,
326 s
->br_blockcount
, s
->br_state
);
330 * Set the blockcount field in a bmap extent record.
333 xfs_bmbt_set_blockcount(
334 xfs_bmbt_rec_host_t
*r
,
337 ASSERT((v
& XFS_MASK64HI(43)) == 0);
338 r
->l1
= (r
->l1
& (xfs_bmbt_rec_base_t
)XFS_MASK64HI(43)) |
339 (xfs_bmbt_rec_base_t
)(v
& XFS_MASK64LO(21));
343 * Set the startblock field in a bmap extent record.
346 xfs_bmbt_set_startblock(
347 xfs_bmbt_rec_host_t
*r
,
351 ASSERT((v
& XFS_MASK64HI(12)) == 0);
352 r
->l0
= (r
->l0
& (xfs_bmbt_rec_base_t
)XFS_MASK64HI(55)) |
353 (xfs_bmbt_rec_base_t
)(v
>> 43);
354 r
->l1
= (r
->l1
& (xfs_bmbt_rec_base_t
)XFS_MASK64LO(21)) |
355 (xfs_bmbt_rec_base_t
)(v
<< 21);
356 #else /* !XFS_BIG_BLKNOS */
357 if (ISNULLSTARTBLOCK(v
)) {
358 r
->l0
|= (xfs_bmbt_rec_base_t
)XFS_MASK64LO(9);
359 r
->l1
= (xfs_bmbt_rec_base_t
)XFS_MASK64HI(11) |
360 ((xfs_bmbt_rec_base_t
)v
<< 21) |
361 (r
->l1
& (xfs_bmbt_rec_base_t
)XFS_MASK64LO(21));
363 r
->l0
&= ~(xfs_bmbt_rec_base_t
)XFS_MASK64LO(9);
364 r
->l1
= ((xfs_bmbt_rec_base_t
)v
<< 21) |
365 (r
->l1
& (xfs_bmbt_rec_base_t
)XFS_MASK64LO(21));
367 #endif /* XFS_BIG_BLKNOS */
371 * Set the startoff field in a bmap extent record.
374 xfs_bmbt_set_startoff(
375 xfs_bmbt_rec_host_t
*r
,
378 ASSERT((v
& XFS_MASK64HI(9)) == 0);
379 r
->l0
= (r
->l0
& (xfs_bmbt_rec_base_t
) XFS_MASK64HI(1)) |
380 ((xfs_bmbt_rec_base_t
)v
<< 9) |
381 (r
->l0
& (xfs_bmbt_rec_base_t
)XFS_MASK64LO(9));
385 * Set the extent state field in a bmap extent record.
389 xfs_bmbt_rec_host_t
*r
,
392 ASSERT(v
== XFS_EXT_NORM
|| v
== XFS_EXT_UNWRITTEN
);
393 if (v
== XFS_EXT_NORM
)
394 r
->l0
&= XFS_MASK64LO(64 - BMBT_EXNTFLAG_BITLEN
);
396 r
->l0
|= XFS_MASK64HI(BMBT_EXNTFLAG_BITLEN
);
400 * Convert in-memory form of btree root to on-disk form.
404 struct xfs_mount
*mp
,
405 struct xfs_btree_block
*rblock
,
407 xfs_bmdr_block_t
*dblock
,
416 ASSERT(be32_to_cpu(rblock
->bb_magic
) == XFS_BMAP_MAGIC
);
417 ASSERT(be64_to_cpu(rblock
->bb_u
.l
.bb_leftsib
) == NULLDFSBNO
);
418 ASSERT(be64_to_cpu(rblock
->bb_u
.l
.bb_rightsib
) == NULLDFSBNO
);
419 ASSERT(be16_to_cpu(rblock
->bb_level
) > 0);
420 dblock
->bb_level
= rblock
->bb_level
;
421 dblock
->bb_numrecs
= rblock
->bb_numrecs
;
422 dmxr
= xfs_bmdr_maxrecs(mp
, dblocklen
, 0);
423 fkp
= XFS_BMBT_KEY_ADDR(mp
, rblock
, 1);
424 tkp
= XFS_BMDR_KEY_ADDR(dblock
, 1);
425 fpp
= XFS_BMAP_BROOT_PTR_ADDR(mp
, rblock
, 1, rblocklen
);
426 tpp
= XFS_BMDR_PTR_ADDR(dblock
, 1, dmxr
);
427 dmxr
= be16_to_cpu(dblock
->bb_numrecs
);
428 memcpy(tkp
, fkp
, sizeof(*fkp
) * dmxr
);
429 memcpy(tpp
, fpp
, sizeof(*fpp
) * dmxr
);
433 * Check extent records, which have just been read, for
434 * any bit in the extent flag field. ASSERT on debug
435 * kernels, as this condition should not occur.
436 * Return an error condition (1) if any flags found,
437 * otherwise return 0.
441 xfs_check_nostate_extents(
446 for (; num
> 0; num
--, idx
++) {
447 xfs_bmbt_rec_host_t
*ep
= xfs_iext_get_ext(ifp
, idx
);
449 (64 - BMBT_EXNTFLAG_BITLEN
)) != 0) {
458 STATIC
struct xfs_btree_cur
*
460 struct xfs_btree_cur
*cur
)
462 struct xfs_btree_cur
*new;
464 new = xfs_bmbt_init_cursor(cur
->bc_mp
, cur
->bc_tp
,
465 cur
->bc_private
.b
.ip
, cur
->bc_private
.b
.whichfork
);
468 * Copy the firstblock, flist, and flags values,
469 * since init cursor doesn't get them.
471 new->bc_private
.b
.firstblock
= cur
->bc_private
.b
.firstblock
;
472 new->bc_private
.b
.flist
= cur
->bc_private
.b
.flist
;
473 new->bc_private
.b
.flags
= cur
->bc_private
.b
.flags
;
479 xfs_bmbt_update_cursor(
480 struct xfs_btree_cur
*src
,
481 struct xfs_btree_cur
*dst
)
483 ASSERT((dst
->bc_private
.b
.firstblock
!= NULLFSBLOCK
) ||
484 (dst
->bc_private
.b
.ip
->i_d
.di_flags
& XFS_DIFLAG_REALTIME
));
485 ASSERT(dst
->bc_private
.b
.flist
== src
->bc_private
.b
.flist
);
487 dst
->bc_private
.b
.allocated
+= src
->bc_private
.b
.allocated
;
488 dst
->bc_private
.b
.firstblock
= src
->bc_private
.b
.firstblock
;
490 src
->bc_private
.b
.allocated
= 0;
494 xfs_bmbt_alloc_block(
495 struct xfs_btree_cur
*cur
,
496 union xfs_btree_ptr
*start
,
497 union xfs_btree_ptr
*new,
501 xfs_alloc_arg_t args
; /* block allocation args */
502 int error
; /* error return value */
504 memset(&args
, 0, sizeof(args
));
505 args
.tp
= cur
->bc_tp
;
506 args
.mp
= cur
->bc_mp
;
507 args
.fsbno
= cur
->bc_private
.b
.firstblock
;
508 args
.firstblock
= args
.fsbno
;
510 if (args
.fsbno
== NULLFSBLOCK
) {
511 args
.fsbno
= be64_to_cpu(start
->l
);
512 args
.type
= XFS_ALLOCTYPE_START_BNO
;
514 * Make sure there is sufficient room left in the AG to
515 * complete a full tree split for an extent insert. If
516 * we are converting the middle part of an extent then
517 * we may need space for two tree splits.
519 * We are relying on the caller to make the correct block
520 * reservation for this operation to succeed. If the
521 * reservation amount is insufficient then we may fail a
522 * block allocation here and corrupt the filesystem.
524 args
.minleft
= xfs_trans_get_block_res(args
.tp
);
525 } else if (cur
->bc_private
.b
.flist
->xbf_low
) {
526 args
.type
= XFS_ALLOCTYPE_START_BNO
;
528 args
.type
= XFS_ALLOCTYPE_NEAR_BNO
;
531 args
.minlen
= args
.maxlen
= args
.prod
= 1;
532 args
.wasdel
= cur
->bc_private
.b
.flags
& XFS_BTCUR_BPRV_WASDEL
;
533 if (!args
.wasdel
&& xfs_trans_get_block_res(args
.tp
) == 0) {
534 error
= XFS_ERROR(ENOSPC
);
537 error
= xfs_alloc_vextent(&args
);
541 if (args
.fsbno
== NULLFSBLOCK
&& args
.minleft
) {
543 * Could not find an AG with enough free space to satisfy
544 * a full btree split. Try again without minleft and if
545 * successful activate the lowspace algorithm.
548 args
.type
= XFS_ALLOCTYPE_FIRST_AG
;
550 error
= xfs_alloc_vextent(&args
);
553 cur
->bc_private
.b
.flist
->xbf_low
= 1;
555 if (args
.fsbno
== NULLFSBLOCK
) {
556 XFS_BTREE_TRACE_CURSOR(cur
, XBT_EXIT
);
560 ASSERT(args
.len
== 1);
561 cur
->bc_private
.b
.firstblock
= args
.fsbno
;
562 cur
->bc_private
.b
.allocated
++;
563 cur
->bc_private
.b
.ip
->i_d
.di_nblocks
++;
564 xfs_trans_log_inode(args
.tp
, cur
->bc_private
.b
.ip
, XFS_ILOG_CORE
);
565 XFS_TRANS_MOD_DQUOT_BYINO(args
.mp
, args
.tp
, cur
->bc_private
.b
.ip
,
566 XFS_TRANS_DQ_BCOUNT
, 1L);
568 new->l
= cpu_to_be64(args
.fsbno
);
570 XFS_BTREE_TRACE_CURSOR(cur
, XBT_EXIT
);
575 XFS_BTREE_TRACE_CURSOR(cur
, XBT_ERROR
);
581 struct xfs_btree_cur
*cur
,
584 struct xfs_mount
*mp
= cur
->bc_mp
;
585 struct xfs_inode
*ip
= cur
->bc_private
.b
.ip
;
586 struct xfs_trans
*tp
= cur
->bc_tp
;
587 xfs_fsblock_t fsbno
= XFS_DADDR_TO_FSB(mp
, XFS_BUF_ADDR(bp
));
589 xfs_bmap_add_free(fsbno
, 1, cur
->bc_private
.b
.flist
, mp
);
590 ip
->i_d
.di_nblocks
--;
592 xfs_trans_log_inode(tp
, ip
, XFS_ILOG_CORE
);
593 XFS_TRANS_MOD_DQUOT_BYINO(mp
, tp
, ip
, XFS_TRANS_DQ_BCOUNT
, -1L);
594 xfs_trans_binval(tp
, bp
);
599 xfs_bmbt_get_minrecs(
600 struct xfs_btree_cur
*cur
,
603 if (level
== cur
->bc_nlevels
- 1) {
604 struct xfs_ifork
*ifp
;
606 ifp
= XFS_IFORK_PTR(cur
->bc_private
.b
.ip
,
607 cur
->bc_private
.b
.whichfork
);
609 return xfs_bmbt_maxrecs(cur
->bc_mp
,
610 ifp
->if_broot_bytes
, level
== 0) / 2;
613 return cur
->bc_mp
->m_bmap_dmnr
[level
!= 0];
617 xfs_bmbt_get_maxrecs(
618 struct xfs_btree_cur
*cur
,
621 if (level
== cur
->bc_nlevels
- 1) {
622 struct xfs_ifork
*ifp
;
624 ifp
= XFS_IFORK_PTR(cur
->bc_private
.b
.ip
,
625 cur
->bc_private
.b
.whichfork
);
627 return xfs_bmbt_maxrecs(cur
->bc_mp
,
628 ifp
->if_broot_bytes
, level
== 0);
631 return cur
->bc_mp
->m_bmap_dmxr
[level
!= 0];
636 * Get the maximum records we could store in the on-disk format.
638 * For non-root nodes this is equivalent to xfs_bmbt_get_maxrecs, but
639 * for the root node this checks the available space in the dinode fork
640 * so that we can resize the in-memory buffer to match it. After a
641 * resize to the maximum size this function returns the same value
642 * as xfs_bmbt_get_maxrecs for the root node, too.
645 xfs_bmbt_get_dmaxrecs(
646 struct xfs_btree_cur
*cur
,
649 if (level
!= cur
->bc_nlevels
- 1)
650 return cur
->bc_mp
->m_bmap_dmxr
[level
!= 0];
651 return xfs_bmdr_maxrecs(cur
->bc_mp
, cur
->bc_private
.b
.forksize
,
656 xfs_bmbt_init_key_from_rec(
657 union xfs_btree_key
*key
,
658 union xfs_btree_rec
*rec
)
660 key
->bmbt
.br_startoff
=
661 cpu_to_be64(xfs_bmbt_disk_get_startoff(&rec
->bmbt
));
665 xfs_bmbt_init_rec_from_key(
666 union xfs_btree_key
*key
,
667 union xfs_btree_rec
*rec
)
669 ASSERT(key
->bmbt
.br_startoff
!= 0);
671 xfs_bmbt_disk_set_allf(&rec
->bmbt
, be64_to_cpu(key
->bmbt
.br_startoff
),
676 xfs_bmbt_init_rec_from_cur(
677 struct xfs_btree_cur
*cur
,
678 union xfs_btree_rec
*rec
)
680 xfs_bmbt_disk_set_all(&rec
->bmbt
, &cur
->bc_rec
.b
);
684 xfs_bmbt_init_ptr_from_cur(
685 struct xfs_btree_cur
*cur
,
686 union xfs_btree_ptr
*ptr
)
693 struct xfs_btree_cur
*cur
,
694 union xfs_btree_key
*key
)
696 return (__int64_t
)be64_to_cpu(key
->bmbt
.br_startoff
) -
697 cur
->bc_rec
.b
.br_startoff
;
702 xfs_bmbt_keys_inorder(
703 struct xfs_btree_cur
*cur
,
704 union xfs_btree_key
*k1
,
705 union xfs_btree_key
*k2
)
707 return be64_to_cpu(k1
->bmbt
.br_startoff
) <
708 be64_to_cpu(k2
->bmbt
.br_startoff
);
712 xfs_bmbt_recs_inorder(
713 struct xfs_btree_cur
*cur
,
714 union xfs_btree_rec
*r1
,
715 union xfs_btree_rec
*r2
)
717 return xfs_bmbt_disk_get_startoff(&r1
->bmbt
) +
718 xfs_bmbt_disk_get_blockcount(&r1
->bmbt
) <=
719 xfs_bmbt_disk_get_startoff(&r2
->bmbt
);
723 #ifdef XFS_BTREE_TRACE
724 ktrace_t
*xfs_bmbt_trace_buf
;
727 xfs_bmbt_trace_enter(
728 struct xfs_btree_cur
*cur
,
745 struct xfs_inode
*ip
= cur
->bc_private
.b
.ip
;
746 int whichfork
= cur
->bc_private
.b
.whichfork
;
748 ktrace_enter(xfs_bmbt_trace_buf
,
749 (void *)((__psint_t
)type
| (whichfork
<< 8) | (line
<< 16)),
750 (void *)func
, (void *)s
, (void *)ip
, (void *)cur
,
751 (void *)a0
, (void *)a1
, (void *)a2
, (void *)a3
,
752 (void *)a4
, (void *)a5
, (void *)a6
, (void *)a7
,
753 (void *)a8
, (void *)a9
, (void *)a10
);
754 ktrace_enter(ip
->i_btrace
,
755 (void *)((__psint_t
)type
| (whichfork
<< 8) | (line
<< 16)),
756 (void *)func
, (void *)s
, (void *)ip
, (void *)cur
,
757 (void *)a0
, (void *)a1
, (void *)a2
, (void *)a3
,
758 (void *)a4
, (void *)a5
, (void *)a6
, (void *)a7
,
759 (void *)a8
, (void *)a9
, (void *)a10
);
763 xfs_bmbt_trace_cursor(
764 struct xfs_btree_cur
*cur
,
769 struct xfs_bmbt_rec_host r
;
771 xfs_bmbt_set_all(&r
, &cur
->bc_rec
.b
);
773 *s0
= (cur
->bc_nlevels
<< 24) |
774 (cur
->bc_private
.b
.flags
<< 16) |
775 cur
->bc_private
.b
.allocated
;
782 struct xfs_btree_cur
*cur
,
783 union xfs_btree_key
*key
,
787 *l0
= be64_to_cpu(key
->bmbt
.br_startoff
);
792 xfs_bmbt_trace_record(
793 struct xfs_btree_cur
*cur
,
794 union xfs_btree_rec
*rec
,
799 struct xfs_bmbt_irec irec
;
801 xfs_bmbt_disk_get_all(&rec
->bmbt
, &irec
);
802 *l0
= irec
.br_startoff
;
803 *l1
= irec
.br_startblock
;
804 *l2
= irec
.br_blockcount
;
806 #endif /* XFS_BTREE_TRACE */
808 static const struct xfs_btree_ops xfs_bmbt_ops
= {
809 .rec_len
= sizeof(xfs_bmbt_rec_t
),
810 .key_len
= sizeof(xfs_bmbt_key_t
),
812 .dup_cursor
= xfs_bmbt_dup_cursor
,
813 .update_cursor
= xfs_bmbt_update_cursor
,
814 .alloc_block
= xfs_bmbt_alloc_block
,
815 .free_block
= xfs_bmbt_free_block
,
816 .get_maxrecs
= xfs_bmbt_get_maxrecs
,
817 .get_minrecs
= xfs_bmbt_get_minrecs
,
818 .get_dmaxrecs
= xfs_bmbt_get_dmaxrecs
,
819 .init_key_from_rec
= xfs_bmbt_init_key_from_rec
,
820 .init_rec_from_key
= xfs_bmbt_init_rec_from_key
,
821 .init_rec_from_cur
= xfs_bmbt_init_rec_from_cur
,
822 .init_ptr_from_cur
= xfs_bmbt_init_ptr_from_cur
,
823 .key_diff
= xfs_bmbt_key_diff
,
826 .keys_inorder
= xfs_bmbt_keys_inorder
,
827 .recs_inorder
= xfs_bmbt_recs_inorder
,
830 #ifdef XFS_BTREE_TRACE
831 .trace_enter
= xfs_bmbt_trace_enter
,
832 .trace_cursor
= xfs_bmbt_trace_cursor
,
833 .trace_key
= xfs_bmbt_trace_key
,
834 .trace_record
= xfs_bmbt_trace_record
,
839 * Allocate a new bmap btree cursor.
841 struct xfs_btree_cur
* /* new bmap btree cursor */
842 xfs_bmbt_init_cursor(
843 struct xfs_mount
*mp
, /* file system mount point */
844 struct xfs_trans
*tp
, /* transaction pointer */
845 struct xfs_inode
*ip
, /* inode owning the btree */
846 int whichfork
) /* data or attr fork */
848 struct xfs_ifork
*ifp
= XFS_IFORK_PTR(ip
, whichfork
);
849 struct xfs_btree_cur
*cur
;
851 cur
= kmem_zone_zalloc(xfs_btree_cur_zone
, KM_SLEEP
);
855 cur
->bc_nlevels
= be16_to_cpu(ifp
->if_broot
->bb_level
) + 1;
856 cur
->bc_btnum
= XFS_BTNUM_BMAP
;
857 cur
->bc_blocklog
= mp
->m_sb
.sb_blocklog
;
859 cur
->bc_ops
= &xfs_bmbt_ops
;
860 cur
->bc_flags
= XFS_BTREE_LONG_PTRS
| XFS_BTREE_ROOT_IN_INODE
;
862 cur
->bc_private
.b
.forksize
= XFS_IFORK_SIZE(ip
, whichfork
);
863 cur
->bc_private
.b
.ip
= ip
;
864 cur
->bc_private
.b
.firstblock
= NULLFSBLOCK
;
865 cur
->bc_private
.b
.flist
= NULL
;
866 cur
->bc_private
.b
.allocated
= 0;
867 cur
->bc_private
.b
.flags
= 0;
868 cur
->bc_private
.b
.whichfork
= whichfork
;
874 * Calculate number of records in a bmap btree block.
878 struct xfs_mount
*mp
,
882 blocklen
-= XFS_BMBT_BLOCK_LEN(mp
);
885 return blocklen
/ sizeof(xfs_bmbt_rec_t
);
886 return blocklen
/ (sizeof(xfs_bmbt_key_t
) + sizeof(xfs_bmbt_ptr_t
));
890 * Calculate number of records in a bmap btree inode root.
894 struct xfs_mount
*mp
,
898 blocklen
-= sizeof(xfs_bmdr_block_t
);
901 return blocklen
/ sizeof(xfs_bmdr_rec_t
);
902 return blocklen
/ (sizeof(xfs_bmdr_key_t
) + sizeof(xfs_bmdr_ptr_t
));