G:/ScriptBasic/source/extensions/bdb/db.h

Go to the documentation of this file.
00001 /* DO NOT EDIT: automatically built by dist/distrib. */
00002 /*-
00003  * See the file LICENSE for redistribution information.
00004  *
00005  * Copyright (c) 1996, 1997, 1998, 1999, 2000
00006  *      Sleepycat Software.  All rights reserved.
00007  *
00008  *      $Id: db.h,v 1.1 2002/07/03 14:42:11 verhas Exp $
00009  */
00010 
00011 #ifndef _DB_H_
00012 #define _DB_H_
00013 
00014 #ifndef __NO_SYSTEM_INCLUDES
00015 #include <sys/types.h>
00016 
00017 #include <stdio.h>
00018 #endif
00019 
00020 #if defined(__cplusplus)
00021 extern "C" {
00022 #endif
00023 
00024 /*
00025  * XXX
00026  * MacOS: ensure that Metrowerks C makes enumeration types int sized.
00027  */
00028 #ifdef __MWERKS__
00029 #pragma enumsalwaysint on
00030 #endif
00031 
00032 /*
00033  * XXX
00034  * Handle function prototypes and the keyword "const".  This steps on name
00035  * space that DB doesn't control, but all of the other solutions are worse.
00036  *
00037  * XXX
00038  * While Microsoft's compiler is ANSI C compliant, it doesn't have _STDC_
00039  * defined by default, you specify a command line flag or #pragma to turn
00040  * it on.  Don't do that, however, because some of Microsoft's own header
00041  * files won't compile.
00042  */
00043 #undef  __P
00044 #if defined(__STDC__) || defined(__cplusplus) || defined(_MSC_VER)
00045 #define __P(protos)     protos          /* ANSI C prototypes */
00046 #else
00047 #define const
00048 #define __P(protos)     ()              /* K&R C preprocessor */
00049 #endif
00050 
00051 /*
00052  * !!!
00053  * DB needs basic information about specifically sized types.  If they're
00054  * not provided by 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 short int16_t;
00068 typedef unsigned short u_int16_t;
00069 typedef int int32_t;
00070 typedef unsigned int u_int32_t;
00071 #endif
00072 
00073 #if !defined(_WINSOCKAPI_)
00074 typedef unsigned char u_char;
00075 typedef unsigned short u_short;
00076 typedef unsigned int u_int;
00077 typedef unsigned long u_long;
00078 #endif
00079 typedef int ssize_t;
00080 
00081 #define DB_VERSION_MAJOR        3
00082 #define DB_VERSION_MINOR        1
00083 #define DB_VERSION_PATCH        14
00084 #define DB_VERSION_STRING       "Sleepycat Software: Berkeley DB 3.1.14: (June  7, 2000)"
00085 
00086 typedef u_int32_t       db_pgno_t;      /* Page number type. */
00087 typedef u_int16_t       db_indx_t;      /* Page offset type. */
00088 #define DB_MAX_PAGES    0xffffffff      /* >= # of pages in a file */
00089 
00090 typedef u_int32_t       db_recno_t;     /* Record number type. */
00091 #define DB_MAX_RECORDS  0xffffffff      /* >= # of records in a tree */
00092 
00093 /* Forward structure declarations, so applications get type checking. */
00094 struct __db;            typedef struct __db DB;
00095 #ifdef DB_DBM_HSEARCH
00096                         typedef struct __db DBM;
00097 #endif
00098 struct __db_bt_stat;    typedef struct __db_bt_stat DB_BTREE_STAT;
00099 struct __db_dbt;        typedef struct __db_dbt DBT;
00100 struct __db_env;        typedef struct __db_env DB_ENV;
00101 struct __db_h_stat;     typedef struct __db_h_stat DB_HASH_STAT;
00102 struct __db_ilock;      typedef struct __db_ilock DB_LOCK_ILOCK;
00103 struct __db_lock_stat;  typedef struct __db_lock_stat DB_LOCK_STAT;
00104 struct __db_lock_u;     typedef struct __db_lock_u DB_LOCK;
00105 struct __db_lockreq;    typedef struct __db_lockreq DB_LOCKREQ;
00106 struct __db_log_stat;   typedef struct __db_log_stat DB_LOG_STAT;
00107 struct __db_lsn;        typedef struct __db_lsn DB_LSN;
00108 struct __db_mpool_finfo;typedef struct __db_mpool_finfo DB_MPOOL_FINFO;
00109 struct __db_mpool_fstat;typedef struct __db_mpool_fstat DB_MPOOL_FSTAT;
00110 struct __db_mpool_stat; typedef struct __db_mpool_stat DB_MPOOL_STAT;
00111 struct __db_mpoolfile;  typedef struct __db_mpoolfile DB_MPOOLFILE;
00112 struct __db_qam_stat;   typedef struct __db_qam_stat DB_QUEUE_STAT;
00113 struct __db_txn;        typedef struct __db_txn DB_TXN;
00114 struct __db_txn_active; typedef struct __db_txn_active DB_TXN_ACTIVE;
00115 struct __db_txn_stat;   typedef struct __db_txn_stat DB_TXN_STAT;
00116 struct __dbc;           typedef struct __dbc DBC;
00117 struct __dbc_internal;  typedef struct __dbc_internal DBC_INTERNAL;
00118 struct __fh_t;          typedef struct __fh_t DB_FH;
00119 struct __key_range;     typedef struct __key_range DB_KEY_RANGE;
00120 
00121 /* Key/data structure -- a Data-Base Thang. */
00122 struct __db_dbt {
00123         /*
00124          * data/size must be fields 1 and 2 for DB 1.85 compatibility.
00125          */
00126         void     *data;                 /* Key/data */
00127         u_int32_t size;                 /* key/data length */
00128 
00129         u_int32_t ulen;                 /* RO: length of user buffer. */
00130         u_int32_t dlen;                 /* RO: get/put record length. */
00131         u_int32_t doff;                 /* RO: get/put record offset. */
00132 
00133 #define DB_DBT_ISSET    0x001           /* Lower level calls set value. */
00134 #define DB_DBT_MALLOC   0x002           /* Return in malloc'd memory. */
00135 #define DB_DBT_PARTIAL  0x004           /* Partial put/get. */
00136 #define DB_DBT_REALLOC  0x008           /* Return in realloc'd memory. */
00137 #define DB_DBT_USERMEM  0x010           /* Return in user's memory. */
00138 #define DB_DBT_DUPOK    0x020           /* Insert if duplicate. */
00139         u_int32_t flags;
00140 
00141         void     *app_private;          /* Key/data application private. */
00142 };
00143 
00144 /*
00145  * Flags understood by both db_env_create and db_create.
00146  */
00147 #define DB_CXX_NO_EXCEPTIONS  0x000001  /* C++: return error values. */
00148 
00149 /*
00150  * Flags understood by only db_env_create.
00151  */
00152 #define DB_CLIENT             0x000002  /* Open for a client environment. */
00153 
00154 /*
00155  * Flags understood by only db_create.
00156  */
00157 #define DB_XA_CREATE          0x000002  /* Open in an XA environment. */
00158 
00159 /*
00160  * Flags understood by both DBENV->open and DB->open.
00161  */
00162 #define DB_CREATE             0x000001  /* Create file as necessary. */
00163 #define DB_NOMMAP             0x000002  /* Don't mmap underlying file. */
00164 #define DB_THREAD             0x000004  /* Applications are threaded. */
00165 
00166 /*
00167  * Flags understood by both DBENV->open and DBENV->remove.
00168  */
00169 #define DB_FORCE              0x000008  /* Force (anything). */
00170 #define DB_INIT_CDB           0x000010  /* Concurrent Access Methods. */
00171 #define DB_INIT_LOCK          0x000020  /* Initialize locking. */
00172 #define DB_INIT_LOG           0x000040  /* Initialize logging. */
00173 #define DB_INIT_MPOOL         0x000080  /* Initialize mpool. */
00174 #define DB_INIT_TXN           0x000100  /* Initialize transactions. */
00175 #define DB_RECOVER            0x000200  /* Run normal recovery. */
00176 #define DB_RECOVER_FATAL      0x000400  /* Run catastrophic recovery. */
00177 #define DB_SYSTEM_MEM         0x000800  /* Use system-backed memory. */
00178 #define DB_TXN_NOSYNC         0x001000  /* Do not sync log on commit. */
00179 #define DB_USE_ENVIRON        0x002000  /* Use the environment. */
00180 #define DB_USE_ENVIRON_ROOT   0x004000  /* Use the environment if root. */
00181 
00182 /*
00183  * Flags understood by only DBENV->open.
00184  */
00185 #define DB_LOCKDOWN           0x008000  /* Lock memory into physical core. */
00186 #define DB_PRIVATE            0x010000  /* DB_ENV is process local. */
00187 
00188 /*
00189  * Flags understood by DBENV->txn_begin.
00190  */
00191 /*      DB_TXN_NOSYNC         0x001000     Do not sync log on commit. */
00192 #define DB_TXN_SYNC           0x000001  /* Always sync log on commit. */
00193 #define DB_TXN_NOWAIT         0x000002  /* Do not wait for locks in this TXN. */
00194 
00195 /*
00196  * Flags understood by only DB->open.
00197  */
00198 #define DB_EXCL               0x000008  /* Exclusive open (O_EXCL). */
00199 #define DB_RDONLY             0x000010  /* Read-only (O_RDONLY). */
00200 #define DB_TRUNCATE           0x000020  /* Discard existing DB (O_TRUNC). */
00201 #define DB_FCNTL_LOCKING      0x000040  /* Undocumented: fcntl(2) locking. */
00202 #define DB_ODDFILESIZE        0x000080  /* Undocumented: trunc. to N*pgsize. */
00203 #define DB_RDWRMASTER         0x000100  /* Undoc: allow subdb master open R/W */
00204 
00205 /*
00206  * Flags understood by DB->verify.
00207  *
00208  * !!!
00209  * These must not go over 0x8000, or they will collide with the flags
00210  * used by __bam_vrfy_subtree.
00211  */
00212 #define DB_AGGRESSIVE         0x0001  /* Salvage anything which might be data.*/
00213 #define DB_NOORDERCHK         0x0002  /* Skip order check; subdb w/ user func */
00214 #define DB_ORDERCHKONLY       0x0004  /* Only perform an order check on subdb */
00215 #define DB_PR_PAGE            0x0008  /* Show page contents (-da). */
00216 #define DB_PR_HEADERS         0x0010  /* Show only page headers (-dh). */
00217 #define DB_PR_RECOVERYTEST    0x0020  /* Recovery test (-dr). */
00218 #define DB_SALVAGE            0x0040  /* Salvage what looks like data. */
00219 #define DB_VRFY_FLAGMASK      0xffff  /* For masking above flags. */
00220 
00221 /*
00222  * Flags understood by only DB->set_feedback's callback.
00223  */
00224 /*      DB_RECOVER            0x000200     Running recovery. */
00225 #define DB_UPGRADE            0x000001  /* Upgrading. */
00226 
00227 /*
00228  * Deadlock detector modes; used in the DBENV structure to configure the
00229  * locking subsystem.
00230  */
00231 #define DB_LOCK_NORUN           0
00232 #define DB_LOCK_DEFAULT         1       /* Default policy. */
00233 #define DB_LOCK_OLDEST          2       /* Abort oldest transaction. */
00234 #define DB_LOCK_RANDOM          3       /* Abort random transaction. */
00235 #define DB_LOCK_YOUNGEST        4       /* Abort youngest transaction. */
00236 
00237 /*
00238  * Flags understood by only DB->set_flags.
00239  */
00240 #define DB_DUP                  0x0001  /* Btree, Hash: duplicate keys. */
00241 #define DB_DUPSORT              0x0002  /* Btree, Hash: duplicate keys. */
00242 #define DB_RECNUM               0x0004  /* Btree: record numbers. */
00243 #define DB_RENUMBER             0x0008  /* Recno: renumber on insert/delete. */
00244 #define DB_REVSPLITOFF          0x0010  /* Btree: turn off reverse splits. */
00245 #define DB_SNAPSHOT             0x0020  /* Recno: snapshot the input. */
00246 
00247 /*
00248  * Flags understood only by DB->join.
00249  */
00250 #define DB_JOIN_NOSORT          0x0001  /* Don't try to optimize join. */
00251 
00252 typedef enum {
00253         DB_TXN_ABORT,
00254         DB_TXN_BACKWARD_ROLL,
00255         DB_TXN_FORWARD_ROLL,
00256         DB_TXN_OPENFILES
00257 } db_recops;
00258 
00259 #define DB_UNDO(op)     ((op) == DB_TXN_ABORT || (op) == DB_TXN_BACKWARD_ROLL)
00260 #define DB_REDO(op)     ((op) == DB_TXN_FORWARD_ROLL)
00261 
00262 struct __db_env {
00263         /*******************************************************
00264          * Public: owned by the application.
00265          *******************************************************/
00266         FILE            *db_errfile;    /* Error message file stream. */
00267         const char      *db_errpfx;     /* Error message prefix. */
00268                                         /* Callbacks. */
00269         void (*db_errcall) __P((const char *, char *));
00270         void (*db_feedback) __P((DB_ENV *, int, int));
00271         void (*db_paniccall) __P((DB_ENV *, int));
00272         int  (*db_recovery_init) __P((DB_ENV *));
00273 
00274         /*
00275          * Currently, the verbose list is a bit field with room for 32
00276          * entries.  There's no reason that it needs to be limited, if
00277          * there are ever more than 32 entries, convert to a bit array.
00278          */
00279 #define DB_VERB_CHKPOINT        0x0001  /* List checkpoints. */
00280 #define DB_VERB_DEADLOCK        0x0002  /* Deadlock detection information. */
00281 #define DB_VERB_RECOVERY        0x0004  /* Recovery information. */
00282 #define DB_VERB_WAITSFOR        0x0008  /* Dump waits-for table. */
00283         u_int32_t        verbose;       /* Verbose output. */
00284 
00285         /* Locking. */
00286         u_int8_t        *lk_conflicts;  /* Two dimensional conflict matrix. */
00287         u_int32_t        lk_modes;      /* Number of lock modes in table. */
00288         u_int32_t        lk_max;        /* Maximum number of locks. */
00289         u_int32_t        lk_detect;     /* Deadlock detect on all conflicts. */
00290 
00291         /* Logging. */
00292         u_int32_t        lg_bsize;      /* Buffer size. */
00293         u_int32_t        lg_max;        /* Maximum file size. */
00294 
00295         /* Memory pool. */
00296         u_int32_t        mp_gbytes;     /* Cachesize: GB. */
00297         u_int32_t        mp_bytes;      /* Cachesize: Bytes. */
00298         size_t           mp_size;       /* DEPRECATED: Cachesize: bytes. */
00299         int              mp_ncache;     /* Number of cache regions. */
00300         size_t           mp_mmapsize;   /* Maximum file size for mmap. */
00301 
00302         /* Transactions. */
00303         u_int32_t        tx_max;        /* Maximum number of transactions. */
00304         time_t           tx_timestamp;  /* Recover to specific timestamp. */
00305         int (*tx_recover)               /* Dispatch function for recovery. */
00306             __P((DB_ENV *, DBT *, DB_LSN *, db_recops, void *));
00307 
00308         /*******************************************************
00309          * Private: owned by DB.
00310          *******************************************************/
00311         int              db_panic;      /* Panic causing errno. */
00312 
00313         /* User files, paths. */
00314         char            *db_home;       /* Database home. */
00315         char            *db_log_dir;    /* Database log file directory. */
00316         char            *db_tmp_dir;    /* Database tmp file directory. */
00317 
00318         char           **db_data_dir;   /* Database data file directories. */
00319         int              data_cnt;      /* Database data file slots. */
00320         int              data_next;     /* Next Database data file slot. */
00321 
00322         int              db_mode;       /* Default open permissions. */
00323 
00324         void            *reginfo;       /* REGINFO structure reference. */
00325         DB_FH           *lockfhp;       /* fcntl(2) locking file handle. */
00326         long             shm_key;       /* shmget(2) key. */
00327 
00328         void            *lg_handle;     /* Log handle. */
00329 
00330         void            *lk_handle;     /* Lock handle. */
00331 
00332         void            *mp_handle;     /* Mpool handle. */
00333 
00334         void            *tx_handle;     /* Txn handle. */
00335 
00336         int           (**dtab)          /* Dispatch table */
00337                             __P((DB_ENV *, DBT *, DB_LSN *, db_recops, void *));
00338         size_t           dtab_size;     /* Slots in the dispatch table. */
00339 
00340         void            *cl_handle;     /* RPC: remote client handle. */
00341         long             cl_id;         /* RPC: Remote client env id. */
00342 
00343         int              dblocal_ref;   /* DB_ENV_DBLOCAL: reference count. */
00344 
00345         /*
00346          * XA support.
00347          *
00348          * !!!
00349          * Explicit representations of structures in queue.h.
00350          *
00351          * TAILQ_ENTRY(__db_env);
00352          */
00353         struct {
00354                 struct __db_env *tqe_next;
00355                 struct __db_env **tqe_prev;
00356         } links;
00357         int              xa_rmid;       /* XA Resource Manager ID. */
00358         DB_TXN          *xa_txn;        /* XA Current transaction. */
00359 
00360         void    *cj_internal;           /* C++/Java private. */
00361 
00362                                         /* Methods. */
00363         int  (*close) __P((DB_ENV *, u_int32_t));
00364         void (*err) __P((const DB_ENV *, int, const char *, ...));
00365         void (*errx) __P((const DB_ENV *, const char *, ...));
00366         int  (*open) __P((DB_ENV *, const char *, u_int32_t, int));
00367         int  (*remove) __P((DB_ENV *, const char *, u_int32_t));
00368         int  (*set_data_dir) __P((DB_ENV *, const char *));
00369         void (*set_errcall) __P((DB_ENV *, void (*)(const char *, char *)));
00370         void (*set_errfile) __P((DB_ENV *, FILE *));
00371         void (*set_errpfx) __P((DB_ENV *, const char *));
00372         int  (*set_feedback) __P((DB_ENV *, void (*)(DB_ENV *, int, int)));
00373         int  (*set_paniccall) __P((DB_ENV *, void (*)(DB_ENV *, int)));
00374         int  (*set_recovery_init) __P((DB_ENV *, int (*)(DB_ENV *)));
00375         int  (*set_server) __P((DB_ENV *, char *, long, long, u_int32_t));
00376         int  (*set_shm_key) __P((DB_ENV *, long));
00377         int  (*set_tmp_dir) __P((DB_ENV *, const char *));
00378         int  (*set_verbose) __P((DB_ENV *, u_int32_t, int));
00379 
00380         int  (*set_lg_bsize) __P((DB_ENV *, u_int32_t));
00381         int  (*set_lg_dir) __P((DB_ENV *, const char *));
00382         int  (*set_lg_max) __P((DB_ENV *, u_int32_t));
00383 
00384         int  (*set_lk_conflicts) __P((DB_ENV *, u_int8_t *, int));
00385         int  (*set_lk_detect) __P((DB_ENV *, u_int32_t));
00386         int  (*set_lk_max) __P((DB_ENV *, u_int32_t));
00387 
00388         int  (*set_mp_mmapsize) __P((DB_ENV *, size_t));
00389         int  (*set_cachesize) __P((DB_ENV *, u_int32_t, u_int32_t, int));
00390 
00391         int  (*set_tx_max) __P((DB_ENV *, u_int32_t));
00392         int  (*set_tx_recover) __P((DB_ENV *,
00393                 int (*)(DB_ENV *, DBT *, DB_LSN *, db_recops, void *)));
00394         int  (*set_tx_timestamp) __P((DB_ENV *, time_t *));
00395 
00396 #ifdef CONFIG_TEST
00397 #define DB_TEST_PREOPEN          1      /* before __os_open */
00398 #define DB_TEST_POSTOPEN         2      /* after __os_open */
00399 #define DB_TEST_POSTLOGMETA      3      /* after logging meta in btree */
00400 #define DB_TEST_POSTLOG          4      /* after logging all pages */
00401 #define DB_TEST_POSTSYNC         5      /* after syncing the log */
00402 #define DB_TEST_PRERENAME        6      /* before __os_rename */
00403 #define DB_TEST_POSTRENAME       7      /* after __os_rename */
00404         int              test_abort;    /* Abort value for testing. */
00405         int              test_copy;     /* Copy value for testing. */
00406 #endif
00407 
00408 #define DB_ENV_CDB              0x00001 /* DB_INIT_CDB. */
00409 #define DB_ENV_CREATE           0x00002 /* DB_CREATE set. */
00410 #define DB_ENV_DBLOCAL          0x00004 /* DB_ENV allocated for private DB. */
00411 #define DB_ENV_LOCKDOWN         0x00008 /* DB_LOCKDOWN set. */
00412 #define DB_ENV_NOMMAP           0x00010 /* DB_NOMMAP set. */
00413 #define DB_ENV_OPEN_CALLED      0x00020 /* DBENV->open called (paths valid). */
00414 #define DB_ENV_PRIVATE          0x00040 /* DB_PRIVATE set. */
00415 #define DB_ENV_RPCCLIENT        0x00080 /* DB_CLIENT set. */
00416 #define DB_ENV_STANDALONE       0x00100 /* Test: freestanding environment. */
00417 #define DB_ENV_SYSTEM_MEM       0x00200 /* DB_SYSTEM_MEM set. */
00418 #define DB_ENV_THREAD           0x00400 /* DB_THREAD set. */
00419 #define DB_ENV_TXN_NOSYNC       0x00800 /* DB_TXN_NOSYNC set. */
00420 #define DB_ENV_USER_ALLOC       0x01000 /* User allocated the structure. */
00421         u_int32_t        flags;         /* Flags. */
00422 };
00423 
00424 /*******************************************************
00425  * Access methods.
00426  *******************************************************/
00427 /*
00428  * !!!
00429  * Changes here must be reflected in java/src/com/sleepycat/db/Db.java.
00430  */
00431 typedef enum {
00432         DB_BTREE=1,
00433         DB_HASH,
00434         DB_RECNO,
00435         DB_QUEUE,
00436         DB_UNKNOWN                      /* Figure it out on open. */
00437 } DBTYPE;
00438 
00439 #define DB_BTREEVERSION 8               /* Current btree version. */
00440 #define DB_BTREEOLDVER  6               /* Oldest btree version supported. */
00441 #define DB_BTREEMAGIC   0x053162
00442 
00443 #define DB_HASHVERSION  7               /* Current hash version. */
00444 #define DB_HASHOLDVER   4               /* Oldest hash version supported. */
00445 #define DB_HASHMAGIC    0x061561
00446 
00447 #define DB_QAMVERSION   2               /* Current queue version. */
00448 #define DB_QAMOLDVER    1               /* Oldest queue version supported. */
00449 #define DB_QAMMAGIC     0x042253
00450 
00451 #define DB_LOGVERSION   2               /* Current log version. */
00452 #define DB_LOGOLDVER    2               /* Oldest log version supported. */
00453 #define DB_LOGMAGIC     0x040988
00454 
00455 /*
00456  * DB access method and cursor operation values.  Each value is an operation
00457  * code to which additional bit flags are added.
00458  */
00459 #define DB_AFTER         1              /* c_put() */
00460 #define DB_APPEND        2              /* put() */
00461 #define DB_BEFORE        3              /* c_put() */
00462 #define DB_CACHED_COUNTS 4              /* stat() */
00463 #define DB_CHECKPOINT    5              /* log_put(), log_get() */
00464 #define DB_CONSUME       6              /* c_get() */
00465 #define DB_CURLSN        7              /* log_put() */
00466 #define DB_CURRENT       8              /* c_get(), c_put(), log_get() */
00467 #define DB_FIRST         9              /* c_get(), log_get() */
00468 #define DB_FLUSH        10              /* log_put() */
00469 #define DB_GET_BOTH     11              /* get(), c_get() */
00470 #define DB_GET_BOTHC    12              /* c_get() (internal) */
00471 #define DB_GET_RECNO    13              /* c_get() */
00472 #define DB_JOIN_ITEM    14              /* c_get(); do not do primary lookup */
00473 #define DB_KEYFIRST     15              /* c_put() */
00474 #define DB_KEYLAST      16              /* c_put() */
00475 #define DB_LAST         17              /* c_get(), log_get() */
00476 #define DB_NEXT         18              /* c_get(), log_get() */
00477 #define DB_NEXT_DUP     19              /* c_get() */
00478 #define DB_NEXT_NODUP   20              /* c_get() */
00479 #define DB_NODUPDATA    21              /* put(), c_put() */
00480 #define DB_NOOVERWRITE  22              /* put() */
00481 #define DB_NOSYNC       23              /* close() */
00482 #define DB_POSITION     24              /* c_dup() */
00483 #define DB_POSITIONI    25              /* c_dup() (internal) */
00484 #define DB_PREV         26              /* c_get(), log_get() */
00485 #define DB_PREV_NODUP   27              /* c_get(), log_get() */
00486 #define DB_RECORDCOUNT  28              /* stat() */
00487 #define DB_SET          29              /* c_get(), log_get() */
00488 #define DB_SET_RANGE    30              /* c_get() */
00489 #define DB_SET_RECNO    31              /* get(), c_get() */
00490 #define DB_WRITECURSOR  32              /* cursor() */
00491 #define DB_WRITELOCK    33              /* cursor() (internal) */
00492 
00493 /* This has to change when the max opcode hits 255. */
00494 #define DB_OPFLAGS_MASK 0x000000ff      /* Mask for operations flags. */
00495 #define DB_RMW          0x80000000      /* Acquire write flag immediately. */
00496 
00497 /*
00498  * DB (user visible) error return codes.
00499  *
00500  * !!!
00501  * Changes to any of the user visible error return codes must be reflected
00502  * in java/src/com/sleepycat/db/Db.java.
00503  *
00504  * !!!
00505  * For source compatibility with DB 2.X deadlock return (EAGAIN), use the
00506  * following:
00507  *      #include <errno.h>
00508  *      #define DB_LOCK_DEADLOCK EAGAIN
00509  *
00510  * !!!
00511  * We don't want our error returns to conflict with other packages where
00512  * possible, so pick a base error value that's hopefully not common.
00513  */
00514 #define DB_INCOMPLETE           (-30999)/* Sync didn't finish. */
00515 #define DB_KEYEMPTY             (-30998)/* Key/data deleted or never created. */
00516 #define DB_KEYEXIST             (-30997)/* The key/data pair already exists. */
00517 #define DB_LOCK_DEADLOCK        (-30996)/* Deadlock. */
00518 #define DB_LOCK_NOTGRANTED      (-30995)/* Lock unavailable. */
00519 #define DB_NOSERVER             (-30994)/* Server panic return. */
00520 #define DB_NOSERVER_HOME        (-30993)/* Bad home sent to server. */
00521 #define DB_NOSERVER_ID          (-30992)/* Bad ID sent to server. */
00522 #define DB_NOTFOUND             (-30991)/* Key/data pair not found (EOF). */
00523 #define DB_OLD_VERSION          (-30990)/* Out-of-date version. */
00524 #define DB_RUNRECOVERY          (-30989)/* Panic return. */
00525 #define DB_VERIFY_BAD           (-30988)/* Verify failed; bad format. */
00526 
00527 /* DB (private) error return codes. */
00528 #define DB_DELETED              (-30899)/* Recovery file marked deleted. */
00529 #define DB_NEEDSPLIT            (-30898)/* Page needs to be split. */
00530 #define DB_SWAPBYTES            (-30897)/* Database needs byte swapping. */
00531 #define DB_TXN_CKP              (-30896)/* Encountered ckp record in log. */
00532 #define DB_VERIFY_FATAL         (-30895)/* Fatal: DB->verify cannot proceed. */
00533 
00534 #define DB_FILE_ID_LEN          20      /* DB file ID length. */
00535 
00536 /* DB access method description structure. */
00537 struct __db {
00538         /*******************************************************
00539          * Public: owned by the application.
00540          *******************************************************/
00541         u_int32_t pgsize;               /* Database logical page size. */
00542 
00543                                         /* Callbacks. */
00544         void (*db_feedback) __P((DB *, int, int));
00545         void *(*db_malloc) __P((size_t));
00546         void *(*db_realloc) __P((void *, size_t));
00547         int (*dup_compare) __P((const DBT *, const DBT *));
00548 
00549         /*******************************************************
00550          * Private: owned by DB.
00551          *******************************************************/
00552         DB_ENV  *dbenv;                 /* Backing environment. */
00553 
00554         DBTYPE   type;                  /* DB access method type. */
00555 
00556         DB_MPOOLFILE *mpf;              /* Backing buffer pool. */
00557 
00558         void    *mutexp;                /* Synchronization for free threading */
00559 
00560         u_int8_t fileid[DB_FILE_ID_LEN];/* File's unique ID for locking. */
00561 
00562 #define DB_LOGFILEID_INVALID    -1
00563         int32_t  log_fileid;            /* File's unique ID for logging. */
00564         db_pgno_t meta_pgno;            /* Meta page number */
00565         DB_TXN  *open_txn;              /* Transaction to protect creates. */
00566 
00567         long     cl_id;                 /* RPC: remote client id. */
00568 
00569         /*
00570          * !!!
00571          * Some applications use DB but implement their own locking outside of
00572          * DB.  If they're using fcntl(2) locking on the underlying database
00573          * file, and we open and close a file descriptor for that file, we will
00574          * discard their locks.  The DB_FCNTL_LOCKING flag to DB->open is an
00575          * undocumented interface to support this usage which leaves any file
00576          * descriptors we open until DB->close.  This will only work with the
00577          * DB->open interface and simple caches, e.g., creating a transaction
00578          * thread may open/close file descriptors this flag doesn't protect.
00579          * Locking with fcntl(2) on a file that you don't own is a very, very
00580          * unsafe thing to do.  'Nuff said.
00581          */
00582         DB_FH   *saved_open_fhp;        /* Saved file handle. */
00583 
00584         /*
00585          * Linked list of DBP's, used in the log's dbentry table
00586          * to keep track of all open db handles for a given log id.
00587          * !!!
00588          * Explicit representations of structures in queue.h.
00589          *
00590          * TAILQ_ENTRY(__db) links;
00591          */
00592         struct {
00593                 struct __db *tqe_next;
00594                 struct __db **tqe_prev;
00595         } links;
00596 
00597         /*
00598          * Cursor queues.
00599          *
00600          * !!!
00601          * Explicit representations of structures in queue.h.
00602          *
00603          * TAILQ_HEAD(free_queue, __dbc);
00604          * TAILQ_HEAD(active_queue, __dbc);
00605          * TAILQ_HEAD(join_queue, __dbc);
00606          */
00607         struct {
00608                 struct __dbc *tqh_first;
00609                 struct __dbc **tqh_last;
00610         } free_queue;
00611         struct {
00612                 struct __dbc *tqh_first;
00613                 struct __dbc **tqh_last;
00614         } active_queue;
00615         struct {
00616                 struct __dbc *tqh_first;
00617                 struct __dbc **tqh_last;
00618         } join_queue;
00619 
00620         void    *bt_internal;           /* Btree/Recno access method private. */
00621         void    *cj_internal;           /* C++/Java private. */
00622         void    *h_internal;            /* Hash access method private. */
00623         void    *q_internal;            /* Queue access method private. */
00624         void    *xa_internal;           /* XA private. */
00625 
00626                                         /* Methods. */
00627         int  (*close) __P((DB *, u_int32_t));
00628         int  (*cursor) __P((DB *, DB_TXN *, DBC **, u_int32_t));
00629         int  (*del) __P((DB *, DB_TXN *, DBT *, u_int32_t));
00630         void (*err) __P((DB *, int, const char *, ...));
00631         void (*errx) __P((DB *, const char *, ...));
00632         int  (*fd) __P((DB *, int *));
00633         int  (*get) __P((DB *, DB_TXN *, DBT *, DBT *, u_int32_t));
00634         int  (*get_byteswapped) __P((DB *));
00635         DBTYPE
00636              (*get_type) __P((DB *));
00637         int  (*join) __P((DB *, DBC **, DBC **, u_int32_t));
00638         int  (*key_range) __P((DB *,
00639                 DB_TXN *, DBT *, DB_KEY_RANGE *, u_int32_t));
00640         int  (*open) __P((DB *,
00641                 const char *, const char *, DBTYPE, u_int32_t, int));
00642         int  (*put) __P((DB *, DB_TXN *, DBT *, DBT *, u_int32_t));
00643         int  (*remove) __P((DB *, const char *, const char *, u_int32_t));
00644         int  (*rename) __P((DB *,
00645                 const char *, const char *, const char *, u_int32_t));
00646         int  (*set_cachesize) __P((DB *, u_int32_t, u_int32_t, int));
00647         int  (*set_dup_compare) __P((DB *, int (*)(const DBT *, const DBT *)));
00648         void (*set_errcall) __P((DB *, void (*)(const char *, char *)));
00649         void (*set_errfile) __P((DB *, FILE *));
00650         void (*set_errpfx) __P((DB *, const char *));
00651         int  (*set_feedback) __P((DB *, void (*)(DB *, int, int)));
00652         int  (*set_flags) __P((DB *, u_int32_t));
00653         int  (*set_lorder) __P((DB *, int));
00654         int  (*set_malloc) __P((DB *, void *(*)(size_t)));
00655         int  (*set_pagesize) __P((DB *, u_int32_t));
00656         int  (*set_paniccall) __P((DB *, void (*)(DB_ENV *, int)));
00657         int  (*set_realloc) __P((DB *, void *(*)(void *, size_t)));
00658         int  (*stat) __P((DB *, void *, void *(*)(size_t), u_int32_t));
00659         int  (*sync) __P((DB *, u_int32_t));
00660         int  (*upgrade) __P((DB *, const char *, u_int32_t));
00661         int  (*verify) __P((DB *,
00662             const char *, const char *, FILE *, u_int32_t));
00663 
00664         int  (*set_bt_compare) __P((DB *, int (*)(const DBT *, const DBT *)));
00665         int  (*set_bt_maxkey) __P((DB *, u_int32_t));
00666         int  (*set_bt_minkey) __P((DB *, u_int32_t));
00667         int  (*set_bt_prefix) __P((DB *, size_t (*)(const DBT *, const DBT *)));
00668 
00669         int  (*set_h_ffactor) __P((DB *, u_int32_t));
00670         int  (*set_h_hash) __P((DB *, u_int32_t (*)(const void *, u_int32_t)));
00671         int  (*set_h_nelem) __P((DB *, u_int32_t));
00672 
00673         int  (*set_re_delim) __P((DB *, int));
00674         int  (*set_re_len) __P((DB *, u_int32_t));
00675         int  (*set_re_pad) __P((DB *, int));
00676         int  (*set_re_source) __P((DB *, const char *));
00677 
00678 #define DB_OK_BTREE     0x01
00679 #define DB_OK_HASH      0x02
00680 #define DB_OK_QUEUE     0x04
00681 #define DB_OK_RECNO     0x08
00682         u_int32_t       am_ok;          /* Legal AM choices. */
00683 
00684 #define DB_AM_DISCARD   0x00001         /* Discard any cached pages. */
00685 #define DB_AM_DUP       0x00002         /* DB_DUP. */
00686 #define DB_AM_DUPSORT   0x00004         /* DB_DUPSORT. */
00687 #define DB_AM_INMEM     0x00008         /* In-memory; no sync on close. */
00688 #define DB_AM_PGDEF     0x00010         /* Page size was defaulted. */
00689 #define DB_AM_RDONLY    0x00020         /* Database is readonly. */
00690 #define DB_AM_RECOVER   0x00040         /* DBP opened by recovery routine. */
00691 #define DB_AM_SUBDB     0x00080         /* Subdatabases supported. */
00692 #define DB_AM_SWAP      0x00100         /* Pages need to be byte-swapped. */
00693 #define DB_BT_RECNUM    0x00200         /* DB_RECNUM. */
00694 #define DB_BT_REVSPLIT  0x00400         /* DB_REVSPLITOFF. */
00695 #define DB_DBM_ERROR    0x00800         /* Error in DBM/NDBM database. */
00696 #define DB_OPEN_CALLED  0x01000         /* DB->open called. */
00697 #define DB_RE_DELIMITER 0x02000         /* Variablen length delimiter set. */
00698 #define DB_RE_FIXEDLEN  0x04000         /* Fixed-length records. */
00699 #define DB_RE_PAD       0x08000         /* Fixed-length record pad. */
00700 #define DB_RE_RENUMBER  0x10000         /* DB_RENUMBER. */
00701 #define DB_RE_SNAPSHOT  0x20000         /* DB_SNAPSHOT. */
00702         u_int32_t flags;
00703 };
00704 
00705 /*
00706  * DB_LOCK_ILOCK --
00707  *      Internal DB access method lock.
00708  */
00709 struct __db_ilock {
00710         db_pgno_t pgno;                 /* Page being locked. */
00711         u_int8_t fileid[DB_FILE_ID_LEN];/* File id. */
00712 #define DB_RECORD_LOCK  1
00713 #define DB_PAGE_LOCK    2
00714         u_int8_t type;                  /* Record or Page lock */
00715 };
00716 
00717 /*
00718  * DB_LOCK --
00719  *      The structure is allocated by the caller and filled in during a
00720  *      lock_get request (or a lock_vec/DB_LOCK_GET).
00721  */
00722 struct __db_lock_u {
00723         size_t          off;            /* Offset of the lock in the region */
00724         u_int32_t       ndx;            /* Index of the object referenced by
00725                                          * this lock; used for locking. */
00726         u_int32_t       gen;            /* Generation number of this lock. */
00727 };
00728 
00729 /* Cursor description structure. */
00730 struct __dbc {
00731         DB *dbp;                        /* Related DB access method. */
00732         DB_TXN   *txn;                  /* Associated transaction. */
00733 
00734         /*
00735          * !!!
00736          * Explicit representations of structures in queue.h.
00737          *
00738          * TAILQ_ENTRY(__dbc) links;    Active/free cursor queues.
00739          */
00740         struct {
00741                 DBC *tqe_next;
00742                 DBC **tqe_prev;
00743         } links;
00744 
00745         DBC *opd;                       /* Off-page duplicate cursor. */
00746 
00747         DBT       rkey;                 /* Returned key. */
00748         DBT       rdata;                /* Returned data. */
00749 
00750         u_int32_t lid;                  /* Default process' locker id. */
00751         u_int32_t locker;               /* Locker for this operation. */
00752         DBT       lock_dbt;             /* DBT referencing lock. */
00753         DB_LOCK_ILOCK lock;             /* Object to be locked. */
00754         DB_LOCK   mylock;               /* Lock held on this cursor. */
00755 
00756         long      cl_id;                /* Remote client id. */
00757 
00758         DBTYPE    dbtype;               /* Cursor type. */
00759 
00760         DBC_INTERNAL *internal;         /* Access method private. */
00761 
00762         int (*c_close) __P((DBC *));    /* Methods: public. */
00763         int (*c_count) __P((DBC *, db_recno_t *, u_int32_t));
00764         int (*c_del) __P((DBC *, u_int32_t));
00765         int (*c_dup) __P((DBC *, DBC **, u_int32_t));
00766         int (*c_get) __P((DBC *, DBT *, DBT *, u_int32_t));
00767         int (*c_put) __P((DBC *, DBT *, DBT *, u_int32_t));
00768 
00769                                         /* Methods: private. */
00770         int (*c_am_close) __P((DBC *, db_pgno_t, int *));
00771         int (*c_am_del) __P((DBC *));
00772         int (*c_am_destroy) __P((DBC *));
00773         int (*c_am_get) __P((DBC *, DBT *, DBT *, u_int32_t, db_pgno_t *));
00774         int (*c_am_put) __P((DBC *, DBT *, DBT *, u_int32_t, db_pgno_t *));
00775         int (*c_am_writelock) __P((DBC *));
00776 
00777 #define DBC_ACTIVE      0x001           /* Cursor is being used. */
00778 #define DBC_OPD         0x002           /* Cursor references off-page dups. */
00779 #define DBC_RECOVER     0x004           /* Cursor created by  recovery routine
00780                                          * (do not log or lock).
00781                                          */
00782 #define DBC_RMW         0x008           /* Acquire write flag in read op. */
00783 #define DBC_WRITECURSOR 0x010           /* Cursor may be used to write (CDB). */
00784 #define DBC_WRITEDUP    0x020           /* idup'ed DBC_WRITECURSOR (CDB). */
00785 #define DBC_WRITER      0x040           /* Cursor immediately writing (CDB). */
00786 #define DBC_TRANSIENT   0x080           /* Cursor is transient. */
00787         u_int32_t flags;
00788 };
00789 
00790 /* Key range statistics structure */
00791 struct __key_range {
00792         double less;
00793         double equal;
00794         double greater;
00795 };
00796 
00797 /* Btree/Recno statistics structure. */
00798 struct __db_bt_stat {
00799         u_int32_t bt_magic;             /* Magic number. */
00800         u_int32_t bt_version;           /* Version number. */
00801         u_int32_t bt_metaflags;         /* Metadata flags. */
00802         u_int32_t bt_nkeys;             /* Number of unique keys. */
00803         u_int32_t bt_ndata;             /* Number of data items. */
00804         u_int32_t bt_pagesize;          /* Page size. */
00805         u_int32_t bt_maxkey;            /* Maxkey value. */
00806         u_int32_t bt_minkey;            /* Minkey value. */
00807         u_int32_t bt_re_len;            /* Fixed-length record length. */
00808         u_int32_t bt_re_pad;            /* Fixed-length record pad. */
00809         u_int32_t bt_levels;            /* Tree levels. */
00810         u_int32_t bt_int_pg;            /* Internal pages. */
00811         u_int32_t bt_leaf_pg;           /* Leaf pages. */
00812         u_int32_t bt_dup_pg;            /* Duplicate pages. */
00813         u_int32_t bt_over_pg;           /* Overflow pages. */
00814         u_int32_t bt_free;              /* Pages on the free list. */
00815         u_int32_t bt_int_pgfree;        /* Bytes free in internal pages. */
00816         u_int32_t bt_leaf_pgfree;       /* Bytes free in leaf pages. */
00817         u_int32_t bt_dup_pgfree;        /* Bytes free in duplicate pages. */
00818         u_int32_t bt_over_pgfree;       /* Bytes free in overflow pages. */
00819 };
00820 
00821 /* Queue statistics structure. */
00822 struct __db_qam_stat {
00823         u_int32_t qs_magic;             /* Magic number. */
00824         u_int32_t qs_version;           /* Version number. */
00825         u_int32_t qs_metaflags;         /* Metadata flags. */
00826         u_int32_t qs_nkeys;             /* Number of unique keys. */
00827         u_int32_t qs_ndata;             /* Number of data items. */
00828         u_int32_t qs_pagesize;          /* Page size. */
00829         u_int32_t qs_pages;             /* Data pages. */
00830         u_int32_t qs_re_len;            /* Fixed-length record length. */
00831         u_int32_t qs_re_pad;            /* Fixed-length record pad. */
00832         u_int32_t qs_pgfree;            /* Bytes free in data pages. */
00833         u_int32_t qs_start;             /* Start offset. */
00834         u_int32_t qs_first_recno;       /* First not deleted record. */
00835         u_int32_t qs_cur_recno;         /* Last allocated record number. */
00836 };
00837 
00838 /* Hash statistics structure. */
00839 struct __db_h_stat {
00840         u_int32_t hash_magic;           /* Magic number. */
00841         u_int32_t hash_version;         /* Version number. */
00842         u_int32_t hash_metaflags;       /* Metadata flags. */
00843         u_int32_t hash_nkeys;           /* Number of unique keys. */
00844         u_int32_t hash_ndata;           /* Number of data items. */
00845         u_int32_t hash_pagesize;        /* Page size. */
00846         u_int32_t hash_nelem;           /* Original nelem specified. */
00847         u_int32_t hash_ffactor;         /* Fill factor specified at create. */
00848         u_int32_t hash_buckets;         /* Number of hash buckets. */
00849         u_int32_t hash_free;            /* Pages on the free list. */
00850         u_int32_t hash_bfree;           /* Bytes free on bucket pages. */
00851         u_int32_t hash_bigpages;        /* Number of big key/data pages. */
00852         u_int32_t hash_big_bfree;       /* Bytes free on big item pages. */
00853         u_int32_t hash_overflows;       /* Number of overflow pages. */
00854         u_int32_t hash_ovfl_free;       /* Bytes free on ovfl pages. */
00855         u_int32_t hash_dup;             /* Number of dup pages. */
00856         u_int32_t hash_dup_free;        /* Bytes free on duplicate pages. */
00857 };
00858 
00859 int   db_create __P((DB **, DB_ENV *, u_int32_t));
00860 int   db_env_create __P((DB_ENV **, u_int32_t));
00861 int   db_env_set_func_close __P((int (*)(int)));
00862 int   db_env_set_func_dirfree __P((void (*)(char **, int)));
00863 int   db_env_set_func_dirlist __P((int (*)(const char *, char ***, int *)));
00864 int   db_env_set_func_exists __P((int (*)(const char *, int *)));
00865 int   db_env_set_func_free __P((void (*)(void *)));
00866 int   db_env_set_func_fsync __P((int (*)(int)));
00867 int   db_env_set_func_ioinfo __P((int (*)(const char *,
00868           int, u_int32_t *, u_int32_t *, u_int32_t *)));
00869 int   db_env_set_func_malloc __P((void *(*)(size_t)));
00870 int   db_env_set_func_map __P((int (*)(char *, size_t, int, int, void **)));
00871 int   db_env_set_func_open __P((int (*)(const char *, int, ...)));
00872 int   db_env_set_func_read __P((ssize_t (*)(int, void *, size_t)));
00873 int   db_env_set_func_realloc __P((void *(*)(void *, size_t)));
00874 int   db_env_set_func_rename __P((int (*)(const char *, const char *)));
00875 int   db_env_set_func_seek
00876           __P((int (*)(int, size_t, db_pgno_t, u_int32_t, int, int)));
00877 int   db_env_set_func_sleep __P((int (*)(u_long, u_long)));
00878 int   db_env_set_func_unlink __P((int (*)(const char *)));
00879 int   db_env_set_func_unmap __P((int (*)(void *, size_t)));
00880 int   db_env_set_func_write __P((ssize_t (*)(int, const void *, size_t)));
00881 int   db_env_set_func_yield __P((int (*)(void)));
00882 int   db_env_set_mutexlocks __P((int));
00883 int   db_env_set_pageyield __P((int));
00884 int   db_env_set_panicstate __P((int));
00885 int   db_env_set_region_init __P((int));
00886 int   db_env_set_tas_spins __P((u_int32_t));
00887 char *db_strerror __P((int));
00888 char *db_version __P((int *, int *, int *));
00889 
00890 /*******************************************************
00891  * Locking
00892  *******************************************************/
00893 #define DB_LOCKVERSION  1
00894 
00895 /* Flag values for lock_vec(), lock_get(). */
00896 #define DB_LOCK_NOWAIT          0x01    /* Don't wait on unavailable lock. */
00897 #define DB_LOCK_RECORD          0x02    /* Internal: record lock. */
00898 #define DB_LOCK_UPGRADE         0x04    /* Internal: upgrade existing lock. */
00899 
00900 /* Flag values for lock_detect(). */
00901 #define DB_LOCK_CONFLICT        0x01    /* Run on any conflict. */
00902 
00903 /*
00904  * Request types.
00905  *
00906  * !!!
00907  * Changes here must be reflected in java/src/com/sleepycat/db/Db.java.
00908  */
00909 typedef enum {
00910         DB_LOCK_DUMP=0,                 /* Display held locks. */
00911         DB_LOCK_GET,                    /* Get the lock. */
00912         DB_LOCK_INHERIT,                /* Pass locks to parent. */
00913         DB_LOCK_PUT,                    /* Release the lock. */
00914         DB_LOCK_PUT_ALL,                /* Release locker's locks. */
00915         DB_LOCK_PUT_OBJ                 /* Release locker's locks on obj. */
00916 } db_lockop_t;
00917 
00918 /*
00919  * Simple R/W lock modes and for multi-granularity intention locking.
00920  *
00921  * !!!
00922  * These values are NOT random, as they are used as an index into the lock
00923  * conflicts arrays, i.e., DB_LOCK_IWRITE must be == 3, and DB_LOCK_IREAD
00924  * must be == 4.
00925  *
00926  * !!!
00927  * Changes here must be reflected in java/src/com/sleepycat/db/Db.java.
00928  */
00929 typedef enum {
00930         DB_LOCK_NG=0,                   /* Not granted. */
00931         DB_LOCK_READ,                   /* Shared/read. */
00932         DB_LOCK_WRITE,                  /* Exclusive/write. */
00933         DB_LOCK_IWRITE,                 /* Intent exclusive/write. */
00934         DB_LOCK_IREAD,                  /* Intent to share/read. */
00935         DB_LOCK_IWR                     /* Intent to read and write. */
00936 } db_lockmode_t;
00937 
00938 /*
00939  * Status of a lock.
00940  */
00941 typedef enum {
00942         DB_LSTAT_ABORTED,               /* Lock belongs to an aborted txn. */
00943         DB_LSTAT_ERR,                   /* Lock is bad. */
00944         DB_LSTAT_FREE,                  /* Lock is unallocated. */
00945         DB_LSTAT_HELD,                  /* Lock is currently held. */
00946         DB_LSTAT_NOGRANT,               /* Lock was not granted. */
00947         DB_LSTAT_PENDING,               /* Lock was waiting and has been
00948                                          * promoted; waiting for the owner
00949                                          * to run and upgrade it to held. */
00950         DB_LSTAT_WAITING                /* Lock is on the wait queue. */
00951 } db_status_t;
00952 
00953 /* Lock request structure. */
00954 struct __db_lockreq {
00955         db_lockop_t      op;            /* Operation. */
00956         db_lockmode_t    mode;          /* Requested mode. */
00957         u_int32_t        locker;        /* Locker identity. */
00958         DBT             *obj;           /* Object being locked. */
00959         DB_LOCK          lock;          /* Lock returned. */
00960 };
00961 
00962 /*
00963  * Commonly used conflict matrices.
00964  *
00965  * Standard Read/Write (or exclusive/shared) locks.
00966  */
00967 #define DB_LOCK_RW_N    3
00968 extern const u_int8_t db_rw_conflicts[];
00969 
00970 /* Multi-granularity locking. */
00971 #define DB_LOCK_RIW_N   6
00972 extern const u_int8_t db_riw_conflicts[];
00973 
00974 struct __db_lock_stat {
00975         u_int32_t st_lastid;            /* Last allocated locker ID. */
00976         u_int32_t st_maxlocks;          /* Maximum number of locks in table. */
00977         u_int32_t st_nmodes;            /* Number of lock modes. */
00978         u_int32_t st_nlockers;          /* Number of lockers. */
00979         u_int32_t st_maxnlockers;       /* Maximum number of lockers. */
00980         u_int32_t st_nconflicts;        /* Number of lock conflicts. */
00981         u_int32_t st_nrequests;         /* Number of lock gets. */
00982         u_int32_t st_nreleases;         /* Number of lock puts. */
00983         u_int32_t st_nnowaits;          /* Number of requests that would have
00984                                            waited, but NOWAIT was set. */
00985         u_int32_t st_ndeadlocks;        /* Number of lock deadlocks. */
00986         u_int32_t st_region_wait;       /* Region lock granted after wait. */
00987         u_int32_t st_region_nowait;     /* Region lock granted without wait. */
00988         u_int32_t st_regsize;           /* Region size. */
00989 };
00990 
00991 int       lock_detect __P((DB_ENV *, u_int32_t, u_int32_t, int *));
00992 int       lock_get __P((DB_ENV *,
00993             u_int32_t, u_int32_t, const DBT *, db_lockmode_t, DB_LOCK *));
00994 int       lock_id __P((DB_ENV *, u_int32_t *));
00995 int       lock_put __P((DB_ENV *, DB_LOCK *));
00996 int       lock_stat __P((DB_ENV *, DB_LOCK_STAT **, void *(*)(size_t)));
00997 int       lock_vec __P((DB_ENV *,
00998             u_int32_t, u_int32_t, DB_LOCKREQ *, int, DB_LOCKREQ **));
00999 
01000 /*******************************************************
01001  * Logging.
01002  *******************************************************/
01003 /* Flag values for log_archive(). */
01004 #define DB_ARCH_ABS             0x001   /* Absolute pathnames. */
01005 #define DB_ARCH_DATA            0x002   /* Data files. */
01006 #define DB_ARCH_LOG             0x004   /* Log files. */
01007 
01008 /*
01009  * A DB_LSN has two parts, a fileid which identifies a specific file, and an
01010  * offset within that file.  The fileid is an unsigned 4-byte quantity that
01011  * uniquely identifies a file within the log directory -- currently a simple
01012  * counter inside the log.  The offset is also an unsigned 4-byte value.  The
01013  * log manager guarantees the offset is never more than 4 bytes by switching
01014  * to a new log file before the maximum length imposed by an unsigned 4-byte
01015  * offset is reached.
01016  */
01017 struct __db_lsn {
01018         u_int32_t       file;           /* File ID. */
01019         u_int32_t       offset;         /* File offset. */
01020 };
01021 
01022 /* Log statistics structure. */
01023 struct __db_log_stat {
01024         u_int32_t st_magic;             /* Log file magic number. */
01025         u_int32_t st_version;           /* Log file version number. */
01026         int st_mode;                    /* Log file mode. */
01027         u_int32_t st_lg_bsize;          /* Log buffer size. */
01028         u_int32_t st_lg_max;            /* Maximum log file size. */
01029         u_int32_t st_w_bytes;           /* Bytes to log. */
01030         u_int32_t st_w_mbytes;          /* Megabytes to log. */
01031         u_int32_t st_wc_bytes;          /* Bytes to log since checkpoint. */
01032         u_int32_t st_wc_mbytes;         /* Megabytes to log since checkpoint. */
01033         u_int32_t st_wcount;            /* Total writes to the log. */
01034         u_int32_t st_wcount_fill;       /* Overflow writes to the log. */
01035         u_int32_t st_scount;            /* Total syncs to the log. */
01036         u_int32_t st_region_wait;       /* Region lock granted after wait. */
01037         u_int32_t st_region_nowait;     /* Region lock granted without wait. */
01038         u_int32_t st_cur_file;          /* Current log file number. */
01039         u_int32_t st_cur_offset;        /* Current log file offset. */
01040         u_int32_t st_regsize;           /* Region size. */
01041 };
01042 
01043 int      log_archive __P((DB_ENV *, char **[], u_int32_t, void *(*)(size_t)));
01044 int      log_compare __P((const DB_LSN *, const DB_LSN *));
01045 int      log_file __P((DB_ENV *, const DB_LSN *, char *, size_t));
01046 int      log_flush __P((DB_ENV *, const DB_LSN *));
01047 int      log_get __P((DB_ENV *, DB_LSN *, DBT *, u_int32_t));
01048 int      log_put __P((DB_ENV *, DB_LSN *, const DBT *, u_int32_t));
01049 int      log_register __P((DB_ENV *, DB *, const char *));
01050 int      log_stat __P((DB_ENV *, DB_LOG_STAT **, void *(*)(size_t)));
01051 int      log_unregister __P((DB_ENV *, DB *));
01052 
01053 /*******************************************************
01054  * Mpool
01055  *******************************************************/
01056 /* Flag values for memp_fget(). */
01057 #define DB_MPOOL_CREATE         0x001   /* Create a page. */
01058 #define DB_MPOOL_LAST           0x002   /* Return the last page. */
01059 #define DB_MPOOL_NEW            0x004   /* Create a new page. */
01060 #define DB_MPOOL_NEW_GROUP      0x008   /* Create a group of pages. */
01061 
01062 /* Flag values for memp_fput(), memp_fset(). */
01063 #define DB_MPOOL_CLEAN          0x001   /* Page is not modified. */
01064 #define DB_MPOOL_DIRTY          0x002   /* Page is modified. */
01065 #define DB_MPOOL_DISCARD        0x004   /* Don't cache the page. */
01066 
01067 /* Mpool statistics structure. */
01068 struct __db_mpool_stat {
01069         u_int32_t st_cache_hit;         /* Pages found in the cache. */
01070         u_int32_t st_cache_miss;        /* Pages not found in the cache. */
01071         u_int32_t st_map;               /* Pages from mapped files. */
01072         u_int32_t st_page_create;       /* Pages created in the cache. */
01073         u_int32_t st_page_in;           /* Pages read in. */
01074         u_int32_t st_page_out;          /* Pages written out. */
01075         u_int32_t st_ro_evict;          /* Clean pages forced from the cache. */
01076         u_int32_t st_rw_evict;          /* Dirty pages forced from the cache. */
01077         u_int32_t st_hash_buckets;      /* Number of hash buckets. */
01078         u_int32_t st_hash_searches;     /* Total hash chain searches. */
01079         u_int32_t st_hash_longest;      /* Longest hash chain searched. */
01080         u_int32_t st_hash_examined;     /* Total hash entries searched. */
01081         u_int32_t st_page_clean;        /* Clean pages. */
01082         u_int32_t st_page_dirty;        /* Dirty pages. */
01083         u_int32_t st_page_trickle;      /* Pages written by memp_trickle. */
01084         u_int32_t st_region_wait;       /* Region lock granted after wait. */
01085         u_int32_t st_region_nowait;     /* Region lock granted without wait. */
01086         u_int32_t st_gbytes;            /* Total cache size: GB. */
01087         u_int32_t st_bytes;             /* Total cache size: B. */
01088         u_int32_t st_ncache;            /* Number of caches. */
01089         u_int32_t st_regsize;           /* Cache size. */
01090 };
01091 
01092 /* Mpool file open information structure. */
01093 struct __db_mpool_finfo {
01094         int        ftype;               /* File type. */
01095         DBT       *pgcookie;            /* Byte-string passed to pgin/pgout. */
01096         u_int8_t  *fileid;              /* Unique file ID. */
01097         int32_t    lsn_offset;          /* LSN offset in page. */
01098         u_int32_t  clear_len;           /* Cleared length on created pages. */
01099 };
01100 
01101 /* Mpool file statistics structure. */
01102 struct __db_mpool_fstat {
01103         char *file_name;                /* File name. */
01104         size_t st_pagesize;             /* Page size. */
01105         u_int32_t st_cache_hit;         /* Pages found in the cache. */
01106         u_int32_t st_cache_miss;        /* Pages not found in the cache. */
01107         u_int32_t st_map;               /* Pages from mapped files. */
01108         u_int32_t st_page_create;       /* Pages created in the cache. */
01109         u_int32_t st_page_in;           /* Pages read in. */
01110         u_int32_t st_page_out;          /* Pages written out. */
01111 };
01112 
01113 int     memp_fclose __P((DB_MPOOLFILE *));
01114 int     memp_fget __P((DB_MPOOLFILE *, db_pgno_t *, u_int32_t, void *));
01115 int     memp_fopen __P((DB_ENV *, const char *,
01116             u_int32_t, int, size_t, DB_MPOOL_FINFO *, DB_MPOOLFILE **));
01117 int     memp_fput __P((DB_MPOOLFILE *, void *, u_int32_t));
01118 int     memp_fset __P((DB_MPOOLFILE *, void *, u_int32_t));
01119 int     memp_fsync __P((DB_MPOOLFILE *));
01120 int     memp_register __P((DB_ENV *, int,
01121             int (*)(DB_ENV *, db_pgno_t, void *, DBT *),
01122             int (*)(DB_ENV *, db_pgno_t, void *, DBT *)));
01123 int     memp_stat __P((DB_ENV *,
01124             DB_MPOOL_STAT **, DB_MPOOL_FSTAT ***, void *(*)(size_t)));
01125 int     memp_sync __P((DB_ENV *, DB_LSN *));
01126 int     memp_trickle __P((DB_ENV *, int, int *));
01127 
01128 /*******************************************************
01129  * Transactions.
01130  *******************************************************/
01131 #define DB_TXNVERSION   1
01132 
01133 /* Operations values to the tx_recover() function. */
01134 #define DB_TXN_BACKWARD_ROLL    1       /* Read the log backwards. */
01135 #define DB_TXN_FORWARD_ROLL     2       /* Read the log forwards. */
01136 #define DB_TXN_OPENFILES        3       /* Read for open files. */
01137 #define DB_TXN_REDO             4       /* Redo the operation. */
01138 #define DB_TXN_UNDO             5       /* Undo the operation. */
01139 
01140 /* Internal transaction status values. */
01141 
01142 /* Transaction statistics structure. */
01143 struct __db_txn_active {
01144         u_int32_t       txnid;          /* Transaction ID */
01145         u_int32_t       parentid;       /* Transaction ID of parent */
01146         DB_LSN          lsn;            /* Lsn of the begin record */
01147 };
01148 
01149 struct __db_txn_stat {
01150         DB_LSN    st_last_ckp;          /* lsn of the last checkpoint */
01151         DB_LSN    st_pending_ckp;       /* last checkpoint did not finish */
01152         time_t    st_time_ckp;          /* time of last checkpoint */
01153         u_int32_t st_last_txnid;        /* last transaction id given out */
01154         u_int32_t st_maxtxns;           /* maximum txns possible */
01155         u_int32_t st_naborts;           /* number of aborted transactions */
01156         u_int32_t st_nbegins;           /* number of begun transactions */
01157         u_int32_t st_ncommits;          /* number of committed transactions */
01158         u_int32_t st_nactive;           /* number of active transactions */
01159         u_int32_t st_maxnactive;        /* maximum active transactions */
01160         DB_TXN_ACTIVE
01161                  *st_txnarray;          /* array of active transactions */
01162         u_int32_t st_region_wait;       /* Region lock granted after wait. */
01163         u_int32_t st_region_nowait;     /* Region lock granted without wait. */
01164         u_int32_t st_regsize;           /* Region size. */
01165 };
01166 
01167 int       txn_abort __P((DB_TXN *));
01168 int       txn_begin __P((DB_ENV *, DB_TXN *, DB_TXN **, u_int32_t));
01169 int       txn_checkpoint __P((DB_ENV *, u_int32_t, u_int32_t, u_int32_t));
01170 int       txn_commit __P((DB_TXN *, u_int32_t));
01171 u_int32_t txn_id __P((DB_TXN *));
01172 int       txn_prepare __P((DB_TXN *));
01173 int       txn_stat __P((DB_ENV *, DB_TXN_STAT **, void *(*)(size_t)));
01174 
01175 #ifndef DB_DBM_HSEARCH
01176 #define DB_DBM_HSEARCH  0               /* No historic interfaces by default. */
01177 #endif
01178 #if DB_DBM_HSEARCH != 0
01179 /*******************************************************
01180  * Dbm/Ndbm historic interfaces.
01181  *******************************************************/
01182 #define DBM_INSERT      0               /* Flags to dbm_store(). */
01183 #define DBM_REPLACE     1
01184 
01185 /*
01186  * The DB support for ndbm(3) always appends this suffix to the
01187  * file name to avoid overwriting the user's original database.
01188  */
01189 #define DBM_SUFFIX      ".db"
01190 
01191 #if defined(_XPG4_2)
01192 typedef struct {
01193         char *dptr;
01194         size_t dsize;
01195 } datum;
01196 #else
01197 typedef struct {
01198         char *dptr;
01199         int dsize;
01200 } datum;
01201 #endif
01202 
01203 /*
01204  * Translate DBM calls into DB calls so that DB doesn't step on the
01205  * application's name space.
01206  *
01207  * The global variables dbrdonly, dirf and pagf were not retained when 4BSD
01208  * replaced the dbm interface with ndbm, and are not supported here.
01209  */
01210 #define dbminit(a)      __db_dbm_init(a)
01211 #define dbmclose        __db_dbm_close
01212 #if !defined(__cplusplus)
01213 #define delete(a)       __db_dbm_delete(a)
01214 #endif
01215 #define fetch(a)        __db_dbm_fetch(a)
01216 #define firstkey        __db_dbm_firstkey
01217 #define nextkey(a)      __db_dbm_nextkey(a)
01218 #define store(a, b)     __db_dbm_store(a, b)
01219 
01220 /* Prototype the DB calls. */
01221 int      __db_dbm_close __P((void));
01222 int      __db_dbm_dbrdonly __P((void));
01223 int      __db_dbm_delete __P((datum));
01224 int      __db_dbm_dirf __P((void));
01225 datum    __db_dbm_fetch __P((datum));
01226 datum    __db_dbm_firstkey __P((void));
01227 int      __db_dbm_init __P((char *));
01228 datum    __db_dbm_nextkey __P((datum));
01229 int      __db_dbm_pagf __P((void));
01230 int      __db_dbm_store __P((datum, datum));
01231 
01232 /*
01233  * Translate NDBM calls into DB calls so that DB doesn't step on the
01234  * application's name space.
01235  */
01236 #define dbm_clearerr(a)         __db_ndbm_clearerr(a)
01237 #define dbm_close(a)            __db_ndbm_close(a)
01238 #define dbm_delete(a, b)        __db_ndbm_delete(a, b)
01239 #define dbm_dirfno(a)           __db_ndbm_dirfno(a)
01240 #define dbm_error(a)            __db_ndbm_error(a)
01241 #define dbm_fetch(a, b)         __db_ndbm_fetch(a, b)
01242 #define dbm_firstkey(a)         __db_ndbm_firstkey(a)
01243 #define dbm_nextkey(a)          __db_ndbm_nextkey(a)
01244 #define dbm_open(a, b, c)       __db_ndbm_open(a, b, c)
01245 #define dbm_pagfno(a)           __db_ndbm_pagfno(a)
01246 #define dbm_rdonly(a)           __db_ndbm_rdonly(a)
01247 #define dbm_store(a, b, c, d)   __db_ndbm_store(a, b, c, d)
01248 
01249 /* Prototype the DB calls. */
01250 int      __db_ndbm_clearerr __P((DBM *));
01251 void     __db_ndbm_close __P((DBM *));
01252 int      __db_ndbm_delete __P((DBM *, datum));
01253 int      __db_ndbm_dirfno __P((DBM *));
01254 int      __db_ndbm_error __P((DBM *));
01255 datum    __db_ndbm_fetch __P((DBM *, datum));
01256 datum    __db_ndbm_firstkey __P((DBM *));
01257 datum    __db_ndbm_nextkey __P((DBM *));
01258 DBM     *__db_ndbm_open __P((const char *, int, int));
01259 int      __db_ndbm_pagfno __P((DBM *));
01260 int      __db_ndbm_rdonly __P((DBM *));
01261 int      __db_ndbm_store __P((DBM *, datum, datum, int));
01262 
01263 /*******************************************************
01264  * Hsearch historic interface.
01265  *******************************************************/
01266 typedef enum {
01267         FIND, ENTER
01268 } ACTION;
01269 
01270 typedef struct entry {
01271         char *key;
01272         char *data;
01273 } ENTRY;
01274 
01275 /*
01276  * Translate HSEARCH calls into DB calls so that DB doesn't step on the
01277  * application's name space.
01278  */
01279 #define hcreate(a)      __db_hcreate(a)
01280 #define hdestroy        __db_hdestroy
01281 #define hsearch(a, b)   __db_hsearch(a, b)
01282 
01283 /* Prototype the DB calls. */
01284 int      __db_hcreate __P((size_t));
01285 void     __db_hdestroy __P((void));
01286 ENTRY   *__db_hsearch __P((ENTRY, ACTION));
01287 #endif /* DB_DBM_HSEARCH */
01288 
01289 /*
01290  * XXX
01291  * MacOS: Reset Metrowerks C enum sizes.
01292  */
01293 #ifdef __MWERKS__
01294 #pragma enumsalwaysint reset
01295 #endif
01296 
01297 #if defined(__cplusplus)
01298 }
01299 #endif
01300 
01301 #endif /* !_DB_H_ */

Generated on Sun Mar 12 23:56:28 2006 for ScriptBasic by  doxygen 1.4.6-NO