bt_overflow.c File Reference

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

Include dependency graph for bt_overflow.c:

Go to the source code of this file.

Functions

int __ovfl_delete (BTREE *t, void *p)
int __ovfl_get (BTREE *t, void *p, size_t *ssz, void **buf, size_t *bufsz)
int __ovfl_put (BTREE *t, const DBT *dbt, pgno_t *pg)


Function Documentation

int __ovfl_delete ( BTREE t,
void *  p 
)

Definition at line 193 of file bt_overflow.c.

References __bt_free(), BTDATAOFF, _page::flags, h, mpool_get, mpool_put, _page::nextpg, NULL, P_INVALID, P_PRESERVE, RET_ERROR, and RET_SUCCESS.

Referenced by __bt_dleaf(), __bt_pdelete(), and __rec_dleaf().

00196 {
00197    PAGE *h;
00198    pgno_t pg;
00199    size_t plen;
00200    u_int32_t sz;
00201 
00202    memmove(&pg, p, sizeof(pgno_t));
00203    memmove(&sz, (char *)p + sizeof(pgno_t), sizeof(u_int32_t));
00204 
00205 #ifdef DEBUG
00206    if (pg == P_INVALID || sz == 0)
00207       abort();
00208 #endif
00209    if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL)
00210       return (RET_ERROR);
00211 
00212    /* Don't delete chains used by internal pages. */
00213    if (h->flags & P_PRESERVE) {
00214       mpool_put(t->bt_mp, h, 0);
00215       return (RET_SUCCESS);
00216    }
00217 
00218    /* Step through the chain, calling the free routine for each page. */
00219    for (plen = t->bt_psize - BTDATAOFF;; sz -= plen) {
00220       pg = h->nextpg;
00221       __bt_free(t, h);
00222       if (sz <= plen)
00223          break;
00224       if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL)
00225          return (RET_ERROR);
00226    }
00227    return (RET_SUCCESS);
00228 }

int __ovfl_get ( BTREE t,
void *  p,
size_t *  ssz,
void **  buf,
size_t *  bufsz 
)

Definition at line 80 of file bt_overflow.c.

References BTDATAOFF, h, malloc, MIN, mpool_get, mpool_put, _page::nextpg, NULL, P_INVALID, realloc, RET_ERROR, and RET_SUCCESS.

Referenced by __bt_cmp(), __bt_ret(), and __rec_ret().

00086 {
00087    PAGE *h;
00088    pgno_t pg;
00089    size_t nb, plen;
00090    u_int32_t sz;
00091 
00092    memmove(&pg, p, sizeof(pgno_t));
00093    memmove(&sz, (char *)p + sizeof(pgno_t), sizeof(u_int32_t));
00094    *ssz = sz;
00095 
00096 #ifdef DEBUG
00097    if (pg == P_INVALID || sz == 0)
00098       abort();
00099 #endif
00100    /* Make the buffer bigger as necessary. */
00101    if (*bufsz < sz) {
00102       *buf = (char *)(*buf == NULL ? malloc(sz) : realloc(*buf, sz));
00103       if (*buf == NULL)
00104          return (RET_ERROR);
00105       *bufsz = sz;
00106    }
00107 
00108    /*
00109     * Step through the linked list of pages, copying the data on each one
00110     * into the buffer.  Never copy more than the data's length.
00111     */
00112    plen = t->bt_psize - BTDATAOFF;
00113    for (p = *buf;; p = (char *)p + nb, pg = h->nextpg) {
00114       if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL)
00115          return (RET_ERROR);
00116 
00117       nb = MIN(sz, plen);
00118       memmove(p, (char *)h + BTDATAOFF, nb);
00119       mpool_put(t->bt_mp, h, 0);
00120 
00121       if ((sz -= nb) == 0)
00122          break;
00123    }
00124    return (RET_SUCCESS);
00125 }

int __ovfl_put ( BTREE t,
const DBT dbt,
pgno_t pg 
)

Definition at line 139 of file bt_overflow.c.

References __bt_new(), BTDATAOFF, DBT::data, _page::flags, h, last, _page::lower, MIN, MPOOL_DIRTY, mpool_put, _page::nextpg, NULL, P_INVALID, P_OVERFLOW, _page::pgno, _page::prevpg, RET_ERROR, RET_SUCCESS, DBT::size, and _page::upper.

Referenced by __bt_put(), and __rec_iput().

00143 {
00144    PAGE *h, *last;
00145    void *p;
00146    pgno_t npg;
00147    size_t nb, plen;
00148    u_int32_t sz;
00149 
00150    /*
00151     * Allocate pages and copy the key/data record into them.  Store the
00152     * number of the first page in the chain.
00153     */
00154    plen = t->bt_psize - BTDATAOFF;
00155    for (last = NULL, p = dbt->data, sz = dbt->size;;
00156        p = (char *)p + plen, last = h) {
00157       if ((h = __bt_new(t, &npg)) == NULL)
00158          return (RET_ERROR);
00159 
00160       h->pgno = npg;
00161       h->nextpg = h->prevpg = P_INVALID;
00162       h->flags = P_OVERFLOW;
00163       h->lower = h->upper = 0;
00164 
00165       nb = MIN(sz, plen);
00166       memmove((char *)h + BTDATAOFF, p, nb);
00167 
00168       if (last) {
00169          last->nextpg = h->pgno;
00170          mpool_put(t->bt_mp, last, MPOOL_DIRTY);
00171       } else
00172          *pg = h->pgno;
00173 
00174       if ((sz -= nb) == 0) {
00175          mpool_put(t->bt_mp, h, MPOOL_DIRTY);
00176          break;
00177       }
00178    }
00179    return (RET_SUCCESS);
00180 }


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