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