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