From 8d6f1731fcd082e4f744ba9cb4bde4be7c08f1b3 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Sun, 2 Jan 2000 06:01:06 +0000 Subject: Update. * Makeconfig (all-subdirs): Remove db and db2. * db/*: Removed. * db2/*: Removed. --- db2/progs/db_archive/db_archive.c | 156 -------- db2/progs/db_checkpoint/db_checkpoint.c | 263 -------------- db2/progs/db_deadlock/db_deadlock.c | 245 ------------- db2/progs/db_dump/db_dump.c | 260 ------------- db2/progs/db_dump185/db_dump185.c | 353 ------------------ db2/progs/db_load/db_load.c | 571 ----------------------------- db2/progs/db_printlog/README | 22 -- db2/progs/db_printlog/commit.awk | 7 - db2/progs/db_printlog/count.awk | 9 - db2/progs/db_printlog/db_printlog.c | 192 ---------- db2/progs/db_printlog/pgno.awk | 43 --- db2/progs/db_printlog/range.awk | 27 -- db2/progs/db_printlog/status.awk | 26 -- db2/progs/db_printlog/txn.awk | 30 -- db2/progs/db_recover/db_recover.c | 147 -------- db2/progs/db_stat/db_stat.c | 621 -------------------------------- 16 files changed, 2972 deletions(-) delete mode 100644 db2/progs/db_archive/db_archive.c delete mode 100644 db2/progs/db_checkpoint/db_checkpoint.c delete mode 100644 db2/progs/db_deadlock/db_deadlock.c delete mode 100644 db2/progs/db_dump/db_dump.c delete mode 100644 db2/progs/db_dump185/db_dump185.c delete mode 100644 db2/progs/db_load/db_load.c delete mode 100644 db2/progs/db_printlog/README delete mode 100644 db2/progs/db_printlog/commit.awk delete mode 100644 db2/progs/db_printlog/count.awk delete mode 100644 db2/progs/db_printlog/db_printlog.c delete mode 100644 db2/progs/db_printlog/pgno.awk delete mode 100644 db2/progs/db_printlog/range.awk delete mode 100644 db2/progs/db_printlog/status.awk delete mode 100644 db2/progs/db_printlog/txn.awk delete mode 100644 db2/progs/db_recover/db_recover.c delete mode 100644 db2/progs/db_stat/db_stat.c (limited to 'db2/progs') diff --git a/db2/progs/db_archive/db_archive.c b/db2/progs/db_archive/db_archive.c deleted file mode 100644 index ca48995..0000000 --- a/db2/progs/db_archive/db_archive.c +++ /dev/null @@ -1,156 +0,0 @@ -/*- - * See the file LICENSE for redistribution information. - * - * Copyright (c) 1996, 1997, 1998 - * Sleepycat Software. All rights reserved. - */ - -#include "config.h" - -#ifndef lint -static const char copyright[] = -"@(#) Copyright (c) 1996, 1997, 1998\n\ - Sleepycat Software Inc. All rights reserved.\n"; -static const char sccsid[] = "@(#)db_archive.c 10.20 (Sleepycat) 10/3/98"; -#endif - -#ifndef NO_SYSTEM_INCLUDES -#include - -#include -#include -#include -#include -#include -#include -#endif - -#include "db_int.h" -#include "shqueue.h" -#include "log.h" -#include "db_dispatch.h" -#include "clib_ext.h" -#include "common_ext.h" - -DB_ENV *db_init __P((char *, int)); -int main __P((int, char *[])); -void nosig __P((void)); -void usage __P((void)); - -const char - *progname = "db_archive"; /* Program name. */ - -int -main(argc, argv) - int argc; - char *argv[]; -{ - extern char *optarg; - extern int optind; - DB_ENV *dbenv; - u_int32_t flags; - int ch, verbose; - char *home, **list; - - flags = verbose = 0; - home = NULL; - while ((ch = getopt(argc, argv, "ah:lsv")) != EOF) - switch (ch) { - case 'a': - flags |= DB_ARCH_ABS; - break; - case 'h': - home = optarg; - break; - case 'l': - flags |= DB_ARCH_LOG; - break; - case 's': - flags |= DB_ARCH_DATA; - break; - case 'v': - verbose = 1; - break; - case '?': - default: - usage(); - } - argc -= optind; - argv += optind; - - if (argc != 0) - usage(); - - /* - * Ignore signals -- we don't want to be interrupted because we're - * spending all of our time in the DB library. - */ - nosig(); - dbenv = db_init(home, verbose); - - /* Get the list of names. */ - if ((errno = log_archive(dbenv->lg_info, &list, flags, NULL)) != 0) { - warn(NULL); - (void)db_appexit(dbenv); - return (1); - } - - /* Print the names. */ - if (list != NULL) - for (; *list != NULL; ++list) - printf("%s\n", *list); - - if ((errno = db_appexit(dbenv)) != 0) { - warn(NULL); - return (1); - } - - return (0); -} - -/* - * db_init -- - * Initialize the environment. - */ -DB_ENV * -db_init(home, verbose) - char *home; - int verbose; -{ - DB_ENV *dbenv; - - if ((dbenv = (DB_ENV *)calloc(sizeof(DB_ENV), 1)) == NULL) { - errno = ENOMEM; - err(1, NULL); - } - dbenv->db_errfile = stderr; - dbenv->db_errpfx = progname; - dbenv->db_verbose = verbose; - - if ((errno = db_appinit(home, NULL, dbenv, - DB_CREATE | DB_INIT_LOG | DB_INIT_TXN | DB_USE_ENVIRON)) != 0) - err(1, "db_appinit"); - - return (dbenv); -} - -/* - * nosig -- - * We don't want to be interrupted. - */ -void -nosig() -{ -#ifdef SIGHUP - (void)signal(SIGHUP, SIG_IGN); -#endif - (void)signal(SIGINT, SIG_IGN); - (void)signal(SIGTERM, SIG_IGN); -} - -void -usage() -{ - (void)fprintf(stderr, "usage: db_archive [-alsv] [-h home]\n"); - exit(1); -} diff --git a/db2/progs/db_checkpoint/db_checkpoint.c b/db2/progs/db_checkpoint/db_checkpoint.c deleted file mode 100644 index f0fe48a..0000000 --- a/db2/progs/db_checkpoint/db_checkpoint.c +++ /dev/null @@ -1,263 +0,0 @@ -/*- - * See the file LICENSE for redistribution information. - * - * Copyright (c) 1996, 1997, 1998 - * Sleepycat Software. All rights reserved. - */ - -#include "config.h" - -#ifndef lint -static const char copyright[] = -"@(#) Copyright (c) 1996, 1997, 1998\n\ - Sleepycat Software Inc. All rights reserved.\n"; -static const char sccsid[] = "@(#)db_checkpoint.c 10.21 (Sleepycat) 10/4/98"; -#endif - -#ifndef NO_SYSTEM_INCLUDES -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#endif - -#include "db_int.h" -#include "shqueue.h" -#include "db_page.h" -#include "log.h" -#include "btree.h" -#include "hash.h" -#include "clib_ext.h" -#include "common_ext.h" - -char *check __P((DB_ENV *, long, long)); -DB_ENV *db_init __P((char *)); -int logpid __P((char *, int)); -int main __P((int, char *[])); -void onint __P((int)); -void siginit __P((void)); -void usage __P((void)); - -int interrupted; -const char - *progname = "db_checkpoint"; /* Program name. */ - -int -main(argc, argv) - int argc; - char *argv[]; -{ - extern char *optarg; - extern int optind; - DB_ENV *dbenv; - time_t now; - long argval; - u_int32_t kbytes, minutes, seconds; - int ch, once, ret, verbose; - char *home, *logfile; - - /* - * XXX - * Don't allow a fully unsigned 32-bit number, some compilers get - * upset and require it to be specified in hexadecimal and so on. - */ -#define MAX_UINT32_T 2147483647 - - kbytes = minutes = 0; - once = ret = verbose = 0; - home = logfile = NULL; - while ((ch = getopt(argc, argv, "1h:k:L:p:v")) != EOF) - switch (ch) { - case '1': - once = 1; - break; - case 'h': - home = optarg; - break; - case 'k': - get_long(optarg, 1, (long)MAX_UINT32_T, &argval); - kbytes = argval; - break; - case 'L': - logfile = optarg; - break; - case 'p': - get_long(optarg, 1, (long)MAX_UINT32_T, &argval); - minutes = argval; - break; - case 'v': - verbose = 1; - break; - case '?': - default: - usage(); - } - argc -= optind; - argv += optind; - - if (argc != 0) - usage(); - - if (once == 0 && kbytes == 0 && minutes == 0) { - warnx("at least one of -1, -k and -p must be specified"); - usage(); - } - - /* Initialize the environment. */ - siginit(); - dbenv = db_init(home); - - if (logfile != NULL && logpid(logfile, 1)) { - (void)db_appexit(dbenv); - return (1); - } - - /* - * If we have only a time delay, then we'll sleep the right amount - * to wake up when a checkpoint is necessary. If we have a "kbytes" - * field set, then we'll check every 30 seconds. - */ - seconds = kbytes != 0 ? 30 : minutes * 60; - while (!interrupted) { - if (verbose) { - (void)time(&now); - warnx("checkpoint: %s", ctime(&now)); - } - - errno = txn_checkpoint(dbenv->tx_info, kbytes, minutes); - while (errno == DB_INCOMPLETE) { - if (verbose) - warnx("checkpoint did not finish, retrying\n"); - (void)sleep(2); - errno = txn_checkpoint(dbenv->tx_info, 0, 0); - } - - if (errno != 0) { - ret = 1; - warn(NULL); - break; - } - - if (once) - break; - - (void)sleep(seconds); - } - - if (logfile != NULL && logpid(logfile, 0)) - ret = 1; - - if ((errno = db_appexit(dbenv)) != 0) { - ret = 1; - warn(NULL); - } - - if (interrupted) { - (void)signal(interrupted, SIG_DFL); - (void)raise(interrupted); - /* NOTREACHED */ - } - - return (ret); -} - -/* - * db_init -- - * Initialize the environment. - */ -DB_ENV * -db_init(home) - char *home; -{ - DB_ENV *dbenv; - - if ((dbenv = (DB_ENV *)calloc(sizeof(DB_ENV), 1)) == NULL) { - errno = ENOMEM; - err(1, NULL); - } - dbenv->db_errfile = stderr; - dbenv->db_errpfx = progname; - - if ((errno = db_appinit(home, NULL, dbenv, - DB_INIT_LOG | DB_INIT_TXN | DB_INIT_MPOOL | DB_USE_ENVIRON)) != 0) - err(1, "db_appinit"); - - if (memp_register(dbenv->mp_info, - DB_FTYPE_BTREE, __bam_pgin, __bam_pgout) || - memp_register(dbenv->mp_info, - DB_FTYPE_HASH, __ham_pgin, __ham_pgout)) { - (void)db_appexit(dbenv); - errx(1, - "db_appinit: failed to register access method functions"); - } - - return (dbenv); -} - -/* - * logpid -- - * Log that we're running. - */ -int -logpid(fname, is_open) - char *fname; - int is_open; -{ - FILE *fp; - time_t now; - - if (is_open) { - if ((fp = fopen(fname, "w")) == NULL) { - warn("%s", fname); - return (1); - } - (void)time(&now); - fprintf(fp, - "%.24s: %lu %s", progname, (u_long)getpid(), ctime(&now)); - fclose(fp); - } else - (void)remove(fname); - return (0); -} - -/* - * siginit -- - * Initialize the set of signals for which we want to clean up. - * Generally, we try not to leave the shared regions locked if - * we can. - */ -void -siginit() -{ -#ifdef SIGHUP - (void)signal(SIGHUP, onint); -#endif - (void)signal(SIGINT, onint); - (void)signal(SIGTERM, onint); -} - -/* - * onint -- - * Interrupt signal handler. - */ -void -onint(signo) - int signo; -{ - if ((interrupted = signo) == 0) - interrupted = SIGINT; -} - -void -usage() -{ - (void)fprintf(stderr, - "usage: db_checkpoint [-1v] [-h home] [-k kbytes] [-L file] [-p min]\n"); - exit(1); -} diff --git a/db2/progs/db_deadlock/db_deadlock.c b/db2/progs/db_deadlock/db_deadlock.c deleted file mode 100644 index bc5039e..0000000 --- a/db2/progs/db_deadlock/db_deadlock.c +++ /dev/null @@ -1,245 +0,0 @@ -/*- - * See the file LICENSE for redistribution information. - * - * Copyright (c) 1996, 1997, 1998 - * Sleepycat Software. All rights reserved. - */ - -#include "config.h" - -#ifndef lint -static const char copyright[] = -"@(#) Copyright (c) 1996, 1997, 1998\n\ - Sleepycat Software Inc. All rights reserved.\n"; -static const char sccsid[] = "@(#)db_deadlock.c 10.23 (Sleepycat) 10/4/98"; -#endif - -#ifndef NO_SYSTEM_INCLUDES -#include - -#include -#include -#include -#include -#include -#include -#include -#endif - -#include "db_int.h" -#include "clib_ext.h" -#include "common_ext.h" - -#define BAD_KILLID 0xffffffff - -DB_ENV *db_init __P((char *, int)); -int logpid __P((char *, int)); -int main __P((int, char *[])); -void onint __P((int)); -void siginit __P((void)); -void usage __P((void)); - -int interrupted; -const char - *progname = "db_deadlock"; /* Program name. */ - -int -main(argc, argv) - int argc; - char *argv[]; -{ - extern char *optarg; - extern int optind; - DB_ENV *dbenv; - u_int32_t atype; - time_t now; - long usecs; - u_int32_t flags; - int ch, ret, verbose; - char *home, *logfile; - - atype = DB_LOCK_DEFAULT; - home = logfile = NULL; - usecs = 0; - flags = 0; - ret = verbose = 0; - while ((ch = getopt(argc, argv, "a:h:L:t:vw")) != EOF) - switch (ch) { - case 'a': - switch (optarg[0]) { - case 'o': - atype = DB_LOCK_OLDEST; - break; - case 'y': - atype = DB_LOCK_YOUNGEST; - break; - default: - usage(); - /* NOTREACHED */ - } - if (optarg[1] != '\0') - usage(); - break; - case 'h': - home = optarg; - break; - case 'L': - logfile = optarg; - break; - case 't': - get_long(optarg, 1, LONG_MAX, &usecs); - usecs *= 1000000; - break; - case 'v': - verbose = 1; - break; - case 'w': - LF_SET(DB_LOCK_CONFLICT); - break; - case '?': - default: - usage(); - } - argc -= optind; - argv += optind; - - if (argc != 0) - usage(); - - if (usecs == 0 && !LF_ISSET(DB_LOCK_CONFLICT)) { - warnx("at least one of -t and -w must be specified"); - usage(); - } - - /* - * We detect every 100ms (100000 us) when we're running in - * DB_LOCK_CONFLICT mode. - */ - if (usecs == 0) - usecs = 100000; - - /* Initialize the deadlock detector by opening the lock manager. */ - siginit(); - dbenv = db_init(home, verbose); - - if (logfile != NULL && logpid(logfile, 1)) { - (void)db_appexit(dbenv); - return (1); - } - - while (!interrupted) { - if (dbenv->db_verbose != 0) { - time(&now); - warnx("Running at %.24s", ctime(&now)); - } - - if ((errno = lock_detect(dbenv->lk_info, flags, atype)) != 0) { - ret = 1; - warnx(NULL); - break; - } - - /* Make a pass every "usecs" usecs. */ - (void)usleep(usecs); - } - - if (logfile != NULL && logpid(logfile, 0)) - ret = 1; - - if ((errno = db_appexit(dbenv)) != 0) { - ret = 1; - warn(NULL); - } - - if (interrupted) { - (void)signal(interrupted, SIG_DFL); - (void)raise(interrupted); - /* NOTREACHED */ - } - - return (ret); -} - -DB_ENV * -db_init(home, verbose) - char *home; - int verbose; -{ - DB_ENV *dbenv; - - if ((dbenv = (DB_ENV *)calloc(sizeof(DB_ENV), 1)) == NULL) { - errno = ENOMEM; - err(1, NULL); - } - dbenv->db_errfile = stderr; - dbenv->db_errpfx = progname; - dbenv->db_verbose = verbose; - - if ((errno = db_appinit(home, - NULL, dbenv, DB_INIT_LOCK | DB_USE_ENVIRON)) != 0) - err(1, "db_appinit"); - - return (dbenv); -} - -/* - * logpid -- - * Log that we're running. - */ -int -logpid(fname, is_open) - char *fname; - int is_open; -{ - FILE *fp; - time_t now; - - if (is_open) { - if ((fp = fopen(fname, "w")) == NULL) { - warn("%s", fname); - return (1); - } - (void)time(&now); - fprintf(fp, - "%.24s: %lu %s", progname, (u_long)getpid(), ctime(&now)); - fclose(fp); - } else - (void)remove(fname); - return (0); -} - -/* - * siginit -- - * Initialize the set of signals for which we want to clean up. - * Generally, we try not to leave the shared regions locked if - * we can. - */ -void -siginit() -{ -#ifdef SIGHUP - (void)signal(SIGHUP, onint); -#endif - (void)signal(SIGINT, onint); - (void)signal(SIGTERM, onint); -} - -/* - * onint -- - * Interrupt signal handler. - */ -void -onint(signo) - int signo; -{ - if ((interrupted = signo) == 0) - interrupted = SIGINT; -} - -void -usage() -{ - (void)fprintf(stderr, - "usage: db_deadlock [-vw] [-a m | o | y] [-h home] [-L file] [-t sec]\n"); - exit(1); -} diff --git a/db2/progs/db_dump/db_dump.c b/db2/progs/db_dump/db_dump.c deleted file mode 100644 index 0f34ddc..0000000 --- a/db2/progs/db_dump/db_dump.c +++ /dev/null @@ -1,260 +0,0 @@ -/*- - * See the file LICENSE for redistribution information. - * - * Copyright (c) 1996, 1997, 1998 - * Sleepycat Software. All rights reserved. - */ - -#include "config.h" - -#ifndef lint -static const char copyright[] = -"@(#) Copyright (c) 1996, 1997, 1998\n\ - Sleepycat Software Inc. All rights reserved.\n"; -static const char sccsid[] = "@(#)db_dump.c 10.24 (Sleepycat) 11/22/98"; -#endif - -#ifndef NO_SYSTEM_INCLUDES -#include - -#include -#include -#include -#include -#include -#include -#endif - -#undef stat - -#include "db_int.h" -#include "db_page.h" -#include "btree.h" -#include "hash.h" -#include "clib_ext.h" - -void configure __P((char *)); -DB_ENV *db_init __P((char *)); -int main __P((int, char *[])); -void pheader __P((DB *, int)); -void usage __P((void)); - -const char - *progname = "db_dump"; /* Program name. */ - -int -main(argc, argv) - int argc; - char *argv[]; -{ - extern char *optarg; - extern int optind; - DB *dbp; - DBC *dbcp; - DBT key, data; - DB_ENV *dbenv; - int ch, checkprint, dflag; - char *home; - - home = NULL; - checkprint = dflag = 0; - while ((ch = getopt(argc, argv, "df:h:Np")) != EOF) - switch (ch) { - case 'd': - dflag = 1; - break; - case 'f': - if (freopen(optarg, "w", stdout) == NULL) - err(1, "%s", optarg); - break; - case 'h': - home = optarg; - break; - case 'N': - (void)db_value_set(0, DB_MUTEXLOCKS); - break; - case 'p': - checkprint = 1; - break; - case '?': - default: - usage(); - } - argc -= optind; - argv += optind; - - if (argc != 1) - usage(); - - if (dflag && checkprint) - errx(1, "the -d and -p options may not both be specified"); - - /* Initialize the environment. */ - dbenv = db_init(home); - - /* Open the DB file. */ - if ((errno = - db_open(argv[0], DB_UNKNOWN, DB_RDONLY, 0, dbenv, NULL, &dbp)) != 0) - err(1, "%s", argv[0]); - - /* DB dump. */ - if (dflag) { - (void)__db_dump(dbp, NULL, 1); - if ((errno = dbp->close(dbp, 0)) != 0) - err(1, "close"); - exit (0); - } - - /* Get a cursor and step through the database. */ - if ((errno = dbp->cursor(dbp, NULL, &dbcp, 0)) != 0) { - (void)dbp->close(dbp, 0); - err(1, "cursor"); - } - - /* Print out the header. */ - pheader(dbp, checkprint); - - /* Print out the key/data pairs. */ - memset(&key, 0, sizeof(key)); - memset(&data, 0, sizeof(data)); - while ((errno = dbcp->c_get(dbcp, &key, &data, DB_NEXT)) == 0) { - if (dbp->type != DB_RECNO && - (errno = __db_prdbt(&key, checkprint, stdout)) != 0) - break; - if ((errno = __db_prdbt(&data, checkprint, stdout)) != 0) - break; - } - - if (errno != DB_NOTFOUND) - err(1, "cursor get"); - - if ((errno = dbp->close(dbp, 0)) != 0) - err(1, "close"); - return (0); -} - -/* - * db_init -- - * Initialize the environment. - */ -DB_ENV * -db_init(home) - char *home; -{ - DB_ENV *dbenv; - - if ((dbenv = (DB_ENV *)calloc(1, sizeof(DB_ENV))) == NULL) { - errno = ENOMEM; - err(1, NULL); - } - - /* - * Try and use the shared mpool region so that we get pages that - * haven't been flushed to disk (mostly useful for debugging). - * If that fails, try again, without the DB_INIT_MPOOL flag. - * - * If it works, set the error output options so that future errors - * are correctly reported. - */ - if ((errno = db_appinit(home, - NULL, dbenv, DB_USE_ENVIRON | DB_INIT_MPOOL)) == 0) { - dbenv->db_errfile = stderr; - dbenv->db_errpfx = progname; - return (dbenv); - } - - /* Set the error output options -- this time we want a message. */ - memset(dbenv, 0, sizeof(*dbenv)); - dbenv->db_errfile = stderr; - dbenv->db_errpfx = progname; - - /* Try again, and it's fatal if we fail. */ - if ((errno = db_appinit(home, NULL, dbenv, DB_USE_ENVIRON)) != 0) - err(1, "db_appinit"); - - return (dbenv); -} - -/* - * pheader -- - * Write out the header information. - */ -void -pheader(dbp, pflag) - DB *dbp; - int pflag; -{ - DBC *dbc; - DB_BTREE_STAT *btsp; - HASH_CURSOR *hcp; - int ret; - - printf("format=%s\n", pflag ? "print" : "bytevalue"); - switch (dbp->type) { - case DB_BTREE: - printf("type=btree\n"); - if ((errno = dbp->stat(dbp, &btsp, NULL, 0)) != 0) - err(1, "dbp->stat"); - if (F_ISSET(dbp, DB_BT_RECNUM)) - printf("recnum=1\n"); - if (btsp->bt_maxkey != 0) - printf("bt_maxkey=%lu\n", (u_long)btsp->bt_maxkey); - if (btsp->bt_minkey != 0) - printf("bt_minkey=%lu\n", (u_long)btsp->bt_minkey); - break; - case DB_HASH: - printf("type=hash\n"); - if ((ret = dbp->cursor(dbp, NULL, &dbc, 0)) != 0) - break; - hcp = (HASH_CURSOR *)dbc->internal; - GET_META(dbp, hcp, ret); - if (ret == 0) { - if (hcp->hdr->ffactor != 0) - printf("h_ffactor=%lu\n", - (u_long)hcp->hdr->ffactor); - if (hcp->hdr->nelem != 0) - printf("h_nelem=%lu\n", - (u_long)hcp->hdr->nelem); - RELEASE_META(dbp, hcp); - } - (void)dbc->c_close(dbc); - break; - case DB_RECNO: - printf("type=recno\n"); - if ((errno = dbp->stat(dbp, &btsp, NULL, 0)) != 0) - err(1, "dbp->stat"); - if (F_ISSET(dbp, DB_RE_RENUMBER)) - printf("renumber=1\n"); - if (F_ISSET(dbp, DB_RE_FIXEDLEN)) - printf("re_len=%lu\n", (u_long)btsp->bt_re_len); - if (F_ISSET(dbp, DB_RE_PAD)) - printf("re_pad=%#x\n", btsp->bt_re_pad); - break; - case DB_UNKNOWN: - abort(); - /* NOTREACHED */ - } - - if (F_ISSET(dbp, DB_AM_DUP)) - printf("duplicates=1\n"); - - if (dbp->dbenv->db_lorder != 0) - printf("db_lorder=%lu\n", (u_long)dbp->dbenv->db_lorder); - - if (!F_ISSET(dbp, DB_AM_PGDEF)) - printf("db_pagesize=%lu\n", (u_long)dbp->pgsize); - - printf("HEADER=END\n"); -} - -/* - * usage -- - * Display the usage message. - */ -void -usage() -{ - (void)fprintf(stderr, - "usage: db_dump [-dNp] [-f file] [-h home] db_file\n"); - exit(1); -} diff --git a/db2/progs/db_dump185/db_dump185.c b/db2/progs/db_dump185/db_dump185.c deleted file mode 100644 index 1745110..0000000 --- a/db2/progs/db_dump185/db_dump185.c +++ /dev/null @@ -1,353 +0,0 @@ -/*- - * See the file LICENSE for redistribution information. - * - * Copyright (c) 1996, 1997, 1998 - * Sleepycat Software. All rights reserved. - */ - -#include "config.h" - -#ifndef lint -static const char copyright[] = -"@(#) Copyright (c) 1996, 1997, 1998\n\ - Sleepycat Software Inc. All rights reserved.\n"; -static const char sccsid[] = "@(#)db_dump185.c 10.10 (Sleepycat) 4/10/98"; -#endif - -#ifndef NO_SYSTEM_INCLUDES -#include - -#include -#include -#include -#include -#include -#include -#include -#endif - -#include "db_185.h" -#include "clib_ext.h" - -/* Hash Table Information */ -typedef struct hashhdr185 { /* Disk resident portion */ - int magic; /* Magic NO for hash tables */ - int version; /* Version ID */ - u_int32_t lorder; /* Byte Order */ - int bsize; /* Bucket/Page Size */ - int bshift; /* Bucket shift */ - int dsize; /* Directory Size */ - int ssize; /* Segment Size */ - int sshift; /* Segment shift */ - int ovfl_point; /* Where overflow pages are being - * allocated */ - int last_freed; /* Last overflow page freed */ - int max_bucket; /* ID of Maximum bucket in use */ - int high_mask; /* Mask to modulo into entire table */ - int low_mask; /* Mask to modulo into lower half of - * table */ - int ffactor; /* Fill factor */ - int nkeys; /* Number of keys in hash table */ -} HASHHDR185; -typedef struct htab185 { /* Memory resident data structure */ - HASHHDR185 hdr; /* Header */ -} HTAB185; - -/* Hash Table Information */ -typedef struct hashhdr186 { /* Disk resident portion */ - int32_t magic; /* Magic NO for hash tables */ - int32_t version; /* Version ID */ - int32_t lorder; /* Byte Order */ - int32_t bsize; /* Bucket/Page Size */ - int32_t bshift; /* Bucket shift */ - int32_t ovfl_point; /* Where overflow pages are being allocated */ - int32_t last_freed; /* Last overflow page freed */ - int32_t max_bucket; /* ID of Maximum bucket in use */ - int32_t high_mask; /* Mask to modulo into entire table */ - int32_t low_mask; /* Mask to modulo into lower half of table */ - int32_t ffactor; /* Fill factor */ - int32_t nkeys; /* Number of keys in hash table */ - int32_t hdrpages; /* Size of table header */ - int32_t h_charkey; /* value of hash(CHARKEY) */ -#define NCACHED 32 /* number of bit maps and spare points */ - int32_t spares[NCACHED];/* spare pages for overflow */ - u_int16_t bitmaps[NCACHED]; /* address of overflow page bitmaps */ -} HASHHDR186; -typedef struct htab186 { /* Memory resident data structure */ - HASHHDR186 hdr; /* Header */ -} HTAB186; - -typedef struct _epgno { - u_int32_t pgno; /* the page number */ - u_int16_t index; /* the index on the page */ -} EPGNO; - -typedef struct _epg { - void *page; /* the (pinned) page */ - u_int16_t index; /* the index on the page */ -} EPG; - -typedef struct _cursor { - EPGNO pg; /* B: Saved tree reference. */ - DBT key; /* B: Saved key, or key.data == NULL. */ - u_int32_t rcursor; /* R: recno cursor (1-based) */ - -#define CURS_ACQUIRE 0x01 /* B: Cursor needs to be reacquired. */ -#define CURS_AFTER 0x02 /* B: Unreturned cursor after key. */ -#define CURS_BEFORE 0x04 /* B: Unreturned cursor before key. */ -#define CURS_INIT 0x08 /* RB: Cursor initialized. */ - u_int8_t flags; -} CURSOR; - -/* The in-memory btree/recno data structure. */ -typedef struct _btree { - void *bt_mp; /* memory pool cookie */ - - void *bt_dbp; /* pointer to enclosing DB */ - - EPG bt_cur; /* current (pinned) page */ - void *bt_pinned; /* page pinned across calls */ - - CURSOR bt_cursor; /* cursor */ - - EPGNO bt_stack[50]; /* stack of parent pages */ - EPGNO *bt_sp; /* current stack pointer */ - - DBT bt_rkey; /* returned key */ - DBT bt_rdata; /* returned data */ - - int bt_fd; /* tree file descriptor */ - - u_int32_t bt_free; /* next free page */ - u_int32_t bt_psize; /* page size */ - u_int16_t bt_ovflsize; /* cut-off for key/data overflow */ - int bt_lorder; /* byte order */ - /* sorted order */ - enum { NOT, BACK, FORWARD } bt_order; - EPGNO bt_last; /* last insert */ - - /* B: key comparison function */ - int (*bt_cmp) __P((const DBT *, const DBT *)); - /* B: prefix comparison function */ - size_t (*bt_pfx) __P((const DBT *, const DBT *)); - /* R: recno input function */ - int (*bt_irec) __P((struct _btree *, u_int32_t)); - - FILE *bt_rfp; /* R: record FILE pointer */ - int bt_rfd; /* R: record file descriptor */ - - void *bt_cmap; /* R: current point in mapped space */ - void *bt_smap; /* R: start of mapped space */ - void *bt_emap; /* R: end of mapped space */ - size_t bt_msize; /* R: size of mapped region. */ - - u_int32_t bt_nrecs; /* R: number of records */ - size_t bt_reclen; /* R: fixed record length */ - u_char bt_bval; /* R: delimiting byte/pad character */ - -/* - * NB: - * B_NODUPS and R_RECNO are stored on disk, and may not be changed. - */ -#define B_INMEM 0x00001 /* in-memory tree */ -#define B_METADIRTY 0x00002 /* need to write metadata */ -#define B_MODIFIED 0x00004 /* tree modified */ -#define B_NEEDSWAP 0x00008 /* if byte order requires swapping */ -#define B_RDONLY 0x00010 /* read-only tree */ - -#define B_NODUPS 0x00020 /* no duplicate keys permitted */ -#define R_RECNO 0x00080 /* record oriented tree */ - -#define R_CLOSEFP 0x00040 /* opened a file pointer */ -#define R_EOF 0x00100 /* end of input file reached. */ -#define R_FIXLEN 0x00200 /* fixed length records */ -#define R_MEMMAPPED 0x00400 /* memory mapped file. */ -#define R_INMEM 0x00800 /* in-memory file */ -#define R_MODIFIED 0x01000 /* modified file */ -#define R_RDONLY 0x02000 /* read-only file */ - -#define B_DB_LOCK 0x04000 /* DB_LOCK specified. */ -#define B_DB_SHMEM 0x08000 /* DB_SHMEM specified. */ -#define B_DB_TXN 0x10000 /* DB_TXN specified. */ - u_int32_t flags; -} BTREE; - -void db_btree __P((DB *, int)); -void db_hash __P((DB *, int)); -void dbt_dump __P((DBT *)); -void dbt_print __P((DBT *)); -int main __P((int, char *[])); -void usage __P((void)); - -const char - *progname = "db_dump185"; /* Program name. */ - -int -main(argc, argv) - int argc; - char *argv[]; -{ - extern char *optarg; - extern int optind; - DB *dbp; - DBT key, data; - int ch, pflag, rval; - - pflag = 0; - while ((ch = getopt(argc, argv, "f:p")) != EOF) - switch (ch) { - case 'f': - if (freopen(optarg, "w", stdout) == NULL) - err(1, "%s", optarg); - break; - case 'p': - pflag = 1; - break; - case '?': - default: - usage(); - } - argc -= optind; - argv += optind; - - if (argc != 1) - usage(); - - if ((dbp = dbopen(argv[0], O_RDONLY, 0, DB_BTREE, NULL)) == NULL) { - if ((dbp = dbopen(argv[0], O_RDONLY, 0, DB_HASH, NULL)) == NULL) - err(1, "%s", argv[0]); - db_hash(dbp, pflag); - } else - db_btree(dbp, pflag); - - /* - * !!! - * DB 1.85 DBTs are a subset of DB 2.0 DBTs, so we just use the - * new dump/print routines. - */ - if (pflag) - while (!(rval = dbp->seq(dbp, &key, &data, R_NEXT))) { - dbt_print(&key); - dbt_print(&data); - } - else - while (!(rval = dbp->seq(dbp, &key, &data, R_NEXT))) { - dbt_dump(&key); - dbt_dump(&data); - } - - if (rval == -1) - err(1, "seq"); - return (0); -} - -/* - * db_hash -- - * Dump out hash header information. - */ -void -db_hash(dbp, pflag) - DB *dbp; - int pflag; -{ - HTAB185 *hash185p; - HTAB186 *hash186p; - - printf("format=%s\n", pflag ? "print" : "bytevalue"); - printf("type=hash\n"); - - /* DB 1.85 was version 2, DB 1.86 was version 3. */ - hash185p = dbp->internal; - if (hash185p->hdr.version > 2) { - hash186p = dbp->internal; - printf("h_ffactor=%lu\n", (u_long)hash186p->hdr.ffactor); - if (hash186p->hdr.lorder != 0) - printf("db_lorder=%lu\n", (u_long)hash186p->hdr.lorder); - printf("db_pagesize=%lu\n", (u_long)hash186p->hdr.bsize); - } else { - printf("h_ffactor=%lu\n", (u_long)hash185p->hdr.ffactor); - if (hash185p->hdr.lorder != 0) - printf("db_lorder=%lu\n", (u_long)hash185p->hdr.lorder); - printf("db_pagesize=%lu\n", (u_long)hash185p->hdr.bsize); - } - printf("HEADER=END\n"); -} - -/* - * db_btree -- - * Dump out btree header information. - */ -void -db_btree(dbp, pflag) - DB *dbp; - int pflag; -{ - BTREE *btp; - - btp = dbp->internal; - - printf("format=%s\n", pflag ? "print" : "bytevalue"); - printf("type=btree\n"); -#ifdef NOT_AVAILABLE_IN_185 - printf("bt_minkey=%lu\n", (u_long)XXX); - printf("bt_maxkey=%lu\n", (u_long)XXX); -#endif - if (btp->bt_lorder != 0) - printf("db_lorder=%lu\n", (u_long)btp->bt_lorder); - printf("db_pagesize=%lu\n", (u_long)btp->bt_psize); - if (!(btp->flags & B_NODUPS)) - printf("duplicates=1\n"); - printf("HEADER=END\n"); -} - -static char hex[] = "0123456789abcdef"; - -/* - * dbt_dump -- - * Write out a key or data item using byte values. - */ -void -dbt_dump(dbtp) - DBT *dbtp; -{ - size_t len; - u_int8_t *p; - - for (len = dbtp->size, p = dbtp->data; len--; ++p) - (void)printf("%c%c", - hex[(*p & 0xf0) >> 4], hex[*p & 0x0f]); - printf("\n"); -} - -/* - * dbt_print -- - * Write out a key or data item using printable characters. - */ -void -dbt_print(dbtp) - DBT *dbtp; -{ - size_t len; - u_int8_t *p; - - for (len = dbtp->size, p = dbtp->data; len--; ++p) - if (isprint(*p)) { - if (*p == '\\') - (void)printf("\\"); - (void)printf("%c", *p); - } else - (void)printf("\\%c%c", - hex[(*p & 0xf0) >> 4], hex[*p & 0x0f]); - printf("\n"); -} - -/* - * usage -- - * Display the usage message. - */ -void -usage() -{ - (void)fprintf(stderr, "usage: db_dump [-p] [-f file] db_file\n"); - exit(1); -} diff --git a/db2/progs/db_load/db_load.c b/db2/progs/db_load/db_load.c deleted file mode 100644 index a242602..0000000 --- a/db2/progs/db_load/db_load.c +++ /dev/null @@ -1,571 +0,0 @@ -/*- - * See the file LICENSE for redistribution information. - * - * Copyright (c) 1996, 1997, 1998 - * Sleepycat Software. All rights reserved. - */ - -#include "config.h" - -#ifndef lint -static const char copyright[] = -"@(#) Copyright (c) 1996, 1997, 1998\n\ - Sleepycat Software Inc. All rights reserved.\n"; -static const char sccsid[] = "@(#)db_load.c 10.23 (Sleepycat) 10/4/98"; -#endif - -#ifndef NO_SYSTEM_INCLUDES -#include - -#include -#include -#include -#include -#include -#include -#include -#endif - -#include "db_int.h" -#include "db_page.h" -#include "db_am.h" -#include "clib_ext.h" - -void badnum __P((void)); -void configure __P((DB_INFO *, char **)); -DB_ENV *db_init __P((char *)); -int dbt_rdump __P((DBT *)); -int dbt_rprint __P((DBT *)); -int digitize __P((int)); -int main __P((int, char *[])); -void onint __P((int)); -void rheader __P((DBTYPE *, int *, DB_INFO *)); -void siginit __P((void)); -void usage __P((void)); - -int interrupted; -const char - *progname = "db_load"; /* Program name. */ - -int -main(argc, argv) - int argc; - char *argv[]; -{ - extern char *optarg; - extern int optind; - DB *dbp; - DBT key, data; - DBTYPE argtype, dbtype; - DB_ENV *dbenv; - DB_INFO dbinfo; - db_recno_t recno; - u_int32_t db_nooverwrite; - int ch, checkprint, existed, no_header, ret; - char **clist, **clp, *home; - - /* Allocate enough room for configuration arguments. */ - if ((clp = clist = (char **)calloc(argc + 1, sizeof(char *))) == NULL) - err(1, NULL); - - dbp = NULL; - home = NULL; - db_nooverwrite = 0; - checkprint = existed = no_header = ret = 0; - argtype = dbtype = DB_UNKNOWN; - while ((ch = getopt(argc, argv, "c:f:h:nTt:")) != EOF) - switch (ch) { - case 'c': - *clp++ = optarg; - break; - case 'f': - if (freopen(optarg, "r", stdin) == NULL) - err(1, "%s", optarg); - break; - case 'h': - home = optarg; - break; - case 'n': - db_nooverwrite = DB_NOOVERWRITE; - break; - case 'T': - no_header = checkprint = 1; - break; - case 't': - if (strcmp(optarg, "btree") == 0) { - argtype = DB_BTREE; - break; - } - if (strcmp(optarg, "hash") == 0) { - argtype = DB_HASH; - break; - } - if (strcmp(optarg, "recno") == 0) { - argtype = DB_RECNO; - break; - } - usage(); - /* NOTREACHED */ - case '?': - default: - usage(); - } - argc -= optind; - argv += optind; - - if (argc != 1) - usage(); - - /* - * Read the header. If there isn't any header, we're expecting flat - * text, set the checkprint flag appropriately. - */ - memset(&dbinfo, 0, sizeof(DB_INFO)); - if (no_header) - dbtype = argtype; - else { - rheader(&dbtype, &checkprint, &dbinfo); - if (argtype != DB_UNKNOWN) { - /* Conversion to/from recno is prohibited. */ - if ((dbtype == DB_RECNO && argtype != DB_RECNO) || - (argtype == DB_RECNO && dbtype != DB_RECNO)) - errx(1, - "databases of type recno may not be converted"); - dbtype = argtype; - } - } - - if (dbtype == DB_UNKNOWN) - errx(1, "no database type specified"); - - /* Apply command-line configuration changes. */ - configure(&dbinfo, clist); - - /* Initialize the key/data pair. */ - memset(&key, 0, sizeof(DBT)); - if (dbtype == DB_RECNO) { - key.data = &recno; - key.size = sizeof(recno); - } else - if ((key.data = (void *)malloc(key.ulen = 1024)) == NULL) { - errno = ENOMEM; - err(1, NULL); - } - memset(&data, 0, sizeof(DBT)); - if ((data.data = (void *)malloc(data.ulen = 1024)) == NULL) { - errno = ENOMEM; - err(1, NULL); - } - - /* Initialize the environment if the user specified one. */ - siginit(); - dbenv = home == NULL ? NULL : db_init(home); - - /* Open the DB file. */ - if ((errno = db_open(argv[0], dbtype, DB_CREATE, - __db_omode("rwrwrw"), dbenv, &dbinfo, &dbp)) != 0) { - warn("%s", argv[0]); - goto err; - } - - /* Get each key/data pair and add them to the database. */ - for (recno = 1; !interrupted; ++recno) { - if (dbtype == DB_RECNO) { - if (checkprint) { - if (dbt_rprint(&data)) - break; - } else { - if (dbt_rdump(&data)) - break; - } - } else { - if (checkprint) { - if (dbt_rprint(&key)) - break; - if (dbt_rprint(&data)) - goto fmt; - } else { - if (dbt_rdump(&key)) - break; - if (dbt_rdump(&data)) { -fmt: warnx("odd number of key/data pairs"); - goto err; - } - } - } - switch (errno = - dbp->put(dbp, NULL, &key, &data, db_nooverwrite)) { - case 0: - break; - case DB_KEYEXIST: - existed = 1; - warnx("%s: line %d: key already exists, not loaded:", - argv[0], - dbtype == DB_RECNO ? recno : recno * 2 - 1); - - (void)__db_prdbt(&key, checkprint, stderr); - break; - default: - warn(NULL); - goto err; - } - } - - if (0) { -err: ret = 1; - } - if (dbp != NULL && (errno = dbp->close(dbp, 0)) != 0) { - ret = 1; - warn(NULL); - } - - if (dbenv != NULL && (errno = db_appexit(dbenv)) != 0) { - ret = 1; - warn(NULL); - } - - if (interrupted) { - (void)signal(interrupted, SIG_DFL); - (void)raise(interrupted); - /* NOTREACHED */ - } - - /* Return 0 on success, 1 if keys existed already, and 2 on failure. */ - return (ret == 0 ? (existed == 0 ? 0 : 1) : 2); -} - -/* - * db_init -- - * Initialize the environment. - */ -DB_ENV * -db_init(home) - char *home; -{ - DB_ENV *dbenv; - - if ((dbenv = (DB_ENV *)calloc(sizeof(DB_ENV), 1)) == NULL) { - errno = ENOMEM; - err(1, NULL); - } - - /* - * The database may be live, try and use the shared regions. - * - * If it works, we're done. Set the error output options so that - * future errors are correctly reported. - */ - if ((errno = db_appinit(home, NULL, dbenv, DB_INIT_LOCK | - DB_INIT_LOG | DB_INIT_MPOOL | DB_INIT_TXN | DB_USE_ENVIRON)) == 0) { - dbenv->db_errfile = stderr; - dbenv->db_errpfx = progname; - return (dbenv); - } - - /* - * If the db_appinit fails, assume the database isn't live, and don't - * bother with an environment. - */ - free(dbenv); - return (NULL); -} - -#define FLAG(name, value, keyword, flag) \ - if (strcmp(name, keyword) == 0) { \ - switch (*value) { \ - case '1': \ - dbinfop->flags |= (flag); \ - break; \ - case '0': \ - dbinfop->flags &= ~(flag); \ - break; \ - default: \ - badnum(); \ - /* NOTREACHED */ \ - } \ - continue; \ - } -#define NUMBER(name, value, keyword, field, flag) \ - if (strcmp(name, keyword) == 0) { \ - get_long(value, 1, LONG_MAX, &val); \ - dbinfop->field = val; \ - if (flag != 0) \ - dbinfop->flags |= (flag); \ - continue; \ - } -#define STRING(name, value, keyword, field, flag) \ - if (strcmp(name, keyword) == 0) { \ - dbinfop->field = value[0]; \ - if (flag != 0) \ - dbinfop->flags |= (flag); \ - continue; \ - } - -/* - * configure -- - * Handle command-line configuration options. - */ -void -configure(dbinfop, clp) - DB_INFO *dbinfop; - char **clp; -{ - long val; - char *name, *value; - - for (; (name = *clp) != NULL; ++clp) { - if ((value = strchr(name, '=')) == NULL) - errx(1, - "command-line configuration uses name=value format"); - *value++ = '\0'; - - NUMBER(name, value, "bt_maxkey", bt_maxkey, 0); - NUMBER(name, value, "bt_minkey", bt_minkey, 0); - NUMBER(name, value, "db_lorder", db_lorder, 0); - NUMBER(name, value, "db_pagesize", db_pagesize, 0); - FLAG(name, value, "duplicates", DB_DUP); - NUMBER(name, value, "h_ffactor", h_ffactor, 0); - NUMBER(name, value, "h_nelem", h_nelem, 0); - NUMBER(name, value, "re_len", re_len, DB_FIXEDLEN); - STRING(name, value, "re_pad", re_pad, DB_PAD); - FLAG(name, value, "recnum", DB_RECNUM); - FLAG(name, value, "renumber", DB_RENUMBER); - - errx(1, "unknown command-line configuration keyword"); - } -} - -/* - * rheader -- - * Read the header message. - */ -void -rheader(dbtypep, checkprintp, dbinfop) - DBTYPE *dbtypep; - int *checkprintp; - DB_INFO *dbinfop; -{ - long lineno, val; - char name[256], value[256]; - - *dbtypep = DB_UNKNOWN; - *checkprintp = 0; - - for (lineno = 1;; ++lineno) { - /* If we don't see the expected information, it's an error. */ - if (fscanf(stdin, "%[^=]=%s\n", name, value) != 2) - errx(1, "line %lu: unexpected format", lineno); - - /* Check for the end of the header lines. */ - if (strcmp(name, "HEADER") == 0) - break; - - if (strcmp(name, "format") == 0) { - if (strcmp(value, "bytevalue") == 0) { - *checkprintp = 0; - continue; - } - if (strcmp(value, "print") == 0) { - *checkprintp = 1; - continue; - } - errx(1, "line %d: unknown format", lineno); - } - if (strcmp(name, "type") == 0) { - if (strcmp(value, "btree") == 0) { - *dbtypep = DB_BTREE; - continue; - } - if (strcmp(value, "hash") == 0) { - *dbtypep = DB_HASH; - continue; - } - if (strcmp(value, "recno") == 0) { - *dbtypep = DB_RECNO; - continue; - } - errx(1, "line %d: unknown type", lineno); - } - NUMBER(name, value, "bt_maxkey", bt_maxkey, 0); - NUMBER(name, value, "bt_minkey", bt_minkey, 0); - NUMBER(name, value, "db_lorder", db_lorder, 0); - NUMBER(name, value, "db_pagesize", db_pagesize, 0); - FLAG(name, value, "duplicates", DB_DUP); - NUMBER(name, value, "h_ffactor", h_ffactor, 0); - NUMBER(name, value, "h_nelem", h_nelem, 0); - NUMBER(name, value, "re_len", re_len, DB_FIXEDLEN); - STRING(name, value, "re_pad", re_pad, DB_PAD); - FLAG(name, value, "recnum", DB_RECNUM); - FLAG(name, value, "renumber", DB_RENUMBER); - - errx(1, "unknown input-file header configuration keyword"); - } -} - -/* - * dbt_rprint -- - * Read a printable line into a DBT structure. - */ -int -dbt_rprint(dbtp) - DBT *dbtp; -{ - u_int32_t len; - u_int8_t *p; - int c1, c2, escape; - - escape = 0; - for (p = dbtp->data, len = 0; (c1 = getchar()) != '\n';) { - if (c1 == EOF) { - if (len == 0) - return (1); - err(1, "unexpected end of key/data pair"); - } - if (escape) { - if (c1 != '\\') { - if ((c2 = getchar()) == EOF) - err(1, - "unexpected end of key/data pair"); - c1 = digitize(c1) << 4 | digitize(c2); - } - escape = 0; - } else - if (c1 == '\\') { - escape = 1; - continue; - } - if (len >= dbtp->ulen - 10) { - dbtp->ulen *= 2; - if ((dbtp->data = - (void *)realloc(dbtp->data, dbtp->ulen)) == NULL) { - errno = ENOMEM; - err(1, NULL); - } - p = (u_int8_t *)dbtp->data + len; - } - ++len; - *p++ = c1; - } - dbtp->size = len; - return (0); -} - -/* - * dbt_rdump -- - * Read a byte dump line into a DBT structure. - */ -int -dbt_rdump(dbtp) - DBT *dbtp; -{ - u_int32_t len; - u_int8_t *p; - int c1, c2; - - for (p = dbtp->data, len = 0; (c1 = getchar()) != '\n';) { - if (c1 == EOF) { - if (len == 0) - return (1); - err(1, "unexpected end of key/data pair"); - } - if ((c2 = getchar()) == EOF) - err(1, "unexpected end of key/data pair"); - if (len >= dbtp->ulen - 10) { - dbtp->ulen *= 2; - if ((dbtp->data = - (void *)realloc(dbtp->data, dbtp->ulen)) == NULL) { - errno = ENOMEM; - err(1, NULL); - } - p = (u_int8_t *)dbtp->data + len; - } - ++len; - *p++ = digitize(c1) << 4 | digitize(c2); - } - dbtp->size = len; - return (0); -} - -/* - * digitize -- - * Convert a character to an integer. - */ -int -digitize(c) - int c; -{ - switch (c) { /* Don't depend on ASCII ordering. */ - case '0': return (0); - case '1': return (1); - case '2': return (2); - case '3': return (3); - case '4': return (4); - case '5': return (5); - case '6': return (6); - case '7': return (7); - case '8': return (8); - case '9': return (9); - case 'a': return (10); - case 'b': return (11); - case 'c': return (12); - case 'd': return (13); - case 'e': return (14); - case 'f': return (15); - } - - err(1, "unexpected hexadecimal value"); - /* NOTREACHED */ - - return (0); -} - -/* - * badnum -- - * Display the bad number message. - */ -void -badnum() -{ - err(1, "boolean name=value pairs require a value of 0 or 1"); -} - -/* - * siginit -- - * Initialize the set of signals for which we want to clean up. - * Generally, we try not to leave the shared regions locked if - * we can. - */ -void -siginit() -{ -#ifdef SIGHUP - (void)signal(SIGHUP, onint); -#endif - (void)signal(SIGINT, onint); - (void)signal(SIGTERM, onint); -} - -/* - * onint -- - * Interrupt signal handler. - */ -void -onint(signo) - int signo; -{ - if ((interrupted = signo) == 0) - interrupted = SIGINT; -} - -/* - * usage -- - * Display the usage message. - */ -void -usage() -{ - (void)fprintf(stderr, "%s\n\t%s\n", - "usage: db_load [-nT]", - "[-c name=value] [-f file] [-h home] [-t btree | hash | recno] db_file"); - exit(1); -} diff --git a/db2/progs/db_printlog/README b/db2/progs/db_printlog/README deleted file mode 100644 index 05051f3..0000000 --- a/db2/progs/db_printlog/README +++ /dev/null @@ -1,22 +0,0 @@ -# @(#)README 10.3 (Sleepycat) 11/1/98 - -Berkeley DB log dump utility. This utility dumps out a DB log in human -readable form, a record at a time, to assist in recovery and transaction -abort debugging. - -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= -commit.awk Output transaction ID of committed transactions. - -count.awk Print out the number of log records for transactions - that we encountered. - -pgno.awk Take a comma-separated list of page numbers and spit - out all the log records that affect those page numbers. - -range.awk Print out a range of the log. - -status.awk Read through db_printlog output and list the transactions - encountered, and whether they commited or aborted. - -txn.awk Print out all the records for a comma-separated list of - transaction IDs. diff --git a/db2/progs/db_printlog/commit.awk b/db2/progs/db_printlog/commit.awk deleted file mode 100644 index 711064b..0000000 --- a/db2/progs/db_printlog/commit.awk +++ /dev/null @@ -1,7 +0,0 @@ -# @(#)commit.awk 10.1 (Sleepycat) 11/1/98 -# -# Output tid of committed transactions. - -/txn_regop/ { - print $5 -} diff --git a/db2/progs/db_printlog/count.awk b/db2/progs/db_printlog/count.awk deleted file mode 100644 index a0b214a..0000000 --- a/db2/progs/db_printlog/count.awk +++ /dev/null @@ -1,9 +0,0 @@ -# @(#)count.awk 10.1 (Sleepycat) 11/1/98 -# -# Print out the number of log records for transactions that we -# encountered. - -/^\[/{ - if ($5 != 0) - print $5 -} diff --git a/db2/progs/db_printlog/db_printlog.c b/db2/progs/db_printlog/db_printlog.c deleted file mode 100644 index 5a0c2eb..0000000 --- a/db2/progs/db_printlog/db_printlog.c +++ /dev/null @@ -1,192 +0,0 @@ -/*- - * See the file LICENSE for redistribution information. - * - * Copyright (c) 1996, 1997, 1998 - * Sleepycat Software. All rights reserved. - */ - -#include "config.h" - -#ifndef lint -static const char copyright[] = -"@(#) Copyright (c) 1996, 1997, 1998\n\ - Sleepycat Software Inc. All rights reserved.\n"; -static const char sccsid[] = "@(#)db_printlog.c 10.17 (Sleepycat) 11/1/98"; -#endif - -#ifndef NO_SYSTEM_INCLUDES -#include - -#include -#include -#include -#include -#include -#include -#endif - -#include "db_int.h" -#include "shqueue.h" -#include "db_page.h" -#include "btree.h" -#include "hash.h" -#include "log.h" -#include "txn.h" -#include "db_am.h" -#include "clib_ext.h" - -DB_ENV *db_init __P((char *)); -int main __P((int, char *[])); -void onint __P((int)); -void siginit __P((void)); -void usage __P((void)); - -int interrupted; -const char - *progname = "db_printlog"; /* Program name. */ - -int -main(argc, argv) - int argc; - char *argv[]; -{ - extern char *optarg; - extern int optind; - DB_ENV *dbenv; - DBT data; - DB_LSN key; - int ch, ret; - char *home; - - ret = 0; - home = NULL; - while ((ch = getopt(argc, argv, "h:N")) != EOF) - switch (ch) { - case 'h': - home = optarg; - break; - case 'N': - (void)db_value_set(0, DB_MUTEXLOCKS); - break; - case '?': - default: - usage(); - } - argc -= optind; - argv += optind; - - if (argc > 0) - usage(); - - /* Initialize the environment. */ - siginit(); - dbenv = db_init(home); - - if ((errno = __bam_init_print(dbenv)) != 0 || - (errno = __db_init_print(dbenv)) != 0 || - (errno = __ham_init_print(dbenv)) != 0 || - (errno = __log_init_print(dbenv)) != 0 || - (errno = __txn_init_print(dbenv)) != 0) { - warn("initialization"); - (void)db_appexit(dbenv); - return (1); - } - - memset(&data, 0, sizeof(data)); - while (!interrupted) { - if ((errno = - log_get(dbenv->lg_info, &key, &data, DB_NEXT)) != 0) { - if (errno == DB_NOTFOUND) - break; - warn("log_get"); - goto err; - } - if (dbenv->tx_recover != NULL) - errno = dbenv->tx_recover(dbenv->lg_info, - &data, &key, 0, NULL); - else - errno = __db_dispatch(dbenv->lg_info, - &data, &key, 0, NULL); - - fflush(stdout); - if (errno != 0) { - warn("dispatch"); - goto err; - } - } - - if (0) { -err: ret = 1; - } - - if (dbenv != NULL && (errno = db_appexit(dbenv)) != 0) { - ret = 1; - warn(NULL); - } - - if (interrupted) { - (void)signal(interrupted, SIG_DFL); - (void)raise(interrupted); - /* NOTREACHED */ - } - - return (ret); -} - -/* - * db_init -- - * Initialize the environment. - */ -DB_ENV * -db_init(home) - char *home; -{ - DB_ENV *dbenv; - - if ((dbenv = (DB_ENV *)calloc(sizeof(DB_ENV), 1)) == NULL) { - errno = ENOMEM; - err(1, NULL); - } - dbenv->db_errfile = stderr; - dbenv->db_errpfx = progname; - - if ((errno = - db_appinit(home, NULL, dbenv, DB_CREATE | DB_INIT_LOG)) != 0) - err(1, "db_appinit"); - return (dbenv); -} - -/* - * siginit -- - * Initialize the set of signals for which we want to clean up. - * Generally, we try not to leave the shared regions locked if - * we can. - */ -void -siginit() -{ -#ifdef SIGHUP - (void)signal(SIGHUP, onint); -#endif - (void)signal(SIGINT, onint); - (void)signal(SIGTERM, onint); -} - -/* - * onint -- - * Interrupt signal handler. - */ -void -onint(signo) - int signo; -{ - if ((interrupted = signo) == 0) - interrupted = SIGINT; -} - -void -usage() -{ - fprintf(stderr, "usage: db_printlog [-N] [-h home]\n"); - exit (1); -} diff --git a/db2/progs/db_printlog/pgno.awk b/db2/progs/db_printlog/pgno.awk deleted file mode 100644 index 99aa38f..0000000 --- a/db2/progs/db_printlog/pgno.awk +++ /dev/null @@ -1,43 +0,0 @@ -# @(#)pgno.awk 10.1 (Sleepycat) 11/1/98 -# -# Take a comma-separated list of page numbers and spit out all the -# log records that affect those page numbers. - -{ - if (NR == 1) { - npages = 0 - while ((ndx = index(PGNO, ",")) != 0) { - pgno[npages] = substr(PGNO, 1, ndx - 1); - PGNO = substr(PGNO, ndx + 1, length(PGNO) - ndx); - npages++ - } - pgno[npages] = PGNO; - } -} -/^\[/{ - if (printme == 1) { - printf("%s\n", rec); - printme = 0 - } - rec = ""; - - rec = $0 -} -/^ /{ - rec = sprintf("%s\n%s", rec, $0); -} -/pgno/{ - for (i = 0; i <= npages; i++) - if ($2 == pgno[i]) - printme = 1 -} -/right/{ - for (i = 0; i <= npages; i++) - if ($2 == pgno[i]) - printme = 1 -} -/left/{ - for (i = 0; i <= npages; i++) - if ($2 == pgno[i]) - printme = 1 -} diff --git a/db2/progs/db_printlog/range.awk b/db2/progs/db_printlog/range.awk deleted file mode 100644 index 89c56ea..0000000 --- a/db2/progs/db_printlog/range.awk +++ /dev/null @@ -1,27 +0,0 @@ -# @(#)range.awk 10.1 (Sleepycat) 11/1/98 -# -# Print out a range of the log - -/^\[/{ - l = length($1) - 1; - i = index($1, "]"); - file = substr($1, 2, i - 2); - file += 0; - start = i + 2; - offset = substr($1, start, l - start + 1); - i = index(offset, "]"); - offset = substr($1, start, i - 1); - offset += 0; - - if ((file == START_FILE && offset >= START_OFFSET || file > START_FILE)\ - && (file < END_FILE || (file == END_FILE && offset < END_OFFSET))) - printme = 1 - else if (file == END_FILE && offset > END_OFFSET || file > END_FILE) - exit - else - printme = 0 -} -{ - if (printme == 1) - print $0 -} diff --git a/db2/progs/db_printlog/status.awk b/db2/progs/db_printlog/status.awk deleted file mode 100644 index d97e935..0000000 --- a/db2/progs/db_printlog/status.awk +++ /dev/null @@ -1,26 +0,0 @@ -# @(#)status.awk 10.1 (Sleepycat) 11/1/98 -# -# Read through db_printlog output and list all the transactions encountered -# and whether they commited or aborted. -# -# 1 = started -# 2 = commited -BEGIN { - cur_txn = 0 -} -/^\[/{ - if (status[$5] == 0) { - status[$5] = 1; - txns[cur_txn] = $5; - cur_txn++; - } -} -/txn_regop/ { - status[$5] = 2 -} -END { - for (i = 0; i < cur_txn; i++) { - printf("%s\t%s\n", - txns[i], status[txns[i]] == 1 ? "ABORT" : "COMMIT"); - } -} diff --git a/db2/progs/db_printlog/txn.awk b/db2/progs/db_printlog/txn.awk deleted file mode 100644 index c8d3bd3..0000000 --- a/db2/progs/db_printlog/txn.awk +++ /dev/null @@ -1,30 +0,0 @@ -# @(#)txn.awk 10.1 (Sleepycat) 11/1/98 -# -# Print out all the records for a comma-separated list of transaction ids. -{ - if (NR == 1) { - ntxns = 0 - while ((ndx = index(TXN, ",")) != 0) { - txn[ntxns] = substr(TXN, 1, ndx - 1); - TXN = substr(TXN, ndx + 1, length(TXN) - ndx); - ntxns++ - } - txn[ntxns] = TXN; - } -} -/^\[/{ - if (printme == 1) { - printf("%s\n", rec); - printme = 0 - } - rec = ""; - - for (i = 0; i <= ntxns; i++) - if (txn[i] == $5) { - rec = $0 - printme = 1 - } -} -/^ /{ - rec = sprintf("%s\n%s", rec, $0); -} diff --git a/db2/progs/db_recover/db_recover.c b/db2/progs/db_recover/db_recover.c deleted file mode 100644 index d946ca1..0000000 --- a/db2/progs/db_recover/db_recover.c +++ /dev/null @@ -1,147 +0,0 @@ -/*- - * See the file LICENSE for redistribution information. - * - * Copyright (c) 1996, 1997, 1998 - * Sleepycat Software. All rights reserved. - */ - -#include "config.h" - -#ifndef lint -static const char copyright[] = -"@(#) Copyright (c) 1996, 1997, 1998\n\ - Sleepycat Software Inc. All rights reserved.\n"; -static const char sccsid[] = "@(#)db_recover.c 10.23 (Sleepycat) 10/5/98"; -#endif - -#ifndef NO_SYSTEM_INCLUDES -#include - -#include -#include -#include -#include -#include -#endif - -#include "db_int.h" -#include "shqueue.h" -#include "txn.h" -#include "common_ext.h" -#include "clib_ext.h" - -DB_ENV *db_init __P((char *, u_int32_t, int)); -int main __P((int, char *[])); -void nosig __P((void)); -void usage __P((void)); - -const char - *progname = "db_recover"; /* Program name. */ - -int -main(argc, argv) - int argc; - char *argv[]; -{ - extern char *optarg; - extern int optind; - DB_ENV *dbenv; - time_t now; - u_int32_t flags; - int ch, verbose; - char *home; - - home = NULL; - flags = verbose = 0; - while ((ch = getopt(argc, argv, "ch:v")) != EOF) - switch (ch) { - case 'c': - LF_SET(DB_RECOVER_FATAL); - break; - case 'h': - home = optarg; - break; - case 'v': - verbose = 1; - break; - case '?': - default: - usage(); - } - argc -= optind; - argv += optind; - - if (argc != 0) - usage(); - - /* - * Ignore signals -- we don't want to be interrupted because we're - * spending all of our time in the DB library. - */ - nosig(); - dbenv = db_init(home, flags, verbose); - if (verbose) { - __db_err(dbenv, "Recovery complete at %.24s", ctime(&now)); - __db_err(dbenv, "%s %lx %s [%lu][%lu]", - "Maximum transaction id", - (u_long)dbenv->tx_info->region->last_txnid, - "Recovery checkpoint", - (u_long)dbenv->tx_info->region->last_ckp.file, - (u_long)dbenv->tx_info->region->last_ckp.offset); - } - - return (db_appexit(dbenv)); -} - -DB_ENV * -db_init(home, flags, verbose) - char *home; - u_int32_t flags; - int verbose; -{ - DB_ENV *dbenv; - u_int32_t local_flags; - - if ((dbenv = (DB_ENV *)calloc(sizeof(DB_ENV), 1)) == NULL) { - errno = ENOMEM; - err(1, NULL); - } - dbenv->db_errfile = stderr; - dbenv->db_errpfx = "db_recover"; - dbenv->db_verbose = verbose; - - /* Initialize environment for pathnames only. */ - local_flags = DB_CREATE | DB_INIT_LOG | - DB_INIT_MPOOL | DB_INIT_LOCK | DB_INIT_TXN | DB_USE_ENVIRON; - - if (LF_ISSET(DB_RECOVER_FATAL)) - local_flags |= DB_RECOVER_FATAL; - else - local_flags |= DB_RECOVER; - - if ((errno = db_appinit(home, NULL, dbenv, local_flags)) != 0) - err(1, "appinit failed"); - - return (dbenv); -} - -/* - * nosig -- - * We don't want to be interrupted. - */ -void -nosig() -{ -#ifdef SIGHUP - (void)signal(SIGHUP, SIG_IGN); -#endif - (void)signal(SIGINT, SIG_IGN); - (void)signal(SIGTERM, SIG_IGN); -} - -void -usage() -{ - (void)fprintf(stderr, "usage: db_recover [-cv] [-h home]\n"); - exit(1); -} diff --git a/db2/progs/db_stat/db_stat.c b/db2/progs/db_stat/db_stat.c deleted file mode 100644 index cef645d..0000000 --- a/db2/progs/db_stat/db_stat.c +++ /dev/null @@ -1,621 +0,0 @@ -/*- - * See the file LICENSE for redistribution information. - * - * Copyright (c) 1996, 1997, 1998 - * Sleepycat Software. All rights reserved. - */ - -#include "config.h" - -#ifndef lint -static const char copyright[] = -"@(#) Copyright (c) 1996, 1997, 1998\n\ - Sleepycat Software Inc. All rights reserved.\n"; -static const char sccsid[] = "@(#)db_stat.c 8.41 (Sleepycat) 10/3/98"; -#endif - -#ifndef NO_SYSTEM_INCLUDES -#include - -#include -#include -#include -#include -#include -#include -#include -#endif - -#undef stat - -#include "db_int.h" -#include "shqueue.h" -#include "db_shash.h" -#include "lock.h" -#include "mp.h" -#include "clib_ext.h" - -typedef enum { T_NOTSET, T_DB, T_LOCK, T_LOG, T_MPOOL, T_TXN } test_t; - -int argcheck __P((char *, const char *)); -void btree_stats __P((DB *)); -DB_ENV *db_init __P((char *, test_t)); -void dl __P((const char *, u_long)); -void hash_stats __P((DB *)); -int lock_ok __P((char *)); -void lock_stats __P((DB_ENV *)); -void log_stats __P((DB_ENV *)); -int main __P((int, char *[])); -int mpool_ok __P((char *)); -void mpool_stats __P((DB_ENV *)); -void nosig __P((void)); -void prflags __P((u_int32_t, const FN *)); -int txn_compare __P((const void *, const void *)); -void txn_stats __P((DB_ENV *)); -void usage __P((void)); - -char *internal; -const char - *progname = "db_stat"; /* Program name. */ - -int -main(argc, argv) - int argc; - char *argv[]; -{ - extern char *optarg; - extern int optind; - DB *dbp; - DB_ENV *dbenv; - test_t ttype; - int ch; - char *db, *home; - - ttype = T_NOTSET; - db = home = NULL; - while ((ch = getopt(argc, argv, "C:cd:h:lM:mNt")) != EOF) - switch (ch) { - case 'C': - ttype = T_LOCK; - if (!argcheck(internal = optarg, "Acflmo")) - usage(); - break; - case 'c': - ttype = T_LOCK; - break; - case 'd': - db = optarg; - ttype = T_DB; - break; - case 'h': - home = optarg; - break; - case 'l': - ttype = T_LOG; - break; - case 'M': - ttype = T_MPOOL; - if (!argcheck(internal = optarg, "Ahlm")) - usage(); - break; - case 'm': - ttype = T_MPOOL; - break; - case 'N': - (void)db_value_set(0, DB_MUTEXLOCKS); - break; - case 't': - ttype = T_TXN; - break; - case '?': - default: - usage(); - } - argc -= optind; - argv += optind; - - if (argc != 0 || ttype == T_NOTSET) - usage(); - - /* - * Ignore signals -- we don't want to be interrupted because we're - * spending all of our time in the DB library. - */ - nosig(); - dbenv = db_init(home, ttype); - - switch (ttype) { - case T_DB: - if ((errno = db_open(db, DB_UNKNOWN, - DB_RDONLY, 0, dbenv, NULL, &dbp)) != 0) { - warn("%s", db); - return (1); - } - switch (dbp->type) { - case DB_BTREE: - case DB_RECNO: - btree_stats(dbp); - break; - case DB_HASH: - hash_stats(dbp); - break; - case DB_UNKNOWN: - abort(); /* Impossible. */ - /* NOTREACHED */ - } - (void)dbp->close(dbp, 0); - break; - case T_LOCK: - lock_stats(dbenv); - break; - case T_LOG: - log_stats(dbenv); - break; - case T_MPOOL: - mpool_stats(dbenv); - break; - case T_TXN: - txn_stats(dbenv); - break; - case T_NOTSET: - abort(); /* Impossible. */ - /* NOTREACHED */ - } - - if ((errno = db_appexit(dbenv)) != 0) { - warn(NULL); - return (1); - } - return (0); -} - -/* - * btree_stats -- - * Display btree/recno statistics. - */ -void -btree_stats(dbp) - DB *dbp; -{ - static const FN fn[] = { - { DB_DUP, "DB_DUP" }, - { DB_FIXEDLEN, "DB_FIXEDLEN" }, - { DB_RECNUM, "DB_RECNUM" }, - { DB_RENUMBER, "DB_RENUMBER" }, - { 0 } - }; - DB_BTREE_STAT *sp; - - if (dbp->stat(dbp, &sp, NULL, 0)) - err(1, "dbp->stat"); - -#define PCT(f, t) \ - (t == 0 ? 0 : \ - (((double)((t * sp->bt_pagesize) - f) / (t * sp->bt_pagesize)) * 100)) - - printf("%#lx\tBtree magic number.\n", (u_long)sp->bt_magic); - printf("%lu\tBtree version number.\n", (u_long)sp->bt_version); - prflags(sp->bt_flags, fn); - if (dbp->type == DB_BTREE) { -#ifdef NOT_IMPLEMENTED - dl("Maximum keys per-page.\n", (u_long)sp->bt_maxkey); -#endif - dl("Minimum keys per-page.\n", (u_long)sp->bt_minkey); - } - if (dbp->type == DB_RECNO) { - dl("Fixed-length record size.\n", (u_long)sp->bt_re_len); - if (isprint(sp->bt_re_pad)) - printf("%c\tFixed-length record pad.\n", - (int)sp->bt_re_pad); - else - printf("0x%x\tFixed-length record pad.\n", - (int)sp->bt_re_pad); - } - dl("Underlying tree page size.\n", (u_long)sp->bt_pagesize); - dl("Number of levels in the tree.\n", (u_long)sp->bt_levels); - dl("Number of keys in the tree.\n", (u_long)sp->bt_nrecs); - dl("Number of tree internal pages.\n", (u_long)sp->bt_int_pg); - dl("Number of tree leaf pages.\n", (u_long)sp->bt_leaf_pg); - dl("Number of tree duplicate pages.\n", (u_long)sp->bt_dup_pg); - dl("Number of tree overflow pages.\n", (u_long)sp->bt_over_pg); - dl("Number of pages on the free list.\n", (u_long)sp->bt_free); - dl("Number of bytes free in tree internal pages", - (u_long)sp->bt_int_pgfree); - printf(" (%.0f%% ff).\n", PCT(sp->bt_int_pgfree, sp->bt_int_pg)); - dl("Number of bytes free in tree leaf pages", - (u_long)sp->bt_leaf_pgfree); - printf(" (%.0f%% ff).\n", PCT(sp->bt_leaf_pgfree, sp->bt_leaf_pg)); - dl("Number of bytes free in tree duplicate pages", - (u_long)sp->bt_dup_pgfree); - printf(" (%.0f%% ff).\n", PCT(sp->bt_dup_pgfree, sp->bt_dup_pg)); - dl("Number of bytes free in tree overflow pages", - (u_long)sp->bt_over_pgfree); - printf(" (%.0f%% ff).\n", PCT(sp->bt_over_pgfree, sp->bt_over_pg)); -} - -/* - * hash_stats -- - * Display hash statistics. - */ -void -hash_stats(dbp) - DB *dbp; -{ - COMPQUIET(dbp, NULL); - - printf("Hash statistics not currently available.\n"); - return; -} - -/* - * lock_stats -- - * Display lock statistics. - */ -void -lock_stats(dbenv) - DB_ENV *dbenv; -{ - DB_LOCK_STAT *sp; - - if (internal != NULL) { - __lock_dump_region(dbenv->lk_info, internal, stdout); - return; - } - - if (lock_stat(dbenv->lk_info, &sp, NULL)) - err(1, NULL); - - printf("%#lx\tLock magic number.\n", (u_long)sp->st_magic); - printf("%lu\tLock version number.\n", (u_long)sp->st_version); - dl("Lock region reference count.\n", (u_long)sp->st_refcnt); - dl("Lock region size.\n", (u_long)sp->st_regsize); - dl("Maximum number of locks.\n", (u_long)sp->st_maxlocks); - dl("Number of lock modes.\n", (u_long)sp->st_nmodes); - dl("Number of lock objects.\n", (u_long)sp->st_numobjs); - dl("Number of lockers.\n", (u_long)sp->st_nlockers); - dl("Number of lock conflicts.\n", (u_long)sp->st_nconflicts); - dl("Number of lock requests.\n", (u_long)sp->st_nrequests); - dl("Number of lock releases.\n", (u_long)sp->st_nreleases); - dl("Number of deadlocks.\n", (u_long)sp->st_ndeadlocks); - dl("The number of region locks granted without waiting.\n", - (u_long)sp->st_region_nowait); - dl("The number of region locks granted after waiting.\n", - (u_long)sp->st_region_wait); -} - -/* - * log_stats -- - * Display log statistics. - */ -void -log_stats(dbenv) - DB_ENV *dbenv; -{ - DB_LOG_STAT *sp; - - if (log_stat(dbenv->lg_info, &sp, NULL)) - err(1, NULL); - - printf("%#lx\tLog magic number.\n", (u_long)sp->st_magic); - printf("%lu\tLog version number.\n", (u_long)sp->st_version); - dl("Log region reference count.\n", (u_long)sp->st_refcnt); - dl("Log region size.\n", (u_long)sp->st_regsize); - printf("%#o\tLog file mode.\n", sp->st_mode); - if (sp->st_lg_max % MEGABYTE == 0) - printf("%luMb\tLog file size.\n", - (u_long)sp->st_lg_max / MEGABYTE); - else if (sp->st_lg_max % 1024 == 0) - printf("%luKb\tLog file size.\n", (u_long)sp->st_lg_max / 1024); - else - printf("%lu\tLog file size.\n", (u_long)sp->st_lg_max); - printf("%luMb\tLog bytes written (+%lu bytes).\n", - (u_long)sp->st_w_mbytes, (u_long)sp->st_w_bytes); - printf("%luMb\tLog bytes written since last checkpoint (+%lu bytes).\n", - (u_long)sp->st_wc_mbytes, (u_long)sp->st_wc_bytes); - dl("Total log file writes.\n", (u_long)sp->st_wcount); - dl("Total log file flushes.\n", (u_long)sp->st_scount); - printf("%lu\tCurrent log file number.\n", (u_long)sp->st_cur_file); - printf("%lu\tCurrent log file offset.\n", (u_long)sp->st_cur_offset); - dl("The number of region locks granted without waiting.\n", - (u_long)sp->st_region_nowait); - dl("The number of region locks granted after waiting.\n", - (u_long)sp->st_region_wait); -} - -/* - * mpool_stats -- - * Display mpool statistics. - */ -void -mpool_stats(dbenv) - DB_ENV *dbenv; -{ - DB_MPOOL_FSTAT **fsp; - DB_MPOOL_STAT *gsp; - - if (internal != NULL) { - __memp_dump_region(dbenv->mp_info, internal, stdout); - return; - } - - if (memp_stat(dbenv->mp_info, &gsp, &fsp, NULL)) - err(1, NULL); - - dl("Pool region reference count.\n", (u_long)gsp->st_refcnt); - dl("Pool region size.\n", (u_long)gsp->st_regsize); - dl("Cache size", (u_long)gsp->st_cachesize); - printf(" (%luK).\n", (u_long)gsp->st_cachesize / 1024); - dl("Requested pages found in the cache", (u_long)gsp->st_cache_hit); - if (gsp->st_cache_hit + gsp->st_cache_miss != 0) - printf(" (%.0f%%)", ((double)gsp->st_cache_hit / - (gsp->st_cache_hit + gsp->st_cache_miss)) * 100); - printf(".\n"); - dl("Requested pages mapped into the process' address space.\n", - (u_long)gsp->st_map); - dl("Requested pages not found in the cache.\n", - (u_long)gsp->st_cache_miss); - dl("Pages created in the cache.\n", (u_long)gsp->st_page_create); - dl("Pages read into the cache.\n", (u_long)gsp->st_page_in); - dl("Pages written from the cache to the backing file.\n", - (u_long)gsp->st_page_out); - dl("Clean pages forced from the cache.\n", - (u_long)gsp->st_ro_evict); - dl("Dirty pages forced from the cache.\n", - (u_long)gsp->st_rw_evict); - dl("Dirty buffers written by trickle-sync thread.\n", - (u_long)gsp->st_page_trickle); - dl("Current clean buffer count.\n", - (u_long)gsp->st_page_clean); - dl("Current dirty buffer count.\n", - (u_long)gsp->st_page_dirty); - dl("Number of hash buckets used for page location.\n", - (u_long)gsp->st_hash_buckets); - dl("Total number of times hash chains searched for a page.\n", - (u_long)gsp->st_hash_searches); - dl("The longest hash chain searched for a page.\n", - (u_long)gsp->st_hash_longest); - dl("Total number of hash buckets examined for page location.\n", - (u_long)gsp->st_hash_examined); - dl("The number of region locks granted without waiting.\n", - (u_long)gsp->st_region_nowait); - dl("The number of region locks granted after waiting.\n", - (u_long)gsp->st_region_wait); - - for (; fsp != NULL && *fsp != NULL; ++fsp) { - printf("%s\n", DB_LINE); - printf("%s\n", (*fsp)->file_name); - dl("Page size.\n", (u_long)(*fsp)->st_pagesize); - dl("Requested pages found in the cache", - (u_long)(*fsp)->st_cache_hit); - if ((*fsp)->st_cache_hit + (*fsp)->st_cache_miss != 0) - printf(" (%.0f%%)", ((double)(*fsp)->st_cache_hit / - ((*fsp)->st_cache_hit + (*fsp)->st_cache_miss)) * - 100); - printf(".\n"); - dl("Requested pages mapped into the process' address space.\n", - (u_long)(*fsp)->st_map); - dl("Requested pages not found in the cache.\n", - (u_long)(*fsp)->st_cache_miss); - dl("Pages created in the cache.\n", - (u_long)(*fsp)->st_page_create); - dl("Pages read into the cache.\n", - (u_long)(*fsp)->st_page_in); - dl("Pages written from the cache to the backing file.\n", - (u_long)(*fsp)->st_page_out); - } -} - -/* - * txn_stats -- - * Display transaction statistics. - */ -void -txn_stats(dbenv) - DB_ENV *dbenv; -{ - DB_TXN_STAT *sp; - u_int32_t i; - const char *p; - - if (txn_stat(dbenv->tx_info, &sp, NULL)) - err(1, NULL); - - dl("Txn region reference count.\n", (u_long)sp->st_refcnt); - dl("Txn region size.\n", (u_long)sp->st_regsize); - p = sp->st_last_ckp.file == 0 ? - "No checkpoint LSN." : "File/offset for last checkpoint LSN."; - printf("%lu/%lu\t%s\n", - (u_long)sp->st_last_ckp.file, (u_long)sp->st_last_ckp.offset, p); - p = sp->st_pending_ckp.file == 0 ? - "No pending checkpoint LSN." : - "File/offset for last pending checkpoint LSN."; - printf("%lu/%lu\t%s\n", - (u_long)sp->st_pending_ckp.file, - (u_long)sp->st_pending_ckp.offset, p); - if (sp->st_time_ckp == 0) - printf("0\tNo checkpoint timestamp.\n"); - else - printf("%.24s\tCheckpoint timestamp.\n", - ctime(&sp->st_time_ckp)); - printf("%lx\tLast transaction ID allocated.\n", - (u_long)sp->st_last_txnid); - dl("Maximum number of active transactions.\n", (u_long)sp->st_maxtxns); - dl("Number of transactions begun.\n", (u_long)sp->st_nbegins); - dl("Number of transactions aborted.\n", (u_long)sp->st_naborts); - dl("Number of transactions committed.\n", (u_long)sp->st_ncommits); - dl("The number of region locks granted without waiting.\n", - (u_long)sp->st_region_nowait); - dl("The number of region locks granted after waiting.\n", - (u_long)sp->st_region_wait); - dl("Active transactions.\n", (u_long)sp->st_nactive); - qsort(sp->st_txnarray, - sp->st_nactive, sizeof(sp->st_txnarray[0]), txn_compare); - for (i = 0; i < sp->st_nactive; ++i) - printf("\tid: %lx; initial LSN file/offest %lu/%lu\n", - (u_long)sp->st_txnarray[i].txnid, - (u_long)sp->st_txnarray[i].lsn.file, - (u_long)sp->st_txnarray[i].lsn.offset); -} - -int -txn_compare(a1, b1) - const void *a1, *b1; -{ - const DB_TXN_ACTIVE *a, *b; - - a = a1; - b = b1; - - if (a->txnid > b->txnid) - return (1); - if (a->txnid < b->txnid) - return (-1); - return (0); -} - -/* - * dl -- - * Display a big value. - */ -void -dl(msg, value) - const char *msg; - u_long value; -{ - /* - * Two formats: if less than 10 million, display as the number, if - * greater than 10 million display as ###M. - */ - if (value < 10000000) - printf("%lu\t%s", value, msg); - else - printf("%luM\t%s", value / 1000000, msg); -} - -/* - * prflags -- - * Print out flag values. - */ -void -prflags(flags, fnp) - u_int32_t flags; - const FN *fnp; -{ - const char *sep; - - sep = " "; - printf("Flags:"); - for (; fnp->mask != 0; ++fnp) - if (fnp->mask & flags) { - printf("%s%s", sep, fnp->name); - sep = ", "; - } - printf("\n"); -} - -/* - * db_init -- - * Initialize the environment. - */ -DB_ENV * -db_init(home, ttype) - char *home; - test_t ttype; -{ - DB_ENV *dbenv; - u_int32_t flags; - - if ((dbenv = (DB_ENV *)malloc(sizeof(DB_ENV))) == NULL) { - errno = ENOMEM; - err(1, NULL); - } - - /* - * Try and use the shared regions when reporting statistics on the - * DB databases, so our information is as up-to-date as possible, - * even if the mpool cache hasn't been flushed. If that fails, we - * turn off the DB_INIT_MPOOL flag and try again. - */ - flags = DB_USE_ENVIRON; - switch (ttype) { - case T_DB: - case T_MPOOL: - LF_SET(DB_INIT_MPOOL); - break; - case T_LOCK: - LF_SET(DB_INIT_LOCK); - break; - case T_LOG: - LF_SET(DB_INIT_LOG); - break; - case T_TXN: - LF_SET(DB_INIT_TXN); - break; - case T_NOTSET: - abort(); - /* NOTREACHED */ - } - - /* - * If it works, we're done. Set the error output options so that - * future errors are correctly reported. - */ - memset(dbenv, 0, sizeof(*dbenv)); - if ((errno = db_appinit(home, NULL, dbenv, flags)) == 0) { - dbenv->db_errfile = stderr; - dbenv->db_errpfx = progname; - return (dbenv); - } - - /* Turn off the DB_INIT_MPOOL flag if it's a database. */ - if (ttype == T_DB) - LF_CLR(DB_INIT_MPOOL); - - /* Set the error output options -- this time we want a message. */ - memset(dbenv, 0, sizeof(*dbenv)); - dbenv->db_errfile = stderr; - dbenv->db_errpfx = progname; - - /* Try again, and it's fatal if we fail. */ - if ((errno = db_appinit(home, NULL, dbenv, flags)) != 0) - err(1, "db_appinit"); - - return (dbenv); -} - -/* - * argcheck -- - * Return if argument flags are okay. - */ -int -argcheck(arg, ok_args) - char *arg; - const char *ok_args; -{ - for (; *arg != '\0'; ++arg) - if (strchr(ok_args, *arg) == NULL) - return (0); - return (1); -} - -/* - * nosig -- - * We don't want to be interrupted. - */ -void -nosig() -{ -#ifdef SIGHUP - (void)signal(SIGHUP, SIG_IGN); -#endif - (void)signal(SIGINT, SIG_IGN); - (void)signal(SIGTERM, SIG_IGN); -} - -void -usage() -{ - fprintf(stderr, - "usage: db_stat [-clmNt] [-C Acflmo] [-d file] [-h home] [-M Ahlm]\n"); - exit (1); -} -- cgit v1.1