diff options
Diffstat (limited to 'db/include')
-rw-r--r-- | db/include/cxx_common.h | 45 | ||||
-rw-r--r-- | db/include/cxx_except.h | 78 | ||||
-rw-r--r-- | db/include/db.in | 1388 | ||||
-rw-r--r-- | db/include/db_185.in | 165 | ||||
-rw-r--r-- | db/include/db_int.in | 442 |
5 files changed, 2118 insertions, 0 deletions
diff --git a/db/include/cxx_common.h b/db/include/cxx_common.h new file mode 100644 index 000000000..45b21c6cb --- /dev/null +++ b/db/include/cxx_common.h @@ -0,0 +1,45 @@ +/*- + * See the file LICENSE for redistribution information. + * + * Copyright (c) 1997-2001 + * Sleepycat Software. All rights reserved. + * + * Id: cxx_common.h,v 11.1 2001/04/29 06:44:05 dda Exp + */ + +#ifndef _CXX_COMMON_H_ +#define _CXX_COMMON_H_ + +// +// Common definitions used by all of Berkeley DB's C++ include files. +// + +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// +// +// Mechanisms for declaring classes +// + +// +// Every class defined in this file has an _exported next to the class name. +// This is needed for WinTel machines so that the class methods can +// be exported or imported in a DLL as appropriate. Users of the DLL +// use the define DB_USE_DLL. When the DLL is built, DB_CREATE_DLL +// must be defined. +// +#if defined(_MSC_VER) + +# if defined(DB_CREATE_DLL) +# define _exported __declspec(dllexport) // creator of dll +# elif defined(DB_USE_DLL) +# define _exported __declspec(dllimport) // user of dll +# else +# define _exported // static lib creator or user +# endif + +#else /* _MSC_VER */ + +# define _exported + +#endif /* _MSC_VER */ +#endif /* !_CXX_COMMON_H_ */ diff --git a/db/include/cxx_except.h b/db/include/cxx_except.h new file mode 100644 index 000000000..d19d9715b --- /dev/null +++ b/db/include/cxx_except.h @@ -0,0 +1,78 @@ +/*- + * See the file LICENSE for redistribution information. + * + * Copyright (c) 1997-2001 + * Sleepycat Software. All rights reserved. + * + * Id: cxx_except.h,v 11.2 2001/05/08 18:58:45 bostic Exp + */ + +#ifndef _CXX_EXCEPT_H_ +#define _CXX_EXCEPT_H_ + +#include "cxx_common.h" + +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// +// +// Forward declarations +// + +class DbException; // forward +class DbMemoryException; // forward +class Dbt; // forward + +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// +// +// Exception classes +// + +// Almost any error in the DB library throws a DbException. +// Every exception should be considered an abnormality +// (e.g. bug, misuse of DB, file system error). +// +// NOTE: We would like to inherit from class exception and +// let it handle what(), but there are +// MSVC++ problems when <exception> is included. +// +class _exported DbException +{ +public: + virtual ~DbException(); + DbException(int err); + DbException(const char *description); + DbException(const char *prefix, int err); + DbException(const char *prefix1, const char *prefix2, int err); + int get_errno() const; + virtual const char *what() const; + + DbException(const DbException &); + DbException &operator = (const DbException &); + +private: + char *what_; + int err_; // errno +}; + +// +// A specific sort of exception that occurs when +// user declared memory is insufficient in a Dbt. +// +class _exported DbMemoryException : public DbException +{ +public: + virtual ~DbMemoryException(); + DbMemoryException(Dbt *dbt); + DbMemoryException(const char *description); + DbMemoryException(const char *prefix, Dbt *dbt); + DbMemoryException(const char *prefix1, const char *prefix2, Dbt *dbt); + Dbt *get_dbt() const; + + DbMemoryException(const DbMemoryException &); + DbMemoryException &operator = (const DbMemoryException &); + +private: + Dbt *dbt_; +}; +#endif /* !_CXX_EXCEPT_H_ */ diff --git a/db/include/db.in b/db/include/db.in new file mode 100644 index 000000000..26455cd79 --- /dev/null +++ b/db/include/db.in @@ -0,0 +1,1388 @@ +/* + * See the file LICENSE for redistribution information. + * + * Copyright (c) 1996-2001 + * Sleepycat Software. All rights reserved. + * + * Id: db.in,v 11.158 2001/05/08 18:54:39 bostic Exp + */ + +#ifndef _DB_H_ +#define _DB_H_ + +#ifndef __NO_SYSTEM_INCLUDES +#include <sys/types.h> + +#include <stdio.h> +#endif + +#if defined(__cplusplus) +extern "C" { +#endif + +/* + * XXX + * Handle function prototypes and the keyword "const". This steps on name + * space that DB doesn't control, but all of the other solutions are worse. + * + * XXX + * While Microsoft's compiler is ANSI C compliant, it doesn't have _STDC_ + * defined by default, you specify a command line flag or #pragma to turn + * it on. Don't do that, however, because some of Microsoft's own header + * files won't compile. + */ +#undef __P +#if defined(__STDC__) || defined(__cplusplus) || defined(_MSC_VER) +#define __P(protos) protos /* ANSI C prototypes */ +#else +#define const +#define __P(protos) () /* K&R C preprocessor */ +#endif + +/* + * !!! + * DB needs basic information about specifically sized types. If they're + * not provided by the system, typedef them here. + * + * We protect them against multiple inclusion using __BIT_TYPES_DEFINED__, + * as does BIND and Kerberos, since we don't know for sure what #include + * files the user is using. + * + * !!! + * We also provide the standard u_int, u_long etc., if they're not provided + * by the system. + */ +#ifndef __BIT_TYPES_DEFINED__ +#define __BIT_TYPES_DEFINED__ +@u_int8_decl@ +@int16_decl@ +@u_int16_decl@ +@int32_decl@ +@u_int32_decl@ +#endif + +@u_char_decl@ +@u_short_decl@ +@u_int_decl@ +@u_long_decl@ +@ssize_t_decl@ + +#define DB_VERSION_MAJOR @DB_VERSION_MAJOR@ +#define DB_VERSION_MINOR @DB_VERSION_MINOR@ +#define DB_VERSION_PATCH @DB_VERSION_PATCH@ +#define DB_VERSION_STRING @DB_VERSION_STRING@ + +typedef u_int32_t db_pgno_t; /* Page number type. */ +typedef u_int16_t db_indx_t; /* Page offset type. */ +#define DB_MAX_PAGES 0xffffffff /* >= # of pages in a file */ + +typedef u_int32_t db_recno_t; /* Record number type. */ +#define DB_MAX_RECORDS 0xffffffff /* >= # of records in a tree */ + +/* Forward structure declarations, so applications get type checking. */ +struct __db; typedef struct __db DB; +struct __db_bt_stat; typedef struct __db_bt_stat DB_BTREE_STAT; +struct __db_dbt; typedef struct __db_dbt DBT; +struct __db_env; typedef struct __db_env DB_ENV; +struct __db_h_stat; typedef struct __db_h_stat DB_HASH_STAT; +struct __db_ilock; typedef struct __db_ilock DB_LOCK_ILOCK; +struct __db_lock_stat; typedef struct __db_lock_stat DB_LOCK_STAT; +struct __db_lock_u; typedef struct __db_lock_u DB_LOCK; +struct __db_lockreq; typedef struct __db_lockreq DB_LOCKREQ; +struct __db_log_stat; typedef struct __db_log_stat DB_LOG_STAT; +struct __db_lsn; typedef struct __db_lsn DB_LSN; +struct __db_mpool_finfo;typedef struct __db_mpool_finfo DB_MPOOL_FINFO; +struct __db_mpool_fstat;typedef struct __db_mpool_fstat DB_MPOOL_FSTAT; +struct __db_mpool_stat; typedef struct __db_mpool_stat DB_MPOOL_STAT; +struct __db_mpoolfile; typedef struct __db_mpoolfile DB_MPOOLFILE; +struct __db_qam_stat; typedef struct __db_qam_stat DB_QUEUE_STAT; +struct __db_txn; typedef struct __db_txn DB_TXN; +struct __db_txn_active; typedef struct __db_txn_active DB_TXN_ACTIVE; +struct __db_txn_stat; typedef struct __db_txn_stat DB_TXN_STAT; +struct __dbc; typedef struct __dbc DBC; +struct __dbc_internal; typedef struct __dbc_internal DBC_INTERNAL; +struct __fh_t; typedef struct __fh_t DB_FH; +struct __key_range; typedef struct __key_range DB_KEY_RANGE; + +/* Key/data structure -- a Data-Base Thang. */ +struct __db_dbt { + /* + * data/size must be fields 1 and 2 for DB 1.85 compatibility. + */ + void *data; /* Key/data */ + u_int32_t size; /* key/data length */ + + u_int32_t ulen; /* RO: length of user buffer. */ + u_int32_t dlen; /* RO: get/put record length. */ + u_int32_t doff; /* RO: get/put record offset. */ + +#define DB_DBT_APPMALLOC 0x001 /* Callback allocated memory. */ +#define DB_DBT_ISSET 0x002 /* Lower level calls set value. */ +#define DB_DBT_MALLOC 0x004 /* Return in malloc'd memory. */ +#define DB_DBT_PARTIAL 0x008 /* Partial put/get. */ +#define DB_DBT_REALLOC 0x010 /* Return in realloc'd memory. */ +#define DB_DBT_USERMEM 0x020 /* Return in user's memory. */ +#define DB_DBT_DUPOK 0x040 /* Insert if duplicate. */ + u_int32_t flags; +}; + +/* + * Macros for bulk get. Note that wherever we use a DBT *, we explicitly + * cast it; this allows the same macros to work with C++ Dbt *'s, as + * Dbt is a subclass of struct DBT in C++. + */ +#define DB_MULTIPLE_INIT(pointer, dbt) \ + (pointer = (u_int8_t *)((DBT *)(dbt))->data + \ + ((DBT *)(dbt))->ulen - sizeof(u_int32_t)) +#define DB_MULTIPLE_NEXT(pointer, dbt, retdata, retdlen) \ + do { \ + if (*((u_int32_t *)(pointer)) == (u_int32_t)-1) { \ + retdata = NULL; \ + pointer = NULL; \ + break; \ + } \ + retdata = (u_int8_t *) \ + ((DBT *)(dbt))->data + *(u_int32_t *)(pointer); \ + (pointer) = (u_int32_t *)(pointer) - 1; \ + if (retdata == (u_int8_t *)((DBT *)(dbt))->data) \ + retdata = NULL; \ + retdlen = *(u_int32_t *)(pointer); \ + (pointer) = (u_int32_t *)(pointer) - 1; \ + } while (0) +#define DB_MULTIPLE_KEY_NEXT(pointer, dbt, retkey, retklen, retdata, retdlen) \ + do { \ + if (*((u_int32_t *)(pointer)) == (u_int32_t)-1) { \ + retdata = NULL; \ + retkey = NULL; \ + pointer = NULL; \ + break; \ + } \ + retkey = (u_int8_t *) \ + ((DBT *)(dbt))->data + *(u_int32_t *)(pointer); \ + (pointer) = (u_int32_t *)(pointer) - 1; \ + retklen = *(u_int32_t *)(pointer); \ + (pointer) = (u_int32_t *)(pointer) - 1; \ + retdata = (u_int8_t *) \ + ((DBT *)(dbt))->data + *(u_int32_t *)(pointer); \ + (pointer) = (u_int32_t *)(pointer) - 1; \ + retdlen = *(u_int32_t *)(pointer); \ + (pointer) = (u_int32_t *)(pointer) - 1; \ + } while (0) + +#define DB_MULTIPLE_RECNO_NEXT(pointer, dbt, recno, retdata, retdlen) \ + do { \ + if (*((u_int32_t *)(pointer)) == (u_int32_t)-1) { \ + recno = 0; \ + retdata = NULL; \ + pointer = NULL; \ + break; \ + } \ + recno = *(u_int32_t *)(pointer); \ + (pointer) = (u_int32_t *)(pointer) - 1; \ + retdata = (u_int8_t *) \ + ((DBT *)(dbt))->data + *(u_int32_t *)(pointer); \ + (pointer) = (u_int32_t *)(pointer) - 1; \ + retdlen = *(u_int32_t *)(pointer); \ + (pointer) = (u_int32_t *)(pointer) - 1; \ + } while (0) + +/* + * Common flags -- + * Interfaces which use any of these common flags should never have + * interface specific flags in this range. + */ +#define DB_CREATE 0x000001 /* Create file as necessary. */ +#define DB_CXX_NO_EXCEPTIONS 0x000002 /* C++: return error values. */ +#define DB_FORCE 0x000004 /* Force (anything). */ +#define DB_NOMMAP 0x000008 /* Don't mmap underlying file. */ +#define DB_RDONLY 0x000010 /* Read-only (O_RDONLY). */ +#define DB_RECOVER 0x000020 /* Run normal recovery. */ +#define DB_THREAD 0x000040 /* Applications are threaded. */ +#define DB_TXN_NOSYNC 0x000080 /* Do not sync log on commit. */ +#define DB_USE_ENVIRON 0x000100 /* Use the environment. */ +#define DB_USE_ENVIRON_ROOT 0x000200 /* Use the environment if root. */ + +/* This flag is common between the open call and the command calls */ +/* define DB_DIRTY_READ 0x10000000 Support Dirty Read. */ + +/* + * Flags private to db_env_create. + */ +#define DB_CLIENT 0x000400 /* Open for a client environment. */ + +/* + * Flags private to db_create. + */ +#define DB_XA_CREATE 0x000400 /* Open in an XA environment. */ + +/* + * Flags private to DBENV->open. + */ +#define DB_INIT_CDB 0x000400 /* Concurrent Access Methods. */ +#define DB_INIT_LOCK 0x000800 /* Initialize locking. */ +#define DB_INIT_LOG 0x001000 /* Initialize logging. */ +#define DB_INIT_MPOOL 0x002000 /* Initialize mpool. */ +#define DB_INIT_TXN 0x004000 /* Initialize transactions. */ +#define DB_JOINENV 0x008000 /* Initialize all subsystems present. */ +#define DB_LOCKDOWN 0x010000 /* Lock memory into physical core. */ +#define DB_PRIVATE 0x020000 /* DB_ENV is process local. */ +#define DB_RECOVER_FATAL 0x040000 /* Run catastrophic recovery. */ +#define DB_SYSTEM_MEM 0x080000 /* Use system-backed memory. */ + +/* + * Flags private to DB->open. + */ +#define DB_EXCL 0x000400 /* Exclusive open (O_EXCL). */ +#define DB_FCNTL_LOCKING 0x000800 /* UNDOC: fcntl(2) locking. */ +#define DB_ODDFILESIZE 0x001000 /* UNDOC: truncate to N * pgsize. */ +#define DB_RDWRMASTER 0x002000 /* UNDOC: allow subdb master open R/W */ +#define DB_TRUNCATE 0x004000 /* Discard existing DB (O_TRUNC). */ +#define DB_EXTENT 0x008000 /* UNDOC: dealing with an extent. */ + +/* + * Flags private to DBENV->txn_begin. + */ +#define DB_TXN_NOWAIT 0x000400 /* Do not wait for locks in this TXN. */ +#define DB_TXN_SYNC 0x000800 /* Always sync log on commit. */ + +/* + * Flags private to DBENV->set_flags. + */ +#define DB_CDB_ALLDB 0x000400 /* In CDB, lock across environment. */ + +/* + * Flags private to DB->set_feedback's callback. + */ +#define DB_UPGRADE 0x000400 /* Upgrading. */ +#define DB_VERIFY 0x000800 /* Verifying. */ + +/* + * Flags private to DB->set_flags. + * + * DB->set_flags does not share common flags and so values start at 0x01. + */ +#define DB_DUP 0x0001 /* Btree, Hash: duplicate keys. */ +#define DB_DUPSORT 0x0002 /* Btree, Hash: duplicate keys. */ +#define DB_RECNUM 0x0004 /* Btree: record numbers. */ +#define DB_RENUMBER 0x0008 /* Recno: renumber on insert/delete. */ +#define DB_REVSPLITOFF 0x0010 /* Btree: turn off reverse splits. */ +#define DB_SNAPSHOT 0x0020 /* Recno: snapshot the input. */ + +/* + * Flags private to DB->join. + * + * DB->join does not share common flags and so values start at 0x01. + */ +#define DB_JOIN_NOSORT 0x0001 /* Don't try to optimize join. */ + +/* + * Flags private to DB->verify. + * + * DB->verify does not share common flags and so values start at 0x01. + */ +#define DB_AGGRESSIVE 0x0001 /* Salvage anything which might be data.*/ +#define DB_NOORDERCHK 0x0002 /* Skip order check; subdb w/ user func */ +#define DB_ORDERCHKONLY 0x0004 /* Only perform an order check on subdb */ +#define DB_PR_PAGE 0x0008 /* Show page contents (-da). */ +#define DB_PR_RECOVERYTEST 0x0010 /* Recovery test (-dr). */ +#define DB_SALVAGE 0x0020 /* Salvage what looks like data. */ +/* + * !!! + * These must not go over 0x8000, or they will collide with the flags + * used by __bam_vrfy_subtree. + */ + +/* + * Deadlock detector modes; used in the DBENV structure to configure the + * locking subsystem. + */ +#define DB_LOCK_NORUN 0 +#define DB_LOCK_DEFAULT 1 /* Default policy. */ +#define DB_LOCK_MAXLOCKS 2 /* Abort txn with maximum # of locks. */ +#define DB_LOCK_MINLOCKS 3 /* Abort txn with minimum # of locks. */ +#define DB_LOCK_MINWRITE 4 /* Abort txn with minimum writelocks. */ +#define DB_LOCK_OLDEST 5 /* Abort oldest transaction. */ +#define DB_LOCK_RANDOM 6 /* Abort random transaction. */ +#define DB_LOCK_YOUNGEST 7 /* Abort youngest transaction. */ + +/******************************************************* + * Environment. + *******************************************************/ +#define DB_REGION_MAGIC 0x120897 /* Environment magic number. */ + +/* + * !!! + * The values of these enums are used explicitly by the Java code, since + * the DbConstant-building facility does not handle enums. Make sure + * that java/src/com/sleepycat/db/Db.java is kept up-to-date with this. + */ +typedef enum { + DB_TXN_ABORT = 0, + DB_TXN_BACKWARD_ROLL = 1, + DB_TXN_FORWARD_ROLL = 2, + DB_TXN_OPENFILES = 3, + DB_TXN_POPENFILES = 4 +} db_recops; + +#define DB_UNDO(op) ((op) == DB_TXN_ABORT || (op) == DB_TXN_BACKWARD_ROLL) +#define DB_REDO(op) ((op) == DB_TXN_FORWARD_ROLL) + +struct __db_env { + /******************************************************* + * Public: owned by the application. + *******************************************************/ + FILE *db_errfile; /* Error message file stream. */ + const char *db_errpfx; /* Error message prefix. */ + /* Callbacks. */ + void (*db_errcall) __P((const char *, char *)); + void (*db_feedback) __P((DB_ENV *, int, int)); + void (*db_paniccall) __P((DB_ENV *, int)); + int (*db_recovery_init) __P((DB_ENV *)); + + /* App-specified alloc functions. */ + void *(*db_malloc) __P((size_t)); + void *(*db_realloc) __P((void *, size_t)); + void (*db_free) __P((void *)); + + /* + * Currently, the verbose list is a bit field with room for 32 + * entries. There's no reason that it needs to be limited, if + * there are ever more than 32 entries, convert to a bit array. + */ +#define DB_VERB_CHKPOINT 0x0001 /* List checkpoints. */ +#define DB_VERB_DEADLOCK 0x0002 /* Deadlock detection information. */ +#define DB_VERB_RECOVERY 0x0004 /* Recovery information. */ +#define DB_VERB_WAITSFOR 0x0008 /* Dump waits-for table. */ + u_int32_t verbose; /* Verbose output. */ + + void *app_private; /* Application-private handle. */ + + /* Locking. */ + u_int8_t *lk_conflicts; /* Two dimensional conflict matrix. */ + u_int32_t lk_modes; /* Number of lock modes in table. */ + u_int32_t lk_max; /* Maximum number of locks. */ + u_int32_t lk_max_lockers;/* Maximum number of lockers. */ + u_int32_t lk_max_objects;/* Maximum number of locked objects. */ + u_int32_t lk_detect; /* Deadlock detect on all conflicts. */ + + /* Logging. */ + u_int32_t lg_bsize; /* Buffer size. */ + u_int32_t lg_max; /* Maximum file size. */ + u_int32_t lg_regionmax; /* Region size. */ + + /* Memory pool. */ + u_int32_t mp_gbytes; /* Cachesize: GB. */ + u_int32_t mp_bytes; /* Cachesize: Bytes. */ + size_t mp_size; /* DEPRECATED: Cachesize: bytes. */ + int mp_ncache; /* Number of cache regions. */ + size_t mp_mmapsize; /* Maximum file size for mmap. */ + + /* Transactions. */ + u_int32_t tx_max; /* Maximum number of transactions. */ + time_t tx_timestamp; /* Recover to specific timestamp. */ + int (*tx_recover) /* Dispatch function for recovery. */ + __P((DB_ENV *, DBT *, DB_LSN *, db_recops)); + + /******************************************************* + * Private: owned by DB. + *******************************************************/ + int panic_errval; /* Panic causing errno. */ + + /* User files, paths. */ + char *db_home; /* Database home. */ + char *db_log_dir; /* Database log file directory. */ + char *db_tmp_dir; /* Database tmp file directory. */ + + char **db_data_dir; /* Database data file directories. */ + int data_cnt; /* Database data file slots. */ + int data_next; /* Next Database data file slot. */ + + int db_mode; /* Default open permissions. */ + + void *reginfo; /* REGINFO structure reference. */ + DB_FH *lockfhp; /* fcntl(2) locking file handle. */ + long shm_key; /* shmget(2) key. */ + + void *lg_handle; /* Log handle. */ + + void *lk_handle; /* Lock handle. */ + + void *mp_handle; /* Mpool handle. */ + + void *tx_handle; /* Txn handle. */ + + int (**dtab) /* Dispatch table */ + __P((DB_ENV *, DBT *, DB_LSN *, db_recops, void *)); + size_t dtab_size; /* Slots in the dispatch table. */ + + void *cl_handle; /* RPC: remote client handle. */ + long cl_id; /* RPC: remote client env id. */ + + int db_ref; /* db reference count. */ + u_int32_t db_mutexlocks; /* db_set_mutexlocks */ + + /* + * List of open DB handles for this DB_ENV, used for cursor + * adjustment. Must be protected for multi-threaded support. + * + * !!! + * As this structure is allocated in per-process memory, the + * mutex may need to be stored elsewhere on architectures unable + * to support mutexes in heap memory, e.g. HP/UX 9. + */ + void *dblist_mutexp; /* Mutex. */ + /* + * !!! + * Explicit representation of structure in queue.h. + * LIST_HEAD(dblist, __db); + */ + struct { + struct __db *lh_first; + } dblist; + + /* + * XA support. + * + * !!! + * Explicit representations of structures in queue.h. + * + * TAILQ_ENTRY(__db_env); + */ + struct { + struct __db_env *tqe_next; + struct __db_env **tqe_prev; + } links; + int xa_rmid; /* XA Resource Manager ID. */ + DB_TXN *xa_txn; /* XA Current transaction. */ + + void *cj_internal; /* C++/Java private. */ + + /* Methods. */ + int (*close) __P((DB_ENV *, u_int32_t)); + void (*err) __P((const DB_ENV *, int, const char *, ...)); + void (*errx) __P((const DB_ENV *, const char *, ...)); + int (*open) __P((DB_ENV *, const char *, u_int32_t, int)); + int (*remove) __P((DB_ENV *, const char *, u_int32_t)); + int (*set_data_dir) __P((DB_ENV *, const char *)); + int (*set_alloc) __P((DB_ENV *, void *(*)(size_t), + void *(*)(void *, size_t), void (*)(void *))); + void (*set_errcall) __P((DB_ENV *, void (*)(const char *, char *))); + void (*set_errfile) __P((DB_ENV *, FILE *)); + void (*set_errpfx) __P((DB_ENV *, const char *)); + int (*set_feedback) __P((DB_ENV *, void (*)(DB_ENV *, int, int))); + int (*set_flags) __P((DB_ENV *, u_int32_t, int)); + int (*set_mutexlocks) __P((DB_ENV *, int)); + int (*set_paniccall) __P((DB_ENV *, void (*)(DB_ENV *, int))); + int (*set_recovery_init) __P((DB_ENV *, int (*)(DB_ENV *))); + int (*set_rpc_server) __P((DB_ENV *, + void *, const char *, long, long, u_int32_t)); + int (*set_server) __P((DB_ENV *, const char *, long, long, u_int32_t)); + int (*set_shm_key) __P((DB_ENV *, long)); + int (*set_tmp_dir) __P((DB_ENV *, const char *)); + int (*set_verbose) __P((DB_ENV *, u_int32_t, int)); + + int (*set_lg_bsize) __P((DB_ENV *, u_int32_t)); + int (*set_lg_dir) __P((DB_ENV *, const char *)); + int (*set_lg_max) __P((DB_ENV *, u_int32_t)); + int (*set_lg_regionmax) __P((DB_ENV *, u_int32_t)); + + int (*set_lk_conflicts) __P((DB_ENV *, u_int8_t *, int)); + int (*set_lk_detect) __P((DB_ENV *, u_int32_t)); + int (*set_lk_max) __P((DB_ENV *, u_int32_t)); + int (*set_lk_max_locks) __P((DB_ENV *, u_int32_t)); + int (*set_lk_max_lockers) __P((DB_ENV *, u_int32_t)); + int (*set_lk_max_objects) __P((DB_ENV *, u_int32_t)); + + int (*set_mp_mmapsize) __P((DB_ENV *, size_t)); + int (*set_cachesize) __P((DB_ENV *, u_int32_t, u_int32_t, int)); + + int (*set_tx_max) __P((DB_ENV *, u_int32_t)); + int (*set_tx_recover) __P((DB_ENV *, + int (*)(DB_ENV *, DBT *, DB_LSN *, db_recops))); + int (*set_tx_timestamp) __P((DB_ENV *, time_t *)); + +#ifdef CONFIG_TEST +#define DB_TEST_PREOPEN 1 /* before __os_open */ +#define DB_TEST_POSTOPEN 2 /* after __os_open */ +#define DB_TEST_POSTLOGMETA 3 /* after logging meta in btree */ +#define DB_TEST_POSTLOG 4 /* after logging all pages */ +#define DB_TEST_POSTSYNC 5 /* after syncing the log */ +#define DB_TEST_PRERENAME 6 /* before __os_rename */ +#define DB_TEST_POSTRENAME 7 /* after __os_rename */ + int test_abort; /* Abort value for testing. */ + int test_copy; /* Copy value for testing. */ +#endif + +#define DB_ENV_CDB 0x00001 /* DB_INIT_CDB. */ +#define DB_ENV_CDB_ALLDB 0x00002 /* CDB environment wide locking. */ +#define DB_ENV_CREATE 0x00004 /* DB_CREATE set. */ +#define DB_ENV_DBLOCAL 0x00008 /* DB_ENV allocated for private DB. */ +#define DB_ENV_LOCKDOWN 0x00010 /* DB_LOCKDOWN set. */ +#define DB_ENV_NOMMAP 0x00020 /* DB_NOMMAP set. */ +#define DB_ENV_OPEN_CALLED 0x00040 /* DBENV->open called (paths valid). */ +#define DB_ENV_PANIC_OK 0x00080 /* Removing env, okay if panic set */ +#define DB_ENV_PRIVATE 0x00100 /* DB_PRIVATE set. */ +#define DB_ENV_RPCCLIENT 0x00200 /* DB_CLIENT set. */ +#define DB_ENV_RPCCLIENT_GIVEN 0x00400 /* User-supplied RPC client struct */ +#define DB_ENV_STANDALONE 0x00800 /* Test: freestanding environment. */ +#define DB_ENV_SYSTEM_MEM 0x01000 /* DB_SYSTEM_MEM set. */ +#define DB_ENV_THREAD 0x02000 /* DB_THREAD set. */ +#define DB_ENV_TXN_NOSYNC 0x04000 /* DB_TXN_NOSYNC set. */ +#define DB_ENV_USER_ALLOC 0x08000 /* User allocated the structure. */ + u_int32_t flags; /* Flags. */ +}; + +/******************************************************* + * Access methods. + *******************************************************/ +/* + * !!! + * Changes here must be reflected in java/src/com/sleepycat/db/Db.java. + */ +typedef enum { + DB_BTREE=1, + DB_HASH, + DB_RECNO, + DB_QUEUE, + DB_UNKNOWN /* Figure it out on open. */ +} DBTYPE; + +#define DB_BTREEVERSION 8 /* Current btree version. */ +#define DB_BTREEOLDVER 6 /* Oldest btree version supported. */ +#define DB_BTREEMAGIC 0x053162 + +#define DB_HASHVERSION 7 /* Current hash version. */ +#define DB_HASHOLDVER 4 /* Oldest hash version supported. */ +#define DB_HASHMAGIC 0x061561 + +#define DB_QAMVERSION 3 /* Current queue version. */ +#define DB_QAMOLDVER 1 /* Oldest queue version supported. */ +#define DB_QAMMAGIC 0x042253 + +#define DB_LOGVERSION 3 /* Current log version. */ +#define DB_LOGOLDVER 3 /* Oldest log version supported. */ +#define DB_LOGMAGIC 0x040988 + +/* + * DB access method and cursor operation values. Each value is an operation + * code to which additional bit flags are added. + */ +#define DB_AFTER 1 /* c_put() */ +#define DB_APPEND 2 /* put() */ +#define DB_BEFORE 3 /* c_put() */ +#define DB_CACHED_COUNTS 4 /* stat() */ +#define DB_CHECKPOINT 5 /* log_put(), log_get() */ +#define DB_COMMIT 6 /* log_put() (internal) */ +#define DB_CONSUME 7 /* get() */ +#define DB_CONSUME_WAIT 8 /* get() */ +#define DB_CURLSN 9 /* log_put() */ +#define DB_CURRENT 10 /* c_get(), c_put(), log_get() */ +#define DB_FAST_STAT 11 /* stat() */ +#define DB_FIRST 12 /* c_get(), log_get() */ +#define DB_FLUSH 13 /* log_put() */ +#define DB_GET_BOTH 14 /* get(), c_get() */ +#define DB_GET_BOTHC 15 /* c_get() (internal) */ +#define DB_GET_RECNO 16 /* c_get() */ +#define DB_JOIN_ITEM 17 /* c_get(); do not do primary lookup */ +#define DB_KEYFIRST 18 /* c_put() */ +#define DB_KEYLAST 19 /* c_put() */ +#define DB_LAST 20 /* c_get(), log_get() */ +#define DB_NEXT 21 /* c_get(), log_get() */ +#define DB_NEXT_DUP 22 /* c_get() */ +#define DB_NEXT_NODUP 23 /* c_get() */ +#define DB_NODUPDATA 24 /* put(), c_put() */ +#define DB_NOOVERWRITE 25 /* put() */ +#define DB_NOSYNC 26 /* close() */ +#define DB_POSITION 27 /* c_dup() */ +#define DB_POSITIONI 28 /* c_dup() (internal) */ +#define DB_PREV 29 /* c_get(), log_get() */ +#define DB_PREV_NODUP 30 /* c_get(), log_get() */ +#define DB_RECORDCOUNT 31 /* stat() */ +#define DB_SET 32 /* c_get(), log_get() */ +#define DB_SET_RANGE 33 /* c_get() */ +#define DB_SET_RECNO 34 /* get(), c_get() */ +#define DB_UPDATE_SECONDARY 35 /* c_get(), c_del() (internal) */ +#define DB_WRITECURSOR 36 /* cursor() */ +#define DB_WRITELOCK 37 /* cursor() (internal) */ + +/* This has to change when the max opcode hits 255. */ +#define DB_OPFLAGS_MASK 0x000000ff /* Mask for operations flags. */ +#define DB_DIRTY_READ 0x10000000 /* Support Dirty Read. */ +#define DB_MULTIPLE 0x20000000 /* Return multiple data values. */ +#define DB_MULTIPLE_KEY 0x40000000 /* Return multiple data/key pairs. */ +#define DB_RMW 0x80000000 /* Acquire write flag immediately. */ + +/* + * DB (user visible) error return codes. + * + * !!! + * Changes to any of the user visible error return codes must be reflected + * in java/src/com/sleepycat/db/Db.java. + * + * !!! + * For source compatibility with DB 2.X deadlock return (EAGAIN), use the + * following: + * #include <errno.h> + * #define DB_LOCK_DEADLOCK EAGAIN + * + * !!! + * We don't want our error returns to conflict with other packages where + * possible, so pick a base error value that's hopefully not common. We + * document that we own the error name space from -30,800 to -30,999. + */ +/* Public error return codes. */ +#define DB_DONOTINDEX (-30999)/* "Null" return from 2ndary callbk. */ +#define DB_INCOMPLETE (-30998)/* Sync didn't finish. */ +#define DB_KEYEMPTY (-30997)/* Key/data deleted or never created. */ +#define DB_KEYEXIST (-30996)/* The key/data pair already exists. */ +#define DB_LOCK_DEADLOCK (-30995)/* Deadlock. */ +#define DB_LOCK_NOTGRANTED (-30994)/* Lock unavailable. */ +#define DB_NOSERVER (-30993)/* Server panic return. */ +#define DB_NOSERVER_HOME (-30992)/* Bad home sent to server. */ +#define DB_NOSERVER_ID (-30991)/* Bad ID sent to server. */ +#define DB_NOTFOUND (-30990)/* Key/data pair not found (EOF). */ +#define DB_OLD_VERSION (-30989)/* Out-of-date version. */ +#define DB_PAGE_NOTFOUND (-30988)/* Verify failed; bad format. */ +#define DB_RUNRECOVERY (-30987)/* Panic return. */ +#define DB_VERIFY_BAD (-30986)/* Verify failed; bad format. */ + +/* DB (private) error return codes. */ +#define DB_ALREADY_ABORTED (-30899) +#define DB_DELETED (-30898)/* Recovery file marked deleted. */ +#define DB_JAVA_CALLBACK (-30897)/* Exception during a java callback. */ +#define DB_NEEDSPLIT (-30896)/* Page needs to be split. */ +#define DB_SWAPBYTES (-30895)/* Database needs byte swapping. */ +#define DB_TXN_CKP (-30894)/* Encountered ckp record in log. */ +#define DB_VERIFY_FATAL (-30893)/* Fatal: DB->verify cannot proceed. */ + +#define DB_FILE_ID_LEN 20 /* DB file ID length. */ + +/* DB access method description structure. */ +struct __db { + /******************************************************* + * Public: owned by the application. + *******************************************************/ + u_int32_t pgsize; /* Database logical page size. */ + + /* Callbacks. */ + int (*db_append_recno) __P((DB *, DBT *, db_recno_t)); + void (*db_feedback) __P((DB *, int, int)); + int (*dup_compare) __P((DB *, const DBT *, const DBT *)); + + void *app_private; /* Application-private handle. */ + + /******************************************************* + * Private: owned by DB. + *******************************************************/ + DB_ENV *dbenv; /* Backing environment. */ + + DBTYPE type; /* DB access method type. */ + + DB_MPOOLFILE *mpf; /* Backing buffer pool. */ + + void *mutexp; /* Synchronization for free threading */ + + u_int8_t fileid[DB_FILE_ID_LEN];/* File's unique ID for locking. */ + + u_int32_t adj_fileid; /* File's unique ID for curs. adj. */ + +#define DB_LOGFILEID_INVALID -1 + int32_t log_fileid; /* File's unique ID for logging. */ + db_pgno_t meta_pgno; /* Meta page number */ + DB_TXN *open_txn; /* Transaction to protect creates. */ + + long cl_id; /* RPC: remote client id. */ + + /* + * Returned data memory for DB->get() and friends. + */ + DBT my_rskey; /* Secondary key. */ + DBT my_rkey; /* [Primary] key. */ + DBT my_rdata; /* Data. */ + + /* + * !!! + * Some applications use DB but implement their own locking outside of + * DB. If they're using fcntl(2) locking on the underlying database + * file, and we open and close a file descriptor for that file, we will + * discard their locks. The DB_FCNTL_LOCKING flag to DB->open is an + * undocumented interface to support this usage which leaves any file + * descriptors we open until DB->close. This will only work with the + * DB->open interface and simple caches, e.g., creating a transaction + * thread may open/close file descriptors this flag doesn't protect. + * Locking with fcntl(2) on a file that you don't own is a very, very + * unsafe thing to do. 'Nuff said. + */ + DB_FH *saved_open_fhp; /* Saved file handle. */ + + /* + * Linked list of DBP's, used in the log's dbentry table + * to keep track of all open db handles for a given log id. + * !!! + * Explicit representations of structures in queue.h. + * + * TAILQ_ENTRY(__db) links; + */ + struct { + struct __db *tqe_next; + struct __db **tqe_prev; + } links; + + /* + * Linked list of DBP's, linked from the DB_ENV, used to + * keep track of all open db handles for cursor adjustment. + * + * XXX + * Eventually, this should be merged with "links" above. + * + * !!! + * Explicit representations of structures in queue.h. + * + * LIST_ENTRY(__db) dblistlinks; + */ + struct { + struct __db *le_next; + struct __db **le_prev; + } dblistlinks; + + /* + * Cursor queues. + * + * !!! + * Explicit representations of structures in queue.h. + * + * TAILQ_HEAD(free_queue, __dbc); + * TAILQ_HEAD(active_queue, __dbc); + * TAILQ_HEAD(join_queue, __dbc); + */ + struct { + struct __dbc *tqh_first; + struct __dbc **tqh_last; + } free_queue; + struct { + struct __dbc *tqh_first; + struct __dbc **tqh_last; + } active_queue; + struct { + struct __dbc *tqh_first; + struct __dbc **tqh_last; + } join_queue; + + /* + * Secondary index support. + * + * !!! + * Explicit representations of structures in queue.h. + */ + /* Linked list of secondary indices -- set in the primary. */ + struct { + struct __db *lh_first; + } s_secondaries; + + /* + * List entries for secondaries, and reference count of how + * many threads are updating this secondary (see __db_c_put). + * + * !!! + * Note that these are synchronized by the primary's mutex, but + * filled in in the secondaries. + */ + struct { + struct __db *le_next; + struct __db **le_prev; + } s_links; + u_int32_t s_refcnt; + + /* Secondary callback and free functions -- set in the secondary. */ + int (*s_callback)(DB *, const DBT *, const DBT *, DBT *); + + /* Reference to primary -- set in the secondary. */ + DB *s_primary; + + /* + * Subsystem-private structures. + */ + + void *bt_internal; /* Btree/Recno access method private. */ + void *cj_internal; /* C++/Java private. */ + void *h_internal; /* Hash access method private. */ + void *q_internal; /* Queue access method private. */ + void *xa_internal; /* XA private. */ + + /* Methods. */ + int (*associate) __P((DB *, DB *, int (*)(DB *, const DBT *, + const DBT *, DBT *), u_int32_t)); + int (*close) __P((DB *, u_int32_t)); + int (*cursor) __P((DB *, DB_TXN *, DBC **, u_int32_t)); + int (*del) __P((DB *, DB_TXN *, DBT *, u_int32_t)); + void (*err) __P((DB *, int, const char *, ...)); + void (*errx) __P((DB *, const char *, ...)); + int (*fd) __P((DB *, int *)); + int (*get) __P((DB *, DB_TXN *, DBT *, DBT *, u_int32_t)); + int (*pget) __P((DB *, DB_TXN *, DBT *, DBT *, DBT *, u_int32_t)); + int (*get_byteswapped) __P((DB *)); + DBTYPE + (*get_type) __P((DB *)); + int (*join) __P((DB *, DBC **, DBC **, u_int32_t)); + int (*key_range) __P((DB *, + DB_TXN *, DBT *, DB_KEY_RANGE *, u_int32_t)); + int (*open) __P((DB *, + const char *, const char *, DBTYPE, u_int32_t, int)); + int (*put) __P((DB *, DB_TXN *, DBT *, DBT *, u_int32_t)); + int (*remove) __P((DB *, const char *, const char *, u_int32_t)); + int (*rename) __P((DB *, + const char *, const char *, const char *, u_int32_t)); + int (*truncate) __P((DB *, + const char *, const char *, u_int32_t *, u_int32_t)); + int (*set_append_recno) __P((DB *, int (*)(DB *, DBT *, db_recno_t))); + int (*set_alloc) __P((DB *, void *(*)(size_t), + void *(*)(void *, size_t), void (*)(void *))); + int (*set_cachesize) __P((DB *, u_int32_t, u_int32_t, int)); + int (*set_dup_compare) __P((DB *, + int (*)(DB *, const DBT *, const DBT *))); + void (*set_errcall) __P((DB *, void (*)(const char *, char *))); + void (*set_errfile) __P((DB *, FILE *)); + void (*set_errpfx) __P((DB *, const char *)); + int (*set_feedback) __P((DB *, void (*)(DB *, int, int))); + int (*set_flags) __P((DB *, u_int32_t)); + int (*set_lorder) __P((DB *, int)); + int (*set_pagesize) __P((DB *, u_int32_t)); + int (*set_paniccall) __P((DB *, void (*)(DB_ENV *, int))); + int (*stat) __P((DB *, void *, u_int32_t)); + int (*sync) __P((DB *, u_int32_t)); + int (*upgrade) __P((DB *, const char *, u_int32_t)); + int (*verify) __P((DB *, + const char *, const char *, FILE *, u_int32_t)); + + int (*set_bt_compare) __P((DB *, + int (*)(DB *, const DBT *, const DBT *))); + int (*set_bt_maxkey) __P((DB *, u_int32_t)); + int (*set_bt_minkey) __P((DB *, u_int32_t)); + int (*set_bt_prefix) __P((DB *, + size_t (*)(DB *, const DBT *, const DBT *))); + + int (*set_h_ffactor) __P((DB *, u_int32_t)); + int (*set_h_hash) __P((DB *, + u_int32_t (*)(DB *, const void *, u_int32_t))); + int (*set_h_nelem) __P((DB *, u_int32_t)); + + int (*set_re_delim) __P((DB *, int)); + int (*set_re_len) __P((DB *, u_int32_t)); + int (*set_re_pad) __P((DB *, int)); + int (*set_re_source) __P((DB *, const char *)); + int (*set_q_extentsize) __P((DB *, u_int32_t)); + + int (*db_am_remove) __P((DB *, const char *, + const char *, DB_LSN *, int (**)(DB *, void *), void **)); + int (*db_am_rename) __P((DB *, + const char *, const char *, const char *)); + +#define DB_OK_BTREE 0x01 +#define DB_OK_HASH 0x02 +#define DB_OK_QUEUE 0x04 +#define DB_OK_RECNO 0x08 + u_int32_t am_ok; /* Legal AM choices. */ + +#define DB_AM_DIRTY 0x000001 /* Support Dirty Reads. */ +#define DB_AM_DISCARD 0x000002 /* Discard any cached pages. */ +#define DB_AM_DUP 0x000004 /* DB_DUP. */ +#define DB_AM_DUPSORT 0x000008 /* DB_DUPSORT. */ +#define DB_AM_INMEM 0x000010 /* In-memory; no sync on close. */ +#define DB_AM_PGDEF 0x000020 /* Page size was defaulted. */ +#define DB_AM_RDONLY 0x000040 /* Database is readonly. */ +#define DB_AM_RECOVER 0x000080 /* DBP opened by recovery routine. */ +#define DB_AM_SECONDARY 0x000100 /* Database is a secondary index. */ +#define DB_AM_SUBDB 0x000200 /* Subdatabases supported. */ +#define DB_AM_SWAP 0x000400 /* Pages need to be byte-swapped. */ +#define DB_AM_TXN 0x000800 /* DBP was in a transaction. */ +#define DB_AM_VERIFYING 0x001000 /* DB handle is in the verifier. */ +#define DB_BT_RECNUM 0x002000 /* DB_RECNUM. */ +#define DB_BT_REVSPLIT 0x004000 /* DB_REVSPLITOFF. */ +#define DB_DBM_ERROR 0x008000 /* Error in DBM/NDBM database. */ +#define DB_OPEN_CALLED 0x010000 /* DB->open called. */ +#define DB_RE_DELIMITER 0x020000 /* Variablen length delimiter set. */ +#define DB_RE_FIXEDLEN 0x040000 /* Fixed-length records. */ +#define DB_RE_PAD 0x080000 /* Fixed-length record pad. */ +#define DB_RE_RENUMBER 0x100000 /* DB_RENUMBER. */ +#define DB_RE_SNAPSHOT 0x200000 /* DB_SNAPSHOT. */ + u_int32_t flags; +}; +/******************************************************* + * Locking + *******************************************************/ +#define DB_LOCKVERSION 1 + +/* Flag values for lock_vec(), lock_get(). */ +#define DB_LOCK_NOWAIT 0x01 /* Don't wait on unavailable lock. */ +#define DB_LOCK_RECORD 0x02 /* Internal: record lock. */ +#define DB_LOCK_UPGRADE 0x04 /* Internal: upgrade existing lock. */ +#define DB_LOCK_SWITCH 0x08 /* Internal: switch existing lock. */ + +/* + * Request types. + * + * !!! + * Changes here must be reflected in java/src/com/sleepycat/db/Db.java. + */ +typedef enum { + DB_LOCK_DUMP=0, /* Display held locks. */ + DB_LOCK_GET, /* Get the lock. */ + DB_LOCK_INHERIT, /* Pass locks to parent. */ + DB_LOCK_PUT, /* Release the lock. */ + DB_LOCK_PUT_ALL, /* Release locker's locks. */ + DB_LOCK_PUT_OBJ, /* Release locker's locks on obj. */ + DB_LOCK_UPGRADE_WRITE /* Upgrade writes for dirty reads. */ +} db_lockop_t; + +/* + * Simple R/W lock modes and for multi-granularity intention locking. + * + * !!! + * These values are NOT random, as they are used as an index into the lock + * conflicts arrays, i.e., DB_LOCK_IWRITE must be == 3, and DB_LOCK_IREAD + * must be == 4. + * + * !!! + * Changes here must be reflected in java/src/com/sleepycat/db/Db.java. + */ +typedef enum { + DB_LOCK_NG=0, /* Not granted. */ + DB_LOCK_READ, /* Shared/read. */ + DB_LOCK_WRITE, /* Exclusive/write. */ + DB_LOCK_WAIT, /* Wait for event */ + DB_LOCK_IWRITE, /* Intent exclusive/write. */ + DB_LOCK_IREAD, /* Intent to share/read. */ + DB_LOCK_IWR, /* Intent to read and write. */ + DB_LOCK_DIRTY, /* Dirty Read. */ + DB_LOCK_WWRITE /* Was Written. */ +} db_lockmode_t; + +/* + * Status of a lock. + */ +typedef enum { + DB_LSTAT_ABORTED, /* Lock belongs to an aborted txn. */ + DB_LSTAT_ERR, /* Lock is bad. */ + DB_LSTAT_FREE, /* Lock is unallocated. */ + DB_LSTAT_HELD, /* Lock is currently held. */ + DB_LSTAT_NOGRANT, /* Lock was not granted. */ + DB_LSTAT_PENDING, /* Lock was waiting and has been + * promoted; waiting for the owner + * to run and upgrade it to held. */ + DB_LSTAT_WAITING /* Lock is on the wait queue. */ +} db_status_t; + +/* Lock statistics structure. */ +struct __db_lock_stat { + u_int32_t st_lastid; /* Last allocated locker ID. */ + u_int32_t st_maxlocks; /* Maximum number of locks in table. */ + u_int32_t st_maxlockers; /* Maximum num of lockers in table. */ + u_int32_t st_maxobjects; /* Maximum num of objects in table. */ + u_int32_t st_nmodes; /* Number of lock modes. */ + u_int32_t st_nlocks; /* Current number of locks. */ + u_int32_t st_maxnlocks; /* Maximum number of locks so far. */ + u_int32_t st_nlockers; /* Current number of lockers. */ + u_int32_t st_maxnlockers; /* Maximum number of lockers so far. */ + u_int32_t st_nobjects; /* Current number of objects. */ + u_int32_t st_maxnobjects; /* Maximum number of objects so far. */ + u_int32_t st_nconflicts; /* Number of lock conflicts. */ + u_int32_t st_nrequests; /* Number of lock gets. */ + u_int32_t st_nreleases; /* Number of lock puts. */ + u_int32_t st_nnowaits; /* Number of requests that would have + waited, but NOWAIT was set. */ + u_int32_t st_ndeadlocks; /* Number of lock deadlocks. */ + u_int32_t st_region_wait; /* Region lock granted after wait. */ + u_int32_t st_region_nowait; /* Region lock granted without wait. */ + u_int32_t st_regsize; /* Region size. */ +}; + +/* + * DB_LOCK_ILOCK -- + * Internal DB access method lock. + */ +struct __db_ilock { + db_pgno_t pgno; /* Page being locked. */ + u_int8_t fileid[DB_FILE_ID_LEN];/* File id. */ +#define DB_RECORD_LOCK 1 +#define DB_PAGE_LOCK 2 + u_int8_t type; /* Record or Page lock */ +}; + +/* + * DB_LOCK -- + * The structure is allocated by the caller and filled in during a + * lock_get request (or a lock_vec/DB_LOCK_GET). + */ +struct __db_lock_u { + size_t off; /* Offset of the lock in the region */ + u_int32_t ndx; /* Index of the object referenced by + * this lock; used for locking. */ + u_int32_t gen; /* Generation number of this lock. */ + db_lockmode_t mode; /* mode of this lock. */ +}; + +/* Lock request structure. */ +struct __db_lockreq { + db_lockop_t op; /* Operation. */ + db_lockmode_t mode; /* Requested mode. */ + DBT *obj; /* Object being locked. */ + DB_LOCK lock; /* Lock returned. */ +}; + +/* Cursor description structure. */ +struct __dbc { + DB *dbp; /* Related DB access method. */ + DB_TXN *txn; /* Associated transaction. */ + + /* + * !!! + * Explicit representations of structures in queue.h. + * + * TAILQ_ENTRY(__dbc) links; Active/free cursor queues. + */ + struct { + DBC *tqe_next; + DBC **tqe_prev; + } links; + + /* + * The DBT *'s below are used by the cursor routines to return + * data to the user when DBT flags indicate that DB should manage + * the returned memory. They point at a DBT containing the buffer + * and length that will be used, and "belonging" to the handle that + * should "own" this memory. This may be a "my_*" field of this + * cursor--the default--or it may be the corresponding field of + * another cursor, a DB handle, a join cursor, etc. In general, it + * will be whatever handle the user originally used for the current + * DB interface call. + */ + DBT *rskey; /* Returned secondary key. */ + DBT *rkey; /* Returned [primary] key. */ + DBT *rdata; /* Returned data. */ + + DBT my_rskey; /* Space for returned secondary key. */ + DBT my_rkey; /* Space for returned [primary] key. */ + DBT my_rdata; /* Space for returned data. */ + + u_int32_t lid; /* Default process' locker id. */ + u_int32_t locker; /* Locker for this operation. */ + DBT lock_dbt; /* DBT referencing lock. */ + DB_LOCK_ILOCK lock; /* Object to be locked. */ + DB_LOCK mylock; /* Lock held on this cursor. */ + + long cl_id; /* Remote client id. */ + + DBTYPE dbtype; /* Cursor type. */ + + DBC_INTERNAL *internal; /* Access method private. */ + + int (*c_close) __P((DBC *)); /* Methods: public. */ + int (*c_count) __P((DBC *, db_recno_t *, u_int32_t)); + int (*c_del) __P((DBC *, u_int32_t)); + int (*c_dup) __P((DBC *, DBC **, u_int32_t)); + int (*c_get) __P((DBC *, DBT *, DBT *, u_int32_t)); + int (*c_pget) __P((DBC *, DBT *, DBT *, DBT *, u_int32_t)); + int (*c_put) __P((DBC *, DBT *, DBT *, u_int32_t)); + + /* Methods: private. */ + int (*c_am_bulk) __P((DBC *, DBT *, u_int32_t)); + int (*c_am_close) __P((DBC *, db_pgno_t, int *)); + int (*c_am_del) __P((DBC *)); + int (*c_am_destroy) __P((DBC *)); + int (*c_am_get) __P((DBC *, DBT *, DBT *, u_int32_t, db_pgno_t *)); + int (*c_am_put) __P((DBC *, DBT *, DBT *, u_int32_t, db_pgno_t *)); + int (*c_am_writelock) __P((DBC *)); + + /* Private: for secondary indices. */ + int (*c_real_get) __P((DBC *, DBT *, DBT *, u_int32_t)); + +#define DBC_ACTIVE 0x001 /* Cursor is being used. */ +#define DBC_COMPENSATE 0x002 /* Cursor is doing compensation + * do not lock. + */ +#define DBC_DIRTY_READ 0x004 /* Cursor is supporting dirty reads. */ +#define DBC_OPD 0x008 /* Cursor references off-page dups. */ +#define DBC_RECOVER 0x010 /* Cursor created by recovery routine + * (do not log or lock). + */ +#define DBC_RMW 0x020 /* Acquire write flag in read op. */ +#define DBC_TRANSIENT 0x040 /* Cursor is transient. */ +#define DBC_WRITECURSOR 0x080 /* Cursor may be used to write (CDB). */ +#define DBC_WRITEDUP 0x100 /* idup'ed DBC_WRITECURSOR (CDB). */ +#define DBC_WRITER 0x200 /* Cursor immediately writing (CDB). */ +#define DBC_MULTIPLE 0x400 /* Return Multiple data. */ +#define DBC_MULTIPLE_KEY 0x800 /* Return Multiple keys and data. */ + u_int32_t flags; +}; + +/* Key range statistics structure */ +struct __key_range { + double less; + double equal; + double greater; +}; + +/* Btree/Recno statistics structure. */ +struct __db_bt_stat { + u_int32_t bt_magic; /* Magic number. */ + u_int32_t bt_version; /* Version number. */ + u_int32_t bt_metaflags; /* Metadata flags. */ + u_int32_t bt_nkeys; /* Number of unique keys. */ + u_int32_t bt_ndata; /* Number of data items. */ + u_int32_t bt_pagesize; /* Page size. */ + u_int32_t bt_maxkey; /* Maxkey value. */ + u_int32_t bt_minkey; /* Minkey value. */ + u_int32_t bt_re_len; /* Fixed-length record length. */ + u_int32_t bt_re_pad; /* Fixed-length record pad. */ + u_int32_t bt_levels; /* Tree levels. */ + u_int32_t bt_int_pg; /* Internal pages. */ + u_int32_t bt_leaf_pg; /* Leaf pages. */ + u_int32_t bt_dup_pg; /* Duplicate pages. */ + u_int32_t bt_over_pg; /* Overflow pages. */ + u_int32_t bt_free; /* Pages on the free list. */ + u_int32_t bt_int_pgfree; /* Bytes free in internal pages. */ + u_int32_t bt_leaf_pgfree; /* Bytes free in leaf pages. */ + u_int32_t bt_dup_pgfree; /* Bytes free in duplicate pages. */ + u_int32_t bt_over_pgfree; /* Bytes free in overflow pages. */ +}; + +/* Queue statistics structure. */ +struct __db_qam_stat { + u_int32_t qs_magic; /* Magic number. */ + u_int32_t qs_version; /* Version number. */ + u_int32_t qs_metaflags; /* Metadata flags. */ + u_int32_t qs_nkeys; /* Number of unique keys. */ + u_int32_t qs_ndata; /* Number of data items. */ + u_int32_t qs_pagesize; /* Page size. */ + u_int32_t qs_extentsize; /* Pages per extent. */ + u_int32_t qs_pages; /* Data pages. */ + u_int32_t qs_re_len; /* Fixed-length record length. */ + u_int32_t qs_re_pad; /* Fixed-length record pad. */ + u_int32_t qs_pgfree; /* Bytes free in data pages. */ + u_int32_t qs_first_recno; /* First not deleted record. */ + u_int32_t qs_cur_recno; /* Last allocated record number. */ +}; + +/* Hash statistics structure. */ +struct __db_h_stat { + u_int32_t hash_magic; /* Magic number. */ + u_int32_t hash_version; /* Version number. */ + u_int32_t hash_metaflags; /* Metadata flags. */ + u_int32_t hash_nkeys; /* Number of unique keys. */ + u_int32_t hash_ndata; /* Number of data items. */ + u_int32_t hash_pagesize; /* Page size. */ + u_int32_t hash_nelem; /* Original nelem specified. */ + u_int32_t hash_ffactor; /* Fill factor specified at create. */ + u_int32_t hash_buckets; /* Number of hash buckets. */ + u_int32_t hash_free; /* Pages on the free list. */ + u_int32_t hash_bfree; /* Bytes free on bucket pages. */ + u_int32_t hash_bigpages; /* Number of big key/data pages. */ + u_int32_t hash_big_bfree; /* Bytes free on big item pages. */ + u_int32_t hash_overflows; /* Number of overflow pages. */ + u_int32_t hash_ovfl_free; /* Bytes free on ovfl pages. */ + u_int32_t hash_dup; /* Number of dup pages. */ + u_int32_t hash_dup_free; /* Bytes free on duplicate pages. */ +}; + +/******************************************************* +* Logging. + *******************************************************/ +/* Flag values for log_archive(). */ +#define DB_ARCH_ABS 0x001 /* Absolute pathnames. */ +#define DB_ARCH_DATA 0x002 /* Data files. */ +#define DB_ARCH_LOG 0x004 /* Log files. */ + +/* + * A DB_LSN has two parts, a fileid which identifies a specific file, and an + * offset within that file. The fileid is an unsigned 4-byte quantity that + * uniquely identifies a file within the log directory -- currently a simple + * counter inside the log. The offset is also an unsigned 4-byte value. The + * log manager guarantees the offset is never more than 4 bytes by switching + * to a new log file before the maximum length imposed by an unsigned 4-byte + * offset is reached. + */ +struct __db_lsn { + u_int32_t file; /* File ID. */ + u_int32_t offset; /* File offset. */ +}; + +/* Log statistics structure. */ +struct __db_log_stat { + u_int32_t st_magic; /* Log file magic number. */ + u_int32_t st_version; /* Log file version number. */ + int st_mode; /* Log file mode. */ + u_int32_t st_lg_bsize; /* Log buffer size. */ + u_int32_t st_lg_max; /* Maximum log file size. */ + u_int32_t st_w_bytes; /* Bytes to log. */ + u_int32_t st_w_mbytes; /* Megabytes to log. */ + u_int32_t st_wc_bytes; /* Bytes to log since checkpoint. */ + u_int32_t st_wc_mbytes; /* Megabytes to log since checkpoint. */ + u_int32_t st_wcount; /* Total writes to the log. */ + u_int32_t st_wcount_fill; /* Overflow writes to the log. */ + u_int32_t st_scount; /* Total syncs to the log. */ + u_int32_t st_region_wait; /* Region lock granted after wait. */ + u_int32_t st_region_nowait; /* Region lock granted without wait. */ + u_int32_t st_cur_file; /* Current log file number. */ + u_int32_t st_cur_offset; /* Current log file offset. */ + u_int32_t st_regsize; /* Region size. */ +}; + +/******************************************************* + * Mpool + *******************************************************/ +/* Flag values for memp_fget(). */ +#define DB_MPOOL_CREATE 0x001 /* Create a page. */ +#define DB_MPOOL_LAST 0x002 /* Return the last page. */ +#define DB_MPOOL_NEW 0x004 /* Create a new page. */ +#define DB_MPOOL_NEW_GROUP 0x008 /* Create a group of pages. */ + +/* Flag values for memp_fput(), memp_fset(). */ +#define DB_MPOOL_CLEAN 0x001 /* Page is not modified. */ +#define DB_MPOOL_DIRTY 0x002 /* Page is modified. */ +#define DB_MPOOL_DISCARD 0x004 /* Don't cache the page. */ + +/* Mpool statistics structure. */ +struct __db_mpool_stat { + u_int32_t st_cache_hit; /* Pages found in the cache. */ + u_int32_t st_cache_miss; /* Pages not found in the cache. */ + u_int32_t st_map; /* Pages from mapped files. */ + u_int32_t st_page_create; /* Pages created in the cache. */ + u_int32_t st_page_in; /* Pages read in. */ + u_int32_t st_page_out; /* Pages written out. */ + u_int32_t st_ro_evict; /* Clean pages forced from the cache. */ + u_int32_t st_rw_evict; /* Dirty pages forced from the cache. */ + u_int32_t st_hash_buckets; /* Number of hash buckets. */ + u_int32_t st_hash_searches; /* Total hash chain searches. */ + u_int32_t st_hash_longest; /* Longest hash chain searched. */ + u_int32_t st_hash_examined; /* Total hash entries searched. */ + u_int32_t st_page_clean; /* Clean pages. */ + u_int32_t st_page_dirty; /* Dirty pages. */ + u_int32_t st_page_trickle; /* Pages written by memp_trickle. */ + u_int32_t st_region_wait; /* Region lock granted after wait. */ + u_int32_t st_region_nowait; /* Region lock granted without wait. */ + u_int32_t st_gbytes; /* Total cache size: GB. */ + u_int32_t st_bytes; /* Total cache size: B. */ + u_int32_t st_ncache; /* Number of caches. */ + u_int32_t st_regsize; /* Cache size. */ +}; + +/* Mpool file open information structure. */ +struct __db_mpool_finfo { + int ftype; /* File type. */ + DBT *pgcookie; /* Byte-string passed to pgin/pgout. */ + u_int8_t *fileid; /* Unique file ID. */ + int32_t lsn_offset; /* LSN offset in page. */ + u_int32_t clear_len; /* Cleared length on created pages. */ +}; + +/* Mpool file statistics structure. */ +struct __db_mpool_fstat { + char *file_name; /* File name. */ + size_t st_pagesize; /* Page size. */ + u_int32_t st_cache_hit; /* Pages found in the cache. */ + u_int32_t st_cache_miss; /* Pages not found in the cache. */ + u_int32_t st_map; /* Pages from mapped files. */ + u_int32_t st_page_create; /* Pages created in the cache. */ + u_int32_t st_page_in; /* Pages read in. */ + u_int32_t st_page_out; /* Pages written out. */ +}; + +/******************************************************* + * Transactions. + *******************************************************/ +#define DB_TXNVERSION 1 + +/* Transaction statistics structure. */ +struct __db_txn_active { + u_int32_t txnid; /* Transaction ID */ + u_int32_t parentid; /* Transaction ID of parent */ + DB_LSN lsn; /* Lsn of the begin record */ +}; + +struct __db_txn_stat { + DB_LSN st_last_ckp; /* lsn of the last checkpoint */ + DB_LSN st_pending_ckp; /* last checkpoint did not finish */ + time_t st_time_ckp; /* time of last checkpoint */ + u_int32_t st_last_txnid; /* last transaction id given out */ + u_int32_t st_maxtxns; /* maximum txns possible */ + u_int32_t st_naborts; /* number of aborted transactions */ + u_int32_t st_nbegins; /* number of begun transactions */ + u_int32_t st_ncommits; /* number of committed transactions */ + u_int32_t st_nactive; /* number of active transactions */ + u_int32_t st_nrestores; /* number of restored transactions + after recovery. */ + u_int32_t st_maxnactive; /* maximum active transactions */ + DB_TXN_ACTIVE + *st_txnarray; /* array of active transactions */ + u_int32_t st_region_wait; /* Region lock granted after wait. */ + u_int32_t st_region_nowait; /* Region lock granted without wait. */ + u_int32_t st_regsize; /* Region size. */ +}; + +/* + * Structure used for two phase commit interface. Berkeley DB support for two + * phase commit is compatible with the X/open XA interface. The xa #define + * XIDDATASIZE defines the size of a global transaction ID. We have our own + * version here which must have the same value. + */ +#define DB_XIDDATASIZE 128 +typedef struct db_preplist { + DB_TXN *txn; + u_int8_t gid[DB_XIDDATASIZE]; +} DB_PREPLIST; + +#ifndef DB_DBM_HSEARCH +#define DB_DBM_HSEARCH 0 /* No historic interfaces by default. */ +#endif +#if DB_DBM_HSEARCH != 0 +/******************************************************* + * Dbm/Ndbm historic interfaces. + *******************************************************/ +typedef struct __db DBM; + +#define DBM_INSERT 0 /* Flags to dbm_store(). */ +#define DBM_REPLACE 1 + +/* + * The DB support for ndbm(3) always appends this suffix to the + * file name to avoid overwriting the user's original database. + */ +#define DBM_SUFFIX ".db" + +#if defined(_XPG4_2) +typedef struct { + char *dptr; + size_t dsize; +} datum; +#else +typedef struct { + char *dptr; + int dsize; +} datum; +#endif + +/******************************************************* + * Hsearch historic interface. + *******************************************************/ +typedef enum { + FIND, ENTER +} ACTION; + +typedef struct entry { + char *key; + char *data; +} ENTRY; + +#endif /* DB_DBM_HSEARCH */ + +/* + * XXX + * MacOS: Reset Metrowerks C enum sizes. + */ +#ifdef __MWERKS__ +#pragma enumsalwaysint reset +#endif + +#if defined(__cplusplus) +} +#endif diff --git a/db/include/db_185.in b/db/include/db_185.in new file mode 100644 index 000000000..2aabce823 --- /dev/null +++ b/db/include/db_185.in @@ -0,0 +1,165 @@ +/*- + * See the file LICENSE for redistribution information. + * + * Copyright (c) 1996-2001 + * Sleepycat Software. All rights reserved. + */ +/* + * Copyright (c) 1990, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Id: db_185.in,v 11.6 2001/04/10 20:44:10 bostic Exp + */ + +#ifndef _DB_185_H_ +#define _DB_185_H_ + +#include <sys/types.h> + +#include <limits.h> + +/* + * XXX + * Handle function prototypes and the keyword "const". This steps on name + * space that DB doesn't control, but all of the other solutions are worse. + */ +#undef __P +#if defined(__STDC__) || defined(__cplusplus) +#define __P(protos) protos /* ANSI C prototypes */ +#else +#define const +#define __P(protos) () /* K&R C preprocessor */ +#endif + +#define RET_ERROR -1 /* Return values. */ +#define RET_SUCCESS 0 +#define RET_SPECIAL 1 + +#ifndef __BIT_TYPES_DEFINED__ +#define __BIT_TYPES_DEFINED__ +@u_int8_decl@ +@int16_decl@ +@u_int16_decl@ +@int32_decl@ +@u_int32_decl@ +#endif + +/* + * XXX + * SGI/IRIX already has a pgno_t. + */ +#ifdef sgi +#define pgno_t db_pgno_t +#endif + +#define MAX_PAGE_NUMBER 0xffffffff /* >= # of pages in a file */ +typedef u_int32_t pgno_t; +#define MAX_PAGE_OFFSET 65535 /* >= # of bytes in a page */ +typedef u_int16_t indx_t; +#define MAX_REC_NUMBER 0xffffffff /* >= # of records in a tree */ +typedef u_int32_t recno_t; + +/* Key/data structure -- a Data-Base Thang. */ +typedef struct { + void *data; /* data */ + size_t size; /* data length */ +} DBT; + +/* Routine flags. */ +#define R_CURSOR 1 /* del, put, seq */ +#define __R_UNUSED 2 /* UNUSED */ +#define R_FIRST 3 /* seq */ +#define R_IAFTER 4 /* put (RECNO) */ +#define R_IBEFORE 5 /* put (RECNO) */ +#define R_LAST 6 /* seq (BTREE, RECNO) */ +#define R_NEXT 7 /* seq */ +#define R_NOOVERWRITE 8 /* put */ +#define R_PREV 9 /* seq (BTREE, RECNO) */ +#define R_SETCURSOR 10 /* put (RECNO) */ +#define R_RECNOSYNC 11 /* sync (RECNO) */ + +typedef enum { DB_BTREE, DB_HASH, DB_RECNO } DBTYPE; + +/* Access method description structure. */ +typedef struct __db { + DBTYPE type; /* Underlying db type. */ + int (*close) __P((struct __db *)); + int (*del) __P((const struct __db *, const DBT *, u_int)); + int (*get) __P((const struct __db *, const DBT *, DBT *, u_int)); + int (*put) __P((const struct __db *, DBT *, const DBT *, u_int)); + int (*seq) __P((const struct __db *, DBT *, DBT *, u_int)); + int (*sync) __P((const struct __db *, u_int)); + void *internal; /* Access method private. */ + int (*fd) __P((const struct __db *)); +} DB; + +#define BTREEMAGIC 0x053162 +#define BTREEVERSION 3 + +/* Structure used to pass parameters to the btree routines. */ +typedef struct { +#define R_DUP 0x01 /* duplicate keys */ + u_int32_t flags; + u_int32_t cachesize; /* bytes to cache */ + u_int32_t maxkeypage; /* maximum keys per page */ + u_int32_t minkeypage; /* minimum keys per page */ + u_int32_t psize; /* page size */ + int (*compare) /* comparison function */ + __P((const DBT *, const DBT *)); + size_t (*prefix) /* prefix function */ + __P((const DBT *, const DBT *)); + int lorder; /* byte order */ +} BTREEINFO; + +#define HASHMAGIC 0x061561 +#define HASHVERSION 2 + +/* Structure used to pass parameters to the hashing routines. */ +typedef struct { + u_int32_t bsize; /* bucket size */ + u_int32_t ffactor; /* fill factor */ + u_int32_t nelem; /* number of elements */ + u_int32_t cachesize; /* bytes to cache */ + u_int32_t /* hash function */ + (*hash) __P((const void *, size_t)); + int lorder; /* byte order */ +} HASHINFO; + +/* Structure used to pass parameters to the record routines. */ +typedef struct { +#define R_FIXEDLEN 0x01 /* fixed-length records */ +#define R_NOKEY 0x02 /* key not required */ +#define R_SNAPSHOT 0x04 /* snapshot the input */ + u_int32_t flags; + u_int32_t cachesize; /* bytes to cache */ + u_int32_t psize; /* page size */ + int lorder; /* byte order */ + size_t reclen; /* record length (fixed-length records) */ + u_char bval; /* delimiting byte (variable-length records */ + char *bfname; /* btree file name */ +} RECNOINFO; + diff --git a/db/include/db_int.in b/db/include/db_int.in new file mode 100644 index 000000000..b556d6a0e --- /dev/null +++ b/db/include/db_int.in @@ -0,0 +1,442 @@ +/*- + * See the file LICENSE for redistribution information. + * + * Copyright (c) 1996-2001 + * Sleepycat Software. All rights reserved. + * + * Id: db_int.in,v 11.54 2001/04/27 15:49:47 bostic Exp + */ + +#ifndef _DB_INTERNAL_H_ +#define _DB_INTERNAL_H_ + +/******************************************************* + * General includes. + *******************************************************/ +#include "db.h" + +#ifndef NO_SYSTEM_INCLUDES +#if defined(__STDC__) || defined(__cplusplus) +#include <stdarg.h> +#else +#include <varargs.h> +#endif +#include <errno.h> +#endif + +#include "queue.h" +#include "shqueue.h" + +#if defined(__cplusplus) +extern "C" { +#endif + +/******************************************************* + * General purpose constants and macros. + *******************************************************/ +#define UINT16_T_MAX 0xffff /* Maximum 16 bit unsigned. */ +#define UINT32_T_MAX 0xffffffff /* Maximum 32 bit unsigned. */ + +#define MEGABYTE 1048576 +#define GIGABYTE 1073741824 + +#define MS_PER_SEC 1000 /* Milliseconds in a second. */ +#define USEC_PER_MS 1000 /* Microseconds in a millisecond. */ + +#define DB_MIN_PGSIZE 0x000200 /* Minimum page size (512). */ +#define DB_MAX_PGSIZE 0x010000 /* Maximum page size (65536). */ + +#define RECNO_OOB 0 /* Illegal record number. */ + +/* + * If we are unable to determine the underlying filesystem block size, use + * 8K on the grounds that most OS's use less than 8K for a VM page size. + */ +#define DB_DEF_IOSIZE (8 * 1024) + +/* + * Aligning items to particular sizes or in pages or memory. + * + * db_align_t -- + * Largest integral type, used to align structures in memory. We don't store + * floating point types in structures, so integral types should be sufficient + * (and we don't have to worry about systems that store floats in other than + * power-of-2 numbers of bytes). Additionally this fixes compiler that rewrite + * structure assignments and ANSI C memcpy calls to be in-line instructions + * that happen to require alignment. Note: this alignment isn't sufficient for + * mutexes, which depend on things like cache line alignment. Mutex alignment + * is handled separately, in mutex.h. + * + * db_alignp_t -- + * Integral type that's the same size as a pointer. There are places where + * DB modifies pointers by discarding the bottom bits to guarantee alignment. + * We can't use db_align_t, it may be larger than the pointer, and compilers + * get upset about that. So far we haven't run on any machine where there + * isn't an integral type the same size as a pointer -- here's hoping. + */ +@db_align_t_decl@ +@db_alignp_t_decl@ + +/* Align an integer to a specific boundary. */ +#undef ALIGN +#define ALIGN(value, bound) \ + (((value) + (bound) - 1) & ~(((u_int)bound) - 1)) + +/* Align a pointer to a specific boundary. */ +#undef ALIGNP +#define ALIGNP(value, bound) ALIGN((db_alignp_t)value, bound) + +/* + * There are several on-page structures that are declared to have a number of + * fields followed by a variable length array of items. The structure size + * without including the variable length array or the address of the first of + * those elements can be found using SSZ. + * + * This macro can also be used to find the offset of a structure element in a + * structure. This is used in various places to copy structure elements from + * unaligned memory references, e.g., pointers into a packed page. + * + * There are two versions because compilers object if you take the address of + * an array. + */ +#undef SSZ +#define SSZ(name, field) ((int)&(((name *)0)->field)) + +#undef SSZA +#define SSZA(name, field) ((int)&(((name *)0)->field[0])) + +/* + * Print an address as a u_long (a u_long is the largest type we can print + * portably). Most 64-bit systems have made longs 64-bits, so this should + * work. + */ +#define P_TO_ULONG(p) ((u_long)(db_alignp_t)(p)) + +/* Structure used to print flag values. */ +typedef struct __fn { + u_int32_t mask; /* Flag value. */ + const char *name; /* Flag name. */ +} FN; + +/* Set, clear and test flags. */ +#define FLD_CLR(fld, f) (fld) &= ~(f) +#define FLD_ISSET(fld, f) ((fld) & (f)) +#define FLD_SET(fld, f) (fld) |= (f) +#define F_CLR(p, f) (p)->flags &= ~(f) +#define F_ISSET(p, f) ((p)->flags & (f)) +#define F_SET(p, f) (p)->flags |= (f) +#define LF_CLR(f) (flags &= ~(f)) +#define LF_ISSET(f) (flags & (f)) +#define LF_SET(f) (flags |= (f)) + +/* Display separator string. */ +#undef DB_LINE +#define DB_LINE "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=" + +/* Unused, or not-used-yet variable. "Shut that bloody compiler up!" */ +#define COMPQUIET(n, v) (n) = (v) + +/******************************************************* + * Files. + *******************************************************/ + /* + * We use 1024 as the maximum path length. It's too hard to figure out what + * the real path length is, as it was traditionally stored in <sys/param.h>, + * and that file isn't always available. + */ +#undef MAXPATHLEN +#define MAXPATHLEN 1024 + +#define PATH_DOT "." /* Current working directory. */ +#define PATH_SEPARATOR "/" /* Path separator character. */ + +/* + * Flags understood by __os_open. + */ +#define DB_OSO_CREATE 0x001 /* POSIX: O_CREAT */ +#define DB_OSO_EXCL 0x002 /* POSIX: O_EXCL */ +#define DB_OSO_LOG 0x004 /* Opening a log file. */ +#define DB_OSO_RDONLY 0x008 /* POSIX: O_RDONLY */ +#define DB_OSO_REGION 0x010 /* Opening a region file. */ +#define DB_OSO_SEQ 0x020 /* Expected sequential access. */ +#define DB_OSO_TEMP 0x040 /* Remove after last close. */ +#define DB_OSO_TRUNC 0x080 /* POSIX: O_TRUNC */ + +/* + * Seek options understood by __os_seek. + */ +typedef enum { + DB_OS_SEEK_CUR, /* POSIX: SEEK_CUR */ + DB_OS_SEEK_END, /* POSIX: SEEK_END */ + DB_OS_SEEK_SET /* POSIX: SEEK_SET */ +} DB_OS_SEEK; + +/******************************************************* + * Environment. + *******************************************************/ +/* Type passed to __db_appname(). */ +typedef enum { + DB_APP_NONE=0, /* No type (region). */ + DB_APP_DATA, /* Data file. */ + DB_APP_LOG, /* Log file. */ + DB_APP_TMP /* Temporary file. */ +} APPNAME; + +/* + * CDB_LOCKING CDB product locking. + * LOCKING_ON Locking has been configured. + * LOGGING_ON Logging has been configured. + * MPOOL_ON Memory pool has been configured. + * TXN_ON Transactions have been configured. + */ +#define CDB_LOCKING(dbenv) F_ISSET(dbenv, DB_ENV_CDB) +#define LOCKING_ON(dbenv) ((dbenv)->lk_handle != NULL) +#define LOGGING_ON(dbenv) ((dbenv)->lg_handle != NULL) +#define MPOOL_ON(dbenv) ((dbenv)->mp_handle != NULL) +#define TXN_ON(dbenv) ((dbenv)->tx_handle != NULL) + +/* + * STD_LOCKING Standard locking, that is, locking was configured and CDB + * was not. We do not do locking in off-page duplicate trees, + * so we check for that in the cursor first. + */ +#define STD_LOCKING(dbc) \ + (!F_ISSET(dbc, DBC_OPD) && \ + !CDB_LOCKING((dbc)->dbp->dbenv) && LOCKING_ON((dbc)->dbp->dbenv)) + +/* + * IS_RECOVERING The system is running recovery. + */ +#define IS_RECOVERING(dbenv) \ + (LOGGING_ON(dbenv) && \ + F_ISSET((DB_LOG *)(dbenv)->lg_handle, DBLOG_RECOVER)) + +/* Most initialization methods cannot be called after open is called. */ +#define ENV_ILLEGAL_AFTER_OPEN(dbenv, name) \ + if (F_ISSET((dbenv), DB_ENV_OPEN_CALLED)) \ + return (__db_mi_open(dbenv, name, 1)); + +/* We're not actually user hostile, honest. */ +#define ENV_REQUIRES_CONFIG(dbenv, handle, i, flags) \ + if (handle == NULL) \ + return (__db_env_config(dbenv, i, flags)); + +/******************************************************* + * Database Access Methods. + *******************************************************/ +/* + * DB_IS_THREADED -- + * The database handle is free-threaded (was opened with DB_THREAD). + */ +#define DB_IS_THREADED(dbp) \ + ((dbp)->mutexp != NULL) + +/* Initialization methods are often illegal before/after open is called. */ +#define DB_ILLEGAL_AFTER_OPEN(dbp, name) \ + if (F_ISSET((dbp), DB_OPEN_CALLED)) \ + return (__db_mi_open(dbp->dbenv, name, 1)); +#define DB_ILLEGAL_BEFORE_OPEN(dbp, name) \ + if (!F_ISSET((dbp), DB_OPEN_CALLED)) \ + return (__db_mi_open(dbp->dbenv, name, 0)); +/* Some initialization methods are illegal if environment isn't local. */ +#define DB_ILLEGAL_IN_ENV(dbp, name) \ + if (!F_ISSET(dbp->dbenv, DB_ENV_DBLOCAL)) \ + return (__db_mi_env(dbp->dbenv, name)); +#define DB_ILLEGAL_METHOD(dbp, flags) { \ + int __ret; \ + if ((__ret = __dbh_am_chk(dbp, flags)) != 0) \ + return (__ret); \ +} + +/* + * Common DBC->internal fields. Each access method adds additional fields + * to this list, but the initial fields are common. + */ +#define __DBC_INTERNAL \ + DBC *opd; /* Off-page duplicate cursor. */\ + \ + void *page; /* Referenced page. */ \ + db_pgno_t root; /* Tree root. */ \ + db_pgno_t pgno; /* Referenced page number. */ \ + db_indx_t indx; /* Referenced key item index. */\ + \ + DB_LOCK lock; /* Cursor lock. */ \ + db_lockmode_t lock_mode; /* Lock mode. */ + +struct __dbc_internal { + __DBC_INTERNAL +}; + +/* + * Access-method-common macro for determining whether a cursor + * has been initialized. + */ +#define IS_INITIALIZED(dbc) ((dbc)->internal->pgno != PGNO_INVALID) + +/* Free the callback-allocated buffer, if necessary, hanging off of a DBT. */ +#define FREE_IF_NEEDED(sdbp, dbt) \ + if (F_ISSET((dbt), DB_DBT_APPMALLOC)) { \ + __os_ufree((sdbp)->dbenv, (dbt)->data, 0); \ + F_CLR((dbt), DB_DBT_APPMALLOC); \ + } + +/* + * Use memory belonging to object "owner" to return the results of + * any no-DBT-flag get ops on cursor "dbc". + */ +#define SET_RET_MEM(dbc, owner) \ + do { \ + (dbc)->rskey = &(owner)->my_rskey; \ + (dbc)->rkey = &(owner)->my_rkey; \ + (dbc)->rdata = &(owner)->my_rdata; \ + } while (0) + +/* Use the return-data memory src is currently set to use in dest as well. */ +#define COPY_RET_MEM(src, dest) \ + do { \ + (dest)->rskey = (src)->rskey; \ + (dest)->rkey = (src)->rkey; \ + (dest)->rdata = (src)->rdata; \ + } while (0) + +/* Reset the returned-memory pointers to their defaults. */ +#define RESET_RET_MEM(dbc) \ + do { \ + (dbc)->rskey = &(dbc)->my_rskey; \ + (dbc)->rkey = &(dbc)->my_rkey; \ + (dbc)->rdata = &(dbc)->my_rdata; \ + } while (0) + +/******************************************************* + * Mpool. + *******************************************************/ +/* + * File types for DB access methods. Negative numbers are reserved to DB. + */ +#define DB_FTYPE_SET -1 /* Call pgin/pgout functions. */ +#define DB_FTYPE_NOTSET 0 /* Don't call... */ + +/* Structure used as the DB pgin/pgout pgcookie. */ +typedef struct __dbpginfo { + size_t db_pagesize; /* Underlying page size. */ + int needswap; /* If swapping required. */ +} DB_PGINFO; + +/******************************************************* + * Log. + *******************************************************/ +/* Initialize an LSN to 'zero'. */ +#define ZERO_LSN(LSN) do { \ + (LSN).file = 0; \ + (LSN).offset = 0; \ +} while (0) + +#define MAX_LSN(LSN) do { \ + (LSN).file = UINT32_T_MAX; \ + (LSN).offset = UINT32_T_MAX; \ +} while (0) + +/* If logging is turned off, smash the lsn. */ +#define LSN_NOT_LOGGED(LSN) do { \ + (LSN).file = 0; \ + (LSN).offset = 1; \ +} while (0) + +/* Return 1 if LSN is a 'zero' lsn, otherwise return 0. */ +#define IS_ZERO_LSN(LSN) ((LSN).file == 0) +#define IS_MAX_LSN(LSN) \ + ((LSN).file == UINT32_T_MAX && (LSN).file == UINT32_T_MAX) + +/* Test if we need to log a change. */ +#define DB_LOGGING(dbc) \ + (LOGGING_ON((dbc)->dbp->dbenv) && !F_ISSET(dbc, DBC_RECOVER)) + +/******************************************************* + * Txn. + *******************************************************/ +#define DB_NONBLOCK(C) ((C)->txn != NULL && F_ISSET((C)->txn, TXN_NOWAIT)) +#define IS_SUBTRANSACTION(txn) \ + ((txn) != NULL && (txn)->parent != NULL) + +/******************************************************* + * Global variables. + *******************************************************/ +#ifdef HAVE_VXWORKS +#include "semLib.h" +#endif + +/* + * DB global variables. Done in a single structure to minimize the name-space + * pollution. + */ +typedef struct __db_globals { + u_int32_t db_pageyield; /* db_set_pageyield */ + u_int32_t db_panic; /* db_set_panic */ + u_int32_t db_region_init; /* db_set_region_init */ + u_int32_t db_tas_spins; /* db_set_tas_spins */ +#ifdef HAVE_VXWORKS + u_int32_t db_global_init; /* VxWorks: inited */ + SEM_ID db_global_lock; /* VxWorks: global semaphore */ +#endif + /* XA: list of opened environments. */ + TAILQ_HEAD(__db_envq, __db_env) db_envq; +} DB_GLOBALS; + +#ifdef DB_INITIALIZE_DB_GLOBALS +DB_GLOBALS __db_global_values = { + 0, /* db_set_pageyield */ + 1, /* db_set_panic */ + 0, /* db_set_region_init */ + 0, /* db_set_tas_spins */ +#ifdef HAVE_VXWORKS + 0, /* db_global_init */ + NULL, /* db_global_lock */ +#endif + /* XA environment queue */ + {NULL, &__db_global_values.db_envq.tqh_first} +}; +#else +extern DB_GLOBALS __db_global_values; +#endif +#define DB_GLOBAL(v) __db_global_values.v + +/* Forward structure declarations. */ +struct __db_reginfo_t; typedef struct __db_reginfo_t REGINFO; +struct __mutex_t; typedef struct __mutex_t MUTEX; +struct __vrfy_childinfo; typedef struct __vrfy_childinfo VRFY_CHILDINFO; +struct __vrfy_dbinfo; typedef struct __vrfy_dbinfo VRFY_DBINFO; +struct __vrfy_pageinfo; typedef struct __vrfy_pageinfo VRFY_PAGEINFO; +struct __db_txnlist; typedef struct __db_txnlist DB_TXNLIST; +struct __db_txnhead; typedef struct __db_txnhead DB_TXNHEAD; +typedef enum { + TXNLIST_DELETE, + TXNLIST_LSN, + TXNLIST_TXNID, + TXNLIST_PGNO +} db_txnlist_type; + +/* + * Currently, region offsets are limited to 32-bits. I expect that's going + * to have to be fixed in the not-too-distant future, since we won't want to + * split 100Gb memory pools into that many different regions. It's typedef'd + * so it won't be too painful to upgrade. + */ +typedef u_int32_t roff_t; + +#if defined(__cplusplus) +} +#endif + +/******************************************************* + * More general includes. + *******************************************************/ +#include "debug.h" +#include "mutex.h" +#include "region.h" +#include "mutex_ext.h" +#include "env_ext.h" +#include "os.h" +#include "os_ext.h" +#include "common_ext.h" + +#endif /* !_DB_INTERNAL_H_ */ |