1/* DO NOT EDIT: automatically built by dist/s_windows. */
2/*
3 * See the file LICENSE for redistribution information.
4 *
5 * Copyright (c) 1996,2008 Oracle.  All rights reserved.
6 *
7 * $Id: db.in,v 12.193 2008/05/07 12:33:12 bschmeck Exp $
8 *
9 * db.h include file layout:
10 *	General.
11 *	Database Environment.
12 *	Locking subsystem.
13 *	Logging subsystem.
14 *	Shared buffer cache (mpool) subsystem.
15 *	Transaction subsystem.
16 *	Access methods.
17 *	Access method cursors.
18 *	Dbm/Ndbm, Hsearch historic interfaces.
19 */
20
21#ifndef _DB_H_
22#define	_DB_H_
23
24#ifndef	__NO_SYSTEM_INCLUDES
25#include <sys/types.h>
26#include <stddef.h>
27#include <stdio.h>
28#endif
29
30/*
31 * Turn off inappropriate compiler warnings
32 */
33#ifdef _MSC_VER
34/*
35 * This warning is explicitly disabled in Visual C++ by default.
36 * It is necessary to explicitly enable the /Wall flag to generate this
37 * warning.
38 * Since this is a shared include file it should compile without warnings
39 * at the highest warning level, so third party applications can use
40 * higher warning levels cleanly.
41 *
42 * 4820: 'bytes' bytes padding added after member 'member'
43 *       The type and order of elements caused the compiler to
44 *       add padding to the end of a struct.
45 */
46#pragma warning(push)
47#pragma warning(disable: 4820)
48#endif /* _MSC_VER */
49#if defined(__cplusplus)
50extern "C" {
51#endif
52
53
54#undef __P
55#define	__P(protos)	protos
56
57/*
58 * Berkeley DB version information.
59 */
60#define	DB_VERSION_MAJOR	4
61#define	DB_VERSION_MINOR	7
62#define	DB_VERSION_PATCH	25
63#define	DB_VERSION_STRING	"Berkeley DB 4.7.25: (May 15, 2008)"
64
65/*
66 * !!!
67 * Berkeley DB uses specifically sized types.  If they're not provided by
68 * the system, typedef them here.
69 *
70 * We protect them against multiple inclusion using __BIT_TYPES_DEFINED__,
71 * as does BIND and Kerberos, since we don't know for sure what #include
72 * files the user is using.
73 *
74 * !!!
75 * We also provide the standard u_int, u_long etc., if they're not provided
76 * by the system.
77 */
78#ifndef	__BIT_TYPES_DEFINED__
79#define	__BIT_TYPES_DEFINED__
80typedef unsigned char u_int8_t;
81typedef short int16_t;
82typedef unsigned short u_int16_t;
83typedef int int32_t;
84typedef unsigned int u_int32_t;
85typedef __int64 int64_t;
86typedef unsigned __int64 u_int64_t;
87#endif
88
89#ifndef _WINSOCKAPI_
90typedef unsigned char u_char;
91typedef unsigned int u_int;
92typedef unsigned long u_long;
93#endif
94typedef unsigned short u_short;
95
96/*
97 * Missing ANSI types.
98 *
99 * uintmax_t --
100 * Largest unsigned type, used to align structures in memory.  We don't store
101 * floating point types in structures, so integral types should be sufficient
102 * (and we don't have to worry about systems that store floats in other than
103 * power-of-2 numbers of bytes).  Additionally this fixes compilers that rewrite
104 * structure assignments and ANSI C memcpy calls to be in-line instructions
105 * that happen to require alignment.
106 *
107 * uintptr_t --
108 * Unsigned type that's the same size as a pointer.  There are places where
109 * DB modifies pointers by discarding the bottom bits to guarantee alignment.
110 * We can't use uintmax_t, it may be larger than the pointer, and compilers
111 * get upset about that.  So far we haven't run on any machine where there's
112 * no unsigned type the same size as a pointer -- here's hoping.
113 */
114typedef u_int64_t uintmax_t;
115#ifdef _WIN64
116typedef u_int64_t uintptr_t;
117#else
118typedef u_int32_t uintptr_t;
119#endif
120
121/*
122 * Windows defines off_t to long (i.e., 32 bits).  We need to pass 64-bit
123 * file offsets, so we declare our own.
124 */
125#define	off_t	__db_off_t
126typedef int64_t off_t;
127typedef int pid_t;
128#ifdef _WIN64
129typedef int64_t ssize_t;
130#else
131typedef int32_t ssize_t;
132#endif
133
134/*
135 * Sequences are only available on machines with 64-bit integral types.
136 */
137typedef int64_t db_seq_t;
138
139/* Thread and process identification. */
140typedef u_int32_t db_threadid_t;
141
142/* Basic types that are exported or quasi-exported. */
143typedef	u_int32_t	db_pgno_t;	/* Page number type. */
144typedef	u_int16_t	db_indx_t;	/* Page offset type. */
145#define	DB_MAX_PAGES	0xffffffff	/* >= # of pages in a file */
146
147typedef	u_int32_t	db_recno_t;	/* Record number type. */
148#define	DB_MAX_RECORDS	0xffffffff	/* >= # of records in a tree */
149
150typedef u_int32_t	db_timeout_t;	/* Type of a timeout. */
151
152/*
153 * Region offsets are the difference between a pointer in a region and the
154 * region's base address.  With private environments, both addresses are the
155 * result of calling malloc, and we can't assume anything about what malloc
156 * will return, so region offsets have to be able to hold differences between
157 * arbitrary pointers.
158 */
159typedef	uintptr_t	roff_t;
160
161/*
162 * Forward structure declarations, so we can declare pointers and
163 * applications can get type checking.
164 */
165struct __db;		typedef struct __db DB;
166struct __db_bt_stat;	typedef struct __db_bt_stat DB_BTREE_STAT;
167struct __db_cipher;	typedef struct __db_cipher DB_CIPHER;
168struct __db_compact;	typedef struct __db_compact DB_COMPACT;
169struct __db_dbt;	typedef struct __db_dbt DBT;
170struct __db_distab;	typedef struct __db_distab DB_DISTAB;
171struct __db_env;	typedef struct __db_env DB_ENV;
172struct __db_h_stat;	typedef struct __db_h_stat DB_HASH_STAT;
173struct __db_ilock;	typedef struct __db_ilock DB_LOCK_ILOCK;
174struct __db_lock_hstat;	typedef struct __db_lock_hstat DB_LOCK_HSTAT;
175struct __db_lock_pstat;	typedef struct __db_lock_pstat DB_LOCK_PSTAT;
176struct __db_lock_stat;	typedef struct __db_lock_stat DB_LOCK_STAT;
177struct __db_lock_u;	typedef struct __db_lock_u DB_LOCK;
178struct __db_locker;	typedef struct __db_locker DB_LOCKER;
179struct __db_lockreq;	typedef struct __db_lockreq DB_LOCKREQ;
180struct __db_locktab;	typedef struct __db_locktab DB_LOCKTAB;
181struct __db_log;	typedef struct __db_log DB_LOG;
182struct __db_log_cursor;	typedef struct __db_log_cursor DB_LOGC;
183struct __db_log_stat;	typedef struct __db_log_stat DB_LOG_STAT;
184struct __db_lsn;	typedef struct __db_lsn DB_LSN;
185struct __db_mpool;	typedef struct __db_mpool DB_MPOOL;
186struct __db_mpool_fstat;typedef struct __db_mpool_fstat DB_MPOOL_FSTAT;
187struct __db_mpool_stat;	typedef struct __db_mpool_stat DB_MPOOL_STAT;
188struct __db_mpoolfile;	typedef struct __db_mpoolfile DB_MPOOLFILE;
189struct __db_mutex_stat;	typedef struct __db_mutex_stat DB_MUTEX_STAT;
190struct __db_mutex_t;	typedef struct __db_mutex_t DB_MUTEX;
191struct __db_mutexmgr;	typedef struct __db_mutexmgr DB_MUTEXMGR;
192struct __db_preplist;	typedef struct __db_preplist DB_PREPLIST;
193struct __db_qam_stat;	typedef struct __db_qam_stat DB_QUEUE_STAT;
194struct __db_rep;	typedef struct __db_rep DB_REP;
195struct __db_rep_stat;	typedef struct __db_rep_stat DB_REP_STAT;
196struct __db_repmgr_site;typedef struct __db_repmgr_site DB_REPMGR_SITE;
197struct __db_repmgr_stat;typedef struct __db_repmgr_stat DB_REPMGR_STAT;
198struct __db_seq_record; typedef struct __db_seq_record DB_SEQ_RECORD;
199struct __db_seq_stat;	typedef struct __db_seq_stat DB_SEQUENCE_STAT;
200struct __db_sequence;	typedef struct __db_sequence DB_SEQUENCE;
201struct __db_thread_info;typedef struct __db_thread_info DB_THREAD_INFO;
202struct __db_txn;	typedef struct __db_txn DB_TXN;
203struct __db_txn_active;	typedef struct __db_txn_active DB_TXN_ACTIVE;
204struct __db_txn_stat;	typedef struct __db_txn_stat DB_TXN_STAT;
205struct __db_txnmgr;	typedef struct __db_txnmgr DB_TXNMGR;
206struct __dbc;		typedef struct __dbc DBC;
207struct __dbc_internal;	typedef struct __dbc_internal DBC_INTERNAL;
208struct __env;		typedef struct __env ENV;
209struct __fh_t;		typedef struct __fh_t DB_FH;
210struct __fname;		typedef struct __fname FNAME;
211struct __key_range;	typedef struct __key_range DB_KEY_RANGE;
212struct __mpoolfile;	typedef struct __mpoolfile MPOOLFILE;
213
214/*
215 * The Berkeley DB API flags are automatically-generated -- the following flag names are
216 * no longer used, but remain for compatibility reasons.
217 */
218#define	DB_DEGREE_2	      DB_READ_COMMITTED
219#define	DB_DIRTY_READ	      DB_READ_UNCOMMITTED
220#define	DB_JOINENV	      0x0
221
222/* Key/data structure -- a Data-Base Thang. */
223struct __db_dbt {
224	void	 *data;			/* Key/data */
225	u_int32_t size;			/* key/data length */
226
227	u_int32_t ulen;			/* RO: length of user buffer. */
228	u_int32_t dlen;			/* RO: get/put record length. */
229	u_int32_t doff;			/* RO: get/put record offset. */
230
231	void *app_data;
232
233#define	DB_DBT_APPMALLOC	0x001	/* Callback allocated memory. */
234#define	DB_DBT_DUPOK		0x002	/* Insert if duplicate. */
235#define	DB_DBT_ISSET		0x004	/* Lower level calls set value. */
236#define	DB_DBT_MALLOC		0x008	/* Return in malloc'd memory. */
237#define	DB_DBT_MULTIPLE		0x010	/* References multiple records. */
238#define	DB_DBT_PARTIAL		0x020	/* Partial put/get. */
239#define	DB_DBT_REALLOC		0x040	/* Return in realloc'd memory. */
240#define	DB_DBT_USERCOPY		0x080	/* Use the user-supplied callback. */
241#define	DB_DBT_USERMEM		0x100	/* Return in user's memory. */
242	u_int32_t flags;
243};
244
245/*******************************************************
246 * Mutexes.
247 *******************************************************/
248typedef u_int32_t	db_mutex_t;
249
250struct __db_mutex_stat {
251	/* The following fields are maintained in the region's copy. */
252	u_int32_t st_mutex_align;	/* Mutex alignment */
253	u_int32_t st_mutex_tas_spins;	/* Mutex test-and-set spins */
254	u_int32_t st_mutex_cnt;		/* Mutex count */
255	u_int32_t st_mutex_free;	/* Available mutexes */
256	u_int32_t st_mutex_inuse;	/* Mutexes in use */
257	u_int32_t st_mutex_inuse_max;	/* Maximum mutexes ever in use */
258
259	/* The following fields are filled-in from other places. */
260#ifndef __TEST_DB_NO_STATISTICS
261	u_int32_t st_region_wait;	/* Region lock granted after wait. */
262	u_int32_t st_region_nowait;	/* Region lock granted without wait. */
263	roff_t	  st_regsize;		/* Region size. */
264#endif
265};
266
267/* This is the length of the buffer passed to DB_ENV->thread_id_string() */
268#define	DB_THREADID_STRLEN	128
269
270/*******************************************************
271 * Locking.
272 *******************************************************/
273#define	DB_LOCKVERSION	1
274
275#define	DB_FILE_ID_LEN		20	/* Unique file ID length. */
276
277/*
278 * Deadlock detector modes; used in the DB_ENV structure to configure the
279 * locking subsystem.
280 */
281#define	DB_LOCK_NORUN		0
282#define	DB_LOCK_DEFAULT		1	/* Default policy. */
283#define	DB_LOCK_EXPIRE		2	/* Only expire locks, no detection. */
284#define	DB_LOCK_MAXLOCKS	3	/* Select locker with max locks. */
285#define	DB_LOCK_MAXWRITE	4	/* Select locker with max writelocks. */
286#define	DB_LOCK_MINLOCKS	5	/* Select locker with min locks. */
287#define	DB_LOCK_MINWRITE	6	/* Select locker with min writelocks. */
288#define	DB_LOCK_OLDEST		7	/* Select oldest locker. */
289#define	DB_LOCK_RANDOM		8	/* Select random locker. */
290#define	DB_LOCK_YOUNGEST	9	/* Select youngest locker. */
291
292/*
293 * Simple R/W lock modes and for multi-granularity intention locking.
294 *
295 * !!!
296 * These values are NOT random, as they are used as an index into the lock
297 * conflicts arrays, i.e., DB_LOCK_IWRITE must be == 3, and DB_LOCK_IREAD
298 * must be == 4.
299 */
300typedef enum {
301	DB_LOCK_NG=0,			/* Not granted. */
302	DB_LOCK_READ=1,			/* Shared/read. */
303	DB_LOCK_WRITE=2,		/* Exclusive/write. */
304	DB_LOCK_WAIT=3,			/* Wait for event */
305	DB_LOCK_IWRITE=4,		/* Intent exclusive/write. */
306	DB_LOCK_IREAD=5,		/* Intent to share/read. */
307	DB_LOCK_IWR=6,			/* Intent to read and write. */
308	DB_LOCK_READ_UNCOMMITTED=7,	/* Degree 1 isolation. */
309	DB_LOCK_WWRITE=8		/* Was Written. */
310} db_lockmode_t;
311
312/*
313 * Request types.
314 */
315typedef enum {
316	DB_LOCK_DUMP=0,			/* Display held locks. */
317	DB_LOCK_GET=1,			/* Get the lock. */
318	DB_LOCK_GET_TIMEOUT=2,		/* Get lock with a timeout. */
319	DB_LOCK_INHERIT=3,		/* Pass locks to parent. */
320	DB_LOCK_PUT=4,			/* Release the lock. */
321	DB_LOCK_PUT_ALL=5,		/* Release locker's locks. */
322	DB_LOCK_PUT_OBJ=6,		/* Release locker's locks on obj. */
323	DB_LOCK_PUT_READ=7,		/* Release locker's read locks. */
324	DB_LOCK_TIMEOUT=8,		/* Force a txn to timeout. */
325	DB_LOCK_TRADE=9,		/* Trade locker ids on a lock. */
326	DB_LOCK_UPGRADE_WRITE=10	/* Upgrade writes for dirty reads. */
327} db_lockop_t;
328
329/*
330 * Status of a lock.
331 */
332typedef enum  {
333	DB_LSTAT_ABORTED=1,		/* Lock belongs to an aborted txn. */
334	DB_LSTAT_EXPIRED=2,		/* Lock has expired. */
335	DB_LSTAT_FREE=3,		/* Lock is unallocated. */
336	DB_LSTAT_HELD=4,		/* Lock is currently held. */
337	DB_LSTAT_PENDING=5,		/* Lock was waiting and has been
338					 * promoted; waiting for the owner
339					 * to run and upgrade it to held. */
340	DB_LSTAT_WAITING=6		/* Lock is on the wait queue. */
341}db_status_t;
342
343/* Lock statistics structure. */
344struct __db_lock_stat {
345	u_int32_t st_id;		/* Last allocated locker ID. */
346	u_int32_t st_cur_maxid;		/* Current maximum unused ID. */
347	u_int32_t st_maxlocks;		/* Maximum number of locks in table. */
348	u_int32_t st_maxlockers;	/* Maximum num of lockers in table. */
349	u_int32_t st_maxobjects;	/* Maximum num of objects in table. */
350	u_int32_t st_partitions;	/* number of partitions. */
351	int	  st_nmodes;		/* Number of lock modes. */
352	u_int32_t st_nlockers;		/* Current number of lockers. */
353#ifndef __TEST_DB_NO_STATISTICS
354	u_int32_t st_nlocks;		/* Current number of locks. */
355	u_int32_t st_maxnlocks;		/* Maximum number of locks so far. */
356	u_int32_t st_maxhlocks;		/* Maximum number of locks in any bucket. */
357	u_int32_t st_locksteals;	/* Number of lock steals so far. */
358	u_int32_t st_maxlsteals;	/* Maximum number steals in any partition. */
359	u_int32_t st_maxnlockers;	/* Maximum number of lockers so far. */
360	u_int32_t st_nobjects;		/* Current number of objects. */
361	u_int32_t st_maxnobjects;	/* Maximum number of objects so far. */
362	u_int32_t st_maxhobjects;	/* Maximum number of objectsin any bucket. */
363	u_int32_t st_objectsteals;	/* Number of objects steals so far. */
364	u_int32_t st_maxosteals;	/* Maximum number of steals in any partition. */
365	u_int32_t st_nrequests;		/* Number of lock gets. */
366	u_int32_t st_nreleases;		/* Number of lock puts. */
367	u_int32_t st_nupgrade;		/* Number of lock upgrades. */
368	u_int32_t st_ndowngrade;	/* Number of lock downgrades. */
369	u_int32_t st_lock_wait;		/* Lock conflicts w/ subsequent wait */
370	u_int32_t st_lock_nowait;	/* Lock conflicts w/o subsequent wait */
371	u_int32_t st_ndeadlocks;	/* Number of lock deadlocks. */
372	db_timeout_t st_locktimeout;	/* Lock timeout. */
373	u_int32_t st_nlocktimeouts;	/* Number of lock timeouts. */
374	db_timeout_t st_txntimeout;	/* Transaction timeout. */
375	u_int32_t st_ntxntimeouts;	/* Number of transaction timeouts. */
376	u_int32_t st_part_wait;		/* Partition lock granted after wait. */
377	u_int32_t st_part_nowait;	/* Partition lock granted without wait. */
378	u_int32_t st_part_max_wait;	/* Max partition lock granted after wait. */
379	u_int32_t st_part_max_nowait;	/* Max partition lock granted without wait. */
380	u_int32_t st_objs_wait;		/* Object lock granted after wait. */
381	u_int32_t st_objs_nowait;	/* Object lock granted without wait. */
382	u_int32_t st_lockers_wait;	/* Locker lock granted after wait. */
383	u_int32_t st_lockers_nowait;	/* Locker lock granted without wait. */
384	u_int32_t st_region_wait;	/* Region lock granted after wait. */
385	u_int32_t st_region_nowait;	/* Region lock granted without wait. */
386	u_int32_t st_hash_len;		/* Max length of bucket. */
387	roff_t	  st_regsize;		/* Region size. */
388#endif
389};
390
391struct __db_lock_hstat {
392	u_int32_t st_nrequests;		/* Number of lock gets. */
393	u_int32_t st_nreleases;		/* Number of lock puts. */
394	u_int32_t st_nupgrade;		/* Number of lock upgrades. */
395	u_int32_t st_ndowngrade;	/* Number of lock downgrades. */
396	u_int32_t st_nlocks;		/* Current number of locks. */
397	u_int32_t st_maxnlocks;		/* Maximum number of locks so far. */
398	u_int32_t st_nobjects;		/* Current number of objects. */
399	u_int32_t st_maxnobjects;	/* Maximum number of objects so far. */
400	u_int32_t st_lock_wait;		/* Lock conflicts w/ subsequent wait */
401	u_int32_t st_lock_nowait;	/* Lock conflicts w/o subsequent wait */
402	u_int32_t st_nlocktimeouts;	/* Number of lock timeouts. */
403	u_int32_t st_ntxntimeouts;	/* Number of transaction timeouts. */
404	u_int32_t st_hash_len;		/* Max length of bucket. */
405};
406
407struct __db_lock_pstat {
408	u_int32_t st_nlocks;		/* Current number of locks. */
409	u_int32_t st_maxnlocks;		/* Maximum number of locks so far. */
410	u_int32_t st_nobjects;		/* Current number of objects. */
411	u_int32_t st_maxnobjects;	/* Maximum number of objects so far. */
412	u_int32_t st_locksteals;	/* Number of lock steals so far. */
413	u_int32_t st_objectsteals;	/* Number of objects steals so far. */
414};
415
416/*
417 * DB_LOCK_ILOCK --
418 *	Internal DB access method lock.
419 */
420struct __db_ilock {
421	db_pgno_t pgno;			/* Page being locked. */
422	u_int8_t fileid[DB_FILE_ID_LEN];/* File id. */
423#define	DB_HANDLE_LOCK	1
424#define	DB_RECORD_LOCK	2
425#define	DB_PAGE_LOCK	3
426	u_int32_t type;			/* Type of lock. */
427};
428
429/*
430 * DB_LOCK --
431 *	The structure is allocated by the caller and filled in during a
432 *	lock_get request (or a lock_vec/DB_LOCK_GET).
433 */
434struct __db_lock_u {
435	roff_t		off;		/* Offset of the lock in the region */
436	u_int32_t	ndx;		/* Index of the object referenced by
437					 * this lock; used for locking. */
438	u_int32_t	gen;		/* Generation number of this lock. */
439	db_lockmode_t	mode;		/* mode of this lock. */
440};
441
442/* Lock request structure. */
443struct __db_lockreq {
444	db_lockop_t	 op;		/* Operation. */
445	db_lockmode_t	 mode;		/* Requested mode. */
446	db_timeout_t	 timeout;	/* Time to expire lock. */
447	DBT		*obj;		/* Object being locked. */
448	DB_LOCK		 lock;		/* Lock returned. */
449};
450
451/*******************************************************
452 * Logging.
453 *******************************************************/
454#define	DB_LOGVERSION	14		/* Current log version. */
455#define	DB_LOGOLDVER	8		/* Oldest log version supported. */
456#define	DB_LOGMAGIC	0x040988
457
458/*
459 * A DB_LSN has two parts, a fileid which identifies a specific file, and an
460 * offset within that file.  The fileid is an unsigned 4-byte quantity that
461 * uniquely identifies a file within the log directory -- currently a simple
462 * counter inside the log.  The offset is also an unsigned 4-byte value.  The
463 * log manager guarantees the offset is never more than 4 bytes by switching
464 * to a new log file before the maximum length imposed by an unsigned 4-byte
465 * offset is reached.
466 */
467struct __db_lsn {
468	u_int32_t	file;		/* File ID. */
469	u_int32_t	offset;		/* File offset. */
470};
471
472/*
473 * Application-specified log record types start at DB_user_BEGIN, and must not
474 * equal or exceed DB_debug_FLAG.
475 *
476 * DB_debug_FLAG is the high-bit of the u_int32_t that specifies a log record
477 * type.  If the flag is set, it's a log record that was logged for debugging
478 * purposes only, even if it reflects a database change -- the change was part
479 * of a non-durable transaction.
480 */
481#define	DB_user_BEGIN		10000
482#define	DB_debug_FLAG		0x80000000
483
484/*
485 * DB_LOGC --
486 *	Log cursor.
487 */
488struct __db_log_cursor {
489	ENV	 *env;			/* Environment */
490
491	DB_FH	 *fhp;			/* File handle. */
492	DB_LSN	  lsn;			/* Cursor: LSN */
493	u_int32_t len;			/* Cursor: record length */
494	u_int32_t prev;			/* Cursor: previous record's offset */
495
496	DBT	  dbt;			/* Return DBT. */
497	DB_LSN    p_lsn;		/* Persist LSN. */
498	u_int32_t p_version;		/* Persist version. */
499
500	u_int8_t *bp;			/* Allocated read buffer. */
501	u_int32_t bp_size;		/* Read buffer length in bytes. */
502	u_int32_t bp_rlen;		/* Read buffer valid data length. */
503	DB_LSN	  bp_lsn;		/* Read buffer first byte LSN. */
504
505	u_int32_t bp_maxrec;		/* Max record length in the log file. */
506
507	/* DB_LOGC PUBLIC HANDLE LIST BEGIN */
508	int (*close) __P((DB_LOGC *, u_int32_t));
509	int (*get) __P((DB_LOGC *, DB_LSN *, DBT *, u_int32_t));
510	int (*version) __P((DB_LOGC *, u_int32_t *, u_int32_t));
511	/* DB_LOGC PUBLIC HANDLE LIST END */
512
513#define	DB_LOG_DISK		0x01	/* Log record came from disk. */
514#define	DB_LOG_LOCKED		0x02	/* Log region already locked */
515#define	DB_LOG_SILENT_ERR	0x04	/* Turn-off error messages. */
516	u_int32_t flags;
517};
518
519/* Log statistics structure. */
520struct __db_log_stat {
521	u_int32_t st_magic;		/* Log file magic number. */
522	u_int32_t st_version;		/* Log file version number. */
523	int	  st_mode;		/* Log file permissions mode. */
524	u_int32_t st_lg_bsize;		/* Log buffer size. */
525	u_int32_t st_lg_size;		/* Log file size. */
526	u_int32_t st_wc_bytes;		/* Bytes to log since checkpoint. */
527	u_int32_t st_wc_mbytes;		/* Megabytes to log since checkpoint. */
528#ifndef __TEST_DB_NO_STATISTICS
529	u_int32_t st_record;		/* Records entered into the log. */
530	u_int32_t st_w_bytes;		/* Bytes to log. */
531	u_int32_t st_w_mbytes;		/* Megabytes to log. */
532	u_int32_t st_wcount;		/* Total I/O writes to the log. */
533	u_int32_t st_wcount_fill;	/* Overflow writes to the log. */
534	u_int32_t st_rcount;		/* Total I/O reads from the log. */
535	u_int32_t st_scount;		/* Total syncs to the log. */
536	u_int32_t st_region_wait;	/* Region lock granted after wait. */
537	u_int32_t st_region_nowait;	/* Region lock granted without wait. */
538	u_int32_t st_cur_file;		/* Current log file number. */
539	u_int32_t st_cur_offset;	/* Current log file offset. */
540	u_int32_t st_disk_file;		/* Known on disk log file number. */
541	u_int32_t st_disk_offset;	/* Known on disk log file offset. */
542	u_int32_t st_maxcommitperflush;	/* Max number of commits in a flush. */
543	u_int32_t st_mincommitperflush;	/* Min number of commits in a flush. */
544	roff_t	  st_regsize;		/* Region size. */
545#endif
546};
547
548/*
549 * We need to record the first log record of a transaction.  For user
550 * defined logging this macro returns the place to put that information,
551 * if it is need in rlsnp, otherwise it leaves it unchanged.  We also
552 * need to track the last record of the transaction, this returns the
553 * place to put that info.
554 */
555#define	DB_SET_TXN_LSNP(txn, blsnp, llsnp)		\
556	((txn)->set_txn_lsnp(txn, blsnp, llsnp))
557
558/*******************************************************
559 * Shared buffer cache (mpool).
560 *******************************************************/
561/* Priority values for DB_MPOOLFILE->{put,set_priority}. */
562typedef enum {
563	DB_PRIORITY_UNCHANGED=0,
564	DB_PRIORITY_VERY_LOW=1,
565	DB_PRIORITY_LOW=2,
566	DB_PRIORITY_DEFAULT=3,
567	DB_PRIORITY_HIGH=4,
568	DB_PRIORITY_VERY_HIGH=5
569} DB_CACHE_PRIORITY;
570
571/* Per-process DB_MPOOLFILE information. */
572struct __db_mpoolfile {
573	DB_FH	  *fhp;			/* Underlying file handle. */
574
575	/*
576	 * !!!
577	 * The ref, pinref and q fields are protected by the region lock.
578	 */
579	u_int32_t  ref;			/* Reference count. */
580
581	u_int32_t pinref;		/* Pinned block reference count. */
582
583	/*
584	 * !!!
585	 * Explicit representations of structures from queue.h.
586	 * TAILQ_ENTRY(__db_mpoolfile) q;
587	 */
588	struct {
589		struct __db_mpoolfile *tqe_next;
590		struct __db_mpoolfile **tqe_prev;
591	} q;				/* Linked list of DB_MPOOLFILE's. */
592
593	/*
594	 * !!!
595	 * The rest of the fields (with the exception of the MP_FLUSH flag)
596	 * are not thread-protected, even when they may be modified at any
597	 * time by the application.  The reason is the DB_MPOOLFILE handle
598	 * is single-threaded from the viewpoint of the application, and so
599	 * the only fields needing to be thread-protected are those accessed
600	 * by checkpoint or sync threads when using DB_MPOOLFILE structures
601	 * to flush buffers from the cache.
602	 */
603	ENV	       *env;		/* Environment */
604	MPOOLFILE      *mfp;		/* Underlying MPOOLFILE. */
605
606	u_int32_t	clear_len;	/* Cleared length on created pages. */
607	u_int8_t			/* Unique file ID. */
608			fileid[DB_FILE_ID_LEN];
609	int		ftype;		/* File type. */
610	int32_t		lsn_offset;	/* LSN offset in page. */
611	u_int32_t	gbytes, bytes;	/* Maximum file size. */
612	DBT	       *pgcookie;	/* Byte-string passed to pgin/pgout. */
613	int32_t		priority;	/* Cache priority. */
614
615	void	       *addr;		/* Address of mmap'd region. */
616	size_t		len;		/* Length of mmap'd region. */
617
618	u_int32_t	config_flags;	/* Flags to DB_MPOOLFILE->set_flags. */
619
620	/* DB_MPOOLFILE PUBLIC HANDLE LIST BEGIN */
621	int (*close) __P((DB_MPOOLFILE *, u_int32_t));
622	int (*get)
623	    __P((DB_MPOOLFILE *, db_pgno_t *, DB_TXN *, u_int32_t, void *));
624	int (*get_clear_len) __P((DB_MPOOLFILE *, u_int32_t *));
625	int (*get_fileid) __P((DB_MPOOLFILE *, u_int8_t *));
626	int (*get_flags) __P((DB_MPOOLFILE *, u_int32_t *));
627	int (*get_ftype) __P((DB_MPOOLFILE *, int *));
628	int (*get_last_pgno) __P((DB_MPOOLFILE *, db_pgno_t *));
629	int (*get_lsn_offset) __P((DB_MPOOLFILE *, int32_t *));
630	int (*get_maxsize) __P((DB_MPOOLFILE *, u_int32_t *, u_int32_t *));
631	int (*get_pgcookie) __P((DB_MPOOLFILE *, DBT *));
632	int (*get_priority) __P((DB_MPOOLFILE *, DB_CACHE_PRIORITY *));
633	int (*open) __P((DB_MPOOLFILE *, const char *, u_int32_t, int, size_t));
634	int (*put) __P((DB_MPOOLFILE *, void *, DB_CACHE_PRIORITY, u_int32_t));
635	int (*set_clear_len) __P((DB_MPOOLFILE *, u_int32_t));
636	int (*set_fileid) __P((DB_MPOOLFILE *, u_int8_t *));
637	int (*set_flags) __P((DB_MPOOLFILE *, u_int32_t, int));
638	int (*set_ftype) __P((DB_MPOOLFILE *, int));
639	int (*set_lsn_offset) __P((DB_MPOOLFILE *, int32_t));
640	int (*set_maxsize) __P((DB_MPOOLFILE *, u_int32_t, u_int32_t));
641	int (*set_pgcookie) __P((DB_MPOOLFILE *, DBT *));
642	int (*set_priority) __P((DB_MPOOLFILE *, DB_CACHE_PRIORITY));
643	int (*sync) __P((DB_MPOOLFILE *));
644	/* DB_MPOOLFILE PUBLIC HANDLE LIST END */
645
646	/*
647	 * MP_FILEID_SET, MP_OPEN_CALLED and MP_READONLY do not need to be
648	 * thread protected because they are initialized before the file is
649	 * linked onto the per-process lists, and never modified.
650	 *
651	 * MP_FLUSH is thread protected because it is potentially read/set by
652	 * multiple threads of control.
653	 */
654#define	MP_FILEID_SET	0x001		/* Application supplied a file ID. */
655#define	MP_FLUSH	0x002		/* Was opened to flush a buffer. */
656#define	MP_MULTIVERSION	0x004		/* Opened for multiversion access. */
657#define	MP_OPEN_CALLED	0x008		/* File opened. */
658#define	MP_READONLY	0x010		/* File is readonly. */
659#define	MP_DUMMY	0x020		/* File is dummy for __memp_fput. */
660	u_int32_t  flags;
661};
662
663/* Mpool statistics structure. */
664struct __db_mpool_stat {
665	u_int32_t st_gbytes;		/* Total cache size: GB. */
666	u_int32_t st_bytes;		/* Total cache size: B. */
667	u_int32_t st_ncache;		/* Number of cache regions. */
668	u_int32_t st_max_ncache;	/* Maximum number of regions. */
669	size_t	  st_mmapsize;		/* Maximum file size for mmap. */
670	int	  st_maxopenfd;		/* Maximum number of open fd's. */
671	int	  st_maxwrite;		/* Maximum buffers to write. */
672	db_timeout_t st_maxwrite_sleep;	/* Sleep after writing max buffers. */
673	u_int32_t st_pages;		/* Total number of pages. */
674#ifndef __TEST_DB_NO_STATISTICS
675	u_int32_t st_map;		/* Pages from mapped files. */
676	u_int32_t st_cache_hit;		/* Pages found in the cache. */
677	u_int32_t st_cache_miss;	/* Pages not found in the cache. */
678	u_int32_t st_page_create;	/* Pages created in the cache. */
679	u_int32_t st_page_in;		/* Pages read in. */
680	u_int32_t st_page_out;		/* Pages written out. */
681	u_int32_t st_ro_evict;		/* Clean pages forced from the cache. */
682	u_int32_t st_rw_evict;		/* Dirty pages forced from the cache. */
683	u_int32_t st_page_trickle;	/* Pages written by memp_trickle. */
684	u_int32_t st_page_clean;	/* Clean pages. */
685	u_int32_t st_page_dirty;	/* Dirty pages. */
686	u_int32_t st_hash_buckets;	/* Number of hash buckets. */
687	u_int32_t st_hash_searches;	/* Total hash chain searches. */
688	u_int32_t st_hash_longest;	/* Longest hash chain searched. */
689	u_int32_t st_hash_examined;	/* Total hash entries searched. */
690	u_int32_t st_hash_nowait;	/* Hash lock granted with nowait. */
691	u_int32_t st_hash_wait;		/* Hash lock granted after wait. */
692	u_int32_t st_hash_max_nowait;	/* Max hash lock granted with nowait. */
693	u_int32_t st_hash_max_wait;	/* Max hash lock granted after wait. */
694	u_int32_t st_region_nowait;	/* Region lock granted with nowait. */
695	u_int32_t st_region_wait;	/* Region lock granted after wait. */
696	u_int32_t st_mvcc_frozen;		/* Buffers frozen. */
697	u_int32_t st_mvcc_thawed;		/* Buffers thawed. */
698	u_int32_t st_mvcc_freed;		/* Frozen buffers freed. */
699	u_int32_t st_alloc;		/* Number of page allocations. */
700	u_int32_t st_alloc_buckets;	/* Buckets checked during allocation. */
701	u_int32_t st_alloc_max_buckets;	/* Max checked during allocation. */
702	u_int32_t st_alloc_pages;	/* Pages checked during allocation. */
703	u_int32_t st_alloc_max_pages;	/* Max checked during allocation. */
704	u_int32_t st_io_wait;		/* Thread waited on buffer I/O. */
705	roff_t	  st_regsize;		/* Region size. */
706#endif
707};
708
709/* Mpool file statistics structure. */
710struct __db_mpool_fstat {
711	char *file_name;		/* File name. */
712	u_int32_t st_pagesize;		/* Page size. */
713#ifndef __TEST_DB_NO_STATISTICS
714	u_int32_t st_map;		/* Pages from mapped files. */
715	u_int32_t st_cache_hit;		/* Pages found in the cache. */
716	u_int32_t st_cache_miss;	/* Pages not found in the cache. */
717	u_int32_t st_page_create;	/* Pages created in the cache. */
718	u_int32_t st_page_in;		/* Pages read in. */
719	u_int32_t st_page_out;		/* Pages written out. */
720#endif
721};
722
723/*******************************************************
724 * Transactions and recovery.
725 *******************************************************/
726#define	DB_TXNVERSION	1
727
728typedef enum {
729	DB_TXN_ABORT=0,			/* Public. */
730	DB_TXN_APPLY=1,			/* Public. */
731	DB_TXN_BACKWARD_ROLL=3,		/* Public. */
732	DB_TXN_FORWARD_ROLL=4,		/* Public. */
733	DB_TXN_OPENFILES=5,		/* Internal. */
734	DB_TXN_POPENFILES=6,		/* Internal. */
735	DB_TXN_PRINT=7			/* Public. */
736} db_recops;
737
738/*
739 * BACKWARD_ALLOC is used during the forward pass to pick up any aborted
740 * allocations for files that were created during the forward pass.
741 * The main difference between _ALLOC and _ROLL is that the entry for
742 * the file not exist during the rollforward pass.
743 */
744#define	DB_UNDO(op)	((op) == DB_TXN_ABORT || (op) == DB_TXN_BACKWARD_ROLL)
745#define	DB_REDO(op)	((op) == DB_TXN_FORWARD_ROLL || (op) == DB_TXN_APPLY)
746
747struct __db_txn {
748	DB_TXNMGR	*mgrp;		/* Pointer to transaction manager. */
749	DB_TXN		*parent;	/* Pointer to transaction's parent. */
750	DB_THREAD_INFO	*thread_info;	/* Pointer to thread information. */
751
752	u_int32_t	txnid;		/* Unique transaction id. */
753	char		*name;		/* Transaction name. */
754	DB_LOCKER	*locker;	/* Locker for this txn. */
755
756	db_threadid_t	tid;		/* Thread id for use in MT XA. */
757	void		*td;		/* Detail structure within region. */
758	db_timeout_t	lock_timeout;	/* Timeout for locks for this txn. */
759	db_timeout_t	expire;		/* Time transaction expires. */
760	void		*txn_list;	/* Undo information for parent. */
761
762	/*
763	 * !!!
764	 * Explicit representations of structures from queue.h.
765	 * TAILQ_ENTRY(__db_txn) links;
766	 * TAILQ_ENTRY(__db_txn) xalinks;
767	 */
768	struct {
769		struct __db_txn *tqe_next;
770		struct __db_txn **tqe_prev;
771	} links;			/* Links transactions off manager. */
772	struct {
773		struct __db_txn *tqe_next;
774		struct __db_txn **tqe_prev;
775	} xalinks;			/* Links active XA transactions. */
776
777	/*
778	 * !!!
779	 * Explicit representations of structures from queue.h.
780	 * TAILQ_HEAD(__kids, __db_txn) kids;
781	 */
782	struct __kids {
783		struct __db_txn *tqh_first;
784		struct __db_txn **tqh_last;
785	} kids;
786
787	/*
788	 * !!!
789	 * Explicit representations of structures from queue.h.
790	 * TAILQ_HEAD(__events, __txn_event) events;
791	 */
792	struct {
793		struct __txn_event *tqh_first;
794		struct __txn_event **tqh_last;
795	} events;			/* Links deferred events. */
796
797	/*
798	 * !!!
799	 * Explicit representations of structures from queue.h.
800	 * STAILQ_HEAD(__logrec, __txn_logrec) logs;
801	 */
802	struct {
803		struct __txn_logrec *stqh_first;
804		struct __txn_logrec **stqh_last;
805	} logs;				/* Links in memory log records. */
806
807	/*
808	 * !!!
809	 * Explicit representations of structures from queue.h.
810	 * TAILQ_ENTRY(__db_txn) klinks;
811	 */
812	struct {
813		struct __db_txn *tqe_next;
814		struct __db_txn **tqe_prev;
815	} klinks;
816
817	void	*api_internal;		/* C++ API private. */
818	void	*xml_internal;		/* XML API private. */
819
820	u_int32_t	cursors;	/* Number of cursors open for txn */
821
822	/* DB_TXN PUBLIC HANDLE LIST BEGIN */
823	int	  (*abort) __P((DB_TXN *));
824	int	  (*commit) __P((DB_TXN *, u_int32_t));
825	int	  (*discard) __P((DB_TXN *, u_int32_t));
826	int	  (*get_name) __P((DB_TXN *, const char **));
827	u_int32_t (*id) __P((DB_TXN *));
828	int	  (*prepare) __P((DB_TXN *, u_int8_t *));
829	int	  (*set_name) __P((DB_TXN *, const char *));
830	int	  (*set_timeout) __P((DB_TXN *, db_timeout_t, u_int32_t));
831	/* DB_TXN PUBLIC HANDLE LIST END */
832
833	/* DB_TXN PRIVATE HANDLE LIST BEGIN */
834	void	  (*set_txn_lsnp) __P((DB_TXN *txn, DB_LSN **, DB_LSN **));
835	/* DB_TXN PRIVATE HANDLE LIST END */
836
837#define	TXN_CHILDCOMMIT		0x0001	/* Txn has committed. */
838#define	TXN_CDSGROUP		0x0002	/* CDS group handle. */
839#define	TXN_COMPENSATE		0x0004	/* Compensating transaction. */
840#define	TXN_DEADLOCK		0x0008	/* Txn has deadlocked. */
841#define	TXN_LOCKTIMEOUT		0x0010	/* Txn has a lock timeout. */
842#define	TXN_MALLOC		0x0020	/* Structure allocated by TXN system. */
843#define	TXN_NOSYNC		0x0040	/* Do not sync on prepare and commit. */
844#define	TXN_NOWAIT		0x0080	/* Do not wait on locks. */
845#define	TXN_PRIVATE		0x0100	/* Txn owned by cursor.. */
846#define	TXN_READ_COMMITTED	0x0200	/* Txn has degree 2 isolation. */
847#define	TXN_READ_UNCOMMITTED	0x0400	/* Txn has degree 1 isolation. */
848#define	TXN_RESTORED		0x0800	/* Txn has been restored. */
849#define	TXN_SNAPSHOT		0x1000	/* Snapshot Isolation. */
850#define	TXN_SYNC		0x2000	/* Write and sync on prepare/commit. */
851#define	TXN_WRITE_NOSYNC	0x4000	/* Write only on prepare/commit. */
852	u_int32_t	flags;
853};
854
855#define	TXN_SYNC_FLAGS (TXN_SYNC | TXN_NOSYNC | TXN_WRITE_NOSYNC)
856
857/*
858 * Structure used for two phase commit interface.  Berkeley DB support for two
859 * phase commit is compatible with the X/Open XA interface.
860 *
861 * The XA #define XIDDATASIZE defines the size of a global transaction ID.  We
862 * have our own version here (for name space reasons) which must have the same
863 * value.
864 */
865#define	DB_XIDDATASIZE	128
866struct __db_preplist {
867	DB_TXN	*txn;
868	u_int8_t gid[DB_XIDDATASIZE];
869};
870
871/* Transaction statistics structure. */
872struct __db_txn_active {
873	u_int32_t txnid;		/* Transaction ID */
874	u_int32_t parentid;		/* Transaction ID of parent */
875	pid_t     pid;			/* Process owning txn ID */
876	db_threadid_t tid;		/* Thread owning txn ID */
877
878	DB_LSN	  lsn;			/* LSN when transaction began */
879
880	DB_LSN	  read_lsn;		/* Read LSN for MVCC */
881	u_int32_t mvcc_ref;		/* MVCC reference count */
882
883#define	TXN_ABORTED		1
884#define	TXN_COMMITTED		2
885#define	TXN_PREPARED		3
886#define	TXN_RUNNING		4
887	u_int32_t status;		/* Status of the transaction */
888
889#define	TXN_XA_ABORTED		1
890#define	TXN_XA_DEADLOCKED	2
891#define	TXN_XA_ENDED		3
892#define	TXN_XA_PREPARED		4
893#define	TXN_XA_STARTED		5
894#define	TXN_XA_SUSPENDED	6
895	u_int32_t xa_status;		/* XA status */
896
897	u_int8_t  xid[DB_XIDDATASIZE];	/* Global transaction ID */
898	char	  name[51];		/* 50 bytes of name, nul termination */
899};
900
901struct __db_txn_stat {
902	u_int32_t st_nrestores;		/* number of restored transactions
903					   after recovery. */
904#ifndef __TEST_DB_NO_STATISTICS
905	DB_LSN	  st_last_ckp;		/* lsn of the last checkpoint */
906	time_t	  st_time_ckp;		/* time of last checkpoint */
907	u_int32_t st_last_txnid;	/* last transaction id given out */
908	u_int32_t st_maxtxns;		/* maximum txns possible */
909	u_int32_t st_naborts;		/* number of aborted transactions */
910	u_int32_t st_nbegins;		/* number of begun transactions */
911	u_int32_t st_ncommits;		/* number of committed transactions */
912	u_int32_t st_nactive;		/* number of active transactions */
913	u_int32_t st_nsnapshot;		/* number of snapshot transactions */
914	u_int32_t st_maxnactive;	/* maximum active transactions */
915	u_int32_t st_maxnsnapshot;	/* maximum snapshot transactions */
916	DB_TXN_ACTIVE *st_txnarray;	/* array of active transactions */
917	u_int32_t st_region_wait;	/* Region lock granted after wait. */
918	u_int32_t st_region_nowait;	/* Region lock granted without wait. */
919	roff_t	  st_regsize;		/* Region size. */
920#endif
921};
922
923/*******************************************************
924 * Replication.
925 *******************************************************/
926/* Special, out-of-band environment IDs. */
927#define	DB_EID_BROADCAST	-1
928#define	DB_EID_INVALID		-2
929
930#define	DB_REP_DEFAULT_PRIORITY		100
931
932/* Acknowledgement policies. */
933#define	DB_REPMGR_ACKS_ALL		1
934#define	DB_REPMGR_ACKS_ALL_PEERS	2
935#define	DB_REPMGR_ACKS_NONE		3
936#define	DB_REPMGR_ACKS_ONE		4
937#define	DB_REPMGR_ACKS_ONE_PEER		5
938#define	DB_REPMGR_ACKS_QUORUM		6
939
940/* Replication timeout configuration values. */
941#define	DB_REP_ACK_TIMEOUT		1	/* RepMgr acknowledgements. */
942#define	DB_REP_CHECKPOINT_DELAY		2	/* Master checkpoint delay. */
943#define	DB_REP_CONNECTION_RETRY		3	/* RepMgr connections. */
944#define	DB_REP_ELECTION_RETRY		4	/* RepMgr elect retries. */
945#define	DB_REP_ELECTION_TIMEOUT		5	/* Rep normal elections. */
946#define	DB_REP_FULL_ELECTION_TIMEOUT	6	/* Rep full elections. */
947#define	DB_REP_HEARTBEAT_MONITOR	7	/* RepMgr client HB monitor. */
948#define	DB_REP_HEARTBEAT_SEND		8	/* RepMgr master send freq. */
949#define	DB_REP_LEASE_TIMEOUT		9	/* Master leases. */
950
951/* Event notification types. */
952#define	DB_EVENT_NO_SUCH_EVENT		0 /* out-of-band sentinel value */
953#define	DB_EVENT_PANIC			1
954#define	DB_EVENT_REP_CLIENT		2
955#define	DB_EVENT_REP_ELECTED		3
956#define	DB_EVENT_REP_MASTER		4
957#define	DB_EVENT_REP_NEWMASTER		5
958#define	DB_EVENT_REP_PERM_FAILED	6
959#define	DB_EVENT_REP_STARTUPDONE	7
960#define	DB_EVENT_WRITE_FAILED		8
961
962/* Replication Manager site status. */
963struct __db_repmgr_site {
964	int eid;
965	char *host;
966	u_int port;
967
968#define	DB_REPMGR_CONNECTED	0x01
969#define	DB_REPMGR_DISCONNECTED	0x02
970	u_int32_t status;
971};
972
973/* Replication statistics. */
974struct __db_rep_stat {
975	/* !!!
976	 * Many replication statistics fields cannot be protected by a mutex
977	 * without an unacceptable performance penalty, since most message
978	 * processing is done without the need to hold a region-wide lock.
979	 * Fields whose comments end with a '+' may be updated without holding
980	 * the replication or log mutexes (as appropriate), and thus may be
981	 * off somewhat (or, on unreasonable architectures under unlucky
982	 * circumstances, garbaged).
983	 */
984	u_int32_t st_log_queued;	/* Log records currently queued.+ */
985	u_int32_t st_startup_complete;	/* Site completed client sync-up. */
986#ifndef __TEST_DB_NO_STATISTICS
987	u_int32_t st_status;		/* Current replication status. */
988	DB_LSN st_next_lsn;		/* Next LSN to use or expect. */
989	DB_LSN st_waiting_lsn;		/* LSN we're awaiting, if any. */
990	DB_LSN st_max_perm_lsn;		/* Maximum permanent LSN. */
991	db_pgno_t st_next_pg;		/* Next pg we expect. */
992	db_pgno_t st_waiting_pg;	/* pg we're awaiting, if any. */
993
994	u_int32_t st_dupmasters;	/* # of times a duplicate master
995					   condition was detected.+ */
996	int st_env_id;			/* Current environment ID. */
997	u_int32_t st_env_priority;	/* Current environment priority. */
998	u_int32_t st_bulk_fills;	/* Bulk buffer fills. */
999	u_int32_t st_bulk_overflows;	/* Bulk buffer overflows. */
1000	u_int32_t st_bulk_records;	/* Bulk records stored. */
1001	u_int32_t st_bulk_transfers;	/* Transfers of bulk buffers. */
1002	u_int32_t st_client_rerequests;	/* Number of forced rerequests. */
1003	u_int32_t st_client_svc_req;	/* Number of client service requests
1004					   received by this client. */
1005	u_int32_t st_client_svc_miss;	/* Number of client service requests
1006					   missing on this client. */
1007	u_int32_t st_gen;		/* Current generation number. */
1008	u_int32_t st_egen;		/* Current election gen number. */
1009	u_int32_t st_log_duplicated;	/* Log records received multiply.+ */
1010	u_int32_t st_log_queued_max;	/* Max. log records queued at once.+ */
1011	u_int32_t st_log_queued_total;	/* Total # of log recs. ever queued.+ */
1012	u_int32_t st_log_records;	/* Log records received and put.+ */
1013	u_int32_t st_log_requested;	/* Log recs. missed and requested.+ */
1014	int st_master;			/* Env. ID of the current master. */
1015	u_int32_t st_master_changes;	/* # of times we've switched masters. */
1016	u_int32_t st_msgs_badgen;	/* Messages with a bad generation #.+ */
1017	u_int32_t st_msgs_processed;	/* Messages received and processed.+ */
1018	u_int32_t st_msgs_recover;	/* Messages ignored because this site
1019					   was a client in recovery.+ */
1020	u_int32_t st_msgs_send_failures;/* # of failed message sends.+ */
1021	u_int32_t st_msgs_sent;		/* # of successful message sends.+ */
1022	u_int32_t st_newsites;		/* # of NEWSITE msgs. received.+ */
1023	u_int32_t st_nsites;		/* Current number of sites we will
1024					   assume during elections. */
1025	u_int32_t st_nthrottles;	/* # of times we were throttled. */
1026	u_int32_t st_outdated;		/* # of times we detected and returned
1027					   an OUTDATED condition.+ */
1028	u_int32_t st_pg_duplicated;	/* Pages received multiply.+ */
1029	u_int32_t st_pg_records;	/* Pages received and stored.+ */
1030	u_int32_t st_pg_requested;	/* Pages missed and requested.+ */
1031	u_int32_t st_txns_applied;	/* # of transactions applied.+ */
1032	u_int32_t st_startsync_delayed;	/* # of STARTSYNC msgs delayed.+ */
1033
1034	/* Elections generally. */
1035	u_int32_t st_elections;		/* # of elections held.+ */
1036	u_int32_t st_elections_won;	/* # of elections won by this site.+ */
1037
1038	/* Statistics about an in-progress election. */
1039	int st_election_cur_winner;	/* Current front-runner. */
1040	u_int32_t st_election_gen;	/* Election generation number. */
1041	DB_LSN st_election_lsn;		/* Max. LSN of current winner. */
1042	u_int32_t st_election_nsites;	/* # of "registered voters". */
1043	u_int32_t st_election_nvotes;	/* # of "registered voters" needed. */
1044	u_int32_t st_election_priority;	/* Current election priority. */
1045	int st_election_status;		/* Current election status. */
1046	u_int32_t st_election_tiebreaker;/* Election tiebreaker value. */
1047	u_int32_t st_election_votes;	/* Votes received in this round. */
1048	u_int32_t st_election_sec;	/* Last election time seconds. */
1049	u_int32_t st_election_usec;	/* Last election time useconds. */
1050	u_int32_t st_max_lease_sec;	/* Maximum lease timestamp seconds. */
1051	u_int32_t st_max_lease_usec;	/* Maximum lease timestamp useconds. */
1052#endif
1053};
1054
1055/* Replication Manager statistics. */
1056struct __db_repmgr_stat {
1057	u_int32_t st_perm_failed;	/* # of insufficiently ack'ed msgs. */
1058	u_int32_t st_msgs_queued;	/* # msgs queued for network delay. */
1059	u_int32_t st_msgs_dropped;	/* # msgs discarded due to excessive
1060					   queue length. */
1061	u_int32_t st_connection_drop;	/* Existing connections dropped. */
1062	u_int32_t st_connect_fail;	/* Failed new connection attempts. */
1063};
1064
1065/*******************************************************
1066 * Sequences.
1067 *******************************************************/
1068/*
1069 * The storage record for a sequence.
1070 */
1071struct __db_seq_record {
1072	u_int32_t	seq_version;	/* Version size/number. */
1073	u_int32_t	flags;		/* DB_SEQ_XXX Flags. */
1074	db_seq_t	seq_value;	/* Current value. */
1075	db_seq_t	seq_max;	/* Max permitted. */
1076	db_seq_t	seq_min;	/* Min permitted. */
1077};
1078
1079/*
1080 * Handle for a sequence object.
1081 */
1082struct __db_sequence {
1083	DB		*seq_dbp;	/* DB handle for this sequence. */
1084	db_mutex_t	mtx_seq;	/* Mutex if sequence is threaded. */
1085	DB_SEQ_RECORD	*seq_rp;	/* Pointer to current data. */
1086	DB_SEQ_RECORD	seq_record;	/* Data from DB_SEQUENCE. */
1087	int32_t		seq_cache_size; /* Number of values cached. */
1088	db_seq_t	seq_last_value;	/* Last value cached. */
1089	DBT		seq_key;	/* DBT pointing to sequence key. */
1090	DBT		seq_data;	/* DBT pointing to seq_record. */
1091
1092	/* API-private structure: used by C++ and Java. */
1093	void		*api_internal;
1094
1095	/* DB_SEQUENCE PUBLIC HANDLE LIST BEGIN */
1096	int		(*close) __P((DB_SEQUENCE *, u_int32_t));
1097	int		(*get) __P((DB_SEQUENCE *,
1098			      DB_TXN *, int32_t, db_seq_t *, u_int32_t));
1099	int		(*get_cachesize) __P((DB_SEQUENCE *, int32_t *));
1100	int		(*get_db) __P((DB_SEQUENCE *, DB **));
1101	int		(*get_flags) __P((DB_SEQUENCE *, u_int32_t *));
1102	int		(*get_key) __P((DB_SEQUENCE *, DBT *));
1103	int		(*get_range) __P((DB_SEQUENCE *,
1104			     db_seq_t *, db_seq_t *));
1105	int		(*initial_value) __P((DB_SEQUENCE *, db_seq_t));
1106	int		(*open) __P((DB_SEQUENCE *,
1107			    DB_TXN *, DBT *, u_int32_t));
1108	int		(*remove) __P((DB_SEQUENCE *, DB_TXN *, u_int32_t));
1109	int		(*set_cachesize) __P((DB_SEQUENCE *, int32_t));
1110	int		(*set_flags) __P((DB_SEQUENCE *, u_int32_t));
1111	int		(*set_range) __P((DB_SEQUENCE *, db_seq_t, db_seq_t));
1112	int		(*stat) __P((DB_SEQUENCE *,
1113			    DB_SEQUENCE_STAT **, u_int32_t));
1114	int		(*stat_print) __P((DB_SEQUENCE *, u_int32_t));
1115	/* DB_SEQUENCE PUBLIC HANDLE LIST END */
1116};
1117
1118struct __db_seq_stat {
1119	u_int32_t st_wait;		/* Sequence lock granted w/o wait. */
1120	u_int32_t st_nowait;		/* Sequence lock granted after wait. */
1121	db_seq_t  st_current;		/* Current value in db. */
1122	db_seq_t  st_value;		/* Current cached value. */
1123	db_seq_t  st_last_value;	/* Last cached value. */
1124	db_seq_t  st_min;		/* Minimum value. */
1125	db_seq_t  st_max;		/* Maximum value. */
1126	int32_t   st_cache_size;	/* Cache size. */
1127	u_int32_t st_flags;		/* Flag value. */
1128};
1129
1130/*******************************************************
1131 * Access methods.
1132 *******************************************************/
1133typedef enum {
1134	DB_BTREE=1,
1135	DB_HASH=2,
1136	DB_RECNO=3,
1137	DB_QUEUE=4,
1138	DB_UNKNOWN=5			/* Figure it out on open. */
1139} DBTYPE;
1140
1141#define	DB_RENAMEMAGIC	0x030800	/* File has been renamed. */
1142
1143#define	DB_BTREEVERSION	9		/* Current btree version. */
1144#define	DB_BTREEOLDVER	8		/* Oldest btree version supported. */
1145#define	DB_BTREEMAGIC	0x053162
1146
1147#define	DB_HASHVERSION	9		/* Current hash version. */
1148#define	DB_HASHOLDVER	7		/* Oldest hash version supported. */
1149#define	DB_HASHMAGIC	0x061561
1150
1151#define	DB_QAMVERSION	4		/* Current queue version. */
1152#define	DB_QAMOLDVER	3		/* Oldest queue version supported. */
1153#define	DB_QAMMAGIC	0x042253
1154
1155#define	DB_SEQUENCE_VERSION 2		/* Current sequence version. */
1156#define	DB_SEQUENCE_OLDVER  1		/* Oldest sequence version supported. */
1157
1158/*
1159 * DB access method and cursor operation values.  Each value is an operation
1160 * code to which additional bit flags are added.
1161 */
1162#define	DB_AFTER		 1	/* Dbc.put */
1163#define	DB_APPEND		 2	/* Db.put */
1164#define	DB_BEFORE		 3	/* Dbc.put */
1165#define	DB_CONSUME		 4	/* Db.get */
1166#define	DB_CONSUME_WAIT		 5	/* Db.get */
1167#define	DB_CURRENT		 6	/* Dbc.get, Dbc.put, DbLogc.get */
1168#define	DB_FIRST		 7	/* Dbc.get, DbLogc->get */
1169#define	DB_GET_BOTH		 8	/* Db.get, Dbc.get */
1170#define	DB_GET_BOTHC		 9	/* Dbc.get (internal) */
1171#define	DB_GET_BOTH_RANGE	10	/* Db.get, Dbc.get */
1172#define	DB_GET_RECNO		11	/* Dbc.get */
1173#define	DB_JOIN_ITEM		12	/* Dbc.get; don't do primary lookup */
1174#define	DB_KEYFIRST		13	/* Dbc.put */
1175#define	DB_KEYLAST		14	/* Dbc.put */
1176#define	DB_LAST			15	/* Dbc.get, DbLogc->get */
1177#define	DB_NEXT			16	/* Dbc.get, DbLogc->get */
1178#define	DB_NEXT_DUP		17	/* Dbc.get */
1179#define	DB_NEXT_NODUP		18	/* Dbc.get */
1180#define	DB_NODUPDATA		19	/* Db.put, Dbc.put */
1181#define	DB_NOOVERWRITE		20	/* Db.put */
1182#define	DB_NOSYNC		21	/* Db.close */
1183#define	DB_POSITION		22	/* Dbc.dup */
1184#define	DB_PREV			23	/* Dbc.get, DbLogc->get */
1185#define	DB_PREV_DUP		24	/* Dbc.get */
1186#define	DB_PREV_NODUP		25	/* Dbc.get */
1187#define	DB_SET			26	/* Dbc.get, DbLogc->get */
1188#define	DB_SET_RANGE		27	/* Dbc.get */
1189#define	DB_SET_RECNO		28	/* Db.get, Dbc.get */
1190#define	DB_UPDATE_SECONDARY	29	/* Dbc.get, Dbc.del (internal) */
1191#define	DB_WRITECURSOR		30	/* Db.cursor */
1192#define	DB_WRITELOCK		31	/* Db.cursor (internal) */
1193
1194/* This has to change when the max opcode hits 255. */
1195#define	DB_OPFLAGS_MASK	0x000000ff	/* Mask for operations flags. */
1196
1197/*
1198 * DB (user visible) error return codes.
1199 *
1200 * !!!
1201 * We don't want our error returns to conflict with other packages where
1202 * possible, so pick a base error value that's hopefully not common.  We
1203 * document that we own the error name space from -30,800 to -30,999.
1204 */
1205/* DB (public) error return codes. */
1206#define	DB_BUFFER_SMALL		(-30999)/* User memory too small for return. */
1207#define	DB_DONOTINDEX		(-30998)/* "Null" return from 2ndary callbk. */
1208#define	DB_FOREIGN_CONFLICT	(-30997)/* A foreign db constraint triggered. */
1209#define	DB_KEYEMPTY		(-30996)/* Key/data deleted or never created. */
1210#define	DB_KEYEXIST		(-30995)/* The key/data pair already exists. */
1211#define	DB_LOCK_DEADLOCK	(-30994)/* Deadlock. */
1212#define	DB_LOCK_NOTGRANTED	(-30993)/* Lock unavailable. */
1213#define	DB_LOG_BUFFER_FULL	(-30992)/* In-memory log buffer full. */
1214#define	DB_NOSERVER		(-30991)/* Server panic return. */
1215#define	DB_NOSERVER_HOME	(-30990)/* Bad home sent to server. */
1216#define	DB_NOSERVER_ID		(-30989)/* Bad ID sent to server. */
1217#define	DB_NOTFOUND		(-30988)/* Key/data pair not found (EOF). */
1218#define	DB_OLD_VERSION		(-30987)/* Out-of-date version. */
1219#define	DB_PAGE_NOTFOUND	(-30986)/* Requested page not found. */
1220#define	DB_REP_DUPMASTER	(-30985)/* There are two masters. */
1221#define	DB_REP_HANDLE_DEAD	(-30984)/* Rolled back a commit. */
1222#define	DB_REP_HOLDELECTION	(-30983)/* Time to hold an election. */
1223#define	DB_REP_IGNORE		(-30982)/* This msg should be ignored.*/
1224#define	DB_REP_ISPERM		(-30981)/* Cached not written perm written.*/
1225#define	DB_REP_JOIN_FAILURE	(-30980)/* Unable to join replication group. */
1226#define	DB_REP_LEASE_EXPIRED	(-30979)/* Master lease has expired. */
1227#define	DB_REP_LOCKOUT		(-30978)/* API/Replication lockout now. */
1228#define	DB_REP_NEWSITE		(-30977)/* New site entered system. */
1229#define	DB_REP_NOTPERM		(-30976)/* Permanent log record not written. */
1230#define	DB_REP_UNAVAIL		(-30975)/* Site cannot currently be reached. */
1231#define	DB_RUNRECOVERY		(-30974)/* Panic return. */
1232#define	DB_SECONDARY_BAD	(-30973)/* Secondary index corrupt. */
1233#define	DB_VERIFY_BAD		(-30972)/* Verify failed; bad format. */
1234#define	DB_VERSION_MISMATCH	(-30971)/* Environment version mismatch. */
1235
1236
1237/* DB (private) error return codes. */
1238#define	DB_ALREADY_ABORTED	(-30899)
1239#define	DB_DELETED		(-30898)/* Recovery file marked deleted. */
1240#define	DB_EVENT_NOT_HANDLED	(-30897)/* Forward event to application. */
1241#define	DB_NEEDSPLIT		(-30896)/* Page needs to be split. */
1242#define	DB_REP_BULKOVF		(-30895)/* Rep bulk buffer overflow. */
1243#define	DB_REP_EGENCHG		(-30894)/* Egen changed while in election. */
1244#define	DB_REP_LOGREADY		(-30893)/* Rep log ready for recovery. */
1245#define	DB_REP_NEWMASTER	(-30892)/* We have learned of a new master. */
1246#define	DB_REP_PAGEDONE		(-30891)/* This page was already done. */
1247#define	DB_SURPRISE_KID		(-30890)/* Child commit where parent
1248					   didn't know it was a parent. */
1249#define	DB_SWAPBYTES		(-30889)/* Database needs byte swapping. */
1250#define	DB_TIMEOUT		(-30888)/* Timed out waiting for election. */
1251#define	DB_TXN_CKP		(-30887)/* Encountered ckp record in log. */
1252#define	DB_VERIFY_FATAL		(-30886)/* DB->verify cannot proceed. */
1253
1254/* Database handle. */
1255struct __db {
1256	/*******************************************************
1257	 * Public: owned by the application.
1258	 *******************************************************/
1259	u_int32_t pgsize;		/* Database logical page size. */
1260	DB_CACHE_PRIORITY priority;	/* Database priority in cache. */
1261
1262					/* Callbacks. */
1263	int (*db_append_recno) __P((DB *, DBT *, db_recno_t));
1264	void (*db_feedback) __P((DB *, int, int));
1265	int (*dup_compare) __P((DB *, const DBT *, const DBT *));
1266
1267	void	*app_private;		/* Application-private handle. */
1268
1269	/*******************************************************
1270	 * Private: owned by DB.
1271	 *******************************************************/
1272	DB_ENV	*dbenv;			/* Backing public environment. */
1273	ENV	*env;			/* Backing private environment. */
1274
1275	DBTYPE	 type;			/* DB access method type. */
1276
1277	DB_MPOOLFILE *mpf;		/* Backing buffer pool. */
1278
1279	db_mutex_t mutex;		/* Synchronization for free threading */
1280
1281	char *fname, *dname;		/* File/database passed to DB->open. */
1282	u_int32_t open_flags;		/* Flags passed to DB->open. */
1283
1284	u_int8_t fileid[DB_FILE_ID_LEN];/* File's unique ID for locking. */
1285
1286	u_int32_t adj_fileid;		/* File's unique ID for curs. adj. */
1287
1288#define	DB_LOGFILEID_INVALID	-1
1289	FNAME *log_filename;		/* File's naming info for logging. */
1290
1291	db_pgno_t meta_pgno;		/* Meta page number */
1292	DB_LOCKER *locker;		/* Locker for handle locking. */
1293	DB_LOCKER *cur_locker;		/* Current handle lock holder. */
1294	DB_TXN *cur_txn;		/* Opening transaction. */
1295	DB_LOCKER *associate_locker;	/* Locker for DB->associate call. */
1296	DB_LOCK	 handle_lock;		/* Lock held on this handle. */
1297
1298	u_int	 cl_id;			/* RPC: remote client id. */
1299
1300	time_t	 timestamp;		/* Handle timestamp for replication. */
1301	u_int32_t fid_gen;		/* Rep generation number for fids. */
1302
1303	/*
1304	 * Returned data memory for DB->get() and friends.
1305	 */
1306	DBT	 my_rskey;		/* Secondary key. */
1307	DBT	 my_rkey;		/* [Primary] key. */
1308	DBT	 my_rdata;		/* Data. */
1309
1310	/*
1311	 * !!!
1312	 * Some applications use DB but implement their own locking outside of
1313	 * DB.  If they're using fcntl(2) locking on the underlying database
1314	 * file, and we open and close a file descriptor for that file, we will
1315	 * discard their locks.  The DB_FCNTL_LOCKING flag to DB->open is an
1316	 * undocumented interface to support this usage which leaves any file
1317	 * descriptors we open until DB->close.  This will only work with the
1318	 * DB->open interface and simple caches, e.g., creating a transaction
1319	 * thread may open/close file descriptors this flag doesn't protect.
1320	 * Locking with fcntl(2) on a file that you don't own is a very, very
1321	 * unsafe thing to do.  'Nuff said.
1322	 */
1323	DB_FH	*saved_open_fhp;	/* Saved file handle. */
1324
1325	/*
1326	 * Linked list of DBP's, linked from the ENV, used to keep track
1327	 * of all open db handles for cursor adjustment.
1328	 *
1329	 * !!!
1330	 * Explicit representations of structures from queue.h.
1331	 * TAILQ_ENTRY(__db) dblistlinks;
1332	 */
1333	struct {
1334		struct __db *tqe_next;
1335		struct __db **tqe_prev;
1336	} dblistlinks;
1337
1338	/*
1339	 * Cursor queues.
1340	 *
1341	 * !!!
1342	 * Explicit representations of structures from queue.h.
1343	 * TAILQ_HEAD(__cq_fq, __dbc) free_queue;
1344	 * TAILQ_HEAD(__cq_aq, __dbc) active_queue;
1345	 * TAILQ_HEAD(__cq_jq, __dbc) join_queue;
1346	 */
1347	struct __cq_fq {
1348		struct __dbc *tqh_first;
1349		struct __dbc **tqh_last;
1350	} free_queue;
1351	struct __cq_aq {
1352		struct __dbc *tqh_first;
1353		struct __dbc **tqh_last;
1354	} active_queue;
1355	struct __cq_jq {
1356		struct __dbc *tqh_first;
1357		struct __dbc **tqh_last;
1358	} join_queue;
1359
1360	/*
1361	 * Secondary index support.
1362	 *
1363	 * Linked list of secondary indices -- set in the primary.
1364	 *
1365	 * !!!
1366	 * Explicit representations of structures from queue.h.
1367	 * LIST_HEAD(s_secondaries, __db);
1368	 */
1369	struct {
1370		struct __db *lh_first;
1371	} s_secondaries;
1372
1373	/*
1374	 * List entries for secondaries, and reference count of how many
1375	 * threads are updating this secondary (see Dbc.put).
1376	 *
1377	 * !!!
1378	 * Note that these are synchronized by the primary's mutex, but
1379	 * filled in in the secondaries.
1380	 *
1381	 * !!!
1382	 * Explicit representations of structures from queue.h.
1383	 * LIST_ENTRY(__db) s_links;
1384	 */
1385	struct {
1386		struct __db *le_next;
1387		struct __db **le_prev;
1388	} s_links;
1389	u_int32_t s_refcnt;
1390
1391	/* Secondary callback and free functions -- set in the secondary. */
1392	int	(*s_callback) __P((DB *, const DBT *, const DBT *, DBT *));
1393
1394	/* Reference to primary -- set in the secondary. */
1395	DB	*s_primary;
1396
1397#define	DB_ASSOC_IMMUTABLE_KEY    0x00000001 /* Secondary key is immutable. */
1398
1399	/* Flags passed to associate -- set in the secondary. */
1400	u_int32_t s_assoc_flags;
1401
1402	/*
1403	 * Foreign key support.
1404	 *
1405	 * Linked list of primary dbs -- set in the foreign db
1406	 *
1407	 * !!!
1408	 * Explicit representations of structures from queue.h.
1409	 * LIST_HEAD(f_primaries, __db);
1410	 */
1411	struct {
1412		struct __db_foreign_info *lh_first;
1413	} f_primaries;
1414
1415	/* Reference to foreign -- set in the secondary. */
1416	DB      *s_foreign;
1417
1418	/* API-private structure: used by DB 1.85, C++, Java, Perl and Tcl */
1419	void	*api_internal;
1420
1421	/* Subsystem-private structure. */
1422	void	*bt_internal;		/* Btree/Recno access method. */
1423	void	*h_internal;		/* Hash access method. */
1424	void	*q_internal;		/* Queue access method. */
1425	void	*xa_internal;		/* XA. */
1426
1427	/* DB PUBLIC HANDLE LIST BEGIN */
1428	int  (*associate) __P((DB *, DB_TXN *, DB *,
1429		int (*)(DB *, const DBT *, const DBT *, DBT *), u_int32_t));
1430	int  (*associate_foreign) __P((DB *, DB *,
1431		int (*)(DB *, const DBT *, DBT *, const DBT *, int *),
1432		u_int32_t));
1433	int  (*close) __P((DB *, u_int32_t));
1434	int  (*compact) __P((DB *,
1435		DB_TXN *, DBT *, DBT *, DB_COMPACT *, u_int32_t, DBT *));
1436	int  (*cursor) __P((DB *, DB_TXN *, DBC **, u_int32_t));
1437	int  (*del) __P((DB *, DB_TXN *, DBT *, u_int32_t));
1438	void (*err) __P((DB *, int, const char *, ...));
1439	void (*errx) __P((DB *, const char *, ...));
1440	int  (*exists) __P((DB *, DB_TXN *, DBT *, u_int32_t));
1441	int  (*fd) __P((DB *, int *));
1442	int  (*get) __P((DB *, DB_TXN *, DBT *, DBT *, u_int32_t));
1443	int  (*get_bt_minkey) __P((DB *, u_int32_t *));
1444	int  (*get_byteswapped) __P((DB *, int *));
1445	int  (*get_cachesize) __P((DB *, u_int32_t *, u_int32_t *, int *));
1446	int  (*get_dbname) __P((DB *, const char **, const char **));
1447	int  (*get_encrypt_flags) __P((DB *, u_int32_t *));
1448	DB_ENV *(*get_env) __P((DB *));
1449	void (*get_errcall) __P((DB *,
1450		void (**)(const DB_ENV *, const char *, const char *)));
1451	void (*get_errfile) __P((DB *, FILE **));
1452	void (*get_errpfx) __P((DB *, const char **));
1453	int  (*get_flags) __P((DB *, u_int32_t *));
1454	int  (*get_h_ffactor) __P((DB *, u_int32_t *));
1455	int  (*get_h_nelem) __P((DB *, u_int32_t *));
1456	int  (*get_lorder) __P((DB *, int *));
1457	DB_MPOOLFILE *(*get_mpf) __P((DB *));
1458	void (*get_msgfile) __P((DB *, FILE **));
1459	int  (*get_multiple) __P((DB *));
1460	int  (*get_open_flags) __P((DB *, u_int32_t *));
1461	int  (*get_pagesize) __P((DB *, u_int32_t *));
1462	int  (*get_priority) __P((DB *, DB_CACHE_PRIORITY *));
1463	int  (*get_q_extentsize) __P((DB *, u_int32_t *));
1464	int  (*get_re_delim) __P((DB *, int *));
1465	int  (*get_re_len) __P((DB *, u_int32_t *));
1466	int  (*get_re_pad) __P((DB *, int *));
1467	int  (*get_re_source) __P((DB *, const char **));
1468	int  (*get_transactional) __P((DB *));
1469	int  (*get_type) __P((DB *, DBTYPE *));
1470	int  (*join) __P((DB *, DBC **, DBC **, u_int32_t));
1471	int  (*key_range)
1472		__P((DB *, DB_TXN *, DBT *, DB_KEY_RANGE *, u_int32_t));
1473	int  (*open) __P((DB *,
1474		DB_TXN *, const char *, const char *, DBTYPE, u_int32_t, int));
1475	int  (*pget) __P((DB *, DB_TXN *, DBT *, DBT *, DBT *, u_int32_t));
1476	int  (*put) __P((DB *, DB_TXN *, DBT *, DBT *, u_int32_t));
1477	int  (*remove) __P((DB *, const char *, const char *, u_int32_t));
1478	int  (*rename) __P((DB *,
1479		const char *, const char *, const char *, u_int32_t));
1480	int  (*set_alloc) __P((DB *, void *(*)(size_t),
1481		void *(*)(void *, size_t), void (*)(void *)));
1482	int  (*set_append_recno) __P((DB *, int (*)(DB *, DBT *, db_recno_t)));
1483	int  (*set_bt_compare)
1484		__P((DB *, int (*)(DB *, const DBT *, const DBT *)));
1485	int  (*set_bt_minkey) __P((DB *, u_int32_t));
1486	int  (*set_bt_prefix)
1487		__P((DB *, size_t (*)(DB *, const DBT *, const DBT *)));
1488	int  (*set_cachesize) __P((DB *, u_int32_t, u_int32_t, int));
1489	int  (*set_dup_compare)
1490		__P((DB *, int (*)(DB *, const DBT *, const DBT *)));
1491	int  (*set_encrypt) __P((DB *, const char *, u_int32_t));
1492	void (*set_errcall) __P((DB *,
1493		void (*)(const DB_ENV *, const char *, const char *)));
1494	void (*set_errfile) __P((DB *, FILE *));
1495	void (*set_errpfx) __P((DB *, const char *));
1496	int  (*set_feedback) __P((DB *, void (*)(DB *, int, int)));
1497	int  (*set_flags) __P((DB *, u_int32_t));
1498	int  (*set_h_compare)
1499		__P((DB *, int (*)(DB *, const DBT *, const DBT *)));
1500	int  (*set_h_ffactor) __P((DB *, u_int32_t));
1501	int  (*set_h_hash)
1502		__P((DB *, u_int32_t (*)(DB *, const void *, u_int32_t)));
1503	int  (*set_h_nelem) __P((DB *, u_int32_t));
1504	int  (*set_lorder) __P((DB *, int));
1505	void (*set_msgcall) __P((DB *, void (*)(const DB_ENV *, const char *)));
1506	void (*set_msgfile) __P((DB *, FILE *));
1507	int  (*set_pagesize) __P((DB *, u_int32_t));
1508	int  (*set_paniccall) __P((DB *, void (*)(DB_ENV *, int)));
1509	int  (*set_priority) __P((DB *, DB_CACHE_PRIORITY));
1510	int  (*set_q_extentsize) __P((DB *, u_int32_t));
1511	int  (*set_re_delim) __P((DB *, int));
1512	int  (*set_re_len) __P((DB *, u_int32_t));
1513	int  (*set_re_pad) __P((DB *, int));
1514	int  (*set_re_source) __P((DB *, const char *));
1515	int  (*stat) __P((DB *, DB_TXN *, void *, u_int32_t));
1516	int  (*stat_print) __P((DB *, u_int32_t));
1517	int  (*sync) __P((DB *, u_int32_t));
1518	int  (*truncate) __P((DB *, DB_TXN *, u_int32_t *, u_int32_t));
1519	int  (*upgrade) __P((DB *, const char *, u_int32_t));
1520	int  (*verify)
1521		__P((DB *, const char *, const char *, FILE *, u_int32_t));
1522	/* DB PUBLIC HANDLE LIST END */
1523
1524	/* DB PRIVATE HANDLE LIST BEGIN */
1525	int  (*dump) __P((DB *, const char *,
1526		int (*)(void *, const void *), void *, int, int));
1527	int  (*db_am_remove) __P((DB *, DB_TXN *, const char *, const char *));
1528	int  (*db_am_rename) __P((DB *, DB_TXN *,
1529	    const char *, const char *, const char *));
1530	/* DB PRIVATE HANDLE LIST END */
1531
1532	/*
1533	 * Never called; these are a place to save function pointers
1534	 * so that we can undo an associate.
1535	 */
1536	int  (*stored_get) __P((DB *, DB_TXN *, DBT *, DBT *, u_int32_t));
1537	int  (*stored_close) __P((DB *, u_int32_t));
1538
1539#define	DB_OK_BTREE	0x01
1540#define	DB_OK_HASH	0x02
1541#define	DB_OK_QUEUE	0x04
1542#define	DB_OK_RECNO	0x08
1543	u_int32_t	am_ok;		/* Legal AM choices. */
1544
1545	/*
1546	 * This field really ought to be an AM_FLAG, but we have
1547	 * have run out of bits.  If/when we decide to split up
1548	 * the flags, we can incorporate it.
1549	 */
1550	int	 preserve_fid;		/* Do not free fileid on close. */
1551
1552#define	DB_AM_CHKSUM		0x00000001 /* Checksumming */
1553#define	DB_AM_COMPENSATE	0x00000002 /* Created by compensating txn */
1554#define	DB_AM_CREATED		0x00000004 /* Database was created upon open */
1555#define	DB_AM_CREATED_MSTR	0x00000008 /* Encompassing file was created */
1556#define	DB_AM_DBM_ERROR		0x00000010 /* Error in DBM/NDBM database */
1557#define	DB_AM_DELIMITER		0x00000020 /* Variable length delimiter set */
1558#define	DB_AM_DISCARD		0x00000040 /* Discard any cached pages */
1559#define	DB_AM_DUP		0x00000080 /* DB_DUP */
1560#define	DB_AM_DUPSORT		0x00000100 /* DB_DUPSORT */
1561#define	DB_AM_ENCRYPT		0x00000200 /* Encryption */
1562#define	DB_AM_FIXEDLEN		0x00000400 /* Fixed-length records */
1563#define	DB_AM_INMEM		0x00000800 /* In-memory; no sync on close */
1564#define	DB_AM_INORDER		0x00001000 /* DB_INORDER */
1565#define	DB_AM_IN_RENAME		0x00002000 /* File is being renamed */
1566#define	DB_AM_NOT_DURABLE	0x00004000 /* Do not log changes */
1567#define	DB_AM_OPEN_CALLED	0x00008000 /* DB->open called */
1568#define	DB_AM_PAD		0x00010000 /* Fixed-length record pad */
1569#define	DB_AM_PGDEF		0x00020000 /* Page size was defaulted */
1570#define	DB_AM_RDONLY		0x00040000 /* Database is readonly */
1571#define	DB_AM_READ_UNCOMMITTED	0x00080000 /* Support degree 1 isolation */
1572#define	DB_AM_RECNUM		0x00100000 /* DB_RECNUM */
1573#define	DB_AM_RECOVER		0x00200000 /* DB opened by recovery routine */
1574#define	DB_AM_RENUMBER		0x00400000 /* DB_RENUMBER */
1575#define	DB_AM_REVSPLITOFF	0x00800000 /* DB_REVSPLITOFF */
1576#define	DB_AM_SECONDARY		0x01000000 /* Database is a secondary index */
1577#define	DB_AM_SNAPSHOT		0x02000000 /* DB_SNAPSHOT */
1578#define	DB_AM_SUBDB		0x04000000 /* Subdatabases supported */
1579#define	DB_AM_SWAP		0x08000000 /* Pages need to be byte-swapped */
1580#define	DB_AM_TXN		0x10000000 /* Opened in a transaction */
1581#define	DB_AM_VERIFYING		0x20000000 /* DB handle is in the verifier */
1582	u_int32_t orig_flags;		   /* Flags at  open, for refresh */
1583	u_int32_t flags;
1584};
1585
1586/*
1587 * Macros for bulk get.  These are only intended for the C API.
1588 * For C++, use DbMultiple*Iterator.
1589 */
1590#define	DB_MULTIPLE_INIT(pointer, dbt)					\
1591	(pointer = (u_int8_t *)(dbt)->data +				\
1592	    (dbt)->ulen - sizeof(u_int32_t))
1593#define	DB_MULTIPLE_NEXT(pointer, dbt, retdata, retdlen)		\
1594	do {								\
1595		if (*((u_int32_t *)(pointer)) == (u_int32_t)-1) {	\
1596			retdata = NULL;					\
1597			pointer = NULL;					\
1598			break;						\
1599		}							\
1600		retdata = (u_int8_t *)					\
1601		    (dbt)->data + *(u_int32_t *)(pointer);		\
1602		(pointer) = (u_int32_t *)(pointer) - 1;			\
1603		retdlen = *(u_int32_t *)(pointer);			\
1604		(pointer) = (u_int32_t *)(pointer) - 1;			\
1605		if (retdlen == 0 &&					\
1606		    retdata == (u_int8_t *)(dbt)->data)			\
1607			retdata = NULL;					\
1608	} while (0)
1609#define	DB_MULTIPLE_KEY_NEXT(pointer, dbt, retkey, retklen, retdata, retdlen) \
1610	do {								\
1611		if (*((u_int32_t *)(pointer)) == (u_int32_t)-1) {	\
1612			retdata = NULL;					\
1613			retkey = NULL;					\
1614			pointer = NULL;					\
1615			break;						\
1616		}							\
1617		retkey = (u_int8_t *)					\
1618		    (dbt)->data + *(u_int32_t *)(pointer);		\
1619		(pointer) = (u_int32_t *)(pointer) - 1;			\
1620		retklen = *(u_int32_t *)(pointer);			\
1621		(pointer) = (u_int32_t *)(pointer) - 1;			\
1622		retdata = (u_int8_t *)					\
1623		    (dbt)->data + *(u_int32_t *)(pointer);		\
1624		(pointer) = (u_int32_t *)(pointer) - 1;			\
1625		retdlen = *(u_int32_t *)(pointer);			\
1626		(pointer) = (u_int32_t *)(pointer) - 1;			\
1627	} while (0)
1628
1629#define	DB_MULTIPLE_RECNO_NEXT(pointer, dbt, recno, retdata, retdlen)   \
1630	do {								\
1631		if (*((u_int32_t *)(pointer)) == (u_int32_t)0) {	\
1632			recno = 0;					\
1633			retdata = NULL;					\
1634			pointer = NULL;					\
1635			break;						\
1636		}							\
1637		recno = *(u_int32_t *)(pointer);			\
1638		(pointer) = (u_int32_t *)(pointer) - 1;			\
1639		retdata = (u_int8_t *)					\
1640		    (dbt)->data + *(u_int32_t *)(pointer);		\
1641		(pointer) = (u_int32_t *)(pointer) - 1;			\
1642		retdlen = *(u_int32_t *)(pointer);			\
1643		(pointer) = (u_int32_t *)(pointer) - 1;			\
1644	} while (0)
1645
1646/*******************************************************
1647 * Access method cursors.
1648 *******************************************************/
1649struct __dbc {
1650	DB *dbp;			/* Backing database */
1651	DB_ENV *dbenv;			/* Backing environment */
1652	ENV *env;			/* Backing environment */
1653
1654	DB_THREAD_INFO *thread_info;	/* Thread that owns this cursor. */
1655	DB_TXN	 *txn;			/* Associated transaction. */
1656	DB_CACHE_PRIORITY priority;	/* Priority in cache. */
1657
1658	/*
1659	 * Active/free cursor queues.
1660	 *
1661	 * !!!
1662	 * Explicit representations of structures from queue.h.
1663	 * TAILQ_ENTRY(__dbc) links;
1664	 */
1665	struct {
1666		DBC *tqe_next;
1667		DBC **tqe_prev;
1668	} links;
1669
1670	/*
1671	 * The DBT *'s below are used by the cursor routines to return
1672	 * data to the user when DBT flags indicate that DB should manage
1673	 * the returned memory.  They point at a DBT containing the buffer
1674	 * and length that will be used, and "belonging" to the handle that
1675	 * should "own" this memory.  This may be a "my_*" field of this
1676	 * cursor--the default--or it may be the corresponding field of
1677	 * another cursor, a DB handle, a join cursor, etc.  In general, it
1678	 * will be whatever handle the user originally used for the current
1679	 * DB interface call.
1680	 */
1681	DBT	 *rskey;		/* Returned secondary key. */
1682	DBT	 *rkey;			/* Returned [primary] key. */
1683	DBT	 *rdata;		/* Returned data. */
1684
1685	DBT	  my_rskey;		/* Space for returned secondary key. */
1686	DBT	  my_rkey;		/* Space for returned [primary] key. */
1687	DBT	  my_rdata;		/* Space for returned data. */
1688
1689	DB_LOCKER *lref;		/* Reference to default locker. */
1690	DB_LOCKER *locker;		/* Locker for this operation. */
1691	DBT	  lock_dbt;		/* DBT referencing lock. */
1692	DB_LOCK_ILOCK lock;		/* Object to be locked. */
1693	DB_LOCK	  mylock;		/* CDB lock held on this cursor. */
1694
1695	u_int	  cl_id;		/* Remote client id. */
1696
1697	DBTYPE	  dbtype;		/* Cursor type. */
1698
1699	DBC_INTERNAL *internal;		/* Access method private. */
1700
1701	/* DBC PUBLIC HANDLE LIST BEGIN */
1702	int (*close) __P((DBC *));
1703	int (*count) __P((DBC *, db_recno_t *, u_int32_t));
1704	int (*del) __P((DBC *, u_int32_t));
1705	int (*dup) __P((DBC *, DBC **, u_int32_t));
1706	int (*get) __P((DBC *, DBT *, DBT *, u_int32_t));
1707	int (*get_priority) __P((DBC *, DB_CACHE_PRIORITY *));
1708	int (*pget) __P((DBC *, DBT *, DBT *, DBT *, u_int32_t));
1709	int (*put) __P((DBC *, DBT *, DBT *, u_int32_t));
1710	int (*set_priority) __P((DBC *, DB_CACHE_PRIORITY));
1711	/* DBC PUBLIC HANDLE LIST END */
1712
1713	/* The following are the method names deprecated in the 4.6 release. */
1714	int (*c_close) __P((DBC *));
1715	int (*c_count) __P((DBC *, db_recno_t *, u_int32_t));
1716	int (*c_del) __P((DBC *, u_int32_t));
1717	int (*c_dup) __P((DBC *, DBC **, u_int32_t));
1718	int (*c_get) __P((DBC *, DBT *, DBT *, u_int32_t));
1719	int (*c_pget) __P((DBC *, DBT *, DBT *, DBT *, u_int32_t));
1720	int (*c_put) __P((DBC *, DBT *, DBT *, u_int32_t));
1721
1722	/* DBC PRIVATE HANDLE LIST BEGIN */
1723	int (*am_bulk) __P((DBC *, DBT *, u_int32_t));
1724	int (*am_close) __P((DBC *, db_pgno_t, int *));
1725	int (*am_del) __P((DBC *));
1726	int (*am_destroy) __P((DBC *));
1727	int (*am_get) __P((DBC *, DBT *, DBT *, u_int32_t, db_pgno_t *));
1728	int (*am_put) __P((DBC *, DBT *, DBT *, u_int32_t, db_pgno_t *));
1729	int (*am_writelock) __P((DBC *));
1730	/* DBC PRIVATE HANDLE LIST END */
1731
1732/*
1733 * DBC_DONTLOCK and DBC_RECOVER are used during recovery and transaction
1734 * abort.  If a transaction is being aborted or recovered then DBC_RECOVER
1735 * will be set and locking and logging will be disabled on this cursor.  If
1736 * we are performing a compensating transaction (e.g. free page processing)
1737 * then DB_DONTLOCK will be set to inhibit locking, but logging will still
1738 * be required. DB_DONTLOCK is also used if the whole database is locked.
1739 */
1740#define	DBC_ACTIVE		0x0001	/* Cursor in use. */
1741#define	DBC_DONTLOCK		0x0002	/* Don't lock on this cursor. */
1742#define	DBC_DUPLICATE		0x0004	/* Create a duplicate cursor. */
1743#define	DBC_MULTIPLE		0x0008	/* Return Multiple data. */
1744#define	DBC_MULTIPLE_KEY	0x0010	/* Return Multiple keys and data. */
1745#define	DBC_OPD			0x0020	/* Cursor references off-page dups. */
1746#define	DBC_OWN_LID		0x0040	/* Free lock id on destroy. */
1747#define	DBC_READ_COMMITTED	0x0080	/* Cursor has degree 2 isolation. */
1748#define	DBC_READ_UNCOMMITTED	0x0100	/* Cursor has degree 1 isolation. */
1749#define	DBC_RECOVER		0x0200	/* Recovery cursor; don't log/lock. */
1750#define	DBC_RMW			0x0400	/* Acquire write flag in read op. */
1751#define	DBC_TRANSIENT		0x0800	/* Cursor is transient. */
1752#define	DBC_WRITECURSOR		0x1000	/* Cursor may be used to write (CDB). */
1753#define	DBC_WRITER		0x2000	/* Cursor immediately writing (CDB). */
1754	u_int32_t flags;
1755};
1756
1757/* Key range statistics structure */
1758struct __key_range {
1759	double less;
1760	double equal;
1761	double greater;
1762};
1763
1764/* Btree/Recno statistics structure. */
1765struct __db_bt_stat {
1766	u_int32_t bt_magic;		/* Magic number. */
1767	u_int32_t bt_version;		/* Version number. */
1768	u_int32_t bt_metaflags;		/* Metadata flags. */
1769	u_int32_t bt_nkeys;		/* Number of unique keys. */
1770	u_int32_t bt_ndata;		/* Number of data items. */
1771	u_int32_t bt_pagecnt;		/* Page count. */
1772	u_int32_t bt_pagesize;		/* Page size. */
1773	u_int32_t bt_minkey;		/* Minkey value. */
1774	u_int32_t bt_re_len;		/* Fixed-length record length. */
1775	u_int32_t bt_re_pad;		/* Fixed-length record pad. */
1776	u_int32_t bt_levels;		/* Tree levels. */
1777	u_int32_t bt_int_pg;		/* Internal pages. */
1778	u_int32_t bt_leaf_pg;		/* Leaf pages. */
1779	u_int32_t bt_dup_pg;		/* Duplicate pages. */
1780	u_int32_t bt_over_pg;		/* Overflow pages. */
1781	u_int32_t bt_empty_pg;		/* Empty pages. */
1782	u_int32_t bt_free;		/* Pages on the free list. */
1783	u_int32_t bt_int_pgfree;	/* Bytes free in internal pages. */
1784	u_int32_t bt_leaf_pgfree;	/* Bytes free in leaf pages. */
1785	u_int32_t bt_dup_pgfree;	/* Bytes free in duplicate pages. */
1786	u_int32_t bt_over_pgfree;	/* Bytes free in overflow pages. */
1787};
1788
1789struct __db_compact {
1790	/* Input Parameters. */
1791	u_int32_t	compact_fillpercent;	/* Desired fillfactor: 1-100 */
1792	db_timeout_t	compact_timeout;	/* Lock timeout. */
1793	u_int32_t	compact_pages;		/* Max pages to process. */
1794	/* Output Stats. */
1795	u_int32_t	compact_pages_free;	/* Number of pages freed. */
1796	u_int32_t	compact_pages_examine;	/* Number of pages examine. */
1797	u_int32_t	compact_levels;		/* Number of levels removed. */
1798	u_int32_t	compact_deadlock;	/* Number of deadlocks. */
1799	db_pgno_t	compact_pages_truncated; /* Pages truncated to OS. */
1800	/* Internal. */
1801	db_pgno_t	compact_truncate;	/* Page number for truncation */
1802};
1803
1804/* Hash statistics structure. */
1805struct __db_h_stat {
1806	u_int32_t hash_magic;		/* Magic number. */
1807	u_int32_t hash_version;		/* Version number. */
1808	u_int32_t hash_metaflags;	/* Metadata flags. */
1809	u_int32_t hash_nkeys;		/* Number of unique keys. */
1810	u_int32_t hash_ndata;		/* Number of data items. */
1811	u_int32_t hash_pagecnt;		/* Page count. */
1812	u_int32_t hash_pagesize;	/* Page size. */
1813	u_int32_t hash_ffactor;		/* Fill factor specified at create. */
1814	u_int32_t hash_buckets;		/* Number of hash buckets. */
1815	u_int32_t hash_free;		/* Pages on the free list. */
1816	u_int32_t hash_bfree;		/* Bytes free on bucket pages. */
1817	u_int32_t hash_bigpages;	/* Number of big key/data pages. */
1818	u_int32_t hash_big_bfree;	/* Bytes free on big item pages. */
1819	u_int32_t hash_overflows;	/* Number of overflow pages. */
1820	u_int32_t hash_ovfl_free;	/* Bytes free on ovfl pages. */
1821	u_int32_t hash_dup;		/* Number of dup pages. */
1822	u_int32_t hash_dup_free;	/* Bytes free on duplicate pages. */
1823};
1824
1825/* Queue statistics structure. */
1826struct __db_qam_stat {
1827	u_int32_t qs_magic;		/* Magic number. */
1828	u_int32_t qs_version;		/* Version number. */
1829	u_int32_t qs_metaflags;		/* Metadata flags. */
1830	u_int32_t qs_nkeys;		/* Number of unique keys. */
1831	u_int32_t qs_ndata;		/* Number of data items. */
1832	u_int32_t qs_pagesize;		/* Page size. */
1833	u_int32_t qs_extentsize;	/* Pages per extent. */
1834	u_int32_t qs_pages;		/* Data pages. */
1835	u_int32_t qs_re_len;		/* Fixed-length record length. */
1836	u_int32_t qs_re_pad;		/* Fixed-length record pad. */
1837	u_int32_t qs_pgfree;		/* Bytes free in data pages. */
1838	u_int32_t qs_first_recno;	/* First not deleted record. */
1839	u_int32_t qs_cur_recno;		/* Next available record number. */
1840};
1841
1842/*******************************************************
1843 * Environment.
1844 *******************************************************/
1845#define	DB_REGION_MAGIC	0x120897	/* Environment magic number. */
1846
1847/*
1848 * Database environment structure.
1849 *
1850 * This is the public database environment handle.  The private environment
1851 * handle is the ENV structure.   The user owns this structure, the library
1852 * owns the ENV structure.  The reason there are two structures is because
1853 * the user's configuration outlives any particular DB_ENV->open call, and
1854 * separate structures allows us to easily discard internal information without
1855 * discarding the user's configuration.
1856 *
1857 * Fields in the DB_ENV structure should normally be set only by application
1858 * DB_ENV handle methods.
1859 */
1860struct __db_env {
1861	ENV *env;			/* Linked ENV structure */
1862
1863	/*
1864	 * The DB_ENV structure can be used concurrently, so field access is
1865	 * protected.
1866	 */
1867	db_mutex_t mtx_db_env;		/* DB_ENV structure mutex */
1868
1869					/* Error message callback */
1870	void (*db_errcall) __P((const DB_ENV *, const char *, const char *));
1871	FILE		*db_errfile;	/* Error message file stream */
1872	const char	*db_errpfx;	/* Error message prefix */
1873
1874					/* Other message callback */
1875	void (*db_msgcall) __P((const DB_ENV *, const char *));
1876	FILE		*db_msgfile;	/* Other message file stream */
1877
1878	/* Other application callback functions */
1879	int   (*app_dispatch) __P((DB_ENV *, DBT *, DB_LSN *, db_recops));
1880	void  (*db_event_func) __P((DB_ENV *, u_int32_t, void *));
1881	void  (*db_feedback) __P((DB_ENV *, int, int));
1882	void  (*db_free) __P((void *));
1883	void  (*db_paniccall) __P((DB_ENV *, int));
1884	void *(*db_malloc) __P((size_t));
1885	void *(*db_realloc) __P((void *, size_t));
1886	int   (*is_alive) __P((DB_ENV *, pid_t, db_threadid_t, u_int32_t));
1887	void  (*thread_id) __P((DB_ENV *, pid_t *, db_threadid_t *));
1888	char *(*thread_id_string) __P((DB_ENV *, pid_t, db_threadid_t, char *));
1889
1890	/* Application specified paths */
1891	char	*db_log_dir;		/* Database log file directory */
1892	char	*db_tmp_dir;		/* Database tmp file directory */
1893
1894	char   **db_data_dir;		/* Database data file directories */
1895	int	 data_cnt;		/* Database data file slots */
1896	int	 data_next;		/* Next database data file slot */
1897
1898	char	*intermediate_dir_mode;	/* Intermediate directory perms */
1899
1900	long	 shm_key;		/* shmget key */
1901
1902	char	*passwd;		/* Cryptography support */
1903	size_t	 passwd_len;
1904
1905	void	*cl_handle;		/* RPC: remote client handle */
1906	u_int	 cl_id;			/* RPC: remote client env id */
1907
1908	/* Private handle references */
1909	void	*app_private;		/* Application-private handle */
1910	void	*api1_internal;		/* C++, Perl API private */
1911	void	*api2_internal;		/* Java API private */
1912
1913	u_int32_t	verbose;	/* DB_VERB_XXX flags */
1914
1915	/* Mutex configuration */
1916	u_int32_t	mutex_align;	/* Mutex alignment */
1917	u_int32_t	mutex_cnt;	/* Number of mutexes to configure */
1918	u_int32_t	mutex_inc;	/* Number of mutexes to add */
1919	u_int32_t	mutex_tas_spins;/* Test-and-set spin count */
1920
1921	/* Locking configuration */
1922	u_int8_t       *lk_conflicts;	/* Two dimensional conflict matrix */
1923	int		lk_modes;	/* Number of lock modes in table */
1924	u_int32_t	lk_detect;	/* Deadlock detect on all conflicts */
1925	u_int32_t	lk_max;	/* Maximum number of locks */
1926	u_int32_t	lk_max_lockers;/* Maximum number of lockers */
1927	u_int32_t	lk_max_objects;/* Maximum number of locked objects */
1928	u_int32_t	lk_partitions ;/* Number of object partitions */
1929	db_timeout_t	lk_timeout;	/* Lock timeout period */
1930
1931	/* Logging configuration */
1932	u_int32_t	lg_bsize;	/* Buffer size */
1933	int		lg_filemode;	/* Log file permission mode */
1934	u_int32_t	lg_regionmax;	/* Region size */
1935	u_int32_t	lg_size;	/* Log file size */
1936	u_int32_t	lg_flags;	/* Log configuration */
1937
1938	/* Memory pool configuration */
1939	u_int32_t	mp_gbytes;	/* Cache size: GB */
1940	u_int32_t	mp_bytes;	/* Cache size: bytes */
1941	u_int32_t	mp_max_gbytes;	/* Maximum cache size: GB */
1942	u_int32_t	mp_max_bytes;	/* Maximum cache size: bytes */
1943	size_t		mp_mmapsize;	/* Maximum file size for mmap */
1944	int		mp_maxopenfd;	/* Maximum open file descriptors */
1945	int		mp_maxwrite;	/* Maximum buffers to write */
1946	u_int		mp_ncache;	/* Initial number of cache regions */
1947					/* Sleep after writing max buffers */
1948	db_timeout_t	mp_maxwrite_sleep;
1949
1950	/* Transaction configuration */
1951	u_int32_t	tx_max;		/* Maximum number of transactions */
1952	time_t		tx_timestamp;	/* Recover to specific timestamp */
1953	db_timeout_t	tx_timeout;	/* Timeout for transactions */
1954
1955	/* Thread tracking configuration */
1956	u_int32_t	thr_max;	/* Thread count */
1957
1958	/*
1959	 * The following fields are not strictly user-owned, but they outlive
1960	 * the ENV structure, and so are stored here.
1961	 */
1962	DB_FH		*registry;	/* DB_REGISTER file handle */
1963	u_int32_t	registry_off;	/*
1964					 * Offset of our slot.  We can't use
1965					 * off_t because its size depends on
1966					 * build settings.
1967					 */
1968
1969#define	DB_ENV_AUTO_COMMIT	0x00000001 /* DB_AUTO_COMMIT */
1970#define	DB_ENV_CDB_ALLDB	0x00000002 /* CDB environment wide locking */
1971#define	DB_ENV_DIRECT_DB	0x00000004 /* DB_DIRECT_DB set */
1972#define	DB_ENV_DSYNC_DB		0x00000008 /* DB_DSYNC_DB set */
1973#define	DB_ENV_MULTIVERSION	0x00000010 /* DB_MULTIVERSION set */
1974#define	DB_ENV_NOLOCKING	0x00000020 /* DB_NOLOCKING set */
1975#define	DB_ENV_NOMMAP		0x00000040 /* DB_NOMMAP set */
1976#define	DB_ENV_NOPANIC		0x00000080 /* Okay if panic set */
1977#define	DB_ENV_OVERWRITE	0x00000100 /* DB_OVERWRITE set */
1978#define	DB_ENV_REGION_INIT	0x00000200 /* DB_REGION_INIT set */
1979#define	DB_ENV_RPCCLIENT	0x00000400 /* DB_RPCCLIENT set */
1980#define	DB_ENV_RPCCLIENT_GIVEN	0x00000800 /* User-supplied RPC client struct */
1981#define	DB_ENV_TIME_NOTGRANTED	0x00001000 /* DB_TIME_NOTGRANTED set */
1982#define	DB_ENV_TXN_NOSYNC	0x00002000 /* DB_TXN_NOSYNC set */
1983#define	DB_ENV_TXN_NOWAIT	0x00004000 /* DB_TXN_NOWAIT set */
1984#define	DB_ENV_TXN_SNAPSHOT	0x00008000 /* DB_TXN_SNAPSHOT set */
1985#define	DB_ENV_TXN_WRITE_NOSYNC	0x00010000 /* DB_TXN_WRITE_NOSYNC set */
1986#define	DB_ENV_YIELDCPU		0x00020000 /* DB_YIELDCPU set */
1987	u_int32_t flags;
1988
1989	/* DB_ENV PUBLIC HANDLE LIST BEGIN */
1990	int  (*cdsgroup_begin) __P((DB_ENV *, DB_TXN **));
1991	int  (*close) __P((DB_ENV *, u_int32_t));
1992	int  (*dbremove) __P((DB_ENV *,
1993		DB_TXN *, const char *, const char *, u_int32_t));
1994	int  (*dbrename) __P((DB_ENV *,
1995		DB_TXN *, const char *, const char *, const char *, u_int32_t));
1996	void (*err) __P((const DB_ENV *, int, const char *, ...));
1997	void (*errx) __P((const DB_ENV *, const char *, ...));
1998	int  (*failchk) __P((DB_ENV *, u_int32_t));
1999	int  (*fileid_reset) __P((DB_ENV *, const char *, u_int32_t));
2000	int  (*get_cache_max) __P((DB_ENV *, u_int32_t *, u_int32_t *));
2001	int  (*get_cachesize) __P((DB_ENV *, u_int32_t *, u_int32_t *, int *));
2002	int  (*get_data_dirs) __P((DB_ENV *, const char ***));
2003	int  (*get_encrypt_flags) __P((DB_ENV *, u_int32_t *));
2004	void (*get_errcall) __P((DB_ENV *,
2005		void (**)(const DB_ENV *, const char *, const char *)));
2006	void (*get_errfile) __P((DB_ENV *, FILE **));
2007	void (*get_errpfx) __P((DB_ENV *, const char **));
2008	int  (*get_flags) __P((DB_ENV *, u_int32_t *));
2009	int  (*get_home) __P((DB_ENV *, const char **));
2010	int  (*get_intermediate_dir_mode) __P((DB_ENV *, const char **));
2011	int  (*get_lg_bsize) __P((DB_ENV *, u_int32_t *));
2012	int  (*get_lg_dir) __P((DB_ENV *, const char **));
2013	int  (*get_lg_filemode) __P((DB_ENV *, int *));
2014	int  (*get_lg_max) __P((DB_ENV *, u_int32_t *));
2015	int  (*get_lg_regionmax) __P((DB_ENV *, u_int32_t *));
2016	int  (*get_lk_conflicts) __P((DB_ENV *, const u_int8_t **, int *));
2017	int  (*get_lk_detect) __P((DB_ENV *, u_int32_t *));
2018	int  (*get_lk_max_lockers) __P((DB_ENV *, u_int32_t *));
2019	int  (*get_lk_max_locks) __P((DB_ENV *, u_int32_t *));
2020	int  (*get_lk_max_objects) __P((DB_ENV *, u_int32_t *));
2021	int  (*get_lk_partitions) __P((DB_ENV *, u_int32_t *));
2022	int  (*get_mp_max_openfd) __P((DB_ENV *, int *));
2023	int  (*get_mp_max_write) __P((DB_ENV *, int *, db_timeout_t *));
2024	int  (*get_mp_mmapsize) __P((DB_ENV *, size_t *));
2025	void (*get_msgfile) __P((DB_ENV *, FILE **));
2026	int  (*get_open_flags) __P((DB_ENV *, u_int32_t *));
2027	int  (*get_shm_key) __P((DB_ENV *, long *));
2028	int  (*get_thread_count) __P((DB_ENV *, u_int32_t *));
2029	int  (*get_timeout) __P((DB_ENV *, db_timeout_t *, u_int32_t));
2030	int  (*get_tmp_dir) __P((DB_ENV *, const char **));
2031	int  (*get_tx_max) __P((DB_ENV *, u_int32_t *));
2032	int  (*get_tx_timestamp) __P((DB_ENV *, time_t *));
2033	int  (*get_verbose) __P((DB_ENV *, u_int32_t, int *));
2034	int  (*is_bigendian) __P((void));
2035	int  (*lock_detect) __P((DB_ENV *, u_int32_t, u_int32_t, int *));
2036	int  (*lock_get) __P((DB_ENV *,
2037		u_int32_t, u_int32_t, const DBT *, db_lockmode_t, DB_LOCK *));
2038	int  (*lock_id) __P((DB_ENV *, u_int32_t *));
2039	int  (*lock_id_free) __P((DB_ENV *, u_int32_t));
2040	int  (*lock_put) __P((DB_ENV *, DB_LOCK *));
2041	int  (*lock_stat) __P((DB_ENV *, DB_LOCK_STAT **, u_int32_t));
2042	int  (*lock_stat_print) __P((DB_ENV *, u_int32_t));
2043	int  (*lock_vec) __P((DB_ENV *,
2044		u_int32_t, u_int32_t, DB_LOCKREQ *, int, DB_LOCKREQ **));
2045	int  (*log_archive) __P((DB_ENV *, char **[], u_int32_t));
2046	int  (*log_cursor) __P((DB_ENV *, DB_LOGC **, u_int32_t));
2047	int  (*log_file) __P((DB_ENV *, const DB_LSN *, char *, size_t));
2048	int  (*log_flush) __P((DB_ENV *, const DB_LSN *));
2049	int  (*log_get_config) __P((DB_ENV *, u_int32_t, int *));
2050	int  (*log_printf) __P((DB_ENV *, DB_TXN *, const char *, ...));
2051	int  (*log_put) __P((DB_ENV *, DB_LSN *, const DBT *, u_int32_t));
2052	int  (*log_set_config) __P((DB_ENV *, u_int32_t, int));
2053	int  (*log_stat) __P((DB_ENV *, DB_LOG_STAT **, u_int32_t));
2054	int  (*log_stat_print) __P((DB_ENV *, u_int32_t));
2055	int  (*lsn_reset) __P((DB_ENV *, const char *, u_int32_t));
2056	int  (*memp_fcreate) __P((DB_ENV *, DB_MPOOLFILE **, u_int32_t));
2057	int  (*memp_register) __P((DB_ENV *, int, int (*)(DB_ENV *, db_pgno_t,
2058		void *, DBT *), int (*)(DB_ENV *, db_pgno_t, void *, DBT *)));
2059	int  (*memp_stat) __P((DB_ENV *,
2060		DB_MPOOL_STAT **, DB_MPOOL_FSTAT ***, u_int32_t));
2061	int  (*memp_stat_print) __P((DB_ENV *, u_int32_t));
2062	int  (*memp_sync) __P((DB_ENV *, DB_LSN *));
2063	int  (*memp_trickle) __P((DB_ENV *, int, int *));
2064	int  (*mutex_alloc) __P((DB_ENV *, u_int32_t, db_mutex_t *));
2065	int  (*mutex_free) __P((DB_ENV *, db_mutex_t));
2066	int  (*mutex_get_align) __P((DB_ENV *, u_int32_t *));
2067	int  (*mutex_get_increment) __P((DB_ENV *, u_int32_t *));
2068	int  (*mutex_get_max) __P((DB_ENV *, u_int32_t *));
2069	int  (*mutex_get_tas_spins) __P((DB_ENV *, u_int32_t *));
2070	int  (*mutex_lock) __P((DB_ENV *, db_mutex_t));
2071	int  (*mutex_set_align) __P((DB_ENV *, u_int32_t));
2072	int  (*mutex_set_increment) __P((DB_ENV *, u_int32_t));
2073	int  (*mutex_set_max) __P((DB_ENV *, u_int32_t));
2074	int  (*mutex_set_tas_spins) __P((DB_ENV *, u_int32_t));
2075	int  (*mutex_stat) __P((DB_ENV *, DB_MUTEX_STAT **, u_int32_t));
2076	int  (*mutex_stat_print) __P((DB_ENV *, u_int32_t));
2077	int  (*mutex_unlock) __P((DB_ENV *, db_mutex_t));
2078	int  (*open) __P((DB_ENV *, const char *, u_int32_t, int));
2079	int  (*remove) __P((DB_ENV *, const char *, u_int32_t));
2080	int  (*rep_elect) __P((DB_ENV *, u_int32_t, u_int32_t, u_int32_t));
2081	int  (*rep_flush) __P((DB_ENV *));
2082	int  (*rep_get_clockskew) __P((DB_ENV *, u_int32_t *, u_int32_t *));
2083	int  (*rep_get_config) __P((DB_ENV *, u_int32_t, int *));
2084	int  (*rep_get_limit) __P((DB_ENV *, u_int32_t *, u_int32_t *));
2085	int  (*rep_get_nsites) __P((DB_ENV *, u_int32_t *));
2086	int  (*rep_get_priority) __P((DB_ENV *, u_int32_t *));
2087	int  (*rep_get_request) __P((DB_ENV *, u_int32_t *, u_int32_t *));
2088	int  (*rep_get_timeout) __P((DB_ENV *, int, u_int32_t *));
2089	int  (*rep_process_message)
2090		__P((DB_ENV *, DBT *, DBT *, int, DB_LSN *));
2091	int  (*rep_set_clockskew) __P((DB_ENV *, u_int32_t, u_int32_t));
2092	int  (*rep_set_config) __P((DB_ENV *, u_int32_t, int));
2093	int  (*rep_set_limit) __P((DB_ENV *, u_int32_t, u_int32_t));
2094	int  (*rep_set_nsites) __P((DB_ENV *, u_int32_t));
2095	int  (*rep_set_priority) __P((DB_ENV *, u_int32_t));
2096	int  (*rep_set_request) __P((DB_ENV *, u_int32_t, u_int32_t));
2097	int  (*rep_set_timeout) __P((DB_ENV *, int, db_timeout_t));
2098	int  (*rep_set_transport) __P((DB_ENV *, int, int (*)(DB_ENV *,
2099		const DBT *, const DBT *, const DB_LSN *, int, u_int32_t)));
2100	int  (*rep_start) __P((DB_ENV *, DBT *, u_int32_t));
2101	int  (*rep_stat) __P((DB_ENV *, DB_REP_STAT **, u_int32_t));
2102	int  (*rep_stat_print) __P((DB_ENV *, u_int32_t));
2103	int  (*rep_sync) __P((DB_ENV *, u_int32_t));
2104	int  (*repmgr_add_remote_site)
2105		__P((DB_ENV *, const char *, u_int, int *, u_int32_t));
2106	int  (*repmgr_get_ack_policy) __P((DB_ENV *, int *));
2107	int  (*repmgr_set_ack_policy) __P((DB_ENV *, int));
2108	int  (*repmgr_set_local_site)
2109		__P((DB_ENV *, const char *, u_int, u_int32_t));
2110	int  (*repmgr_site_list)
2111		__P((DB_ENV *, u_int *, DB_REPMGR_SITE **));
2112	int  (*repmgr_start) __P((DB_ENV *, int, u_int32_t));
2113	int  (*repmgr_stat) __P((DB_ENV *, DB_REPMGR_STAT **, u_int32_t));
2114	int  (*repmgr_stat_print) __P((DB_ENV *, u_int32_t));
2115	int  (*set_alloc) __P((DB_ENV *, void *(*)(size_t),
2116		void *(*)(void *, size_t), void (*)(void *)));
2117	int  (*set_app_dispatch)
2118		__P((DB_ENV *, int (*)(DB_ENV *, DBT *, DB_LSN *, db_recops)));
2119	int  (*set_cache_max) __P((DB_ENV *, u_int32_t, u_int32_t));
2120	int  (*set_cachesize) __P((DB_ENV *, u_int32_t, u_int32_t, int));
2121	int  (*set_data_dir) __P((DB_ENV *, const char *));
2122	int  (*set_encrypt) __P((DB_ENV *, const char *, u_int32_t));
2123	void (*set_errcall) __P((DB_ENV *,
2124		void (*)(const DB_ENV *, const char *, const char *)));
2125	void (*set_errfile) __P((DB_ENV *, FILE *));
2126	void (*set_errpfx) __P((DB_ENV *, const char *));
2127	int  (*set_event_notify)
2128		__P((DB_ENV *, void (*)(DB_ENV *, u_int32_t, void *)));
2129	int  (*set_feedback) __P((DB_ENV *, void (*)(DB_ENV *, int, int)));
2130	int  (*set_flags) __P((DB_ENV *, u_int32_t, int));
2131	int  (*set_intermediate_dir_mode) __P((DB_ENV *, const char *));
2132	int  (*set_isalive) __P((DB_ENV *,
2133		int (*)(DB_ENV *, pid_t, db_threadid_t, u_int32_t)));
2134	int  (*set_lg_bsize) __P((DB_ENV *, u_int32_t));
2135	int  (*set_lg_dir) __P((DB_ENV *, const char *));
2136	int  (*set_lg_filemode) __P((DB_ENV *, int));
2137	int  (*set_lg_max) __P((DB_ENV *, u_int32_t));
2138	int  (*set_lg_regionmax) __P((DB_ENV *, u_int32_t));
2139	int  (*set_lk_conflicts) __P((DB_ENV *, u_int8_t *, int));
2140	int  (*set_lk_detect) __P((DB_ENV *, u_int32_t));
2141	int  (*set_lk_max_lockers) __P((DB_ENV *, u_int32_t));
2142	int  (*set_lk_max_locks) __P((DB_ENV *, u_int32_t));
2143	int  (*set_lk_max_objects) __P((DB_ENV *, u_int32_t));
2144	int  (*set_lk_partitions) __P((DB_ENV *, u_int32_t));
2145	int  (*set_mp_max_openfd) __P((DB_ENV *, int));
2146	int  (*set_mp_max_write) __P((DB_ENV *, int, db_timeout_t));
2147	int  (*set_mp_mmapsize) __P((DB_ENV *, size_t));
2148	void (*set_msgcall)
2149		__P((DB_ENV *, void (*)(const DB_ENV *, const char *)));
2150	void (*set_msgfile) __P((DB_ENV *, FILE *));
2151	int  (*set_paniccall) __P((DB_ENV *, void (*)(DB_ENV *, int)));
2152	int  (*set_rpc_server)
2153		__P((DB_ENV *, void *, const char *, long, long, u_int32_t));
2154	int  (*set_shm_key) __P((DB_ENV *, long));
2155	int  (*set_thread_count) __P((DB_ENV *, u_int32_t));
2156	int  (*set_thread_id)
2157		__P((DB_ENV *, void (*)(DB_ENV *, pid_t *, db_threadid_t *)));
2158	int  (*set_thread_id_string) __P((DB_ENV *,
2159		char *(*)(DB_ENV *, pid_t, db_threadid_t, char *)));
2160	int  (*set_timeout) __P((DB_ENV *, db_timeout_t, u_int32_t));
2161	int  (*set_tmp_dir) __P((DB_ENV *, const char *));
2162	int  (*set_tx_max) __P((DB_ENV *, u_int32_t));
2163	int  (*set_tx_timestamp) __P((DB_ENV *, time_t *));
2164	int  (*set_verbose) __P((DB_ENV *, u_int32_t, int));
2165	int  (*stat_print) __P((DB_ENV *, u_int32_t));
2166	int  (*txn_begin) __P((DB_ENV *, DB_TXN *, DB_TXN **, u_int32_t));
2167	int  (*txn_checkpoint) __P((DB_ENV *, u_int32_t, u_int32_t, u_int32_t));
2168	int  (*txn_recover)
2169		__P((DB_ENV *, DB_PREPLIST *, long, long *, u_int32_t));
2170	int  (*txn_stat) __P((DB_ENV *, DB_TXN_STAT **, u_int32_t));
2171	int  (*txn_stat_print) __P((DB_ENV *, u_int32_t));
2172	/* DB_ENV PUBLIC HANDLE LIST END */
2173
2174	/* DB_ENV PRIVATE HANDLE LIST BEGIN */
2175	int  (*prdbt) __P((DBT *,
2176		int, const char *, void *, int (*)(void *, const void *), int));
2177	/* DB_ENV PRIVATE HANDLE LIST END */
2178};
2179
2180/*
2181 * Dispatch structure for recovery and print routines.  Since internal and
2182 * external routines take different arguments (ENV versus DB_ENV), we need
2183 * something more elaborate than a single pointer and size.
2184 */
2185struct __db_distab {
2186	int   (**int_dispatch) __P((ENV *, DBT *, DB_LSN *, db_recops, void *));
2187	size_t	int_size;
2188	int   (**ext_dispatch) __P((DB_ENV *, DBT *, DB_LSN *, db_recops));
2189	size_t	ext_size;
2190};
2191
2192#ifndef DB_DBM_HSEARCH
2193#define	DB_DBM_HSEARCH	0		/* No historic interfaces by default. */
2194#endif
2195#if DB_DBM_HSEARCH != 0
2196/*******************************************************
2197 * Dbm/Ndbm historic interfaces.
2198 *******************************************************/
2199typedef struct __db DBM;
2200
2201#define	DBM_INSERT	0		/* Flags to dbm_store(). */
2202#define	DBM_REPLACE	1
2203
2204/*
2205 * The DB support for ndbm(3) always appends this suffix to the
2206 * file name to avoid overwriting the user's original database.
2207 */
2208#define	DBM_SUFFIX	".db"
2209
2210#if defined(_XPG4_2)
2211typedef struct {
2212	char *dptr;
2213	size_t dsize;
2214} datum;
2215#else
2216typedef struct {
2217	char *dptr;
2218	int dsize;
2219} datum;
2220#endif
2221
2222/*
2223 * Translate NDBM calls into DB calls so that DB doesn't step on the
2224 * application's name space.
2225 */
2226#define	dbm_clearerr(a)		__db_ndbm_clearerr(a)
2227#define	dbm_close(a)		__db_ndbm_close(a)
2228#define	dbm_delete(a, b)	__db_ndbm_delete(a, b)
2229#define	dbm_dirfno(a)		__db_ndbm_dirfno(a)
2230#define	dbm_error(a)		__db_ndbm_error(a)
2231#define	dbm_fetch(a, b)		__db_ndbm_fetch(a, b)
2232#define	dbm_firstkey(a)		__db_ndbm_firstkey(a)
2233#define	dbm_nextkey(a)		__db_ndbm_nextkey(a)
2234#define	dbm_open(a, b, c)	__db_ndbm_open(a, b, c)
2235#define	dbm_pagfno(a)		__db_ndbm_pagfno(a)
2236#define	dbm_rdonly(a)		__db_ndbm_rdonly(a)
2237#define	dbm_store(a, b, c, d) \
2238	__db_ndbm_store(a, b, c, d)
2239
2240/*
2241 * Translate DBM calls into DB calls so that DB doesn't step on the
2242 * application's name space.
2243 *
2244 * The global variables dbrdonly, dirf and pagf were not retained when 4BSD
2245 * replaced the dbm interface with ndbm, and are not supported here.
2246 */
2247#define	dbminit(a)	__db_dbm_init(a)
2248#define	dbmclose	__db_dbm_close
2249#if !defined(__cplusplus)
2250#define	delete(a)	__db_dbm_delete(a)
2251#endif
2252#define	fetch(a)	__db_dbm_fetch(a)
2253#define	firstkey	__db_dbm_firstkey
2254#define	nextkey(a)	__db_dbm_nextkey(a)
2255#define	store(a, b)	__db_dbm_store(a, b)
2256
2257/*******************************************************
2258 * Hsearch historic interface.
2259 *******************************************************/
2260typedef enum {
2261	FIND, ENTER
2262} ACTION;
2263
2264typedef struct entry {
2265	char *key;
2266	char *data;
2267} ENTRY;
2268
2269#define	hcreate(a)	__db_hcreate(a)
2270#define	hdestroy	__db_hdestroy
2271#define	hsearch(a, b)	__db_hsearch(a, b)
2272
2273#endif /* DB_DBM_HSEARCH */
2274
2275#if defined(__cplusplus)
2276}
2277#endif
2278
2279/* Restore default compiler warnings */
2280#ifdef _MSC_VER
2281#pragma warning(pop)
2282#endif
2283#endif /* !_DB_H_ */
2284/* DO NOT EDIT: automatically built by dist/s_apiflags. */
2285#define	DB_AGGRESSIVE				0x00000001
2286#define	DB_ARCH_ABS				0x00000001
2287#define	DB_ARCH_DATA				0x00000002
2288#define	DB_ARCH_LOG				0x00000004
2289#define	DB_ARCH_REMOVE				0x00000008
2290#define	DB_AUTO_COMMIT				0x00000100
2291#define	DB_CDB_ALLDB				0x00000004
2292#define	DB_CHKSUM				0x00000004
2293#define	DB_CKP_INTERNAL				0x00000002
2294#define	DB_CREATE				0x00000001
2295#define	DB_CXX_NO_EXCEPTIONS			0x00000002
2296#define	DB_DIRECT				0x00000002
2297#define	DB_DIRECT_DB				0x00000040
2298#define	DB_DSYNC_DB				0x00000080
2299#define	DB_DUP					0x00000008
2300#define	DB_DUPSORT				0x00000002
2301#define	DB_DURABLE_UNKNOWN			0x00000020
2302#define	DB_ENCRYPT				0x00000001
2303#define	DB_ENCRYPT_AES				0x00000001
2304#define	DB_EXCL					0x00000400
2305#define	DB_EXTENT				0x00000004
2306#define	DB_FAST_STAT				0x00000001
2307#define	DB_FCNTL_LOCKING			0x00001000
2308#define	DB_FLUSH				0x00000001
2309#define	DB_FORCE				0x00000001
2310#define	DB_FOREIGN_ABORT			0x00000001
2311#define	DB_FOREIGN_CASCADE			0x00000002
2312#define	DB_FOREIGN_NULLIFY			0x00000004
2313#define	DB_FREELIST_ONLY			0x00000001
2314#define	DB_FREE_SPACE				0x00000002
2315#define	DB_IGNORE_LEASE				0x00001000
2316#define	DB_IMMUTABLE_KEY			0x00000002
2317#define	DB_INIT_CDB				0x00000020
2318#define	DB_INIT_LOCK				0x00000040
2319#define	DB_INIT_LOG				0x00000080
2320#define	DB_INIT_MPOOL				0x00000100
2321#define	DB_INIT_REP				0x00000200
2322#define	DB_INIT_TXN				0x00000400
2323#define	DB_INORDER				0x00000010
2324#define	DB_JOIN_NOSORT				0x00000001
2325#define	DB_LOCKDOWN				0x00000800
2326#define	DB_LOCK_NOWAIT				0x00000001
2327#define	DB_LOCK_RECORD				0x00000002
2328#define	DB_LOCK_SET_TIMEOUT			0x00000004
2329#define	DB_LOCK_SWITCH				0x00000008
2330#define	DB_LOCK_UPGRADE				0x00000010
2331#define	DB_LOG_AUTO_REMOVE			0x00000004
2332#define	DB_LOG_CHKPNT				0x00000002
2333#define	DB_LOG_COMMIT				0x00000004
2334#define	DB_LOG_DIRECT				0x00000001
2335#define	DB_LOG_DSYNC				0x00000002
2336#define	DB_LOG_IN_MEMORY			0x00000008
2337#define	DB_LOG_NOCOPY				0x00000008
2338#define	DB_LOG_NOT_DURABLE			0x00000010
2339#define	DB_LOG_WRNOSYNC				0x00000020
2340#define	DB_LOG_ZERO				0x00000010
2341#define	DB_MPOOL_CREATE				0x00000001
2342#define	DB_MPOOL_DIRTY				0x00000002
2343#define	DB_MPOOL_DISCARD			0x00000001
2344#define	DB_MPOOL_EDIT				0x00000004
2345#define	DB_MPOOL_FREE				0x00000008
2346#define	DB_MPOOL_LAST				0x00000010
2347#define	DB_MPOOL_NEW				0x00000020
2348#define	DB_MPOOL_NOFILE				0x00000001
2349#define	DB_MPOOL_NOLOCK				0x00000002
2350#define	DB_MPOOL_UNLINK				0x00000002
2351#define	DB_MULTIPLE				0x00002000
2352#define	DB_MULTIPLE_KEY				0x00000100
2353#define	DB_MULTIVERSION				0x00000008
2354#define	DB_MUTEX_ALLOCATED			0x00000001
2355#define	DB_MUTEX_LOCKED				0x00000002
2356#define	DB_MUTEX_LOGICAL_LOCK			0x00000004
2357#define	DB_MUTEX_PROCESS_ONLY			0x00000008
2358#define	DB_MUTEX_SELF_BLOCK			0x00000010
2359#define	DB_NOLOCKING				0x00000200
2360#define	DB_NOMMAP				0x00000010
2361#define	DB_NOORDERCHK				0x00000002
2362#define	DB_NOPANIC				0x00000400
2363#define	DB_NO_AUTO_COMMIT			0x00002000
2364#define	DB_ODDFILESIZE				0x00000040
2365#define	DB_ORDERCHKONLY				0x00000004
2366#define	DB_OVERWRITE				0x00001000
2367#define	DB_PANIC_ENVIRONMENT			0x00002000
2368#define	DB_PRINTABLE				0x00000008
2369#define	DB_PRIVATE				0x00001000
2370#define	DB_PR_PAGE				0x00000010
2371#define	DB_PR_RECOVERYTEST			0x00000020
2372#define	DB_RDONLY				0x00000080
2373#define	DB_RDWRMASTER				0x00004000
2374#define	DB_READ_COMMITTED			0x00000400
2375#define	DB_READ_UNCOMMITTED			0x00000200
2376#define	DB_RECNUM				0x00000020
2377#define	DB_RECOVER				0x00000010
2378#define	DB_RECOVER_FATAL			0x00002000
2379#define	DB_REGION_INIT				0x00004000
2380#define	DB_REGISTER				0x00004000
2381#define	DB_RENUMBER				0x00000040
2382#define	DB_REPMGR_CONF_2SITE_STRICT		0x00000001
2383#define	DB_REPMGR_PEER				0x00000001
2384#define	DB_REP_ANYWHERE				0x00000001
2385#define	DB_REP_CLIENT				0x00000001
2386#define	DB_REP_CONF_BULK			0x00000002
2387#define	DB_REP_CONF_DELAYCLIENT			0x00000004
2388#define	DB_REP_CONF_LEASE			0x00000008
2389#define	DB_REP_CONF_NOAUTOINIT			0x00000010
2390#define	DB_REP_CONF_NOWAIT			0x00000020
2391#define	DB_REP_ELECTION				0x00000004
2392#define	DB_REP_MASTER				0x00000002
2393#define	DB_REP_NOBUFFER				0x00000002
2394#define	DB_REP_PERMANENT			0x00000004
2395#define	DB_REP_REREQUEST			0x00000008
2396#define	DB_REVSPLITOFF				0x00000080
2397#define	DB_RMW					0x00000800
2398#define	DB_RPCCLIENT				0x00000001
2399#define	DB_SALVAGE				0x00000040
2400#define	DB_SA_SKIPFIRSTKEY			0x00010000
2401#define	DB_SEQ_DEC				0x00000001
2402#define	DB_SEQ_INC				0x00000002
2403#define	DB_SEQ_RANGE_SET			0x00000004
2404#define	DB_SEQ_WRAP				0x00000008
2405#define	DB_SEQ_WRAPPED				0x00000010
2406#define	DB_SET_LOCK_TIMEOUT			0x00000002
2407#define	DB_SET_TXN_NOW				0x00000004
2408#define	DB_SET_TXN_TIMEOUT			0x00000001
2409#define	DB_SNAPSHOT				0x00000100
2410#define	DB_STAT_ALL				0x00000002
2411#define	DB_STAT_CLEAR				0x00000001
2412#define	DB_STAT_LOCK_CONF			0x00000004
2413#define	DB_STAT_LOCK_LOCKERS			0x00000008
2414#define	DB_STAT_LOCK_OBJECTS			0x00000010
2415#define	DB_STAT_LOCK_PARAMS			0x00000020
2416#define	DB_STAT_MEMP_HASH			0x00000004
2417#define	DB_STAT_MEMP_NOERROR			0x00000008
2418#define	DB_STAT_SUBSYSTEM			0x00000004
2419#define	DB_ST_DUPOK				0x00000100
2420#define	DB_ST_DUPSET				0x00000200
2421#define	DB_ST_DUPSORT				0x00000400
2422#define	DB_ST_IS_RECNO				0x00000800
2423#define	DB_ST_OVFL_LEAF				0x00001000
2424#define	DB_ST_RECNUM				0x00002000
2425#define	DB_ST_RELEN				0x00004000
2426#define	DB_ST_TOPLEVEL				0x00008000
2427#define	DB_SYSTEM_MEM				0x00008000
2428#define	DB_THREAD				0x00000004
2429#define	DB_TIME_NOTGRANTED			0x00008000
2430#define	DB_TRUNCATE				0x00008000
2431#define	DB_TXN_NOSYNC				0x00000001
2432#define	DB_TXN_NOT_DURABLE			0x00000200
2433#define	DB_TXN_NOWAIT				0x00000002
2434#define	DB_TXN_SNAPSHOT				0x00000800
2435#define	DB_TXN_SYNC				0x00000004
2436#define	DB_TXN_WAIT				0x00000008
2437#define	DB_TXN_WRITE_NOSYNC			0x00000020
2438#define	DB_UNREF				0x00000080
2439#define	DB_UPGRADE				0x00000001
2440#define	DB_USE_ENVIRON				0x00000002
2441#define	DB_USE_ENVIRON_ROOT			0x00000008
2442#define	DB_VERB_DEADLOCK			0x00000001
2443#define	DB_VERB_FILEOPS				0x00000002
2444#define	DB_VERB_FILEOPS_ALL			0x00000004
2445#define	DB_VERB_RECOVERY			0x00000008
2446#define	DB_VERB_REGISTER			0x00000010
2447#define	DB_VERB_REPLICATION			0x00000020
2448#define	DB_VERB_REPMGR_CONNFAIL			0x00000040
2449#define	DB_VERB_REPMGR_MISC			0x00000080
2450#define	DB_VERB_REP_ELECT			0x00000100
2451#define	DB_VERB_REP_LEASE			0x00000200
2452#define	DB_VERB_REP_MISC			0x00000400
2453#define	DB_VERB_REP_MSGS			0x00000800
2454#define	DB_VERB_REP_SYNC			0x00001000
2455#define	DB_VERB_WAITSFOR			0x00002000
2456#define	DB_VERIFY				0x00000002
2457#define	DB_WRITEOPEN				0x00010000
2458#define	DB_XA_CREATE				0x00000800
2459#define	DB_YIELDCPU				0x00010000
2460
2461/* DO NOT EDIT: automatically built by dist/s_include. */
2462#ifndef	_DB_EXT_PROT_IN_
2463#define	_DB_EXT_PROT_IN_
2464
2465#if defined(__cplusplus)
2466extern "C" {
2467#endif
2468
2469int db_create __P((DB **, DB_ENV *, u_int32_t));
2470char *db_strerror __P((int));
2471int db_env_set_func_close __P((int (*)(int)));
2472int db_env_set_func_dirfree __P((void (*)(char **, int)));
2473int db_env_set_func_dirlist __P((int (*)(const char *, char ***, int *)));
2474int db_env_set_func_exists __P((int (*)(const char *, int *)));
2475int db_env_set_func_free __P((void (*)(void *)));
2476int db_env_set_func_fsync __P((int (*)(int)));
2477int db_env_set_func_ftruncate __P((int (*)(int, off_t)));
2478int db_env_set_func_ioinfo __P((int (*)(const char *, int, u_int32_t *, u_int32_t *, u_int32_t *)));
2479int db_env_set_func_malloc __P((void *(*)(size_t)));
2480int db_env_set_func_file_map __P((int (*)(DB_ENV *, char *, size_t, int, void **), int (*)(DB_ENV *, void *)));
2481int db_env_set_func_region_map __P((int (*)(DB_ENV *, char *, size_t, int *, void **), int (*)(DB_ENV *, void *)));
2482int db_env_set_func_pread __P((ssize_t (*)(int, void *, size_t, off_t)));
2483int db_env_set_func_pwrite __P((ssize_t (*)(int, const void *, size_t, off_t)));
2484int db_env_set_func_open __P((int (*)(const char *, int, ...)));
2485int db_env_set_func_read __P((ssize_t (*)(int, void *, size_t)));
2486int db_env_set_func_realloc __P((void *(*)(void *, size_t)));
2487int db_env_set_func_rename __P((int (*)(const char *, const char *)));
2488int db_env_set_func_seek __P((int (*)(int, off_t, int)));
2489int db_env_set_func_unlink __P((int (*)(const char *)));
2490int db_env_set_func_write __P((ssize_t (*)(int, const void *, size_t)));
2491int db_env_set_func_yield __P((int (*)(u_long, u_long)));
2492int db_env_create __P((DB_ENV **, u_int32_t));
2493char *db_version __P((int *, int *, int *));
2494int log_compare __P((const DB_LSN *, const DB_LSN *));
2495int db_sequence_create __P((DB_SEQUENCE **, DB *, u_int32_t));
2496#if DB_DBM_HSEARCH != 0
2497int	 __db_ndbm_clearerr __P((DBM *));
2498void	 __db_ndbm_close __P((DBM *));
2499int	 __db_ndbm_delete __P((DBM *, datum));
2500int	 __db_ndbm_dirfno __P((DBM *));
2501int	 __db_ndbm_error __P((DBM *));
2502datum __db_ndbm_fetch __P((DBM *, datum));
2503datum __db_ndbm_firstkey __P((DBM *));
2504datum __db_ndbm_nextkey __P((DBM *));
2505DBM	*__db_ndbm_open __P((const char *, int, int));
2506int	 __db_ndbm_pagfno __P((DBM *));
2507int	 __db_ndbm_rdonly __P((DBM *));
2508int	 __db_ndbm_store __P((DBM *, datum, datum, int));
2509int	 __db_dbm_close __P((void));
2510int	 __db_dbm_delete __P((datum));
2511datum __db_dbm_fetch __P((datum));
2512datum __db_dbm_firstkey __P((void));
2513int	 __db_dbm_init __P((char *));
2514datum __db_dbm_nextkey __P((datum));
2515int	 __db_dbm_store __P((datum, datum));
2516#endif
2517#if DB_DBM_HSEARCH != 0
2518int __db_hcreate __P((size_t));
2519ENTRY *__db_hsearch __P((ENTRY, ACTION));
2520void __db_hdestroy __P((void));
2521#endif
2522
2523#if defined(__cplusplus)
2524}
2525#endif
2526#endif /* !_DB_EXT_PROT_IN_ */
2527