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