Main Page | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Related Pages

db.h

00001 /* DO NOT EDIT: automatically built by dist/s_vxworks. */
00002 /*
00003  * See the file LICENSE for redistribution information.
00004  *
00005  * Copyright (c) 1996-2005
00006  *      Sleepycat Software.  All rights reserved.
00007  *
00008  * $Id: db.in,v 12.67 2005/11/10 21:10:24 bostic Exp $
00009  *
00010  * db.h include file layout:
00011  *      General.
00012  *      Database Environment.
00013  *      Locking subsystem.
00014  *      Logging subsystem.
00015  *      Shared buffer cache (mpool) subsystem.
00016  *      Transaction subsystem.
00017  *      Access methods.
00018  *      Access method cursors.
00019  *      Dbm/Ndbm, Hsearch historic interfaces.
00020  */
00021 
00022 #ifndef _DB_H_
00023 #define _DB_H_
00024 
00025 #ifndef __NO_SYSTEM_INCLUDES
00026 #include <sys/types.h>
00027 #include <stdio.h>
00028 #endif
00029 
00030 #if defined(__cplusplus)
00031 extern "C" {
00032 #endif
00033 
00034 /* Tornado 2 does not provide a standard C pre-processor #define. */
00035 #ifndef __vxworks
00036 #define __vxworks
00037 #endif
00038 
00039 
00040 #undef __P
00041 #define __P(protos)     protos
00042 
00043 /*
00044  * Berkeley DB version information.
00045  */
00046 #define DB_VERSION_MAJOR        4
00047 #define DB_VERSION_MINOR        4
00048 #define DB_VERSION_PATCH        16
00049 #define DB_VERSION_STRING       "Sleepycat Software: Berkeley DB 4.4.16: (November 12, 2005)"
00050 
00051 /*
00052  * !!!
00053  * Berkeley DB uses specifically sized types.  If they're not provided by
00054  * the system, typedef them here.
00055  *
00056  * We protect them against multiple inclusion using __BIT_TYPES_DEFINED__,
00057  * as does BIND and Kerberos, since we don't know for sure what #include
00058  * files the user is using.
00059  *
00060  * !!!
00061  * We also provide the standard u_int, u_long etc., if they're not provided
00062  * by the system.
00063  */
00064 #ifndef __BIT_TYPES_DEFINED__
00065 #define __BIT_TYPES_DEFINED__
00066 typedef unsigned char u_int8_t;
00067 typedef unsigned short u_int16_t;
00068 typedef unsigned int u_int32_t;
00069 
00070 typedef unsigned long long u_int64_t;
00071 #endif
00072 
00073 
00074 /*
00075  * uintmax_t --
00076  * Largest unsigned type, used to align structures in memory.  We don't store
00077  * floating point types in structures, so integral types should be sufficient
00078  * (and we don't have to worry about systems that store floats in other than
00079  * power-of-2 numbers of bytes).  Additionally this fixes compilers that rewrite
00080  * structure assignments and ANSI C memcpy calls to be in-line instructions
00081  * that happen to require alignment.
00082  *
00083  * uintptr_t --
00084  * Unsigned type that's the same size as a pointer.  There are places where
00085  * DB modifies pointers by discarding the bottom bits to guarantee alignment.
00086  * We can't use uintmax_t, it may be larger than the pointer, and compilers
00087  * get upset about that.  So far we haven't run on any machine where there's
00088  * no unsigned type the same size as a pointer -- here's hoping.
00089  */
00090 typedef unsigned long uintmax_t;
00091 typedef unsigned long uintptr_t;
00092 
00093 /*
00094  * Sequences are only available on machines with 64-bit integral types.
00095  */
00096 typedef int db_seq_t;
00097 
00098 /* Thread and process identification. */
00099 typedef uintmax_t db_threadid_t;
00100 
00101 /* Basic types that are exported or quasi-exported. */
00102 typedef u_int32_t       db_pgno_t;      /* Page number type. */
00103 typedef u_int16_t       db_indx_t;      /* Page offset type. */
00104 #define DB_MAX_PAGES    0xffffffff      /* >= # of pages in a file */
00105 
00106 typedef u_int32_t       db_recno_t;     /* Record number type. */
00107 #define DB_MAX_RECORDS  0xffffffff      /* >= # of records in a tree */
00108 
00109 typedef u_int32_t       db_timeout_t;   /* Type of a timeout. */
00110 
00111 /*
00112  * Region offsets are the difference between a pointer in a region and the
00113  * region's base address.  With private environments, both addresses are the
00114  * result of calling malloc, and we can't assume anything about what malloc
00115  * will return, so region offsets have to be able to hold differences between
00116  * arbitrary pointers.
00117  */
00118 typedef uintptr_t       roff_t;
00119 
00120 /*
00121  * Forward structure declarations, so we can declare pointers and
00122  * applications can get type checking.
00123  */
00124 struct __db;            typedef struct __db DB;
00125 struct __db_bt_stat;    typedef struct __db_bt_stat DB_BTREE_STAT;
00126 struct __db_cipher;     typedef struct __db_cipher DB_CIPHER;
00127 struct __db_compact;    typedef struct __db_compact DB_COMPACT;
00128 struct __db_dbt;        typedef struct __db_dbt DBT;
00129 struct __db_env;        typedef struct __db_env DB_ENV;
00130 struct __db_h_stat;     typedef struct __db_h_stat DB_HASH_STAT;
00131 struct __db_ilock;      typedef struct __db_ilock DB_LOCK_ILOCK;
00132 struct __db_lock_stat;  typedef struct __db_lock_stat DB_LOCK_STAT;
00133 struct __db_lock_u;     typedef struct __db_lock_u DB_LOCK;
00134 struct __db_lockreq;    typedef struct __db_lockreq DB_LOCKREQ;
00135 struct __db_log_cursor; typedef struct __db_log_cursor DB_LOGC;
00136 struct __db_log_stat;   typedef struct __db_log_stat DB_LOG_STAT;
00137 struct __db_lsn;        typedef struct __db_lsn DB_LSN;
00138 struct __db_mpool;      typedef struct __db_mpool DB_MPOOL;
00139 struct __db_mpool_fstat;typedef struct __db_mpool_fstat DB_MPOOL_FSTAT;
00140 struct __db_mpool_stat; typedef struct __db_mpool_stat DB_MPOOL_STAT;
00141 struct __db_mpoolfile;  typedef struct __db_mpoolfile DB_MPOOLFILE;
00142 struct __db_mutex_stat; typedef struct __db_mutex_stat DB_MUTEX_STAT;
00143 struct __db_preplist;   typedef struct __db_preplist DB_PREPLIST;
00144 struct __db_qam_stat;   typedef struct __db_qam_stat DB_QUEUE_STAT;
00145 struct __db_rep;        typedef struct __db_rep DB_REP;
00146 struct __db_rep_stat;   typedef struct __db_rep_stat DB_REP_STAT;
00147 struct __db_seq_record; typedef struct __db_seq_record DB_SEQ_RECORD;
00148 struct __db_seq_stat;   typedef struct __db_seq_stat DB_SEQUENCE_STAT;
00149 struct __db_sequence;   typedef struct __db_sequence DB_SEQUENCE;
00150 struct __db_txn;        typedef struct __db_txn DB_TXN;
00151 struct __db_txn_active; typedef struct __db_txn_active DB_TXN_ACTIVE;
00152 struct __db_txn_stat;   typedef struct __db_txn_stat DB_TXN_STAT;
00153 struct __db_txnmgr;     typedef struct __db_txnmgr DB_TXNMGR;
00154 struct __dbc;           typedef struct __dbc DBC;
00155 struct __dbc_internal;  typedef struct __dbc_internal DBC_INTERNAL;
00156 struct __fh_t;          typedef struct __fh_t DB_FH;
00157 struct __fname;         typedef struct __fname FNAME;
00158 struct __key_range;     typedef struct __key_range DB_KEY_RANGE;
00159 struct __mpoolfile;     typedef struct __mpoolfile MPOOLFILE;
00160 
00161 /* Key/data structure -- a Data-Base Thang. */
00162 struct __db_dbt {
00163         void     *data;                 /* Key/data */
00164         u_int32_t size;                 /* key/data length */
00165 
00166         u_int32_t ulen;                 /* RO: length of user buffer. */
00167         u_int32_t dlen;                 /* RO: get/put record length. */
00168         u_int32_t doff;                 /* RO: get/put record offset. */
00169 
00170 #define DB_DBT_APPMALLOC        0x001   /* Callback allocated memory. */
00171 #define DB_DBT_ISSET            0x002   /* Lower level calls set value. */
00172 #define DB_DBT_MALLOC           0x004   /* Return in malloc'd memory. */
00173 #define DB_DBT_PARTIAL          0x008   /* Partial put/get. */
00174 #define DB_DBT_REALLOC          0x010   /* Return in realloc'd memory. */
00175 #define DB_DBT_USERMEM          0x020   /* Return in user's memory. */
00176 #define DB_DBT_DUPOK            0x040   /* Insert if duplicate. */
00177         u_int32_t flags;
00178 };
00179 
00180 /*
00181  * Common flags --
00182  *      Interfaces which use any of these common flags should never have
00183  *      interface specific flags in this range.
00184  */
00185 #define DB_CREATE             0x0000001 /* Create file as necessary. */
00186 #define DB_DURABLE_UNKNOWN    0x0000002 /* Durability on open (internal). */
00187 #define DB_FORCE              0x0000004 /* Force (anything). */
00188 #define DB_NOMMAP             0x0000008 /* Don't mmap underlying file. */
00189 #define DB_RDONLY             0x0000010 /* Read-only (O_RDONLY). */
00190 #define DB_RECOVER            0x0000020 /* Run normal recovery. */
00191 #define DB_THREAD             0x0000040 /* Applications are threaded. */
00192 #define DB_TRUNCATE           0x0000080 /* Discard existing DB (O_TRUNC). */
00193 #define DB_TXN_NOSYNC         0x0000100 /* Do not sync log on commit. */
00194 #define DB_TXN_NOT_DURABLE    0x0000200 /* Do not log changes. */
00195 #define DB_TXN_WRITE_NOSYNC   0x0000400 /* Write the log but don't sync. */
00196 #define DB_USE_ENVIRON        0x0000800 /* Use the environment. */
00197 #define DB_USE_ENVIRON_ROOT   0x0001000 /* Use the environment if root. */
00198 
00199 /*
00200  * Common flags --
00201  *      Interfaces which use any of these common flags should never have
00202  *      interface specific flags in this range.
00203  *
00204  * DB_AUTO_COMMIT:
00205  *      DB_ENV->set_flags, DB->open
00206  *      (Note: until the 4.3 release, legal to DB->associate, DB->del,
00207  *      DB->put, DB->remove, DB->rename and DB->truncate, and others.)
00208  * DB_READ_COMMITTED:
00209  *      DB->cursor, DB->get, DB->join, DBcursor->c_get, DB_ENV->txn_begin
00210  * DB_READ_UNCOMMITTED:
00211  *      DB->cursor, DB->get, DB->join, DB->open, DBcursor->c_get,
00212  *      DB_ENV->txn_begin
00213  *
00214  * !!!
00215  * The DB_READ_COMMITTED and DB_READ_UNCOMMITTED bit masks can't be changed
00216  * without also changing the masks for the flags that can be OR'd into DB
00217  * access method and cursor operation values.
00218  */
00219 #define DB_AUTO_COMMIT        0x01000000/* Implied transaction. */
00220 
00221 #define DB_READ_COMMITTED     0x02000000/* Degree 2 isolation. */
00222 #define DB_DEGREE_2           0x02000000/*      Historic name. */
00223 
00224 #define DB_READ_UNCOMMITTED   0x04000000/* Degree 1 isolation. */
00225 #define DB_DIRTY_READ         0x04000000/*      Historic name. */
00226 
00227 /*
00228  * Flags common to db_env_create and db_create.
00229  */
00230 #define DB_CXX_NO_EXCEPTIONS  0x0000001 /* C++: return error values. */
00231 
00232 /*
00233  * Flags private to db_env_create.
00234  *         Shared flags up to 0x0000001 */
00235 #define DB_RPCCLIENT          0x0000002 /* An RPC client environment. */
00236 
00237 /*
00238  * Flags private to db_create.
00239  *         Shared flags up to 0x0000001 */
00240 #define DB_XA_CREATE          0x0000002 /* Open in an XA environment. */
00241 
00242 /*
00243  * Flags private to DB_ENV->open.
00244  *         Shared flags up to 0x0001000 */
00245 #define DB_INIT_CDB           0x0002000 /* Concurrent Access Methods. */
00246 #define DB_INIT_LOCK          0x0004000 /* Initialize locking. */
00247 #define DB_INIT_LOG           0x0008000 /* Initialize logging. */
00248 #define DB_INIT_MPOOL         0x0010000 /* Initialize mpool. */
00249 #define DB_INIT_REP           0x0020000 /* Initialize replication. */
00250 #define DB_INIT_TXN           0x0040000 /* Initialize transactions. */
00251 #define DB_LOCKDOWN           0x0080000 /* Lock memory into physical core. */
00252 #define DB_PRIVATE            0x0100000 /* DB_ENV is process local. */
00253 #define DB_RECOVER_FATAL      0x0200000 /* Run catastrophic recovery. */
00254 #define DB_REGISTER           0x0400000 /* Multi-process registry. */
00255 #define DB_SYSTEM_MEM         0x0800000 /* Use system-backed memory. */
00256 
00257 #define DB_JOINENV            0x0       /* Compatibility. */
00258 
00259 /*
00260  * Flags private to DB->open.
00261  *         Shared flags up to 0x0001000 */
00262 #define DB_EXCL               0x0002000 /* Exclusive open (O_EXCL). */
00263 #define DB_FCNTL_LOCKING      0x0004000 /* UNDOC: fcntl(2) locking. */
00264 #define DB_NO_AUTO_COMMIT     0x0008000 /* Override env-wide AUTOCOMMIT. */
00265 #define DB_RDWRMASTER         0x0010000 /* UNDOC: allow subdb master open R/W */
00266 #define DB_WRITEOPEN          0x0020000 /* UNDOC: open with write lock. */
00267 
00268 /*
00269  * Flags private to DB->associate.
00270  *         Shared flags up to 0x0001000 */
00271 #define DB_IMMUTABLE_KEY      0x0002000 /* Secondary key is immutable. */
00272 /*            Shared flags at 0x1000000 */
00273 
00274 /*
00275  * Flags private to DB_ENV->txn_begin.
00276  *         Shared flags up to 0x0001000 */
00277 #define DB_TXN_NOWAIT         0x0002000 /* Do not wait for locks in this TXN. */
00278 #define DB_TXN_SYNC           0x0004000 /* Always sync log on commit. */
00279 
00280 /*
00281  * Flags private to DB_ENV->set_encrypt.
00282  */
00283 #define DB_ENCRYPT_AES        0x0000001 /* AES, assumes SHA1 checksum */
00284 
00285 /*
00286  * Flags private to DB_ENV->set_flags.
00287  *         Shared flags up to 0x00001000 */
00288 #define DB_CDB_ALLDB          0x00002000/* Set CDB locking per environment. */
00289 #define DB_DIRECT_DB          0x00004000/* Don't buffer databases in the OS. */
00290 #define DB_DIRECT_LOG         0x00008000/* Don't buffer log files in the OS. */
00291 #define DB_DSYNC_DB           0x00010000/* Set O_DSYNC on the databases. */
00292 #define DB_DSYNC_LOG          0x00020000/* Set O_DSYNC on the log. */
00293 #define DB_LOG_AUTOREMOVE     0x00040000/* Automatically remove log files. */
00294 #define DB_LOG_INMEMORY       0x00080000/* Store logs in buffers in memory. */
00295 #define DB_NOLOCKING          0x00100000/* Set locking/mutex behavior. */
00296 #define DB_NOPANIC            0x00200000/* Set panic state per DB_ENV. */
00297 #define DB_OVERWRITE          0x00400000/* Overwrite unlinked region files. */
00298 #define DB_PANIC_ENVIRONMENT  0x00800000/* Set panic state per environment. */
00299 /*            Shared flags at 0x01000000 */
00300 /*            Shared flags at 0x02000000 */
00301 /*            Shared flags at 0x04000000 */
00302 #define DB_REGION_INIT        0x08000000/* Page-fault regions on open. */
00303 #define DB_TIME_NOTGRANTED    0x10000000/* Return NOTGRANTED on timeout. */
00304 #define DB_YIELDCPU           0x20000000/* Yield the CPU (a lot). */
00305 
00306 /*
00307  * Flags private to DB->set_feedback's callback.
00308  */
00309 #define DB_UPGRADE            0x0000001 /* Upgrading. */
00310 #define DB_VERIFY             0x0000002 /* Verifying. */
00311 
00312 /*
00313  * Flags private to DB->compact.
00314  *         Shared flags up to 0x00001000
00315  */
00316 #define DB_FREELIST_ONLY      0x00002000 /* Just sort and truncate. */
00317 #define DB_FREE_SPACE         0x00004000 /* Free space . */
00318 #define DB_COMPACT_FLAGS      \
00319       (DB_FREELIST_ONLY | DB_FREE_SPACE)
00320 
00321 /*
00322  * Flags private to DB_MPOOLFILE->open.
00323  *         Shared flags up to 0x0001000 */
00324 #define DB_DIRECT             0x0002000 /* Don't buffer the file in the OS. */
00325 #define DB_EXTENT             0x0004000 /* internal: dealing with an extent. */
00326 #define DB_ODDFILESIZE        0x0008000 /* Truncate file to N * pgsize. */
00327 
00328 /*
00329  * Flags private to DB->set_flags.
00330  *         Shared flags up to 0x00001000 */
00331 #define DB_CHKSUM             0x00002000 /* Do checksumming */
00332 #define DB_DUP                0x00004000 /* Btree, Hash: duplicate keys. */
00333 #define DB_DUPSORT            0x00008000 /* Btree, Hash: duplicate keys. */
00334 #define DB_ENCRYPT            0x00010000 /* Btree, Hash: duplicate keys. */
00335 #define DB_INORDER            0x00020000 /* Queue: strict ordering on consume */
00336 #define DB_RECNUM             0x00040000 /* Btree: record numbers. */
00337 #define DB_RENUMBER           0x00080000 /* Recno: renumber on insert/delete. */
00338 #define DB_REVSPLITOFF        0x00100000 /* Btree: turn off reverse splits. */
00339 #define DB_SNAPSHOT           0x00200000 /* Recno: snapshot the input. */
00340 
00341 /*
00342  * Flags private to the DB_ENV->stat_print, DB->stat and DB->stat_print methods.
00343  */
00344 #define DB_STAT_ALL           0x0000001 /* Print: Everything. */
00345 #define DB_STAT_CLEAR         0x0000002 /* Clear stat after returning values. */
00346 #define DB_STAT_LOCK_CONF     0x0000004 /* Print: Lock conflict matrix. */
00347 #define DB_STAT_LOCK_LOCKERS  0x0000008 /* Print: Lockers. */
00348 #define DB_STAT_LOCK_OBJECTS  0x0000010 /* Print: Lock objects. */
00349 #define DB_STAT_LOCK_PARAMS   0x0000020 /* Print: Lock parameters. */
00350 #define DB_STAT_MEMP_HASH     0x0000040 /* Print: Mpool hash buckets. */
00351 #define DB_STAT_SUBSYSTEM     0x0000080 /* Print: Subsystems too. */
00352 
00353 /*
00354  * Flags private to DB->join.
00355  */
00356 #define DB_JOIN_NOSORT        0x0000001 /* Don't try to optimize join. */
00357 
00358 /*
00359  * Flags private to DB->verify.
00360  */
00361 #define DB_AGGRESSIVE         0x0000001 /* Salvage whatever could be data.*/
00362 #define DB_NOORDERCHK         0x0000002 /* Skip sort order/hashing check. */
00363 #define DB_ORDERCHKONLY       0x0000004 /* Only perform the order check. */
00364 #define DB_PR_PAGE            0x0000008 /* Show page contents (-da). */
00365 #define DB_PR_RECOVERYTEST    0x0000010 /* Recovery test (-dr). */
00366 #define DB_PRINTABLE          0x0000020 /* Use printable format for salvage. */
00367 #define DB_SALVAGE            0x0000040 /* Salvage what looks like data. */
00368 #define DB_UNREF              0x0000080 /* Report unreferenced pages. */
00369 /*
00370  * !!!
00371  * These must not go over 0x8000, or they will collide with the flags
00372  * used by __bam_vrfy_subtree.
00373  */
00374 
00375 /*
00376  * Flags private to DB->set_rep_transport's send callback.
00377  */
00378 #define DB_REP_ANYWHERE       0x0000001 /* Message can be serviced anywhere. */
00379 #define DB_REP_NOBUFFER       0x0000002 /* Do not buffer this message. */
00380 #define DB_REP_PERMANENT      0x0000004 /* Important--app. may want to flush. */
00381 #define DB_REP_REREQUEST      0x0000008 /* This msg already been requested. */
00382 
00383 /*******************************************************
00384  * Mutexes.
00385  *******************************************************/
00386 typedef u_int32_t       db_mutex_t;
00387 
00388 /*
00389  * Flag arguments for DbEnv.mutex_alloc and for the DB_MUTEX structure.
00390  */
00391 #define DB_MUTEX_ALLOCATED      0x01    /* Mutex currently allocated. */
00392 #define DB_MUTEX_LOCKED         0x02    /* Mutex currently locked. */
00393 #define DB_MUTEX_LOGICAL_LOCK   0x04    /* Mutex backs a database lock. */
00394 #define DB_MUTEX_SELF_BLOCK     0x08    /* Must be able to block self. */
00395 #define DB_MUTEX_THREAD         0x10    /* Thread-only mutex. */
00396 
00397 struct __db_mutex_stat {
00398         /* The following fields are maintained in the region's copy. */
00399         u_int32_t st_mutex_align;       /* Mutex alignment */
00400         u_int32_t st_mutex_tas_spins;   /* Mutex test-and-set spins */
00401         u_int32_t st_mutex_cnt;         /* Mutex count */
00402         u_int32_t st_mutex_free;        /* Available mutexes */
00403         u_int32_t st_mutex_inuse;       /* Mutexes in use */
00404         u_int32_t st_mutex_inuse_max;   /* Maximum mutexes ever in use */
00405 
00406         /* The following fields are filled-in from other places. */
00407         u_int32_t st_region_wait;       /* Region lock granted after wait. */
00408         u_int32_t st_region_nowait;     /* Region lock granted without wait. */
00409         roff_t    st_regsize;           /* Region size. */
00410 };
00411 
00412 /* This is the length of the buffer passed to DB_ENV->thread_id_string() */
00413 #define DB_THREADID_STRLEN      128
00414 
00415 /*******************************************************
00416  * Locking.
00417  *******************************************************/
00418 #define DB_LOCKVERSION  1
00419 
00420 #define DB_FILE_ID_LEN          20      /* Unique file ID length. */
00421 
00422 /*
00423  * Deadlock detector modes; used in the DB_ENV structure to configure the
00424  * locking subsystem.
00425  */
00426 #define DB_LOCK_NORUN           0
00427 #define DB_LOCK_DEFAULT         1       /* Default policy. */
00428 #define DB_LOCK_EXPIRE          2       /* Only expire locks, no detection. */
00429 #define DB_LOCK_MAXLOCKS        3       /* Select locker with max locks. */
00430 #define DB_LOCK_MAXWRITE        4       /* Select locker with max writelocks. */
00431 #define DB_LOCK_MINLOCKS        5       /* Select locker with min locks. */
00432 #define DB_LOCK_MINWRITE        6       /* Select locker with min writelocks. */
00433 #define DB_LOCK_OLDEST          7       /* Select oldest locker. */
00434 #define DB_LOCK_RANDOM          8       /* Select random locker. */
00435 #define DB_LOCK_YOUNGEST        9       /* Select youngest locker. */
00436 
00437 /* Flag values for lock_vec(), lock_get(). */
00438 #define DB_LOCK_ABORT           0x001   /* Internal: Lock during abort. */
00439 #define DB_LOCK_NOWAIT          0x002   /* Don't wait on unavailable lock. */
00440 #define DB_LOCK_RECORD          0x004   /* Internal: record lock. */
00441 #define DB_LOCK_SET_TIMEOUT     0x008   /* Internal: set lock timeout. */
00442 #define DB_LOCK_SWITCH          0x010   /* Internal: switch existing lock. */
00443 #define DB_LOCK_UPGRADE         0x020   /* Internal: upgrade existing lock. */
00444 
00445 /*
00446  * Simple R/W lock modes and for multi-granularity intention locking.
00447  *
00448  * !!!
00449  * These values are NOT random, as they are used as an index into the lock
00450  * conflicts arrays, i.e., DB_LOCK_IWRITE must be == 3, and DB_LOCK_IREAD
00451  * must be == 4.
00452  */
00453 typedef enum {
00454         DB_LOCK_NG=0,                   /* Not granted. */
00455         DB_LOCK_READ=1,                 /* Shared/read. */
00456         DB_LOCK_WRITE=2,                /* Exclusive/write. */
00457         DB_LOCK_WAIT=3,                 /* Wait for event */
00458         DB_LOCK_IWRITE=4,               /* Intent exclusive/write. */
00459         DB_LOCK_IREAD=5,                /* Intent to share/read. */
00460         DB_LOCK_IWR=6,                  /* Intent to read and write. */
00461         DB_LOCK_READ_UNCOMMITTED=7,     /* Degree 1 isolation. */
00462         DB_LOCK_WWRITE=8                /* Was Written. */
00463 } db_lockmode_t;
00464 
00465 /*
00466  * Request types.
00467  */
00468 typedef enum {
00469         DB_LOCK_DUMP=0,                 /* Display held locks. */
00470         DB_LOCK_GET=1,                  /* Get the lock. */
00471         DB_LOCK_GET_TIMEOUT=2,          /* Get lock with a timeout. */
00472         DB_LOCK_INHERIT=3,              /* Pass locks to parent. */
00473         DB_LOCK_PUT=4,                  /* Release the lock. */
00474         DB_LOCK_PUT_ALL=5,              /* Release locker's locks. */
00475         DB_LOCK_PUT_OBJ=6,              /* Release locker's locks on obj. */
00476         DB_LOCK_PUT_READ=7,             /* Release locker's read locks. */
00477         DB_LOCK_TIMEOUT=8,              /* Force a txn to timeout. */
00478         DB_LOCK_TRADE=9,                /* Trade locker ids on a lock. */
00479         DB_LOCK_UPGRADE_WRITE=10        /* Upgrade writes for dirty reads. */
00480 } db_lockop_t;
00481 
00482 /*
00483  * Status of a lock.
00484  */
00485 typedef enum  {
00486         DB_LSTAT_ABORTED=1,             /* Lock belongs to an aborted txn. */
00487         DB_LSTAT_EXPIRED=2,             /* Lock has expired. */
00488         DB_LSTAT_FREE=3,                /* Lock is unallocated. */
00489         DB_LSTAT_HELD=4,                /* Lock is currently held. */
00490         DB_LSTAT_PENDING=5,             /* Lock was waiting and has been
00491                                          * promoted; waiting for the owner
00492                                          * to run and upgrade it to held. */
00493         DB_LSTAT_WAITING=6              /* Lock is on the wait queue. */
00494 }db_status_t;
00495 
00496 /* Lock statistics structure. */
00497 struct __db_lock_stat {
00498         u_int32_t st_id;                /* Last allocated locker ID. */
00499         u_int32_t st_cur_maxid;         /* Current maximum unused ID. */
00500         u_int32_t st_maxlocks;          /* Maximum number of locks in table. */
00501         u_int32_t st_maxlockers;        /* Maximum num of lockers in table. */
00502         u_int32_t st_maxobjects;        /* Maximum num of objects in table. */
00503         int       st_nmodes;            /* Number of lock modes. */
00504         u_int32_t st_nlocks;            /* Current number of locks. */
00505         u_int32_t st_maxnlocks;         /* Maximum number of locks so far. */
00506         u_int32_t st_nlockers;          /* Current number of lockers. */
00507         u_int32_t st_maxnlockers;       /* Maximum number of lockers so far. */
00508         u_int32_t st_nobjects;          /* Current number of objects. */
00509         u_int32_t st_maxnobjects;       /* Maximum number of objects so far. */
00510         u_int32_t st_nrequests;         /* Number of lock gets. */
00511         u_int32_t st_nreleases;         /* Number of lock puts. */
00512         u_int32_t st_nupgrade;          /* Number of lock upgrades. */
00513         u_int32_t st_ndowngrade;        /* Number of lock downgrades. */
00514         u_int32_t st_lock_wait;         /* Lock conflicts w/ subsequent wait */
00515         u_int32_t st_lock_nowait;       /* Lock conflicts w/o subsequent wait */
00516         u_int32_t st_ndeadlocks;        /* Number of lock deadlocks. */
00517         db_timeout_t st_locktimeout;    /* Lock timeout. */
00518         u_int32_t st_nlocktimeouts;     /* Number of lock timeouts. */
00519         db_timeout_t st_txntimeout;     /* Transaction timeout. */
00520         u_int32_t st_ntxntimeouts;      /* Number of transaction timeouts. */
00521         u_int32_t st_region_wait;       /* Region lock granted after wait. */
00522         u_int32_t st_region_nowait;     /* Region lock granted without wait. */
00523         roff_t    st_regsize;           /* Region size. */
00524 };
00525 
00526 /*
00527  * DB_LOCK_ILOCK --
00528  *      Internal DB access method lock.
00529  */
00530 struct __db_ilock {
00531         db_pgno_t pgno;                 /* Page being locked. */
00532         u_int8_t fileid[DB_FILE_ID_LEN];/* File id. */
00533 #define DB_HANDLE_LOCK  1
00534 #define DB_RECORD_LOCK  2
00535 #define DB_PAGE_LOCK    3
00536         u_int32_t type;                 /* Type of lock. */
00537 };
00538 
00539 /*
00540  * DB_LOCK --
00541  *      The structure is allocated by the caller and filled in during a
00542  *      lock_get request (or a lock_vec/DB_LOCK_GET).
00543  */
00544 struct __db_lock_u {
00545         roff_t          off;            /* Offset of the lock in the region */
00546         u_int32_t       ndx;            /* Index of the object referenced by
00547                                          * this lock; used for locking. */
00548         u_int32_t       gen;            /* Generation number of this lock. */
00549         db_lockmode_t   mode;           /* mode of this lock. */
00550 };
00551 
00552 /* Lock request structure. */
00553 struct __db_lockreq {
00554         db_lockop_t      op;            /* Operation. */
00555         db_lockmode_t    mode;          /* Requested mode. */
00556         db_timeout_t     timeout;       /* Time to expire lock. */
00557         DBT             *obj;           /* Object being locked. */
00558         DB_LOCK          lock;          /* Lock returned. */
00559 };
00560 
00561 /*******************************************************
00562  * Logging.
00563  *******************************************************/
00564 #define DB_LOGVERSION   11              /* Current log version. */
00565 #define DB_LOGOLDVER    11              /* Oldest log version supported. */
00566 #define DB_LOGMAGIC     0x040988
00567 
00568 /* Flag values for DB_ENV->log_archive(). */
00569 #define DB_ARCH_ABS     0x001           /* Absolute pathnames. */
00570 #define DB_ARCH_DATA    0x002           /* Data files. */
00571 #define DB_ARCH_LOG     0x004           /* Log files. */
00572 #define DB_ARCH_REMOVE  0x008   /* Remove log files. */
00573 
00574 /* Flag values for DB_ENV->log_put(). */
00575 #define DB_FLUSH                0x001   /* Flush data to disk (public). */
00576 #define DB_LOG_CHKPNT           0x002   /* Flush supports a checkpoint */
00577 #define DB_LOG_COMMIT           0x004   /* Flush supports a commit */
00578 #define DB_LOG_NOCOPY           0x008   /* Don't copy data */
00579 #define DB_LOG_NOT_DURABLE      0x010   /* Do not log; keep in memory */
00580 #define DB_LOG_PERM             0x020   /* Flag record with REP_PERMANENT */
00581 #define DB_LOG_RESEND           0x040   /* Resent log record */
00582 #define DB_LOG_WRNOSYNC         0x080   /* Write, don't sync log_put */
00583 
00584 /*
00585  * A DB_LSN has two parts, a fileid which identifies a specific file, and an
00586  * offset within that file.  The fileid is an unsigned 4-byte quantity that
00587  * uniquely identifies a file within the log directory -- currently a simple
00588  * counter inside the log.  The offset is also an unsigned 4-byte value.  The
00589  * log manager guarantees the offset is never more than 4 bytes by switching
00590  * to a new log file before the maximum length imposed by an unsigned 4-byte
00591  * offset is reached.
00592  */
00593 struct __db_lsn {
00594         u_int32_t       file;           /* File ID. */
00595         u_int32_t       offset;         /* File offset. */
00596 };
00597 
00598 /*
00599  * Application-specified log record types start at DB_user_BEGIN, and must not
00600  * equal or exceed DB_debug_FLAG.
00601  *
00602  * DB_debug_FLAG is the high-bit of the u_int32_t that specifies a log record
00603  * type.  If the flag is set, it's a log record that was logged for debugging
00604  * purposes only, even if it reflects a database change -- the change was part
00605  * of a non-durable transaction.
00606  */
00607 #define DB_user_BEGIN           10000
00608 #define DB_debug_FLAG           0x80000000
00609 
00610 /*
00611  * DB_LOGC --
00612  *      Log cursor.
00613  */
00614 struct __db_log_cursor {
00615         DB_ENV   *dbenv;                /* Enclosing dbenv. */
00616 
00617         DB_FH    *c_fhp;                /* File handle. */
00618         DB_LSN    c_lsn;                /* Cursor: LSN */
00619         u_int32_t c_len;                /* Cursor: record length */
00620         u_int32_t c_prev;               /* Cursor: previous record's offset */
00621 
00622         DBT       c_dbt;                /* Return DBT. */
00623 
00624 #define DB_LOGC_BUF_SIZE        (32 * 1024)
00625         u_int8_t *bp;                   /* Allocated read buffer. */
00626         u_int32_t bp_size;              /* Read buffer length in bytes. */
00627         u_int32_t bp_rlen;              /* Read buffer valid data length. */
00628         DB_LSN    bp_lsn;               /* Read buffer first byte LSN. */
00629 
00630         u_int32_t bp_maxrec;            /* Max record length in the log file. */
00631 
00632         /* DB_LOGC PUBLIC HANDLE LIST BEGIN */
00633         int (*close) __P((DB_LOGC *, u_int32_t));
00634         int (*get) __P((DB_LOGC *, DB_LSN *, DBT *, u_int32_t));
00635         /* DB_LOGC PUBLIC HANDLE LIST END */
00636 
00637 #define DB_LOG_DISK             0x01    /* Log record came from disk. */
00638 #define DB_LOG_LOCKED           0x02    /* Log region already locked */
00639 #define DB_LOG_SILENT_ERR       0x04    /* Turn-off error messages. */
00640         u_int32_t flags;
00641 };
00642 
00643 /* Log statistics structure. */
00644 struct __db_log_stat {
00645         u_int32_t st_magic;             /* Log file magic number. */
00646         u_int32_t st_version;           /* Log file version number. */
00647         int       st_mode;              /* Log file permissions mode. */
00648         u_int32_t st_lg_bsize;          /* Log buffer size. */
00649         u_int32_t st_lg_size;           /* Log file size. */
00650         u_int32_t st_record;            /* Records entered into the log. */
00651         u_int32_t st_w_bytes;           /* Bytes to log. */
00652         u_int32_t st_w_mbytes;          /* Megabytes to log. */
00653         u_int32_t st_wc_bytes;          /* Bytes to log since checkpoint. */
00654         u_int32_t st_wc_mbytes;         /* Megabytes to log since checkpoint. */
00655         u_int32_t st_wcount;            /* Total I/O writes to the log. */
00656         u_int32_t st_wcount_fill;       /* Overflow writes to the log. */
00657         u_int32_t st_rcount;            /* Total I/O reads from the log. */
00658         u_int32_t st_scount;            /* Total syncs to the log. */
00659         u_int32_t st_region_wait;       /* Region lock granted after wait. */
00660         u_int32_t st_region_nowait;     /* Region lock granted without wait. */
00661         u_int32_t st_cur_file;          /* Current log file number. */
00662         u_int32_t st_cur_offset;        /* Current log file offset. */
00663         u_int32_t st_disk_file;         /* Known on disk log file number. */
00664         u_int32_t st_disk_offset;       /* Known on disk log file offset. */
00665         roff_t    st_regsize;           /* Region size. */
00666         u_int32_t st_maxcommitperflush; /* Max number of commits in a flush. */
00667         u_int32_t st_mincommitperflush; /* Min number of commits in a flush. */
00668 };
00669 
00670 /*
00671  * We need to record the first log record of a transaction.  For user
00672  * defined logging this macro returns the place to put that information,
00673  * if it is need in rlsnp, otherwise it leaves it unchanged.  We also
00674  * need to track the last record of the transaction, this returns the
00675  * place to put that info.
00676  */
00677 #define DB_SET_TXN_LSNP(txn, blsnp, llsnp)              \
00678         ((txn)->set_txn_lsnp(txn, blsnp, llsnp))
00679 
00680 /*******************************************************
00681  * Shared buffer cache (mpool).
00682  *******************************************************/
00683 /* Flag values for DB_MPOOLFILE->get. */
00684 #define DB_MPOOL_CREATE         0x001   /* Create a page. */
00685 #define DB_MPOOL_LAST           0x002   /* Return the last page. */
00686 #define DB_MPOOL_NEW            0x004   /* Create a new page. */
00687 #define DB_MPOOL_FREE           0x008   /* Free page if present. */
00688 
00689 /* Flag values for DB_MPOOLFILE->put, DB_MPOOLFILE->set. */
00690 #define DB_MPOOL_CLEAN          0x001   /* Page is not modified. */
00691 #define DB_MPOOL_DIRTY          0x002   /* Page is modified. */
00692 #define DB_MPOOL_DISCARD        0x004   /* Don't cache the page. */
00693 
00694 /* Flags values for DB_MPOOLFILE->set_flags. */
00695 #define DB_MPOOL_NOFILE         0x001   /* Never open a backing file. */
00696 #define DB_MPOOL_UNLINK         0x002   /* Unlink the file on last close. */
00697 
00698 /* Priority values for DB_MPOOLFILE->set_priority. */
00699 typedef enum {
00700         DB_PRIORITY_VERY_LOW=1,
00701         DB_PRIORITY_LOW=2,
00702         DB_PRIORITY_DEFAULT=3,
00703         DB_PRIORITY_HIGH=4,
00704         DB_PRIORITY_VERY_HIGH=5
00705 } DB_CACHE_PRIORITY;
00706 
00707 /* Per-process DB_MPOOLFILE information. */
00708 struct __db_mpoolfile {
00709         DB_FH     *fhp;                 /* Underlying file handle. */
00710 
00711         /*
00712          * !!!
00713          * The ref, pinref and q fields are protected by the region lock.
00714          */
00715         u_int32_t  ref;                 /* Reference count. */
00716 
00717         u_int32_t pinref;               /* Pinned block reference count. */
00718 
00719         /*
00720          * !!!
00721          * Explicit representations of structures from queue.h.
00722          * TAILQ_ENTRY(__db_mpoolfile) q;
00723          */
00724         struct {
00725                 struct __db_mpoolfile *tqe_next;
00726                 struct __db_mpoolfile **tqe_prev;
00727         } q;                            /* Linked list of DB_MPOOLFILE's. */
00728 
00729         /*
00730          * !!!
00731          * The rest of the fields (with the exception of the MP_FLUSH flag)
00732          * are not thread-protected, even when they may be modified at any
00733          * time by the application.  The reason is the DB_MPOOLFILE handle
00734          * is single-threaded from the viewpoint of the application, and so
00735          * the only fields needing to be thread-protected are those accessed
00736          * by checkpoint or sync threads when using DB_MPOOLFILE structures
00737          * to flush buffers from the cache.
00738          */
00739         DB_ENV         *dbenv;          /* Overlying DB_ENV. */
00740         MPOOLFILE      *mfp;            /* Underlying MPOOLFILE. */
00741 
00742         u_int32_t       clear_len;      /* Cleared length on created pages. */
00743         u_int8_t                        /* Unique file ID. */
00744                         fileid[DB_FILE_ID_LEN];
00745         int             ftype;          /* File type. */
00746         int32_t         lsn_offset;     /* LSN offset in page. */
00747         u_int32_t       gbytes, bytes;  /* Maximum file size. */
00748         DBT            *pgcookie;       /* Byte-string passed to pgin/pgout. */
00749         int32_t         priority;       /* Cache priority. */
00750 
00751         void           *addr;           /* Address of mmap'd region. */
00752         size_t          len;            /* Length of mmap'd region. */
00753 
00754         u_int32_t       config_flags;   /* Flags to DB_MPOOLFILE->set_flags. */
00755 
00756         /* DB_MPOOLFILE PUBLIC HANDLE LIST BEGIN */
00757         int (*close) __P((DB_MPOOLFILE *, u_int32_t));
00758         int (*get) __P((DB_MPOOLFILE *, db_pgno_t *, u_int32_t, void *));
00759         int (*open) __P((DB_MPOOLFILE *, const char *, u_int32_t, int, size_t));
00760         int (*put) __P((DB_MPOOLFILE *, void *, u_int32_t));
00761         int (*set) __P((DB_MPOOLFILE *, void *, u_int32_t));
00762         int (*get_clear_len) __P((DB_MPOOLFILE *, u_int32_t *));
00763         int (*set_clear_len) __P((DB_MPOOLFILE *, u_int32_t));
00764         int (*get_fileid) __P((DB_MPOOLFILE *, u_int8_t *));
00765         int (*set_fileid) __P((DB_MPOOLFILE *, u_int8_t *));
00766         int (*get_flags) __P((DB_MPOOLFILE *, u_int32_t *));
00767         int (*set_flags) __P((DB_MPOOLFILE *, u_int32_t, int));
00768         int (*get_ftype) __P((DB_MPOOLFILE *, int *));
00769         int (*set_ftype) __P((DB_MPOOLFILE *, int));
00770         int (*get_lsn_offset) __P((DB_MPOOLFILE *, int32_t *));
00771         int (*set_lsn_offset) __P((DB_MPOOLFILE *, int32_t));
00772         int (*get_maxsize) __P((DB_MPOOLFILE *, u_int32_t *, u_int32_t *));
00773         int (*set_maxsize) __P((DB_MPOOLFILE *, u_int32_t, u_int32_t));
00774         int (*get_pgcookie) __P((DB_MPOOLFILE *, DBT *));
00775         int (*set_pgcookie) __P((DB_MPOOLFILE *, DBT *));
00776         int (*get_priority) __P((DB_MPOOLFILE *, DB_CACHE_PRIORITY *));
00777         int (*set_priority) __P((DB_MPOOLFILE *, DB_CACHE_PRIORITY));
00778         int (*sync) __P((DB_MPOOLFILE *));
00779         /* DB_MPOOLFILE PUBLIC HANDLE LIST END */
00780 
00781         /*
00782          * MP_FILEID_SET, MP_OPEN_CALLED and MP_READONLY do not need to be
00783          * thread protected because they are initialized before the file is
00784          * linked onto the per-process lists, and never modified.
00785          *
00786          * MP_FLUSH is thread protected because it is potentially read/set by
00787          * multiple threads of control.
00788          */
00789 #define MP_FILEID_SET   0x001           /* Application supplied a file ID. */
00790 #define MP_FLUSH        0x002           /* Was opened to flush a buffer. */
00791 #define MP_OPEN_CALLED  0x004           /* File opened. */
00792 #define MP_READONLY     0x008           /* File is readonly. */
00793         u_int32_t  flags;
00794 };
00795 
00796 /* Mpool statistics structure. */
00797 struct __db_mpool_stat {
00798         u_int32_t st_gbytes;            /* Total cache size: GB. */
00799         u_int32_t st_bytes;             /* Total cache size: B. */
00800         u_int32_t st_ncache;            /* Number of caches. */
00801         roff_t    st_regsize;           /* Region size. */
00802         size_t    st_mmapsize;          /* Maximum file size for mmap. */
00803         int       st_maxopenfd;         /* Maximum number of open fd's. */
00804         int       st_maxwrite;          /* Maximum buffers to write. */
00805         int       st_maxwrite_sleep;    /* Sleep after writing max buffers. */
00806         u_int32_t st_map;               /* Pages from mapped files. */
00807         u_int32_t st_cache_hit;         /* Pages found in the cache. */
00808         u_int32_t st_cache_miss;        /* Pages not found in the cache. */
00809         u_int32_t st_page_create;       /* Pages created in the cache. */
00810         u_int32_t st_page_in;           /* Pages read in. */
00811         u_int32_t st_page_out;          /* Pages written out. */
00812         u_int32_t st_ro_evict;          /* Clean pages forced from the cache. */
00813         u_int32_t st_rw_evict;          /* Dirty pages forced from the cache. */
00814         u_int32_t st_page_trickle;      /* Pages written by memp_trickle. */
00815         u_int32_t st_pages;             /* Total number of pages. */
00816         u_int32_t st_page_clean;        /* Clean pages. */
00817         u_int32_t st_page_dirty;        /* Dirty pages. */
00818         u_int32_t st_hash_buckets;      /* Number of hash buckets. */
00819         u_int32_t st_hash_searches;     /* Total hash chain searches. */
00820         u_int32_t st_hash_longest;      /* Longest hash chain searched. */
00821         u_int32_t st_hash_examined;     /* Total hash entries searched. */
00822         u_int32_t st_hash_nowait;       /* Hash lock granted with nowait. */
00823         u_int32_t st_hash_wait;         /* Hash lock granted after wait. */
00824         u_int32_t st_hash_max_wait;     /* Max hash lock granted after wait. */
00825         u_int32_t st_region_nowait;     /* Region lock granted with nowait. */
00826         u_int32_t st_region_wait;       /* Region lock granted after wait. */
00827         u_int32_t st_alloc;             /* Number of page allocations. */
00828         u_int32_t st_alloc_buckets;     /* Buckets checked during allocation. */
00829         u_int32_t st_alloc_max_buckets; /* Max checked during allocation. */
00830         u_int32_t st_alloc_pages;       /* Pages checked during allocation. */
00831         u_int32_t st_alloc_max_pages;   /* Max checked during allocation. */
00832 };
00833 
00834 /* Mpool file statistics structure. */
00835 struct __db_mpool_fstat {
00836         char *file_name;                /* File name. */
00837         u_int32_t st_pagesize;          /* Page size. */
00838         u_int32_t st_map;               /* Pages from mapped files. */
00839         u_int32_t st_cache_hit;         /* Pages found in the cache. */
00840         u_int32_t st_cache_miss;        /* Pages not found in the cache. */
00841         u_int32_t st_page_create;       /* Pages created in the cache. */
00842         u_int32_t st_page_in;           /* Pages read in. */
00843         u_int32_t st_page_out;          /* Pages written out. */
00844 };
00845 
00846 /*******************************************************
00847  * Transactions and recovery.
00848  *******************************************************/
00849 #define DB_TXNVERSION   1
00850 
00851 typedef enum {
00852         DB_TXN_ABORT=0,                 /* Public. */
00853         DB_TXN_APPLY=1,                 /* Public. */
00854         DB_TXN_BACKWARD_ALLOC=2,        /* Internal. */
00855         DB_TXN_BACKWARD_ROLL=3,         /* Public. */
00856         DB_TXN_FORWARD_ROLL=4,          /* Public. */
00857         DB_TXN_OPENFILES=5,             /* Internal. */
00858         DB_TXN_POPENFILES=6,            /* Internal. */
00859         DB_TXN_PRINT=7                  /* Public. */
00860 } db_recops;
00861 
00862 /*
00863  * BACKWARD_ALLOC is used during the forward pass to pick up any aborted
00864  * allocations for files that were created during the forward pass.
00865  * The main difference between _ALLOC and _ROLL is that the entry for
00866  * the file not exist during the rollforward pass.
00867  */
00868 #define DB_UNDO(op)     ((op) == DB_TXN_ABORT ||                        \
00869                 (op) == DB_TXN_BACKWARD_ROLL || (op) == DB_TXN_BACKWARD_ALLOC)
00870 #define DB_REDO(op)     ((op) == DB_TXN_FORWARD_ROLL || (op) == DB_TXN_APPLY)
00871 
00872 struct __db_txn {
00873         DB_TXNMGR       *mgrp;          /* Pointer to transaction manager. */
00874         DB_TXN          *parent;        /* Pointer to transaction's parent. */
00875 
00876         u_int32_t       txnid;          /* Unique transaction id. */
00877         char            *name;          /* Transaction name */
00878 
00879         db_threadid_t   tid;            /* Thread id for use in MT XA. */
00880         void            *td;            /* Detail structure within region. */
00881         db_timeout_t    lock_timeout;   /* Timeout for locks for this txn. */
00882         db_timeout_t    expire;         /* Time transaction expires. */
00883         void            *txn_list;      /* Undo information for parent. */
00884 
00885         /*
00886          * !!!
00887          * Explicit representations of structures from queue.h.
00888          * TAILQ_ENTRY(__db_txn) links;
00889          * TAILQ_ENTRY(__db_txn) xalinks;
00890          */
00891         struct {
00892                 struct __db_txn *tqe_next;
00893                 struct __db_txn **tqe_prev;
00894         } links;                        /* Links transactions off manager. */
00895         struct {
00896                 struct __db_txn *tqe_next;
00897                 struct __db_txn **tqe_prev;
00898         } xalinks;                      /* Links active XA transactions. */
00899 
00900         /*
00901          * !!!
00902          * Explicit representations of structures from queue.h.
00903          * TAILQ_HEAD(__kids, __db_txn) kids;
00904          */
00905         struct __kids {
00906                 struct __db_txn *tqh_first;
00907                 struct __db_txn **tqh_last;
00908         } kids;
00909 
00910         /*
00911          * !!!
00912          * Explicit representations of structures from queue.h.
00913          * TAILQ_HEAD(__events, __txn_event) events;
00914          */
00915         struct {
00916                 struct __txn_event *tqh_first;
00917                 struct __txn_event **tqh_last;
00918         } events;
00919 
00920         /*
00921          * !!!
00922          * Explicit representations of structures from queue.h.
00923          * STAILQ_HEAD(__logrec, __txn_logrec) logs;
00924          */
00925         struct {
00926                 struct __txn_logrec *stqh_first;
00927                 struct __txn_logrec **stqh_last;
00928         } logs;                         /* Links deferred events. */
00929 
00930         /*
00931          * !!!
00932          * Explicit representations of structures from queue.h.
00933          * TAILQ_ENTRY(__db_txn) klinks;
00934          */
00935         struct {
00936                 struct __db_txn *tqe_next;
00937                 struct __db_txn **tqe_prev;
00938         } klinks;
00939 
00940         void    *api_internal;          /* C++ API private. */
00941         void    *xml_internal;          /* XML API private. */
00942 
00943         u_int32_t       cursors;        /* Number of cursors open for txn */
00944 
00945         /* DB_TXN PUBLIC HANDLE LIST BEGIN */
00946         int       (*abort) __P((DB_TXN *));
00947         int       (*commit) __P((DB_TXN *, u_int32_t));
00948         int       (*discard) __P((DB_TXN *, u_int32_t));
00949         int       (*get_name) __P((DB_TXN *, const char **));
00950         u_int32_t (*id) __P((DB_TXN *));
00951         int       (*prepare) __P((DB_TXN *, u_int8_t *));
00952         int       (*set_name) __P((DB_TXN *, const char *));
00953         int       (*set_timeout) __P((DB_TXN *, db_timeout_t, u_int32_t));
00954         /* DB_TXN PUBLIC HANDLE LIST END */
00955 
00956         /* DB_TXN PRIVATE HANDLE LIST BEGIN */
00957         void      (*set_txn_lsnp) __P((DB_TXN *txn, DB_LSN **, DB_LSN **));
00958         /* DB_TXN PRIVATE HANDLE LIST END */
00959 
00960 #define TXN_CHILDCOMMIT         0x001   /* Txn has committed. */
00961 #define TXN_COMPENSATE          0x002   /* Compensating transaction. */
00962 #define TXN_DEADLOCK            0x004   /* Txn has deadlocked. */
00963 #define TXN_LOCKTIMEOUT         0x008   /* Txn has a lock timeout. */
00964 #define TXN_MALLOC              0x010   /* Structure allocated by TXN system. */
00965 #define TXN_NOSYNC              0x020   /* Do not sync on prepare and commit. */
00966 #define TXN_NOWAIT              0x040   /* Do not wait on locks. */
00967 #define TXN_READ_COMMITTED      0x080   /* Txn has degree 2 isolation. */
00968 #define TXN_READ_UNCOMMITTED    0x100   /* Txn has degree 1 isolation. */
00969 #define TXN_RESTORED            0x200   /* Txn has been restored. */
00970 #define TXN_SYNC                0x400   /* Write and sync on prepare/commit. */
00971 #define TXN_WRITE_NOSYNC        0x800   /* Write only on prepare/commit. */
00972         u_int32_t       flags;
00973 };
00974 
00975 #define TXN_SYNC_FLAGS (TXN_SYNC | TXN_NOSYNC | TXN_WRITE_NOSYNC)
00976 
00977 /*
00978  * Structure used for two phase commit interface.  Berkeley DB support for two
00979  * phase commit is compatible with the X/Open XA interface.
00980  *
00981  * The XA #define XIDDATASIZE defines the size of a global transaction ID.  We
00982  * have our own version here (for name space reasons) which must have the same
00983  * value.
00984  */
00985 #define DB_XIDDATASIZE  128
00986 struct __db_preplist {
00987         DB_TXN  *txn;
00988         u_int8_t gid[DB_XIDDATASIZE];
00989 };
00990 
00991 /* Transaction statistics structure. */
00992 struct __db_txn_active {
00993         u_int32_t txnid;                /* Transaction ID */
00994         u_int32_t parentid;             /* Transaction ID of parent */
00995         pid_t     pid;                  /* Process owning txn ID */
00996         db_threadid_t tid;              /* Thread owning txn ID */
00997         DB_LSN    lsn;                  /* LSN when transaction began */
00998         u_int32_t xa_status;            /* XA status */
00999         u_int8_t  xid[DB_XIDDATASIZE];  /* XA global transaction ID */
01000         char      name[51];             /* 50 bytes of name, nul termination */
01001 };
01002 
01003 struct __db_txn_stat {
01004         DB_LSN    st_last_ckp;          /* lsn of the last checkpoint */
01005         time_t    st_time_ckp;          /* time of last checkpoint */
01006         u_int32_t st_last_txnid;        /* last transaction id given out */
01007         u_int32_t st_maxtxns;           /* maximum txns possible */
01008         u_int32_t st_naborts;           /* number of aborted transactions */
01009         u_int32_t st_nbegins;           /* number of begun transactions */
01010         u_int32_t st_ncommits;          /* number of committed transactions */
01011         u_int32_t st_nactive;           /* number of active transactions */
01012         u_int32_t st_nrestores;         /* number of restored transactions
01013                                            after recovery. */
01014         u_int32_t st_maxnactive;        /* maximum active transactions */
01015         DB_TXN_ACTIVE *st_txnarray;     /* array of active transactions */
01016         u_int32_t st_region_wait;       /* Region lock granted after wait. */
01017         u_int32_t st_region_nowait;     /* Region lock granted without wait. */
01018         roff_t    st_regsize;           /* Region size. */
01019 };
01020 
01021 /*******************************************************
01022  * Replication.
01023  *******************************************************/
01024 /* Special, out-of-band environment IDs. */
01025 #define DB_EID_BROADCAST        -1
01026 #define DB_EID_INVALID          -2
01027 
01028 /* rep_config flag values. */
01029 #define DB_REP_CONF_BULK        0x0001  /* Bulk transfer. */
01030 #define DB_REP_CONF_DELAYCLIENT 0x0002  /* Delay client synchronization. */
01031 #define DB_REP_CONF_NOAUTOINIT  0x0004  /* No automatic client init. */
01032 #define DB_REP_CONF_NOWAIT      0x0008  /* Don't wait, return error. */
01033 
01034 /* rep_start flags values. */
01035 #define DB_REP_CLIENT           0x001
01036 #define DB_REP_MASTER           0x002
01037 
01038 /* Replication statistics. */
01039 struct __db_rep_stat {
01040         /* !!!
01041          * Many replication statistics fields cannot be protected by a mutex
01042          * without an unacceptable performance penalty, since most message
01043          * processing is done without the need to hold a region-wide lock.
01044          * Fields whose comments end with a '+' may be updated without holding
01045          * the replication or log mutexes (as appropriate), and thus may be
01046          * off somewhat (or, on unreasonable architectures under unlucky
01047          * circumstances, garbaged).
01048          */
01049         u_int32_t st_status;            /* Current replication status. */
01050         DB_LSN st_next_lsn;             /* Next LSN to use or expect. */
01051         DB_LSN st_waiting_lsn;          /* LSN we're awaiting, if any. */
01052         db_pgno_t st_next_pg;           /* Next pg we expect. */
01053         db_pgno_t st_waiting_pg;        /* pg we're awaiting, if any. */
01054 
01055         u_int32_t st_dupmasters;        /* # of times a duplicate master
01056                                            condition was detected.+ */
01057         int st_env_id;                  /* Current environment ID. */
01058         int st_env_priority;            /* Current environment priority. */
01059         u_int32_t st_bulk_fills;        /* Bulk buffer fills. */
01060         u_int32_t st_bulk_overflows;    /* Bulk buffer overflows. */
01061         u_int32_t st_bulk_records;      /* Bulk records stored. */
01062         u_int32_t st_bulk_transfers;    /* Transfers of bulk buffers. */
01063         u_int32_t st_client_rerequests; /* Number of forced rerequests. */
01064         u_int32_t st_client_svc_req;    /* Number of client service requests
01065                                            received by this client. */
01066         u_int32_t st_client_svc_miss;   /* Number of client service requests
01067                                            missing on this client. */
01068         u_int32_t st_gen;               /* Current generation number. */
01069         u_int32_t st_egen;              /* Current election gen number. */
01070         u_int32_t st_log_duplicated;    /* Log records received multiply.+ */
01071         u_int32_t st_log_queued;        /* Log records currently queued.+ */
01072         u_int32_t st_log_queued_max;    /* Max. log records queued at once.+ */
01073         u_int32_t st_log_queued_total;  /* Total # of log recs. ever queued.+ */
01074         u_int32_t st_log_records;       /* Log records received and put.+ */
01075         u_int32_t st_log_requested;     /* Log recs. missed and requested.+ */
01076         int st_master;                  /* Env. ID of the current master. */
01077         u_int32_t st_master_changes;    /* # of times we've switched masters. */
01078         u_int32_t st_msgs_badgen;       /* Messages with a bad generation #.+ */
01079         u_int32_t st_msgs_processed;    /* Messages received and processed.+ */
01080         u_int32_t st_msgs_recover;      /* Messages ignored because this site
01081                                            was a client in recovery.+ */
01082         u_int32_t st_msgs_send_failures;/* # of failed message sends.+ */
01083         u_int32_t st_msgs_sent;         /* # of successful message sends.+ */
01084         u_int32_t st_newsites;          /* # of NEWSITE msgs. received.+ */
01085         int st_nsites;                  /* Current number of sites we will
01086                                            assume during elections. */
01087         u_int32_t st_nthrottles;        /* # of times we were throttled. */
01088         u_int32_t st_outdated;          /* # of times we detected and returned
01089                                            an OUTDATED condition.+ */
01090         u_int32_t st_pg_duplicated;     /* Pages received multiply.+ */
01091         u_int32_t st_pg_records;        /* Pages received and stored.+ */
01092         u_int32_t st_pg_requested;      /* Pages missed and requested.+ */
01093         u_int32_t st_startup_complete;  /* Site completed client sync-up. */
01094         u_int32_t st_txns_applied;      /* # of transactions applied.+ */
01095 
01096         /* Elections generally. */
01097         u_int32_t st_elections;         /* # of elections held.+ */
01098         u_int32_t st_elections_won;     /* # of elections won by this site.+ */
01099 
01100         /* Statistics about an in-progress election. */
01101         int st_election_cur_winner;     /* Current front-runner. */
01102         u_int32_t st_election_gen;      /* Election generation number. */
01103         DB_LSN st_election_lsn;         /* Max. LSN of current winner. */
01104         int st_election_nsites;         /* # of "registered voters". */
01105         int st_election_nvotes;         /* # of "registered voters" needed. */
01106         int st_election_priority;       /* Current election priority. */
01107         int st_election_status;         /* Current election status. */
01108         u_int32_t st_election_tiebreaker;/* Election tiebreaker value. */
01109         int st_election_votes;          /* Votes received in this round. */
01110         u_int32_t st_election_sec;      /* Last election time seconds. */
01111         u_int32_t st_election_usec;     /* Last election time useconds. */
01112 };
01113 
01114 /*******************************************************
01115  * Sequences.
01116  *******************************************************/
01117 /*
01118  * The storage record for a sequence.
01119  */
01120 struct __db_seq_record {
01121         u_int32_t       seq_version;    /* Version size/number. */
01122 #define DB_SEQ_DEC              0x00000001      /* Decrement sequence. */
01123 #define DB_SEQ_INC              0x00000002      /* Increment sequence. */
01124 #define DB_SEQ_RANGE_SET        0x00000004      /* Range set (internal). */
01125 #define DB_SEQ_WRAP             0x00000008      /* Wrap sequence at min/max. */
01126 #define DB_SEQ_WRAPPED          0x00000010      /* Just wrapped (internal). */
01127         u_int32_t       flags;          /* Flags. */
01128         db_seq_t        seq_value;      /* Current value. */
01129         db_seq_t        seq_max;        /* Max permitted. */
01130         db_seq_t        seq_min;        /* Min permitted. */
01131 };
01132 
01133 /*
01134  * Handle for a sequence object.
01135  */
01136 struct __db_sequence {
01137         DB              *seq_dbp;       /* DB handle for this sequence. */
01138         db_mutex_t      mtx_seq;        /* Mutex if sequence is threaded. */
01139         DB_SEQ_RECORD   *seq_rp;        /* Pointer to current data. */
01140         DB_SEQ_RECORD   seq_record;     /* Data from DB_SEQUENCE. */
01141         int32_t         seq_cache_size; /* Number of values cached. */
01142         db_seq_t        seq_last_value; /* Last value cached. */
01143         DBT             seq_key;        /* DBT pointing to sequence key. */
01144         DBT             seq_data;       /* DBT pointing to seq_record. */
01145 
01146         /* API-private structure: used by C++ and Java. */
01147         void            *api_internal;
01148 
01149         /* DB_SEQUENCE PUBLIC HANDLE LIST BEGIN */
01150         int             (*close) __P((DB_SEQUENCE *, u_int32_t));
01151         int             (*get) __P((DB_SEQUENCE *,
01152                               DB_TXN *, int32_t, db_seq_t *, u_int32_t));
01153         int             (*get_cachesize) __P((DB_SEQUENCE *, int32_t *));
01154         int             (*get_db) __P((DB_SEQUENCE *, DB **));
01155         int             (*get_flags) __P((DB_SEQUENCE *, u_int32_t *));
01156         int             (*get_key) __P((DB_SEQUENCE *, DBT *));
01157         int             (*get_range) __P((DB_SEQUENCE *,
01158                              db_seq_t *, db_seq_t *));
01159         int             (*initial_value) __P((DB_SEQUENCE *, db_seq_t));
01160         int             (*open) __P((DB_SEQUENCE *,
01161                             DB_TXN *, DBT *, u_int32_t));
01162         int             (*remove) __P((DB_SEQUENCE *, DB_TXN *, u_int32_t));
01163         int             (*set_cachesize) __P((DB_SEQUENCE *, int32_t));
01164         int             (*set_flags) __P((DB_SEQUENCE *, u_int32_t));
01165         int             (*set_range) __P((DB_SEQUENCE *, db_seq_t, db_seq_t));
01166         int             (*stat) __P((DB_SEQUENCE *,
01167                             DB_SEQUENCE_STAT **, u_int32_t));
01168         int             (*stat_print) __P((DB_SEQUENCE *, u_int32_t));
01169         /* DB_SEQUENCE PUBLIC HANDLE LIST END */
01170 };
01171 
01172 struct __db_seq_stat {
01173         u_int32_t st_wait;              /* Sequence lock granted w/o wait. */
01174         u_int32_t st_nowait;            /* Sequence lock granted after wait. */
01175         db_seq_t  st_current;           /* Current value in db. */
01176         db_seq_t  st_value;             /* Current cached value. */
01177         db_seq_t  st_last_value;        /* Last cached value. */
01178         db_seq_t  st_min;               /* Minimum value. */
01179         db_seq_t  st_max;               /* Maximum value. */
01180         int32_t   st_cache_size;        /* Cache size. */
01181         u_int32_t st_flags;             /* Flag value. */
01182 };
01183 
01184 /*******************************************************
01185  * Access methods.
01186  *******************************************************/
01187 typedef enum {
01188         DB_BTREE=1,
01189         DB_HASH=2,
01190         DB_RECNO=3,
01191         DB_QUEUE=4,
01192         DB_UNKNOWN=5                    /* Figure it out on open. */
01193 } DBTYPE;
01194 
01195 #define DB_RENAMEMAGIC  0x030800        /* File has been renamed. */
01196 
01197 #define DB_BTREEVERSION 9               /* Current btree version. */
01198 #define DB_BTREEOLDVER  8               /* Oldest btree version supported. */
01199 #define DB_BTREEMAGIC   0x053162
01200 
01201 #define DB_HASHVERSION  8               /* Current hash version. */
01202 #define DB_HASHOLDVER   7               /* Oldest hash version supported. */
01203 #define DB_HASHMAGIC    0x061561
01204 
01205 #define DB_QAMVERSION   4               /* Current queue version. */
01206 #define DB_QAMOLDVER    3               /* Oldest queue version supported. */
01207 #define DB_QAMMAGIC     0x042253
01208 
01209 #define DB_SEQUENCE_VERSION 2           /* Current sequence version. */
01210 #define DB_SEQUENCE_OLDVER  1           /* Oldest sequence version supported. */
01211 
01212 /*
01213  * DB access method and cursor operation values.  Each value is an operation
01214  * code to which additional bit flags are added.
01215  */
01216 #define DB_AFTER                 1      /* c_put() */
01217 #define DB_APPEND                2      /* put() */
01218 #define DB_BEFORE                3      /* c_put() */
01219 #define DB_CACHED_COUNTS         4      /* stat() */
01220 #define DB_CONSUME               5      /* get() */
01221 #define DB_CONSUME_WAIT          6      /* get() */
01222 #define DB_CURRENT               7      /* c_get(), c_put(), DB_LOGC->get() */
01223 #define DB_FAST_STAT             8      /* stat() */
01224 #define DB_FIRST                 9      /* c_get(), DB_LOGC->get() */
01225 #define DB_GET_BOTH             10      /* get(), c_get() */
01226 #define DB_GET_BOTHC            11      /* c_get() (internal) */
01227 #define DB_GET_BOTH_RANGE       12      /* get(), c_get() */
01228 #define DB_GET_RECNO            13      /* c_get() */
01229 #define DB_JOIN_ITEM            14      /* c_get(); do not do primary lookup */
01230 #define DB_KEYFIRST             15      /* c_put() */
01231 #define DB_KEYLAST              16      /* c_put() */
01232 #define DB_LAST                 17      /* c_get(), DB_LOGC->get() */
01233 #define DB_NEXT                 18      /* c_get(), DB_LOGC->get() */
01234 #define DB_NEXT_DUP             19      /* c_get() */
01235 #define DB_NEXT_NODUP           20      /* c_get() */
01236 #define DB_NODUPDATA            21      /* put(), c_put() */
01237 #define DB_NOOVERWRITE          22      /* put() */
01238 #define DB_NOSYNC               23      /* close() */
01239 #define DB_POSITION             24      /* c_dup() */
01240 #define DB_PREV                 25      /* c_get(), DB_LOGC->get() */
01241 #define DB_PREV_NODUP           26      /* c_get(), DB_LOGC->get() */
01242 #define DB_RECORDCOUNT          27      /* stat() */
01243 #define DB_SET                  28      /* c_get(), DB_LOGC->get() */
01244 #define DB_SET_LOCK_TIMEOUT     29      /* set_timout() */
01245 #define DB_SET_RANGE            30      /* c_get() */
01246 #define DB_SET_RECNO            31      /* get(), c_get() */
01247 #define DB_SET_TXN_NOW          32      /* set_timout() (internal) */
01248 #define DB_SET_TXN_TIMEOUT      33      /* set_timout() */
01249 #define DB_UPDATE_SECONDARY     34      /* c_get(), c_del() (internal) */
01250 #define DB_WRITECURSOR          35      /* cursor() */
01251 #define DB_WRITELOCK            36      /* cursor() (internal) */
01252 
01253 /* This has to change when the max opcode hits 255. */
01254 #define DB_OPFLAGS_MASK 0x000000ff      /* Mask for operations flags. */
01255 
01256 /*
01257  * Masks for flags that can be OR'd into DB access method and cursor
01258  * operation values.  Three top bits have already been taken:
01259  *
01260  * DB_AUTO_COMMIT       0x01000000
01261  * DB_READ_COMMITTED    0x02000000
01262  * DB_READ_UNCOMMITTED  0x04000000
01263  */
01264 #define DB_MULTIPLE     0x08000000      /* Return multiple data values. */
01265 #define DB_MULTIPLE_KEY 0x10000000      /* Return multiple data/key pairs. */
01266 #define DB_RMW          0x20000000      /* Acquire write lock immediately. */
01267 
01268 /*
01269  * DB (user visible) error return codes.
01270  *
01271  * !!!
01272  * For source compatibility with DB 2.X deadlock return (EAGAIN), use the
01273  * following:
01274  *      #include <errno.h>
01275  *      #define DB_LOCK_DEADLOCK EAGAIN
01276  *
01277  * !!!
01278  * We don't want our error returns to conflict with other packages where
01279  * possible, so pick a base error value that's hopefully not common.  We
01280  * document that we own the error name space from -30,800 to -30,999.
01281  */
01282 /* DB (public) error return codes. */
01283 #define DB_BUFFER_SMALL         (-30999)/* User memory too small for return. */
01284 #define DB_DONOTINDEX           (-30998)/* "Null" return from 2ndary callbk. */
01285 #define DB_KEYEMPTY             (-30997)/* Key/data deleted or never created. */
01286 #define DB_KEYEXIST             (-30996)/* The key/data pair already exists. */
01287 #define DB_LOCK_DEADLOCK        (-30995)/* Deadlock. */
01288 #define DB_LOCK_NOTGRANTED      (-30994)/* Lock unavailable. */
01289 #define DB_LOG_BUFFER_FULL      (-30993)/* In-memory log buffer full. */
01290 #define DB_NOSERVER             (-30992)/* Server panic return. */
01291 #define DB_NOSERVER_HOME        (-30991)/* Bad home sent to server. */
01292 #define DB_NOSERVER_ID          (-30990)/* Bad ID sent to server. */
01293 #define DB_NOTFOUND             (-30989)/* Key/data pair not found (EOF). */
01294 #define DB_OLD_VERSION          (-30988)/* Out-of-date version. */
01295 #define DB_PAGE_NOTFOUND        (-30987)/* Requested page not found. */
01296 #define DB_REP_DUPMASTER        (-30986)/* There are two masters. */
01297 #define DB_REP_HANDLE_DEAD      (-30985)/* Rolled back a commit. */
01298 #define DB_REP_HOLDELECTION     (-30984)/* Time to hold an election. */
01299 #define DB_REP_IGNORE           (-30983)/* This msg should be ignored.*/
01300 #define DB_REP_ISPERM           (-30982)/* Cached not written perm written.*/
01301 #define DB_REP_JOIN_FAILURE     (-30981)/* Unable to join replication group. */
01302 #define DB_REP_LOCKOUT          (-30980)/* API/Replication lockout now. */
01303 #define DB_REP_NEWMASTER        (-30979)/* We have learned of a new master. */
01304 #define DB_REP_NEWSITE          (-30978)/* New site entered system. */
01305 #define DB_REP_NOTPERM          (-30977)/* Permanent log record not written. */
01306 #define DB_REP_STARTUPDONE      (-30976)/* Client startup complete. */
01307 #define DB_REP_UNAVAIL          (-30975)/* Site cannot currently be reached. */
01308 #define DB_RUNRECOVERY          (-30974)/* Panic return. */
01309 #define DB_SECONDARY_BAD        (-30973)/* Secondary index corrupt. */
01310 #define DB_VERIFY_BAD           (-30972)/* Verify failed; bad format. */
01311 #define DB_VERSION_MISMATCH     (-30971)/* Environment version mismatch. */
01312 
01313 /* DB (private) error return codes. */
01314 #define DB_ALREADY_ABORTED      (-30899)
01315 #define DB_DELETED              (-30898)/* Recovery file marked deleted. */
01316 #define DB_NEEDSPLIT            (-30897)/* Page needs to be split. */
01317 #define DB_REP_BULKOVF          (-30896)/* Rep bulk buffer overflow. */
01318 #define DB_REP_EGENCHG          (-30895)/* Egen changed while in election. */
01319 #define DB_REP_LOGREADY         (-30894)/* Rep log ready for recovery. */
01320 #define DB_REP_PAGEDONE         (-30893)/* This page was already done. */
01321 #define DB_SURPRISE_KID         (-30892)/* Child commit where parent
01322                                            didn't know it was a parent. */
01323 #define DB_SWAPBYTES            (-30891)/* Database needs byte swapping. */
01324 #define DB_TIMEOUT              (-30890)/* Timed out waiting for election. */
01325 #define DB_TXN_CKP              (-30889)/* Encountered ckp record in log. */
01326 #define DB_VERIFY_FATAL         (-30888)/* DB->verify cannot proceed. */
01327 
01328 /* Database handle. */
01329 struct __db {
01330         /*******************************************************
01331          * Public: owned by the application.
01332          *******************************************************/
01333         u_int32_t pgsize;               /* Database logical page size. */
01334 
01335                                         /* Callbacks. */
01336         int (*db_append_recno) __P((DB *, DBT *, db_recno_t));
01337         void (*db_feedback) __P((DB *, int, int));
01338         int (*dup_compare) __P((DB *, const DBT *, const DBT *));
01339 
01340         void    *app_private;           /* Application-private handle. */
01341 
01342         /*******************************************************
01343          * Private: owned by DB.
01344          *******************************************************/
01345         DB_ENV  *dbenv;                 /* Backing environment. */
01346 
01347         DBTYPE   type;                  /* DB access method type. */
01348 
01349         DB_MPOOLFILE *mpf;              /* Backing buffer pool. */
01350 
01351         db_mutex_t mutex;               /* Synchronization for free threading */
01352 
01353         char *fname, *dname;            /* File/database passed to DB->open. */
01354         u_int32_t open_flags;           /* Flags passed to DB->open. */
01355 
01356         u_int8_t fileid[DB_FILE_ID_LEN];/* File's unique ID for locking. */
01357 
01358         u_int32_t adj_fileid;           /* File's unique ID for curs. adj. */
01359 
01360 #define DB_LOGFILEID_INVALID    -1
01361         FNAME *log_filename;            /* File's naming info for logging. */
01362 
01363         db_pgno_t meta_pgno;            /* Meta page number */
01364         u_int32_t lid;                  /* Locker id for handle locking. */
01365         u_int32_t cur_lid;              /* Current handle lock holder. */
01366         u_int32_t associate_lid;        /* Locker id for DB->associate call. */
01367         DB_LOCK  handle_lock;           /* Lock held on this handle. */
01368 
01369         u_int    cl_id;                 /* RPC: remote client id. */
01370 
01371         time_t   timestamp;             /* Handle timestamp for replication. */
01372         u_int32_t fid_gen;              /* Rep generation number for fids. */
01373 
01374         /*
01375          * Returned data memory for DB->get() and friends.
01376          */
01377         DBT      my_rskey;              /* Secondary key. */
01378         DBT      my_rkey;               /* [Primary] key. */
01379         DBT      my_rdata;              /* Data. */
01380 
01381         /*
01382          * !!!
01383          * Some applications use DB but implement their own locking outside of
01384          * DB.  If they're using fcntl(2) locking on the underlying database
01385          * file, and we open and close a file descriptor for that file, we will
01386          * discard their locks.  The DB_FCNTL_LOCKING flag to DB->open is an
01387          * undocumented interface to support this usage which leaves any file
01388          * descriptors we open until DB->close.  This will only work with the
01389          * DB->open interface and simple caches, e.g., creating a transaction
01390          * thread may open/close file descriptors this flag doesn't protect.
01391          * Locking with fcntl(2) on a file that you don't own is a very, very
01392          * unsafe thing to do.  'Nuff said.
01393          */
01394         DB_FH   *saved_open_fhp;        /* Saved file handle. */
01395 
01396         /*
01397          * Linked list of DBP's, linked from the DB_ENV, used to keep track
01398          * of all open db handles for cursor adjustment.
01399          *
01400          * !!!
01401          * Explicit representations of structures from queue.h.
01402          * LIST_ENTRY(__db) dblistlinks;
01403          */
01404         struct {
01405                 struct __db *le_next;
01406                 struct __db **le_prev;
01407         } dblistlinks;
01408 
01409         /*
01410          * Cursor queues.
01411          *
01412          * !!!
01413          * Explicit representations of structures from queue.h.
01414          * TAILQ_HEAD(__cq_fq, __dbc) free_queue;
01415          * TAILQ_HEAD(__cq_aq, __dbc) active_queue;
01416          * TAILQ_HEAD(__cq_jq, __dbc) join_queue;
01417          */
01418         struct __cq_fq {
01419                 struct __dbc *tqh_first;
01420                 struct __dbc **tqh_last;
01421         } free_queue;
01422         struct __cq_aq {
01423                 struct __dbc *tqh_first;
01424                 struct __dbc **tqh_last;
01425         } active_queue;
01426         struct __cq_jq {
01427                 struct __dbc *tqh_first;
01428                 struct __dbc **tqh_last;
01429         } join_queue;
01430 
01431         /*
01432          * Secondary index support.
01433          *
01434          * Linked list of secondary indices -- set in the primary.
01435          *
01436          * !!!
01437          * Explicit representations of structures from queue.h.
01438          * LIST_HEAD(s_secondaries, __db);
01439          */
01440         struct {
01441                 struct __db *lh_first;
01442         } s_secondaries;
01443 
01444         /*
01445          * List entries for secondaries, and reference count of how
01446          * many threads are updating this secondary (see __db_c_put).
01447          *
01448          * !!!
01449          * Note that these are synchronized by the primary's mutex, but
01450          * filled in in the secondaries.
01451          *
01452          * !!!
01453          * Explicit representations of structures from queue.h.
01454          * LIST_ENTRY(__db) s_links;
01455          */
01456         struct {
01457                 struct __db *le_next;
01458                 struct __db **le_prev;
01459         } s_links;
01460         u_int32_t s_refcnt;
01461 
01462         /* Secondary callback and free functions -- set in the secondary. */
01463         int     (*s_callback) __P((DB *, const DBT *, const DBT *, DBT *));
01464 
01465         /* Reference to primary -- set in the secondary. */
01466         DB      *s_primary;
01467 
01468 #define DB_ASSOC_IMMUTABLE_KEY    0x00000001 /* Secondary key is immutable. */
01469 
01470         /* Flags passed to associate -- set in the secondary. */
01471         u_int32_t s_assoc_flags;
01472 
01473         /* API-private structure: used by DB 1.85, C++, Java, Perl and Tcl */
01474         void    *api_internal;
01475 
01476         /* Subsystem-private structure. */
01477         void    *bt_internal;           /* Btree/Recno access method. */
01478         void    *h_internal;            /* Hash access method. */
01479         void    *q_internal;            /* Queue access method. */
01480         void    *xa_internal;           /* XA. */
01481 
01482         /* DB PUBLIC HANDLE LIST BEGIN */
01483         int  (*associate) __P((DB *, DB_TXN *, DB *,
01484                 int (*)(DB *, const DBT *, const DBT *, DBT *), u_int32_t));
01485         int  (*close) __P((DB *, u_int32_t));
01486         int  (*compact) __P((DB *,
01487                 DB_TXN *, DBT *, DBT *, DB_COMPACT *, u_int32_t, DBT *));
01488         int  (*cursor) __P((DB *, DB_TXN *, DBC **, u_int32_t));
01489         int  (*del) __P((DB *, DB_TXN *, DBT *, u_int32_t));
01490         void (*err) __P((DB *, int, const char *, ...));
01491         void (*errx) __P((DB *, const char *, ...));
01492         int  (*fd) __P((DB *, int *));
01493         int  (*get) __P((DB *, DB_TXN *, DBT *, DBT *, u_int32_t));
01494         int  (*get_bt_minkey) __P((DB *, u_int32_t *));
01495         int  (*get_byteswapped) __P((DB *, int *));
01496         int  (*get_cachesize) __P((DB *, u_int32_t *, u_int32_t *, int *));
01497         int  (*get_dbname) __P((DB *, const char **, const char **));
01498         int  (*get_encrypt_flags) __P((DB *, u_int32_t *));
01499         DB_ENV *(*get_env) __P((DB *));
01500         void (*get_errfile) __P((DB *, FILE **));
01501         void (*get_errpfx) __P((DB *, const char **));
01502         int  (*get_flags) __P((DB *, u_int32_t *));
01503         int  (*get_h_ffactor) __P((DB *, u_int32_t *));
01504         int  (*get_h_nelem) __P((DB *, u_int32_t *));
01505         int  (*get_lorder) __P((DB *, int *));
01506         DB_MPOOLFILE *(*get_mpf) __P((DB *));
01507         void (*get_msgfile) __P((DB *, FILE **));
01508         int  (*get_open_flags) __P((DB *, u_int32_t *));
01509         int  (*get_pagesize) __P((DB *, u_int32_t *));
01510         int  (*get_q_extentsize) __P((DB *, u_int32_t *));
01511         int  (*get_re_delim) __P((DB *, int *));
01512         int  (*get_re_len) __P((DB *, u_int32_t *));
01513         int  (*get_re_pad) __P((DB *, int *));
01514         int  (*get_re_source) __P((DB *, const char **));
01515         int  (*get_transactional) __P((DB *));
01516         int  (*get_type) __P((DB *, DBTYPE *));
01517         int  (*join) __P((DB *, DBC **, DBC **, u_int32_t));
01518         int  (*key_range)
01519                 __P((DB *, DB_TXN *, DBT *, DB_KEY_RANGE *, u_int32_t));
01520         int  (*open) __P((DB *,
01521                 DB_TXN *, const char *, const char *, DBTYPE, u_int32_t, int));
01522         int  (*pget) __P((DB *, DB_TXN *, DBT *, DBT *, DBT *, u_int32_t));
01523         int  (*put) __P((DB *, DB_TXN *, DBT *, DBT *, u_int32_t));
01524         int  (*remove) __P((DB *, const char *, const char *, u_int32_t));
01525         int  (*rename) __P((DB *,
01526                 const char *, const char *, const char *, u_int32_t));
01527         int  (*set_alloc) __P((DB *, void *(*)(size_t),
01528                 void *(*)(void *, size_t), void (*)(void *)));
01529         int  (*set_append_recno) __P((DB *, int (*)(DB *, DBT *, db_recno_t)));
01530         int  (*set_bt_compare)
01531                 __P((DB *, int (*)(DB *, const DBT *, const DBT *)));
01532         int  (*set_bt_minkey) __P((DB *, u_int32_t));
01533         int  (*set_bt_prefix)
01534                 __P((DB *, size_t (*)(DB *, const DBT *, const DBT *)));
01535         int  (*set_cachesize) __P((DB *, u_int32_t, u_int32_t, int));
01536         int  (*set_dup_compare)
01537                 __P((DB *, int (*)(DB *, const DBT *, const DBT *)));
01538         int  (*set_encrypt) __P((DB *, const char *, u_int32_t));
01539         void (*set_errcall) __P((DB *,
01540                 void (*)(const DB_ENV *, const char *, const char *)));
01541         void (*set_errfile) __P((DB *, FILE *));
01542         void (*set_errpfx) __P((DB *, const char *));
01543         int  (*set_feedback) __P((DB *, void (*)(DB *, int, int)));
01544         int  (*set_flags) __P((DB *, u_int32_t));
01545         int  (*set_h_ffactor) __P((DB *, u_int32_t));
01546         int  (*set_h_hash)
01547                 __P((DB *, u_int32_t (*)(DB *, const void *, u_int32_t)));
01548         int  (*set_h_nelem) __P((DB *, u_int32_t));
01549         int  (*set_lorder) __P((DB *, int));
01550         void (*set_msgcall) __P((DB *, void (*)(const DB_ENV *, const char *)));
01551         void (*set_msgfile) __P((DB *, FILE *));
01552         int  (*set_pagesize) __P((DB *, u_int32_t));
01553         int  (*set_paniccall) __P((DB *, void (*)(DB_ENV *, int)));
01554         int  (*set_q_extentsize) __P((DB *, u_int32_t));
01555         int  (*set_re_delim) __P((DB *, int));
01556         int  (*set_re_len) __P((DB *, u_int32_t));
01557         int  (*set_re_pad) __P((DB *, int));
01558         int  (*set_re_source) __P((DB *, const char *));
01559         int  (*stat) __P((DB *, DB_TXN *, void *, u_int32_t));
01560         int  (*stat_print) __P((DB *, u_int32_t));
01561         int  (*sync) __P((DB *, u_int32_t));
01562         int  (*truncate) __P((DB *, DB_TXN *, u_int32_t *, u_int32_t));
01563         int  (*upgrade) __P((DB *, const char *, u_int32_t));
01564         int  (*verify)
01565                 __P((DB *, const char *, const char *, FILE *, u_int32_t));
01566         /* DB PUBLIC HANDLE LIST END */
01567 
01568         /* DB PRIVATE HANDLE LIST BEGIN */
01569         int  (*dump) __P((DB *, const char *,
01570                 int (*)(void *, const void *), void *, int, int));
01571         int  (*db_am_remove) __P((DB *, DB_TXN *, const char *, const char *));
01572         int  (*db_am_rename) __P((DB *, DB_TXN *,
01573             const char *, const char *, const char *));
01574         /* DB PRIVATE HANDLE LIST END */
01575 
01576         /*
01577          * Never called; these are a place to save function pointers
01578          * so that we can undo an associate.
01579          */
01580         int  (*stored_get) __P((DB *, DB_TXN *, DBT *, DBT *, u_int32_t));
01581         int  (*stored_close) __P((DB *, u_int32_t));
01582 
01583 #define DB_OK_BTREE     0x01
01584 #define DB_OK_HASH      0x02
01585 #define DB_OK_QUEUE     0x04
01586 #define DB_OK_RECNO     0x08
01587         u_int32_t       am_ok;          /* Legal AM choices. */
01588 
01589         /*
01590          * This field really ought to be an AM_FLAG, but we have
01591          * have run out of bits.  If/when we decide to split up
01592          * the flags, we can incorporate it.
01593          */
01594         int      preserve_fid;          /* Do not free fileid on close. */
01595 
01596 #define DB_AM_CHKSUM            0x00000001 /* Checksumming */
01597 #define DB_AM_CL_WRITER         0x00000002 /* Allow writes in client replica */
01598 #define DB_AM_COMPENSATE        0x00000004 /* Created by compensating txn */
01599 #define DB_AM_CREATED           0x00000008 /* Database was created upon open */
01600 #define DB_AM_CREATED_MSTR      0x00000010 /* Encompassing file was created */
01601 #define DB_AM_DBM_ERROR         0x00000020 /* Error in DBM/NDBM database */
01602 #define DB_AM_DELIMITER         0x00000040 /* Variable length delimiter set */
01603 #define DB_AM_DISCARD           0x00000080 /* Discard any cached pages */
01604 #define DB_AM_DUP               0x00000100 /* DB_DUP */
01605 #define DB_AM_DUPSORT           0x00000200 /* DB_DUPSORT */
01606 #define DB_AM_ENCRYPT           0x00000400 /* Encryption */
01607 #define DB_AM_FIXEDLEN          0x00000800 /* Fixed-length records */
01608 #define DB_AM_INMEM             0x00001000 /* In-memory; no sync on close */
01609 #define DB_AM_INORDER           0x00002000 /* DB_INORDER */
01610 #define DB_AM_IN_RENAME         0x00004000 /* File is being renamed */
01611 #define DB_AM_NOT_DURABLE       0x00008000 /* Do not log changes */
01612 #define DB_AM_OPEN_CALLED       0x00010000 /* DB->open called */
01613 #define DB_AM_PAD               0x00020000 /* Fixed-length record pad */
01614 #define DB_AM_PGDEF             0x00040000 /* Page size was defaulted */
01615 #define DB_AM_RDONLY            0x00080000 /* Database is readonly */
01616 #define DB_AM_READ_UNCOMMITTED  0x00100000 /* Support degree 1 isolation */
01617 #define DB_AM_RECNUM            0x00200000 /* DB_RECNUM */
01618 #define DB_AM_RECOVER           0x00400000 /* DB opened by recovery routine */
01619 #define DB_AM_RENUMBER          0x00800000 /* DB_RENUMBER */
01620 #define DB_AM_REVSPLITOFF       0x01000000 /* DB_REVSPLITOFF */
01621 #define DB_AM_SECONDARY         0x02000000 /* Database is a secondary index */
01622 #define DB_AM_SNAPSHOT          0x04000000 /* DB_SNAPSHOT */
01623 #define DB_AM_SUBDB             0x08000000 /* Subdatabases supported */
01624 #define DB_AM_SWAP              0x10000000 /* Pages need to be byte-swapped */
01625 #define DB_AM_TXN               0x20000000 /* Opened in a transaction */
01626 #define DB_AM_VERIFYING         0x40000000 /* DB handle is in the verifier */
01627         u_int32_t orig_flags;              /* Flags at  open, for refresh */
01628         u_int32_t flags;
01629 };
01630 
01631 /*
01632  * Macros for bulk get.  These are only intended for the C API.
01633  * For C++, use DbMultiple*Iterator.
01634  */
01635 #define DB_MULTIPLE_INIT(pointer, dbt)                                  \
01636         (pointer = (u_int8_t *)(dbt)->data +                            \
01637             (dbt)->ulen - sizeof(u_int32_t))
01638 #define DB_MULTIPLE_NEXT(pointer, dbt, retdata, retdlen)                \
01639         do {                                                            \
01640                 if (*((u_int32_t *)(pointer)) == (u_int32_t)-1) {       \
01641                         retdata = NULL;                                 \
01642                         pointer = NULL;                                 \
01643                         break;                                          \
01644                 }                                                       \
01645                 retdata = (u_int8_t *)                                  \
01646                     (dbt)->data + *(u_int32_t *)(pointer);              \
01647                 (pointer) = (u_int32_t *)(pointer) - 1;                 \
01648                 retdlen = *(u_int32_t *)(pointer);                      \
01649                 (pointer) = (u_int32_t *)(pointer) - 1;                 \
01650                 if (retdlen == 0 &&                                     \
01651                     retdata == (u_int8_t *)(dbt)->data)                 \
01652                         retdata = NULL;                                 \
01653         } while (0)
01654 #define DB_MULTIPLE_KEY_NEXT(pointer, dbt, retkey, retklen, retdata, retdlen) \
01655         do {                                                            \
01656                 if (*((u_int32_t *)(pointer)) == (u_int32_t)-1) {       \
01657                         retdata = NULL;                                 \
01658                         retkey = NULL;                                  \
01659                         pointer = NULL;                                 \
01660                         break;                                          \
01661                 }                                                       \
01662                 retkey = (u_int8_t *)                                   \
01663                     (dbt)->data + *(u_int32_t *)(pointer);              \
01664                 (pointer) = (u_int32_t *)(pointer) - 1;                 \
01665                 retklen = *(u_int32_t *)(pointer);                      \
01666                 (pointer) = (u_int32_t *)(pointer) - 1;                 \
01667                 retdata = (u_int8_t *)                                  \
01668                     (dbt)->data + *(u_int32_t *)(pointer);              \
01669                 (pointer) = (u_int32_t *)(pointer) - 1;                 \
01670                 retdlen = *(u_int32_t *)(pointer);                      \
01671                 (pointer) = (u_int32_t *)(pointer) - 1;                 \
01672         } while (0)
01673 
01674 #define DB_MULTIPLE_RECNO_NEXT(pointer, dbt, recno, retdata, retdlen)   \
01675         do {                                                            \
01676                 if (*((u_int32_t *)(pointer)) == (u_int32_t)0) {        \
01677                         recno = 0;                                      \
01678                         retdata = NULL;                                 \
01679                         pointer = NULL;                                 \
01680                         break;                                          \
01681                 }                                                       \
01682                 recno = *(u_int32_t *)(pointer);                        \
01683                 (pointer) = (u_int32_t *)(pointer) - 1;                 \
01684                 retdata = (u_int8_t *)                                  \
01685                     (dbt)->data + *(u_int32_t *)(pointer);              \
01686                 (pointer) = (u_int32_t *)(pointer) - 1;                 \
01687                 retdlen = *(u_int32_t *)(pointer);                      \
01688                 (pointer) = (u_int32_t *)(pointer) - 1;                 \
01689         } while (0)
01690 
01691 /*******************************************************
01692  * Access method cursors.
01693  *******************************************************/
01694 struct __dbc {
01695         DB *dbp;                        /* Related DB access method. */
01696         DB_TXN   *txn;                  /* Associated transaction. */
01697 
01698         /*
01699          * Active/free cursor queues.
01700          *
01701          * !!!
01702          * Explicit representations of structures from queue.h.
01703          * TAILQ_ENTRY(__dbc) links;
01704          */
01705         struct {
01706                 DBC *tqe_next;
01707                 DBC **tqe_prev;
01708         } links;
01709 
01710         /*
01711          * The DBT *'s below are used by the cursor routines to return
01712          * data to the user when DBT flags indicate that DB should manage
01713          * the returned memory.  They point at a DBT containing the buffer
01714          * and length that will be used, and "belonging" to the handle that
01715          * should "own" this memory.  This may be a "my_*" field of this
01716          * cursor--the default--or it may be the corresponding field of
01717          * another cursor, a DB handle, a join cursor, etc.  In general, it
01718          * will be whatever handle the user originally used for the current
01719          * DB interface call.
01720          */
01721         DBT      *rskey;                /* Returned secondary key. */
01722         DBT      *rkey;                 /* Returned [primary] key. */
01723         DBT      *rdata;                /* Returned data. */
01724 
01725         DBT       my_rskey;             /* Space for returned secondary key. */
01726         DBT       my_rkey;              /* Space for returned [primary] key. */
01727         DBT       my_rdata;             /* Space for returned data. */
01728 
01729         void     *lref;                 /* Reference to default locker. */
01730         u_int32_t locker;               /* Locker for this operation. */
01731         DBT       lock_dbt;             /* DBT referencing lock. */
01732         DB_LOCK_ILOCK lock;             /* Object to be locked. */
01733         DB_LOCK   mylock;               /* CDB lock held on this cursor. */
01734 
01735         u_int     cl_id;                /* Remote client id. */
01736 
01737         DBTYPE    dbtype;               /* Cursor type. */
01738 
01739         DBC_INTERNAL *internal;         /* Access method private. */
01740 
01741         /* DBC PUBLIC HANDLE LIST BEGIN */
01742         int (*c_close) __P((DBC *));
01743         int (*c_count) __P((DBC *, db_recno_t *, u_int32_t));
01744         int (*c_del) __P((DBC *, u_int32_t));
01745         int (*c_dup) __P((DBC *, DBC **, u_int32_t));
01746         int (*c_get) __P((DBC *, DBT *, DBT *, u_int32_t));
01747         int (*c_pget) __P((DBC *, DBT *, DBT *, DBT *, u_int32_t));
01748         int (*c_put) __P((DBC *, DBT *, DBT *, u_int32_t));
01749         /* DBC PUBLIC HANDLE LIST END */
01750 
01751         /* DBC PRIVATE HANDLE LIST BEGIN */
01752         int (*c_am_bulk) __P((DBC *, DBT *, u_int32_t));
01753         int (*c_am_close) __P((DBC *, db_pgno_t, int *));
01754         int (*c_am_del) __P((DBC *));
01755         int (*c_am_destroy) __P((DBC *));
01756         int (*c_am_get) __P((DBC *, DBT *, DBT *, u_int32_t, db_pgno_t *));
01757         int (*c_am_put) __P((DBC *, DBT *, DBT *, u_int32_t, db_pgno_t *));
01758         int (*c_am_writelock) __P((DBC *));
01759         /* DBC PRIVATE HANDLE LIST END */
01760 
01761 /*
01762  * DBC_COMPENSATE and DBC_RECOVER are used during recovery and transaction
01763  * abort.  If a transaction is being aborted or recovered then DBC_RECOVER
01764  * will be set and locking and logging will be disabled on this cursor.  If
01765  * we are performing a compensating transaction (e.g. free page processing)
01766  * then DB_COMPENSATE will be set to inhibit locking, but logging will still
01767  * be required.
01768  */
01769 #define DBC_ACTIVE              0x0001  /* Cursor in use. */
01770 #define DBC_COMPENSATE          0x0002  /* Cursor compensating, don't lock. */
01771 #define DBC_MULTIPLE            0x0004  /* Return Multiple data. */
01772 #define DBC_MULTIPLE_KEY        0x0008  /* Return Multiple keys and data. */
01773 #define DBC_OPD                 0x0010  /* Cursor references off-page dups. */
01774 #define DBC_OWN_LID             0x0020  /* Free lock id on destroy. */
01775 #define DBC_READ_COMMITTED      0x0040  /* Cursor has degree 2 isolation. */
01776 #define DBC_READ_UNCOMMITTED    0x0080  /* Cursor has degree 1 isolation. */
01777 #define DBC_RECOVER             0x0100  /* Recovery cursor; don't log/lock. */
01778 #define DBC_RMW                 0x0200  /* Acquire write flag in read op. */
01779 #define DBC_TRANSIENT           0x0400  /* Cursor is transient. */
01780 #define DBC_WRITECURSOR         0x0800  /* Cursor may be used to write (CDB). */
01781 #define DBC_WRITER              0x1000  /* Cursor immediately writing (CDB). */
01782         u_int32_t flags;
01783 };
01784 
01785 /* Key range statistics structure */
01786 struct __key_range {
01787         double less;
01788         double equal;
01789         double greater;
01790 };
01791 
01792 /* Btree/Recno statistics structure. */
01793 struct __db_bt_stat {
01794         u_int32_t bt_magic;             /* Magic number. */
01795         u_int32_t bt_version;           /* Version number. */
01796         u_int32_t bt_metaflags;         /* Metadata flags. */
01797         u_int32_t bt_nkeys;             /* Number of unique keys. */
01798         u_int32_t bt_ndata;             /* Number of data items. */
01799         u_int32_t bt_pagesize;          /* Page size. */
01800         u_int32_t bt_minkey;            /* Minkey value. */
01801         u_int32_t bt_re_len;            /* Fixed-length record length. */
01802         u_int32_t bt_re_pad;            /* Fixed-length record pad. */
01803         u_int32_t bt_levels;            /* Tree levels. */
01804         u_int32_t bt_int_pg;            /* Internal pages. */
01805         u_int32_t bt_leaf_pg;           /* Leaf pages. */
01806         u_int32_t bt_dup_pg;            /* Duplicate pages. */
01807         u_int32_t bt_over_pg;           /* Overflow pages. */
01808         u_int32_t bt_empty_pg;          /* Empty pages. */
01809         u_int32_t bt_free;              /* Pages on the free list. */
01810         u_int32_t bt_int_pgfree;        /* Bytes free in internal pages. */
01811         u_int32_t bt_leaf_pgfree;       /* Bytes free in leaf pages. */
01812         u_int32_t bt_dup_pgfree;        /* Bytes free in duplicate pages. */
01813         u_int32_t bt_over_pgfree;       /* Bytes free in overflow pages. */
01814 };
01815 
01816 struct __db_compact {
01817         /* Input Parameters. */
01818         u_int32_t       compact_fillpercent;    /* Desired fillfactor: 1-100 */
01819         db_timeout_t    compact_timeout;        /* Lock timeout. */
01820         u_int32_t       compact_pages;          /* Max pages to process. */
01821         /* Output Stats. */
01822         u_int32_t       compact_pages_free;     /* Number of pages freed. */
01823         u_int32_t       compact_pages_examine;  /* Number of pages examine. */
01824         u_int32_t       compact_levels;         /* Number of levels removed. */
01825         u_int32_t       compact_deadlock;       /* Number of deadlocks. */
01826         db_pgno_t       compact_pages_truncated; /* Pages truncated to OS. */
01827         /* Internal. */
01828         db_pgno_t       compact_truncate;       /* Page number for truncation */
01829 };
01830 
01831 /* Hash statistics structure. */
01832 struct __db_h_stat {
01833         u_int32_t hash_magic;           /* Magic number. */
01834         u_int32_t hash_version;         /* Version number. */
01835         u_int32_t hash_metaflags;       /* Metadata flags. */
01836         u_int32_t hash_nkeys;           /* Number of unique keys. */
01837         u_int32_t hash_ndata;           /* Number of data items. */
01838         u_int32_t hash_pagesize;        /* Page size. */
01839         u_int32_t hash_ffactor;         /* Fill factor specified at create. */
01840         u_int32_t hash_buckets;         /* Number of hash buckets. */
01841         u_int32_t hash_free;            /* Pages on the free list. */
01842         u_int32_t hash_bfree;           /* Bytes free on bucket pages. */
01843         u_int32_t hash_bigpages;        /* Number of big key/data pages. */
01844         u_int32_t hash_big_bfree;       /* Bytes free on big item pages. */
01845         u_int32_t hash_overflows;       /* Number of overflow pages. */
01846         u_int32_t hash_ovfl_free;       /* Bytes free on ovfl pages. */
01847         u_int32_t hash_dup;             /* Number of dup pages. */
01848         u_int32_t hash_dup_free;        /* Bytes free on duplicate pages. */
01849 };
01850 
01851 /* Queue statistics structure. */
01852 struct __db_qam_stat {
01853         u_int32_t qs_magic;             /* Magic number. */
01854         u_int32_t qs_version;           /* Version number. */
01855         u_int32_t qs_metaflags;         /* Metadata flags. */
01856         u_int32_t qs_nkeys;             /* Number of unique keys. */
01857         u_int32_t qs_ndata;             /* Number of data items. */
01858         u_int32_t qs_pagesize;          /* Page size. */
01859         u_int32_t qs_extentsize;        /* Pages per extent. */
01860         u_int32_t qs_pages;             /* Data pages. */
01861         u_int32_t qs_re_len;            /* Fixed-length record length. */
01862         u_int32_t qs_re_pad;            /* Fixed-length record pad. */
01863         u_int32_t qs_pgfree;            /* Bytes free in data pages. */
01864         u_int32_t qs_first_recno;       /* First not deleted record. */
01865         u_int32_t qs_cur_recno;         /* Next available record number. */
01866 };
01867 
01868 /*******************************************************
01869  * Environment.
01870  *******************************************************/
01871 #define DB_REGION_MAGIC 0x120897        /* Environment magic number. */
01872 
01873 /* Database Environment handle. */
01874 struct __db_env {
01875         /*******************************************************
01876          * Public: owned by the application.
01877          *******************************************************/
01878                                         /* Error message callback. */
01879         void (*db_errcall) __P((const DB_ENV *, const char *, const char *));
01880         FILE            *db_errfile;    /* Error message file stream. */
01881         const char      *db_errpfx;     /* Error message prefix. */
01882 
01883         FILE            *db_msgfile;    /* Statistics message file stream. */
01884                                         /* Statistics message callback. */
01885         void (*db_msgcall) __P((const DB_ENV *, const char *));
01886 
01887                                         /* Other Callbacks. */
01888         void (*db_feedback) __P((DB_ENV *, int, int));
01889         void (*db_paniccall) __P((DB_ENV *, int));
01890 
01891                                         /* App-specified alloc functions. */
01892         void *(*db_malloc) __P((size_t));
01893         void *(*db_realloc) __P((void *, size_t));
01894         void (*db_free) __P((void *));
01895 
01896         /*
01897          * Currently, the verbose list is a bit field with room for 32
01898          * entries.  There's no reason that it needs to be limited, if
01899          * there are ever more than 32 entries, convert to a bit array.
01900          */
01901 #define DB_VERB_DEADLOCK        0x0001  /* Deadlock detection information. */
01902 #define DB_VERB_RECOVERY        0x0002  /* Recovery information. */
01903 #define DB_VERB_REGISTER        0x0004  /* Dump waits-for table. */
01904 #define DB_VERB_REPLICATION     0x0008  /* Replication information. */
01905 #define DB_VERB_WAITSFOR        0x0010  /* Dump waits-for table. */
01906         u_int32_t        verbose;       /* Verbose output. */
01907 
01908         void            *app_private;   /* Application-private handle. */
01909 
01910         int (*app_dispatch)             /* User-specified recovery dispatch. */
01911             __P((DB_ENV *, DBT *, DB_LSN *, db_recops));
01912 
01913         /* Mutexes. */
01914         u_int32_t       mutex_align;    /* Mutex alignment */
01915         u_int32_t       mutex_cnt;      /* Number of mutexes to configure */
01916         u_int32_t       mutex_inc;      /* Number of mutexes to add */
01917         u_int32_t       mutex_tas_spins;/* Test-and-set spin count */
01918 
01919         struct {
01920                 int       alloc_id;     /* Allocation ID argument */
01921                 u_int32_t flags;        /* Flags argument */
01922         } *mutex_iq;                    /* Initial mutexes queue */
01923         u_int           mutex_iq_next;  /* Count of initial mutexes */
01924         u_int           mutex_iq_max;   /* Maximum initial mutexes */
01925 
01926         /* Locking. */
01927         u_int8_t        *lk_conflicts;  /* Two dimensional conflict matrix. */
01928         int              lk_modes;      /* Number of lock modes in table. */
01929         u_int32_t        lk_max;        /* Maximum number of locks. */
01930         u_int32_t        lk_max_lockers;/* Maximum number of lockers. */
01931         u_int32_t        lk_max_objects;/* Maximum number of locked objects. */
01932         u_int32_t        lk_detect;     /* Deadlock detect on all conflicts. */
01933         db_timeout_t     lk_timeout;    /* Lock timeout period. */
01934 
01935         /* Logging. */
01936         u_int32_t        lg_bsize;      /* Buffer size. */
01937         u_int32_t        lg_size;       /* Log file size. */
01938         u_int32_t        lg_regionmax;  /* Region size. */
01939         int              lg_filemode;   /* Log file permission mode. */
01940 
01941         /* Memory pool. */
01942         u_int32_t        mp_gbytes;     /* Cachesize: GB. */
01943         u_int32_t        mp_bytes;      /* Cachesize: Bytes. */
01944         u_int            mp_ncache;     /* Number of cache regions. */
01945         size_t           mp_mmapsize;   /* Maximum file size for mmap. */
01946         int              mp_maxopenfd;  /* Maximum open file descriptors. */
01947         int              mp_maxwrite;   /* Maximum buffers to write. */
01948         int                             /* Sleep after writing max buffers. */
01949                          mp_maxwrite_sleep;
01950 
01951         /* Replication */
01952         int              rep_eid;       /* environment id. */
01953         int             (*rep_send)     /* Send function. */
01954                             __P((DB_ENV *, const DBT *, const DBT *,
01955                             const DB_LSN *, int, u_int32_t));
01956 
01957         /* Transactions. */
01958         u_int32_t        tx_max;        /* Maximum number of transactions. */
01959         time_t           tx_timestamp;  /* Recover to specific timestamp. */
01960         db_timeout_t     tx_timeout;    /* Timeout for transactions. */
01961 
01962         /* Thread tracking. */
01963         u_int32_t       thr_nbucket;    /* Number of hash buckets. */
01964         u_int32_t       thr_max;        /* Max before garbage collection. */
01965         void            *thr_hashtab;   /* Hash table of DB_THREAD_INFO. */
01966 
01967         /*******************************************************
01968          * Private: owned by DB.
01969          *******************************************************/
01970         pid_t           pid_cache;      /* Cached process ID. */
01971 
01972                                         /* User files, paths. */
01973         char            *db_home;       /* Database home. */
01974         char            *db_abshome;    /* Absolute path when started. */
01975         char            *db_log_dir;    /* Database log file directory. */
01976         char            *db_tmp_dir;    /* Database tmp file directory. */
01977 
01978         char           **db_data_dir;   /* Database data file directories. */
01979         int              data_cnt;      /* Database data file slots. */
01980         int              data_next;     /* Next Database data file slot. */
01981 
01982         int              db_mode;       /* Default open permissions. */
01983         int              dir_mode;      /* Intermediate directory perms. */
01984         void            *env_lref;      /* Locker in non-threaded handles. */
01985         u_int32_t        open_flags;    /* Flags passed to DB_ENV->open. */
01986 
01987         void            *reginfo;       /* REGINFO structure reference. */
01988         DB_FH           *lockfhp;       /* fcntl(2) locking file handle. */
01989 
01990         DB_FH           *registry;      /* DB_REGISTER file handle. */
01991         u_int32_t       registry_off;   /*
01992                                          * Offset of our slot.  We can't use
01993                                          * off_t because its size depends on
01994                                          * build settings.
01995                                          */
01996 
01997                                         /* Return ID, check if ID alive. */
01998         void           (*thread_id) __P((DB_ENV *, pid_t *, db_threadid_t *));
01999         int            (*is_alive) __P((DB_ENV *, pid_t, db_threadid_t));
02000         char           *(*thread_id_string)
02001                         __P((DB_ENV *, pid_t, db_threadid_t, char *));
02002 
02003         int           (**recover_dtab)  /* Dispatch table for recover funcs. */
02004                             __P((DB_ENV *, DBT *, DB_LSN *, db_recops, void *));
02005         size_t           recover_dtab_size;
02006                                         /* Slots in the dispatch table. */
02007 
02008         void            *cl_handle;     /* RPC: remote client handle. */
02009         u_int            cl_id;         /* RPC: remote client env id. */
02010 
02011         int              db_ref;        /* DB reference count. */
02012 
02013         long             shm_key;       /* shmget(2) key. */
02014 
02015         /*
02016          * List of open DB handles for this DB_ENV, used for cursor
02017          * adjustment.  Must be protected for multi-threaded support.
02018          *
02019          * !!!
02020          * As this structure is allocated in per-process memory, the
02021          * mutex may need to be stored elsewhere on architectures unable
02022          * to support mutexes in heap memory, e.g. HP/UX 9.
02023          *
02024          * !!!
02025          * Explicit representation of structure in queue.h.
02026          * LIST_HEAD(dblist, __db);
02027          */
02028         db_mutex_t mtx_dblist;          /* Mutex. */
02029         struct {
02030                 struct __db *lh_first;
02031         } dblist;
02032 
02033         /*
02034          * XA support.
02035          *
02036          * !!!
02037          * Explicit representations of structures from queue.h.
02038          * TAILQ_ENTRY(__db_env) links;
02039          * TAILQ_HEAD(xa_txn, __db_txn);
02040          */
02041         struct {
02042                 struct __db_env *tqe_next;
02043                 struct __db_env **tqe_prev;
02044         } links;
02045         struct __xa_txn {       /* XA Active Transactions. */
02046                 struct __db_txn *tqh_first;
02047                 struct __db_txn **tqh_last;
02048         } xa_txn;
02049         int              xa_rmid;       /* XA Resource Manager ID. */
02050 
02051         char            *passwd;        /* Cryptography support. */
02052         size_t           passwd_len;
02053         void            *crypto_handle; /* Primary handle. */
02054         db_mutex_t       mtx_mt;        /* Mersenne Twister mutex. */
02055         int              mti;           /* Mersenne Twister index. */
02056         u_long          *mt;            /* Mersenne Twister state vector. */
02057 
02058         /* API-private structure. */
02059         void            *api1_internal; /* C++, Perl API private */
02060         void            *api2_internal; /* Java API private */
02061 
02062         void *lg_handle;                /* Log handle. */
02063         void *lk_handle;                /* Lock handle. */
02064         void *mp_handle;                /* Mpool handle. */
02065         void *mutex_handle;             /* Mutex handle. */
02066         void *rep_handle;               /* Replication handle. */
02067         void *tx_handle;                /* Txn handle. */
02068 
02069         /* DB_ENV PUBLIC HANDLE LIST BEGIN */
02070         int  (*close) __P((DB_ENV *, u_int32_t));
02071         int  (*dbremove) __P((DB_ENV *,
02072                 DB_TXN *, const char *, const char *, u_int32_t));
02073         int  (*dbrename) __P((DB_ENV *,
02074                 DB_TXN *, const char *, const char *, const char *, u_int32_t));
02075         void (*err) __P((const DB_ENV *, int, const char *, ...));
02076         void (*errx) __P((const DB_ENV *, const char *, ...));
02077         int  (*failchk) __P((DB_ENV *, u_int32_t));
02078         int  (*fileid_reset) __P((DB_ENV *, const char *, u_int32_t));
02079         int  (*get_cachesize) __P((DB_ENV *, u_int32_t *, u_int32_t *, int *));
02080         int  (*get_data_dirs) __P((DB_ENV *, const char ***));
02081         int  (*get_encrypt_flags) __P((DB_ENV *, u_int32_t *));
02082         void (*get_errfile) __P((DB_ENV *, FILE **));
02083         void (*get_errpfx) __P((DB_ENV *, const char **));
02084         int  (*get_flags) __P((DB_ENV *, u_int32_t *));
02085         int  (*get_home) __P((DB_ENV *, const char **));
02086         int  (*get_lg_bsize) __P((DB_ENV *, u_int32_t *));
02087         int  (*get_lg_dir) __P((DB_ENV *, const char **));
02088         int  (*get_lg_filemode) __P((DB_ENV *, int *));
02089         int  (*get_lg_max) __P((DB_ENV *, u_int32_t *));
02090         int  (*get_lg_regionmax) __P((DB_ENV *, u_int32_t *));
02091         int  (*get_lk_conflicts) __P((DB_ENV *, const u_int8_t **, int *));
02092         int  (*get_lk_detect) __P((DB_ENV *, u_int32_t *));
02093         int  (*get_lk_max_lockers) __P((DB_ENV *, u_int32_t *));
02094         int  (*get_lk_max_locks) __P((DB_ENV *, u_int32_t *));
02095         int  (*get_lk_max_objects) __P((DB_ENV *, u_int32_t *));
02096         int  (*get_mp_max_openfd) __P((DB_ENV *, int *));
02097         int  (*get_mp_max_write) __P((DB_ENV *, int *, int *));
02098         int  (*get_mp_mmapsize) __P((DB_ENV *, size_t *));
02099         void (*get_msgfile) __P((DB_ENV *, FILE **));
02100         int  (*get_open_flags) __P((DB_ENV *, u_int32_t *));
02101         int  (*get_rep_limit) __P((DB_ENV *, u_int32_t *, u_int32_t *));
02102         int  (*get_shm_key) __P((DB_ENV *, long *));
02103         int  (*get_timeout) __P((DB_ENV *, db_timeout_t *, u_int32_t));
02104         int  (*get_tmp_dir) __P((DB_ENV *, const char **));
02105         int  (*get_tx_max) __P((DB_ENV *, u_int32_t *));
02106         int  (*get_tx_timestamp) __P((DB_ENV *, time_t *));
02107         int  (*get_verbose) __P((DB_ENV *, u_int32_t, int *));
02108         int  (*is_bigendian) __P((void));
02109         int  (*lock_detect) __P((DB_ENV *, u_int32_t, u_int32_t, int *));
02110         int  (*lock_get) __P((DB_ENV *,
02111                 u_int32_t, u_int32_t, const DBT *, db_lockmode_t, DB_LOCK *));
02112         int  (*lock_id) __P((DB_ENV *, u_int32_t *));
02113         int  (*lock_id_free) __P((DB_ENV *, u_int32_t));
02114         int  (*lock_put) __P((DB_ENV *, DB_LOCK *));
02115         int  (*lock_stat) __P((DB_ENV *, DB_LOCK_STAT **, u_int32_t));
02116         int  (*lock_stat_print) __P((DB_ENV *, u_int32_t));
02117         int  (*lock_vec) __P((DB_ENV *,
02118                 u_int32_t, u_int32_t, DB_LOCKREQ *, int, DB_LOCKREQ **));
02119         int  (*log_archive) __P((DB_ENV *, char **[], u_int32_t));
02120         int  (*log_cursor) __P((DB_ENV *, DB_LOGC **, u_int32_t));
02121         int  (*log_file) __P((DB_ENV *, const DB_LSN *, char *, size_t));
02122         int  (*log_flush) __P((DB_ENV *, const DB_LSN *));
02123         int  (*log_printf) __P((DB_ENV *, DB_TXN *, const char *, ...));
02124         int  (*log_put) __P((DB_ENV *, DB_LSN *, const DBT *, u_int32_t));
02125         int  (*log_stat) __P((DB_ENV *, DB_LOG_STAT **, u_int32_t));
02126         int  (*log_stat_print) __P((DB_ENV *, u_int32_t));
02127         int  (*lsn_reset) __P((DB_ENV *, const char *, u_int32_t));
02128         int  (*memp_fcreate) __P((DB_ENV *, DB_MPOOLFILE **, u_int32_t));
02129         int  (*memp_register) __P((DB_ENV *, int, int (*)(DB_ENV *,
02130                 db_pgno_t, void *, DBT *), int (*)(DB_ENV *,
02131                 db_pgno_t, void *, DBT *)));
02132         int  (*memp_stat) __P((DB_ENV *,
02133                 DB_MPOOL_STAT **, DB_MPOOL_FSTAT ***, u_int32_t));
02134         int  (*memp_stat_print) __P((DB_ENV *, u_int32_t));
02135         int  (*memp_sync) __P((DB_ENV *, DB_LSN *));
02136         int  (*memp_trickle) __P((DB_ENV *, int, int *));
02137         int  (*mutex_alloc) __P((DB_ENV *, u_int32_t, db_mutex_t *));
02138         int  (*mutex_free) __P((DB_ENV *, db_mutex_t));
02139         int  (*mutex_get_align) __P((DB_ENV *, u_int32_t *));
02140         int  (*mutex_get_increment) __P((DB_ENV *, u_int32_t *));
02141         int  (*mutex_get_max) __P((DB_ENV *, u_int32_t *));
02142         int  (*mutex_get_tas_spins) __P((DB_ENV *, u_int32_t *));
02143         int  (*mutex_lock) __P((DB_ENV *, db_mutex_t));
02144         int  (*mutex_set_align) __P((DB_ENV *, u_int32_t));
02145         int  (*mutex_set_increment) __P((DB_ENV *, u_int32_t));
02146         int  (*mutex_set_max) __P((DB_ENV *, u_int32_t));
02147         int  (*mutex_set_tas_spins) __P((DB_ENV *, u_int32_t));
02148         int  (*mutex_stat) __P((DB_ENV *, DB_MUTEX_STAT **, u_int32_t));
02149         int  (*mutex_stat_print) __P((DB_ENV *, u_int32_t));
02150         int  (*mutex_unlock) __P((DB_ENV *, db_mutex_t));
02151         int  (*open) __P((DB_ENV *, const char *, u_int32_t, int));
02152         int  (*remove) __P((DB_ENV *, const char *, u_int32_t));
02153         int  (*rep_elect)
02154                 __P((DB_ENV *, int, int, int, u_int32_t, int *, u_int32_t));
02155         int  (*rep_flush) __P((DB_ENV *));
02156         int  (*rep_get_config) __P((DB_ENV *, u_int32_t, int *));
02157         int  (*rep_process_message)
02158                 __P((DB_ENV *, DBT *, DBT *, int *, DB_LSN *));
02159         int  (*rep_set_config) __P((DB_ENV *, u_int32_t, int));
02160         int  (*rep_start) __P((DB_ENV *, DBT *, u_int32_t));
02161         int  (*rep_stat) __P((DB_ENV *, DB_REP_STAT **, u_int32_t));
02162         int  (*rep_stat_print) __P((DB_ENV *, u_int32_t));
02163         int  (*rep_sync) __P((DB_ENV *, u_int32_t));
02164         int  (*set_alloc) __P((DB_ENV *, void *(*)(size_t),
02165                 void *(*)(void *, size_t), void (*)(void *)));
02166         int  (*set_app_dispatch)
02167                 __P((DB_ENV *, int (*)(DB_ENV *, DBT *, DB_LSN *, db_recops)));
02168         int  (*set_cachesize) __P((DB_ENV *, u_int32_t, u_int32_t, int));
02169         int  (*set_data_dir) __P((DB_ENV *, const char *));
02170         int  (*set_encrypt) __P((DB_ENV *, const char *, u_int32_t));
02171         void (*set_errcall) __P((DB_ENV *,
02172                 void (*)(const DB_ENV *, const char *, const char *)));
02173         void (*set_errfile) __P((DB_ENV *, FILE *));
02174         void (*set_errpfx) __P((DB_ENV *, const char *));
02175         int  (*set_feedback) __P((DB_ENV *, void (*)(DB_ENV *, int, int)));
02176         int  (*set_flags) __P((DB_ENV *, u_int32_t, int));
02177         int  (*set_intermediate_dir) __P((DB_ENV *, int, u_int32_t));
02178         int  (*set_isalive) __P((DB_ENV *,
02179                 int (*)(DB_ENV *, pid_t, db_threadid_t)));
02180         int  (*set_lg_bsize) __P((DB_ENV *, u_int32_t));
02181         int  (*set_lg_dir) __P((DB_ENV *, const char *));
02182         int  (*set_lg_filemode) __P((DB_ENV *, int));
02183         int  (*set_lg_max) __P((DB_ENV *, u_int32_t));
02184         int  (*set_lg_regionmax) __P((DB_ENV *, u_int32_t));
02185         int  (*set_lk_conflicts) __P((DB_ENV *, u_int8_t *, int));
02186         int  (*set_lk_detect) __P((DB_ENV *, u_int32_t));
02187         int  (*set_lk_max) __P((DB_ENV *, u_int32_t));
02188         int  (*set_lk_max_lockers) __P((DB_ENV *, u_int32_t));
02189         int  (*set_lk_max_locks) __P((DB_ENV *, u_int32_t));
02190         int  (*set_lk_max_objects) __P((DB_ENV *, u_int32_t));
02191         int  (*set_mp_max_openfd) __P((DB_ENV *, int));
02192         int  (*set_mp_max_write) __P((DB_ENV *, int, int));
02193         int  (*set_mp_mmapsize) __P((DB_ENV *, size_t));
02194         void (*set_msgcall)
02195                 __P((DB_ENV *, void (*)(const DB_ENV *, const char *)));
02196         void (*set_msgfile) __P((DB_ENV *, FILE *));
02197         int  (*set_paniccall) __P((DB_ENV *, void (*)(DB_ENV *, int)));
02198         int  (*set_rep_limit) __P((DB_ENV *, u_int32_t, u_int32_t));
02199         int  (*set_rep_request) __P((DB_ENV *, u_int32_t, u_int32_t));
02200         int  (*set_rep_transport) __P((DB_ENV *, int, int (*)(DB_ENV *,
02201                 const DBT *, const DBT *, const DB_LSN *, int, u_int32_t)));
02202         int  (*set_rpc_server)
02203                 __P((DB_ENV *, void *, const char *, long, long, u_int32_t));
02204         int  (*set_shm_key) __P((DB_ENV *, long));
02205         int  (*set_thread_count) __P((DB_ENV *, u_int32_t));
02206         int  (*set_thread_id) __P((DB_ENV *,
02207                 void (*)(DB_ENV *, pid_t *, db_threadid_t *)));
02208         int  (*set_thread_id_string) __P((DB_ENV *,
02209                 char *(*)(DB_ENV *, pid_t, db_threadid_t, char *)));
02210         int  (*set_timeout) __P((DB_ENV *, db_timeout_t, u_int32_t));
02211         int  (*set_tmp_dir) __P((DB_ENV *, const char *));
02212         int  (*set_tx_max) __P((DB_ENV *, u_int32_t));
02213         int  (*set_tx_timestamp) __P((DB_ENV *, time_t *));
02214         int  (*set_verbose) __P((DB_ENV *, u_int32_t, int));
02215         int  (*stat_print) __P((DB_ENV *, u_int32_t));
02216         int  (*txn_begin) __P((DB_ENV *, DB_TXN *, DB_TXN **, u_int32_t));
02217         int  (*txn_checkpoint) __P((DB_ENV *, u_int32_t, u_int32_t, u_int32_t));
02218         int  (*txn_recover)
02219                 __P((DB_ENV *, DB_PREPLIST *, long, long *, u_int32_t));
02220         int  (*txn_stat) __P((DB_ENV *, DB_TXN_STAT **, u_int32_t));
02221         int  (*txn_stat_print) __P((DB_ENV *, u_int32_t));
02222         /* DB_ENV PUBLIC HANDLE LIST END */
02223 
02224         /* DB_ENV PRIVATE HANDLE LIST BEGIN */
02225         int  (*prdbt) __P((DBT *,
02226                 int, const char *, void *, int (*)(void *, const void *), int));
02227         /* DB_ENV PRIVATE HANDLE LIST END */
02228 
02229 #define DB_TEST_ELECTINIT        1      /* after __rep_elect_init */
02230 #define DB_TEST_ELECTVOTE1       2      /* after sending VOTE1 */
02231 #define DB_TEST_POSTDESTROY      3      /* after destroy op */
02232 #define DB_TEST_POSTLOG          4      /* after logging all pages */
02233 #define DB_TEST_POSTLOGMETA      5      /* after logging meta in btree */
02234 #define DB_TEST_POSTOPEN         6      /* after __os_open */
02235 #define DB_TEST_POSTSYNC         7      /* after syncing the log */
02236 #define DB_TEST_PREDESTROY       8      /* before destroy op */
02237 #define DB_TEST_PREOPEN          9      /* before __os_open */
02238 #define DB_TEST_SUBDB_LOCKS      10     /* subdb locking tests */
02239         int              test_abort;    /* Abort value for testing. */
02240         int              test_check;    /* Checkpoint value for testing. */
02241         int              test_copy;     /* Copy value for testing. */
02242 
02243 #define DB_ENV_AUTO_COMMIT      0x0000001 /* DB_AUTO_COMMIT. */
02244 #define DB_ENV_CDB              0x0000002 /* DB_INIT_CDB. */
02245 #define DB_ENV_CDB_ALLDB        0x0000004 /* CDB environment wide locking. */
02246 #define DB_ENV_CREATE           0x0000008 /* DB_CREATE set. */
02247 #define DB_ENV_DBLOCAL          0x0000010 /* DB_ENV allocated for private DB. */
02248 #define DB_ENV_DIRECT_DB        0x0000020 /* DB_DIRECT_DB set. */
02249 #define DB_ENV_DIRECT_LOG       0x0000040 /* DB_DIRECT_LOG set. */
02250 #define DB_ENV_DSYNC_DB         0x0000080 /* DB_DSYNC_DB set. */
02251 #define DB_ENV_DSYNC_LOG        0x0000100 /* DB_DSYNC_LOG set. */
02252 #define DB_ENV_FATAL            0x0000200 /* Doing fatal recovery in env. */
02253 #define DB_ENV_LOCKDOWN         0x0000400 /* DB_LOCKDOWN set. */
02254 #define DB_ENV_LOG_AUTOREMOVE   0x0000800 /* DB_LOG_AUTOREMOVE set. */
02255 #define DB_ENV_LOG_INMEMORY     0x0001000 /* DB_LOG_INMEMORY set. */
02256 #define DB_ENV_NOLOCKING        0x0002000 /* DB_NOLOCKING set. */
02257 #define DB_ENV_NOMMAP           0x0004000 /* DB_NOMMAP set. */
02258 #define DB_ENV_NOPANIC          0x0008000 /* Okay if panic set. */
02259 #define DB_ENV_OPEN_CALLED      0x0010000 /* DB_ENV->open called. */
02260 #define DB_ENV_OVERWRITE        0x0020000 /* DB_OVERWRITE set. */
02261 #define DB_ENV_PRIVATE          0x0040000 /* DB_PRIVATE set. */
02262 #define DB_ENV_REGION_INIT      0x0080000 /* DB_REGION_INIT set. */
02263 #define DB_ENV_RPCCLIENT        0x0100000 /* DB_RPCCLIENT set. */
02264 #define DB_ENV_RPCCLIENT_GIVEN  0x0200000 /* User-supplied RPC client struct */
02265 #define DB_ENV_SYSTEM_MEM       0x0400000 /* DB_SYSTEM_MEM set. */
02266 #define DB_ENV_THREAD           0x0800000 /* DB_THREAD set. */
02267 #define DB_ENV_TIME_NOTGRANTED  0x1000000 /* DB_TIME_NOTGRANTED set. */
02268 #define DB_ENV_TXN_NOSYNC       0x2000000 /* DB_TXN_NOSYNC set. */
02269 #define DB_ENV_TXN_WRITE_NOSYNC 0x4000000 /* DB_TXN_WRITE_NOSYNC set. */
02270 #define DB_ENV_YIELDCPU         0x8000000 /* DB_YIELDCPU set. */
02271         u_int32_t flags;
02272 };
02273 
02274 #ifndef DB_DBM_HSEARCH
02275 #define DB_DBM_HSEARCH  0               /* No historic interfaces by default. */
02276 #endif
02277 #if DB_DBM_HSEARCH != 0
02278 /*******************************************************
02279  * Dbm/Ndbm historic interfaces.
02280  *******************************************************/
02281 typedef struct __db DBM;
02282 
02283 #define DBM_INSERT      0               /* Flags to dbm_store(). */
02284 #define DBM_REPLACE     1
02285 
02286 /*
02287  * The DB support for ndbm(3) always appends this suffix to the
02288  * file name to avoid overwriting the user's original database.
02289  */
02290 #define DBM_SUFFIX      ".db"
02291 
02292 #if defined(_XPG4_2)
02293 typedef struct {
02294         char *dptr;
02295         size_t dsize;
02296 } datum;
02297 #else
02298 typedef struct {
02299         char *dptr;
02300         int dsize;
02301 } datum;
02302 #endif
02303 
02304 /*
02305  * Translate NDBM calls into DB calls so that DB doesn't step on the
02306  * application's name space.
02307  */
02308 #define dbm_clearerr(a)         __db_ndbm_clearerr(a)
02309 #define dbm_close(a)            __db_ndbm_close(a)
02310 #define dbm_delete(a, b)        __db_ndbm_delete(a, b)
02311 #define dbm_dirfno(a)           __db_ndbm_dirfno(a)
02312 #define dbm_error(a)            __db_ndbm_error(a)
02313 #define dbm_fetch(a, b)         __db_ndbm_fetch(a, b)
02314 #define dbm_firstkey(a)         __db_ndbm_firstkey(a)
02315 #define dbm_nextkey(a)          __db_ndbm_nextkey(a)
02316 #define dbm_open(a, b, c)       __db_ndbm_open(a, b, c)
02317 #define dbm_pagfno(a)           __db_ndbm_pagfno(a)
02318 #define dbm_rdonly(a)           __db_ndbm_rdonly(a)
02319 #define dbm_store(a, b, c, d) \
02320         __db_ndbm_store(a, b, c, d)
02321 
02322 /*
02323  * Translate DBM calls into DB calls so that DB doesn't step on the
02324  * application's name space.
02325  *
02326  * The global variables dbrdonly, dirf and pagf were not retained when 4BSD
02327  * replaced the dbm interface with ndbm, and are not supported here.
02328  */
02329 #define dbminit(a)      __db_dbm_init(a)
02330 #define dbmclose        __db_dbm_close
02331 #if !defined(__cplusplus)
02332 #define delete(a)       __db_dbm_delete(a)
02333 #endif
02334 #define fetch(a)        __db_dbm_fetch(a)
02335 #define firstkey        __db_dbm_firstkey
02336 #define nextkey(a)      __db_dbm_nextkey(a)
02337 #define store(a, b)     __db_dbm_store(a, b)
02338 
02339 /*******************************************************
02340  * Hsearch historic interface.
02341  *******************************************************/
02342 typedef enum {
02343         FIND, ENTER
02344 } ACTION;
02345 
02346 typedef struct entry {
02347         char *key;
02348         char *data;
02349 } ENTRY;
02350 
02351 #define hcreate(a)      __db_hcreate(a)
02352 #define hdestroy        __db_hdestroy
02353 #define hsearch(a, b)   __db_hsearch(a, b)
02354 
02355 #endif /* DB_DBM_HSEARCH */
02356 
02357 #if defined(__cplusplus)
02358 }
02359 #endif
02360 #endif /* !_DB_H_ */
02361 
02362 /* DO NOT EDIT: automatically built by dist/s_include. */
02363 #ifndef _DB_EXT_PROT_IN_
02364 #define _DB_EXT_PROT_IN_
02365 
02366 #if defined(__cplusplus)
02367 extern "C" {
02368 #endif
02369 
02370 int db_create __P((DB **, DB_ENV *, u_int32_t));
02371 char *db_strerror __P((int));
02372 int db_env_create __P((DB_ENV **, u_int32_t));
02373 char *db_version __P((int *, int *, int *));
02374 int log_compare __P((const DB_LSN *, const DB_LSN *));
02375 int db_env_set_func_close __P((int (*)(int)));
02376 int db_env_set_func_dirfree __P((void (*)(char **, int)));
02377 int db_env_set_func_dirlist __P((int (*)(const char *, char ***, int *)));
02378 int db_env_set_func_exists __P((int (*)(const char *, int *)));
02379 int db_env_set_func_free __P((void (*)(void *)));
02380 int db_env_set_func_fsync __P((int (*)(int)));
02381 int db_env_set_func_ftruncate __P((int (*)(int, off_t)));
02382 int db_env_set_func_ioinfo __P((int (*)(const char *, int, u_int32_t *, u_int32_t *, u_int32_t *)));
02383 int db_env_set_func_malloc __P((void *(*)(size_t)));
02384 int db_env_set_func_map __P((int (*)(char *, size_t, int, int, void **)));
02385 int db_env_set_func_pread __P((ssize_t (*)(int, void *, size_t, off_t)));
02386 int db_env_set_func_pwrite __P((ssize_t (*)(int, const void *, size_t, off_t)));
02387 int db_env_set_func_open __P((int (*)(const char *, int, ...)));
02388 int db_env_set_func_read __P((ssize_t (*)(int, void *, size_t)));
02389 int db_env_set_func_realloc __P((void *(*)(void *, size_t)));
02390 int db_env_set_func_rename __P((int (*)(const char *, const char *)));
02391 int db_env_set_func_seek __P((int (*)(int, off_t, int)));
02392 int db_env_set_func_sleep __P((int (*)(u_long, u_long)));
02393 int db_env_set_func_unlink __P((int (*)(const char *)));
02394 int db_env_set_func_unmap __P((int (*)(void *, size_t)));
02395 int db_env_set_func_write __P((ssize_t (*)(int, const void *, size_t)));
02396 int db_env_set_func_yield __P((int (*)(void)));
02397 int db_sequence_create __P((DB_SEQUENCE **, DB *, u_int32_t));
02398 #if DB_DBM_HSEARCH != 0
02399 int      __db_ndbm_clearerr __P((DBM *));
02400 void     __db_ndbm_close __P((DBM *));
02401 int      __db_ndbm_delete __P((DBM *, datum));
02402 int      __db_ndbm_dirfno __P((DBM *));
02403 int      __db_ndbm_error __P((DBM *));
02404 datum __db_ndbm_fetch __P((DBM *, datum));
02405 datum __db_ndbm_firstkey __P((DBM *));
02406 datum __db_ndbm_nextkey __P((DBM *));
02407 DBM     *__db_ndbm_open __P((const char *, int, int));
02408 int      __db_ndbm_pagfno __P((DBM *));
02409 int      __db_ndbm_rdonly __P((DBM *));
02410 int      __db_ndbm_store __P((DBM *, datum, datum, int));
02411 int      __db_dbm_close __P((void));
02412 int      __db_dbm_delete __P((datum));
02413 datum __db_dbm_fetch __P((datum));
02414 datum __db_dbm_firstkey __P((void));
02415 int      __db_dbm_init __P((char *));
02416 datum __db_dbm_nextkey __P((datum));
02417 int      __db_dbm_store __P((datum, datum));
02418 #endif
02419 #if DB_DBM_HSEARCH != 0
02420 int __db_hcreate __P((size_t));
02421 ENTRY *__db_hsearch __P((ENTRY, ACTION));
02422 void __db_hdestroy __P((void));
02423 #endif
02424 
02425 #if defined(__cplusplus)
02426 }
02427 #endif
02428 #endif /* !_DB_EXT_PROT_IN_ */

Generated on Sun Dec 25 12:14:15 2005 for Berkeley DB 4.4.16 by  doxygen 1.4.2