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