Update.
[glibc.git] / db2 / include / db.h.src
blob97ad55693f59aa77faf1d306c8c75eab55dad4bc
1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 1996, 1997, 1998
5  *      Sleepycat Software.  All rights reserved.
6  *
7  *      @(#)db.h.src    10.131 (Sleepycat) 6/2/98
8  */
10 #ifndef _DB_H_
11 #define _DB_H_
13 #ifndef __NO_SYSTEM_INCLUDES
14 #include <sys/types.h>
16 #include <stdio.h>
17 #endif
20  * XXX
21  * MacOS: ensure that Metrowerks C makes enumeration types int sized.
22  */
23 #ifdef __MWERKS__
24 #pragma enumsalwaysint on
25 #endif
28  * XXX
29  * Handle function prototypes and the keyword "const".  This steps on name
30  * space that DB doesn't control, but all of the other solutions are worse.
31  *
32  * XXX
33  * While Microsoft's compiler is ANSI C compliant, it doesn't have _STDC_
34  * defined by default, you specify a command line flag or #pragma to turn
35  * it on.  Don't do that, however, because some of Microsoft's own header
36  * files won't compile.
37  */
38 #undef  __P
39 #if defined(__STDC__) || defined(__cplusplus) || defined(_MSC_VER)
40 #define __P(protos)     protos          /* ANSI C prototypes */
41 #else
42 #define const
43 #define __P(protos)     ()              /* K&R C preprocessor */
44 #endif
47  * !!!
48  * DB needs basic information about specifically sized types.  If they're
49  * not provided by the system, typedef them here.
50  *
51  * We protect them against multiple inclusion using __BIT_TYPES_DEFINED__,
52  * as does BIND and Kerberos, since we don't know for sure what #include
53  * files the user is using.
54  *
55  * !!!
56  * We also provide the standard u_int, u_long etc., if they're not provided
57  * by the system.
58  */
59 #ifndef __BIT_TYPES_DEFINED__
60 #define __BIT_TYPES_DEFINED__
61 @u_int8_decl@
62 @int16_decl@
63 @u_int16_decl@
64 @int32_decl@
65 @u_int32_decl@
66 #endif
68 @u_char_decl@
69 @u_short_decl@
70 @u_int_decl@
71 @u_long_decl@
73 #define DB_VERSION_MAJOR        2
74 #define DB_VERSION_MINOR        4
75 #define DB_VERSION_PATCH        14
76 #define DB_VERSION_STRING       "Sleepycat Software: DB 2.4.14: (6/2/98)"
78 typedef u_int32_t       db_pgno_t;      /* Page number type. */
79 typedef u_int16_t       db_indx_t;      /* Page offset type. */
80 #define DB_MAX_PAGES    0xffffffff      /* >= # of pages in a file */
82 typedef u_int32_t       db_recno_t;     /* Record number type. */
83 typedef size_t          DB_LOCK;        /* Object returned by lock manager. */
84 #define DB_MAX_RECORDS  0xffffffff      /* >= # of records in a tree */
86 #define DB_FILE_ID_LEN          20      /* DB file ID length. */
88 /* Forward structure declarations, so applications get type checking. */
89 struct __db;            typedef struct __db DB;
90 #ifdef DB_DBM_HSEARCH
91                         typedef struct __db DBM;
92 #endif
93 struct __db_bt_stat;    typedef struct __db_bt_stat DB_BTREE_STAT;
94 struct __db_dbt;        typedef struct __db_dbt DBT;
95 struct __db_env;        typedef struct __db_env DB_ENV;
96 struct __db_info;       typedef struct __db_info DB_INFO;
97 struct __db_lock_stat;  typedef struct __db_lock_stat DB_LOCK_STAT;
98 struct __db_lockregion; typedef struct __db_lockregion DB_LOCKREGION;
99 struct __db_lockreq;    typedef struct __db_lockreq DB_LOCKREQ;
100 struct __db_locktab;    typedef struct __db_locktab DB_LOCKTAB;
101 struct __db_log;        typedef struct __db_log DB_LOG;
102 struct __db_log_stat;   typedef struct __db_log_stat DB_LOG_STAT;
103 struct __db_lsn;        typedef struct __db_lsn DB_LSN;
104 struct __db_mpool;      typedef struct __db_mpool DB_MPOOL;
105 struct __db_mpool_finfo;typedef struct __db_mpool_finfo DB_MPOOL_FINFO;
106 struct __db_mpool_fstat;typedef struct __db_mpool_fstat DB_MPOOL_FSTAT;
107 struct __db_mpool_stat; typedef struct __db_mpool_stat DB_MPOOL_STAT;
108 struct __db_mpoolfile;  typedef struct __db_mpoolfile DB_MPOOLFILE;
109 struct __db_txn;        typedef struct __db_txn DB_TXN;
110 struct __db_txn_active; typedef struct __db_txn_active DB_TXN_ACTIVE;
111 struct __db_txn_stat;   typedef struct __db_txn_stat DB_TXN_STAT;
112 struct __db_txnmgr;     typedef struct __db_txnmgr DB_TXNMGR;
113 struct __db_txnregion;  typedef struct __db_txnregion DB_TXNREGION;
114 struct __dbc;           typedef struct __dbc DBC;
116 /* Key/data structure -- a Data-Base Thang. */
117 struct __db_dbt {
118         void     *data;                 /* key/data */
119         u_int32_t size;                 /* key/data length */
120         u_int32_t ulen;                 /* RO: length of user buffer. */
121         u_int32_t dlen;                 /* RO: get/put record length. */
122         u_int32_t doff;                 /* RO: get/put record offset. */
124 #define DB_DBT_INTERNAL 0x01            /* Perform any mallocs using regular
125                                            malloc, not the user's malloc. */
126 #define DB_DBT_MALLOC   0x02            /* Return in allocated memory. */
127 #define DB_DBT_PARTIAL  0x04            /* Partial put/get. */
128 #define DB_DBT_USERMEM  0x08            /* Return in user's memory. */
129         u_int32_t flags;
133  * DB internal configuration.
135  * There are a set of functions that the application can replace with its
136  * own versions, and some other knobs which can be turned at run-time.
137  */
138 #define DB_FUNC_CALLOC   1      /* DELETED: ANSI C calloc. */
139 #define DB_FUNC_CLOSE    2              /* POSIX 1003.1 close. */
140 #define DB_FUNC_DIRFREE  3              /* DB: free directory list. */
141 #define DB_FUNC_DIRLIST  4              /* DB: create directory list. */
142 #define DB_FUNC_EXISTS   5              /* DB: return if file exists. */
143 #define DB_FUNC_FREE     6              /* ANSI C free. */
144 #define DB_FUNC_FSYNC    7              /* POSIX 1003.1 fsync. */
145 #define DB_FUNC_IOINFO   8              /* DB: return file I/O information. */
146 #define DB_FUNC_MALLOC   9              /* ANSI C malloc. */
147 #define DB_FUNC_MAP     10              /* DB: map file into shared memory. */
148 #define DB_FUNC_OPEN    11              /* POSIX 1003.1 open. */
149 #define DB_FUNC_READ    12              /* POSIX 1003.1 read. */
150 #define DB_FUNC_REALLOC 13              /* ANSI C realloc. */
151 #define DB_FUNC_SEEK    14              /* POSIX 1003.1 lseek. */
152 #define DB_FUNC_SLEEP   15              /* DB: sleep secs/usecs. */
153 #define DB_FUNC_STRDUP  16      /* DELETED: DB: strdup(3). */
154 #define DB_FUNC_UNLINK  17              /* POSIX 1003.1 unlink. */
155 #define DB_FUNC_UNMAP   18              /* DB: unmap shared memory file. */
156 #define DB_FUNC_WRITE   19              /* POSIX 1003.1 write. */
157 #define DB_FUNC_YIELD   20              /* DB: yield thread to scheduler. */
158 #define DB_TSL_SPINS    21              /* DB: initialize spin count. */
159 #define DB_FUNC_RUNLINK 22              /* DB: remove a shared region. */
160 #define DB_REGION_ANON  23              /* DB: anonymous, unnamed regions. */
161 #define DB_REGION_INIT  24              /* DB: page-fault regions in create. */
162 #define DB_REGION_NAME  25              /* DB: anonymous, named regions. */
163 #define DB_MUTEXLOCKS   26              /* DB: turn off all mutex locks. */
164 #define DB_PAGEYIELD    27              /* DB: yield the CPU on pool get. */
167  * Database configuration and initialization.
168  */
169  /*
170   * Flags understood by both db_open(3) and db_appinit(3).
171   */
172 #define DB_CREATE             0x000001  /* O_CREAT: create file as necessary. */
173 #define DB_NOMMAP             0x000002  /* Don't mmap underlying file. */
174 #define DB_THREAD             0x000004  /* Free-thread DB package handles. */
177  * Flags understood by db_appinit(3).
178  */
179 /*                            0x000007     COMMON MASK. */
180 #define DB_INIT_LOCK          0x000008  /* Initialize locking. */
181 #define DB_INIT_LOG           0x000010  /* Initialize logging. */
182 #define DB_INIT_MPOOL         0x000020  /* Initialize mpool. */
183 #define DB_INIT_TXN           0x000040  /* Initialize transactions. */
184 #define DB_MPOOL_PRIVATE      0x000080  /* Mpool: private memory pool. */
185 #define __UNUSED_100          0x000100
186 #define DB_RECOVER            0x000200  /* Run normal recovery. */
187 #define DB_RECOVER_FATAL      0x000400  /* Run catastrophic recovery. */
188 #define DB_TXN_NOSYNC         0x000800  /* Do not sync log on commit. */
189 #define DB_USE_ENVIRON        0x001000  /* Use the environment. */
190 #define DB_USE_ENVIRON_ROOT   0x002000  /* Use the environment if root. */
192 /* CURRENTLY UNUSED LOCK FLAGS. */
193 #define DB_TXN_LOCK_2PL       0x000000  /* Two-phase locking. */
194 #define DB_TXN_LOCK_OPTIMIST  0x000000  /* Optimistic locking. */
195 #define DB_TXN_LOCK_MASK      0x000000  /* Lock flags mask. */
197 /* CURRENTLY UNUSED LOG FLAGS. */
198 #define DB_TXN_LOG_REDO       0x000000  /* Redo-only logging. */
199 #define DB_TXN_LOG_UNDO       0x000000  /* Undo-only logging. */
200 #define DB_TXN_LOG_UNDOREDO   0x000000  /* Undo/redo write-ahead logging. */
201 #define DB_TXN_LOG_MASK       0x000000  /* Log flags mask. */
204  * Flags understood by db_open(3).
206  * DB_EXCL and DB_TEMPORARY are internal only, and are not documented.
207  * DB_SEQUENTIAL is currently internal, but may be exported some day.
208  */
209 /*                            0x000007     COMMON MASK. */
210 /*                            0x003fff     ALREADY USED. */
211 #define __UNUSED_4000         0x004000
212 #define DB_EXCL               0x008000  /* O_EXCL: exclusive open. */
213 #define DB_RDONLY             0x010000  /* O_RDONLY: read-only. */
214 #define DB_SEQUENTIAL         0x020000  /* Indicate sequential access. */
215 #define DB_TEMPORARY          0x040000  /* Remove on last close. */
216 #define DB_TRUNCATE           0x080000  /* O_TRUNCATE: replace existing DB. */
219  * Deadlock detector modes; used in the DBENV structure to configure the
220  * locking subsystem.
221  */
222 #define DB_LOCK_NORUN           0x0
223 #define DB_LOCK_DEFAULT         0x1     /* Default policy. */
224 #define DB_LOCK_OLDEST          0x2     /* Abort oldest transaction. */
225 #define DB_LOCK_RANDOM          0x3     /* Abort random transaction. */
226 #define DB_LOCK_YOUNGEST        0x4     /* Abort youngest transaction. */
228 struct __db_env {
229         int              db_lorder;     /* Byte order. */
231                                         /* Error message callback. */
232         void (*db_errcall) __P((const char *, char *));
233         FILE            *db_errfile;    /* Error message file stream. */
234         const char      *db_errpfx;     /* Error message prefix. */
235         int              db_verbose;    /* Generate debugging messages. */
237         /* User paths. */
238         char            *db_home;       /* Database home. */
239         char            *db_log_dir;    /* Database log file directory. */
240         char            *db_tmp_dir;    /* Database tmp file directory. */
242         char           **db_data_dir;   /* Database data file directories. */
243         int              data_cnt;      /* Database data file slots. */
244         int              data_next;     /* Next Database data file slot. */
246         /* Locking. */
247         DB_LOCKTAB      *lk_info;       /* Return from lock_open(). */
248         u_int8_t        *lk_conflicts;  /* Two dimensional conflict matrix. */
249         u_int32_t        lk_modes;      /* Number of lock modes in table. */
250         u_int32_t        lk_max;        /* Maximum number of locks. */
251         u_int32_t        lk_detect;     /* Deadlock detect on all conflicts. */
253         /* Logging. */
254         DB_LOG          *lg_info;       /* Return from log_open(). */
255         u_int32_t        lg_max;        /* Maximum file size. */
257         /* Memory pool. */
258         DB_MPOOL        *mp_info;       /* Return from memp_open(). */
259         size_t           mp_mmapsize;   /* Maximum file size for mmap. */
260         size_t           mp_size;       /* Bytes in the mpool cache. */
262         /* Transactions. */
263         DB_TXNMGR       *tx_info;       /* Return from txn_open(). */
264         u_int32_t        tx_max;        /* Maximum number of transactions. */
265         int (*tx_recover)               /* Dispatch function for recovery. */
266             __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
268 #define DB_ENV_APPINIT          0x01    /* Paths initialized by db_appinit(). */
269 #define DB_ENV_STANDALONE       0x02    /* Test: freestanding environment. */
270 #define DB_ENV_THREAD           0x04    /* DB_ENV is multi-threaded. */
271         u_int32_t        flags;         /* Flags. */
274 /*******************************************************
275  * Access methods.
276  *******************************************************/
278  * XXX
279  * Changes here must be reflected in java/src/com/sleepycat/db/Db.java.
280  */
281 typedef enum {
282         DB_BTREE=1,                     /* B+tree. */
283         DB_HASH,                        /* Extended Linear Hashing. */
284         DB_RECNO,                       /* Fixed and variable-length records. */
285         DB_UNKNOWN                      /* Figure it out on open. */
286 } DBTYPE;
288 #define DB_BTREEVERSION 6               /* Current btree version. */
289 #define DB_BTREEOLDVER  6               /* Oldest btree version supported. */
290 #define DB_BTREEMAGIC   0x053162
292 #define DB_HASHVERSION  5               /* Current hash version. */
293 #define DB_HASHOLDVER   4               /* Oldest hash version supported. */
294 #define DB_HASHMAGIC    0x061561
296 #define DB_LOGVERSION   2               /* Current log version. */
297 #define DB_LOGOLDVER    2               /* Oldest log version supported. */
298 #define DB_LOGMAGIC     0x040988
300 struct __db_info {
301         int              db_lorder;     /* Byte order. */
302         size_t           db_cachesize;  /* Underlying cache size. */
303         size_t           db_pagesize;   /* Underlying page size. */
305                                         /* Local heap allocation. */
306         void *(*db_malloc) __P((size_t));
308         /* Btree access method. */
309         u_int32_t        bt_maxkey;     /* Maximum keys per page. */
310         u_int32_t        bt_minkey;     /* Minimum keys per page. */
311         int (*bt_compare)               /* Comparison function. */
312             __P((const DBT *, const DBT *));
313         size_t (*bt_prefix)             /* Prefix function. */
314             __P((const DBT *, const DBT *));
316         /* Hash access method. */
317         u_int32_t        h_ffactor;     /* Fill factor. */
318         u_int32_t        h_nelem;       /* Number of elements. */
319         u_int32_t      (*h_hash)        /* Hash function. */
320             __P((const void *, u_int32_t));
322         /* Recno access method. */
323         int              re_pad;        /* Fixed-length padding byte. */
324         int              re_delim;      /* Variable-length delimiting byte. */
325         u_int32_t        re_len;        /* Length for fixed-length records. */
326         char            *re_source;     /* Source file name. */
328 #define DB_DELIMITER            0x0001  /* Recno: re_delim set. */
329 #define DB_DUP                  0x0002  /* Btree, Hash: duplicate keys. */
330 #define DB_FIXEDLEN             0x0004  /* Recno: fixed-length records. */
331 #define DB_PAD                  0x0008  /* Recno: re_pad set. */
332 #define DB_RECNUM               0x0010  /* Btree: record numbers. */
333 #define DB_RENUMBER             0x0020  /* Recno: renumber on insert/delete. */
334 #define DB_SNAPSHOT             0x0040  /* Recno: snapshot the input. */
335         u_int32_t        flags;
339  * DB access method and cursor operation codes.  These are implemented as
340  * bit fields for future flexibility, but currently only a single one may
341  * be specified to any function.
342  */
343 #define DB_AFTER        0x000001        /* c_put() */
344 #define DB_APPEND       0x000002        /* put() */
345 #define DB_BEFORE       0x000004        /* c_put() */
346 #define DB_CHECKPOINT   0x000008        /* log_put(), log_get() */
347 #define DB_CURRENT      0x000010        /* c_get(), c_put(), log_get() */
348 #define DB_FIRST        0x000020        /* c_get(), log_get() */
349 #define DB_FLUSH        0x000040        /* log_put() */
350 #define DB_GET_RECNO    0x000080        /* get(), c_get() */
351 #define DB_KEYFIRST     0x000100        /* c_put() */
352 #define DB_KEYLAST      0x000200        /* c_put() */
353 #define DB_LAST         0x000400        /* c_get(), log_get() */
354 #define DB_NEXT         0x000800        /* c_get(), log_get() */
355 #define DB_NOOVERWRITE  0x001000        /* put() */
356 #define DB_NOSYNC       0x002000        /* close() */
357 #define DB_PREV         0x004000        /* c_get(), log_get() */
358 #define DB_RECORDCOUNT  0x008000        /* stat() */
359 #define DB_SET          0x010000        /* c_get(), log_get() */
360 #define DB_SET_RANGE    0x020000        /* c_get() */
361 #define DB_SET_RECNO    0x040000        /* c_get() */
362 #define DB_CURLSN       0x080000        /* log_put() */
365  * DB (user visible) error return codes.
367  * XXX
368  * Changes to any of the user visible error return codes must be reflected
369  * in java/src/com/sleepycat/db/Db.java.
370  */
371 #define DB_INCOMPLETE           ( -1)   /* Sync didn't finish. */
372 #define DB_KEYEMPTY             ( -2)   /* The key/data pair was deleted or
373                                            was never created by the user. */
374 #define DB_KEYEXIST             ( -3)   /* The key/data pair already exists. */
375 #define DB_LOCK_DEADLOCK        ( -4)   /* Locker killed to resolve deadlock. */
376 #define DB_LOCK_NOTGRANTED      ( -5)   /* Lock unavailable, no-wait set. */
377 #define DB_LOCK_NOTHELD         ( -6)   /* Lock not held by locker. */
378 #define DB_NOTFOUND             ( -7)   /* Key/data pair not found (EOF). */
380 /* DB (private) error return codes. */
381 #define DB_DELETED              ( -8)   /* Recovery file marked deleted. */
382 #define DB_NEEDSPLIT            ( -9)   /* Page needs to be split. */
383 #define DB_REGISTERED           (-10)   /* Entry was previously registered. */
384 #define DB_SWAPBYTES            (-11)   /* Database needs byte swapping. */
385 #define DB_TXN_CKP              (-12)   /* Encountered ckp record in log. */
387 struct __db_ilock {                     /* Internal DB access method lock. */
388         db_pgno_t       pgno;           /* Page being locked. */
389                                         /* File id. */
390         u_int8_t        fileid[DB_FILE_ID_LEN];
393 /* DB access method description structure. */
394 struct __db {
395         void    *mutexp;                /* Synchronization for free threading */
396         DBTYPE   type;                  /* DB access method. */
397         DB_ENV  *dbenv;                 /* DB_ENV structure. */
398         DB_ENV  *mp_dbenv;              /* DB_ENV for local mpool creation. */
400         DB      *master;                /* Original DB created by db_open. */
401         void    *internal;              /* Access method private. */
403         DB_MPOOL        *mp;            /* The access method's mpool. */
404         DB_MPOOLFILE    *mpf;           /* The access method's mpool file. */
406         /*
407          * XXX
408          * Explicit representations of structures in queue.h.
409          *
410          * TAILQ_HEAD(curs_queue, __dbc);
411          */
412         struct {
413                 struct __dbc *tqh_first;
414                 struct __dbc **tqh_last;
415         } curs_queue;
417         /*
418          * XXX
419          * Explicit representations of structures in queue.h.
420          *
421          * LIST_HEAD(handleq, __db);
422          * LIST_ENTRY(__db);
423          */
424         struct {
425                 struct __db *lh_first;
426         } handleq;                      /* List of handles for this DB. */
427         struct {
428                 struct __db *le_next;
429                 struct __db **le_prev;
430         } links;                        /* Links for the handle list. */
432         u_int32_t log_fileid;           /* Logging file id. */
434         DB_TXN   *txn;                  /* Current transaction. */
435         u_int32_t locker;               /* Default process' locker id. */
436         DBT       lock_dbt;             /* DBT referencing lock. */
437         struct __db_ilock lock;         /* Lock. */
439         size_t    pgsize;               /* Logical page size of file. */
441                                         /* Local heap allocation. */
442         void *(*db_malloc) __P((size_t));
444                                         /* Functions. */
445         int (*close)    __P((DB *, u_int32_t));
446         int (*cursor)   __P((DB *, DB_TXN *, DBC **));
447         int (*del)      __P((DB *, DB_TXN *, DBT *, u_int32_t));
448         int (*fd)       __P((DB *, int *));
449         int (*get)      __P((DB *, DB_TXN *, DBT *, DBT *, u_int32_t));
450         int (*put)      __P((DB *, DB_TXN *, DBT *, DBT *, u_int32_t));
451         int (*stat)     __P((DB *, void *, void *(*)(size_t), u_int32_t));
452         int (*sync)     __P((DB *, u_int32_t));
454 #define DB_AM_DUP       0x000001        /* DB_DUP (internal). */
455 #define DB_AM_INMEM     0x000002        /* In-memory; no sync on close. */
456 #define DB_AM_LOCKING   0x000004        /* Perform locking. */
457 #define DB_AM_LOGGING   0x000008        /* Perform logging. */
458 #define DB_AM_MLOCAL    0x000010        /* Database memory pool is local. */
459 #define DB_AM_PGDEF     0x000020        /* Page size was defaulted. */
460 #define DB_AM_RDONLY    0x000040        /* Database is readonly. */
461 #define DB_AM_RECOVER   0x000080        /* In recovery (do not log or lock). */
462 #define DB_AM_SWAP      0x000100        /* Pages need to be byte-swapped. */
463 #define DB_AM_THREAD    0x000200        /* DB is multi-threaded. */
464 #define DB_BT_RECNUM    0x000400        /* DB_RECNUM (internal) */
465 #define DB_HS_DIRTYMETA 0x000800        /* Hash: Metadata page modified. */
466 #define DB_RE_DELIMITER 0x001000        /* DB_DELIMITER (internal). */
467 #define DB_RE_FIXEDLEN  0x002000        /* DB_FIXEDLEN (internal). */
468 #define DB_RE_PAD       0x004000        /* DB_PAD (internal). */
469 #define DB_RE_RENUMBER  0x008000        /* DB_RENUMBER (internal). */
470 #define DB_RE_SNAPSHOT  0x010000        /* DB_SNAPSHOT (internal). */
471         u_int32_t flags;
474 /* Cursor description structure. */
475 struct __dbc {
476         DB *dbp;                        /* Related DB access method. */
477         DB_TXN   *txn;                  /* Associated transaction. */
479         /*
480          * XXX
481          * Explicit representations of structures in queue.h.
482          *
483          * TAILQ_ENTRY(__dbc);
484          */
485         struct {
486                 struct __dbc *tqe_next;
487                 struct __dbc **tqe_prev;
488         } links;
490         void     *internal;             /* Access method private. */
492         int (*c_close)  __P((DBC *));
493         int (*c_del)    __P((DBC *, u_int32_t));
494         int (*c_get)    __P((DBC *, DBT *, DBT *, u_int32_t));
495         int (*c_put)    __P((DBC *, DBT *, DBT *, u_int32_t));
498 /* Btree/recno statistics structure. */
499 struct __db_bt_stat {
500         u_int32_t bt_flags;             /* Open flags. */
501         u_int32_t bt_maxkey;            /* Maxkey value. */
502         u_int32_t bt_minkey;            /* Minkey value. */
503         u_int32_t bt_re_len;            /* Fixed-length record length. */
504         u_int32_t bt_re_pad;            /* Fixed-length record pad. */
505         u_int32_t bt_pagesize;          /* Page size. */
506         u_int32_t bt_levels;            /* Tree levels. */
507         u_int32_t bt_nrecs;             /* Number of records. */
508         u_int32_t bt_int_pg;            /* Internal pages. */
509         u_int32_t bt_leaf_pg;           /* Leaf pages. */
510         u_int32_t bt_dup_pg;            /* Duplicate pages. */
511         u_int32_t bt_over_pg;           /* Overflow pages. */
512         u_int32_t bt_free;              /* Pages on the free list. */
513         u_int32_t bt_freed;             /* Pages freed for reuse. */
514         u_int32_t bt_int_pgfree;        /* Bytes free in internal pages. */
515         u_int32_t bt_leaf_pgfree;       /* Bytes free in leaf pages. */
516         u_int32_t bt_dup_pgfree;        /* Bytes free in duplicate pages. */
517         u_int32_t bt_over_pgfree;       /* Bytes free in overflow pages. */
518         u_int32_t bt_pfxsaved;          /* Bytes saved by prefix compression. */
519         u_int32_t bt_split;             /* Total number of splits. */
520         u_int32_t bt_rootsplit;         /* Root page splits. */
521         u_int32_t bt_fastsplit;         /* Fast splits. */
522         u_int32_t bt_added;             /* Items added. */
523         u_int32_t bt_deleted;           /* Items deleted. */
524         u_int32_t bt_get;               /* Items retrieved. */
525         u_int32_t bt_cache_hit;         /* Hits in fast-insert code. */
526         u_int32_t bt_cache_miss;        /* Misses in fast-insert code. */
527         u_int32_t bt_magic;             /* Magic number. */
528         u_int32_t bt_version;           /* Version number. */
531 #if defined(__cplusplus)
532 extern "C" {
533 #endif
534 int   db_appinit __P((const char *, char * const *, DB_ENV *, u_int32_t));
535 int   db_appexit __P((DB_ENV *));
536 int   db_jump_set __P((void *, int));
537 int   db_open __P((const char *,
538           DBTYPE, u_int32_t, int, DB_ENV *, DB_INFO *, DB **));
539 int   db_value_set __P((int, int));
540 char *db_version __P((int *, int *, int *));
541 #if defined(__cplusplus)
543 #endif
545 /*******************************************************
546  * Locking
547  *******************************************************/
548 #define DB_LOCKVERSION  1
549 #define DB_LOCKMAGIC    0x090193
551 /* Flag values for lock_vec(). */
552 #define DB_LOCK_NOWAIT          0x01    /* Don't wait on unavailable lock. */
554 /* Flag values for lock_detect(). */
555 #define DB_LOCK_CONFLICT        0x01    /* Run on any conflict. */
558  * Request types.
560  * XXX
561  * Changes here must be reflected in java/src/com/sleepycat/db/Db.java.
562  */
563 typedef enum {
564         DB_LOCK_DUMP=0,                 /* Display held locks. */
565         DB_LOCK_GET,                    /* Get the lock. */
566         DB_LOCK_PUT,                    /* Release the lock. */
567         DB_LOCK_PUT_ALL,                /* Release locker's locks. */
568         DB_LOCK_PUT_OBJ                 /* Release locker's locks on obj. */
569 } db_lockop_t;
572  * Simple R/W lock modes and for multi-granularity intention locking.
574  * XXX
575  * Changes here must be reflected in java/src/com/sleepycat/db/Db.java.
576  */
577 typedef enum {
578         DB_LOCK_NG=0,                   /* Not granted. */
579         DB_LOCK_READ,                   /* Shared/read. */
580         DB_LOCK_WRITE,                  /* Exclusive/write. */
581         DB_LOCK_IREAD,                  /* Intent to share/read. */
582         DB_LOCK_IWRITE,                 /* Intent exclusive/write. */
583         DB_LOCK_IWR                     /* Intent to read and write. */
584 } db_lockmode_t;
587  * Status of a lock.
588  */
589 typedef enum {
590         DB_LSTAT_ABORTED,               /* Lock belongs to an aborted txn. */
591         DB_LSTAT_ERR,                   /* Lock is bad. */
592         DB_LSTAT_FREE,                  /* Lock is unallocated. */
593         DB_LSTAT_HELD,                  /* Lock is currently held. */
594         DB_LSTAT_NOGRANT,               /* Lock was not granted. */
595         DB_LSTAT_PENDING,               /* Lock was waiting and has been
596                                          * promoted; waiting for the owner
597                                          * to run and upgrade it to held. */
598         DB_LSTAT_WAITING                /* Lock is on the wait queue. */
599 } db_status_t;
601 /* Lock request structure. */
602 struct __db_lockreq {
603         db_lockop_t      op;            /* Operation. */
604         db_lockmode_t    mode;          /* Requested mode. */
605         u_int32_t        locker;        /* Locker identity. */
606         DBT             *obj;           /* Object being locked. */
607         DB_LOCK          lock;          /* Lock returned. */
611  * Commonly used conflict matrices.
613  * Standard Read/Write (or exclusive/shared) locks.
614  */
615 #define DB_LOCK_RW_N    3
616 extern const u_int8_t db_rw_conflicts[];
618 /* Multi-granularity locking. */
619 #define DB_LOCK_RIW_N   6
620 extern const u_int8_t db_riw_conflicts[];
622 struct __db_lock_stat {
623         u_int32_t st_magic;             /* Lock file magic number. */
624         u_int32_t st_version;           /* Lock file version number. */
625         u_int32_t st_maxlocks;          /* Maximum number of locks in table. */
626         u_int32_t st_nmodes;            /* Number of lock modes. */
627         u_int32_t st_numobjs;           /* Number of objects. */
628         u_int32_t st_nlockers;          /* Number of lockers. */
629         u_int32_t st_nconflicts;        /* Number of lock conflicts. */
630         u_int32_t st_nrequests;         /* Number of lock gets. */
631         u_int32_t st_nreleases;         /* Number of lock puts. */
632         u_int32_t st_ndeadlocks;        /* Number of lock deadlocks. */
633         u_int32_t st_region_wait;       /* Region lock granted after wait. */
634         u_int32_t st_region_nowait;     /* Region lock granted without wait. */
635         u_int32_t st_refcnt;            /* Region reference count. */
636         u_int32_t st_regsize;           /* Region size. */
639 #if defined(__cplusplus)
640 extern "C" {
641 #endif
642 int       lock_close __P((DB_LOCKTAB *));
643 int       lock_detect __P((DB_LOCKTAB *, u_int32_t, u_int32_t));
644 int       lock_get __P((DB_LOCKTAB *,
645             u_int32_t, u_int32_t, const DBT *, db_lockmode_t, DB_LOCK *));
646 int       lock_id __P((DB_LOCKTAB *, u_int32_t *));
647 int       lock_open __P((const char *,
648             u_int32_t, int, DB_ENV *, DB_LOCKTAB **));
649 int       lock_put __P((DB_LOCKTAB *, DB_LOCK));
650 int       lock_stat __P((DB_LOCKTAB *, DB_LOCK_STAT **, void *(*)(size_t)));
651 int       lock_unlink __P((const char *, int, DB_ENV *));
652 int       lock_vec __P((DB_LOCKTAB *,
653             u_int32_t, u_int32_t, DB_LOCKREQ *, int, DB_LOCKREQ **));
654 #if defined(__cplusplus)
656 #endif
658 /*******************************************************
659  * Logging.
660  *******************************************************/
661 /* Flag values for log_archive(). */
662 #define DB_ARCH_ABS             0x001   /* Absolute pathnames. */
663 #define DB_ARCH_DATA            0x002   /* Data files. */
664 #define DB_ARCH_LOG             0x004   /* Log files. */
667  * A DB_LSN has two parts, a fileid which identifies a specific file, and an
668  * offset within that file.  The fileid is an unsigned 4-byte quantity that
669  * uniquely identifies a file within the log directory -- currently a simple
670  * counter inside the log.  The offset is also an unsigned 4-byte value.  The
671  * log manager guarantees the offset is never more than 4 bytes by switching
672  * to a new log file before the maximum length imposed by an unsigned 4-byte
673  * offset is reached.
674  */
675 struct __db_lsn {
676         u_int32_t       file;           /* File ID. */
677         u_int32_t       offset;         /* File offset. */
680 /* Log statistics structure. */
681 struct __db_log_stat {
682         u_int32_t st_magic;             /* Log file magic number. */
683         u_int32_t st_version;           /* Log file version number. */
684         int st_mode;                    /* Log file mode. */
685         u_int32_t st_lg_max;            /* Maximum log file size. */
686         u_int32_t st_w_bytes;           /* Bytes to log. */
687         u_int32_t st_w_mbytes;          /* Megabytes to log. */
688         u_int32_t st_wc_bytes;          /* Bytes to log since checkpoint. */
689         u_int32_t st_wc_mbytes;         /* Megabytes to log since checkpoint. */
690         u_int32_t st_wcount;            /* Total syncs to the log. */
691         u_int32_t st_scount;            /* Total writes to the log. */
692         u_int32_t st_region_wait;       /* Region lock granted after wait. */
693         u_int32_t st_region_nowait;     /* Region lock granted without wait. */
694         u_int32_t st_cur_file;          /* Current log file number. */
695         u_int32_t st_cur_offset;        /* Current log file offset. */
696         u_int32_t st_refcnt;            /* Region reference count. */
697         u_int32_t st_regsize;           /* Region size. */
700 #if defined(__cplusplus)
701 extern "C" {
702 #endif
703 int      log_archive __P((DB_LOG *, char **[], u_int32_t, void *(*)(size_t)));
704 int      log_close __P((DB_LOG *));
705 int      log_compare __P((const DB_LSN *, const DB_LSN *));
706 int      log_file __P((DB_LOG *, const DB_LSN *, char *, size_t));
707 int      log_flush __P((DB_LOG *, const DB_LSN *));
708 int      log_get __P((DB_LOG *, DB_LSN *, DBT *, u_int32_t));
709 int      log_open __P((const char *, u_int32_t, int, DB_ENV *, DB_LOG **));
710 int      log_put __P((DB_LOG *, DB_LSN *, const DBT *, u_int32_t));
711 int      log_register __P((DB_LOG *, DB *, const char *, DBTYPE, u_int32_t *));
712 int      log_stat __P((DB_LOG *, DB_LOG_STAT **, void *(*)(size_t)));
713 int      log_unlink __P((const char *, int, DB_ENV *));
714 int      log_unregister __P((DB_LOG *, u_int32_t));
715 #if defined(__cplusplus)
717 #endif
719 /*******************************************************
720  * Mpool
721  *******************************************************/
722 /* Flag values for memp_fget(). */
723 #define DB_MPOOL_CREATE         0x001   /* Create a page. */
724 #define DB_MPOOL_LAST           0x002   /* Return the last page. */
725 #define DB_MPOOL_NEW            0x004   /* Create a new page. */
727 /* Flag values for memp_fput(), memp_fset(). */
728 #define DB_MPOOL_CLEAN          0x001   /* Clear modified bit. */
729 #define DB_MPOOL_DIRTY          0x002   /* Page is modified. */
730 #define DB_MPOOL_DISCARD        0x004   /* Don't cache the page. */
732 /* Mpool statistics structure. */
733 struct __db_mpool_stat {
734         size_t st_cachesize;            /* Cache size. */
735         u_int32_t st_cache_hit;         /* Pages found in the cache. */
736         u_int32_t st_cache_miss;        /* Pages not found in the cache. */
737         u_int32_t st_map;               /* Pages from mapped files. */
738         u_int32_t st_page_create;       /* Pages created in the cache. */
739         u_int32_t st_page_in;           /* Pages read in. */
740         u_int32_t st_page_out;          /* Pages written out. */
741         u_int32_t st_ro_evict;          /* Clean pages forced from the cache. */
742         u_int32_t st_rw_evict;          /* Dirty pages forced from the cache. */
743         u_int32_t st_hash_buckets;      /* Number of hash buckets. */
744         u_int32_t st_hash_searches;     /* Total hash chain searches. */
745         u_int32_t st_hash_longest;      /* Longest hash chain searched. */
746         u_int32_t st_hash_examined;     /* Total hash entries searched. */
747         u_int32_t st_page_clean;        /* Clean pages. */
748         u_int32_t st_page_dirty;        /* Dirty pages. */
749         u_int32_t st_page_trickle;      /* Pages written by memp_trickle. */
750         u_int32_t st_region_wait;       /* Region lock granted after wait. */
751         u_int32_t st_region_nowait;     /* Region lock granted without wait. */
752         u_int32_t st_refcnt;            /* Region reference count. */
753         u_int32_t st_regsize;           /* Region size. */
756 /* Mpool file open information structure. */
757 struct __db_mpool_finfo {
758         int        ftype;               /* File type. */
759         DBT       *pgcookie;            /* Byte-string passed to pgin/pgout. */
760         u_int8_t  *fileid;              /* Unique file ID. */
761         int32_t    lsn_offset;          /* LSN offset in page. */
762         u_int32_t  clear_len;           /* Cleared length on created pages. */
765 /* Mpool file statistics structure. */
766 struct __db_mpool_fstat {
767         char *file_name;                /* File name. */
768         size_t st_pagesize;             /* Page size. */
769         u_int32_t st_cache_hit;         /* Pages found in the cache. */
770         u_int32_t st_cache_miss;        /* Pages not found in the cache. */
771         u_int32_t st_map;               /* Pages from mapped files. */
772         u_int32_t st_page_create;       /* Pages created in the cache. */
773         u_int32_t st_page_in;           /* Pages read in. */
774         u_int32_t st_page_out;          /* Pages written out. */
777 #if defined(__cplusplus)
778 extern "C" {
779 #endif
780 int     memp_close __P((DB_MPOOL *));
781 int     memp_fclose __P((DB_MPOOLFILE *));
782 int     memp_fget __P((DB_MPOOLFILE *, db_pgno_t *, u_int32_t, void *));
783 int     memp_fopen __P((DB_MPOOL *, const char *,
784             u_int32_t, int, size_t, DB_MPOOL_FINFO *, DB_MPOOLFILE **));
785 int     memp_fput __P((DB_MPOOLFILE *, void *, u_int32_t));
786 int     memp_fset __P((DB_MPOOLFILE *, void *, u_int32_t));
787 int     memp_fsync __P((DB_MPOOLFILE *));
788 int     memp_open __P((const char *, u_int32_t, int, DB_ENV *, DB_MPOOL **));
789 int     memp_register __P((DB_MPOOL *, int,
790             int (*)(db_pgno_t, void *, DBT *),
791             int (*)(db_pgno_t, void *, DBT *)));
792 int     memp_stat __P((DB_MPOOL *,
793             DB_MPOOL_STAT **, DB_MPOOL_FSTAT ***, void *(*)(size_t)));
794 int     memp_sync __P((DB_MPOOL *, DB_LSN *));
795 int     memp_trickle __P((DB_MPOOL *, int, int *));
796 int     memp_unlink __P((const char *, int, DB_ENV *));
797 #if defined(__cplusplus)
799 #endif
801 /*******************************************************
802  * Transactions.
803  *******************************************************/
804 #define DB_TXNVERSION   1
805 #define DB_TXNMAGIC     0x041593
807 /* Operations values to the tx_recover() function. */
808 #define DB_TXN_BACKWARD_ROLL    1       /* Read the log backwards. */
809 #define DB_TXN_FORWARD_ROLL     2       /* Read the log forwards. */
810 #define DB_TXN_OPENFILES        3       /* Read for open files. */
811 #define DB_TXN_REDO             4       /* Redo the operation. */
812 #define DB_TXN_UNDO             5       /* Undo the operation. */
814 /* Internal transaction status values. */
816 /* Transaction statistics structure. */
817 struct __db_txn_active {
818         u_int32_t       txnid;          /* Transaction ID */
819         DB_LSN          lsn;            /* Lsn of the begin record */
822 struct __db_txn_stat {
823         DB_LSN    st_last_ckp;          /* lsn of the last checkpoint */
824         DB_LSN    st_pending_ckp;       /* last checkpoint did not finish */
825         time_t    st_time_ckp;          /* time of last checkpoint */
826         u_int32_t st_last_txnid;        /* last transaction id given out */
827         u_int32_t st_maxtxns;   /* maximum number of active txns */
828         u_int32_t st_naborts;   /* number of aborted transactions */
829         u_int32_t st_nbegins;   /* number of begun transactions */
830         u_int32_t st_ncommits;  /* number of committed transactions */
831         u_int32_t st_nactive;   /* number of active transactions */
832         DB_TXN_ACTIVE
833                  *st_txnarray;  /* array of active transactions */
834         u_int32_t st_region_wait;       /* Region lock granted after wait. */
835         u_int32_t st_region_nowait;     /* Region lock granted without wait. */
836         u_int32_t st_refcnt;            /* Region reference count. */
837         u_int32_t st_regsize;           /* Region size. */
840 #if defined(__cplusplus)
841 extern "C" {
842 #endif
843 int       txn_abort __P((DB_TXN *));
844 int       txn_begin __P((DB_TXNMGR *, DB_TXN *, DB_TXN **));
845 int       txn_checkpoint __P((const DB_TXNMGR *, u_int32_t, u_int32_t));
846 int       txn_commit __P((DB_TXN *));
847 int       txn_close __P((DB_TXNMGR *));
848 u_int32_t txn_id __P((DB_TXN *));
849 int       txn_open __P((const char *, u_int32_t, int, DB_ENV *, DB_TXNMGR **));
850 int       txn_prepare __P((DB_TXN *));
851 int       txn_stat __P((DB_TXNMGR *, DB_TXN_STAT **, void *(*)(size_t)));
852 int       txn_unlink __P((const char *, int, DB_ENV *));
853 #if defined(__cplusplus)
855 #endif
857 #ifndef DB_DBM_HSEARCH
858 #define DB_DBM_HSEARCH  0               /* No historic interfaces by default. */
859 #endif
860 #if DB_DBM_HSEARCH != 0
861 /*******************************************************
862  * Dbm/Ndbm historic interfaces.
863  *******************************************************/
864 #define DBM_INSERT      0               /* Flags to dbm_store(). */
865 #define DBM_REPLACE     1
868  * The db(3) support for ndbm(3) always appends this suffix to the
869  * file name to avoid overwriting the user's original database.
870  */
871 #define DBM_SUFFIX      ".db"
873 #if defined(_XPG4_2)
874 typedef struct {
875         char *dptr;
876         size_t dsize;
877 } datum;
878 #else
879 typedef struct {
880         char *dptr;
881         int dsize;
882 } datum;
883 #endif
886  * Translate DBM calls into DB calls so that DB doesn't step on the
887  * application's name space.
889  * The global variables dbrdonly, dirf and pagf were not retained when
890  * 4BSD replaced the dbm interface with ndbm, and are not support here.
891  */
892 #define dbminit(a)      __db_dbm_init(a)
893 #if !defined(__cplusplus)
894 #define delete(a)       __db_dbm_delete(a)
895 #endif
896 #define fetch(a)        __db_dbm_fetch(a)
897 #define firstkey        __db_dbm_firstkey
898 #define nextkey(a)      __db_dbm_nextkey(a)
899 #define store(a, b)     __db_dbm_store(a, b)
901 /* Prototype the DB calls. */
902 #if defined(__cplusplus)
903 extern "C" {
904 #endif
905 int      __db_dbm_init __P((char *));
906 int      __db_dbm_delete __P((datum));
907 int      __db_dbm_dbrdonly __P((void));
908 int      __db_dbm_dirf __P((void));
909 datum    __db_dbm_fetch __P((datum));
910 datum    __db_dbm_firstkey __P((void));
911 datum    __db_dbm_nextkey __P((datum));
912 int      __db_dbm_pagf __P((void));
913 int      __db_dbm_store __P((datum, datum));
914 #if defined(__cplusplus)
916 #endif
919  * Translate NDBM calls into DB calls so that DB doesn't step on the
920  * application's name space.
921  */
922 #define dbm_clearerr(a)         __db_ndbm_clearerr(a)
923 #define dbm_close(a)            __db_ndbm_close(a)
924 #define dbm_delete(a, b)        __db_ndbm_delete(a, b)
925 #define dbm_dirfno(a)           __db_ndbm_dirfno(a)
926 #define dbm_error(a)            __db_ndbm_error(a)
927 #define dbm_fetch(a, b)         __db_ndbm_fetch(a, b)
928 #define dbm_firstkey(a)         __db_ndbm_firstkey(a)
929 #define dbm_nextkey(a)          __db_ndbm_nextkey(a)
930 #define dbm_open(a, b, c)       __db_ndbm_open(a, b, c)
931 #define dbm_pagfno(a)           __db_ndbm_pagfno(a)
932 #define dbm_rdonly(a)           __db_ndbm_rdonly(a)
933 #define dbm_store(a, b, c, d)   __db_ndbm_store(a, b, c, d)
935 /* Prototype the DB calls. */
936 #if defined(__cplusplus)
937 extern "C" {
938 #endif
939 int      __db_ndbm_clearerr __P((DBM *));
940 void     __db_ndbm_close __P((DBM *));
941 int      __db_ndbm_delete __P((DBM *, datum));
942 int      __db_ndbm_dirfno __P((DBM *));
943 int      __db_ndbm_error __P((DBM *));
944 datum    __db_ndbm_fetch __P((DBM *, datum));
945 datum    __db_ndbm_firstkey __P((DBM *));
946 datum    __db_ndbm_nextkey __P((DBM *));
947 DBM     *__db_ndbm_open __P((const char *, int, int));
948 int      __db_ndbm_pagfno __P((DBM *));
949 int      __db_ndbm_rdonly __P((DBM *));
950 int      __db_ndbm_store __P((DBM *, datum, datum, int));
951 #if defined(__cplusplus)
953 #endif
955 /*******************************************************
956  * Hsearch historic interface.
957  *******************************************************/
958 typedef enum {
959         FIND, ENTER
960 } ACTION;
962 typedef struct entry {
963         char *key;
964         char *data;
965 } ENTRY;
968  * Translate HSEARCH calls into DB calls so that DB doesn't step on the
969  * application's name space.
970  */
971 #define hcreate(a)      __db_hcreate(a)
972 #define hdestroy        __db_hdestroy
973 #define hsearch(a, b)   __db_hsearch(a, b)
975 /* Prototype the DB calls. */
976 #if defined(__cplusplus)
977 extern "C" {
978 #endif
979 int      __db_hcreate __P((size_t));
980 void     __db_hdestroy __P((void));
981 ENTRY   *__db_hsearch __P((ENTRY, ACTION));
982 #if defined(__cplusplus)
984 #endif
985 #endif /* DB_DBM_HSEARCH */
988  * XXX
989  * MacOS: Reset Metrowerks C enum sizes.
990  */
991 #ifdef __MWERKS__
992 #pragma enumsalwaysint reset
993 #endif
994 #endif /* !_DB_H_ */