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