1 | /*- |
---|
2 | * See the file LICENSE for redistribution information. |
---|
3 | * |
---|
4 | * Copyright (c) 1996-2002 |
---|
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 11.13 2002/08/06 06:11:12 bostic 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 "dbinc/db_page.h" |
---|
20 | #include "dbinc/db_swap.h" |
---|
21 | #include "dbinc/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 *, db_pgno_t, void *, DBT *)); |
---|
29 | */ |
---|
30 | int |
---|
31 | __bam_pgin(dbenv, dummydbp, pg, pp, cookie) |
---|
32 | DB_ENV *dbenv; |
---|
33 | DB *dummydbp; |
---|
34 | db_pgno_t pg; |
---|
35 | void *pp; |
---|
36 | DBT *cookie; |
---|
37 | { |
---|
38 | DB_PGINFO *pginfo; |
---|
39 | PAGE *h; |
---|
40 | |
---|
41 | pginfo = (DB_PGINFO *)cookie->data; |
---|
42 | if (!F_ISSET(pginfo, DB_AM_SWAP)) |
---|
43 | return (0); |
---|
44 | |
---|
45 | h = pp; |
---|
46 | return (TYPE(h) == P_BTREEMETA ? __bam_mswap(pp) : |
---|
47 | __db_byteswap(dbenv, dummydbp, pg, pp, pginfo->db_pagesize, 1)); |
---|
48 | } |
---|
49 | |
---|
50 | /* |
---|
51 | * __bam_pgout -- |
---|
52 | * Convert host-specific page layout to the host-independent format |
---|
53 | * stored on disk. |
---|
54 | * |
---|
55 | * PUBLIC: int __bam_pgout __P((DB_ENV *, DB *, db_pgno_t, void *, DBT *)); |
---|
56 | */ |
---|
57 | int |
---|
58 | __bam_pgout(dbenv, dummydbp, pg, pp, cookie) |
---|
59 | DB_ENV *dbenv; |
---|
60 | DB *dummydbp; |
---|
61 | db_pgno_t pg; |
---|
62 | void *pp; |
---|
63 | DBT *cookie; |
---|
64 | { |
---|
65 | DB_PGINFO *pginfo; |
---|
66 | PAGE *h; |
---|
67 | |
---|
68 | pginfo = (DB_PGINFO *)cookie->data; |
---|
69 | if (!F_ISSET(pginfo, DB_AM_SWAP)) |
---|
70 | return (0); |
---|
71 | |
---|
72 | h = pp; |
---|
73 | return (TYPE(h) == P_BTREEMETA ? __bam_mswap(pp) : |
---|
74 | __db_byteswap(dbenv, dummydbp, pg, pp, pginfo->db_pagesize, 0)); |
---|
75 | } |
---|
76 | |
---|
77 | /* |
---|
78 | * __bam_mswap -- |
---|
79 | * Swap the bytes on the btree metadata page. |
---|
80 | * |
---|
81 | * PUBLIC: int __bam_mswap __P((PAGE *)); |
---|
82 | */ |
---|
83 | int |
---|
84 | __bam_mswap(pg) |
---|
85 | PAGE *pg; |
---|
86 | { |
---|
87 | u_int8_t *p; |
---|
88 | |
---|
89 | __db_metaswap(pg); |
---|
90 | |
---|
91 | p = (u_int8_t *)pg + sizeof(DBMETA); |
---|
92 | |
---|
93 | SWAP32(p); /* maxkey */ |
---|
94 | SWAP32(p); /* minkey */ |
---|
95 | SWAP32(p); /* re_len */ |
---|
96 | SWAP32(p); /* re_pad */ |
---|
97 | SWAP32(p); /* root */ |
---|
98 | p += 92 * sizeof(u_int32_t); /* unused */ |
---|
99 | SWAP32(p); /* crypto_magic */ |
---|
100 | |
---|
101 | return (0); |
---|
102 | } |
---|