1 /* $NetBSD: bt_conv.c,v 1.14 2008/09/10 17:52:35 joerg Exp $ */
4 * Copyright (c) 1990, 1993, 1994
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #if HAVE_NBTOOL_CONFIG_H
36 #include "nbtool_config.h"
39 #include <sys/cdefs.h>
40 __RCSID("$NetBSD: bt_conv.c,v 1.14 2008/09/10 17:52:35 joerg Exp $");
48 static void mswap(PAGE
*);
51 * __BT_BPGIN, __BT_BPGOUT --
52 * Convert host-specific number layout to/from the host-independent
53 * format stored on disk.
61 __bt_pgin(void *t
, pgno_t pg
, void *pp
)
68 if (!F_ISSET(((BTREE
*)t
), B_NEEDSWAP
))
84 if ((h
->flags
& P_TYPE
) == P_BINTERNAL
)
85 for (i
= 0; i
< top
; i
++) {
86 M_16_SWAP(h
->linp
[i
]);
87 p
= (char *)(void *)GETBINTERNAL(h
, i
);
89 p
+= sizeof(uint32_t);
92 if (*(uint8_t *)p
& P_BIGKEY
) {
99 else if ((h
->flags
& P_TYPE
) == P_BLEAF
)
100 for (i
= 0; i
< top
; i
++) {
101 M_16_SWAP(h
->linp
[i
]);
102 p
= (char *)(void *)GETBLEAF(h
, i
);
104 p
+= sizeof(uint32_t);
106 p
+= sizeof(uint32_t);
107 flags
= *(uint8_t *)p
;
108 if (flags
& (P_BIGKEY
| P_BIGDATA
)) {
109 p
+= sizeof(uint8_t);
110 if (flags
& P_BIGKEY
) {
115 if (flags
& P_BIGDATA
) {
116 p
+= sizeof(uint32_t);
126 __bt_pgout(void *t
, pgno_t pg
, void *pp
)
133 if (!F_ISSET(((BTREE
*)t
), B_NEEDSWAP
))
142 if ((h
->flags
& P_TYPE
) == P_BINTERNAL
)
143 for (i
= 0; i
< top
; i
++) {
144 p
= (char *)(void *)GETBINTERNAL(h
, i
);
146 p
+= sizeof(uint32_t);
149 if (*(uint8_t *)p
& P_BIGKEY
) {
150 p
+= sizeof(uint8_t);
155 M_16_SWAP(h
->linp
[i
]);
157 else if ((h
->flags
& P_TYPE
) == P_BLEAF
)
158 for (i
= 0; i
< top
; i
++) {
159 p
= (char *)(void *)GETBLEAF(h
, i
);
161 p
+= sizeof(uint32_t);
163 p
+= sizeof(uint32_t);
164 flags
= *(uint8_t *)p
;
165 if (flags
& (P_BIGKEY
| P_BIGDATA
)) {
166 p
+= sizeof(uint8_t);
167 if (flags
& P_BIGKEY
) {
172 if (flags
& P_BIGDATA
) {
173 p
+= sizeof(uint32_t);
179 M_16_SWAP(h
->linp
[i
]);
183 M_32_SWAP(h
->prevpg
);
184 M_32_SWAP(h
->nextpg
);
191 * MSWAP -- Actually swap the bytes on the meta page.
201 p
= (char *)(void *)pg
;
202 P_32_SWAP(p
); /* magic */
203 p
+= sizeof(uint32_t);
204 P_32_SWAP(p
); /* version */
205 p
+= sizeof(uint32_t);
206 P_32_SWAP(p
); /* psize */
207 p
+= sizeof(uint32_t);
208 P_32_SWAP(p
); /* free */
209 p
+= sizeof(uint32_t);
210 P_32_SWAP(p
); /* nrecs */
211 p
+= sizeof(uint32_t);
212 P_32_SWAP(p
); /* flags */
213 p
+= sizeof(uint32_t);