17c478bdstevel@tonic-gate/*-
27c478bdstevel@tonic-gate * See the file LICENSE for redistribution information.
37c478bdstevel@tonic-gate *
47c478bdstevel@tonic-gate * Copyright (c) 1996, 1997, 1998
57c478bdstevel@tonic-gate *	Sleepycat Software.  All rights reserved.
67c478bdstevel@tonic-gate *
77c478bdstevel@tonic-gate *	@(#)db.h	10.174 (Sleepycat) 1/3/99
87c478bdstevel@tonic-gate */
97c478bdstevel@tonic-gate
107c478bdstevel@tonic-gate#ifndef _DB_H_
117c478bdstevel@tonic-gate#define	_DB_H_
127c478bdstevel@tonic-gate
137c478bdstevel@tonic-gate#ifndef __NO_SYSTEM_INCLUDES
147c478bdstevel@tonic-gate#include <sys/types.h>
157c478bdstevel@tonic-gate
167c478bdstevel@tonic-gate#include <stdio.h>
177c478bdstevel@tonic-gate#endif
187c478bdstevel@tonic-gate
197c478bdstevel@tonic-gate/*
207c478bdstevel@tonic-gate * XXX
217c478bdstevel@tonic-gate * MacOS: ensure that Metrowerks C makes enumeration types int sized.
227c478bdstevel@tonic-gate */
237c478bdstevel@tonic-gate#ifdef __MWERKS__
247c478bdstevel@tonic-gate#pragma enumsalwaysint on
257c478bdstevel@tonic-gate#endif
267c478bdstevel@tonic-gate
277c478bdstevel@tonic-gate/*
287c478bdstevel@tonic-gate * XXX
297c478bdstevel@tonic-gate * Handle function prototypes and the keyword "const".  This steps on name
307c478bdstevel@tonic-gate * space that DB doesn't control, but all of the other solutions are worse.
317c478bdstevel@tonic-gate *
327c478bdstevel@tonic-gate * XXX
337c478bdstevel@tonic-gate * While Microsoft's compiler is ANSI C compliant, it doesn't have _STDC_
347c478bdstevel@tonic-gate * defined by default, you specify a command line flag or #pragma to turn
357c478bdstevel@tonic-gate * it on.  Don't do that, however, because some of Microsoft's own header
367c478bdstevel@tonic-gate * files won't compile.
377c478bdstevel@tonic-gate */
387c478bdstevel@tonic-gate#undef	__P
397c478bdstevel@tonic-gate#if defined(__STDC__) || defined(__cplusplus) || defined(_MSC_VER)
407c478bdstevel@tonic-gate#define	__P(protos)	protos		/* ANSI C prototypes */
417c478bdstevel@tonic-gate#else
427c478bdstevel@tonic-gate#define	const
437c478bdstevel@tonic-gate#define	__P(protos)	()		/* K&R C preprocessor */
447c478bdstevel@tonic-gate#endif
457c478bdstevel@tonic-gate
467c478bdstevel@tonic-gate/*
477c478bdstevel@tonic-gate * !!!
487c478bdstevel@tonic-gate * DB needs basic information about specifically sized types.  If they're
497c478bdstevel@tonic-gate * not provided by the system, typedef them here.
507c478bdstevel@tonic-gate *
517c478bdstevel@tonic-gate * We protect them against multiple inclusion using __BIT_TYPES_DEFINED__,
527c478bdstevel@tonic-gate * as does BIND and Kerberos, since we don't know for sure what #include
537c478bdstevel@tonic-gate * files the user is using.
547c478bdstevel@tonic-gate *
557c478bdstevel@tonic-gate * !!!
567c478bdstevel@tonic-gate * We also provide the standard u_int, u_long etc., if they're not provided
577c478bdstevel@tonic-gate * by the system.
587c478bdstevel@tonic-gate */
597c478bdstevel@tonic-gate#ifndef	__BIT_TYPES_DEFINED__
607c478bdstevel@tonic-gate#define	__BIT_TYPES_DEFINED__
617c478bdstevel@tonic-gatetypedef unsigned char u_int8_t;
627c478bdstevel@tonic-gate
637c478bdstevel@tonic-gatetypedef unsigned short u_int16_t;
647c478bdstevel@tonic-gate
657c478bdstevel@tonic-gatetypedef unsigned int u_int32_t;
667c478bdstevel@tonic-gate#endif
677c478bdstevel@tonic-gate
687c478bdstevel@tonic-gate
697c478bdstevel@tonic-gate
707c478bdstevel@tonic-gate
717c478bdstevel@tonic-gate
727c478bdstevel@tonic-gate
737c478bdstevel@tonic-gate#define	DB_VERSION_MAJOR	2
747c478bdstevel@tonic-gate#define	DB_VERSION_MINOR	7
757c478bdstevel@tonic-gate#define	DB_VERSION_PATCH	7
767c478bdstevel@tonic-gate#define	DB_VERSION_STRING	"Sleepycat Software: Berkeley DB 2.7.7: (08/20/99)"
777c478bdstevel@tonic-gate
787c478bdstevel@tonic-gatetypedef	u_int32_t	db_pgno_t;	/* Page number type. */
797c478bdstevel@tonic-gatetypedef	u_int16_t	db_indx_t;	/* Page offset type. */
807c478bdstevel@tonic-gate#define	DB_MAX_PAGES	0xffffffff	/* >= # of pages in a file */
817c478bdstevel@tonic-gate
827c478bdstevel@tonic-gatetypedef	u_int32_t	db_recno_t;	/* Record number type. */
837c478bdstevel@tonic-gate#define	DB_MAX_RECORDS	0xffffffff	/* >= # of records in a tree */
847c478bdstevel@tonic-gate
857c478bdstevel@tonic-gatetypedef size_t		DB_LOCK;	/* Object returned by lock manager. */
867c478bdstevel@tonic-gate
877c478bdstevel@tonic-gate/* Forward structure declarations, so applications get type checking. */
887c478bdstevel@tonic-gatestruct __db;		typedef struct __db DB;
897c478bdstevel@tonic-gate#ifdef DB_DBM_HSEARCH
907c478bdstevel@tonic-gate			typedef struct __db DBM;
917c478bdstevel@tonic-gate#endif
927c478bdstevel@tonic-gatestruct __db_bt_stat;	typedef struct __db_bt_stat DB_BTREE_STAT;
937c478bdstevel@tonic-gatestruct __db_dbt;	typedef struct __db_dbt DBT;
947c478bdstevel@tonic-gatestruct __db_env;	typedef struct __db_env DB_ENV;
957c478bdstevel@tonic-gatestruct __db_ilock;	typedef struct __db_ilock DB_LOCK_ILOCK;
967c478bdstevel@tonic-gatestruct __db_info;	typedef struct __db_info DB_INFO;
977c478bdstevel@tonic-gatestruct __db_lock_stat;	typedef struct __db_lock_stat DB_LOCK_STAT;
987c478bdstevel@tonic-gatestruct __db_lockregion;	typedef struct __db_lockregion DB_LOCKREGION;
997c478bdstevel@tonic-gatestruct __db_lockreq;	typedef struct __db_lockreq DB_LOCKREQ;
1007c478bdstevel@tonic-gatestruct __db_locktab;	typedef struct __db_locktab DB_LOCKTAB;
1017c478bdstevel@tonic-gatestruct __db_log;	typedef struct __db_log DB_LOG;
1027c478bdstevel@tonic-gatestruct __db_log_stat;	typedef struct __db_log_stat DB_LOG_STAT;
1037c478bdstevel@tonic-gatestruct __db_lsn;	typedef struct __db_lsn DB_LSN;
1047c478bdstevel@tonic-gatestruct __db_mpool;	typedef struct __db_mpool DB_MPOOL;
1057c478bdstevel@tonic-gatestruct __db_mpool_finfo;typedef struct __db_mpool_finfo DB_MPOOL_FINFO;
1067c478bdstevel@tonic-gatestruct __db_mpool_fstat;typedef struct __db_mpool_fstat DB_MPOOL_FSTAT;
1077c478bdstevel@tonic-gatestruct __db_mpool_stat;	typedef struct __db_mpool_stat DB_MPOOL_STAT;
1087c478bdstevel@tonic-gatestruct __db_mpoolfile;	typedef struct __db_mpoolfile DB_MPOOLFILE;
1097c478bdstevel@tonic-gatestruct __db_txn;	typedef struct __db_txn DB_TXN;
1107c478bdstevel@tonic-gatestruct __db_txn_active;	typedef struct __db_txn_active DB_TXN_ACTIVE;
1117c478bdstevel@tonic-gatestruct __db_txn_stat;	typedef struct __db_txn_stat DB_TXN_STAT;
1127c478bdstevel@tonic-gatestruct __db_txnmgr;	typedef struct __db_txnmgr DB_TXNMGR;
1137c478bdstevel@tonic-gatestruct __db_txnregion;	typedef struct __db_txnregion DB_TXNREGION;
1147c478bdstevel@tonic-gatestruct __dbc;		typedef struct __dbc DBC;
1157c478bdstevel@tonic-gate
1167c478bdstevel@tonic-gate/* Key/data structure -- a Data-Base Thang. */
1177c478bdstevel@tonic-gatestruct __db_dbt {
1187c478bdstevel@tonic-gate	void	 *data;			/* key/data */
1197c478bdstevel@tonic-gate	u_int32_t size;			/* key/data length */
1207c478bdstevel@tonic-gate	u_int32_t ulen;			/* RO: length of user buffer. */
1217c478bdstevel@tonic-gate	u_int32_t dlen;			/* RO: get/put record length. */
1227c478bdstevel@tonic-gate	u_int32_t doff;			/* RO: get/put record offset. */
1237c478bdstevel@tonic-gate
1247c478bdstevel@tonic-gate#define	DB_DBT_INTERNAL	0x01		/* Ignore user's malloc (internal). */
1257c478bdstevel@tonic-gate#define	DB_DBT_MALLOC	0x02		/* Return in allocated memory. */
1267c478bdstevel@tonic-gate#define	DB_DBT_PARTIAL	0x04		/* Partial put/get. */
1277c478bdstevel@tonic-gate#define	DB_DBT_USERMEM	0x08		/* Return in user's memory. */
1287c478bdstevel@tonic-gate	u_int32_t flags;
1297c478bdstevel@tonic-gate};
1307c478bdstevel@tonic-gate
1317c478bdstevel@tonic-gate/*
1327c478bdstevel@tonic-gate * DB run-time interface configuration.
1337c478bdstevel@tonic-gate *
1347c478bdstevel@tonic-gate * There are a set of functions that the application can replace with its
1357c478bdstevel@tonic-gate * own versions, and some other knobs which can be turned at run-time.
1367c478bdstevel@tonic-gate */
1377c478bdstevel@tonic-gate#define	DB_FUNC_CLOSE	 1		/* POSIX 1003.1 close. */
1387c478bdstevel@tonic-gate#define	DB_FUNC_DIRFREE	 2		/* DB: free directory list. */
1397c478bdstevel@tonic-gate#define	DB_FUNC_DIRLIST	 3		/* DB: create directory list. */
1407c478bdstevel@tonic-gate#define	DB_FUNC_EXISTS	 4		/* DB: return if file exists. */
1417c478bdstevel@tonic-gate#define	DB_FUNC_FREE	 5		/* ANSI C free. */
1427c478bdstevel@tonic-gate#define	DB_FUNC_FSYNC	 6		/* POSIX 1003.1 fsync. */
1437c478bdstevel@tonic-gate#define	DB_FUNC_IOINFO	 7		/* DB: return file I/O information. */
1447c478bdstevel@tonic-gate#define	DB_FUNC_MALLOC	 8		/* ANSI C malloc. */
1457c478bdstevel@tonic-gate#define	DB_FUNC_MAP	 9		/* DB: map file into shared memory. */
1467c478bdstevel@tonic-gate#define	DB_FUNC_OPEN	10		/* POSIX 1003.1 open. */
1477c478bdstevel@tonic-gate#define	DB_FUNC_READ	11		/* POSIX 1003.1 read. */
1487c478bdstevel@tonic-gate#define	DB_FUNC_REALLOC	12		/* ANSI C realloc. */
1497c478bdstevel@tonic-gate#define	DB_FUNC_RUNLINK	13		/* DB: remove a shared region. */
1507c478bdstevel@tonic-gate#define	DB_FUNC_SEEK	14		/* POSIX 1003.1 lseek. */
1517c478bdstevel@tonic-gate#define	DB_FUNC_SLEEP	15		/* DB: sleep secs/usecs. */
1527c478bdstevel@tonic-gate#define	DB_FUNC_UNLINK	16		/* POSIX 1003.1 unlink. */
1537c478bdstevel@tonic-gate#define	DB_FUNC_UNMAP	17		/* DB: unmap shared memory file. */
1547c478bdstevel@tonic-gate#define	DB_FUNC_WRITE	18		/* POSIX 1003.1 write. */
1557c478bdstevel@tonic-gate#define	DB_FUNC_YIELD	19		/* DB: yield thread to scheduler. */
1567c478bdstevel@tonic-gate#define	DB_MUTEXLOCKS	20		/* DB: turn off all mutex locks. */
1577c478bdstevel@tonic-gate#define	DB_PAGEYIELD	21		/* DB: yield the CPU on pool get. */
1587c478bdstevel@tonic-gate#define	DB_REGION_ANON	22		/* DB: anonymous, unnamed regions. */
1597c478bdstevel@tonic-gate#define	DB_REGION_INIT	23		/* DB: page-fault regions in create. */
1607c478bdstevel@tonic-gate#define	DB_REGION_NAME	24		/* DB: anonymous, named regions. */
1617c478bdstevel@tonic-gate#define	DB_TSL_SPINS	25		/* DB: initialize spin count. */
1627c478bdstevel@tonic-gate
1637c478bdstevel@tonic-gate/*
1647c478bdstevel@tonic-gate * Database configuration and initialization.
1657c478bdstevel@tonic-gate */
1667c478bdstevel@tonic-gate /*
1677c478bdstevel@tonic-gate  * Flags understood by both db_open(3) and db_appinit(3).
1687c478bdstevel@tonic-gate  */
1697c478bdstevel@tonic-gate#define	DB_CREATE	      0x000001	/* O_CREAT: create file as necessary. */
1707c478bdstevel@tonic-gate#define	DB_NOMMAP	      0x000002	/* Don't mmap underlying file. */
1717c478bdstevel@tonic-gate#define	DB_THREAD	      0x000004	/* Free-thread DB package handles. */
1727c478bdstevel@tonic-gate
1737c478bdstevel@tonic-gate/*
1747c478bdstevel@tonic-gate * Flags understood by db_appinit(3).
1757c478bdstevel@tonic-gate */
1767c478bdstevel@tonic-gate/*			      0x000007	   COMMON MASK. */
1777c478bdstevel@tonic-gate#define	DB_INIT_CDB	      0x000008	/* Concurrent Access Methods. */
1787c478bdstevel@tonic-gate#define	DB_INIT_LOCK	      0x000010	/* Initialize locking. */
1797c478bdstevel@tonic-gate#define	DB_INIT_LOG	      0x000020	/* Initialize logging. */
1807c478bdstevel@tonic-gate#define	DB_INIT_MPOOL	      0x000040	/* Initialize mpool. */
1817c478bdstevel@tonic-gate#define	DB_INIT_TXN	      0x000080	/* Initialize transactions. */
1827c478bdstevel@tonic-gate#define	DB_MPOOL_PRIVATE      0x000100	/* Mpool: private memory pool. */
1837c478bdstevel@tonic-gate#define	DB_RECOVER	      0x000200	/* Run normal recovery. */
1847c478bdstevel@tonic-gate#define	DB_RECOVER_FATAL      0x000400	/* Run catastrophic recovery. */
1857c478bdstevel@tonic-gate#define	DB_TXN_NOSYNC	      0x000800	/* Do not sync log on commit. */
1867c478bdstevel@tonic-gate#define	DB_USE_ENVIRON	      0x001000	/* Use the environment. */
1877c478bdstevel@tonic-gate#define	DB_USE_ENVIRON_ROOT   0x002000	/* Use the environment if root. */
1887c478bdstevel@tonic-gate
1897c478bdstevel@tonic-gate/*
1907c478bdstevel@tonic-gate * Flags understood by db_open(3).
1917c478bdstevel@tonic-gate *
1927c478bdstevel@tonic-gate * DB_EXCL and DB_TEMPORARY are internal only, and are not documented.
1937c478bdstevel@tonic-gate * DB_SEQUENTIAL is currently internal, but may be exported some day.
1947c478bdstevel@tonic-gate */
1957c478bdstevel@tonic-gate/*			      0x000007	   COMMON MASK. */
1967c478bdstevel@tonic-gate/*			      0x001fff	   ALREADY USED. */
1977c478bdstevel@tonic-gate#define	DB_EXCL		      0x002000	/* O_EXCL: exclusive open (internal). */
1987c478bdstevel@tonic-gate#define	DB_RDONLY	      0x004000	/* O_RDONLY: read-only. */
1997c478bdstevel@tonic-gate#define	DB_SEQUENTIAL	      0x008000	/* Sequential access (internal). */
2007c478bdstevel@tonic-gate#define	DB_TEMPORARY	      0x010000	/* Remove on last close (internal). */
2017c478bdstevel@tonic-gate#define	DB_TRUNCATE	      0x020000	/* O_TRUNCATE: replace existing DB. */
2027c478bdstevel@tonic-gate#define	DB_FCNTL_LOCKING      0x040000	/* Undocumented: fcntl(2) locking. */
2037c478bdstevel@tonic-gate
2047c478bdstevel@tonic-gate/*
2057c478bdstevel@tonic-gate * Deadlock detector modes; used in the DBENV structure to configure the
2067c478bdstevel@tonic-gate * locking subsystem.
2077c478bdstevel@tonic-gate */
2087c478bdstevel@tonic-gate#define	DB_LOCK_NORUN		0
2097c478bdstevel@tonic-gate#define	DB_LOCK_DEFAULT		1	/* Default policy. */
2107c478bdstevel@tonic-gate#define	DB_LOCK_OLDEST		2	/* Abort oldest transaction. */
2117c478bdstevel@tonic-gate#define	DB_LOCK_RANDOM		3	/* Abort random transaction. */
2127c478bdstevel@tonic-gate#define	DB_LOCK_YOUNGEST	4	/* Abort youngest transaction. */
2137c478bdstevel@tonic-gate
2147c478bdstevel@tonic-gatestruct __db_env {
2157c478bdstevel@tonic-gate	int		 db_lorder;	/* Byte order. */
2167c478bdstevel@tonic-gate
2177c478bdstevel@tonic-gate					/* Error message callback. */
2187c478bdstevel@tonic-gate	void (*db_errcall) __P((const char *, char *));
2197c478bdstevel@tonic-gate	FILE		*db_errfile;	/* Error message file stream. */
2207c478bdstevel@tonic-gate	const char	*db_errpfx;	/* Error message prefix. */
2217c478bdstevel@tonic-gate	int		 db_verbose;	/* Generate debugging messages. */
2227c478bdstevel@tonic-gate	int		 db_panic;	/* Panic flag, callback function. */
2237c478bdstevel@tonic-gate	void (*db_paniccall) __P((DB_ENV *, int));
2247c478bdstevel@tonic-gate
2257c478bdstevel@tonic-gate	/* User paths. */
2267c478bdstevel@tonic-gate	char		*db_home;	/* Database home. */
2277c478bdstevel@tonic-gate	char		*db_log_dir;	/* Database log file directory. */
2287c478bdstevel@tonic-gate	char		*db_tmp_dir;	/* Database tmp file directory. */
2297c478bdstevel@tonic-gate
2307c478bdstevel@tonic-gate	char	       **db_data_dir;	/* Database data file directories. */
2317c478bdstevel@tonic-gate	int		 data_cnt;	/* Database data file slots. */
2327c478bdstevel@tonic-gate	int		 data_next;	/* Next Database data file slot. */
2337c478bdstevel@tonic-gate
2347c478bdstevel@tonic-gate	/* Locking. */
2357c478bdstevel@tonic-gate	DB_LOCKTAB	*lk_info;	/* Return from lock_open(). */
2367c478bdstevel@tonic-gate	const u_int8_t	*lk_conflicts;	/* Two dimensional conflict matrix. */
2377c478bdstevel@tonic-gate	u_int32_t	 lk_modes;	/* Number of lock modes in table. */
2387c478bdstevel@tonic-gate	u_int32_t	 lk_max;	/* Maximum number of locks. */
2397c478bdstevel@tonic-gate	u_int32_t	 lk_detect;	/* Deadlock detect on all conflicts. */
2407c478bdstevel@tonic-gate
2417c478bdstevel@tonic-gate	/* Logging. */
2427c478bdstevel@tonic-gate	DB_LOG		*lg_info;	/* Return from log_open(). */
2437c478bdstevel@tonic-gate	u_int32_t	 lg_max;	/* Maximum file size. */
2447c478bdstevel@tonic-gate
2457c478bdstevel@tonic-gate	/* Memory pool. */
2467c478bdstevel@tonic-gate	DB_MPOOL	*mp_info;	/* Return from memp_open(). */
2477c478bdstevel@tonic-gate	size_t		 mp_mmapsize;	/* Maximum file size for mmap. */
2487c478bdstevel@tonic-gate	size_t		 mp_size;	/* Bytes in the mpool cache. */
2497c478bdstevel@tonic-gate
2507c478bdstevel@tonic-gate	/* Transactions. */
2517c478bdstevel@tonic-gate	DB_TXNMGR	*tx_info;	/* Return from txn_open(). */
2527c478bdstevel@tonic-gate	u_int32_t	 tx_max;	/* Maximum number of transactions. */
2537c478bdstevel@tonic-gate	int (*tx_recover)		/* Dispatch function for recovery. */
2547c478bdstevel@tonic-gate	    __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
2557c478bdstevel@tonic-gate
2567c478bdstevel@tonic-gate	/*
2577c478bdstevel@tonic-gate	 * XA support.
2587c478bdstevel@tonic-gate	 *
2597c478bdstevel@tonic-gate	 * !!!
2607c478bdstevel@tonic-gate	 * Explicit representations of structures in queue.h.
2617c478bdstevel@tonic-gate	 *
2627c478bdstevel@tonic-gate	 * TAILQ_ENTRY(__db_env);
2637c478bdstevel@tonic-gate	 */
2647c478bdstevel@tonic-gate	struct {
2657c478bdstevel@tonic-gate		struct __db_env *tqe_next;
2667c478bdstevel@tonic-gate		struct __db_env **tqe_prev;
2677c478bdstevel@tonic-gate	} links;
2687c478bdstevel@tonic-gate	int		 xa_rmid;	/* XA Resource Manager ID. */
2697c478bdstevel@tonic-gate	DB_TXN		*xa_txn;	/* XA Current transaction. */
2707c478bdstevel@tonic-gate
2717c478bdstevel@tonic-gate#define	DB_ENV_APPINIT		0x01	/* Paths initialized by db_appinit(). */
2727c478bdstevel@tonic-gate#define	DB_ENV_CDB		0x02	/* Concurrent DB product. */
2737c478bdstevel@tonic-gate#define	DB_ENV_STANDALONE	0x04	/* Test: freestanding environment. */
2747c478bdstevel@tonic-gate#define	DB_ENV_THREAD		0x08	/* DB_ENV is multi-threaded. */
2757c478bdstevel@tonic-gate	u_int32_t	 flags;		/* Flags. */
2767c478bdstevel@tonic-gate};
2777c478bdstevel@tonic-gate
2787c478bdstevel@tonic-gate/*******************************************************
2797c478bdstevel@tonic-gate * Access methods.
2807c478bdstevel@tonic-gate *******************************************************/
2817c478bdstevel@tonic-gate/*
2827c478bdstevel@tonic-gate * !!!
2837c478bdstevel@tonic-gate * Changes here must be reflected in java/src/com/sleepycat/db/Db.java.
2847c478bdstevel@tonic-gate */
2857c478bdstevel@tonic-gatetypedef enum {
2867c478bdstevel@tonic-gate	DB_BTREE=1,			/* B+tree. */
2877c478bdstevel@tonic-gate	DB_HASH,			/* Extended Linear Hashing. */
2887c478bdstevel@tonic-gate	DB_RECNO,			/* Fixed and variable-length records. */
2897c478bdstevel@tonic-gate	DB_UNKNOWN			/* Figure it out on open. */
2907c478bdstevel@tonic-gate} DBTYPE;
2917c478bdstevel@tonic-gate
2927c478bdstevel@tonic-gate#define	DB_BTREEVERSION	6		/* Current btree version. */
2937c478bdstevel@tonic-gate#define	DB_BTREEOLDVER	6		/* Oldest btree version supported. */
2947c478bdstevel@tonic-gate#define	DB_BTREEMAGIC	0x053162
2957c478bdstevel@tonic-gate
2967c478bdstevel@tonic-gate#define	DB_HASHVERSION	5		/* Current hash version. */
2977c478bdstevel@tonic-gate#define	DB_HASHOLDVER	4		/* Oldest hash version supported. */
2987c478bdstevel@tonic-gate#define	DB_HASHMAGIC	0x061561
2997c478bdstevel@tonic-gate
3007c478bdstevel@tonic-gate#define	DB_LOGVERSION	2		/* Current log version. */
3017c478bdstevel@tonic-gate#define	DB_LOGOLDVER	2		/* Oldest log version supported. */
3027c478bdstevel@tonic-gate#define	DB_LOGMAGIC	0x040988
3037c478bdstevel@tonic-gate
3047c478bdstevel@tonic-gatestruct __db_info {
3057c478bdstevel@tonic-gate	int		 db_lorder;	/* Byte order. */
3067c478bdstevel@tonic-gate	size_t		 db_cachesize;	/* Underlying cache size. */
3077c478bdstevel@tonic-gate	size_t		 db_pagesize;	/* Underlying page size. */
3087c478bdstevel@tonic-gate
3097c478bdstevel@tonic-gate					/* Local heap allocation. */
3107c478bdstevel@tonic-gate	void *(*db_malloc) __P((size_t));
3117c478bdstevel@tonic-gate	int (*dup_compare)		/* Duplicate compare function. */
3127c478bdstevel@tonic-gate	    __P((const DBT *, const DBT *));
3137c478bdstevel@tonic-gate
3147c478bdstevel@tonic-gate	/* Btree access method. */
3157c478bdstevel@tonic-gate	u_int32_t	 bt_maxkey;	/* Maximum keys per page. */
3167c478bdstevel@tonic-gate	u_int32_t	 bt_minkey;	/* Minimum keys per page. */
3177c478bdstevel@tonic-gate	int (*bt_compare)		/* Comparison function. */
3187c478bdstevel@tonic-gate	    __P((const DBT *, const DBT *));
3197c478bdstevel@tonic-gate	size_t (*bt_prefix)		/* Prefix function. */
3207c478bdstevel@tonic-gate	    __P((const DBT *, const DBT *));
3217c478bdstevel@tonic-gate
3227c478bdstevel@tonic-gate	/* Hash access method. */
3237c478bdstevel@tonic-gate	u_int32_t 	 h_ffactor;	/* Fill factor. */
3247c478bdstevel@tonic-gate	u_int32_t	 h_nelem;	/* Number of elements. */
3257c478bdstevel@tonic-gate	u_int32_t      (*h_hash)	/* Hash function. */
3267c478bdstevel@tonic-gate	    __P((const void *, u_int32_t));
3277c478bdstevel@tonic-gate
3287c478bdstevel@tonic-gate	/* Recno access method. */
3297c478bdstevel@tonic-gate	int		 re_pad;	/* Fixed-length padding byte. */
3307c478bdstevel@tonic-gate	int		 re_delim;	/* Variable-length delimiting byte. */
3317c478bdstevel@tonic-gate	u_int32_t	 re_len;	/* Length for fixed-length records. */
3327c478bdstevel@tonic-gate	char		*re_source;	/* Source file name. */
3337c478bdstevel@tonic-gate
3347c478bdstevel@tonic-gate#define	DB_DELIMITER		0x0001	/* Recno: re_delim set. */
3357c478bdstevel@tonic-gate#define	DB_DUP			0x0002	/* Btree, Hash: duplicate keys. */
3367c478bdstevel@tonic-gate#define	DB_DUPSORT		0x0004	/* Btree, Hash: duplicate keys. */
3377c478bdstevel@tonic-gate#define	DB_FIXEDLEN		0x0008	/* Recno: fixed-length records. */
3387c478bdstevel@tonic-gate#define	DB_PAD			0x0010	/* Recno: re_pad set. */
3397c478bdstevel@tonic-gate#define	DB_RECNUM		0x0020	/* Btree: record numbers. */
3407c478bdstevel@tonic-gate#define	DB_RENUMBER		0x0040	/* Recno: renumber on insert/delete. */
3417c478bdstevel@tonic-gate#define	DB_SNAPSHOT		0x0080	/* Recno: snapshot the input. */
3427c478bdstevel@tonic-gate	u_int32_t	 flags;
3437c478bdstevel@tonic-gate};
3447c478bdstevel@tonic-gate
3457c478bdstevel@tonic-gate/*
3467c478bdstevel@tonic-gate * DB access method and cursor operation values.  Each value is an operation
3477c478bdstevel@tonic-gate * code to which additional bit flags are added.
3487c478bdstevel@tonic-gate */
3497c478bdstevel@tonic-gate#define	DB_AFTER	 1		/* c_put() */
3507c478bdstevel@tonic-gate#define	DB_APPEND	 2		/* put() */
3517c478bdstevel@tonic-gate#define	DB_BEFORE	 3		/* c_put() */
3527c478bdstevel@tonic-gate#define	DB_CHECKPOINT	 4		/* log_put(), log_get() */
3537c478bdstevel@tonic-gate#define	DB_CURLSN	 5		/* log_put() */
3547c478bdstevel@tonic-gate#define	DB_CURRENT	 6		/* c_get(), c_put(), log_get() */
3557c478bdstevel@tonic-gate#define	DB_FIRST	 7		/* c_get(), log_get() */
3567c478bdstevel@tonic-gate#define	DB_FLUSH	 8		/* log_put() */
3577c478bdstevel@tonic-gate#define	DB_GET_BOTH	 9		/* get(), c_get() */
3587c478bdstevel@tonic-gate#define	DB_GET_RECNO	10		/* c_get() */
3597c478bdstevel@tonic-gate#define	DB_JOIN_ITEM	11		/* c_get(); do not do primary lookup */
3607c478bdstevel@tonic-gate#define	DB_KEYFIRST	12		/* c_put() */
3617c478bdstevel@tonic-gate#define	DB_KEYLAST	13		/* c_put() */
3627c478bdstevel@tonic-gate#define	DB_LAST		14		/* c_get(), log_get() */
3637c478bdstevel@tonic-gate#define	DB_NEXT		15		/* c_get(), log_get() */
3647c478bdstevel@tonic-gate#define	DB_NEXT_DUP	16		/* c_get() */
3657c478bdstevel@tonic-gate#define	DB_NOOVERWRITE	17		/* put() */
3667c478bdstevel@tonic-gate#define	DB_NOSYNC	18		/* close() */
3677c478bdstevel@tonic-gate#define	DB_PREV		19		/* c_get(), log_get() */
3687c478bdstevel@tonic-gate#define	DB_RECORDCOUNT	20		/* stat() */
3697c478bdstevel@tonic-gate#define	DB_SET		21		/* c_get(), log_get() */
3707c478bdstevel@tonic-gate#define	DB_SET_RANGE	22		/* c_get() */
3717c478bdstevel@tonic-gate#define	DB_SET_RECNO	23		/* get(), c_get() */
3727c478bdstevel@tonic-gate#define	DB_WRITELOCK	24		/* cursor() (internal) */
3737c478bdstevel@tonic-gate
3747c478bdstevel@tonic-gate#define	DB_OPFLAGS_MASK	0x1f		/* Mask for operations flags. */
3757c478bdstevel@tonic-gate#define	DB_RMW		0x80000000	/* Acquire write flag immediately. */
3767c478bdstevel@tonic-gate
3777c478bdstevel@tonic-gate/*
3787c478bdstevel@tonic-gate * DB (user visible) error return codes.
3797c478bdstevel@tonic-gate *
3807c478bdstevel@tonic-gate * !!!
3817c478bdstevel@tonic-gate * Changes to any of the user visible error return codes must be reflected
3827c478bdstevel@tonic-gate * in java/src/com/sleepycat/db/Db.java.
3837c478bdstevel@tonic-gate */
3847c478bdstevel@tonic-gate#define	DB_INCOMPLETE		( -1)	/* Sync didn't finish. */
3857c478bdstevel@tonic-gate#define	DB_KEYEMPTY		( -2)	/* The key/data pair was deleted or
3867c478bdstevel@tonic-gate					   was never created by the user. */
3877c478bdstevel@tonic-gate#define	DB_KEYEXIST		( -3)	/* The key/data pair already exists. */
3887c478bdstevel@tonic-gate#define	DB_LOCK_DEADLOCK	( -4)	/* Locker killed to resolve deadlock. */
3897c478bdstevel@tonic-gate#define	DB_LOCK_NOTGRANTED	( -5)	/* Lock unavailable, no-wait set. */
3907c478bdstevel@tonic-gate#define	DB_LOCK_NOTHELD		( -6)	/* Lock not held by locker. */
3917c478bdstevel@tonic-gate#define	DB_NOTFOUND		( -7)	/* Key/data pair not found (EOF). */
3927c478bdstevel@tonic-gate#define	DB_RUNRECOVERY		( -8)	/* Panic return. */
3937c478bdstevel@tonic-gate
3947c478bdstevel@tonic-gate/* DB (private) error return codes. */
3957c478bdstevel@tonic-gate#define	DB_DELETED		( -9)	/* Recovery file marked deleted. */
3967c478bdstevel@tonic-gate#define	DB_NEEDSPLIT		(-10)	/* Page needs to be split. */
3977c478bdstevel@tonic-gate#define	DB_SWAPBYTES		(-11)	/* Database needs byte swapping. */
3987c478bdstevel@tonic-gate#define	DB_TXN_CKP		(-12)	/* Encountered ckp record in log. */
3997c478bdstevel@tonic-gate
4007c478bdstevel@tonic-gate#define	DB_FILE_ID_LEN		20	/* DB file ID length. */
4017c478bdstevel@tonic-gate
4027c478bdstevel@tonic-gate/* DB access method description structure. */
4037c478bdstevel@tonic-gatestruct __db {
4047c478bdstevel@tonic-gate	void	*mutexp;		/* Synchronization for free threading */
4057c478bdstevel@tonic-gate
4067c478bdstevel@tonic-gate					/* Documented, returned information. */
4077c478bdstevel@tonic-gate	DBTYPE	 type;			/* DB access method. */
4087c478bdstevel@tonic-gate	int	 byteswapped;		/* Database byte order is swapped. */
4097c478bdstevel@tonic-gate	int	 saved_open_fd;		/* For fcntl lock preservation. */
4107c478bdstevel@tonic-gate
4117c478bdstevel@tonic-gate	DB_ENV	*dbenv;			/* DB_ENV structure. */
4127c478bdstevel@tonic-gate	DB_ENV	*mp_dbenv;		/* DB_ENV for local mpool creation. */
4137c478bdstevel@tonic-gate
4147c478bdstevel@tonic-gate	void	*internal;		/* Access method private. */
4157c478bdstevel@tonic-gate
4167c478bdstevel@tonic-gate	DB_MPOOL	*mp;		/* The access method's mpool. */
4177c478bdstevel@tonic-gate	DB_MPOOLFILE	*mpf;		/* The access method's mpool file. */
4187c478bdstevel@tonic-gate
4197c478bdstevel@tonic-gate	/*
4207c478bdstevel@tonic-gate	 * !!!
4217c478bdstevel@tonic-gate	 * Explicit representations of structures in queue.h.
4227c478bdstevel@tonic-gate	 *
4237c478bdstevel@tonic-gate	 * TAILQ_HEAD(free_queue, __dbc);
4247c478bdstevel@tonic-gate	 * TAILQ_HEAD(active_queue, __dbc);
4257c478bdstevel@tonic-gate	 */
4267c478bdstevel@tonic-gate	struct {
4277c478bdstevel@tonic-gate		struct __dbc *tqh_first;
4287c478bdstevel@tonic-gate		struct __dbc **tqh_last;
4297c478bdstevel@tonic-gate	} free_queue;
4307c478bdstevel@tonic-gate	struct {
4317c478bdstevel@tonic-gate		struct __dbc *tqh_first;
4327c478bdstevel@tonic-gate		struct __dbc **tqh_last;
4337c478bdstevel@tonic-gate	} active_queue;
4347c478bdstevel@tonic-gate
4357c478bdstevel@tonic-gate	u_int8_t  fileid[DB_FILE_ID_LEN]; /* Uniquely identify this file for
4367c478bdstevel@tonic-gate					     locking. */
4377c478bdstevel@tonic-gate	u_int32_t log_fileid;		/* Logging file id. */
4387c478bdstevel@tonic-gate	size_t	  pgsize;		/* Logical page size of file. */
4397c478bdstevel@tonic-gate
4407c478bdstevel@tonic-gate					/* Local heap allocation. */
4417c478bdstevel@tonic-gate	void *(*db_malloc) __P((size_t));
4427c478bdstevel@tonic-gate	int (*dup_compare)		/* Duplicate compare function. */
4437c478bdstevel@tonic-gate	    __P((const DBT *, const DBT *));
4447c478bdstevel@tonic-gate	u_int32_t (*h_hash)		/* Hash function. */
4457c478bdstevel@tonic-gate	    __P((const void *, u_int32_t));
4467c478bdstevel@tonic-gate
4477c478bdstevel@tonic-gate					/* Functions. */
4487c478bdstevel@tonic-gate	int (*am_close)	__P((DB *));
4497c478bdstevel@tonic-gate	int (*close)	__P((DB *, u_int32_t));
4507c478bdstevel@tonic-gate	int (*cursor)	__P((DB *, DB_TXN *, DBC **, u_int32_t));
4517c478bdstevel@tonic-gate	int (*del)	__P((DB *, DB_TXN *, DBT *, u_int32_t));
4527c478bdstevel@tonic-gate	int (*fd)	__P((DB *, int *));
4537c478bdstevel@tonic-gate	int (*get)	__P((DB *, DB_TXN *, DBT *, DBT *, u_int32_t));
4547c478bdstevel@tonic-gate	int (*join)	__P((DB *, DBC **, u_int32_t, DBC **));
4557c478bdstevel@tonic-gate	int (*put)	__P((DB *, DB_TXN *, DBT *, DBT *, u_int32_t));
4567c478bdstevel@tonic-gate	int (*stat)	__P((DB *, void *, void *(*)(size_t), u_int32_t));
4577c478bdstevel@tonic-gate	int (*sync)	__P((DB *, u_int32_t));
4587c478bdstevel@tonic-gate
4597c478bdstevel@tonic-gate#define	DB_AM_CDB	0x000001	/* Concurrent Access Methods. */
4607c478bdstevel@tonic-gate#define	DB_AM_DUP	0x000002	/* DB_DUP (internal). */
4617c478bdstevel@tonic-gate#define	DB_AM_INMEM	0x000004	/* In-memory; no sync on close. */
4627c478bdstevel@tonic-gate#define	DB_AM_LOCKING	0x000008	/* Perform locking. */
4637c478bdstevel@tonic-gate#define	DB_AM_LOGGING	0x000010	/* Perform logging. */
4647c478bdstevel@tonic-gate#define	DB_AM_MLOCAL	0x000020	/* Database memory pool is local. */
4657c478bdstevel@tonic-gate#define	DB_AM_PGDEF	0x000040	/* Page size was defaulted. */
4667c478bdstevel@tonic-gate#define	DB_AM_RDONLY	0x000080	/* Database is readonly. */
4677c478bdstevel@tonic-gate#define	DB_AM_SWAP	0x000100	/* Pages need to be byte-swapped. */
4687c478bdstevel@tonic-gate#define	DB_AM_THREAD	0x000200	/* DB is multi-threaded. */
4697c478bdstevel@tonic-gate#define	DB_BT_RECNUM	0x000400	/* DB_RECNUM (internal). */
4707c478bdstevel@tonic-gate#define	DB_DBM_ERROR	0x000800	/* Error in DBM/NDBM database. */
4717c478bdstevel@tonic-gate#define	DB_RE_DELIMITER	0x001000	/* DB_DELIMITER (internal). */
4727c478bdstevel@tonic-gate#define	DB_RE_FIXEDLEN	0x002000	/* DB_FIXEDLEN (internal). */
4737c478bdstevel@tonic-gate#define	DB_RE_PAD	0x004000	/* DB_PAD (internal). */
4747c478bdstevel@tonic-gate#define	DB_RE_RENUMBER	0x008000	/* DB_RENUMBER (internal). */
4757c478bdstevel@tonic-gate#define	DB_RE_SNAPSHOT	0x010000	/* DB_SNAPSHOT (internal). */
4767c478bdstevel@tonic-gate	u_int32_t flags;
4777c478bdstevel@tonic-gate};
4787c478bdstevel@tonic-gate
4797c478bdstevel@tonic-gatestruct __db_ilock {			/* Internal DB access method lock. */
4807c478bdstevel@tonic-gate	db_pgno_t pgno;			/* Page being locked. */
4817c478bdstevel@tonic-gate	u_int8_t fileid[DB_FILE_ID_LEN];/* File id. */
4827c478bdstevel@tonic-gate};
4837c478bdstevel@tonic-gate
4847c478bdstevel@tonic-gate/* Cursor description structure. */
4857c478bdstevel@tonic-gatestruct __dbc {
4867c478bdstevel@tonic-gate	DB *dbp;			/* Related DB access method. */
4877c478bdstevel@tonic-gate	DB_TXN	 *txn;			/* Associated transaction. */
4887c478bdstevel@tonic-gate
4897c478bdstevel@tonic-gate	/*
4907c478bdstevel@tonic-gate	 * !!!
4917c478bdstevel@tonic-gate	 * Explicit representations of structures in queue.h.
4927c478bdstevel@tonic-gate	 *
4937c478bdstevel@tonic-gate	 * TAILQ_ENTRY(__dbc);
4947c478bdstevel@tonic-gate	 */
4957c478bdstevel@tonic-gate	struct {
4967c478bdstevel@tonic-gate		struct __dbc *tqe_next;
4977c478bdstevel@tonic-gate		struct __dbc **tqe_prev;
4987c478bdstevel@tonic-gate	} links;
4997c478bdstevel@tonic-gate
5007c478bdstevel@tonic-gate	u_int32_t lid;			/* Default process' locker id. */
5017c478bdstevel@tonic-gate	u_int32_t locker;		/* Locker for this operation. */
5027c478bdstevel@tonic-gate	DBT	  lock_dbt;		/* DBT referencing lock. */
5037c478bdstevel@tonic-gate	DB_LOCK_ILOCK lock;		/* Object to be locked. */
5047c478bdstevel@tonic-gate	DB_LOCK	mylock;			/* Lock held on this cursor. */
5057c478bdstevel@tonic-gate
5067c478bdstevel@tonic-gate	DBT rkey;			/* Returned key. */
5077c478bdstevel@tonic-gate	DBT rdata;			/* Returned data. */
5087c478bdstevel@tonic-gate
5097c478bdstevel@tonic-gate	int (*c_am_close) __P((DBC *));
5107c478bdstevel@tonic-gate	int (*c_am_destroy) __P((DBC *));
5117c478bdstevel@tonic-gate	int (*c_close) __P((DBC *));
5127c478bdstevel@tonic-gate	int (*c_del) __P((DBC *, u_int32_t));
5137c478bdstevel@tonic-gate	int (*c_get) __P((DBC *, DBT *, DBT *, u_int32_t));
5147c478bdstevel@tonic-gate	int (*c_put) __P((DBC *, DBT *, DBT *, u_int32_t));
5157c478bdstevel@tonic-gate
5167c478bdstevel@tonic-gate	void	 *internal;		/* Access method private. */
5177c478bdstevel@tonic-gate
5187c478bdstevel@tonic-gate#define	DBC_CONTINUE	0x001		/* Continue dup search: next item. */
5197c478bdstevel@tonic-gate#define	DBC_KEYSET	0x002		/* Continue dup search: current item. */
5207c478bdstevel@tonic-gate#define	DBC_RECOVER	0x004		/* In recovery (do not log or lock). */
5217c478bdstevel@tonic-gate#define	DBC_RMW		0x008		/* Acquire write flag in read op. */
5227c478bdstevel@tonic-gate#define	DBC_WRITER	0x010		/* Cursor immediately writing (CDB). */
5237c478bdstevel@tonic-gate	u_int32_t flags;
5247c478bdstevel@tonic-gate};
5257c478bdstevel@tonic-gate
5267c478bdstevel@tonic-gate/* Btree/recno statistics structure. */
5277c478bdstevel@tonic-gatestruct __db_bt_stat {
5287c478bdstevel@tonic-gate	u_int32_t bt_flags;		/* Open flags. */
5297c478bdstevel@tonic-gate	u_int32_t bt_maxkey;		/* Maxkey value. */
5307c478bdstevel@tonic-gate	u_int32_t bt_minkey;		/* Minkey value. */
5317c478bdstevel@tonic-gate	u_int32_t bt_re_len;		/* Fixed-length record length. */
5327c478bdstevel@tonic-gate	u_int32_t bt_re_pad;		/* Fixed-length record pad. */
5337c478bdstevel@tonic-gate	u_int32_t bt_pagesize;		/* Page size. */
5347c478bdstevel@tonic-gate	u_int32_t bt_levels;		/* Tree levels. */
5357c478bdstevel@tonic-gate	u_int32_t bt_nrecs;		/* Number of records. */
5367c478bdstevel@tonic-gate	u_int32_t bt_int_pg;		/* Internal pages. */
5377c478bdstevel@tonic-gate	u_int32_t bt_leaf_pg;		/* Leaf pages. */
5387c478bdstevel@tonic-gate	u_int32_t bt_dup_pg;		/* Duplicate pages. */
5397c478bdstevel@tonic-gate	u_int32_t bt_over_pg;		/* Overflow pages. */
5407c478bdstevel@tonic-gate	u_int32_t bt_free;		/* Pages on the free list. */
5417c478bdstevel@tonic-gate	u_int32_t bt_int_pgfree;	/* Bytes free in internal pages. */
5427c478bdstevel@tonic-gate	u_int32_t bt_leaf_pgfree;	/* Bytes free in leaf pages. */
5437c478bdstevel@tonic-gate	u_int32_t bt_dup_pgfree;	/* Bytes free in duplicate pages. */
5447c478bdstevel@tonic-gate	u_int32_t bt_over_pgfree;	/* Bytes free in overflow pages. */
5457c478bdstevel@tonic-gate	u_int32_t bt_magic;		/* Magic number. */
5467c478bdstevel@tonic-gate	u_int32_t bt_version;		/* Version number. */
5477c478bdstevel@tonic-gate};
5487c478bdstevel@tonic-gate
5497c478bdstevel@tonic-gate/* Hash statistics structure. */
5507c478bdstevel@tonic-gatestruct __db_h_stat {
5517c478bdstevel@tonic-gate	u_int32_t hash_accesses;	/* Number of accesses to this table. */
5527c478bdstevel@tonic-gate	u_int32_t hash_collisions;	/* Number of collisions on search. */
5537c478bdstevel@tonic-gate	u_int32_t hash_expansions;	/* Number of times we added a bucket. */
5547c478bdstevel@tonic-gate	u_int32_t hash_overflows;	/* Number of overflow pages. */
5557c478bdstevel@tonic-gate	u_int32_t hash_bigpages;	/* Number of big key/data pages. */
5567c478bdstevel@tonic-gate	u_int32_t hash_dup;		/* Number of dup pages. */
5577c478bdstevel@tonic-gate	u_int32_t hash_free;		/* Pages on the free list. */
5587c478bdstevel@tonic-gate	u_int32_t hash_bfree;		/* Bytes free on bucket pages. */
5597c478bdstevel@tonic-gate	u_int32_t hash_dup_free;	/* Bytes free on duplicate pages. */
5607c478bdstevel@tonic-gate	u_int32_t hash_big_bfree;	/* Bytes free on big item pages. */
5617c478bdstevel@tonic-gate	u_int32_t hash_buckets;		/* Number of hash buckets. */
5627c478bdstevel@tonic-gate	u_int32_t hash_put;		/* Number of puts. */
5637c478bdstevel@tonic-gate	u_int32_t hash_deleted;		/* Number of deletes. */
5647c478bdstevel@tonic-gate	u_int32_t hash_get;		/* Number of gets. */
5657c478bdstevel@tonic-gate	u_int32_t hash_magic;		/* Magic number. */
5667c478bdstevel@tonic-gate	u_int32_t hash_version;		/* Version number. */
5677c478bdstevel@tonic-gate	u_int32_t hash_pagesize;	/* Page size. */
5687c478bdstevel@tonic-gate	u_int32_t hash_nrecs;		/* Number of records. */
5697c478bdstevel@tonic-gate};
5707c478bdstevel@tonic-gate
5717c478bdstevel@tonic-gate#if defined(__cplusplus)
5727c478bdstevel@tonic-gateextern "C" {
5737c478bdstevel@tonic-gate#endif
5747c478bdstevel@tonic-gateint   db_appinit __P((const char *, char * const *, DB_ENV *, u_int32_t));
5757c478bdstevel@tonic-gateint   db_appexit __P((DB_ENV *));
5767c478bdstevel@tonic-gateint   db_jump_set __P((void *, int));
5777c478bdstevel@tonic-gateint   db_open __P((const char *,
5787c478bdstevel@tonic-gate	  DBTYPE, u_int32_t, int, DB_ENV *, DB_INFO *, DB **));
5797c478bdstevel@tonic-gateint   db_value_set __P((int, int));
5807c478bdstevel@tonic-gatechar *db_version __P((int *, int *, int *));
5817c478bdstevel@tonic-gateint   db_xa_open __P((const char *,
5827c478bdstevel@tonic-gate	  DBTYPE, u_int32_t, int, DB_INFO *, DB **));
5837c478bdstevel@tonic-gate#if defined(__cplusplus)
5847c478bdstevel@tonic-gate}
5857c478bdstevel@tonic-gate#endif
5867c478bdstevel@tonic-gate
5877c478bdstevel@tonic-gate/*******************************************************
5887c478bdstevel@tonic-gate * Locking
5897c478bdstevel@tonic-gate *******************************************************/
5907c478bdstevel@tonic-gate#define	DB_LOCKVERSION	1
5917c478bdstevel@tonic-gate#define	DB_LOCKMAGIC	0x090193
5927c478bdstevel@tonic-gate
5937c478bdstevel@tonic-gate/* Flag values for lock_vec(), lock_get(). */
5947c478bdstevel@tonic-gate#define	DB_LOCK_NOWAIT		0x01	/* Don't wait on unavailable lock. */
5957c478bdstevel@tonic-gate#define	DB_LOCK_UPGRADE		0x02	/* Upgrade an existing lock instead
5967c478bdstevel@tonic-gate					   of granting a new one (internal). */
5977c478bdstevel@tonic-gate
5987c478bdstevel@tonic-gate/* Flag values for lock_detect(). */
5997c478bdstevel@tonic-gate#define	DB_LOCK_CONFLICT	0x01	/* Run on any conflict. */
6007c478bdstevel@tonic-gate
6017c478bdstevel@tonic-gate/*
6027c478bdstevel@tonic-gate * Request types.
6037c478bdstevel@tonic-gate *
6047c478bdstevel@tonic-gate * !!!
6057c478bdstevel@tonic-gate * Changes here must be reflected in java/src/com/sleepycat/db/Db.java.
6067c478bdstevel@tonic-gate */
6077c478bdstevel@tonic-gatetypedef enum {
6087c478bdstevel@tonic-gate	DB_LOCK_DUMP=0,			/* Display held locks. */
6097c478bdstevel@tonic-gate	DB_LOCK_GET,			/* Get the lock. */
6107c478bdstevel@tonic-gate	DB_LOCK_INHERIT,		/* Pass locks to parent. */
6117c478bdstevel@tonic-gate	DB_LOCK_PUT,			/* Release the lock. */
6127c478bdstevel@tonic-gate	DB_LOCK_PUT_ALL,		/* Release locker's locks. */
6137c478bdstevel@tonic-gate	DB_LOCK_PUT_OBJ			/* Release locker's locks on obj. */
6147c478bdstevel@tonic-gate} db_lockop_t;
6157c478bdstevel@tonic-gate
6167c478bdstevel@tonic-gate/*
6177c478bdstevel@tonic-gate * Simple R/W lock modes and for multi-granularity intention locking.
6187c478bdstevel@tonic-gate *
6197c478bdstevel@tonic-gate * !!!
6207c478bdstevel@tonic-gate * These values are NOT random, as they are used as an index into the lock
6217c478bdstevel@tonic-gate * conflicts arrays, i.e., DB_LOCK_IWRITE must be == 3, and DB_LOCK_IREAD
6227c478bdstevel@tonic-gate * must be == 4.
6237c478bdstevel@tonic-gate *
6247c478bdstevel@tonic-gate * !!!
6257c478bdstevel@tonic-gate * Changes here must be reflected in java/src/com/sleepycat/db/Db.java.
6267c478bdstevel@tonic-gate */
6277c478bdstevel@tonic-gatetypedef enum {
6287c478bdstevel@tonic-gate	DB_LOCK_NG=0,			/* Not granted. */
6297c478bdstevel@tonic-gate	DB_LOCK_READ,			/* Shared/read. */
6307c478bdstevel@tonic-gate	DB_LOCK_WRITE,			/* Exclusive/write. */
6317c478bdstevel@tonic-gate	DB_LOCK_IWRITE,			/* Intent exclusive/write. */
6327c478bdstevel@tonic-gate	DB_LOCK_IREAD,			/* Intent to share/read. */
6337c478bdstevel@tonic-gate	DB_LOCK_IWR			/* Intent to read and write. */
6347c478bdstevel@tonic-gate} db_lockmode_t;
6357c478bdstevel@tonic-gate
6367c478bdstevel@tonic-gate/*
6377c478bdstevel@tonic-gate * Status of a lock.
6387c478bdstevel@tonic-gate */
6397c478bdstevel@tonic-gatetypedef enum {
6407c478bdstevel@tonic-gate	DB_LSTAT_ABORTED,		/* Lock belongs to an aborted txn. */
6417c478bdstevel@tonic-gate	DB_LSTAT_ERR,			/* Lock is bad. */
6427c478bdstevel@tonic-gate	DB_LSTAT_FREE,			/* Lock is unallocated. */
6437c478bdstevel@tonic-gate	DB_LSTAT_HELD,			/* Lock is currently held. */
6447c478bdstevel@tonic-gate	DB_LSTAT_NOGRANT,		/* Lock was not granted. */
6457c478bdstevel@tonic-gate	DB_LSTAT_PENDING,		/* Lock was waiting and has been
6467c478bdstevel@tonic-gate					 * promoted; waiting for the owner
6477c478bdstevel@tonic-gate					 * to run and upgrade it to held. */
6487c478bdstevel@tonic-gate	DB_LSTAT_WAITING		/* Lock is on the wait queue. */
6497c478bdstevel@tonic-gate} db_status_t;
6507c478bdstevel@tonic-gate
6517c478bdstevel@tonic-gate/* Lock request structure. */
6527c478bdstevel@tonic-gatestruct __db_lockreq {
6537c478bdstevel@tonic-gate	db_lockop_t	 op;		/* Operation. */
6547c478bdstevel@tonic-gate	db_lockmode_t	 mode;		/* Requested mode. */
6557c478bdstevel@tonic-gate	u_int32_t	 locker;	/* Locker identity. */
6567c478bdstevel@tonic-gate	DBT		*obj;		/* Object being locked. */
6577c478bdstevel@tonic-gate	DB_LOCK		 lock;		/* Lock returned. */
6587c478bdstevel@tonic-gate};
6597c478bdstevel@tonic-gate
6607c478bdstevel@tonic-gate/*
6617c478bdstevel@tonic-gate * Commonly used conflict matrices.
6627c478bdstevel@tonic-gate *
6637c478bdstevel@tonic-gate * Standard Read/Write (or exclusive/shared) locks.
6647c478bdstevel@tonic-gate */
6657c478bdstevel@tonic-gate#define	DB_LOCK_RW_N	3
6667c478bdstevel@tonic-gateextern const u_int8_t db_rw_conflicts[];
6677c478bdstevel@tonic-gate
6687c478bdstevel@tonic-gate/* Multi-granularity locking. */
6697c478bdstevel@tonic-gate#define	DB_LOCK_RIW_N	6
6707c478bdstevel@tonic-gateextern const u_int8_t db_riw_conflicts[];
6717c478bdstevel@tonic-gate
6727c478bdstevel@tonic-gatestruct __db_lock_stat {
6737c478bdstevel@tonic-gate	u_int32_t st_magic;		/* Lock file magic number. */
6747c478bdstevel@tonic-gate	u_int32_t st_version;		/* Lock file version number. */
6757c478bdstevel@tonic-gate	u_int32_t st_maxlocks;		/* Maximum number of locks in table. */
6767c478bdstevel@tonic-gate	u_int32_t st_nmodes;		/* Number of lock modes. */
6777c478bdstevel@tonic-gate	u_int32_t st_numobjs;		/* Number of objects. */
6787c478bdstevel@tonic-gate	u_int32_t st_nlockers;		/* Number of lockers. */
6797c478bdstevel@tonic-gate	u_int32_t st_nconflicts;	/* Number of lock conflicts. */
6807c478bdstevel@tonic-gate	u_int32_t st_nrequests;		/* Number of lock gets. */
6817c478bdstevel@tonic-gate	u_int32_t st_nreleases;		/* Number of lock puts. */
6827c478bdstevel@tonic-gate	u_int32_t st_ndeadlocks;	/* Number of lock deadlocks. */
6837c478bdstevel@tonic-gate	u_int32_t st_region_wait;	/* Region lock granted after wait. */
6847c478bdstevel@tonic-gate	u_int32_t st_region_nowait;	/* Region lock granted without wait. */
6857c478bdstevel@tonic-gate	u_int32_t st_refcnt;		/* Region reference count. */
6867c478bdstevel@tonic-gate	u_int32_t st_regsize;		/* Region size. */
6877c478bdstevel@tonic-gate};
6887c478bdstevel@tonic-gate
6897c478bdstevel@tonic-gate#if defined(__cplusplus)
6907c478bdstevel@tonic-gateextern "C" {
6917c478bdstevel@tonic-gate#endif
6927c478bdstevel@tonic-gateint	  lock_close __P((DB_LOCKTAB *));
6937c478bdstevel@tonic-gateint	  lock_detect __P((DB_LOCKTAB *, u_int32_t, u_int32_t));
6947c478bdstevel@tonic-gateint	  lock_get __P((DB_LOCKTAB *,
6957c478bdstevel@tonic-gate	    u_int32_t, u_int32_t, const DBT *, db_lockmode_t, DB_LOCK *));
6967c478bdstevel@tonic-gateint	  lock_id __P((DB_LOCKTAB *, u_int32_t *));
6977c478bdstevel@tonic-gateint	  lock_open __P((const char *,
6987c478bdstevel@tonic-gate	    u_int32_t, int, DB_ENV *, DB_LOCKTAB **));
6997c478bdstevel@tonic-gateint	  lock_put __P((DB_LOCKTAB *, DB_LOCK));
7007c478bdstevel@tonic-gateint	  lock_tget __P((DB_LOCKTAB *,
7017c478bdstevel@tonic-gate	    DB_TXN *, u_int32_t, const DBT *, db_lockmode_t, DB_LOCK *));
7027c478bdstevel@tonic-gateint	  lock_stat __P((DB_LOCKTAB *, DB_LOCK_STAT **, void *(*)(size_t)));
7037c478bdstevel@tonic-gateint	  lock_unlink __P((const char *, int, DB_ENV *));
7047c478bdstevel@tonic-gateint	  lock_vec __P((DB_LOCKTAB *,
7057c478bdstevel@tonic-gate	    u_int32_t, u_int32_t, DB_LOCKREQ *, int, DB_LOCKREQ **));
7067c478bdstevel@tonic-gateint	  lock_tvec __P((DB_LOCKTAB *,
7077c478bdstevel@tonic-gate	    DB_TXN *, u_int32_t, DB_LOCKREQ *, int, DB_LOCKREQ **));
7087c478bdstevel@tonic-gate#if defined(__cplusplus)
7097c478bdstevel@tonic-gate}
7107c478bdstevel@tonic-gate#endif
7117c478bdstevel@tonic-gate
7127c478bdstevel@tonic-gate/*******************************************************
7137c478bdstevel@tonic-gate * Logging.
7147c478bdstevel@tonic-gate *******************************************************/
7157c478bdstevel@tonic-gate/* Flag values for log_archive(). */
7167c478bdstevel@tonic-gate#define	DB_ARCH_ABS		0x001	/* Absolute pathnames. */
7177c478bdstevel@tonic-gate#define	DB_ARCH_DATA		0x002	/* Data files. */
7187c478bdstevel@tonic-gate#define	DB_ARCH_LOG		0x004	/* Log files. */
7197c478bdstevel@tonic-gate
7207c478bdstevel@tonic-gate/*
7217c478bdstevel@tonic-gate * A DB_LSN has two parts, a fileid which identifies a specific file, and an
7227c478bdstevel@tonic-gate * offset within that file.  The fileid is an unsigned 4-byte quantity that
7237c478bdstevel@tonic-gate * uniquely identifies a file within the log directory -- currently a simple
7247c478bdstevel@tonic-gate * counter inside the log.  The offset is also an unsigned 4-byte value.  The
7257c478bdstevel@tonic-gate * log manager guarantees the offset is never more than 4 bytes by switching
7267c478bdstevel@tonic-gate * to a new log file before the maximum length imposed by an unsigned 4-byte
7277c478bdstevel@tonic-gate * offset is reached.
7287c478bdstevel@tonic-gate */
7297c478bdstevel@tonic-gatestruct __db_lsn {
7307c478bdstevel@tonic-gate	u_int32_t	file;		/* File ID. */
7317c478bdstevel@tonic-gate	u_int32_t	offset;		/* File offset. */
7327c478bdstevel@tonic-gate};
7337c478bdstevel@tonic-gate
7347c478bdstevel@tonic-gate/* Log statistics structure. */
7357c478bdstevel@tonic-gatestruct __db_log_stat {
7367c478bdstevel@tonic-gate	u_int32_t st_magic;		/* Log file magic number. */
7377c478bdstevel@tonic-gate	u_int32_t st_version;		/* Log file version number. */
7387c478bdstevel@tonic-gate	int st_mode;			/* Log file mode. */
7397c478bdstevel@tonic-gate	u_int32_t st_lg_max;		/* Maximum log file size. */
7407c478bdstevel@tonic-gate	u_int32_t st_w_bytes;		/* Bytes to log. */
7417c478bdstevel@tonic-gate	u_int32_t st_w_mbytes;		/* Megabytes to log. */
7427c478bdstevel@tonic-gate	u_int32_t st_wc_bytes;		/* Bytes to log since checkpoint. */
7437c478bdstevel@tonic-gate	u_int32_t st_wc_mbytes;		/* Megabytes to log since checkpoint. */
7447c478bdstevel@tonic-gate	u_int32_t st_wcount;		/* Total syncs to the log. */
7457c478bdstevel@tonic-gate	u_int32_t st_scount;		/* Total writes to the log. */
7467c478bdstevel@tonic-gate	u_int32_t st_region_wait;	/* Region lock granted after wait. */
7477c478bdstevel@tonic-gate	u_int32_t st_region_nowait;	/* Region lock granted without wait. */
7487c478bdstevel@tonic-gate	u_int32_t st_cur_file;		/* Current log file number. */
7497c478bdstevel@tonic-gate	u_int32_t st_cur_offset;	/* Current log file offset. */
7507c478bdstevel@tonic-gate	u_int32_t st_refcnt;		/* Region reference count. */
7517c478bdstevel@tonic-gate	u_int32_t st_regsize;		/* Region size. */
7527c478bdstevel@tonic-gate};
7537c478bdstevel@tonic-gate
7547c478bdstevel@tonic-gate#if defined(__cplusplus)
7557c478bdstevel@tonic-gateextern "C" {
7567c478bdstevel@tonic-gate#endif
7577c478bdstevel@tonic-gateint	 log_archive __P((DB_LOG *, char **[], u_int32_t, void *(*)(size_t)));
7587c478bdstevel@tonic-gateint	 log_close __P((DB_LOG *));
7597c478bdstevel@tonic-gateint	 log_compare __P((const DB_LSN *, const DB_LSN *));
7607c478bdstevel@tonic-gateint	 log_file __P((DB_LOG *, const DB_LSN *, char *, size_t));
7617c478bdstevel@tonic-gateint	 log_flush __P((DB_LOG *, const DB_LSN *));
7627c478bdstevel@tonic-gateint	 log_get __P((DB_LOG *, DB_LSN *, DBT *, u_int32_t));
7637c478bdstevel@tonic-gateint	 log_open __P((const char *, u_int32_t, int, DB_ENV *, DB_LOG **));
7647c478bdstevel@tonic-gateint	 log_put __P((DB_LOG *, DB_LSN *, const DBT *, u_int32_t));
7657c478bdstevel@tonic-gateint	 log_register __P((DB_LOG *, DB *, const char *, DBTYPE, u_int32_t *));
7667c478bdstevel@tonic-gateint	 log_stat __P((DB_LOG *, DB_LOG_STAT **, void *(*)(size_t)));
7677c478bdstevel@tonic-gateint	 log_unlink __P((const char *, int, DB_ENV *));
7687c478bdstevel@tonic-gateint	 log_unregister __P((DB_LOG *, u_int32_t));
7697c478bdstevel@tonic-gate#if defined(__cplusplus)
7707c478bdstevel@tonic-gate}
7717c478bdstevel@tonic-gate#endif
7727c478bdstevel@tonic-gate
7737c478bdstevel@tonic-gate/*******************************************************
7747c478bdstevel@tonic-gate * Mpool
7757c478bdstevel@tonic-gate *******************************************************/
7767c478bdstevel@tonic-gate/* Flag values for memp_fget(). */
7777c478bdstevel@tonic-gate#define	DB_MPOOL_CREATE		0x001	/* Create a page. */
7787c478bdstevel@tonic-gate#define	DB_MPOOL_LAST		0x002	/* Return the last page. */
7797c478bdstevel@tonic-gate#define	DB_MPOOL_NEW		0x004	/* Create a new page. */
7807c478bdstevel@tonic-gate
7817c478bdstevel@tonic-gate/* Flag values for memp_fput(), memp_fset(). */
7827c478bdstevel@tonic-gate#define	DB_MPOOL_CLEAN		0x001	/* Clear modified bit. */
7837c478bdstevel@tonic-gate#define	DB_MPOOL_DIRTY		0x002	/* Page is modified. */
7847c478bdstevel@tonic-gate#define	DB_MPOOL_DISCARD	0x004	/* Don't cache the page. */
7857c478bdstevel@tonic-gate
7867c478bdstevel@tonic-gate/* Mpool statistics structure. */
7877c478bdstevel@tonic-gatestruct __db_mpool_stat {
7887c478bdstevel@tonic-gate	size_t st_cachesize;		/* Cache size. */
7897c478bdstevel@tonic-gate	u_int32_t st_cache_hit;		/* Pages found in the cache. */
7907c478bdstevel@tonic-gate	u_int32_t st_cache_miss;	/* Pages not found in the cache. */
7917c478bdstevel@tonic-gate	u_int32_t st_map;		/* Pages from mapped files. */
7927c478bdstevel@tonic-gate	u_int32_t st_page_create;	/* Pages created in the cache. */
7937c478bdstevel@tonic-gate	u_int32_t st_page_in;		/* Pages read in. */
7947c478bdstevel@tonic-gate	u_int32_t st_page_out;		/* Pages written out. */
7957c478bdstevel@tonic-gate	u_int32_t st_ro_evict;		/* Clean pages forced from the cache. */
7967c478bdstevel@tonic-gate	u_int32_t st_rw_evict;		/* Dirty pages forced from the cache. */
7977c478bdstevel@tonic-gate	u_int32_t st_hash_buckets;	/* Number of hash buckets. */
7987c478bdstevel@tonic-gate	u_int32_t st_hash_searches;	/* Total hash chain searches. */
7997c478bdstevel@tonic-gate	u_int32_t st_hash_longest;	/* Longest hash chain searched. */
8007c478bdstevel@tonic-gate	u_int32_t st_hash_examined;	/* Total hash entries searched. */
8017c478bdstevel@tonic-gate	u_int32_t st_page_clean;	/* Clean pages. */
8027c478bdstevel@tonic-gate	u_int32_t st_page_dirty;	/* Dirty pages. */
8037c478bdstevel@tonic-gate	u_int32_t st_page_trickle;	/* Pages written by memp_trickle. */
8047c478bdstevel@tonic-gate	u_int32_t st_region_wait;	/* Region lock granted after wait. */
8057c478bdstevel@tonic-gate	u_int32_t st_region_nowait;	/* Region lock granted without wait. */
8067c478bdstevel@tonic-gate	u_int32_t st_refcnt;		/* Region reference count. */
8077c478bdstevel@tonic-gate	u_int32_t st_regsize;		/* Region size. */
8087c478bdstevel@tonic-gate};
8097c478bdstevel@tonic-gate
8107c478bdstevel@tonic-gate/* Mpool file open information structure. */
8117c478bdstevel@tonic-gatestruct __db_mpool_finfo {
8127c478bdstevel@tonic-gate	int	   ftype;		/* File type. */
8137c478bdstevel@tonic-gate	DBT	  *pgcookie;		/* Byte-string passed to pgin/pgout. */
8147c478bdstevel@tonic-gate	u_int8_t  *fileid;		/* Unique file ID. */
8157c478bdstevel@tonic-gate	int32_t	   lsn_offset;		/* LSN offset in page. */
8167c478bdstevel@tonic-gate	u_int32_t  clear_len;		/* Cleared length on created pages. */
8177c478bdstevel@tonic-gate};
8187c478bdstevel@tonic-gate
8197c478bdstevel@tonic-gate/* Mpool file statistics structure. */
8207c478bdstevel@tonic-gatestruct __db_mpool_fstat {
8217c478bdstevel@tonic-gate	char *file_name;		/* File name. */
8227c478bdstevel@tonic-gate	size_t st_pagesize;		/* Page size. */
8237c478bdstevel@tonic-gate	u_int32_t st_cache_hit;		/* Pages found in the cache. */
8247c478bdstevel@tonic-gate	u_int32_t st_cache_miss;	/* Pages not found in the cache. */
8257c478bdstevel@tonic-gate	u_int32_t st_map;		/* Pages from mapped files. */
8267c478bdstevel@tonic-gate	u_int32_t st_page_create;	/* Pages created in the cache. */
8277c478bdstevel@tonic-gate	u_int32_t st_page_in;		/* Pages read in. */
8287c478bdstevel@tonic-gate	u_int32_t st_page_out;		/* Pages written out. */
8297c478bdstevel@tonic-gate};
8307c478bdstevel@tonic-gate
8317c478bdstevel@tonic-gate#if defined(__cplusplus)
8327c478bdstevel@tonic-gateextern "C" {
8337c478bdstevel@tonic-gate#endif
8347c478bdstevel@tonic-gateint	memp_close __P((DB_MPOOL *));
8357c478bdstevel@tonic-gateint	memp_fclose __P((DB_MPOOLFILE *));
8367c478bdstevel@tonic-gateint	memp_fget __P((DB_MPOOLFILE *, db_pgno_t *, u_int32_t, void *));
8377c478bdstevel@tonic-gateint	memp_fopen __P((DB_MPOOL *, const char *,
8387c478bdstevel@tonic-gate	    u_int32_t, int, size_t, DB_MPOOL_FINFO *, DB_MPOOLFILE **));
8397c478bdstevel@tonic-gateint	memp_fput __P((DB_MPOOLFILE *, void *, u_int32_t));
8407c478bdstevel@tonic-gateint	memp_fset __P((DB_MPOOLFILE *, void *, u_int32_t));
8417c478bdstevel@tonic-gateint	memp_fsync __P((DB_MPOOLFILE *));
8427c478bdstevel@tonic-gateint	memp_open __P((const char *, u_int32_t, int, DB_ENV *, DB_MPOOL **));
8437c478bdstevel@tonic-gateint	memp_register __P((DB_MPOOL *, int,
8447c478bdstevel@tonic-gate	    int (*)(db_pgno_t, void *, DBT *),
8457c478bdstevel@tonic-gate	    int (*)(db_pgno_t, void *, DBT *)));
8467c478bdstevel@tonic-gateint	memp_stat __P((DB_MPOOL *,
8477c478bdstevel@tonic-gate	    DB_MPOOL_STAT **, DB_MPOOL_FSTAT ***, void *(*)(size_t)));
8487c478bdstevel@tonic-gateint	memp_sync __P((DB_MPOOL *, DB_LSN *));
8497c478bdstevel@tonic-gateint	memp_trickle __P((DB_MPOOL *, int, int *));
8507c478bdstevel@tonic-gateint	memp_unlink __P((const char *, int, DB_ENV *));
8517c478bdstevel@tonic-gate#if defined(__cplusplus)
8527c478bdstevel@tonic-gate}
8537c478bdstevel@tonic-gate#endif
8547c478bdstevel@tonic-gate
8557c478bdstevel@tonic-gate/*******************************************************
8567c478bdstevel@tonic-gate * Transactions.
8577c478bdstevel@tonic-gate *******************************************************/
8587c478bdstevel@tonic-gate#define	DB_TXNVERSION	1
8597c478bdstevel@tonic-gate#define	DB_TXNMAGIC	0x041593
8607c478bdstevel@tonic-gate
8617c478bdstevel@tonic-gate/* Operations values to the tx_recover() function. */
8627c478bdstevel@tonic-gate#define	DB_TXN_BACKWARD_ROLL	1	/* Read the log backwards. */
8637c478bdstevel@tonic-gate#define	DB_TXN_FORWARD_ROLL	2	/* Read the log forwards. */
8647c478bdstevel@tonic-gate#define	DB_TXN_OPENFILES	3	/* Read for open files. */
8657c478bdstevel@tonic-gate#define	DB_TXN_REDO		4	/* Redo the operation. */
8667c478bdstevel@tonic-gate#define	DB_TXN_UNDO		5	/* Undo the operation. */
8677c478bdstevel@tonic-gate
8687c478bdstevel@tonic-gate/* Internal transaction status values. */
8697c478bdstevel@tonic-gate
8707c478bdstevel@tonic-gate/* Transaction statistics structure. */
8717c478bdstevel@tonic-gatestruct __db_txn_active {
8727c478bdstevel@tonic-gate	u_int32_t	txnid;		/* Transaction ID */
8737c478bdstevel@tonic-gate	DB_LSN		lsn;		/* Lsn of the begin record */
8747c478bdstevel@tonic-gate};
8757c478bdstevel@tonic-gate
8767c478bdstevel@tonic-gatestruct __db_txn_stat {
8777c478bdstevel@tonic-gate	DB_LSN	  st_last_ckp;		/* lsn of the last checkpoint */
8787c478bdstevel@tonic-gate	DB_LSN	  st_pending_ckp;	/* last checkpoint did not finish */
8797c478bdstevel@tonic-gate	time_t	  st_time_ckp;		/* time of last checkpoint */
8807c478bdstevel@tonic-gate	u_int32_t st_last_txnid;	/* last transaction id given out */
8817c478bdstevel@tonic-gate	u_int32_t st_maxtxns;	/* maximum number of active txns */
8827c478bdstevel@tonic-gate	u_int32_t st_naborts;	/* number of aborted transactions */
8837c478bdstevel@tonic-gate	u_int32_t st_nbegins;	/* number of begun transactions */
8847c478bdstevel@tonic-gate	u_int32_t st_ncommits;	/* number of committed transactions */
8857c478bdstevel@tonic-gate	u_int32_t st_nactive;	/* number of active transactions */
8867c478bdstevel@tonic-gate	DB_TXN_ACTIVE
8877c478bdstevel@tonic-gate		 *st_txnarray;	/* array of active transactions */
8887c478bdstevel@tonic-gate	u_int32_t st_region_wait;	/* Region lock granted after wait. */
8897c478bdstevel@tonic-gate	u_int32_t st_region_nowait;	/* Region lock granted without wait. */
8907c478bdstevel@tonic-gate	u_int32_t st_refcnt;		/* Region reference count. */
8917c478bdstevel@tonic-gate	u_int32_t st_regsize;		/* Region size. */
8927c478bdstevel@tonic-gate};
8937c478bdstevel@tonic-gate
8947c478bdstevel@tonic-gate#if defined(__cplusplus)
8957c478bdstevel@tonic-gateextern "C" {
8967c478bdstevel@tonic-gate#endif
8977c478bdstevel@tonic-gateint	  txn_abort __P((DB_TXN *));
8987c478bdstevel@tonic-gateint	  txn_begin __P((DB_TXNMGR *, DB_TXN *, DB_TXN **));
8997c478bdstevel@tonic-gateint	  txn_checkpoint __P((const DB_TXNMGR *, u_int32_t, u_int32_t));
9007c478bdstevel@tonic-gateint	  txn_commit __P((DB_TXN *));
9017c478bdstevel@tonic-gateint	  txn_close __P((DB_TXNMGR *));
9027c478bdstevel@tonic-gateu_int32_t txn_id __P((DB_TXN *));
9037c478bdstevel@tonic-gateint	  txn_open __P((const char *, u_int32_t, int, DB_ENV *, DB_TXNMGR **));
9047c478bdstevel@tonic-gateint	  txn_prepare __P((DB_TXN *));
9057c478bdstevel@tonic-gateint	  txn_stat __P((DB_TXNMGR *, DB_TXN_STAT **, void *(*)(size_t)));
9067c478bdstevel@tonic-gateint	  txn_unlink __P((const char *, int, DB_ENV *));
9077c478bdstevel@tonic-gate#if defined(__cplusplus)
9087c478bdstevel@tonic-gate}
9097c478bdstevel@tonic-gate#endif
9107c478bdstevel@tonic-gate
9117c478bdstevel@tonic-gate#ifndef DB_DBM_HSEARCH
9127c478bdstevel@tonic-gate#define	DB_DBM_HSEARCH	0		/* No historic interfaces by default. */
9137c478bdstevel@tonic-gate#endif
9147c478bdstevel@tonic-gate#if DB_DBM_HSEARCH != 0
9157c478bdstevel@tonic-gate/*******************************************************
9167c478bdstevel@tonic-gate * Dbm/Ndbm historic interfaces.
9177c478bdstevel@tonic-gate *******************************************************/
9187c478bdstevel@tonic-gate#define	DBM_INSERT	0		/* Flags to dbm_store(). */
9197c478bdstevel@tonic-gate#define	DBM_REPLACE	1
9207c478bdstevel@tonic-gate
9217c478bdstevel@tonic-gate/*
9227c478bdstevel@tonic-gate * The db(3) support for ndbm(3) always appends this suffix to the
9237c478bdstevel@tonic-gate * file name to avoid overwriting the user's original database.
9247c478bdstevel@tonic-gate */
9257c478bdstevel@tonic-gate#define	DBM_SUFFIX	".db"
9267c478bdstevel@tonic-gate
9277c478bdstevel@tonic-gate#if defined(_XPG4_2)
9287c478bdstevel@tonic-gatetypedef struct {
9297c478bdstevel@tonic-gate	char *dptr;
9307c478bdstevel@tonic-gate	size_t dsize;
9317c478bdstevel@tonic-gate} datum;
9327c478bdstevel@tonic-gate#else
9337c478bdstevel@tonic-gatetypedef struct {
9347c478bdstevel@tonic-gate	char *dptr;
9357c478bdstevel@tonic-gate	int dsize;
9367c478bdstevel@tonic-gate} datum;
9377c478bdstevel@tonic-gate#endif
9387c478bdstevel@tonic-gate
9397c478bdstevel@tonic-gate/*
9407c478bdstevel@tonic-gate * Translate DBM calls into DB calls so that DB doesn't step on the
9417c478bdstevel@tonic-gate * application's name space.
9427c478bdstevel@tonic-gate *
9437c478bdstevel@tonic-gate * The global variables dbrdonly, dirf and pagf were not retained when
9447c478bdstevel@tonic-gate * 4BSD replaced the dbm interface with ndbm, and are not support here.
9457c478bdstevel@tonic-gate */
9467c478bdstevel@tonic-gate#define	dbminit(a)	__db_dbm_init(a)
9477c478bdstevel@tonic-gate#define	dbmclose	__db_dbm_close
9487c478bdstevel@tonic-gate#if !defined(__cplusplus)
9497c478bdstevel@tonic-gate#define	delete(a)	__db_dbm_delete(a)
9507c478bdstevel@tonic-gate#endif
9517c478bdstevel@tonic-gate#define	fetch(a)	__db_dbm_fetch(a)
9527c478bdstevel@tonic-gate#define	firstkey	__db_dbm_firstkey
9537c478bdstevel@tonic-gate#define	nextkey(a)	__db_dbm_nextkey(a)
9547c478bdstevel@tonic-gate#define	store(a, b)	__db_dbm_store(a, b)
9557c478bdstevel@tonic-gate
9567c478bdstevel@tonic-gate/* Prototype the DB calls. */
9577c478bdstevel@tonic-gate#if defined(__cplusplus)
9587c478bdstevel@tonic-gateextern "C" {
9597c478bdstevel@tonic-gate#endif
9607c478bdstevel@tonic-gateint	 __db_dbm_close __P((void));
9617c478bdstevel@tonic-gateint	 __db_dbm_dbrdonly __P((void));
9627c478bdstevel@tonic-gateint	 __db_dbm_delete __P((datum));
9637c478bdstevel@tonic-gateint	 __db_dbm_dirf __P((void));
9647c478bdstevel@tonic-gatedatum	 __db_dbm_fetch __P((datum));
9657c478bdstevel@tonic-gatedatum	 __db_dbm_firstkey __P((void));
9667c478bdstevel@tonic-gateint	 __db_dbm_init __P((char *));
9677c478bdstevel@tonic-gatedatum	 __db_dbm_nextkey __P((datum));
9687c478bdstevel@tonic-gateint	 __db_dbm_pagf __P((void));
9697c478bdstevel@tonic-gateint	 __db_dbm_store __P((datum, datum));
9707c478bdstevel@tonic-gate#if defined(__cplusplus)
9717c478bdstevel@tonic-gate}
9727c478bdstevel@tonic-gate#endif
9737c478bdstevel@tonic-gate
9747c478bdstevel@tonic-gate/*
9757c478bdstevel@tonic-gate * Translate NDBM calls into DB calls so that DB doesn't step on the
9767c478bdstevel@tonic-gate * application's name space.
9777c478bdstevel@tonic-gate */
9787c478bdstevel@tonic-gate#define	dbm_clearerr(a)		__db_ndbm_clearerr(a)
9797c478bdstevel@tonic-gate#define	dbm_close(a)		__db_ndbm_close(a)
9807c478bdstevel@tonic-gate#define	dbm_delete(a, b)	__db_ndbm_delete(a, b)
9817c478bdstevel@tonic-gate#define	dbm_dirfno(a)		__db_ndbm_dirfno(a)
9827c478bdstevel@tonic-gate#define	dbm_error(a)		__db_ndbm_error(a)
9837c478bdstevel@tonic-gate#define	dbm_fetch(a, b)		__db_ndbm_fetch(a, b)
9847c478bdstevel@tonic-gate#define	dbm_firstkey(a)		__db_ndbm_firstkey(a)
9857c478bdstevel@tonic-gate#define	dbm_nextkey(a)		__db_ndbm_nextkey(a)
9867c478bdstevel@tonic-gate#define	dbm_open(a, b, c)	__db_ndbm_open(a, b, c)
9877c478bdstevel@tonic-gate#define	dbm_pagfno(a)		__db_ndbm_pagfno(a)
9887c478bdstevel@tonic-gate#define	dbm_rdonly(a)		__db_ndbm_rdonly(a)
9897c478bdstevel@tonic-gate#define	dbm_store(a, b, c, d)	__db_ndbm_store(a, b, c, d)
9907c478bdstevel@tonic-gate
9917c478bdstevel@tonic-gate/* Prototype the DB calls. */
9927c478bdstevel@tonic-gate#if defined(__cplusplus)
9937c478bdstevel@tonic-gateextern "C" {
9947c478bdstevel@tonic-gate#endif
9957c478bdstevel@tonic-gateint	 __db_ndbm_clearerr __P((DBM *));
9967c478bdstevel@tonic-gatevoid	 __db_ndbm_close __P((DBM *));
9977c478bdstevel@tonic-gateint	 __db_ndbm_delete __P((DBM *, datum));
9987c478bdstevel@tonic-gateint	 __db_ndbm_dirfno __P((DBM *));
9997c478bdstevel@tonic-gateint	 __db_ndbm_error __P((DBM *));
10007c478bdstevel@tonic-gatedatum	 __db_ndbm_fetch __P((DBM *, datum));
10017c478bdstevel@tonic-gatedatum	 __db_ndbm_firstkey __P((DBM *));
10027c478bdstevel@tonic-gatedatum	 __db_ndbm_nextkey __P((DBM *));
10037c478bdstevel@tonic-gateDBM	*__db_ndbm_open __P((const char *, int, int));
10047c478bdstevel@tonic-gateint	 __db_ndbm_pagfno __P((DBM *));
10057c478bdstevel@tonic-gateint	 __db_ndbm_rdonly __P((DBM *));
10067c478bdstevel@tonic-gateint	 __db_ndbm_store __P((DBM *, datum, datum, int));
10077c478bdstevel@tonic-gate#if defined(__cplusplus)
10087c478bdstevel@tonic-gate}
10097c478bdstevel@tonic-gate#endif
10107c478bdstevel@tonic-gate
10117c478bdstevel@tonic-gate/*******************************************************
10127c478bdstevel@tonic-gate * Hsearch historic interface.
10137c478bdstevel@tonic-gate *******************************************************/
10147c478bdstevel@tonic-gatetypedef enum {
10157c478bdstevel@tonic-gate	FIND, ENTER
10167c478bdstevel@tonic-gate} ACTION;
10177c478bdstevel@tonic-gate
10187c478bdstevel@tonic-gatetypedef struct entry {
10197c478bdstevel@tonic-gate	char *key;
10207c478bdstevel@tonic-gate	char *data;
10217c478bdstevel@tonic-gate} ENTRY;
10227c478bdstevel@tonic-gate
10237c478bdstevel@tonic-gate/*
10247c478bdstevel@tonic-gate * Translate HSEARCH calls into DB calls so that DB doesn't step on the
10257c478bdstevel@tonic-gate * application's name space.
10267c478bdstevel@tonic-gate */
10277c478bdstevel@tonic-gate#define	hcreate(a)	__db_hcreate(a)
10287c478bdstevel@tonic-gate#define	hdestroy	__db_hdestroy
10297c478bdstevel@tonic-gate#define	hsearch(a, b)	__db_hsearch(a, b)
10307c478bdstevel@tonic-gate
10317c478bdstevel@tonic-gate/* Prototype the DB calls. */
10327c478bdstevel@tonic-gate#if defined(__cplusplus)
10337c478bdstevel@tonic-gateextern "C" {
10347c478bdstevel@tonic-gate#endif
10357c478bdstevel@tonic-gateint	 __db_hcreate __P((size_t));
10367c478bdstevel@tonic-gatevoid	 __db_hdestroy __P((void));
10377c478bdstevel@tonic-gateENTRY	*__db_hsearch __P((ENTRY, ACTION));
10387c478bdstevel@tonic-gate#if defined(__cplusplus)
10397c478bdstevel@tonic-gate}
10407c478bdstevel@tonic-gate#endif
10417c478bdstevel@tonic-gate#endif /* DB_DBM_HSEARCH */
10427c478bdstevel@tonic-gate
10437c478bdstevel@tonic-gate/*
10447c478bdstevel@tonic-gate * XXX
10457c478bdstevel@tonic-gate * MacOS: Reset Metrowerks C enum sizes.
10467c478bdstevel@tonic-gate */
10477c478bdstevel@tonic-gate#ifdef __MWERKS__
10487c478bdstevel@tonic-gate#pragma enumsalwaysint reset
10497c478bdstevel@tonic-gate#endif
10507c478bdstevel@tonic-gate#endif /* !_DB_H_ */
1051