~ubuntu-branches/ubuntu/maverick/evolution-data-server/maverick-proposed

« back to all changes in this revision

Viewing changes to libdb/db/db_method.c

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2010-05-17 17:02:06 UTC
  • mfrom: (1.1.79 upstream) (1.6.12 experimental)
  • Revision ID: james.westby@ubuntu.com-20100517170206-4ufr52vwrhh26yh0
Tags: 2.30.1-1ubuntu1
* Merge from debian experimental. Remaining change:
  (LP: #42199, #229669, #173703, #360344, #508494)
  + debian/control:
    - add Vcs-Bzr tag
    - don't use libgnome
    - Use Breaks instead of Conflicts against evolution 2.25 and earlier.
  + debian/evolution-data-server.install,
    debian/patches/45_libcamel_providers_version.patch:
    - use the upstream versioning, not a Debian-specific one 
  + debian/libedata-book1.2-dev.install, debian/libebackend-1.2-dev.install,
    debian/libcamel1.2-dev.install, debian/libedataserverui1.2-dev.install:
    - install html documentation
  + debian/rules:
    - don't build documentation it's shipped with the tarball

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*-
2
 
 * See the file LICENSE for redistribution information.
3
 
 *
4
 
 * Copyright (c) 1999-2002
5
 
 *      Sleepycat Software.  All rights reserved.
6
 
 */
7
 
 
8
 
#include "db_config.h"
9
 
 
10
 
#ifndef lint
11
 
static const char revid[] = "$Id$";
12
 
#endif /* not lint */
13
 
 
14
 
#ifndef NO_SYSTEM_INCLUDES
15
 
#include <sys/types.h>
16
 
 
17
 
#ifdef HAVE_RPC
18
 
#include <rpc/rpc.h>
19
 
#endif
20
 
 
21
 
#include <string.h>
22
 
#endif
23
 
 
24
 
#include "db_int.h"
25
 
#include "dbinc/crypto.h"
26
 
#include "dbinc/db_page.h"
27
 
#include "dbinc/db_shash.h"
28
 
#include "dbinc/btree.h"
29
 
#include "dbinc/hash.h"
30
 
#include "dbinc/qam.h"
31
 
#include "dbinc/xa.h"
32
 
#include "dbinc_auto/xa_ext.h"
33
 
#include "dbinc/db_shash.h"
34
 
#include "dbinc/lock.h"
35
 
 
36
 
#ifdef HAVE_RPC
37
 
#include "dbinc_auto/db_server.h"
38
 
#include "dbinc_auto/rpc_client_ext.h"
39
 
#endif
40
 
 
41
 
static int  __db_get_byteswapped __P((DB *, int *));
42
 
static int  __db_get_type __P((DB *, DBTYPE *dbtype));
43
 
static int  __db_init __P((DB *, u_int32_t));
44
 
static int  __db_key_range
45
 
                __P((DB *, DB_TXN *, DBT *, DB_KEY_RANGE *, u_int32_t));
46
 
static int  __db_set_alloc __P((DB *, void *(*)(size_t),
47
 
                void *(*)(void *, size_t), void (*)(void *)));
48
 
static int  __db_set_append_recno __P((DB *, int (*)(DB *, DBT *, db_recno_t)));
49
 
static int  __db_set_cachesize __P((DB *, u_int32_t, u_int32_t, int));
50
 
static int  __db_set_cache_priority __P((DB *, DB_CACHE_PRIORITY));
51
 
static int  __db_set_dup_compare
52
 
                __P((DB *, int (*)(DB *, const DBT *, const DBT *)));
53
 
static int  __db_set_encrypt __P((DB *, const char *, u_int32_t));
54
 
static int  __db_set_feedback __P((DB *, void (*)(DB *, int, int)));
55
 
static int  __db_set_flags __P((DB *, u_int32_t));
56
 
static int  __db_set_pagesize __P((DB *, u_int32_t));
57
 
static int  __db_set_paniccall __P((DB *, void (*)(DB_ENV *, int)));
58
 
static void __db_set_errcall __P((DB *, void (*)(const char *, char *)));
59
 
static void __db_set_errfile __P((DB *, FILE *));
60
 
static void __db_set_errpfx __P((DB *, const char *));
61
 
static int  __db_stat_fail __P((DB *, void *, u_int32_t));
62
 
static void __dbh_err __P((DB *, int, const char *, ...));
63
 
static void __dbh_errx __P((DB *, const char *, ...));
64
 
 
65
 
#ifdef HAVE_RPC
66
 
static int  __dbcl_init __P((DB *, DB_ENV *, u_int32_t));
67
 
#endif
68
 
 
69
 
/*
70
 
 * db_create --
71
 
 *      DB constructor.
72
 
 *
73
 
 * EXTERN: int db_create __P((DB **, DB_ENV *, u_int32_t));
74
 
 */
75
 
int
76
 
db_create(dbpp, dbenv, flags)
77
 
        DB **dbpp;
78
 
        DB_ENV *dbenv;
79
 
        u_int32_t flags;
80
 
{
81
 
        DB *dbp;
82
 
        int ret;
83
 
 
84
 
        /* Check for invalid function flags. */
85
 
        switch (flags) {
86
 
        case 0:
87
 
                break;
88
 
        case DB_XA_CREATE:
89
 
                if (dbenv != NULL) {
90
 
                        __db_err(dbenv,
91
 
                "XA applications may not specify an environment to db_create");
92
 
                        return (EINVAL);
93
 
                }
94
 
 
95
 
                /*
96
 
                 * If it's an XA database, open it within the XA environment,
97
 
                 * taken from the global list of environments.  (When the XA
98
 
                 * transaction manager called our xa_start() routine the
99
 
                 * "current" environment was moved to the start of the list.
100
 
                 */
101
 
                dbenv = TAILQ_FIRST(&DB_GLOBAL(db_envq));
102
 
                break;
103
 
        default:
104
 
                return (__db_ferr(dbenv, "db_create", 0));
105
 
        }
106
 
 
107
 
        /* Allocate the DB. */
108
 
        if ((ret = __os_calloc(dbenv, 1, sizeof(*dbp), &dbp)) != 0)
109
 
                return (ret);
110
 
#ifdef HAVE_RPC
111
 
        if (dbenv != NULL && RPC_ON(dbenv))
112
 
                ret = __dbcl_init(dbp, dbenv, flags);
113
 
        else
114
 
#endif
115
 
                ret = __db_init(dbp, flags);
116
 
        if (ret != 0) {
117
 
                __os_free(dbenv, dbp);
118
 
                return (ret);
119
 
        }
120
 
 
121
 
        /* If we don't have an environment yet, allocate a local one. */
122
 
        if (dbenv == NULL) {
123
 
                if ((ret = db_env_create(&dbenv, 0)) != 0) {
124
 
                        __os_free(dbenv, dbp);
125
 
                        return (ret);
126
 
                }
127
 
                F_SET(dbenv, DB_ENV_DBLOCAL);
128
 
        }
129
 
        ++dbenv->db_ref;
130
 
 
131
 
        dbp->dbenv = dbenv;
132
 
 
133
 
        *dbpp = dbp;
134
 
        return (0);
135
 
}
136
 
 
137
 
/*
138
 
 * __db_init --
139
 
 *      Initialize a DB structure.
140
 
 */
141
 
static int
142
 
__db_init(dbp, flags)
143
 
        DB *dbp;
144
 
        u_int32_t flags;
145
 
{
146
 
        int ret;
147
 
 
148
 
        dbp->lid = DB_LOCK_INVALIDID;
149
 
        LOCK_INIT(dbp->handle_lock);
150
 
 
151
 
        TAILQ_INIT(&dbp->free_queue);
152
 
        TAILQ_INIT(&dbp->active_queue);
153
 
        TAILQ_INIT(&dbp->join_queue);
154
 
        LIST_INIT(&dbp->s_secondaries);
155
 
 
156
 
        FLD_SET(dbp->am_ok,
157
 
            DB_OK_BTREE | DB_OK_HASH | DB_OK_QUEUE | DB_OK_RECNO);
158
 
 
159
 
        dbp->associate = __db_associate;
160
 
        dbp->close = __db_close;
161
 
        dbp->cursor = __db_cursor;
162
 
        dbp->del = __db_delete;
163
 
        dbp->err = __dbh_err;
164
 
        dbp->errx = __dbh_errx;
165
 
        dbp->fd = __db_fd;
166
 
        dbp->get = __db_get;
167
 
        dbp->get_byteswapped = __db_get_byteswapped;
168
 
        dbp->get_type = __db_get_type;
169
 
        dbp->join = __db_join;
170
 
        dbp->key_range = __db_key_range;
171
 
        dbp->open = __db_open;
172
 
        dbp->pget = __db_pget;
173
 
        dbp->put = __db_put;
174
 
        dbp->remove = __db_remove;
175
 
        dbp->rename = __db_rename;
176
 
        dbp->truncate = __db_truncate;
177
 
        dbp->set_alloc = __db_set_alloc;
178
 
        dbp->set_append_recno = __db_set_append_recno;
179
 
        dbp->set_cachesize = __db_set_cachesize;
180
 
        dbp->set_cache_priority = __db_set_cache_priority;
181
 
        dbp->set_dup_compare = __db_set_dup_compare;
182
 
        dbp->set_encrypt = __db_set_encrypt;
183
 
        dbp->set_errcall = __db_set_errcall;
184
 
        dbp->set_errfile = __db_set_errfile;
185
 
        dbp->set_errpfx = __db_set_errpfx;
186
 
        dbp->set_feedback = __db_set_feedback;
187
 
        dbp->set_flags = __db_set_flags;
188
 
        dbp->set_lorder = __db_set_lorder;
189
 
        dbp->set_pagesize = __db_set_pagesize;
190
 
        dbp->set_paniccall = __db_set_paniccall;
191
 
        dbp->stat = __db_stat_fail;
192
 
        dbp->sync = __db_sync;
193
 
        dbp->upgrade = __db_upgrade;
194
 
        dbp->verify = __db_verify;
195
 
 
196
 
                                        /* Access method specific. */
197
 
        if ((ret = __bam_db_create(dbp)) != 0)
198
 
                return (ret);
199
 
        if ((ret = __ham_db_create(dbp)) != 0)
200
 
                return (ret);
201
 
        if ((ret = __qam_db_create(dbp)) != 0)
202
 
                return (ret);
203
 
 
204
 
        /*
205
 
         * XA specific: must be last, as we replace methods set by the
206
 
         * access methods.
207
 
         */
208
 
        if (LF_ISSET(DB_XA_CREATE) && (ret = __db_xa_create(dbp)) != 0)
209
 
                return (ret);
210
 
 
211
 
        return (0);
212
 
}
213
 
 
214
 
/*
215
 
 * __dbh_am_chk --
216
 
 *      Error if an unreasonable method is called.
217
 
 *
218
 
 * PUBLIC: int __dbh_am_chk __P((DB *, u_int32_t));
219
 
 */
220
 
int
221
 
__dbh_am_chk(dbp, flags)
222
 
        DB *dbp;
223
 
        u_int32_t flags;
224
 
{
225
 
        /*
226
 
         * We start out allowing any access methods to be called, and as the
227
 
         * application calls the methods the options become restricted.  The
228
 
         * idea is to quit as soon as an illegal method combination is called.
229
 
         */
230
 
        if ((LF_ISSET(DB_OK_BTREE) && FLD_ISSET(dbp->am_ok, DB_OK_BTREE)) ||
231
 
            (LF_ISSET(DB_OK_HASH) && FLD_ISSET(dbp->am_ok, DB_OK_HASH)) ||
232
 
            (LF_ISSET(DB_OK_QUEUE) && FLD_ISSET(dbp->am_ok, DB_OK_QUEUE)) ||
233
 
            (LF_ISSET(DB_OK_RECNO) && FLD_ISSET(dbp->am_ok, DB_OK_RECNO))) {
234
 
                FLD_CLR(dbp->am_ok, ~flags);
235
 
                return (0);
236
 
        }
237
 
 
238
 
        __db_err(dbp->dbenv,
239
 
    "call implies an access method which is inconsistent with previous calls");
240
 
        return (EINVAL);
241
 
}
242
 
 
243
 
/*
244
 
 * __dbh_err --
245
 
 *      Error message, including the standard error string.
246
 
 */
247
 
static void
248
 
#ifdef __STDC__
249
 
__dbh_err(DB *dbp, int error, const char *fmt, ...)
250
 
#else
251
 
__dbh_err(dbp, error, fmt, va_alist)
252
 
        DB *dbp;
253
 
        int error;
254
 
        const char *fmt;
255
 
        va_dcl
256
 
#endif
257
 
{
258
 
        DB_REAL_ERR(dbp->dbenv, error, 1, 1, fmt);
259
 
}
260
 
 
261
 
/*
262
 
 * __dbh_errx --
263
 
 *      Error message.
264
 
 */
265
 
static void
266
 
#ifdef __STDC__
267
 
__dbh_errx(DB *dbp, const char *fmt, ...)
268
 
#else
269
 
__dbh_errx(dbp, fmt, va_alist)
270
 
        DB *dbp;
271
 
        const char *fmt;
272
 
        va_dcl
273
 
#endif
274
 
{
275
 
        DB_REAL_ERR(dbp->dbenv, 0, 0, 1, fmt);
276
 
}
277
 
 
278
 
/*
279
 
 * __db_get_byteswapped --
280
 
 *      Return if database requires byte swapping.
281
 
 */
282
 
static int
283
 
__db_get_byteswapped(dbp, isswapped)
284
 
        DB *dbp;
285
 
        int *isswapped;
286
 
{
287
 
        DB_ILLEGAL_BEFORE_OPEN(dbp, "get_byteswapped");
288
 
 
289
 
        *isswapped = F_ISSET(dbp, DB_AM_SWAP) ? 1 : 0;
290
 
        return (0);
291
 
}
292
 
 
293
 
/*
294
 
 * __db_get_type --
295
 
 *      Return type of underlying database.
296
 
 */
297
 
static int
298
 
__db_get_type(dbp, dbtype)
299
 
        DB *dbp;
300
 
        DBTYPE *dbtype;
301
 
{
302
 
        DB_ILLEGAL_BEFORE_OPEN(dbp, "get_type");
303
 
 
304
 
        *dbtype = dbp->type;
305
 
        return (0);
306
 
}
307
 
 
308
 
/*
309
 
 * __db_key_range --
310
 
 *      Return proportion of keys above and below given key.
311
 
 */
312
 
static int
313
 
__db_key_range(dbp, txn, key, kr, flags)
314
 
        DB *dbp;
315
 
        DB_TXN *txn;
316
 
        DBT *key;
317
 
        DB_KEY_RANGE *kr;
318
 
        u_int32_t flags;
319
 
{
320
 
        COMPQUIET(txn, NULL);
321
 
        COMPQUIET(key, NULL);
322
 
        COMPQUIET(kr, NULL);
323
 
        COMPQUIET(flags, 0);
324
 
 
325
 
        DB_ILLEGAL_BEFORE_OPEN(dbp, "key_range");
326
 
        DB_ILLEGAL_METHOD(dbp, DB_OK_BTREE);
327
 
 
328
 
        return (EINVAL);
329
 
}
330
 
 
331
 
/*
332
 
 * __db_set_append_recno --
333
 
 *      Set record number append routine.
334
 
 */
335
 
static int
336
 
__db_set_append_recno(dbp, func)
337
 
        DB *dbp;
338
 
        int (*func) __P((DB *, DBT *, db_recno_t));
339
 
{
340
 
        DB_ILLEGAL_AFTER_OPEN(dbp, "set_append_recno");
341
 
        DB_ILLEGAL_METHOD(dbp, DB_OK_QUEUE | DB_OK_RECNO);
342
 
 
343
 
        dbp->db_append_recno = func;
344
 
 
345
 
        return (0);
346
 
}
347
 
 
348
 
/*
349
 
 * __db_set_cachesize --
350
 
 *      Set underlying cache size.
351
 
 */
352
 
static int
353
 
__db_set_cachesize(dbp, cache_gbytes, cache_bytes, ncache)
354
 
        DB *dbp;
355
 
        u_int32_t cache_gbytes, cache_bytes;
356
 
        int ncache;
357
 
{
358
 
        DB_ILLEGAL_IN_ENV(dbp, "set_cachesize");
359
 
        DB_ILLEGAL_AFTER_OPEN(dbp, "set_cachesize");
360
 
 
361
 
        return (dbp->dbenv->set_cachesize(
362
 
            dbp->dbenv, cache_gbytes, cache_bytes, ncache));
363
 
}
364
 
 
365
 
/*
366
 
 * __db_set_cache_priority --
367
 
 *      Set cache priority for pages from this file.
368
 
 */
369
 
static int
370
 
__db_set_cache_priority(dbp, priority)
371
 
        DB *dbp;
372
 
        DB_CACHE_PRIORITY priority;
373
 
{
374
 
        /*
375
 
         * If an underlying DB_MPOOLFILE exists, call it.  Otherwise, save
376
 
         * the information away until DB->open is called.
377
 
         */
378
 
        if (dbp->mpf == NULL) {
379
 
                dbp->priority = priority;
380
 
                return (0);
381
 
        }
382
 
        return (dbp->mpf->set_priority(dbp->mpf, priority));
383
 
}
384
 
 
385
 
/*
386
 
 * __db_set_dup_compare --
387
 
 *      Set duplicate comparison routine.
388
 
 */
389
 
static int
390
 
__db_set_dup_compare(dbp, func)
391
 
        DB *dbp;
392
 
        int (*func) __P((DB *, const DBT *, const DBT *));
393
 
{
394
 
        int ret;
395
 
 
396
 
        DB_ILLEGAL_AFTER_OPEN(dbp, "dup_compare");
397
 
        DB_ILLEGAL_METHOD(dbp, DB_OK_BTREE | DB_OK_HASH);
398
 
 
399
 
        if ((ret = dbp->set_flags(dbp, DB_DUPSORT)) != 0)
400
 
                return (ret);
401
 
 
402
 
        dbp->dup_compare = func;
403
 
 
404
 
        return (0);
405
 
}
406
 
 
407
 
/*
408
 
 * __db_set_encrypt --
409
 
 *      Set database passwd.
410
 
 */
411
 
static int
412
 
__db_set_encrypt(dbp, passwd, flags)
413
 
        DB *dbp;
414
 
        const char *passwd;
415
 
        u_int32_t flags;
416
 
{
417
 
        DB_CIPHER *db_cipher;
418
 
        int ret;
419
 
 
420
 
        DB_ILLEGAL_IN_ENV(dbp, "set_encrypt");
421
 
        DB_ILLEGAL_AFTER_OPEN(dbp, "set_encrypt");
422
 
 
423
 
        if ((ret = dbp->dbenv->set_encrypt(dbp->dbenv, passwd, flags)) != 0)
424
 
                return (ret);
425
 
 
426
 
        /*
427
 
         * In a real env, this gets initialized with the region.  In a local
428
 
         * env, we must do it here.
429
 
         */
430
 
        db_cipher = (DB_CIPHER *)dbp->dbenv->crypto_handle;
431
 
        if (!F_ISSET(db_cipher, CIPHER_ANY) &&
432
 
            (ret = db_cipher->init(dbp->dbenv, db_cipher)) != 0)
433
 
                return (ret);
434
 
 
435
 
        return (dbp->set_flags(dbp, DB_ENCRYPT));
436
 
}
437
 
 
438
 
static void
439
 
__db_set_errcall(dbp, errcall)
440
 
        DB *dbp;
441
 
        void (*errcall) __P((const char *, char *));
442
 
{
443
 
        dbp->dbenv->set_errcall(dbp->dbenv, errcall);
444
 
}
445
 
 
446
 
static void
447
 
__db_set_errfile(dbp, errfile)
448
 
        DB *dbp;
449
 
        FILE *errfile;
450
 
{
451
 
        dbp->dbenv->set_errfile(dbp->dbenv, errfile);
452
 
}
453
 
 
454
 
static void
455
 
__db_set_errpfx(dbp, errpfx)
456
 
        DB *dbp;
457
 
        const char *errpfx;
458
 
{
459
 
        dbp->dbenv->set_errpfx(dbp->dbenv, errpfx);
460
 
}
461
 
 
462
 
static int
463
 
__db_set_feedback(dbp, feedback)
464
 
        DB *dbp;
465
 
        void (*feedback) __P((DB *, int, int));
466
 
{
467
 
        dbp->db_feedback = feedback;
468
 
        return (0);
469
 
}
470
 
 
471
 
static int
472
 
__db_set_flags(dbp, flags)
473
 
        DB *dbp;
474
 
        u_int32_t flags;
475
 
{
476
 
        int ret;
477
 
 
478
 
        /*
479
 
         * !!!
480
 
         * The hash access method only takes two flags: DB_DUP and DB_DUPSORT.
481
 
         * The Btree access method uses them for the same purposes, and so we
482
 
         * resolve them there.
483
 
         *
484
 
         * The queue access method takes no flags.
485
 
         */
486
 
        if (LF_ISSET(DB_ENCRYPT)) {
487
 
                if (!CRYPTO_ON(dbp->dbenv)) {
488
 
                        __db_err(dbp->dbenv,
489
 
                    "Database environment not configured for encryption");
490
 
                        return (EINVAL);
491
 
                }
492
 
                F_SET(dbp, DB_AM_ENCRYPT);
493
 
                F_SET(dbp, DB_AM_CHKSUM);
494
 
                LF_CLR(DB_ENCRYPT);
495
 
        }
496
 
        if (LF_ISSET(DB_CHKSUM_SHA1)) {
497
 
                F_SET(dbp, DB_AM_CHKSUM);
498
 
                LF_CLR(DB_CHKSUM_SHA1);
499
 
        }
500
 
 
501
 
        if ((ret = __bam_set_flags(dbp, &flags)) != 0)
502
 
                return (ret);
503
 
        if ((ret = __ram_set_flags(dbp, &flags)) != 0)
504
 
                return (ret);
505
 
 
506
 
        return (flags == 0 ? 0 : __db_ferr(dbp->dbenv, "DB->set_flags", 0));
507
 
}
508
 
 
509
 
/*
510
 
 * __db_set_lorder --
511
 
 *      Set whether lorder is swapped or not.
512
 
 *
513
 
 * PUBLIC: int  __db_set_lorder __P((DB *, int));
514
 
 */
515
 
int
516
 
__db_set_lorder(dbp, db_lorder)
517
 
        DB *dbp;
518
 
        int db_lorder;
519
 
{
520
 
        int ret;
521
 
 
522
 
        DB_ILLEGAL_AFTER_OPEN(dbp, "set_lorder");
523
 
 
524
 
        /* Flag if the specified byte order requires swapping. */
525
 
        switch (ret = __db_byteorder(dbp->dbenv, db_lorder)) {
526
 
        case 0:
527
 
                F_CLR(dbp, DB_AM_SWAP);
528
 
                break;
529
 
        case DB_SWAPBYTES:
530
 
                F_SET(dbp, DB_AM_SWAP);
531
 
                break;
532
 
        default:
533
 
                return (ret);
534
 
                /* NOTREACHED */
535
 
        }
536
 
        return (0);
537
 
}
538
 
 
539
 
static int
540
 
__db_set_alloc(dbp, mal_func, real_func, free_func)
541
 
        DB *dbp;
542
 
        void *(*mal_func) __P((size_t));
543
 
        void *(*real_func) __P((void *, size_t));
544
 
        void (*free_func) __P((void *));
545
 
{
546
 
        DB_ILLEGAL_IN_ENV(dbp, "set_alloc");
547
 
        DB_ILLEGAL_AFTER_OPEN(dbp, "set_alloc");
548
 
 
549
 
        return (dbp->dbenv->set_alloc(dbp->dbenv,
550
 
            mal_func, real_func, free_func));
551
 
}
552
 
 
553
 
static int
554
 
__db_set_pagesize(dbp, db_pagesize)
555
 
        DB *dbp;
556
 
        u_int32_t db_pagesize;
557
 
{
558
 
        DB_ILLEGAL_AFTER_OPEN(dbp, "set_pagesize");
559
 
 
560
 
        if (db_pagesize < DB_MIN_PGSIZE) {
561
 
                __db_err(dbp->dbenv, "page sizes may not be smaller than %lu",
562
 
                    (u_long)DB_MIN_PGSIZE);
563
 
                return (EINVAL);
564
 
        }
565
 
        if (db_pagesize > DB_MAX_PGSIZE) {
566
 
                __db_err(dbp->dbenv, "page sizes may not be larger than %lu",
567
 
                    (u_long)DB_MAX_PGSIZE);
568
 
                return (EINVAL);
569
 
        }
570
 
 
571
 
        /*
572
 
         * We don't want anything that's not a power-of-2, as we rely on that
573
 
         * for alignment of various types on the pages.
574
 
         */
575
 
        if (!POWER_OF_TWO(db_pagesize)) {
576
 
                __db_err(dbp->dbenv, "page sizes must be a power-of-2");
577
 
                return (EINVAL);
578
 
        }
579
 
 
580
 
        /*
581
 
         * XXX
582
 
         * Should we be checking for a page size that's not a multiple of 512,
583
 
         * so that we never try and write less than a disk sector?
584
 
         */
585
 
        dbp->pgsize = db_pagesize;
586
 
 
587
 
        return (0);
588
 
}
589
 
 
590
 
static int
591
 
__db_set_paniccall(dbp, paniccall)
592
 
        DB *dbp;
593
 
        void (*paniccall) __P((DB_ENV *, int));
594
 
{
595
 
        return (dbp->dbenv->set_paniccall(dbp->dbenv, paniccall));
596
 
}
597
 
 
598
 
static int
599
 
__db_stat_fail(dbp, sp, flags)
600
 
        DB *dbp;
601
 
        void *sp;
602
 
        u_int32_t flags;
603
 
{
604
 
        COMPQUIET(sp, NULL);
605
 
        COMPQUIET(flags, 0);
606
 
 
607
 
        /*
608
 
         * DB->stat isn't initialized until the actual DB->open call,
609
 
         * but we don't want to core dump.
610
 
         */
611
 
        PANIC_CHECK(dbp->dbenv);
612
 
        DB_ILLEGAL_BEFORE_OPEN(dbp, "DB->stat");
613
 
 
614
 
        /* NOTREACHED */
615
 
        return (EINVAL);
616
 
}
617
 
 
618
 
#ifdef HAVE_RPC
619
 
/*
620
 
 * __dbcl_init --
621
 
 *      Initialize a DB structure on the server.
622
 
 */
623
 
static int
624
 
__dbcl_init(dbp, dbenv, flags)
625
 
        DB *dbp;
626
 
        DB_ENV *dbenv;
627
 
        u_int32_t flags;
628
 
{
629
 
        TAILQ_INIT(&dbp->free_queue);
630
 
        TAILQ_INIT(&dbp->active_queue);
631
 
        /* !!!
632
 
         * Note that we don't need to initialize the join_queue;  it's
633
 
         * not used in RPC clients.  See the comment in __dbcl_db_join_ret().
634
 
         */
635
 
 
636
 
        dbp->associate = __dbcl_db_associate;
637
 
        dbp->close = __dbcl_db_close;
638
 
        dbp->cursor = __dbcl_db_cursor;
639
 
        dbp->del = __dbcl_db_del;
640
 
        dbp->err = __dbh_err;
641
 
        dbp->errx = __dbh_errx;
642
 
        dbp->fd = __dbcl_db_fd;
643
 
        dbp->get = __dbcl_db_get;
644
 
        dbp->get_byteswapped = __db_get_byteswapped;
645
 
        dbp->get_type = __db_get_type;
646
 
        dbp->join = __dbcl_db_join;
647
 
        dbp->key_range = __dbcl_db_key_range;
648
 
        dbp->open = __dbcl_db_open_wrap;
649
 
        dbp->pget = __dbcl_db_pget;
650
 
        dbp->put = __dbcl_db_put;
651
 
        dbp->remove = __dbcl_db_remove;
652
 
        dbp->rename = __dbcl_db_rename;
653
 
        dbp->set_alloc = __dbcl_db_alloc;
654
 
        dbp->set_append_recno = __dbcl_db_set_append_recno;
655
 
        dbp->set_cachesize = __dbcl_db_cachesize;
656
 
        dbp->set_cache_priority = __dbcl_db_cache_priority;
657
 
        dbp->set_dup_compare = __dbcl_db_dup_compare;
658
 
        dbp->set_encrypt = __dbcl_db_encrypt;
659
 
        dbp->set_errcall = __db_set_errcall;
660
 
        dbp->set_errfile = __db_set_errfile;
661
 
        dbp->set_errpfx = __db_set_errpfx;
662
 
        dbp->set_feedback = __dbcl_db_feedback;
663
 
        dbp->set_flags = __dbcl_db_flags;
664
 
        dbp->set_lorder = __dbcl_db_lorder;
665
 
        dbp->set_pagesize = __dbcl_db_pagesize;
666
 
        dbp->set_paniccall = __dbcl_db_panic;
667
 
        dbp->stat = __dbcl_db_stat;
668
 
        dbp->sync = __dbcl_db_sync;
669
 
        dbp->truncate = __dbcl_db_truncate;
670
 
        dbp->upgrade = __dbcl_db_upgrade;
671
 
        dbp->verify = __dbcl_db_verify;
672
 
 
673
 
        /*
674
 
         * Set all the method specific functions to client funcs as well.
675
 
         */
676
 
        dbp->set_bt_compare = __dbcl_db_bt_compare;
677
 
        dbp->set_bt_maxkey = __dbcl_db_bt_maxkey;
678
 
        dbp->set_bt_minkey = __dbcl_db_bt_minkey;
679
 
        dbp->set_bt_prefix = __dbcl_db_bt_prefix;
680
 
        dbp->set_h_ffactor = __dbcl_db_h_ffactor;
681
 
        dbp->set_h_hash = __dbcl_db_h_hash;
682
 
        dbp->set_h_nelem = __dbcl_db_h_nelem;
683
 
        dbp->set_q_extentsize = __dbcl_db_extentsize;
684
 
        dbp->set_re_delim = __dbcl_db_re_delim;
685
 
        dbp->set_re_len = __dbcl_db_re_len;
686
 
        dbp->set_re_pad = __dbcl_db_re_pad;
687
 
        dbp->set_re_source = __dbcl_db_re_source;
688
 
 
689
 
        return (__dbcl_db_create(dbp, dbenv, flags));
690
 
}
691
 
#endif