]>
git.ipfire.org Git - thirdparty/glibc.git/blob - db2/db/db_conv.c
2 * See the file LICENSE for redistribution information.
4 * Copyright (c) 1996, 1997
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.8 (Sleepycat) 1/8/98";
50 #ifndef NO_SYSTEM_INCLUDES
51 #include <sys/types.h>
61 static int __db_convert
__P((db_pgno_t
, void *, size_t, int));
66 * PUBLIC: int __db_pgin __P((db_pgno_t, size_t, void *));
69 __db_pgin(pg
, pagesize
, pp
)
74 return (__db_convert(pg
, pp
, pagesize
, 1));
80 * PUBLIC: int __db_pgout __P((db_pgno_t, size_t, void *));
83 __db_pgout(pg
, pagesize
, pp
)
88 return (__db_convert(pg
, pp
, pagesize
, 0));
93 * Actually convert a page.
96 __db_convert(pg
, pp
, pagesize
, pgin
)
107 db_indx_t i
, len
, tmp
;
114 M_32_SWAP(h
->lsn
.file
);
115 M_32_SWAP(h
->lsn
.offset
);
117 M_32_SWAP(h
->prev_pgno
);
118 M_32_SWAP(h
->next_pgno
);
119 M_16_SWAP(h
->entries
);
120 M_16_SWAP(h
->hf_offset
);
125 for (i
= 0; i
< NUM_ENT(h
); i
++) {
127 M_16_SWAP(h
->inp
[i
]);
129 switch (HPAGE_TYPE(h
, i
)) {
133 len
= LEN_HKEYDATA(h
, pagesize
, i
);
134 p
= HKEYDATA_DATA(P_ENTRY(h
, i
));
135 for (end
= p
+ len
; p
< end
;) {
139 p
, sizeof(db_indx_t
));
140 p
+= sizeof(db_indx_t
);
143 p
, sizeof(db_indx_t
));
151 p
= HOFFPAGE_PGNO(P_ENTRY(h
, i
));
152 SWAP32(p
); /* pgno */
155 p
= HOFFPAGE_PGNO(P_ENTRY(h
, i
));
156 SWAP32(p
); /* pgno */
157 SWAP32(p
); /* tlen */
163 for (i
= 0; i
< NUM_ENT(h
); i
++)
164 M_16_SWAP(h
->inp
[i
]);
169 for (i
= 0; i
< NUM_ENT(h
); i
++) {
171 M_16_SWAP(h
->inp
[i
]);
173 bk
= GET_BKEYDATA(h
, i
);
174 switch (B_TYPE(bk
->type
)) {
180 bo
= (BOVERFLOW
*)bk
;
187 M_16_SWAP(h
->inp
[i
]);
191 for (i
= 0; i
< NUM_ENT(h
); i
++) {
193 M_16_SWAP(h
->inp
[i
]);
195 bi
= GET_BINTERNAL(h
, i
);
196 switch (B_TYPE(bi
->type
)) {
200 M_32_SWAP(bi
->nrecs
);
204 bo
= (BOVERFLOW
*)bi
;
211 M_16_SWAP(h
->inp
[i
]);
215 for (i
= 0; i
< NUM_ENT(h
); i
++) {
217 M_16_SWAP(h
->inp
[i
]);
219 ri
= GET_RINTERNAL(h
, i
);
221 M_32_SWAP(ri
->nrecs
);
224 M_16_SWAP(h
->inp
[i
]);
235 /* Swap the header information. */
236 M_32_SWAP(h
->lsn
.file
);
237 M_32_SWAP(h
->lsn
.offset
);
239 M_32_SWAP(h
->prev_pgno
);
240 M_32_SWAP(h
->next_pgno
);
241 M_16_SWAP(h
->entries
);
242 M_16_SWAP(h
->hf_offset
);