2 * Copyright (c) 1990, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software contributed to Berkeley by
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 4. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 #if defined(LIBC_SCCS) && !defined(lint)
34 static char sccsid[] = "@(#)bt_conv.c 8.5 (Berkeley) 8/17/94";
35 #endif /* LIBC_SCCS and not lint */
36 #include <sys/cdefs.h>
37 __FBSDID("$FreeBSD$");
39 #include <sys/param.h>
46 static void mswap(PAGE *);
49 * __BT_BPGIN, __BT_BPGOUT --
50 * Convert host-specific number layout to/from the host-independent
51 * format stored on disk.
59 __bt_pgin(void *t, pgno_t pg, void *pp)
66 if (!F_ISSET(((BTREE *)t), B_NEEDSWAP))
82 if ((h->flags & P_TYPE) == P_BINTERNAL)
83 for (i = 0; i < top; i++) {
84 M_16_SWAP(h->linp[i]);
85 p = (char *)GETBINTERNAL(h, i);
87 p += sizeof(u_int32_t);
90 if (*(u_char *)p & P_BIGKEY) {
97 else if ((h->flags & P_TYPE) == P_BLEAF)
98 for (i = 0; i < top; i++) {
99 M_16_SWAP(h->linp[i]);
100 p = (char *)GETBLEAF(h, i);
102 p += sizeof(u_int32_t);
104 p += sizeof(u_int32_t);
105 flags = *(u_char *)p;
106 if (flags & (P_BIGKEY | P_BIGDATA)) {
108 if (flags & P_BIGKEY) {
113 if (flags & P_BIGDATA) {
114 p += sizeof(u_int32_t);
124 __bt_pgout(void *t, pgno_t pg, void *pp)
131 if (!F_ISSET(((BTREE *)t), B_NEEDSWAP))
140 if ((h->flags & P_TYPE) == P_BINTERNAL)
141 for (i = 0; i < top; i++) {
142 p = (char *)GETBINTERNAL(h, i);
144 p += sizeof(u_int32_t);
147 if (*(u_char *)p & P_BIGKEY) {
153 M_16_SWAP(h->linp[i]);
155 else if ((h->flags & P_TYPE) == P_BLEAF)
156 for (i = 0; i < top; i++) {
157 p = (char *)GETBLEAF(h, i);
159 p += sizeof(u_int32_t);
161 p += sizeof(u_int32_t);
162 flags = *(u_char *)p;
163 if (flags & (P_BIGKEY | P_BIGDATA)) {
165 if (flags & P_BIGKEY) {
170 if (flags & P_BIGDATA) {
171 p += sizeof(u_int32_t);
177 M_16_SWAP(h->linp[i]);
181 M_32_SWAP(h->prevpg);
182 M_32_SWAP(h->nextpg);
189 * MSWAP -- Actually swap the bytes on the meta page.
200 P_32_SWAP(p); /* magic */
201 p += sizeof(u_int32_t);
202 P_32_SWAP(p); /* version */
203 p += sizeof(u_int32_t);
204 P_32_SWAP(p); /* psize */
205 p += sizeof(u_int32_t);
206 P_32_SWAP(p); /* free */
207 p += sizeof(u_int32_t);
208 P_32_SWAP(p); /* nrecs */
209 p += sizeof(u_int32_t);
210 P_32_SWAP(p); /* flags */
211 p += sizeof(u_int32_t);