bt_conv.c File Reference

#include <sys/param.h>
#include <stdio.h>
#include "../include/db.h"
#include "btree.h"

Include dependency graph for bt_conv.c:

Go to the source code of this file.

Functions

void __bt_pgin (void *t, pgno_t pg, void *pp)
void __bt_pgout (void *t, pgno_t pg, void *pp)
static void mswap __P ((PAGE *))
static void mswap (PAGE *pg)


Function Documentation

void __bt_pgin ( void *  t,
pgno_t  pg,
void *  pp 
)

Definition at line 61 of file bt_conv.c.

References B_NEEDSWAP, F_ISSET, _page::flags, GETBINTERNAL, GETBLEAF, h, _page::linp, _page::lower, mswap(), NEXTINDEX, _page::nextpg, P_BIGDATA, P_BIGKEY, P_BINTERNAL, P_BLEAF, P_META, P_TYPE, _page::pgno, _page::prevpg, and _page::upper.

Referenced by __bt_open().

00065 {
00066    PAGE *h;
00067    indx_t i, top;
00068    u_char flags;
00069    char *p;
00070 
00071    if (!F_ISSET(((BTREE *)t), B_NEEDSWAP))
00072       return;
00073    if (pg == P_META) {
00074       mswap(pp);
00075       return;
00076    }
00077 
00078    h = pp;
00079    M_32_SWAP(h->pgno);
00080    M_32_SWAP(h->prevpg);
00081    M_32_SWAP(h->nextpg);
00082    M_32_SWAP(h->flags);
00083    M_16_SWAP(h->lower);
00084    M_16_SWAP(h->upper);
00085 
00086    top = NEXTINDEX(h);
00087    if ((h->flags & P_TYPE) == P_BINTERNAL)
00088       for (i = 0; i < top; i++) {
00089          M_16_SWAP(h->linp[i]);
00090          p = (char *)GETBINTERNAL(h, i);
00091          P_32_SWAP(p);
00092          p += sizeof(u_int32_t);
00093          P_32_SWAP(p);
00094          p += sizeof(pgno_t);
00095          if (*(u_char *)p & P_BIGKEY) {
00096             p += sizeof(u_char);
00097             P_32_SWAP(p);
00098             p += sizeof(pgno_t);
00099             P_32_SWAP(p);
00100          }
00101       }
00102    else if ((h->flags & P_TYPE) == P_BLEAF)
00103       for (i = 0; i < top; i++) {
00104          M_16_SWAP(h->linp[i]);
00105          p = (char *)GETBLEAF(h, i);
00106          P_32_SWAP(p);
00107          p += sizeof(u_int32_t);
00108          P_32_SWAP(p);
00109          p += sizeof(u_int32_t);
00110          flags = *(u_char *)p;
00111          if (flags & (P_BIGKEY | P_BIGDATA)) {
00112             p += sizeof(u_char);
00113             if (flags & P_BIGKEY) {
00114                P_32_SWAP(p);
00115                p += sizeof(pgno_t);
00116                P_32_SWAP(p);
00117             }
00118             if (flags & P_BIGDATA) {
00119                p += sizeof(u_int32_t);
00120                P_32_SWAP(p);
00121                p += sizeof(pgno_t);
00122                P_32_SWAP(p);
00123             }
00124          }
00125       }
00126 }

void __bt_pgout ( void *  t,
pgno_t  pg,
void *  pp 
)

Definition at line 129 of file bt_conv.c.

References B_NEEDSWAP, F_ISSET, _page::flags, GETBINTERNAL, GETBLEAF, h, _page::linp, _page::lower, mswap(), NEXTINDEX, _page::nextpg, P_BIGDATA, P_BIGKEY, P_BINTERNAL, P_BLEAF, P_META, P_TYPE, _page::pgno, _page::prevpg, and _page::upper.

Referenced by __bt_open().

00133 {
00134    PAGE *h;
00135    indx_t i, top;
00136    u_char flags;
00137    char *p;
00138 
00139    if (!F_ISSET(((BTREE *)t), B_NEEDSWAP))
00140       return;
00141    if (pg == P_META) {
00142       mswap(pp);
00143       return;
00144    }
00145 
00146    h = pp;
00147    top = NEXTINDEX(h);
00148    if ((h->flags & P_TYPE) == P_BINTERNAL)
00149       for (i = 0; i < top; i++) {
00150          p = (char *)GETBINTERNAL(h, i);
00151          P_32_SWAP(p);
00152          p += sizeof(u_int32_t);
00153          P_32_SWAP(p);
00154          p += sizeof(pgno_t);
00155          if (*(u_char *)p & P_BIGKEY) {
00156             p += sizeof(u_char);
00157             P_32_SWAP(p);
00158             p += sizeof(pgno_t);
00159             P_32_SWAP(p);
00160          }
00161          M_16_SWAP(h->linp[i]);
00162       }
00163    else if ((h->flags & P_TYPE) == P_BLEAF)
00164       for (i = 0; i < top; i++) {
00165          p = (char *)GETBLEAF(h, i);
00166          P_32_SWAP(p);
00167          p += sizeof(u_int32_t);
00168          P_32_SWAP(p);
00169          p += sizeof(u_int32_t);
00170          flags = *(u_char *)p;
00171          if (flags & (P_BIGKEY | P_BIGDATA)) {
00172             p += sizeof(u_char);
00173             if (flags & P_BIGKEY) {
00174                P_32_SWAP(p);
00175                p += sizeof(pgno_t);
00176                P_32_SWAP(p);
00177             }
00178             if (flags & P_BIGDATA) {
00179                p += sizeof(u_int32_t);
00180                P_32_SWAP(p);
00181                p += sizeof(pgno_t);
00182                P_32_SWAP(p);
00183             }
00184          }
00185          M_16_SWAP(h->linp[i]);
00186       }
00187 
00188    M_32_SWAP(h->pgno);
00189    M_32_SWAP(h->prevpg);
00190    M_32_SWAP(h->nextpg);
00191    M_32_SWAP(h->flags);
00192    M_16_SWAP(h->lower);
00193    M_16_SWAP(h->upper);
00194 }

static void mswap __P ( (PAGE *)   )  [static]

static void mswap ( PAGE pg  )  [static]

Definition at line 203 of file bt_conv.c.

Referenced by __bt_pgin(), and __bt_pgout().

00205 {
00206    char *p;
00207 
00208    p = (char *)pg;
00209    P_32_SWAP(p);     /* magic */
00210    p += sizeof(u_int32_t);
00211    P_32_SWAP(p);     /* version */
00212    p += sizeof(u_int32_t);
00213    P_32_SWAP(p);     /* psize */
00214    p += sizeof(u_int32_t);
00215    P_32_SWAP(p);     /* free */
00216    p += sizeof(u_int32_t);
00217    P_32_SWAP(p);     /* nrecs */
00218    p += sizeof(u_int32_t);
00219    P_32_SWAP(p);     /* flags */
00220    p += sizeof(u_int32_t);
00221 }


Generated on Thu Apr 16 06:29:14 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6