/*
* Copyright (c) 2000-2002,2005 Silicon Graphics, Inc.
* All Rights Reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it would be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "xfs.h"
#include "xfs_fs.h"
#include "xfs_types.h"
#include "xfs_bit.h"
#include "xfs_log.h"
#include "xfs_inum.h"
#include "xfs_trans.h"
#include "xfs_sb.h"
#include "xfs_ag.h"
#include "xfs_dir2.h"
#include "xfs_dmapi.h"
#include "xfs_mount.h"
#include "xfs_bmap_btree.h"
#include "xfs_alloc_btree.h"
#include "xfs_ialloc_btree.h"
#include "xfs_dir2_sf.h"
#include "xfs_attr_sf.h"
#include "xfs_dinode.h"
#include "xfs_inode.h"
#include "xfs_btree.h"
#include "xfs_btree_trace.h"
#include "xfs_ialloc.h"
#include "xfs_error.h"
/*
* Cursor allocation zone.
*/
kmem_zone_t *xfs_btree_cur_zone;
/*
* Btree magic numbers.
*/
const __uint32_t xfs_magics[XFS_BTNUM_MAX] = {
XFS_ABTB_MAGIC, XFS_ABTC_MAGIC, XFS_BMAP_MAGIC, XFS_IBT_MAGIC
};
/*
* External routines.
*/
#ifdef DEBUG
/*
* Debug routine: check that keys are in the right order.
*/
void
xfs_btree_check_key(
xfs_btnum_t btnum, /* btree identifier */
void *ak1, /* pointer to left (lower) key */
void *ak2) /* pointer to right (higher) key */
{
switch (btnum) {
case XFS_BTNUM_BNO: {
xfs_alloc_key_t *k1;
xfs_alloc_key_t *k2;
k1 = ak1;
k2 = ak2;
ASSERT(be32_to_cpu(k1->ar_startblock) < be32_to_cpu(k2->ar_startblock));
break;
}
case XFS_BTNUM_CNT: {
xfs_alloc_key_t *k1;
xfs_alloc_key_t *k2;
k1 = ak1;
k2 = ak2;
ASSERT(be32_to_cpu(k1->ar_blockcount) < be32_to_cpu(k2->ar_blockcount) ||
(k1->ar_blockcount == k2->ar_blockcount &&
be32_to_cpu(k1->ar_startblock) < be32_to_cpu(k2->ar_startblock)));
break;
}
case XFS_BTNUM_BMAP: {
xfs_bmbt_key_t *k1;
xfs_bmbt_key_t *k2;
k1 = ak1;
k2 = ak2;
ASSERT(be64_to_cpu(k1->br_startoff) < be64_to_cpu(k2->br_startoff));
break;
}
case XFS_BTNUM_INO: {
xfs_inobt_key_t *k1;
xfs_inobt_key_t *k2;
k1 = ak1;
k2 = ak2;
ASSERT(be32_to_cpu(k1->ir_startino) < be32_to_cpu(k2->ir_startino));
break;
}
default:
ASSERT(0);
}
}
/*
* Debug routine: check that records are in the right order.
*/
void
xfs_btree_check_rec(
xfs_btnum_t btnum, /* btree identifier */
void *ar1, /* pointer to left (lower) record */
void *ar2) /* pointer to right (higher) record */
{
switch (btnum) {
case XFS_BTNUM_BNO: {
xfs_alloc_rec_t *r1;
xfs_alloc_rec_t *r2;
r1 = ar1;
r2 = ar2;
ASSERT(be32_to_cpu(r1->ar_startblock) +
be32_to_cpu(r1->ar_blockcount) <=
be32_to_cpu(r2->ar_startblock));
break;
}
case XFS_BTNUM_CNT: {
xfs_alloc_rec_t *r1;
xfs_alloc_rec_t *r2;
r1 = ar1;
r2 = ar2;
ASSERT(be32_to_cpu(r1->ar_blockcount