Asterisk - The Open Source Telephony Project  18.5.0
Functions
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

◆ __ovfl_delete()

int __ovfl_delete ( BTREE t,
void *  p 
)

Definition at line 193 of file bt_overflow.c.

References __bt_free(), _btree::bt_mp, _btree::bt_psize, BTDATAOFF, _page::flags, 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().

196 {
197  PAGE *h;
198  pgno_t pg;
199  size_t plen;
200  u_int32_t sz;
201 
202  memmove(&pg, p, sizeof(pgno_t));
203  memmove(&sz, (char *)p + sizeof(pgno_t), sizeof(u_int32_t));
204 
205 #ifdef DEBUG
206  if (pg == P_INVALID || sz == 0)
207  abort();
208 #endif
209  if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL)
210  return (RET_ERROR);
211 
212  /* Don't delete chains used by internal pages. */
213  if (h->flags & P_PRESERVE) {
214  mpool_put(t->bt_mp, h, 0);
215  return (RET_SUCCESS);
216  }
217 
218  /* Step through the chain, calling the free routine for each page. */
219  for (plen = t->bt_psize - BTDATAOFF;; sz -= plen) {
220  pg = h->nextpg;
221  __bt_free(t, h);
222  if (sz <= plen)
223  break;
224  if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL)
225  return (RET_ERROR);
226  }
227  return (RET_SUCCESS);
228 }
Definition: btree.h:75
#define P_PRESERVE
Definition: btree.h:86
#define RET_ERROR
Definition: db.h:51
int mpool_put(MPOOL *mp, void *page, u_int flags)
Definition: mpool.c:251
#define NULL
Definition: resample.c:96
void * mpool_get(MPOOL *mp, pgno_t pgno, u_int flags)
Definition: mpool.c:165
int __bt_free(BTREE *t, PAGE *h)
Definition: bt_page.c:60
u_int32_t flags
Definition: btree.h:87
#define RET_SUCCESS
Definition: db.h:52
MPOOL * bt_mp
Definition: btree.h:313
u_int32_t pgno_t
Definition: db.h:78
pgno_t nextpg
Definition: btree.h:78
u_int32_t bt_psize
Definition: btree.h:338
unsigned int u_int32_t
#define P_INVALID
Definition: btree.h:63
#define BTDATAOFF
Definition: btree.h:95

◆ __ovfl_get()

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 _btree::bt_mp, _btree::bt_psize, BTDATAOFF, buf, 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().

86 {
87  PAGE *h;
88  pgno_t pg;
89  size_t nb, plen;
90  u_int32_t sz;
91 
92  memmove(&pg, p, sizeof(pgno_t));
93  memmove(&sz, (char *)p + sizeof(pgno_t), sizeof(u_int32_t));
94  *ssz = sz;
95 
96 #ifdef DEBUG
97  if (pg == P_INVALID || sz == 0)
98  abort();
99 #endif
100  /* Make the buffer bigger as necessary. */
101  if (*bufsz < sz) {
102  *buf = (char *)(*buf == NULL ? malloc(sz) : realloc(*buf, sz));
103  if (*buf == NULL)
104  return (RET_ERROR);
105  *bufsz = sz;
106  }
107 
108  /*
109  * Step through the linked list of pages, copying the data on each one
110  * into the buffer. Never copy more than the data's length.
111  */
112  plen = t->bt_psize - BTDATAOFF;
113  for (p = *buf;; p = (char *)p + nb, pg = h->nextpg) {
114  if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL)
115  return (RET_ERROR);
116 
117  nb = MIN(sz, plen);
118  memmove(p, (char *)h + BTDATAOFF, nb);
119  mpool_put(t->bt_mp, h, 0);
120 
121  if ((sz -= nb) == 0)
122  break;
123  }
124  return (RET_SUCCESS);
125 }
Definition: btree.h:75
#define RET_ERROR
Definition: db.h:51
#define realloc(a, b)
Definition: astmm.h:163
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
int mpool_put(MPOOL *mp, void *page, u_int flags)
Definition: mpool.c:251
#define NULL
Definition: resample.c:96
#define MIN(a, b)
Definition: utils.h:226
char * malloc()
void * mpool_get(MPOOL *mp, pgno_t pgno, u_int flags)
Definition: mpool.c:165
#define RET_SUCCESS
Definition: db.h:52
MPOOL * bt_mp
Definition: btree.h:313
u_int32_t pgno_t
Definition: db.h:78
pgno_t nextpg
Definition: btree.h:78
u_int32_t bt_psize
Definition: btree.h:338
unsigned int u_int32_t
#define P_INVALID
Definition: btree.h:63
#define BTDATAOFF
Definition: btree.h:95

◆ __ovfl_put()

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

Definition at line 139 of file bt_overflow.c.

References __bt_new(), _btree::bt_mp, _btree::bt_psize, BTDATAOFF, DBT::data, _page::flags, 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().

143 {
144  PAGE *h, *last;
145  void *p;
146  pgno_t npg;
147  size_t nb, plen;
148  u_int32_t sz;
149 
150  /*
151  * Allocate pages and copy the key/data record into them. Store the
152  * number of the first page in the chain.
153  */
154  plen = t->bt_psize - BTDATAOFF;
155  for (last = NULL, p = dbt->data, sz = dbt->size;;
156  p = (char *)p + plen, last = h) {
157  if ((h = __bt_new(t, &npg)) == NULL)
158  return (RET_ERROR);
159 
160  h->pgno = npg;
161  h->nextpg = h->prevpg = P_INVALID;
162  h->flags = P_OVERFLOW;
163  h->lower = h->upper = 0;
164 
165  nb = MIN(sz, plen);
166  memmove((char *)h + BTDATAOFF, p, nb);
167 
168  if (last) {
169  last->nextpg = h->pgno;
170  mpool_put(t->bt_mp, last, MPOOL_DIRTY);
171  } else
172  *pg = h->pgno;
173 
174  if ((sz -= nb) == 0) {
175  mpool_put(t->bt_mp, h, MPOOL_DIRTY);
176  break;
177  }
178  }
179  return (RET_SUCCESS);
180 }
Definition: btree.h:75
void * data
Definition: db.h:86
size_t size
Definition: db.h:87
#define RET_ERROR
Definition: db.h:51
pgno_t pgno
Definition: btree.h:76
int mpool_put(MPOOL *mp, void *page, u_int flags)
Definition: mpool.c:251
indx_t lower
Definition: btree.h:89
#define NULL
Definition: resample.c:96
indx_t upper
Definition: btree.h:90
#define MPOOL_DIRTY
Definition: mpool.h:61
#define MIN(a, b)
Definition: utils.h:226
u_int32_t flags
Definition: btree.h:87
struct sla_ringing_trunk * last
Definition: app_meetme.c:1092
#define RET_SUCCESS
Definition: db.h:52
MPOOL * bt_mp
Definition: btree.h:313
u_int32_t pgno_t
Definition: db.h:78
pgno_t nextpg
Definition: btree.h:78
pgno_t prevpg
Definition: btree.h:77
u_int32_t bt_psize
Definition: btree.h:338
unsigned int u_int32_t
#define P_INVALID
Definition: btree.h:63
#define BTDATAOFF
Definition: btree.h:95
#define P_OVERFLOW
Definition: btree.h:82
PAGE * __bt_new(BTREE *t, pgno_t *npg)
Definition: bt_page.c:86