2 * See the file LICENSE for redistribution information.
4 * Copyright (c) 1996, 1997, 1998
5 * Sleepycat Software. All rights reserved.
8 * Copyright (c) 1990, 1993, 1994, 1995, 1996
9 * Keith Bostic. All rights reserved.
12 * Copyright (c) 1990, 1993, 1994, 1995
13 * The Regents of the University of California. All rights reserved.
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
23 * 3. All advertising materials mentioning features or use of this software
24 * must display the following acknowledgement:
25 * This product includes software developed by the University of
26 * California, Berkeley and its contributors.
27 * 4. Neither the name of the University nor the names of its contributors
28 * may be used to endorse or promote products derived from this software
29 * without specific prior written permission.
31 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
32 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
33 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
34 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
35 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
39 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
40 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47 static const char sccsid
[] = "@(#)db_conv.c 10.13 (Sleepycat) 4/26/98";
50 #ifndef NO_SYSTEM_INCLUDES
51 #include <sys/types.h>
62 static int __db_convert
__P((db_pgno_t
, void *, size_t, int));
67 * PUBLIC: int __db_pgin __P((db_pgno_t, size_t, void *));
70 __db_pgin(pg
, pagesize
, pp
)
75 return (__db_convert(pg
, pp
, pagesize
, 1));
81 * PUBLIC: int __db_pgout __P((db_pgno_t, size_t, void *));
84 __db_pgout(pg
, pagesize
, pp
)
89 return (__db_convert(pg
, pp
, pagesize
, 0));
94 * Actually convert a page.
97 __db_convert(pg
, pp
, pagesize
, pgin
)
108 db_indx_t i
, len
, tmp
;
115 M_32_SWAP(h
->lsn
.file
);
116 M_32_SWAP(h
->lsn
.offset
);
118 M_32_SWAP(h
->prev_pgno
);
119 M_32_SWAP(h
->next_pgno
);
120 M_16_SWAP(h
->entries
);
121 M_16_SWAP(h
->hf_offset
);
126 for (i
= 0; i
< NUM_ENT(h
); i
++) {
128 M_16_SWAP(h
->inp
[i
]);
130 switch (HPAGE_TYPE(h
, i
)) {
134 len
= LEN_HKEYDATA(h
, pagesize
, i
);
135 p
= HKEYDATA_DATA(P_ENTRY(h
, i
));
136 for (end
= p
+ len
; p
< end
;) {
140 p
, sizeof(db_indx_t
));
141 p
+= sizeof(db_indx_t
);
144 p
, sizeof(db_indx_t
));
152 p
= HOFFPAGE_PGNO(P_ENTRY(h
, i
));
153 SWAP32(p
); /* pgno */
156 p
= HOFFPAGE_PGNO(P_ENTRY(h
, i
));
157 SWAP32(p
); /* pgno */
158 SWAP32(p
); /* tlen */
165 * The offsets in the inp array are used to determine
166 * the size of entries on a page; therefore they
167 * cannot be converted until we've done all the
171 for (i
= 0; i
< NUM_ENT(h
); i
++)
172 M_16_SWAP(h
->inp
[i
]);
177 for (i
= 0; i
< NUM_ENT(h
); i
++) {
179 M_16_SWAP(h
->inp
[i
]);
181 bk
= GET_BKEYDATA(h
, i
);
182 switch (B_TYPE(bk
->type
)) {
188 bo
= (BOVERFLOW
*)bk
;
195 M_16_SWAP(h
->inp
[i
]);
199 for (i
= 0; i
< NUM_ENT(h
); i
++) {
201 M_16_SWAP(h
->inp
[i
]);
203 bi
= GET_BINTERNAL(h
, i
);
206 M_32_SWAP(bi
->nrecs
);
208 switch (B_TYPE(bi
->type
)) {
213 bo
= (BOVERFLOW
*)bi
->data
;
220 M_16_SWAP(h
->inp
[i
]);
224 for (i
= 0; i
< NUM_ENT(h
); i
++) {
226 M_16_SWAP(h
->inp
[i
]);
228 ri
= GET_RINTERNAL(h
, i
);
230 M_32_SWAP(ri
->nrecs
);
233 M_16_SWAP(h
->inp
[i
]);
245 /* Swap the header information. */
246 M_32_SWAP(h
->lsn
.file
);
247 M_32_SWAP(h
->lsn
.offset
);
249 M_32_SWAP(h
->prev_pgno
);
250 M_32_SWAP(h
->next_pgno
);
251 M_16_SWAP(h
->entries
);
252 M_16_SWAP(h
->hf_offset
);