1 | /*- |
---|
2 | * See the file LICENSE for redistribution information. |
---|
3 | * |
---|
4 | * Copyright (c) 1996, 1997, 1998, 1999, 2000 |
---|
5 | * Sleepycat Software. All rights reserved. |
---|
6 | */ |
---|
7 | |
---|
8 | #include "db_config.h" |
---|
9 | |
---|
10 | #ifndef lint |
---|
11 | static const char revid[] = "$Id: bt_conv.c,v 1.1.1.2 2002-02-11 16:26:12 ghudson Exp $"; |
---|
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 -- |
---|
25 | * Convert host-specific page layout from the host-independent format |
---|
26 | * stored on disk. |
---|
27 | * |
---|
28 | * PUBLIC: int __bam_pgin __P((DB_ENV *, db_pgno_t, void *, DBT *)); |
---|
29 | */ |
---|
30 | int |
---|
31 | __bam_pgin(dbenv, pg, pp, cookie) |
---|
32 | DB_ENV *dbenv; |
---|
33 | db_pgno_t pg; |
---|
34 | void *pp; |
---|
35 | DBT *cookie; |
---|
36 | { |
---|
37 | DB_PGINFO *pginfo; |
---|
38 | PAGE *h; |
---|
39 | |
---|
40 | pginfo = (DB_PGINFO *)cookie->data; |
---|
41 | if (!pginfo->needswap) |
---|
42 | return (0); |
---|
43 | |
---|
44 | h = pp; |
---|
45 | return (TYPE(h) == P_BTREEMETA ? __bam_mswap(pp) : |
---|
46 | __db_byteswap(dbenv, pg, pp, pginfo->db_pagesize, 1)); |
---|
47 | } |
---|
48 | |
---|
49 | /* |
---|
50 | * __bam_pgout -- |
---|
51 | * Convert host-specific page layout to the host-independent format |
---|
52 | * stored on disk. |
---|
53 | * |
---|
54 | * PUBLIC: int __bam_pgout __P((DB_ENV *, db_pgno_t, void *, DBT *)); |
---|
55 | */ |
---|
56 | int |
---|
57 | __bam_pgout(dbenv, pg, pp, cookie) |
---|
58 | DB_ENV *dbenv; |
---|
59 | db_pgno_t pg; |
---|
60 | void *pp; |
---|
61 | DBT *cookie; |
---|
62 | { |
---|
63 | DB_PGINFO *pginfo; |
---|
64 | PAGE *h; |
---|
65 | |
---|
66 | pginfo = (DB_PGINFO *)cookie->data; |
---|
67 | if (!pginfo->needswap) |
---|
68 | return (0); |
---|
69 | |
---|
70 | h = pp; |
---|
71 | return (TYPE(h) == P_BTREEMETA ? __bam_mswap(pp) : |
---|
72 | __db_byteswap(dbenv, pg, pp, pginfo->db_pagesize, 0)); |
---|
73 | } |
---|
74 | |
---|
75 | /* |
---|
76 | * __bam_mswap -- |
---|
77 | * Swap the bytes on the btree metadata page. |
---|
78 | * |
---|
79 | * PUBLIC: int __bam_mswap __P((PAGE *)); |
---|
80 | */ |
---|
81 | int |
---|
82 | __bam_mswap(pg) |
---|
83 | PAGE *pg; |
---|
84 | { |
---|
85 | u_int8_t *p; |
---|
86 | |
---|
87 | __db_metaswap(pg); |
---|
88 | |
---|
89 | p = (u_int8_t *)pg + sizeof(DBMETA); |
---|
90 | |
---|
91 | SWAP32(p); /* maxkey */ |
---|
92 | SWAP32(p); /* minkey */ |
---|
93 | SWAP32(p); /* re_len */ |
---|
94 | SWAP32(p); /* re_pad */ |
---|
95 | SWAP32(p); /* root */ |
---|
96 | |
---|
97 | return (0); |
---|
98 | } |
---|