~ubuntu-branches/ubuntu/edgy/rpm/edgy

« back to all changes in this revision

Viewing changes to db/hash/hash_conv.c

  • Committer: Bazaar Package Importer
  • Author(s): Joey Hess
  • Date: 2002-01-22 20:56:57 UTC
  • Revision ID: james.westby@ubuntu.com-20020122205657-l74j50mr9z8ofcl5
Tags: upstream-4.0.3
ImportĀ upstreamĀ versionĀ 4.0.3

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) 1996-2001
 
5
 *      Sleepycat Software.  All rights reserved.
 
6
 */
 
7
#include "db_config.h"
 
8
 
 
9
#ifndef lint
 
10
static const char revid[] = "$Id: hash_conv.c,v 11.6 2001/01/25 18:22:47 bostic Exp $";
 
11
#endif /* not lint */
 
12
 
 
13
#ifndef NO_SYSTEM_INCLUDES
 
14
#include <sys/types.h>
 
15
#endif
 
16
 
 
17
#include "db_int.h"
 
18
#include "db_page.h"
 
19
#include "db_swap.h"
 
20
#include "hash.h"
 
21
 
 
22
/*
 
23
 * __ham_pgin --
 
24
 *      Convert host-specific page layout from the host-independent format
 
25
 *      stored on disk.
 
26
 *
 
27
 * PUBLIC: int __ham_pgin __P((DB_ENV *, db_pgno_t, void *, DBT *));
 
28
 */
 
29
int
 
30
__ham_pgin(dbenv, pg, pp, cookie)
 
31
        DB_ENV *dbenv;
 
32
        db_pgno_t pg;
 
33
        void *pp;
 
34
        DBT *cookie;
 
35
{
 
36
        DB_PGINFO *pginfo;
 
37
        PAGE *h;
 
38
 
 
39
        h = pp;
 
40
        pginfo = (DB_PGINFO *)cookie->data;
 
41
 
 
42
        /*
 
43
         * The hash access method does blind reads of pages, causing them
 
44
         * to be created.  If the type field isn't set it's one of them,
 
45
         * initialize the rest of the page and return.
 
46
         */
 
47
        if (h->type != P_HASHMETA && h->pgno == PGNO_INVALID) {
 
48
                P_INIT(pp, pginfo->db_pagesize,
 
49
                    pg, PGNO_INVALID, PGNO_INVALID, 0, P_HASH);
 
50
                return (0);
 
51
        }
 
52
 
 
53
        if (!pginfo->needswap)
 
54
                return (0);
 
55
 
 
56
        return (h->type == P_HASHMETA ?  __ham_mswap(pp) :
 
57
            __db_byteswap(dbenv, pg, pp, pginfo->db_pagesize, 1));
 
58
}
 
59
 
 
60
/*
 
61
 * __ham_pgout --
 
62
 *      Convert host-specific page layout to the host-independent format
 
63
 *      stored on disk.
 
64
 *
 
65
 * PUBLIC: int __ham_pgout __P((DB_ENV *, db_pgno_t, void *, DBT *));
 
66
 */
 
67
int
 
68
__ham_pgout(dbenv, pg, pp, cookie)
 
69
        DB_ENV *dbenv;
 
70
        db_pgno_t pg;
 
71
        void *pp;
 
72
        DBT *cookie;
 
73
{
 
74
        DB_PGINFO *pginfo;
 
75
        PAGE *h;
 
76
 
 
77
        pginfo = (DB_PGINFO *)cookie->data;
 
78
        if (!pginfo->needswap)
 
79
                return (0);
 
80
 
 
81
        h = pp;
 
82
        return (h->type == P_HASHMETA ?  __ham_mswap(pp) :
 
83
             __db_byteswap(dbenv, pg, pp, pginfo->db_pagesize, 0));
 
84
}
 
85
 
 
86
/*
 
87
 * __ham_mswap --
 
88
 *      Swap the bytes on the hash metadata page.
 
89
 *
 
90
 * PUBLIC: int __ham_mswap __P((void *));
 
91
 */
 
92
int
 
93
__ham_mswap(pg)
 
94
        void *pg;
 
95
{
 
96
        u_int8_t *p;
 
97
        int i;
 
98
 
 
99
        __db_metaswap(pg);
 
100
 
 
101
        p = (u_int8_t *)pg + sizeof(DBMETA);
 
102
 
 
103
        SWAP32(p);              /* max_bucket */
 
104
        SWAP32(p);              /* high_mask */
 
105
        SWAP32(p);              /* low_mask */
 
106
        SWAP32(p);              /* ffactor */
 
107
        SWAP32(p);              /* nelem */
 
108
        SWAP32(p);              /* h_charkey */
 
109
        for (i = 0; i < NCACHED; ++i)
 
110
                SWAP32(p);      /* spares */
 
111
        return (0);
 
112
}