2 * SPDX-License-Identifier: BSD-3-Clause
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 defined(LIBC_SCCS) && !defined(lint)
36 static char sccsid[] = "@(#)bt_conv.c 8.5 (Berkeley) 8/17/94";
37 #endif /* LIBC_SCCS and not lint */
38 #include <sys/cdefs.h>
39 __FBSDID("$FreeBSD$");
41 #include <sys/param.h>
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 *)GETBINTERNAL(h, i);
89 p += sizeof(u_int32_t);
92 if (*(u_char *)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 *)GETBLEAF(h, i);
104 p += sizeof(u_int32_t);
106 p += sizeof(u_int32_t);
107 flags = *(u_char *)p;
108 if (flags & (P_BIGKEY | P_BIGDATA)) {
110 if (flags & P_BIGKEY) {
115 if (flags & P_BIGDATA) {
116 p += sizeof(u_int32_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 *)GETBINTERNAL(h, i);
146 p += sizeof(u_int32_t);
149 if (*(u_char *)p & P_BIGKEY) {
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 *)GETBLEAF(h, i);
161 p += sizeof(u_int32_t);
163 p += sizeof(u_int32_t);
164 flags = *(u_char *)p;
165 if (flags & (P_BIGKEY | P_BIGDATA)) {
167 if (flags & P_BIGKEY) {
172 if (flags & P_BIGDATA) {
173 p += sizeof(u_int32_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.
202 P_32_SWAP(p); /* magic */
203 p += sizeof(u_int32_t);
204 P_32_SWAP(p); /* version */
205 p += sizeof(u_int32_t);
206 P_32_SWAP(p); /* psize */
207 p += sizeof(u_int32_t);
208 P_32_SWAP(p); /* free */
209 p += sizeof(u_int32_t);
210 P_32_SWAP(p); /* nrecs */
211 p += sizeof(u_int32_t);
212 P_32_SWAP(p); /* flags */
213 p += sizeof(u_int32_t);