2 * See the file LICENSE for redistribution information.
4 * Copyright (c) 1996, 1997
5 * Sleepycat Software. All rights reserved.
7 * @(#)db.h.src 10.77 (Sleepycat) 9/24/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 #if defined(__STDC__) || defined(__cplusplus)
34 #define __P(protos) protos /* ANSI C prototypes */
37 #define __P(protos) () /* K&R C preprocessor */
42 * DB needs basic information about specifically sized types. If they're
43 * not provided by the system, typedef them here.
45 * We protect them against multiple inclusion using __BIT_TYPES_DEFINED__,
46 * as does BIND and Kerberos, since we don't know for sure what #include
47 * files the user is using.
50 * We also provide the standard u_int, u_long etc., if they're not provided
51 * by the system. This isn't completely necessary, but the example programs
54 #ifndef __BIT_TYPES_DEFINED__
55 #define __BIT_TYPES_DEFINED__
68 #define DB_VERSION_MAJOR 2
69 #define DB_VERSION_MINOR 3
70 #define DB_VERSION_PATCH 10
71 #define DB_VERSION_STRING "Sleepycat Software: DB 2.3.10: (9/24/97)"
73 typedef u_int32_t db_pgno_t
; /* Page number type. */
74 typedef u_int16_t db_indx_t
; /* Page offset type. */
75 #define DB_MAX_PAGES 0xffffffff /* >= # of pages in a file */
77 typedef u_int32_t db_recno_t
; /* Record number type. */
78 typedef size_t DB_LOCK
; /* Object returned by lock manager. */
79 #define DB_MAX_RECORDS 0xffffffff /* >= # of records in a tree */
81 #define DB_FILE_ID_LEN 20 /* DB file ID length. */
83 /* Forward structure declarations, so applications get type checking. */
84 struct __db
; typedef struct __db DB
;
86 typedef struct __db DBM
;
88 struct __db_bt_stat
; typedef struct __db_bt_stat DB_BTREE_STAT
;
89 struct __db_dbt
; typedef struct __db_dbt DBT
;
90 struct __db_env
; typedef struct __db_env DB_ENV
;
91 struct __db_info
; typedef struct __db_info DB_INFO
;
92 struct __db_lockregion
; typedef struct __db_lockregion DB_LOCKREGION
;
93 struct __db_lockreq
; typedef struct __db_lockreq DB_LOCKREQ
;
94 struct __db_locktab
; typedef struct __db_locktab DB_LOCKTAB
;
95 struct __db_log
; typedef struct __db_log DB_LOG
;
96 struct __db_lsn
; typedef struct __db_lsn DB_LSN
;
97 struct __db_mpool
; typedef struct __db_mpool DB_MPOOL
;
98 struct __db_mpool_fstat
;typedef struct __db_mpool_fstat DB_MPOOL_FSTAT
;
99 struct __db_mpool_stat
; typedef struct __db_mpool_stat DB_MPOOL_STAT
;
100 struct __db_mpoolfile
; typedef struct __db_mpoolfile DB_MPOOLFILE
;
101 struct __db_txn
; typedef struct __db_txn DB_TXN
;
102 struct __db_txn_active
; typedef struct __db_txn_active DB_TXN_ACTIVE
;
103 struct __db_txn_stat
; typedef struct __db_txn_stat DB_TXN_STAT
;
104 struct __db_txnmgr
; typedef struct __db_txnmgr DB_TXNMGR
;
105 struct __db_txnregion
; typedef struct __db_txnregion DB_TXNREGION
;
106 struct __dbc
; typedef struct __dbc DBC
;
108 /* Key/data structure -- a Data-Base Thang. */
110 void *data
; /* key/data */
111 u_int32_t size
; /* key/data length */
112 u_int32_t ulen
; /* RO: length of user buffer. */
113 u_int32_t dlen
; /* RO: get/put record length. */
114 u_int32_t doff
; /* RO: get/put record offset. */
116 #define DB_DBT_INTERNAL 0x01 /* Perform any mallocs using regular
117 malloc, not the user's malloc. */
118 #define DB_DBT_MALLOC 0x02 /* Return in allocated memory. */
119 #define DB_DBT_PARTIAL 0x04 /* Partial put/get. */
120 #define DB_DBT_USERMEM 0x08 /* Return in user's memory. */
125 * Database configuration and initialization.
128 * Flags understood by both db_open(3) and db_appinit(3).
130 #define DB_CREATE 0x00001 /* O_CREAT: create file as necessary. */
131 #define DB_NOMMAP 0x00002 /* Don't mmap underlying file. */
132 #define DB_THREAD 0x00004 /* Free-thread DB package handles. */
135 * Flags understood by db_appinit(3).
137 * DB_APP_INIT and DB_MUTEXDEBUG are internal only, and not documented.
139 /* 0x00007 COMMON MASK. */
140 #define DB_APP_INIT 0x00008 /* Appinit called, paths initialized. */
141 #define DB_INIT_LOCK 0x00010 /* Initialize locking. */
142 #define DB_INIT_LOG 0x00020 /* Initialize logging. */
143 #define DB_INIT_MPOOL 0x00040 /* Initialize mpool. */
144 #define DB_INIT_TXN 0x00080 /* Initialize transactions. */
145 #define DB_MPOOL_PRIVATE 0x00100 /* Mpool: private memory pool. */
146 #define DB_MUTEXDEBUG 0x00200 /* Do not get/set mutexes in regions. */
147 #define DB_RECOVER 0x00400 /* Run normal recovery. */
148 #define DB_RECOVER_FATAL 0x00800 /* Run catastrophic recovery. */
149 #define DB_TXN_NOSYNC 0x01000 /* Do not sync log on commit. */
150 #define DB_USE_ENVIRON 0x02000 /* Use the environment. */
151 #define DB_USE_ENVIRON_ROOT 0x04000 /* Use the environment if root. */
153 /* CURRENTLY UNUSED LOCK FLAGS. */
154 #define DB_TXN_LOCK_2PL 0x00000 /* Two-phase locking. */
155 #define DB_TXN_LOCK_OPTIMISTIC 0x00000 /* Optimistic locking. */
156 #define DB_TXN_LOCK_MASK 0x00000 /* Lock flags mask. */
158 /* CURRENTLY UNUSED LOG FLAGS. */
159 #define DB_TXN_LOG_REDO 0x00000 /* Redo-only logging. */
160 #define DB_TXN_LOG_UNDO 0x00000 /* Undo-only logging. */
161 #define DB_TXN_LOG_UNDOREDO 0x00000 /* Undo/redo write-ahead logging. */
162 #define DB_TXN_LOG_MASK 0x00000 /* Log flags mask. */
165 * Flags understood by db_open(3).
167 * DB_EXCL and DB_TEMPORARY are internal only, and not documented.
168 * DB_SEQUENTIAL is currently internal, but likely to be exported some day.
170 /* 0x00007 COMMON MASK. */
171 /* 0x07fff ALREADY USED. */
172 #define DB_EXCL 0x08000 /* O_EXCL: exclusive open. */
173 #define DB_RDONLY 0x10000 /* O_RDONLY: read-only. */
174 #define DB_SEQUENTIAL 0x20000 /* Indicate sequential access. */
175 #define DB_TEMPORARY 0x40000 /* Remove on last close. */
176 #define DB_TRUNCATE 0x80000 /* O_TRUNCATE: replace existing DB. */
179 * Deadlock detector modes; used in the DBENV structure to configure the
182 #define DB_LOCK_NORUN 0x0
183 #define DB_LOCK_DEFAULT 0x1
184 #define DB_LOCK_OLDEST 0x2
185 #define DB_LOCK_RANDOM 0x3
186 #define DB_LOCK_YOUNGEST 0x4
189 int db_lorder
; /* Byte order. */
191 /* Error message callback. */
192 void (*db_errcall
) __P((const char *, char *));
193 FILE *db_errfile
; /* Error message file stream. */
194 const char *db_errpfx
; /* Error message prefix. */
195 int db_verbose
; /* Generate debugging messages. */
198 char *db_home
; /* Database home. */
199 char *db_log_dir
; /* Database log file directory. */
200 char *db_tmp_dir
; /* Database tmp file directory. */
202 char **db_data_dir
; /* Database data file directories. */
203 int data_cnt
; /* Database data file slots. */
204 int data_next
; /* Next Database data file slot. */
207 DB_LOCKTAB
*lk_info
; /* Return from lock_open(). */
208 u_int8_t
*lk_conflicts
; /* Two dimensional conflict matrix. */
209 int lk_modes
; /* Number of lock modes in table. */
210 unsigned int lk_max
; /* Maximum number of locks. */
211 u_int32_t lk_detect
; /* Deadlock detect on every conflict. */
212 int (*db_yield
) __P((void)); /* Yield function for threads. */
215 DB_LOG
*lg_info
; /* Return from log_open(). */
216 u_int32_t lg_max
; /* Maximum file size. */
219 DB_MPOOL
*mp_info
; /* Return from memp_open(). */
220 size_t mp_mmapsize
; /* Maximum file size for mmap. */
221 size_t mp_size
; /* Bytes in the mpool cache. */
224 DB_TXNMGR
*tx_info
; /* Return from txn_open(). */
225 unsigned int tx_max
; /* Maximum number of transactions. */
226 int (*tx_recover
) /* Dispatch function for recovery. */
227 __P((DB_LOG
*, DBT
*, DB_LSN
*, int, void *));
229 u_int32_t flags
; /* Flags. */
232 /*******************************************************
234 *******************************************************/
236 DB_BTREE
=1, /* B+tree. */
237 DB_HASH
, /* Extended Linear Hashing. */
238 DB_RECNO
, /* Fixed and variable-length records. */
239 DB_UNKNOWN
/* Figure it out on open. */
242 #define DB_BTREEVERSION 6 /* Current btree version. */
243 #define DB_BTREEOLDVER 6 /* Oldest btree version supported. */
244 #define DB_BTREEMAGIC 0x053162
246 #define DB_HASHVERSION 5 /* Current hash version. */
247 #define DB_HASHOLDVER 4 /* Oldest hash version supported. */
248 #define DB_HASHMAGIC 0x061561
250 #define DB_LOGVERSION 2 /* Current log version. */
251 #define DB_LOGOLDVER 2 /* Oldest log version supported. */
252 #define DB_LOGMAGIC 0x040988
255 int db_lorder
; /* Byte order. */
256 size_t db_cachesize
; /* Underlying cache size. */
257 size_t db_pagesize
; /* Underlying page size. */
259 /* Local heap allocation. */
260 void *(*db_malloc
) __P((size_t));
262 /* Btree access method. */
263 int bt_maxkey
; /* Maximum keys per page. */
264 int bt_minkey
; /* Minimum keys per page. */
265 int (*bt_compare
) /* Comparison function. */
266 __P((const DBT
*, const DBT
*));
267 size_t (*bt_prefix
) /* Prefix function. */
268 __P((const DBT
*, const DBT
*));
270 /* Hash access method. */
271 unsigned int h_ffactor
; /* Fill factor. */
272 unsigned int h_nelem
; /* Number of elements. */
273 u_int32_t (*h_hash
) /* Hash function. */
274 __P((const void *, u_int32_t
));
276 /* Recno access method. */
277 int re_pad
; /* Fixed-length padding byte. */
278 int re_delim
; /* Variable-length delimiting byte. */
279 u_int32_t re_len
; /* Length for fixed-length records. */
280 char *re_source
; /* Source file name. */
282 #define DB_DELIMITER 0x0001 /* Recno: re_delim set. */
283 #define DB_DUP 0x0002 /* Btree, Hash: duplicate keys. */
284 #define DB_FIXEDLEN 0x0004 /* Recno: fixed-length records. */
285 #define DB_PAD 0x0008 /* Recno: re_pad set. */
286 #define DB_RECNUM 0x0010 /* Btree: record numbers. */
287 #define DB_RENUMBER 0x0020 /* Recno: renumber on insert/delete. */
288 #define DB_SNAPSHOT 0x0040 /* Recno: snapshot the input. */
293 * DB access method and cursor operation codes. These are implemented as
294 * bit fields for future flexibility, but currently only a single one may
295 * be specified to any function.
297 #define DB_AFTER 0x000001 /* c_put() */
298 #define DB_APPEND 0x000002 /* put() */
299 #define DB_BEFORE 0x000004 /* c_put() */
300 #define DB_CHECKPOINT 0x000008 /* log_put(), log_get() */
301 #define DB_CURRENT 0x000010 /* c_get(), c_put(), log_get() */
302 #define DB_FIRST 0x000020 /* c_get(), log_get() */
303 #define DB_FLUSH 0x000040 /* log_put() */
304 #define DB_GET_RECNO 0x000080 /* c_get() */
305 #define DB_KEYFIRST 0x000100 /* c_put() */
306 #define DB_KEYLAST 0x000200 /* c_put() */
307 #define DB_LAST 0x000400 /* c_get(), log_get() */
308 #define DB_NEXT 0x000800 /* c_get(), log_get() */
309 #define DB_NOOVERWRITE 0x001000 /* put() */
310 #define DB_NOSYNC 0x002000 /* close() */
311 #define DB_PREV 0x004000 /* c_get(), log_get() */
312 #define DB_RECORDCOUNT 0x008000 /* stat() */
313 #define DB_SET 0x010000 /* c_get(), log_get() */
314 #define DB_SET_RANGE 0x020000 /* c_get() */
315 #define DB_SET_RECNO 0x040000 /* get(), c_get() */
317 /* DB (user visible) error return codes. */
318 #define DB_INCOMPLETE ( -1) /* Sync didn't finish. */
319 #define DB_KEYEMPTY ( -2) /* The key/data pair was deleted or
320 was never created by the user. */
321 #define DB_KEYEXIST ( -3) /* The key/data pair already exists. */
322 #define DB_LOCK_DEADLOCK ( -4) /* Locker killed to resolve deadlock. */
323 #define DB_LOCK_NOTGRANTED ( -5) /* Lock unavailable, no-wait set. */
324 #define DB_LOCK_NOTHELD ( -6) /* Lock not held by locker. */
325 #define DB_NOTFOUND ( -7) /* Key/data pair not found (EOF). */
327 /* DB (private) error return codes. */
328 #define DB_DELETED ( -8) /* Recovery file marked deleted. */
329 #define DB_NEEDSPLIT ( -9) /* Page needs to be split. */
330 #define DB_REGISTERED (-10) /* Entry was previously registered. */
331 #define DB_SWAPBYTES (-11) /* Database needs byte swapping. */
332 #define DB_TXN_CKP (-12) /* Encountered ckp record in log. */
334 struct __db_ilock
{ /* Internal DB access method lock. */
335 db_pgno_t pgno
; /* Page being locked. */
337 u_int8_t fileid
[DB_FILE_ID_LEN
];
340 /* DB access method description structure. */
342 void *mutexp
; /* Synchronization for free threading */
343 DBTYPE type
; /* DB access method. */
344 DB_ENV
*dbenv
; /* DB_ENV structure. */
345 DB_ENV
*mp_dbenv
; /* DB_ENV for local mpool creation. */
347 DB
*master
; /* Original DB created by db_open. */
348 void *internal
; /* Access method private. */
350 DB_MPOOL
*mp
; /* The access method's mpool. */
351 DB_MPOOLFILE
*mpf
; /* The access method's mpool file. */
355 * Explicit representations of structures in queue.h.
357 * TAILQ_HEAD(curs_queue, __dbc);
360 struct __dbc
*tqh_first
;
361 struct __dbc
**tqh_last
;
366 * Explicit representations of structures in queue.h.
368 * LIST_HEAD(handleq, __db);
372 struct __db
*lh_first
;
373 } handleq
; /* List of handles for this DB. */
375 struct __db
*le_next
;
376 struct __db
**le_prev
;
377 } links
; /* Links for the handle list. */
379 u_int32_t log_fileid
; /* Logging file id. */
381 DB_TXN
*txn
; /* Current transaction. */
382 u_int32_t locker
; /* Default process' locker id. */
383 DBT lock_dbt
; /* DBT referencing lock. */
384 struct __db_ilock lock
; /* Lock. */
386 size_t pgsize
; /* Logical page size of file. */
388 /* Local heap allocation. */
389 void *(*db_malloc
) __P((size_t));
392 int (*close
) __P((DB
*, int));
393 int (*cursor
) __P((DB
*, DB_TXN
*, DBC
**));
394 int (*del
) __P((DB
*, DB_TXN
*, DBT
*, int));
395 int (*fd
) __P((DB
*, int *));
396 int (*get
) __P((DB
*, DB_TXN
*, DBT
*, DBT
*, int));
397 int (*put
) __P((DB
*, DB_TXN
*, DBT
*, DBT
*, int));
398 int (*stat
) __P((DB
*, void *, void *(*)(size_t), int));
399 int (*sync
) __P((DB
*, int));
401 #define DB_AM_DUP 0x000001 /* DB_DUP (internal). */
402 #define DB_AM_INMEM 0x000002 /* In-memory; no sync on close. */
403 #define DB_AM_LOCKING 0x000004 /* Perform locking. */
404 #define DB_AM_LOGGING 0x000008 /* Perform logging. */
405 #define DB_AM_MLOCAL 0x000010 /* Database memory pool is local. */
406 #define DB_AM_PGDEF 0x000020 /* Page size was defaulted. */
407 #define DB_AM_RDONLY 0x000040 /* Database is readonly. */
408 #define DB_AM_RECOVER 0x000080 /* In recovery (do not log or lock). */
409 #define DB_AM_SWAP 0x000100 /* Pages need to be byte-swapped. */
410 #define DB_AM_THREAD 0x000200 /* DB is multi-threaded. */
411 #define DB_BT_RECNUM 0x000400 /* DB_RECNUM (internal) */
412 #define DB_HS_DIRTYMETA 0x000800 /* Hash: Metadata page modified. */
413 #define DB_RE_DELIMITER 0x001000 /* DB_DELIMITER (internal). */
414 #define DB_RE_FIXEDLEN 0x002000 /* DB_FIXEDLEN (internal). */
415 #define DB_RE_PAD 0x004000 /* DB_PAD (internal). */
416 #define DB_RE_RENUMBER 0x008000 /* DB_RENUMBER (internal). */
417 #define DB_RE_SNAPSHOT 0x010000 /* DB_SNAPSHOT (internal). */
422 /* Cursor description structure. */
424 DB
*dbp
; /* Related DB access method. */
425 DB_TXN
*txn
; /* Associated transaction. */
429 * Explicit representations of structures in queue.h.
431 * TAILQ_ENTRY(__dbc);
434 struct __dbc
*tqe_next
;
435 struct __dbc
**tqe_prev
;
438 void *internal
; /* Access method private. */
440 int (*c_close
) __P((DBC
*));
441 int (*c_del
) __P((DBC
*, int));
442 int (*c_get
) __P((DBC
*, DBT
*, DBT
*, int));
443 int (*c_put
) __P((DBC
*, DBT
*, DBT
*, int));
446 /* Btree/recno statistics structure. */
447 struct __db_bt_stat
{
448 u_int32_t bt_flags
; /* Open flags. */
449 u_int32_t bt_maxkey
; /* Maxkey value. */
450 u_int32_t bt_minkey
; /* Minkey value. */
451 u_int32_t bt_re_len
; /* Fixed-length record length. */
452 u_int32_t bt_re_pad
; /* Fixed-length record pad. */
453 u_int32_t bt_pagesize
; /* Page size. */
454 u_int32_t bt_levels
; /* Tree levels. */
455 u_int32_t bt_nrecs
; /* Number of records. */
456 u_int32_t bt_int_pg
; /* Internal pages. */
457 u_int32_t bt_leaf_pg
; /* Leaf pages. */
458 u_int32_t bt_dup_pg
; /* Duplicate pages. */
459 u_int32_t bt_over_pg
; /* Overflow pages. */
460 u_int32_t bt_free
; /* Pages on the free list. */
461 u_int32_t bt_freed
; /* Pages freed for reuse. */
462 u_int32_t bt_int_pgfree
; /* Bytes free in internal pages. */
463 u_int32_t bt_leaf_pgfree
; /* Bytes free in leaf pages. */
464 u_int32_t bt_dup_pgfree
; /* Bytes free in duplicate pages. */
465 u_int32_t bt_over_pgfree
; /* Bytes free in overflow pages. */
466 u_int32_t bt_pfxsaved
; /* Bytes saved by prefix compression. */
467 u_int32_t bt_split
; /* Total number of splits. */
468 u_int32_t bt_rootsplit
; /* Root page splits. */
469 u_int32_t bt_fastsplit
; /* Fast splits. */
470 u_int32_t bt_added
; /* Items added. */
471 u_int32_t bt_deleted
; /* Items deleted. */
472 u_int32_t bt_get
; /* Items retrieved. */
473 u_int32_t bt_cache_hit
; /* Hits in fast-insert code. */
474 u_int32_t bt_cache_miss
; /* Misses in fast-insert code. */
477 #if defined(__cplusplus)
480 int db_appinit
__P((const char *, char * const *, DB_ENV
*, int));
481 int db_appexit
__P((DB_ENV
*));
482 int db_open
__P((const char *, DBTYPE
, int, int, DB_ENV
*, DB_INFO
*, DB
**));
483 char *db_version
__P((int *, int *, int *));
484 #if defined(__cplusplus)
488 /*******************************************************
490 *******************************************************/
491 #define DB_LOCKVERSION 1
492 #define DB_LOCKMAGIC 0x090193
494 /* Flag values for lock_vec(). */
495 #define DB_LOCK_NOWAIT 0x01 /* Don't wait on unavailable lock. */
497 /* Flag values for lock_detect(). */
498 #define DB_LOCK_CONFLICT 0x01 /* Run on any conflict. */
502 DB_LOCK_DUMP
, /* Display held locks. */
503 DB_LOCK_GET
, /* Get the lock. */
504 DB_LOCK_PUT
, /* Release the lock. */
505 DB_LOCK_PUT_ALL
, /* Release locker's locks. */
506 DB_LOCK_PUT_OBJ
/* Release locker's locks on obj. */
509 /* Simple R/W lock modes and for multi-granularity intention locking. */
511 DB_LOCK_NG
=0, /* Not granted. */
512 DB_LOCK_READ
, /* Shared/read. */
513 DB_LOCK_WRITE
, /* Exclusive/write. */
514 DB_LOCK_IREAD
, /* Intent to share/read. */
515 DB_LOCK_IWRITE
, /* Intent exclusive/write. */
516 DB_LOCK_IWR
/* Intent to read and write. */
519 /* Lock request structure. */
520 struct __db_lockreq
{
521 db_lockop_t op
; /* Operation. */
522 db_lockmode_t mode
; /* Requested mode. */
523 u_int32_t locker
; /* Locker identity. */
524 DBT
*obj
; /* Object being locked. */
525 DB_LOCK lock
; /* Lock returned. */
529 * Commonly used conflict matrices.
531 * Standard Read/Write (or exclusive/shared) locks.
533 #define DB_LOCK_RW_N 3
534 extern const u_int8_t db_rw_conflicts
[];
536 /* Multi-granularity locking. */
537 #define DB_LOCK_RIW_N 6
538 extern const u_int8_t db_riw_conflicts
[];
540 #if defined(__cplusplus)
543 int lock_close
__P((DB_LOCKTAB
*));
544 int lock_detect
__P((DB_LOCKTAB
*, int, u_int32_t
));
545 int lock_get
__P((DB_LOCKTAB
*,
546 u_int32_t
, int, const DBT
*, db_lockmode_t
, DB_LOCK
*));
547 int lock_id
__P((DB_LOCKTAB
*, u_int32_t
*));
548 int lock_open
__P((const char *, int, int, DB_ENV
*, DB_LOCKTAB
**));
549 int lock_put
__P((DB_LOCKTAB
*, DB_LOCK
));
550 int lock_unlink
__P((const char *, int, DB_ENV
*));
551 int lock_vec
__P((DB_LOCKTAB
*,
552 u_int32_t
, int, DB_LOCKREQ
*, int, DB_LOCKREQ
**));
553 #if defined(__cplusplus)
557 /*******************************************************
559 *******************************************************/
560 /* Flag values for log_archive(). */
561 #define DB_ARCH_ABS 0x001 /* Absolute pathnames. */
562 #define DB_ARCH_DATA 0x002 /* Data files. */
563 #define DB_ARCH_LOG 0x004 /* Log files. */
566 * A DB_LSN has two parts, a fileid which identifies a specific file, and an
567 * offset within that file. The fileid is an unsigned 4-byte quantity that
568 * uniquely identifies a file within the log directory -- currently a simple
569 * counter inside the log. The offset is also an unsigned 4-byte value. The
570 * log manager guarantees the offset is never more than 4 bytes by switching
571 * to a new log file before the maximum length imposed by an unsigned 4-byte
575 u_int32_t file
; /* File ID. */
576 u_int32_t offset
; /* File offset. */
579 #if defined(__cplusplus)
582 int log_archive
__P((DB_LOG
*, char **[], int, void *(*)(size_t)));
583 int log_close
__P((DB_LOG
*));
584 int log_compare
__P((const DB_LSN
*, const DB_LSN
*));
585 int log_file
__P((DB_LOG
*, const DB_LSN
*, char *, size_t));
586 int log_flush
__P((DB_LOG
*, const DB_LSN
*));
587 int log_get
__P((DB_LOG
*, DB_LSN
*, DBT
*, int));
588 int log_open
__P((const char *, int, int, DB_ENV
*, DB_LOG
**));
589 int log_put
__P((DB_LOG
*, DB_LSN
*, const DBT
*, int));
590 int log_register
__P((DB_LOG
*, DB
*, const char *, DBTYPE
, u_int32_t
*));
591 int log_unlink
__P((const char *, int, DB_ENV
*));
592 int log_unregister
__P((DB_LOG
*, u_int32_t
));
593 #if defined(__cplusplus)
597 /*******************************************************
599 *******************************************************/
600 /* Flag values for memp_fget(). */
601 #define DB_MPOOL_CREATE 0x001 /* Create a page. */
602 #define DB_MPOOL_LAST 0x002 /* Return the last page. */
603 #define DB_MPOOL_NEW 0x004 /* Create a new page. */
605 /* Flag values for memp_fput(), memp_fset(). */
606 #define DB_MPOOL_CLEAN 0x001 /* Clear modified bit. */
607 #define DB_MPOOL_DIRTY 0x002 /* Page is modified. */
608 #define DB_MPOOL_DISCARD 0x004 /* Don't cache the page. */
610 /* Mpool statistics structure. */
611 struct __db_mpool_stat
{
612 size_t st_cachesize
; /* Cache size. */
613 unsigned long st_cache_hit
; /* Pages found in the cache. */
614 unsigned long st_cache_miss
; /* Pages not found in the cache. */
615 unsigned long st_map
; /* Pages from mapped files. */
616 unsigned long st_page_create
; /* Pages created in the cache. */
617 unsigned long st_page_in
; /* Pages read in. */
618 unsigned long st_page_out
; /* Pages written out. */
619 unsigned long st_ro_evict
; /* Read-only pages evicted. */
620 unsigned long st_rw_evict
; /* Read-write pages evicted. */
621 unsigned long st_hash_buckets
; /* Number of hash buckets. */
622 unsigned long st_hash_searches
; /* Total hash chain searches. */
623 unsigned long st_hash_longest
; /* Longest hash chain searched. */
624 unsigned long st_hash_examined
; /* Total hash entries searched. */
627 /* Mpool file statistics structure. */
628 struct __db_mpool_fstat
{
629 char *file_name
; /* File name. */
630 size_t st_pagesize
; /* Page size. */
631 unsigned long st_cache_hit
; /* Pages found in the cache. */
632 unsigned long st_cache_miss
; /* Pages not found in the cache. */
633 unsigned long st_map
; /* Pages from mapped files. */
634 unsigned long st_page_create
; /* Pages created in the cache. */
635 unsigned long st_page_in
; /* Pages read in. */
636 unsigned long st_page_out
; /* Pages written out. */
639 #if defined(__cplusplus)
642 int memp_close
__P((DB_MPOOL
*));
643 int memp_fclose
__P((DB_MPOOLFILE
*));
644 int memp_fget
__P((DB_MPOOLFILE
*, db_pgno_t
*, int, void *));
645 int memp_fopen
__P((DB_MPOOL
*, const char *,
646 int, int, int, size_t, int, DBT
*, u_int8_t
*, DB_MPOOLFILE
**));
647 int memp_fput
__P((DB_MPOOLFILE
*, void *, int));
648 int memp_fset
__P((DB_MPOOLFILE
*, void *, int));
649 int memp_fsync
__P((DB_MPOOLFILE
*));
650 int memp_open
__P((const char *, int, int, DB_ENV
*, DB_MPOOL
**));
651 int memp_register
__P((DB_MPOOL
*, int,
652 int (*)(db_pgno_t
, void *, DBT
*),
653 int (*)(db_pgno_t
, void *, DBT
*)));
654 int memp_stat
__P((DB_MPOOL
*,
655 DB_MPOOL_STAT
**, DB_MPOOL_FSTAT
***, void *(*)(size_t)));
656 int memp_sync
__P((DB_MPOOL
*, DB_LSN
*));
657 int memp_unlink
__P((const char *, int, DB_ENV
*));
658 #if defined(__cplusplus)
662 /*******************************************************
664 *******************************************************/
665 #define DB_TXNVERSION 1
666 #define DB_TXNMAGIC 0x041593
668 /* Operations values to the tx_recover() function. */
669 #define DB_TXN_BACKWARD_ROLL 1 /* Read the log backwards. */
670 #define DB_TXN_FORWARD_ROLL 2 /* Read the log forwards. */
671 #define DB_TXN_OPENFILES 3 /* Read for open files. */
672 #define DB_TXN_REDO 4 /* Redo the operation. */
673 #define DB_TXN_UNDO 5 /* Undo the operation. */
675 /* Internal transaction status values. */
677 /* Transaction statistics structure. */
678 struct __db_txn_active
{
679 u_int32_t txnid
; /* Transaction ID */
680 DB_LSN lsn
; /* Lsn of the begin record */
683 struct __db_txn_stat
{
684 DB_LSN st_last_ckp
; /* lsn of the last checkpoint */
685 DB_LSN st_pending_ckp
; /* last checkpoint did not finish */
686 time_t st_time_ckp
; /* time of last checkpoint */
687 u_int32_t st_last_txnid
; /* last transaction id given out */
688 u_int32_t st_maxtxns
; /* maximum number of active txns */
689 u_int32_t st_naborts
; /* number of aborted transactions */
690 u_int32_t st_nbegins
; /* number of begun transactions */
691 u_int32_t st_ncommits
; /* number of committed transactions */
692 u_int32_t st_nactive
; /* number of active transactions */
693 DB_TXN_ACTIVE
*st_txnarray
; /* array of active transactions */
696 #if defined(__cplusplus)
699 int txn_abort
__P((DB_TXN
*));
700 int txn_begin
__P((DB_TXNMGR
*, DB_TXN
*, DB_TXN
**));
701 int txn_checkpoint
__P((const DB_TXNMGR
*, int, int));
702 int txn_commit
__P((DB_TXN
*));
703 int txn_close
__P((DB_TXNMGR
*));
704 u_int32_t txn_id
__P((DB_TXN
*));
705 int txn_open
__P((const char *, int, int, DB_ENV
*, DB_TXNMGR
**));
706 int txn_prepare
__P((DB_TXN
*));
707 int txn_stat
__P((DB_TXNMGR
*, DB_TXN_STAT
**, void *(*)(size_t)));
708 int txn_unlink
__P((const char *, int, DB_ENV
*));
709 #if defined(__cplusplus)
713 #ifdef DB_DBM_HSEARCH
714 /*******************************************************
715 * Dbm/Ndbm historic interfaces.
716 *******************************************************/
717 #define DBM_INSERT 0 /* Flags to dbm_store(). */
718 #define DBM_REPLACE 1
721 * The db(3) support for ndbm(3) always appends this suffix to the
722 * file name to avoid overwriting the user's original database.
724 #define DBM_SUFFIX ".db"
731 #if defined(__cplusplus)
734 int dbminit
__P((char *));
735 #if !defined(__cplusplus)
736 int delete __P((datum
));
738 datum fetch
__P((datum
));
739 datum firstkey
__P((void));
740 datum nextkey
__P((datum
));
741 int store
__P((datum
, datum
));
747 * dbm_clearerr(DBM *db);
748 * dbm_dirfno(DBM *db);
749 * dbm_error(DBM *db);
750 * dbm_pagfno(DBM *db);
751 * dbm_rdonly(DBM *db);
753 * they weren't documented and were historically implemented as #define's.
755 void dbm_close
__P((DBM
*));
756 int dbm_delete
__P((DBM
*, datum
));
757 datum dbm_fetch
__P((DBM
*, datum
));
758 datum dbm_firstkey
__P((DBM
*));
759 long dbm_forder
__P((DBM
*, datum
));
760 datum dbm_nextkey
__P((DBM
*));
761 DBM
*dbm_open
__P((const char *, int, int));
762 int dbm_store
__P((DBM
*, datum
, datum
, int));
763 #if defined(__cplusplus)
767 /*******************************************************
768 * Hsearch historic interface.
769 *******************************************************/
774 typedef struct entry
{
779 #if defined(__cplusplus)
782 int hcreate
__P((unsigned int));
783 void hdestroy
__P((void));
784 ENTRY
*hsearch
__P((ENTRY
, ACTION
));
785 #if defined(__cplusplus)
788 #endif /* DB_DBM_HSEARCH */
792 * MacOS: Reset Metrowerks C enum sizes.
795 #pragma enumsalwaysint reset