1 /*- 2 * Copyright (c) 1990 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Mike Olson. 7 * 8 * %sccs.include.redist.c% 9 */ 10 11 #if defined(LIBC_SCCS) && !defined(lint) 12 static char sccsid[] = "@(#)bt_conv.c 5.1 (Berkeley) 09/04/91"; 13 #endif /* LIBC_SCCS and not lint */ 14 15 #include <sys/param.h> 16 #include <db.h> 17 #include <stdio.h> 18 #include "btree.h" 19 20 /* 21 * __BT_BPGIN, __BT_BPGOUT -- 22 * Convert host-specific number layout to/from the host-independent 23 * format stored on disk. 24 * 25 * Parameters: 26 * tree: tree 27 * h: page to convert 28 * 29 * Side Effects: 30 * Layout of tree metadata on the page is changed in place. 31 * 32 * Warnings: 33 * Everywhere else in the code, the types pgno_t and index_t are 34 * opaque. These two routines know what they really are. 35 */ 36 void 37 __bt_pgin(t, pg, p) 38 void *t; 39 pgno_t pg; 40 void *p; 41 { 42 register BINTERNAL *bi; 43 register BLEAF *bl; 44 register int i, top; 45 PAGE *h; 46 47 if (((BTREE *)t)->bt_lorder == BYTE_ORDER) 48 return; 49 50 h = p; 51 BLSWAP(h->pgno); 52 BLSWAP(h->prevpg); 53 BLSWAP(h->nextpg); 54 BLSWAP(h->flags); 55 BLSWAP(h->lower); 56 BLSWAP(h->upper); 57 58 top = NEXTINDEX(h); 59 if (!(h->flags & (P_BLEAF | P_RLEAF))) 60 for (i = 0; i < top; i++) { 61 BLSWAP(h->linp[i]); 62 bi = GETBINTERNAL(h, i); 63 BLSWAP(bi->ksize); 64 BLSWAP(bi->pgno); 65 BLSWAP(bi->flags); 66 if (bi->flags & P_BIGKEY) 67 BLSWAP(*(long *)bi->bytes); 68 } 69 else if (!(h->flags & P_OVERFLOW)) 70 for (i = 0; i < top; i++) { 71 BLSWAP(h->linp[i]); 72 bl = GETBLEAF(h, i); 73 BLSWAP(bl->dsize); 74 BLSWAP(bl->ksize); 75 BLSWAP(bl->flags); 76 if (bl->flags & P_BIGKEY) 77 BLSWAP(*(long *)bl->bytes); 78 if (bl->flags & P_BIGDATA) 79 BLSWAP(*(long *)(bl->bytes + bl->ksize)); 80 } 81 } 82 83 void 84 __bt_pgout(t, pg, p) 85 void *t; 86 pgno_t pg; 87 void *p; 88 { 89 register BINTERNAL *bi; 90 register BLEAF *bl; 91 register int i, top; 92 PAGE *h; 93 94 if (((BTREE *)t)->bt_lorder == BYTE_ORDER) 95 return; 96 97 h = p; 98 top = NEXTINDEX(h); 99 if (!(h->flags & (P_BLEAF | P_RLEAF))) 100 for (i = 0; i < top; i++) { 101 bi = GETBINTERNAL(h, i); 102 BLSWAP(bi->ksize); 103 BLSWAP(bi->pgno); 104 if (bi->flags & P_BIGKEY) 105 BLSWAP(*(long *)bi->bytes); 106 BLSWAP(h->linp[i]); 107 } 108 else if (!(h->flags & P_OVERFLOW)) 109 for (i = 0; i < top; i++) { 110 bl = GETBLEAF(h, i); 111 BLSWAP(bl->ksize); 112 BLSWAP(bl->dsize); 113 if (bl->flags & P_BIGKEY) 114 BLSWAP(*(long *)bl->bytes); 115 if (bl->flags & P_BIGDATA) 116 BLSWAP(*(long *)(bl->bytes + bl->ksize)); 117 BLSWAP(h->linp[i]); 118 } 119 BLSWAP(h->pgno); 120 BLSWAP(h->prevpg); 121 BLSWAP(h->nextpg); 122 BLSWAP(h->flags); 123 BLSWAP(h->lower); 124 BLSWAP(h->upper); 125 } 126