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