]>
git.ipfire.org Git - thirdparty/glibc.git/blob - db2/db/db_conv.c
8eccc2e602718e343aa69c943ab3f8c4c91accac
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.7 (Sleepycat) 9/21/97";
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
)
97 db_pgno_t pg
; /* Unused, but left for the future. */
107 db_indx_t i
, len
, tmp
;
112 M_32_SWAP(h
->lsn
.file
);
113 M_32_SWAP(h
->lsn
.offset
);
115 M_32_SWAP(h
->prev_pgno
);
116 M_32_SWAP(h
->next_pgno
);
117 M_16_SWAP(h
->entries
);
118 M_16_SWAP(h
->hf_offset
);
123 for (i
= 0; i
< NUM_ENT(h
); i
++) {
125 M_16_SWAP(h
->inp
[i
]);
127 switch (HPAGE_TYPE(h
, i
)) {
131 len
= LEN_HKEYDATA(h
, pagesize
, i
);
132 p
= HKEYDATA_DATA(P_ENTRY(h
, i
));
133 for (end
= p
+ len
; p
< end
;) {
137 p
, sizeof(db_indx_t
));
138 p
+= sizeof(db_indx_t
);
141 p
, sizeof(db_indx_t
));
149 p
= HOFFPAGE_PGNO(P_ENTRY(h
, i
));
150 SWAP32(p
); /* pgno */
153 p
= HOFFPAGE_PGNO(P_ENTRY(h
, i
));
154 SWAP32(p
); /* pgno */
155 SWAP32(p
); /* tlen */
161 for (i
= 0; i
< NUM_ENT(h
); i
++)
162 M_16_SWAP(h
->inp
[i
]);
167 for (i
= 0; i
< NUM_ENT(h
); i
++) {
169 M_16_SWAP(h
->inp
[i
]);
171 bk
= GET_BKEYDATA(h
, i
);
172 switch (B_TYPE(bk
->type
)) {
178 bo
= (BOVERFLOW
*)bk
;
185 M_16_SWAP(h
->inp
[i
]);
189 for (i
= 0; i
< NUM_ENT(h
); i
++) {
191 M_16_SWAP(h
->inp
[i
]);
193 bi
= GET_BINTERNAL(h
, i
);
194 switch (B_TYPE(bi
->type
)) {
198 M_32_SWAP(bi
->nrecs
);
202 bo
= (BOVERFLOW
*)bi
;
209 M_16_SWAP(h
->inp
[i
]);
213 for (i
= 0; i
< NUM_ENT(h
); i
++) {
215 M_16_SWAP(h
->inp
[i
]);
217 ri
= GET_RINTERNAL(h
, i
);
219 M_32_SWAP(ri
->nrecs
);
222 M_16_SWAP(h
->inp
[i
]);
233 /* Swap the header information. */
234 M_32_SWAP(h
->lsn
.file
);
235 M_32_SWAP(h
->lsn
.offset
);
237 M_32_SWAP(h
->prev_pgno
);
238 M_32_SWAP(h
->next_pgno
);
239 M_16_SWAP(h
->entries
);
240 M_16_SWAP(h
->hf_offset
);