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