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 * 3. 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
32 * @(#)bt_conv.c 8.5 (Berkeley) 8/17/94
33 * $DragonFly: src/lib/libc/db/btree/bt_conv.c,v 1.6 2005/11/12 23:01:54 swildner Exp $
36 #include <sys/param.h>
43 static void mswap (PAGE
*);
46 * __BT_BPGIN, __BT_BPGOUT --
47 * Convert host-specific number layout to/from the host-independent
48 * format stored on disk.
56 __bt_pgin(void *t
, pgno_t pg
, void *pp
)
63 if (!F_ISSET(((BTREE
*)t
), B_NEEDSWAP
))
79 if ((h
->flags
& P_TYPE
) == P_BINTERNAL
)
80 for (i
= 0; i
< top
; i
++) {
81 M_16_SWAP(h
->linp
[i
]);
82 p
= (char *)GETBINTERNAL(h
, i
);
84 p
+= sizeof(u_int32_t
);
87 if (*(u_char
*)p
& P_BIGKEY
) {
94 else if ((h
->flags
& P_TYPE
) == P_BLEAF
)
95 for (i
= 0; i
< top
; i
++) {
96 M_16_SWAP(h
->linp
[i
]);
97 p
= (char *)GETBLEAF(h
, i
);
99 p
+= sizeof(u_int32_t
);
101 p
+= sizeof(u_int32_t
);
102 flags
= *(u_char
*)p
;
103 if (flags
& (P_BIGKEY
| P_BIGDATA
)) {
105 if (flags
& P_BIGKEY
) {
110 if (flags
& P_BIGDATA
) {
111 p
+= sizeof(u_int32_t
);
121 __bt_pgout(void *t
, pgno_t pg
, void *pp
)
128 if (!F_ISSET(((BTREE
*)t
), B_NEEDSWAP
))
137 if ((h
->flags
& P_TYPE
) == P_BINTERNAL
)
138 for (i
= 0; i
< top
; i
++) {
139 p
= (char *)GETBINTERNAL(h
, i
);
141 p
+= sizeof(u_int32_t
);
144 if (*(u_char
*)p
& P_BIGKEY
) {
150 M_16_SWAP(h
->linp
[i
]);
152 else if ((h
->flags
& P_TYPE
) == P_BLEAF
)
153 for (i
= 0; i
< top
; i
++) {
154 p
= (char *)GETBLEAF(h
, i
);
156 p
+= sizeof(u_int32_t
);
158 p
+= sizeof(u_int32_t
);
159 flags
= *(u_char
*)p
;
160 if (flags
& (P_BIGKEY
| P_BIGDATA
)) {
162 if (flags
& P_BIGKEY
) {
167 if (flags
& P_BIGDATA
) {
168 p
+= sizeof(u_int32_t
);
174 M_16_SWAP(h
->linp
[i
]);
178 M_32_SWAP(h
->prevpg
);
179 M_32_SWAP(h
->nextpg
);
186 * MSWAP -- Actually swap the bytes on the meta page.
197 P_32_SWAP(p
); /* magic */
198 p
+= sizeof(u_int32_t
);
199 P_32_SWAP(p
); /* version */
200 p
+= sizeof(u_int32_t
);
201 P_32_SWAP(p
); /* psize */
202 p
+= sizeof(u_int32_t
);
203 P_32_SWAP(p
); /* free */
204 p
+= sizeof(u_int32_t
);
205 P_32_SWAP(p
); /* nrecs */
206 p
+= sizeof(u_int32_t
);
207 P_32_SWAP(p
); /* flags */
208 p
+= sizeof(u_int32_t
);