00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #include "config.h"
00041
00042 #ifndef lint
00043 static const char revid[] = "$Id: db__conv_8c-source.html,v 1.1 2008/06/08 10:17:24 sebdiaz Exp $";
00044 #endif
00045
00046 #ifndef NO_SYSTEM_INCLUDES
00047 #include <sys/types.h>
00048
00049 #include <errno.h>
00050 #include <string.h>
00051 #endif
00052
00053 #include "db_int.h"
00054 #include "db_page.h"
00055 #include "db_swap.h"
00056 #include "db_am.h"
00057 #include "btree.h"
00058 #include "hash.h"
00059 #include "qam.h"
00060
00061
00062
00063
00064
00065
00066
00067 int
00068 CDB___db_pgin(dbenv, pg, pp, cookie)
00069 DB_ENV *dbenv;
00070 db_pgno_t pg;
00071 void *pp;
00072 DBT *cookie;
00073 {
00074 DB_PGINFO *pginfo;
00075
00076 pginfo = (DB_PGINFO *)cookie->data;
00077
00078 switch (TYPE(pp)) {
00079 case P_HASH:
00080 case P_HASHMETA:
00081 case P_INVALID:
00082 return (CDB___ham_pgin(dbenv, pg, pp, cookie));
00083 case P_BTREEMETA:
00084 case P_IBTREE:
00085 case P_IRECNO:
00086 case P_LBTREE:
00087 case P_LDUP:
00088 case P_LRECNO:
00089 case P_OVERFLOW:
00090 return (CDB___bam_pgin(dbenv, pg, pp, cookie));
00091 case P_QAMMETA:
00092 case P_QAMDATA:
00093 return (CDB___qam_pgin_out(dbenv, pg, pp, cookie));
00094 default:
00095 break;
00096 }
00097 return (CDB___db_unknown_type(dbenv, "CDB___db_pgin", ((PAGE *)pp)->type));
00098 }
00099
00100
00101
00102
00103
00104
00105
00106 int
00107 CDB___db_pgout(dbenv, pg, pp, cookie)
00108 DB_ENV *dbenv;
00109 db_pgno_t pg;
00110 void *pp;
00111 DBT *cookie;
00112 {
00113 DB_PGINFO *pginfo;
00114
00115 pginfo = (DB_PGINFO *)cookie->data;
00116
00117 switch (TYPE(pp)) {
00118 case P_HASH:
00119 case P_HASHMETA:
00120 case P_INVALID:
00121 return (CDB___ham_pgout(dbenv, pg, pp, cookie));
00122 case P_BTREEMETA:
00123 case P_IBTREE:
00124 case P_IRECNO:
00125 case P_LBTREE:
00126 case P_LDUP:
00127 case P_LRECNO:
00128 case P_OVERFLOW:
00129 return (CDB___bam_pgout(dbenv, pg, pp, cookie));
00130 case P_QAMMETA:
00131 case P_QAMDATA:
00132 return (CDB___qam_pgin_out(dbenv, pg, pp, cookie));
00133 default:
00134 break;
00135 }
00136 return (CDB___db_unknown_type(dbenv, "CDB___db_pgout", ((PAGE *)pp)->type));
00137 }
00138
00139
00140
00141
00142
00143
00144
00145 void
00146 CDB___db_metaswap(pg)
00147 PAGE *pg;
00148 {
00149 u_int8_t *p;
00150
00151 p = (u_int8_t *)pg;
00152
00153
00154 SWAP32(p);
00155 SWAP32(p);
00156 SWAP32(p);
00157 SWAP32(p);
00158 SWAP32(p);
00159 SWAP32(p);
00160 p += 4;
00161 SWAP32(p);
00162 SWAP32(p);
00163 SWAP32(p);
00164 SWAP32(p);
00165 SWAP32(p);
00166 SWAP32(p);
00167 }
00168
00169
00170
00171
00172
00173
00174
00175 int
00176 CDB___db_byteswap(dbenv, pg, h, pagesize, pgin)
00177 DB_ENV *dbenv;
00178 db_pgno_t pg;
00179 PAGE *h;
00180 size_t pagesize;
00181 int pgin;
00182 {
00183 BINTERNAL *bi;
00184 BKEYDATA *bk;
00185 BOVERFLOW *bo;
00186 RINTERNAL *ri;
00187 db_indx_t i, len, tmp;
00188 u_int8_t *p, *end;
00189
00190 COMPQUIET(pg, 0);
00191
00192 if (pgin) {
00193 M_32_SWAP(h->lsn.file);
00194 M_32_SWAP(h->lsn.offset);
00195 M_32_SWAP(h->pgno);
00196 M_32_SWAP(h->prev_pgno);
00197 M_32_SWAP(h->next_pgno);
00198 M_16_SWAP(h->entries);
00199 M_16_SWAP(h->hf_offset);
00200 }
00201
00202 switch (TYPE(h)) {
00203 case P_HASH:
00204 for (i = 0; i < NUM_ENT(h); i++) {
00205 if (pgin)
00206 M_16_SWAP(h->inp[i]);
00207
00208 switch (HPAGE_TYPE(h, i)) {
00209 case H_KEYDATA:
00210 break;
00211 case H_DUPLICATE:
00212 len = LEN_HKEYDATA(h, pagesize, i);
00213 p = HKEYDATA_DATA(P_ENTRY(h, i));
00214 for (end = p + len; p < end;) {
00215 if (pgin) {
00216 P_16_SWAP(p);
00217 memcpy(&tmp,
00218 p, sizeof(db_indx_t));
00219 p += sizeof(db_indx_t);
00220 } else {
00221 memcpy(&tmp,
00222 p, sizeof(db_indx_t));
00223 SWAP16(p);
00224 }
00225 p += tmp;
00226 SWAP16(p);
00227 }
00228 break;
00229 case H_OFFDUP:
00230 p = HOFFPAGE_PGNO(P_ENTRY(h, i));
00231 SWAP32(p);
00232 break;
00233 case H_OFFPAGE:
00234 p = HOFFPAGE_PGNO(P_ENTRY(h, i));
00235 SWAP32(p);
00236 SWAP32(p);
00237 break;
00238 }
00239
00240 }
00241
00242
00243
00244
00245
00246
00247
00248 if (!pgin)
00249 for (i = 0; i < NUM_ENT(h); i++)
00250 M_16_SWAP(h->inp[i]);
00251 break;
00252 case P_LBTREE:
00253 case P_LDUP:
00254 case P_LRECNO:
00255 for (i = 0; i < NUM_ENT(h); i++) {
00256 if (pgin)
00257 M_16_SWAP(h->inp[i]);
00258
00259
00260
00261
00262
00263 if (TYPE(h) == P_LBTREE && i > 1) {
00264 if (pgin) {
00265 if (h->inp[i] == h->inp[i - 2])
00266 continue;
00267 } else {
00268 M_16_SWAP(h->inp[i]);
00269 if (h->inp[i] == h->inp[i - 2])
00270 continue;
00271 M_16_SWAP(h->inp[i]);
00272 }
00273 }
00274
00275 bk = GET_BKEYDATA(h, i);
00276 switch (B_TYPE(bk->type)) {
00277 case B_KEYDATA:
00278 M_16_SWAP(bk->len);
00279 break;
00280 case B_DUPLICATE:
00281 case B_OVERFLOW:
00282 bo = (BOVERFLOW *)bk;
00283 M_32_SWAP(bo->pgno);
00284 M_32_SWAP(bo->tlen);
00285 break;
00286 }
00287
00288 if (!pgin)
00289 M_16_SWAP(h->inp[i]);
00290 }
00291 break;
00292 case P_IBTREE:
00293 for (i = 0; i < NUM_ENT(h); i++) {
00294 if (pgin)
00295 M_16_SWAP(h->inp[i]);
00296
00297 bi = GET_BINTERNAL(h, i);
00298 M_16_SWAP(bi->len);
00299 M_32_SWAP(bi->pgno);
00300 M_32_SWAP(bi->nrecs);
00301
00302 switch (B_TYPE(bi->type)) {
00303 case B_KEYDATA:
00304 break;
00305 case B_DUPLICATE:
00306 case B_OVERFLOW:
00307 bo = (BOVERFLOW *)bi->data;
00308 M_32_SWAP(bo->pgno);
00309 M_32_SWAP(bo->tlen);
00310 break;
00311 }
00312
00313 if (!pgin)
00314 M_16_SWAP(h->inp[i]);
00315 }
00316 break;
00317 case P_IRECNO:
00318 for (i = 0; i < NUM_ENT(h); i++) {
00319 if (pgin)
00320 M_16_SWAP(h->inp[i]);
00321
00322 ri = GET_RINTERNAL(h, i);
00323 M_32_SWAP(ri->pgno);
00324 M_32_SWAP(ri->nrecs);
00325
00326 if (!pgin)
00327 M_16_SWAP(h->inp[i]);
00328 }
00329 break;
00330 case P_OVERFLOW:
00331 case P_INVALID:
00332
00333 break;
00334 default:
00335 return (CDB___db_unknown_type(dbenv, "CDB___db_byteswap", h->type));
00336 }
00337
00338 if (!pgin) {
00339
00340 M_32_SWAP(h->lsn.file);
00341 M_32_SWAP(h->lsn.offset);
00342 M_32_SWAP(h->pgno);
00343 M_32_SWAP(h->prev_pgno);
00344 M_32_SWAP(h->next_pgno);
00345 M_16_SWAP(h->entries);
00346 M_16_SWAP(h->hf_offset);
00347 }
00348 return (0);
00349 }