about summary refs log tree commit diff
path: root/db2/db/db_pr.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>1997-08-27 20:26:10 +0000
committerUlrich Drepper <drepper@redhat.com>1997-08-27 20:26:10 +0000
commit92f1da4da04a7a86ddee91be5eaf0b10c333ac64 (patch)
tree2a10ce9e4e407e7e5b5ca092ca0947d234b5ff60 /db2/db/db_pr.c
parent22be878ecbc66606371bd33258f56e6711e6ba7a (diff)
downloadglibc-92f1da4da04a7a86ddee91be5eaf0b10c333ac64.tar.gz
glibc-92f1da4da04a7a86ddee91be5eaf0b10c333ac64.tar.xz
glibc-92f1da4da04a7a86ddee91be5eaf0b10c333ac64.zip
1997-08-10 19:17  Philip Blundell  <Philip.Blundell@pobox.com>

	* nss/nss_db/db-XXX.c: Include <db_185.h> not <db.h>.  Somebody
	should update this to use the new db API.
	* nss/nss_db/db-netgrp.c: Likewise.
	* nss/nss_db/db-alias.c: Likewise.
	* db2/Makefile: Makefile for db-2.x in glibc.

1997-08-27 21:20  Ulrich Drepper  <drepper@cygnus.com>

	* csu/Makefile (before-compile): New goal.  Make sure abi-tag.h
	is generated.
	[$(elf)=yes] (asm-CPPFLAGS): Make sure abi-tag.h file can be found.

	* Makeconfig [$(build-omitfp)=yes] (CFLAGS-.o): Add
	-D__USE_STRING_INLINES.
	* string/string.f: Move strnlen optimization after inclusion of
	<bits/string.h>.  Include <bits/string.h> only if __USE_STRING_INLINES
	is defined.
	* sysdeps/generic/memcpy.c: Undef memcpy to allow macro of this name
	in <bits/string.h>.
	* sysdeps/generic/memset.c: Likewise.
	* sysdeps/i386/string.h: i386 optimized string functions.
	* sysdeps/i386/i486string.h: i486+ optimized string functions.

	* Makefile (subdirs): Change db to db2.
	* shlib-versions: Bump libdb verion number to 3.
	* include/db.h: Include from db2 directory.
	* include/db_185.h: New file.
	* sysdeps/i386/Makefile [$(subdirs)=db2] (CPPFLAGS): Add macros
	to provide spinlock information for db2.
	* sysdeps/m68k/m68020/Makefile: New file.  Likewise.
	* sysdeps/sparc/Makefile: New file.  Likewise.
	* sysdeps/unix/sysv/linux/Makefile [$(subdirs)=db2] (CPPFLAGS):
	Add -DHAVE_LLSEEK.
	* db2/config.h: Hand-edited config file for db2 in glibc.
	* db2/compat.h: New file from db-2.3.4.
	* db2/db.h: Likewise.
	* db2/db_185.h: Likewise.
	* db2/db_int.h: Likewise.
	* db2/makedb.c: Likewise.
	* db2/btree/bt_close.c: Likewise.
	* db2/btree/bt_compare.c: Likewise.
	* db2/btree/bt_conv.c: Likewise.
	* db2/btree/bt_cursor.c: Likewise.
	* db2/btree/bt_delete.c: Likewise.
	* db2/btree/bt_open.c: Likewise.
	* db2/btree/bt_page.c: Likewise.
	* db2/btree/bt_put.c: Likewise.
	* db2/btree/bt_rec.c: Likewise.
	* db2/btree/bt_recno.c: Likewise.
	* db2/btree/btree_auto.c: Likewise.
	* db2/btree/bt_rsearch.c: Likewise.
	* db2/btree/bt_search.c: Likewise.
	* db2/btree/bt_split.c: Likewise.
	* db2/btree/bt_stat.c: Likewise.
	* db2/btree/btree.src: Likewise.
	* db2/common/db_appinit.c: Likewise.
	* db2/common/db_err.c: Likewise.
	* db2/common/db_byteorder.c: Likewise.
	* db2/common/db_apprec.c: Likewise.
	* db2/common/db_salloc.c: Likewise.
	* db2/common/db_log2.c: Likewise.
	* db2/common/db_region.c: Likewise.
	* db2/common/db_shash.c: Likewise.
	* db2/db/db.c: Likewise.
	* db2/db/db.src: Likewise.
	* db2/db/db_conv.c: Likewise.
	* db2/db/db_dispatch.c: Likewise.
	* db2/db/db_dup.c: Likewise.
	* db2/db/db_overflow.c: Likewise.
	* db2/db/db_pr.c: Likewise.
	* db2/db/db_rec.c: Likewise.
	* db2/db/db_ret.c: Likewise.
	* db2/db/db_thread.c: Likewise.
	* db2/db/db_auto.c: Likewise.
	* db2/db185/db185.c: Likewise.
	* db2/db185/db185_int.h: Likewise.
	* db2/dbm/dbm.c: Likewise.
	* db2/hash/hash.c: Likewise.
	* db2/hash/hash.src: Likewise.
	* db2/hash/hash_page.c: Likewise.
	* db2/hash/hash_conv.c: Likewise.
	* db2/hash/hash_debug.c: Likewise.
	* db2/hash/hash_stat.c: Likewise.
	* db2/hash/hash_rec.c: Likewise.
	* db2/hash/hash_dup.c: Likewise.
	* db2/hash/hash_func.c: Likewise.
	* db2/hash/hash_auto.c: Likewise.
	* db2/include/mp.h: Likewise.
	* db2/include/btree.h: Likewise.
	* db2/include/db.h.src: Likewise.
	* db2/include/db_int.h.src: Likewise.
	* db2/include/db_shash.h: Likewise.
	* db2/include/db_swap.h: Likewise.
	* db2/include/db_185.h.src: Likewise.
	* db2/include/txn.h: Likewise.
	* db2/include/db_am.h: Likewise.
	* db2/include/shqueue.h: Likewise.
	* db2/include/hash.h: Likewise.
	* db2/include/db_dispatch.h: Likewise.
	* db2/include/lock.h: Likewise.
	* db2/include/db_page.h: Likewise.
	* db2/include/log.h: Likewise.
	* db2/include/db_auto.h: Likewise.
	* db2/include/btree_auto.h: Likewise.
	* db2/include/hash_auto.h: Likewise.
	* db2/include/log_auto.h: Likewise.
	* db2/include/txn_auto.h: Likewise.
	* db2/include/db_ext.h: Likewise.
	* db2/include/btree_ext.h: Likewise.
	* db2/include/clib_ext.h: Likewise.
	* db2/include/common_ext.h: Likewise.
	* db2/include/hash_ext.h: Likewise.
	* db2/include/lock_ext.h: Likewise.
	* db2/include/log_ext.h: Likewise.
	* db2/include/mp_ext.h: Likewise.
	* db2/include/mutex_ext.h: Likewise.
	* db2/include/os_ext.h: Likewise.
	* db2/include/txn_ext.h: Likewise.
	* db2/include/cxx_int.h: Likewise.
	* db2/include/db_cxx.h: Likewise.
	* db2/include/queue.h: Likewise.
	* db2/lock/lock.c: Likewise.
	* db2/lock/lock_conflict.c: Likewise.
	* db2/lock/lock_util.c: Likewise.
	* db2/lock/lock_deadlock.c: Likewise.
	* db2/log/log.c: Likewise.
	* db2/log/log_get.c: Likewise.
	* db2/log/log.src: Likewise.
	* db2/log/log_compare.c: Likewise.
	* db2/log/log_put.c: Likewise.
	* db2/log/log_rec.c: Likewise.
	* db2/log/log_archive.c: Likewise.
	* db2/log/log_register.c: Likewise.
	* db2/log/log_auto.c: Likewise.
	* db2/log/log_findckp.c: Likewise.
	* db2/mp/mp_bh.c: Likewise.
	* db2/mp/mp_fget.c: Likewise.
	* db2/mp/mp_fopen.c: Likewise.
	* db2/mp/mp_fput.c: Likewise.
	* db2/mp/mp_fset.c: Likewise.
	* db2/mp/mp_open.c: Likewise.
	* db2/mp/mp_region.c: Likewise.
	* db2/mp/mp_pr.c: Likewise.
	* db2/mp/mp_sync.c: Likewise.
	* db2/mutex/68020.gcc: Likewise.
	* db2/mutex/mutex.c: Likewise.
	* db2/mutex/README: Likewise.
	* db2/mutex/x86.gcc: Likewise.
	* db2/mutex/sparc.gcc: Likewise.
	* db2/mutex/uts4.cc.s: Likewise.
	* db2/mutex/alpha.dec: Likewise.
	* db2/mutex/alpha.gcc: Likewise.
	* db2/mutex/parisc.gcc: Likewise.
	* db2/mutex/parisc.hp: Likewise.
	* db2/os/db_os_abs.c: Likewise.
	* db2/os/db_os_dir.c: Likewise.
	* db2/os/db_os_fid.c: Likewise.
	* db2/os/db_os_lseek.c: Likewise.
	* db2/os/db_os_mmap.c: Likewise.
	* db2/os/db_os_open.c: Likewise.
	* db2/os/db_os_rw.c: Likewise.
	* db2/os/db_os_sleep.c: Likewise.
	* db2/os/db_os_stat.c: Likewise.
	* db2/os/db_os_unlink.c: Likewise.
	* db2/txn/txn.c: Likewise.
	* db2/txn/txn.src: Likewise.
	* db2/txn/txn_rec.c: Likewise.
	* db2/txn/txn_auto.c: Likewise.
	* db2/clib/getlong.c: Likewise.
	* db2/progs/db_archive/db_archive.c: Likewise.
	* db2/progs/db_checkpoint/db_checkpoint.c: Likewise.
	* db2/progs/db_deadlock/db_deadlock.c: Likewise.
	* db2/progs/db_dump/db_dump.c: Likewise.
	* db2/progs/db_dump185/db_dump185.c: Likewise.
	* db2/progs/db_load/db_load.c: Likewise.
	* db2/progs/db_printlog/db_printlog.c: Likewise.
	* db2/progs/db_recover/db_recover.c: Likewise.
	* db2/progs/db_stat/db_stat.c: Likewise.

	* libio/stdio.h [__cplusplus] (__STDIO_INLINE): Define as inline.

	* po/de.po, po/sv.po: Update from 2.0.5 translations.

	* sysdeps/unix/sysv/linux/netinet/tcp.h: Pretty print.

	* sunrpc/rpc/xdr.h (XDR): Don't define argument of x_destroy callback
	as const.
	* sunrpc/xdr_mem.c (xdrmem_destroy): Don't define argument as const.
	* sunrpx/xdr_rec.c (xdrrec_destroy): Likewise.
	* sunrpx/xdr_stdio.c (xdrstdio_destroy): Likewise.

1997-08-27 18:47  Ulrich Drepper  <drepper@cygnus.com>

	* sysdeps/unix/sysv/linux/if_index.c: Include <errno.h>.
	Reported by Benjamin Kosnik <bkoz@cygnus.com>.

1997-08-27 02:27  Roland McGrath  <roland@baalperazim.frob.com>

	* abi-tags: New file.
	* csu/Makefile (distribute): Remove abi-tag.h.
	($(objpfx)abi-tag.h): New target.
	* Makefile (distribute): Add abi-tags.
	* sysdeps/unix/sysv/linux/abi-tag.h: File removed.
	* sysdeps/mach/hurd/abi-tag.h: File removed.
	* sysdeps/stub/abi-tag.h: File removed.

1997-08-25  Andreas Schwab  <schwab@issan.informatik.uni-dortmund.de>

	* sysdeps/unix/make-syscalls.sh: Change output so that it
	generates compilation rules only for the currently selected object
	suffixes.

1997-08-25  Andreas Schwab  <schwab@issan.informatik.uni-dortmund.de>

	* sysdeps/m68k/dl-machine.h (RTLD_START): Switch back to previous
	section to avoid confusing the compiler.
	* sysdeps/alpha/dl-machine.h (RTLD_START): Likewise.
	* sysdeps/i386/dl-machine.h (RTLD_START): Likewise.
	* sysdeps/mips/dl-machine.h (RTLD_START): Likewise.
	* sysdeps/mips/mips64/dl-machine.h (RTLD_START): Likewise.
	* sysdeps/sparc/sparc32/dl-machine.h (RTLD_START): Likewise.

	* sysdeps/m68k/dl-machine.h (elf_machine_load_address): Use a GOT
	relocation instead of a constant to avoid text relocation.
	(ELF_MACHINE_BEFORE_RTLD_RELOC): Removed.
	(RTLD_START): Declare global labels as functions and add size
	directive.

1997-08-25 17:01  Ulrich Drepper  <drepper@cygnus.com>

	* sysdeps/i386/bits/select.h: Correct assembler versions to work even
	for descriptors >= 32.

	* stdlib/alloca.h: Don't define alloca to __alloca since if gcc
	is used __alloca is not defined to __builtin_alloca and so might
	not be available.
	Reported by Uwe Ohse <uwe@ohse.de>.

	* sysdeps/unix/sysv/linux/sys/sysmacros.h: Define macros in a special
	way if gcc is not used and so dev_t is an array.
	Reported by Uwe Ohse <uwe@ohse.de>.

1997-08-23  Andreas Schwab  <schwab@issan.informatik.uni-dortmund.de>

	* manual/libc.texinfo: Reorder chapters to match logical order.

1997-08-25 12:22  Ulrich Drepper  <drepper@cygnus.com>

	* sunrpc/rpc/xdr.h: Change name of parameters in prototypes of
	xdr_reference, xdrmem_create, and xdrstdio_create because of clash
	with g++ internal symbols.
	Patch by Sudish Joseph <sj@eng.mindspring.net>.

	* elf/dl-deps.c: Implement handling of DT_FILTER.
Diffstat (limited to 'db2/db/db_pr.c')
-rw-r--r--db2/db/db_pr.c785
1 files changed, 785 insertions, 0 deletions
diff --git a/db2/db/db_pr.c b/db2/db/db_pr.c
new file mode 100644
index 0000000000..c103b10e4f
--- /dev/null
+++ b/db2/db/db_pr.c
@@ -0,0 +1,785 @@
+/*-
+ * See the file LICENSE for redistribution information.
+ *
+ * Copyright (c) 1996, 1997
+ *	Sleepycat Software.  All rights reserved.
+ */
+
+#include "config.h"
+
+#ifndef lint
+static const char sccsid[] = "@(#)db_pr.c	10.14 (Sleepycat) 8/17/97";
+#endif /* not lint */
+
+#ifndef NO_SYSTEM_INCLUDES
+#include <sys/types.h>
+
+#include <ctype.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#endif
+
+#include "db_int.h"
+#include "db_page.h"
+#include "btree.h"
+#include "hash.h"
+#include "db_am.h"
+
+static void __db_proff __P((void *));
+static void __db_psize __P((DB_MPOOLFILE *));
+
+/*
+ * __db_loadme --
+ *	Force loading of this file.
+ *
+ * PUBLIC: void __db_loadme __P((void));
+ */
+void
+__db_loadme()
+{
+	getpid();
+}
+
+static FILE *set_fp;
+
+/*
+ * 64K is the maximum page size, so by default we check for offsets
+ * larger than that, and, where possible, we refine the test.
+ */
+#define	PSIZE_BOUNDARY	(64 * 1024 + 1)
+static size_t set_psize = PSIZE_BOUNDARY;
+
+/*
+ * __db_prinit --
+ *	Initialize tree printing routines.
+ *
+ * PUBLIC: FILE *__db_prinit __P((FILE *));
+ */
+FILE *
+__db_prinit(fp)
+	FILE *fp;
+{
+	if (set_fp == NULL)
+		set_fp = fp == NULL ? stdout : fp;
+	return (set_fp);
+}
+
+/*
+ * __db_dump --
+ *	Dump the tree to a file.
+ *
+ * PUBLIC: int __db_dump __P((DB *, char *, int));
+ */
+int
+__db_dump(dbp, name, all)
+	DB *dbp;
+	char *name;
+	int all;
+{
+	FILE *fp, *save_fp;
+
+	save_fp = NULL;				/* XXX: Shut the compiler up. */
+
+	if (set_psize == PSIZE_BOUNDARY)
+		__db_psize(dbp->mpf);
+
+	if (name != NULL) {
+		if ((fp = fopen(name, "w")) == NULL)
+			return (errno);
+		save_fp = set_fp;
+		set_fp = fp;
+	} else
+		fp = __db_prinit(NULL);
+
+	(void)__db_prdb(dbp);
+	if (dbp->type == DB_HASH)
+		(void)__db_prhash(dbp);
+	else
+		(void)__db_prbtree(dbp);
+	fprintf(fp, "%s\n", DB_LINE);
+	__db_prtree(dbp->mpf, all);
+
+	if (name != NULL) {
+		(void)fclose(fp);
+		set_fp = save_fp;
+	}
+	return (0);
+}
+
+/*
+ * __db_prdb --
+ *	Print out the DB structure information.
+ *
+ * PUBLIC: int __db_prdb __P((DB *));
+ */
+int
+__db_prdb(dbp)
+	DB *dbp;
+{
+	static const FN fn[] = {
+		{ DB_AM_DUP,		"duplicates" },
+		{ DB_AM_INMEM,		"in-memory" },
+		{ DB_AM_LOCKING,	"locking" },
+		{ DB_AM_LOGGING,	"logging" },
+		{ DB_AM_MLOCAL,		"local mpool" },
+		{ DB_AM_PGDEF,		"default page size" },
+		{ DB_AM_RDONLY,		"read-only" },
+		{ DB_AM_RECOVER,	"recover" },
+		{ DB_AM_SWAP,		"needswap" },
+		{ DB_AM_THREAD,		"thread" },
+		{ DB_BT_RECNUM,		"btree:records" },
+		{ DB_HS_DIRTYMETA,	"hash:dirty-meta" },
+		{ DB_RE_DELIMITER,	"recno:delimiter" },
+		{ DB_RE_FIXEDLEN,	"recno:fixed-length" },
+		{ DB_RE_PAD,		"recno:pad" },
+		{ DB_RE_RENUMBER,	"recno:renumber" },
+		{ DB_RE_SNAPSHOT,	"recno:snapshot" },
+		{ 0 },
+	};
+	FILE *fp;
+	const char *t;
+
+	fp = __db_prinit(NULL);
+
+	switch (dbp->type) {
+	case DB_BTREE:
+		t = "btree";
+		break;
+	case DB_HASH:
+		t = "hash";
+		break;
+	case DB_RECNO:
+		t = "recno";
+		break;
+	default:
+		t = "UNKNOWN";
+		break;
+	}
+
+	fprintf(fp, "%s ", t);
+	__db_prflags(dbp->flags, fn);
+	fprintf(fp, "\n");
+
+	return (0);
+}
+
+/*
+ * __db_prbtree --
+ *	Print out the btree internal information.
+ *
+ * PUBLIC: int __db_prbtree __P((DB *));
+ */
+int
+__db_prbtree(dbp)
+	DB *dbp;
+{
+	static const FN mfn[] = {
+		{ BTM_DUP,	"duplicates" },
+		{ BTM_RECNO,	"recno" },
+		{ 0 },
+	};
+	BTMETA *mp;
+	BTREE *t;
+	DB_LOCK lock;
+	EPG *sp;
+	FILE *fp;
+	RECNO *rp;
+	db_pgno_t i;
+	int ret;
+
+	t = dbp->internal;
+	fp = __db_prinit(NULL);
+
+	(void)fprintf(fp, "%s\nOn-page metadata:\n", DB_LINE);
+	i = PGNO_METADATA;
+	if ((ret = __bam_lget(dbp, 0, PGNO_METADATA, DB_LOCK_READ, &lock)) != 0)
+		return (ret);
+
+	if ((ret = __bam_pget(dbp, (PAGE **)&mp, &i, 0)) != 0)
+		return (ret);
+
+	(void)fprintf(fp, "magic %#lx\n", (u_long)mp->magic);
+	(void)fprintf(fp, "version %lu\n", (u_long)mp->version);
+	(void)fprintf(fp, "pagesize %lu\n", (u_long)mp->pagesize);
+	(void)fprintf(fp, "maxkey: %lu minkey: %lu\n",
+	    (u_long)mp->maxkey, (u_long)mp->minkey);
+	(void)fprintf(fp, "free %lu\n", (u_long)mp->free);
+	(void)fprintf(fp, "flags %lu", (u_long)mp->flags);
+	__db_prflags(mp->flags, mfn);
+	(void)fprintf(fp, "\n");
+	(void)memp_fput(dbp->mpf, mp, 0);
+	(void)__bam_lput(dbp, lock);
+
+	(void)fprintf(fp, "%s\nDB_INFO:\n", DB_LINE);
+	(void)fprintf(fp, "bt_maxkey: %lu bt_minkey: %lu\n",
+	    (u_long)t->bt_maxkey, (u_long)t->bt_minkey);
+	(void)fprintf(fp, "bt_compare: %#lx bt_prefix: %#lx\n",
+	    (u_long)t->bt_compare, (u_long)t->bt_prefix);
+	if ((rp = t->bt_recno) != NULL) {
+		(void)fprintf(fp,
+		    "re_delim: %#lx re_pad: %#lx re_len: %lu re_source: %s\n",
+		    (u_long)rp->re_delim, (u_long)rp->re_pad,
+		    (u_long)rp->re_len,
+		    rp->re_source == NULL ? "" : rp->re_source);
+		(void)fprintf(fp,
+		    "cmap: %#lx smap: %#lx emap: %#lx msize: %lu\n",
+		    (u_long)rp->re_cmap, (u_long)rp->re_smap,
+		    (u_long)rp->re_emap, (u_long)rp->re_msize);
+	}
+	(void)fprintf(fp, "stack:");
+	for (sp = t->bt_stack; sp < t->bt_sp; ++sp)
+		(void)fprintf(fp, " %lu", (u_long)sp->page->pgno);
+	(void)fprintf(fp, "\n");
+	(void)fprintf(fp, "ovflsize: %lu\n", (u_long)t->bt_ovflsize);
+	(void)fflush(fp);
+	return (0);
+}
+
+/*
+ * __db_prhash --
+ *	Print out the hash internal information.
+ *
+ * PUBLIC: int __db_prhash __P((DB *));
+ */
+int
+__db_prhash(dbp)
+	DB *dbp;
+{
+	FILE *fp;
+	HTAB *t;
+	int i, put_page, ret;
+	db_pgno_t pgno;
+
+	t = dbp->internal;
+
+	fp = __db_prinit(NULL);
+
+	fprintf(fp, "\thash_accesses    %lu\n", (u_long)t->hash_accesses);
+	fprintf(fp, "\thash_collisions  %lu\n", (u_long)t->hash_collisions);
+	fprintf(fp, "\thash_expansions  %lu\n", (u_long)t->hash_expansions);
+	fprintf(fp, "\thash_overflows 	%lu\n", (u_long)t->hash_overflows);
+	fprintf(fp, "\thash_bigpages    %lu\n", (u_long)t->hash_bigpages);
+	fprintf(fp, "\n");
+
+	if (t->hdr == NULL) {
+		pgno = PGNO_METADATA;
+		if ((ret = memp_fget(dbp->mpf, &pgno, 0, &t->hdr)) != 0)
+			return (ret);
+		put_page = 1;
+	} else
+		put_page = 0;
+
+	fprintf(fp, "\tmagic      %#lx\n", (u_long)t->hdr->magic);
+	fprintf(fp, "\tversion    %lu\n", (u_long)t->hdr->version);
+	fprintf(fp, "\tpagesize   %lu\n", (u_long)t->hdr->pagesize);
+	fprintf(fp, "\tovfl_point %lu\n", (u_long)t->hdr->ovfl_point);
+	fprintf(fp, "\tlast_freed %lu\n", (u_long)t->hdr->last_freed);
+	fprintf(fp, "\tmax_bucket %lu\n", (u_long)t->hdr->max_bucket);
+	fprintf(fp, "\thigh_mask  %#lx\n", (u_long)t->hdr->high_mask);
+	fprintf(fp, "\tlow_mask   %#lx\n", (u_long)t->hdr->low_mask);
+	fprintf(fp, "\tffactor    %lu\n", (u_long)t->hdr->ffactor);
+	fprintf(fp, "\tnelem      %lu\n", (u_long)t->hdr->nelem);
+	fprintf(fp, "\th_charkey  %#lx\n", (u_long)t->hdr->h_charkey);
+
+	for (i = 0; i < NCACHED; i++)
+		fprintf(fp, "%lu ", (u_long)t->hdr->spares[i]);
+	fprintf(fp, "\n");
+
+	(void)fflush(fp);
+	if (put_page) {
+		(void)memp_fput(dbp->mpf, (PAGE *)t->hdr, 0);
+		t->hdr = NULL;
+	}
+	return (0);
+}
+
+/*
+ * __db_prtree --
+ *	Print out the entire tree.
+ *
+ * PUBLIC: int __db_prtree __P((DB_MPOOLFILE *, int));
+ */
+int
+__db_prtree(mpf, all)
+	DB_MPOOLFILE *mpf;
+	int all;
+{
+	PAGE *h;
+	db_pgno_t i;
+	int ret, t_ret;
+
+	if (set_psize == PSIZE_BOUNDARY)
+		__db_psize(mpf);
+
+	ret = 0;
+	for (i = PGNO_ROOT;; ++i) {
+		if ((ret = memp_fget(mpf, &i, 0, &h)) != 0)
+			break;
+		if (TYPE(h) != P_INVALID)
+			if ((t_ret = __db_prpage(h, all)) != 0 && ret == 0)
+				ret = t_ret;
+		(void)memp_fput(mpf, h, 0);
+	}
+	(void)fflush(__db_prinit(NULL));
+	return (ret);
+}
+
+/*
+ * __db_prnpage
+ *	-- Print out a specific page.
+ *
+ * PUBLIC: int __db_prnpage __P((DB_MPOOLFILE *, db_pgno_t));
+ */
+int
+__db_prnpage(mpf, pgno)
+	DB_MPOOLFILE *mpf;
+	db_pgno_t pgno;
+{
+	PAGE *h;
+	int ret;
+
+	if (set_psize == PSIZE_BOUNDARY)
+		__db_psize(mpf);
+
+	if ((ret = memp_fget(mpf, &pgno, 0, &h)) != 0)
+		return (ret);
+
+	ret = __db_prpage(h, 1);
+	(void)fflush(__db_prinit(NULL));
+
+	(void)memp_fput(mpf, h, 0);
+	return (ret);
+}
+
+/*
+ * __db_prpage
+ *	-- Print out a page.
+ *
+ * PUBLIC: int __db_prpage __P((PAGE *, int));
+ */
+int
+__db_prpage(h, all)
+	PAGE *h;
+	int all;
+{
+	BINTERNAL *bi;
+	BKEYDATA *bk;
+	HKEYDATA *hkd;
+	HOFFPAGE a_hkd;
+	FILE *fp;
+	RINTERNAL *ri;
+	db_indx_t dlen, len, i;
+	db_pgno_t pgno;
+	u_int8_t *p;
+	int deleted, ret;
+	const char *s;
+
+	bi = NULL;				/* XXX: Shut the compiler up. */
+	bk = NULL;
+	hkd = NULL;
+	ri = NULL;
+
+	fp = __db_prinit(NULL);
+
+	switch (TYPE(h)) {
+	case P_DUPLICATE:
+		s = "duplicate";
+		break;
+	case P_HASH:
+		s = "hash";
+		break;
+	case P_IBTREE:
+		s = "btree internal";
+		break;
+	case P_INVALID:
+		s = "invalid";
+		break;
+	case P_IRECNO:
+		s = "recno internal";
+		break;
+	case P_LBTREE:
+		s = "btree leaf";
+		break;
+	case P_LRECNO:
+		s = "recno leaf";
+		break;
+	case P_OVERFLOW:
+		s = "overflow";
+		break;
+	default:
+		fprintf(fp, "ILLEGAL PAGE TYPE: page: %lu type: %lu\n",
+		    (u_long)h->pgno, (u_long)TYPE(h));
+			return (1);
+	}
+	fprintf(fp, "page %4lu: (%s)\n", (u_long)h->pgno, s);
+	fprintf(fp, "    lsn.file: %lu lsn.offset: %lu",
+	    (u_long)LSN(h).file, (u_long)LSN(h).offset);
+	if (TYPE(h) == P_IBTREE || TYPE(h) == P_IRECNO ||
+	    (TYPE(h) == P_LRECNO && h->pgno == PGNO_ROOT))
+		fprintf(fp, " total records: %4lu", (u_long)RE_NREC(h));
+	fprintf(fp, "\n");
+	if (TYPE(h) == P_LBTREE || TYPE(h) == P_LRECNO)
+		fprintf(fp, "    prev: %4lu next: %4lu",
+		    (u_long)PREV_PGNO(h), (u_long)NEXT_PGNO(h));
+	if (TYPE(h) == P_IBTREE || TYPE(h) == P_LBTREE)
+		fprintf(fp, " level: %2lu", (u_long)h->level);
+	if (TYPE(h) == P_OVERFLOW) {
+		fprintf(fp, " ref cnt: %4lu ", (u_long)OV_REF(h));
+		__db_pr((u_int8_t *)h + P_OVERHEAD, OV_LEN(h));
+		return (0);
+	}
+	fprintf(fp, " entries: %4lu", (u_long)NUM_ENT(h));
+	fprintf(fp, " offset: %4lu\n", (u_long)HOFFSET(h));
+
+	if (!all || TYPE(h) == P_INVALID)
+		return (0);
+
+	ret = 0;
+	for (i = 0; i < NUM_ENT(h); i++) {
+		if (P_ENTRY(h, i) - (u_int8_t *)h < P_OVERHEAD ||
+		    (size_t)(P_ENTRY(h, i) - (u_int8_t *)h) >= set_psize) {
+			fprintf(fp,
+			    "ILLEGAL PAGE OFFSET: indx: %lu of %lu\n",
+			    (u_long)i, (u_long)h->inp[i]);
+			ret = EINVAL;
+			continue;
+		}
+		deleted = 0;
+		switch (TYPE(h)) {
+		case P_HASH:
+			hkd = GET_HKEYDATA(h, i);
+			break;
+		case P_IBTREE:
+			bi = GET_BINTERNAL(h, i);
+			break;
+		case P_IRECNO:
+			ri = GET_RINTERNAL(h, i);
+			break;
+		case P_LBTREE:
+			bk = GET_BKEYDATA(h, i);
+			deleted = i % 2 == 0 &&
+			    GET_BKEYDATA(h, i + O_INDX)->deleted;
+			break;
+		case P_LRECNO:
+		case P_DUPLICATE:
+			bk = GET_BKEYDATA(h, i);
+			deleted = GET_BKEYDATA(h, i)->deleted;
+			break;
+		default:
+			fprintf(fp,
+			    "ILLEGAL PAGE ITEM: %lu\n", (u_long)TYPE(h));
+			ret = EINVAL;
+			continue;
+		}
+		fprintf(fp, "   %s[%03lu] %4lu ",
+		    deleted ? "D" : " ", (u_long)i, (u_long)h->inp[i]);
+		switch (TYPE(h)) {
+		case P_HASH:
+			switch (hkd->type) {
+			case H_OFFDUP:
+				memcpy(&pgno,
+				    (u_int8_t *)hkd + SSZ(HOFFDUP, pgno),
+				    sizeof(db_pgno_t));
+				fprintf(fp,
+				    "%4lu [offpage dups]\n", (u_long)pgno);
+				break;
+			case H_DUPLICATE:
+				/*
+				 * If this is the first item on a page, then
+				 * we cannot figure out how long it is, so
+				 * we only print the first one in the duplicate
+				 * set.
+				 */
+				if (i != 0)
+					len = LEN_HKEYDATA(h, 0, i);
+				else
+					len = 1;
+
+				fprintf(fp, "Duplicates:\n");
+				for (p = hkd->data; p < hkd->data + len;) {
+					memcpy(&dlen, p, sizeof(db_indx_t));
+					p += sizeof(db_indx_t);
+					fprintf(fp, "\t\t");
+					__db_pr(p, dlen);
+					p += sizeof(db_indx_t) + dlen;
+				}
+				break;
+			case H_KEYDATA:
+				if (i != 0)
+					__db_pr(hkd->data,
+					    LEN_HKEYDATA(h, 0, i));
+				else
+					fprintf(fp, "%s\n", hkd->data);
+				break;
+			case H_OFFPAGE:
+				memcpy(&a_hkd, hkd, HOFFPAGE_SIZE);
+				fprintf(fp,
+				    "overflow: total len: %4lu page: %4lu\n",
+				    (u_long)a_hkd.tlen, (u_long)a_hkd.pgno);
+				break;
+			}
+			break;
+		case P_IBTREE:
+			fprintf(fp, "count: %4lu pgno: %4lu ",
+			    (u_long)bi->nrecs, (u_long)bi->pgno);
+			switch (bi->type) {
+			case B_KEYDATA:
+				__db_pr(bi->data, bi->len);
+				break;
+			case B_DUPLICATE:
+			case B_OVERFLOW:
+				__db_proff(bi->data);
+				break;
+			default:
+				fprintf(fp, "ILLEGAL BINTERNAL TYPE: %lu\n",
+				    (u_long)bi->type);
+				ret = EINVAL;
+				break;
+			}
+			break;
+		case P_IRECNO:
+			fprintf(fp, "entries %4lu pgno %4lu\n",
+			    (u_long)ri->nrecs, (u_long)ri->pgno);
+			break;
+		case P_LBTREE:
+		case P_LRECNO:
+		case P_DUPLICATE:
+			switch (bk->type) {
+			case B_KEYDATA:
+				__db_pr(bk->data, bk->len);
+				break;
+			case B_DUPLICATE:
+			case B_OVERFLOW:
+				__db_proff(bk);
+				break;
+			default:
+				fprintf(fp,
+			    "ILLEGAL DUPLICATE/LBTREE/LRECNO TYPE: %lu\n",
+				    (u_long)bk->type);
+				ret = EINVAL;
+				break;
+			}
+			break;
+		}
+	}
+	(void)fflush(fp);
+	return (ret);
+}
+
+/*
+ * __db_isbad
+ *	-- Decide if a page is corrupted.
+ *
+ * PUBLIC: int __db_isbad __P((PAGE *, int));
+ */
+int
+__db_isbad(h, die)
+	PAGE *h;
+	int die;
+{
+	BINTERNAL *bi;
+	BKEYDATA *bk;
+	HKEYDATA *hkd;
+	FILE *fp;
+	db_indx_t i;
+
+	bi = NULL;				/* XXX: Shut the compiler up. */
+	bk = NULL;
+	hkd = NULL;
+
+	fp = __db_prinit(NULL);
+
+	switch (TYPE(h)) {
+	case P_DUPLICATE:
+	case P_HASH:
+	case P_IBTREE:
+	case P_INVALID:
+	case P_IRECNO:
+	case P_LBTREE:
+	case P_LRECNO:
+	case P_OVERFLOW:
+		break;
+	default:
+		fprintf(fp, "ILLEGAL PAGE TYPE: page: %lu type: %lu\n",
+		    (u_long)h->pgno, (u_long)TYPE(h));
+		goto bad;
+	}
+
+	for (i = 0; i < NUM_ENT(h); i++) {
+		if (P_ENTRY(h, i) - (u_int8_t *)h < P_OVERHEAD ||
+		    (size_t)(P_ENTRY(h, i) - (u_int8_t *)h) >= set_psize) {
+			fprintf(fp,
+			    "ILLEGAL PAGE OFFSET: indx: %lu of %lu\n",
+			    (u_long)i, (u_long)h->inp[i]);
+			goto bad;
+		}
+		switch (TYPE(h)) {
+		case P_HASH:
+			hkd = GET_HKEYDATA(h, i);
+			if (hkd->type != H_OFFDUP &&
+			    hkd->type != H_DUPLICATE &&
+			    hkd->type != H_KEYDATA &&
+			    hkd->type != H_OFFPAGE) {
+				fprintf(fp, "ILLEGAL HASH TYPE: %lu\n",
+				    (u_long)hkd->type);
+				goto bad;
+			}
+			break;
+		case P_IBTREE:
+			bi = GET_BINTERNAL(h, i);
+			if (bi->type != B_KEYDATA &&
+			    bi->type != B_DUPLICATE &&
+			    bi->type != B_OVERFLOW) {
+				fprintf(fp, "ILLEGAL BINTERNAL TYPE: %lu\n",
+				    (u_long)bi->type);
+				goto bad;
+			}
+			break;
+		case P_IRECNO:
+		case P_LBTREE:
+		case P_LRECNO:
+			break;
+		case P_DUPLICATE:
+			bk = GET_BKEYDATA(h, i);
+			if (bk->type != B_KEYDATA &&
+			    bk->type != B_DUPLICATE &&
+			    bk->type != B_OVERFLOW) {
+				fprintf(fp,
+			    "ILLEGAL DUPLICATE/LBTREE/LRECNO TYPE: %lu\n",
+				    (u_long)bk->type);
+				goto bad;
+			}
+			break;
+		default:
+			fprintf(fp,
+			    "ILLEGAL PAGE ITEM: %lu\n", (u_long)TYPE(h));
+			goto bad;
+		}
+	}
+	return (0);
+
+bad:	if (die) {
+		abort();
+		/* NOTREACHED */
+	}
+	return (1);
+}
+
+/*
+ * __db_pr --
+ *	Print out a data element.
+ *
+ * PUBLIC: void __db_pr __P((u_int8_t *, u_int32_t));
+ */
+void
+__db_pr(p, len)
+	u_int8_t *p;
+	u_int32_t len;
+{
+	FILE *fp;
+	int i, lastch;
+
+	fp = __db_prinit(NULL);
+
+	fprintf(fp, "len: %3lu", (u_long)len);
+	lastch = '.';
+	if (len != 0) {
+		fprintf(fp, " data: ");
+		for (i = len <= 20 ? len : 20; i > 0; --i, ++p) {
+			lastch = *p;
+			if (isprint(*p) || *p == '\n')
+				fprintf(fp, "%c", *p);
+			else
+				fprintf(fp, "%#x", (u_int)*p);
+		}
+		if (len > 20) {
+			fprintf(fp, "...");
+			lastch = '.';
+		}
+	}
+	if (lastch != '\n')
+		fprintf(fp, "\n");
+}
+
+/*
+ * __db_proff --
+ *	Print out an off-page element.
+ */
+static void
+__db_proff(vp)
+	void *vp;
+{
+	FILE *fp;
+	BOVERFLOW *p;
+
+	fp = __db_prinit(NULL);
+
+	p = vp;
+	switch (p->type) {
+	case B_OVERFLOW:
+		fprintf(fp, "overflow: total len: %4lu page: %4lu\n",
+		    (u_long)p->tlen, (u_long)p->pgno);
+		break;
+	case B_DUPLICATE:
+		fprintf(fp, "duplicate: page: %4lu\n", (u_long)p->pgno);
+		break;
+	}
+}
+
+/*
+ * __db_prflags --
+ *	Print out flags values.
+ *
+ * PUBLIC: void __db_prflags __P((u_int32_t, const FN *));
+ */
+void
+__db_prflags(flags, fn)
+	u_int32_t flags;
+	FN const *fn;
+{
+	FILE *fp;
+	const FN *fnp;
+	int found;
+	const char *sep;
+
+	fp = __db_prinit(NULL);
+
+	sep = " (";
+	for (found = 0, fnp = fn; fnp->mask != 0; ++fnp)
+		if (fnp->mask & flags) {
+			fprintf(fp, "%s%s", sep, fnp->name);
+			sep = ", ";
+			found = 1;
+		}
+	if (found)
+		fprintf(fp, ")");
+}
+
+/*
+ * __db_psize --
+ *	Get the page size.
+ */
+static void
+__db_psize(mpf)
+	DB_MPOOLFILE *mpf;
+{
+	BTMETA *mp;
+	db_pgno_t pgno;
+
+	set_psize = PSIZE_BOUNDARY - 1;
+
+	pgno = PGNO_METADATA;
+	if (memp_fget(mpf, &pgno, 0, &mp) != 0)
+		return;
+
+	switch (mp->magic) {
+	case DB_BTREEMAGIC:
+	case DB_HASHMAGIC:
+		set_psize = mp->pagesize;
+		break;
+	}
+	(void)memp_fput(mpf, mp, 0);
+}