Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-05-18 08:29:45

0001 /*
0002  * Copyright (c) 1996, 2020 Oracle and/or its affiliates.  All rights reserved.
0003  *
0004  * See the file LICENSE for license information.
0005  *
0006  * $Id$
0007  *
0008  * db.h include file layout:
0009  *  General.
0010  *  Database Environment.
0011  *  Locking subsystem.
0012  *  Logging subsystem.
0013  *  Shared buffer cache (mpool) subsystem.
0014  *  Transaction subsystem.
0015  *  Access methods.
0016  *  Access method cursors.
0017  *  Dbm/Ndbm, Hsearch historic interfaces.
0018  */
0019 
0020 #ifndef _DB_H_
0021 #define _DB_H_
0022 
0023 #ifndef __NO_SYSTEM_INCLUDES
0024 #include <sys/types.h>
0025 #include <inttypes.h>
0026 #include <stdint.h>
0027 #include <stddef.h>
0028 #include <stdio.h>
0029 #include <unistd.h>
0030 #include <pthread.h>
0031 #endif
0032 
0033 
0034 #if defined(__cplusplus)
0035 extern "C" {
0036 #endif
0037 
0038 
0039 #undef __P
0040 #define __P(protos) protos
0041 
0042 /*
0043  * Berkeley DB version information.
0044  */
0045 #define DB_VERSION_MAJOR    18
0046 #define DB_VERSION_MINOR    1
0047 #define DB_VERSION_PATCH    40
0048 #define DB_VERSION_STRING   "Berkeley DB 18.1.40: (May 29, 2020)"
0049 #define DB_VERSION_FULL_STRING  "Berkeley DB Release 18.1, library version 18.1.40: (May 29, 2020)"
0050 
0051 /*
0052  * These two version numbers are deprecated and will be removed in a future
0053  * release.  Until that time they are the same as the major and minor numbers.
0054  */
0055 #define DB_VERSION_FAMILY   18
0056 #define DB_VERSION_RELEASE  1
0057 
0058 /*
0059  * !!!
0060  * Berkeley DB uses specifically sized types.  If they're not provided by
0061  * the system, typedef them here.
0062  *
0063  * We protect them against multiple inclusion using __BIT_TYPES_DEFINED__,
0064  * as does BIND and Kerberos, since we don't know for sure what #include
0065  * files the user is using.
0066  *
0067  * !!!
0068  * We also provide the standard u_int, u_long etc., if they're not provided
0069  * by the system.
0070  */
0071 #ifndef __BIT_TYPES_DEFINED__
0072 #define __BIT_TYPES_DEFINED__
0073 
0074 
0075 
0076 
0077 
0078 
0079 
0080 #endif
0081 
0082 
0083 
0084 
0085 
0086 
0087 /*
0088  * Missing ANSI types.
0089  *
0090  * uintmax_t --
0091  * Largest unsigned type, used to align structures in memory.  We don't store
0092  * floating point types in structures, so integral types should be sufficient
0093  * (and we don't have to worry about systems that store floats in other than
0094  * power-of-2 numbers of bytes).  Additionally this fixes compilers that rewrite
0095  * structure assignments and ANSI C memcpy calls to be in-line instructions
0096  * that happen to require alignment.
0097  *
0098  * uintptr_t --
0099  * Unsigned type that's the same size as a pointer.  There are places where
0100  * DB modifies pointers by discarding the bottom bits to guarantee alignment.
0101  * We can't use uintmax_t, it may be larger than the pointer, and compilers
0102  * get upset about that.  So far we haven't run on any machine where there's
0103  * no unsigned type the same size as a pointer -- here's hoping.
0104  */
0105 
0106 
0107 
0108 
0109 
0110 typedef long db_off_t;
0111 #define DB_OFF_T_MAX INT64_MAX
0112 
0113 
0114 #ifdef HAVE_MIXED_SIZE_ADDRESSING
0115 typedef u_int32_t db_size_t;
0116 #else
0117 typedef size_t db_size_t;
0118 #endif
0119 
0120 #ifdef HAVE_MIXED_SIZE_ADDRESSING
0121 typedef int32_t db_ssize_t;
0122 #else
0123 typedef ssize_t db_ssize_t;
0124 #endif
0125 
0126 
0127 /*
0128  * Sequences are only available on machines with 64-bit integral types.
0129  */
0130 typedef long db_seq_t;
0131 
0132 /* Thread and process identification. */
0133 typedef pthread_t db_threadid_t;
0134 
0135 /* Basic types that are exported or quasi-exported. */
0136 typedef u_int32_t   db_pgno_t;  /* Page number type. */
0137 typedef u_int16_t   db_indx_t;  /* Page offset type. */
0138 #define DB_MAX_PAGES    0xffffffff  /* >= # of pages in a file */
0139 
0140 typedef u_int32_t   db_recno_t; /* Record number type. */
0141 #define DB_MAX_RECORDS  0xffffffff  /* >= # of records in a recno tree. */
0142 
0143 typedef u_int32_t   db_timeout_t;   /* Type of a timeout in microseconds. */
0144 
0145 /*
0146  * Region offsets are the difference between a pointer in a region and the
0147  * region's base address.  With private environments, both addresses are the
0148  * result of calling malloc, and we can't assume anything about what malloc
0149  * will return, so region offsets have to be able to hold differences between
0150  * arbitrary pointers.
0151  */
0152 typedef db_size_t   roff_t;
0153 
0154 /*
0155  * Forward structure declarations, so we can declare pointers and
0156  * applications can get type checking.
0157  */
0158 struct __channel;   typedef struct __channel CHANNEL;
0159 struct __db;        typedef struct __db DB;
0160 struct __db_bt_stat;    typedef struct __db_bt_stat DB_BTREE_STAT;
0161 struct __db_channel;    typedef struct __db_channel DB_CHANNEL;
0162 struct __db_cipher; typedef struct __db_cipher DB_CIPHER;
0163 struct __db_compact;    typedef struct __db_compact DB_COMPACT;
0164 struct __db_dbt;    typedef struct __db_dbt DBT;
0165 struct __db_distab; typedef struct __db_distab DB_DISTAB;
0166 struct __db_env;    typedef struct __db_env DB_ENV;
0167 struct __db_event_mutex_died_info;
0168     typedef struct __db_event_mutex_died_info DB_EVENT_MUTEX_DIED_INFO;
0169 struct __db_event_failchk_info;
0170     typedef struct __db_event_failchk_info DB_EVENT_FAILCHK_INFO;
0171 struct __db_h_stat; typedef struct __db_h_stat DB_HASH_STAT;
0172 struct __db_heap_rid;   typedef struct __db_heap_rid DB_HEAP_RID;
0173 struct __db_heap_stat;  typedef struct __db_heap_stat DB_HEAP_STAT;
0174 struct __db_ilock;  typedef struct __db_ilock DB_LOCK_ILOCK;
0175 struct __db_lock_hstat; typedef struct __db_lock_hstat DB_LOCK_HSTAT;
0176 struct __db_lock_pstat; typedef struct __db_lock_pstat DB_LOCK_PSTAT;
0177 struct __db_lock_stat;  typedef struct __db_lock_stat DB_LOCK_STAT;
0178 struct __db_lock_u; typedef struct __db_lock_u DB_LOCK;
0179 struct __db_locker; typedef struct __db_locker DB_LOCKER;
0180 struct __db_lockreq;    typedef struct __db_lockreq DB_LOCKREQ;
0181 struct __db_locktab;    typedef struct __db_locktab DB_LOCKTAB;
0182 struct __db_log;    typedef struct __db_log DB_LOG;
0183 struct __db_log_cursor; typedef struct __db_log_cursor DB_LOGC;
0184 struct __db_log_stat;   typedef struct __db_log_stat DB_LOG_STAT;
0185 struct __db_lsn;    typedef struct __db_lsn DB_LSN;
0186 struct __db_mpool;  typedef struct __db_mpool DB_MPOOL;
0187 struct __db_mpool_fstat;typedef struct __db_mpool_fstat DB_MPOOL_FSTAT;
0188 struct __db_mpool_stat; typedef struct __db_mpool_stat DB_MPOOL_STAT;
0189 struct __db_mpoolfile;  typedef struct __db_mpoolfile DB_MPOOLFILE;
0190 struct __db_mutex_stat; typedef struct __db_mutex_stat DB_MUTEX_STAT;
0191 struct __db_mutex_t;    typedef struct __db_mutex_t DB_MUTEX;
0192 struct __db_mutexmgr;   typedef struct __db_mutexmgr DB_MUTEXMGR;
0193 struct __db_preplist;   typedef struct __db_preplist DB_PREPLIST;
0194 struct __db_qam_stat;   typedef struct __db_qam_stat DB_QUEUE_STAT;
0195 struct __db_rep;    typedef struct __db_rep DB_REP;
0196 struct __db_rep_stat;   typedef struct __db_rep_stat DB_REP_STAT;
0197 struct __db_repmgr_conn_err;
0198     typedef struct __db_repmgr_conn_err DB_REPMGR_CONN_ERR;
0199 struct __db_repmgr_site;typedef struct __db_repmgr_site DB_REPMGR_SITE;
0200 struct __db_repmgr_stat;typedef struct __db_repmgr_stat DB_REPMGR_STAT;
0201 struct __db_seq_record; typedef struct __db_seq_record DB_SEQ_RECORD;
0202 struct __db_seq_stat;   typedef struct __db_seq_stat DB_SEQUENCE_STAT;
0203 struct __db_stream; typedef struct __db_stream DB_STREAM;
0204 struct __db_site;   typedef struct __db_site DB_SITE;
0205 struct __db_sequence;   typedef struct __db_sequence DB_SEQUENCE;
0206 struct __db_thread_info;typedef struct __db_thread_info DB_THREAD_INFO;
0207 struct __db_txn;    typedef struct __db_txn DB_TXN;
0208 struct __db_txn_active; typedef struct __db_txn_active DB_TXN_ACTIVE;
0209 struct __db_txn_active_slice;
0210     typedef struct __db_txn_active_slice DB_TXN_ACTIVE_SLICE;
0211 struct __db_txn_stat;   typedef struct __db_txn_stat DB_TXN_STAT;
0212 struct __db_txn_token;  typedef struct __db_txn_token DB_TXN_TOKEN;
0213 struct __db_txnmgr; typedef struct __db_txnmgr DB_TXNMGR;
0214 struct __dbc;       typedef struct __dbc DBC;
0215 struct __dbc_internal;  typedef struct __dbc_internal DBC_INTERNAL;
0216 struct __env;       typedef struct __env ENV;
0217 struct __fh_t;      typedef struct __fh_t DB_FH;
0218 struct __fname;     typedef struct __fname FNAME;
0219 struct __key_range; typedef struct __key_range DB_KEY_RANGE;
0220 struct __mpoolfile; typedef struct __mpoolfile MPOOLFILE;
0221 struct __db_logvrfy_config;
0222 typedef struct __db_logvrfy_config DB_LOG_VERIFY_CONFIG;
0223 
0224 /*
0225  * The Berkeley DB API flags are automatically-generated -- the following flag
0226  * names are no longer used, but remain for compatibility reasons.
0227  */
0228 #define DB_DEGREE_2       DB_READ_COMMITTED
0229 #define DB_DIRTY_READ         DB_READ_UNCOMMITTED
0230 #define DB_JOINENV        0x0
0231 
0232 /* Key/data structure -- a Data-Base Thang. */
0233 struct __db_dbt {
0234     void     *data;         /* Key/data */
0235     u_int32_t size;         /* key/data length */
0236 
0237     u_int32_t ulen;         /* RO: length of user buffer. */
0238     u_int32_t dlen;         /* RO: get/put record length. */
0239     u_int32_t doff;         /* RO: get/put record offset. */
0240 
0241     void *app_data;
0242 
0243 #define DB_DBT_APPMALLOC    0x0001  /* Callback allocated memory. */
0244 #define DB_DBT_BULK     0x0002  /* Internal: Insert if duplicate. */
0245 #define DB_DBT_DUPOK        0x0004  /* Internal: Insert if duplicate. */
0246 #define DB_DBT_ISSET        0x0008  /* Lower level calls set value. */
0247 #define DB_DBT_MALLOC       0x0010  /* Return in malloc'd memory. */
0248 #define DB_DBT_MULTIPLE     0x0020  /* References multiple records. */
0249 #define DB_DBT_PARTIAL      0x0040  /* Partial put/get. */
0250 #define DB_DBT_REALLOC      0x0080  /* Return in realloc'd memory. */
0251 #define DB_DBT_READONLY     0x0100  /* Readonly, don't update. */
0252 #define DB_DBT_STREAMING    0x0200  /* Internal: DBT is being streamed. */
0253 #define DB_DBT_USERCOPY     0x0400  /* Use the user-supplied callback. */
0254 #define DB_DBT_USERMEM      0x0800  /* Return in user's memory. */
0255 #define DB_DBT_BLOB     0x1000  /* Alias DB_DBT_EXT_FILE. */
0256 #define DB_DBT_EXT_FILE     0x1000  /* Data item is an external file. */
0257 #define DB_DBT_BLOB_REC     0x2000  /* Internal: Blob database record. */
0258     u_int32_t flags;
0259 };
0260 
0261 /*******************************************************
0262  * Mutexes.
0263  *******************************************************/
0264 /* 
0265  * When mixed size addressing is supported mutexes need to be the same size
0266  * independent of the process address size is.
0267  */
0268 #ifdef HAVE_MIXED_SIZE_ADDRESSING
0269 typedef db_size_t   db_mutex_t;
0270 #else
0271 typedef uintptr_t   db_mutex_t;
0272 #endif
0273 
0274 struct __db_mutex_stat { /* SHARED */
0275     /* The following fields are maintained in the region's copy. */
0276     u_int32_t st_mutex_align;   /* Mutex alignment */
0277     u_int32_t st_mutex_tas_spins;   /* Mutex test-and-set spins */
0278     u_int32_t st_mutex_init;    /* Initial mutex count */
0279     u_int32_t st_mutex_cnt;     /* Mutex count */
0280     u_int32_t st_mutex_max;     /* Mutex max */
0281     u_int32_t st_mutex_free;    /* Available mutexes */
0282     u_int32_t st_mutex_inuse;   /* Mutexes in use */
0283     u_int32_t st_mutex_inuse_max;   /* Maximum mutexes ever in use */
0284 
0285     /* The following fields are filled-in from other places. */
0286 #ifndef __TEST_DB_NO_STATISTICS
0287     uintmax_t st_region_wait;   /* Region lock granted after wait. */
0288     uintmax_t st_region_nowait; /* Region lock granted without wait. */
0289     roff_t    st_regsize;       /* Region size. */
0290     roff_t    st_regmax;        /* Region max. */
0291 #endif
0292 };
0293 
0294 /* Buffers passed to __mutex_describe() must be at least this large. */
0295 #define DB_MUTEX_DESCRIBE_STRLEN    128
0296 
0297 /* This is the info of a DB_EVENT_MUTEX_DIED event notification. */
0298 struct __db_event_mutex_died_info {
0299     pid_t         pid;  /* Process which last owned the mutex */
0300     db_threadid_t tid;  /* Thread which last owned the mutex */
0301     db_mutex_t    mutex;    /* ID of the mutex */
0302     char          desc[DB_MUTEX_DESCRIBE_STRLEN];
0303 };
0304 
0305 /* This is the info of a DB_EVENT_FAILCHK event notification. */
0306 #define DB_FAILURE_SYMPTOM_SIZE 120
0307 struct __db_event_failchk_info {
0308     int error;
0309     char    symptom[DB_FAILURE_SYMPTOM_SIZE];
0310 };
0311 /* This is the length of the buffer passed to DB_ENV->thread_id_string() */
0312 #define DB_THREADID_STRLEN  128
0313 
0314 /*
0315  * Type of the number of slices in a sliced environment; also the subscript
0316  * into a slice array, such as DB.db_slices[].
0317  */
0318 typedef u_int32_t db_slice_t;
0319 
0320 /*******************************************************
0321  * Locking.
0322  *******************************************************/
0323 #define DB_LOCKVERSION  1
0324 
0325 #define DB_FILE_ID_LEN      20  /* Unique file ID length. */
0326 
0327 /*
0328  * Deadlock detector modes; used in the DB_ENV structure to configure the
0329  * locking subsystem.
0330  */
0331 #define DB_LOCK_NORUN       0
0332 #define DB_LOCK_DEFAULT     1   /* Default policy. */
0333 #define DB_LOCK_EXPIRE      2   /* Only expire locks, no detection. */
0334 #define DB_LOCK_MAXLOCKS    3   /* Select locker with max locks. */
0335 #define DB_LOCK_MAXWRITE    4   /* Select locker with max writelocks. */
0336 #define DB_LOCK_MINLOCKS    5   /* Select locker with min locks. */
0337 #define DB_LOCK_MINWRITE    6   /* Select locker with min writelocks. */
0338 #define DB_LOCK_OLDEST      7   /* Select oldest locker. */
0339 #define DB_LOCK_RANDOM      8   /* Select random locker. */
0340 #define DB_LOCK_YOUNGEST    9   /* Select youngest locker. */
0341 
0342 /*
0343  * Simple R/W lock modes and for multi-granularity intention locking.
0344  *
0345  * !!!
0346  * These values are NOT random, as they are used as an index into the lock
0347  * conflicts arrays, i.e., DB_LOCK_IWRITE must be == 3, and DB_LOCK_IREAD
0348  * must be == 4.
0349  */
0350 typedef enum {
0351     DB_LOCK_NG=0,           /* Not granted. */
0352     DB_LOCK_READ=1,         /* Shared/read. */
0353     DB_LOCK_WRITE=2,        /* Exclusive/write. */
0354     DB_LOCK_WAIT=3,         /* Wait for event */
0355     DB_LOCK_IWRITE=4,       /* Intent exclusive/write. */
0356     DB_LOCK_IREAD=5,        /* Intent to share/read. */
0357     DB_LOCK_IWR=6,          /* Intent to read and write. */
0358     DB_LOCK_READ_UNCOMMITTED=7, /* Degree 1 isolation. */
0359     DB_LOCK_WWRITE=8        /* Was Written. */
0360 } db_lockmode_t;
0361 
0362 /*
0363  * Request types.
0364  */
0365 typedef enum {
0366     DB_LOCK_DUMP=0,         /* Display held locks. */
0367     DB_LOCK_GET=1,          /* Get the lock. */
0368     DB_LOCK_GET_TIMEOUT=2,      /* Get lock with a timeout. */
0369     DB_LOCK_INHERIT=3,      /* Pass locks to parent. */
0370     DB_LOCK_PUT=4,          /* Release the lock. */
0371     DB_LOCK_PUT_ALL=5,      /* Release locker's locks. */
0372     DB_LOCK_PUT_OBJ=6,      /* Release locker's locks on obj. */
0373     DB_LOCK_PUT_READ=7,     /* Release locker's read locks. */
0374     DB_LOCK_TIMEOUT=8,      /* Force a txn to timeout. */
0375     DB_LOCK_TRADE=9,        /* Trade locker ids on a lock. */
0376     DB_LOCK_UPGRADE_WRITE=10    /* Upgrade writes for dirty reads. */
0377 } db_lockop_t;
0378 
0379 /*
0380  * Status of a lock.
0381  */
0382 typedef enum  {
0383     DB_LSTAT_ABORTED=1,     /* Lock belongs to an aborted txn. */
0384     DB_LSTAT_EXPIRED=2,     /* Lock has expired. */
0385     DB_LSTAT_FREE=3,        /* Lock is unallocated. */
0386     DB_LSTAT_HELD=4,        /* Lock is currently held. */
0387     DB_LSTAT_PENDING=5,     /* Lock was waiting and has been
0388                      * promoted; waiting for the owner
0389                      * to run and upgrade it to held. */
0390     DB_LSTAT_WAITING=6      /* Lock is on the wait queue. */
0391 }db_status_t;
0392 
0393 /* Lock statistics structure. */
0394 struct __db_lock_stat { /* SHARED */
0395     u_int32_t st_id;        /* Last allocated locker ID. */
0396     u_int32_t st_cur_maxid;     /* Current maximum unused ID. */
0397     u_int32_t st_initlocks;     /* Initial number of locks in table. */
0398     u_int32_t st_initlockers;   /* Initial num of lockers in table. */
0399     u_int32_t st_initobjects;   /* Initial num of objects in table. */
0400     u_int32_t st_locks;     /* Current number of locks in table. */
0401     u_int32_t st_lockers;       /* Current num of lockers in table. */
0402     u_int32_t st_objects;       /* Current num of objects in table. */
0403     u_int32_t st_maxlocks;      /* Maximum number of locks in table. */
0404     u_int32_t st_maxlockers;    /* Maximum num of lockers in table. */
0405     u_int32_t st_maxobjects;    /* Maximum num of objects in table. */
0406     u_int32_t st_partitions;    /* number of partitions. */
0407     u_int32_t st_tablesize;     /* Size of object hash table. */
0408     int32_t   st_nmodes;        /* Number of lock modes. */
0409     u_int32_t st_nlockers;      /* Current number of lockers. */
0410 #ifndef __TEST_DB_NO_STATISTICS
0411     u_int32_t st_nlocks;        /* Current number of locks. */
0412     u_int32_t st_maxnlocks;     /* Maximum number of locks so far. */
0413     u_int32_t st_maxhlocks;     /* Maximum number of locks in any bucket. */
0414     uintmax_t st_locksteals;    /* Number of lock steals so far. */
0415     uintmax_t st_maxlsteals;    /* Maximum number steals in any partition. */
0416     u_int32_t st_maxnlockers;   /* Maximum number of lockers so far. */
0417     u_int32_t st_nobjects;      /* Current number of objects. */
0418     u_int32_t st_maxnobjects;   /* Maximum number of objects so far. */
0419     u_int32_t st_maxhobjects;   /* Maximum number of objectsin any bucket. */
0420     uintmax_t st_objectsteals;  /* Number of objects steals so far. */
0421     uintmax_t st_maxosteals;    /* Maximum number of steals in any partition. */
0422     uintmax_t st_nrequests;     /* Number of lock gets. */
0423     uintmax_t st_nreleases;     /* Number of lock puts. */
0424     uintmax_t st_nupgrade;      /* Number of lock upgrades. */
0425     uintmax_t st_ndowngrade;    /* Number of lock downgrades. */
0426     uintmax_t st_lock_wait;     /* Lock conflicts w/ subsequent wait */
0427     uintmax_t st_lock_nowait;   /* Lock conflicts w/o subsequent wait */
0428     uintmax_t st_ndeadlocks;    /* Number of lock deadlocks. */
0429     db_timeout_t st_locktimeout;    /* Lock timeout. */
0430     uintmax_t st_nlocktimeouts; /* Number of lock timeouts. */
0431     db_timeout_t st_txntimeout; /* Transaction timeout. */
0432     uintmax_t st_ntxntimeouts;  /* Number of transaction timeouts. */
0433     uintmax_t st_part_wait;     /* Partition lock granted after wait. */
0434     uintmax_t st_part_nowait;   /* Partition lock granted without wait. */
0435     uintmax_t st_part_max_wait; /* Max partition lock granted after wait. */
0436     uintmax_t st_part_max_nowait;   /* Max partition lock granted without wait. */
0437     uintmax_t st_objs_wait; /*  Object lock granted after wait. */
0438     uintmax_t st_objs_nowait;   /* Object lock granted without wait. */
0439     uintmax_t st_lockers_wait;  /* Locker lock granted after wait. */
0440     uintmax_t st_lockers_nowait;    /* Locker lock granted without wait. */
0441     uintmax_t st_region_wait;   /* Region lock granted after wait. */
0442     uintmax_t st_region_nowait; /* Region lock granted without wait. */
0443     uintmax_t st_nlockers_hit;  /* Lockers found in thread info. */
0444     uintmax_t st_nlockers_reused;   /* Lockers reallocated from thread info. */
0445     u_int32_t st_hash_len;      /* Max length of bucket. */
0446     roff_t    st_regsize;       /* Region size. */
0447 #endif
0448 };
0449 
0450 struct __db_lock_hstat { /* SHARED */
0451     uintmax_t st_nrequests;     /* Number of lock gets. */
0452     uintmax_t st_nreleases;     /* Number of lock puts. */
0453     uintmax_t st_nupgrade;      /* Number of lock upgrades. */
0454     uintmax_t st_ndowngrade;    /* Number of lock downgrades. */
0455     u_int32_t st_nlocks;        /* Current number of locks. */
0456     u_int32_t st_maxnlocks;     /* Maximum number of locks so far. */
0457     u_int32_t st_nobjects;      /* Current number of objects. */
0458     u_int32_t st_maxnobjects;   /* Maximum number of objects so far. */
0459     uintmax_t st_lock_wait;     /* Lock conflicts w/ subsequent wait */
0460     uintmax_t st_lock_nowait;   /* Lock conflicts w/o subsequent wait */
0461     uintmax_t st_nlocktimeouts; /* Number of lock timeouts. */
0462     uintmax_t st_ntxntimeouts;  /* Number of transaction timeouts. */
0463     u_int32_t st_hash_len;      /* Max length of bucket. */
0464 };
0465 
0466 struct __db_lock_pstat { /* SHARED */
0467     u_int32_t st_nlocks;        /* Current number of locks. */
0468     u_int32_t st_maxnlocks;     /* Maximum number of locks so far. */
0469     u_int32_t st_nobjects;      /* Current number of objects. */
0470     u_int32_t st_maxnobjects;   /* Maximum number of objects so far. */
0471     uintmax_t st_locksteals;    /* Number of lock steals so far. */
0472     uintmax_t st_objectsteals;  /* Number of objects steals so far. */
0473 };
0474 
0475 /*
0476  * DB_LOCK_ILOCK --
0477  *  Internal DB access method lock.
0478  */
0479 struct __db_ilock { /* SHARED */
0480     db_pgno_t pgno;         /* Page being locked. */
0481     u_int8_t fileid[DB_FILE_ID_LEN];/* File id. */
0482 #define DB_HANDLE_LOCK      1
0483 #define DB_RECORD_LOCK      2
0484 #define DB_PAGE_LOCK        3
0485 #define DB_DATABASE_LOCK    4
0486     u_int32_t type;         /* Type of lock. */
0487 };
0488 
0489 /*
0490  * DB_LOCK --
0491  *  The structure is allocated by the caller and filled in during a
0492  *  lock_get request (or a lock_vec/DB_LOCK_GET).
0493  */
0494 struct __db_lock_u { /* SHARED */
0495     roff_t      off;        /* Offset of the lock in the region */
0496     u_int32_t   ndx;        /* Index of the object referenced by
0497                      * this lock; used for locking. */
0498     u_int32_t   gen;        /* Generation number of this lock. */
0499     db_lockmode_t   mode;       /* mode of this lock. */
0500 };
0501 
0502 /* Lock request structure. */
0503 struct __db_lockreq {
0504     db_lockop_t  op;        /* Operation. */
0505     db_lockmode_t    mode;      /* Requested mode. */
0506     db_timeout_t     timeout;   /* Time to expire lock. */
0507     DBT     *obj;       /* Object being locked. */
0508     DB_LOCK      lock;      /* Lock returned. */
0509 };
0510 
0511 /*******************************************************
0512  * Logging.
0513  *******************************************************/
0514 #define DB_LOGVERSION   23      /* Current log version. */
0515 #define DB_LOGVERSION_LATCHING 15   /* Log version using latching: db-4.8 */
0516 #define DB_LOGCHKSUM    12      /* Check sum headers: db-4.5 */
0517 #define DB_LOGOLDVER    8       /* Oldest version supported: db-4.2 */
0518 #define DB_LOGMAGIC 0x040988
0519 
0520 /*
0521  * A DB_LSN has two parts, a fileid which identifies a specific file, and an
0522  * offset within that file.  The fileid is an unsigned 4-byte quantity that
0523  * uniquely identifies a file within the log directory -- currently a simple
0524  * counter inside the log.  The offset is also an unsigned 4-byte value.  The
0525  * log manager guarantees the offset is never more than 4 bytes by switching
0526  * to a new log file before the maximum length imposed by an unsigned 4-byte
0527  * offset is reached.
0528  */
0529 struct __db_lsn { /* SHARED */
0530     u_int32_t   file;       /* File ID. */
0531     u_int32_t   offset;     /* File offset. */
0532 };
0533 
0534 /*
0535  * Application-specified log record types start at DB_user_BEGIN, and must not
0536  * equal or exceed DB_debug_FLAG.
0537  *
0538  * DB_debug_FLAG is the high-bit of the u_int32_t that specifies a log record
0539  * type.  If the flag is set, it's a log record that was logged for debugging
0540  * purposes only, even if it reflects a database change -- the change was part
0541  * of a non-durable transaction.
0542  */
0543 #define DB_user_BEGIN       10000
0544 #define DB_debug_FLAG       0x80000000
0545 
0546 /*
0547  * DB_LOGC --
0548  *  Log cursor.
0549  */
0550 struct __db_log_cursor {
0551     ENV  *env;          /* Environment */
0552 
0553     DB_FH    *fhp;          /* File handle. */
0554     DB_LSN    lsn;          /* Cursor: LSN */
0555     u_int32_t len;          /* Cursor: record length */
0556     u_int32_t prev;         /* Cursor: previous record's offset */
0557 
0558     DBT   dbt;          /* Return DBT. */
0559     DB_LSN    p_lsn;        /* Persist LSN. */
0560     u_int32_t p_version;        /* Persist version. */
0561 
0562     u_int8_t *bp;           /* Allocated read buffer. */
0563     u_int32_t bp_size;      /* Read buffer length in bytes. */
0564     u_int32_t bp_rlen;      /* Read buffer valid data length. */
0565     DB_LSN    bp_lsn;       /* Read buffer first byte LSN. */
0566 
0567     u_int32_t bp_maxrec;        /* Max record length in the log file. */
0568 
0569     /* DB_LOGC PUBLIC HANDLE LIST BEGIN */
0570     int (*close) __P((DB_LOGC *, u_int32_t));
0571     int (*get) __P((DB_LOGC *, DB_LSN *, DBT *, u_int32_t));
0572     int (*version) __P((DB_LOGC *, u_int32_t *, u_int32_t));
0573     /* DB_LOGC PUBLIC HANDLE LIST END */
0574 
0575 #define DB_LOG_DISK     0x01    /* Log record came from disk. */
0576 #define DB_LOG_LOCKED       0x02    /* Log region already locked */
0577 #define DB_LOG_SILENT_ERR   0x04    /* Turn-off error messages. */
0578     u_int32_t flags;
0579 };
0580 
0581 /* Log statistics structure. */
0582 struct __db_log_stat { /* SHARED */
0583     u_int32_t st_magic;     /* Log file magic number. */
0584     u_int32_t st_version;       /* Log file version number. */
0585     int32_t   st_mode;      /* Log file permissions mode. */
0586     u_int32_t st_lg_bsize;      /* Log buffer size. */
0587     u_int32_t st_lg_size;       /* Log file size. */
0588     u_int32_t st_wc_bytes;      /* Bytes to log since checkpoint. */
0589     u_int32_t st_wc_mbytes;     /* Megabytes to log since checkpoint. */
0590     u_int32_t st_fileid_init;   /* Initial allocation for fileids. */
0591 #ifndef __TEST_DB_NO_STATISTICS
0592     u_int32_t st_nfileid;       /* Current number of fileids. */
0593     u_int32_t st_maxnfileid;    /* Maximum number of fileids used. */
0594     uintmax_t st_record;        /* Records entered into the log. */
0595     u_int32_t st_w_bytes;       /* Bytes to log. */
0596     u_int32_t st_w_mbytes;      /* Megabytes to log. */
0597     uintmax_t st_wcount;        /* Total I/O writes to the log. */
0598     uintmax_t st_wcount_fill;   /* Overflow writes to the log. */
0599     uintmax_t st_rcount;        /* Total I/O reads from the log. */
0600     uintmax_t st_scount;        /* Total syncs to the log. */
0601     uintmax_t st_region_wait;   /* Region lock granted after wait. */
0602     uintmax_t st_region_nowait; /* Region lock granted without wait. */
0603     u_int32_t st_cur_file;      /* Current log file number. */
0604     u_int32_t st_cur_offset;    /* Current log file offset. */
0605     u_int32_t st_disk_file;     /* Known on disk log file number. */
0606     u_int32_t st_disk_offset;   /* Known on disk log file offset. */
0607     u_int32_t st_maxcommitperflush; /* Max number of commits in a flush. */
0608     u_int32_t st_mincommitperflush; /* Min number of commits in a flush. */
0609     roff_t    st_regsize;       /* Region size. */
0610 #endif
0611 };
0612 
0613 /*
0614  * We need to record the first log record of a transaction.  For user
0615  * defined logging this macro returns the place to put that information,
0616  * if it is need in rlsnp, otherwise it leaves it unchanged.  We also
0617  * need to track the last record of the transaction, this returns the
0618  * place to put that info.
0619  */
0620 #define DB_SET_TXN_LSNP(txn, blsnp, llsnp)      \
0621     ((txn)->set_txn_lsnp(txn, blsnp, llsnp))
0622 
0623 /*
0624  * Definition of the structure which specifies marshalling of log records.
0625  */
0626 typedef enum {
0627     LOGREC_Done,
0628     LOGREC_ARG,
0629     LOGREC_HDR,
0630     LOGREC_DATA,
0631     LOGREC_DB,
0632     LOGREC_DBOP,
0633     LOGREC_DBT,
0634     LOGREC_LOCKS,
0635     LOGREC_OP,
0636     LOGREC_PGDBT,
0637     LOGREC_PGDDBT,
0638     LOGREC_PGLIST,
0639     LOGREC_POINTER,
0640     LOGREC_TIME,
0641     LOGREC_LONGARG
0642 } log_rec_type_t;
0643 
0644 typedef const struct __log_rec_spec {
0645     log_rec_type_t  type;
0646     u_int32_t   offset;
0647     const char  *name;
0648     const char  fmt[4];
0649 } DB_LOG_RECSPEC;
0650 
0651 /*
0652  * Size of a DBT in a log record.
0653  */
0654 #define LOG_DBT_SIZE(dbt)                       \
0655     (sizeof(u_int32_t) + ((dbt) == NULL ? 0 : (dbt)->size))
0656 
0657 /*******************************************************
0658  * Shared buffer cache (mpool).
0659  *******************************************************/
0660 /* Priority values for DB_MPOOLFILE->{put,set_priority}. */
0661 typedef enum {
0662     DB_PRIORITY_UNCHANGED=0,
0663     DB_PRIORITY_VERY_LOW=1,
0664     DB_PRIORITY_LOW=2,
0665     DB_PRIORITY_DEFAULT=3,
0666     DB_PRIORITY_HIGH=4,
0667     DB_PRIORITY_VERY_HIGH=5
0668 } DB_CACHE_PRIORITY;
0669 
0670 /* Per-process DB_MPOOLFILE information. */
0671 struct __db_mpoolfile {
0672     DB_FH     *fhp;         /* Underlying file handle. */
0673 
0674     /*
0675      * !!!
0676      * The ref, pinref and q fields are protected by the region lock.
0677      */
0678     u_int32_t  ref;         /* Reference count. */
0679 
0680     u_int32_t pinref;       /* Pinned block reference count. */
0681 
0682     /*
0683      * !!!
0684      * Explicit representations of structures from queue.h.
0685      * TAILQ_ENTRY(__db_mpoolfile) q;
0686      */
0687     struct {
0688         struct __db_mpoolfile *tqe_next;
0689         struct __db_mpoolfile **tqe_prev;
0690     } q;                /* Linked list of DB_MPOOLFILE's. */
0691 
0692     /*
0693      * !!!
0694      * The rest of the fields (with the exception of the MP_FLUSH flag)
0695      * are not thread-protected, even when they may be modified at any
0696      * time by the application.  The reason is the DB_MPOOLFILE handle
0697      * is single-threaded from the viewpoint of the application, and so
0698      * the only fields needing to be thread-protected are those accessed
0699      * by checkpoint or sync threads when using DB_MPOOLFILE structures
0700      * to flush buffers from the cache.
0701      */
0702     ENV        *env;        /* Environment */
0703     MPOOLFILE      *mfp;        /* Underlying MPOOLFILE. */
0704 
0705     u_int32_t   clear_len;  /* Cleared length on created pages. */
0706     u_int8_t            /* Unique file ID. */
0707             fileid[DB_FILE_ID_LEN];
0708     int     ftype;      /* File type. */
0709     int32_t     lsn_offset; /* LSN offset in page. */
0710     u_int32_t   gbytes, bytes;  /* Maximum file size. */
0711     DBT        *pgcookie;   /* Byte-string passed to pgin/pgout. */
0712     int32_t     priority;   /* Cache priority. */
0713 
0714     void           *addr;       /* Address of mmap'd region. */
0715     size_t      len;        /* Length of mmap'd region. */
0716 
0717     u_int32_t   config_flags;   /* Flags to DB_MPOOLFILE->set_flags. */
0718 
0719     /* DB_MPOOLFILE PUBLIC HANDLE LIST BEGIN */
0720     int (*close) __P((DB_MPOOLFILE *, u_int32_t));
0721     int (*get)
0722         __P((DB_MPOOLFILE *, db_pgno_t *, DB_TXN *, u_int32_t, void *));
0723     int (*get_clear_len) __P((DB_MPOOLFILE *, u_int32_t *));
0724     int (*get_fileid) __P((DB_MPOOLFILE *, u_int8_t *));
0725     int (*get_flags) __P((DB_MPOOLFILE *, u_int32_t *));
0726     int (*get_ftype) __P((DB_MPOOLFILE *, int *));
0727     int (*get_last_pgno) __P((DB_MPOOLFILE *, db_pgno_t *));
0728     int (*get_lsn_offset) __P((DB_MPOOLFILE *, int32_t *));
0729     int (*get_maxsize) __P((DB_MPOOLFILE *, u_int32_t *, u_int32_t *));
0730     int (*get_pgcookie) __P((DB_MPOOLFILE *, DBT *));
0731     int (*get_priority) __P((DB_MPOOLFILE *, DB_CACHE_PRIORITY *));
0732     int (*open) __P((DB_MPOOLFILE *, const char *, u_int32_t, int, size_t));
0733     int (*put) __P((DB_MPOOLFILE *, void *, DB_CACHE_PRIORITY, u_int32_t));
0734     int (*set_clear_len) __P((DB_MPOOLFILE *, u_int32_t));
0735     int (*set_fileid) __P((DB_MPOOLFILE *, u_int8_t *));
0736     int (*set_flags) __P((DB_MPOOLFILE *, u_int32_t, int));
0737     int (*set_ftype) __P((DB_MPOOLFILE *, int));
0738     int (*set_lsn_offset) __P((DB_MPOOLFILE *, int32_t));
0739     int (*set_maxsize) __P((DB_MPOOLFILE *, u_int32_t, u_int32_t));
0740     int (*set_pgcookie) __P((DB_MPOOLFILE *, DBT *));
0741     int (*set_priority) __P((DB_MPOOLFILE *, DB_CACHE_PRIORITY));
0742     int (*sync) __P((DB_MPOOLFILE *));
0743     /* DB_MPOOLFILE PUBLIC HANDLE LIST END */
0744 
0745     /*
0746      * MP_FILEID_SET, MP_OPEN_CALLED and MP_READONLY do not need to be
0747      * thread protected because they are initialized before the file is
0748      * linked onto the per-process lists, and never modified.
0749      *
0750      * MP_FLUSH is thread protected because it is potentially read/set by
0751      * multiple threads of control.
0752      */
0753 #define MP_FILEID_SET   0x001       /* Application supplied a file ID. */
0754 #define MP_FLUSH    0x002       /* Was used to flush a buffer. */
0755 #define MP_FOR_FLUSH    0x004       /* Was opened to flush a buffer. */
0756 #define MP_MULTIVERSION 0x008       /* Opened for multiversion access. */
0757 #define MP_OPEN_CALLED  0x010       /* File opened. */
0758 #define MP_READONLY 0x020       /* File is readonly. */
0759 #define MP_DUMMY    0x040       /* File is dummy for __memp_fput. */
0760     u_int32_t  flags;
0761 };
0762 
0763 /* Mpool statistics structure. */
0764 struct __db_mpool_stat { /* SHARED */
0765     u_int32_t st_gbytes;        /* Total cache size: GB. */
0766     u_int32_t st_bytes;     /* Total cache size: B. */
0767     u_int32_t st_ncache;        /* Number of cache regions. */
0768     u_int32_t st_max_ncache;    /* Maximum number of regions. */
0769     db_size_t st_mmapsize;      /* Maximum file size for mmap. */
0770     int32_t st_maxopenfd;       /* Maximum number of open fd's. */
0771     int32_t st_maxwrite;        /* Maximum buffers to write. */
0772     db_timeout_t st_maxwrite_sleep; /* Sleep after writing max buffers. */
0773     u_int32_t st_pages;     /* Total number of pages. */
0774 #ifndef __TEST_DB_NO_STATISTICS
0775     u_int32_t st_map;       /* Pages from mapped files. */
0776     uintmax_t st_cache_hit; /* Pages found in the cache. */
0777     uintmax_t st_cache_miss;    /* Pages not found in the cache. */
0778     uintmax_t st_page_create;   /* Pages created in the cache. */
0779     uintmax_t st_page_in;       /* Pages read in. */
0780     uintmax_t st_page_out;      /* Pages written out. */
0781     uintmax_t st_ro_evict;      /* Clean pages forced from the cache. */
0782     uintmax_t st_rw_evict;      /* Dirty pages forced from the cache. */
0783     uintmax_t st_page_trickle;  /* Pages written by memp_trickle. */
0784     u_int32_t st_page_clean;    /* Clean pages. */
0785     u_int32_t st_page_dirty;    /* Dirty pages. */
0786     u_int32_t st_hash_buckets;  /* Number of hash buckets. */
0787     u_int32_t st_hash_mutexes;  /* Number of hash bucket mutexes. */
0788     u_int32_t st_pagesize;      /* Assumed page size. */
0789     u_int32_t st_hash_searches; /* Total hash chain searches. */
0790     u_int32_t st_hash_longest;  /* Longest hash chain searched. */
0791     uintmax_t st_hash_examined; /* Total hash entries searched. */
0792     uintmax_t st_hash_nowait;   /* Hash lock granted with nowait. */
0793     uintmax_t st_hash_wait;     /* Hash lock granted after wait. */
0794     uintmax_t st_hash_max_nowait;   /* Max hash lock granted with nowait. */
0795     uintmax_t st_hash_max_wait; /* Max hash lock granted after wait. */
0796     uintmax_t st_region_nowait; /* Region lock granted with nowait. */
0797     uintmax_t st_region_wait;   /* Region lock granted after wait. */
0798     uintmax_t st_mvcc_frozen;   /* Buffers frozen. */
0799     uintmax_t st_mvcc_thawed;   /* Buffers thawed. */
0800     uintmax_t st_mvcc_freed;    /* Frozen buffers freed. */
0801     uintmax_t st_mvcc_reused;   /* Outdated invisible buffers reused. */
0802     uintmax_t st_alloc;     /* Number of page allocations. */
0803     uintmax_t st_alloc_buckets; /* Buckets checked during allocation. */
0804     uintmax_t st_alloc_max_buckets;/* Max checked during allocation. */
0805     uintmax_t st_alloc_pages;   /* Pages checked during allocation. */
0806     uintmax_t st_alloc_max_pages;   /* Max checked during allocation. */
0807     uintmax_t st_io_wait;       /* Thread waited on buffer I/O. */
0808     uintmax_t st_sync_interrupted;  /* Number of times sync interrupted. */
0809     u_int32_t st_oddfsize_detect;   /* Odd file size detected. */
0810     u_int32_t st_oddfsize_resolve;  /* Odd file size resolved. */
0811     roff_t    st_regsize;       /* Region size. */
0812     roff_t    st_regmax;        /* Region max. */
0813 #endif
0814 };
0815 
0816 /*
0817  * Mpool file statistics structure.
0818  * The first fields in this structure must mirror the __db_mpool_fstat_int
0819  * structure, since content is mem copied between the two.
0820  */
0821 struct __db_mpool_fstat {
0822     u_int32_t st_pagesize;      /* Page size. */
0823 #ifndef __TEST_DB_NO_STATISTICS
0824     u_int32_t st_map;       /* Pages from mapped files. */
0825     uintmax_t st_cache_hit; /* Pages found in the cache. */
0826     uintmax_t st_cache_miss;    /* Pages not found in the cache. */
0827     uintmax_t st_page_create;   /* Pages created in the cache. */
0828     uintmax_t st_page_in;       /* Pages read in. */
0829     uintmax_t st_page_out;      /* Pages written out. */
0830     uintmax_t st_backup_spins;  /* Number of spins during a copy. */
0831 #endif
0832     char *file_name;    /* File name. */
0833 };
0834 
0835 /*******************************************************
0836  * Transactions and recovery.
0837  *******************************************************/
0838 #define DB_TXNVERSION   1
0839 
0840 typedef enum {
0841     DB_TXN_ABORT=0,         /* Public. */
0842     DB_TXN_APPLY=1,         /* Public. */
0843     DB_TXN_BACKWARD_ROLL=3,     /* Public. */
0844     DB_TXN_FORWARD_ROLL=4,      /* Public. */
0845     DB_TXN_OPENFILES=5,     /* Internal. */
0846     DB_TXN_POPENFILES=6,        /* Internal. */
0847     DB_TXN_PRINT=7,         /* Public. */
0848     DB_TXN_LOG_VERIFY=8     /* Internal. */
0849 } db_recops;
0850 
0851 /*
0852  * BACKWARD_ALLOC is used during the forward pass to pick up any aborted
0853  * allocations for files that were created during the forward pass.
0854  * The main difference between _ALLOC and _ROLL is that the entry for
0855  * the file not exist during the rollforward pass.
0856  */
0857 #define DB_UNDO(op) ((op) == DB_TXN_ABORT || (op) == DB_TXN_BACKWARD_ROLL)
0858 #define DB_REDO(op) ((op) == DB_TXN_FORWARD_ROLL || (op) == DB_TXN_APPLY)
0859 
0860 struct __db_txn {
0861     DB_TXNMGR   *mgrp;      /* Pointer to transaction manager. */
0862     DB_TXN      *parent;    /* Pointer to transaction's parent. */
0863     DB_THREAD_INFO  *thread_info;   /* Pointer to thread information. */
0864 
0865     u_int32_t   cursors;    /* Number of cursors open for txn */
0866 
0867     u_int32_t   txnid;      /* Unique transaction id. */
0868     char        *name;      /* Transaction name. */
0869     DB_LOCKER   *locker;    /* Locker for this txn. */
0870 
0871     void        *td;        /* Detail structure within region. */
0872     db_timeout_t    lock_timeout;   /* Timeout for locks for this txn. */
0873     void        *txn_list;  /* Undo information for parent. */
0874 
0875 
0876     /*
0877      * Txn_slices is __os_calloc'd with one potential entry for each
0878      * slice. DML is allowed to set only one entry. DDL can have one per
0879      * slice, but does not (in V1) guarantee atomicity between those txns.
0880      */
0881     DB_TXN      **txn_slices;   /* Txns for this container's slices. */
0882     DB_TXN      *txn_container; /* Container of this slice. */
0883 
0884     /*
0885      * !!!
0886      * Explicit representations of structures from queue.h.
0887      * TAILQ_ENTRY(__db_txn) links;
0888      */
0889     struct {
0890         struct __db_txn *tqe_next;
0891         struct __db_txn **tqe_prev;
0892     } links;            /* Links transactions off manager. */
0893 
0894     /*
0895      * !!!
0896      * Explicit representations of structures from shqueue.h.
0897      * SH_TAILQ_ENTRY xa_links;
0898      * These links link together transactions that are active in
0899      * the same thread of control.
0900      */
0901     struct {
0902         db_ssize_t stqe_next;
0903         db_ssize_t stqe_prev;
0904     } xa_links;         /* Links XA transactions. */
0905 
0906     /*
0907      * !!!
0908      * Explicit representations of structures from queue.h.
0909      * TAILQ_HEAD(__kids, __db_txn) kids;
0910      */
0911     struct __kids {
0912         struct __db_txn *tqh_first;
0913         struct __db_txn **tqh_last;
0914     } kids;
0915 
0916     /*
0917      * !!!
0918      * Explicit representations of structures from queue.h.
0919      * TAILQ_HEAD(__events, __txn_event) events;
0920      */
0921     struct {
0922         struct __txn_event *tqh_first;
0923         struct __txn_event **tqh_last;
0924     } events;           /* Links deferred events. */
0925 
0926     /*
0927      * !!!
0928      * Explicit representations of structures from queue.h.
0929      * STAILQ_HEAD(__logrec, __txn_logrec) logs;
0930      */
0931     struct {
0932         struct __txn_logrec *stqh_first;
0933         struct __txn_logrec **stqh_last;
0934     } logs;             /* Links in memory log records. */
0935 
0936     /*
0937      * !!!
0938      * Explicit representations of structures from queue.h.
0939      * TAILQ_ENTRY(__db_txn) klinks;
0940      */
0941     struct {
0942         struct __db_txn *tqe_next;
0943         struct __db_txn **tqe_prev;
0944     } klinks;           /* Links of children in parent. */
0945 
0946     /*
0947      * !!!
0948      * Explicit representations of structures from queue.h.
0949      * TAILQ_HEAD(__my_cursors, __dbc) my_cursors;
0950      */
0951     struct __my_cursors {
0952         struct __dbc *tqh_first;
0953         struct __dbc **tqh_last;
0954     } my_cursors;
0955 
0956     /*
0957      * !!!
0958      * Explicit representations of structures from queue.h.
0959      * TAILQ_HEAD(__femfs, MPOOLFILE) femfs;
0960      *
0961      * These are DBs involved in file extension in this transaction.
0962      */
0963     struct __femfs {
0964         DB *tqh_first;
0965         DB **tqh_last;
0966     } femfs;
0967 
0968     DB_TXN_TOKEN    *token_buffer;  /* User's commit token buffer. */
0969     void    *api_internal;      /* C++ API private. */
0970     void    *xml_internal;      /* XML API private. */
0971 
0972     /* DB_TXN PUBLIC HANDLE LIST BEGIN */
0973     int   (*abort) __P((DB_TXN *));
0974     int   (*commit) __P((DB_TXN *, u_int32_t));
0975     int   (*discard) __P((DB_TXN *, u_int32_t));
0976     int   (*get_name) __P((DB_TXN *, const char **));
0977     int   (*get_priority) __P((DB_TXN *, u_int32_t *));
0978     u_int32_t (*id) __P((DB_TXN *));
0979     int   (*prepare) __P((DB_TXN *, u_int8_t *));
0980     int   (*set_commit_token) __P((DB_TXN *, DB_TXN_TOKEN *));
0981     int   (*set_name) __P((DB_TXN *, const char *));
0982     int   (*set_priority) __P((DB_TXN *, u_int32_t));
0983     int   (*set_timeout) __P((DB_TXN *, db_timeout_t, u_int32_t));
0984     /* DB_TXN PUBLIC HANDLE LIST END */
0985 
0986     /* DB_TXN PRIVATE HANDLE LIST BEGIN */
0987     void      (*set_txn_lsnp) __P((DB_TXN *txn, DB_LSN **, DB_LSN **));
0988     /* DB_TXN PRIVATE HANDLE LIST END */
0989 
0990 #define TXN_XA_THREAD_NOTA      0
0991 #define TXN_XA_THREAD_ASSOCIATED    1
0992 #define TXN_XA_THREAD_SUSPENDED     2
0993 #define TXN_XA_THREAD_UNASSOCIATED  3
0994     u_int32_t   xa_thr_status;
0995 
0996 #define TXN_CHILDCOMMIT     0x00001 /* Txn has committed. */
0997 #define TXN_DISPATCH        0x00002 /* Internal; use for __db_dispatch(). */
0998 #define TXN_DEADLOCK        0x00004 /* Txn has deadlocked. */
0999 #define TXN_FAMILY      0x00008 /* Cursors/children are independent. */
1000 #define TXN_IGNORE_LEASE    0x00010 /* Skip lease check at commit time. */
1001 #define TXN_INFAMILY        0x00020 /* Part of a transaction family. */
1002 #define TXN_LOCKTIMEOUT     0x00040 /* Txn has a lock timeout. */
1003 #define TXN_MALLOC      0x00080 /* Structure allocated by TXN system. */
1004 #define TXN_NOSYNC      0x00100 /* Do not sync on prepare and commit. */
1005 #define TXN_NOWAIT      0x00200 /* Do not wait on locks. */
1006 #define TXN_PRIVATE     0x00400 /* Txn owned by cursor. */
1007 #define TXN_READONLY        0x00800 /* CDS group handle. */
1008 #define TXN_READ_COMMITTED  0x01000 /* Txn has degree 2 isolation. */
1009 #define TXN_READ_UNCOMMITTED    0x02000 /* Txn has degree 1 isolation. */
1010 #define TXN_RESTORED        0x04000 /* Txn has been restored. */
1011 #define TXN_SNAPSHOT        0x08000 /* Snapshot Isolation. */
1012 #define TXN_SYNC        0x10000 /* Write and sync on prepare/commit. */
1013 #define TXN_WRITE_NOSYNC    0x20000 /* Write only on prepare/commit. */
1014 #define TXN_BULK        0x40000 /* Enable bulk loading optimization. */
1015     u_int32_t   flags;
1016 
1017     u_int32_t   begin_flags;    /* Saved by txn_begin(), for slices. */
1018 };
1019 
1020 #define TXN_SYNC_FLAGS (TXN_SYNC | TXN_NOSYNC | TXN_WRITE_NOSYNC)
1021 
1022 /*
1023  * Structure used for two phase commit interface.
1024  * We set the size of our global transaction id (gid) to be 128 in order
1025  * to match that defined by the XA X/Open standard.
1026  */
1027 #define DB_GID_SIZE 128
1028 struct __db_preplist {
1029     DB_TXN  *txn;
1030     u_int8_t gid[DB_GID_SIZE];
1031 };
1032 
1033 /*
1034  * Active transaction statistics for slices.
1035  * If a container's transaction touches any slices, its TXN_DETAIL.slice_details
1036  * has a DB_ENV->slice_cnt sized array in shared memory of these. Entries whose
1037  * txnid is not TXN_INVALID are active. The slice number is implied by the
1038  * position in the array.
1039  */
1040 struct __db_txn_active_slice {
1041     u_int32_t txnid;        /* Txnid in that slice  */
1042 };
1043 
1044 /* Active transaction statistics structure. */
1045 struct __db_txn_active {
1046     u_int32_t txnid;        /* Transaction ID */
1047     u_int32_t parentid;     /* Transaction ID of parent */
1048     pid_t     pid;          /* Process owning txn ID */
1049     db_threadid_t tid;      /* Thread owning txn ID */
1050 
1051     DB_LSN    lsn;          /* LSN when transaction began */
1052 
1053     DB_LSN    read_lsn;     /* Read LSN for MVCC */
1054     u_int32_t mvcc_ref;     /* MVCC reference count */
1055 
1056     u_int32_t priority;     /* Deadlock resolution priority */
1057 
1058 #define TXN_ABORTED     1
1059 #define TXN_COMMITTED       2
1060 #define TXN_NEED_ABORT      3
1061 #define TXN_PREPARED        4
1062 #define TXN_RUNNING     5
1063     u_int32_t status;       /* Status of the transaction */
1064 
1065 #define TXN_XA_ACTIVE       1
1066 #define TXN_XA_DEADLOCKED   2
1067 #define TXN_XA_IDLE     3
1068 #define TXN_XA_PREPARED     4
1069 #define TXN_XA_ROLLEDBACK   5
1070     u_int32_t xa_status;        /* XA status */
1071 
1072     u_int8_t  gid[DB_GID_SIZE]; /* Global transaction ID */
1073     char      name[51];     /* 50 bytes of name, nul termination */
1074 
1075     /*
1076      * This array of txnids can either be NULL, or it is a
1077      * DB_ENV->get_slice_count()-sized array. Any slices which have active
1078      * subordinate transactions have non-empty entries.
1079      */
1080     DB_TXN_ACTIVE_SLICE *slice_txns;
1081 };
1082 
1083 struct __db_txn_stat {
1084     u_int32_t st_nrestores;     /* number of restored transactions
1085                        after recovery. */
1086 #ifndef __TEST_DB_NO_STATISTICS
1087     DB_LSN    st_last_ckp;      /* lsn of the last checkpoint */
1088     time_t    st_time_ckp;      /* time of last checkpoint */
1089     u_int32_t st_last_txnid;    /* last transaction id given out */
1090     u_int32_t st_inittxns;      /* inital txns allocated */
1091     u_int32_t st_maxtxns;       /* maximum txns possible */
1092     uintmax_t st_naborts;       /* number of aborted transactions */
1093     uintmax_t st_nbegins;       /* number of begun transactions */
1094     uintmax_t st_ncommits;      /* number of committed transactions */
1095     u_int32_t st_nactive;       /* number of active transactions */
1096     u_int32_t st_nsnapshot;     /* number of snapshot transactions */
1097     u_int32_t st_maxnactive;    /* maximum active transactions */
1098     u_int32_t st_maxnsnapshot;  /* maximum snapshot transactions */
1099     uintmax_t st_region_wait;   /* Region lock granted after wait. */
1100     uintmax_t st_region_nowait; /* Region lock granted without wait. */
1101     roff_t    st_regsize;       /* Region size. */
1102     DB_TXN_ACTIVE *st_txnarray; /* array of active transactions */
1103 #endif
1104 };
1105 
1106 #define DB_TXN_TOKEN_SIZE       20
1107 struct __db_txn_token {
1108     u_int8_t buf[DB_TXN_TOKEN_SIZE];
1109 };
1110 
1111 /*******************************************************
1112  * Replication.
1113  *******************************************************/
1114 /* Special, out-of-band environment IDs. */
1115 #define DB_EID_BROADCAST    -1
1116 #define DB_EID_INVALID      -2
1117 #define DB_EID_MASTER       -3
1118 
1119 #define DB_REP_DEFAULT_PRIORITY     100
1120 
1121 /* Acknowledgement policies; 0 reserved as OOB. */
1122 #define DB_REPMGR_ACKS_ALL      1
1123 #define DB_REPMGR_ACKS_ALL_AVAILABLE    2
1124 #define DB_REPMGR_ACKS_ALL_PEERS    3
1125 #define DB_REPMGR_ACKS_NONE     4
1126 #define DB_REPMGR_ACKS_ONE      5
1127 #define DB_REPMGR_ACKS_ONE_PEER     6
1128 #define DB_REPMGR_ACKS_QUORUM       7
1129 
1130 /* Configuration options for SSL support for Replication Manager */
1131 #define DB_REPMGR_SSL_CA_CERT           1 /* CA Cert Location */
1132 #define DB_REPMGR_SSL_CA_DIR            2 /* CA Cert Directory */
1133 #define DB_REPMGR_SSL_REPNODE_CERT      3 /* RepNode Cert for auth */
1134 #define DB_REPMGR_SSL_REPNODE_PRIVATE_KEY   4 /* Repnode Cert Private key */
1135 #define DB_REPMGR_SSL_REPNODE_KEY_PASSWD    5 /* Password for Private key */
1136 #define DB_REPMGR_SSL_VERIFY_DEPTH      6 /* SSL verification depth */
1137 
1138 /* Replication timeout configuration values. */
1139 #define DB_REP_ACK_TIMEOUT      1   /* RepMgr acknowledgements. */
1140 #define DB_REP_CHECKPOINT_DELAY     2   /* Master checkpoint delay. */
1141 #define DB_REP_CONNECTION_RETRY     3   /* RepMgr connections. */
1142 #define DB_REP_ELECTION_RETRY       4   /* RepMgr elect retries. */
1143 #define DB_REP_ELECTION_TIMEOUT     5   /* Rep normal elections. */
1144 #define DB_REP_FULL_ELECTION_TIMEOUT    6   /* Rep full elections. */
1145 #define DB_REP_HEARTBEAT_MONITOR    7   /* RepMgr client HB monitor. */
1146 #define DB_REP_HEARTBEAT_SEND       8   /* RepMgr master send freq. */
1147 #define DB_REP_LEASE_TIMEOUT        9   /* Master leases. */
1148 #define DB_REP_WRITE_FORWARD_TIMEOUT    10  /* Write forwarding. */
1149 
1150 /*
1151  * Event notification types.  (Tcl testing interface currently assumes there are
1152  * no more than 32 of these.). Comments include any relevant event_info types.
1153  */
1154 #define DB_EVENT_PANIC           0
1155 #define DB_EVENT_REG_ALIVE       1  /* int: pid which was in env */
1156 #define DB_EVENT_REG_PANIC       2  /* int: error causing the panic. */
1157 #define DB_EVENT_REP_AUTOTAKEOVER    3
1158 #define DB_EVENT_REP_AUTOTAKEOVER_FAILED 4
1159 #define DB_EVENT_REP_CLIENT      5
1160 #define DB_EVENT_REP_CONNECT_BROKEN  6  /* DB_REPMGR_CONN_ERR */
1161 #define DB_EVENT_REP_CONNECT_ESTD    7  /* int: EID of remote site */
1162 #define DB_EVENT_REP_CONNECT_TRY_FAILED  8  /* DB_REPMGR_CONN_ERR */
1163 #define DB_EVENT_REP_DUPMASTER       9
1164 #define DB_EVENT_REP_ELECTED        10
1165 #define DB_EVENT_REP_ELECTION_FAILED    11
1166 #define DB_EVENT_REP_INIT_DONE      12
1167 #define DB_EVENT_REP_INQUEUE_FULL   13
1168 #define DB_EVENT_REP_JOIN_FAILURE   14
1169 #define DB_EVENT_REP_LOCAL_SITE_REMOVED 15
1170 #define DB_EVENT_REP_MASTER     16
1171 #define DB_EVENT_REP_MASTER_FAILURE 17
1172 #define DB_EVENT_REP_NEWMASTER      18  /* int: new master's site id */
1173 #define DB_EVENT_REP_PERM_FAILED    19
1174 #define DB_EVENT_REP_SITE_ADDED     20  /* int: eid */
1175 #define DB_EVENT_REP_SITE_REMOVED   21  /* int: eid */
1176 #define DB_EVENT_REP_STARTUPDONE    22
1177 #define DB_EVENT_REP_WOULD_ROLLBACK 23  /* Undocumented; C API only. */
1178 #define DB_EVENT_WRITE_FAILED       24
1179 #define DB_EVENT_MUTEX_DIED     25  /* DB_EVENT_MUTEX_DIED_INFO */
1180 #define DB_EVENT_FAILCHK_PANIC      26  /* DB_EVENT_FAILCHK_INFO */
1181 #define DB_EVENT_NO_SUCH_EVENT       0xffffffff /* OOB sentinel value */
1182 
1183 /* Supported network event polling methods */
1184 typedef enum {
1185     SELECT=1,
1186     POLL=2,
1187     EPOLL=3
1188 } poll_method_t;
1189 
1190 #if defined(HAVE_EPOLL_CREATE) && defined(HAVE_EPOLL_CTL) && defined(HAVE_EPOLL_WAIT)
1191 #define HAVE_EPOLL  1
1192 #endif
1193 
1194 /* Replication Manager site status. */
1195 struct __db_repmgr_site {
1196     int eid;
1197     char *host;
1198     u_int port;
1199     DB_LSN max_ack_lsn;
1200 
1201 #define DB_REPMGR_CONNECTED 1
1202 #define DB_REPMGR_DISCONNECTED  2
1203     u_int32_t status;
1204 
1205 #define DB_REPMGR_ISELECTABLE   0x01
1206 #define DB_REPMGR_ISPEER    0x02
1207 #define DB_REPMGR_ISVIEW    0x04
1208     u_int32_t flags;
1209 };
1210 
1211 /* Replication statistics. */
1212 struct __db_rep_stat { /* SHARED */
1213     /* !!!
1214      * Many replication statistics fields cannot be protected by a mutex
1215      * without an unacceptable performance penalty, since most message
1216      * processing is done without the need to hold a region-wide lock.
1217      * Fields whose comments end with a '+' may be updated without holding
1218      * the replication or log mutexes (as appropriate), and thus may be
1219      * off somewhat (or, on unreasonable architectures under unlucky
1220      * circumstances, garbaged).
1221      */
1222     u_int32_t st_startup_complete;  /* Site completed client sync-up. */
1223     u_int32_t st_view;      /* Site is a view. */
1224 #ifndef __TEST_DB_NO_STATISTICS
1225     uintmax_t st_log_queued;    /* Log records currently queued.+ */
1226     u_int32_t st_status;        /* Current replication status. */
1227     DB_LSN st_next_lsn;     /* Next LSN to use or expect. */
1228     DB_LSN st_waiting_lsn;      /* LSN we're awaiting, if any. */
1229     DB_LSN st_max_perm_lsn;     /* Maximum permanent LSN. */
1230     db_pgno_t st_next_pg;       /* Next pg we expect. */
1231     db_pgno_t st_waiting_pg;    /* pg we're awaiting, if any. */
1232 
1233     u_int32_t st_dupmasters;    /* # of times a duplicate master
1234                        condition was detected.+ */
1235     db_ssize_t st_env_id;       /* Current environment ID. */
1236     u_int32_t st_env_priority;  /* Current environment priority. */
1237     uintmax_t st_ext_duplicated;    /* Dup ext file data messages.+ */
1238     uintmax_t st_ext_records;   /* # of ext file data messages.+ */
1239     uintmax_t st_ext_rereq;     /* Ext file chunk re-requests.+ */
1240     uintmax_t st_ext_update_rereq;  /* Ext file update re-requests. + */
1241     uintmax_t st_bulk_fills;    /* Bulk buffer fills. */
1242     uintmax_t st_bulk_overflows;    /* Bulk buffer overflows. */
1243     uintmax_t st_bulk_records;  /* Bulk records stored. */
1244     uintmax_t st_bulk_transfers;    /* Transfers of bulk buffers. */
1245     uintmax_t st_client_rerequests;/* Number of forced rerequests. */
1246     uintmax_t st_client_svc_req;    /* Number of client service requests
1247                        received by this client. */
1248     uintmax_t st_client_svc_miss;   /* Number of client service requests
1249                        missing on this client. */
1250     u_int32_t st_gen;       /* Current generation number. */
1251     u_int32_t st_egen;      /* Current election gen number. */
1252     uintmax_t st_lease_chk;     /* Lease validity checks. */
1253     uintmax_t st_lease_chk_misses;  /* Lease checks invalid. */
1254     uintmax_t st_lease_chk_refresh; /* Lease refresh attempts. */
1255     uintmax_t st_lease_sends;   /* Lease messages sent live. */
1256 
1257     uintmax_t st_log_duplicated;    /* Log records received multiply.+ */
1258     uintmax_t st_log_queued_max;    /* Max. log records queued at once.+ */
1259     uintmax_t st_log_queued_total;  /* Total # of log recs. ever queued.+ */
1260     uintmax_t st_log_records;   /* Log records received and put.+ */
1261     uintmax_t st_log_requested; /* Log recs. missed and requested.+ */
1262     db_ssize_t st_master;       /* Env. ID of the current master. */
1263     uintmax_t st_master_changes;    /* # of times we've switched masters. */
1264     uintmax_t st_msgs_badgen;   /* Messages with a bad generation #.+ */
1265     uintmax_t st_msgs_processed;    /* Messages received and processed.+ */
1266     uintmax_t st_msgs_recover;  /* Messages ignored because this site
1267                        was a client in recovery.+ */
1268     uintmax_t st_msgs_send_failures;/* # of failed message sends.+ */
1269     uintmax_t st_msgs_sent; /* # of successful message sends.+ */
1270     uintmax_t st_newsites;      /* # of NEWSITE msgs. received.+ */
1271     u_int32_t st_nsites;        /* Current number of sites we will
1272                        assume during elections. */
1273     uintmax_t st_nthrottles;    /* # of times we were throttled. */
1274     uintmax_t st_outdated;      /* # of times we detected and returned
1275                        an OUTDATED condition.+ */
1276     uintmax_t st_pg_duplicated; /* Pages received multiply.+ */
1277     uintmax_t st_pg_records;    /* Pages received and stored.+ */
1278     uintmax_t st_pg_requested;  /* Pages missed and requested.+ */
1279     uintmax_t st_txns_applied;  /* # of transactions applied.+ */
1280     uintmax_t st_startsync_delayed;/* # of STARTSYNC msgs delayed.+ */
1281 
1282     /* Elections generally. */
1283     uintmax_t st_elections; /* # of elections held.+ */
1284     uintmax_t st_elections_won; /* # of elections won by this site.+ */
1285 
1286     /* Statistics about an in-progress election. */
1287     db_ssize_t st_election_cur_winner;  /* Current front-runner. */
1288     u_int32_t st_election_gen;  /* Election generation number. */
1289     u_int32_t st_election_datagen;  /* Election data generation number. */
1290     DB_LSN st_election_lsn;     /* Max. LSN of current winner. */
1291     u_int32_t st_election_nsites;   /* # of "registered voters". */
1292     u_int32_t st_election_nvotes;   /* # of "registered voters" needed. */
1293     u_int32_t st_election_priority; /* Current election priority. */
1294     int32_t   st_election_status;   /* Current election status. */
1295     u_int32_t st_election_tiebreaker;/* Election tiebreaker value. */
1296     u_int32_t st_election_votes;    /* Votes received in this round. */
1297     u_int32_t st_election_sec;  /* Last election time seconds. */
1298     u_int32_t st_election_usec; /* Last election time useconds. */
1299     u_int32_t st_max_lease_sec; /* Maximum lease timestamp seconds. */
1300     u_int32_t st_max_lease_usec;    /* Maximum lease timestamp useconds. */
1301 
1302     /* Undocumented statistics only used by the test system. */
1303 #ifdef  CONFIG_TEST
1304     uintmax_t st_ext_deleted;   /* Ext files deleted during II.+ */
1305     uintmax_t st_ext_truncated; /* Ext files shortened during II.+ */
1306     u_int32_t st_filefail_cleanups; /* # of FILE_FAIL cleanups done. */
1307     uintmax_t st_log_futuredup; /* Future log records that are dups. */
1308 #endif
1309 #endif
1310 };
1311 
1312 /* Replication Manager statistics. */
1313 struct __db_repmgr_stat { /* SHARED */
1314     uintmax_t st_perm_failed;   /* # of insufficiently ack'ed msgs. */
1315     uintmax_t st_msgs_queued;   /* # msgs queued for network delay. */
1316     uintmax_t st_msgs_dropped;  /* # msgs discarded due to excessive
1317                        queue length. */
1318     u_int32_t st_incoming_queue_gbytes; /* Incoming queue size: GB. */
1319     u_int32_t st_incoming_queue_bytes;  /* Incoming queue size: B. */
1320     uintmax_t st_incoming_msgs_dropped; /* # of msgs discarded due to
1321                            incoming queue full. */
1322     uintmax_t st_connection_drop;   /* Existing connections dropped. */
1323     uintmax_t st_connect_fail;  /* Failed new connection attempts. */
1324     u_int32_t st_elect_threads; /* # of active election threads. */
1325     u_int32_t st_group_stable_log_file; /* Earliest log file still
1326                            needed by repgroup. */
1327     u_int32_t st_max_elect_threads; /* Max concurrent e-threads ever. */
1328     u_int32_t st_site_participants; /* # of repgroup participant sites. */
1329     u_int32_t st_site_total;    /* # of repgroup total sites. */
1330     u_int32_t st_site_views;    /* # of repgroup view sites. */
1331     u_int32_t st_polling_method;    /* 1=select, 2=poll, 3=epoll. */
1332     uintmax_t st_takeovers;     /* # of automatic listener takeovers. */
1333     uintmax_t st_write_ops_forwarded;   /* # of writes forwarded by
1334                            this client. */
1335     uintmax_t st_write_ops_received;    /* # of forwarded writes
1336                            received by this master. */
1337 };
1338 
1339 /* Replication Manager connection error. */
1340 struct __db_repmgr_conn_err {
1341     int     eid;        /* Replication Environment ID. */
1342     int     error;      /* System networking error code. */
1343 };
1344 
1345 /* Replication Manager socket. */
1346 typedef int DB_REPMGR_SOCKET;
1347 
1348 /*******************************************************
1349  * Sequences.
1350  *******************************************************/
1351 /*
1352  * The storage record for a sequence.
1353  */
1354 struct __db_seq_record {
1355     u_int32_t   seq_version;    /* Version size/number. */
1356     u_int32_t   flags;      /* DB_SEQ_XXX Flags. */
1357     db_seq_t    seq_value;  /* Current value. */
1358     db_seq_t    seq_max;    /* Max permitted. */
1359     db_seq_t    seq_min;    /* Min permitted. */
1360 };
1361 
1362 /*
1363  * Handle for a sequence object.
1364  */
1365 struct __db_sequence {
1366     DB      *seq_dbp;   /* DB handle for this sequence. */
1367     db_mutex_t  mtx_seq;    /* Mutex if sequence is threaded. */
1368     DB_SEQ_RECORD   *seq_rp;    /* Pointer to current data. */
1369     DB_SEQ_RECORD   seq_record; /* Data from DB_SEQUENCE. */
1370     u_int32_t   seq_cache_size; /* Number of values cached. */
1371     db_seq_t    seq_last_value; /* Last value cached. */
1372     db_seq_t    seq_prev_value; /* Last value returned. */
1373     DBT     seq_key;    /* DBT pointing to sequence key. */
1374     DBT     seq_data;   /* DBT pointing to seq_record. */
1375 
1376     /* API-private structure: used by C++ and Java. */
1377     void        *api_internal;
1378 
1379     /* DB_SEQUENCE PUBLIC HANDLE LIST BEGIN */
1380     int     (*close) __P((DB_SEQUENCE *, u_int32_t));
1381     int     (*get) __P((DB_SEQUENCE *,
1382                   DB_TXN *, u_int32_t, db_seq_t *, u_int32_t));
1383     int     (*get_cachesize) __P((DB_SEQUENCE *, u_int32_t *));
1384     int     (*get_db) __P((DB_SEQUENCE *, DB **));
1385     int     (*get_flags) __P((DB_SEQUENCE *, u_int32_t *));
1386     int     (*get_key) __P((DB_SEQUENCE *, DBT *));
1387     int     (*get_range) __P((DB_SEQUENCE *,
1388                  db_seq_t *, db_seq_t *));
1389     int     (*initial_value) __P((DB_SEQUENCE *, db_seq_t));
1390     int     (*open) __P((DB_SEQUENCE *,
1391                 DB_TXN *, DBT *, u_int32_t));
1392     int     (*remove) __P((DB_SEQUENCE *, DB_TXN *, u_int32_t));
1393     int     (*set_cachesize) __P((DB_SEQUENCE *, u_int32_t));
1394     int     (*set_flags) __P((DB_SEQUENCE *, u_int32_t));
1395     int     (*set_range) __P((DB_SEQUENCE *, db_seq_t, db_seq_t));
1396     int     (*stat) __P((DB_SEQUENCE *,
1397                 DB_SEQUENCE_STAT **, u_int32_t));
1398     int     (*stat_print) __P((DB_SEQUENCE *, u_int32_t));
1399     /* DB_SEQUENCE PUBLIC HANDLE LIST END */
1400 };
1401 
1402 struct __db_seq_stat { /* SHARED */
1403     uintmax_t st_wait;      /* Sequence lock granted w/o wait. */
1404     uintmax_t st_nowait;        /* Sequence lock granted after wait. */
1405     db_seq_t  st_current;       /* Current value in db. */
1406     db_seq_t  st_value;     /* Current cached value. */
1407     db_seq_t  st_last_value;    /* Last cached value. */
1408     db_seq_t  st_min;       /* Minimum value. */
1409     db_seq_t  st_max;       /* Maximum value. */
1410     u_int32_t st_cache_size;    /* Cache size. */
1411     u_int32_t st_flags;     /* Flag value. */
1412 };
1413 
1414 /*******************************************************
1415  * Access methods.
1416  *******************************************************/
1417 /*
1418  * Any new methods need to retain the original numbering.  The type
1419  * is written in a log record so must be maintained.
1420  */
1421 typedef enum {
1422     DB_BTREE=1,
1423     DB_HASH=2,
1424     DB_HEAP=6,
1425     DB_RECNO=3,
1426     DB_QUEUE=4,
1427     DB_UNKNOWN=5            /* Figure it out on open. */
1428 } DBTYPE;
1429 
1430 #define DB_RENAMEMAGIC  0x030800    /* File has been renamed. */
1431 
1432 #define DB_BTREEVERSION 10      /* Current btree version. */
1433 #define DB_BTREEOLDVER  8       /* Oldest btree version supported. */
1434 #define DB_BTREEMAGIC   0x053162
1435 
1436 #define DB_HASHVERSION  10      /* Current hash version. */
1437 #define DB_HASHOLDVER   7       /* Oldest hash version supported. */
1438 #define DB_HASHMAGIC    0x061561
1439 
1440 #define DB_HEAPVERSION  2       /* Current heap version. */
1441 #define DB_HEAPOLDVER   1       /* Oldest heap version supported. */
1442 #define DB_HEAPMAGIC    0x074582
1443 
1444 #define DB_QAMVERSION   4       /* Current queue version. */
1445 #define DB_QAMOLDVER    3       /* Oldest queue version supported. */
1446 #define DB_QAMMAGIC 0x042253
1447 
1448 #define DB_SEQUENCE_VERSION 2       /* Current sequence version. */
1449 #define DB_SEQUENCE_OLDVER  1       /* Oldest sequence version supported. */
1450 
1451 /*
1452  * DB access method and cursor operation values.  Each value is an operation
1453  * code to which additional bit flags are added.
1454  */
1455 #define DB_AFTER         1  /* Dbc.put */
1456 #define DB_APPEND        2  /* Db.put */
1457 #define DB_BEFORE        3  /* Dbc.put */
1458 #define DB_CONSUME       4  /* Db.get */
1459 #define DB_CONSUME_WAIT      5  /* Db.get */
1460 #define DB_CURRENT       6  /* Dbc.get, Dbc.put, DbLogc.get */
1461 #define DB_FIRST         7  /* Dbc.get, DbLogc->get */
1462 #define DB_GET_BOTH      8  /* Db.get, Dbc.get */
1463 #define DB_GET_BOTHC         9  /* Dbc.get (internal) */
1464 #define DB_GET_BOTH_RANGE   10  /* Db.get, Dbc.get */
1465 #define DB_GET_RECNO        11  /* Dbc.get */
1466 #define DB_JOIN_ITEM        12  /* Dbc.get; don't do primary lookup */
1467 #define DB_KEYFIRST     13  /* Dbc.put */
1468 #define DB_KEYLAST      14  /* Dbc.put */
1469 #define DB_LAST         15  /* Dbc.get, DbLogc->get */
1470 #define DB_NEXT         16  /* Dbc.get, DbLogc->get */
1471 #define DB_NEXT_DUP     17  /* Dbc.get */
1472 #define DB_NEXT_NODUP       18  /* Dbc.get */
1473 #define DB_NODUPDATA        19  /* Db.put, Dbc.put */
1474 #define DB_NOOVERWRITE      20  /* Db.put */
1475 #define DB_OVERWRITE_DUP    21  /* Dbc.put, Db.put; no DB_KEYEXIST */
1476 #define DB_POSITION     22  /* Dbc.dup */
1477 #define DB_PREV         23  /* Dbc.get, DbLogc->get */
1478 #define DB_PREV_DUP     24  /* Dbc.get */
1479 #define DB_PREV_NODUP       25  /* Dbc.get */
1480 #define DB_SET          26  /* Dbc.get, DbLogc->get */
1481 #define DB_SET_RANGE        27  /* Dbc.get */
1482 #define DB_SET_RECNO        28  /* Db.get, Dbc.get */
1483 #define DB_UPDATE_SECONDARY 29  /* Dbc.get, Dbc.del (internal) */
1484 #define DB_SET_LTE      30  /* Dbc.get (internal) */
1485 #define DB_GET_BOTH_LTE     31  /* Dbc.get (internal) */
1486 
1487 /* This has to change when the max opcode hits 255. */
1488 #define DB_OPFLAGS_MASK 0x000000ff  /* Mask for operations flags. */
1489 
1490 /*
1491  * DB (user visible) error return codes.
1492  *
1493  * !!!
1494  * We don't want our error returns to conflict with other packages where
1495  * possible, so pick a base error value that's hopefully not common.  We
1496  * document that we own the error name space from -30,800 to -30,999.
1497  */
1498 /* DB (public) error return codes. */
1499 #define DB_BUFFER_SMALL     (-30999)/* User memory too small for return. */
1500 #define DB_DONOTINDEX       (-30998)/* "Null" return from 2ndary callbk. */
1501 #define DB_FOREIGN_CONFLICT (-30997)/* A foreign db constraint triggered. */
1502 #define DB_HEAP_FULL        (-30996)/* No free space in a heap file. */
1503 #define DB_KEYEMPTY     (-30995)/* Key/data deleted or never created. */
1504 #define DB_KEYEXIST     (-30994)/* The key/data pair already exists. */
1505 #define DB_LOCK_DEADLOCK    (-30993)/* Deadlock. */
1506 #define DB_LOCK_NOTGRANTED  (-30992)/* Lock unavailable. */
1507 #define DB_LOG_BUFFER_FULL  (-30991)/* In-memory log buffer full. */
1508 #define DB_LOG_VERIFY_BAD   (-30990)/* Log verification failed. */
1509 #define DB_META_CHKSUM_FAIL (-30989)/* Metadata page checksum failed. */
1510 #define DB_NOSERVER     (-30988)/* Server panic return. */
1511 #define DB_NOTFOUND     (-30987)/* Key/data pair not found (EOF). */
1512 #define DB_OLD_VERSION      (-30986)/* Out-of-date version. */
1513 #define DB_PAGE_NOTFOUND    (-30985)/* Requested page not found. */
1514 #define DB_REP_DUPMASTER    (-30984)/* There are two masters. */
1515 #define DB_REP_HANDLE_DEAD  (-30983)/* Rolled back a commit. */
1516 #define DB_REP_HOLDELECTION (-30982)/* Time to hold an election. */
1517 #define DB_REP_IGNORE       (-30981)/* This msg should be ignored.*/
1518 #define DB_REP_INELECT      (-30980)/* Replication is in an election. */
1519 #define DB_REP_ISPERM       (-30979)/* Cached not written perm written.*/
1520 #define DB_REP_JOIN_FAILURE (-30978)/* Unable to join replication group. */
1521 #define DB_REP_LEASE_EXPIRED    (-30977)/* Master lease has expired. */
1522 #define DB_REP_LOCKOUT      (-30976)/* API/Replication lockout now. */
1523 #define DB_REP_NEWSITE      (-30975)/* New site entered system. */
1524 #define DB_REP_NOTPERM      (-30974)/* Permanent log record not written. */
1525 #define DB_REP_UNAVAIL      (-30973)/* Site cannot currently be reached. */
1526 #define DB_REP_WOULDROLLBACK    (-30972)/* UNDOC: rollback inhibited by app. */
1527 #define DB_RUNRECOVERY      (-30971)/* Panic return. */
1528 #define DB_SECONDARY_BAD    (-30970)/* Secondary index corrupt. */
1529 #define DB_SLICE_CORRUPT    (-30969)/* A part of a sliced env is corrupt. */
1530 #define DB_TIMEOUT      (-30968)/* Timed out on read consistency. */
1531 #define DB_VERIFY_BAD       (-30967)/* Verify failed; bad format. */
1532 #define DB_VERSION_MISMATCH (-30966)/* Environment version mismatch. */
1533 #define DB_SYSTEM_MEM_MISSING   (-30965)/* Attach to shared memory failed. */
1534  
1535 /* DB (private) error return codes. */
1536 #define DB_ALREADY_ABORTED  (-30899)
1537                         /* Spare error number (-30898). */
1538 #define DB_DELETED      (-30897)/* Recovery file marked deleted. */
1539 #define DB_EVENT_NOT_HANDLED    (-30896)/* Forward event to application. */
1540 #define DB_NEEDSPLIT        (-30895)/* Page needs to be split. */
1541 #define DB_NOINTMP      (-30886)/* Sequences not supported in temporary
1542                        or in-memory databases. */
1543 #define DB_REP_BULKOVF      (-30894)/* Rep bulk buffer overflow. */
1544 #define DB_REP_LOGREADY     (-30893)/* Rep log ready for recovery. */
1545 #define DB_REP_NEWMASTER    (-30892)/* We have learned of a new master. */
1546 #define DB_REP_PAGEDONE     (-30891)/* This page was already done. */
1547 #define DB_SURPRISE_KID     (-30890)/* Child commit where parent
1548                        didn't know it was a parent. */
1549 #define DB_SWAPBYTES        (-30889)/* Database needs byte swapping. */
1550 #define DB_TXN_CKP      (-30888)/* Encountered ckp record in log. */
1551 #define DB_VERIFY_FATAL     (-30887)/* DB->verify cannot proceed. */
1552 
1553 /*
1554  * This exit status indicates that a BDB utility failed because it needed a
1555  * resource which had been held by a process which crashed or otherwise did
1556  * not exit cleanly.
1557  */
1558 #define DB_EXIT_FAILCHK     3
1559 
1560 /* Database handle. */
1561 struct __db {
1562     /*******************************************************
1563      * Public: owned by the application.
1564      *******************************************************/
1565     u_int32_t pgsize;       /* Database logical page size. */
1566     DB_CACHE_PRIORITY priority; /* Database priority in cache. */
1567 
1568                     /* Callbacks. */
1569     int (*db_append_recno) __P((DB *, DBT *, db_recno_t));
1570     void (*db_feedback) __P((DB *, int, int));
1571     int (*dup_compare) __P((DB *, const DBT *, const DBT *, size_t *));
1572 
1573     void    *app_private;       /* Application-private handle. */
1574 
1575     /*******************************************************
1576      * Private: owned by DB.
1577      *******************************************************/
1578     DB_ENV  *dbenv;         /* Backing public environment. */
1579     ENV *env;           /* Backing private environment. */
1580 
1581     DB_MPOOLFILE *mpf;      /* Backing buffer pool. */
1582 
1583     DB  **db_slices;        /* A containing db's array of DB handles
1584                       for its slices. */
1585     DB  *db_container;      /* A slice's pointer to its
1586                        containing DB. */
1587     db_slice_t db_slice_index;  /* Position in container's db_slices. */
1588     DBTYPE   type;          /* DB access method type. */
1589 
1590     db_mutex_t mutex;       /* Synchronization for free threading */
1591 
1592     char *fname, *dname;        /* File/database passed to DB->open. */
1593     const char *dirname;        /* Directory of DB file. */
1594     u_int32_t open_flags;       /* Flags passed to DB->open. */
1595 
1596     u_int8_t fileid[DB_FILE_ID_LEN];/* File's unique ID for locking. */
1597 
1598     u_int32_t adj_fileid;       /* File's unique ID for curs. adj. */
1599 
1600     u_int32_t blob_threshold;   /* Ext file threshold record size. */
1601 
1602 #define DB_LOGFILEID_INVALID    -1
1603     FNAME *log_filename;        /* File's naming info for logging. */
1604 
1605     db_pgno_t meta_pgno;        /* Meta page number */
1606     DB_LOCKER *locker;      /* Locker for handle locking. */
1607     DB_LOCKER *cur_locker;      /* Current handle lock holder. */
1608     DB_TXN *cur_txn;        /* Opening transaction. */
1609     DB_LOCKER *associate_locker;    /* Locker for DB->associate call. */
1610     DB_LOCK  handle_lock;       /* Lock held on this handle. */
1611 
1612     time_t   timestamp;     /* Handle timestamp for replication. */
1613     u_int32_t fid_gen;      /* Rep generation number for fids. */
1614 
1615     /*
1616      * Returned data memory for DB->get() and friends.
1617      */
1618     DBT  my_rskey;      /* Secondary key. */
1619     DBT  my_rkey;       /* [Primary] key. */
1620     DBT  my_rdata;      /* Data. */
1621 
1622     /*
1623      * !!!
1624      * Some applications use DB but implement their own locking outside of
1625      * DB.  If they're using fcntl(2) locking on the underlying database
1626      * file, and we open and close a file descriptor for that file, we will
1627      * discard their locks.  The DB_FCNTL_LOCKING flag to DB->open is an
1628      * undocumented interface to support this usage which leaves any file
1629      * descriptors we open until DB->close.  This will only work with the
1630      * DB->open interface and simple caches, e.g., creating a transaction
1631      * thread may open/close file descriptors this flag doesn't protect.
1632      * Locking with fcntl(2) on a file that you don't own is a very, very
1633      * unsafe thing to do.  'Nuff said.
1634      */
1635     DB_FH   *saved_open_fhp;    /* Saved file handle. */
1636 
1637     /*
1638      * Linked list of DBP's, linked from the ENV, used to keep track
1639      * of all open db handles for cursor adjustment.
1640      *
1641      * !!!
1642      * Explicit representations of structures from queue.h.
1643      * TAILQ_ENTRY(__db) dblistlinks;
1644      */
1645     struct {
1646         struct __db *tqe_next;
1647         struct __db **tqe_prev;
1648     } dblistlinks;
1649 
1650     /*
1651      * Cursor queues.
1652      *
1653      * !!!
1654      * Explicit representations of structures from queue.h.
1655      * TAILQ_HEAD(__cq_fq, __dbc) free_queue;
1656      * TAILQ_HEAD(__cq_aq, __dbc) active_queue;
1657      * TAILQ_HEAD(__cq_jq, __dbc) join_queue;
1658      */
1659     struct __cq_fq {
1660         struct __dbc *tqh_first;
1661         struct __dbc **tqh_last;
1662     } free_queue;
1663     struct __cq_aq {
1664         struct __dbc *tqh_first;
1665         struct __dbc **tqh_last;
1666     } active_queue;
1667     struct __cq_jq {
1668         struct __dbc *tqh_first;
1669         struct __dbc **tqh_last;
1670     } join_queue;
1671 
1672     /*
1673      * Secondary index support.
1674      *
1675      * Linked list of secondary indices -- set in the primary.
1676      *
1677      * !!!
1678      * Explicit representations of structures from queue.h.
1679      * LIST_HEAD(s_secondaries, __db);
1680      */
1681     struct {
1682         struct __db *lh_first;
1683     } s_secondaries;
1684 
1685     /*
1686      * List entries for secondaries, and reference count of how many
1687      * threads are updating this secondary (see Dbc.put).
1688      *
1689      * !!!
1690      * Note that these are synchronized by the primary's mutex, but
1691      * filled in in the secondaries.
1692      *
1693      * !!!
1694      * Explicit representations of structures from queue.h.
1695      * LIST_ENTRY(__db) s_links;
1696      */
1697     struct {
1698         struct __db *le_next;
1699         struct __db **le_prev;
1700     } s_links;
1701     u_int32_t s_refcnt;
1702 
1703     /* Secondary callback and free functions -- set in the secondary. */
1704     int (*s_callback) __P((DB *, const DBT *, const DBT *, DBT *));
1705 
1706     /* Reference to primary -- set in the secondary. */
1707     DB  *s_primary;
1708 
1709 #define DB_ASSOC_IMMUTABLE_KEY    0x00000001 /* Secondary key is immutable. */
1710 #define DB_ASSOC_CREATE    0x00000002 /* Secondary db populated on open. */
1711 
1712     /* Flags passed to associate -- set in the secondary. */
1713     u_int32_t s_assoc_flags;
1714 
1715     /*
1716      * Foreign key support.
1717      *
1718      * Linked list of primary dbs -- set in the foreign db
1719      *
1720      * !!!
1721      * Explicit representations of structures from queue.h.
1722      * LIST_HEAD(f_primaries, __db);
1723      */
1724     struct {
1725         struct __db_foreign_info *lh_first;
1726     } f_primaries;
1727 
1728     /*
1729      * !!!
1730      * Explicit representations of structures from queue.h.
1731      * TAILQ_ENTRY(__db) felink;
1732      *
1733      * Links in a list of DBs involved in file extension
1734      * during a transaction.  These are to be used only while the
1735      * metadata is locked.
1736      */
1737     struct {
1738         struct __db *tqe_next;
1739         struct __db **tqe_prev;
1740     } felink;
1741 
1742     /* Reference to foreign -- set in the secondary. */
1743     DB      *s_foreign;
1744 
1745     DB      *blob_meta_db;  /* DBs holding ext file metadata. */
1746     DB_SEQUENCE *blob_seq;  /* Sequence of ext file ids. */
1747     char        *blob_sub_dir;  /* Subdirectory for ext files */
1748     db_seq_t    blob_file_id;   /* Id of the file ext file directory. */
1749     db_seq_t    blob_sdb_id;    /* Id of subdb ext file directory. */
1750 
1751     /* API-private structure: used by DB 1.85, C++, Java, Perl and Tcl */
1752     void    *api_internal;
1753 
1754     /* Subsystem-private structure. */
1755     void    *bt_internal;       /* Btree/Recno access method. */
1756     void    *h_internal;        /* Hash access method. */
1757     void    *heap_internal;     /* Heap access method. */
1758     void    *p_internal;        /* Partition informaiton. */
1759     void    *q_internal;        /* Queue access method. */
1760 
1761     /* DB PUBLIC HANDLE LIST BEGIN */
1762     int  (*associate) __P((DB *, DB_TXN *, DB *,
1763         int (*)(DB *, const DBT *, const DBT *, DBT *), u_int32_t));
1764     int  (*associate_foreign) __P((DB *, DB *,
1765         int (*)(DB *, const DBT *, DBT *, const DBT *, int *),
1766         u_int32_t));
1767     int  (*close) __P((DB *, u_int32_t));
1768     int  (*compact) __P((DB *,
1769         DB_TXN *, DBT *, DBT *, DB_COMPACT *, u_int32_t, DBT *));
1770     int  (*convert) __P((DB *, const char *, u_int32_t));
1771     int  (*cursor) __P((DB *, DB_TXN *, DBC **, u_int32_t));
1772     int  (*del) __P((DB *, DB_TXN *, DBT *, u_int32_t));
1773     void (*err) __P((DB *, int, const char *, ...));
1774     void (*errx) __P((DB *, const char *, ...));
1775     int  (*exists) __P((DB *, DB_TXN *, DBT *, u_int32_t));
1776     int  (*fd) __P((DB *, int *));
1777     int  (*get) __P((DB *, DB_TXN *, DBT *, DBT *, u_int32_t));
1778     int  (*get_alloc) __P((DB *, void *(**)(size_t),
1779         void *(**)(void *, size_t), void (**)(void *)));
1780     int  (*get_append_recno) __P((DB *, int (**)(DB *, DBT *, db_recno_t)));
1781     int  (*get_assoc_flags) __P((DB *, u_int32_t *));
1782     int  (*get_blob_dir) __P((DB *, const char **));
1783     int  (*get_blob_sub_dir) __P((DB *, const char **));
1784     int  (*get_blob_threshold) __P((DB *, u_int32_t *));
1785     int  (*get_bt_compare)
1786         __P((DB *, int (**)(DB *, const DBT *, const DBT *, size_t *)));
1787     int  (*get_bt_compress) __P((DB *,
1788         int (**)(DB *,
1789         const DBT *, const DBT *, const DBT *, const DBT *, DBT *),
1790         int (**)(DB *, const DBT *, const DBT *, DBT *, DBT *, DBT *)));
1791     int  (*get_bt_minkey) __P((DB *, u_int32_t *));
1792     int  (*get_bt_prefix)
1793         __P((DB *, size_t (**)(DB *, const DBT *, const DBT *)));
1794     int  (*get_byteswapped) __P((DB *, int *));
1795     int  (*get_cachesize) __P((DB *, u_int32_t *, u_int32_t *, int *));
1796     int  (*get_create_dir) __P((DB *, const char **));
1797     int  (*get_dbname) __P((DB *, const char **, const char **));
1798     int  (*get_dup_compare)
1799         __P((DB *, int (**)(DB *, const DBT *, const DBT *, size_t *)));
1800     int  (*get_encrypt_flags) __P((DB *, u_int32_t *));
1801     DB_ENV *(*get_env) __P((DB *));
1802     void (*get_errcall) __P((DB *,
1803         void (**)(const DB_ENV *, const char *, const char *)));
1804     void (*get_errfile) __P((DB *, FILE **));
1805     void (*get_errpfx) __P((DB *, const char **));
1806     int  (*get_ext_file_dir) __P((DB *, const char **));
1807     int  (*get_ext_file_threshold) __P((DB *, u_int32_t *));
1808     int  (*get_feedback) __P((DB *, void (**)(DB *, int, int)));
1809     int  (*get_flags) __P((DB *, u_int32_t *));
1810     int  (*get_h_compare)
1811         __P((DB *, int (**)(DB *, const DBT *, const DBT *, size_t *)));
1812     int  (*get_h_ffactor) __P((DB *, u_int32_t *));
1813     int  (*get_h_hash)
1814         __P((DB *, u_int32_t (**)(DB *, const void *, u_int32_t)));
1815     int  (*get_h_nelem) __P((DB *, u_int32_t *));
1816     int  (*get_heapsize) __P((DB *, u_int32_t *, u_int32_t *));
1817     int  (*get_heap_regionsize) __P((DB *, u_int32_t *));
1818     int  (*get_lk_exclusive) __P((DB *, int *, int *));
1819     int  (*get_lorder) __P((DB *, int *));
1820     DB_MPOOLFILE *(*get_mpf) __P((DB *));
1821     void (*get_msgcall) __P((DB *,
1822         void (**)(const DB_ENV *, const char *, const char *)));
1823     void (*get_msgfile) __P((DB *, FILE **));
1824     void (*get_msgpfx) __P((DB *, const char **));
1825     int  (*get_multiple) __P((DB *));
1826     int  (*get_open_flags) __P((DB *, u_int32_t *));
1827     int  (*get_pagesize) __P((DB *, u_int32_t *));
1828     int  (*get_partition_callback) __P((DB *,
1829         u_int32_t *, u_int32_t (**)(DB *, DBT *key)));
1830     int  (*get_partition_dirs) __P((DB *, const char ***));
1831     int  (*get_partition_keys) __P((DB *, u_int32_t *, DBT **));
1832     int  (*get_priority) __P((DB *, DB_CACHE_PRIORITY *));
1833     int  (*get_q_extentsize) __P((DB *, u_int32_t *));
1834     int  (*get_re_delim) __P((DB *, int *));
1835     int  (*get_re_len) __P((DB *, u_int32_t *));
1836     int  (*get_re_pad) __P((DB *, int *));
1837     int  (*get_re_source) __P((DB *, const char **));
1838     int  (*get_slices) __P((DB *, DB ***));
1839     int  (*get_transactional) __P((DB *));
1840     int  (*get_type) __P((DB *, DBTYPE *));
1841     int  (*join) __P((DB *, DBC **, DBC **, u_int32_t));
1842     int  (*key_range)
1843         __P((DB *, DB_TXN *, DBT *, DB_KEY_RANGE *, u_int32_t));
1844     void (*msg) __P((DB *, const char *, ...));
1845     int  (*open) __P((DB *,
1846         DB_TXN *, const char *, const char *, DBTYPE, u_int32_t, int));
1847     int  (*pget) __P((DB *, DB_TXN *, DBT *, DBT *, DBT *, u_int32_t));
1848     int  (*put) __P((DB *, DB_TXN *, DBT *, DBT *, u_int32_t));
1849     int  (*remove) __P((DB *, const char *, const char *, u_int32_t));
1850     int  (*rename) __P((DB *,
1851         const char *, const char *, const char *, u_int32_t));
1852     int  (*set_alloc) __P((DB *, void *(*)(size_t),
1853         void *(*)(void *, size_t), void (*)(void *)));
1854     int  (*set_append_recno) __P((DB *, int (*)(DB *, DBT *, db_recno_t)));
1855     int  (*set_blob_dir) __P((DB *, const char *));
1856     int  (*set_blob_threshold) __P((DB *, u_int32_t, u_int32_t));
1857     int  (*set_bt_compare)
1858         __P((DB *, int (*)(DB *, const DBT *, const DBT *, size_t *)));
1859     int  (*set_bt_compress) __P((DB *,
1860         int (*)(DB *, const DBT *, const DBT *, const DBT *, const DBT *, DBT *),
1861         int (*)(DB *, const DBT *, const DBT *, DBT *, DBT *, DBT *)));
1862     int  (*set_bt_minkey) __P((DB *, u_int32_t));
1863     int  (*set_bt_prefix)
1864         __P((DB *, size_t (*)(DB *, const DBT *, const DBT *)));
1865     int  (*set_cachesize) __P((DB *, u_int32_t, u_int32_t, int));
1866     int  (*set_create_dir) __P((DB *, const char *));
1867     int  (*set_dup_compare)
1868         __P((DB *, int (*)(DB *, const DBT *, const DBT *, size_t *)));
1869     int  (*set_encrypt) __P((DB *, const char *, u_int32_t));
1870     void (*set_errcall) __P((DB *,
1871         void (*)(const DB_ENV *, const char *, const char *)));
1872     void (*set_errfile) __P((DB *, FILE *));
1873     void (*set_errpfx) __P((DB *, const char *));
1874     int  (*set_ext_file_dir) __P((DB *, const char *));
1875     int  (*set_ext_file_threshold) __P((DB *, u_int32_t, u_int32_t));
1876     int  (*set_feedback) __P((DB *, void (*)(DB *, int, int)));
1877     int  (*set_flags) __P((DB *, u_int32_t));
1878     int  (*set_h_compare)
1879         __P((DB *, int (*)(DB *, const DBT *, const DBT *, size_t *)));
1880     int  (*set_h_ffactor) __P((DB *, u_int32_t));
1881     int  (*set_h_hash)
1882         __P((DB *, u_int32_t (*)(DB *, const void *, u_int32_t)));
1883     int  (*set_h_nelem) __P((DB *, u_int32_t));
1884     int  (*set_heapsize) __P((DB *, u_int32_t, u_int32_t, u_int32_t));
1885     int  (*set_heap_regionsize) __P((DB *, u_int32_t));
1886     int  (*set_lk_exclusive) __P((DB *, int));
1887     int  (*set_lorder) __P((DB *, int));
1888     int  (*set_slice_callback)
1889         __P((DB *, int (*)(const DB *, const DBT *, DBT *)));
1890     void (*set_msgcall) __P((DB *,
1891         void (*)(const DB_ENV *, const char *, const char *)));
1892     void (*set_msgfile) __P((DB *, FILE *));
1893     void (*set_msgpfx) __P((DB *, const char *));
1894     int  (*set_pagesize) __P((DB *, u_int32_t));
1895     int  (*set_paniccall) __P((DB *, void (*)(DB_ENV *, int)));
1896     int  (*set_partition) __P((DB *,
1897         u_int32_t, DBT *, u_int32_t (*)(DB *, DBT *key)));
1898     int  (*set_partition_dirs) __P((DB *, const char **));
1899     int  (*set_priority) __P((DB *, DB_CACHE_PRIORITY));
1900     int  (*set_q_extentsize) __P((DB *, u_int32_t));
1901     int  (*set_re_delim) __P((DB *, int));
1902     int  (*set_re_len) __P((DB *, u_int32_t));
1903     int  (*set_re_pad) __P((DB *, int));
1904     int  (*set_re_source) __P((DB *, const char *));
1905     int  (*slice_lookup) __P((DB *, const DBT *, DB **, u_int32_t));
1906     int  (*sort_multiple) __P((DB *, DBT *, DBT *, u_int32_t));
1907     int  (*stat) __P((DB *, DB_TXN *, void *, u_int32_t));
1908     int  (*stat_print) __P((DB *, u_int32_t));
1909     int  (*sync) __P((DB *, u_int32_t));
1910     int  (*truncate) __P((DB *, DB_TXN *, u_int32_t *, u_int32_t));
1911     int  (*upgrade) __P((DB *, const char *, u_int32_t));
1912     int  (*verify)
1913         __P((DB *, const char *, const char *, FILE *, u_int32_t));
1914     /* DB PUBLIC HANDLE LIST END */
1915 
1916     /* DB PRIVATE HANDLE LIST BEGIN */
1917     int (*slice_callback)(const DB *db, const DBT *key, DBT *slice);
1918     int  (*dump) __P((DB *, const char *,
1919         int (*)(void *, const void *), void *, int, int));
1920     int  (*db_am_remove) __P((DB *, DB_THREAD_INFO *,
1921         DB_TXN *, const char *, const char *, u_int32_t));
1922     int  (*db_am_rename) __P((DB *, DB_THREAD_INFO *,
1923         DB_TXN *, const char *, const char *, const char *));
1924     /* DB PRIVATE HANDLE LIST END */
1925 
1926     /*
1927      * Never called; these are a place to save function pointers
1928      * so that we can undo an associate.
1929      */
1930     int  (*stored_get) __P((DB *, DB_TXN *, DBT *, DBT *, u_int32_t));
1931     int  (*stored_close) __P((DB *, u_int32_t));
1932 
1933     /* Alternative handle close function, used by C++ API. */
1934     int  (*alt_close) __P((DB *, u_int32_t));
1935 
1936 #define DB_OK_BTREE 0x01
1937 #define DB_OK_HASH  0x02
1938 #define DB_OK_HEAP  0x04
1939 #define DB_OK_QUEUE 0x08
1940 #define DB_OK_RECNO 0x10
1941     u_int32_t   am_ok;      /* Legal AM choices. */
1942 
1943     /*
1944      * This field really ought to be an AM_FLAG, but we have
1945      * have run out of bits.  If/when we decide to split up
1946      * the flags, we can incorporate it.
1947      */
1948     int  preserve_fid;      /* Do not free fileid on close. */
1949 
1950     /*
1951      * This saves the DB_ flags from open, for refresh; they are not the
1952      * DB_AM_... or DB2_AM_... translations.
1953      */
1954     u_int32_t orig_flags;
1955 
1956 #define DB_AM_CHKSUM        0x00000001 /* Checksumming */
1957 #define DB_AM_COMPENSATE    0x00000002 /* Created by compensating txn */
1958 #define DB_AM_COMPRESS      0x00000004 /* Compressed BTree */
1959 #define DB_AM_CREATED       0x00000008 /* Database was created upon open */
1960 #define DB_AM_CREATED_MSTR  0x00000010 /* Encompassing file was created */
1961 #define DB_AM_DBM_ERROR     0x00000020 /* Error in DBM/NDBM database */
1962 #define DB_AM_DELIMITER     0x00000040 /* Variable length delimiter set */
1963 #define DB_AM_DISCARD       0x00000080 /* Discard any cached pages */
1964 #define DB_AM_DUP       0x00000100 /* DB_DUP */
1965 #define DB_AM_DUPSORT       0x00000200 /* DB_DUPSORT */
1966 #define DB_AM_ENCRYPT       0x00000400 /* Encryption */
1967 #define DB_AM_FIXEDLEN      0x00000800 /* Fixed-length records */
1968 #define DB_AM_INMEM     0x00001000 /* In-memory; no sync on close */
1969 #define DB_AM_INORDER       0x00002000 /* DB_INORDER */
1970 #define DB_AM_IN_RENAME     0x00004000 /* File is being renamed */
1971 #define DB_AM_NOT_DURABLE   0x00008000 /* Do not log changes */
1972 #define DB_AM_OPEN_CALLED   0x00010000 /* DB->open called */
1973 #define DB_AM_PAD       0x00020000 /* Fixed-length record pad */
1974 #define DB_AM_PARTDB        0x00040000 /* Handle for a database partition */
1975 #define DB_AM_PGDEF     0x00080000 /* Page size was defaulted */
1976 #define DB_AM_RDONLY        0x00100000 /* Database is readonly */
1977 #define DB_AM_READ_UNCOMMITTED  0x00200000 /* Support degree 1 isolation */
1978 #define DB_AM_RECNUM        0x00400000 /* DB_RECNUM */
1979 #define DB_AM_RECOVER       0x00800000 /* DB opened by recovery routine */
1980 #define DB_AM_RENUMBER      0x01000000 /* DB_RENUMBER */
1981 #define DB_AM_REVSPLITOFF   0x02000000 /* DB_REVSPLITOFF */
1982 #define DB_AM_SECONDARY     0x04000000 /* Database is a secondary index */
1983 #define DB_AM_SNAPSHOT      0x08000000 /* DB_SNAPSHOT */
1984 #define DB_AM_SUBDB     0x10000000 /* Subdatabases supported */
1985 #define DB_AM_SWAP      0x20000000 /* Pages need to be byte-swapped */
1986 #define DB_AM_TXN       0x40000000 /* Opened in a transaction */
1987 #define DB_AM_VERIFYING     0x80000000 /* DB handle is in the verifier */
1988     u_int32_t flags;
1989 
1990 #define DB2_AM_EXCL     0x00000001 /* Exclusively lock the handle */ 
1991 #define DB2_AM_INTEXCL      0x00000002 /* Internal exclusive lock. */
1992 #define DB2_AM_MPOOL_OPENED 0x00000004 /* Memory pool setup completed */
1993 #define DB2_AM_NOWAIT       0x00000008 /* Do not wait for handle lock */
1994     u_int32_t flags2;          /* Second flags word */
1995 };
1996 
1997 /* 
1998  * Stream interface for external files.
1999  */
2000 struct __db_stream {
2001     DBC     *dbc;   /* Cursor pointing to the db ext file record. */
2002     DB_FH       *fhp;
2003 
2004     /* DB_STREAM PUBLIC HANDLE LIST BEGIN */
2005     int  (*close) __P((DB_STREAM *, u_int32_t));
2006     int  (*read) __P((DB_STREAM *, DBT *, db_off_t, u_int32_t, u_int32_t));
2007     int  (*size) __P((DB_STREAM *, db_off_t *, u_int32_t));
2008     int  (*write) __P((DB_STREAM *, DBT *, db_off_t, u_int32_t));
2009     /* DB_STREAM PUBLIC HANDLE LIST END */
2010 
2011     u_int32_t   flags;
2012 #define DB_STREAM_READ      0x00000001 /* Stream is read only. */
2013 #define DB_STREAM_WRITE     0x00000002 /* Stream is writeable. */
2014 #define DB_STREAM_SYNC_WRITE    0x00000004 /* Sync file on each write. */
2015     db_seq_t    blob_id;
2016     db_off_t    file_size;
2017 };
2018 
2019 /*
2020  * Macros for bulk operations.  These are only intended for the C API.
2021  * For C++, use DbMultiple*Iterator or DbMultiple*Builder.
2022  *
2023  * Bulk operations store multiple entries into a single DBT structure. The
2024  * following macros assist with creating and reading these Multiple DBTs.
2025  *
2026  * The basic layout for single data items is:
2027  *
2028  * -------------------------------------------------------------------------
2029  * | data1 | ... | dataN | ..... |-1 | dNLen | dNOff | ... | d1Len | d1Off |
2030  * -------------------------------------------------------------------------
2031  *
2032  * For the DB_MULTIPLE_KEY* macros, the items are in key/data pairs, so data1
2033  * would be a key, and data2 its corresponding value (N is always even).
2034  *
2035  * For the DB_MULTIPLE_RECNO* macros, the record number is stored along with
2036  * the len/off pair in the "header" section, and the list is zero terminated
2037  * (since -1 is a valid record number):
2038  *
2039  * --------------------------------------------------------------------------
2040  * | d1 |..| dN |..| 0 | dNLen | dNOff | recnoN |..| d1Len | d1Off | recno1 |
2041  * --------------------------------------------------------------------------
2042  */
2043 #define DB_MULTIPLE_INIT(pointer, dbt)                  \
2044     (pointer = (u_int8_t *)(dbt)->data +                \
2045         (dbt)->ulen - sizeof(u_int32_t))
2046 
2047 #define DB_MULTIPLE_NEXT(pointer, dbt, retdata, retdlen)        \
2048     do {                                \
2049         u_int32_t *__p = (u_int32_t *)(pointer);        \
2050         if (*__p == (u_int32_t)-1) {                \
2051             retdata = NULL;                 \
2052             pointer = NULL;                 \
2053             break;                      \
2054         }                           \
2055         retdata = (u_int8_t *)(dbt)->data + *__p--;     \
2056         retdlen = *__p--;                   \
2057         pointer = __p;                      \
2058         if (retdlen == 0 && retdata == (u_int8_t *)(dbt)->data) \
2059             retdata = NULL;                 \
2060     } while (0)
2061 
2062 #define DB_MULTIPLE_KEY_NEXT(pointer, dbt, retkey, retklen, retdata, retdlen) \
2063     do {                                \
2064         u_int32_t *__p = (u_int32_t *)(pointer);        \
2065         if (*__p == (u_int32_t)-1) {                \
2066             retdata = NULL;                 \
2067             retkey = NULL;                  \
2068             pointer = NULL;                 \
2069             break;                      \
2070         }                           \
2071         retkey = (u_int8_t *)(dbt)->data + *__p--;      \
2072         retklen = *__p--;                   \
2073         retdata = (u_int8_t *)(dbt)->data + *__p--;     \
2074         retdlen = *__p--;                   \
2075         pointer = __p;                      \
2076     } while (0)
2077 
2078 #define DB_MULTIPLE_RECNO_NEXT(pointer, dbt, recno, retdata, retdlen)   \
2079     do {                                \
2080         u_int32_t *__p = (u_int32_t *)(pointer);        \
2081         if (*__p == (u_int32_t)0) {             \
2082             recno = 0;                  \
2083             retdata = NULL;                 \
2084             pointer = NULL;                 \
2085             break;                      \
2086         }                           \
2087         recno = *__p--;                     \
2088         retdata = (u_int8_t *)(dbt)->data + *__p--;     \
2089         retdlen = *__p--;                   \
2090         pointer = __p;                      \
2091     } while (0)
2092 
2093 #define DB_MULTIPLE_WRITE_INIT(pointer, dbt)                \
2094     do {                                \
2095         (dbt)->flags |= DB_DBT_BULK;                \
2096         pointer = (u_int8_t *)(dbt)->data +         \
2097             (dbt)->ulen - sizeof(u_int32_t);            \
2098         *(u_int32_t *)(pointer) = (u_int32_t)-1;        \
2099     } while (0)
2100 
2101 #define DB_MULTIPLE_RESERVE_NEXT(pointer, dbt, writedata, writedlen)    \
2102     do {                                \
2103         u_int32_t *__p = (u_int32_t *)(pointer);        \
2104         u_int32_t __off = ((pointer) == (u_int8_t *)(dbt)->data +\
2105             (dbt)->ulen - sizeof(u_int32_t)) ?  0 : __p[1] + __p[2];\
2106         if ((u_int8_t *)(dbt)->data + __off + (writedlen) > \
2107             (u_int8_t *)(__p - 2))              \
2108             writedata = NULL;               \
2109         else {                          \
2110             writedata = (u_int8_t *)(dbt)->data + __off;    \
2111             __p[0] = __off;                 \
2112             __p[-1] = (u_int32_t)(writedlen);       \
2113             __p[-2] = (u_int32_t)-1;            \
2114             pointer = __p - 2;              \
2115         }                           \
2116     } while (0)
2117 
2118 #define DB_MULTIPLE_WRITE_NEXT(pointer, dbt, writedata, writedlen)  \
2119     do {                                \
2120         void *__destd;                      \
2121         DB_MULTIPLE_RESERVE_NEXT((pointer), (dbt),      \
2122             __destd, (writedlen));              \
2123         if (__destd == NULL)                    \
2124             pointer = NULL;                 \
2125         else                            \
2126             memcpy(__destd, (writedata), (writedlen));  \
2127     } while (0)
2128 
2129 #define DB_MULTIPLE_KEY_RESERVE_NEXT(pointer, dbt, writekey, writeklen, writedata, writedlen) \
2130     do {                                \
2131         u_int32_t *__p = (u_int32_t *)(pointer);        \
2132         u_int32_t __off = ((pointer) == (u_int8_t *)(dbt)->data +\
2133             (dbt)->ulen - sizeof(u_int32_t)) ?  0 : __p[1] + __p[2];\
2134         if ((u_int8_t *)(dbt)->data + __off + (writeklen) + \
2135             (writedlen) > (u_int8_t *)(__p - 4)) {      \
2136             writekey = NULL;                \
2137             writedata = NULL;               \
2138         } else {                        \
2139             writekey = (u_int8_t *)(dbt)->data + __off; \
2140             __p[0] = __off;                 \
2141             __p[-1] = (u_int32_t)(writeklen);       \
2142             __p -= 2;                   \
2143             __off += (u_int32_t)(writeklen);        \
2144             writedata = (u_int8_t *)(dbt)->data + __off;    \
2145             __p[0] = __off;                 \
2146             __p[-1] = (u_int32_t)(writedlen);       \
2147             __p[-2] = (u_int32_t)-1;            \
2148             pointer = __p - 2;              \
2149         }                           \
2150     } while (0)
2151 
2152 #define DB_MULTIPLE_KEY_WRITE_NEXT(pointer, dbt, writekey, writeklen, writedata, writedlen) \
2153     do {                                \
2154         void *__destk, *__destd;                \
2155         DB_MULTIPLE_KEY_RESERVE_NEXT((pointer), (dbt),      \
2156             __destk, (writeklen), __destd, (writedlen));    \
2157         if (__destk == NULL)                    \
2158             pointer = NULL;                 \
2159         else {                          \
2160             memcpy(__destk, (writekey), (writeklen));   \
2161             if (__destd != NULL)                \
2162                 memcpy(__destd, (writedata), (writedlen));\
2163         }                           \
2164     } while (0)
2165 
2166 #define DB_MULTIPLE_RECNO_WRITE_INIT(pointer, dbt)          \
2167     do {                                \
2168         (dbt)->flags |= DB_DBT_BULK;                \
2169         pointer = (u_int8_t *)(dbt)->data +         \
2170             (dbt)->ulen - sizeof(u_int32_t);            \
2171         *(u_int32_t *)(pointer) = 0;                \
2172     } while (0)
2173 
2174 #define DB_MULTIPLE_RECNO_RESERVE_NEXT(pointer, dbt, recno, writedata, writedlen) \
2175     do {                                \
2176         u_int32_t *__p = (u_int32_t *)(pointer);        \
2177         u_int32_t __off = ((pointer) == (u_int8_t *)(dbt)->data +\
2178             (dbt)->ulen - sizeof(u_int32_t)) ? 0 : __p[1] + __p[2]; \
2179         if (((u_int8_t *)(dbt)->data + __off) + (writedlen) >   \
2180             (u_int8_t *)(__p - 3))              \
2181             writedata = NULL;               \
2182         else {                          \
2183             writedata = (u_int8_t *)(dbt)->data + __off;    \
2184             __p[0] = (u_int32_t)(recno);            \
2185             __p[-1] = __off;                \
2186             __p[-2] = (u_int32_t)(writedlen);       \
2187             __p[-3] = 0;                    \
2188             pointer = __p - 3;              \
2189         }                           \
2190     } while (0)
2191 
2192 #define DB_MULTIPLE_RECNO_WRITE_NEXT(pointer, dbt, recno, writedata, writedlen)\
2193     do {                                \
2194         void *__destd;                      \
2195         DB_MULTIPLE_RECNO_RESERVE_NEXT((pointer), (dbt),    \
2196             (recno), __destd, (writedlen));         \
2197         if (__destd == NULL)                    \
2198             pointer = NULL;                 \
2199         else if ((writedlen) != 0)              \
2200             memcpy(__destd, (writedata), (writedlen));  \
2201     } while (0)
2202 
2203 struct __db_heap_rid {
2204     db_pgno_t pgno;         /* Page number. */
2205     db_indx_t indx;         /* Index in the offset table. */
2206 };
2207 #define DB_HEAP_RID_SZ  (sizeof(db_pgno_t) + sizeof(db_indx_t))
2208 
2209 /*******************************************************
2210  * Access method cursors.
2211  *******************************************************/
2212 struct __dbc {
2213     DB *dbp;            /* Backing database */
2214     DB_ENV *dbenv;          /* Backing environment */
2215     ENV *env;           /* Backing environment */
2216 
2217     DB_THREAD_INFO *thread_info;    /* Thread that owns this cursor. */
2218     DB_TXN   *txn;          /* Associated transaction. */
2219     DB_CACHE_PRIORITY priority; /* Priority in cache. */
2220 
2221     db_slice_t dbc_curslice;    /* Current DB of an all-slice DBC. */
2222     DBC *dbc_slices[1];         /* A containing dbc's array of DBC
2223                        handles for its slices. */
2224 
2225     /*
2226      * Active/free cursor queues.
2227      *
2228      * !!!
2229      * Explicit representations of structures from queue.h.
2230      * TAILQ_ENTRY(__dbc) links;
2231      */
2232     struct {
2233         DBC *tqe_next;
2234         DBC **tqe_prev;
2235     } links;
2236 
2237     /*
2238      * Cursor queue of the owning transaction.
2239      *
2240      * !!!
2241      * Explicit representations of structures from queue.h.
2242      * TAILQ_ENTRY(__dbc) txn_cursors;
2243      */
2244     struct {
2245         DBC *tqe_next;  /* next element */
2246         DBC **tqe_prev; /* address of previous next element */
2247     } txn_cursors;
2248 
2249     /*
2250      * The DBT *'s below are used by the cursor routines to return
2251      * data to the user when DBT flags indicate that DB should manage
2252      * the returned memory.  They point at a DBT containing the buffer
2253      * and length that will be used, and "belonging" to the handle that
2254      * should "own" this memory.  This may be a "my_*" field of this
2255      * cursor--the default--or it may be the corresponding field of
2256      * another cursor, a DB handle, a join cursor, etc.  In general, it
2257      * will be whatever handle the user originally used for the current
2258      * DB interface call.
2259      */
2260     DBT  *rskey;        /* Returned secondary key. */
2261     DBT  *rkey;         /* Returned [primary] key. */
2262     DBT  *rdata;        /* Returned data. */
2263 
2264     DBT   my_rskey;     /* Space for returned secondary key. */
2265     DBT   my_rkey;      /* Space for returned [primary] key. */
2266     DBT   my_rdata;     /* Space for returned data. */
2267 
2268     DBT  *cur_key;
2269 
2270     DB_LOCKER *lref;        /* Reference to default locker. */
2271     DB_LOCKER *locker;      /* Locker for this operation. */
2272     DBT   lock_dbt;     /* DBT referencing lock. */
2273     DB_LOCK_ILOCK lock;     /* Object to be locked. */
2274     DB_LOCK   mylock;       /* CDB lock held on this cursor. */
2275 
2276     DBTYPE    dbtype;       /* Cursor type. */
2277 
2278     DBC_INTERNAL *internal;     /* Access method private. */
2279 
2280     /* DBC PUBLIC HANDLE LIST BEGIN */
2281     int (*close) __P((DBC *));
2282     int (*cmp) __P((DBC *, DBC *, int *, u_int32_t));
2283     int (*count) __P((DBC *, db_recno_t *, u_int32_t));
2284     int (*db_stream) __P((DBC *, DB_STREAM **, u_int32_t));
2285     int (*del) __P((DBC *, u_int32_t));
2286     int (*dup) __P((DBC *, DBC **, u_int32_t));
2287     int (*get) __P((DBC *, DBT *, DBT *, u_int32_t));
2288     int (*get_priority) __P((DBC *, DB_CACHE_PRIORITY *));
2289     int (*pget) __P((DBC *, DBT *, DBT *, DBT *, u_int32_t));
2290     int (*put) __P((DBC *, DBT *, DBT *, u_int32_t));
2291     int (*set_priority) __P((DBC *, DB_CACHE_PRIORITY));
2292     /* DBC PUBLIC HANDLE LIST END */
2293 
2294     /* The following are the method names deprecated in the 4.6 release. */
2295     int (*c_close) __P((DBC *));
2296     int (*c_count) __P((DBC *, db_recno_t *, u_int32_t));
2297     int (*c_del) __P((DBC *, u_int32_t));
2298     int (*c_dup) __P((DBC *, DBC **, u_int32_t));
2299     int (*c_get) __P((DBC *, DBT *, DBT *, u_int32_t));
2300     int (*c_pget) __P((DBC *, DBT *, DBT *, DBT *, u_int32_t));
2301     int (*c_put) __P((DBC *, DBT *, DBT *, u_int32_t));
2302 
2303     /* DBC PRIVATE HANDLE LIST BEGIN */
2304     int (*am_bulk) __P((DBC *, DBT *, u_int32_t));
2305     int (*am_close) __P((DBC *, db_pgno_t, int *));
2306     int (*am_del) __P((DBC *, u_int32_t));
2307     int (*am_destroy) __P((DBC *));
2308     int (*am_get) __P((DBC *, DBT *, DBT *, u_int32_t, db_pgno_t *));
2309     int (*am_put) __P((DBC *, DBT *, DBT *, u_int32_t, db_pgno_t *));
2310     int (*am_writelock) __P((DBC *));
2311     /* DBC PRIVATE HANDLE LIST END */
2312 
2313     u_int32_t open_flags;       /* Flags passed to DB->cursor. */
2314 /*
2315  * DBC_DONTLOCK and DBC_RECOVER are used during recovery and transaction
2316  * abort.  If a transaction is being aborted or recovered then DBC_RECOVER
2317  * will be set and locking and logging will be disabled on this cursor.  If
2318  * we are performing a compensating transaction (e.g. free page processing)
2319  * then DB_DONTLOCK will be set to inhibit locking, but logging will still
2320  * be required. DB_DONTLOCK is also used if the whole database is locked.
2321  */
2322 #define DBC_ACTIVE      0x00001 /* Cursor in use. */
2323 #define DBC_BULK        0x00002 /* Bulk update cursor. */
2324 #define DBC_DONTLOCK        0x00004 /* Don't lock on this cursor. */
2325 #define DBC_DOWNREV     0x00008 /* Down rev replication master. */
2326 #define DBC_DUPLICATE       0x00010 /* Create a duplicate cursor. */
2327 #define DBC_ERROR       0x00020 /* Error in this request. */
2328 #define DBC_FAMILY      0x00040 /* Part of a locker family. */
2329 #define DBC_FROM_DB_GET     0x00080 /* Called from the DB->get() method. */
2330 #define DBC_MULTIPLE        0x00100 /* Return Multiple data. */
2331 #define DBC_MULTIPLE_KEY    0x00200 /* Return Multiple keys and data. */
2332 #define DBC_OPD         0x00400 /* Cursor references off-page dups. */
2333 #define DBC_OWN_LID     0x00800 /* Free lock id on destroy. */
2334 #define DBC_PARTITIONED     0x01000 /* Cursor for a partitioned db. */
2335 #define DBC_READ_COMMITTED  0x02000 /* Cursor has degree 2 isolation. */
2336 #define DBC_READ_UNCOMMITTED    0x04000 /* Cursor has degree 1 isolation. */
2337 #define DBC_RECOVER     0x08000 /* Recovery cursor; don't log/lock. */
2338 #define DBC_RMW         0x10000 /* Acquire write flag in read op. */
2339 #define DBC_TRANSIENT       0x20000 /* Cursor is transient. */
2340 #define DBC_WAS_READ_COMMITTED  0x40000 /* Cursor holds a read commited lock. */
2341 #define DBC_WRITECURSOR     0x80000 /* Cursor may be used to write (CDB). */
2342 #define DBC_WRITER         0x100000 /* Cursor immediately writing (CDB). */
2343     u_int32_t flags;
2344 };
2345 
2346 /* Key range statistics structure */
2347 struct __key_range {
2348     double less;
2349     double equal;
2350     double greater;
2351 };
2352 
2353 /* Btree/Recno statistics structure. */
2354 struct __db_bt_stat { /* SHARED */
2355     u_int32_t bt_magic;     /* Magic number. */
2356     u_int32_t bt_version;       /* Version number. */
2357     u_int32_t bt_metaflags;     /* Metadata flags. */
2358     u_int32_t bt_nkeys;     /* Number of unique keys. */
2359     u_int32_t bt_ndata;     /* Number of data items. */
2360     u_int32_t bt_pagecnt;       /* Page count. */
2361     u_int32_t bt_pagesize;      /* Page size. */
2362     u_int32_t bt_minkey;        /* Minkey value. */
2363     u_int32_t bt_ext_files;     /* Number of external files. */
2364     u_int32_t bt_nblobs;        /* Deprecated alias bt_ext_files. */
2365     u_int32_t bt_re_len;        /* Fixed-length record length. */
2366     u_int32_t bt_re_pad;        /* Fixed-length record pad. */
2367     u_int32_t bt_levels;        /* Tree levels. */
2368     u_int32_t bt_int_pg;        /* Internal pages. */
2369     u_int32_t bt_leaf_pg;       /* Leaf pages. */
2370     u_int32_t bt_dup_pg;        /* Duplicate pages. */
2371     u_int32_t bt_over_pg;       /* Overflow pages. */
2372     u_int32_t bt_empty_pg;      /* Empty pages. */
2373     u_int32_t bt_free;      /* Pages on the free list. */
2374     uintmax_t bt_int_pgfree;    /* Bytes free in internal pages. */
2375     uintmax_t bt_leaf_pgfree;   /* Bytes free in leaf pages. */
2376     uintmax_t bt_dup_pgfree;    /* Bytes free in duplicate pages. */
2377     uintmax_t bt_over_pgfree;   /* Bytes free in overflow pages. */
2378 };
2379 
2380 struct __db_compact {
2381     /* Input Parameters. */
2382     u_int32_t   compact_fillpercent;    /* Desired fillfactor: 1-100 */
2383     db_timeout_t    compact_timeout;    /* Lock timeout. */
2384     u_int32_t   compact_pages;      /* Max pages to process. */
2385     /* Output Stats. */
2386     u_int32_t   compact_empty_buckets;  /* Empty hash buckets found. */
2387     u_int32_t   compact_pages_free; /* Number of pages freed. */
2388     u_int32_t   compact_pages_examine;  /* Number of pages examine. */
2389     u_int32_t   compact_levels;     /* Number of levels removed. */
2390     u_int32_t   compact_deadlock;   /* Number of deadlocks. */
2391     db_pgno_t   compact_pages_truncated; /* Pages truncated to OS. */
2392     /* Internal. */
2393     db_pgno_t   compact_truncate;   /* Exchange pages above here. */
2394 };
2395 
2396 /* Hash statistics structure. */
2397 struct __db_h_stat { /* SHARED */
2398     u_int32_t hash_magic;       /* Magic number. */
2399     u_int32_t hash_version;     /* Version number. */
2400     u_int32_t hash_metaflags;   /* Metadata flags. */
2401     u_int32_t hash_nkeys;       /* Number of unique keys. */
2402     u_int32_t hash_ndata;       /* Number of data items. */
2403     u_int32_t hash_ext_files;   /* Number of external files. */
2404     u_int32_t hash_nblobs;      /* Deprecated alias hash_ext_files. */
2405     u_int32_t hash_pagecnt;     /* Page count. */
2406     u_int32_t hash_pagesize;    /* Page size. */
2407     u_int32_t hash_ffactor;     /* Fill factor specified at create. */
2408     u_int32_t hash_buckets;     /* Number of hash buckets. */
2409     u_int32_t hash_free;        /* Pages on the free list. */
2410     uintmax_t hash_bfree;       /* Bytes free on bucket pages. */
2411     u_int32_t hash_bigpages;    /* Number of big key/data pages. */
2412     uintmax_t hash_big_bfree;   /* Bytes free on big item pages. */
2413     u_int32_t hash_overflows;   /* Number of overflow pages. */
2414     uintmax_t hash_ovfl_free;   /* Bytes free on ovfl pages. */
2415     u_int32_t hash_dup;     /* Number of dup pages. */
2416     uintmax_t hash_dup_free;    /* Bytes free on duplicate pages. */
2417 };
2418 
2419 /* Heap statistics structure. */
2420 struct __db_heap_stat { /* SHARED */
2421     u_int32_t heap_magic;       /* Magic number. */
2422     u_int32_t heap_version;     /* Version number. */
2423     u_int32_t heap_metaflags;   /* Metadata flags. */
2424     u_int32_t heap_ext_files;   /* Number of external files. */
2425     u_int32_t heap_nblobs;      /* Deprecated alias heap_ext_files. */
2426     u_int32_t heap_nrecs;       /* Number of records. */
2427     u_int32_t heap_pagecnt;     /* Page count. */
2428     u_int32_t heap_pagesize;    /* Page size. */
2429     u_int32_t heap_nregions;    /* Number of regions. */
2430     u_int32_t heap_regionsize;  /* Number of pages in a region. */
2431 };
2432 
2433 /* Queue statistics structure. */
2434 struct __db_qam_stat { /* SHARED */
2435     u_int32_t qs_magic;     /* Magic number. */
2436     u_int32_t qs_version;       /* Version number. */
2437     u_int32_t qs_metaflags;     /* Metadata flags. */
2438     u_int32_t qs_nkeys;     /* Number of unique keys. */
2439     u_int32_t qs_ndata;     /* Number of data items. */
2440     u_int32_t qs_pagesize;      /* Page size. */
2441     u_int32_t qs_extentsize;    /* Pages per extent. */
2442     u_int32_t qs_pages;     /* Data pages. */
2443     u_int32_t qs_re_len;        /* Fixed-length record length. */
2444     u_int32_t qs_re_pad;        /* Fixed-length record pad. */
2445     u_int32_t qs_pgfree;        /* Bytes free in data pages. */
2446     u_int32_t qs_first_recno;   /* First not deleted record. */
2447     u_int32_t qs_cur_recno;     /* Next available record number. */
2448 };
2449 
2450 /*******************************************************
2451  * Environment.
2452  *******************************************************/
2453 #define DB_REGION_MAGIC     0x120897 /* The environment is available. */
2454 #define DB_REGION_MAGIC_RECOVER 0xeeeccc /* Recovery is running. */
2455 
2456 /*
2457  * Database environment structure.
2458  *
2459  * This is the public database environment handle.  The private environment
2460  * handle is the ENV structure.   The user owns this structure, the library
2461  * owns the ENV structure.  The reason there are two structures is because
2462  * the user's configuration outlives any particular DB_ENV->open call, and
2463  * separate structures allows us to easily discard internal information without
2464  * discarding the user's configuration.
2465  *
2466  * Fields in the DB_ENV structure should normally be set only by application
2467  * DB_ENV handle methods.
2468  */
2469 
2470 /*
2471  * Memory configuration types.
2472  */
2473 typedef enum {
2474     DB_MEM_DATABASE=1,
2475     DB_MEM_DATABASE_LENGTH=2,
2476     DB_MEM_EXTFILE_DATABASE=3,
2477     DB_MEM_LOCK=4,
2478     DB_MEM_LOCKOBJECT=5,
2479     DB_MEM_LOCKER=6,
2480     DB_MEM_LOGID=7,
2481     DB_MEM_REP_SITE=8,
2482     DB_MEM_TRANSACTION=9,
2483     DB_MEM_THREAD=10
2484 } DB_MEM_CONFIG;
2485 
2486 /*
2487  * Backup configuration types.
2488  */
2489 typedef enum {
2490     DB_BACKUP_READ_COUNT=1,
2491     DB_BACKUP_READ_SLEEP=2,
2492     DB_BACKUP_SIZE=3,
2493     DB_BACKUP_WRITE_DIRECT=4
2494 } DB_BACKUP_CONFIG;
2495 
2496 struct __db_env {
2497     ENV *env;           /* Linked ENV structure */
2498 
2499                     /* Error message callback */
2500     void (*db_errcall) __P((const DB_ENV *, const char *, const char *));
2501     FILE        *db_errfile;    /* Error message file stream */
2502     const char  *db_errpfx; /* Error message prefix */
2503 
2504                     /* Other message callback */
2505     void (*db_msgcall) __P((const DB_ENV *, const char *, const char *));
2506     FILE        *db_msgfile;    /* Other message file stream */
2507     const char  *db_msgpfx; /* Other message prefix */
2508 
2509     /* Other application callback functions */
2510     int   (*app_dispatch) __P((DB_ENV *, DBT *, DB_LSN *, db_recops));
2511     void  (*db_event_func) __P((DB_ENV *, u_int32_t, void *));
2512     void  (*db_feedback) __P((DB_ENV *, int, int));
2513     void  (*db_free) __P((void *));
2514     void  (*db_paniccall) __P((DB_ENV *, int));
2515     void *(*db_malloc) __P((size_t));
2516     void *(*db_realloc) __P((void *, size_t));
2517     int   (*is_alive) __P((DB_ENV *, pid_t, db_threadid_t, u_int32_t));
2518     void  (*thread_id) __P((DB_ENV *, pid_t *, db_threadid_t *));
2519     char *(*thread_id_string) __P((DB_ENV *, pid_t, db_threadid_t, char *));
2520 
2521     /* Application specified paths */
2522     char    *db_blob_dir;       /* External file directory */
2523     char    *db_log_dir;        /* Database log file directory */
2524     char    *db_md_dir;     /* Persistent metadata directory */
2525     char    *db_reg_dir;        /* Region file directory */
2526     char    *db_tmp_dir;        /* Database tmp file directory */
2527 
2528     char    *db_create_dir;     /* Create directory for data files */
2529     char   **db_data_dir;       /* Database data file directories (or
2530                        sliced environment home dirs?) */
2531     int  data_cnt;      /* Database data file slots */
2532     int  data_next;     /* Next database data file slot */
2533 
2534     char    *intermediate_dir_mode; /* Intermediate directory perms */
2535 
2536     long     shm_key;       /* shmget key */
2537 
2538     char    *passwd;        /* Cryptography support */
2539     size_t   passwd_len;
2540     u_int32_t   encrypt_flags;  
2541 
2542     /* Private handle references */
2543     void    *app_private;       /* Application-private handle */
2544     void    *api1_internal;     /* C++, Perl API private */
2545     void    *api2_internal;     /* Java API private */
2546 
2547     u_int32_t   verbose;    /* DB_VERB_XXX flags */
2548 
2549     u_int32_t   blob_threshold; /* External file threshold size */
2550 
2551     /* Database configuration */
2552     u_int32_t   db_init_databases;  /* Number of databases. */
2553     u_int32_t   db_init_db_len;     /* Database name length. */
2554     u_int32_t   db_init_extfile_dbs;    /*
2555                          * Number of additional
2556                          * external file metadata
2557                          * databases.
2558                          */
2559 
2560     /* Mutex configuration */
2561     u_int32_t   mutex_align;    /* Mutex alignment */
2562     u_int32_t   mutex_cnt;  /* Number of mutexes to configure */
2563     u_int32_t   mutex_inc;  /* Number of mutexes to add */
2564     u_int32_t   mutex_max;  /* Max number of mutexes */
2565     u_int32_t   mutex_tas_spins;/* Test-and-set spin count */
2566 
2567     /* Locking configuration */
2568     u_int8_t       *lk_conflicts;   /* Two dimensional conflict matrix */
2569     int     lk_modes;   /* Number of lock modes in table */
2570     u_int32_t   lk_detect;  /* Deadlock detect on all conflicts */
2571     u_int32_t   lk_max; /* Maximum number of locks */
2572     u_int32_t   lk_max_lockers;/* Maximum number of lockers */
2573     u_int32_t   lk_max_objects;/* Maximum number of locked objects */
2574     u_int32_t   lk_init;    /* Initial number of locks */
2575     u_int32_t   lk_init_lockers;/* Initial number of lockers */
2576     u_int32_t   lk_init_objects;/* Initial number of locked objects */
2577     u_int32_t   lk_partitions ;/* Number of object partitions */
2578     db_timeout_t    lk_timeout; /* Lock timeout period */
2579     /* Used during initialization */
2580     u_int32_t   locker_t_size;  /* Locker hash table size. */
2581     u_int32_t   object_t_size;  /* Object hash table size. */
2582 
2583     /* Logging configuration */
2584     u_int32_t   lg_bsize;   /* Buffer size */
2585     u_int32_t   lg_fileid_init; /* Initial allocation for fname structs */
2586     int     lg_filemode;    /* Log file permission mode */
2587     u_int32_t   lg_regionmax;   /* Region size */
2588     u_int32_t   lg_size;    /* Log file size */
2589     u_int32_t   lg_flags;   /* Log configuration */
2590 
2591     /* Memory pool configuration */
2592     u_int32_t   mp_gbytes;  /* Cache size: GB */
2593     u_int32_t   mp_bytes;   /* Cache size: bytes */
2594     u_int32_t   mp_max_gbytes;  /* Maximum cache size: GB */
2595     u_int32_t   mp_max_bytes;   /* Maximum cache size: bytes */
2596     size_t      mp_mmapsize;    /* Maximum file size for mmap */
2597     int     mp_maxopenfd;   /* Maximum open file descriptors */
2598     int     mp_maxwrite;    /* Maximum buffers to write */
2599     u_int       mp_ncache;  /* Initial number of cache regions */
2600     u_int32_t   mp_pagesize;    /* Average page size */
2601     u_int32_t   mp_tablesize;   /* Approximate hash table size */
2602     u_int32_t   mp_mtxcount;    /* Number of mutexs */
2603                     /* Sleep after writing max buffers */
2604     db_timeout_t    mp_maxwrite_sleep;
2605 
2606     /* Replication configuration */
2607     u_int32_t   rep_init_sites; /* Number of replication sites. */
2608 
2609     /* Transaction configuration */
2610     u_int32_t   tx_init;    /* Initial number of transactions */
2611     u_int32_t   tx_max;     /* Maximum number of transactions */
2612     time_t      tx_timestamp;   /* Recover to specific timestamp */
2613     db_timeout_t    tx_timeout; /* Timeout for transactions */
2614 
2615     /* Thread tracking configuration */
2616     u_int32_t   thr_init;   /* Thread count */
2617     u_int32_t   thr_max;    /* Thread max */
2618     roff_t      memory_max; /* Maximum region memory */
2619 
2620     /*
2621      * The following fields are not strictly user-owned, but they outlive
2622      * the ENV structure, and so are stored here.
2623      */
2624     DB_FH       *registry;  /* DB_REGISTER file handle */
2625     u_int32_t   registry_off;   /*
2626                      * Offset of our slot.  We can't use
2627                      * off_t because its size depends on
2628                      * build settings.
2629                      */
2630         db_timeout_t    envreg_timeout; /* DB_REGISTER wait timeout */
2631 
2632     /*
2633      * When failchk broadcasting is active, any wait for a mutex will wake
2634      * up this frequently in order to check whether the mutex has died.
2635      */
2636     db_timeout_t    mutex_failchk_timeout;
2637 
2638     /* slice_cnt is non-zero only for containers. */
2639     db_slice_t  slice_cnt;
2640 
2641 #define DB_ENV_AUTO_COMMIT  0x00000001 /* DB_AUTO_COMMIT */
2642 #define DB_ENV_CDB_ALLDB    0x00000002 /* CDB environment wide locking */
2643 #define DB_ENV_FAILCHK      0x00000004 /* Failchk is running */
2644 #define DB_ENV_DIRECT_DB    0x00000008 /* DB_DIRECT_DB set */
2645 #define DB_ENV_DSYNC_DB     0x00000010 /* DB_DSYNC_DB set */
2646 #define DB_ENV_DATABASE_LOCKING 0x00000020 /* Try database-level locking */
2647 #define DB_ENV_MULTIVERSION 0x00000040 /* DB_MULTIVERSION set */
2648 #define DB_ENV_NOLOCKING    0x00000080 /* DB_NOLOCKING set */
2649 #define DB_ENV_NOMMAP       0x00000100 /* DB_NOMMAP set */
2650 #define DB_ENV_NOPANIC      0x00000200 /* Okay if panic set */
2651 #define DB_ENV_OVERWRITE    0x00000400 /* DB_OVERWRITE set */
2652 #define DB_ENV_REGION_INIT  0x00000800 /* DB_REGION_INIT set */
2653 #define DB_ENV_TIME_NOTGRANTED  0x00001000 /* DB_TIME_NOTGRANTED set */
2654 #define DB_ENV_TXN_NOSYNC   0x00002000 /* DB_TXN_NOSYNC set */
2655 #define DB_ENV_TXN_NOWAIT   0x00004000 /* DB_TXN_NOWAIT set */
2656 #define DB_ENV_TXN_SNAPSHOT 0x00008000 /* DB_TXN_SNAPSHOT set */
2657 #define DB_ENV_TXN_WRITE_NOSYNC 0x00010000 /* DB_TXN_WRITE_NOSYNC set */
2658 #define DB_ENV_YIELDCPU     0x00020000 /* DB_YIELDCPU set */
2659 #define DB_ENV_HOTBACKUP    0x00040000 /* DB_HOTBACKUP_IN_PROGRESS set */
2660 #define DB_ENV_NOFLUSH      0x00080000 /* DB_NOFLUSH set */
2661     u_int32_t flags;
2662 
2663     /* DB_ENV PUBLIC HANDLE LIST BEGIN */
2664     int  (*add_data_dir) __P((DB_ENV *, const char *));
2665     int  (*backup)  __P((DB_ENV *, const char *, u_int32_t));
2666     int  (*cdsgroup_begin) __P((DB_ENV *, DB_TXN **));
2667     int  (*close) __P((DB_ENV *, u_int32_t));
2668     int  (*dbbackup) __P((DB_ENV *, const char *, const char *, u_int32_t));
2669     int  (*dbremove) __P((DB_ENV *,
2670         DB_TXN *, const char *, const char *, u_int32_t));
2671     int  (*dbrename) __P((DB_ENV *,
2672         DB_TXN *, const char *, const char *, const char *, u_int32_t));
2673     void (*err) __P((const DB_ENV *, int, const char *, ...));
2674     void (*errx) __P((const DB_ENV *, const char *, ...));
2675     int  (*failchk) __P((DB_ENV *, u_int32_t));
2676     int  (*fileid_reset) __P((DB_ENV *, const char *, u_int32_t));
2677     int  (*get_alloc) __P((DB_ENV *, void *(**)(size_t),
2678         void *(**)(void *, size_t), void (**)(void *)));
2679     int  (*get_app_dispatch)
2680         __P((DB_ENV *, int (**)(DB_ENV *, DBT *, DB_LSN *, db_recops)));
2681     int  (*get_blob_dir) __P((DB_ENV *, const char **));
2682     int  (*get_blob_threshold) __P((DB_ENV*, u_int32_t *));
2683     int  (*get_cache_max) __P((DB_ENV *, u_int32_t *, u_int32_t *));
2684     int  (*get_cachesize) __P((DB_ENV *, u_int32_t *, u_int32_t *, int *));
2685     int  (*get_create_dir) __P((DB_ENV *, const char **));
2686     int  (*get_data_dirs) __P((DB_ENV *, const char ***));
2687     int  (*get_data_len) __P((DB_ENV *, u_int32_t *));
2688     int  (*get_backup_callbacks) __P((DB_ENV *,
2689         int (**)(DB_ENV *, const char *, const char *, void **),
2690         int (**)(DB_ENV *, u_int32_t, u_int32_t, u_int32_t, u_int8_t *, void *),
2691         int (**)(DB_ENV *, const char *, void *)));
2692     int  (*get_backup_config) __P((DB_ENV *, DB_BACKUP_CONFIG, u_int32_t *));
2693     int  (*get_encrypt_flags) __P((DB_ENV *, u_int32_t *));
2694     void (*get_errcall) __P((DB_ENV *,
2695         void (**)(const DB_ENV *, const char *, const char *)));
2696     void (*get_errfile) __P((DB_ENV *, FILE **));
2697     void (*get_errpfx) __P((DB_ENV *, const char **));
2698     int  (*get_ext_file_dir) __P((DB_ENV *, const char **));
2699     int  (*get_ext_file_threshold) __P((DB_ENV*, u_int32_t *));
2700     int  (*get_feedback) __P((DB_ENV *, void (**)(DB_ENV *, int, int)));
2701     int  (*get_flags) __P((DB_ENV *, u_int32_t *));
2702     int  (*get_home) __P((DB_ENV *, const char **));
2703     int  (*get_intermediate_dir_mode) __P((DB_ENV *, const char **));
2704     int  (*get_isalive) __P((DB_ENV *,
2705         int (**)(DB_ENV *, pid_t, db_threadid_t, u_int32_t)));
2706     int  (*get_lg_bsize) __P((DB_ENV *, u_int32_t *));
2707     int  (*get_lg_dir) __P((DB_ENV *, const char **));
2708     int  (*get_lg_filemode) __P((DB_ENV *, int *));
2709     int  (*get_lg_max) __P((DB_ENV *, u_int32_t *));
2710     int  (*get_lg_regionmax) __P((DB_ENV *, u_int32_t *));
2711     int  (*get_lk_conflicts) __P((DB_ENV *, const u_int8_t **, int *));
2712     int  (*get_lk_detect) __P((DB_ENV *, u_int32_t *));
2713     int  (*get_lk_max_lockers) __P((DB_ENV *, u_int32_t *));
2714     int  (*get_lk_max_locks) __P((DB_ENV *, u_int32_t *));
2715     int  (*get_lk_max_objects) __P((DB_ENV *, u_int32_t *));
2716     int  (*get_lk_partitions) __P((DB_ENV *, u_int32_t *));
2717     int  (*get_lk_priority) __P((DB_ENV *, u_int32_t, u_int32_t *));
2718     int  (*get_lk_tablesize) __P((DB_ENV *, u_int32_t *));
2719     int  (*get_memory_init) __P((DB_ENV *, DB_MEM_CONFIG, u_int32_t *));
2720     int  (*get_memory_max) __P((DB_ENV *, u_int32_t *, u_int32_t *));
2721     int  (*get_metadata_dir) __P((DB_ENV *, const char **));
2722     int  (*get_mp_max_openfd) __P((DB_ENV *, int *));
2723     int  (*get_mp_max_write) __P((DB_ENV *, int *, db_timeout_t *));
2724     int  (*get_mp_mmapsize) __P((DB_ENV *, size_t *));
2725     int  (*get_mp_mtxcount) __P((DB_ENV *, u_int32_t *));
2726     int  (*get_mp_pagesize) __P((DB_ENV *, u_int32_t *));
2727     int  (*get_mp_tablesize) __P((DB_ENV *, u_int32_t *));
2728     void (*get_msgcall) __P((DB_ENV *,
2729         void (**)(const DB_ENV *, const char *, const char *)));
2730     void (*get_msgfile) __P((DB_ENV *, FILE **));
2731     void (*get_msgpfx) __P((DB_ENV *, const char **));
2732     int  (*get_open_flags) __P((DB_ENV *, u_int32_t *));
2733     int  (*get_region_dir) __P((DB_ENV *, const char **));
2734     int  (*get_slice_count) __P((DB_ENV *, u_int32_t *));
2735     int  (*get_slices) __P((DB_ENV *, DB_ENV ***));
2736     int  (*get_shm_key) __P((DB_ENV *, long *));
2737     int  (*get_thread_count) __P((DB_ENV *, u_int32_t *));
2738     int  (*get_thread_id_fn)
2739         __P((DB_ENV *, void (**)(DB_ENV *, pid_t *, db_threadid_t *)));
2740     int  (*get_thread_id_string_fn) __P((DB_ENV *,
2741         char *(**)(DB_ENV *, pid_t, db_threadid_t, char *)));
2742     int  (*get_timeout) __P((DB_ENV *, db_timeout_t *, u_int32_t));
2743     int  (*get_tmp_dir) __P((DB_ENV *, const char **));
2744     int  (*get_tx_max) __P((DB_ENV *, u_int32_t *));
2745     int  (*get_tx_timestamp) __P((DB_ENV *, time_t *));
2746     int  (*get_verbose) __P((DB_ENV *, u_int32_t, int *));
2747     int  (*is_bigendian) __P((void));
2748     int  (*lock_detect) __P((DB_ENV *, u_int32_t, u_int32_t, int *));
2749     int  (*lock_get) __P((DB_ENV *,
2750         u_int32_t, u_int32_t, DBT *, db_lockmode_t, DB_LOCK *));
2751     int  (*lock_id) __P((DB_ENV *, u_int32_t *));
2752     int  (*lock_id_free) __P((DB_ENV *, u_int32_t));
2753     int  (*lock_put) __P((DB_ENV *, DB_LOCK *));
2754     int  (*lock_stat) __P((DB_ENV *, DB_LOCK_STAT **, u_int32_t));
2755     int  (*lock_stat_print) __P((DB_ENV *, u_int32_t));
2756     int  (*lock_vec) __P((DB_ENV *,
2757         u_int32_t, u_int32_t, DB_LOCKREQ *, int, DB_LOCKREQ **));
2758     int  (*log_archive) __P((DB_ENV *, char **[], u_int32_t));
2759     int  (*log_cursor) __P((DB_ENV *, DB_LOGC **, u_int32_t));
2760     int  (*log_file) __P((DB_ENV *, const DB_LSN *, char *, size_t));
2761     int  (*log_flush) __P((DB_ENV *, const DB_LSN *));
2762     int  (*log_get_config) __P((DB_ENV *, u_int32_t, int *));
2763     int  (*log_printf) __P((DB_ENV *, DB_TXN *, const char *, ...));
2764     int  (*log_put) __P((DB_ENV *, DB_LSN *, const DBT *, u_int32_t));
2765     int  (*log_put_record) __P((DB_ENV *, DB *, DB_TXN *, DB_LSN *,
2766         u_int32_t, u_int32_t, u_int32_t, u_int32_t,
2767         DB_LOG_RECSPEC *, ...));
2768     int  (*log_read_record) __P((DB_ENV *, DB **,
2769         void *, void *, DB_LOG_RECSPEC *, u_int32_t, void **));
2770     int  (*log_set_config) __P((DB_ENV *, u_int32_t, int));
2771     int  (*log_stat) __P((DB_ENV *, DB_LOG_STAT **, u_int32_t));
2772     int  (*log_stat_print) __P((DB_ENV *, u_int32_t));
2773     int  (*log_verify) __P((DB_ENV *, const DB_LOG_VERIFY_CONFIG *));
2774     int  (*lsn_reset) __P((DB_ENV *, const char *, u_int32_t));
2775     int  (*memp_fcreate) __P((DB_ENV *, DB_MPOOLFILE **, u_int32_t));
2776     int  (*memp_register) __P((DB_ENV *, int, int (*)(DB_ENV *, db_pgno_t,
2777         void *, DBT *), int (*)(DB_ENV *, db_pgno_t, void *, DBT *)));
2778     int  (*memp_stat) __P((DB_ENV *,
2779         DB_MPOOL_STAT **, DB_MPOOL_FSTAT ***, u_int32_t));
2780     int  (*memp_stat_print) __P((DB_ENV *, u_int32_t));
2781     int  (*memp_sync) __P((DB_ENV *, DB_LSN *));
2782     int  (*memp_trickle) __P((DB_ENV *, int, int *));
2783     void (*msg) __P((const DB_ENV *, const char *, ...));
2784     int  (*mutex_alloc) __P((DB_ENV *, u_int32_t, db_mutex_t *));
2785     int  (*mutex_free) __P((DB_ENV *, db_mutex_t));
2786     int  (*mutex_get_align) __P((DB_ENV *, u_int32_t *));
2787     int  (*mutex_get_increment) __P((DB_ENV *, u_int32_t *));
2788     int  (*mutex_get_init) __P((DB_ENV *, u_int32_t *));
2789     int  (*mutex_get_max) __P((DB_ENV *, u_int32_t *));
2790     int  (*mutex_get_tas_spins) __P((DB_ENV *, u_int32_t *));
2791     int  (*mutex_lock) __P((DB_ENV *, db_mutex_t));
2792     int  (*mutex_set_align) __P((DB_ENV *, u_int32_t));
2793     int  (*mutex_set_increment) __P((DB_ENV *, u_int32_t));
2794     int  (*mutex_set_init) __P((DB_ENV *, u_int32_t));
2795     int  (*mutex_set_max) __P((DB_ENV *, u_int32_t));
2796     int  (*mutex_set_tas_spins) __P((DB_ENV *, u_int32_t));
2797     int  (*mutex_stat) __P((DB_ENV *, DB_MUTEX_STAT **, u_int32_t));
2798     int  (*mutex_stat_print) __P((DB_ENV *, u_int32_t));
2799     int  (*mutex_unlock) __P((DB_ENV *, db_mutex_t));
2800     int  (*open) __P((DB_ENV *, const char *, u_int32_t, int));
2801     int  (*remove) __P((DB_ENV *, const char *, u_int32_t));
2802     int  (*rep_elect) __P((DB_ENV *, u_int32_t, u_int32_t, u_int32_t));
2803     int  (*rep_flush) __P((DB_ENV *));
2804     int  (*rep_get_clockskew) __P((DB_ENV *, u_int32_t *, u_int32_t *));
2805     int  (*rep_get_config) __P((DB_ENV *, u_int32_t, int *));
2806     int  (*rep_get_limit) __P((DB_ENV *, u_int32_t *, u_int32_t *));
2807     int  (*rep_get_nsites) __P((DB_ENV *, u_int32_t *));
2808     int  (*rep_get_priority) __P((DB_ENV *, u_int32_t *));
2809     int  (*rep_get_request) __P((DB_ENV *, u_int32_t *, u_int32_t *));
2810     int  (*rep_get_timeout) __P((DB_ENV *, int, u_int32_t *));
2811     int  (*rep_process_message)
2812         __P((DB_ENV *, DBT *, DBT *, int, DB_LSN *));
2813     int  (*rep_set_clockskew) __P((DB_ENV *, u_int32_t, u_int32_t));
2814     int  (*rep_set_config) __P((DB_ENV *, u_int32_t, int));
2815     int  (*rep_set_limit) __P((DB_ENV *, u_int32_t, u_int32_t));
2816     int  (*rep_set_nsites) __P((DB_ENV *, u_int32_t));
2817     int  (*rep_set_priority) __P((DB_ENV *, u_int32_t));
2818     int  (*rep_set_request) __P((DB_ENV *, u_int32_t, u_int32_t));
2819     int  (*rep_set_timeout) __P((DB_ENV *, int, db_timeout_t));
2820     int  (*rep_set_transport) __P((DB_ENV *, int, int (*)(DB_ENV *,
2821         const DBT *, const DBT *, const DB_LSN *, int, u_int32_t)));
2822     int  (*rep_set_view) __P((DB_ENV *, int (*)(DB_ENV *,
2823         const char *, int *, u_int32_t)));
2824     int  (*rep_start) __P((DB_ENV *, DBT *, u_int32_t));
2825     int  (*rep_stat) __P((DB_ENV *, DB_REP_STAT **, u_int32_t));
2826     int  (*rep_stat_print) __P((DB_ENV *, u_int32_t));
2827     int  (*rep_sync) __P((DB_ENV *, u_int32_t));
2828     int  (*repmgr_channel) __P((DB_ENV *, int, DB_CHANNEL **, u_int32_t));
2829     int  (*repmgr_get_ack_policy) __P((DB_ENV *, int *));
2830     int  (*repmgr_get_incoming_queue_max)
2831         __P((DB_ENV *, u_int32_t *, u_int32_t *));
2832     int  (*repmgr_local_site) __P((DB_ENV *, DB_SITE **));
2833     int  (*repmgr_msg_dispatch) __P((DB_ENV *,
2834         void (*)(DB_ENV *, DB_CHANNEL *, DBT *, u_int32_t, u_int32_t),
2835         u_int32_t));
2836     int  (*repmgr_set_ack_policy) __P((DB_ENV *, int));
2837     int  (*repmgr_set_incoming_queue_max)
2838         __P((DB_ENV *, u_int32_t, u_int32_t));
2839     int  (*repmgr_set_socket) __P((DB_ENV *, int (*)(DB_ENV *,
2840         DB_REPMGR_SOCKET, int *, u_int32_t)));
2841     int (*repmgr_set_ssl_config) __P((DB_ENV *, int, char *));
2842     int  (*repmgr_site)
2843         __P((DB_ENV *, const char *, u_int, DB_SITE**, u_int32_t));
2844     int  (*repmgr_site_by_eid) __P((DB_ENV *, int, DB_SITE**));
2845     int  (*repmgr_site_list) __P((DB_ENV *, u_int *, DB_REPMGR_SITE **));
2846     int  (*repmgr_start) __P((DB_ENV *, int, u_int32_t));
2847     int  (*repmgr_stat) __P((DB_ENV *, DB_REPMGR_STAT **, u_int32_t));
2848     int  (*repmgr_stat_print) __P((DB_ENV *, u_int32_t));
2849     int  (*set_alloc) __P((DB_ENV *, void *(*)(size_t),
2850         void *(*)(void *, size_t), void (*)(void *)));
2851     int  (*set_app_dispatch)
2852         __P((DB_ENV *, int (*)(DB_ENV *, DBT *, DB_LSN *, db_recops)));
2853     int  (*set_blob_dir) __P((DB_ENV *, const char *));
2854     int  (*set_blob_threshold) __P((DB_ENV *, u_int32_t, u_int32_t));
2855     int  (*set_cache_max) __P((DB_ENV *, u_int32_t, u_int32_t));
2856     int  (*set_cachesize) __P((DB_ENV *, u_int32_t, u_int32_t, int));
2857     int  (*set_create_dir) __P((DB_ENV *, const char *));
2858     int  (*set_data_dir) __P((DB_ENV *, const char *));
2859     int  (*set_data_len) __P((DB_ENV *, u_int32_t));
2860     int  (*set_backup_callbacks) __P((DB_ENV *,
2861         int (*)(DB_ENV *, const char *, const char *, void **),
2862         int (*)(DB_ENV *, u_int32_t,
2863             u_int32_t, u_int32_t, u_int8_t *, void *),
2864         int (*)(DB_ENV *, const char *, void *)));
2865     int  (*set_backup_config) __P((DB_ENV *, DB_BACKUP_CONFIG, u_int32_t));
2866     int  (*set_encrypt) __P((DB_ENV *, const char *, u_int32_t));
2867     void (*set_errcall) __P((DB_ENV *,
2868         void (*)(const DB_ENV *, const char *, const char *)));
2869     void (*set_errfile) __P((DB_ENV *, FILE *));
2870     void (*set_errpfx) __P((DB_ENV *, const char *));
2871     int  (*set_event_notify)
2872         __P((DB_ENV *, void (*)(DB_ENV *, u_int32_t, void *)));
2873     int  (*set_ext_file_dir) __P((DB_ENV *, const char *));
2874     int  (*set_ext_file_threshold) __P((DB_ENV *, u_int32_t, u_int32_t));
2875     int  (*set_feedback) __P((DB_ENV *, void (*)(DB_ENV *, int, int)));
2876     int  (*set_flags) __P((DB_ENV *, u_int32_t, int));
2877     int  (*set_intermediate_dir_mode) __P((DB_ENV *, const char *));
2878     int  (*set_isalive) __P((DB_ENV *,
2879         int (*)(DB_ENV *, pid_t, db_threadid_t, u_int32_t)));
2880     int  (*set_lg_bsize) __P((DB_ENV *, u_int32_t));
2881     int  (*set_lg_dir) __P((DB_ENV *, const char *));
2882     int  (*set_lg_filemode) __P((DB_ENV *, int));
2883     int  (*set_lg_max) __P((DB_ENV *, u_int32_t));
2884     int  (*set_lg_regionmax) __P((DB_ENV *, u_int32_t));
2885     int  (*set_lk_conflicts) __P((DB_ENV *, u_int8_t *, int));
2886     int  (*set_lk_detect) __P((DB_ENV *, u_int32_t));
2887     int  (*set_lk_max_lockers) __P((DB_ENV *, u_int32_t));
2888     int  (*set_lk_max_locks) __P((DB_ENV *, u_int32_t));
2889     int  (*set_lk_max_objects) __P((DB_ENV *, u_int32_t));
2890     int  (*set_lk_partitions) __P((DB_ENV *, u_int32_t));
2891     int  (*set_lk_priority) __P((DB_ENV *, u_int32_t, u_int32_t));
2892     int  (*set_lk_tablesize) __P((DB_ENV *, u_int32_t));
2893     int  (*set_memory_init) __P((DB_ENV *, DB_MEM_CONFIG, u_int32_t));
2894     int  (*set_memory_max) __P((DB_ENV *, u_int32_t, u_int32_t));
2895     int  (*set_metadata_dir) __P((DB_ENV *, const char *));
2896     int  (*set_mp_max_openfd) __P((DB_ENV *, int));
2897     int  (*set_mp_max_write) __P((DB_ENV *, int, db_timeout_t));
2898     int  (*set_mp_mmapsize) __P((DB_ENV *, size_t));
2899     int  (*set_mp_mtxcount) __P((DB_ENV *, u_int32_t));
2900     int  (*set_mp_pagesize) __P((DB_ENV *, u_int32_t));
2901     int  (*set_mp_tablesize) __P((DB_ENV *, u_int32_t));
2902     void (*set_msgcall) __P((DB_ENV *,
2903         void (*)(const DB_ENV *, const char *, const char *)));
2904     void (*set_msgfile) __P((DB_ENV *, FILE *));
2905     void (*set_msgpfx) __P((DB_ENV *, const char *));
2906     int  (*set_paniccall) __P((DB_ENV *, void (*)(DB_ENV *, int)));
2907     int  (*set_region_dir) __P((DB_ENV *, const char *));
2908     int  (*set_shm_key) __P((DB_ENV *, long));
2909     int  (*set_thread_count) __P((DB_ENV *, u_int32_t));
2910     int  (*set_thread_id)
2911         __P((DB_ENV *, void (*)(DB_ENV *, pid_t *, db_threadid_t *)));
2912     int  (*set_thread_id_string) __P((DB_ENV *,
2913         char *(*)(DB_ENV *, pid_t, db_threadid_t, char *)));
2914     int  (*set_timeout) __P((DB_ENV *, db_timeout_t, u_int32_t));
2915     int  (*set_tmp_dir) __P((DB_ENV *, const char *));
2916     int  (*set_tx_max) __P((DB_ENV *, u_int32_t));
2917     int  (*set_tx_timestamp) __P((DB_ENV *, time_t *));
2918     int  (*set_verbose) __P((DB_ENV *, u_int32_t, int));
2919     int  (*txn_applied) __P((DB_ENV *,
2920         DB_TXN_TOKEN *, db_timeout_t, u_int32_t));
2921     int  (*stat_print) __P((DB_ENV *, u_int32_t));
2922     int  (*txn_begin) __P((DB_ENV *, DB_TXN *, DB_TXN **, u_int32_t));
2923     int  (*txn_checkpoint) __P((DB_ENV *, u_int32_t, u_int32_t, u_int32_t));
2924     int  (*txn_recover) __P((DB_ENV *,
2925         DB_PREPLIST *, long, long *, u_int32_t));
2926     int  (*txn_stat) __P((DB_ENV *, DB_TXN_STAT **, u_int32_t));
2927     int  (*txn_stat_print) __P((DB_ENV *, u_int32_t));
2928     /* DB_ENV PUBLIC HANDLE LIST END */
2929 
2930     /* DB_ENV PRIVATE HANDLE LIST BEGIN */
2931     int  (*prdbt) __P((DBT *, int, const char *, void *,
2932         int (*)(void *, const void *), int, int, int));
2933     /* DB_ENV PRIVATE HANDLE LIST END */
2934 };
2935 
2936 /*
2937  * Dispatch structure for recovery, log verification and print routines. Since
2938  * internal and external routines take different arguments (ENV versus DB_ENV),
2939  * we need something more elaborate than a single pointer and size.  Each size
2940  * is the number of allocated entries in the corresponding dispatch table,
2941  * rather than a byte count.
2942  */
2943 struct __db_distab {
2944     int   (**int_dispatch) __P((ENV *, DBT *, DB_LSN *, db_recops, void *));
2945     int   (**ext_dispatch) __P((DB_ENV *, DBT *, DB_LSN *, db_recops));
2946     size_t  int_size;
2947     size_t  ext_size;
2948 };
2949 
2950 /*
2951  * Log verification configuration structure.
2952  */
2953 struct __db_logvrfy_config {
2954     int continue_after_fail;
2955     int verbose;
2956     u_int32_t cachesize;
2957     const char *temp_envhome;
2958     const char *dbfile;
2959     const char *dbname;
2960     DB_LSN start_lsn;
2961     DB_LSN end_lsn;
2962     time_t start_time;
2963     time_t end_time;
2964 };
2965 
2966 struct __db_channel {
2967     CHANNEL *channel;   /* Pointer to internal state details. */
2968     int eid;        /* Env. ID passed in constructor. */
2969     db_timeout_t timeout;
2970 
2971     /* DB_CHANNEL PUBLIC HANDLE LIST BEGIN */
2972     int (*close) __P((DB_CHANNEL *, u_int32_t));
2973     int (*send_msg) __P((DB_CHANNEL *, DBT *, u_int32_t, u_int32_t));
2974     int (*send_request) __P((DB_CHANNEL *,
2975         DBT *, u_int32_t, DBT *, db_timeout_t, u_int32_t));
2976     int  (*set_timeout) __P((DB_CHANNEL *, db_timeout_t));
2977     /* DB_CHANNEL PUBLIC HANDLE LIST END */
2978 };
2979 
2980 struct __db_site {
2981     ENV *env;
2982     int eid;
2983     const char *host;
2984     u_int port;
2985     u_int32_t flags;
2986 
2987     /* DB_SITE PUBLIC HANDLE LIST BEGIN */
2988     int (*get_address) __P((DB_SITE *, const char **, u_int *));
2989     int (*get_config) __P((DB_SITE *, u_int32_t, u_int32_t *));
2990     int (*get_eid) __P((DB_SITE *, int *));
2991     int (*set_config) __P((DB_SITE *, u_int32_t, u_int32_t));
2992     int (*remove) __P((DB_SITE *));
2993     int (*close) __P((DB_SITE *));
2994     /* DB_SITE PUBLIC HANDLE LIST END */
2995 };
2996 
2997 #if DB_DBM_HSEARCH != 0
2998 /*******************************************************
2999  * Dbm/Ndbm historic interfaces.
3000  *******************************************************/
3001 typedef struct __db DBM;
3002 
3003 #define DBM_INSERT  0       /* Flags to dbm_store(). */
3004 #define DBM_REPLACE 1
3005 
3006 /*
3007  * The DB support for ndbm(3) always appends this suffix to the
3008  * file name to avoid overwriting the user's original database.
3009  */
3010 #define DBM_SUFFIX  ".db"
3011 
3012 #if defined(_XPG4_2)
3013 typedef struct {
3014     char *dptr;
3015     size_t dsize;
3016 } datum;
3017 #else
3018 typedef struct {
3019     char *dptr;
3020     int dsize;
3021 } datum;
3022 #endif
3023 
3024 /*
3025  * Translate NDBM calls into DB calls so that DB doesn't step on the
3026  * application's name space.
3027  */
3028 #define dbm_clearerr(a)     __db_ndbm_clearerr(a)
3029 #define dbm_close(a)        __db_ndbm_close(a)
3030 #define dbm_delete(a, b)    __db_ndbm_delete(a, b)
3031 #define dbm_dirfno(a)       __db_ndbm_dirfno(a)
3032 #define dbm_error(a)        __db_ndbm_error(a)
3033 #define dbm_fetch(a, b)     __db_ndbm_fetch(a, b)
3034 #define dbm_firstkey(a)     __db_ndbm_firstkey(a)
3035 #define dbm_nextkey(a)      __db_ndbm_nextkey(a)
3036 #define dbm_open(a, b, c)   __db_ndbm_open(a, b, c)
3037 #define dbm_pagfno(a)       __db_ndbm_pagfno(a)
3038 #define dbm_rdonly(a)       __db_ndbm_rdonly(a)
3039 #define dbm_store(a, b, c, d) \
3040     __db_ndbm_store(a, b, c, d)
3041 
3042 /*
3043  * Translate DBM calls into DB calls so that DB doesn't step on the
3044  * application's name space.
3045  *
3046  * The global variables dbrdonly, dirf and pagf were not retained when 4BSD
3047  * replaced the dbm interface with ndbm, and are not supported here.
3048  *
3049  * Definition of 'store' interface will cause macro conflict for modern
3050  * compiler with C++11 support, we will exclude this case here.
3051  */
3052 #define dbminit(a)  __db_dbm_init(a)
3053 #define dbmclose    __db_dbm_close
3054 #if !defined(__cplusplus)
3055 #define delete(a)   __db_dbm_delete(a)
3056 #define store(a, b) __db_dbm_store(a, b)
3057 #endif
3058 #define fetch(a)    __db_dbm_fetch(a)
3059 #define firstkey    __db_dbm_firstkey
3060 #define nextkey(a)  __db_dbm_nextkey(a)
3061 
3062 /*******************************************************
3063  * Hsearch historic interface.
3064  *******************************************************/
3065 typedef enum {
3066     FIND, ENTER
3067 } ACTION;
3068 
3069 typedef struct entry {
3070     char *key;
3071     char *data;
3072 } ENTRY;
3073 
3074 #define hcreate(a)  __db_hcreate(a)
3075 #define hdestroy    __db_hdestroy
3076 #define hsearch(a, b)   __db_hsearch(a, b)
3077 
3078 #endif /* DB_DBM_HSEARCH */
3079 
3080 #if defined(__cplusplus)
3081 }
3082 #endif
3083 
3084 
3085 #endif /* !_DB_H_ */
3086 /* DO NOT EDIT: automatically built by dist/s_apiflags. */
3087 #define DB_AGGRESSIVE               0x00000001
3088 #define DB_ARCH_ABS             0x00000001
3089 #define DB_ARCH_DATA                0x00000002
3090 #define DB_ARCH_LOG             0x00000004
3091 #define DB_ARCH_REMOVE              0x00000008
3092 #define DB_AUTO_COMMIT              0x00000100
3093 #define DB_BACKUP_CLEAN             0x00000002
3094 #define DB_BACKUP_DEEP_COPY         0x00000008
3095 #define DB_BACKUP_FILES             0x00000010
3096 #define DB_BACKUP_NO_LOGS           0x00000020
3097 #define DB_BACKUP_SINGLE_DIR            0x00000040
3098 #define DB_BACKUP_UPDATE            0x00000080
3099 #define DB_BOOTSTRAP_HELPER         0x00000001
3100 #define DB_CDB_ALLDB                0x00000040
3101 #define DB_CHKSUM               0x00000008
3102 #define DB_CKP_INTERNAL             0x00000002
3103 #define DB_CONVERT              0x00000001
3104 #define DB_CREATE               0x00000001
3105 #define DB_CURSOR_BULK              0x00000001
3106 #define DB_CURSOR_TRANSIENT         0x00000008
3107 #define DB_CXX_NO_EXCEPTIONS            0x00000002
3108 #define DB_DATABASE_LOCKING         0x00000080
3109 #define DB_DIRECT               0x00000020
3110 #define DB_DIRECT_DB                0x00000200
3111 #define DB_DSYNC_DB             0x00000400
3112 #define DB_DUP                  0x00000010
3113 #define DB_DUPSORT              0x00000002
3114 #define DB_DURABLE_UNKNOWN          0x00000040
3115 #define DB_ENCRYPT              0x00000001
3116 #define DB_ENCRYPT_AES              0x00000001
3117 #define DB_EXCL                 0x00000004
3118 #define DB_EXTENT               0x00000100
3119 #define DB_FAILCHK              0x00000010
3120 #define DB_FAILCHK_ISALIVE          0x00000040
3121 #define DB_FAST_STAT                0x00000001
3122 #define DB_FCNTL_LOCKING            0x00001000
3123 #define DB_FLUSH                0x00000002
3124 #define DB_FORCE                0x00000001
3125 #define DB_FORCESYNC                0x00000001
3126 #define DB_FORCESYNCENV             0x00000002
3127 #define DB_FOREIGN_ABORT            0x00000001
3128 #define DB_FOREIGN_CASCADE          0x00000002
3129 #define DB_FOREIGN_NULLIFY          0x00000004
3130 #define DB_FREELIST_ONLY            0x00000001
3131 #define DB_FREE_SPACE               0x00000002
3132 #define DB_GROUP_CREATOR            0x00000002
3133 #define DB_HOTBACKUP_IN_PROGRESS        0x00000800
3134 #define DB_IGNORE_LEASE             0x00001000
3135 #define DB_IMMUTABLE_KEY            0x00000002
3136 #define DB_INIT_CDB             0x00000080
3137 #define DB_INIT_LOCK                0x00000100
3138 #define DB_INIT_LOG             0x00000200
3139 #define DB_INIT_MPOOL               0x00000400
3140 #define DB_INIT_MUTEX               0x00000800
3141 #define DB_INIT_REP             0x00001000
3142 #define DB_INIT_TXN             0x00002000
3143 #define DB_INORDER              0x00000020
3144 #define DB_INTERNAL_BLOB_DB         0x00002000
3145 #define DB_INTERNAL_PERSISTENT_DB       0x00004000
3146 #define DB_INTERNAL_TEMPORARY_DB        0x00008000
3147 #define DB_JOIN_NOSORT              0x00000001
3148 #define DB_LEGACY               0x00000004
3149 #define DB_LOCAL_SITE               0x00000008
3150 #define DB_LOCKDOWN             0x00004000
3151 #define DB_LOCK_CHECK               0x00000001
3152 #define DB_LOCK_IGNORE_REC          0x00000002
3153 #define DB_LOCK_NOWAIT              0x00000004
3154 #define DB_LOCK_RECORD              0x00000008
3155 #define DB_LOCK_SET_TIMEOUT         0x00000010
3156 #define DB_LOCK_SWITCH              0x00000020
3157 #define DB_LOCK_UPGRADE             0x00000040
3158 #define DB_LOG_AUTO_REMOVE          0x00000001
3159 #define DB_LOG_CHKPNT               0x00000001
3160 #define DB_LOG_COMMIT               0x00000004
3161 #define DB_LOG_DIRECT               0x00000002
3162 #define DB_LOG_DSYNC                0x00000004
3163 #define DB_LOG_EXT_FILE             0x00000008
3164 #define DB_LOG_BLOB             0x00000008
3165 #define DB_LOG_IN_MEMORY            0x00000010
3166 #define DB_LOG_NOCOPY               0x00000008
3167 #define DB_LOG_NOSYNC               0x00000020
3168 #define DB_LOG_NOT_DURABLE          0x00000010
3169 #define DB_LOG_NO_DATA              0x00000002
3170 #define DB_LOG_VERIFY_CAF           0x00000001
3171 #define DB_LOG_VERIFY_DBFILE            0x00000002
3172 #define DB_LOG_VERIFY_ERR           0x00000004
3173 #define DB_LOG_VERIFY_FORWARD           0x00000008
3174 #define DB_LOG_VERIFY_INTERR            0x00000010
3175 #define DB_LOG_VERIFY_PARTIAL           0x00000020
3176 #define DB_LOG_VERIFY_VERBOSE           0x00000040
3177 #define DB_LOG_VERIFY_WARNING           0x00000080
3178 #define DB_LOG_WRNOSYNC             0x00000020
3179 #define DB_LOG_ZERO             0x00000040
3180 #define DB_MPOOL_CREATE             0x00000001
3181 #define DB_MPOOL_DIRTY              0x00000002
3182 #define DB_MPOOL_DISCARD            0x00000001
3183 #define DB_MPOOL_EDIT               0x00000004
3184 #define DB_MPOOL_FREE               0x00000008
3185 #define DB_MPOOL_LAST               0x00000010
3186 #define DB_MPOOL_NEW                0x00000020
3187 #define DB_MPOOL_NOFILE             0x00000001
3188 #define DB_MPOOL_NOLOCK             0x00000004
3189 #define DB_MPOOL_TRY                0x00000040
3190 #define DB_MPOOL_UNLINK             0x00000002
3191 #define DB_MULTIPLE             0x00000800
3192 #define DB_MULTIPLE_KEY             0x00004000
3193 #define DB_MULTIVERSION             0x00000008
3194 #define DB_MUTEX_ALLOCATED          0x00000001
3195 #define DB_MUTEX_LOCKED             0x00000002
3196 #define DB_MUTEX_LOGICAL_LOCK           0x00000004
3197 #define DB_MUTEX_OWNER_DEAD         0x00000020
3198 #define DB_MUTEX_PROCESS_ONLY           0x00000008
3199 #define DB_MUTEX_SELF_BLOCK         0x00000010
3200 #define DB_MUTEX_SHARED             0x00000040
3201 #define DB_NOERROR              0x00010000
3202 #define DB_NOFLUSH              0x00001000
3203 #define DB_NOLOCKING                0x00002000
3204 #define DB_NOMMAP               0x00000010
3205 #define DB_NOORDERCHK               0x00000002
3206 #define DB_NOPANIC              0x00004000
3207 #define DB_NOSYNC               0x00000001
3208 #define DB_NO_AUTO_COMMIT           0x00020000
3209 #define DB_NO_CHECKPOINT            0x00008000
3210 #define DB_ODDFILESIZE              0x00000080
3211 #define DB_ORDERCHKONLY             0x00000004
3212 #define DB_OVERWRITE                0x00008000
3213 #define DB_PANIC_ENVIRONMENT            0x00010000
3214 #define DB_PRINTABLE                0x00000008
3215 #define DB_PRIVATE              0x00010000
3216 #define DB_PR_PAGE              0x00000010
3217 #define DB_PR_RECOVERYTEST          0x00000020
3218 #define DB_RDONLY               0x00000400
3219 #define DB_RDWRMASTER               0x00040000
3220 #define DB_READ_COMMITTED           0x00000400
3221 #define DB_READ_UNCOMMITTED         0x00000200
3222 #define DB_RECNUM               0x00000040
3223 #define DB_RECOVER              0x00000002
3224 #define DB_RECOVER_FATAL            0x00020000
3225 #define DB_REGION_INIT              0x00020000
3226 #define DB_REGISTER             0x00040000
3227 #define DB_RENUMBER             0x00000080
3228 #define DB_REPMGR_CONF_2SITE_STRICT     0x00000001
3229 #define DB_REPMGR_CONF_DISABLE_POLL     0x00000002
3230 #define DB_REPMGR_CONF_DISABLE_SSL      0x00000004
3231 #define DB_REPMGR_CONF_ELECTIONS        0x00000008
3232 #define DB_REPMGR_CONF_ENABLE_EPOLL     0x00000010
3233 #define DB_REPMGR_CONF_FORWARD_WRITES       0x00000020
3234 #define DB_REPMGR_CONF_PREFMAS_CLIENT       0x00000040
3235 #define DB_REPMGR_CONF_PREFMAS_MASTER       0x00000080
3236 #define DB_REPMGR_NEED_RESPONSE         0x00000001
3237 #define DB_REPMGR_PEER              0x00000010
3238 #define DB_REP_ANYWHERE             0x00000001
3239 #define DB_REP_CLIENT               0x00000001
3240 #define DB_REP_CONF_AUTOINIT            0x00000100
3241 #define DB_REP_CONF_AUTOROLLBACK        0x00000200
3242 #define DB_REP_CONF_BULK            0x00000400
3243 #define DB_REP_CONF_DELAYCLIENT         0x00000800
3244 #define DB_REP_CONF_ELECT_LOGLENGTH     0x00001000
3245 #define DB_REP_CONF_INMEM           0x00002000
3246 #define DB_REP_CONF_LEASE           0x00004000
3247 #define DB_REP_CONF_NOWAIT          0x00008000
3248 #define DB_REP_ELECTION             0x00000004
3249 #define DB_REP_MASTER               0x00000002
3250 #define DB_REP_NOBUFFER             0x00000002
3251 #define DB_REP_PERMANENT            0x00000004
3252 #define DB_REP_REREQUEST            0x00000008
3253 #define DB_REVSPLITOFF              0x00000100
3254 #define DB_RMW                  0x00002000
3255 #define DB_SALVAGE              0x00000040
3256 #define DB_SA_SKIPFIRSTKEY          0x00000080
3257 #define DB_SA_UNKNOWNKEY            0x00000100
3258 #define DB_SEQ_DEC              0x00000001
3259 #define DB_SEQ_INC              0x00000002
3260 #define DB_SEQ_RANGE_SET            0x00000004
3261 #define DB_SEQ_WRAP             0x00000008
3262 #define DB_SEQ_WRAPPED              0x00000010
3263 #define DB_SET_LOCK_TIMEOUT         0x00000001
3264 #define DB_SET_MUTEX_FAILCHK_TIMEOUT        0x00000004
3265 #define DB_SET_REG_TIMEOUT          0x00000008
3266 #define DB_SET_TXN_NOW              0x00000010
3267 #define DB_SET_TXN_TIMEOUT          0x00000002
3268 #define DB_SHALLOW_DUP              0x00000100
3269 #define DB_SLICED               0x00000800
3270 #define DB_SNAPSHOT             0x00000200
3271 #define DB_STAT_ALL             0x00000004
3272 #define DB_STAT_ALLOC               0x00000008
3273 #define DB_STAT_CLEAR               0x00000001
3274 #define DB_STAT_LOCK_CONF           0x00000010
3275 #define DB_STAT_LOCK_LOCKERS            0x00000020
3276 #define DB_STAT_LOCK_OBJECTS            0x00000040
3277 #define DB_STAT_LOCK_PARAMS         0x00000080
3278 #define DB_STAT_MEMP_HASH           0x00000010
3279 #define DB_STAT_MEMP_NOERROR            0x00000020
3280 #define DB_STAT_SUBSYSTEM           0x00000002
3281 #define DB_STAT_SUMMARY             0x00000010
3282 #define DB_ST_DUPOK             0x00000200
3283 #define DB_ST_DUPSET                0x00000400
3284 #define DB_ST_DUPSORT               0x00000800
3285 #define DB_ST_IS_RECNO              0x00001000
3286 #define DB_ST_OVFL_LEAF             0x00002000
3287 #define DB_ST_RECNUM                0x00004000
3288 #define DB_ST_RELEN             0x00008000
3289 #define DB_ST_TOPLEVEL              0x00010000
3290 #define DB_SYSTEM_MEM               0x00080000
3291 #define DB_THREAD               0x00000020
3292 #define DB_TIME_NOTGRANTED          0x00040000
3293 #define DB_TRUNCATE             0x00080000
3294 #define DB_TXN_BULK             0x00000010
3295 #define DB_TXN_DISPATCH             0x00000040
3296 #define DB_TXN_FAMILY               0x00000080
3297 #define DB_TXN_NOSYNC               0x00000001
3298 #define DB_TXN_NOT_DURABLE          0x00000004
3299 #define DB_TXN_NOWAIT               0x00000002
3300 #define DB_TXN_SNAPSHOT             0x00000004
3301 #define DB_TXN_SYNC             0x00000008
3302 #define DB_TXN_WAIT             0x00000100
3303 #define DB_TXN_WRITE_NOSYNC         0x00000020
3304 #define DB_UNREF                0x00020000
3305 #define DB_UPGRADE              0x00000002
3306 #define DB_USE_ENVIRON              0x00000004
3307 #define DB_USE_ENVIRON_ROOT         0x00000008
3308 #define DB_VERB_BACKUP              0x00000001
3309 #define DB_VERB_DEADLOCK            0x00000002
3310 #define DB_VERB_FILEOPS             0x00000004
3311 #define DB_VERB_FILEOPS_ALL         0x00000008
3312 #define DB_VERB_MVCC                0x00000010
3313 #define DB_VERB_RECOVERY            0x00000020
3314 #define DB_VERB_REGISTER            0x00000040
3315 #define DB_VERB_REPLICATION         0x00000080
3316 #define DB_VERB_REPMGR_CONNFAIL         0x00000100
3317 #define DB_VERB_REPMGR_MISC         0x00000200
3318 #define DB_VERB_REPMGR_SSL_ALL          0x00000400
3319 #define DB_VERB_REPMGR_SSL_CONN         0x00000800
3320 #define DB_VERB_REPMGR_SSL_IO           0x00001000
3321 #define DB_VERB_REP_ELECT           0x00002000
3322 #define DB_VERB_REP_LEASE           0x00004000
3323 #define DB_VERB_REP_MISC            0x00008000
3324 #define DB_VERB_REP_MSGS            0x00010000
3325 #define DB_VERB_REP_SYNC            0x00020000
3326 #define DB_VERB_REP_SYSTEM          0x00040000
3327 #define DB_VERB_REP_TEST            0x00080000
3328 #define DB_VERB_SLICE               0x00100000
3329 #define DB_VERB_WAITSFOR            0x00200000
3330 #define DB_VERIFY               0x00000004
3331 #define DB_VERIFY_PARTITION         0x00040000
3332 #define DB_WRITECURSOR              0x00000010
3333 #define DB_WRITELOCK                0x00000020
3334 #define DB_WRITEOPEN                0x00100000
3335 #define DB_XA_CREATE                0x00000001
3336 #define DB_YIELDCPU             0x00080000
3337 
3338 /* DO NOT EDIT: automatically built by dist/s_include. */
3339 #ifndef _DB_EXT_PROT_IN_
3340 #define _DB_EXT_PROT_IN_
3341 
3342 #if defined(__cplusplus)
3343 extern "C" {
3344 #endif
3345 
3346 int db_copy __P((DB_ENV *, const char *, const char *, const char *));
3347 int db_create __P((DB **, DB_ENV *, u_int32_t));
3348 char *db_strerror __P((int));
3349 int db_env_set_func_assert __P((void (*)(const char *, const char *, int)));
3350 int db_env_set_func_close __P((int (*)(int)));
3351 int db_env_set_func_dirfree __P((void (*)(char **, int)));
3352 int db_env_set_func_dirlist __P((int (*)(const char *, char ***, int *)));
3353 int db_env_set_func_exists __P((int (*)(const char *, int *)));
3354 int db_env_set_func_free __P((void (*)(void *)));
3355 int db_env_set_func_fsync __P((int (*)(int)));
3356 int db_env_set_func_ftruncate __P((int (*)(int, off_t)));
3357 int db_env_set_func_ioinfo __P((int (*)(const char *, int, u_int32_t *, u_int32_t *, u_int32_t *)));
3358 int db_env_set_func_malloc __P((void *(*)(size_t)));
3359 int db_env_set_func_file_map __P((int (*)(DB_ENV *, char *, size_t, int, void **), int (*)(DB_ENV *, void *)));
3360 int db_env_set_func_region_map __P((int (*)(DB_ENV *, char *, size_t, int *, void **), int (*)(DB_ENV *, void *)));
3361 int db_env_set_func_pread __P((ssize_t (*)(int, void *, size_t, off_t)));
3362 int db_env_set_func_pwrite __P((ssize_t (*)(int, const void *, size_t, off_t)));
3363 int db_env_set_func_open __P((int (*)(const char *, int, ...)));
3364 int db_env_set_func_read __P((ssize_t (*)(int, void *, size_t)));
3365 int db_env_set_func_realloc __P((void *(*)(void *, size_t)));
3366 int db_env_set_func_rename __P((int (*)(const char *, const char *)));
3367 int db_env_set_func_seek __P((int (*)(int, off_t, int)));
3368 int db_env_set_func_unlink __P((int (*)(const char *)));
3369 int db_env_set_func_write __P((ssize_t (*)(int, const void *, size_t)));
3370 int db_env_set_func_yield __P((int (*)(u_long, u_long)));
3371 int db_env_create __P((DB_ENV **, u_int32_t));
3372 char *db_version __P((int *, int *, int *));
3373 char *db_full_version __P((int *, int *, int *, int *, int *));
3374 int log_compare __P((const DB_LSN *, const DB_LSN *));
3375 #if defined(DB_WIN32) && !defined(DB_WINCE)
3376 int db_env_set_win_security __P((SECURITY_ATTRIBUTES *sa));
3377 #endif
3378 int db_sequence_create __P((DB_SEQUENCE **, DB *, u_int32_t));
3379 #if DB_DBM_HSEARCH != 0
3380 int  __db_ndbm_clearerr __P((DBM *));
3381 void     __db_ndbm_close __P((DBM *));
3382 int  __db_ndbm_delete __P((DBM *, datum));
3383 int  __db_ndbm_dirfno __P((DBM *));
3384 int  __db_ndbm_error __P((DBM *));
3385 datum __db_ndbm_fetch __P((DBM *, datum));
3386 datum __db_ndbm_firstkey __P((DBM *));
3387 datum __db_ndbm_nextkey __P((DBM *));
3388 DBM *__db_ndbm_open __P((const char *, int, int));
3389 int  __db_ndbm_pagfno __P((DBM *));
3390 int  __db_ndbm_rdonly __P((DBM *));
3391 int  __db_ndbm_store __P((DBM *, datum, datum, int));
3392 int  __db_dbm_close __P((void));
3393 int  __db_dbm_delete __P((datum));
3394 datum __db_dbm_fetch __P((datum));
3395 datum __db_dbm_firstkey __P((void));
3396 int  __db_dbm_init __P((char *));
3397 datum __db_dbm_nextkey __P((datum));
3398 int  __db_dbm_store __P((datum, datum));
3399 #endif
3400 #if DB_DBM_HSEARCH != 0
3401 int __db_hcreate __P((size_t));
3402 ENTRY *__db_hsearch __P((ENTRY, ACTION));
3403 void __db_hdestroy __P((void));
3404 #endif
3405 
3406 #if defined(__cplusplus)
3407 }
3408 #endif
3409 #endif /* !_DB_EXT_PROT_IN_ */