From: Barry Naujok Date: Fri, 3 Oct 2008 04:35:04 +0000 (+0000) Subject: Consolidate btree block handling for xfs_db X-Git-Tag: v3.0.0~51 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=49b314177f28f8bd80f22abee7c8ab91a2ff5d89;p=thirdparty%2Fxfsprogs-dev.git Consolidate btree block handling for xfs_db Currently xfs_db has five different implementations for poking at btree blocks, even duplicating code for btree blocks with entirely identical layout (bmapbta vs bmapbtd and bno vs cnt). Merge all these into a single implementation that uses a table of btree characteristics keyed of their magic number. There's probably a way to further consolidate the magic arrays for the different types, but I don't quite understand xfs_db's table driven command parser for that. Signed-off-by: Christoph Hellwig Merge of master-melb:xfs-cmds:32248a by kenmcd. Consolidate btree block handling for xfs_db --- diff --git a/db/Makefile b/db/Makefile index edef85e12..125c4c566 100644 --- a/db/Makefile +++ b/db/Makefile @@ -8,12 +8,11 @@ include $(TOPDIR)/include/builddefs LTCOMMAND = xfs_db HFILES = addr.h agf.h agfl.h agi.h attr.h attrshort.h bit.h block.h bmap.h \ - bmapbt.h bmroot.h bnobt.h check.h cntbt.h command.h convert.h \ - dbread.h debug.h dir.h dir2.h dir2sf.h dirshort.h dquot.h echo.h \ - faddr.h field.h flist.h fprint.h frag.h freesp.h hash.h help.h \ - init.h inobt.h inode.h input.h io.h malloc.h metadump.h output.h \ - print.h quit.h sb.h sig.h strvec.h text.h type.h write.h \ - attrset.h + btblock.h bmroot.h check.h command.h convert.h dbread.h debug.h \ + dir.h dir2.h dir2sf.h dirshort.h dquot.h echo.h faddr.h field.h \ + flist.h fprint.h frag.h freesp.h hash.h help.h init.h inode.h input.h \ + io.h malloc.h metadump.h output.h print.h quit.h sb.h sig.h strvec.h \ + text.h type.h write.h attrset.h CFILES = $(HFILES:.h=.c) LSRCFILES = xfs_admin.sh xfs_check.sh xfs_ncheck.sh xfs_metadump.sh LLDLIBS = $(LIBXFS) $(LIBXLOG) $(LIBUUID) $(LIBRT) $(LIBPTHREAD) diff --git a/db/bmapbt.c b/db/bmapbt.c deleted file mode 100644 index 44ecabdb4..000000000 --- a/db/bmapbt.c +++ /dev/null @@ -1,329 +0,0 @@ -/* - * Copyright (c) 2000-2001,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 -#include "type.h" -#include "faddr.h" -#include "fprint.h" -#include "field.h" -#include "bmapbt.h" -#include "print.h" -#include "bit.h" -#include "init.h" - -static int bmapbta_key_count(void *obj, int startoff); -static int bmapbta_key_offset(void *obj, int startoff, int idx); -static int bmapbta_ptr_count(void *obj, int startoff); -static int bmapbta_ptr_offset(void *obj, int startoff, int idx); -static int bmapbta_rec_count(void *obj, int startoff); -static int bmapbta_rec_offset(void *obj, int startoff, int idx); -static int bmapbtd_key_count(void *obj, int startoff); -static int bmapbtd_key_offset(void *obj, int startoff, int idx); -static int bmapbtd_ptr_count(void *obj, int startoff); -static int bmapbtd_ptr_offset(void *obj, int startoff, int idx); -static int bmapbtd_rec_count(void *obj, int startoff); -static int bmapbtd_rec_offset(void *obj, int startoff, int idx); - -const field_t bmapbta_hfld[] = { - { "", FLDT_BMAPBTA, OI(0), C1, 0, TYP_NONE }, - { NULL } -}; -const field_t bmapbtd_hfld[] = { - { "", FLDT_BMAPBTD, OI(0), C1, 0, TYP_NONE }, - { NULL } -}; - -#define OFF(f) bitize(offsetof(xfs_bmbt_block_t, bb_ ## f)) -const field_t bmapbta_flds[] = { - { "magic", FLDT_UINT32X, OI(OFF(magic)), C1, 0, TYP_NONE }, - { "level", FLDT_UINT16D, OI(OFF(level)), C1, 0, TYP_NONE }, - { "numrecs", FLDT_UINT16D, OI(OFF(numrecs)), C1, 0, TYP_NONE }, - { "leftsib", FLDT_DFSBNO, OI(OFF(leftsib)), C1, 0, TYP_BMAPBTA }, - { "rightsib", FLDT_DFSBNO, OI(OFF(rightsib)), C1, 0, TYP_BMAPBTA }, - { "recs", FLDT_BMAPBTAREC, bmapbta_rec_offset, bmapbta_rec_count, - FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_NONE }, - { "keys", FLDT_BMAPBTAKEY, bmapbta_key_offset, bmapbta_key_count, - FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_NONE }, - { "ptrs", FLDT_BMAPBTAPTR, bmapbta_ptr_offset, bmapbta_ptr_count, - FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_BMAPBTA }, - { NULL } -}; -const field_t bmapbtd_flds[] = { - { "magic", FLDT_UINT32X, OI(OFF(magic)), C1, 0, TYP_NONE }, - { "level", FLDT_UINT16D, OI(OFF(level)), C1, 0, TYP_NONE }, - { "numrecs", FLDT_UINT16D, OI(OFF(numrecs)), C1, 0, TYP_NONE }, - { "leftsib", FLDT_DFSBNO, OI(OFF(leftsib)), C1, 0, TYP_BMAPBTD }, - { "rightsib", FLDT_DFSBNO, OI(OFF(rightsib)), C1, 0, TYP_BMAPBTD }, - { "recs", FLDT_BMAPBTDREC, bmapbtd_rec_offset, bmapbtd_rec_count, - FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_NONE }, - { "keys", FLDT_BMAPBTDKEY, bmapbtd_key_offset, bmapbtd_key_count, - FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_NONE }, - { "ptrs", FLDT_BMAPBTDPTR, bmapbtd_ptr_offset, bmapbtd_ptr_count, - FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_BMAPBTD }, - { NULL } -}; - -#define KOFF(f) bitize(offsetof(xfs_bmbt_key_t, br_ ## f)) -const field_t bmapbta_key_flds[] = { - { "startoff", FLDT_DFILOFFA, OI(KOFF(startoff)), C1, 0, TYP_ATTR }, - { NULL } -}; -const field_t bmapbtd_key_flds[] = { - { "startoff", FLDT_DFILOFFD, OI(KOFF(startoff)), C1, 0, TYP_INODATA }, - { NULL } -}; - -#ifndef XFS_NATIVE_HOST - -#define BMBT_EXNTFLAG_BITOFF 0 -#define BMBT_STARTOFF_BITOFF (BMBT_EXNTFLAG_BITOFF + BMBT_EXNTFLAG_BITLEN) -#define BMBT_STARTBLOCK_BITOFF (BMBT_STARTOFF_BITOFF + BMBT_STARTOFF_BITLEN) -#define BMBT_BLOCKCOUNT_BITOFF \ - (BMBT_STARTBLOCK_BITOFF + BMBT_STARTBLOCK_BITLEN) - -#else - -#define BMBT_EXNTFLAG_BITOFF 63 -#define BMBT_STARTOFF_BITOFF (BMBT_EXNTFLAG_BITOFF - BMBT_STARTOFF_BITLEN) -#define BMBT_STARTBLOCK_BITOFF 85 /* 128 - 43 (other 9 is in first word) */ -#define BMBT_BLOCKCOUNT_BITOFF 64 /* Start of second 64 bit container */ - -#endif /* XFS_NATIVE_HOST */ - -const field_t bmapbta_rec_flds[] = { - { "startoff", FLDT_CFILEOFFA, OI(BMBT_STARTOFF_BITOFF), C1, 0, - TYP_ATTR }, - { "startblock", FLDT_CFSBLOCK, OI(BMBT_STARTBLOCK_BITOFF), C1, 0, - TYP_ATTR }, - { "blockcount", FLDT_CEXTLEN, OI(BMBT_BLOCKCOUNT_BITOFF), C1, 0, - TYP_NONE }, - { "extentflag", FLDT_CEXTFLG, OI(BMBT_EXNTFLAG_BITOFF), C1, 0, - TYP_NONE }, - { NULL } -}; -const field_t bmapbtd_rec_flds[] = { - { "startoff", FLDT_CFILEOFFD, OI(BMBT_STARTOFF_BITOFF), C1, 0, - TYP_INODATA }, - { "startblock", FLDT_CFSBLOCK, OI(BMBT_STARTBLOCK_BITOFF), C1, 0, - TYP_INODATA }, - { "blockcount", FLDT_CEXTLEN, OI(BMBT_BLOCKCOUNT_BITOFF), C1, 0, - TYP_NONE }, - { "extentflag", FLDT_CEXTFLG, OI(BMBT_EXNTFLAG_BITOFF), C1, 0, - TYP_NONE }, - { NULL } -}; - -static int -bmapbta_key_count( - void *obj, - int startoff) -{ - xfs_bmbt_block_t *block; - - ASSERT(startoff == 0); - block = obj; - if (be16_to_cpu(block->bb_level) == 0) - return 0; - return be16_to_cpu(block->bb_numrecs); -} - -static int -bmapbta_key_offset( - void *obj, - int startoff, - int idx) -{ - xfs_bmbt_block_t *block; - xfs_bmbt_key_t *kp; - - ASSERT(startoff == 0); - block = obj; - ASSERT(be16_to_cpu(block->bb_level) > 0); - kp = XFS_BTREE_KEY_ADDR(xfs_bmbt, block, idx); - return bitize((int)((char *)kp - (char *)block)); -} - -static int -bmapbta_ptr_count( - void *obj, - int startoff) -{ - xfs_bmbt_block_t *block; - - ASSERT(startoff == 0); - block = obj; - if (be16_to_cpu(block->bb_level) == 0) - return 0; - return be16_to_cpu(block->bb_numrecs); -} - -static int -bmapbta_ptr_offset( - void *obj, - int startoff, - int idx) -{ - xfs_bmbt_block_t *block; - xfs_bmbt_ptr_t *pp; - - ASSERT(startoff == 0); - block = obj; - ASSERT(be16_to_cpu(block->bb_level) > 0); - pp = XFS_BTREE_PTR_ADDR(xfs_bmbt, block, idx, - XFS_BTREE_BLOCK_MAXRECS(mp->m_sb.sb_blocksize, xfs_bmbt, 0)); - return bitize((int)((char *)pp - (char *)block)); -} - -static int -bmapbta_rec_count( - void *obj, - int startoff) -{ - xfs_bmbt_block_t *block; - - ASSERT(startoff == 0); - block = obj; - if (be16_to_cpu(block->bb_level) > 0) - return 0; - return be16_to_cpu(block->bb_numrecs); -} - -static int -bmapbta_rec_offset( - void *obj, - int startoff, - int idx) -{ - xfs_bmbt_block_t *block; - xfs_bmbt_rec_t *rp; - - ASSERT(startoff == 0); - block = obj; - ASSERT(be16_to_cpu(block->bb_level) == 0); - rp = XFS_BTREE_REC_ADDR(xfs_bmbt, block, idx); - return bitize((int)((char *)rp - (char *)block)); -} - -int -bmapbta_size( - void *obj, - int startoff, - int idx) -{ - return bitize(mp->m_sb.sb_blocksize); -} - -static int -bmapbtd_key_count( - void *obj, - int startoff) -{ - xfs_bmbt_block_t *block; - - ASSERT(startoff == 0); - block = obj; - if (be16_to_cpu(block->bb_level) == 0) - return 0; - return be16_to_cpu(block->bb_numrecs); -} - -static int -bmapbtd_key_offset( - void *obj, - int startoff, - int idx) -{ - xfs_bmbt_block_t *block; - xfs_bmbt_key_t *kp; - - ASSERT(startoff == 0); - block = obj; - ASSERT(be16_to_cpu(block->bb_level) > 0); - kp = XFS_BTREE_KEY_ADDR(xfs_bmbt, block, idx); - return bitize((int)((char *)kp - (char *)block)); -} - -static int -bmapbtd_ptr_count( - void *obj, - int startoff) -{ - xfs_bmbt_block_t *block; - - ASSERT(startoff == 0); - block = obj; - if (be16_to_cpu(block->bb_level) == 0) - return 0; - return be16_to_cpu(block->bb_numrecs); -} - -static int -bmapbtd_ptr_offset( - void *obj, - int startoff, - int idx) -{ - xfs_bmbt_block_t *block; - xfs_bmbt_ptr_t *pp; - - ASSERT(startoff == 0); - block = obj; - ASSERT(be16_to_cpu(block->bb_level) > 0); - pp = XFS_BTREE_PTR_ADDR(xfs_bmbt, block, idx, - XFS_BTREE_BLOCK_MAXRECS(mp->m_sb.sb_blocksize, xfs_bmbt, 0)); - return bitize((int)((char *)pp - (char *)block)); -} - -static int -bmapbtd_rec_count( - void *obj, - int startoff) -{ - xfs_bmbt_block_t *block; - - ASSERT(startoff == 0); - block = obj; - if (be16_to_cpu(block->bb_level) > 0) - return 0; - return be16_to_cpu(block->bb_numrecs); -} - -static int -bmapbtd_rec_offset( - void *obj, - int startoff, - int idx) -{ - xfs_bmbt_block_t *block; - xfs_bmbt_rec_t *rp; - - ASSERT(startoff == 0); - block = obj; - ASSERT(be16_to_cpu(block->bb_level) == 0); - rp = XFS_BTREE_REC_ADDR(xfs_bmbt, block, idx); - return bitize((int)((char *)rp - (char *)block)); -} - -int -bmapbtd_size( - void *obj, - int startoff, - int idx) -{ - return bitize(mp->m_sb.sb_blocksize); -} diff --git a/db/bnobt.c b/db/bnobt.c deleted file mode 100644 index e1d664c68..000000000 --- a/db/bnobt.c +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Copyright (c) 2000-2001,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 -#include "type.h" -#include "faddr.h" -#include "fprint.h" -#include "field.h" -#include "bnobt.h" -#include "io.h" -#include "print.h" -#include "bit.h" -#include "init.h" - -static int bnobt_key_count(void *obj, int startoff); -static int bnobt_key_offset(void *obj, int startoff, int idx); -static int bnobt_ptr_count(void *obj, int startoff); -static int bnobt_ptr_offset(void *obj, int startoff, int idx); -static int bnobt_rec_count(void *obj, int startoff); -static int bnobt_rec_offset(void *obj, int startoff, int idx); - -const field_t bnobt_hfld[] = { - { "", FLDT_BNOBT, OI(0), C1, 0, TYP_NONE }, - { NULL } -}; - -#define OFF(f) bitize(offsetof(xfs_alloc_block_t, bb_ ## f)) -const field_t bnobt_flds[] = { - { "magic", FLDT_UINT32X, OI(OFF(magic)), C1, 0, TYP_NONE }, - { "level", FLDT_UINT16D, OI(OFF(level)), C1, 0, TYP_NONE }, - { "numrecs", FLDT_UINT16D, OI(OFF(numrecs)), C1, 0, TYP_NONE }, - { "leftsib", FLDT_AGBLOCK, OI(OFF(leftsib)), C1, 0, TYP_BNOBT }, - { "rightsib", FLDT_AGBLOCK, OI(OFF(rightsib)), C1, 0, TYP_BNOBT }, - { "recs", FLDT_BNOBTREC, bnobt_rec_offset, bnobt_rec_count, - FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_NONE }, - { "keys", FLDT_BNOBTKEY, bnobt_key_offset, bnobt_key_count, - FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_NONE }, - { "ptrs", FLDT_BNOBTPTR, bnobt_ptr_offset, bnobt_ptr_count, - FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_BNOBT }, - { NULL } -}; - -#define KOFF(f) bitize(offsetof(xfs_alloc_key_t, ar_ ## f)) -const field_t bnobt_key_flds[] = { - { "startblock", FLDT_AGBLOCK, OI(KOFF(startblock)), C1, 0, TYP_DATA }, - { "blockcount", FLDT_EXTLEN, OI(KOFF(blockcount)), C1, 0, TYP_NONE }, - { NULL } -}; - -#define ROFF(f) bitize(offsetof(xfs_alloc_rec_t, ar_ ## f)) -const field_t bnobt_rec_flds[] = { - { "startblock", FLDT_AGBLOCK, OI(ROFF(startblock)), C1, 0, TYP_DATA }, - { "blockcount", FLDT_EXTLEN, OI(ROFF(blockcount)), C1, 0, TYP_NONE }, - { NULL } -}; - -static int -bnobt_key_count( - void *obj, - int startoff) -{ - xfs_alloc_block_t *block; - - ASSERT(startoff == 0); - block = obj; - if (be16_to_cpu(block->bb_level) == 0) - return 0; - return be16_to_cpu(block->bb_numrecs); -} - -static int -bnobt_key_offset( - void *obj, - int startoff, - int idx) -{ - xfs_alloc_block_t *block; - xfs_alloc_key_t *kp; - - ASSERT(startoff == 0); - block = obj; - ASSERT(be16_to_cpu(block->bb_level) > 0); - kp = XFS_BTREE_KEY_ADDR(xfs_alloc, block, idx); - return bitize((int)((char *)kp - (char *)block)); -} - -static int -bnobt_ptr_count( - void *obj, - int startoff) -{ - xfs_alloc_block_t *block; - - ASSERT(startoff == 0); - block = obj; - if (be16_to_cpu(block->bb_level) == 0) - return 0; - return be16_to_cpu(block->bb_numrecs); -} - -static int -bnobt_ptr_offset( - void *obj, - int startoff, - int idx) -{ - xfs_alloc_block_t *block; - xfs_alloc_ptr_t *pp; - - ASSERT(startoff == 0); - block = obj; - ASSERT(be16_to_cpu(block->bb_level) > 0); - pp = XFS_BTREE_PTR_ADDR(xfs_alloc, block, idx, - XFS_BTREE_BLOCK_MAXRECS(mp->m_sb.sb_blocksize, xfs_alloc, 0)); - return bitize((int)((char *)pp - (char *)block)); -} - -static int -bnobt_rec_count( - void *obj, - int startoff) -{ - xfs_alloc_block_t *block; - - ASSERT(startoff == 0); - block = obj; - if (be16_to_cpu(block->bb_level) > 0) - return 0; - return be16_to_cpu(block->bb_numrecs); -} - -static int -bnobt_rec_offset( - void *obj, - int startoff, - int idx) -{ - xfs_alloc_block_t *block; - xfs_alloc_rec_t *rp; - - ASSERT(startoff == 0); - block = obj; - ASSERT(be16_to_cpu(block->bb_level) == 0); - rp = XFS_BTREE_REC_ADDR(xfs_alloc, block, idx); - return bitize((int)((char *)rp - (char *)block)); -} - -int -bnobt_size( - void *obj, - int startoff, - int idx) -{ - return bitize(mp->m_sb.sb_blocksize); -} diff --git a/db/bnobt.h b/db/bnobt.h deleted file mode 100644 index 3fff16934..000000000 --- a/db/bnobt.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2000-2001,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 - */ - -extern const struct field bnobt_flds[]; -extern const struct field bnobt_hfld[]; -extern const struct field bnobt_key_flds[]; -extern const struct field bnobt_rec_flds[]; - -extern int bnobt_size(void *obj, int startoff, int idx); diff --git a/db/btblock.c b/db/btblock.c new file mode 100644 index 000000000..89e550c34 --- /dev/null +++ b/db/btblock.c @@ -0,0 +1,414 @@ +/* + * Copyright (c) 2000-2001,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 +#include "type.h" +#include "faddr.h" +#include "fprint.h" +#include "field.h" +#include "btblock.h" +#include "print.h" +#include "bit.h" +#include "init.h" + + +/* + * Definition of the possible btree block layouts. + */ +struct xfs_db_btree { + size_t block_len; + size_t key_len; + size_t rec_len; + size_t ptr_len; +} btrees[] = { + [/*0x424d415*/0] = { /* BMAP */ + sizeof(struct xfs_btree_lblock), + sizeof(xfs_bmbt_key_t), + sizeof(xfs_bmbt_rec_t), + sizeof(__be64), + }, + [/*0x4142544*/2] = { /* ABTB */ + sizeof(struct xfs_btree_sblock), + sizeof(xfs_alloc_key_t), + sizeof(xfs_alloc_rec_t), + sizeof(__be32), + }, + [/*0x4142544*/3] = { /* ABTC */ + sizeof(struct xfs_btree_sblock), + sizeof(xfs_alloc_key_t), + sizeof(xfs_alloc_rec_t), + sizeof(__be32), + }, + [/*0x4941425*/4] = { /* IABT */ + sizeof(struct xfs_btree_sblock), + sizeof(xfs_inobt_key_t), + sizeof(xfs_inobt_rec_t), + sizeof(__be32), + }, +}; + +/* + * Find the right block defintion for a given ondisk block. + * + * We use the least significant bit of the magic number as index into + * the array of block defintions. + */ +#define block_to_bt(bb) \ + (&btrees[be32_to_cpu((bb)->bb_magic) & 0xf]) + +/* calculate max records. Only for non-leaves. */ +static int +btblock_maxrecs(struct xfs_db_btree *bt, int blocksize) +{ + blocksize -= bt->block_len; + + return blocksize / (bt->key_len + bt->ptr_len); +} + +/* + * Get the number of keys in a btree block. + * + * Note: can also be used to get the number of ptrs because there are + * always the same number of keys and ptrs in a block. + */ +static int +btblock_key_count( + void *obj, + int startoff) +{ + struct xfs_btree_block *block = obj; + + ASSERT(startoff == 0); + + if (block->bb_level == 0) + return 0; + return be16_to_cpu(block->bb_numrecs); +} + +/* + * Get the number of keys in a btree block. + */ +static int +btblock_rec_count( + void *obj, + int startoff) +{ + struct xfs_btree_block *block = obj; + + ASSERT(startoff == 0); + + if (block->bb_level != 0) + return 0; + return be16_to_cpu(block->bb_numrecs); +} + +/* + * Get the offset of the key at idx in a btree block. + */ +static int +btblock_key_offset( + void *obj, + int startoff, + int idx) +{ + struct xfs_btree_block *block = obj; + struct xfs_db_btree *bt = block_to_bt(block); + int offset; + + ASSERT(startoff == 0); + ASSERT(block->bb_level != 0); + + offset = bt->block_len + (idx - 1) * bt->key_len; + return bitize(offset); +} + +/* + * Get the offset of the ptr at idx in a btree block. + */ +static int +btblock_ptr_offset( + void *obj, + int startoff, + int idx) +{ + struct xfs_btree_block *block = obj; + struct xfs_db_btree *bt = block_to_bt(block); + int offset; + int maxrecs; + + ASSERT(startoff == 0); + ASSERT(block->bb_level != 0); + + maxrecs = btblock_maxrecs(bt, mp->m_sb.sb_blocksize); + offset = bt->block_len + + maxrecs * bt->key_len + + (idx - 1) * bt->ptr_len; + + return bitize(offset); +} + +/* + * Get the offset of the record at idx in a btree block. + */ +static int +btblock_rec_offset( + void *obj, + int startoff, + int idx) +{ + struct xfs_btree_block *block = obj; + struct xfs_db_btree *bt = block_to_bt(block); + int offset; + + ASSERT(startoff == 0); + ASSERT(block->bb_level == 0); + + offset = bt->block_len + (idx - 1) * bt->rec_len; + return bitize(offset); +} + +/* + * Get the size of a btree block. + */ +int +btblock_size( + void *obj, + int startoff, + int idx) +{ + return bitize(mp->m_sb.sb_blocksize); +} + + +/* + * Bmap btree. + */ + +const field_t bmapbta_hfld[] = { + { "", FLDT_BMAPBTA, OI(0), C1, 0, TYP_NONE }, + { NULL } +}; +const field_t bmapbtd_hfld[] = { + { "", FLDT_BMAPBTD, OI(0), C1, 0, TYP_NONE }, + { NULL } +}; + +#define OFF(f) bitize(offsetof(xfs_bmbt_block_t, bb_ ## f)) +const field_t bmapbta_flds[] = { + { "magic", FLDT_UINT32X, OI(OFF(magic)), C1, 0, TYP_NONE }, + { "level", FLDT_UINT16D, OI(OFF(level)), C1, 0, TYP_NONE }, + { "numrecs", FLDT_UINT16D, OI(OFF(numrecs)), C1, 0, TYP_NONE }, + { "leftsib", FLDT_DFSBNO, OI(OFF(leftsib)), C1, 0, TYP_BMAPBTA }, + { "rightsib", FLDT_DFSBNO, OI(OFF(rightsib)), C1, 0, TYP_BMAPBTA }, + { "recs", FLDT_BMAPBTAREC, btblock_rec_offset, btblock_rec_count, + FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_NONE }, + { "keys", FLDT_BMAPBTAKEY, btblock_key_offset, btblock_key_count, + FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_NONE }, + { "ptrs", FLDT_BMAPBTAPTR, btblock_ptr_offset, btblock_key_count, + FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_BMAPBTA }, + { NULL } +}; +const field_t bmapbtd_flds[] = { + { "magic", FLDT_UINT32X, OI(OFF(magic)), C1, 0, TYP_NONE }, + { "level", FLDT_UINT16D, OI(OFF(level)), C1, 0, TYP_NONE }, + { "numrecs", FLDT_UINT16D, OI(OFF(numrecs)), C1, 0, TYP_NONE }, + { "leftsib", FLDT_DFSBNO, OI(OFF(leftsib)), C1, 0, TYP_BMAPBTD }, + { "rightsib", FLDT_DFSBNO, OI(OFF(rightsib)), C1, 0, TYP_BMAPBTD }, + { "recs", FLDT_BMAPBTDREC, btblock_rec_offset, btblock_rec_count, + FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_NONE }, + { "keys", FLDT_BMAPBTDKEY, btblock_key_offset, btblock_key_count, + FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_NONE }, + { "ptrs", FLDT_BMAPBTDPTR, btblock_ptr_offset, btblock_key_count, + FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_BMAPBTD }, + { NULL } +}; +#undef OFF + +#define KOFF(f) bitize(offsetof(xfs_bmbt_key_t, br_ ## f)) +const field_t bmapbta_key_flds[] = { + { "startoff", FLDT_DFILOFFA, OI(KOFF(startoff)), C1, 0, TYP_ATTR }, + { NULL } +}; +const field_t bmapbtd_key_flds[] = { + { "startoff", FLDT_DFILOFFD, OI(KOFF(startoff)), C1, 0, TYP_INODATA }, + { NULL } +}; +#undef KOFF + +#ifndef XFS_NATIVE_HOST + +#define BMBT_EXNTFLAG_BITOFF 0 +#define BMBT_STARTOFF_BITOFF (BMBT_EXNTFLAG_BITOFF + BMBT_EXNTFLAG_BITLEN) +#define BMBT_STARTBLOCK_BITOFF (BMBT_STARTOFF_BITOFF + BMBT_STARTOFF_BITLEN) +#define BMBT_BLOCKCOUNT_BITOFF \ + (BMBT_STARTBLOCK_BITOFF + BMBT_STARTBLOCK_BITLEN) + +#else + +#define BMBT_EXNTFLAG_BITOFF 63 +#define BMBT_STARTOFF_BITOFF (BMBT_EXNTFLAG_BITOFF - BMBT_STARTOFF_BITLEN) +#define BMBT_STARTBLOCK_BITOFF 85 /* 128 - 43 (other 9 is in first word) */ +#define BMBT_BLOCKCOUNT_BITOFF 64 /* Start of second 64 bit container */ + +#endif /* XFS_NATIVE_HOST */ + +const field_t bmapbta_rec_flds[] = { + { "startoff", FLDT_CFILEOFFA, OI(BMBT_STARTOFF_BITOFF), C1, 0, + TYP_ATTR }, + { "startblock", FLDT_CFSBLOCK, OI(BMBT_STARTBLOCK_BITOFF), C1, 0, + TYP_ATTR }, + { "blockcount", FLDT_CEXTLEN, OI(BMBT_BLOCKCOUNT_BITOFF), C1, 0, + TYP_NONE }, + { "extentflag", FLDT_CEXTFLG, OI(BMBT_EXNTFLAG_BITOFF), C1, 0, + TYP_NONE }, + { NULL } +}; +const field_t bmapbtd_rec_flds[] = { + { "startoff", FLDT_CFILEOFFD, OI(BMBT_STARTOFF_BITOFF), C1, 0, + TYP_INODATA }, + { "startblock", FLDT_CFSBLOCK, OI(BMBT_STARTBLOCK_BITOFF), C1, 0, + TYP_INODATA }, + { "blockcount", FLDT_CEXTLEN, OI(BMBT_BLOCKCOUNT_BITOFF), C1, 0, + TYP_NONE }, + { "extentflag", FLDT_CEXTFLG, OI(BMBT_EXNTFLAG_BITOFF), C1, 0, + TYP_NONE }, + { NULL } +}; + + +/* + * Inode allocation btree. + */ + +const field_t inobt_hfld[] = { + { "", FLDT_INOBT, OI(0), C1, 0, TYP_NONE }, + { NULL } +}; + +#define OFF(f) bitize(offsetof(struct xfs_btree_sblock, bb_ ## f)) +const field_t inobt_flds[] = { + { "magic", FLDT_UINT32X, OI(OFF(magic)), C1, 0, TYP_NONE }, + { "level", FLDT_UINT16D, OI(OFF(level)), C1, 0, TYP_NONE }, + { "numrecs", FLDT_UINT16D, OI(OFF(numrecs)), C1, 0, TYP_NONE }, + { "leftsib", FLDT_AGBLOCK, OI(OFF(leftsib)), C1, 0, TYP_INOBT }, + { "rightsib", FLDT_AGBLOCK, OI(OFF(rightsib)), C1, 0, TYP_INOBT }, + { "recs", FLDT_INOBTREC, btblock_rec_offset, btblock_rec_count, + FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_NONE }, + { "keys", FLDT_INOBTKEY, btblock_key_offset, btblock_key_count, + FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_NONE }, + { "ptrs", FLDT_INOBTPTR, btblock_ptr_offset, btblock_key_count, + FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_INOBT }, + { NULL } +}; +#undef OFF + +#define KOFF(f) bitize(offsetof(xfs_inobt_key_t, ir_ ## f)) +const field_t inobt_key_flds[] = { + { "startino", FLDT_AGINO, OI(KOFF(startino)), C1, 0, TYP_INODE }, + { NULL } +}; +#undef KOFF + +#define ROFF(f) bitize(offsetof(xfs_inobt_rec_t, ir_ ## f)) +const field_t inobt_rec_flds[] = { + { "startino", FLDT_AGINO, OI(ROFF(startino)), C1, 0, TYP_INODE }, + { "freecount", FLDT_INT32D, OI(ROFF(freecount)), C1, 0, TYP_NONE }, + { "free", FLDT_INOFREE, OI(ROFF(free)), C1, 0, TYP_NONE }, + { NULL } +}; +#undef ROFF + + +/* + * Allocation btrees. + */ +const field_t bnobt_hfld[] = { + { "", FLDT_BNOBT, OI(0), C1, 0, TYP_NONE }, + { NULL } +}; + +#define OFF(f) bitize(offsetof(xfs_alloc_block_t, bb_ ## f)) +const field_t bnobt_flds[] = { + { "magic", FLDT_UINT32X, OI(OFF(magic)), C1, 0, TYP_NONE }, + { "level", FLDT_UINT16D, OI(OFF(level)), C1, 0, TYP_NONE }, + { "numrecs", FLDT_UINT16D, OI(OFF(numrecs)), C1, 0, TYP_NONE }, + { "leftsib", FLDT_AGBLOCK, OI(OFF(leftsib)), C1, 0, TYP_BNOBT }, + { "rightsib", FLDT_AGBLOCK, OI(OFF(rightsib)), C1, 0, TYP_BNOBT }, + { "recs", FLDT_BNOBTREC, btblock_rec_offset, btblock_rec_count, + FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_NONE }, + { "keys", FLDT_BNOBTKEY, btblock_key_offset, btblock_key_count, + FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_NONE }, + { "ptrs", FLDT_BNOBTPTR, btblock_ptr_offset, btblock_key_count, + FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_BNOBT }, + { NULL } +}; +#undef OFF + +#define KOFF(f) bitize(offsetof(xfs_alloc_key_t, ar_ ## f)) +const field_t bnobt_key_flds[] = { + { "startblock", FLDT_AGBLOCK, OI(KOFF(startblock)), C1, 0, TYP_DATA }, + { "blockcount", FLDT_EXTLEN, OI(KOFF(blockcount)), C1, 0, TYP_NONE }, + { NULL } +}; +#undef KOFF + +#define ROFF(f) bitize(offsetof(xfs_alloc_rec_t, ar_ ## f)) +const field_t bnobt_rec_flds[] = { + { "startblock", FLDT_AGBLOCK, OI(ROFF(startblock)), C1, 0, TYP_DATA }, + { "blockcount", FLDT_EXTLEN, OI(ROFF(blockcount)), C1, 0, TYP_NONE }, + { NULL } +}; +#undef ROFF + +const field_t cntbt_hfld[] = { + { "", FLDT_CNTBT, OI(0), C1, 0, TYP_NONE }, + { NULL } +}; + +#define OFF(f) bitize(offsetof(xfs_alloc_block_t, bb_ ## f)) +const field_t cntbt_flds[] = { + { "magic", FLDT_UINT32X, OI(OFF(magic)), C1, 0, TYP_NONE }, + { "level", FLDT_UINT16D, OI(OFF(level)), C1, 0, TYP_NONE }, + { "numrecs", FLDT_UINT16D, OI(OFF(numrecs)), C1, 0, TYP_NONE }, + { "leftsib", FLDT_AGBLOCK, OI(OFF(leftsib)), C1, 0, TYP_CNTBT }, + { "rightsib", FLDT_AGBLOCK, OI(OFF(rightsib)), C1, 0, TYP_CNTBT }, + { "recs", FLDT_CNTBTREC, btblock_rec_offset, btblock_rec_count, + FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_NONE }, + { "keys", FLDT_CNTBTKEY, btblock_key_offset, btblock_key_count, + FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_NONE }, + { "ptrs", FLDT_CNTBTPTR, btblock_ptr_offset, btblock_key_count, + FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_CNTBT }, + { NULL } +}; +#undef OFF + +#define KOFF(f) bitize(offsetof(xfs_alloc_key_t, ar_ ## f)) +const field_t cntbt_key_flds[] = { + { "blockcount", FLDT_EXTLEN, OI(KOFF(blockcount)), C1, 0, TYP_NONE }, + { "startblock", FLDT_AGBLOCK, OI(KOFF(startblock)), C1, 0, TYP_DATA }, + { NULL } +}; +#undef KOFF + +#define ROFF(f) bitize(offsetof(xfs_alloc_rec_t, ar_ ## f)) +const field_t cntbt_rec_flds[] = { + { "startblock", FLDT_AGBLOCK, OI(ROFF(startblock)), C1, 0, TYP_DATA }, + { "blockcount", FLDT_EXTLEN, OI(ROFF(blockcount)), C1, 0, TYP_NONE }, + { NULL } +}; +#undef ROFF diff --git a/db/bmapbt.h b/db/btblock.h similarity index 65% rename from db/bmapbt.h rename to db/btblock.h index f19c4c404..0631e66ea 100644 --- a/db/bmapbt.h +++ b/db/btblock.h @@ -20,10 +20,25 @@ extern const struct field bmapbta_flds[]; extern const struct field bmapbta_hfld[]; extern const struct field bmapbta_key_flds[]; extern const struct field bmapbta_rec_flds[]; + extern const struct field bmapbtd_flds[]; extern const struct field bmapbtd_hfld[]; extern const struct field bmapbtd_key_flds[]; extern const struct field bmapbtd_rec_flds[]; -extern int bmapbta_size(void *obj, int startoff, int idx); -extern int bmapbtd_size(void *obj, int startoff, int idx); +extern const struct field inobt_flds[]; +extern const struct field inobt_hfld[]; +extern const struct field inobt_key_flds[]; +extern const struct field inobt_rec_flds[]; + +extern const struct field bnobt_flds[]; +extern const struct field bnobt_hfld[]; +extern const struct field bnobt_key_flds[]; +extern const struct field bnobt_rec_flds[]; + +extern const struct field cntbt_flds[]; +extern const struct field cntbt_hfld[]; +extern const struct field cntbt_key_flds[]; +extern const struct field cntbt_rec_flds[]; + +extern int btblock_size(void *obj, int startoff, int idx); diff --git a/db/check.c b/db/check.c index 74147e644..62865ea27 100644 --- a/db/check.c +++ b/db/check.c @@ -2689,6 +2689,12 @@ process_inode( } return; } + if (be32_to_cpu(dip->di_next_unlinked) != NULLAGINO) { + if (!sflag || isfree || id->ilist || CHECK_BLIST(bno)) + dbprintf("bad next unlinked %#x for inode %lld\n", + be32_to_cpu(dip->di_next_unlinked), ino); + error++; + } /* * di_mode is a 16-bit uint so no need to check the < 0 case */ diff --git a/db/cntbt.c b/db/cntbt.c deleted file mode 100644 index aa21428d1..000000000 --- a/db/cntbt.c +++ /dev/null @@ -1,176 +0,0 @@ -/* - * Copyright (c) 2000-2001,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 -#include "type.h" -#include "faddr.h" -#include "fprint.h" -#include "field.h" -#include "cntbt.h" -#include "print.h" -#include "bit.h" -#include "init.h" - -static int cntbt_key_count(void *obj, int startoff); -static int cntbt_key_offset(void *obj, int startoff, int idx); -static int cntbt_ptr_count(void *obj, int startoff); -static int cntbt_ptr_offset(void *obj, int startoff, int idx); -static int cntbt_rec_count(void *obj, int startoff); -static int cntbt_rec_offset(void *obj, int startoff, int idx); - -const field_t cntbt_hfld[] = { - { "", FLDT_CNTBT, OI(0), C1, 0, TYP_NONE }, - { NULL } -}; - -#define OFF(f) bitize(offsetof(xfs_alloc_block_t, bb_ ## f)) -const field_t cntbt_flds[] = { - { "magic", FLDT_UINT32X, OI(OFF(magic)), C1, 0, TYP_NONE }, - { "level", FLDT_UINT16D, OI(OFF(level)), C1, 0, TYP_NONE }, - { "numrecs", FLDT_UINT16D, OI(OFF(numrecs)), C1, 0, TYP_NONE }, - { "leftsib", FLDT_AGBLOCK, OI(OFF(leftsib)), C1, 0, TYP_CNTBT }, - { "rightsib", FLDT_AGBLOCK, OI(OFF(rightsib)), C1, 0, TYP_CNTBT }, - { "recs", FLDT_CNTBTREC, cntbt_rec_offset, cntbt_rec_count, - FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_NONE }, - { "keys", FLDT_CNTBTKEY, cntbt_key_offset, cntbt_key_count, - FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_NONE }, - { "ptrs", FLDT_CNTBTPTR, cntbt_ptr_offset, cntbt_ptr_count, - FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_CNTBT }, - { NULL } -}; - -#define KOFF(f) bitize(offsetof(xfs_alloc_key_t, ar_ ## f)) -const field_t cntbt_key_flds[] = { - { "blockcount", FLDT_EXTLEN, OI(KOFF(blockcount)), C1, 0, TYP_NONE }, - { "startblock", FLDT_AGBLOCK, OI(KOFF(startblock)), C1, 0, TYP_DATA }, - { NULL } -}; - -#define ROFF(f) bitize(offsetof(xfs_alloc_rec_t, ar_ ## f)) -const field_t cntbt_rec_flds[] = { - { "startblock", FLDT_AGBLOCK, OI(ROFF(startblock)), C1, 0, TYP_DATA }, - { "blockcount", FLDT_EXTLEN, OI(ROFF(blockcount)), C1, 0, TYP_NONE }, - { NULL } -}; - -/*ARGSUSED*/ -static int -cntbt_key_count( - void *obj, - int startoff) -{ - xfs_alloc_block_t *block; - - ASSERT(startoff == 0); - block = obj; - if (be16_to_cpu(block->bb_level) == 0) - return 0; - return be16_to_cpu(block->bb_numrecs); -} - -/*ARGSUSED*/ -static int -cntbt_key_offset( - void *obj, - int startoff, - int idx) -{ - xfs_alloc_block_t *block; - xfs_alloc_key_t *kp; - - ASSERT(startoff == 0); - block = obj; - ASSERT(be16_to_cpu(block->bb_level) > 0); - kp = XFS_BTREE_KEY_ADDR(xfs_alloc, block, idx); - return bitize((int)((char *)kp - (char *)block)); -} - -/*ARGSUSED*/ -static int -cntbt_ptr_count( - void *obj, - int startoff) -{ - xfs_alloc_block_t *block; - - ASSERT(startoff == 0); - block = obj; - if (be16_to_cpu(block->bb_level) == 0) - return 0; - return be16_to_cpu(block->bb_numrecs); -} - -/*ARGSUSED*/ -static int -cntbt_ptr_offset( - void *obj, - int startoff, - int idx) -{ - xfs_alloc_block_t *block; - xfs_alloc_ptr_t *pp; - - ASSERT(startoff == 0); - block = obj; - ASSERT(be16_to_cpu(block->bb_level) > 0); - pp = XFS_BTREE_PTR_ADDR(xfs_alloc, block, idx, - XFS_BTREE_BLOCK_MAXRECS(mp->m_sb.sb_blocksize, xfs_alloc, 0)); - return bitize((int)((char *)pp - (char *)block)); -} - -/*ARGSUSED*/ -static int -cntbt_rec_count( - void *obj, - int startoff) -{ - xfs_alloc_block_t *block; - - ASSERT(startoff == 0); - block = obj; - if (be16_to_cpu(block->bb_level) > 0) - return 0; - return be16_to_cpu(block->bb_numrecs); -} - -/*ARGSUSED*/ -static int -cntbt_rec_offset( - void *obj, - int startoff, - int idx) -{ - xfs_alloc_block_t *block; - xfs_alloc_rec_t *rp; - - ASSERT(startoff == 0); - block = obj; - ASSERT(be16_to_cpu(block->bb_level) == 0); - rp = XFS_BTREE_REC_ADDR(xfs_alloc, block, idx); - return bitize((int)((char *)rp - (char *)block)); -} - -/*ARGSUSED*/ -int -cntbt_size( - void *obj, - int startoff, - int idx) -{ - return bitize(mp->m_sb.sb_blocksize); -} diff --git a/db/cntbt.h b/db/cntbt.h deleted file mode 100644 index d5accccf0..000000000 --- a/db/cntbt.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2000-2001,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 - */ - -extern const struct field cntbt_flds[]; -extern const struct field cntbt_hfld[]; -extern const struct field cntbt_key_flds[]; -extern const struct field cntbt_rec_flds[]; - -extern int cntbt_size(void *obj, int startoff, int idx); diff --git a/db/field.c b/db/field.c index 6e6212b52..5cf97e170 100644 --- a/db/field.c +++ b/db/field.c @@ -22,10 +22,7 @@ #include "fprint.h" #include "field.h" #include "inode.h" -#include "bnobt.h" -#include "cntbt.h" -#include "inobt.h" -#include "bmapbt.h" +#include "btblock.h" #include "bmroot.h" #include "bit.h" #include "agf.h" @@ -87,7 +84,7 @@ const ftattr_t ftattrtab[] = { fa_attrblock, NULL }, { FLDT_ATTRSHORT, "attrshort", NULL, (char *)attr_shortform_flds, attrshort_size, FTARG_SIZE, NULL, attr_shortform_flds }, - { FLDT_BMAPBTA, "bmapbta", NULL, (char *)bmapbta_flds, bmapbta_size, + { FLDT_BMAPBTA, "bmapbta", NULL, (char *)bmapbta_flds, btblock_size, FTARG_SIZE, NULL, bmapbta_flds }, { FLDT_BMAPBTAKEY, "bmapbtakey", fp_sarray, (char *)bmapbta_key_flds, SI(bitsz(xfs_bmbt_key_t)), 0, NULL, bmapbta_key_flds }, @@ -95,7 +92,7 @@ const ftattr_t ftattrtab[] = { SI(bitsz(xfs_bmbt_ptr_t)), 0, fa_dfsbno, NULL }, { FLDT_BMAPBTAREC, "bmapbtarec", fp_sarray, (char *)bmapbta_rec_flds, SI(bitsz(xfs_bmbt_rec_t)), 0, NULL, bmapbta_rec_flds }, - { FLDT_BMAPBTD, "bmapbtd", NULL, (char *)bmapbtd_flds, bmapbtd_size, + { FLDT_BMAPBTD, "bmapbtd", NULL, (char *)bmapbtd_flds, btblock_size, FTARG_SIZE, NULL, bmapbtd_flds }, { FLDT_BMAPBTDKEY, "bmapbtdkey", fp_sarray, (char *)bmapbtd_key_flds, SI(bitsz(xfs_bmbt_key_t)), 0, NULL, bmapbtd_key_flds }, @@ -115,7 +112,7 @@ const ftattr_t ftattrtab[] = { SI(bitsz(xfs_bmdr_key_t)), 0, NULL, bmrootd_key_flds }, { FLDT_BMROOTDPTR, "bmrootdptr", fp_num, "%llu", SI(bitsz(xfs_bmdr_ptr_t)), 0, fa_dfsbno, NULL }, - { FLDT_BNOBT, "bnobt", NULL, (char *)bnobt_flds, bnobt_size, FTARG_SIZE, + { FLDT_BNOBT, "bnobt", NULL, (char *)bnobt_flds, btblock_size, FTARG_SIZE, NULL, bnobt_flds }, { FLDT_BNOBTKEY, "bnobtkey", fp_sarray, (char *)bnobt_key_flds, SI(bitsz(xfs_alloc_key_t)), 0, NULL, bnobt_key_flds }, @@ -136,7 +133,7 @@ const ftattr_t ftattrtab[] = { { FLDT_CHARNS, "charns", fp_charns, NULL, SI(bitsz(char)), 0, NULL, NULL }, { FLDT_CHARS, "chars", fp_num, "%c", SI(bitsz(char)), 0, NULL, NULL }, - { FLDT_CNTBT, "cntbt", NULL, (char *)cntbt_flds, cntbt_size, FTARG_SIZE, + { FLDT_CNTBT, "cntbt", NULL, (char *)cntbt_flds, btblock_size, FTARG_SIZE, NULL, cntbt_flds }, { FLDT_CNTBTKEY, "cntbtkey", fp_sarray, (char *)cntbt_key_flds, SI(bitsz(xfs_alloc_key_t)), 0, NULL, cntbt_key_flds }, @@ -247,7 +244,7 @@ const ftattr_t ftattrtab[] = { FTARG_SIGNED, NULL, NULL }, { FLDT_INO, "ino", fp_num, "%llu", SI(bitsz(xfs_ino_t)), FTARG_DONULL, fa_ino, NULL }, - { FLDT_INOBT, "inobt", NULL, (char *)inobt_flds, inobt_size, + { FLDT_INOBT, "inobt", NULL, (char *)inobt_flds, btblock_size, FTARG_SIZE, NULL, inobt_flds }, { FLDT_INOBTKEY, "inobtkey", fp_sarray, (char *)inobt_key_flds, SI(bitsz(xfs_inobt_key_t)), 0, NULL, inobt_key_flds }, diff --git a/db/fprint.c b/db/fprint.c index b6738555d..2e60f9378 100644 --- a/db/fprint.c +++ b/db/fprint.c @@ -24,7 +24,7 @@ #include "fprint.h" #include "field.h" #include "inode.h" -#include "inobt.h" +#include "btblock.h" #include "bit.h" #include "print.h" #include "output.h" diff --git a/db/inobt.c b/db/inobt.c deleted file mode 100644 index ef2cd7086..000000000 --- a/db/inobt.c +++ /dev/null @@ -1,176 +0,0 @@ -/* - * Copyright (c) 2000-2001,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 -#include "type.h" -#include "faddr.h" -#include "fprint.h" -#include "field.h" -#include "inobt.h" -#include "print.h" -#include "bit.h" -#include "init.h" - -static int inobt_key_count(void *obj, int startoff); -static int inobt_key_offset(void *obj, int startoff, int idx); -static int inobt_ptr_count(void *obj, int startoff); -static int inobt_ptr_offset(void *obj, int startoff, int idx); -static int inobt_rec_count(void *obj, int startoff); -static int inobt_rec_offset(void *obj, int startoff, int idx); - -const field_t inobt_hfld[] = { - { "", FLDT_INOBT, OI(0), C1, 0, TYP_NONE }, - { NULL } -}; - -#define OFF(f) bitize(offsetof(xfs_inobt_block_t, bb_ ## f)) -const field_t inobt_flds[] = { - { "magic", FLDT_UINT32X, OI(OFF(magic)), C1, 0, TYP_NONE }, - { "level", FLDT_UINT16D, OI(OFF(level)), C1, 0, TYP_NONE }, - { "numrecs", FLDT_UINT16D, OI(OFF(numrecs)), C1, 0, TYP_NONE }, - { "leftsib", FLDT_AGBLOCK, OI(OFF(leftsib)), C1, 0, TYP_INOBT }, - { "rightsib", FLDT_AGBLOCK, OI(OFF(rightsib)), C1, 0, TYP_INOBT }, - { "recs", FLDT_INOBTREC, inobt_rec_offset, inobt_rec_count, - FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_NONE }, - { "keys", FLDT_INOBTKEY, inobt_key_offset, inobt_key_count, - FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_NONE }, - { "ptrs", FLDT_INOBTPTR, inobt_ptr_offset, inobt_ptr_count, - FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_INOBT }, - { NULL } -}; - -#define KOFF(f) bitize(offsetof(xfs_inobt_key_t, ir_ ## f)) -const field_t inobt_key_flds[] = { - { "startino", FLDT_AGINO, OI(KOFF(startino)), C1, 0, TYP_INODE }, - { NULL } -}; - -#define ROFF(f) bitize(offsetof(xfs_inobt_rec_t, ir_ ## f)) -const field_t inobt_rec_flds[] = { - { "startino", FLDT_AGINO, OI(ROFF(startino)), C1, 0, TYP_INODE }, - { "freecount", FLDT_INT32D, OI(ROFF(freecount)), C1, 0, TYP_NONE }, - { "free", FLDT_INOFREE, OI(ROFF(free)), C1, 0, TYP_NONE }, - { NULL } -}; - -/*ARGSUSED*/ -static int -inobt_key_count( - void *obj, - int startoff) -{ - xfs_inobt_block_t *block; - - ASSERT(startoff == 0); - block = obj; - if (be16_to_cpu(block->bb_level) == 0) - return 0; - return be16_to_cpu(block->bb_numrecs); -} - -/*ARGSUSED*/ -static int -inobt_key_offset( - void *obj, - int startoff, - int idx) -{ - xfs_inobt_block_t *block; - xfs_inobt_key_t *kp; - - ASSERT(startoff == 0); - block = obj; - ASSERT(be16_to_cpu(block->bb_level) > 0); - kp = XFS_BTREE_KEY_ADDR(xfs_inobt, block, idx); - return bitize((int)((char *)kp - (char *)block)); -} - -/*ARGSUSED*/ -static int -inobt_ptr_count( - void *obj, - int startoff) -{ - xfs_inobt_block_t *block; - - ASSERT(startoff == 0); - block = obj; - if (be16_to_cpu(block->bb_level) == 0) - return 0; - return be16_to_cpu(block->bb_numrecs); -} - -/*ARGSUSED*/ -static int -inobt_ptr_offset( - void *obj, - int startoff, - int idx) -{ - xfs_inobt_block_t *block; - xfs_inobt_ptr_t *pp; - - ASSERT(startoff == 0); - block = obj; - ASSERT(be16_to_cpu(block->bb_level) > 0); - pp = XFS_BTREE_PTR_ADDR(xfs_inobt, block, idx, - XFS_BTREE_BLOCK_MAXRECS(mp->m_sb.sb_blocksize, xfs_inobt, 0)); - return bitize((int)((char *)pp - (char *)block)); -} - -/*ARGSUSED*/ -static int -inobt_rec_count( - void *obj, - int startoff) -{ - xfs_inobt_block_t *block; - - ASSERT(startoff == 0); - block = obj; - if (be16_to_cpu(block->bb_level) > 0) - return 0; - return be16_to_cpu(block->bb_numrecs); -} - -/*ARGSUSED*/ -static int -inobt_rec_offset( - void *obj, - int startoff, - int idx) -{ - xfs_inobt_block_t *block; - xfs_inobt_rec_t *rp; - - ASSERT(startoff == 0); - block = obj; - ASSERT(be16_to_cpu(block->bb_level) == 0); - rp = XFS_BTREE_REC_ADDR(xfs_inobt, block, idx); - return bitize((int)((char *)rp - (char *)block)); -} - -/*ARGSUSED*/ -int -inobt_size( - void *obj, - int startoff, - int idx) -{ - return bitize(mp->m_sb.sb_blocksize); -} diff --git a/db/inobt.h b/db/inobt.h deleted file mode 100644 index dfdf56d2d..000000000 --- a/db/inobt.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2000-2001,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 - */ - -extern const struct field inobt_flds[]; -extern const struct field inobt_hfld[]; -extern const struct field inobt_key_flds[]; -extern const struct field inobt_rec_flds[]; - -extern int inobt_size(void *obj, int startoff, int idx); diff --git a/db/type.c b/db/type.c index a23e66c63..9c2b1d7f4 100644 --- a/db/type.c +++ b/db/type.c @@ -26,10 +26,7 @@ #include "print.h" #include "sb.h" #include "inode.h" -#include "bnobt.h" -#include "cntbt.h" -#include "inobt.h" -#include "bmapbt.h" +#include "btblock.h" #include "bmroot.h" #include "agf.h" #include "agfl.h"