1*7c478bd9Sstevel@tonic-gate /*-
2*7c478bd9Sstevel@tonic-gate * See the file LICENSE for redistribution information.
3*7c478bd9Sstevel@tonic-gate *
4*7c478bd9Sstevel@tonic-gate * Copyright (c) 1996, 1997
5*7c478bd9Sstevel@tonic-gate * Sleepycat Software. All rights reserved.
6*7c478bd9Sstevel@tonic-gate */
7*7c478bd9Sstevel@tonic-gate /*
8*7c478bd9Sstevel@tonic-gate * Copyright (c) 1998 by Sun Microsystems, Inc.
9*7c478bd9Sstevel@tonic-gate * All rights reserved.
10*7c478bd9Sstevel@tonic-gate */
11*7c478bd9Sstevel@tonic-gate
12*7c478bd9Sstevel@tonic-gate #include "config.h"
13*7c478bd9Sstevel@tonic-gate
14*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
15*7c478bd9Sstevel@tonic-gate
16*7c478bd9Sstevel@tonic-gate #ifndef lint
17*7c478bd9Sstevel@tonic-gate static const char sccsid[] = "@(#)hash_conv.c 10.4 (Sleepycat) 9/15/97";
18*7c478bd9Sstevel@tonic-gate static const char sccsi2[] = "%W% (Sun) %G%";
19*7c478bd9Sstevel@tonic-gate #endif /* not lint */
20*7c478bd9Sstevel@tonic-gate
21*7c478bd9Sstevel@tonic-gate #ifndef NO_SYSTEM_INCLUDES
22*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
23*7c478bd9Sstevel@tonic-gate #endif
24*7c478bd9Sstevel@tonic-gate
25*7c478bd9Sstevel@tonic-gate #include "db_int.h"
26*7c478bd9Sstevel@tonic-gate #include "db_page.h"
27*7c478bd9Sstevel@tonic-gate #include "db_swap.h"
28*7c478bd9Sstevel@tonic-gate #include "hash.h"
29*7c478bd9Sstevel@tonic-gate
30*7c478bd9Sstevel@tonic-gate /*
31*7c478bd9Sstevel@tonic-gate * __ham_pgin --
32*7c478bd9Sstevel@tonic-gate * Convert host-specific page layout from the host-independent format
33*7c478bd9Sstevel@tonic-gate * stored on disk.
34*7c478bd9Sstevel@tonic-gate *
35*7c478bd9Sstevel@tonic-gate * PUBLIC: int __ham_pgin __P((db_pgno_t, void *, DBT *));
36*7c478bd9Sstevel@tonic-gate */
37*7c478bd9Sstevel@tonic-gate int
__ham_pgin(pg,pp,cookie)38*7c478bd9Sstevel@tonic-gate __ham_pgin(pg, pp, cookie)
39*7c478bd9Sstevel@tonic-gate db_pgno_t pg;
40*7c478bd9Sstevel@tonic-gate void *pp;
41*7c478bd9Sstevel@tonic-gate DBT *cookie;
42*7c478bd9Sstevel@tonic-gate {
43*7c478bd9Sstevel@tonic-gate DB_PGINFO *pginfo;
44*7c478bd9Sstevel@tonic-gate u_int32_t tpgno;
45*7c478bd9Sstevel@tonic-gate
46*7c478bd9Sstevel@tonic-gate pginfo = (DB_PGINFO *)cookie->data;
47*7c478bd9Sstevel@tonic-gate tpgno = PGNO((PAGE *)pp);
48*7c478bd9Sstevel@tonic-gate if (pginfo->needswap)
49*7c478bd9Sstevel@tonic-gate M_32_SWAP(tpgno);
50*7c478bd9Sstevel@tonic-gate
51*7c478bd9Sstevel@tonic-gate if (pg != PGNO_METADATA && pg != tpgno) {
52*7c478bd9Sstevel@tonic-gate P_INIT(pp, pginfo->db_pagesize,
53*7c478bd9Sstevel@tonic-gate pg, PGNO_INVALID, PGNO_INVALID, 0, P_HASH);
54*7c478bd9Sstevel@tonic-gate return (0);
55*7c478bd9Sstevel@tonic-gate }
56*7c478bd9Sstevel@tonic-gate
57*7c478bd9Sstevel@tonic-gate if (!pginfo->needswap)
58*7c478bd9Sstevel@tonic-gate return (0);
59*7c478bd9Sstevel@tonic-gate return (pg == PGNO_METADATA ?
60*7c478bd9Sstevel@tonic-gate __ham_mswap(pp) : __db_pgin(pg, pginfo->db_pagesize, pp));
61*7c478bd9Sstevel@tonic-gate }
62*7c478bd9Sstevel@tonic-gate
63*7c478bd9Sstevel@tonic-gate /*
64*7c478bd9Sstevel@tonic-gate * __ham_pgout --
65*7c478bd9Sstevel@tonic-gate * Convert host-specific page layout to the host-independent format
66*7c478bd9Sstevel@tonic-gate * stored on disk.
67*7c478bd9Sstevel@tonic-gate *
68*7c478bd9Sstevel@tonic-gate * PUBLIC: int __ham_pgout __P((db_pgno_t, void *, DBT *));
69*7c478bd9Sstevel@tonic-gate */
70*7c478bd9Sstevel@tonic-gate int
__ham_pgout(pg,pp,cookie)71*7c478bd9Sstevel@tonic-gate __ham_pgout(pg, pp, cookie)
72*7c478bd9Sstevel@tonic-gate db_pgno_t pg;
73*7c478bd9Sstevel@tonic-gate void *pp;
74*7c478bd9Sstevel@tonic-gate DBT *cookie;
75*7c478bd9Sstevel@tonic-gate {
76*7c478bd9Sstevel@tonic-gate DB_PGINFO *pginfo;
77*7c478bd9Sstevel@tonic-gate
78*7c478bd9Sstevel@tonic-gate pginfo = (DB_PGINFO *)cookie->data;
79*7c478bd9Sstevel@tonic-gate if (!pginfo->needswap)
80*7c478bd9Sstevel@tonic-gate return (0);
81*7c478bd9Sstevel@tonic-gate return (pg == PGNO_METADATA ?
82*7c478bd9Sstevel@tonic-gate __ham_mswap(pp) : __db_pgout(pg, pginfo->db_pagesize, pp));
83*7c478bd9Sstevel@tonic-gate }
84*7c478bd9Sstevel@tonic-gate
85*7c478bd9Sstevel@tonic-gate /*
86*7c478bd9Sstevel@tonic-gate * __ham_mswap --
87*7c478bd9Sstevel@tonic-gate * Swap the bytes on the hash metadata page.
88*7c478bd9Sstevel@tonic-gate *
89*7c478bd9Sstevel@tonic-gate * PUBLIC: int __ham_mswap __P((void *));
90*7c478bd9Sstevel@tonic-gate */
91*7c478bd9Sstevel@tonic-gate int
__ham_mswap(pg)92*7c478bd9Sstevel@tonic-gate __ham_mswap(pg)
93*7c478bd9Sstevel@tonic-gate void *pg;
94*7c478bd9Sstevel@tonic-gate {
95*7c478bd9Sstevel@tonic-gate u_int8_t *p;
96*7c478bd9Sstevel@tonic-gate int i;
97*7c478bd9Sstevel@tonic-gate
98*7c478bd9Sstevel@tonic-gate p = (u_int8_t *)pg;
99*7c478bd9Sstevel@tonic-gate SWAP32(p); /* lsn part 1 */
100*7c478bd9Sstevel@tonic-gate SWAP32(p); /* lsn part 2 */
101*7c478bd9Sstevel@tonic-gate SWAP32(p); /* pgno */
102*7c478bd9Sstevel@tonic-gate SWAP32(p); /* magic */
103*7c478bd9Sstevel@tonic-gate SWAP32(p); /* version */
104*7c478bd9Sstevel@tonic-gate SWAP32(p); /* pagesize */
105*7c478bd9Sstevel@tonic-gate SWAP32(p); /* ovfl_point */
106*7c478bd9Sstevel@tonic-gate SWAP32(p); /* last_freed */
107*7c478bd9Sstevel@tonic-gate SWAP32(p); /* max_bucket */
108*7c478bd9Sstevel@tonic-gate SWAP32(p); /* high_mask */
109*7c478bd9Sstevel@tonic-gate SWAP32(p); /* low_mask */
110*7c478bd9Sstevel@tonic-gate SWAP32(p); /* ffactor */
111*7c478bd9Sstevel@tonic-gate SWAP32(p); /* nelem */
112*7c478bd9Sstevel@tonic-gate SWAP32(p); /* h_charkey */
113*7c478bd9Sstevel@tonic-gate SWAP32(p); /* flags */
114*7c478bd9Sstevel@tonic-gate for (i = 0; i < NCACHED; ++i)
115*7c478bd9Sstevel@tonic-gate SWAP32(p); /* spares */
116*7c478bd9Sstevel@tonic-gate return (0);
117*7c478bd9Sstevel@tonic-gate }
118