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