Update after charmap correction.
[glibc/history.git] / db2 / btree / bt_conv.c
blob3da4507723020dc11e1e0819c872ce88d24f855e
1 /*-
2 * See the file LICENSE for redistribution information.
4 * Copyright (c) 1996, 1997, 1998
5 * Sleepycat Software. All rights reserved.
6 */
8 #include "config.h"
10 #ifndef lint
11 static const char sccsid[] = "@(#)bt_conv.c 10.6 (Sleepycat) 4/10/98";
12 #endif /* not lint */
14 #ifndef NO_SYSTEM_INCLUDES
15 #include <sys/types.h>
16 #endif
18 #include "db_int.h"
19 #include "db_page.h"
20 #include "db_swap.h"
21 #include "btree.h"
24 * __bam_pgin --
25 * Convert host-specific page layout from the host-independent format
26 * stored on disk.
28 * PUBLIC: int __bam_pgin __P((db_pgno_t, void *, DBT *));
30 int
31 __bam_pgin(pg, pp, cookie)
32 db_pgno_t pg;
33 void *pp;
34 DBT *cookie;
36 DB_PGINFO *pginfo;
38 pginfo = (DB_PGINFO *)cookie->data;
39 if (!pginfo->needswap)
40 return (0);
41 return (pg == PGNO_METADATA ?
42 __bam_mswap(pp) : __db_pgin(pg, pginfo->db_pagesize, pp));
46 * __bam_pgout --
47 * Convert host-specific page layout to the host-independent format
48 * stored on disk.
50 * PUBLIC: int __bam_pgout __P((db_pgno_t, void *, DBT *));
52 int
53 __bam_pgout(pg, pp, cookie)
54 db_pgno_t pg;
55 void *pp;
56 DBT *cookie;
58 DB_PGINFO *pginfo;
60 pginfo = (DB_PGINFO *)cookie->data;
61 if (!pginfo->needswap)
62 return (0);
63 return (pg == PGNO_METADATA ?
64 __bam_mswap(pp) : __db_pgout(pg, pginfo->db_pagesize, pp));
68 * __bam_mswap --
69 * Swap the bytes on the btree metadata page.
71 * PUBLIC: int __bam_mswap __P((PAGE *));
73 int
74 __bam_mswap(pg)
75 PAGE *pg;
77 u_int8_t *p;
79 p = (u_int8_t *)pg;
81 /* Swap the meta-data information. */
82 SWAP32(p); /* lsn.file */
83 SWAP32(p); /* lsn.offset */
84 SWAP32(p); /* pgno */
85 SWAP32(p); /* magic */
86 SWAP32(p); /* version */
87 SWAP32(p); /* pagesize */
88 SWAP32(p); /* maxkey */
89 SWAP32(p); /* minkey */
90 SWAP32(p); /* free */
91 SWAP32(p); /* flags */
93 /* Swap the statistics. */
94 p = (u_int8_t *)&((BTMETA *)pg)->stat;
95 SWAP32(p); /* bt_freed */
96 SWAP32(p); /* bt_pfxsaved */
97 SWAP32(p); /* bt_split */
98 SWAP32(p); /* bt_rootsplit */
99 SWAP32(p); /* bt_fastsplit */
100 SWAP32(p); /* bt_added */
101 SWAP32(p); /* bt_deleted */
102 SWAP32(p); /* bt_get */
103 SWAP32(p); /* bt_cache_hit */
104 SWAP32(p); /* bt_cache_miss */
106 return (0);