Update.
[glibc.git] / db2 / db.h
blob306f2ffce46947200bcaceab8c2ac64b66c277cd
1 /*-
2 * See the file LICENSE for redistribution information.
4 * Copyright (c) 1996, 1997, 1998
5 * Sleepycat Software. All rights reserved.
7 * @(#)db.h 10.174 (Sleepycat) 1/3/99
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.
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.
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.
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.
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.
55 * !!!
56 * We also provide the standard u_int, u_long etc., if they're not provided
57 * by the system.
60 #define DB_VERSION_MAJOR 2
61 #define DB_VERSION_MINOR 7
62 #define DB_VERSION_PATCH 5
63 #define DB_VERSION_STRING "Sleepycat Software: Berkeley DB 2.7.5: (04/18/99)"
65 typedef u_int32_t db_pgno_t; /* Page number type. */
66 typedef u_int16_t db_indx_t; /* Page offset type. */
67 #define DB_MAX_PAGES 0xffffffff /* >= # of pages in a file */
69 typedef u_int32_t db_recno_t; /* Record number type. */
70 #define DB_MAX_RECORDS 0xffffffff /* >= # of records in a tree */
72 typedef size_t DB_LOCK; /* Object returned by lock manager. */
74 /* Forward structure declarations, so applications get type checking. */
75 struct __db; typedef struct __db DB;
76 #ifdef DB_DBM_HSEARCH
77 typedef struct __db DBM;
78 #endif
79 struct __db_bt_stat; typedef struct __db_bt_stat DB_BTREE_STAT;
80 struct __db_dbt; typedef struct __db_dbt DBT;
81 struct __db_env; typedef struct __db_env DB_ENV;
82 struct __db_ilock; typedef struct __db_ilock DB_LOCK_ILOCK;
83 struct __db_info; typedef struct __db_info DB_INFO;
84 struct __db_lock_stat; typedef struct __db_lock_stat DB_LOCK_STAT;
85 struct __db_lockregion; typedef struct __db_lockregion DB_LOCKREGION;
86 struct __db_lockreq; typedef struct __db_lockreq DB_LOCKREQ;
87 struct __db_locktab; typedef struct __db_locktab DB_LOCKTAB;
88 struct __db_log; typedef struct __db_log DB_LOG;
89 struct __db_log_stat; typedef struct __db_log_stat DB_LOG_STAT;
90 struct __db_lsn; typedef struct __db_lsn DB_LSN;
91 struct __db_mpool; typedef struct __db_mpool DB_MPOOL;
92 struct __db_mpool_finfo;typedef struct __db_mpool_finfo DB_MPOOL_FINFO;
93 struct __db_mpool_fstat;typedef struct __db_mpool_fstat DB_MPOOL_FSTAT;
94 struct __db_mpool_stat; typedef struct __db_mpool_stat DB_MPOOL_STAT;
95 struct __db_mpoolfile; typedef struct __db_mpoolfile DB_MPOOLFILE;
96 struct __db_txn; typedef struct __db_txn DB_TXN;
97 struct __db_txn_active; typedef struct __db_txn_active DB_TXN_ACTIVE;
98 struct __db_txn_stat; typedef struct __db_txn_stat DB_TXN_STAT;
99 struct __db_txnmgr; typedef struct __db_txnmgr DB_TXNMGR;
100 struct __db_txnregion; typedef struct __db_txnregion DB_TXNREGION;
101 struct __dbc; typedef struct __dbc DBC;
103 /* Key/data structure -- a Data-Base Thang. */
104 struct __db_dbt {
105 void *data; /* key/data */
106 u_int32_t size; /* key/data length */
107 u_int32_t ulen; /* RO: length of user buffer. */
108 u_int32_t dlen; /* RO: get/put record length. */
109 u_int32_t doff; /* RO: get/put record offset. */
111 #define DB_DBT_INTERNAL 0x01 /* Ignore user's malloc (internal). */
112 #define DB_DBT_MALLOC 0x02 /* Return in allocated memory. */
113 #define DB_DBT_PARTIAL 0x04 /* Partial put/get. */
114 #define DB_DBT_USERMEM 0x08 /* Return in user's memory. */
115 u_int32_t flags;
119 * DB run-time interface configuration.
121 * There are a set of functions that the application can replace with its
122 * own versions, and some other knobs which can be turned at run-time.
124 #define DB_FUNC_CLOSE 1 /* POSIX 1003.1 close. */
125 #define DB_FUNC_DIRFREE 2 /* DB: free directory list. */
126 #define DB_FUNC_DIRLIST 3 /* DB: create directory list. */
127 #define DB_FUNC_EXISTS 4 /* DB: return if file exists. */
128 #define DB_FUNC_FREE 5 /* ANSI C free. */
129 #define DB_FUNC_FSYNC 6 /* POSIX 1003.1 fsync. */
130 #define DB_FUNC_IOINFO 7 /* DB: return file I/O information. */
131 #define DB_FUNC_MALLOC 8 /* ANSI C malloc. */
132 #define DB_FUNC_MAP 9 /* DB: map file into shared memory. */
133 #define DB_FUNC_OPEN 10 /* POSIX 1003.1 open. */
134 #define DB_FUNC_READ 11 /* POSIX 1003.1 read. */
135 #define DB_FUNC_REALLOC 12 /* ANSI C realloc. */
136 #define DB_FUNC_RUNLINK 13 /* DB: remove a shared region. */
137 #define DB_FUNC_SEEK 14 /* POSIX 1003.1 lseek. */
138 #define DB_FUNC_SLEEP 15 /* DB: sleep secs/usecs. */
139 #define DB_FUNC_UNLINK 16 /* POSIX 1003.1 unlink. */
140 #define DB_FUNC_UNMAP 17 /* DB: unmap shared memory file. */
141 #define DB_FUNC_WRITE 18 /* POSIX 1003.1 write. */
142 #define DB_FUNC_YIELD 19 /* DB: yield thread to scheduler. */
143 #define DB_MUTEXLOCKS 20 /* DB: turn off all mutex locks. */
144 #define DB_PAGEYIELD 21 /* DB: yield the CPU on pool get. */
145 #define DB_REGION_ANON 22 /* DB: anonymous, unnamed regions. */
146 #define DB_REGION_INIT 23 /* DB: page-fault regions in create. */
147 #define DB_REGION_NAME 24 /* DB: anonymous, named regions. */
148 #define DB_TSL_SPINS 25 /* DB: initialize spin count. */
151 * Database configuration and initialization.
154 * Flags understood by both db_open(3) and db_appinit(3).
156 #define DB_CREATE 0x000001 /* O_CREAT: create file as necessary. */
157 #define DB_NOMMAP 0x000002 /* Don't mmap underlying file. */
158 #define DB_THREAD 0x000004 /* Free-thread DB package handles. */
161 * Flags understood by db_appinit(3).
163 /* 0x000007 COMMON MASK. */
164 #define DB_INIT_CDB 0x000008 /* Concurrent Access Methods. */
165 #define DB_INIT_LOCK 0x000010 /* Initialize locking. */
166 #define DB_INIT_LOG 0x000020 /* Initialize logging. */
167 #define DB_INIT_MPOOL 0x000040 /* Initialize mpool. */
168 #define DB_INIT_TXN 0x000080 /* Initialize transactions. */
169 #define DB_MPOOL_PRIVATE 0x000100 /* Mpool: private memory pool. */
170 #define DB_RECOVER 0x000200 /* Run normal recovery. */
171 #define DB_RECOVER_FATAL 0x000400 /* Run catastrophic recovery. */
172 #define DB_TXN_NOSYNC 0x000800 /* Do not sync log on commit. */
173 #define DB_USE_ENVIRON 0x001000 /* Use the environment. */
174 #define DB_USE_ENVIRON_ROOT 0x002000 /* Use the environment if root. */
177 * Flags understood by db_open(3).
179 * DB_EXCL and DB_TEMPORARY are internal only, and are not documented.
180 * DB_SEQUENTIAL is currently internal, but may be exported some day.
182 /* 0x000007 COMMON MASK. */
183 /* 0x001fff ALREADY USED. */
184 #define DB_EXCL 0x002000 /* O_EXCL: exclusive open (internal). */
185 #define DB_RDONLY 0x004000 /* O_RDONLY: read-only. */
186 #define DB_SEQUENTIAL 0x008000 /* Sequential access (internal). */
187 #define DB_TEMPORARY 0x010000 /* Remove on last close (internal). */
188 #define DB_TRUNCATE 0x020000 /* O_TRUNCATE: replace existing DB. */
191 * Deadlock detector modes; used in the DBENV structure to configure the
192 * locking subsystem.
194 #define DB_LOCK_NORUN 0
195 #define DB_LOCK_DEFAULT 1 /* Default policy. */
196 #define DB_LOCK_OLDEST 2 /* Abort oldest transaction. */
197 #define DB_LOCK_RANDOM 3 /* Abort random transaction. */
198 #define DB_LOCK_YOUNGEST 4 /* Abort youngest transaction. */
200 struct __db_env {
201 int db_lorder; /* Byte order. */
203 /* Error message callback. */
204 void (*db_errcall) (const char *, char *);
205 FILE *db_errfile; /* Error message file stream. */
206 const char *db_errpfx; /* Error message prefix. */
207 int db_verbose; /* Generate debugging messages. */
208 int db_panic; /* Panic flag, callback function. */
209 void (*db_paniccall) (DB_ENV *, int);
211 /* User paths. */
212 char *db_home; /* Database home. */
213 char *db_log_dir; /* Database log file directory. */
214 char *db_tmp_dir; /* Database tmp file directory. */
216 char **db_data_dir; /* Database data file directories. */
217 int data_cnt; /* Database data file slots. */
218 int data_next; /* Next Database data file slot. */
220 /* Locking. */
221 DB_LOCKTAB *lk_info; /* Return from lock_open(). */
222 const u_int8_t *lk_conflicts; /* Two dimensional conflict matrix. */
223 u_int32_t lk_modes; /* Number of lock modes in table. */
224 u_int32_t lk_max; /* Maximum number of locks. */
225 u_int32_t lk_detect; /* Deadlock detect on all conflicts. */
227 /* Logging. */
228 DB_LOG *lg_info; /* Return from log_open(). */
229 u_int32_t lg_max; /* Maximum file size. */
231 /* Memory pool. */
232 DB_MPOOL *mp_info; /* Return from memp_open(). */
233 size_t mp_mmapsize; /* Maximum file size for mmap. */
234 size_t mp_size; /* Bytes in the mpool cache. */
236 /* Transactions. */
237 DB_TXNMGR *tx_info; /* Return from txn_open(). */
238 u_int32_t tx_max; /* Maximum number of transactions. */
239 int (*tx_recover) /* Dispatch function for recovery. */
240 (DB_LOG *, DBT *, DB_LSN *, int, void *);
243 * XA support.
245 * !!!
246 * Explicit representations of structures in queue.h.
248 * TAILQ_ENTRY(__db_env);
250 struct {
251 struct __db_env *tqe_next;
252 struct __db_env **tqe_prev;
253 } links;
254 int xa_rmid; /* XA Resource Manager ID. */
255 DB_TXN *xa_txn; /* XA Current transaction. */
257 #define DB_ENV_APPINIT 0x01 /* Paths initialized by db_appinit(). */
258 #define DB_ENV_CDB 0x02 /* Concurrent DB product. */
259 #define DB_ENV_STANDALONE 0x04 /* Test: freestanding environment. */
260 #define DB_ENV_THREAD 0x08 /* DB_ENV is multi-threaded. */
261 u_int32_t flags; /* Flags. */
264 /*******************************************************
265 * Access methods.
266 *******************************************************/
268 * !!!
269 * Changes here must be reflected in java/src/com/sleepycat/db/Db.java.
271 typedef enum {
272 DB_BTREE=1, /* B+tree. */
273 DB_HASH, /* Extended Linear Hashing. */
274 DB_RECNO, /* Fixed and variable-length records. */
275 DB_UNKNOWN /* Figure it out on open. */
276 } DBTYPE;
278 #define DB_BTREEVERSION 6 /* Current btree version. */
279 #define DB_BTREEOLDVER 6 /* Oldest btree version supported. */
280 #define DB_BTREEMAGIC 0x053162
282 #define DB_HASHVERSION 5 /* Current hash version. */
283 #define DB_HASHOLDVER 4 /* Oldest hash version supported. */
284 #define DB_HASHMAGIC 0x061561
286 #define DB_LOGVERSION 2 /* Current log version. */
287 #define DB_LOGOLDVER 2 /* Oldest log version supported. */
288 #define DB_LOGMAGIC 0x040988
290 struct __db_info {
291 int db_lorder; /* Byte order. */
292 size_t db_cachesize; /* Underlying cache size. */
293 size_t db_pagesize; /* Underlying page size. */
295 /* Local heap allocation. */
296 void *(*db_malloc) (size_t);
297 int (*dup_compare) /* Duplicate compare function. */
298 (const DBT *, const DBT *);
300 /* Btree access method. */
301 u_int32_t bt_maxkey; /* Maximum keys per page. */
302 u_int32_t bt_minkey; /* Minimum keys per page. */
303 int (*bt_compare) /* Comparison function. */
304 (const DBT *, const DBT *);
305 size_t (*bt_prefix) /* Prefix function. */
306 (const DBT *, const DBT *);
308 /* Hash access method. */
309 u_int32_t h_ffactor; /* Fill factor. */
310 u_int32_t h_nelem; /* Number of elements. */
311 u_int32_t (*h_hash) /* Hash function. */
312 (const void *, u_int32_t);
314 /* Recno access method. */
315 int re_pad; /* Fixed-length padding byte. */
316 int re_delim; /* Variable-length delimiting byte. */
317 u_int32_t re_len; /* Length for fixed-length records. */
318 char *re_source; /* Source file name. */
320 #define DB_DELIMITER 0x0001 /* Recno: re_delim set. */
321 #define DB_DUP 0x0002 /* Btree, Hash: duplicate keys. */
322 #define DB_DUPSORT 0x0004 /* Btree, Hash: duplicate keys. */
323 #define DB_FIXEDLEN 0x0008 /* Recno: fixed-length records. */
324 #define DB_PAD 0x0010 /* Recno: re_pad set. */
325 #define DB_RECNUM 0x0020 /* Btree: record numbers. */
326 #define DB_RENUMBER 0x0040 /* Recno: renumber on insert/delete. */
327 #define DB_SNAPSHOT 0x0080 /* Recno: snapshot the input. */
328 u_int32_t flags;
332 * DB access method and cursor operation values. Each value is an operation
333 * code to which additional bit flags are added.
335 #define DB_AFTER 1 /* c_put() */
336 #define DB_APPEND 2 /* put() */
337 #define DB_BEFORE 3 /* c_put() */
338 #define DB_CHECKPOINT 4 /* log_put(), log_get() */
339 #define DB_CURLSN 5 /* log_put() */
340 #define DB_CURRENT 6 /* c_get(), c_put(), log_get() */
341 #define DB_FIRST 7 /* c_get(), log_get() */
342 #define DB_FLUSH 8 /* log_put() */
343 #define DB_GET_BOTH 9 /* get(), c_get() */
344 #define DB_GET_RECNO 10 /* c_get() */
345 #define DB_JOIN_ITEM 11 /* c_get(); do not do primary lookup */
346 #define DB_KEYFIRST 12 /* c_put() */
347 #define DB_KEYLAST 13 /* c_put() */
348 #define DB_LAST 14 /* c_get(), log_get() */
349 #define DB_NEXT 15 /* c_get(), log_get() */
350 #define DB_NEXT_DUP 16 /* c_get() */
351 #define DB_NOOVERWRITE 17 /* put() */
352 #define DB_NOSYNC 18 /* close() */
353 #define DB_PREV 19 /* c_get(), log_get() */
354 #define DB_RECORDCOUNT 20 /* stat() */
355 #define DB_SET 21 /* c_get(), log_get() */
356 #define DB_SET_RANGE 22 /* c_get() */
357 #define DB_SET_RECNO 23 /* get(), c_get() */
358 #define DB_WRITELOCK 24 /* cursor() (internal) */
360 #define DB_OPFLAGS_MASK 0x1f /* Mask for operations flags. */
361 #define DB_RMW 0x80000000 /* Acquire write flag immediately. */
364 * DB (user visible) error return codes.
366 * !!!
367 * Changes to any of the user visible error return codes must be reflected
368 * in java/src/com/sleepycat/db/Db.java.
370 #define DB_INCOMPLETE ( -1) /* Sync didn't finish. */
371 #define DB_KEYEMPTY ( -2) /* The key/data pair was deleted or
372 was never created by the user. */
373 #define DB_KEYEXIST ( -3) /* The key/data pair already exists. */
374 #define DB_LOCK_DEADLOCK ( -4) /* Locker killed to resolve deadlock. */
375 #define DB_LOCK_NOTGRANTED ( -5) /* Lock unavailable, no-wait set. */
376 #define DB_LOCK_NOTHELD ( -6) /* Lock not held by locker. */
377 #define DB_NOTFOUND ( -7) /* Key/data pair not found (EOF). */
378 #define DB_RUNRECOVERY ( -8) /* Panic return. */
380 /* DB (private) error return codes. */
381 #define DB_DELETED ( -9) /* Recovery file marked deleted. */
382 #define DB_NEEDSPLIT (-10) /* Page needs to be split. */
383 #define DB_SWAPBYTES (-11) /* Database needs byte swapping. */
384 #define DB_TXN_CKP (-12) /* Encountered ckp record in log. */
386 #define DB_FILE_ID_LEN 20 /* DB file ID length. */
388 /* DB access method description structure. */
389 struct __db {
390 void *mutexp; /* Synchronization for free threading */
392 /* Documented, returned information. */
393 DBTYPE type; /* DB access method. */
394 int byteswapped; /* Database byte order is swapped. */
396 DB_ENV *dbenv; /* DB_ENV structure. */
397 DB_ENV *mp_dbenv; /* DB_ENV for local mpool creation. */
399 void *internal; /* Access method private. */
401 DB_MPOOL *mp; /* The access method's mpool. */
402 DB_MPOOLFILE *mpf; /* The access method's mpool file. */
405 * !!!
406 * Explicit representations of structures in queue.h.
408 * TAILQ_HEAD(free_queue, __dbc);
409 * TAILQ_HEAD(active_queue, __dbc);
411 struct {
412 struct __dbc *tqh_first;
413 struct __dbc **tqh_last;
414 } free_queue;
415 struct {
416 struct __dbc *tqh_first;
417 struct __dbc **tqh_last;
418 } active_queue;
420 u_int8_t fileid[DB_FILE_ID_LEN]; /* Uniquely identify this file for
421 locking. */
422 u_int32_t log_fileid; /* Logging file id. */
423 size_t pgsize; /* Logical page size of file. */
425 /* Local heap allocation. */
426 void *(*db_malloc) (size_t);
427 int (*dup_compare) /* Duplicate compare function. */
428 (const DBT *, const DBT *);
429 u_int32_t (*h_hash) /* Hash function. */
430 (const void *, u_int32_t);
432 /* Functions. */
433 int (*am_close) (DB *);
434 int (*close) (DB *, u_int32_t);
435 int (*cursor) (DB *, DB_TXN *, DBC **, u_int32_t);
436 int (*del) (DB *, DB_TXN *, DBT *, u_int32_t);
437 int (*fd) (DB *, int *);
438 int (*get) (DB *, DB_TXN *, DBT *, DBT *, u_int32_t);
439 int (*join) (DB *, DBC **, u_int32_t, DBC **);
440 int (*put) (DB *, DB_TXN *, DBT *, DBT *, u_int32_t);
441 int (*stat) (DB *, void *, void *(*)(size_t), u_int32_t);
442 int (*sync) (DB *, u_int32_t);
444 #define DB_AM_CDB 0x000001 /* Concurrent Access Methods. */
445 #define DB_AM_DUP 0x000002 /* DB_DUP (internal). */
446 #define DB_AM_INMEM 0x000004 /* In-memory; no sync on close. */
447 #define DB_AM_LOCKING 0x000008 /* Perform locking. */
448 #define DB_AM_LOGGING 0x000010 /* Perform logging. */
449 #define DB_AM_MLOCAL 0x000020 /* Database memory pool is local. */
450 #define DB_AM_PGDEF 0x000040 /* Page size was defaulted. */
451 #define DB_AM_RDONLY 0x000080 /* Database is readonly. */
452 #define DB_AM_SWAP 0x000100 /* Pages need to be byte-swapped. */
453 #define DB_AM_THREAD 0x000200 /* DB is multi-threaded. */
454 #define DB_BT_RECNUM 0x000400 /* DB_RECNUM (internal). */
455 #define DB_DBM_ERROR 0x000800 /* Error in DBM/NDBM database. */
456 #define DB_RE_DELIMITER 0x001000 /* DB_DELIMITER (internal). */
457 #define DB_RE_FIXEDLEN 0x002000 /* DB_FIXEDLEN (internal). */
458 #define DB_RE_PAD 0x004000 /* DB_PAD (internal). */
459 #define DB_RE_RENUMBER 0x008000 /* DB_RENUMBER (internal). */
460 #define DB_RE_SNAPSHOT 0x010000 /* DB_SNAPSHOT (internal). */
461 u_int32_t flags;
464 struct __db_ilock { /* Internal DB access method lock. */
465 db_pgno_t pgno; /* Page being locked. */
466 u_int8_t fileid[DB_FILE_ID_LEN];/* File id. */
469 /* Cursor description structure. */
470 struct __dbc {
471 DB *dbp; /* Related DB access method. */
472 DB_TXN *txn; /* Associated transaction. */
475 * !!!
476 * Explicit representations of structures in queue.h.
478 * TAILQ_ENTRY(__dbc);
480 struct {
481 struct __dbc *tqe_next;
482 struct __dbc **tqe_prev;
483 } links;
485 u_int32_t lid; /* Default process' locker id. */
486 u_int32_t locker; /* Locker for this operation. */
487 DBT lock_dbt; /* DBT referencing lock. */
488 DB_LOCK_ILOCK lock; /* Object to be locked. */
489 DB_LOCK mylock; /* Lock held on this cursor. */
491 DBT rkey; /* Returned key. */
492 DBT rdata; /* Returned data. */
494 int (*c_am_close) (DBC *);
495 int (*c_am_destroy) (DBC *);
496 int (*c_close) (DBC *);
497 int (*c_del) (DBC *, u_int32_t);
498 int (*c_get) (DBC *, DBT *, DBT *, u_int32_t);
499 int (*c_put) (DBC *, DBT *, DBT *, u_int32_t);
501 void *internal; /* Access method private. */
503 #define DBC_CONTINUE 0x001 /* Continue dup search: next item. */
504 #define DBC_KEYSET 0x002 /* Continue dup search: current item. */
505 #define DBC_RECOVER 0x004 /* In recovery (do not log or lock). */
506 #define DBC_RMW 0x008 /* Acquire write flag in read op. */
507 #define DBC_WRITER 0x010 /* Cursor immediately writing (CDB). */
508 u_int32_t flags;
511 /* Btree/recno statistics structure. */
512 struct __db_bt_stat {
513 u_int32_t bt_flags; /* Open flags. */
514 u_int32_t bt_maxkey; /* Maxkey value. */
515 u_int32_t bt_minkey; /* Minkey value. */
516 u_int32_t bt_re_len; /* Fixed-length record length. */
517 u_int32_t bt_re_pad; /* Fixed-length record pad. */
518 u_int32_t bt_pagesize; /* Page size. */
519 u_int32_t bt_levels; /* Tree levels. */
520 u_int32_t bt_nrecs; /* Number of records. */
521 u_int32_t bt_int_pg; /* Internal pages. */
522 u_int32_t bt_leaf_pg; /* Leaf pages. */
523 u_int32_t bt_dup_pg; /* Duplicate pages. */
524 u_int32_t bt_over_pg; /* Overflow pages. */
525 u_int32_t bt_free; /* Pages on the free list. */
526 u_int32_t bt_int_pgfree; /* Bytes free in internal pages. */
527 u_int32_t bt_leaf_pgfree; /* Bytes free in leaf pages. */
528 u_int32_t bt_dup_pgfree; /* Bytes free in duplicate pages. */
529 u_int32_t bt_over_pgfree; /* Bytes free in overflow pages. */
530 u_int32_t bt_magic; /* Magic number. */
531 u_int32_t bt_version; /* Version number. */
534 /* Hash statistics structure. */
535 struct __db_h_stat {
536 u_int32_t hash_accesses; /* Number of accesses to this table. */
537 u_int32_t hash_collisions; /* Number of collisions on search. */
538 u_int32_t hash_expansions; /* Number of times we added a bucket. */
539 u_int32_t hash_overflows; /* Number of overflow pages. */
540 u_int32_t hash_bigpages; /* Number of big key/data pages. */
541 u_int32_t hash_dup; /* Number of dup pages. */
542 u_int32_t hash_free; /* Pages on the free list. */
543 u_int32_t hash_bfree; /* Bytes free on bucket pages. */
544 u_int32_t hash_dup_free; /* Bytes free on duplicate pages. */
545 u_int32_t hash_big_bfree; /* Bytes free on big item pages. */
546 u_int32_t hash_buckets; /* Number of hash buckets. */
547 u_int32_t hash_put; /* Number of puts. */
548 u_int32_t hash_deleted; /* Number of deletes. */
549 u_int32_t hash_get; /* Number of gets. */
550 u_int32_t hash_magic; /* Magic number. */
551 u_int32_t hash_version; /* Version number. */
552 u_int32_t hash_pagesize; /* Page size. */
553 u_int32_t hash_nrecs; /* Number of records. */
556 #if defined(__cplusplus)
557 extern "C" {
558 #endif
559 int db_appinit (const char *, char * const *, DB_ENV *, u_int32_t);
560 int db_appexit (DB_ENV *);
561 int db_jump_set (void *, int);
562 int db_open (const char *,
563 DBTYPE, u_int32_t, int, DB_ENV *, DB_INFO *, DB **);
564 int db_value_set (int, int);
565 char *db_version (int *, int *, int *);
566 int db_xa_open (const char *, DBTYPE, u_int32_t, int, DB_INFO *, DB **);
567 #if defined(__cplusplus)
569 #endif
571 /*******************************************************
572 * Locking
573 *******************************************************/
574 #define DB_LOCKVERSION 1
575 #define DB_LOCKMAGIC 0x090193
577 /* Flag values for lock_vec(), lock_get(). */
578 #define DB_LOCK_NOWAIT 0x01 /* Don't wait on unavailable lock. */
579 #define DB_LOCK_UPGRADE 0x02 /* Upgrade an existing lock instead
580 of granting a new one (internal). */
582 /* Flag values for lock_detect(). */
583 #define DB_LOCK_CONFLICT 0x01 /* Run on any conflict. */
586 * Request types.
588 * !!!
589 * Changes here must be reflected in java/src/com/sleepycat/db/Db.java.
591 typedef enum {
592 DB_LOCK_DUMP=0, /* Display held locks. */
593 DB_LOCK_GET, /* Get the lock. */
594 DB_LOCK_INHERIT, /* Pass locks to parent. */
595 DB_LOCK_PUT, /* Release the lock. */
596 DB_LOCK_PUT_ALL, /* Release locker's locks. */
597 DB_LOCK_PUT_OBJ /* Release locker's locks on obj. */
598 } db_lockop_t;
601 * Simple R/W lock modes and for multi-granularity intention locking.
603 * !!!
604 * These values are NOT random, as they are used as an index into the lock
605 * conflicts arrays, i.e., DB_LOCK_IWRITE must be == 3, and DB_LOCK_IREAD
606 * must be == 4.
608 * !!!
609 * Changes here must be reflected in java/src/com/sleepycat/db/Db.java.
611 typedef enum {
612 DB_LOCK_NG=0, /* Not granted. */
613 DB_LOCK_READ, /* Shared/read. */
614 DB_LOCK_WRITE, /* Exclusive/write. */
615 DB_LOCK_IWRITE, /* Intent exclusive/write. */
616 DB_LOCK_IREAD, /* Intent to share/read. */
617 DB_LOCK_IWR /* Intent to read and write. */
618 } db_lockmode_t;
621 * Status of a lock.
623 typedef enum {
624 DB_LSTAT_ABORTED, /* Lock belongs to an aborted txn. */
625 DB_LSTAT_ERR, /* Lock is bad. */
626 DB_LSTAT_FREE, /* Lock is unallocated. */
627 DB_LSTAT_HELD, /* Lock is currently held. */
628 DB_LSTAT_NOGRANT, /* Lock was not granted. */
629 DB_LSTAT_PENDING, /* Lock was waiting and has been
630 * promoted; waiting for the owner
631 * to run and upgrade it to held. */
632 DB_LSTAT_WAITING /* Lock is on the wait queue. */
633 } db_status_t;
635 /* Lock request structure. */
636 struct __db_lockreq {
637 db_lockop_t op; /* Operation. */
638 db_lockmode_t mode; /* Requested mode. */
639 u_int32_t locker; /* Locker identity. */
640 DBT *obj; /* Object being locked. */
641 DB_LOCK lock; /* Lock returned. */
645 * Commonly used conflict matrices.
647 * Standard Read/Write (or exclusive/shared) locks.
649 #define DB_LOCK_RW_N 3
650 extern const u_int8_t db_rw_conflicts[];
652 /* Multi-granularity locking. */
653 #define DB_LOCK_RIW_N 6
654 extern const u_int8_t db_riw_conflicts[];
656 struct __db_lock_stat {
657 u_int32_t st_magic; /* Lock file magic number. */
658 u_int32_t st_version; /* Lock file version number. */
659 u_int32_t st_maxlocks; /* Maximum number of locks in table. */
660 u_int32_t st_nmodes; /* Number of lock modes. */
661 u_int32_t st_numobjs; /* Number of objects. */
662 u_int32_t st_nlockers; /* Number of lockers. */
663 u_int32_t st_nconflicts; /* Number of lock conflicts. */
664 u_int32_t st_nrequests; /* Number of lock gets. */
665 u_int32_t st_nreleases; /* Number of lock puts. */
666 u_int32_t st_ndeadlocks; /* Number of lock deadlocks. */
667 u_int32_t st_region_wait; /* Region lock granted after wait. */
668 u_int32_t st_region_nowait; /* Region lock granted without wait. */
669 u_int32_t st_refcnt; /* Region reference count. */
670 u_int32_t st_regsize; /* Region size. */
673 #if defined(__cplusplus)
674 extern "C" {
675 #endif
676 int lock_close (DB_LOCKTAB *);
677 int lock_detect (DB_LOCKTAB *, u_int32_t, u_int32_t);
678 int lock_get (DB_LOCKTAB *,
679 u_int32_t, u_int32_t, const DBT *, db_lockmode_t, DB_LOCK *);
680 int lock_id (DB_LOCKTAB *, u_int32_t *);
681 int lock_open (const char *, u_int32_t, int, DB_ENV *, DB_LOCKTAB **);
682 int lock_put (DB_LOCKTAB *, DB_LOCK);
683 int lock_tget (DB_LOCKTAB *,
684 DB_TXN *, u_int32_t, const DBT *, db_lockmode_t, DB_LOCK *);
685 int lock_stat (DB_LOCKTAB *, DB_LOCK_STAT **, void *(*)(size_t));
686 int lock_unlink (const char *, int, DB_ENV *);
687 int lock_vec (DB_LOCKTAB *,
688 u_int32_t, u_int32_t, DB_LOCKREQ *, int, DB_LOCKREQ **);
689 int lock_tvec (DB_LOCKTAB *,
690 DB_TXN *, u_int32_t, DB_LOCKREQ *, int, DB_LOCKREQ **);
691 #if defined(__cplusplus)
693 #endif
695 /*******************************************************
696 * Logging.
697 *******************************************************/
698 /* Flag values for log_archive(). */
699 #define DB_ARCH_ABS 0x001 /* Absolute pathnames. */
700 #define DB_ARCH_DATA 0x002 /* Data files. */
701 #define DB_ARCH_LOG 0x004 /* Log files. */
704 * A DB_LSN has two parts, a fileid which identifies a specific file, and an
705 * offset within that file. The fileid is an unsigned 4-byte quantity that
706 * uniquely identifies a file within the log directory -- currently a simple
707 * counter inside the log. The offset is also an unsigned 4-byte value. The
708 * log manager guarantees the offset is never more than 4 bytes by switching
709 * to a new log file before the maximum length imposed by an unsigned 4-byte
710 * offset is reached.
712 struct __db_lsn {
713 u_int32_t file; /* File ID. */
714 u_int32_t offset; /* File offset. */
717 /* Log statistics structure. */
718 struct __db_log_stat {
719 u_int32_t st_magic; /* Log file magic number. */
720 u_int32_t st_version; /* Log file version number. */
721 int st_mode; /* Log file mode. */
722 u_int32_t st_lg_max; /* Maximum log file size. */
723 u_int32_t st_w_bytes; /* Bytes to log. */
724 u_int32_t st_w_mbytes; /* Megabytes to log. */
725 u_int32_t st_wc_bytes; /* Bytes to log since checkpoint. */
726 u_int32_t st_wc_mbytes; /* Megabytes to log since checkpoint. */
727 u_int32_t st_wcount; /* Total syncs to the log. */
728 u_int32_t st_scount; /* Total writes to the log. */
729 u_int32_t st_region_wait; /* Region lock granted after wait. */
730 u_int32_t st_region_nowait; /* Region lock granted without wait. */
731 u_int32_t st_cur_file; /* Current log file number. */
732 u_int32_t st_cur_offset; /* Current log file offset. */
733 u_int32_t st_refcnt; /* Region reference count. */
734 u_int32_t st_regsize; /* Region size. */
737 #if defined(__cplusplus)
738 extern "C" {
739 #endif
740 int log_archive (DB_LOG *, char **[], u_int32_t, void *(*)(size_t));
741 int log_close (DB_LOG *);
742 int log_compare (const DB_LSN *, const DB_LSN *);
743 int log_file (DB_LOG *, const DB_LSN *, char *, size_t);
744 int log_flush (DB_LOG *, const DB_LSN *);
745 int log_get (DB_LOG *, DB_LSN *, DBT *, u_int32_t);
746 int log_open (const char *, u_int32_t, int, DB_ENV *, DB_LOG **);
747 int log_put (DB_LOG *, DB_LSN *, const DBT *, u_int32_t);
748 int log_register (DB_LOG *, DB *, const char *, DBTYPE, u_int32_t *);
749 int log_stat (DB_LOG *, DB_LOG_STAT **, void *(*)(size_t));
750 int log_unlink (const char *, int, DB_ENV *);
751 int log_unregister (DB_LOG *, u_int32_t);
752 #if defined(__cplusplus)
754 #endif
756 /*******************************************************
757 * Mpool
758 *******************************************************/
759 /* Flag values for memp_fget(). */
760 #define DB_MPOOL_CREATE 0x001 /* Create a page. */
761 #define DB_MPOOL_LAST 0x002 /* Return the last page. */
762 #define DB_MPOOL_NEW 0x004 /* Create a new page. */
764 /* Flag values for memp_fput(), memp_fset(). */
765 #define DB_MPOOL_CLEAN 0x001 /* Clear modified bit. */
766 #define DB_MPOOL_DIRTY 0x002 /* Page is modified. */
767 #define DB_MPOOL_DISCARD 0x004 /* Don't cache the page. */
769 /* Mpool statistics structure. */
770 struct __db_mpool_stat {
771 size_t st_cachesize; /* Cache size. */
772 u_int32_t st_cache_hit; /* Pages found in the cache. */
773 u_int32_t st_cache_miss; /* Pages not found in the cache. */
774 u_int32_t st_map; /* Pages from mapped files. */
775 u_int32_t st_page_create; /* Pages created in the cache. */
776 u_int32_t st_page_in; /* Pages read in. */
777 u_int32_t st_page_out; /* Pages written out. */
778 u_int32_t st_ro_evict; /* Clean pages forced from the cache. */
779 u_int32_t st_rw_evict; /* Dirty pages forced from the cache. */
780 u_int32_t st_hash_buckets; /* Number of hash buckets. */
781 u_int32_t st_hash_searches; /* Total hash chain searches. */
782 u_int32_t st_hash_longest; /* Longest hash chain searched. */
783 u_int32_t st_hash_examined; /* Total hash entries searched. */
784 u_int32_t st_page_clean; /* Clean pages. */
785 u_int32_t st_page_dirty; /* Dirty pages. */
786 u_int32_t st_page_trickle; /* Pages written by memp_trickle. */
787 u_int32_t st_region_wait; /* Region lock granted after wait. */
788 u_int32_t st_region_nowait; /* Region lock granted without wait. */
789 u_int32_t st_refcnt; /* Region reference count. */
790 u_int32_t st_regsize; /* Region size. */
793 /* Mpool file open information structure. */
794 struct __db_mpool_finfo {
795 int ftype; /* File type. */
796 DBT *pgcookie; /* Byte-string passed to pgin/pgout. */
797 u_int8_t *fileid; /* Unique file ID. */
798 int32_t lsn_offset; /* LSN offset in page. */
799 u_int32_t clear_len; /* Cleared length on created pages. */
802 /* Mpool file statistics structure. */
803 struct __db_mpool_fstat {
804 char *file_name; /* File name. */
805 size_t st_pagesize; /* Page size. */
806 u_int32_t st_cache_hit; /* Pages found in the cache. */
807 u_int32_t st_cache_miss; /* Pages not found in the cache. */
808 u_int32_t st_map; /* Pages from mapped files. */
809 u_int32_t st_page_create; /* Pages created in the cache. */
810 u_int32_t st_page_in; /* Pages read in. */
811 u_int32_t st_page_out; /* Pages written out. */
814 #if defined(__cplusplus)
815 extern "C" {
816 #endif
817 int memp_close (DB_MPOOL *);
818 int memp_fclose (DB_MPOOLFILE *);
819 int memp_fget (DB_MPOOLFILE *, db_pgno_t *, u_int32_t, void *);
820 int memp_fopen (DB_MPOOL *, const char *,
821 u_int32_t, int, size_t, DB_MPOOL_FINFO *, DB_MPOOLFILE **);
822 int memp_fput (DB_MPOOLFILE *, void *, u_int32_t);
823 int memp_fset (DB_MPOOLFILE *, void *, u_int32_t);
824 int memp_fsync (DB_MPOOLFILE *);
825 int memp_open (const char *, u_int32_t, int, DB_ENV *, DB_MPOOL **);
826 int memp_register (DB_MPOOL *, int,
827 int (*)(db_pgno_t, void *, DBT *),
828 int (*)(db_pgno_t, void *, DBT *));
829 int memp_stat (DB_MPOOL *,
830 DB_MPOOL_STAT **, DB_MPOOL_FSTAT ***, void *(*)(size_t));
831 int memp_sync (DB_MPOOL *, DB_LSN *);
832 int memp_trickle (DB_MPOOL *, int, int *);
833 int memp_unlink (const char *, int, DB_ENV *);
834 #if defined(__cplusplus)
836 #endif
838 /*******************************************************
839 * Transactions.
840 *******************************************************/
841 #define DB_TXNVERSION 1
842 #define DB_TXNMAGIC 0x041593
844 /* Operations values to the tx_recover() function. */
845 #define DB_TXN_BACKWARD_ROLL 1 /* Read the log backwards. */
846 #define DB_TXN_FORWARD_ROLL 2 /* Read the log forwards. */
847 #define DB_TXN_OPENFILES 3 /* Read for open files. */
848 #define DB_TXN_REDO 4 /* Redo the operation. */
849 #define DB_TXN_UNDO 5 /* Undo the operation. */
851 /* Internal transaction status values. */
853 /* Transaction statistics structure. */
854 struct __db_txn_active {
855 u_int32_t txnid; /* Transaction ID */
856 DB_LSN lsn; /* Lsn of the begin record */
859 struct __db_txn_stat {
860 DB_LSN st_last_ckp; /* lsn of the last checkpoint */
861 DB_LSN st_pending_ckp; /* last checkpoint did not finish */
862 time_t st_time_ckp; /* time of last checkpoint */
863 u_int32_t st_last_txnid; /* last transaction id given out */
864 u_int32_t st_maxtxns; /* maximum number of active txns */
865 u_int32_t st_naborts; /* number of aborted transactions */
866 u_int32_t st_nbegins; /* number of begun transactions */
867 u_int32_t st_ncommits; /* number of committed transactions */
868 u_int32_t st_nactive; /* number of active transactions */
869 DB_TXN_ACTIVE
870 *st_txnarray; /* array of active transactions */
871 u_int32_t st_region_wait; /* Region lock granted after wait. */
872 u_int32_t st_region_nowait; /* Region lock granted without wait. */
873 u_int32_t st_refcnt; /* Region reference count. */
874 u_int32_t st_regsize; /* Region size. */
877 #if defined(__cplusplus)
878 extern "C" {
879 #endif
880 int txn_abort (DB_TXN *);
881 int txn_begin (DB_TXNMGR *, DB_TXN *, DB_TXN **);
882 int txn_checkpoint (const DB_TXNMGR *, u_int32_t, u_int32_t);
883 int txn_commit (DB_TXN *);
884 int txn_close (DB_TXNMGR *);
885 u_int32_t txn_id (DB_TXN *);
886 int txn_open (const char *, u_int32_t, int, DB_ENV *, DB_TXNMGR **);
887 int txn_prepare (DB_TXN *);
888 int txn_stat (DB_TXNMGR *, DB_TXN_STAT **, void *(*)(size_t));
889 int txn_unlink (const char *, int, DB_ENV *);
890 #if defined(__cplusplus)
892 #endif
894 #ifndef DB_DBM_HSEARCH
895 #define DB_DBM_HSEARCH 0 /* No historic interfaces by default. */
896 #endif
897 #if DB_DBM_HSEARCH != 0
898 /*******************************************************
899 * Dbm/Ndbm historic interfaces.
900 *******************************************************/
901 #define DBM_INSERT 0 /* Flags to dbm_store(). */
902 #define DBM_REPLACE 1
905 * The db(3) support for ndbm(3) always appends this suffix to the
906 * file name to avoid overwriting the user's original database.
908 #define DBM_SUFFIX ".db"
910 #if defined(_XPG4_2)
911 typedef struct {
912 char *dptr;
913 size_t dsize;
914 } datum;
915 #else
916 typedef struct {
917 char *dptr;
918 int dsize;
919 } datum;
920 #endif
923 * Translate DBM calls into DB calls so that DB doesn't step on the
924 * application's name space.
926 * The global variables dbrdonly, dirf and pagf were not retained when
927 * 4BSD replaced the dbm interface with ndbm, and are not support here.
929 #define dbminit(a) __db_dbm_init(a)
930 #define dbmclose __db_dbm_close
931 #if !defined(__cplusplus)
932 #define delete(a) __db_dbm_delete(a)
933 #endif
934 #define fetch(a) __db_dbm_fetch(a)
935 #define firstkey __db_dbm_firstkey
936 #define nextkey(a) __db_dbm_nextkey(a)
937 #define store(a, b) __db_dbm_store(a, b)
939 /* Prototype the DB calls. */
940 #if defined(__cplusplus)
941 extern "C" {
942 #endif
943 int __db_dbm_close (void);
944 int __db_dbm_dbrdonly (void);
945 int __db_dbm_delete (datum);
946 int __db_dbm_dirf (void);
947 datum __db_dbm_fetch (datum);
948 datum __db_dbm_firstkey (void);
949 int __db_dbm_init (char *);
950 datum __db_dbm_nextkey (datum);
951 int __db_dbm_pagf (void);
952 int __db_dbm_store (datum, datum);
953 #if defined(__cplusplus)
955 #endif
958 * Translate NDBM calls into DB calls so that DB doesn't step on the
959 * application's name space.
961 #define dbm_clearerr(a) __db_ndbm_clearerr(a)
962 #define dbm_close(a) __db_ndbm_close(a)
963 #define dbm_delete(a, b) __db_ndbm_delete(a, b)
964 #define dbm_dirfno(a) __db_ndbm_dirfno(a)
965 #define dbm_error(a) __db_ndbm_error(a)
966 #define dbm_fetch(a, b) __db_ndbm_fetch(a, b)
967 #define dbm_firstkey(a) __db_ndbm_firstkey(a)
968 #define dbm_nextkey(a) __db_ndbm_nextkey(a)
969 #define dbm_open(a, b, c) __db_ndbm_open(a, b, c)
970 #define dbm_pagfno(a) __db_ndbm_pagfno(a)
971 #define dbm_rdonly(a) __db_ndbm_rdonly(a)
972 #define dbm_store(a, b, c, d) __db_ndbm_store(a, b, c, d)
974 /* Prototype the DB calls. */
975 #if defined(__cplusplus)
976 extern "C" {
977 #endif
978 int __db_ndbm_clearerr (DBM *);
979 void __db_ndbm_close (DBM *);
980 int __db_ndbm_delete (DBM *, datum);
981 int __db_ndbm_dirfno (DBM *);
982 int __db_ndbm_error (DBM *);
983 datum __db_ndbm_fetch (DBM *, datum);
984 datum __db_ndbm_firstkey (DBM *);
985 datum __db_ndbm_nextkey (DBM *);
986 DBM *__db_ndbm_open (const char *, int, int);
987 int __db_ndbm_pagfno (DBM *);
988 int __db_ndbm_rdonly (DBM *);
989 int __db_ndbm_store (DBM *, datum, datum, int);
990 #if defined(__cplusplus)
992 #endif
994 /*******************************************************
995 * Hsearch historic interface.
996 *******************************************************/
997 typedef enum {
998 FIND, ENTER
999 } ACTION;
1001 typedef struct entry {
1002 char *key;
1003 char *data;
1004 } ENTRY;
1007 * Translate HSEARCH calls into DB calls so that DB doesn't step on the
1008 * application's name space.
1010 #define hcreate(a) __db_hcreate(a)
1011 #define hdestroy __db_hdestroy
1012 #define hsearch(a, b) __db_hsearch(a, b)
1014 /* Prototype the DB calls. */
1015 #if defined(__cplusplus)
1016 extern "C" {
1017 #endif
1018 int __db_hcreate (size_t);
1019 void __db_hdestroy (void);
1020 ENTRY *__db_hsearch (ENTRY, ACTION);
1021 #if defined(__cplusplus)
1023 #endif
1024 #endif /* DB_DBM_HSEARCH */
1027 * XXX
1028 * MacOS: Reset Metrowerks C enum sizes.
1030 #ifdef __MWERKS__
1031 #pragma enumsalwaysint reset
1032 #endif
1033 #endif /* !_DB_H_ */