Update.
[glibc.git] / db2 / hash / hash_conv.c
blobc6d0ba4d4eadb543b68fdf267727d21f99b5fc0c
1 /*-
2 * See the file LICENSE for redistribution information.
4 * Copyright (c) 1996, 1997, 1998
5 * Sleepycat Software. All rights reserved.
6 */
7 #include "config.h"
9 #ifndef lint
10 static const char sccsid[] = "@(#)hash_conv.c 10.5 (Sleepycat) 4/10/98";
11 #endif /* not lint */
13 #ifndef NO_SYSTEM_INCLUDES
14 #include <sys/types.h>
15 #endif
17 #include "db_int.h"
18 #include "db_page.h"
19 #include "db_swap.h"
20 #include "hash.h"
23 * __ham_pgin --
24 * Convert host-specific page layout from the host-independent format
25 * stored on disk.
27 * PUBLIC: int __ham_pgin __P((db_pgno_t, void *, DBT *));
29 int
30 __ham_pgin(pg, pp, cookie)
31 db_pgno_t pg;
32 void *pp;
33 DBT *cookie;
35 DB_PGINFO *pginfo;
36 u_int32_t tpgno;
38 pginfo = (DB_PGINFO *)cookie->data;
39 tpgno = PGNO((PAGE *)pp);
40 if (pginfo->needswap)
41 M_32_SWAP(tpgno);
43 if (pg != PGNO_METADATA && pg != tpgno) {
44 P_INIT(pp, pginfo->db_pagesize,
45 pg, PGNO_INVALID, PGNO_INVALID, 0, P_HASH);
46 return (0);
49 if (!pginfo->needswap)
50 return (0);
51 return (pg == PGNO_METADATA ?
52 __ham_mswap(pp) : __db_pgin(pg, pginfo->db_pagesize, pp));
56 * __ham_pgout --
57 * Convert host-specific page layout to the host-independent format
58 * stored on disk.
60 * PUBLIC: int __ham_pgout __P((db_pgno_t, void *, DBT *));
62 int
63 __ham_pgout(pg, pp, cookie)
64 db_pgno_t pg;
65 void *pp;
66 DBT *cookie;
68 DB_PGINFO *pginfo;
70 pginfo = (DB_PGINFO *)cookie->data;
71 if (!pginfo->needswap)
72 return (0);
73 return (pg == PGNO_METADATA ?
74 __ham_mswap(pp) : __db_pgout(pg, pginfo->db_pagesize, pp));
78 * __ham_mswap --
79 * Swap the bytes on the hash metadata page.
81 * PUBLIC: int __ham_mswap __P((void *));
83 int
84 __ham_mswap(pg)
85 void *pg;
87 u_int8_t *p;
88 int i;
90 p = (u_int8_t *)pg;
91 SWAP32(p); /* lsn part 1 */
92 SWAP32(p); /* lsn part 2 */
93 SWAP32(p); /* pgno */
94 SWAP32(p); /* magic */
95 SWAP32(p); /* version */
96 SWAP32(p); /* pagesize */
97 SWAP32(p); /* ovfl_point */
98 SWAP32(p); /* last_freed */
99 SWAP32(p); /* max_bucket */
100 SWAP32(p); /* high_mask */
101 SWAP32(p); /* low_mask */
102 SWAP32(p); /* ffactor */
103 SWAP32(p); /* nelem */
104 SWAP32(p); /* h_charkey */
105 SWAP32(p); /* flags */
106 for (i = 0; i < NCACHED; ++i)
107 SWAP32(p); /* spares */
108 return (0);