1 /* DO NOT EDIT: automatically built by dist/s_vxworks. */
2 /*
3  * Copyright (c) 1996, 2020 Oracle and/or its affiliates.  All rights reserved.
4  *
5  * See the file LICENSE for license information.
6  *
7  * $Id$
8  *
9  * db.h include file layout:
10  *	General.
11  *	Database Environment.
12  *	Locking subsystem.
13  *	Logging subsystem.
14  *	Shared buffer cache (mpool) subsystem.
15  *	Transaction subsystem.
16  *	Access methods.
17  *	Access method cursors.
18  *	Dbm/Ndbm, Hsearch historic interfaces.
19  */
20 
21 #ifndef _DB_H_
22 #define	_DB_H_
23 
24 #ifndef	__NO_SYSTEM_INCLUDES
25 #include <sys/types.h>
26 #include <stdio.h>
27 #include <pthread.h>
28 #endif
29 
30 #if defined(__cplusplus)
31 extern "C" {
32 #endif
33 
34 #ifndef __vxworks
35 #define	__vxworks
36 #endif
37 
38 
39 #undef __P
40 #define	__P(protos)	protos
41 
42 /*
43  * Berkeley DB version information.
44  */
45 #define	DB_VERSION_MAJOR	18
46 #define	DB_VERSION_MINOR	1
47 #define	DB_VERSION_PATCH	40
48 #define	DB_VERSION_STRING	"Berkeley DB 18.1.40: (May 29, 2020)"
49 #define	DB_VERSION_FULL_STRING	"Berkeley DB Release 18.1, library version 18.1.40: (May 29, 2020)"
50 
51 /*
52  * These two version numbers are deprecated and will be removed in a future
53  * release.  Until that time they are the same as the major and minor numbers.
54  */
55 #define	DB_VERSION_FAMILY	18
56 #define	DB_VERSION_RELEASE	1
57 
58 /*
59  * !!!
60  * Berkeley DB uses specifically sized types.  If they're not provided by
61  * the system, typedef them here.
62  *
63  * We protect them against multiple inclusion using __BIT_TYPES_DEFINED__,
64  * as does BIND and Kerberos, since we don't know for sure what #include
65  * files the user is using.
66  *
67  * !!!
68  * We also provide the standard u_int, u_long etc., if they're not provided
69  * by the system.
70  */
71 #ifndef	__BIT_TYPES_DEFINED__
72 #define	__BIT_TYPES_DEFINED__
73 typedef unsigned char u_int8_t;
74 typedef unsigned short u_int16_t;
75 typedef unsigned int u_int32_t;
76 
77 typedef unsigned long long u_int64_t;
78 #endif
79 
80 
81 /*
82  * Missing ANSI types.
83  *
84  * uintmax_t --
85  * Largest unsigned type, used to align structures in memory.  We don't store
86  * floating point types in structures, so integral types should be sufficient
87  * (and we don't have to worry about systems that store floats in other than
88  * power-of-2 numbers of bytes).  Additionally this fixes compilers that rewrite
89  * structure assignments and ANSI C memcpy calls to be in-line instructions
90  * that happen to require alignment.
91  *
92  * uintptr_t --
93  * Unsigned type that's the same size as a pointer.  There are places where
94  * DB modifies pointers by discarding the bottom bits to guarantee alignment.
95  * We can't use uintmax_t, it may be larger than the pointer, and compilers
96  * get upset about that.  So far we haven't run on any machine where there's
97  * no unsigned type the same size as a pointer -- here's hoping.
98  */
99 typedef unsigned long uintmax_t;
100 
101 typedef int64_t db_off_t;
102 #define DB_OFF_T_MAX INT64_MAX
103 #ifdef HAVE_MIXED_SIZE_ADDRESSING
104 typedef u_int32_t db_size_t;
105 #else
106 typedef size_t db_size_t;
107 #endif
108 #ifdef HAVE_MIXED_SIZE_ADDRESSING
109 typedef int32_t db_ssize_t;
110 #else
111 typedef ssize_t db_ssize_t;
112 #endif
113 
114 /*
115  * Sequences are only available on machines with 64-bit integral types.
116  */
117 typedef int64_t db_seq_t;
118 
119 /* Thread and process identification. */
120 typedef uintmax_t db_threadid_t;
121 
122 /* Basic types that are exported or quasi-exported. */
123 typedef	u_int32_t	db_pgno_t;	/* Page number type. */
124 typedef	u_int16_t	db_indx_t;	/* Page offset type. */
125 #define	DB_MAX_PAGES	0xffffffff	/* >= # of pages in a file */
126 
127 typedef	u_int32_t	db_recno_t;	/* Record number type. */
128 #define	DB_MAX_RECORDS	0xffffffff	/* >= # of records in a recno tree. */
129 
130 typedef u_int32_t	db_timeout_t;	/* Type of a timeout in microseconds. */
131 
132 /*
133  * Region offsets are the difference between a pointer in a region and the
134  * region's base address.  With private environments, both addresses are the
135  * result of calling malloc, and we can't assume anything about what malloc
136  * will return, so region offsets have to be able to hold differences between
137  * arbitrary pointers.
138  */
139 typedef	db_size_t	roff_t;
140 
141 /*
142  * Forward structure declarations, so we can declare pointers and
143  * applications can get type checking.
144  */
145 struct __channel;	typedef struct __channel CHANNEL;
146 struct __db;		typedef struct __db DB;
147 struct __db_bt_stat;	typedef struct __db_bt_stat DB_BTREE_STAT;
148 struct __db_channel;	typedef struct __db_channel DB_CHANNEL;
149 struct __db_cipher;	typedef struct __db_cipher DB_CIPHER;
150 struct __db_compact;	typedef struct __db_compact DB_COMPACT;
151 struct __db_dbt;	typedef struct __db_dbt DBT;
152 struct __db_distab;	typedef struct __db_distab DB_DISTAB;
153 struct __db_env;	typedef struct __db_env DB_ENV;
154 struct __db_event_mutex_died_info;
155 	typedef struct __db_event_mutex_died_info DB_EVENT_MUTEX_DIED_INFO;
156 struct __db_event_failchk_info;
157 	typedef struct __db_event_failchk_info DB_EVENT_FAILCHK_INFO;
158 struct __db_h_stat;	typedef struct __db_h_stat DB_HASH_STAT;
159 struct __db_heap_rid;	typedef struct __db_heap_rid DB_HEAP_RID;
160 struct __db_heap_stat;	typedef struct __db_heap_stat DB_HEAP_STAT;
161 struct __db_ilock;	typedef struct __db_ilock DB_LOCK_ILOCK;
162 struct __db_lock_hstat;	typedef struct __db_lock_hstat DB_LOCK_HSTAT;
163 struct __db_lock_pstat;	typedef struct __db_lock_pstat DB_LOCK_PSTAT;
164 struct __db_lock_stat;	typedef struct __db_lock_stat DB_LOCK_STAT;
165 struct __db_lock_u;	typedef struct __db_lock_u DB_LOCK;
166 struct __db_locker;	typedef struct __db_locker DB_LOCKER;
167 struct __db_lockreq;	typedef struct __db_lockreq DB_LOCKREQ;
168 struct __db_locktab;	typedef struct __db_locktab DB_LOCKTAB;
169 struct __db_log;	typedef struct __db_log DB_LOG;
170 struct __db_log_cursor;	typedef struct __db_log_cursor DB_LOGC;
171 struct __db_log_stat;	typedef struct __db_log_stat DB_LOG_STAT;
172 struct __db_lsn;	typedef struct __db_lsn DB_LSN;
173 struct __db_mpool;	typedef struct __db_mpool DB_MPOOL;
174 struct __db_mpool_fstat;typedef struct __db_mpool_fstat DB_MPOOL_FSTAT;
175 struct __db_mpool_stat;	typedef struct __db_mpool_stat DB_MPOOL_STAT;
176 struct __db_mpoolfile;	typedef struct __db_mpoolfile DB_MPOOLFILE;
177 struct __db_mutex_stat;	typedef struct __db_mutex_stat DB_MUTEX_STAT;
178 struct __db_mutex_t;	typedef struct __db_mutex_t DB_MUTEX;
179 struct __db_mutexmgr;	typedef struct __db_mutexmgr DB_MUTEXMGR;
180 struct __db_preplist;	typedef struct __db_preplist DB_PREPLIST;
181 struct __db_qam_stat;	typedef struct __db_qam_stat DB_QUEUE_STAT;
182 struct __db_rep;	typedef struct __db_rep DB_REP;
183 struct __db_rep_stat;	typedef struct __db_rep_stat DB_REP_STAT;
184 struct __db_repmgr_conn_err;
185 	typedef struct __db_repmgr_conn_err DB_REPMGR_CONN_ERR;
186 struct __db_repmgr_site;typedef struct __db_repmgr_site DB_REPMGR_SITE;
187 struct __db_repmgr_stat;typedef struct __db_repmgr_stat DB_REPMGR_STAT;
188 struct __db_seq_record; typedef struct __db_seq_record DB_SEQ_RECORD;
189 struct __db_seq_stat;	typedef struct __db_seq_stat DB_SEQUENCE_STAT;
190 struct __db_stream;	typedef struct __db_stream DB_STREAM;
191 struct __db_site;	typedef struct __db_site DB_SITE;
192 struct __db_sequence;	typedef struct __db_sequence DB_SEQUENCE;
193 struct __db_thread_info;typedef struct __db_thread_info DB_THREAD_INFO;
194 struct __db_txn;	typedef struct __db_txn DB_TXN;
195 struct __db_txn_active;	typedef struct __db_txn_active DB_TXN_ACTIVE;
196 struct __db_txn_active_slice;
197 	typedef struct __db_txn_active_slice DB_TXN_ACTIVE_SLICE;
198 struct __db_txn_stat;	typedef struct __db_txn_stat DB_TXN_STAT;
199 struct __db_txn_token;	typedef struct __db_txn_token DB_TXN_TOKEN;
200 struct __db_txnmgr;	typedef struct __db_txnmgr DB_TXNMGR;
201 struct __dbc;		typedef struct __dbc DBC;
202 struct __dbc_internal;	typedef struct __dbc_internal DBC_INTERNAL;
203 struct __env;		typedef struct __env ENV;
204 struct __fh_t;		typedef struct __fh_t DB_FH;
205 struct __fname;		typedef struct __fname FNAME;
206 struct __key_range;	typedef struct __key_range DB_KEY_RANGE;
207 struct __mpoolfile;	typedef struct __mpoolfile MPOOLFILE;
208 struct __db_logvrfy_config;
209 typedef struct __db_logvrfy_config DB_LOG_VERIFY_CONFIG;
210 
211 /*
212  * The Berkeley DB API flags are automatically-generated -- the following flag
213  * names are no longer used, but remain for compatibility reasons.
214  */
215 #define	DB_DEGREE_2	      DB_READ_COMMITTED
216 #define	DB_DIRTY_READ	      DB_READ_UNCOMMITTED
217 #define	DB_JOINENV	      0x0
218 
219 /* Key/data structure -- a Data-Base Thang. */
220 struct __db_dbt {
221 	void	 *data;			/* Key/data */
222 	u_int32_t size;			/* key/data length */
223 
224 	u_int32_t ulen;			/* RO: length of user buffer. */
225 	u_int32_t dlen;			/* RO: get/put record length. */
226 	u_int32_t doff;			/* RO: get/put record offset. */
227 
228 	void *app_data;
229 
230 #define	DB_DBT_APPMALLOC	0x0001	/* Callback allocated memory. */
231 #define	DB_DBT_BULK		0x0002	/* Internal: Insert if duplicate. */
232 #define	DB_DBT_DUPOK		0x0004	/* Internal: Insert if duplicate. */
233 #define	DB_DBT_ISSET		0x0008	/* Lower level calls set value. */
234 #define	DB_DBT_MALLOC		0x0010	/* Return in malloc'd memory. */
235 #define	DB_DBT_MULTIPLE		0x0020	/* References multiple records. */
236 #define	DB_DBT_PARTIAL		0x0040	/* Partial put/get. */
237 #define	DB_DBT_REALLOC		0x0080	/* Return in realloc'd memory. */
238 #define	DB_DBT_READONLY		0x0100	/* Readonly, don't update. */
239 #define	DB_DBT_STREAMING	0x0200	/* Internal: DBT is being streamed. */
240 #define	DB_DBT_USERCOPY		0x0400	/* Use the user-supplied callback. */
241 #define	DB_DBT_USERMEM		0x0800	/* Return in user's memory. */
242 #define	DB_DBT_BLOB		0x1000	/* Alias DB_DBT_EXT_FILE. */
243 #define	DB_DBT_EXT_FILE		0x1000	/* Data item is an external file. */
244 #define	DB_DBT_BLOB_REC		0x2000	/* Internal: Blob database record. */
245 	u_int32_t flags;
246 };
247 
248 /*******************************************************
249  * Mutexes.
250  *******************************************************/
251 /*
252  * When mixed size addressing is supported mutexes need to be the same size
253  * independent of the process address size is.
254  */
255 #ifdef HAVE_MIXED_SIZE_ADDRESSING
256 typedef db_size_t	db_mutex_t;
257 #else
258 typedef uintptr_t	db_mutex_t;
259 #endif
260 
261 struct __db_mutex_stat { /* SHARED */
262 	/* The following fields are maintained in the region's copy. */
263 	u_int32_t st_mutex_align;	/* Mutex alignment */
264 	u_int32_t st_mutex_tas_spins;	/* Mutex test-and-set spins */
265 	u_int32_t st_mutex_init;	/* Initial mutex count */
266 	u_int32_t st_mutex_cnt;		/* Mutex count */
267 	u_int32_t st_mutex_max;		/* Mutex max */
268 	u_int32_t st_mutex_free;	/* Available mutexes */
269 	u_int32_t st_mutex_inuse;	/* Mutexes in use */
270 	u_int32_t st_mutex_inuse_max;	/* Maximum mutexes ever in use */
271 
272 	/* The following fields are filled-in from other places. */
273 #ifndef __TEST_DB_NO_STATISTICS
274 	uintmax_t st_region_wait;	/* Region lock granted after wait. */
275 	uintmax_t st_region_nowait;	/* Region lock granted without wait. */
276 	roff_t	  st_regsize;		/* Region size. */
277 	roff_t	  st_regmax;		/* Region max. */
278 #endif
279 };
280 
281 /* Buffers passed to __mutex_describe() must be at least this large. */
282 #define	DB_MUTEX_DESCRIBE_STRLEN	128
283 
284 /* This is the info of a DB_EVENT_MUTEX_DIED event notification. */
285 struct __db_event_mutex_died_info {
286 	pid_t         pid;	/* Process which last owned the mutex */
287 	db_threadid_t tid;	/* Thread which last owned the mutex */
288 	db_mutex_t    mutex;	/* ID of the mutex */
289 	char	      desc[DB_MUTEX_DESCRIBE_STRLEN];
290 };
291 
292 /* This is the info of a DB_EVENT_FAILCHK event notification. */
293 #define DB_FAILURE_SYMPTOM_SIZE	120
294 struct __db_event_failchk_info {
295 	int	error;
296 	char	symptom[DB_FAILURE_SYMPTOM_SIZE];
297 };
298 /* This is the length of the buffer passed to DB_ENV->thread_id_string() */
299 #define	DB_THREADID_STRLEN	128
300 
301 /*
302  * Type of the number of slices in a sliced environment; also the subscript
303  * into a slice array, such as DB.db_slices[].
304  */
305 typedef u_int32_t db_slice_t;
306 
307 /*******************************************************
308  * Locking.
309  *******************************************************/
310 #define	DB_LOCKVERSION	1
311 
312 #define	DB_FILE_ID_LEN		20	/* Unique file ID length. */
313 
314 /*
315  * Deadlock detector modes; used in the DB_ENV structure to configure the
316  * locking subsystem.
317  */
318 #define	DB_LOCK_NORUN		0
319 #define	DB_LOCK_DEFAULT		1	/* Default policy. */
320 #define	DB_LOCK_EXPIRE		2	/* Only expire locks, no detection. */
321 #define	DB_LOCK_MAXLOCKS	3	/* Select locker with max locks. */
322 #define	DB_LOCK_MAXWRITE	4	/* Select locker with max writelocks. */
323 #define	DB_LOCK_MINLOCKS	5	/* Select locker with min locks. */
324 #define	DB_LOCK_MINWRITE	6	/* Select locker with min writelocks. */
325 #define	DB_LOCK_OLDEST		7	/* Select oldest locker. */
326 #define	DB_LOCK_RANDOM		8	/* Select random locker. */
327 #define	DB_LOCK_YOUNGEST	9	/* Select youngest locker. */
328 
329 /*
330  * Simple R/W lock modes and for multi-granularity intention locking.
331  *
332  * !!!
333  * These values are NOT random, as they are used as an index into the lock
334  * conflicts arrays, i.e., DB_LOCK_IWRITE must be == 3, and DB_LOCK_IREAD
335  * must be == 4.
336  */
337 typedef enum {
338 	DB_LOCK_NG=0,			/* Not granted. */
339 	DB_LOCK_READ=1,			/* Shared/read. */
340 	DB_LOCK_WRITE=2,		/* Exclusive/write. */
341 	DB_LOCK_WAIT=3,			/* Wait for event */
342 	DB_LOCK_IWRITE=4,		/* Intent exclusive/write. */
343 	DB_LOCK_IREAD=5,		/* Intent to share/read. */
344 	DB_LOCK_IWR=6,			/* Intent to read and write. */
345 	DB_LOCK_READ_UNCOMMITTED=7,	/* Degree 1 isolation. */
346 	DB_LOCK_WWRITE=8		/* Was Written. */
347 } db_lockmode_t;
348 
349 /*
350  * Request types.
351  */
352 typedef enum {
353 	DB_LOCK_DUMP=0,			/* Display held locks. */
354 	DB_LOCK_GET=1,			/* Get the lock. */
355 	DB_LOCK_GET_TIMEOUT=2,		/* Get lock with a timeout. */
356 	DB_LOCK_INHERIT=3,		/* Pass locks to parent. */
357 	DB_LOCK_PUT=4,			/* Release the lock. */
358 	DB_LOCK_PUT_ALL=5,		/* Release locker's locks. */
359 	DB_LOCK_PUT_OBJ=6,		/* Release locker's locks on obj. */
360 	DB_LOCK_PUT_READ=7,		/* Release locker's read locks. */
361 	DB_LOCK_TIMEOUT=8,		/* Force a txn to timeout. */
362 	DB_LOCK_TRADE=9,		/* Trade locker ids on a lock. */
363 	DB_LOCK_UPGRADE_WRITE=10	/* Upgrade writes for dirty reads. */
364 } db_lockop_t;
365 
366 /*
367  * Status of a lock.
368  */
369 typedef enum  {
370 	DB_LSTAT_ABORTED=1,		/* Lock belongs to an aborted txn. */
371 	DB_LSTAT_EXPIRED=2,		/* Lock has expired. */
372 	DB_LSTAT_FREE=3,		/* Lock is unallocated. */
373 	DB_LSTAT_HELD=4,		/* Lock is currently held. */
374 	DB_LSTAT_PENDING=5,		/* Lock was waiting and has been
375 					 * promoted; waiting for the owner
376 					 * to run and upgrade it to held. */
377 	DB_LSTAT_WAITING=6		/* Lock is on the wait queue. */
378 }db_status_t;
379 
380 /* Lock statistics structure. */
381 struct __db_lock_stat { /* SHARED */
382 	u_int32_t st_id;		/* Last allocated locker ID. */
383 	u_int32_t st_cur_maxid;		/* Current maximum unused ID. */
384 	u_int32_t st_initlocks;		/* Initial number of locks in table. */
385 	u_int32_t st_initlockers;	/* Initial num of lockers in table. */
386 	u_int32_t st_initobjects;	/* Initial num of objects in table. */
387 	u_int32_t st_locks;		/* Current number of locks in table. */
388 	u_int32_t st_lockers;		/* Current num of lockers in table. */
389 	u_int32_t st_objects;		/* Current num of objects in table. */
390 	u_int32_t st_maxlocks;		/* Maximum number of locks in table. */
391 	u_int32_t st_maxlockers;	/* Maximum num of lockers in table. */
392 	u_int32_t st_maxobjects;	/* Maximum num of objects in table. */
393 	u_int32_t st_partitions;	/* number of partitions. */
394 	u_int32_t st_tablesize;		/* Size of object hash table. */
395 	int32_t   st_nmodes;		/* Number of lock modes. */
396 	u_int32_t st_nlockers;		/* Current number of lockers. */
397 #ifndef __TEST_DB_NO_STATISTICS
398 	u_int32_t st_nlocks;		/* Current number of locks. */
399 	u_int32_t st_maxnlocks;		/* Maximum number of locks so far. */
400 	u_int32_t st_maxhlocks;		/* Maximum number of locks in any bucket. */
401 	uintmax_t st_locksteals;	/* Number of lock steals so far. */
402 	uintmax_t st_maxlsteals;	/* Maximum number steals in any partition. */
403 	u_int32_t st_maxnlockers;	/* Maximum number of lockers so far. */
404 	u_int32_t st_nobjects;		/* Current number of objects. */
405 	u_int32_t st_maxnobjects;	/* Maximum number of objects so far. */
406 	u_int32_t st_maxhobjects;	/* Maximum number of objectsin any bucket. */
407 	uintmax_t st_objectsteals;	/* Number of objects steals so far. */
408 	uintmax_t st_maxosteals;	/* Maximum number of steals in any partition. */
409 	uintmax_t st_nrequests;		/* Number of lock gets. */
410 	uintmax_t st_nreleases;		/* Number of lock puts. */
411 	uintmax_t st_nupgrade;		/* Number of lock upgrades. */
412 	uintmax_t st_ndowngrade;	/* Number of lock downgrades. */
413 	uintmax_t st_lock_wait;		/* Lock conflicts w/ subsequent wait */
414 	uintmax_t st_lock_nowait;	/* Lock conflicts w/o subsequent wait */
415 	uintmax_t st_ndeadlocks;	/* Number of lock deadlocks. */
416 	db_timeout_t st_locktimeout;	/* Lock timeout. */
417 	uintmax_t st_nlocktimeouts;	/* Number of lock timeouts. */
418 	db_timeout_t st_txntimeout;	/* Transaction timeout. */
419 	uintmax_t st_ntxntimeouts;	/* Number of transaction timeouts. */
420 	uintmax_t st_part_wait;		/* Partition lock granted after wait. */
421 	uintmax_t st_part_nowait;	/* Partition lock granted without wait. */
422 	uintmax_t st_part_max_wait;	/* Max partition lock granted after wait. */
423 	uintmax_t st_part_max_nowait;	/* Max partition lock granted without wait. */
424 	uintmax_t st_objs_wait;	/* 	Object lock granted after wait. */
425 	uintmax_t st_objs_nowait;	/* Object lock granted without wait. */
426 	uintmax_t st_lockers_wait;	/* Locker lock granted after wait. */
427 	uintmax_t st_lockers_nowait;	/* Locker lock granted without wait. */
428 	uintmax_t st_region_wait;	/* Region lock granted after wait. */
429 	uintmax_t st_region_nowait;	/* Region lock granted without wait. */
430 	uintmax_t st_nlockers_hit;	/* Lockers found in thread info. */
431 	uintmax_t st_nlockers_reused;	/* Lockers reallocated from thread info. */
432 	u_int32_t st_hash_len;		/* Max length of bucket. */
433 	roff_t	  st_regsize;		/* Region size. */
434 #endif
435 };
436 
437 struct __db_lock_hstat { /* SHARED */
438 	uintmax_t st_nrequests;		/* Number of lock gets. */
439 	uintmax_t st_nreleases;		/* Number of lock puts. */
440 	uintmax_t st_nupgrade;		/* Number of lock upgrades. */
441 	uintmax_t st_ndowngrade;	/* Number of lock downgrades. */
442 	u_int32_t st_nlocks;		/* Current number of locks. */
443 	u_int32_t st_maxnlocks;		/* Maximum number of locks so far. */
444 	u_int32_t st_nobjects;		/* Current number of objects. */
445 	u_int32_t st_maxnobjects;	/* Maximum number of objects so far. */
446 	uintmax_t st_lock_wait;		/* Lock conflicts w/ subsequent wait */
447 	uintmax_t st_lock_nowait;	/* Lock conflicts w/o subsequent wait */
448 	uintmax_t st_nlocktimeouts;	/* Number of lock timeouts. */
449 	uintmax_t st_ntxntimeouts;	/* Number of transaction timeouts. */
450 	u_int32_t st_hash_len;		/* Max length of bucket. */
451 };
452 
453 struct __db_lock_pstat { /* SHARED */
454 	u_int32_t st_nlocks;		/* Current number of locks. */
455 	u_int32_t st_maxnlocks;		/* Maximum number of locks so far. */
456 	u_int32_t st_nobjects;		/* Current number of objects. */
457 	u_int32_t st_maxnobjects;	/* Maximum number of objects so far. */
458 	uintmax_t st_locksteals;	/* Number of lock steals so far. */
459 	uintmax_t st_objectsteals;	/* Number of objects steals so far. */
460 };
461 
462 /*
463  * DB_LOCK_ILOCK --
464  *	Internal DB access method lock.
465  */
466 struct __db_ilock { /* SHARED */
467 	db_pgno_t pgno;			/* Page being locked. */
468 	u_int8_t fileid[DB_FILE_ID_LEN];/* File id. */
469 #define	DB_HANDLE_LOCK		1
470 #define	DB_RECORD_LOCK		2
471 #define	DB_PAGE_LOCK		3
472 #define	DB_DATABASE_LOCK	4
473 	u_int32_t type;			/* Type of lock. */
474 };
475 
476 /*
477  * DB_LOCK --
478  *	The structure is allocated by the caller and filled in during a
479  *	lock_get request (or a lock_vec/DB_LOCK_GET).
480  */
481 struct __db_lock_u { /* SHARED */
482 	roff_t		off;		/* Offset of the lock in the region */
483 	u_int32_t	ndx;		/* Index of the object referenced by
484 					 * this lock; used for locking. */
485 	u_int32_t	gen;		/* Generation number of this lock. */
486 	db_lockmode_t	mode;		/* mode of this lock. */
487 };
488 
489 /* Lock request structure. */
490 struct __db_lockreq {
491 	db_lockop_t	 op;		/* Operation. */
492 	db_lockmode_t	 mode;		/* Requested mode. */
493 	db_timeout_t	 timeout;	/* Time to expire lock. */
494 	DBT		*obj;		/* Object being locked. */
495 	DB_LOCK		 lock;		/* Lock returned. */
496 };
497 
498 /*******************************************************
499  * Logging.
500  *******************************************************/
501 #define	DB_LOGVERSION	23		/* Current log version. */
502 #define	DB_LOGVERSION_LATCHING 15	/* Log version using latching: db-4.8 */
503 #define	DB_LOGCHKSUM	12		/* Check sum headers: db-4.5 */
504 #define	DB_LOGOLDVER	8		/* Oldest version supported: db-4.2 */
505 #define	DB_LOGMAGIC	0x040988
506 
507 /*
508  * A DB_LSN has two parts, a fileid which identifies a specific file, and an
509  * offset within that file.  The fileid is an unsigned 4-byte quantity that
510  * uniquely identifies a file within the log directory -- currently a simple
511  * counter inside the log.  The offset is also an unsigned 4-byte value.  The
512  * log manager guarantees the offset is never more than 4 bytes by switching
513  * to a new log file before the maximum length imposed by an unsigned 4-byte
514  * offset is reached.
515  */
516 struct __db_lsn { /* SHARED */
517 	u_int32_t	file;		/* File ID. */
518 	u_int32_t	offset;		/* File offset. */
519 };
520 
521 /*
522  * Application-specified log record types start at DB_user_BEGIN, and must not
523  * equal or exceed DB_debug_FLAG.
524  *
525  * DB_debug_FLAG is the high-bit of the u_int32_t that specifies a log record
526  * type.  If the flag is set, it's a log record that was logged for debugging
527  * purposes only, even if it reflects a database change -- the change was part
528  * of a non-durable transaction.
529  */
530 #define	DB_user_BEGIN		10000
531 #define	DB_debug_FLAG		0x80000000
532 
533 /*
534  * DB_LOGC --
535  *	Log cursor.
536  */
537 struct __db_log_cursor {
538 	ENV	 *env;			/* Environment */
539 
540 	DB_FH	 *fhp;			/* File handle. */
541 	DB_LSN	  lsn;			/* Cursor: LSN */
542 	u_int32_t len;			/* Cursor: record length */
543 	u_int32_t prev;			/* Cursor: previous record's offset */
544 
545 	DBT	  dbt;			/* Return DBT. */
546 	DB_LSN    p_lsn;		/* Persist LSN. */
547 	u_int32_t p_version;		/* Persist version. */
548 
549 	u_int8_t *bp;			/* Allocated read buffer. */
550 	u_int32_t bp_size;		/* Read buffer length in bytes. */
551 	u_int32_t bp_rlen;		/* Read buffer valid data length. */
552 	DB_LSN	  bp_lsn;		/* Read buffer first byte LSN. */
553 
554 	u_int32_t bp_maxrec;		/* Max record length in the log file. */
555 
556 	/* DB_LOGC PUBLIC HANDLE LIST BEGIN */
557 	int (*close) __P((DB_LOGC *, u_int32_t));
558 	int (*get) __P((DB_LOGC *, DB_LSN *, DBT *, u_int32_t));
559 	int (*version) __P((DB_LOGC *, u_int32_t *, u_int32_t));
560 	/* DB_LOGC PUBLIC HANDLE LIST END */
561 
562 #define	DB_LOG_DISK		0x01	/* Log record came from disk. */
563 #define	DB_LOG_LOCKED		0x02	/* Log region already locked */
564 #define	DB_LOG_SILENT_ERR	0x04	/* Turn-off error messages. */
565 	u_int32_t flags;
566 };
567 
568 /* Log statistics structure. */
569 struct __db_log_stat { /* SHARED */
570 	u_int32_t st_magic;		/* Log file magic number. */
571 	u_int32_t st_version;		/* Log file version number. */
572 	int32_t   st_mode;		/* Log file permissions mode. */
573 	u_int32_t st_lg_bsize;		/* Log buffer size. */
574 	u_int32_t st_lg_size;		/* Log file size. */
575 	u_int32_t st_wc_bytes;		/* Bytes to log since checkpoint. */
576 	u_int32_t st_wc_mbytes;		/* Megabytes to log since checkpoint. */
577 	u_int32_t st_fileid_init;	/* Initial allocation for fileids. */
578 #ifndef __TEST_DB_NO_STATISTICS
579 	u_int32_t st_nfileid;		/* Current number of fileids. */
580 	u_int32_t st_maxnfileid;	/* Maximum number of fileids used. */
581 	uintmax_t st_record;		/* Records entered into the log. */
582 	u_int32_t st_w_bytes;		/* Bytes to log. */
583 	u_int32_t st_w_mbytes;		/* Megabytes to log. */
584 	uintmax_t st_wcount;		/* Total I/O writes to the log. */
585 	uintmax_t st_wcount_fill;	/* Overflow writes to the log. */
586 	uintmax_t st_rcount;		/* Total I/O reads from the log. */
587 	uintmax_t st_scount;		/* Total syncs to the log. */
588 	uintmax_t st_region_wait;	/* Region lock granted after wait. */
589 	uintmax_t st_region_nowait;	/* Region lock granted without wait. */
590 	u_int32_t st_cur_file;		/* Current log file number. */
591 	u_int32_t st_cur_offset;	/* Current log file offset. */
592 	u_int32_t st_disk_file;		/* Known on disk log file number. */
593 	u_int32_t st_disk_offset;	/* Known on disk log file offset. */
594 	u_int32_t st_maxcommitperflush;	/* Max number of commits in a flush. */
595 	u_int32_t st_mincommitperflush;	/* Min number of commits in a flush. */
596 	roff_t	  st_regsize;		/* Region size. */
597 #endif
598 };
599 
600 /*
601  * We need to record the first log record of a transaction.  For user
602  * defined logging this macro returns the place to put that information,
603  * if it is need in rlsnp, otherwise it leaves it unchanged.  We also
604  * need to track the last record of the transaction, this returns the
605  * place to put that info.
606  */
607 #define	DB_SET_TXN_LSNP(txn, blsnp, llsnp)		\
608 	((txn)->set_txn_lsnp(txn, blsnp, llsnp))
609 
610 /*
611  * Definition of the structure which specifies marshalling of log records.
612  */
613 typedef enum {
614 	LOGREC_Done,
615 	LOGREC_ARG,
616 	LOGREC_HDR,
617 	LOGREC_DATA,
618 	LOGREC_DB,
619 	LOGREC_DBOP,
620 	LOGREC_DBT,
621 	LOGREC_LOCKS,
622 	LOGREC_OP,
623 	LOGREC_PGDBT,
624 	LOGREC_PGDDBT,
625 	LOGREC_PGLIST,
626 	LOGREC_POINTER,
627 	LOGREC_TIME,
628 	LOGREC_LONGARG
629 } log_rec_type_t;
630 
631 typedef const struct __log_rec_spec {
632 	log_rec_type_t	type;
633 	u_int32_t	offset;
634 	const char 	*name;
635 	const char	fmt[4];
636 } DB_LOG_RECSPEC;
637 
638 /*
639  * Size of a DBT in a log record.
640  */
641 #define	LOG_DBT_SIZE(dbt)						\
642     (sizeof(u_int32_t) + ((dbt) == NULL ? 0 : (dbt)->size))
643 
644 /*******************************************************
645  * Shared buffer cache (mpool).
646  *******************************************************/
647 /* Priority values for DB_MPOOLFILE->{put,set_priority}. */
648 typedef enum {
649 	DB_PRIORITY_UNCHANGED=0,
650 	DB_PRIORITY_VERY_LOW=1,
651 	DB_PRIORITY_LOW=2,
652 	DB_PRIORITY_DEFAULT=3,
653 	DB_PRIORITY_HIGH=4,
654 	DB_PRIORITY_VERY_HIGH=5
655 } DB_CACHE_PRIORITY;
656 
657 /* Per-process DB_MPOOLFILE information. */
658 struct __db_mpoolfile {
659 	DB_FH	  *fhp;			/* Underlying file handle. */
660 
661 	/*
662 	 * !!!
663 	 * The ref, pinref and q fields are protected by the region lock.
664 	 */
665 	u_int32_t  ref;			/* Reference count. */
666 
667 	u_int32_t pinref;		/* Pinned block reference count. */
668 
669 	/*
670 	 * !!!
671 	 * Explicit representations of structures from queue.h.
672 	 * TAILQ_ENTRY(__db_mpoolfile) q;
673 	 */
674 	struct {
675 		struct __db_mpoolfile *tqe_next;
676 		struct __db_mpoolfile **tqe_prev;
677 	} q;				/* Linked list of DB_MPOOLFILE's. */
678 
679 	/*
680 	 * !!!
681 	 * The rest of the fields (with the exception of the MP_FLUSH flag)
682 	 * are not thread-protected, even when they may be modified at any
683 	 * time by the application.  The reason is the DB_MPOOLFILE handle
684 	 * is single-threaded from the viewpoint of the application, and so
685 	 * the only fields needing to be thread-protected are those accessed
686 	 * by checkpoint or sync threads when using DB_MPOOLFILE structures
687 	 * to flush buffers from the cache.
688 	 */
689 	ENV	       *env;		/* Environment */
690 	MPOOLFILE      *mfp;		/* Underlying MPOOLFILE. */
691 
692 	u_int32_t	clear_len;	/* Cleared length on created pages. */
693 	u_int8_t			/* Unique file ID. */
694 			fileid[DB_FILE_ID_LEN];
695 	int		ftype;		/* File type. */
696 	int32_t		lsn_offset;	/* LSN offset in page. */
697 	u_int32_t	gbytes, bytes;	/* Maximum file size. */
698 	DBT	       *pgcookie;	/* Byte-string passed to pgin/pgout. */
699 	int32_t		priority;	/* Cache priority. */
700 
701 	void	       *addr;		/* Address of mmap'd region. */
702 	size_t		len;		/* Length of mmap'd region. */
703 
704 	u_int32_t	config_flags;	/* Flags to DB_MPOOLFILE->set_flags. */
705 
706 	/* DB_MPOOLFILE PUBLIC HANDLE LIST BEGIN */
707 	int (*close) __P((DB_MPOOLFILE *, u_int32_t));
708 	int (*get)
709 	    __P((DB_MPOOLFILE *, db_pgno_t *, DB_TXN *, u_int32_t, void *));
710 	int (*get_clear_len) __P((DB_MPOOLFILE *, u_int32_t *));
711 	int (*get_fileid) __P((DB_MPOOLFILE *, u_int8_t *));
712 	int (*get_flags) __P((DB_MPOOLFILE *, u_int32_t *));
713 	int (*get_ftype) __P((DB_MPOOLFILE *, int *));
714 	int (*get_last_pgno) __P((DB_MPOOLFILE *, db_pgno_t *));
715 	int (*get_lsn_offset) __P((DB_MPOOLFILE *, int32_t *));
716 	int (*get_maxsize) __P((DB_MPOOLFILE *, u_int32_t *, u_int32_t *));
717 	int (*get_pgcookie) __P((DB_MPOOLFILE *, DBT *));
718 	int (*get_priority) __P((DB_MPOOLFILE *, DB_CACHE_PRIORITY *));
719 	int (*open) __P((DB_MPOOLFILE *, const char *, u_int32_t, int, size_t));
720 	int (*put) __P((DB_MPOOLFILE *, void *, DB_CACHE_PRIORITY, u_int32_t));
721 	int (*set_clear_len) __P((DB_MPOOLFILE *, u_int32_t));
722 	int (*set_fileid) __P((DB_MPOOLFILE *, u_int8_t *));
723 	int (*set_flags) __P((DB_MPOOLFILE *, u_int32_t, int));
724 	int (*set_ftype) __P((DB_MPOOLFILE *, int));
725 	int (*set_lsn_offset) __P((DB_MPOOLFILE *, int32_t));
726 	int (*set_maxsize) __P((DB_MPOOLFILE *, u_int32_t, u_int32_t));
727 	int (*set_pgcookie) __P((DB_MPOOLFILE *, DBT *));
728 	int (*set_priority) __P((DB_MPOOLFILE *, DB_CACHE_PRIORITY));
729 	int (*sync) __P((DB_MPOOLFILE *));
730 	/* DB_MPOOLFILE PUBLIC HANDLE LIST END */
731 
732 	/*
733 	 * MP_FILEID_SET, MP_OPEN_CALLED and MP_READONLY do not need to be
734 	 * thread protected because they are initialized before the file is
735 	 * linked onto the per-process lists, and never modified.
736 	 *
737 	 * MP_FLUSH is thread protected because it is potentially read/set by
738 	 * multiple threads of control.
739 	 */
740 #define	MP_FILEID_SET	0x001		/* Application supplied a file ID. */
741 #define	MP_FLUSH	0x002		/* Was used to flush a buffer. */
742 #define	MP_FOR_FLUSH	0x004		/* Was opened to flush a buffer. */
743 #define	MP_MULTIVERSION	0x008		/* Opened for multiversion access. */
744 #define	MP_OPEN_CALLED	0x010		/* File opened. */
745 #define	MP_READONLY	0x020		/* File is readonly. */
746 #define	MP_DUMMY	0x040		/* File is dummy for __memp_fput. */
747 	u_int32_t  flags;
748 };
749 
750 /* Mpool statistics structure. */
751 struct __db_mpool_stat { /* SHARED */
752 	u_int32_t st_gbytes;		/* Total cache size: GB. */
753 	u_int32_t st_bytes;		/* Total cache size: B. */
754 	u_int32_t st_ncache;		/* Number of cache regions. */
755 	u_int32_t st_max_ncache;	/* Maximum number of regions. */
756 	db_size_t st_mmapsize;		/* Maximum file size for mmap. */
757 	int32_t st_maxopenfd;		/* Maximum number of open fd's. */
758 	int32_t st_maxwrite;		/* Maximum buffers to write. */
759 	db_timeout_t st_maxwrite_sleep;	/* Sleep after writing max buffers. */
760 	u_int32_t st_pages;		/* Total number of pages. */
761 #ifndef __TEST_DB_NO_STATISTICS
762 	u_int32_t st_map;		/* Pages from mapped files. */
763 	uintmax_t st_cache_hit;	/* Pages found in the cache. */
764 	uintmax_t st_cache_miss;	/* Pages not found in the cache. */
765 	uintmax_t st_page_create;	/* Pages created in the cache. */
766 	uintmax_t st_page_in;		/* Pages read in. */
767 	uintmax_t st_page_out;		/* Pages written out. */
768 	uintmax_t st_ro_evict;		/* Clean pages forced from the cache. */
769 	uintmax_t st_rw_evict;		/* Dirty pages forced from the cache. */
770 	uintmax_t st_page_trickle;	/* Pages written by memp_trickle. */
771 	u_int32_t st_page_clean;	/* Clean pages. */
772 	u_int32_t st_page_dirty;	/* Dirty pages. */
773 	u_int32_t st_hash_buckets;	/* Number of hash buckets. */
774 	u_int32_t st_hash_mutexes;	/* Number of hash bucket mutexes. */
775 	u_int32_t st_pagesize;		/* Assumed page size. */
776 	u_int32_t st_hash_searches;	/* Total hash chain searches. */
777 	u_int32_t st_hash_longest;	/* Longest hash chain searched. */
778 	uintmax_t st_hash_examined;	/* Total hash entries searched. */
779 	uintmax_t st_hash_nowait;	/* Hash lock granted with nowait. */
780 	uintmax_t st_hash_wait;		/* Hash lock granted after wait. */
781 	uintmax_t st_hash_max_nowait;	/* Max hash lock granted with nowait. */
782 	uintmax_t st_hash_max_wait;	/* Max hash lock granted after wait. */
783 	uintmax_t st_region_nowait;	/* Region lock granted with nowait. */
784 	uintmax_t st_region_wait;	/* Region lock granted after wait. */
785 	uintmax_t st_mvcc_frozen;	/* Buffers frozen. */
786 	uintmax_t st_mvcc_thawed;	/* Buffers thawed. */
787 	uintmax_t st_mvcc_freed;	/* Frozen buffers freed. */
788 	uintmax_t st_mvcc_reused;	/* Outdated invisible buffers reused. */
789 	uintmax_t st_alloc;		/* Number of page allocations. */
790 	uintmax_t st_alloc_buckets;	/* Buckets checked during allocation. */
791 	uintmax_t st_alloc_max_buckets;/* Max checked during allocation. */
792 	uintmax_t st_alloc_pages;	/* Pages checked during allocation. */
793 	uintmax_t st_alloc_max_pages;	/* Max checked during allocation. */
794 	uintmax_t st_io_wait;		/* Thread waited on buffer I/O. */
795 	uintmax_t st_sync_interrupted;	/* Number of times sync interrupted. */
796 	u_int32_t st_oddfsize_detect;	/* Odd file size detected. */
797 	u_int32_t st_oddfsize_resolve;	/* Odd file size resolved. */
798 	roff_t	  st_regsize;		/* Region size. */
799 	roff_t	  st_regmax;		/* Region max. */
800 #endif
801 };
802 
803 /*
804  * Mpool file statistics structure.
805  * The first fields in this structure must mirror the __db_mpool_fstat_int
806  * structure, since content is mem copied between the two.
807  */
808 struct __db_mpool_fstat {
809 	u_int32_t st_pagesize;		/* Page size. */
810 #ifndef __TEST_DB_NO_STATISTICS
811 	u_int32_t st_map;		/* Pages from mapped files. */
812 	uintmax_t st_cache_hit;	/* Pages found in the cache. */
813 	uintmax_t st_cache_miss;	/* Pages not found in the cache. */
814 	uintmax_t st_page_create;	/* Pages created in the cache. */
815 	uintmax_t st_page_in;		/* Pages read in. */
816 	uintmax_t st_page_out;		/* Pages written out. */
817 	uintmax_t st_backup_spins;	/* Number of spins during a copy. */
818 #endif
819 	char *file_name;	/* File name. */
820 };
821 
822 /*******************************************************
823  * Transactions and recovery.
824  *******************************************************/
825 #define	DB_TXNVERSION	1
826 
827 typedef enum {
828 	DB_TXN_ABORT=0,			/* Public. */
829 	DB_TXN_APPLY=1,			/* Public. */
830 	DB_TXN_BACKWARD_ROLL=3,		/* Public. */
831 	DB_TXN_FORWARD_ROLL=4,		/* Public. */
832 	DB_TXN_OPENFILES=5,		/* Internal. */
833 	DB_TXN_POPENFILES=6,		/* Internal. */
834 	DB_TXN_PRINT=7,			/* Public. */
835 	DB_TXN_LOG_VERIFY=8		/* Internal. */
836 } db_recops;
837 
838 /*
839  * BACKWARD_ALLOC is used during the forward pass to pick up any aborted
840  * allocations for files that were created during the forward pass.
841  * The main difference between _ALLOC and _ROLL is that the entry for
842  * the file not exist during the rollforward pass.
843  */
844 #define	DB_UNDO(op)	((op) == DB_TXN_ABORT || (op) == DB_TXN_BACKWARD_ROLL)
845 #define	DB_REDO(op)	((op) == DB_TXN_FORWARD_ROLL || (op) == DB_TXN_APPLY)
846 
847 struct __db_txn {
848 	DB_TXNMGR	*mgrp;		/* Pointer to transaction manager. */
849 	DB_TXN		*parent;	/* Pointer to transaction's parent. */
850 	DB_THREAD_INFO	*thread_info;	/* Pointer to thread information. */
851 
852 	u_int32_t	cursors;	/* Number of cursors open for txn */
853 
854 	u_int32_t	txnid;		/* Unique transaction id. */
855 	char		*name;		/* Transaction name. */
856 	DB_LOCKER	*locker;	/* Locker for this txn. */
857 
858 	void		*td;		/* Detail structure within region. */
859 	db_timeout_t	lock_timeout;	/* Timeout for locks for this txn. */
860 	void		*txn_list;	/* Undo information for parent. */
861 
862 
863 	/*
864 	 * Txn_slices is __os_calloc'd with one potential entry for each
865 	 * slice. DML is allowed to set only one entry. DDL can have one per
866 	 * slice, but does not (in V1) guarantee atomicity between those txns.
867 	 */
868 	DB_TXN		**txn_slices;	/* Txns for this container's slices. */
869 	DB_TXN		*txn_container;	/* Container of this slice. */
870 
871 	/*
872 	 * !!!
873 	 * Explicit representations of structures from queue.h.
874 	 * TAILQ_ENTRY(__db_txn) links;
875 	 */
876 	struct {
877 		struct __db_txn *tqe_next;
878 		struct __db_txn **tqe_prev;
879 	} links;			/* Links transactions off manager. */
880 
881 	/*
882 	 * !!!
883 	 * Explicit representations of structures from shqueue.h.
884 	 * SH_TAILQ_ENTRY xa_links;
885 	 * These links link together transactions that are active in
886 	 * the same thread of control.
887 	 */
888 	struct {
889 		db_ssize_t stqe_next;
890 		db_ssize_t stqe_prev;
891 	} xa_links;			/* Links XA transactions. */
892 
893 	/*
894 	 * !!!
895 	 * Explicit representations of structures from queue.h.
896 	 * TAILQ_HEAD(__kids, __db_txn) kids;
897 	 */
898 	struct __kids {
899 		struct __db_txn *tqh_first;
900 		struct __db_txn **tqh_last;
901 	} kids;
902 
903 	/*
904 	 * !!!
905 	 * Explicit representations of structures from queue.h.
906 	 * TAILQ_HEAD(__events, __txn_event) events;
907 	 */
908 	struct {
909 		struct __txn_event *tqh_first;
910 		struct __txn_event **tqh_last;
911 	} events;			/* Links deferred events. */
912 
913 	/*
914 	 * !!!
915 	 * Explicit representations of structures from queue.h.
916 	 * STAILQ_HEAD(__logrec, __txn_logrec) logs;
917 	 */
918 	struct {
919 		struct __txn_logrec *stqh_first;
920 		struct __txn_logrec **stqh_last;
921 	} logs;				/* Links in memory log records. */
922 
923 	/*
924 	 * !!!
925 	 * Explicit representations of structures from queue.h.
926 	 * TAILQ_ENTRY(__db_txn) klinks;
927 	 */
928 	struct {
929 		struct __db_txn *tqe_next;
930 		struct __db_txn **tqe_prev;
931 	} klinks;			/* Links of children in parent. */
932 
933 	/*
934 	 * !!!
935 	 * Explicit representations of structures from queue.h.
936 	 * TAILQ_HEAD(__my_cursors, __dbc) my_cursors;
937 	 */
938 	struct __my_cursors {
939 		struct __dbc *tqh_first;
940 		struct __dbc **tqh_last;
941 	} my_cursors;
942 
943 	/*
944 	 * !!!
945 	 * Explicit representations of structures from queue.h.
946 	 * TAILQ_HEAD(__femfs, MPOOLFILE) femfs;
947 	 *
948 	 * These are DBs involved in file extension in this transaction.
949 	 */
950 	struct __femfs {
951 		DB *tqh_first;
952 		DB **tqh_last;
953 	} femfs;
954 
955 	DB_TXN_TOKEN	*token_buffer;	/* User's commit token buffer. */
956 	void	*api_internal;		/* C++ API private. */
957 	void	*xml_internal;		/* XML API private. */
958 
959 	/* DB_TXN PUBLIC HANDLE LIST BEGIN */
960 	int	  (*abort) __P((DB_TXN *));
961 	int	  (*commit) __P((DB_TXN *, u_int32_t));
962 	int	  (*discard) __P((DB_TXN *, u_int32_t));
963 	int	  (*get_name) __P((DB_TXN *, const char **));
964 	int	  (*get_priority) __P((DB_TXN *, u_int32_t *));
965 	u_int32_t (*id) __P((DB_TXN *));
966 	int	  (*prepare) __P((DB_TXN *, u_int8_t *));
967 	int	  (*set_commit_token) __P((DB_TXN *, DB_TXN_TOKEN *));
968 	int	  (*set_name) __P((DB_TXN *, const char *));
969 	int	  (*set_priority) __P((DB_TXN *, u_int32_t));
970 	int	  (*set_timeout) __P((DB_TXN *, db_timeout_t, u_int32_t));
971 	/* DB_TXN PUBLIC HANDLE LIST END */
972 
973 	/* DB_TXN PRIVATE HANDLE LIST BEGIN */
974 	void	  (*set_txn_lsnp) __P((DB_TXN *txn, DB_LSN **, DB_LSN **));
975 	/* DB_TXN PRIVATE HANDLE LIST END */
976 
977 #define	TXN_XA_THREAD_NOTA		0
978 #define	TXN_XA_THREAD_ASSOCIATED	1
979 #define	TXN_XA_THREAD_SUSPENDED		2
980 #define	TXN_XA_THREAD_UNASSOCIATED 	3
981 	u_int32_t	xa_thr_status;
982 
983 #define	TXN_CHILDCOMMIT		0x00001	/* Txn has committed. */
984 #define	TXN_DISPATCH		0x00002	/* Internal; use for __db_dispatch(). */
985 #define	TXN_DEADLOCK		0x00004	/* Txn has deadlocked. */
986 #define	TXN_FAMILY		0x00008	/* Cursors/children are independent. */
987 #define	TXN_IGNORE_LEASE	0x00010	/* Skip lease check at commit time. */
988 #define	TXN_INFAMILY		0x00020	/* Part of a transaction family. */
989 #define	TXN_LOCKTIMEOUT		0x00040	/* Txn has a lock timeout. */
990 #define	TXN_MALLOC		0x00080	/* Structure allocated by TXN system. */
991 #define	TXN_NOSYNC		0x00100	/* Do not sync on prepare and commit. */
992 #define	TXN_NOWAIT		0x00200	/* Do not wait on locks. */
993 #define	TXN_PRIVATE		0x00400	/* Txn owned by cursor. */
994 #define	TXN_READONLY		0x00800	/* CDS group handle. */
995 #define	TXN_READ_COMMITTED	0x01000	/* Txn has degree 2 isolation. */
996 #define	TXN_READ_UNCOMMITTED	0x02000	/* Txn has degree 1 isolation. */
997 #define	TXN_RESTORED		0x04000	/* Txn has been restored. */
998 #define	TXN_SNAPSHOT		0x08000	/* Snapshot Isolation. */
999 #define	TXN_SYNC		0x10000	/* Write and sync on prepare/commit. */
1000 #define	TXN_WRITE_NOSYNC	0x20000	/* Write only on prepare/commit. */
1001 #define	TXN_BULK		0x40000 /* Enable bulk loading optimization. */
1002 	u_int32_t	flags;
1003 
1004 	u_int32_t	begin_flags;	/* Saved by txn_begin(), for slices. */
1005 };
1006 
1007 #define	TXN_SYNC_FLAGS (TXN_SYNC | TXN_NOSYNC | TXN_WRITE_NOSYNC)
1008 
1009 /*
1010  * Structure used for two phase commit interface.
1011  * We set the size of our global transaction id (gid) to be 128 in order
1012  * to match that defined by the XA X/Open standard.
1013  */
1014 #define	DB_GID_SIZE	128
1015 struct __db_preplist {
1016 	DB_TXN	*txn;
1017 	u_int8_t gid[DB_GID_SIZE];
1018 };
1019 
1020 /*
1021  * Active transaction statistics for slices.
1022  * If a container's transaction touches any slices, its TXN_DETAIL.slice_details
1023  * has a DB_ENV->slice_cnt sized array in shared memory of these. Entries whose
1024  * txnid is not TXN_INVALID are active. The slice number is implied by the
1025  * position in the array.
1026  */
1027 struct __db_txn_active_slice {
1028 	u_int32_t txnid;		/* Txnid in that slice  */
1029 };
1030 
1031 /* Active transaction statistics structure. */
1032 struct __db_txn_active {
1033 	u_int32_t txnid;		/* Transaction ID */
1034 	u_int32_t parentid;		/* Transaction ID of parent */
1035 	pid_t     pid;			/* Process owning txn ID */
1036 	db_threadid_t tid;		/* Thread owning txn ID */
1037 
1038 	DB_LSN	  lsn;			/* LSN when transaction began */
1039 
1040 	DB_LSN	  read_lsn;		/* Read LSN for MVCC */
1041 	u_int32_t mvcc_ref;		/* MVCC reference count */
1042 
1043 	u_int32_t priority;		/* Deadlock resolution priority */
1044 
1045 #define	TXN_ABORTED		1
1046 #define	TXN_COMMITTED		2
1047 #define	TXN_NEED_ABORT		3
1048 #define	TXN_PREPARED		4
1049 #define	TXN_RUNNING		5
1050 	u_int32_t status;		/* Status of the transaction */
1051 
1052 #define	TXN_XA_ACTIVE		1
1053 #define	TXN_XA_DEADLOCKED	2
1054 #define	TXN_XA_IDLE		3
1055 #define	TXN_XA_PREPARED		4
1056 #define	TXN_XA_ROLLEDBACK	5
1057 	u_int32_t xa_status;		/* XA status */
1058 
1059 	u_int8_t  gid[DB_GID_SIZE];	/* Global transaction ID */
1060 	char	  name[51];		/* 50 bytes of name, nul termination */
1061 
1062 	/*
1063 	 * This array of txnids can either be NULL, or it is a
1064 	 * DB_ENV->get_slice_count()-sized array. Any slices which have active
1065 	 * subordinate transactions have non-empty entries.
1066 	 */
1067 	DB_TXN_ACTIVE_SLICE *slice_txns;
1068 };
1069 
1070 struct __db_txn_stat {
1071 	u_int32_t st_nrestores;		/* number of restored transactions
1072 					   after recovery. */
1073 #ifndef __TEST_DB_NO_STATISTICS
1074 	DB_LSN	  st_last_ckp;		/* lsn of the last checkpoint */
1075 	time_t	  st_time_ckp;		/* time of last checkpoint */
1076 	u_int32_t st_last_txnid;	/* last transaction id given out */
1077 	u_int32_t st_inittxns;		/* inital txns allocated */
1078 	u_int32_t st_maxtxns;		/* maximum txns possible */
1079 	uintmax_t st_naborts;		/* number of aborted transactions */
1080 	uintmax_t st_nbegins;		/* number of begun transactions */
1081 	uintmax_t st_ncommits;		/* number of committed transactions */
1082 	u_int32_t st_nactive;		/* number of active transactions */
1083 	u_int32_t st_nsnapshot;		/* number of snapshot transactions */
1084 	u_int32_t st_maxnactive;	/* maximum active transactions */
1085 	u_int32_t st_maxnsnapshot;	/* maximum snapshot transactions */
1086 	uintmax_t st_region_wait;	/* Region lock granted after wait. */
1087 	uintmax_t st_region_nowait;	/* Region lock granted without wait. */
1088 	roff_t	  st_regsize;		/* Region size. */
1089 	DB_TXN_ACTIVE *st_txnarray;	/* array of active transactions */
1090 #endif
1091 };
1092 
1093 #define	DB_TXN_TOKEN_SIZE		20
1094 struct __db_txn_token {
1095 	u_int8_t buf[DB_TXN_TOKEN_SIZE];
1096 };
1097 
1098 /*******************************************************
1099  * Replication.
1100  *******************************************************/
1101 /* Special, out-of-band environment IDs. */
1102 #define	DB_EID_BROADCAST	-1
1103 #define	DB_EID_INVALID		-2
1104 #define	DB_EID_MASTER		-3
1105 
1106 #define	DB_REP_DEFAULT_PRIORITY		100
1107 
1108 /* Acknowledgement policies; 0 reserved as OOB. */
1109 #define	DB_REPMGR_ACKS_ALL		1
1110 #define	DB_REPMGR_ACKS_ALL_AVAILABLE	2
1111 #define	DB_REPMGR_ACKS_ALL_PEERS	3
1112 #define	DB_REPMGR_ACKS_NONE		4
1113 #define	DB_REPMGR_ACKS_ONE		5
1114 #define	DB_REPMGR_ACKS_ONE_PEER		6
1115 #define	DB_REPMGR_ACKS_QUORUM		7
1116 
1117 /* Configuration options for SSL support for Replication Manager */
1118 #define DB_REPMGR_SSL_CA_CERT			1 /* CA Cert Location */
1119 #define DB_REPMGR_SSL_CA_DIR			2 /* CA Cert Directory */
1120 #define DB_REPMGR_SSL_REPNODE_CERT		3 /* RepNode Cert for auth */
1121 #define DB_REPMGR_SSL_REPNODE_PRIVATE_KEY	4 /* Repnode Cert Private key */
1122 #define DB_REPMGR_SSL_REPNODE_KEY_PASSWD	5 /* Password for Private key */
1123 #define DB_REPMGR_SSL_VERIFY_DEPTH		6 /* SSL verification depth */
1124 
1125 /* Replication timeout configuration values. */
1126 #define	DB_REP_ACK_TIMEOUT		1	/* RepMgr acknowledgements. */
1127 #define	DB_REP_CHECKPOINT_DELAY		2	/* Master checkpoint delay. */
1128 #define	DB_REP_CONNECTION_RETRY		3	/* RepMgr connections. */
1129 #define	DB_REP_ELECTION_RETRY		4	/* RepMgr elect retries. */
1130 #define	DB_REP_ELECTION_TIMEOUT		5	/* Rep normal elections. */
1131 #define	DB_REP_FULL_ELECTION_TIMEOUT	6	/* Rep full elections. */
1132 #define	DB_REP_HEARTBEAT_MONITOR	7	/* RepMgr client HB monitor. */
1133 #define	DB_REP_HEARTBEAT_SEND		8	/* RepMgr master send freq. */
1134 #define	DB_REP_LEASE_TIMEOUT		9	/* Master leases. */
1135 #define	DB_REP_WRITE_FORWARD_TIMEOUT	10	/* Write forwarding. */
1136 
1137 /*
1138  * Event notification types.  (Tcl testing interface currently assumes there are
1139  * no more than 32 of these.). Comments include any relevant event_info types.
1140  */
1141 #define	DB_EVENT_PANIC			 0
1142 #define	DB_EVENT_REG_ALIVE		 1	/* int: pid which was in env */
1143 #define	DB_EVENT_REG_PANIC		 2	/* int: error causing the panic. */
1144 #define	DB_EVENT_REP_AUTOTAKEOVER	 3
1145 #define	DB_EVENT_REP_AUTOTAKEOVER_FAILED 4
1146 #define	DB_EVENT_REP_CLIENT		 5
1147 #define	DB_EVENT_REP_CONNECT_BROKEN	 6	/* DB_REPMGR_CONN_ERR */
1148 #define	DB_EVENT_REP_CONNECT_ESTD	 7	/* int: EID of remote site */
1149 #define	DB_EVENT_REP_CONNECT_TRY_FAILED	 8	/* DB_REPMGR_CONN_ERR */
1150 #define	DB_EVENT_REP_DUPMASTER		 9
1151 #define	DB_EVENT_REP_ELECTED		10
1152 #define	DB_EVENT_REP_ELECTION_FAILED	11
1153 #define	DB_EVENT_REP_INIT_DONE		12
1154 #define	DB_EVENT_REP_INQUEUE_FULL	13
1155 #define	DB_EVENT_REP_JOIN_FAILURE	14
1156 #define	DB_EVENT_REP_LOCAL_SITE_REMOVED	15
1157 #define	DB_EVENT_REP_MASTER		16
1158 #define	DB_EVENT_REP_MASTER_FAILURE	17
1159 #define	DB_EVENT_REP_NEWMASTER		18	/* int: new master's site id */
1160 #define	DB_EVENT_REP_PERM_FAILED	19
1161 #define	DB_EVENT_REP_SITE_ADDED		20	/* int: eid */
1162 #define	DB_EVENT_REP_SITE_REMOVED	21	/* int: eid */
1163 #define	DB_EVENT_REP_STARTUPDONE	22
1164 #define	DB_EVENT_REP_WOULD_ROLLBACK	23	/* Undocumented; C API only. */
1165 #define	DB_EVENT_WRITE_FAILED		24
1166 #define	DB_EVENT_MUTEX_DIED		25	/* DB_EVENT_MUTEX_DIED_INFO */
1167 #define	DB_EVENT_FAILCHK_PANIC		26	/* DB_EVENT_FAILCHK_INFO */
1168 #define	DB_EVENT_NO_SUCH_EVENT		 0xffffffff /* OOB sentinel value */
1169 
1170 /* Supported network event polling methods */
1171 typedef enum {
1172 	SELECT=1,
1173 	POLL=2,
1174 	EPOLL=3
1175 } poll_method_t;
1176 
1177 #if defined(HAVE_EPOLL_CREATE) && defined(HAVE_EPOLL_CTL) && defined(HAVE_EPOLL_WAIT)
1178 #define	HAVE_EPOLL	1
1179 #endif
1180 
1181 /* Replication Manager site status. */
1182 struct __db_repmgr_site {
1183 	int eid;
1184 	char *host;
1185 	u_int port;
1186 	DB_LSN max_ack_lsn;
1187 
1188 #define	DB_REPMGR_CONNECTED	1
1189 #define	DB_REPMGR_DISCONNECTED	2
1190 	u_int32_t status;
1191 
1192 #define	DB_REPMGR_ISELECTABLE	0x01
1193 #define	DB_REPMGR_ISPEER	0x02
1194 #define	DB_REPMGR_ISVIEW	0x04
1195 	u_int32_t flags;
1196 };
1197 
1198 /* Replication statistics. */
1199 struct __db_rep_stat { /* SHARED */
1200 	/* !!!
1201 	 * Many replication statistics fields cannot be protected by a mutex
1202 	 * without an unacceptable performance penalty, since most message
1203 	 * processing is done without the need to hold a region-wide lock.
1204 	 * Fields whose comments end with a '+' may be updated without holding
1205 	 * the replication or log mutexes (as appropriate), and thus may be
1206 	 * off somewhat (or, on unreasonable architectures under unlucky
1207 	 * circumstances, garbaged).
1208 	 */
1209 	u_int32_t st_startup_complete;	/* Site completed client sync-up. */
1210 	u_int32_t st_view;		/* Site is a view. */
1211 #ifndef __TEST_DB_NO_STATISTICS
1212 	uintmax_t st_log_queued;	/* Log records currently queued.+ */
1213 	u_int32_t st_status;		/* Current replication status. */
1214 	DB_LSN st_next_lsn;		/* Next LSN to use or expect. */
1215 	DB_LSN st_waiting_lsn;		/* LSN we're awaiting, if any. */
1216 	DB_LSN st_max_perm_lsn;		/* Maximum permanent LSN. */
1217 	db_pgno_t st_next_pg;		/* Next pg we expect. */
1218 	db_pgno_t st_waiting_pg;	/* pg we're awaiting, if any. */
1219 
1220 	u_int32_t st_dupmasters;	/* # of times a duplicate master
1221 					   condition was detected.+ */
1222 	db_ssize_t st_env_id;		/* Current environment ID. */
1223 	u_int32_t st_env_priority;	/* Current environment priority. */
1224 	uintmax_t st_ext_duplicated;	/* Dup ext file data messages.+ */
1225 	uintmax_t st_ext_records;	/* # of ext file data messages.+ */
1226 	uintmax_t st_ext_rereq;		/* Ext file chunk re-requests.+ */
1227 	uintmax_t st_ext_update_rereq;	/* Ext file update re-requests. + */
1228 	uintmax_t st_bulk_fills;	/* Bulk buffer fills. */
1229 	uintmax_t st_bulk_overflows;	/* Bulk buffer overflows. */
1230 	uintmax_t st_bulk_records;	/* Bulk records stored. */
1231 	uintmax_t st_bulk_transfers;	/* Transfers of bulk buffers. */
1232 	uintmax_t st_client_rerequests;/* Number of forced rerequests. */
1233 	uintmax_t st_client_svc_req;	/* Number of client service requests
1234 					   received by this client. */
1235 	uintmax_t st_client_svc_miss;	/* Number of client service requests
1236 					   missing on this client. */
1237 	u_int32_t st_gen;		/* Current generation number. */
1238 	u_int32_t st_egen;		/* Current election gen number. */
1239 	uintmax_t st_lease_chk;		/* Lease validity checks. */
1240 	uintmax_t st_lease_chk_misses;	/* Lease checks invalid. */
1241 	uintmax_t st_lease_chk_refresh;	/* Lease refresh attempts. */
1242 	uintmax_t st_lease_sends;	/* Lease messages sent live. */
1243 
1244 	uintmax_t st_log_duplicated;	/* Log records received multiply.+ */
1245 	uintmax_t st_log_queued_max;	/* Max. log records queued at once.+ */
1246 	uintmax_t st_log_queued_total;	/* Total # of log recs. ever queued.+ */
1247 	uintmax_t st_log_records;	/* Log records received and put.+ */
1248 	uintmax_t st_log_requested;	/* Log recs. missed and requested.+ */
1249 	db_ssize_t st_master;		/* Env. ID of the current master. */
1250 	uintmax_t st_master_changes;	/* # of times we've switched masters. */
1251 	uintmax_t st_msgs_badgen;	/* Messages with a bad generation #.+ */
1252 	uintmax_t st_msgs_processed;	/* Messages received and processed.+ */
1253 	uintmax_t st_msgs_recover;	/* Messages ignored because this site
1254 					   was a client in recovery.+ */
1255 	uintmax_t st_msgs_send_failures;/* # of failed message sends.+ */
1256 	uintmax_t st_msgs_sent;	/* # of successful message sends.+ */
1257 	uintmax_t st_newsites;		/* # of NEWSITE msgs. received.+ */
1258 	u_int32_t st_nsites;		/* Current number of sites we will
1259 					   assume during elections. */
1260 	uintmax_t st_nthrottles;	/* # of times we were throttled. */
1261 	uintmax_t st_outdated;		/* # of times we detected and returned
1262 					   an OUTDATED condition.+ */
1263 	uintmax_t st_pg_duplicated;	/* Pages received multiply.+ */
1264 	uintmax_t st_pg_records;	/* Pages received and stored.+ */
1265 	uintmax_t st_pg_requested;	/* Pages missed and requested.+ */
1266 	uintmax_t st_txns_applied;	/* # of transactions applied.+ */
1267 	uintmax_t st_startsync_delayed;/* # of STARTSYNC msgs delayed.+ */
1268 
1269 	/* Elections generally. */
1270 	uintmax_t st_elections;	/* # of elections held.+ */
1271 	uintmax_t st_elections_won;	/* # of elections won by this site.+ */
1272 
1273 	/* Statistics about an in-progress election. */
1274 	db_ssize_t st_election_cur_winner;	/* Current front-runner. */
1275 	u_int32_t st_election_gen;	/* Election generation number. */
1276 	u_int32_t st_election_datagen;	/* Election data generation number. */
1277 	DB_LSN st_election_lsn;		/* Max. LSN of current winner. */
1278 	u_int32_t st_election_nsites;	/* # of "registered voters". */
1279 	u_int32_t st_election_nvotes;	/* # of "registered voters" needed. */
1280 	u_int32_t st_election_priority;	/* Current election priority. */
1281 	int32_t   st_election_status;	/* Current election status. */
1282 	u_int32_t st_election_tiebreaker;/* Election tiebreaker value. */
1283 	u_int32_t st_election_votes;	/* Votes received in this round. */
1284 	u_int32_t st_election_sec;	/* Last election time seconds. */
1285 	u_int32_t st_election_usec;	/* Last election time useconds. */
1286 	u_int32_t st_max_lease_sec;	/* Maximum lease timestamp seconds. */
1287 	u_int32_t st_max_lease_usec;	/* Maximum lease timestamp useconds. */
1288 
1289 	/* Undocumented statistics only used by the test system. */
1290 #ifdef	CONFIG_TEST
1291 	uintmax_t st_ext_deleted;	/* Ext files deleted during II.+ */
1292 	uintmax_t st_ext_truncated;	/* Ext files shortened during II.+ */
1293 	u_int32_t st_filefail_cleanups;	/* # of FILE_FAIL cleanups done. */
1294 	uintmax_t st_log_futuredup;	/* Future log records that are dups. */
1295 #endif
1296 #endif
1297 };
1298 
1299 /* Replication Manager statistics. */
1300 struct __db_repmgr_stat { /* SHARED */
1301 	uintmax_t st_perm_failed;	/* # of insufficiently ack'ed msgs. */
1302 	uintmax_t st_msgs_queued;	/* # msgs queued for network delay. */
1303 	uintmax_t st_msgs_dropped;	/* # msgs discarded due to excessive
1304 					   queue length. */
1305 	u_int32_t st_incoming_queue_gbytes;	/* Incoming queue size: GB. */
1306 	u_int32_t st_incoming_queue_bytes;	/* Incoming queue size: B. */
1307 	uintmax_t st_incoming_msgs_dropped;	/* # of msgs discarded due to
1308 						   incoming queue full. */
1309 	uintmax_t st_connection_drop;	/* Existing connections dropped. */
1310 	uintmax_t st_connect_fail;	/* Failed new connection attempts. */
1311 	u_int32_t st_elect_threads;	/* # of active election threads. */
1312 	u_int32_t st_group_stable_log_file;	/* Earliest log file still
1313 		  				   needed by repgroup. */
1314 	u_int32_t st_max_elect_threads;	/* Max concurrent e-threads ever. */
1315 	u_int32_t st_site_participants;	/* # of repgroup participant sites. */
1316 	u_int32_t st_site_total;	/* # of repgroup total sites. */
1317 	u_int32_t st_site_views;	/* # of repgroup view sites. */
1318 	u_int32_t st_polling_method;	/* 1=select, 2=poll, 3=epoll. */
1319 	uintmax_t st_takeovers;		/* # of automatic listener takeovers. */
1320 	uintmax_t st_write_ops_forwarded;	/* # of writes forwarded by
1321 		  				   this client. */
1322 	uintmax_t st_write_ops_received;	/* # of forwarded writes
1323 		  				   received by this master. */
1324 };
1325 
1326 /* Replication Manager connection error. */
1327 struct __db_repmgr_conn_err {
1328 	int		eid;		/* Replication Environment ID. */
1329 	int		error;		/* System networking error code. */
1330 };
1331 
1332 /* Replication Manager socket. */
1333 typedef int DB_REPMGR_SOCKET;
1334 
1335 /*******************************************************
1336  * Sequences.
1337  *******************************************************/
1338 /*
1339  * The storage record for a sequence.
1340  */
1341 struct __db_seq_record {
1342 	u_int32_t	seq_version;	/* Version size/number. */
1343 	u_int32_t	flags;		/* DB_SEQ_XXX Flags. */
1344 	db_seq_t	seq_value;	/* Current value. */
1345 	db_seq_t	seq_max;	/* Max permitted. */
1346 	db_seq_t	seq_min;	/* Min permitted. */
1347 };
1348 
1349 /*
1350  * Handle for a sequence object.
1351  */
1352 struct __db_sequence {
1353 	DB		*seq_dbp;	/* DB handle for this sequence. */
1354 	db_mutex_t	mtx_seq;	/* Mutex if sequence is threaded. */
1355 	DB_SEQ_RECORD	*seq_rp;	/* Pointer to current data. */
1356 	DB_SEQ_RECORD	seq_record;	/* Data from DB_SEQUENCE. */
1357 	u_int32_t	seq_cache_size; /* Number of values cached. */
1358 	db_seq_t	seq_last_value;	/* Last value cached. */
1359 	db_seq_t	seq_prev_value;	/* Last value returned. */
1360 	DBT		seq_key;	/* DBT pointing to sequence key. */
1361 	DBT		seq_data;	/* DBT pointing to seq_record. */
1362 
1363 	/* API-private structure: used by C++ and Java. */
1364 	void		*api_internal;
1365 
1366 	/* DB_SEQUENCE PUBLIC HANDLE LIST BEGIN */
1367 	int		(*close) __P((DB_SEQUENCE *, u_int32_t));
1368 	int		(*get) __P((DB_SEQUENCE *,
1369 			      DB_TXN *, u_int32_t, db_seq_t *, u_int32_t));
1370 	int		(*get_cachesize) __P((DB_SEQUENCE *, u_int32_t *));
1371 	int		(*get_db) __P((DB_SEQUENCE *, DB **));
1372 	int		(*get_flags) __P((DB_SEQUENCE *, u_int32_t *));
1373 	int		(*get_key) __P((DB_SEQUENCE *, DBT *));
1374 	int		(*get_range) __P((DB_SEQUENCE *,
1375 			     db_seq_t *, db_seq_t *));
1376 	int		(*initial_value) __P((DB_SEQUENCE *, db_seq_t));
1377 	int		(*open) __P((DB_SEQUENCE *,
1378 			    DB_TXN *, DBT *, u_int32_t));
1379 	int		(*remove) __P((DB_SEQUENCE *, DB_TXN *, u_int32_t));
1380 	int		(*set_cachesize) __P((DB_SEQUENCE *, u_int32_t));
1381 	int		(*set_flags) __P((DB_SEQUENCE *, u_int32_t));
1382 	int		(*set_range) __P((DB_SEQUENCE *, db_seq_t, db_seq_t));
1383 	int		(*stat) __P((DB_SEQUENCE *,
1384 			    DB_SEQUENCE_STAT **, u_int32_t));
1385 	int		(*stat_print) __P((DB_SEQUENCE *, u_int32_t));
1386 	/* DB_SEQUENCE PUBLIC HANDLE LIST END */
1387 };
1388 
1389 struct __db_seq_stat { /* SHARED */
1390 	uintmax_t st_wait;		/* Sequence lock granted w/o wait. */
1391 	uintmax_t st_nowait;		/* Sequence lock granted after wait. */
1392 	db_seq_t  st_current;		/* Current value in db. */
1393 	db_seq_t  st_value;		/* Current cached value. */
1394 	db_seq_t  st_last_value;	/* Last cached value. */
1395 	db_seq_t  st_min;		/* Minimum value. */
1396 	db_seq_t  st_max;		/* Maximum value. */
1397 	u_int32_t st_cache_size;	/* Cache size. */
1398 	u_int32_t st_flags;		/* Flag value. */
1399 };
1400 
1401 /*******************************************************
1402  * Access methods.
1403  *******************************************************/
1404 /*
1405  * Any new methods need to retain the original numbering.  The type
1406  * is written in a log record so must be maintained.
1407  */
1408 typedef enum {
1409 	DB_BTREE=1,
1410 	DB_HASH=2,
1411 	DB_HEAP=6,
1412 	DB_RECNO=3,
1413 	DB_QUEUE=4,
1414 	DB_UNKNOWN=5			/* Figure it out on open. */
1415 } DBTYPE;
1416 
1417 #define	DB_RENAMEMAGIC	0x030800	/* File has been renamed. */
1418 
1419 #define	DB_BTREEVERSION	10		/* Current btree version. */
1420 #define	DB_BTREEOLDVER	8		/* Oldest btree version supported. */
1421 #define	DB_BTREEMAGIC	0x053162
1422 
1423 #define	DB_HASHVERSION	10		/* Current hash version. */
1424 #define	DB_HASHOLDVER	7		/* Oldest hash version supported. */
1425 #define	DB_HASHMAGIC	0x061561
1426 
1427 #define	DB_HEAPVERSION	2		/* Current heap version. */
1428 #define	DB_HEAPOLDVER	1		/* Oldest heap version supported. */
1429 #define	DB_HEAPMAGIC	0x074582
1430 
1431 #define	DB_QAMVERSION	4		/* Current queue version. */
1432 #define	DB_QAMOLDVER	3		/* Oldest queue version supported. */
1433 #define	DB_QAMMAGIC	0x042253
1434 
1435 #define	DB_SEQUENCE_VERSION 2		/* Current sequence version. */
1436 #define	DB_SEQUENCE_OLDVER  1		/* Oldest sequence version supported. */
1437 
1438 /*
1439  * DB access method and cursor operation values.  Each value is an operation
1440  * code to which additional bit flags are added.
1441  */
1442 #define	DB_AFTER		 1	/* Dbc.put */
1443 #define	DB_APPEND		 2	/* Db.put */
1444 #define	DB_BEFORE		 3	/* Dbc.put */
1445 #define	DB_CONSUME		 4	/* Db.get */
1446 #define	DB_CONSUME_WAIT		 5	/* Db.get */
1447 #define	DB_CURRENT		 6	/* Dbc.get, Dbc.put, DbLogc.get */
1448 #define	DB_FIRST		 7	/* Dbc.get, DbLogc->get */
1449 #define	DB_GET_BOTH		 8	/* Db.get, Dbc.get */
1450 #define	DB_GET_BOTHC		 9	/* Dbc.get (internal) */
1451 #define	DB_GET_BOTH_RANGE	10	/* Db.get, Dbc.get */
1452 #define	DB_GET_RECNO		11	/* Dbc.get */
1453 #define	DB_JOIN_ITEM		12	/* Dbc.get; don't do primary lookup */
1454 #define	DB_KEYFIRST		13	/* Dbc.put */
1455 #define	DB_KEYLAST		14	/* Dbc.put */
1456 #define	DB_LAST			15	/* Dbc.get, DbLogc->get */
1457 #define	DB_NEXT			16	/* Dbc.get, DbLogc->get */
1458 #define	DB_NEXT_DUP		17	/* Dbc.get */
1459 #define	DB_NEXT_NODUP		18	/* Dbc.get */
1460 #define	DB_NODUPDATA		19	/* Db.put, Dbc.put */
1461 #define	DB_NOOVERWRITE		20	/* Db.put */
1462 #define	DB_OVERWRITE_DUP	21	/* Dbc.put, Db.put; no DB_KEYEXIST */
1463 #define	DB_POSITION		22	/* Dbc.dup */
1464 #define	DB_PREV			23	/* Dbc.get, DbLogc->get */
1465 #define	DB_PREV_DUP		24	/* Dbc.get */
1466 #define	DB_PREV_NODUP		25	/* Dbc.get */
1467 #define	DB_SET			26	/* Dbc.get, DbLogc->get */
1468 #define	DB_SET_RANGE		27	/* Dbc.get */
1469 #define	DB_SET_RECNO		28	/* Db.get, Dbc.get */
1470 #define	DB_UPDATE_SECONDARY	29	/* Dbc.get, Dbc.del (internal) */
1471 #define	DB_SET_LTE		30	/* Dbc.get (internal) */
1472 #define	DB_GET_BOTH_LTE		31	/* Dbc.get (internal) */
1473 
1474 /* This has to change when the max opcode hits 255. */
1475 #define	DB_OPFLAGS_MASK	0x000000ff	/* Mask for operations flags. */
1476 
1477 /*
1478  * DB (user visible) error return codes.
1479  *
1480  * !!!
1481  * We don't want our error returns to conflict with other packages where
1482  * possible, so pick a base error value that's hopefully not common.  We
1483  * document that we own the error name space from -30,800 to -30,999.
1484  */
1485 /* DB (public) error return codes. */
1486 #define	DB_BUFFER_SMALL		(-30999)/* User memory too small for return. */
1487 #define	DB_DONOTINDEX		(-30998)/* "Null" return from 2ndary callbk. */
1488 #define	DB_FOREIGN_CONFLICT	(-30997)/* A foreign db constraint triggered. */
1489 #define	DB_HEAP_FULL		(-30996)/* No free space in a heap file. */
1490 #define	DB_KEYEMPTY		(-30995)/* Key/data deleted or never created. */
1491 #define	DB_KEYEXIST		(-30994)/* The key/data pair already exists. */
1492 #define	DB_LOCK_DEADLOCK	(-30993)/* Deadlock. */
1493 #define	DB_LOCK_NOTGRANTED	(-30992)/* Lock unavailable. */
1494 #define	DB_LOG_BUFFER_FULL	(-30991)/* In-memory log buffer full. */
1495 #define	DB_LOG_VERIFY_BAD	(-30990)/* Log verification failed. */
1496 #define	DB_META_CHKSUM_FAIL	(-30989)/* Metadata page checksum failed. */
1497 #define	DB_NOSERVER		(-30988)/* Server panic return. */
1498 #define	DB_NOTFOUND		(-30987)/* Key/data pair not found (EOF). */
1499 #define	DB_OLD_VERSION		(-30986)/* Out-of-date version. */
1500 #define	DB_PAGE_NOTFOUND	(-30985)/* Requested page not found. */
1501 #define	DB_REP_DUPMASTER	(-30984)/* There are two masters. */
1502 #define	DB_REP_HANDLE_DEAD	(-30983)/* Rolled back a commit. */
1503 #define	DB_REP_HOLDELECTION	(-30982)/* Time to hold an election. */
1504 #define	DB_REP_IGNORE		(-30981)/* This msg should be ignored.*/
1505 #define	DB_REP_INELECT		(-30980)/* Replication is in an election. */
1506 #define	DB_REP_ISPERM		(-30979)/* Cached not written perm written.*/
1507 #define	DB_REP_JOIN_FAILURE	(-30978)/* Unable to join replication group. */
1508 #define	DB_REP_LEASE_EXPIRED	(-30977)/* Master lease has expired. */
1509 #define	DB_REP_LOCKOUT		(-30976)/* API/Replication lockout now. */
1510 #define	DB_REP_NEWSITE		(-30975)/* New site entered system. */
1511 #define	DB_REP_NOTPERM		(-30974)/* Permanent log record not written. */
1512 #define	DB_REP_UNAVAIL		(-30973)/* Site cannot currently be reached. */
1513 #define	DB_REP_WOULDROLLBACK	(-30972)/* UNDOC: rollback inhibited by app. */
1514 #define	DB_RUNRECOVERY		(-30971)/* Panic return. */
1515 #define	DB_SECONDARY_BAD	(-30970)/* Secondary index corrupt. */
1516 #define	DB_SLICE_CORRUPT	(-30969)/* A part of a sliced env is corrupt. */
1517 #define	DB_TIMEOUT		(-30968)/* Timed out on read consistency. */
1518 #define	DB_VERIFY_BAD		(-30967)/* Verify failed; bad format. */
1519 #define	DB_VERSION_MISMATCH	(-30966)/* Environment version mismatch. */
1520 #define	DB_SYSTEM_MEM_MISSING	(-30965)/* Attach to shared memory failed. */
1521 
1522 /* DB (private) error return codes. */
1523 #define	DB_ALREADY_ABORTED	(-30899)
1524 				        /* Spare error number (-30898). */
1525 #define	DB_DELETED		(-30897)/* Recovery file marked deleted. */
1526 #define	DB_EVENT_NOT_HANDLED	(-30896)/* Forward event to application. */
1527 #define	DB_NEEDSPLIT		(-30895)/* Page needs to be split. */
1528 #define	DB_NOINTMP		(-30886)/* Sequences not supported in temporary
1529 					   or in-memory databases. */
1530 #define	DB_REP_BULKOVF		(-30894)/* Rep bulk buffer overflow. */
1531 #define	DB_REP_LOGREADY		(-30893)/* Rep log ready for recovery. */
1532 #define	DB_REP_NEWMASTER	(-30892)/* We have learned of a new master. */
1533 #define	DB_REP_PAGEDONE		(-30891)/* This page was already done. */
1534 #define	DB_SURPRISE_KID		(-30890)/* Child commit where parent
1535 					   didn't know it was a parent. */
1536 #define	DB_SWAPBYTES		(-30889)/* Database needs byte swapping. */
1537 #define	DB_TXN_CKP		(-30888)/* Encountered ckp record in log. */
1538 #define	DB_VERIFY_FATAL		(-30887)/* DB->verify cannot proceed. */
1539 
1540 /*
1541  * This exit status indicates that a BDB utility failed because it needed a
1542  * resource which had been held by a process which crashed or otherwise did
1543  * not exit cleanly.
1544  */
1545 #define DB_EXIT_FAILCHK		3
1546 
1547 /* Database handle. */
1548 struct __db {
1549 	/*******************************************************
1550 	 * Public: owned by the application.
1551 	 *******************************************************/
1552 	u_int32_t pgsize;		/* Database logical page size. */
1553 	DB_CACHE_PRIORITY priority;	/* Database priority in cache. */
1554 
1555 					/* Callbacks. */
1556 	int (*db_append_recno) __P((DB *, DBT *, db_recno_t));
1557 	void (*db_feedback) __P((DB *, int, int));
1558 	int (*dup_compare) __P((DB *, const DBT *, const DBT *, size_t *));
1559 
1560 	void	*app_private;		/* Application-private handle. */
1561 
1562 	/*******************************************************
1563 	 * Private: owned by DB.
1564 	 *******************************************************/
1565 	DB_ENV	*dbenv;			/* Backing public environment. */
1566 	ENV	*env;			/* Backing private environment. */
1567 
1568 	DB_MPOOLFILE *mpf;		/* Backing buffer pool. */
1569 
1570 	DB	**db_slices;		/* A containing db's array of DB handles
1571 					  for its slices. */
1572 	DB	*db_container;		/* A slice's pointer to its
1573 					   containing DB. */
1574 	db_slice_t db_slice_index;	/* Position in container's db_slices. */
1575 	DBTYPE	 type;			/* DB access method type. */
1576 
1577 	db_mutex_t mutex;		/* Synchronization for free threading */
1578 
1579 	char *fname, *dname;		/* File/database passed to DB->open. */
1580 	const char *dirname;		/* Directory of DB file. */
1581 	u_int32_t open_flags;		/* Flags passed to DB->open. */
1582 
1583 	u_int8_t fileid[DB_FILE_ID_LEN];/* File's unique ID for locking. */
1584 
1585 	u_int32_t adj_fileid;		/* File's unique ID for curs. adj. */
1586 
1587 	u_int32_t blob_threshold;	/* Ext file threshold record size. */
1588 
1589 #define	DB_LOGFILEID_INVALID	-1
1590 	FNAME *log_filename;		/* File's naming info for logging. */
1591 
1592 	db_pgno_t meta_pgno;		/* Meta page number */
1593 	DB_LOCKER *locker;		/* Locker for handle locking. */
1594 	DB_LOCKER *cur_locker;		/* Current handle lock holder. */
1595 	DB_TXN *cur_txn;		/* Opening transaction. */
1596 	DB_LOCKER *associate_locker;	/* Locker for DB->associate call. */
1597 	DB_LOCK	 handle_lock;		/* Lock held on this handle. */
1598 
1599 	time_t	 timestamp;		/* Handle timestamp for replication. */
1600 	u_int32_t fid_gen;		/* Rep generation number for fids. */
1601 
1602 	/*
1603 	 * Returned data memory for DB->get() and friends.
1604 	 */
1605 	DBT	 my_rskey;		/* Secondary key. */
1606 	DBT	 my_rkey;		/* [Primary] key. */
1607 	DBT	 my_rdata;		/* Data. */
1608 
1609 	/*
1610 	 * !!!
1611 	 * Some applications use DB but implement their own locking outside of
1612 	 * DB.  If they're using fcntl(2) locking on the underlying database
1613 	 * file, and we open and close a file descriptor for that file, we will
1614 	 * discard their locks.  The DB_FCNTL_LOCKING flag to DB->open is an
1615 	 * undocumented interface to support this usage which leaves any file
1616 	 * descriptors we open until DB->close.  This will only work with the
1617 	 * DB->open interface and simple caches, e.g., creating a transaction
1618 	 * thread may open/close file descriptors this flag doesn't protect.
1619 	 * Locking with fcntl(2) on a file that you don't own is a very, very
1620 	 * unsafe thing to do.  'Nuff said.
1621 	 */
1622 	DB_FH	*saved_open_fhp;	/* Saved file handle. */
1623 
1624 	/*
1625 	 * Linked list of DBP's, linked from the ENV, used to keep track
1626 	 * of all open db handles for cursor adjustment.
1627 	 *
1628 	 * !!!
1629 	 * Explicit representations of structures from queue.h.
1630 	 * TAILQ_ENTRY(__db) dblistlinks;
1631 	 */
1632 	struct {
1633 		struct __db *tqe_next;
1634 		struct __db **tqe_prev;
1635 	} dblistlinks;
1636 
1637 	/*
1638 	 * Cursor queues.
1639 	 *
1640 	 * !!!
1641 	 * Explicit representations of structures from queue.h.
1642 	 * TAILQ_HEAD(__cq_fq, __dbc) free_queue;
1643 	 * TAILQ_HEAD(__cq_aq, __dbc) active_queue;
1644 	 * TAILQ_HEAD(__cq_jq, __dbc) join_queue;
1645 	 */
1646 	struct __cq_fq {
1647 		struct __dbc *tqh_first;
1648 		struct __dbc **tqh_last;
1649 	} free_queue;
1650 	struct __cq_aq {
1651 		struct __dbc *tqh_first;
1652 		struct __dbc **tqh_last;
1653 	} active_queue;
1654 	struct __cq_jq {
1655 		struct __dbc *tqh_first;
1656 		struct __dbc **tqh_last;
1657 	} join_queue;
1658 
1659 	/*
1660 	 * Secondary index support.
1661 	 *
1662 	 * Linked list of secondary indices -- set in the primary.
1663 	 *
1664 	 * !!!
1665 	 * Explicit representations of structures from queue.h.
1666 	 * LIST_HEAD(s_secondaries, __db);
1667 	 */
1668 	struct {
1669 		struct __db *lh_first;
1670 	} s_secondaries;
1671 
1672 	/*
1673 	 * List entries for secondaries, and reference count of how many
1674 	 * threads are updating this secondary (see Dbc.put).
1675 	 *
1676 	 * !!!
1677 	 * Note that these are synchronized by the primary's mutex, but
1678 	 * filled in in the secondaries.
1679 	 *
1680 	 * !!!
1681 	 * Explicit representations of structures from queue.h.
1682 	 * LIST_ENTRY(__db) s_links;
1683 	 */
1684 	struct {
1685 		struct __db *le_next;
1686 		struct __db **le_prev;
1687 	} s_links;
1688 	u_int32_t s_refcnt;
1689 
1690 	/* Secondary callback and free functions -- set in the secondary. */
1691 	int	(*s_callback) __P((DB *, const DBT *, const DBT *, DBT *));
1692 
1693 	/* Reference to primary -- set in the secondary. */
1694 	DB	*s_primary;
1695 
1696 #define	DB_ASSOC_IMMUTABLE_KEY    0x00000001 /* Secondary key is immutable. */
1697 #define	DB_ASSOC_CREATE    0x00000002 /* Secondary db populated on open. */
1698 
1699 	/* Flags passed to associate -- set in the secondary. */
1700 	u_int32_t s_assoc_flags;
1701 
1702 	/*
1703 	 * Foreign key support.
1704 	 *
1705 	 * Linked list of primary dbs -- set in the foreign db
1706 	 *
1707 	 * !!!
1708 	 * Explicit representations of structures from queue.h.
1709 	 * LIST_HEAD(f_primaries, __db);
1710 	 */
1711 	struct {
1712 		struct __db_foreign_info *lh_first;
1713 	} f_primaries;
1714 
1715 	/*
1716 	 * !!!
1717 	 * Explicit representations of structures from queue.h.
1718 	 * TAILQ_ENTRY(__db) felink;
1719 	 *
1720 	 * Links in a list of DBs involved in file extension
1721 	 * during a transaction.  These are to be used only while the
1722 	 * metadata is locked.
1723 	 */
1724 	struct {
1725 		struct __db *tqe_next;
1726 		struct __db **tqe_prev;
1727 	} felink;
1728 
1729 	/* Reference to foreign -- set in the secondary. */
1730 	DB      *s_foreign;
1731 
1732 	DB		*blob_meta_db;	/* DBs holding ext file metadata. */
1733 	DB_SEQUENCE	*blob_seq;	/* Sequence of ext file ids. */
1734 	char		*blob_sub_dir;	/* Subdirectory for ext files */
1735 	db_seq_t	blob_file_id;	/* Id of the file ext file directory. */
1736 	db_seq_t	blob_sdb_id;	/* Id of subdb ext file directory. */
1737 
1738 	/* API-private structure: used by DB 1.85, C++, Java, Perl and Tcl */
1739 	void	*api_internal;
1740 
1741 	/* Subsystem-private structure. */
1742 	void	*bt_internal;		/* Btree/Recno access method. */
1743 	void	*h_internal;		/* Hash access method. */
1744 	void	*heap_internal;		/* Heap access method. */
1745 	void	*p_internal;		/* Partition informaiton. */
1746 	void	*q_internal;		/* Queue access method. */
1747 
1748 	/* DB PUBLIC HANDLE LIST BEGIN */
1749 	int  (*associate) __P((DB *, DB_TXN *, DB *,
1750 		int (*)(DB *, const DBT *, const DBT *, DBT *), u_int32_t));
1751 	int  (*associate_foreign) __P((DB *, DB *,
1752 		int (*)(DB *, const DBT *, DBT *, const DBT *, int *),
1753 		u_int32_t));
1754 	int  (*close) __P((DB *, u_int32_t));
1755 	int  (*compact) __P((DB *,
1756 		DB_TXN *, DBT *, DBT *, DB_COMPACT *, u_int32_t, DBT *));
1757 	int  (*convert) __P((DB *, const char *, u_int32_t));
1758 	int  (*cursor) __P((DB *, DB_TXN *, DBC **, u_int32_t));
1759 	int  (*del) __P((DB *, DB_TXN *, DBT *, u_int32_t));
1760 	void (*err) __P((DB *, int, const char *, ...));
1761 	void (*errx) __P((DB *, const char *, ...));
1762 	int  (*exists) __P((DB *, DB_TXN *, DBT *, u_int32_t));
1763 	int  (*fd) __P((DB *, int *));
1764 	int  (*get) __P((DB *, DB_TXN *, DBT *, DBT *, u_int32_t));
1765 	int  (*get_alloc) __P((DB *, void *(**)(size_t),
1766 		void *(**)(void *, size_t), void (**)(void *)));
1767 	int  (*get_append_recno) __P((DB *, int (**)(DB *, DBT *, db_recno_t)));
1768 	int  (*get_assoc_flags) __P((DB *, u_int32_t *));
1769 	int  (*get_blob_dir) __P((DB *, const char **));
1770 	int  (*get_blob_sub_dir) __P((DB *, const char **));
1771 	int  (*get_blob_threshold) __P((DB *, u_int32_t *));
1772 	int  (*get_bt_compare)
1773 		__P((DB *, int (**)(DB *, const DBT *, const DBT *, size_t *)));
1774 	int  (*get_bt_compress) __P((DB *,
1775 		int (**)(DB *,
1776 		const DBT *, const DBT *, const DBT *, const DBT *, DBT *),
1777 		int (**)(DB *, const DBT *, const DBT *, DBT *, DBT *, DBT *)));
1778 	int  (*get_bt_minkey) __P((DB *, u_int32_t *));
1779 	int  (*get_bt_prefix)
1780 		__P((DB *, size_t (**)(DB *, const DBT *, const DBT *)));
1781 	int  (*get_byteswapped) __P((DB *, int *));
1782 	int  (*get_cachesize) __P((DB *, u_int32_t *, u_int32_t *, int *));
1783 	int  (*get_create_dir) __P((DB *, const char **));
1784 	int  (*get_dbname) __P((DB *, const char **, const char **));
1785 	int  (*get_dup_compare)
1786 		__P((DB *, int (**)(DB *, const DBT *, const DBT *, size_t *)));
1787 	int  (*get_encrypt_flags) __P((DB *, u_int32_t *));
1788 	DB_ENV *(*get_env) __P((DB *));
1789 	void (*get_errcall) __P((DB *,
1790 		void (**)(const DB_ENV *, const char *, const char *)));
1791 	void (*get_errfile) __P((DB *, FILE **));
1792 	void (*get_errpfx) __P((DB *, const char **));
1793 	int  (*get_ext_file_dir) __P((DB *, const char **));
1794 	int  (*get_ext_file_threshold) __P((DB *, u_int32_t *));
1795 	int  (*get_feedback) __P((DB *, void (**)(DB *, int, int)));
1796 	int  (*get_flags) __P((DB *, u_int32_t *));
1797 	int  (*get_h_compare)
1798 		__P((DB *, int (**)(DB *, const DBT *, const DBT *, size_t *)));
1799 	int  (*get_h_ffactor) __P((DB *, u_int32_t *));
1800 	int  (*get_h_hash)
1801 		__P((DB *, u_int32_t (**)(DB *, const void *, u_int32_t)));
1802 	int  (*get_h_nelem) __P((DB *, u_int32_t *));
1803 	int  (*get_heapsize) __P((DB *, u_int32_t *, u_int32_t *));
1804 	int  (*get_heap_regionsize) __P((DB *, u_int32_t *));
1805 	int  (*get_lk_exclusive) __P((DB *, int *, int *));
1806 	int  (*get_lorder) __P((DB *, int *));
1807 	DB_MPOOLFILE *(*get_mpf) __P((DB *));
1808 	void (*get_msgcall) __P((DB *,
1809 	    void (**)(const DB_ENV *, const char *, const char *)));
1810 	void (*get_msgfile) __P((DB *, FILE **));
1811 	void (*get_msgpfx) __P((DB *, const char **));
1812 	int  (*get_multiple) __P((DB *));
1813 	int  (*get_open_flags) __P((DB *, u_int32_t *));
1814 	int  (*get_pagesize) __P((DB *, u_int32_t *));
1815 	int  (*get_partition_callback) __P((DB *,
1816 		u_int32_t *, u_int32_t (**)(DB *, DBT *key)));
1817 	int  (*get_partition_dirs) __P((DB *, const char ***));
1818 	int  (*get_partition_keys) __P((DB *, u_int32_t *, DBT **));
1819 	int  (*get_priority) __P((DB *, DB_CACHE_PRIORITY *));
1820 	int  (*get_q_extentsize) __P((DB *, u_int32_t *));
1821 	int  (*get_re_delim) __P((DB *, int *));
1822 	int  (*get_re_len) __P((DB *, u_int32_t *));
1823 	int  (*get_re_pad) __P((DB *, int *));
1824 	int  (*get_re_source) __P((DB *, const char **));
1825 	int  (*get_slices) __P((DB *, DB ***));
1826 	int  (*get_transactional) __P((DB *));
1827 	int  (*get_type) __P((DB *, DBTYPE *));
1828 	int  (*join) __P((DB *, DBC **, DBC **, u_int32_t));
1829 	int  (*key_range)
1830 		__P((DB *, DB_TXN *, DBT *, DB_KEY_RANGE *, u_int32_t));
1831 	void (*msg) __P((DB *, const char *, ...));
1832 	int  (*open) __P((DB *,
1833 		DB_TXN *, const char *, const char *, DBTYPE, u_int32_t, int));
1834 	int  (*pget) __P((DB *, DB_TXN *, DBT *, DBT *, DBT *, u_int32_t));
1835 	int  (*put) __P((DB *, DB_TXN *, DBT *, DBT *, u_int32_t));
1836 	int  (*remove) __P((DB *, const char *, const char *, u_int32_t));
1837 	int  (*rename) __P((DB *,
1838 		const char *, const char *, const char *, u_int32_t));
1839 	int  (*set_alloc) __P((DB *, void *(*)(size_t),
1840 		void *(*)(void *, size_t), void (*)(void *)));
1841 	int  (*set_append_recno) __P((DB *, int (*)(DB *, DBT *, db_recno_t)));
1842 	int  (*set_blob_dir) __P((DB *, const char *));
1843 	int  (*set_blob_threshold) __P((DB *, u_int32_t, u_int32_t));
1844 	int  (*set_bt_compare)
1845 		__P((DB *, int (*)(DB *, const DBT *, const DBT *, size_t *)));
1846 	int  (*set_bt_compress) __P((DB *,
1847 		int (*)(DB *, const DBT *, const DBT *, const DBT *, const DBT *, DBT *),
1848 		int (*)(DB *, const DBT *, const DBT *, DBT *, DBT *, DBT *)));
1849 	int  (*set_bt_minkey) __P((DB *, u_int32_t));
1850 	int  (*set_bt_prefix)
1851 		__P((DB *, size_t (*)(DB *, const DBT *, const DBT *)));
1852 	int  (*set_cachesize) __P((DB *, u_int32_t, u_int32_t, int));
1853 	int  (*set_create_dir) __P((DB *, const char *));
1854 	int  (*set_dup_compare)
1855 		__P((DB *, int (*)(DB *, const DBT *, const DBT *, size_t *)));
1856 	int  (*set_encrypt) __P((DB *, const char *, u_int32_t));
1857 	void (*set_errcall) __P((DB *,
1858 		void (*)(const DB_ENV *, const char *, const char *)));
1859 	void (*set_errfile) __P((DB *, FILE *));
1860 	void (*set_errpfx) __P((DB *, const char *));
1861 	int  (*set_ext_file_dir) __P((DB *, const char *));
1862 	int  (*set_ext_file_threshold) __P((DB *, u_int32_t, u_int32_t));
1863 	int  (*set_feedback) __P((DB *, void (*)(DB *, int, int)));
1864 	int  (*set_flags) __P((DB *, u_int32_t));
1865 	int  (*set_h_compare)
1866 		__P((DB *, int (*)(DB *, const DBT *, const DBT *, size_t *)));
1867 	int  (*set_h_ffactor) __P((DB *, u_int32_t));
1868 	int  (*set_h_hash)
1869 		__P((DB *, u_int32_t (*)(DB *, const void *, u_int32_t)));
1870 	int  (*set_h_nelem) __P((DB *, u_int32_t));
1871 	int  (*set_heapsize) __P((DB *, u_int32_t, u_int32_t, u_int32_t));
1872 	int  (*set_heap_regionsize) __P((DB *, u_int32_t));
1873 	int  (*set_lk_exclusive) __P((DB *, int));
1874 	int  (*set_lorder) __P((DB *, int));
1875 	int  (*set_slice_callback)
1876 		__P((DB *, int (*)(const DB *, const DBT *, DBT *)));
1877 	void (*set_msgcall) __P((DB *,
1878 		void (*)(const DB_ENV *, const char *, const char *)));
1879 	void (*set_msgfile) __P((DB *, FILE *));
1880 	void (*set_msgpfx) __P((DB *, const char *));
1881 	int  (*set_pagesize) __P((DB *, u_int32_t));
1882 	int  (*set_paniccall) __P((DB *, void (*)(DB_ENV *, int)));
1883 	int  (*set_partition) __P((DB *,
1884 		u_int32_t, DBT *, u_int32_t (*)(DB *, DBT *key)));
1885 	int  (*set_partition_dirs) __P((DB *, const char **));
1886 	int  (*set_priority) __P((DB *, DB_CACHE_PRIORITY));
1887 	int  (*set_q_extentsize) __P((DB *, u_int32_t));
1888 	int  (*set_re_delim) __P((DB *, int));
1889 	int  (*set_re_len) __P((DB *, u_int32_t));
1890 	int  (*set_re_pad) __P((DB *, int));
1891 	int  (*set_re_source) __P((DB *, const char *));
1892 	int  (*slice_lookup) __P((DB *, const DBT *, DB **, u_int32_t));
1893 	int  (*sort_multiple) __P((DB *, DBT *, DBT *, u_int32_t));
1894 	int  (*stat) __P((DB *, DB_TXN *, void *, u_int32_t));
1895 	int  (*stat_print) __P((DB *, u_int32_t));
1896 	int  (*sync) __P((DB *, u_int32_t));
1897 	int  (*truncate) __P((DB *, DB_TXN *, u_int32_t *, u_int32_t));
1898 	int  (*upgrade) __P((DB *, const char *, u_int32_t));
1899 	int  (*verify)
1900 		__P((DB *, const char *, const char *, FILE *, u_int32_t));
1901 	/* DB PUBLIC HANDLE LIST END */
1902 
1903 	/* DB PRIVATE HANDLE LIST BEGIN */
1904 	int (*slice_callback)(const DB *db, const DBT *key, DBT *slice);
1905 	int  (*dump) __P((DB *, const char *,
1906 		int (*)(void *, const void *), void *, int, int));
1907 	int  (*db_am_remove) __P((DB *, DB_THREAD_INFO *,
1908 		DB_TXN *, const char *, const char *, u_int32_t));
1909 	int  (*db_am_rename) __P((DB *, DB_THREAD_INFO *,
1910 		DB_TXN *, const char *, const char *, const char *));
1911 	/* DB PRIVATE HANDLE LIST END */
1912 
1913 	/*
1914 	 * Never called; these are a place to save function pointers
1915 	 * so that we can undo an associate.
1916 	 */
1917 	int  (*stored_get) __P((DB *, DB_TXN *, DBT *, DBT *, u_int32_t));
1918 	int  (*stored_close) __P((DB *, u_int32_t));
1919 
1920 	/* Alternative handle close function, used by C++ API. */
1921 	int  (*alt_close) __P((DB *, u_int32_t));
1922 
1923 #define	DB_OK_BTREE	0x01
1924 #define	DB_OK_HASH	0x02
1925 #define	DB_OK_HEAP	0x04
1926 #define	DB_OK_QUEUE	0x08
1927 #define	DB_OK_RECNO	0x10
1928 	u_int32_t	am_ok;		/* Legal AM choices. */
1929 
1930 	/*
1931 	 * This field really ought to be an AM_FLAG, but we have
1932 	 * have run out of bits.  If/when we decide to split up
1933 	 * the flags, we can incorporate it.
1934 	 */
1935 	int	 preserve_fid;		/* Do not free fileid on close. */
1936 
1937 	/*
1938 	 * This saves the DB_ flags from open, for refresh; they are not the
1939 	 * DB_AM_... or DB2_AM_... translations.
1940 	 */
1941 	u_int32_t orig_flags;
1942 
1943 #define	DB_AM_CHKSUM		0x00000001 /* Checksumming */
1944 #define	DB_AM_COMPENSATE	0x00000002 /* Created by compensating txn */
1945 #define	DB_AM_COMPRESS		0x00000004 /* Compressed BTree */
1946 #define	DB_AM_CREATED		0x00000008 /* Database was created upon open */
1947 #define	DB_AM_CREATED_MSTR	0x00000010 /* Encompassing file was created */
1948 #define	DB_AM_DBM_ERROR		0x00000020 /* Error in DBM/NDBM database */
1949 #define	DB_AM_DELIMITER		0x00000040 /* Variable length delimiter set */
1950 #define	DB_AM_DISCARD		0x00000080 /* Discard any cached pages */
1951 #define	DB_AM_DUP		0x00000100 /* DB_DUP */
1952 #define	DB_AM_DUPSORT		0x00000200 /* DB_DUPSORT */
1953 #define	DB_AM_ENCRYPT		0x00000400 /* Encryption */
1954 #define	DB_AM_FIXEDLEN		0x00000800 /* Fixed-length records */
1955 #define	DB_AM_INMEM		0x00001000 /* In-memory; no sync on close */
1956 #define	DB_AM_INORDER		0x00002000 /* DB_INORDER */
1957 #define	DB_AM_IN_RENAME		0x00004000 /* File is being renamed */
1958 #define	DB_AM_NOT_DURABLE	0x00008000 /* Do not log changes */
1959 #define	DB_AM_OPEN_CALLED	0x00010000 /* DB->open called */
1960 #define	DB_AM_PAD		0x00020000 /* Fixed-length record pad */
1961 #define	DB_AM_PARTDB		0x00040000 /* Handle for a database partition */
1962 #define	DB_AM_PGDEF		0x00080000 /* Page size was defaulted */
1963 #define	DB_AM_RDONLY		0x00100000 /* Database is readonly */
1964 #define	DB_AM_READ_UNCOMMITTED	0x00200000 /* Support degree 1 isolation */
1965 #define	DB_AM_RECNUM		0x00400000 /* DB_RECNUM */
1966 #define	DB_AM_RECOVER		0x00800000 /* DB opened by recovery routine */
1967 #define	DB_AM_RENUMBER		0x01000000 /* DB_RENUMBER */
1968 #define	DB_AM_REVSPLITOFF	0x02000000 /* DB_REVSPLITOFF */
1969 #define	DB_AM_SECONDARY		0x04000000 /* Database is a secondary index */
1970 #define	DB_AM_SNAPSHOT		0x08000000 /* DB_SNAPSHOT */
1971 #define	DB_AM_SUBDB		0x10000000 /* Subdatabases supported */
1972 #define	DB_AM_SWAP		0x20000000 /* Pages need to be byte-swapped */
1973 #define	DB_AM_TXN		0x40000000 /* Opened in a transaction */
1974 #define	DB_AM_VERIFYING		0x80000000 /* DB handle is in the verifier */
1975 	u_int32_t flags;
1976 
1977 #define	DB2_AM_EXCL		0x00000001 /* Exclusively lock the handle */
1978 #define	DB2_AM_INTEXCL		0x00000002 /* Internal exclusive lock. */
1979 #define	DB2_AM_MPOOL_OPENED	0x00000004 /* Memory pool setup completed */
1980 #define	DB2_AM_NOWAIT		0x00000008 /* Do not wait for handle lock */
1981 	u_int32_t flags2;		   /* Second flags word */
1982 };
1983 
1984 /*
1985  * Stream interface for external files.
1986  */
1987 struct __db_stream {
1988 	DBC		*dbc;	/* Cursor pointing to the db ext file record. */
1989 	DB_FH		*fhp;
1990 
1991 	/* DB_STREAM PUBLIC HANDLE LIST BEGIN */
1992 	int  (*close) __P((DB_STREAM *, u_int32_t));
1993 	int  (*read) __P((DB_STREAM *, DBT *, db_off_t, u_int32_t, u_int32_t));
1994 	int  (*size) __P((DB_STREAM *, db_off_t *, u_int32_t));
1995 	int  (*write) __P((DB_STREAM *, DBT *, db_off_t, u_int32_t));
1996 	/* DB_STREAM PUBLIC HANDLE LIST END */
1997 
1998 	u_int32_t	flags;
1999 #define	DB_STREAM_READ		0x00000001 /* Stream is read only. */
2000 #define	DB_STREAM_WRITE		0x00000002 /* Stream is writeable. */
2001 #define	DB_STREAM_SYNC_WRITE	0x00000004 /* Sync file on each write. */
2002 	db_seq_t	blob_id;
2003 	db_off_t	file_size;
2004 };
2005 
2006 /*
2007  * Macros for bulk operations.  These are only intended for the C API.
2008  * For C++, use DbMultiple*Iterator or DbMultiple*Builder.
2009  *
2010  * Bulk operations store multiple entries into a single DBT structure. The
2011  * following macros assist with creating and reading these Multiple DBTs.
2012  *
2013  * The basic layout for single data items is:
2014  *
2015  * -------------------------------------------------------------------------
2016  * | data1 | ... | dataN | ..... |-1 | dNLen | dNOff | ... | d1Len | d1Off |
2017  * -------------------------------------------------------------------------
2018  *
2019  * For the DB_MULTIPLE_KEY* macros, the items are in key/data pairs, so data1
2020  * would be a key, and data2 its corresponding value (N is always even).
2021  *
2022  * For the DB_MULTIPLE_RECNO* macros, the record number is stored along with
2023  * the len/off pair in the "header" section, and the list is zero terminated
2024  * (since -1 is a valid record number):
2025  *
2026  * --------------------------------------------------------------------------
2027  * | d1 |..| dN |..| 0 | dNLen | dNOff | recnoN |..| d1Len | d1Off | recno1 |
2028  * --------------------------------------------------------------------------
2029  */
2030 #define	DB_MULTIPLE_INIT(pointer, dbt)					\
2031 	(pointer = (u_int8_t *)(dbt)->data +				\
2032 	    (dbt)->ulen - sizeof(u_int32_t))
2033 
2034 #define	DB_MULTIPLE_NEXT(pointer, dbt, retdata, retdlen)		\
2035 	do {								\
2036 		u_int32_t *__p = (u_int32_t *)(pointer);		\
2037 		if (*__p == (u_int32_t)-1) {				\
2038 			retdata = NULL;					\
2039 			pointer = NULL;					\
2040 			break;						\
2041 		}							\
2042 		retdata = (u_int8_t *)(dbt)->data + *__p--;		\
2043 		retdlen = *__p--;					\
2044 		pointer = __p;						\
2045 		if (retdlen == 0 && retdata == (u_int8_t *)(dbt)->data)	\
2046 			retdata = NULL;					\
2047 	} while (0)
2048 
2049 #define	DB_MULTIPLE_KEY_NEXT(pointer, dbt, retkey, retklen, retdata, retdlen) \
2050 	do {								\
2051 		u_int32_t *__p = (u_int32_t *)(pointer);		\
2052 		if (*__p == (u_int32_t)-1) {				\
2053 			retdata = NULL;					\
2054 			retkey = NULL;					\
2055 			pointer = NULL;					\
2056 			break;						\
2057 		}							\
2058 		retkey = (u_int8_t *)(dbt)->data + *__p--;		\
2059 		retklen = *__p--;					\
2060 		retdata = (u_int8_t *)(dbt)->data + *__p--;		\
2061 		retdlen = *__p--;					\
2062 		pointer = __p;						\
2063 	} while (0)
2064 
2065 #define	DB_MULTIPLE_RECNO_NEXT(pointer, dbt, recno, retdata, retdlen)   \
2066 	do {								\
2067 		u_int32_t *__p = (u_int32_t *)(pointer);		\
2068 		if (*__p == (u_int32_t)0) {				\
2069 			recno = 0;					\
2070 			retdata = NULL;					\
2071 			pointer = NULL;					\
2072 			break;						\
2073 		}							\
2074 		recno = *__p--;						\
2075 		retdata = (u_int8_t *)(dbt)->data + *__p--;		\
2076 		retdlen = *__p--;					\
2077 		pointer = __p;						\
2078 	} while (0)
2079 
2080 #define	DB_MULTIPLE_WRITE_INIT(pointer, dbt)				\
2081 	do {								\
2082 		(dbt)->flags |= DB_DBT_BULK;				\
2083 		pointer = (u_int8_t *)(dbt)->data +			\
2084 		    (dbt)->ulen - sizeof(u_int32_t);			\
2085 		*(u_int32_t *)(pointer) = (u_int32_t)-1;		\
2086 	} while (0)
2087 
2088 #define	DB_MULTIPLE_RESERVE_NEXT(pointer, dbt, writedata, writedlen)	\
2089 	do {								\
2090 		u_int32_t *__p = (u_int32_t *)(pointer);		\
2091 		u_int32_t __off = ((pointer) ==	(u_int8_t *)(dbt)->data +\
2092 		    (dbt)->ulen - sizeof(u_int32_t)) ?  0 : __p[1] + __p[2];\
2093 		if ((u_int8_t *)(dbt)->data + __off + (writedlen) >	\
2094 		    (u_int8_t *)(__p - 2))				\
2095 			writedata = NULL;				\
2096 		else {							\
2097 			writedata = (u_int8_t *)(dbt)->data + __off;	\
2098 			__p[0] = __off;					\
2099 			__p[-1] = (u_int32_t)(writedlen);		\
2100 			__p[-2] = (u_int32_t)-1;			\
2101 			pointer = __p - 2;				\
2102 		}							\
2103 	} while (0)
2104 
2105 #define	DB_MULTIPLE_WRITE_NEXT(pointer, dbt, writedata, writedlen)	\
2106 	do {								\
2107 		void *__destd;						\
2108 		DB_MULTIPLE_RESERVE_NEXT((pointer), (dbt),		\
2109 		    __destd, (writedlen));				\
2110 		if (__destd == NULL)					\
2111 			pointer = NULL;					\
2112 		else							\
2113 			memcpy(__destd, (writedata), (writedlen));	\
2114 	} while (0)
2115 
2116 #define	DB_MULTIPLE_KEY_RESERVE_NEXT(pointer, dbt, writekey, writeklen, writedata, writedlen) \
2117 	do {								\
2118 		u_int32_t *__p = (u_int32_t *)(pointer);		\
2119 		u_int32_t __off = ((pointer) == (u_int8_t *)(dbt)->data +\
2120 		    (dbt)->ulen - sizeof(u_int32_t)) ?  0 : __p[1] + __p[2];\
2121 		if ((u_int8_t *)(dbt)->data + __off + (writeklen) +	\
2122 		    (writedlen) > (u_int8_t *)(__p - 4)) {		\
2123 			writekey = NULL;				\
2124 			writedata = NULL;				\
2125 		} else {						\
2126 			writekey = (u_int8_t *)(dbt)->data + __off;	\
2127 			__p[0] = __off;					\
2128 			__p[-1] = (u_int32_t)(writeklen);		\
2129 			__p -= 2;					\
2130 			__off += (u_int32_t)(writeklen);		\
2131 			writedata = (u_int8_t *)(dbt)->data + __off;	\
2132 			__p[0] = __off;					\
2133 			__p[-1] = (u_int32_t)(writedlen);		\
2134 			__p[-2] = (u_int32_t)-1;			\
2135 			pointer = __p - 2;				\
2136 		}							\
2137 	} while (0)
2138 
2139 #define	DB_MULTIPLE_KEY_WRITE_NEXT(pointer, dbt, writekey, writeklen, writedata, writedlen) \
2140 	do {								\
2141 		void *__destk, *__destd;				\
2142 		DB_MULTIPLE_KEY_RESERVE_NEXT((pointer), (dbt),		\
2143 		    __destk, (writeklen), __destd, (writedlen));	\
2144 		if (__destk == NULL)					\
2145 			pointer = NULL;					\
2146 		else {							\
2147 			memcpy(__destk, (writekey), (writeklen));	\
2148 			if (__destd != NULL)				\
2149 				memcpy(__destd, (writedata), (writedlen));\
2150 		}							\
2151 	} while (0)
2152 
2153 #define	DB_MULTIPLE_RECNO_WRITE_INIT(pointer, dbt)			\
2154 	do {								\
2155 		(dbt)->flags |= DB_DBT_BULK;				\
2156 		pointer = (u_int8_t *)(dbt)->data +			\
2157 		    (dbt)->ulen - sizeof(u_int32_t);			\
2158 		*(u_int32_t *)(pointer) = 0;				\
2159 	} while (0)
2160 
2161 #define	DB_MULTIPLE_RECNO_RESERVE_NEXT(pointer, dbt, recno, writedata, writedlen) \
2162 	do {								\
2163 		u_int32_t *__p = (u_int32_t *)(pointer);		\
2164 		u_int32_t __off = ((pointer) == (u_int8_t *)(dbt)->data +\
2165 		    (dbt)->ulen - sizeof(u_int32_t)) ? 0 : __p[1] + __p[2]; \
2166 		if (((u_int8_t *)(dbt)->data + __off) + (writedlen) >	\
2167 		    (u_int8_t *)(__p - 3))				\
2168 			writedata = NULL;				\
2169 		else {							\
2170 			writedata = (u_int8_t *)(dbt)->data + __off;	\
2171 			__p[0] = (u_int32_t)(recno);			\
2172 			__p[-1] = __off;				\
2173 			__p[-2] = (u_int32_t)(writedlen);		\
2174 			__p[-3] = 0;					\
2175 			pointer = __p - 3;				\
2176 		}							\
2177 	} while (0)
2178 
2179 #define	DB_MULTIPLE_RECNO_WRITE_NEXT(pointer, dbt, recno, writedata, writedlen)\
2180 	do {								\
2181 		void *__destd;						\
2182 		DB_MULTIPLE_RECNO_RESERVE_NEXT((pointer), (dbt),	\
2183 		    (recno), __destd, (writedlen));			\
2184 		if (__destd == NULL)					\
2185 			pointer = NULL;					\
2186 		else if ((writedlen) != 0)				\
2187 			memcpy(__destd, (writedata), (writedlen));	\
2188 	} while (0)
2189 
2190 struct __db_heap_rid {
2191 	db_pgno_t pgno;			/* Page number. */
2192 	db_indx_t indx;			/* Index in the offset table. */
2193 };
2194 #define	DB_HEAP_RID_SZ	(sizeof(db_pgno_t) + sizeof(db_indx_t))
2195 
2196 /*******************************************************
2197  * Access method cursors.
2198  *******************************************************/
2199 struct __dbc {
2200 	DB *dbp;			/* Backing database */
2201 	DB_ENV *dbenv;			/* Backing environment */
2202 	ENV *env;			/* Backing environment */
2203 
2204 	DB_THREAD_INFO *thread_info;	/* Thread that owns this cursor. */
2205 	DB_TXN	 *txn;			/* Associated transaction. */
2206 	DB_CACHE_PRIORITY priority;	/* Priority in cache. */
2207 
2208 	db_slice_t dbc_curslice;	/* Current DB of an all-slice DBC. */
2209 	DBC *dbc_slices[1]; 		/* A containing dbc's array of DBC
2210 					   handles for its slices. */
2211 
2212 	/*
2213 	 * Active/free cursor queues.
2214 	 *
2215 	 * !!!
2216 	 * Explicit representations of structures from queue.h.
2217 	 * TAILQ_ENTRY(__dbc) links;
2218 	 */
2219 	struct {
2220 		DBC *tqe_next;
2221 		DBC **tqe_prev;
2222 	} links;
2223 
2224 	/*
2225 	 * Cursor queue of the owning transaction.
2226 	 *
2227 	 * !!!
2228 	 * Explicit representations of structures from queue.h.
2229 	 * TAILQ_ENTRY(__dbc) txn_cursors;
2230 	 */
2231 	struct {
2232 		DBC *tqe_next;	/* next element */
2233 		DBC **tqe_prev;	/* address of previous next element */
2234 	} txn_cursors;
2235 
2236 	/*
2237 	 * The DBT *'s below are used by the cursor routines to return
2238 	 * data to the user when DBT flags indicate that DB should manage
2239 	 * the returned memory.  They point at a DBT containing the buffer
2240 	 * and length that will be used, and "belonging" to the handle that
2241 	 * should "own" this memory.  This may be a "my_*" field of this
2242 	 * cursor--the default--or it may be the corresponding field of
2243 	 * another cursor, a DB handle, a join cursor, etc.  In general, it
2244 	 * will be whatever handle the user originally used for the current
2245 	 * DB interface call.
2246 	 */
2247 	DBT	 *rskey;		/* Returned secondary key. */
2248 	DBT	 *rkey;			/* Returned [primary] key. */
2249 	DBT	 *rdata;		/* Returned data. */
2250 
2251 	DBT	  my_rskey;		/* Space for returned secondary key. */
2252 	DBT	  my_rkey;		/* Space for returned [primary] key. */
2253 	DBT	  my_rdata;		/* Space for returned data. */
2254 
2255 	DBT	 *cur_key;
2256 
2257 	DB_LOCKER *lref;		/* Reference to default locker. */
2258 	DB_LOCKER *locker;		/* Locker for this operation. */
2259 	DBT	  lock_dbt;		/* DBT referencing lock. */
2260 	DB_LOCK_ILOCK lock;		/* Object to be locked. */
2261 	DB_LOCK	  mylock;		/* CDB lock held on this cursor. */
2262 
2263 	DBTYPE	  dbtype;		/* Cursor type. */
2264 
2265 	DBC_INTERNAL *internal;		/* Access method private. */
2266 
2267 	/* DBC PUBLIC HANDLE LIST BEGIN */
2268 	int (*close) __P((DBC *));
2269 	int (*cmp) __P((DBC *, DBC *, int *, u_int32_t));
2270 	int (*count) __P((DBC *, db_recno_t *, u_int32_t));
2271 	int (*db_stream) __P((DBC *, DB_STREAM **, u_int32_t));
2272 	int (*del) __P((DBC *, u_int32_t));
2273 	int (*dup) __P((DBC *, DBC **, u_int32_t));
2274 	int (*get) __P((DBC *, DBT *, DBT *, u_int32_t));
2275 	int (*get_priority) __P((DBC *, DB_CACHE_PRIORITY *));
2276 	int (*pget) __P((DBC *, DBT *, DBT *, DBT *, u_int32_t));
2277 	int (*put) __P((DBC *, DBT *, DBT *, u_int32_t));
2278 	int (*set_priority) __P((DBC *, DB_CACHE_PRIORITY));
2279 	/* DBC PUBLIC HANDLE LIST END */
2280 
2281 	/* The following are the method names deprecated in the 4.6 release. */
2282 	int (*c_close) __P((DBC *));
2283 	int (*c_count) __P((DBC *, db_recno_t *, u_int32_t));
2284 	int (*c_del) __P((DBC *, u_int32_t));
2285 	int (*c_dup) __P((DBC *, DBC **, u_int32_t));
2286 	int (*c_get) __P((DBC *, DBT *, DBT *, u_int32_t));
2287 	int (*c_pget) __P((DBC *, DBT *, DBT *, DBT *, u_int32_t));
2288 	int (*c_put) __P((DBC *, DBT *, DBT *, u_int32_t));
2289 
2290 	/* DBC PRIVATE HANDLE LIST BEGIN */
2291 	int (*am_bulk) __P((DBC *, DBT *, u_int32_t));
2292 	int (*am_close) __P((DBC *, db_pgno_t, int *));
2293 	int (*am_del) __P((DBC *, u_int32_t));
2294 	int (*am_destroy) __P((DBC *));
2295 	int (*am_get) __P((DBC *, DBT *, DBT *, u_int32_t, db_pgno_t *));
2296 	int (*am_put) __P((DBC *, DBT *, DBT *, u_int32_t, db_pgno_t *));
2297 	int (*am_writelock) __P((DBC *));
2298 	/* DBC PRIVATE HANDLE LIST END */
2299 
2300 	u_int32_t open_flags;		/* Flags passed to DB->cursor. */
2301 /*
2302  * DBC_DONTLOCK and DBC_RECOVER are used during recovery and transaction
2303  * abort.  If a transaction is being aborted or recovered then DBC_RECOVER
2304  * will be set and locking and logging will be disabled on this cursor.  If
2305  * we are performing a compensating transaction (e.g. free page processing)
2306  * then DB_DONTLOCK will be set to inhibit locking, but logging will still
2307  * be required. DB_DONTLOCK is also used if the whole database is locked.
2308  */
2309 #define	DBC_ACTIVE		0x00001	/* Cursor in use. */
2310 #define	DBC_BULK		0x00002	/* Bulk update cursor. */
2311 #define	DBC_DONTLOCK		0x00004	/* Don't lock on this cursor. */
2312 #define	DBC_DOWNREV		0x00008	/* Down rev replication master. */
2313 #define	DBC_DUPLICATE		0x00010	/* Create a duplicate cursor. */
2314 #define	DBC_ERROR		0x00020	/* Error in this request. */
2315 #define	DBC_FAMILY		0x00040 /* Part of a locker family. */
2316 #define	DBC_FROM_DB_GET		0x00080 /* Called from the DB->get() method. */
2317 #define	DBC_MULTIPLE		0x00100	/* Return Multiple data. */
2318 #define	DBC_MULTIPLE_KEY	0x00200	/* Return Multiple keys and data. */
2319 #define	DBC_OPD			0x00400	/* Cursor references off-page dups. */
2320 #define	DBC_OWN_LID		0x00800	/* Free lock id on destroy. */
2321 #define	DBC_PARTITIONED		0x01000	/* Cursor for a partitioned db. */
2322 #define	DBC_READ_COMMITTED	0x02000	/* Cursor has degree 2 isolation. */
2323 #define	DBC_READ_UNCOMMITTED	0x04000	/* Cursor has degree 1 isolation. */
2324 #define	DBC_RECOVER		0x08000	/* Recovery cursor; don't log/lock. */
2325 #define	DBC_RMW			0x10000	/* Acquire write flag in read op. */
2326 #define	DBC_TRANSIENT		0x20000	/* Cursor is transient. */
2327 #define	DBC_WAS_READ_COMMITTED	0x40000	/* Cursor holds a read commited lock. */
2328 #define	DBC_WRITECURSOR		0x80000	/* Cursor may be used to write (CDB). */
2329 #define	DBC_WRITER	       0x100000	/* Cursor immediately writing (CDB). */
2330 	u_int32_t flags;
2331 };
2332 
2333 /* Key range statistics structure */
2334 struct __key_range {
2335 	double less;
2336 	double equal;
2337 	double greater;
2338 };
2339 
2340 /* Btree/Recno statistics structure. */
2341 struct __db_bt_stat { /* SHARED */
2342 	u_int32_t bt_magic;		/* Magic number. */
2343 	u_int32_t bt_version;		/* Version number. */
2344 	u_int32_t bt_metaflags;		/* Metadata flags. */
2345 	u_int32_t bt_nkeys;		/* Number of unique keys. */
2346 	u_int32_t bt_ndata;		/* Number of data items. */
2347 	u_int32_t bt_pagecnt;		/* Page count. */
2348 	u_int32_t bt_pagesize;		/* Page size. */
2349 	u_int32_t bt_minkey;		/* Minkey value. */
2350 	u_int32_t bt_ext_files;		/* Number of external files. */
2351 	u_int32_t bt_nblobs;		/* Deprecated alias bt_ext_files. */
2352 	u_int32_t bt_re_len;		/* Fixed-length record length. */
2353 	u_int32_t bt_re_pad;		/* Fixed-length record pad. */
2354 	u_int32_t bt_levels;		/* Tree levels. */
2355 	u_int32_t bt_int_pg;		/* Internal pages. */
2356 	u_int32_t bt_leaf_pg;		/* Leaf pages. */
2357 	u_int32_t bt_dup_pg;		/* Duplicate pages. */
2358 	u_int32_t bt_over_pg;		/* Overflow pages. */
2359 	u_int32_t bt_empty_pg;		/* Empty pages. */
2360 	u_int32_t bt_free;		/* Pages on the free list. */
2361 	uintmax_t bt_int_pgfree;	/* Bytes free in internal pages. */
2362 	uintmax_t bt_leaf_pgfree;	/* Bytes free in leaf pages. */
2363 	uintmax_t bt_dup_pgfree;	/* Bytes free in duplicate pages. */
2364 	uintmax_t bt_over_pgfree;	/* Bytes free in overflow pages. */
2365 };
2366 
2367 struct __db_compact {
2368 	/* Input Parameters. */
2369 	u_int32_t	compact_fillpercent;	/* Desired fillfactor: 1-100 */
2370 	db_timeout_t	compact_timeout;	/* Lock timeout. */
2371 	u_int32_t	compact_pages;		/* Max pages to process. */
2372 	/* Output Stats. */
2373 	u_int32_t	compact_empty_buckets;	/* Empty hash buckets found. */
2374 	u_int32_t	compact_pages_free;	/* Number of pages freed. */
2375 	u_int32_t	compact_pages_examine;	/* Number of pages examine. */
2376 	u_int32_t	compact_levels;		/* Number of levels removed. */
2377 	u_int32_t	compact_deadlock;	/* Number of deadlocks. */
2378 	db_pgno_t	compact_pages_truncated; /* Pages truncated to OS. */
2379 	/* Internal. */
2380 	db_pgno_t	compact_truncate;	/* Exchange pages above here. */
2381 };
2382 
2383 /* Hash statistics structure. */
2384 struct __db_h_stat { /* SHARED */
2385 	u_int32_t hash_magic;		/* Magic number. */
2386 	u_int32_t hash_version;		/* Version number. */
2387 	u_int32_t hash_metaflags;	/* Metadata flags. */
2388 	u_int32_t hash_nkeys;		/* Number of unique keys. */
2389 	u_int32_t hash_ndata;		/* Number of data items. */
2390 	u_int32_t hash_ext_files;	/* Number of external files. */
2391 	u_int32_t hash_nblobs;		/* Deprecated alias hash_ext_files. */
2392 	u_int32_t hash_pagecnt;		/* Page count. */
2393 	u_int32_t hash_pagesize;	/* Page size. */
2394 	u_int32_t hash_ffactor;		/* Fill factor specified at create. */
2395 	u_int32_t hash_buckets;		/* Number of hash buckets. */
2396 	u_int32_t hash_free;		/* Pages on the free list. */
2397 	uintmax_t hash_bfree;		/* Bytes free on bucket pages. */
2398 	u_int32_t hash_bigpages;	/* Number of big key/data pages. */
2399 	uintmax_t hash_big_bfree;	/* Bytes free on big item pages. */
2400 	u_int32_t hash_overflows;	/* Number of overflow pages. */
2401 	uintmax_t hash_ovfl_free;	/* Bytes free on ovfl pages. */
2402 	u_int32_t hash_dup;		/* Number of dup pages. */
2403 	uintmax_t hash_dup_free;	/* Bytes free on duplicate pages. */
2404 };
2405 
2406 /* Heap statistics structure. */
2407 struct __db_heap_stat { /* SHARED */
2408 	u_int32_t heap_magic;		/* Magic number. */
2409 	u_int32_t heap_version;		/* Version number. */
2410 	u_int32_t heap_metaflags;	/* Metadata flags. */
2411 	u_int32_t heap_ext_files;	/* Number of external files. */
2412 	u_int32_t heap_nblobs;		/* Deprecated alias heap_ext_files. */
2413 	u_int32_t heap_nrecs;		/* Number of records. */
2414 	u_int32_t heap_pagecnt;		/* Page count. */
2415 	u_int32_t heap_pagesize;	/* Page size. */
2416 	u_int32_t heap_nregions;	/* Number of regions. */
2417 	u_int32_t heap_regionsize;	/* Number of pages in a region. */
2418 };
2419 
2420 /* Queue statistics structure. */
2421 struct __db_qam_stat { /* SHARED */
2422 	u_int32_t qs_magic;		/* Magic number. */
2423 	u_int32_t qs_version;		/* Version number. */
2424 	u_int32_t qs_metaflags;		/* Metadata flags. */
2425 	u_int32_t qs_nkeys;		/* Number of unique keys. */
2426 	u_int32_t qs_ndata;		/* Number of data items. */
2427 	u_int32_t qs_pagesize;		/* Page size. */
2428 	u_int32_t qs_extentsize;	/* Pages per extent. */
2429 	u_int32_t qs_pages;		/* Data pages. */
2430 	u_int32_t qs_re_len;		/* Fixed-length record length. */
2431 	u_int32_t qs_re_pad;		/* Fixed-length record pad. */
2432 	u_int32_t qs_pgfree;		/* Bytes free in data pages. */
2433 	u_int32_t qs_first_recno;	/* First not deleted record. */
2434 	u_int32_t qs_cur_recno;		/* Next available record number. */
2435 };
2436 
2437 /*******************************************************
2438  * Environment.
2439  *******************************************************/
2440 #define	DB_REGION_MAGIC		0x120897 /* The environment is available. */
2441 #define	DB_REGION_MAGIC_RECOVER	0xeeeccc /* Recovery is running. */
2442 
2443 /*
2444  * Database environment structure.
2445  *
2446  * This is the public database environment handle.  The private environment
2447  * handle is the ENV structure.   The user owns this structure, the library
2448  * owns the ENV structure.  The reason there are two structures is because
2449  * the user's configuration outlives any particular DB_ENV->open call, and
2450  * separate structures allows us to easily discard internal information without
2451  * discarding the user's configuration.
2452  *
2453  * Fields in the DB_ENV structure should normally be set only by application
2454  * DB_ENV handle methods.
2455  */
2456 
2457 /*
2458  * Memory configuration types.
2459  */
2460 typedef enum {
2461 	DB_MEM_DATABASE=1,
2462 	DB_MEM_DATABASE_LENGTH=2,
2463 	DB_MEM_EXTFILE_DATABASE=3,
2464 	DB_MEM_LOCK=4,
2465 	DB_MEM_LOCKOBJECT=5,
2466 	DB_MEM_LOCKER=6,
2467 	DB_MEM_LOGID=7,
2468 	DB_MEM_REP_SITE=8,
2469 	DB_MEM_TRANSACTION=9,
2470 	DB_MEM_THREAD=10
2471 } DB_MEM_CONFIG;
2472 
2473 /*
2474  * Backup configuration types.
2475  */
2476 typedef enum {
2477 	DB_BACKUP_READ_COUNT=1,
2478 	DB_BACKUP_READ_SLEEP=2,
2479 	DB_BACKUP_SIZE=3,
2480 	DB_BACKUP_WRITE_DIRECT=4
2481 } DB_BACKUP_CONFIG;
2482 
2483 struct __db_env {
2484 	ENV *env;			/* Linked ENV structure */
2485 
2486 					/* Error message callback */
2487 	void (*db_errcall) __P((const DB_ENV *, const char *, const char *));
2488 	FILE		*db_errfile;	/* Error message file stream */
2489 	const char	*db_errpfx;	/* Error message prefix */
2490 
2491 					/* Other message callback */
2492 	void (*db_msgcall) __P((const DB_ENV *, const char *, const char *));
2493 	FILE		*db_msgfile;	/* Other message file stream */
2494 	const char	*db_msgpfx;	/* Other message prefix */
2495 
2496 	/* Other application callback functions */
2497 	int   (*app_dispatch) __P((DB_ENV *, DBT *, DB_LSN *, db_recops));
2498 	void  (*db_event_func) __P((DB_ENV *, u_int32_t, void *));
2499 	void  (*db_feedback) __P((DB_ENV *, int, int));
2500 	void  (*db_free) __P((void *));
2501 	void  (*db_paniccall) __P((DB_ENV *, int));
2502 	void *(*db_malloc) __P((size_t));
2503 	void *(*db_realloc) __P((void *, size_t));
2504 	int   (*is_alive) __P((DB_ENV *, pid_t, db_threadid_t, u_int32_t));
2505 	void  (*thread_id) __P((DB_ENV *, pid_t *, db_threadid_t *));
2506 	char *(*thread_id_string) __P((DB_ENV *, pid_t, db_threadid_t, char *));
2507 
2508 	/* Application specified paths */
2509 	char	*db_blob_dir;		/* External file directory */
2510 	char	*db_log_dir;		/* Database log file directory */
2511 	char	*db_md_dir;		/* Persistent metadata directory */
2512 	char	*db_reg_dir;		/* Region file directory */
2513 	char	*db_tmp_dir;		/* Database tmp file directory */
2514 
2515 	char    *db_create_dir;		/* Create directory for data files */
2516 	char   **db_data_dir;		/* Database data file directories (or
2517 					   sliced environment home dirs?) */
2518 	int	 data_cnt;		/* Database data file slots */
2519 	int	 data_next;		/* Next database data file slot */
2520 
2521 	char	*intermediate_dir_mode;	/* Intermediate directory perms */
2522 
2523 	long	 shm_key;		/* shmget key */
2524 
2525 	char	*passwd;		/* Cryptography support */
2526 	size_t	 passwd_len;
2527 	u_int32_t	encrypt_flags;
2528 
2529 	/* Private handle references */
2530 	void	*app_private;		/* Application-private handle */
2531 	void	*api1_internal;		/* C++, Perl API private */
2532 	void	*api2_internal;		/* Java API private */
2533 
2534 	u_int32_t	verbose;	/* DB_VERB_XXX flags */
2535 
2536 	u_int32_t	blob_threshold;	/* External file threshold size */
2537 
2538 	/* Database configuration */
2539 	u_int32_t	db_init_databases;	/* Number of databases. */
2540 	u_int32_t	db_init_db_len;		/* Database name length. */
2541 	u_int32_t	db_init_extfile_dbs;	/*
2542 						 * Number of additional
2543 						 * external file metadata
2544 						 * databases.
2545 						 */
2546 
2547 	/* Mutex configuration */
2548 	u_int32_t	mutex_align;	/* Mutex alignment */
2549 	u_int32_t	mutex_cnt;	/* Number of mutexes to configure */
2550 	u_int32_t	mutex_inc;	/* Number of mutexes to add */
2551 	u_int32_t	mutex_max;	/* Max number of mutexes */
2552 	u_int32_t	mutex_tas_spins;/* Test-and-set spin count */
2553 
2554 	/* Locking configuration */
2555 	u_int8_t       *lk_conflicts;	/* Two dimensional conflict matrix */
2556 	int		lk_modes;	/* Number of lock modes in table */
2557 	u_int32_t	lk_detect;	/* Deadlock detect on all conflicts */
2558 	u_int32_t	lk_max;	/* Maximum number of locks */
2559 	u_int32_t	lk_max_lockers;/* Maximum number of lockers */
2560 	u_int32_t	lk_max_objects;/* Maximum number of locked objects */
2561 	u_int32_t	lk_init;	/* Initial number of locks */
2562 	u_int32_t	lk_init_lockers;/* Initial number of lockers */
2563 	u_int32_t	lk_init_objects;/* Initial number of locked objects */
2564 	u_int32_t	lk_partitions ;/* Number of object partitions */
2565 	db_timeout_t	lk_timeout;	/* Lock timeout period */
2566 	/* Used during initialization */
2567 	u_int32_t	locker_t_size;	/* Locker hash table size. */
2568 	u_int32_t	object_t_size;	/* Object hash table size. */
2569 
2570 	/* Logging configuration */
2571 	u_int32_t	lg_bsize;	/* Buffer size */
2572 	u_int32_t	lg_fileid_init;	/* Initial allocation for fname structs */
2573 	int		lg_filemode;	/* Log file permission mode */
2574 	u_int32_t	lg_regionmax;	/* Region size */
2575 	u_int32_t	lg_size;	/* Log file size */
2576 	u_int32_t	lg_flags;	/* Log configuration */
2577 
2578 	/* Memory pool configuration */
2579 	u_int32_t	mp_gbytes;	/* Cache size: GB */
2580 	u_int32_t	mp_bytes;	/* Cache size: bytes */
2581 	u_int32_t	mp_max_gbytes;	/* Maximum cache size: GB */
2582 	u_int32_t	mp_max_bytes;	/* Maximum cache size: bytes */
2583 	size_t		mp_mmapsize;	/* Maximum file size for mmap */
2584 	int		mp_maxopenfd;	/* Maximum open file descriptors */
2585 	int		mp_maxwrite;	/* Maximum buffers to write */
2586 	u_int		mp_ncache;	/* Initial number of cache regions */
2587 	u_int32_t	mp_pagesize;	/* Average page size */
2588 	u_int32_t	mp_tablesize;	/* Approximate hash table size */
2589 	u_int32_t	mp_mtxcount;	/* Number of mutexs */
2590 					/* Sleep after writing max buffers */
2591 	db_timeout_t	mp_maxwrite_sleep;
2592 
2593 	/* Replication configuration */
2594 	u_int32_t	rep_init_sites;	/* Number of replication sites. */
2595 
2596 	/* Transaction configuration */
2597 	u_int32_t	tx_init;	/* Initial number of transactions */
2598 	u_int32_t	tx_max;		/* Maximum number of transactions */
2599 	time_t		tx_timestamp;	/* Recover to specific timestamp */
2600 	db_timeout_t	tx_timeout;	/* Timeout for transactions */
2601 
2602 	/* Thread tracking configuration */
2603 	u_int32_t	thr_init;	/* Thread count */
2604 	u_int32_t	thr_max;	/* Thread max */
2605 	roff_t		memory_max;	/* Maximum region memory */
2606 
2607 	/*
2608 	 * The following fields are not strictly user-owned, but they outlive
2609 	 * the ENV structure, and so are stored here.
2610 	 */
2611 	DB_FH		*registry;	/* DB_REGISTER file handle */
2612 	u_int32_t	registry_off;	/*
2613 					 * Offset of our slot.  We can't use
2614 					 * off_t because its size depends on
2615 					 * build settings.
2616 					 */
2617         db_timeout_t	envreg_timeout; /* DB_REGISTER wait timeout */
2618 
2619 	/*
2620 	 * When failchk broadcasting is active, any wait for a mutex will wake
2621 	 * up this frequently in order to check whether the mutex has died.
2622 	 */
2623 	db_timeout_t	mutex_failchk_timeout;
2624 
2625 	/* slice_cnt is non-zero only for containers. */
2626 	db_slice_t	slice_cnt;
2627 
2628 #define	DB_ENV_AUTO_COMMIT	0x00000001 /* DB_AUTO_COMMIT */
2629 #define	DB_ENV_CDB_ALLDB	0x00000002 /* CDB environment wide locking */
2630 #define	DB_ENV_FAILCHK		0x00000004 /* Failchk is running */
2631 #define	DB_ENV_DIRECT_DB	0x00000008 /* DB_DIRECT_DB set */
2632 #define	DB_ENV_DSYNC_DB		0x00000010 /* DB_DSYNC_DB set */
2633 #define	DB_ENV_DATABASE_LOCKING	0x00000020 /* Try database-level locking */
2634 #define	DB_ENV_MULTIVERSION	0x00000040 /* DB_MULTIVERSION set */
2635 #define	DB_ENV_NOLOCKING	0x00000080 /* DB_NOLOCKING set */
2636 #define	DB_ENV_NOMMAP		0x00000100 /* DB_NOMMAP set */
2637 #define	DB_ENV_NOPANIC		0x00000200 /* Okay if panic set */
2638 #define	DB_ENV_OVERWRITE	0x00000400 /* DB_OVERWRITE set */
2639 #define	DB_ENV_REGION_INIT	0x00000800 /* DB_REGION_INIT set */
2640 #define	DB_ENV_TIME_NOTGRANTED	0x00001000 /* DB_TIME_NOTGRANTED set */
2641 #define	DB_ENV_TXN_NOSYNC	0x00002000 /* DB_TXN_NOSYNC set */
2642 #define	DB_ENV_TXN_NOWAIT	0x00004000 /* DB_TXN_NOWAIT set */
2643 #define	DB_ENV_TXN_SNAPSHOT	0x00008000 /* DB_TXN_SNAPSHOT set */
2644 #define	DB_ENV_TXN_WRITE_NOSYNC	0x00010000 /* DB_TXN_WRITE_NOSYNC set */
2645 #define	DB_ENV_YIELDCPU		0x00020000 /* DB_YIELDCPU set */
2646 #define	DB_ENV_HOTBACKUP	0x00040000 /* DB_HOTBACKUP_IN_PROGRESS set */
2647 #define	DB_ENV_NOFLUSH		0x00080000 /* DB_NOFLUSH set */
2648 	u_int32_t flags;
2649 
2650 	/* DB_ENV PUBLIC HANDLE LIST BEGIN */
2651 	int  (*add_data_dir) __P((DB_ENV *, const char *));
2652 	int  (*backup)	__P((DB_ENV *, const char *, u_int32_t));
2653 	int  (*cdsgroup_begin) __P((DB_ENV *, DB_TXN **));
2654 	int  (*close) __P((DB_ENV *, u_int32_t));
2655 	int  (*dbbackup) __P((DB_ENV *, const char *, const char *, u_int32_t));
2656 	int  (*dbremove) __P((DB_ENV *,
2657 		DB_TXN *, const char *, const char *, u_int32_t));
2658 	int  (*dbrename) __P((DB_ENV *,
2659 		DB_TXN *, const char *, const char *, const char *, u_int32_t));
2660 	void (*err) __P((const DB_ENV *, int, const char *, ...));
2661 	void (*errx) __P((const DB_ENV *, const char *, ...));
2662 	int  (*failchk) __P((DB_ENV *, u_int32_t));
2663 	int  (*fileid_reset) __P((DB_ENV *, const char *, u_int32_t));
2664 	int  (*get_alloc) __P((DB_ENV *, void *(**)(size_t),
2665 		void *(**)(void *, size_t), void (**)(void *)));
2666 	int  (*get_app_dispatch)
2667 		__P((DB_ENV *, int (**)(DB_ENV *, DBT *, DB_LSN *, db_recops)));
2668 	int  (*get_blob_dir) __P((DB_ENV *, const char **));
2669 	int  (*get_blob_threshold) __P((DB_ENV*, u_int32_t *));
2670 	int  (*get_cache_max) __P((DB_ENV *, u_int32_t *, u_int32_t *));
2671 	int  (*get_cachesize) __P((DB_ENV *, u_int32_t *, u_int32_t *, int *));
2672 	int  (*get_create_dir) __P((DB_ENV *, const char **));
2673 	int  (*get_data_dirs) __P((DB_ENV *, const char ***));
2674 	int  (*get_data_len) __P((DB_ENV *, u_int32_t *));
2675 	int  (*get_backup_callbacks) __P((DB_ENV *,
2676 		int (**)(DB_ENV *, const char *, const char *, void **),
2677 		int (**)(DB_ENV *, u_int32_t, u_int32_t, u_int32_t, u_int8_t *, void *),
2678 		int (**)(DB_ENV *, const char *, void *)));
2679 	int  (*get_backup_config) __P((DB_ENV *, DB_BACKUP_CONFIG, u_int32_t *));
2680 	int  (*get_encrypt_flags) __P((DB_ENV *, u_int32_t *));
2681 	void (*get_errcall) __P((DB_ENV *,
2682 		void (**)(const DB_ENV *, const char *, const char *)));
2683 	void (*get_errfile) __P((DB_ENV *, FILE **));
2684 	void (*get_errpfx) __P((DB_ENV *, const char **));
2685 	int  (*get_ext_file_dir) __P((DB_ENV *, const char **));
2686 	int  (*get_ext_file_threshold) __P((DB_ENV*, u_int32_t *));
2687 	int  (*get_feedback) __P((DB_ENV *, void (**)(DB_ENV *, int, int)));
2688 	int  (*get_flags) __P((DB_ENV *, u_int32_t *));
2689 	int  (*get_home) __P((DB_ENV *, const char **));
2690 	int  (*get_intermediate_dir_mode) __P((DB_ENV *, const char **));
2691 	int  (*get_isalive) __P((DB_ENV *,
2692 		int (**)(DB_ENV *, pid_t, db_threadid_t, u_int32_t)));
2693 	int  (*get_lg_bsize) __P((DB_ENV *, u_int32_t *));
2694 	int  (*get_lg_dir) __P((DB_ENV *, const char **));
2695 	int  (*get_lg_filemode) __P((DB_ENV *, int *));
2696 	int  (*get_lg_max) __P((DB_ENV *, u_int32_t *));
2697 	int  (*get_lg_regionmax) __P((DB_ENV *, u_int32_t *));
2698 	int  (*get_lk_conflicts) __P((DB_ENV *, const u_int8_t **, int *));
2699 	int  (*get_lk_detect) __P((DB_ENV *, u_int32_t *));
2700 	int  (*get_lk_max_lockers) __P((DB_ENV *, u_int32_t *));
2701 	int  (*get_lk_max_locks) __P((DB_ENV *, u_int32_t *));
2702 	int  (*get_lk_max_objects) __P((DB_ENV *, u_int32_t *));
2703 	int  (*get_lk_partitions) __P((DB_ENV *, u_int32_t *));
2704 	int  (*get_lk_priority) __P((DB_ENV *, u_int32_t, u_int32_t *));
2705 	int  (*get_lk_tablesize) __P((DB_ENV *, u_int32_t *));
2706 	int  (*get_memory_init) __P((DB_ENV *, DB_MEM_CONFIG, u_int32_t *));
2707 	int  (*get_memory_max) __P((DB_ENV *, u_int32_t *, u_int32_t *));
2708 	int  (*get_metadata_dir) __P((DB_ENV *, const char **));
2709 	int  (*get_mp_max_openfd) __P((DB_ENV *, int *));
2710 	int  (*get_mp_max_write) __P((DB_ENV *, int *, db_timeout_t *));
2711 	int  (*get_mp_mmapsize) __P((DB_ENV *, size_t *));
2712 	int  (*get_mp_mtxcount) __P((DB_ENV *, u_int32_t *));
2713 	int  (*get_mp_pagesize) __P((DB_ENV *, u_int32_t *));
2714 	int  (*get_mp_tablesize) __P((DB_ENV *, u_int32_t *));
2715 	void (*get_msgcall) __P((DB_ENV *,
2716 		void (**)(const DB_ENV *, const char *, const char *)));
2717 	void (*get_msgfile) __P((DB_ENV *, FILE **));
2718 	void (*get_msgpfx) __P((DB_ENV *, const char **));
2719 	int  (*get_open_flags) __P((DB_ENV *, u_int32_t *));
2720 	int  (*get_region_dir) __P((DB_ENV *, const char **));
2721 	int  (*get_slice_count) __P((DB_ENV *, u_int32_t *));
2722 	int  (*get_slices) __P((DB_ENV *, DB_ENV ***));
2723 	int  (*get_shm_key) __P((DB_ENV *, long *));
2724 	int  (*get_thread_count) __P((DB_ENV *, u_int32_t *));
2725 	int  (*get_thread_id_fn)
2726 		__P((DB_ENV *, void (**)(DB_ENV *, pid_t *, db_threadid_t *)));
2727 	int  (*get_thread_id_string_fn) __P((DB_ENV *,
2728 		char *(**)(DB_ENV *, pid_t, db_threadid_t, char *)));
2729 	int  (*get_timeout) __P((DB_ENV *, db_timeout_t *, u_int32_t));
2730 	int  (*get_tmp_dir) __P((DB_ENV *, const char **));
2731 	int  (*get_tx_max) __P((DB_ENV *, u_int32_t *));
2732 	int  (*get_tx_timestamp) __P((DB_ENV *, time_t *));
2733 	int  (*get_verbose) __P((DB_ENV *, u_int32_t, int *));
2734 	int  (*is_bigendian) __P((void));
2735 	int  (*lock_detect) __P((DB_ENV *, u_int32_t, u_int32_t, int *));
2736 	int  (*lock_get) __P((DB_ENV *,
2737 		u_int32_t, u_int32_t, DBT *, db_lockmode_t, DB_LOCK *));
2738 	int  (*lock_id) __P((DB_ENV *, u_int32_t *));
2739 	int  (*lock_id_free) __P((DB_ENV *, u_int32_t));
2740 	int  (*lock_put) __P((DB_ENV *, DB_LOCK *));
2741 	int  (*lock_stat) __P((DB_ENV *, DB_LOCK_STAT **, u_int32_t));
2742 	int  (*lock_stat_print) __P((DB_ENV *, u_int32_t));
2743 	int  (*lock_vec) __P((DB_ENV *,
2744 		u_int32_t, u_int32_t, DB_LOCKREQ *, int, DB_LOCKREQ **));
2745 	int  (*log_archive) __P((DB_ENV *, char **[], u_int32_t));
2746 	int  (*log_cursor) __P((DB_ENV *, DB_LOGC **, u_int32_t));
2747 	int  (*log_file) __P((DB_ENV *, const DB_LSN *, char *, size_t));
2748 	int  (*log_flush) __P((DB_ENV *, const DB_LSN *));
2749 	int  (*log_get_config) __P((DB_ENV *, u_int32_t, int *));
2750 	int  (*log_printf) __P((DB_ENV *, DB_TXN *, const char *, ...));
2751 	int  (*log_put) __P((DB_ENV *, DB_LSN *, const DBT *, u_int32_t));
2752 	int  (*log_put_record) __P((DB_ENV *, DB *, DB_TXN *, DB_LSN *,
2753 		u_int32_t, u_int32_t, u_int32_t, u_int32_t,
2754 		DB_LOG_RECSPEC *, ...));
2755 	int  (*log_read_record) __P((DB_ENV *, DB **,
2756 		void *, void *, DB_LOG_RECSPEC *, u_int32_t, void **));
2757 	int  (*log_set_config) __P((DB_ENV *, u_int32_t, int));
2758 	int  (*log_stat) __P((DB_ENV *, DB_LOG_STAT **, u_int32_t));
2759 	int  (*log_stat_print) __P((DB_ENV *, u_int32_t));
2760 	int  (*log_verify) __P((DB_ENV *, const DB_LOG_VERIFY_CONFIG *));
2761 	int  (*lsn_reset) __P((DB_ENV *, const char *, u_int32_t));
2762 	int  (*memp_fcreate) __P((DB_ENV *, DB_MPOOLFILE **, u_int32_t));
2763 	int  (*memp_register) __P((DB_ENV *, int, int (*)(DB_ENV *, db_pgno_t,
2764 		void *, DBT *), int (*)(DB_ENV *, db_pgno_t, void *, DBT *)));
2765 	int  (*memp_stat) __P((DB_ENV *,
2766 		DB_MPOOL_STAT **, DB_MPOOL_FSTAT ***, u_int32_t));
2767 	int  (*memp_stat_print) __P((DB_ENV *, u_int32_t));
2768 	int  (*memp_sync) __P((DB_ENV *, DB_LSN *));
2769 	int  (*memp_trickle) __P((DB_ENV *, int, int *));
2770 	void (*msg) __P((const DB_ENV *, const char *, ...));
2771 	int  (*mutex_alloc) __P((DB_ENV *, u_int32_t, db_mutex_t *));
2772 	int  (*mutex_free) __P((DB_ENV *, db_mutex_t));
2773 	int  (*mutex_get_align) __P((DB_ENV *, u_int32_t *));
2774 	int  (*mutex_get_increment) __P((DB_ENV *, u_int32_t *));
2775 	int  (*mutex_get_init) __P((DB_ENV *, u_int32_t *));
2776 	int  (*mutex_get_max) __P((DB_ENV *, u_int32_t *));
2777 	int  (*mutex_get_tas_spins) __P((DB_ENV *, u_int32_t *));
2778 	int  (*mutex_lock) __P((DB_ENV *, db_mutex_t));
2779 	int  (*mutex_set_align) __P((DB_ENV *, u_int32_t));
2780 	int  (*mutex_set_increment) __P((DB_ENV *, u_int32_t));
2781 	int  (*mutex_set_init) __P((DB_ENV *, u_int32_t));
2782 	int  (*mutex_set_max) __P((DB_ENV *, u_int32_t));
2783 	int  (*mutex_set_tas_spins) __P((DB_ENV *, u_int32_t));
2784 	int  (*mutex_stat) __P((DB_ENV *, DB_MUTEX_STAT **, u_int32_t));
2785 	int  (*mutex_stat_print) __P((DB_ENV *, u_int32_t));
2786 	int  (*mutex_unlock) __P((DB_ENV *, db_mutex_t));
2787 	int  (*open) __P((DB_ENV *, const char *, u_int32_t, int));
2788 	int  (*remove) __P((DB_ENV *, const char *, u_int32_t));
2789 	int  (*rep_elect) __P((DB_ENV *, u_int32_t, u_int32_t, u_int32_t));
2790 	int  (*rep_flush) __P((DB_ENV *));
2791 	int  (*rep_get_clockskew) __P((DB_ENV *, u_int32_t *, u_int32_t *));
2792 	int  (*rep_get_config) __P((DB_ENV *, u_int32_t, int *));
2793 	int  (*rep_get_limit) __P((DB_ENV *, u_int32_t *, u_int32_t *));
2794 	int  (*rep_get_nsites) __P((DB_ENV *, u_int32_t *));
2795 	int  (*rep_get_priority) __P((DB_ENV *, u_int32_t *));
2796 	int  (*rep_get_request) __P((DB_ENV *, u_int32_t *, u_int32_t *));
2797 	int  (*rep_get_timeout) __P((DB_ENV *, int, u_int32_t *));
2798 	int  (*rep_process_message)
2799 		__P((DB_ENV *, DBT *, DBT *, int, DB_LSN *));
2800 	int  (*rep_set_clockskew) __P((DB_ENV *, u_int32_t, u_int32_t));
2801 	int  (*rep_set_config) __P((DB_ENV *, u_int32_t, int));
2802 	int  (*rep_set_limit) __P((DB_ENV *, u_int32_t, u_int32_t));
2803 	int  (*rep_set_nsites) __P((DB_ENV *, u_int32_t));
2804 	int  (*rep_set_priority) __P((DB_ENV *, u_int32_t));
2805 	int  (*rep_set_request) __P((DB_ENV *, u_int32_t, u_int32_t));
2806 	int  (*rep_set_timeout) __P((DB_ENV *, int, db_timeout_t));
2807 	int  (*rep_set_transport) __P((DB_ENV *, int, int (*)(DB_ENV *,
2808 		const DBT *, const DBT *, const DB_LSN *, int, u_int32_t)));
2809 	int  (*rep_set_view) __P((DB_ENV *, int (*)(DB_ENV *,
2810 		const char *, int *, u_int32_t)));
2811 	int  (*rep_start) __P((DB_ENV *, DBT *, u_int32_t));
2812 	int  (*rep_stat) __P((DB_ENV *, DB_REP_STAT **, u_int32_t));
2813 	int  (*rep_stat_print) __P((DB_ENV *, u_int32_t));
2814 	int  (*rep_sync) __P((DB_ENV *, u_int32_t));
2815 	int  (*repmgr_channel) __P((DB_ENV *, int, DB_CHANNEL **, u_int32_t));
2816 	int  (*repmgr_get_ack_policy) __P((DB_ENV *, int *));
2817 	int  (*repmgr_get_incoming_queue_max)
2818 		__P((DB_ENV *, u_int32_t *, u_int32_t *));
2819 	int  (*repmgr_local_site) __P((DB_ENV *, DB_SITE **));
2820 	int  (*repmgr_msg_dispatch) __P((DB_ENV *,
2821 		void (*)(DB_ENV *, DB_CHANNEL *, DBT *, u_int32_t, u_int32_t),
2822 		u_int32_t));
2823 	int  (*repmgr_set_ack_policy) __P((DB_ENV *, int));
2824 	int  (*repmgr_set_incoming_queue_max)
2825 		__P((DB_ENV *, u_int32_t, u_int32_t));
2826 	int  (*repmgr_set_socket) __P((DB_ENV *, int (*)(DB_ENV *,
2827 		DB_REPMGR_SOCKET, int *, u_int32_t)));
2828 	int (*repmgr_set_ssl_config) __P((DB_ENV *, int, char *));
2829 	int  (*repmgr_site)
2830 		__P((DB_ENV *, const char *, u_int, DB_SITE**, u_int32_t));
2831 	int  (*repmgr_site_by_eid) __P((DB_ENV *, int, DB_SITE**));
2832 	int  (*repmgr_site_list) __P((DB_ENV *, u_int *, DB_REPMGR_SITE **));
2833 	int  (*repmgr_start) __P((DB_ENV *, int, u_int32_t));
2834 	int  (*repmgr_stat) __P((DB_ENV *, DB_REPMGR_STAT **, u_int32_t));
2835 	int  (*repmgr_stat_print) __P((DB_ENV *, u_int32_t));
2836 	int  (*set_alloc) __P((DB_ENV *, void *(*)(size_t),
2837 		void *(*)(void *, size_t), void (*)(void *)));
2838 	int  (*set_app_dispatch)
2839 		__P((DB_ENV *, int (*)(DB_ENV *, DBT *, DB_LSN *, db_recops)));
2840 	int  (*set_blob_dir) __P((DB_ENV *, const char *));
2841 	int  (*set_blob_threshold) __P((DB_ENV *, u_int32_t, u_int32_t));
2842 	int  (*set_cache_max) __P((DB_ENV *, u_int32_t, u_int32_t));
2843 	int  (*set_cachesize) __P((DB_ENV *, u_int32_t, u_int32_t, int));
2844 	int  (*set_create_dir) __P((DB_ENV *, const char *));
2845 	int  (*set_data_dir) __P((DB_ENV *, const char *));
2846 	int  (*set_data_len) __P((DB_ENV *, u_int32_t));
2847 	int  (*set_backup_callbacks) __P((DB_ENV *,
2848 		int (*)(DB_ENV *, const char *, const char *, void **),
2849 		int (*)(DB_ENV *, u_int32_t,
2850 		    u_int32_t, u_int32_t, u_int8_t *, void *),
2851 		int (*)(DB_ENV *, const char *, void *)));
2852 	int  (*set_backup_config) __P((DB_ENV *, DB_BACKUP_CONFIG, u_int32_t));
2853 	int  (*set_encrypt) __P((DB_ENV *, const char *, u_int32_t));
2854 	void (*set_errcall) __P((DB_ENV *,
2855 		void (*)(const DB_ENV *, const char *, const char *)));
2856 	void (*set_errfile) __P((DB_ENV *, FILE *));
2857 	void (*set_errpfx) __P((DB_ENV *, const char *));
2858 	int  (*set_event_notify)
2859 		__P((DB_ENV *, void (*)(DB_ENV *, u_int32_t, void *)));
2860 	int  (*set_ext_file_dir) __P((DB_ENV *, const char *));
2861 	int  (*set_ext_file_threshold) __P((DB_ENV *, u_int32_t, u_int32_t));
2862 	int  (*set_feedback) __P((DB_ENV *, void (*)(DB_ENV *, int, int)));
2863 	int  (*set_flags) __P((DB_ENV *, u_int32_t, int));
2864 	int  (*set_intermediate_dir_mode) __P((DB_ENV *, const char *));
2865 	int  (*set_isalive) __P((DB_ENV *,
2866 		int (*)(DB_ENV *, pid_t, db_threadid_t, u_int32_t)));
2867 	int  (*set_lg_bsize) __P((DB_ENV *, u_int32_t));
2868 	int  (*set_lg_dir) __P((DB_ENV *, const char *));
2869 	int  (*set_lg_filemode) __P((DB_ENV *, int));
2870 	int  (*set_lg_max) __P((DB_ENV *, u_int32_t));
2871 	int  (*set_lg_regionmax) __P((DB_ENV *, u_int32_t));
2872 	int  (*set_lk_conflicts) __P((DB_ENV *, u_int8_t *, int));
2873 	int  (*set_lk_detect) __P((DB_ENV *, u_int32_t));
2874 	int  (*set_lk_max_lockers) __P((DB_ENV *, u_int32_t));
2875 	int  (*set_lk_max_locks) __P((DB_ENV *, u_int32_t));
2876 	int  (*set_lk_max_objects) __P((DB_ENV *, u_int32_t));
2877 	int  (*set_lk_partitions) __P((DB_ENV *, u_int32_t));
2878 	int  (*set_lk_priority) __P((DB_ENV *, u_int32_t, u_int32_t));
2879 	int  (*set_lk_tablesize) __P((DB_ENV *, u_int32_t));
2880 	int  (*set_memory_init) __P((DB_ENV *, DB_MEM_CONFIG, u_int32_t));
2881 	int  (*set_memory_max) __P((DB_ENV *, u_int32_t, u_int32_t));
2882 	int  (*set_metadata_dir) __P((DB_ENV *, const char *));
2883 	int  (*set_mp_max_openfd) __P((DB_ENV *, int));
2884 	int  (*set_mp_max_write) __P((DB_ENV *, int, db_timeout_t));
2885 	int  (*set_mp_mmapsize) __P((DB_ENV *, size_t));
2886 	int  (*set_mp_mtxcount) __P((DB_ENV *, u_int32_t));
2887 	int  (*set_mp_pagesize) __P((DB_ENV *, u_int32_t));
2888 	int  (*set_mp_tablesize) __P((DB_ENV *, u_int32_t));
2889 	void (*set_msgcall) __P((DB_ENV *,
2890 		void (*)(const DB_ENV *, const char *, const char *)));
2891 	void (*set_msgfile) __P((DB_ENV *, FILE *));
2892 	void (*set_msgpfx) __P((DB_ENV *, const char *));
2893 	int  (*set_paniccall) __P((DB_ENV *, void (*)(DB_ENV *, int)));
2894 	int  (*set_region_dir) __P((DB_ENV *, const char *));
2895 	int  (*set_shm_key) __P((DB_ENV *, long));
2896 	int  (*set_thread_count) __P((DB_ENV *, u_int32_t));
2897 	int  (*set_thread_id)
2898 		__P((DB_ENV *, void (*)(DB_ENV *, pid_t *, db_threadid_t *)));
2899 	int  (*set_thread_id_string) __P((DB_ENV *,
2900 		char *(*)(DB_ENV *, pid_t, db_threadid_t, char *)));
2901 	int  (*set_timeout) __P((DB_ENV *, db_timeout_t, u_int32_t));
2902 	int  (*set_tmp_dir) __P((DB_ENV *, const char *));
2903 	int  (*set_tx_max) __P((DB_ENV *, u_int32_t));
2904 	int  (*set_tx_timestamp) __P((DB_ENV *, time_t *));
2905 	int  (*set_verbose) __P((DB_ENV *, u_int32_t, int));
2906 	int  (*txn_applied) __P((DB_ENV *,
2907 		DB_TXN_TOKEN *, db_timeout_t, u_int32_t));
2908 	int  (*stat_print) __P((DB_ENV *, u_int32_t));
2909 	int  (*txn_begin) __P((DB_ENV *, DB_TXN *, DB_TXN **, u_int32_t));
2910 	int  (*txn_checkpoint) __P((DB_ENV *, u_int32_t, u_int32_t, u_int32_t));
2911 	int  (*txn_recover) __P((DB_ENV *,
2912 		DB_PREPLIST *, long, long *, u_int32_t));
2913 	int  (*txn_stat) __P((DB_ENV *, DB_TXN_STAT **, u_int32_t));
2914 	int  (*txn_stat_print) __P((DB_ENV *, u_int32_t));
2915 	/* DB_ENV PUBLIC HANDLE LIST END */
2916 
2917 	/* DB_ENV PRIVATE HANDLE LIST BEGIN */
2918 	int  (*prdbt) __P((DBT *, int, const char *, void *,
2919 		int (*)(void *, const void *), int, int, int));
2920 	/* DB_ENV PRIVATE HANDLE LIST END */
2921 };
2922 
2923 /*
2924  * Dispatch structure for recovery, log verification and print routines. Since
2925  * internal and external routines take different arguments (ENV versus DB_ENV),
2926  * we need something more elaborate than a single pointer and size.  Each size
2927  * is the number of allocated entries in the corresponding dispatch table,
2928  * rather than a byte count.
2929  */
2930 struct __db_distab {
2931 	int   (**int_dispatch) __P((ENV *, DBT *, DB_LSN *, db_recops, void *));
2932 	int   (**ext_dispatch) __P((DB_ENV *, DBT *, DB_LSN *, db_recops));
2933 	size_t	int_size;
2934 	size_t	ext_size;
2935 };
2936 
2937 /*
2938  * Log verification configuration structure.
2939  */
2940 struct __db_logvrfy_config {
2941 	int continue_after_fail;
2942 	int verbose;
2943 	u_int32_t cachesize;
2944 	const char *temp_envhome;
2945 	const char *dbfile;
2946 	const char *dbname;
2947 	DB_LSN start_lsn;
2948 	DB_LSN end_lsn;
2949 	time_t start_time;
2950 	time_t end_time;
2951 };
2952 
2953 struct __db_channel {
2954 	CHANNEL *channel;	/* Pointer to internal state details. */
2955 	int eid;		/* Env. ID passed in constructor. */
2956 	db_timeout_t timeout;
2957 
2958 	/* DB_CHANNEL PUBLIC HANDLE LIST BEGIN */
2959 	int (*close) __P((DB_CHANNEL *, u_int32_t));
2960 	int (*send_msg) __P((DB_CHANNEL *, DBT *, u_int32_t, u_int32_t));
2961 	int (*send_request) __P((DB_CHANNEL *,
2962 		DBT *, u_int32_t, DBT *, db_timeout_t, u_int32_t));
2963 	int  (*set_timeout) __P((DB_CHANNEL *, db_timeout_t));
2964 	/* DB_CHANNEL PUBLIC HANDLE LIST END */
2965 };
2966 
2967 struct __db_site {
2968 	ENV *env;
2969 	int eid;
2970 	const char *host;
2971 	u_int port;
2972 	u_int32_t flags;
2973 
2974 	/* DB_SITE PUBLIC HANDLE LIST BEGIN */
2975 	int (*get_address) __P((DB_SITE *, const char **, u_int *));
2976 	int (*get_config) __P((DB_SITE *, u_int32_t, u_int32_t *));
2977 	int (*get_eid) __P((DB_SITE *, int *));
2978 	int (*set_config) __P((DB_SITE *, u_int32_t, u_int32_t));
2979 	int (*remove) __P((DB_SITE *));
2980 	int (*close) __P((DB_SITE *));
2981 	/* DB_SITE PUBLIC HANDLE LIST END */
2982 };
2983 
2984 #if DB_DBM_HSEARCH != 0
2985 /*******************************************************
2986  * Dbm/Ndbm historic interfaces.
2987  *******************************************************/
2988 typedef struct __db DBM;
2989 
2990 #define	DBM_INSERT	0		/* Flags to dbm_store(). */
2991 #define	DBM_REPLACE	1
2992 
2993 /*
2994  * The DB support for ndbm(3) always appends this suffix to the
2995  * file name to avoid overwriting the user's original database.
2996  */
2997 #define	DBM_SUFFIX	".db"
2998 
2999 #if defined(_XPG4_2)
3000 typedef struct {
3001 	char *dptr;
3002 	size_t dsize;
3003 } datum;
3004 #else
3005 typedef struct {
3006 	char *dptr;
3007 	int dsize;
3008 } datum;
3009 #endif
3010 
3011 /*
3012  * Translate NDBM calls into DB calls so that DB doesn't step on the
3013  * application's name space.
3014  */
3015 #define	dbm_clearerr(a)		__db_ndbm_clearerr(a)
3016 #define	dbm_close(a)		__db_ndbm_close(a)
3017 #define	dbm_delete(a, b)	__db_ndbm_delete(a, b)
3018 #define	dbm_dirfno(a)		__db_ndbm_dirfno(a)
3019 #define	dbm_error(a)		__db_ndbm_error(a)
3020 #define	dbm_fetch(a, b)		__db_ndbm_fetch(a, b)
3021 #define	dbm_firstkey(a)		__db_ndbm_firstkey(a)
3022 #define	dbm_nextkey(a)		__db_ndbm_nextkey(a)
3023 #define	dbm_open(a, b, c)	__db_ndbm_open(a, b, c)
3024 #define	dbm_pagfno(a)		__db_ndbm_pagfno(a)
3025 #define	dbm_rdonly(a)		__db_ndbm_rdonly(a)
3026 #define	dbm_store(a, b, c, d) \
3027 	__db_ndbm_store(a, b, c, d)
3028 
3029 /*
3030  * Translate DBM calls into DB calls so that DB doesn't step on the
3031  * application's name space.
3032  *
3033  * The global variables dbrdonly, dirf and pagf were not retained when 4BSD
3034  * replaced the dbm interface with ndbm, and are not supported here.
3035  *
3036  * Definition of 'store' interface will cause macro conflict for modern
3037  * compiler with C++11 support, we will exclude this case here.
3038  */
3039 #define	dbminit(a)	__db_dbm_init(a)
3040 #define	dbmclose	__db_dbm_close
3041 #if !defined(__cplusplus)
3042 #define	delete(a)	__db_dbm_delete(a)
3043 #define	store(a, b)	__db_dbm_store(a, b)
3044 #endif
3045 #define	fetch(a)	__db_dbm_fetch(a)
3046 #define	firstkey	__db_dbm_firstkey
3047 #define	nextkey(a)	__db_dbm_nextkey(a)
3048 
3049 /*******************************************************
3050  * Hsearch historic interface.
3051  *******************************************************/
3052 typedef enum {
3053 	FIND, ENTER
3054 } ACTION;
3055 
3056 typedef struct entry {
3057 	char *key;
3058 	char *data;
3059 } ENTRY;
3060 
3061 #define	hcreate(a)	__db_hcreate(a)
3062 #define	hdestroy	__db_hdestroy
3063 #define	hsearch(a, b)	__db_hsearch(a, b)
3064 
3065 #endif /* DB_DBM_HSEARCH */
3066 
3067 #if defined(__cplusplus)
3068 }
3069 #endif
3070 
3071 #endif /* !_DB_H_ */
3072 /* DO NOT EDIT: automatically built by dist/s_apiflags. */
3073 #define	DB_AGGRESSIVE				0x00000001
3074 #define	DB_ARCH_ABS				0x00000001
3075 #define	DB_ARCH_DATA				0x00000002
3076 #define	DB_ARCH_LOG				0x00000004
3077 #define	DB_ARCH_REMOVE				0x00000008
3078 #define	DB_AUTO_COMMIT				0x00000100
3079 #define	DB_BACKUP_CLEAN				0x00000002
3080 #define	DB_BACKUP_DEEP_COPY			0x00000008
3081 #define	DB_BACKUP_FILES				0x00000010
3082 #define	DB_BACKUP_NO_LOGS			0x00000020
3083 #define	DB_BACKUP_SINGLE_DIR			0x00000040
3084 #define	DB_BACKUP_UPDATE			0x00000080
3085 #define	DB_BOOTSTRAP_HELPER			0x00000001
3086 #define	DB_CDB_ALLDB				0x00000040
3087 #define	DB_CHKSUM				0x00000008
3088 #define	DB_CKP_INTERNAL				0x00000002
3089 #define	DB_CONVERT				0x00000001
3090 #define	DB_CREATE				0x00000001
3091 #define	DB_CURSOR_BULK				0x00000001
3092 #define	DB_CURSOR_TRANSIENT			0x00000008
3093 #define	DB_CXX_NO_EXCEPTIONS			0x00000002
3094 #define	DB_DATABASE_LOCKING			0x00000080
3095 #define	DB_DIRECT				0x00000020
3096 #define	DB_DIRECT_DB				0x00000200
3097 #define	DB_DSYNC_DB				0x00000400
3098 #define	DB_DUP					0x00000010
3099 #define	DB_DUPSORT				0x00000002
3100 #define	DB_DURABLE_UNKNOWN			0x00000040
3101 #define	DB_ENCRYPT				0x00000001
3102 #define	DB_ENCRYPT_AES				0x00000001
3103 #define	DB_EXCL					0x00000004
3104 #define	DB_EXTENT				0x00000100
3105 #define	DB_FAILCHK				0x00000010
3106 #define	DB_FAILCHK_ISALIVE			0x00000040
3107 #define	DB_FAST_STAT				0x00000001
3108 #define	DB_FCNTL_LOCKING			0x00001000
3109 #define	DB_FLUSH				0x00000002
3110 #define	DB_FORCE				0x00000001
3111 #define	DB_FORCESYNC				0x00000001
3112 #define	DB_FORCESYNCENV				0x00000002
3113 #define	DB_FOREIGN_ABORT			0x00000001
3114 #define	DB_FOREIGN_CASCADE			0x00000002
3115 #define	DB_FOREIGN_NULLIFY			0x00000004
3116 #define	DB_FREELIST_ONLY			0x00000001
3117 #define	DB_FREE_SPACE				0x00000002
3118 #define	DB_GROUP_CREATOR			0x00000002
3119 #define	DB_HOTBACKUP_IN_PROGRESS		0x00000800
3120 #define	DB_IGNORE_LEASE				0x00001000
3121 #define	DB_IMMUTABLE_KEY			0x00000002
3122 #define	DB_INIT_CDB				0x00000080
3123 #define	DB_INIT_LOCK				0x00000100
3124 #define	DB_INIT_LOG				0x00000200
3125 #define	DB_INIT_MPOOL				0x00000400
3126 #define	DB_INIT_MUTEX				0x00000800
3127 #define	DB_INIT_REP				0x00001000
3128 #define	DB_INIT_TXN				0x00002000
3129 #define	DB_INORDER				0x00000020
3130 #define	DB_INTERNAL_BLOB_DB			0x00002000
3131 #define	DB_INTERNAL_PERSISTENT_DB		0x00004000
3132 #define	DB_INTERNAL_TEMPORARY_DB		0x00008000
3133 #define	DB_JOIN_NOSORT				0x00000001
3134 #define	DB_LEGACY				0x00000004
3135 #define	DB_LOCAL_SITE				0x00000008
3136 #define	DB_LOCKDOWN				0x00004000
3137 #define	DB_LOCK_CHECK				0x00000001
3138 #define	DB_LOCK_IGNORE_REC			0x00000002
3139 #define	DB_LOCK_NOWAIT				0x00000004
3140 #define	DB_LOCK_RECORD				0x00000008
3141 #define	DB_LOCK_SET_TIMEOUT			0x00000010
3142 #define	DB_LOCK_SWITCH				0x00000020
3143 #define	DB_LOCK_UPGRADE				0x00000040
3144 #define	DB_LOG_AUTO_REMOVE			0x00000001
3145 #define	DB_LOG_CHKPNT				0x00000001
3146 #define	DB_LOG_COMMIT				0x00000004
3147 #define	DB_LOG_DIRECT				0x00000002
3148 #define	DB_LOG_DSYNC				0x00000004
3149 #define	DB_LOG_EXT_FILE				0x00000008
3150 #define	DB_LOG_BLOB				0x00000008
3151 #define	DB_LOG_IN_MEMORY			0x00000010
3152 #define	DB_LOG_NOCOPY				0x00000008
3153 #define	DB_LOG_NOSYNC				0x00000020
3154 #define	DB_LOG_NOT_DURABLE			0x00000010
3155 #define	DB_LOG_NO_DATA				0x00000002
3156 #define	DB_LOG_VERIFY_CAF			0x00000001
3157 #define	DB_LOG_VERIFY_DBFILE			0x00000002
3158 #define	DB_LOG_VERIFY_ERR			0x00000004
3159 #define	DB_LOG_VERIFY_FORWARD			0x00000008
3160 #define	DB_LOG_VERIFY_INTERR			0x00000010
3161 #define	DB_LOG_VERIFY_PARTIAL			0x00000020
3162 #define	DB_LOG_VERIFY_VERBOSE			0x00000040
3163 #define	DB_LOG_VERIFY_WARNING			0x00000080
3164 #define	DB_LOG_WRNOSYNC				0x00000020
3165 #define	DB_LOG_ZERO				0x00000040
3166 #define	DB_MPOOL_CREATE				0x00000001
3167 #define	DB_MPOOL_DIRTY				0x00000002
3168 #define	DB_MPOOL_DISCARD			0x00000001
3169 #define	DB_MPOOL_EDIT				0x00000004
3170 #define	DB_MPOOL_FREE				0x00000008
3171 #define	DB_MPOOL_LAST				0x00000010
3172 #define	DB_MPOOL_NEW				0x00000020
3173 #define	DB_MPOOL_NOFILE				0x00000001
3174 #define	DB_MPOOL_NOLOCK				0x00000004
3175 #define	DB_MPOOL_TRY				0x00000040
3176 #define	DB_MPOOL_UNLINK				0x00000002
3177 #define	DB_MULTIPLE				0x00000800
3178 #define	DB_MULTIPLE_KEY				0x00004000
3179 #define	DB_MULTIVERSION				0x00000008
3180 #define	DB_MUTEX_ALLOCATED			0x00000001
3181 #define	DB_MUTEX_LOCKED				0x00000002
3182 #define	DB_MUTEX_LOGICAL_LOCK			0x00000004
3183 #define	DB_MUTEX_OWNER_DEAD			0x00000020
3184 #define	DB_MUTEX_PROCESS_ONLY			0x00000008
3185 #define	DB_MUTEX_SELF_BLOCK			0x00000010
3186 #define	DB_MUTEX_SHARED				0x00000040
3187 #define	DB_NOERROR				0x00010000
3188 #define	DB_NOFLUSH				0x00001000
3189 #define	DB_NOLOCKING				0x00002000
3190 #define	DB_NOMMAP				0x00000010
3191 #define	DB_NOORDERCHK				0x00000002
3192 #define	DB_NOPANIC				0x00004000
3193 #define	DB_NOSYNC				0x00000001
3194 #define	DB_NO_AUTO_COMMIT			0x00020000
3195 #define	DB_NO_CHECKPOINT			0x00008000
3196 #define	DB_ODDFILESIZE				0x00000080
3197 #define	DB_ORDERCHKONLY				0x00000004
3198 #define	DB_OVERWRITE				0x00008000
3199 #define	DB_PANIC_ENVIRONMENT			0x00010000
3200 #define	DB_PRINTABLE				0x00000008
3201 #define	DB_PRIVATE				0x00010000
3202 #define	DB_PR_PAGE				0x00000010
3203 #define	DB_PR_RECOVERYTEST			0x00000020
3204 #define	DB_RDONLY				0x00000400
3205 #define	DB_RDWRMASTER				0x00040000
3206 #define	DB_READ_COMMITTED			0x00000400
3207 #define	DB_READ_UNCOMMITTED			0x00000200
3208 #define	DB_RECNUM				0x00000040
3209 #define	DB_RECOVER				0x00000002
3210 #define	DB_RECOVER_FATAL			0x00020000
3211 #define	DB_REGION_INIT				0x00020000
3212 #define	DB_REGISTER				0x00040000
3213 #define	DB_RENUMBER				0x00000080
3214 #define	DB_REPMGR_CONF_2SITE_STRICT		0x00000001
3215 #define	DB_REPMGR_CONF_DISABLE_POLL		0x00000002
3216 #define	DB_REPMGR_CONF_DISABLE_SSL		0x00000004
3217 #define	DB_REPMGR_CONF_ELECTIONS		0x00000008
3218 #define	DB_REPMGR_CONF_ENABLE_EPOLL		0x00000010
3219 #define	DB_REPMGR_CONF_FORWARD_WRITES		0x00000020
3220 #define	DB_REPMGR_CONF_PREFMAS_CLIENT		0x00000040
3221 #define	DB_REPMGR_CONF_PREFMAS_MASTER		0x00000080
3222 #define	DB_REPMGR_NEED_RESPONSE			0x00000001
3223 #define	DB_REPMGR_PEER				0x00000010
3224 #define	DB_REP_ANYWHERE				0x00000001
3225 #define	DB_REP_CLIENT				0x00000001
3226 #define	DB_REP_CONF_AUTOINIT			0x00000100
3227 #define	DB_REP_CONF_AUTOROLLBACK		0x00000200
3228 #define	DB_REP_CONF_BULK			0x00000400
3229 #define	DB_REP_CONF_DELAYCLIENT			0x00000800
3230 #define	DB_REP_CONF_ELECT_LOGLENGTH		0x00001000
3231 #define	DB_REP_CONF_INMEM			0x00002000
3232 #define	DB_REP_CONF_LEASE			0x00004000
3233 #define	DB_REP_CONF_NOWAIT			0x00008000
3234 #define	DB_REP_ELECTION				0x00000004
3235 #define	DB_REP_MASTER				0x00000002
3236 #define	DB_REP_NOBUFFER				0x00000002
3237 #define	DB_REP_PERMANENT			0x00000004
3238 #define	DB_REP_REREQUEST			0x00000008
3239 #define	DB_REVSPLITOFF				0x00000100
3240 #define	DB_RMW					0x00002000
3241 #define	DB_SALVAGE				0x00000040
3242 #define	DB_SA_SKIPFIRSTKEY			0x00000080
3243 #define	DB_SA_UNKNOWNKEY			0x00000100
3244 #define	DB_SEQ_DEC				0x00000001
3245 #define	DB_SEQ_INC				0x00000002
3246 #define	DB_SEQ_RANGE_SET			0x00000004
3247 #define	DB_SEQ_WRAP				0x00000008
3248 #define	DB_SEQ_WRAPPED				0x00000010
3249 #define	DB_SET_LOCK_TIMEOUT			0x00000001
3250 #define	DB_SET_MUTEX_FAILCHK_TIMEOUT		0x00000004
3251 #define	DB_SET_REG_TIMEOUT			0x00000008
3252 #define	DB_SET_TXN_NOW				0x00000010
3253 #define	DB_SET_TXN_TIMEOUT			0x00000002
3254 #define	DB_SHALLOW_DUP				0x00000100
3255 #define	DB_SLICED				0x00000800
3256 #define	DB_SNAPSHOT				0x00000200
3257 #define	DB_STAT_ALL				0x00000004
3258 #define	DB_STAT_ALLOC				0x00000008
3259 #define	DB_STAT_CLEAR				0x00000001
3260 #define	DB_STAT_LOCK_CONF			0x00000010
3261 #define	DB_STAT_LOCK_LOCKERS			0x00000020
3262 #define	DB_STAT_LOCK_OBJECTS			0x00000040
3263 #define	DB_STAT_LOCK_PARAMS			0x00000080
3264 #define	DB_STAT_MEMP_HASH			0x00000010
3265 #define	DB_STAT_MEMP_NOERROR			0x00000020
3266 #define	DB_STAT_SUBSYSTEM			0x00000002
3267 #define	DB_STAT_SUMMARY				0x00000010
3268 #define	DB_ST_DUPOK				0x00000200
3269 #define	DB_ST_DUPSET				0x00000400
3270 #define	DB_ST_DUPSORT				0x00000800
3271 #define	DB_ST_IS_RECNO				0x00001000
3272 #define	DB_ST_OVFL_LEAF				0x00002000
3273 #define	DB_ST_RECNUM				0x00004000
3274 #define	DB_ST_RELEN				0x00008000
3275 #define	DB_ST_TOPLEVEL				0x00010000
3276 #define	DB_SYSTEM_MEM				0x00080000
3277 #define	DB_THREAD				0x00000020
3278 #define	DB_TIME_NOTGRANTED			0x00040000
3279 #define	DB_TRUNCATE				0x00080000
3280 #define	DB_TXN_BULK				0x00000010
3281 #define	DB_TXN_DISPATCH				0x00000040
3282 #define	DB_TXN_FAMILY				0x00000080
3283 #define	DB_TXN_NOSYNC				0x00000001
3284 #define	DB_TXN_NOT_DURABLE			0x00000004
3285 #define	DB_TXN_NOWAIT				0x00000002
3286 #define	DB_TXN_SNAPSHOT				0x00000004
3287 #define	DB_TXN_SYNC				0x00000008
3288 #define	DB_TXN_WAIT				0x00000100
3289 #define	DB_TXN_WRITE_NOSYNC			0x00000020
3290 #define	DB_UNREF				0x00020000
3291 #define	DB_UPGRADE				0x00000002
3292 #define	DB_USE_ENVIRON				0x00000004
3293 #define	DB_USE_ENVIRON_ROOT			0x00000008
3294 #define	DB_VERB_BACKUP				0x00000001
3295 #define	DB_VERB_DEADLOCK			0x00000002
3296 #define	DB_VERB_FILEOPS				0x00000004
3297 #define	DB_VERB_FILEOPS_ALL			0x00000008
3298 #define	DB_VERB_MVCC				0x00000010
3299 #define	DB_VERB_RECOVERY			0x00000020
3300 #define	DB_VERB_REGISTER			0x00000040
3301 #define	DB_VERB_REPLICATION			0x00000080
3302 #define	DB_VERB_REPMGR_CONNFAIL			0x00000100
3303 #define	DB_VERB_REPMGR_MISC			0x00000200
3304 #define	DB_VERB_REPMGR_SSL_ALL			0x00000400
3305 #define	DB_VERB_REPMGR_SSL_CONN			0x00000800
3306 #define	DB_VERB_REPMGR_SSL_IO			0x00001000
3307 #define	DB_VERB_REP_ELECT			0x00002000
3308 #define	DB_VERB_REP_LEASE			0x00004000
3309 #define	DB_VERB_REP_MISC			0x00008000
3310 #define	DB_VERB_REP_MSGS			0x00010000
3311 #define	DB_VERB_REP_SYNC			0x00020000
3312 #define	DB_VERB_REP_SYSTEM			0x00040000
3313 #define	DB_VERB_REP_TEST			0x00080000
3314 #define	DB_VERB_SLICE				0x00100000
3315 #define	DB_VERB_WAITSFOR			0x00200000
3316 #define	DB_VERIFY				0x00000004
3317 #define	DB_VERIFY_PARTITION			0x00040000
3318 #define	DB_WRITECURSOR				0x00000010
3319 #define	DB_WRITELOCK				0x00000020
3320 #define	DB_WRITEOPEN				0x00100000
3321 #define	DB_XA_CREATE				0x00000001
3322 #define	DB_YIELDCPU				0x00080000
3323 
3324 /* DO NOT EDIT: automatically built by dist/s_include. */
3325 #ifndef	_DB_EXT_PROT_IN_
3326 #define	_DB_EXT_PROT_IN_
3327 
3328 #if defined(__cplusplus)
3329 extern "C" {
3330 #endif
3331 
3332 int db_copy __P((DB_ENV *, const char *, const char *, const char *));
3333 int db_create __P((DB **, DB_ENV *, u_int32_t));
3334 char *db_strerror __P((int));
3335 int db_env_set_func_assert __P((void (*)(const char *, const char *, int)));
3336 int db_env_set_func_close __P((int (*)(int)));
3337 int db_env_set_func_dirfree __P((void (*)(char **, int)));
3338 int db_env_set_func_dirlist __P((int (*)(const char *, char ***, int *)));
3339 int db_env_set_func_exists __P((int (*)(const char *, int *)));
3340 int db_env_set_func_free __P((void (*)(void *)));
3341 int db_env_set_func_fsync __P((int (*)(int)));
3342 int db_env_set_func_ftruncate __P((int (*)(int, off_t)));
3343 int db_env_set_func_ioinfo __P((int (*)(const char *, int, u_int32_t *, u_int32_t *, u_int32_t *)));
3344 int db_env_set_func_malloc __P((void *(*)(size_t)));
3345 int db_env_set_func_file_map __P((int (*)(DB_ENV *, char *, size_t, int, void **), int (*)(DB_ENV *, void *)));
3346 int db_env_set_func_region_map __P((int (*)(DB_ENV *, char *, size_t, int *, void **), int (*)(DB_ENV *, void *)));
3347 int db_env_set_func_pread __P((ssize_t (*)(int, void *, size_t, off_t)));
3348 int db_env_set_func_pwrite __P((ssize_t (*)(int, const void *, size_t, off_t)));
3349 int db_env_set_func_open __P((int (*)(const char *, int, ...)));
3350 int db_env_set_func_read __P((ssize_t (*)(int, void *, size_t)));
3351 int db_env_set_func_realloc __P((void *(*)(void *, size_t)));
3352 int db_env_set_func_rename __P((int (*)(const char *, const char *)));
3353 int db_env_set_func_seek __P((int (*)(int, off_t, int)));
3354 int db_env_set_func_unlink __P((int (*)(const char *)));
3355 int db_env_set_func_write __P((ssize_t (*)(int, const void *, size_t)));
3356 int db_env_set_func_yield __P((int (*)(u_long, u_long)));
3357 int db_env_create __P((DB_ENV **, u_int32_t));
3358 char *db_version __P((int *, int *, int *));
3359 char *db_full_version __P((int *, int *, int *, int *, int *));
3360 int log_compare __P((const DB_LSN *, const DB_LSN *));
3361 #if defined(DB_WIN32) && !defined(DB_WINCE)
3362 int db_env_set_win_security __P((SECURITY_ATTRIBUTES *sa));
3363 #endif
3364 int db_sequence_create __P((DB_SEQUENCE **, DB *, u_int32_t));
3365 #if DB_DBM_HSEARCH != 0
3366 int	 __db_ndbm_clearerr __P((DBM *));
3367 void	 __db_ndbm_close __P((DBM *));
3368 int	 __db_ndbm_delete __P((DBM *, datum));
3369 int	 __db_ndbm_dirfno __P((DBM *));
3370 int	 __db_ndbm_error __P((DBM *));
3371 datum __db_ndbm_fetch __P((DBM *, datum));
3372 datum __db_ndbm_firstkey __P((DBM *));
3373 datum __db_ndbm_nextkey __P((DBM *));
3374 DBM	*__db_ndbm_open __P((const char *, int, int));
3375 int	 __db_ndbm_pagfno __P((DBM *));
3376 int	 __db_ndbm_rdonly __P((DBM *));
3377 int	 __db_ndbm_store __P((DBM *, datum, datum, int));
3378 int	 __db_dbm_close __P((void));
3379 int	 __db_dbm_delete __P((datum));
3380 datum __db_dbm_fetch __P((datum));
3381 datum __db_dbm_firstkey __P((void));
3382 int	 __db_dbm_init __P((char *));
3383 datum __db_dbm_nextkey __P((datum));
3384 int	 __db_dbm_store __P((datum, datum));
3385 #endif
3386 #if DB_DBM_HSEARCH != 0
3387 int __db_hcreate __P((size_t));
3388 ENTRY *__db_hsearch __P((ENTRY, ACTION));
3389 void __db_hdestroy __P((void));
3390 #endif
3391 
3392 #if defined(__cplusplus)
3393 }
3394 #endif
3395 #endif /* !_DB_EXT_PROT_IN_ */
3396