| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
#if defined(LIBC_SCCS) && !defined(lint) |
| 38 |
static char sccsid[] = "@(#)bt_conv.c 8.5 (Berkeley) 8/17/94"; |
| 39 |
#endif |
| 40 |
|
| 41 |
#include <sys/param.h> |
| 42 |
|
| 43 |
#include <stdio.h> |
| 44 |
|
| 45 |
#include "../include/db.h" |
| 46 |
#include "btree.h" |
| 47 |
|
| 48 |
static void mswap __P((PAGE *)); |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
void |
| 61 |
__bt_pgin(t, pg, pp) |
| 62 |
void *t; |
| 63 |
pgno_t pg; |
| 64 |
void *pp; |
| 65 |
{ |
| 66 |
PAGE *h; |
| 67 |
indx_t i, top; |
| 68 |
u_char flags; |
| 69 |
char *p; |
| 70 |
|
| 71 |
if (!F_ISSET(((BTREE *)t), B_NEEDSWAP)) |
| 72 |
return; |
| 73 |
if (pg == P_META) { |
| 74 |
mswap(pp); |
| 75 |
return; |
| 76 |
} |
| 77 |
|
| 78 |
h = pp; |
| 79 |
M_32_SWAP(h->pgno); |
| 80 |
M_32_SWAP(h->prevpg); |
| 81 |
M_32_SWAP(h->nextpg); |
| 82 |
M_32_SWAP(h->flags); |
| 83 |
M_16_SWAP(h->lower); |
| 84 |
M_16_SWAP(h->upper); |
| 85 |
|
| 86 |
top = NEXTINDEX(h); |
| 87 |
if ((h->flags & P_TYPE) == P_BINTERNAL) |
| 88 |
for (i = 0; i < top; i++) { |
| 89 |
M_16_SWAP(h->linp[i]); |
| 90 |
p = (char *)GETBINTERNAL(h, i); |
| 91 |
P_32_SWAP(p); |
| 92 |
p += sizeof(u_int32_t); |
| 93 |
P_32_SWAP(p); |
| 94 |
p += sizeof(pgno_t); |
| 95 |
if (*(u_char *)p & P_BIGKEY) { |
| 96 |
p += sizeof(u_char); |
| 97 |
P_32_SWAP(p); |
| 98 |
p += sizeof(pgno_t); |
| 99 |
P_32_SWAP(p); |
| 100 |
} |
| 101 |
} |
| 102 |
else if ((h->flags & P_TYPE) == P_BLEAF) |
| 103 |
for (i = 0; i < top; i++) { |
| 104 |
M_16_SWAP(h->linp[i]); |
| 105 |
p = (char *)GETBLEAF(h, i); |
| 106 |
P_32_SWAP(p); |
| 107 |
p += sizeof(u_int32_t); |
| 108 |
P_32_SWAP(p); |
| 109 |
p += sizeof(u_int32_t); |
| 110 |
flags = *(u_char *)p; |
| 111 |
if (flags & (P_BIGKEY | P_BIGDATA)) { |
| 112 |
p += sizeof(u_char); |
| 113 |
if (flags & P_BIGKEY) { |
| 114 |
P_32_SWAP(p); |
| 115 |
p += sizeof(pgno_t); |
| 116 |
P_32_SWAP(p); |
| 117 |
} |
| 118 |
if (flags & P_BIGDATA) { |
| 119 |
p += sizeof(u_int32_t); |
| 120 |
P_32_SWAP(p); |
| 121 |
p += sizeof(pgno_t); |
| 122 |
P_32_SWAP(p); |
| 123 |
} |
| 124 |
} |
| 125 |
} |
| 126 |
} |
| 127 |
|
| 128 |
void |
| 129 |
__bt_pgout(t, pg, pp) |
| 130 |
void *t; |
| 131 |
pgno_t pg; |
| 132 |
void *pp; |
| 133 |
{ |
| 134 |
PAGE *h; |
| 135 |
indx_t i, top; |
| 136 |
u_char flags; |
| 137 |
char *p; |
| 138 |
|
| 139 |
if (!F_ISSET(((BTREE *)t), B_NEEDSWAP)) |
| 140 |
return; |
| 141 |
if (pg == P_META) { |
| 142 |
mswap(pp); |
| 143 |
return; |
| 144 |
} |
| 145 |
|
| 146 |
h = pp; |
| 147 |
top = NEXTINDEX(h); |
| 148 |
if ((h->flags & P_TYPE) == P_BINTERNAL) |
| 149 |
for (i = 0; i < top; i++) { |
| 150 |
p = (char *)GETBINTERNAL(h, i); |
| 151 |
P_32_SWAP(p); |
| 152 |
p += sizeof(u_int32_t); |
| 153 |
P_32_SWAP(p); |
| 154 |
p += sizeof(pgno_t); |
| 155 |
if (*(u_char *)p & P_BIGKEY) { |
| 156 |
p += sizeof(u_char); |
| 157 |
P_32_SWAP(p); |
| 158 |
p += sizeof(pgno_t); |
| 159 |
P_32_SWAP(p); |
| 160 |
} |
| 161 |
M_16_SWAP(h->linp[i]); |
| 162 |
} |
| 163 |
else if ((h->flags & P_TYPE) == P_BLEAF) |
| 164 |
for (i = 0; i < top; i++) { |
| 165 |
p = (char *)GETBLEAF(h, i); |
| 166 |
P_32_SWAP(p); |
| 167 |
p += sizeof(u_int32_t); |
| 168 |
P_32_SWAP(p); |
| 169 |
p += sizeof(u_int32_t); |
| 170 |
flags = *(u_char *)p; |
| 171 |
if (flags & (P_BIGKEY | P_BIGDATA)) { |
| 172 |
p += sizeof(u_char); |
| 173 |
if (flags & P_BIGKEY) { |
| 174 |
P_32_SWAP(p); |
| 175 |
p += sizeof(pgno_t); |
| 176 |
P_32_SWAP(p); |
| 177 |
} |
| 178 |
if (flags & P_BIGDATA) { |
| 179 |
p += sizeof(u_int32_t); |
| 180 |
P_32_SWAP(p); |
| 181 |
p += sizeof(pgno_t); |
| 182 |
P_32_SWAP(p); |
| 183 |
} |
| 184 |
} |
| 185 |
M_16_SWAP(h->linp[i]); |
| 186 |
} |
| 187 |
|
| 188 |
M_32_SWAP(h->pgno); |
| 189 |
M_32_SWAP(h->prevpg); |
| 190 |
M_32_SWAP(h->nextpg); |
| 191 |
M_32_SWAP(h->flags); |
| 192 |
M_16_SWAP(h->lower); |
| 193 |
M_16_SWAP(h->upper); |
| 194 |
} |
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
static void |
| 203 |
mswap(pg) |
| 204 |
PAGE *pg; |
| 205 |
{ |
| 206 |
char *p; |
| 207 |
|
| 208 |
p = (char *)pg; |
| 209 |
P_32_SWAP(p); |
| 210 |
p += sizeof(u_int32_t); |
| 211 |
P_32_SWAP(p); |
| 212 |
p += sizeof(u_int32_t); |
| 213 |
P_32_SWAP(p); |
| 214 |
p += sizeof(u_int32_t); |
| 215 |
P_32_SWAP(p); |
| 216 |
p += sizeof(u_int32_t); |
| 217 |
P_32_SWAP(p); |
| 218 |
p += sizeof(u_int32_t); |
| 219 |
P_32_SWAP(p); |
| 220 |
p += sizeof(u_int32_t); |
| 221 |
} |