source: trunk/third/evolution-data-server/libdb/build_win32/db_int.h @ 21189

Revision 21189, 16.3 KB checked in by ghudson, 20 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r21188, which included commits to RCS files with non-trunk default branches.
Line 
1/* DO NOT EDIT: automatically built by dist/s_win32. */
2/*-
3 * See the file LICENSE for redistribution information.
4 *
5 * Copyright (c) 1996-2002
6 *      Sleepycat Software.  All rights reserved.
7 *
8 * $Id: db_int.h,v 1.1.1.1 2004-12-17 17:26:48 ghudson Exp $
9 */
10
11#ifndef _DB_INTERNAL_H_
12#define _DB_INTERNAL_H_
13
14/*******************************************************
15 * System includes, db.h, a few general DB includes.  The DB includes are
16 * here because it's OK if db_int.h includes queue structure declarations.
17 *******************************************************/
18#ifndef NO_SYSTEM_INCLUDES
19#if defined(__STDC__) || defined(__cplusplus)
20#include <stdarg.h>
21#else
22#include <varargs.h>
23#endif
24#include <errno.h>
25#endif
26
27#include "db.h"
28
29#include "dbinc/queue.h"
30#include "dbinc/shqueue.h"
31
32#if defined(__cplusplus)
33extern "C" {
34#endif
35
36/*******************************************************
37 * General purpose constants and macros.
38 *******************************************************/
39#define UINT16_T_MAX        0xffff      /* Maximum 16 bit unsigned. */
40#define UINT32_T_MAX    0xffffffff      /* Maximum 32 bit unsigned. */
41
42#define MEGABYTE        1048576
43#define GIGABYTE        1073741824
44
45#define MS_PER_SEC      1000            /* Milliseconds in a second. */
46#define USEC_PER_MS     1000            /* Microseconds in a millisecond. */
47
48#define RECNO_OOB       0               /* Illegal record number. */
49
50/* Test for a power-of-two (tests true for zero, which doesn't matter here). */
51#define POWER_OF_TWO(x) (((x) & ((x) - 1)) == 0)
52
53/* Test for valid page sizes. */
54#define DB_MIN_PGSIZE   0x000200        /* Minimum page size (512). */
55#define DB_MAX_PGSIZE   0x010000        /* Maximum page size (65536). */
56#define IS_VALID_PAGESIZE(x)                                            \
57        (POWER_OF_TWO(x) && (x) >= DB_MIN_PGSIZE && ((x) <= DB_MAX_PGSIZE))
58
59/* Minimum number of pages cached, by default. */
60#define DB_MINPAGECACHE 16
61
62/*
63 * If we are unable to determine the underlying filesystem block size, use
64 * 8K on the grounds that most OS's use less than 8K for a VM page size.
65 */
66#define DB_DEF_IOSIZE   (8 * 1024)
67
68/*
69 * Aligning items to particular sizes or in pages or memory.
70 *
71 * db_align_t --
72 * Largest integral type, used to align structures in memory.  We don't store
73 * floating point types in structures, so integral types should be sufficient
74 * (and we don't have to worry about systems that store floats in other than
75 * power-of-2 numbers of bytes).  Additionally this fixes compiler that rewrite
76 * structure assignments and ANSI C memcpy calls to be in-line instructions
77 * that happen to require alignment.  Note: this alignment isn't sufficient for
78 * mutexes, which depend on things like cache line alignment.  Mutex alignment
79 * is handled separately, in mutex.h.
80 *
81 * db_alignp_t --
82 * Integral type that's the same size as a pointer.  There are places where
83 * DB modifies pointers by discarding the bottom bits to guarantee alignment.
84 * We can't use db_align_t, it may be larger than the pointer, and compilers
85 * get upset about that.  So far we haven't run on any machine where there
86 * isn't an integral type the same size as a pointer -- here's hoping.
87 */
88typedef unsigned long db_align_t;
89typedef unsigned long db_alignp_t;
90
91/* Align an integer to a specific boundary. */
92#undef  ALIGN
93#define ALIGN(v, bound) (((v) + (bound) - 1) & ~(((db_align_t)bound) - 1))
94
95/*
96 * Print an address as a u_long (a u_long is the largest type we can print
97 * portably).  Most 64-bit systems have made longs 64-bits, so this should
98 * work.
99 */
100#define P_TO_ULONG(p)   ((u_long)(db_alignp_t)(p))
101
102/*
103 * Convert a pointer to a small integral value.
104 *
105 * The (u_int16_t)(db_alignp_t) cast avoids warnings: the (db_alignp_t) cast
106 * converts the value to an integral type, and the (u_int16_t) cast converts
107 * it to a small integral type so we don't get complaints when we assign the
108 * final result to an integral type smaller than db_alignp_t.
109 */
110#define P_TO_UINT32(p)  ((u_int32_t)(db_alignp_t)(p))
111#define P_TO_UINT16(p)  ((u_int16_t)(db_alignp_t)(p))
112
113/*
114 * There are several on-page structures that are declared to have a number of
115 * fields followed by a variable length array of items.  The structure size
116 * without including the variable length array or the address of the first of
117 * those elements can be found using SSZ.
118 *
119 * This macro can also be used to find the offset of a structure element in a
120 * structure.  This is used in various places to copy structure elements from
121 * unaligned memory references, e.g., pointers into a packed page.
122 *
123 * There are two versions because compilers object if you take the address of
124 * an array.
125 */
126#undef  SSZ
127#define SSZ(name, field)  P_TO_UINT16(&(((name *)0)->field))
128
129#undef  SSZA
130#define SSZA(name, field) P_TO_UINT16(&(((name *)0)->field[0]))
131
132/* Structure used to print flag values. */
133typedef struct __fn {
134        u_int32_t mask;                 /* Flag value. */
135        const char *name;               /* Flag name. */
136} FN;
137
138/* Set, clear and test flags. */
139#define FLD_CLR(fld, f)         (fld) &= ~(f)
140#define FLD_ISSET(fld, f)       ((fld) & (f))
141#define FLD_SET(fld, f)         (fld) |= (f)
142#define F_CLR(p, f)             (p)->flags &= ~(f)
143#define F_ISSET(p, f)           ((p)->flags & (f))
144#define F_SET(p, f)             (p)->flags |= (f)
145#define LF_CLR(f)               ((flags) &= ~(f))
146#define LF_ISSET(f)             ((flags) & (f))
147#define LF_SET(f)               ((flags) |= (f))
148
149/* Display separator string. */
150#undef  DB_LINE
151#define DB_LINE "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="
152
153/* Unused, or not-used-yet variable.  "Shut that bloody compiler up!" */
154#define COMPQUIET(n, v) (n) = (v)
155
156/*******************************************************
157 * API return values
158 *******************************************************/
159 /*
160  * Return values that are OK for each different call.  Most calls have
161  * a standard 'return of 0 is only OK value', but some, like db->get
162  * have DB_NOTFOUND as a return value, but it really isn't an error.
163  */
164#define DB_RETOK_STD(ret)       ((ret) == 0)
165#define DB_RETOK_DBCDEL(ret)    ((ret) == 0 || (ret) == DB_KEYEMPTY || \
166                                    (ret) == DB_NOTFOUND)
167#define DB_RETOK_DBCGET(ret)    DB_RETOK_DBGET(ret)
168#define DB_RETOK_DBCPUT(ret)    ((ret) == 0 || (ret) == DB_KEYEXIST || \
169                                    (ret) == DB_NOTFOUND)
170#define DB_RETOK_DBDEL(ret)     ((ret) == 0 || (ret) == DB_NOTFOUND)
171#define DB_RETOK_DBGET(ret)     ((ret) == 0 || (ret) == DB_KEYEMPTY || \
172                                    (ret) == DB_NOTFOUND)
173#define DB_RETOK_DBPUT(ret)     ((ret) == 0 || (ret) == DB_KEYEXIST)
174#define DB_RETOK_LGGET(ret)     ((ret) == 0 || (ret) == DB_NOTFOUND)
175#define DB_RETOK_MPGET(ret)     ((ret) == 0 || (ret) == DB_PAGE_NOTFOUND)
176#define DB_RETOK_REPPMSG(ret)   ((ret) == 0 || (ret) == DB_REP_NEWMASTER || \
177                                    (ret) == DB_REP_NEWSITE)
178
179/*******************************************************
180 * Files.
181 *******************************************************/
182 /*
183  * We use 1024 as the maximum path length.  It's too hard to figure out what
184  * the real path length is, as it was traditionally stored in <sys/param.h>,
185  * and that file isn't always available.
186  */
187#undef  MAXPATHLEN
188#define MAXPATHLEN      1024
189
190#define PATH_DOT        "."     /* Current working directory. */
191#define PATH_SEPARATOR  "\\/:"  /* Path separator character(s). */
192
193/*
194 * Flags understood by __os_open.
195 */
196#define DB_OSO_CREATE   0x0001          /* POSIX: O_CREAT */
197#define DB_OSO_DIRECT   0x0002          /* Don't buffer the file in the OS. */
198#define DB_OSO_EXCL     0x0004          /* POSIX: O_EXCL */
199#define DB_OSO_LOG      0x0008          /* Opening a log file. */
200#define DB_OSO_RDONLY   0x0010          /* POSIX: O_RDONLY */
201#define DB_OSO_REGION   0x0020          /* Opening a region file. */
202#define DB_OSO_SEQ      0x0040          /* Expected sequential access. */
203#define DB_OSO_TEMP     0x0080          /* Remove after last close. */
204#define DB_OSO_TRUNC    0x0100          /* POSIX: O_TRUNC */
205
206/*
207 * Seek options understood by __os_seek.
208 */
209typedef enum {
210        DB_OS_SEEK_CUR,                 /* POSIX: SEEK_CUR */
211        DB_OS_SEEK_END,                 /* POSIX: SEEK_END */
212        DB_OS_SEEK_SET                  /* POSIX: SEEK_SET */
213} DB_OS_SEEK;
214
215/*******************************************************
216 * Environment.
217 *******************************************************/
218/* Type passed to __db_appname(). */
219typedef enum {
220        DB_APP_NONE=0,                  /* No type (region). */
221        DB_APP_DATA,                    /* Data file. */
222        DB_APP_LOG,                     /* Log file. */
223        DB_APP_TMP                      /* Temporary file. */
224} APPNAME;
225
226/*
227 * CDB_LOCKING  CDB product locking.
228 * CRYPTO_ON    Security has been configured.
229 * LOCKING_ON   Locking has been configured.
230 * LOGGING_ON   Logging has been configured.
231 * MPOOL_ON     Memory pool has been configured.
232 * RPC_ON       RPC has been configured.
233 * TXN_ON       Transactions have been configured.
234 */
235#define CDB_LOCKING(dbenv)      F_ISSET(dbenv, DB_ENV_CDB)
236#define CRYPTO_ON(dbenv)        ((dbenv)->crypto_handle != NULL)
237#define LOCKING_ON(dbenv)       ((dbenv)->lk_handle != NULL)
238#define LOGGING_ON(dbenv)       ((dbenv)->lg_handle != NULL)
239#define MPOOL_ON(dbenv)         ((dbenv)->mp_handle != NULL)
240#define RPC_ON(dbenv)           ((dbenv)->cl_handle != NULL)
241#define TXN_ON(dbenv)           ((dbenv)->tx_handle != NULL)
242
243/*
244 * STD_LOCKING  Standard locking, that is, locking was configured and CDB
245 *              was not.  We do not do locking in off-page duplicate trees,
246 *              so we check for that in the cursor first.
247 */
248#define STD_LOCKING(dbc)                                                \
249        (!F_ISSET(dbc, DBC_OPD) &&                                      \
250            !CDB_LOCKING((dbc)->dbp->dbenv) && LOCKING_ON((dbc)->dbp->dbenv))
251
252/*
253 * IS_RECOVERING: The system is running recovery.
254 */
255#define IS_RECOVERING(dbenv)                                            \
256        (LOGGING_ON(dbenv) &&                                           \
257            F_ISSET((DB_LOG *)(dbenv)->lg_handle, DBLOG_RECOVER))
258
259/* Initialization methods are often illegal before/after open is called. */
260#define ENV_ILLEGAL_AFTER_OPEN(dbenv, name)                             \
261        if (F_ISSET((dbenv), DB_ENV_OPEN_CALLED))                       \
262                return (__db_mi_open(dbenv, name, 1));
263#define ENV_ILLEGAL_BEFORE_OPEN(dbenv, name)                            \
264        if (!F_ISSET((dbenv), DB_ENV_OPEN_CALLED))                      \
265                return (__db_mi_open(dbenv, name, 0));
266
267/* We're not actually user hostile, honest. */
268#define ENV_REQUIRES_CONFIG(dbenv, handle, i, flags)                    \
269        if (handle == NULL)                                             \
270                return (__db_env_config(dbenv, i, flags));
271
272/*******************************************************
273 * Database Access Methods.
274 *******************************************************/
275/*
276 * DB_IS_THREADED --
277 *      The database handle is free-threaded (was opened with DB_THREAD).
278 */
279#define DB_IS_THREADED(dbp)                                             \
280        ((dbp)->mutexp != NULL)
281
282/* Initialization methods are often illegal before/after open is called. */
283#define DB_ILLEGAL_AFTER_OPEN(dbp, name)                                \
284        if (F_ISSET((dbp), DB_AM_OPEN_CALLED))                          \
285                return (__db_mi_open((dbp)->dbenv, name, 1));
286#define DB_ILLEGAL_BEFORE_OPEN(dbp, name)                               \
287        if (!F_ISSET((dbp), DB_AM_OPEN_CALLED))                         \
288                return (__db_mi_open((dbp)->dbenv, name, 0));
289/* Some initialization methods are illegal if environment isn't local. */
290#define DB_ILLEGAL_IN_ENV(dbp, name)                                    \
291        if (!F_ISSET((dbp)->dbenv, DB_ENV_DBLOCAL))                     \
292                return (__db_mi_env((dbp)->dbenv, name));
293#define DB_ILLEGAL_METHOD(dbp, flags) {                                 \
294        int __ret;                                                      \
295        if ((__ret = __dbh_am_chk(dbp, flags)) != 0)                    \
296                return (__ret);                                         \
297}
298
299/*
300 * Common DBC->internal fields.  Each access method adds additional fields
301 * to this list, but the initial fields are common.
302 */
303#define __DBC_INTERNAL                                                  \
304        DBC      *opd;                  /* Off-page duplicate cursor. */\
305                                                                        \
306        void     *page;                 /* Referenced page. */          \
307        db_pgno_t root;                 /* Tree root. */                \
308        db_pgno_t pgno;                 /* Referenced page number. */   \
309        db_indx_t indx;                 /* Referenced key item index. */\
310                                                                        \
311        DB_LOCK         lock;           /* Cursor lock. */              \
312        db_lockmode_t   lock_mode;      /* Lock mode. */
313
314struct __dbc_internal {
315        __DBC_INTERNAL
316};
317
318/* Actions that __db_master_update can take. */
319typedef enum { MU_REMOVE, MU_RENAME, MU_OPEN } mu_action;
320
321/*
322 * Access-method-common macro for determining whether a cursor
323 * has been initialized.
324 */
325#define IS_INITIALIZED(dbc)     ((dbc)->internal->pgno != PGNO_INVALID)
326
327/* Free the callback-allocated buffer, if necessary, hanging off of a DBT. */
328#define FREE_IF_NEEDED(sdbp, dbt)                                       \
329        if (F_ISSET((dbt), DB_DBT_APPMALLOC)) {                         \
330                __os_ufree((sdbp)->dbenv, (dbt)->data);                 \
331                F_CLR((dbt), DB_DBT_APPMALLOC);                         \
332        }
333
334/*
335 * Use memory belonging to object "owner" to return the results of
336 * any no-DBT-flag get ops on cursor "dbc".
337 */
338#define SET_RET_MEM(dbc, owner)                         \
339        do {                                            \
340                (dbc)->rskey = &(owner)->my_rskey;      \
341                (dbc)->rkey = &(owner)->my_rkey;        \
342                (dbc)->rdata = &(owner)->my_rdata;      \
343        } while (0)
344
345/* Use the return-data memory src is currently set to use in dest as well. */
346#define COPY_RET_MEM(src, dest)                         \
347        do {                                            \
348                (dest)->rskey = (src)->rskey;           \
349                (dest)->rkey = (src)->rkey;             \
350                (dest)->rdata = (src)->rdata;           \
351        } while (0)
352
353/* Reset the returned-memory pointers to their defaults. */
354#define RESET_RET_MEM(dbc)                              \
355        do {                                            \
356                (dbc)->rskey = &(dbc)->my_rskey;        \
357                (dbc)->rkey = &(dbc)->my_rkey;          \
358                (dbc)->rdata = &(dbc)->my_rdata;        \
359        } while (0)
360
361/*******************************************************
362 * Mpool.
363 *******************************************************/
364/*
365 * File types for DB access methods.  Negative numbers are reserved to DB.
366 */
367#define DB_FTYPE_SET            -1      /* Call pgin/pgout functions. */
368#define DB_FTYPE_NOTSET          0      /* Don't call... */
369
370/* Structure used as the DB pgin/pgout pgcookie. */
371typedef struct __dbpginfo {
372        size_t  db_pagesize;            /* Underlying page size. */
373        u_int32_t flags;                /* Some DB_AM flags needed. */
374        DBTYPE  type;                   /* DB type */
375} DB_PGINFO;
376
377/*******************************************************
378 * Log.
379 *******************************************************/
380/* Initialize an LSN to 'zero'. */
381#define ZERO_LSN(LSN) do {                                              \
382        (LSN).file = 0;                                                 \
383        (LSN).offset = 0;                                               \
384} while (0)
385#define IS_ZERO_LSN(LSN)        ((LSN).file == 0)
386
387#define IS_INIT_LSN(LSN)        ((LSN).file == 1 && (LSN).offset == 0)
388#define INIT_LSN(LSN)           do {                                    \
389        (LSN).file = 1;                                                 \
390        (LSN).offset = 0;                                               \
391} while (0)
392
393#define MAX_LSN(LSN) do {                                               \
394        (LSN).file = UINT32_T_MAX;                                      \
395        (LSN).offset = UINT32_T_MAX;                                    \
396} while (0)
397#define IS_MAX_LSN(LSN) \
398        ((LSN).file == UINT32_T_MAX && (LSN).offset == UINT32_T_MAX)
399
400/* If logging is turned off, smash the lsn. */
401#define LSN_NOT_LOGGED(LSN) do {                                        \
402        (LSN).file = 0;                                                 \
403        (LSN).offset = 1;                                               \
404} while (0)
405#define IS_NOT_LOGGED_LSN(LSN) \
406        ((LSN).file == 0 && (LSN).offset == 1)
407
408/*
409 * Test if the environment is currently logging changes.  If we're in
410 * recovery or we're a replication client, we don't need to log changes
411 * because they're already in the log, even though we have a fully functional
412 * log system.
413 */
414#define DBENV_LOGGING(dbenv)                                            \
415        (LOGGING_ON(dbenv) && !F_ISSET((dbenv), DB_ENV_REP_CLIENT) &&   \
416            (!IS_RECOVERING(dbenv)))
417
418/*
419 * Test if we need to log a change.  Note that the DBC_RECOVER flag is set
420 * when we're in abort, as well as during recovery;  thus DBC_LOGGING may be
421 * false for a particular dbc even when DBENV_LOGGING is true.
422 *
423 * We explicitly use LOGGING_ON/DB_ENV_REP_CLIENT here because we don't
424 * want to have to pull in the log headers, which IS_RECOVERING (and thus
425 * DBENV_LOGGING) rely on, and because DBC_RECOVER should be set anytime
426 * IS_RECOVERING would be true.
427 */
428#define DBC_LOGGING(dbc)                                                \
429        (LOGGING_ON((dbc)->dbp->dbenv) && !F_ISSET((dbc), DBC_RECOVER) && \
430         !F_ISSET((dbc)->dbp->dbenv, DB_ENV_REP_CLIENT))
431
432/*******************************************************
433 * Txn.
434 *******************************************************/
435#define DB_NONBLOCK(C)  ((C)->txn != NULL && F_ISSET((C)->txn, TXN_NOWAIT))
436#define IS_SUBTRANSACTION(txn)                                          \
437        ((txn) != NULL && (txn)->parent != NULL)
438
439/*******************************************************
440 * Crypto.
441 *******************************************************/
442#define DB_IV_BYTES     16              /* Bytes per IV */
443#define DB_MAC_KEY      20              /* Bytes per MAC checksum */
444
445/*******************************************************
446 * Forward structure declarations.
447 *******************************************************/
448struct __db_reginfo_t;  typedef struct __db_reginfo_t REGINFO;
449struct __db_txnhead;    typedef struct __db_txnhead DB_TXNHEAD;
450struct __db_txnlist;    typedef struct __db_txnlist DB_TXNLIST;
451struct __vrfy_childinfo; typedef struct __vrfy_childinfo VRFY_CHILDINFO;
452struct __vrfy_dbinfo;   typedef struct __vrfy_dbinfo VRFY_DBINFO;
453struct __vrfy_pageinfo; typedef struct __vrfy_pageinfo VRFY_PAGEINFO;
454
455#if defined(__cplusplus)
456}
457#endif
458
459/*******************************************************
460 * Remaining general DB includes.
461 *******************************************************/
462
463
464#include "dbinc/globals.h"
465#include "dbinc/debug.h"
466#include "dbinc/mutex.h"
467#include "dbinc/region.h"
468#include "dbinc_auto/mutex_ext.h"       /* XXX: Include after region.h. */
469#include "dbinc_auto/env_ext.h"
470#include "dbinc/os.h"
471#include "dbinc_auto/clib_ext.h"
472#include "dbinc_auto/common_ext.h"
473
474#endif /* !_DB_INTERNAL_H_ */
Note: See TracBrowser for help on using the repository browser.