Asterisk - The Open Source Telephony Project GIT-master-3dae2cf
Functions
rec_search.c File Reference
#include <sys/types.h>
#include <errno.h>
#include <stdio.h>
#include "../include/db.h"
#include "recno.h"
Include dependency graph for rec_search.c:

Go to the source code of this file.

Functions

EPG__rec_search (BTREE *t, recno_t recno, enum SRCHOP op)
 

Function Documentation

◆ __rec_search()

EPG * __rec_search ( BTREE t,
recno_t  recno,
enum SRCHOP  op 
)

Definition at line 64 of file rec_search.c.

68{
69 register indx_t index;
70 register PAGE *h;
71 EPGNO *parent;
72 RINTERNAL *r;
73 pgno_t pg;
74 indx_t top;
76 int sverrno;
77
78 BT_CLR(t);
79 for (pg = P_ROOT, total = 0;;) {
80 if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL)
81 goto err;
82 if (h->flags & P_RLEAF) {
83 t->bt_cur.page = h;
84 t->bt_cur.index = recno - total;
85 return (&t->bt_cur);
86 }
87 for (index = 0, top = NEXTINDEX(h);;) {
88 r = GETRINTERNAL(h, index);
89 if (++index == top || total + r->nrecs > recno)
90 break;
91 total += r->nrecs;
92 }
93
94 BT_PUSH(t, pg, index - 1);
95
96 pg = r->pgno;
97 switch (op) {
98 case SDELETE:
99 --GETRINTERNAL(h, (index - 1))->nrecs;
101 break;
102 case SINSERT:
103 ++GETRINTERNAL(h, (index - 1))->nrecs;
105 break;
106 case SEARCH:
107 mpool_put(t->bt_mp, h, 0);
108 break;
109 }
110
111 }
112 /* Try and recover the tree. */
113err: sverrno = errno;
114 if (op != SEARCH)
115 while ((parent = BT_POP(t)) != NULL) {
116 if ((h = mpool_get(t->bt_mp, parent->pgno, 0)) == NULL)
117 break;
118 if (op == SINSERT)
119 --GETRINTERNAL(h, parent->index)->nrecs;
120 else
121 ++GETRINTERNAL(h, parent->index)->nrecs;
123 }
124 errno = sverrno;
125 return (NULL);
126}
#define P_RLEAF
Definition: btree.h:84
#define GETRINTERNAL(pg, indx)
Definition: btree.h:165
#define BT_CLR(t)
Definition: btree.h:328
#define NEXTINDEX(p)
Definition: btree.h:98
#define BT_POP(t)
Definition: btree.h:327
#define BT_PUSH(t, p, i)
Definition: btree.h:322
#define P_ROOT
Definition: btree.h:65
u_int16_t indx_t
Definition: db.h:80
u_int32_t recno_t
Definition: db.h:82
u_int32_t pgno_t
Definition: db.h:78
int errno
void * mpool_get(MPOOL *mp, pgno_t pgno, u_int flags)
Definition: mpool.c:165
int mpool_put(MPOOL *mp, void *page, u_int flags)
Definition: mpool.c:251
#define MPOOL_DIRTY
Definition: mpool.h:61
@ SEARCH
Definition: recno.h:36
@ SDELETE
Definition: recno.h:36
@ SINSERT
Definition: recno.h:36
static int total
Definition: res_adsi.c:970
#define NULL
Definition: resample.c:96
MPOOL * bt_mp
Definition: btree.h:313
EPG bt_cur
Definition: btree.h:317
indx_t index
Definition: btree.h:256
PAGE * page
Definition: btree.h:255
Definition: btree.h:249
pgno_t pgno
Definition: btree.h:250
indx_t index
Definition: btree.h:251
Definition: btree.h:75
u_int32_t flags
Definition: btree.h:87
pgno_t pgno
Definition: btree.h:161
recno_t nrecs
Definition: btree.h:160

References BT_CLR, _btree::bt_cur, _btree::bt_mp, BT_POP, BT_PUSH, errno, _page::flags, GETRINTERNAL, _epgno::index, _epg::index, MPOOL_DIRTY, mpool_get(), mpool_put(), NEXTINDEX, _rinternal::nrecs, NULL, P_RLEAF, P_ROOT, _epg::page, _rinternal::pgno, _epgno::pgno, SDELETE, SEARCH, SINSERT, and total.

Referenced by __rec_get(), __rec_iput(), __rec_seq(), and rec_rdelete().