2 * See the file LICENSE for redistribution information.
4 * Copyright (c) 1996, 1997
5 * Sleepycat Software. All rights reserved.
7 * @(#)db.h.src 10.91 (Sleepycat) 11/3/97
13 #ifndef __NO_SYSTEM_INCLUDES
14 #include <sys/types.h>
21 * MacOS: ensure that Metrowerks C makes enumeration types int sized.
24 #pragma enumsalwaysint on
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.
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.
39 #if defined(__STDC__) || defined(__cplusplus) || defined(_MSC_VER)
40 #define __P(protos) protos /* ANSI C prototypes */
43 #define __P(protos) () /* K&R C preprocessor */
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.
56 * We also provide the standard u_int, u_long etc., if they're not provided
57 * by the system. This isn't completely necessary, but the example programs
60 #ifndef __BIT_TYPES_DEFINED__
61 #define __BIT_TYPES_DEFINED__
74 #define DB_VERSION_MAJOR 2
75 #define DB_VERSION_MINOR 3
76 #define DB_VERSION_PATCH 12
77 #define DB_VERSION_STRING "Sleepycat Software: DB 2.3.12: (11/3/97)"
79 typedef u_int32_t db_pgno_t
; /* Page number type. */
80 typedef u_int16_t db_indx_t
; /* Page offset type. */
81 #define DB_MAX_PAGES 0xffffffff /* >= # of pages in a file */
83 typedef u_int32_t db_recno_t
; /* Record number type. */
84 typedef size_t DB_LOCK
; /* Object returned by lock manager. */
85 #define DB_MAX_RECORDS 0xffffffff /* >= # of records in a tree */
87 #define DB_FILE_ID_LEN 20 /* DB file ID length. */
89 /* Forward structure declarations, so applications get type checking. */
90 struct __db
; typedef struct __db DB
;
92 typedef struct __db DBM
;
94 struct __db_bt_stat
; typedef struct __db_bt_stat DB_BTREE_STAT
;
95 struct __db_dbt
; typedef struct __db_dbt DBT
;
96 struct __db_env
; typedef struct __db_env DB_ENV
;
97 struct __db_info
; typedef struct __db_info DB_INFO
;
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_fstat
;typedef struct __db_mpool_fstat DB_MPOOL_FSTAT
;
106 struct __db_mpool_stat
; typedef struct __db_mpool_stat DB_MPOOL_STAT
;
107 struct __db_mpoolfile
; typedef struct __db_mpoolfile DB_MPOOLFILE
;
108 struct __db_txn
; typedef struct __db_txn DB_TXN
;
109 struct __db_txn_active
; typedef struct __db_txn_active DB_TXN_ACTIVE
;
110 struct __db_txn_stat
; typedef struct __db_txn_stat DB_TXN_STAT
;
111 struct __db_txnmgr
; typedef struct __db_txnmgr DB_TXNMGR
;
112 struct __db_txnregion
; typedef struct __db_txnregion DB_TXNREGION
;
113 struct __dbc
; typedef struct __dbc DBC
;
115 /* Key/data structure -- a Data-Base Thang. */
117 void *data
; /* key/data */
118 u_int32_t size
; /* key/data length */
119 u_int32_t ulen
; /* RO: length of user buffer. */
120 u_int32_t dlen
; /* RO: get/put record length. */
121 u_int32_t doff
; /* RO: get/put record offset. */
123 #define DB_DBT_INTERNAL 0x01 /* Perform any mallocs using regular
124 malloc, not the user's malloc. */
125 #define DB_DBT_MALLOC 0x02 /* Return in allocated memory. */
126 #define DB_DBT_PARTIAL 0x04 /* Partial put/get. */
127 #define DB_DBT_USERMEM 0x08 /* Return in user's memory. */
132 * DB configuration. There are a set of functions which the application
133 * can replace with its own versions.
135 #define DB_FUNC_CALLOC 1 /* ANSI C calloc. */
136 #define DB_FUNC_CLOSE 2 /* POSIX 1003.1 close. */
137 #define DB_FUNC_DIRFREE 3 /* DB: free directory list. */
138 #define DB_FUNC_DIRLIST 4 /* DB: create directory list. */
139 #define DB_FUNC_EXISTS 5 /* DB: return if file exists. */
140 #define DB_FUNC_FREE 6 /* ANSI C free. */
141 #define DB_FUNC_FSYNC 7 /* POSIX 1003.1 fsync. */
142 #define DB_FUNC_IOINFO 8 /* DB: return file I/O information. */
143 #define DB_FUNC_MALLOC 9 /* ANSI C malloc. */
144 #define DB_FUNC_MAP 10 /* DB: map file into shared memory. */
145 #define DB_FUNC_OPEN 11 /* POSIX 1003.1 open. */
146 #define DB_FUNC_READ 12 /* POSIX 1003.1 read. */
147 #define DB_FUNC_REALLOC 13 /* ANSI C realloc. */
148 #define DB_FUNC_SEEK 14 /* POSIX 1003.1 lseek. */
149 #define DB_FUNC_SLEEP 15 /* DB: sleep secs/usecs. */
150 #define DB_FUNC_STRDUP 16 /* ANSI C strdup. */
151 #define DB_FUNC_UNLINK 17 /* POSIX 1003.1 unlink. */
152 #define DB_FUNC_UNMAP 18 /* DB: unmap shared memory file. */
153 #define DB_FUNC_WRITE 19 /* POSIX 1003.1 write. */
154 #define DB_FUNC_YIELD 20 /* DB: yield thread to scheduler. */
157 * Database configuration and initialization.
160 * Flags understood by both db_open(3) and db_appinit(3).
162 #define DB_CREATE 0x00001 /* O_CREAT: create file as necessary. */
163 #define DB_NOMMAP 0x00002 /* Don't mmap underlying file. */
164 #define DB_THREAD 0x00004 /* Free-thread DB package handles. */
167 * Flags understood by db_appinit(3).
169 * DB_MUTEXDEBUG is internal only, and not documented.
171 /* 0x00007 COMMON MASK. */
172 #define DB_INIT_LOCK 0x00008 /* Initialize locking. */
173 #define DB_INIT_LOG 0x00010 /* Initialize logging. */
174 #define DB_INIT_MPOOL 0x00020 /* Initialize mpool. */
175 #define DB_INIT_TXN 0x00040 /* Initialize transactions. */
176 #define DB_MPOOL_PRIVATE 0x00080 /* Mpool: private memory pool. */
177 #define DB_MUTEXDEBUG 0x00100 /* Do not get/set mutexes in regions. */
178 #define DB_RECOVER 0x00200 /* Run normal recovery. */
179 #define DB_RECOVER_FATAL 0x00400 /* Run catastrophic recovery. */
180 #define DB_TXN_NOSYNC 0x00800 /* Do not sync log on commit. */
181 #define DB_USE_ENVIRON 0x01000 /* Use the environment. */
182 #define DB_USE_ENVIRON_ROOT 0x02000 /* Use the environment if root. */
184 /* CURRENTLY UNUSED LOCK FLAGS. */
185 #define DB_TXN_LOCK_2PL 0x00000 /* Two-phase locking. */
186 #define DB_TXN_LOCK_OPTIMISTIC 0x00000 /* Optimistic locking. */
187 #define DB_TXN_LOCK_MASK 0x00000 /* Lock flags mask. */
189 /* CURRENTLY UNUSED LOG FLAGS. */
190 #define DB_TXN_LOG_REDO 0x00000 /* Redo-only logging. */
191 #define DB_TXN_LOG_UNDO 0x00000 /* Undo-only logging. */
192 #define DB_TXN_LOG_UNDOREDO 0x00000 /* Undo/redo write-ahead logging. */
193 #define DB_TXN_LOG_MASK 0x00000 /* Log flags mask. */
196 * Flags understood by db_open(3).
198 * DB_EXCL and DB_TEMPORARY are internal only, and not documented.
199 * DB_SEQUENTIAL is currently internal, but likely to be exported some day.
201 /* 0x00007 COMMON MASK. */
202 /* 0x07fff ALREADY USED. */
203 #define DB_EXCL 0x08000 /* O_EXCL: exclusive open. */
204 #define DB_RDONLY 0x10000 /* O_RDONLY: read-only. */
205 #define DB_SEQUENTIAL 0x20000 /* Indicate sequential access. */
206 #define DB_TEMPORARY 0x40000 /* Remove on last close. */
207 #define DB_TRUNCATE 0x80000 /* O_TRUNCATE: replace existing DB. */
210 * Deadlock detector modes; used in the DBENV structure to configure the
213 #define DB_LOCK_NORUN 0x0
214 #define DB_LOCK_DEFAULT 0x1
215 #define DB_LOCK_OLDEST 0x2
216 #define DB_LOCK_RANDOM 0x3
217 #define DB_LOCK_YOUNGEST 0x4
220 int db_lorder
; /* Byte order. */
222 /* Error message callback. */
223 void (*db_errcall
) __P((const char *, char *));
224 FILE *db_errfile
; /* Error message file stream. */
225 const char *db_errpfx
; /* Error message prefix. */
226 int db_verbose
; /* Generate debugging messages. */
229 char *db_home
; /* Database home. */
230 char *db_log_dir
; /* Database log file directory. */
231 char *db_tmp_dir
; /* Database tmp file directory. */
233 char **db_data_dir
; /* Database data file directories. */
234 int data_cnt
; /* Database data file slots. */
235 int data_next
; /* Next Database data file slot. */
238 DB_LOCKTAB
*lk_info
; /* Return from lock_open(). */
239 u_int8_t
*lk_conflicts
; /* Two dimensional conflict matrix. */
240 int lk_modes
; /* Number of lock modes in table. */
241 unsigned int lk_max
; /* Maximum number of locks. */
242 u_int32_t lk_detect
; /* Deadlock detect on every conflict. */
245 DB_LOG
*lg_info
; /* Return from log_open(). */
246 u_int32_t lg_max
; /* Maximum file size. */
249 DB_MPOOL
*mp_info
; /* Return from memp_open(). */
250 size_t mp_mmapsize
; /* Maximum file size for mmap. */
251 size_t mp_size
; /* Bytes in the mpool cache. */
254 DB_TXNMGR
*tx_info
; /* Return from txn_open(). */
255 unsigned int tx_max
; /* Maximum number of transactions. */
256 int (*tx_recover
) /* Dispatch function for recovery. */
257 __P((DB_LOG
*, DBT
*, DB_LSN
*, int, void *));
259 #define DB_ENV_APPINIT 0x01 /* Paths initialized by db_appinit(). */
260 #define DB_ENV_STANDALONE 0x02 /* Test: freestanding environment. */
261 #define DB_ENV_THREAD 0x04 /* DB_ENV is multi-threaded. */
262 u_int32_t flags
; /* Flags. */
265 /*******************************************************
267 *******************************************************/
269 DB_BTREE
=1, /* B+tree. */
270 DB_HASH
, /* Extended Linear Hashing. */
271 DB_RECNO
, /* Fixed and variable-length records. */
272 DB_UNKNOWN
/* Figure it out on open. */
275 #define DB_BTREEVERSION 6 /* Current btree version. */
276 #define DB_BTREEOLDVER 6 /* Oldest btree version supported. */
277 #define DB_BTREEMAGIC 0x053162
279 #define DB_HASHVERSION 5 /* Current hash version. */
280 #define DB_HASHOLDVER 4 /* Oldest hash version supported. */
281 #define DB_HASHMAGIC 0x061561
283 #define DB_LOGVERSION 2 /* Current log version. */
284 #define DB_LOGOLDVER 2 /* Oldest log version supported. */
285 #define DB_LOGMAGIC 0x040988
288 int db_lorder
; /* Byte order. */
289 size_t db_cachesize
; /* Underlying cache size. */
290 size_t db_pagesize
; /* Underlying page size. */
292 /* Local heap allocation. */
293 void *(*db_malloc
) __P((size_t));
295 /* Btree access method. */
296 int bt_maxkey
; /* Maximum keys per page. */
297 int bt_minkey
; /* Minimum keys per page. */
298 int (*bt_compare
) /* Comparison function. */
299 __P((const DBT
*, const DBT
*));
300 size_t (*bt_prefix
) /* Prefix function. */
301 __P((const DBT
*, const DBT
*));
303 /* Hash access method. */
304 unsigned int h_ffactor
; /* Fill factor. */
305 unsigned int h_nelem
; /* Number of elements. */
306 u_int32_t (*h_hash
) /* Hash function. */
307 __P((const void *, u_int32_t
));
309 /* Recno access method. */
310 int re_pad
; /* Fixed-length padding byte. */
311 int re_delim
; /* Variable-length delimiting byte. */
312 u_int32_t re_len
; /* Length for fixed-length records. */
313 char *re_source
; /* Source file name. */
315 #define DB_DELIMITER 0x0001 /* Recno: re_delim set. */
316 #define DB_DUP 0x0002 /* Btree, Hash: duplicate keys. */
317 #define DB_FIXEDLEN 0x0004 /* Recno: fixed-length records. */
318 #define DB_PAD 0x0008 /* Recno: re_pad set. */
319 #define DB_RECNUM 0x0010 /* Btree: record numbers. */
320 #define DB_RENUMBER 0x0020 /* Recno: renumber on insert/delete. */
321 #define DB_SNAPSHOT 0x0040 /* Recno: snapshot the input. */
326 * DB access method and cursor operation codes. These are implemented as
327 * bit fields for future flexibility, but currently only a single one may
328 * be specified to any function.
330 #define DB_AFTER 0x000001 /* c_put() */
331 #define DB_APPEND 0x000002 /* put() */
332 #define DB_BEFORE 0x000004 /* c_put() */
333 #define DB_CHECKPOINT 0x000008 /* log_put(), log_get() */
334 #define DB_CURRENT 0x000010 /* c_get(), c_put(), log_get() */
335 #define DB_FIRST 0x000020 /* c_get(), log_get() */
336 #define DB_FLUSH 0x000040 /* log_put() */
337 #define DB_GET_RECNO 0x000080 /* get(), c_get() */
338 #define DB_KEYFIRST 0x000100 /* c_put() */
339 #define DB_KEYLAST 0x000200 /* c_put() */
340 #define DB_LAST 0x000400 /* c_get(), log_get() */
341 #define DB_NEXT 0x000800 /* c_get(), log_get() */
342 #define DB_NOOVERWRITE 0x001000 /* put() */
343 #define DB_NOSYNC 0x002000 /* close() */
344 #define DB_PREV 0x004000 /* c_get(), log_get() */
345 #define DB_RECORDCOUNT 0x008000 /* stat() */
346 #define DB_SET 0x010000 /* c_get(), log_get() */
347 #define DB_SET_RANGE 0x020000 /* c_get() */
348 #define DB_SET_RECNO 0x040000 /* c_get() */
350 /* DB (user visible) error return codes. */
351 #define DB_INCOMPLETE ( -1) /* Sync didn't finish. */
352 #define DB_KEYEMPTY ( -2) /* The key/data pair was deleted or
353 was never created by the user. */
354 #define DB_KEYEXIST ( -3) /* The key/data pair already exists. */
355 #define DB_LOCK_DEADLOCK ( -4) /* Locker killed to resolve deadlock. */
356 #define DB_LOCK_NOTGRANTED ( -5) /* Lock unavailable, no-wait set. */
357 #define DB_LOCK_NOTHELD ( -6) /* Lock not held by locker. */
358 #define DB_NOTFOUND ( -7) /* Key/data pair not found (EOF). */
360 /* DB (private) error return codes. */
361 #define DB_DELETED ( -8) /* Recovery file marked deleted. */
362 #define DB_NEEDSPLIT ( -9) /* Page needs to be split. */
363 #define DB_REGISTERED (-10) /* Entry was previously registered. */
364 #define DB_SWAPBYTES (-11) /* Database needs byte swapping. */
365 #define DB_TXN_CKP (-12) /* Encountered ckp record in log. */
367 struct __db_ilock
{ /* Internal DB access method lock. */
368 db_pgno_t pgno
; /* Page being locked. */
370 u_int8_t fileid
[DB_FILE_ID_LEN
];
373 /* DB access method description structure. */
375 void *mutexp
; /* Synchronization for free threading */
376 DBTYPE type
; /* DB access method. */
377 DB_ENV
*dbenv
; /* DB_ENV structure. */
378 DB_ENV
*mp_dbenv
; /* DB_ENV for local mpool creation. */
380 DB
*master
; /* Original DB created by db_open. */
381 void *internal
; /* Access method private. */
383 DB_MPOOL
*mp
; /* The access method's mpool. */
384 DB_MPOOLFILE
*mpf
; /* The access method's mpool file. */
388 * Explicit representations of structures in queue.h.
390 * TAILQ_HEAD(curs_queue, __dbc);
393 struct __dbc
*tqh_first
;
394 struct __dbc
**tqh_last
;
399 * Explicit representations of structures in queue.h.
401 * LIST_HEAD(handleq, __db);
405 struct __db
*lh_first
;
406 } handleq
; /* List of handles for this DB. */
408 struct __db
*le_next
;
409 struct __db
**le_prev
;
410 } links
; /* Links for the handle list. */
412 u_int32_t log_fileid
; /* Logging file id. */
414 DB_TXN
*txn
; /* Current transaction. */
415 u_int32_t locker
; /* Default process' locker id. */
416 DBT lock_dbt
; /* DBT referencing lock. */
417 struct __db_ilock lock
; /* Lock. */
419 size_t pgsize
; /* Logical page size of file. */
421 /* Local heap allocation. */
422 void *(*db_malloc
) __P((size_t));
425 int (*close
) __P((DB
*, int));
426 int (*cursor
) __P((DB
*, DB_TXN
*, DBC
**));
427 int (*del
) __P((DB
*, DB_TXN
*, DBT
*, int));
428 int (*fd
) __P((DB
*, int *));
429 int (*get
) __P((DB
*, DB_TXN
*, DBT
*, DBT
*, int));
430 int (*put
) __P((DB
*, DB_TXN
*, DBT
*, DBT
*, int));
431 int (*stat
) __P((DB
*, void *, void *(*)(size_t), int));
432 int (*sync
) __P((DB
*, int));
434 #define DB_AM_DUP 0x000001 /* DB_DUP (internal). */
435 #define DB_AM_INMEM 0x000002 /* In-memory; no sync on close. */
436 #define DB_AM_LOCKING 0x000004 /* Perform locking. */
437 #define DB_AM_LOGGING 0x000008 /* Perform logging. */
438 #define DB_AM_MLOCAL 0x000010 /* Database memory pool is local. */
439 #define DB_AM_PGDEF 0x000020 /* Page size was defaulted. */
440 #define DB_AM_RDONLY 0x000040 /* Database is readonly. */
441 #define DB_AM_RECOVER 0x000080 /* In recovery (do not log or lock). */
442 #define DB_AM_SWAP 0x000100 /* Pages need to be byte-swapped. */
443 #define DB_AM_THREAD 0x000200 /* DB is multi-threaded. */
444 #define DB_BT_RECNUM 0x000400 /* DB_RECNUM (internal) */
445 #define DB_HS_DIRTYMETA 0x000800 /* Hash: Metadata page modified. */
446 #define DB_RE_DELIMITER 0x001000 /* DB_DELIMITER (internal). */
447 #define DB_RE_FIXEDLEN 0x002000 /* DB_FIXEDLEN (internal). */
448 #define DB_RE_PAD 0x004000 /* DB_PAD (internal). */
449 #define DB_RE_RENUMBER 0x008000 /* DB_RENUMBER (internal). */
450 #define DB_RE_SNAPSHOT 0x010000 /* DB_SNAPSHOT (internal). */
455 /* Cursor description structure. */
457 DB
*dbp
; /* Related DB access method. */
458 DB_TXN
*txn
; /* Associated transaction. */
462 * Explicit representations of structures in queue.h.
464 * TAILQ_ENTRY(__dbc);
467 struct __dbc
*tqe_next
;
468 struct __dbc
**tqe_prev
;
471 void *internal
; /* Access method private. */
473 int (*c_close
) __P((DBC
*));
474 int (*c_del
) __P((DBC
*, int));
475 int (*c_get
) __P((DBC
*, DBT
*, DBT
*, int));
476 int (*c_put
) __P((DBC
*, DBT
*, DBT
*, int));
479 /* Btree/recno statistics structure. */
480 struct __db_bt_stat
{
481 u_int32_t bt_flags
; /* Open flags. */
482 u_int32_t bt_maxkey
; /* Maxkey value. */
483 u_int32_t bt_minkey
; /* Minkey value. */
484 u_int32_t bt_re_len
; /* Fixed-length record length. */
485 u_int32_t bt_re_pad
; /* Fixed-length record pad. */
486 u_int32_t bt_pagesize
; /* Page size. */
487 u_int32_t bt_levels
; /* Tree levels. */
488 u_int32_t bt_nrecs
; /* Number of records. */
489 u_int32_t bt_int_pg
; /* Internal pages. */
490 u_int32_t bt_leaf_pg
; /* Leaf pages. */
491 u_int32_t bt_dup_pg
; /* Duplicate pages. */
492 u_int32_t bt_over_pg
; /* Overflow pages. */
493 u_int32_t bt_free
; /* Pages on the free list. */
494 u_int32_t bt_freed
; /* Pages freed for reuse. */
495 u_int32_t bt_int_pgfree
; /* Bytes free in internal pages. */
496 u_int32_t bt_leaf_pgfree
; /* Bytes free in leaf pages. */
497 u_int32_t bt_dup_pgfree
; /* Bytes free in duplicate pages. */
498 u_int32_t bt_over_pgfree
; /* Bytes free in overflow pages. */
499 u_int32_t bt_pfxsaved
; /* Bytes saved by prefix compression. */
500 u_int32_t bt_split
; /* Total number of splits. */
501 u_int32_t bt_rootsplit
; /* Root page splits. */
502 u_int32_t bt_fastsplit
; /* Fast splits. */
503 u_int32_t bt_added
; /* Items added. */
504 u_int32_t bt_deleted
; /* Items deleted. */
505 u_int32_t bt_get
; /* Items retrieved. */
506 u_int32_t bt_cache_hit
; /* Hits in fast-insert code. */
507 u_int32_t bt_cache_miss
; /* Misses in fast-insert code. */
508 u_int32_t bt_magic
; /* Magic number. */
509 u_int32_t bt_version
; /* Version number. */
512 #if defined(__cplusplus)
515 int db_appinit
__P((const char *, char * const *, DB_ENV
*, int));
516 int db_appexit
__P((DB_ENV
*));
517 int db_jump_set
__P((void *, int));
518 int db_open
__P((const char *, DBTYPE
, int, int, DB_ENV
*, DB_INFO
*, DB
**));
519 char *db_version
__P((int *, int *, int *));
520 #if defined(__cplusplus)
524 /*******************************************************
526 *******************************************************/
527 #define DB_LOCKVERSION 1
528 #define DB_LOCKMAGIC 0x090193
530 /* Flag values for lock_vec(). */
531 #define DB_LOCK_NOWAIT 0x01 /* Don't wait on unavailable lock. */
533 /* Flag values for lock_detect(). */
534 #define DB_LOCK_CONFLICT 0x01 /* Run on any conflict. */
538 DB_LOCK_DUMP
, /* Display held locks. */
539 DB_LOCK_GET
, /* Get the lock. */
540 DB_LOCK_PUT
, /* Release the lock. */
541 DB_LOCK_PUT_ALL
, /* Release locker's locks. */
542 DB_LOCK_PUT_OBJ
/* Release locker's locks on obj. */
545 /* Simple R/W lock modes and for multi-granularity intention locking. */
547 DB_LOCK_NG
=0, /* Not granted. */
548 DB_LOCK_READ
, /* Shared/read. */
549 DB_LOCK_WRITE
, /* Exclusive/write. */
550 DB_LOCK_IREAD
, /* Intent to share/read. */
551 DB_LOCK_IWRITE
, /* Intent exclusive/write. */
552 DB_LOCK_IWR
/* Intent to read and write. */
555 /* Lock request structure. */
556 struct __db_lockreq
{
557 db_lockop_t op
; /* Operation. */
558 db_lockmode_t mode
; /* Requested mode. */
559 u_int32_t locker
; /* Locker identity. */
560 DBT
*obj
; /* Object being locked. */
561 DB_LOCK lock
; /* Lock returned. */
565 * Commonly used conflict matrices.
567 * Standard Read/Write (or exclusive/shared) locks.
569 #define DB_LOCK_RW_N 3
570 extern const u_int8_t db_rw_conflicts
[];
572 /* Multi-granularity locking. */
573 #define DB_LOCK_RIW_N 6
574 extern const u_int8_t db_riw_conflicts
[];
576 #if defined(__cplusplus)
579 int lock_close
__P((DB_LOCKTAB
*));
580 int lock_detect
__P((DB_LOCKTAB
*, int, u_int32_t
));
581 int lock_get
__P((DB_LOCKTAB
*,
582 u_int32_t
, int, const DBT
*, db_lockmode_t
, DB_LOCK
*));
583 int lock_id
__P((DB_LOCKTAB
*, u_int32_t
*));
584 int lock_open
__P((const char *, int, int, DB_ENV
*, DB_LOCKTAB
**));
585 int lock_put
__P((DB_LOCKTAB
*, DB_LOCK
));
586 int lock_unlink
__P((const char *, int, DB_ENV
*));
587 int lock_vec
__P((DB_LOCKTAB
*,
588 u_int32_t
, int, DB_LOCKREQ
*, int, DB_LOCKREQ
**));
589 #if defined(__cplusplus)
593 /*******************************************************
595 *******************************************************/
596 /* Flag values for log_archive(). */
597 #define DB_ARCH_ABS 0x001 /* Absolute pathnames. */
598 #define DB_ARCH_DATA 0x002 /* Data files. */
599 #define DB_ARCH_LOG 0x004 /* Log files. */
602 * A DB_LSN has two parts, a fileid which identifies a specific file, and an
603 * offset within that file. The fileid is an unsigned 4-byte quantity that
604 * uniquely identifies a file within the log directory -- currently a simple
605 * counter inside the log. The offset is also an unsigned 4-byte value. The
606 * log manager guarantees the offset is never more than 4 bytes by switching
607 * to a new log file before the maximum length imposed by an unsigned 4-byte
611 u_int32_t file
; /* File ID. */
612 u_int32_t offset
; /* File offset. */
615 /* Log statistics structure. */
616 struct __db_log_stat
{
617 u_int32_t st_magic
; /* Log file magic number. */
618 u_int32_t st_version
; /* Log file version number. */
619 int st_mode
; /* Log file mode. */
620 u_int32_t st_lg_max
; /* Maximum log file size. */
621 u_int32_t st_w_bytes
; /* Bytes to log. */
622 u_int32_t st_w_mbytes
; /* Megabytes to log. */
623 u_int32_t st_wc_bytes
; /* Bytes to log since checkpoint. */
624 u_int32_t st_wc_mbytes
; /* Megabytes to log since checkpoint. */
625 u_int32_t st_wcount
; /* Total syncs to the log. */
626 u_int32_t st_scount
; /* Total writes to the log. */
627 u_int32_t st_region_wait
; /* Region lock granted after wait. */
628 u_int32_t st_region_nowait
; /* Region lock granted without wait. */
631 #if defined(__cplusplus)
634 int log_archive
__P((DB_LOG
*, char **[], int, void *(*)(size_t)));
635 int log_close
__P((DB_LOG
*));
636 int log_compare
__P((const DB_LSN
*, const DB_LSN
*));
637 int log_file
__P((DB_LOG
*, const DB_LSN
*, char *, size_t));
638 int log_flush
__P((DB_LOG
*, const DB_LSN
*));
639 int log_get
__P((DB_LOG
*, DB_LSN
*, DBT
*, int));
640 int log_open
__P((const char *, int, int, DB_ENV
*, DB_LOG
**));
641 int log_put
__P((DB_LOG
*, DB_LSN
*, const DBT
*, int));
642 int log_register
__P((DB_LOG
*, DB
*, const char *, DBTYPE
, u_int32_t
*));
643 int log_stat
__P((DB_LOG
*, DB_LOG_STAT
**, void *(*)(size_t)));
644 int log_unlink
__P((const char *, int, DB_ENV
*));
645 int log_unregister
__P((DB_LOG
*, u_int32_t
));
646 #if defined(__cplusplus)
650 /*******************************************************
652 *******************************************************/
653 /* Flag values for memp_fget(). */
654 #define DB_MPOOL_CREATE 0x001 /* Create a page. */
655 #define DB_MPOOL_LAST 0x002 /* Return the last page. */
656 #define DB_MPOOL_NEW 0x004 /* Create a new page. */
658 /* Flag values for memp_fput(), memp_fset(). */
659 #define DB_MPOOL_CLEAN 0x001 /* Clear modified bit. */
660 #define DB_MPOOL_DIRTY 0x002 /* Page is modified. */
661 #define DB_MPOOL_DISCARD 0x004 /* Don't cache the page. */
663 /* Mpool statistics structure. */
664 struct __db_mpool_stat
{
665 size_t st_cachesize
; /* Cache size. */
666 u_int32_t st_cache_hit
; /* Pages found in the cache. */
667 u_int32_t st_cache_miss
; /* Pages not found in the cache. */
668 u_int32_t st_map
; /* Pages from mapped files. */
669 u_int32_t st_page_create
; /* Pages created in the cache. */
670 u_int32_t st_page_in
; /* Pages read in. */
671 u_int32_t st_page_out
; /* Pages written out. */
672 u_int32_t st_ro_evict
; /* Clean pages forced from the cache. */
673 u_int32_t st_rw_evict
; /* Dirty pages forced from the cache. */
674 u_int32_t st_hash_buckets
; /* Number of hash buckets. */
675 u_int32_t st_hash_searches
; /* Total hash chain searches. */
676 u_int32_t st_hash_longest
; /* Longest hash chain searched. */
677 u_int32_t st_hash_examined
; /* Total hash entries searched. */
678 u_int32_t st_page_clean
; /* Clean pages. */
679 u_int32_t st_page_dirty
; /* Dirty pages. */
680 u_int32_t st_page_trickle
; /* Pages written by memp_trickle. */
681 u_int32_t st_region_wait
; /* Region lock granted after wait. */
682 u_int32_t st_region_nowait
; /* Region lock granted without wait. */
685 /* Mpool file statistics structure. */
686 struct __db_mpool_fstat
{
687 char *file_name
; /* File name. */
688 size_t st_pagesize
; /* Page size. */
689 u_int32_t st_cache_hit
; /* Pages found in the cache. */
690 u_int32_t st_cache_miss
; /* Pages not found in the cache. */
691 u_int32_t st_map
; /* Pages from mapped files. */
692 u_int32_t st_page_create
; /* Pages created in the cache. */
693 u_int32_t st_page_in
; /* Pages read in. */
694 u_int32_t st_page_out
; /* Pages written out. */
697 #if defined(__cplusplus)
700 int memp_close
__P((DB_MPOOL
*));
701 int memp_fclose
__P((DB_MPOOLFILE
*));
702 int memp_fget
__P((DB_MPOOLFILE
*, db_pgno_t
*, int, void *));
703 int memp_fopen
__P((DB_MPOOL
*, const char *,
704 int, int, int, size_t, int, DBT
*, u_int8_t
*, DB_MPOOLFILE
**));
705 int memp_fput
__P((DB_MPOOLFILE
*, void *, int));
706 int memp_fset
__P((DB_MPOOLFILE
*, void *, int));
707 int memp_fsync
__P((DB_MPOOLFILE
*));
708 int memp_open
__P((const char *, int, int, DB_ENV
*, DB_MPOOL
**));
709 int memp_register
__P((DB_MPOOL
*, int,
710 int (*)(db_pgno_t
, void *, DBT
*),
711 int (*)(db_pgno_t
, void *, DBT
*)));
712 int memp_stat
__P((DB_MPOOL
*,
713 DB_MPOOL_STAT
**, DB_MPOOL_FSTAT
***, void *(*)(size_t)));
714 int memp_sync
__P((DB_MPOOL
*, DB_LSN
*));
715 int memp_trickle
__P((DB_MPOOL
*, int, int *));
716 int memp_unlink
__P((const char *, int, DB_ENV
*));
717 #if defined(__cplusplus)
721 /*******************************************************
723 *******************************************************/
724 #define DB_TXNVERSION 1
725 #define DB_TXNMAGIC 0x041593
727 /* Operations values to the tx_recover() function. */
728 #define DB_TXN_BACKWARD_ROLL 1 /* Read the log backwards. */
729 #define DB_TXN_FORWARD_ROLL 2 /* Read the log forwards. */
730 #define DB_TXN_OPENFILES 3 /* Read for open files. */
731 #define DB_TXN_REDO 4 /* Redo the operation. */
732 #define DB_TXN_UNDO 5 /* Undo the operation. */
734 /* Internal transaction status values. */
736 /* Transaction statistics structure. */
737 struct __db_txn_active
{
738 u_int32_t txnid
; /* Transaction ID */
739 DB_LSN lsn
; /* Lsn of the begin record */
742 struct __db_txn_stat
{
743 DB_LSN st_last_ckp
; /* lsn of the last checkpoint */
744 DB_LSN st_pending_ckp
; /* last checkpoint did not finish */
745 time_t st_time_ckp
; /* time of last checkpoint */
746 u_int32_t st_last_txnid
; /* last transaction id given out */
747 u_int32_t st_maxtxns
; /* maximum number of active txns */
748 u_int32_t st_naborts
; /* number of aborted transactions */
749 u_int32_t st_nbegins
; /* number of begun transactions */
750 u_int32_t st_ncommits
; /* number of committed transactions */
751 u_int32_t st_nactive
; /* number of active transactions */
752 DB_TXN_ACTIVE
*st_txnarray
; /* array of active transactions */
755 #if defined(__cplusplus)
758 int txn_abort
__P((DB_TXN
*));
759 int txn_begin
__P((DB_TXNMGR
*, DB_TXN
*, DB_TXN
**));
760 int txn_checkpoint
__P((const DB_TXNMGR
*, int, int));
761 int txn_commit
__P((DB_TXN
*));
762 int txn_close
__P((DB_TXNMGR
*));
763 u_int32_t txn_id
__P((DB_TXN
*));
764 int txn_open
__P((const char *, int, int, DB_ENV
*, DB_TXNMGR
**));
765 int txn_prepare
__P((DB_TXN
*));
766 int txn_stat
__P((DB_TXNMGR
*, DB_TXN_STAT
**, void *(*)(size_t)));
767 int txn_unlink
__P((const char *, int, DB_ENV
*));
768 #if defined(__cplusplus)
772 #ifdef DB_DBM_HSEARCH
773 /*******************************************************
774 * Dbm/Ndbm historic interfaces.
775 *******************************************************/
776 #define DBM_INSERT 0 /* Flags to dbm_store(). */
777 #define DBM_REPLACE 1
780 * The db(3) support for ndbm(3) always appends this suffix to the
781 * file name to avoid overwriting the user's original database.
783 #define DBM_SUFFIX ".db"
790 #if defined(__cplusplus)
793 int dbminit
__P((char *));
794 #if !defined(__cplusplus)
795 int delete __P((datum
));
797 datum fetch
__P((datum
));
798 datum firstkey
__P((void));
799 datum nextkey
__P((datum
));
800 int store
__P((datum
, datum
));
806 * dbm_clearerr(DBM *db);
807 * dbm_dirfno(DBM *db);
808 * dbm_error(DBM *db);
809 * dbm_pagfno(DBM *db);
810 * dbm_rdonly(DBM *db);
812 * they weren't documented and were historically implemented as #define's.
814 void dbm_close
__P((DBM
*));
815 int dbm_delete
__P((DBM
*, datum
));
816 datum dbm_fetch
__P((DBM
*, datum
));
817 datum dbm_firstkey
__P((DBM
*));
818 long dbm_forder
__P((DBM
*, datum
));
819 datum dbm_nextkey
__P((DBM
*));
820 DBM
*dbm_open
__P((const char *, int, int));
821 int dbm_store
__P((DBM
*, datum
, datum
, int));
822 #if defined(__cplusplus)
826 /*******************************************************
827 * Hsearch historic interface.
828 *******************************************************/
833 typedef struct entry
{
838 #if defined(__cplusplus)
841 int hcreate
__P((unsigned int));
842 void hdestroy
__P((void));
843 ENTRY
*hsearch
__P((ENTRY
, ACTION
));
844 #if defined(__cplusplus)
847 #endif /* DB_DBM_HSEARCH */
851 * MacOS: Reset Metrowerks C enum sizes.
854 #pragma enumsalwaysint reset