source: trunk/third/db/build_vms/db.h @ 17055

Revision 17055, 47.0 KB checked in by ghudson, 23 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r17054, which included commits to RCS files with non-trunk default branches.
Line 
1/* DO NOT EDIT: automatically built by dist/distrib. */
2/*-
3 * See the file LICENSE for redistribution information.
4 *
5 * Copyright (c) 1996, 1997, 1998, 1999, 2000
6 *      Sleepycat Software.  All rights reserved.
7 *
8 *      $Id: db.h,v 1.1.1.2 2002-02-11 16:30:22 ghudson Exp $
9 */
10
11#ifndef _DB_H_
12#define _DB_H_
13
14#ifndef __NO_SYSTEM_INCLUDES
15#include <sys/types.h>
16
17#include <stdio.h>
18#endif
19
20#if defined(__cplusplus)
21extern "C" {
22#endif
23
24/*
25 * XXX
26 * MacOS: ensure that Metrowerks C makes enumeration types int sized.
27 */
28#ifdef __MWERKS__
29#pragma enumsalwaysint on
30#endif
31
32/*
33 * XXX
34 * Handle function prototypes and the keyword "const".  This steps on name
35 * space that DB doesn't control, but all of the other solutions are worse.
36 *
37 * XXX
38 * While Microsoft's compiler is ANSI C compliant, it doesn't have _STDC_
39 * defined by default, you specify a command line flag or #pragma to turn
40 * it on.  Don't do that, however, because some of Microsoft's own header
41 * files won't compile.
42 */
43#undef  __P
44#if defined(__STDC__) || defined(__cplusplus) || defined(_MSC_VER)
45#define __P(protos)     protos          /* ANSI C prototypes */
46#else
47#define const
48#define __P(protos)     ()              /* K&R C preprocessor */
49#endif
50
51/*
52 * !!!
53 * DB needs basic information about specifically sized types.  If they're
54 * not provided by the system, typedef them here.
55 *
56 * We protect them against multiple inclusion using __BIT_TYPES_DEFINED__,
57 * as does BIND and Kerberos, since we don't know for sure what #include
58 * files the user is using.
59 *
60 * !!!
61 * We also provide the standard u_int, u_long etc., if they're not provided
62 * by the system.
63 */
64#ifndef __BIT_TYPES_DEFINED__
65#define __BIT_TYPES_DEFINED__
66typedef unsigned char u_int8_t;
67typedef short int16_t;
68typedef unsigned short u_int16_t;
69typedef int int32_t;
70typedef unsigned int u_int32_t;
71#endif
72
73
74#define DB_VERSION_MAJOR        3
75#define DB_VERSION_MINOR        1
76#define DB_VERSION_PATCH        17
77#define DB_VERSION_STRING       "Sleepycat Software: Berkeley DB 3.1.17: (July 31, 2000)"
78
79typedef u_int32_t       db_pgno_t;      /* Page number type. */
80typedef u_int16_t       db_indx_t;      /* Page offset type. */
81#define DB_MAX_PAGES    0xffffffff      /* >= # of pages in a file */
82
83typedef u_int32_t       db_recno_t;     /* Record number type. */
84#define DB_MAX_RECORDS  0xffffffff      /* >= # of records in a tree */
85
86/* Forward structure declarations, so applications get type checking. */
87struct __db;            typedef struct __db DB;
88#ifdef DB_DBM_HSEARCH
89                        typedef struct __db DBM;
90#endif
91struct __db_bt_stat;    typedef struct __db_bt_stat DB_BTREE_STAT;
92struct __db_dbt;        typedef struct __db_dbt DBT;
93struct __db_env;        typedef struct __db_env DB_ENV;
94struct __db_h_stat;     typedef struct __db_h_stat DB_HASH_STAT;
95struct __db_ilock;      typedef struct __db_ilock DB_LOCK_ILOCK;
96struct __db_lock_stat;  typedef struct __db_lock_stat DB_LOCK_STAT;
97struct __db_lock_u;     typedef struct __db_lock_u DB_LOCK;
98struct __db_lockreq;    typedef struct __db_lockreq DB_LOCKREQ;
99struct __db_log_stat;   typedef struct __db_log_stat DB_LOG_STAT;
100struct __db_lsn;        typedef struct __db_lsn DB_LSN;
101struct __db_mpool_finfo;typedef struct __db_mpool_finfo DB_MPOOL_FINFO;
102struct __db_mpool_fstat;typedef struct __db_mpool_fstat DB_MPOOL_FSTAT;
103struct __db_mpool_stat; typedef struct __db_mpool_stat DB_MPOOL_STAT;
104struct __db_mpoolfile;  typedef struct __db_mpoolfile DB_MPOOLFILE;
105struct __db_qam_stat;   typedef struct __db_qam_stat DB_QUEUE_STAT;
106struct __db_txn;        typedef struct __db_txn DB_TXN;
107struct __db_txn_active; typedef struct __db_txn_active DB_TXN_ACTIVE;
108struct __db_txn_stat;   typedef struct __db_txn_stat DB_TXN_STAT;
109struct __dbc;           typedef struct __dbc DBC;
110struct __dbc_internal;  typedef struct __dbc_internal DBC_INTERNAL;
111struct __fh_t;          typedef struct __fh_t DB_FH;
112struct __key_range;     typedef struct __key_range DB_KEY_RANGE;
113
114/* Key/data structure -- a Data-Base Thang. */
115struct __db_dbt {
116        /*
117         * data/size must be fields 1 and 2 for DB 1.85 compatibility.
118         */
119        void     *data;                 /* Key/data */
120        u_int32_t size;                 /* key/data length */
121
122        u_int32_t ulen;                 /* RO: length of user buffer. */
123        u_int32_t dlen;                 /* RO: get/put record length. */
124        u_int32_t doff;                 /* RO: get/put record offset. */
125
126#define DB_DBT_ISSET    0x001           /* Lower level calls set value. */
127#define DB_DBT_MALLOC   0x002           /* Return in malloc'd memory. */
128#define DB_DBT_PARTIAL  0x004           /* Partial put/get. */
129#define DB_DBT_REALLOC  0x008           /* Return in realloc'd memory. */
130#define DB_DBT_USERMEM  0x010           /* Return in user's memory. */
131#define DB_DBT_DUPOK    0x020           /* Insert if duplicate. */
132        u_int32_t flags;
133
134        void     *app_private;          /* Key/data application private. */
135};
136
137/*
138 * Flags understood by both db_env_create and db_create.
139 */
140#define DB_CXX_NO_EXCEPTIONS  0x000001  /* C++: return error values. */
141
142/*
143 * Flags understood by only db_env_create.
144 */
145#define DB_CLIENT             0x000002  /* Open for a client environment. */
146
147/*
148 * Flags understood by only db_create.
149 */
150#define DB_XA_CREATE          0x000002  /* Open in an XA environment. */
151
152/*
153 * Flags understood by both DBENV->open and DB->open.
154 */
155#define DB_CREATE             0x000001  /* Create file as necessary. */
156#define DB_NOMMAP             0x000002  /* Don't mmap underlying file. */
157#define DB_THREAD             0x000004  /* Applications are threaded. */
158
159/*
160 * Flags understood by both DBENV->open and DBENV->remove.
161 */
162#define DB_FORCE              0x000008  /* Force (anything). */
163#define DB_INIT_CDB           0x000010  /* Concurrent Access Methods. */
164#define DB_INIT_LOCK          0x000020  /* Initialize locking. */
165#define DB_INIT_LOG           0x000040  /* Initialize logging. */
166#define DB_INIT_MPOOL         0x000080  /* Initialize mpool. */
167#define DB_INIT_TXN           0x000100  /* Initialize transactions. */
168#define DB_RECOVER            0x000200  /* Run normal recovery. */
169#define DB_RECOVER_FATAL      0x000400  /* Run catastrophic recovery. */
170#define DB_SYSTEM_MEM         0x000800  /* Use system-backed memory. */
171#define DB_TXN_NOSYNC         0x001000  /* Do not sync log on commit. */
172#define DB_USE_ENVIRON        0x002000  /* Use the environment. */
173#define DB_USE_ENVIRON_ROOT   0x004000  /* Use the environment if root. */
174
175/*
176 * Flags understood by only DBENV->open.
177 */
178#define DB_LOCKDOWN           0x008000  /* Lock memory into physical core. */
179#define DB_PRIVATE            0x010000  /* DB_ENV is process local. */
180
181/*
182 * Flags understood by DBENV->txn_begin.
183 */
184/*      DB_TXN_NOSYNC         0x001000     Do not sync log on commit. */
185#define DB_TXN_SYNC           0x000001  /* Always sync log on commit. */
186#define DB_TXN_NOWAIT         0x000002  /* Do not wait for locks in this TXN. */
187
188/*
189 * Flags understood by only DB->open.
190 */
191#define DB_EXCL               0x000008  /* Exclusive open (O_EXCL). */
192#define DB_RDONLY             0x000010  /* Read-only (O_RDONLY). */
193#define DB_TRUNCATE           0x000020  /* Discard existing DB (O_TRUNC). */
194#define DB_FCNTL_LOCKING      0x000040  /* Undocumented: fcntl(2) locking. */
195#define DB_ODDFILESIZE        0x000080  /* Undocumented: trunc. to N*pgsize. */
196#define DB_RDWRMASTER         0x000100  /* Undoc: allow subdb master open R/W */
197
198/*
199 * Flags understood by DB->verify.
200 *
201 * !!!
202 * These must not go over 0x8000, or they will collide with the flags
203 * used by __bam_vrfy_subtree.
204 */
205#define DB_AGGRESSIVE         0x0001  /* Salvage anything which might be data.*/
206#define DB_NOORDERCHK         0x0002  /* Skip order check; subdb w/ user func */
207#define DB_ORDERCHKONLY       0x0004  /* Only perform an order check on subdb */
208#define DB_PR_PAGE            0x0008  /* Show page contents (-da). */
209#define DB_PR_HEADERS         0x0010  /* Show only page headers (-dh). */
210#define DB_PR_RECOVERYTEST    0x0020  /* Recovery test (-dr). */
211#define DB_SALVAGE            0x0040  /* Salvage what looks like data. */
212#define DB_VRFY_FLAGMASK      0xffff  /* For masking above flags. */
213
214/*
215 * Flags understood by only DB->set_feedback's callback.
216 */
217/*      DB_RECOVER            0x000200     Running recovery. */
218#define DB_UPGRADE            0x000001  /* Upgrading. */
219
220/*
221 * Deadlock detector modes; used in the DBENV structure to configure the
222 * locking subsystem.
223 */
224#define DB_LOCK_NORUN           0
225#define DB_LOCK_DEFAULT         1       /* Default policy. */
226#define DB_LOCK_OLDEST          2       /* Abort oldest transaction. */
227#define DB_LOCK_RANDOM          3       /* Abort random transaction. */
228#define DB_LOCK_YOUNGEST        4       /* Abort youngest transaction. */
229
230/*
231 * Flags understood by only DB->set_flags.
232 */
233#define DB_DUP                  0x0001  /* Btree, Hash: duplicate keys. */
234#define DB_DUPSORT              0x0002  /* Btree, Hash: duplicate keys. */
235#define DB_RECNUM               0x0004  /* Btree: record numbers. */
236#define DB_RENUMBER             0x0008  /* Recno: renumber on insert/delete. */
237#define DB_REVSPLITOFF          0x0010  /* Btree: turn off reverse splits. */
238#define DB_SNAPSHOT             0x0020  /* Recno: snapshot the input. */
239
240/*
241 * Flags understood only by DB->join.
242 */
243#define DB_JOIN_NOSORT          0x0001  /* Don't try to optimize join. */
244
245typedef enum {
246        DB_TXN_ABORT,
247        DB_TXN_BACKWARD_ROLL,
248        DB_TXN_FORWARD_ROLL,
249        DB_TXN_OPENFILES
250} db_recops;
251
252#define DB_UNDO(op)     ((op) == DB_TXN_ABORT || (op) == DB_TXN_BACKWARD_ROLL)
253#define DB_REDO(op)     ((op) == DB_TXN_FORWARD_ROLL)
254
255struct __db_env {
256        /*******************************************************
257         * Public: owned by the application.
258         *******************************************************/
259        FILE            *db_errfile;    /* Error message file stream. */
260        const char      *db_errpfx;     /* Error message prefix. */
261                                        /* Callbacks. */
262        void (*db_errcall) __P((const char *, char *));
263        void (*db_feedback) __P((DB_ENV *, int, int));
264        void (*db_paniccall) __P((DB_ENV *, int));
265        int  (*db_recovery_init) __P((DB_ENV *));
266
267        /*
268         * Currently, the verbose list is a bit field with room for 32
269         * entries.  There's no reason that it needs to be limited, if
270         * there are ever more than 32 entries, convert to a bit array.
271         */
272#define DB_VERB_CHKPOINT        0x0001  /* List checkpoints. */
273#define DB_VERB_DEADLOCK        0x0002  /* Deadlock detection information. */
274#define DB_VERB_RECOVERY        0x0004  /* Recovery information. */
275#define DB_VERB_WAITSFOR        0x0008  /* Dump waits-for table. */
276        u_int32_t        verbose;       /* Verbose output. */
277
278        /* Locking. */
279        u_int8_t        *lk_conflicts;  /* Two dimensional conflict matrix. */
280        u_int32_t        lk_modes;      /* Number of lock modes in table. */
281        u_int32_t        lk_max;        /* Maximum number of locks. */
282        u_int32_t        lk_detect;     /* Deadlock detect on all conflicts. */
283
284        /* Logging. */
285        u_int32_t        lg_bsize;      /* Buffer size. */
286        u_int32_t        lg_max;        /* Maximum file size. */
287
288        /* Memory pool. */
289        u_int32_t        mp_gbytes;     /* Cachesize: GB. */
290        u_int32_t        mp_bytes;      /* Cachesize: Bytes. */
291        size_t           mp_size;       /* DEPRECATED: Cachesize: bytes. */
292        int              mp_ncache;     /* Number of cache regions. */
293        size_t           mp_mmapsize;   /* Maximum file size for mmap. */
294
295        /* Transactions. */
296        u_int32_t        tx_max;        /* Maximum number of transactions. */
297        time_t           tx_timestamp;  /* Recover to specific timestamp. */
298        int (*tx_recover)               /* Dispatch function for recovery. */
299            __P((DB_ENV *, DBT *, DB_LSN *, db_recops, void *));
300
301        /*******************************************************
302         * Private: owned by DB.
303         *******************************************************/
304        int              db_panic;      /* Panic causing errno. */
305
306        /* User files, paths. */
307        char            *db_home;       /* Database home. */
308        char            *db_log_dir;    /* Database log file directory. */
309        char            *db_tmp_dir;    /* Database tmp file directory. */
310
311        char           **db_data_dir;   /* Database data file directories. */
312        int              data_cnt;      /* Database data file slots. */
313        int              data_next;     /* Next Database data file slot. */
314
315        int              db_mode;       /* Default open permissions. */
316
317        void            *reginfo;       /* REGINFO structure reference. */
318        DB_FH           *lockfhp;       /* fcntl(2) locking file handle. */
319        long             shm_key;       /* shmget(2) key. */
320
321        void            *lg_handle;     /* Log handle. */
322
323        void            *lk_handle;     /* Lock handle. */
324
325        void            *mp_handle;     /* Mpool handle. */
326
327        void            *tx_handle;     /* Txn handle. */
328
329        int           (**dtab)          /* Dispatch table */
330                            __P((DB_ENV *, DBT *, DB_LSN *, db_recops, void *));
331        size_t           dtab_size;     /* Slots in the dispatch table. */
332
333        void            *cl_handle;     /* RPC: remote client handle. */
334        long             cl_id;         /* RPC: Remote client env id. */
335
336        int              dblocal_ref;   /* DB_ENV_DBLOCAL: reference count. */
337
338        /*
339         * XA support.
340         *
341         * !!!
342         * Explicit representations of structures in queue.h.
343         *
344         * TAILQ_ENTRY(__db_env);
345         */
346        struct {
347                struct __db_env *tqe_next;
348                struct __db_env **tqe_prev;
349        } links;
350        int              xa_rmid;       /* XA Resource Manager ID. */
351        DB_TXN          *xa_txn;        /* XA Current transaction. */
352
353        void    *cj_internal;           /* C++/Java private. */
354
355                                        /* Methods. */
356        int  (*close) __P((DB_ENV *, u_int32_t));
357        void (*err) __P((const DB_ENV *, int, const char *, ...));
358        void (*errx) __P((const DB_ENV *, const char *, ...));
359        int  (*open) __P((DB_ENV *, const char *, u_int32_t, int));
360        int  (*remove) __P((DB_ENV *, const char *, u_int32_t));
361        int  (*set_data_dir) __P((DB_ENV *, const char *));
362        void (*set_errcall) __P((DB_ENV *, void (*)(const char *, char *)));
363        void (*set_errfile) __P((DB_ENV *, FILE *));
364        void (*set_errpfx) __P((DB_ENV *, const char *));
365        int  (*set_feedback) __P((DB_ENV *, void (*)(DB_ENV *, int, int)));
366        int  (*set_paniccall) __P((DB_ENV *, void (*)(DB_ENV *, int)));
367        int  (*set_recovery_init) __P((DB_ENV *, int (*)(DB_ENV *)));
368        int  (*set_server) __P((DB_ENV *, char *, long, long, u_int32_t));
369        int  (*set_shm_key) __P((DB_ENV *, long));
370        int  (*set_tmp_dir) __P((DB_ENV *, const char *));
371        int  (*set_verbose) __P((DB_ENV *, u_int32_t, int));
372
373        int  (*set_lg_bsize) __P((DB_ENV *, u_int32_t));
374        int  (*set_lg_dir) __P((DB_ENV *, const char *));
375        int  (*set_lg_max) __P((DB_ENV *, u_int32_t));
376
377        int  (*set_lk_conflicts) __P((DB_ENV *, u_int8_t *, int));
378        int  (*set_lk_detect) __P((DB_ENV *, u_int32_t));
379        int  (*set_lk_max) __P((DB_ENV *, u_int32_t));
380
381        int  (*set_mp_mmapsize) __P((DB_ENV *, size_t));
382        int  (*set_cachesize) __P((DB_ENV *, u_int32_t, u_int32_t, int));
383
384        int  (*set_tx_max) __P((DB_ENV *, u_int32_t));
385        int  (*set_tx_recover) __P((DB_ENV *,
386                int (*)(DB_ENV *, DBT *, DB_LSN *, db_recops, void *)));
387        int  (*set_tx_timestamp) __P((DB_ENV *, time_t *));
388
389#ifdef CONFIG_TEST
390#define DB_TEST_PREOPEN          1      /* before __os_open */
391#define DB_TEST_POSTOPEN         2      /* after __os_open */
392#define DB_TEST_POSTLOGMETA      3      /* after logging meta in btree */
393#define DB_TEST_POSTLOG          4      /* after logging all pages */
394#define DB_TEST_POSTSYNC         5      /* after syncing the log */
395#define DB_TEST_PRERENAME        6      /* before __os_rename */
396#define DB_TEST_POSTRENAME       7      /* after __os_rename */
397        int              test_abort;    /* Abort value for testing. */
398        int              test_copy;     /* Copy value for testing. */
399#endif
400
401#define DB_ENV_CDB              0x00001 /* DB_INIT_CDB. */
402#define DB_ENV_CREATE           0x00002 /* DB_CREATE set. */
403#define DB_ENV_DBLOCAL          0x00004 /* DB_ENV allocated for private DB. */
404#define DB_ENV_LOCKDOWN         0x00008 /* DB_LOCKDOWN set. */
405#define DB_ENV_NOMMAP           0x00010 /* DB_NOMMAP set. */
406#define DB_ENV_OPEN_CALLED      0x00020 /* DBENV->open called (paths valid). */
407#define DB_ENV_PRIVATE          0x00040 /* DB_PRIVATE set. */
408#define DB_ENV_RPCCLIENT        0x00080 /* DB_CLIENT set. */
409#define DB_ENV_STANDALONE       0x00100 /* Test: freestanding environment. */
410#define DB_ENV_SYSTEM_MEM       0x00200 /* DB_SYSTEM_MEM set. */
411#define DB_ENV_THREAD           0x00400 /* DB_THREAD set. */
412#define DB_ENV_TXN_NOSYNC       0x00800 /* DB_TXN_NOSYNC set. */
413#define DB_ENV_USER_ALLOC       0x01000 /* User allocated the structure. */
414        u_int32_t        flags;         /* Flags. */
415};
416
417/*******************************************************
418 * Access methods.
419 *******************************************************/
420/*
421 * !!!
422 * Changes here must be reflected in java/src/com/sleepycat/db/Db.java.
423 */
424typedef enum {
425        DB_BTREE=1,
426        DB_HASH,
427        DB_RECNO,
428        DB_QUEUE,
429        DB_UNKNOWN                      /* Figure it out on open. */
430} DBTYPE;
431
432#define DB_BTREEVERSION 8               /* Current btree version. */
433#define DB_BTREEOLDVER  6               /* Oldest btree version supported. */
434#define DB_BTREEMAGIC   0x053162
435
436#define DB_HASHVERSION  7               /* Current hash version. */
437#define DB_HASHOLDVER   4               /* Oldest hash version supported. */
438#define DB_HASHMAGIC    0x061561
439
440#define DB_QAMVERSION   2               /* Current queue version. */
441#define DB_QAMOLDVER    1               /* Oldest queue version supported. */
442#define DB_QAMMAGIC     0x042253
443
444#define DB_LOGVERSION   2               /* Current log version. */
445#define DB_LOGOLDVER    2               /* Oldest log version supported. */
446#define DB_LOGMAGIC     0x040988
447
448/*
449 * DB access method and cursor operation values.  Each value is an operation
450 * code to which additional bit flags are added.
451 */
452#define DB_AFTER         1              /* c_put() */
453#define DB_APPEND        2              /* put() */
454#define DB_BEFORE        3              /* c_put() */
455#define DB_CACHED_COUNTS 4              /* stat() */
456#define DB_CHECKPOINT    5              /* log_put(), log_get() */
457#define DB_CONSUME       6              /* c_get() */
458#define DB_CURLSN        7              /* log_put() */
459#define DB_CURRENT       8              /* c_get(), c_put(), log_get() */
460#define DB_FIRST         9              /* c_get(), log_get() */
461#define DB_FLUSH        10              /* log_put() */
462#define DB_GET_BOTH     11              /* get(), c_get() */
463#define DB_GET_BOTHC    12              /* c_get() (internal) */
464#define DB_GET_RECNO    13              /* c_get() */
465#define DB_JOIN_ITEM    14              /* c_get(); do not do primary lookup */
466#define DB_KEYFIRST     15              /* c_put() */
467#define DB_KEYLAST      16              /* c_put() */
468#define DB_LAST         17              /* c_get(), log_get() */
469#define DB_NEXT         18              /* c_get(), log_get() */
470#define DB_NEXT_DUP     19              /* c_get() */
471#define DB_NEXT_NODUP   20              /* c_get() */
472#define DB_NODUPDATA    21              /* put(), c_put() */
473#define DB_NOOVERWRITE  22              /* put() */
474#define DB_NOSYNC       23              /* close() */
475#define DB_POSITION     24              /* c_dup() */
476#define DB_POSITIONI    25              /* c_dup() (internal) */
477#define DB_PREV         26              /* c_get(), log_get() */
478#define DB_PREV_NODUP   27              /* c_get(), log_get() */
479#define DB_RECORDCOUNT  28              /* stat() */
480#define DB_SET          29              /* c_get(), log_get() */
481#define DB_SET_RANGE    30              /* c_get() */
482#define DB_SET_RECNO    31              /* get(), c_get() */
483#define DB_WRITECURSOR  32              /* cursor() */
484#define DB_WRITELOCK    33              /* cursor() (internal) */
485
486/* This has to change when the max opcode hits 255. */
487#define DB_OPFLAGS_MASK 0x000000ff      /* Mask for operations flags. */
488#define DB_RMW          0x80000000      /* Acquire write flag immediately. */
489
490/*
491 * DB (user visible) error return codes.
492 *
493 * !!!
494 * Changes to any of the user visible error return codes must be reflected
495 * in java/src/com/sleepycat/db/Db.java.
496 *
497 * !!!
498 * For source compatibility with DB 2.X deadlock return (EAGAIN), use the
499 * following:
500 *      #include <errno.h>
501 *      #define DB_LOCK_DEADLOCK EAGAIN
502 *
503 * !!!
504 * We don't want our error returns to conflict with other packages where
505 * possible, so pick a base error value that's hopefully not common.
506 */
507#define DB_INCOMPLETE           (-30999)/* Sync didn't finish. */
508#define DB_KEYEMPTY             (-30998)/* Key/data deleted or never created. */
509#define DB_KEYEXIST             (-30997)/* The key/data pair already exists. */
510#define DB_LOCK_DEADLOCK        (-30996)/* Deadlock. */
511#define DB_LOCK_NOTGRANTED      (-30995)/* Lock unavailable. */
512#define DB_NOSERVER             (-30994)/* Server panic return. */
513#define DB_NOSERVER_HOME        (-30993)/* Bad home sent to server. */
514#define DB_NOSERVER_ID          (-30992)/* Bad ID sent to server. */
515#define DB_NOTFOUND             (-30991)/* Key/data pair not found (EOF). */
516#define DB_OLD_VERSION          (-30990)/* Out-of-date version. */
517#define DB_RUNRECOVERY          (-30989)/* Panic return. */
518#define DB_VERIFY_BAD           (-30988)/* Verify failed; bad format. */
519
520/* DB (private) error return codes. */
521#define DB_DELETED              (-30899)/* Recovery file marked deleted. */
522#define DB_NEEDSPLIT            (-30898)/* Page needs to be split. */
523#define DB_SWAPBYTES            (-30897)/* Database needs byte swapping. */
524#define DB_TXN_CKP              (-30896)/* Encountered ckp record in log. */
525#define DB_VERIFY_FATAL         (-30895)/* Fatal: DB->verify cannot proceed. */
526
527#define DB_FILE_ID_LEN          20      /* DB file ID length. */
528
529/* DB access method description structure. */
530struct __db {
531        /*******************************************************
532         * Public: owned by the application.
533         *******************************************************/
534        u_int32_t pgsize;               /* Database logical page size. */
535
536                                        /* Callbacks. */
537        void (*db_feedback) __P((DB *, int, int));
538        void *(*db_malloc) __P((size_t));
539        void *(*db_realloc) __P((void *, size_t));
540        int (*dup_compare) __P((const DBT *, const DBT *));
541
542        /*******************************************************
543         * Private: owned by DB.
544         *******************************************************/
545        DB_ENV  *dbenv;                 /* Backing environment. */
546
547        DBTYPE   type;                  /* DB access method type. */
548
549        DB_MPOOLFILE *mpf;              /* Backing buffer pool. */
550
551        void    *mutexp;                /* Synchronization for free threading */
552
553        u_int8_t fileid[DB_FILE_ID_LEN];/* File's unique ID for locking. */
554
555#define DB_LOGFILEID_INVALID    -1
556        int32_t  log_fileid;            /* File's unique ID for logging. */
557        db_pgno_t meta_pgno;            /* Meta page number */
558        DB_TXN  *open_txn;              /* Transaction to protect creates. */
559
560        long     cl_id;                 /* RPC: remote client id. */
561
562        /*
563         * !!!
564         * Some applications use DB but implement their own locking outside of
565         * DB.  If they're using fcntl(2) locking on the underlying database
566         * file, and we open and close a file descriptor for that file, we will
567         * discard their locks.  The DB_FCNTL_LOCKING flag to DB->open is an
568         * undocumented interface to support this usage which leaves any file
569         * descriptors we open until DB->close.  This will only work with the
570         * DB->open interface and simple caches, e.g., creating a transaction
571         * thread may open/close file descriptors this flag doesn't protect.
572         * Locking with fcntl(2) on a file that you don't own is a very, very
573         * unsafe thing to do.  'Nuff said.
574         */
575        DB_FH   *saved_open_fhp;        /* Saved file handle. */
576
577        /*
578         * Linked list of DBP's, used in the log's dbentry table
579         * to keep track of all open db handles for a given log id.
580         * !!!
581         * Explicit representations of structures in queue.h.
582         *
583         * TAILQ_ENTRY(__db) links;
584         */
585        struct {
586                struct __db *tqe_next;
587                struct __db **tqe_prev;
588        } links;
589
590        /*
591         * Cursor queues.
592         *
593         * !!!
594         * Explicit representations of structures in queue.h.
595         *
596         * TAILQ_HEAD(free_queue, __dbc);
597         * TAILQ_HEAD(active_queue, __dbc);
598         * TAILQ_HEAD(join_queue, __dbc);
599         */
600        struct {
601                struct __dbc *tqh_first;
602                struct __dbc **tqh_last;
603        } free_queue;
604        struct {
605                struct __dbc *tqh_first;
606                struct __dbc **tqh_last;
607        } active_queue;
608        struct {
609                struct __dbc *tqh_first;
610                struct __dbc **tqh_last;
611        } join_queue;
612
613        void    *bt_internal;           /* Btree/Recno access method private. */
614        void    *cj_internal;           /* C++/Java private. */
615        void    *h_internal;            /* Hash access method private. */
616        void    *q_internal;            /* Queue access method private. */
617        void    *xa_internal;           /* XA private. */
618
619                                        /* Methods. */
620        int  (*close) __P((DB *, u_int32_t));
621        int  (*cursor) __P((DB *, DB_TXN *, DBC **, u_int32_t));
622        int  (*del) __P((DB *, DB_TXN *, DBT *, u_int32_t));
623        void (*err) __P((DB *, int, const char *, ...));
624        void (*errx) __P((DB *, const char *, ...));
625        int  (*fd) __P((DB *, int *));
626        int  (*get) __P((DB *, DB_TXN *, DBT *, DBT *, u_int32_t));
627        int  (*get_byteswapped) __P((DB *));
628        DBTYPE
629             (*get_type) __P((DB *));
630        int  (*join) __P((DB *, DBC **, DBC **, u_int32_t));
631        int  (*key_range) __P((DB *,
632                DB_TXN *, DBT *, DB_KEY_RANGE *, u_int32_t));
633        int  (*open) __P((DB *,
634                const char *, const char *, DBTYPE, u_int32_t, int));
635        int  (*put) __P((DB *, DB_TXN *, DBT *, DBT *, u_int32_t));
636        int  (*remove) __P((DB *, const char *, const char *, u_int32_t));
637        int  (*rename) __P((DB *,
638                const char *, const char *, const char *, u_int32_t));
639        int  (*set_cachesize) __P((DB *, u_int32_t, u_int32_t, int));
640        int  (*set_dup_compare) __P((DB *, int (*)(const DBT *, const DBT *)));
641        void (*set_errcall) __P((DB *, void (*)(const char *, char *)));
642        void (*set_errfile) __P((DB *, FILE *));
643        void (*set_errpfx) __P((DB *, const char *));
644        int  (*set_feedback) __P((DB *, void (*)(DB *, int, int)));
645        int  (*set_flags) __P((DB *, u_int32_t));
646        int  (*set_lorder) __P((DB *, int));
647        int  (*set_malloc) __P((DB *, void *(*)(size_t)));
648        int  (*set_pagesize) __P((DB *, u_int32_t));
649        int  (*set_paniccall) __P((DB *, void (*)(DB_ENV *, int)));
650        int  (*set_realloc) __P((DB *, void *(*)(void *, size_t)));
651        int  (*stat) __P((DB *, void *, void *(*)(size_t), u_int32_t));
652        int  (*sync) __P((DB *, u_int32_t));
653        int  (*upgrade) __P((DB *, const char *, u_int32_t));
654        int  (*verify) __P((DB *,
655            const char *, const char *, FILE *, u_int32_t));
656
657        int  (*set_bt_compare) __P((DB *, int (*)(const DBT *, const DBT *)));
658        int  (*set_bt_maxkey) __P((DB *, u_int32_t));
659        int  (*set_bt_minkey) __P((DB *, u_int32_t));
660        int  (*set_bt_prefix) __P((DB *, size_t (*)(const DBT *, const DBT *)));
661
662        int  (*set_h_ffactor) __P((DB *, u_int32_t));
663        int  (*set_h_hash) __P((DB *, u_int32_t (*)(const void *, u_int32_t)));
664        int  (*set_h_nelem) __P((DB *, u_int32_t));
665
666        int  (*set_re_delim) __P((DB *, int));
667        int  (*set_re_len) __P((DB *, u_int32_t));
668        int  (*set_re_pad) __P((DB *, int));
669        int  (*set_re_source) __P((DB *, const char *));
670
671#define DB_OK_BTREE     0x01
672#define DB_OK_HASH      0x02
673#define DB_OK_QUEUE     0x04
674#define DB_OK_RECNO     0x08
675        u_int32_t       am_ok;          /* Legal AM choices. */
676
677#define DB_AM_DISCARD   0x00001         /* Discard any cached pages. */
678#define DB_AM_DUP       0x00002         /* DB_DUP. */
679#define DB_AM_DUPSORT   0x00004         /* DB_DUPSORT. */
680#define DB_AM_INMEM     0x00008         /* In-memory; no sync on close. */
681#define DB_AM_PGDEF     0x00010         /* Page size was defaulted. */
682#define DB_AM_RDONLY    0x00020         /* Database is readonly. */
683#define DB_AM_RECOVER   0x00040         /* DBP opened by recovery routine. */
684#define DB_AM_SUBDB     0x00080         /* Subdatabases supported. */
685#define DB_AM_SWAP      0x00100         /* Pages need to be byte-swapped. */
686#define DB_BT_RECNUM    0x00200         /* DB_RECNUM. */
687#define DB_BT_REVSPLIT  0x00400         /* DB_REVSPLITOFF. */
688#define DB_DBM_ERROR    0x00800         /* Error in DBM/NDBM database. */
689#define DB_OPEN_CALLED  0x01000         /* DB->open called. */
690#define DB_RE_DELIMITER 0x02000         /* Variablen length delimiter set. */
691#define DB_RE_FIXEDLEN  0x04000         /* Fixed-length records. */
692#define DB_RE_PAD       0x08000         /* Fixed-length record pad. */
693#define DB_RE_RENUMBER  0x10000         /* DB_RENUMBER. */
694#define DB_RE_SNAPSHOT  0x20000         /* DB_SNAPSHOT. */
695        u_int32_t flags;
696};
697
698/*
699 * DB_LOCK_ILOCK --
700 *      Internal DB access method lock.
701 */
702struct __db_ilock {
703        db_pgno_t pgno;                 /* Page being locked. */
704        u_int8_t fileid[DB_FILE_ID_LEN];/* File id. */
705#define DB_RECORD_LOCK  1
706#define DB_PAGE_LOCK    2
707        u_int8_t type;                  /* Record or Page lock */
708};
709
710/*
711 * DB_LOCK --
712 *      The structure is allocated by the caller and filled in during a
713 *      lock_get request (or a lock_vec/DB_LOCK_GET).
714 */
715struct __db_lock_u {
716        size_t          off;            /* Offset of the lock in the region */
717        u_int32_t       ndx;            /* Index of the object referenced by
718                                         * this lock; used for locking. */
719        u_int32_t       gen;            /* Generation number of this lock. */
720};
721
722/* Cursor description structure. */
723struct __dbc {
724        DB *dbp;                        /* Related DB access method. */
725        DB_TXN   *txn;                  /* Associated transaction. */
726
727        /*
728         * !!!
729         * Explicit representations of structures in queue.h.
730         *
731         * TAILQ_ENTRY(__dbc) links;    Active/free cursor queues.
732         */
733        struct {
734                DBC *tqe_next;
735                DBC **tqe_prev;
736        } links;
737
738        DBC *opd;                       /* Off-page duplicate cursor. */
739
740        DBT       rkey;                 /* Returned key. */
741        DBT       rdata;                /* Returned data. */
742
743        u_int32_t lid;                  /* Default process' locker id. */
744        u_int32_t locker;               /* Locker for this operation. */
745        DBT       lock_dbt;             /* DBT referencing lock. */
746        DB_LOCK_ILOCK lock;             /* Object to be locked. */
747        DB_LOCK   mylock;               /* Lock held on this cursor. */
748
749        long      cl_id;                /* Remote client id. */
750
751        DBTYPE    dbtype;               /* Cursor type. */
752
753        DBC_INTERNAL *internal;         /* Access method private. */
754
755        int (*c_close) __P((DBC *));    /* Methods: public. */
756        int (*c_count) __P((DBC *, db_recno_t *, u_int32_t));
757        int (*c_del) __P((DBC *, u_int32_t));
758        int (*c_dup) __P((DBC *, DBC **, u_int32_t));
759        int (*c_get) __P((DBC *, DBT *, DBT *, u_int32_t));
760        int (*c_put) __P((DBC *, DBT *, DBT *, u_int32_t));
761
762                                        /* Methods: private. */
763        int (*c_am_close) __P((DBC *, db_pgno_t, int *));
764        int (*c_am_del) __P((DBC *));
765        int (*c_am_destroy) __P((DBC *));
766        int (*c_am_get) __P((DBC *, DBT *, DBT *, u_int32_t, db_pgno_t *));
767        int (*c_am_put) __P((DBC *, DBT *, DBT *, u_int32_t, db_pgno_t *));
768        int (*c_am_writelock) __P((DBC *));
769
770#define DBC_ACTIVE      0x001           /* Cursor is being used. */
771#define DBC_OPD         0x002           /* Cursor references off-page dups. */
772#define DBC_RECOVER     0x004           /* Cursor created by  recovery routine
773                                         * (do not log or lock).
774                                         */
775#define DBC_RMW         0x008           /* Acquire write flag in read op. */
776#define DBC_WRITECURSOR 0x010           /* Cursor may be used to write (CDB). */
777#define DBC_WRITEDUP    0x020           /* idup'ed DBC_WRITECURSOR (CDB). */
778#define DBC_WRITER      0x040           /* Cursor immediately writing (CDB). */
779#define DBC_TRANSIENT   0x080           /* Cursor is transient. */
780        u_int32_t flags;
781};
782
783/* Key range statistics structure */
784struct __key_range {
785        double less;
786        double equal;
787        double greater;
788};
789
790/* Btree/Recno statistics structure. */
791struct __db_bt_stat {
792        u_int32_t bt_magic;             /* Magic number. */
793        u_int32_t bt_version;           /* Version number. */
794        u_int32_t bt_metaflags;         /* Metadata flags. */
795        u_int32_t bt_nkeys;             /* Number of unique keys. */
796        u_int32_t bt_ndata;             /* Number of data items. */
797        u_int32_t bt_pagesize;          /* Page size. */
798        u_int32_t bt_maxkey;            /* Maxkey value. */
799        u_int32_t bt_minkey;            /* Minkey value. */
800        u_int32_t bt_re_len;            /* Fixed-length record length. */
801        u_int32_t bt_re_pad;            /* Fixed-length record pad. */
802        u_int32_t bt_levels;            /* Tree levels. */
803        u_int32_t bt_int_pg;            /* Internal pages. */
804        u_int32_t bt_leaf_pg;           /* Leaf pages. */
805        u_int32_t bt_dup_pg;            /* Duplicate pages. */
806        u_int32_t bt_over_pg;           /* Overflow pages. */
807        u_int32_t bt_free;              /* Pages on the free list. */
808        u_int32_t bt_int_pgfree;        /* Bytes free in internal pages. */
809        u_int32_t bt_leaf_pgfree;       /* Bytes free in leaf pages. */
810        u_int32_t bt_dup_pgfree;        /* Bytes free in duplicate pages. */
811        u_int32_t bt_over_pgfree;       /* Bytes free in overflow pages. */
812};
813
814/* Queue statistics structure. */
815struct __db_qam_stat {
816        u_int32_t qs_magic;             /* Magic number. */
817        u_int32_t qs_version;           /* Version number. */
818        u_int32_t qs_metaflags;         /* Metadata flags. */
819        u_int32_t qs_nkeys;             /* Number of unique keys. */
820        u_int32_t qs_ndata;             /* Number of data items. */
821        u_int32_t qs_pagesize;          /* Page size. */
822        u_int32_t qs_pages;             /* Data pages. */
823        u_int32_t qs_re_len;            /* Fixed-length record length. */
824        u_int32_t qs_re_pad;            /* Fixed-length record pad. */
825        u_int32_t qs_pgfree;            /* Bytes free in data pages. */
826        u_int32_t qs_start;             /* Start offset. */
827        u_int32_t qs_first_recno;       /* First not deleted record. */
828        u_int32_t qs_cur_recno;         /* Last allocated record number. */
829};
830
831/* Hash statistics structure. */
832struct __db_h_stat {
833        u_int32_t hash_magic;           /* Magic number. */
834        u_int32_t hash_version;         /* Version number. */
835        u_int32_t hash_metaflags;       /* Metadata flags. */
836        u_int32_t hash_nkeys;           /* Number of unique keys. */
837        u_int32_t hash_ndata;           /* Number of data items. */
838        u_int32_t hash_pagesize;        /* Page size. */
839        u_int32_t hash_nelem;           /* Original nelem specified. */
840        u_int32_t hash_ffactor;         /* Fill factor specified at create. */
841        u_int32_t hash_buckets;         /* Number of hash buckets. */
842        u_int32_t hash_free;            /* Pages on the free list. */
843        u_int32_t hash_bfree;           /* Bytes free on bucket pages. */
844        u_int32_t hash_bigpages;        /* Number of big key/data pages. */
845        u_int32_t hash_big_bfree;       /* Bytes free on big item pages. */
846        u_int32_t hash_overflows;       /* Number of overflow pages. */
847        u_int32_t hash_ovfl_free;       /* Bytes free on ovfl pages. */
848        u_int32_t hash_dup;             /* Number of dup pages. */
849        u_int32_t hash_dup_free;        /* Bytes free on duplicate pages. */
850};
851
852int   db_create __P((DB **, DB_ENV *, u_int32_t));
853int   db_env_create __P((DB_ENV **, u_int32_t));
854int   db_env_set_func_close __P((int (*)(int)));
855int   db_env_set_func_dirfree __P((void (*)(char **, int)));
856int   db_env_set_func_dirlist __P((int (*)(const char *, char ***, int *)));
857int   db_env_set_func_exists __P((int (*)(const char *, int *)));
858int   db_env_set_func_free __P((void (*)(void *)));
859int   db_env_set_func_fsync __P((int (*)(int)));
860int   db_env_set_func_ioinfo __P((int (*)(const char *,
861          int, u_int32_t *, u_int32_t *, u_int32_t *)));
862int   db_env_set_func_malloc __P((void *(*)(size_t)));
863int   db_env_set_func_map __P((int (*)(char *, size_t, int, int, void **)));
864int   db_env_set_func_open __P((int (*)(const char *, int, ...)));
865int   db_env_set_func_read __P((ssize_t (*)(int, void *, size_t)));
866int   db_env_set_func_realloc __P((void *(*)(void *, size_t)));
867int   db_env_set_func_rename __P((int (*)(const char *, const char *)));
868int   db_env_set_func_seek
869          __P((int (*)(int, size_t, db_pgno_t, u_int32_t, int, int)));
870int   db_env_set_func_sleep __P((int (*)(u_long, u_long)));
871int   db_env_set_func_unlink __P((int (*)(const char *)));
872int   db_env_set_func_unmap __P((int (*)(void *, size_t)));
873int   db_env_set_func_write __P((ssize_t (*)(int, const void *, size_t)));
874int   db_env_set_func_yield __P((int (*)(void)));
875int   db_env_set_mutexlocks __P((int));
876int   db_env_set_pageyield __P((int));
877int   db_env_set_panicstate __P((int));
878int   db_env_set_region_init __P((int));
879int   db_env_set_tas_spins __P((u_int32_t));
880char *db_strerror __P((int));
881char *db_version __P((int *, int *, int *));
882
883/*******************************************************
884 * Locking
885 *******************************************************/
886#define DB_LOCKVERSION  1
887
888/* Flag values for lock_vec(), lock_get(). */
889#define DB_LOCK_NOWAIT          0x01    /* Don't wait on unavailable lock. */
890#define DB_LOCK_RECORD          0x02    /* Internal: record lock. */
891#define DB_LOCK_UPGRADE         0x04    /* Internal: upgrade existing lock. */
892
893/* Flag values for lock_detect(). */
894#define DB_LOCK_CONFLICT        0x01    /* Run on any conflict. */
895
896/*
897 * Request types.
898 *
899 * !!!
900 * Changes here must be reflected in java/src/com/sleepycat/db/Db.java.
901 */
902typedef enum {
903        DB_LOCK_DUMP=0,                 /* Display held locks. */
904        DB_LOCK_GET,                    /* Get the lock. */
905        DB_LOCK_INHERIT,                /* Pass locks to parent. */
906        DB_LOCK_PUT,                    /* Release the lock. */
907        DB_LOCK_PUT_ALL,                /* Release locker's locks. */
908        DB_LOCK_PUT_OBJ                 /* Release locker's locks on obj. */
909} db_lockop_t;
910
911/*
912 * Simple R/W lock modes and for multi-granularity intention locking.
913 *
914 * !!!
915 * These values are NOT random, as they are used as an index into the lock
916 * conflicts arrays, i.e., DB_LOCK_IWRITE must be == 3, and DB_LOCK_IREAD
917 * must be == 4.
918 *
919 * !!!
920 * Changes here must be reflected in java/src/com/sleepycat/db/Db.java.
921 */
922typedef enum {
923        DB_LOCK_NG=0,                   /* Not granted. */
924        DB_LOCK_READ,                   /* Shared/read. */
925        DB_LOCK_WRITE,                  /* Exclusive/write. */
926        DB_LOCK_IWRITE,                 /* Intent exclusive/write. */
927        DB_LOCK_IREAD,                  /* Intent to share/read. */
928        DB_LOCK_IWR                     /* Intent to read and write. */
929} db_lockmode_t;
930
931/*
932 * Status of a lock.
933 */
934typedef enum {
935        DB_LSTAT_ABORTED,               /* Lock belongs to an aborted txn. */
936        DB_LSTAT_ERR,                   /* Lock is bad. */
937        DB_LSTAT_FREE,                  /* Lock is unallocated. */
938        DB_LSTAT_HELD,                  /* Lock is currently held. */
939        DB_LSTAT_NOGRANT,               /* Lock was not granted. */
940        DB_LSTAT_PENDING,               /* Lock was waiting and has been
941                                         * promoted; waiting for the owner
942                                         * to run and upgrade it to held. */
943        DB_LSTAT_WAITING                /* Lock is on the wait queue. */
944} db_status_t;
945
946/* Lock request structure. */
947struct __db_lockreq {
948        db_lockop_t      op;            /* Operation. */
949        db_lockmode_t    mode;          /* Requested mode. */
950        u_int32_t        locker;        /* Locker identity. */
951        DBT             *obj;           /* Object being locked. */
952        DB_LOCK          lock;          /* Lock returned. */
953};
954
955/*
956 * Commonly used conflict matrices.
957 *
958 * Standard Read/Write (or exclusive/shared) locks.
959 */
960#define DB_LOCK_RW_N    3
961extern const u_int8_t db_rw_conflicts[];
962
963/* Multi-granularity locking. */
964#define DB_LOCK_RIW_N   6
965extern const u_int8_t db_riw_conflicts[];
966
967struct __db_lock_stat {
968        u_int32_t st_lastid;            /* Last allocated locker ID. */
969        u_int32_t st_maxlocks;          /* Maximum number of locks in table. */
970        u_int32_t st_nmodes;            /* Number of lock modes. */
971        u_int32_t st_nlockers;          /* Number of lockers. */
972        u_int32_t st_maxnlockers;       /* Maximum number of lockers. */
973        u_int32_t st_nconflicts;        /* Number of lock conflicts. */
974        u_int32_t st_nrequests;         /* Number of lock gets. */
975        u_int32_t st_nreleases;         /* Number of lock puts. */
976        u_int32_t st_nnowaits;          /* Number of requests that would have
977                                           waited, but NOWAIT was set. */
978        u_int32_t st_ndeadlocks;        /* Number of lock deadlocks. */
979        u_int32_t st_region_wait;       /* Region lock granted after wait. */
980        u_int32_t st_region_nowait;     /* Region lock granted without wait. */
981        u_int32_t st_regsize;           /* Region size. */
982};
983
984int       lock_detect __P((DB_ENV *, u_int32_t, u_int32_t, int *));
985int       lock_get __P((DB_ENV *,
986            u_int32_t, u_int32_t, const DBT *, db_lockmode_t, DB_LOCK *));
987int       lock_id __P((DB_ENV *, u_int32_t *));
988int       lock_put __P((DB_ENV *, DB_LOCK *));
989int       lock_stat __P((DB_ENV *, DB_LOCK_STAT **, void *(*)(size_t)));
990int       lock_vec __P((DB_ENV *,
991            u_int32_t, u_int32_t, DB_LOCKREQ *, int, DB_LOCKREQ **));
992
993/*******************************************************
994 * Logging.
995 *******************************************************/
996/* Flag values for log_archive(). */
997#define DB_ARCH_ABS             0x001   /* Absolute pathnames. */
998#define DB_ARCH_DATA            0x002   /* Data files. */
999#define DB_ARCH_LOG             0x004   /* Log files. */
1000
1001/*
1002 * A DB_LSN has two parts, a fileid which identifies a specific file, and an
1003 * offset within that file.  The fileid is an unsigned 4-byte quantity that
1004 * uniquely identifies a file within the log directory -- currently a simple
1005 * counter inside the log.  The offset is also an unsigned 4-byte value.  The
1006 * log manager guarantees the offset is never more than 4 bytes by switching
1007 * to a new log file before the maximum length imposed by an unsigned 4-byte
1008 * offset is reached.
1009 */
1010struct __db_lsn {
1011        u_int32_t       file;           /* File ID. */
1012        u_int32_t       offset;         /* File offset. */
1013};
1014
1015/* Log statistics structure. */
1016struct __db_log_stat {
1017        u_int32_t st_magic;             /* Log file magic number. */
1018        u_int32_t st_version;           /* Log file version number. */
1019        int st_mode;                    /* Log file mode. */
1020        u_int32_t st_lg_bsize;          /* Log buffer size. */
1021        u_int32_t st_lg_max;            /* Maximum log file size. */
1022        u_int32_t st_w_bytes;           /* Bytes to log. */
1023        u_int32_t st_w_mbytes;          /* Megabytes to log. */
1024        u_int32_t st_wc_bytes;          /* Bytes to log since checkpoint. */
1025        u_int32_t st_wc_mbytes;         /* Megabytes to log since checkpoint. */
1026        u_int32_t st_wcount;            /* Total writes to the log. */
1027        u_int32_t st_wcount_fill;       /* Overflow writes to the log. */
1028        u_int32_t st_scount;            /* Total syncs to the log. */
1029        u_int32_t st_region_wait;       /* Region lock granted after wait. */
1030        u_int32_t st_region_nowait;     /* Region lock granted without wait. */
1031        u_int32_t st_cur_file;          /* Current log file number. */
1032        u_int32_t st_cur_offset;        /* Current log file offset. */
1033        u_int32_t st_regsize;           /* Region size. */
1034};
1035
1036int      log_archive __P((DB_ENV *, char **[], u_int32_t, void *(*)(size_t)));
1037int      log_compare __P((const DB_LSN *, const DB_LSN *));
1038int      log_file __P((DB_ENV *, const DB_LSN *, char *, size_t));
1039int      log_flush __P((DB_ENV *, const DB_LSN *));
1040int      log_get __P((DB_ENV *, DB_LSN *, DBT *, u_int32_t));
1041int      log_put __P((DB_ENV *, DB_LSN *, const DBT *, u_int32_t));
1042int      log_register __P((DB_ENV *, DB *, const char *));
1043int      log_stat __P((DB_ENV *, DB_LOG_STAT **, void *(*)(size_t)));
1044int      log_unregister __P((DB_ENV *, DB *));
1045
1046/*******************************************************
1047 * Mpool
1048 *******************************************************/
1049/* Flag values for memp_fget(). */
1050#define DB_MPOOL_CREATE         0x001   /* Create a page. */
1051#define DB_MPOOL_LAST           0x002   /* Return the last page. */
1052#define DB_MPOOL_NEW            0x004   /* Create a new page. */
1053#define DB_MPOOL_NEW_GROUP      0x008   /* Create a group of pages. */
1054
1055/* Flag values for memp_fput(), memp_fset(). */
1056#define DB_MPOOL_CLEAN          0x001   /* Page is not modified. */
1057#define DB_MPOOL_DIRTY          0x002   /* Page is modified. */
1058#define DB_MPOOL_DISCARD        0x004   /* Don't cache the page. */
1059
1060/* Mpool statistics structure. */
1061struct __db_mpool_stat {
1062        u_int32_t st_cache_hit;         /* Pages found in the cache. */
1063        u_int32_t st_cache_miss;        /* Pages not found in the cache. */
1064        u_int32_t st_map;               /* Pages from mapped files. */
1065        u_int32_t st_page_create;       /* Pages created in the cache. */
1066        u_int32_t st_page_in;           /* Pages read in. */
1067        u_int32_t st_page_out;          /* Pages written out. */
1068        u_int32_t st_ro_evict;          /* Clean pages forced from the cache. */
1069        u_int32_t st_rw_evict;          /* Dirty pages forced from the cache. */
1070        u_int32_t st_hash_buckets;      /* Number of hash buckets. */
1071        u_int32_t st_hash_searches;     /* Total hash chain searches. */
1072        u_int32_t st_hash_longest;      /* Longest hash chain searched. */
1073        u_int32_t st_hash_examined;     /* Total hash entries searched. */
1074        u_int32_t st_page_clean;        /* Clean pages. */
1075        u_int32_t st_page_dirty;        /* Dirty pages. */
1076        u_int32_t st_page_trickle;      /* Pages written by memp_trickle. */
1077        u_int32_t st_region_wait;       /* Region lock granted after wait. */
1078        u_int32_t st_region_nowait;     /* Region lock granted without wait. */
1079        u_int32_t st_gbytes;            /* Total cache size: GB. */
1080        u_int32_t st_bytes;             /* Total cache size: B. */
1081        u_int32_t st_ncache;            /* Number of caches. */
1082        u_int32_t st_regsize;           /* Cache size. */
1083};
1084
1085/* Mpool file open information structure. */
1086struct __db_mpool_finfo {
1087        int        ftype;               /* File type. */
1088        DBT       *pgcookie;            /* Byte-string passed to pgin/pgout. */
1089        u_int8_t  *fileid;              /* Unique file ID. */
1090        int32_t    lsn_offset;          /* LSN offset in page. */
1091        u_int32_t  clear_len;           /* Cleared length on created pages. */
1092};
1093
1094/* Mpool file statistics structure. */
1095struct __db_mpool_fstat {
1096        char *file_name;                /* File name. */
1097        size_t st_pagesize;             /* Page size. */
1098        u_int32_t st_cache_hit;         /* Pages found in the cache. */
1099        u_int32_t st_cache_miss;        /* Pages not found in the cache. */
1100        u_int32_t st_map;               /* Pages from mapped files. */
1101        u_int32_t st_page_create;       /* Pages created in the cache. */
1102        u_int32_t st_page_in;           /* Pages read in. */
1103        u_int32_t st_page_out;          /* Pages written out. */
1104};
1105
1106int     memp_fclose __P((DB_MPOOLFILE *));
1107int     memp_fget __P((DB_MPOOLFILE *, db_pgno_t *, u_int32_t, void *));
1108int     memp_fopen __P((DB_ENV *, const char *,
1109            u_int32_t, int, size_t, DB_MPOOL_FINFO *, DB_MPOOLFILE **));
1110int     memp_fput __P((DB_MPOOLFILE *, void *, u_int32_t));
1111int     memp_fset __P((DB_MPOOLFILE *, void *, u_int32_t));
1112int     memp_fsync __P((DB_MPOOLFILE *));
1113int     memp_register __P((DB_ENV *, int,
1114            int (*)(DB_ENV *, db_pgno_t, void *, DBT *),
1115            int (*)(DB_ENV *, db_pgno_t, void *, DBT *)));
1116int     memp_stat __P((DB_ENV *,
1117            DB_MPOOL_STAT **, DB_MPOOL_FSTAT ***, void *(*)(size_t)));
1118int     memp_sync __P((DB_ENV *, DB_LSN *));
1119int     memp_trickle __P((DB_ENV *, int, int *));
1120
1121/*******************************************************
1122 * Transactions.
1123 *******************************************************/
1124#define DB_TXNVERSION   1
1125
1126/* Operations values to the tx_recover() function. */
1127#define DB_TXN_BACKWARD_ROLL    1       /* Read the log backwards. */
1128#define DB_TXN_FORWARD_ROLL     2       /* Read the log forwards. */
1129#define DB_TXN_OPENFILES        3       /* Read for open files. */
1130#define DB_TXN_REDO             4       /* Redo the operation. */
1131#define DB_TXN_UNDO             5       /* Undo the operation. */
1132
1133/* Internal transaction status values. */
1134
1135/* Transaction statistics structure. */
1136struct __db_txn_active {
1137        u_int32_t       txnid;          /* Transaction ID */
1138        u_int32_t       parentid;       /* Transaction ID of parent */
1139        DB_LSN          lsn;            /* Lsn of the begin record */
1140};
1141
1142struct __db_txn_stat {
1143        DB_LSN    st_last_ckp;          /* lsn of the last checkpoint */
1144        DB_LSN    st_pending_ckp;       /* last checkpoint did not finish */
1145        time_t    st_time_ckp;          /* time of last checkpoint */
1146        u_int32_t st_last_txnid;        /* last transaction id given out */
1147        u_int32_t st_maxtxns;           /* maximum txns possible */
1148        u_int32_t st_naborts;           /* number of aborted transactions */
1149        u_int32_t st_nbegins;           /* number of begun transactions */
1150        u_int32_t st_ncommits;          /* number of committed transactions */
1151        u_int32_t st_nactive;           /* number of active transactions */
1152        u_int32_t st_maxnactive;        /* maximum active transactions */
1153        DB_TXN_ACTIVE
1154                 *st_txnarray;          /* array of active transactions */
1155        u_int32_t st_region_wait;       /* Region lock granted after wait. */
1156        u_int32_t st_region_nowait;     /* Region lock granted without wait. */
1157        u_int32_t st_regsize;           /* Region size. */
1158};
1159
1160int       txn_abort __P((DB_TXN *));
1161int       txn_begin __P((DB_ENV *, DB_TXN *, DB_TXN **, u_int32_t));
1162int       txn_checkpoint __P((DB_ENV *, u_int32_t, u_int32_t, u_int32_t));
1163int       txn_commit __P((DB_TXN *, u_int32_t));
1164u_int32_t txn_id __P((DB_TXN *));
1165int       txn_prepare __P((DB_TXN *));
1166int       txn_stat __P((DB_ENV *, DB_TXN_STAT **, void *(*)(size_t)));
1167
1168#ifndef DB_DBM_HSEARCH
1169#define DB_DBM_HSEARCH  0               /* No historic interfaces by default. */
1170#endif
1171#if DB_DBM_HSEARCH != 0
1172/*******************************************************
1173 * Dbm/Ndbm historic interfaces.
1174 *******************************************************/
1175#define DBM_INSERT      0               /* Flags to dbm_store(). */
1176#define DBM_REPLACE     1
1177
1178/*
1179 * The DB support for ndbm(3) always appends this suffix to the
1180 * file name to avoid overwriting the user's original database.
1181 */
1182#define DBM_SUFFIX      ".db"
1183
1184#if defined(_XPG4_2)
1185typedef struct {
1186        char *dptr;
1187        size_t dsize;
1188} datum;
1189#else
1190typedef struct {
1191        char *dptr;
1192        int dsize;
1193} datum;
1194#endif
1195
1196/*
1197 * Translate DBM calls into DB calls so that DB doesn't step on the
1198 * application's name space.
1199 *
1200 * The global variables dbrdonly, dirf and pagf were not retained when 4BSD
1201 * replaced the dbm interface with ndbm, and are not supported here.
1202 */
1203#define dbminit(a)      __db_dbm_init(a)
1204#define dbmclose        __db_dbm_close
1205#if !defined(__cplusplus)
1206#define delete(a)       __db_dbm_delete(a)
1207#endif
1208#define fetch(a)        __db_dbm_fetch(a)
1209#define firstkey        __db_dbm_firstkey
1210#define nextkey(a)      __db_dbm_nextkey(a)
1211#define store(a, b)     __db_dbm_store(a, b)
1212
1213/* Prototype the DB calls. */
1214int      __db_dbm_close __P((void));
1215int      __db_dbm_dbrdonly __P((void));
1216int      __db_dbm_delete __P((datum));
1217int      __db_dbm_dirf __P((void));
1218datum    __db_dbm_fetch __P((datum));
1219datum    __db_dbm_firstkey __P((void));
1220int      __db_dbm_init __P((char *));
1221datum    __db_dbm_nextkey __P((datum));
1222int      __db_dbm_pagf __P((void));
1223int      __db_dbm_store __P((datum, datum));
1224
1225/*
1226 * Translate NDBM calls into DB calls so that DB doesn't step on the
1227 * application's name space.
1228 */
1229#define dbm_clearerr(a)         __db_ndbm_clearerr(a)
1230#define dbm_close(a)            __db_ndbm_close(a)
1231#define dbm_delete(a, b)        __db_ndbm_delete(a, b)
1232#define dbm_dirfno(a)           __db_ndbm_dirfno(a)
1233#define dbm_error(a)            __db_ndbm_error(a)
1234#define dbm_fetch(a, b)         __db_ndbm_fetch(a, b)
1235#define dbm_firstkey(a)         __db_ndbm_firstkey(a)
1236#define dbm_nextkey(a)          __db_ndbm_nextkey(a)
1237#define dbm_open(a, b, c)       __db_ndbm_open(a, b, c)
1238#define dbm_pagfno(a)           __db_ndbm_pagfno(a)
1239#define dbm_rdonly(a)           __db_ndbm_rdonly(a)
1240#define dbm_store(a, b, c, d)   __db_ndbm_store(a, b, c, d)
1241
1242/* Prototype the DB calls. */
1243int      __db_ndbm_clearerr __P((DBM *));
1244void     __db_ndbm_close __P((DBM *));
1245int      __db_ndbm_delete __P((DBM *, datum));
1246int      __db_ndbm_dirfno __P((DBM *));
1247int      __db_ndbm_error __P((DBM *));
1248datum    __db_ndbm_fetch __P((DBM *, datum));
1249datum    __db_ndbm_firstkey __P((DBM *));
1250datum    __db_ndbm_nextkey __P((DBM *));
1251DBM     *__db_ndbm_open __P((const char *, int, int));
1252int      __db_ndbm_pagfno __P((DBM *));
1253int      __db_ndbm_rdonly __P((DBM *));
1254int      __db_ndbm_store __P((DBM *, datum, datum, int));
1255
1256/*******************************************************
1257 * Hsearch historic interface.
1258 *******************************************************/
1259typedef enum {
1260        FIND, ENTER
1261} ACTION;
1262
1263typedef struct entry {
1264        char *key;
1265        char *data;
1266} ENTRY;
1267
1268/*
1269 * Translate HSEARCH calls into DB calls so that DB doesn't step on the
1270 * application's name space.
1271 */
1272#define hcreate(a)      __db_hcreate(a)
1273#define hdestroy        __db_hdestroy
1274#define hsearch(a, b)   __db_hsearch(a, b)
1275
1276/* Prototype the DB calls. */
1277int      __db_hcreate __P((size_t));
1278void     __db_hdestroy __P((void));
1279ENTRY   *__db_hsearch __P((ENTRY, ACTION));
1280#endif /* DB_DBM_HSEARCH */
1281
1282/*
1283 * XXX
1284 * MacOS: Reset Metrowerks C enum sizes.
1285 */
1286#ifdef __MWERKS__
1287#pragma enumsalwaysint reset
1288#endif
1289
1290#if defined(__cplusplus)
1291}
1292#endif
1293
1294#endif /* !_DB_H_ */
Note: See TracBrowser for help on using the repository browser.