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