c9d5d1bc3edf374c60fb631948e1e0ce3c7bf7ba
[kopensolaris-gnu/glibc.git] / db2 / btree / bt_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
8 #include "config.h"
9
10 #ifndef lint
11 static const char sccsid[] = "@(#)bt_conv.c     10.4 (Sleepycat) 9/3/97";
12 #endif /* not lint */
13
14 #ifndef NO_SYSTEM_INCLUDES
15 #include <sys/types.h>
16 #endif
17
18 #include "db_int.h"
19 #include "db_page.h"
20 #include "db_swap.h"
21 #include "btree.h"
22
23 /*
24  * __bam_pgin, __bam_pgout --
25  *      Convert host-specific page layout to/from the host-independent
26  *      format stored on disk.
27  *
28  * PUBLIC: int __bam_pgin __P((db_pgno_t, void *, DBT *));
29  * PUBLIC: int __bam_pgout __P((db_pgno_t, void *, DBT *));
30  */
31 int
32 __bam_pgin(pg, pp, cookie)
33         db_pgno_t pg;
34         void *pp;
35         DBT *cookie;
36 {
37         DB_PGINFO *pginfo;
38
39         pginfo = (DB_PGINFO *)cookie->data;
40         if (!pginfo->needswap)
41                 return (0);
42         return (pg == PGNO_METADATA ? __bam_mswap(pp) : __db_pgin(pg, pp));
43 }
44
45 int
46 __bam_pgout(pg, pp, cookie)
47         db_pgno_t pg;
48         void *pp;
49         DBT *cookie;
50 {
51         DB_PGINFO *pginfo;
52
53         pginfo = (DB_PGINFO *)cookie->data;
54         if (!pginfo->needswap)
55                 return (0);
56         return (pg == PGNO_METADATA ? __bam_mswap(pp) : __db_pgout(pg, pp));
57 }
58
59 /*
60  * __bam_mswap --
61  *      Swap the bytes on the btree metadata page.
62  *
63  * PUBLIC: int __bam_mswap __P((PAGE *));
64  */
65 int
66 __bam_mswap(pg)
67         PAGE *pg;
68 {
69         u_int8_t *p;
70
71         p = (u_int8_t *)pg;
72
73         /* Swap the meta-data information. */
74         SWAP32(p);              /* lsn.file */
75         SWAP32(p);              /* lsn.offset */
76         SWAP32(p);              /* pgno */
77         SWAP32(p);              /* magic */
78         SWAP32(p);              /* version */
79         SWAP32(p);              /* pagesize */
80         SWAP32(p);              /* maxkey */
81         SWAP32(p);              /* minkey */
82         SWAP32(p);              /* free */
83         SWAP32(p);              /* flags */
84
85         /* Swap the statistics. */
86         p = (u_int8_t *)&((BTMETA *)pg)->stat;
87         SWAP32(p);              /* bt_freed */
88         SWAP32(p);              /* bt_pfxsaved */
89         SWAP32(p);              /* bt_split */
90         SWAP32(p);              /* bt_rootsplit */
91         SWAP32(p);              /* bt_fastsplit */
92         SWAP32(p);              /* bt_added */
93         SWAP32(p);              /* bt_deleted */
94         SWAP32(p);              /* bt_get */
95         SWAP32(p);              /* bt_cache_hit */
96         SWAP32(p);              /* bt_cache_miss */
97
98         return (0);
99 }