Update to db 2.3.10.
[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.4 (Sleepycat) 9/15/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  * __ham_pgin --
24  *      Convert host-specific page layout from the host-independent format
25  *      stored on disk.
26  *
27  * PUBLIC: int __ham_pgin __P((db_pgno_t, void *, DBT *));
28  */
29 int
30 __ham_pgin(pg, pp, cookie)
31         db_pgno_t pg;
32         void *pp;
33         DBT *cookie;
34 {
35         DB_PGINFO *pginfo;
36         u_int32_t tpgno;
37
38         pginfo = (DB_PGINFO *)cookie->data;
39         tpgno = PGNO((PAGE *)pp);
40         if (pginfo->needswap)
41                 M_32_SWAP(tpgno);
42
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);
47         }
48
49         if (!pginfo->needswap)
50                 return (0);
51         return (pg == PGNO_METADATA ?
52             __ham_mswap(pp) : __db_pgin(pg, pginfo->db_pagesize, pp));
53 }
54
55 /*
56  * __ham_pgout --
57  *      Convert host-specific page layout to the host-independent format
58  *      stored on disk.
59  *
60  * PUBLIC: int __ham_pgout __P((db_pgno_t, void *, DBT *));
61  */
62 int
63 __ham_pgout(pg, pp, cookie)
64         db_pgno_t pg;
65         void *pp;
66         DBT *cookie;
67 {
68         DB_PGINFO *pginfo;
69
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));
75 }
76
77 /*
78  * __ham_mswap --
79  *      Swap the bytes on the hash metadata page.
80  *
81  * PUBLIC: int __ham_mswap __P((void *));
82  */
83 int
84 __ham_mswap(pg)
85         void *pg;
86 {
87         u_int8_t *p;
88         int i;
89
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);
109 }