Back to index

lightning-sunbird  0.9+nobinonly
Functions | Variables
extern.h File Reference

Go to the source code of this file.

Functions

BUFHEAD * __add_ovflpage (HTAB *, BUFHEAD *)
int __addel (HTAB *, BUFHEAD *, const DBT *, const DBT *)
int __big_delete (HTAB *, BUFHEAD *)
int __big_insert (HTAB *, BUFHEAD *, const DBT *, const DBT *)
int __big_keydata (HTAB *, BUFHEAD *, DBT *, DBT *, int)
int __big_return (HTAB *, BUFHEAD *, int, DBT *, int)
int __big_split (HTAB *, BUFHEAD *, BUFHEAD *, BUFHEAD *, uint32, uint32, SPLIT_RETURN *)
int __buf_free (HTAB *, int, int)
void __buf_init (HTAB *, int)
uint32 __call_hash (HTAB *, char *, size_t)
int __delpair (HTAB *, BUFHEAD *, int)
int __expand_table (HTAB *)
int __find_bigpair (HTAB *, BUFHEAD *, int, char *, int)
uint16 __find_last_page (HTAB *, BUFHEAD **)
void __free_ovflpage (HTAB *, BUFHEAD *)
BUFHEAD * __get_buf (HTAB *, uint32, BUFHEAD *, int)
int __get_page (HTAB *, char *, uint32, int, int, int)
int __ibitmap (HTAB *, int, int, int)
uint32 __log2 (uint32)
int __put_page (HTAB *, char *, uint32, int, int)
void __reclaim_buf (HTAB *, BUFHEAD *)
int __split_page (HTAB *, uint32, uint32)

Variables

uint32(* __default_hash )(const void *, size_t)

Function Documentation

BUFHEAD* __add_ovflpage ( HTAB ,
BUFHEAD *   
)

Definition at line 635 of file h_page.c.

{
       register uint16 *sp;
       uint16 ndx, ovfl_num;
#ifdef DEBUG1
       int tmp1, tmp2;
#endif
       sp = (uint16 *)bufp->page;

       /* Check if we are dynamically determining the fill factor */
       if (hashp->FFACTOR == DEF_FFACTOR) {
              hashp->FFACTOR = sp[0] >> 1;
              if (hashp->FFACTOR < MIN_FFACTOR)
                     hashp->FFACTOR = MIN_FFACTOR;
       }
       bufp->flags |= BUF_MOD;
       ovfl_num = overflow_page(hashp);
#ifdef DEBUG1
       tmp1 = bufp->addr;
       tmp2 = bufp->ovfl ? bufp->ovfl->addr : 0;
#endif
       if (!ovfl_num || !(bufp->ovfl = __get_buf(hashp, ovfl_num, bufp, 1)))
              return (NULL);
       bufp->ovfl->flags |= BUF_MOD;
#ifdef DEBUG1
       (void)fprintf(stderr, "ADDOVFLPAGE: %d->ovfl was %d is now %d\n",
           tmp1, tmp2, bufp->ovfl->addr);
#endif
       ndx = sp[0];
       /*
        * Since a pair is allocated on a page only if there's room to add
        * an overflow page, we know that the OVFL information will fit on
        * the page.
        */
       sp[ndx + 4] = OFFSET(sp);
       sp[ndx + 3] = FREESPACE(sp) - OVFLSIZE;
       sp[ndx + 1] = ovfl_num;
       sp[ndx + 2] = OVFLPAGE;
       sp[0] = ndx + 2;
#ifdef HASH_STATISTICS
       hash_overflows++;
#endif
       return (bufp->ovfl);
}

Here is the caller graph for this function:

int __addel ( HTAB ,
BUFHEAD *  ,
const DBT ,
const DBT  
)

Definition at line 542 of file h_page.c.

{
       register uint16 *bp, *sop;
       int do_expand;

       bp = (uint16 *)bufp->page;
       do_expand = 0;
       while (bp[0] && (bp[2] < REAL_KEY || bp[bp[0]] < REAL_KEY))
              /* Exception case */
              if (bp[2] == FULL_KEY_DATA && bp[0] == 2)
                     /* This is the last page of a big key/data pair
                        and we need to add another page */
                     break;
              else if (bp[2] < REAL_KEY && bp[bp[0]] != OVFLPAGE) {
                     bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0);
                     if (!bufp)
                       {
#ifdef DEBUG
                            assert(0);
#endif
                            return (-1);
                       }
                     bp = (uint16 *)bufp->page;
              } else
                     /* Try to squeeze key on this page */
                     if (FREESPACE(bp) > PAIRSIZE(key, val)) {
                       {
                            squeeze_key(bp, key, val);

                            /* LJM: I added this because I think it was
                             * left out on accident.
                             * if this isn't incremented nkeys will not
                             * be the actual number of keys in the db.
                             */
                            hashp->NKEYS++;
                            return (0);
                       }
                     } else {
                            bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0);
                            if (!bufp)
                           {
#ifdef DEBUG
                                assert(0);
#endif
                                   return (-1);
                              }
                            bp = (uint16 *)bufp->page;
                     }

       if (PAIRFITS(bp, key, val))
              putpair(bufp->page, key, (DBT *)val);
       else {
              do_expand = 1;
              bufp = __add_ovflpage(hashp, bufp);
              if (!bufp)
             {
#ifdef DEBUG
                  assert(0);
#endif
                     return (-1);
                }
              sop = (uint16 *)bufp->page;

              if (PAIRFITS(sop, key, val))
                     putpair((char *)sop, key, (DBT *)val);
              else
                     if (__big_insert(hashp, bufp, key, val))
                 {
#ifdef DEBUG
                      assert(0);
#endif
                         return (-1);
                    }
       }
       bufp->flags |= BUF_MOD;
       /*
        * If the average number of keys per bucket exceeds the fill factor,
        * expand the table.
        */
       hashp->NKEYS++;
       if (do_expand ||
           (hashp->NKEYS / (hashp->MAX_BUCKET + 1) > hashp->FFACTOR))
              return (__expand_table(hashp));
       return (0);
}

Here is the caller graph for this function:

int __big_delete ( HTAB ,
BUFHEAD *   
)

Definition at line 187 of file h_bigkey.c.

{
       register BUFHEAD *last_bfp, *rbufp;
       uint16 *bp, pageno;
       int key_done, n;

       rbufp = bufp;
       last_bfp = NULL;
       bp = (uint16 *)bufp->page;
       pageno = 0;
       key_done = 0;

       while (!key_done || (bp[2] != FULL_KEY_DATA)) {
              if (bp[2] == FULL_KEY || bp[2] == FULL_KEY_DATA)
                     key_done = 1;

              /*
               * If there is freespace left on a FULL_KEY_DATA page, then
               * the data is short and fits entirely on this page, and this
               * is the last page.
               */
              if (bp[2] == FULL_KEY_DATA && FREESPACE(bp))
                     break;
              pageno = bp[bp[0] - 1];
              rbufp->flags |= BUF_MOD;
              rbufp = __get_buf(hashp, pageno, rbufp, 0);
              if (last_bfp)
                     __free_ovflpage(hashp, last_bfp);
              last_bfp = rbufp;
              if (!rbufp)
                     return (-1);         /* Error. */
              bp = (uint16 *)rbufp->page;
       }

       /*
        * If we get here then rbufp points to the last page of the big
        * key/data pair.  Bufp points to the first one -- it should now be
        * empty pointing to the next page after this pair.  Can't free it
        * because we don't have the page pointing to it.
        */

       /* This is information from the last page of the pair. */
       n = bp[0];
       pageno = bp[n - 1];

       /* Now, bp is the first page of the pair. */
       bp = (uint16 *)bufp->page;
       if (n > 2) {
              /* There is an overflow page. */
              bp[1] = pageno;
              bp[2] = OVFLPAGE;
              bufp->ovfl = rbufp->ovfl;
       } else
              /* This is the last page. */
              bufp->ovfl = NULL;
       n -= 2;
       bp[0] = n;
       FREESPACE(bp) = hashp->BSIZE - PAGE_META(n);
       OFFSET(bp) = hashp->BSIZE - 1;

       bufp->flags |= BUF_MOD;
       if (rbufp)
              __free_ovflpage(hashp, rbufp);
       if (last_bfp != rbufp)
              __free_ovflpage(hashp, last_bfp);

       hashp->NKEYS--;
       return (0);
}

Here is the caller graph for this function:

int __big_insert ( HTAB ,
BUFHEAD *  ,
const DBT ,
const DBT  
)

Definition at line 90 of file h_bigkey.c.

{
       register uint16 *p;
       uint key_size, n, val_size;
       uint16 space, move_bytes, off;
       char *cp, *key_data, *val_data;

       cp = bufp->page;            /* Character pointer of p. */
       p = (uint16 *)cp;

       key_data = (char *)key->data;
       key_size = key->size;
       val_data = (char *)val->data;
       val_size = val->size;

       /* First move the Key */
       for (space = FREESPACE(p) - BIGOVERHEAD; key_size;
           space = FREESPACE(p) - BIGOVERHEAD) {
              move_bytes = PR_MIN(space, key_size);
              off = OFFSET(p) - move_bytes;
              memmove(cp + off, key_data, move_bytes);
              key_size -= move_bytes;
              key_data += move_bytes;
              n = p[0];
              p[++n] = off;
              p[0] = ++n;
              FREESPACE(p) = off - PAGE_META(n);
              OFFSET(p) = off;
              p[n] = PARTIAL_KEY;
              bufp = __add_ovflpage(hashp, bufp);
              if (!bufp)
                     return (-1);
              n = p[0];
              if (!key_size) {
                     if (FREESPACE(p)) {
                            move_bytes = PR_MIN(FREESPACE(p), val_size);
                            off = OFFSET(p) - move_bytes;
                            p[n] = off;
                            memmove(cp + off, val_data, move_bytes);
                            val_data += move_bytes;
                            val_size -= move_bytes;
                            p[n - 2] = FULL_KEY_DATA;
                            FREESPACE(p) = FREESPACE(p) - move_bytes;
                            OFFSET(p) = off;
                     } else
                            p[n - 2] = FULL_KEY;
              }
              p = (uint16 *)bufp->page;
              cp = bufp->page;
              bufp->flags |= BUF_MOD;
       }

       /* Now move the data */
       for (space = FREESPACE(p) - BIGOVERHEAD; val_size;
           space = FREESPACE(p) - BIGOVERHEAD) {
              move_bytes = PR_MIN(space, val_size);
              /*
               * Here's the hack to make sure that if the data ends on the
               * same page as the key ends, FREESPACE is at least one.
               */
              if (space == val_size && val_size == val->size)
                     move_bytes--;
              off = OFFSET(p) - move_bytes;
              memmove(cp + off, val_data, move_bytes);
              val_size -= move_bytes;
              val_data += move_bytes;
              n = p[0];
              p[++n] = off;
              p[0] = ++n;
              FREESPACE(p) = off - PAGE_META(n);
              OFFSET(p) = off;
              if (val_size) {
                     p[n] = FULL_KEY;
                     bufp = __add_ovflpage(hashp, bufp);
                     if (!bufp)
                            return (-1);
                     cp = bufp->page;
                     p = (uint16 *)cp;
              } else
                     p[n] = FULL_KEY_DATA;
              bufp->flags |= BUF_MOD;
       }
       return (0);
}

Here is the caller graph for this function:

int __big_keydata ( HTAB ,
BUFHEAD *  ,
DBT ,
DBT ,
int   
)

Definition at line 545 of file h_bigkey.c.

{
       key->size = collect_key(hashp, bufp, 0, val, set);
       if (key->size == (size_t)-1)
              return (-1);
       key->data = (uint8 *)hashp->tmp_key;
       return (0);
}

Here is the caller graph for this function:

int __big_return ( HTAB ,
BUFHEAD *  ,
int  ,
DBT ,
int   
)

Definition at line 355 of file h_bigkey.c.

{
       BUFHEAD *save_p;
       uint16 *bp, len, off, save_addr;
       char *tp;
       int save_flags;

       bp = (uint16 *)bufp->page;
       while (bp[ndx + 1] == PARTIAL_KEY) {
              bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0);
              if (!bufp)
                     return (-1);
              bp = (uint16 *)bufp->page;
              ndx = 1;
       }

       if (bp[ndx + 1] == FULL_KEY) {
              bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0);
              if (!bufp)
                     return (-1);
              bp = (uint16 *)bufp->page;
              save_p = bufp;
              save_addr = save_p->addr;
              off = bp[1];
              len = 0;
       } else
              if (!FREESPACE(bp)) {
                     /*
                      * This is a hack.  We can't distinguish between
                      * FULL_KEY_DATA that contains complete data or
                      * incomplete data, so we require that if the data
                      * is complete, there is at least 1 byte of free
                      * space left.
                      */
                     off = bp[bp[0]];
                     len = bp[1] - off;
                     save_p = bufp;
                     save_addr = bufp->addr;
                     bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0);
                     if (!bufp)
                            return (-1);
                     bp = (uint16 *)bufp->page;
              } else {
                     /* The data is all on one page. */
                     tp = (char *)bp;
                     off = bp[bp[0]];
                     val->data = (uint8 *)tp + off;
                     val->size = bp[1] - off;
                     if (set_current) {
                            if (bp[0] == 2) {    /* No more buckets in
                                                  * chain */
                                   hashp->cpage = NULL;
                                   hashp->cbucket++;
                                   hashp->cndx = 1;
                            } else {
                                   hashp->cpage = __get_buf(hashp,
                                       bp[bp[0] - 1], bufp, 0);
                                   if (!hashp->cpage)
                                          return (-1);
                                   hashp->cndx = 1;
                                   if (!((uint16 *)
                                       hashp->cpage->page)[0]) {
                                          hashp->cbucket++;
                                          hashp->cpage = NULL;
                                   }
                            }
                     }
                     return (0);
              }

       /* pin our saved buf so that we don't lose if 
        * we run out of buffers */
       save_flags = save_p->flags;
       save_p->flags |= BUF_PIN;
       val->size = collect_data(hashp, bufp, (int)len, set_current);
       save_p->flags = save_flags;
       if (val->size == (size_t)-1)
              return (-1);
       if (save_p->addr != save_addr) {
              /* We are pretty short on buffers. */
              errno = EINVAL;                    /* OUT OF BUFFERS */
              return (-1);
       }
       memmove(hashp->tmp_buf, (save_p->page) + off, len);
       val->data = (uint8 *)hashp->tmp_buf;
       return (0);
}

Here is the caller graph for this function:

int __big_split ( HTAB ,
BUFHEAD *  ,
BUFHEAD *  ,
BUFHEAD *  ,
uint32  ,
uint32  ,
SPLIT_RETURN  
)

Definition at line 608 of file h_bigkey.c.

{
       register BUFHEAD *tmpp;
       register uint16 *tp;
       BUFHEAD *bp;
       DBT key, val;
       uint32 change;
       uint16 free_space, n, off;

       bp = big_keyp;

       /* Now figure out where the big key/data goes */
       if (__big_keydata(hashp, big_keyp, &key, &val, 0))
              return (-1);
       change = (__call_hash(hashp,(char*) key.data, key.size) != obucket);

       if ((ret->next_addr = __find_last_page(hashp, &big_keyp))) {
              if (!(ret->nextp =
                  __get_buf(hashp, ret->next_addr, big_keyp, 0)))
                     return (-1);;
       } else
              ret->nextp = NULL;

       /* Now make one of np/op point to the big key/data pair */
#ifdef DEBUG
       assert(np->ovfl == NULL);
#endif
       if (change)
              tmpp = np;
       else
              tmpp = op;

       tmpp->flags |= BUF_MOD;
#ifdef DEBUG1
       (void)fprintf(stderr,
           "BIG_SPLIT: %d->ovfl was %d is now %d\n", tmpp->addr,
           (tmpp->ovfl ? tmpp->ovfl->addr : 0), (bp ? bp->addr : 0));
#endif
       tmpp->ovfl = bp;     /* one of op/np point to big_keyp */
       tp = (uint16 *)tmpp->page;


#if 0  /* this get's tripped on database corrupted error */
       assert(FREESPACE(tp) >= OVFLSIZE);
#endif
       if(FREESPACE(tp) < OVFLSIZE)
              return(DATABASE_CORRUPTED_ERROR);

       n = tp[0];
       off = OFFSET(tp);
       free_space = FREESPACE(tp);
       tp[++n] = (uint16)addr;
       tp[++n] = OVFLPAGE;
       tp[0] = n;
       OFFSET(tp) = off;
       FREESPACE(tp) = free_space - OVFLSIZE;

       /*
        * Finally, set the new and old return values. BIG_KEYP contains a
        * pointer to the last page of the big key_data pair. Make sure that
        * big_keyp has no following page (2 elements) or create an empty
        * following page.
        */

       ret->newp = np;
       ret->oldp = op;

       tp = (uint16 *)big_keyp->page;
       big_keyp->flags |= BUF_MOD;
       if (tp[0] > 2) {
              /*
               * There may be either one or two offsets on this page.  If
               * there is one, then the overflow page is linked on normally
               * and tp[4] is OVFLPAGE.  If there are two, tp[4] contains
               * the second offset and needs to get stuffed in after the
               * next overflow page is added.
               */
              n = tp[4];
              free_space = FREESPACE(tp);
              off = OFFSET(tp);
              tp[0] -= 2;
              FREESPACE(tp) = free_space + OVFLSIZE;
              OFFSET(tp) = off;
              tmpp = __add_ovflpage(hashp, big_keyp);
              if (!tmpp)
                     return (-1);
              tp[4] = n;
       } else
              tmpp = big_keyp;

       if (change)
              ret->newp = tmpp;
       else
              ret->oldp = tmpp;
       return (0);
}

Here is the caller graph for this function:

int __buf_free ( HTAB ,
int  ,
int   
)

Definition at line 366 of file hash_buf.c.

{
       BUFHEAD *bp;
       int status = -1;

       /* Need to make sure that buffer manager has been initialized */
       if (!LRU)
              return (0);
       for (bp = LRU; bp != &hashp->bufhead;) {
              /* Check that the buffer is valid */
              if (bp->addr || IS_BUCKET(bp->flags)) {
                     if (to_disk && (bp->flags & BUF_MOD) &&
                         (status = __put_page(hashp, bp->page,
                         bp->addr, IS_BUCKET(bp->flags), 0))) {
                       
                            if (do_free) {
                                   if (bp->page)
                                          free(bp->page);
                                   BUF_REMOVE(bp);
                                   free(bp);
                            }
                            
                            return (status);
                     }
              }
              /* Check if we are freeing stuff */
              if (do_free) {
                     if (bp->page)
                            free(bp->page);
                     BUF_REMOVE(bp);
                     free(bp);
                     bp = LRU;
              } else
                     bp = bp->prev;
       }
       return (0);
}

Here is the caller graph for this function:

void __buf_init ( HTAB ,
int   
)

Definition at line 343 of file hash_buf.c.

{
       BUFHEAD *bfp;
       int npages;

       bfp = &(hashp->bufhead);
       npages = (nbytes + hashp->BSIZE - 1) >> hashp->BSHIFT;
       npages = PR_MAX(npages, MIN_BUFFERS);

       hashp->nbufs = npages;
       bfp->next = bfp;
       bfp->prev = bfp;
       /*
        * This space is calloc'd so these are already null.
        *
        * bfp->ovfl = NULL;
        * bfp->flags = 0;
        * bfp->page = NULL;
        * bfp->addr = 0;
        */
}

Here is the caller graph for this function:

uint32 __call_hash ( HTAB ,
char *  ,
size_t   
)

Definition at line 1074 of file hash.c.

{
       uint32 n, bucket;

       n = hashp->hash(k, len);
       bucket = n & hashp->HIGH_MASK;
       if (bucket > (uint32)hashp->MAX_BUCKET)
              bucket = bucket & hashp->LOW_MASK;
       return (bucket);
}

Here is the caller graph for this function:

int __delpair ( HTAB ,
BUFHEAD *  ,
int   
)

Definition at line 211 of file h_page.c.

{
       register uint16 *bp, newoff;
       register int n;
       uint16 pairlen;

       bp = (uint16 *)bufp->page;
       n = bp[0];

       if (bp[ndx + 1] < REAL_KEY)
              return (__big_delete(hashp, bufp));
       if (ndx != 1)
              newoff = bp[ndx - 1];
       else
              newoff = hashp->BSIZE;
       pairlen = newoff - bp[ndx + 1];

       if (ndx != (n - 1)) {
              /* Hard Case -- need to shuffle keys */
              register int i;
              register char *src = bufp->page + (int)OFFSET(bp);
              uint32 dst_offset = (uint32)OFFSET(bp) + (uint32)pairlen;
              register char *dst = bufp->page + dst_offset;
              uint32 length = bp[ndx + 1] - OFFSET(bp);

              /*
               * +-----------+XXX+---------+XXX+---------+---------> +infinity
               * |           |             |             |
               * 0           src_offset    dst_offset    BSIZE
               *
               * Dst_offset is > src_offset, so if src_offset were bad, dst_offset
               * would be too, therefore we check only dst_offset.
               *
               * If dst_offset is >= BSIZE, either OFFSET(bp), or pairlen, or both
               * is corrupted.
               *
               * Once we know dst_offset is < BSIZE, we can subtract it from BSIZE
               * to get an upper bound on length.
               */
              if(dst_offset > (uint32)hashp->BSIZE)
                     return(DATABASE_CORRUPTED_ERROR);

              if(length > (uint32)(hashp->BSIZE - dst_offset))
                     return(DATABASE_CORRUPTED_ERROR);

              memmove(dst, src, length);

              /* Now adjust the pointers */
              for (i = ndx + 2; i <= n; i += 2) {
                     if (bp[i + 1] == OVFLPAGE) {
                            bp[i - 2] = bp[i];
                            bp[i - 1] = bp[i + 1];
                     } else {
                            bp[i - 2] = bp[i] + pairlen;
                            bp[i - 1] = bp[i + 1] + pairlen;
                     }
              }
       }
       /* Finally adjust the page data */
       bp[n] = OFFSET(bp) + pairlen;
       bp[n - 1] = bp[n + 1] + pairlen + 2 * sizeof(uint16);
       bp[0] = n - 2;
       hashp->NKEYS--;

       bufp->flags |= BUF_MOD;
       return (0);
}

Here is the caller graph for this function:

Definition at line 1003 of file hash.c.

{
       uint32 old_bucket, new_bucket;
       int new_segnum, spare_ndx;
       size_t dirsize;

#ifdef HASH_STATISTICS
       hash_expansions++;
#endif
       new_bucket = ++hashp->MAX_BUCKET;
       old_bucket = (hashp->MAX_BUCKET & hashp->LOW_MASK);

       new_segnum = new_bucket >> hashp->SSHIFT;

       /* Check if we need a new segment */
       if (new_segnum >= hashp->nsegs) {
              /* Check if we need to expand directory */
              if (new_segnum >= hashp->DSIZE) {
                     /* Reallocate directory */
                     dirsize = hashp->DSIZE * sizeof(SEGMENT *);
                     if (!hash_realloc(&hashp->dir, dirsize, dirsize << 1))
                            return (-1);
                     hashp->DSIZE = dirsize << 1;
              }
              if ((hashp->dir[new_segnum] =
                  (SEGMENT)calloc((size_t)hashp->SGSIZE, sizeof(SEGMENT))) == NULL)
                     return (-1);
              hashp->exsegs++;
              hashp->nsegs++;
       }
       /*
        * If the split point is increasing (MAX_BUCKET's log base 2
        * * increases), we need to copy the current contents of the spare
        * split bucket to the next bucket.
        */
       spare_ndx = __log2((uint32)(hashp->MAX_BUCKET + 1));
       if (spare_ndx > hashp->OVFL_POINT) {
              hashp->SPARES[spare_ndx] = hashp->SPARES[hashp->OVFL_POINT];
              hashp->OVFL_POINT = spare_ndx;
       }

       if (new_bucket > (uint32)hashp->HIGH_MASK) {
              /* Starting a new doubling */
              hashp->LOW_MASK = hashp->HIGH_MASK;
              hashp->HIGH_MASK = new_bucket | hashp->LOW_MASK;
       }
       /* Relocate records to the new bucket */
       return (__split_page(hashp, old_bucket, new_bucket));
}

Here is the caller graph for this function:

int __find_bigpair ( HTAB ,
BUFHEAD *  ,
int  ,
char *  ,
int   
)

Definition at line 264 of file h_bigkey.c.

{
       register uint16 *bp;
       register char *p;
       int ksize;
       uint16 bytes;
       char *kkey;

       bp = (uint16 *)bufp->page;
       p = bufp->page;
       ksize = size;
       kkey = key;

       for (bytes = hashp->BSIZE - bp[ndx];
           bytes <= size && bp[ndx + 1] == PARTIAL_KEY;
           bytes = hashp->BSIZE - bp[ndx]) {
              if (memcmp(p + bp[ndx], kkey, bytes))
                     return (-2);
              kkey += bytes;
              ksize -= bytes;
              bufp = __get_buf(hashp, bp[ndx + 2], bufp, 0);
              if (!bufp)
                     return (-3);
              p = bufp->page;
              bp = (uint16 *)p;
              ndx = 1;
       }

       if (bytes != ksize || memcmp(p + bp[ndx], kkey, bytes)) {
#ifdef HASH_STATISTICS
              ++hash_collisions;
#endif
              return (-2);
       } else
              return (ndx);
}

Here is the caller graph for this function:

uint16 __find_last_page ( HTAB ,
BUFHEAD **   
)

Definition at line 311 of file h_bigkey.c.

{
       BUFHEAD *bufp;
       uint16 *bp, pageno;
       uint n;

       bufp = *bpp;
       bp = (uint16 *)bufp->page;
       for (;;) {
              n = bp[0];

              /*
               * This is the last page if: the tag is FULL_KEY_DATA and
               * either only 2 entries OVFLPAGE marker is explicit there
               * is freespace on the page.
               */
              if (bp[2] == FULL_KEY_DATA &&
                  ((n == 2) || (bp[n] == OVFLPAGE) || (FREESPACE(bp))))
                     break;

              /* LJM bound the size of n to reasonable limits
               */
              if(n > hashp->BSIZE/sizeof(uint16))
                     return(0);

              pageno = bp[n - 1];
              bufp = __get_buf(hashp, pageno, bufp, 0);
              if (!bufp)
                     return (0);   /* Need to indicate an error! */
              bp = (uint16 *)bufp->page;
       }

       *bpp = bufp;
       if (bp[0] > 2)
              return (bp[3]);
       else
              return (0);
}

Here is the caller graph for this function:

void __free_ovflpage ( HTAB ,
BUFHEAD *   
)

Definition at line 1107 of file h_page.c.

{
       uint16 addr;
       uint32 *freep;
       uint32 bit_address, free_page, free_bit;
       uint16 ndx;

       if(!obufp || !obufp->addr)
           return;

       addr = obufp->addr;
#ifdef DEBUG1
       (void)fprintf(stderr, "Freeing %d\n", addr);
#endif
       ndx = (((uint16)addr) >> SPLITSHIFT);
       bit_address =
           (ndx ? hashp->SPARES[ndx - 1] : 0) + (addr & SPLITMASK) - 1;
       if (bit_address < (uint32)hashp->LAST_FREED)
              hashp->LAST_FREED = bit_address;
       free_page = (bit_address >> (hashp->BSHIFT + BYTE_SHIFT));
       free_bit = bit_address & ((hashp->BSIZE << BYTE_SHIFT) - 1);

       if (!(freep = hashp->mapp[free_page])) 
              freep = fetch_bitmap(hashp, free_page);

#ifdef DEBUG
       /*
        * This had better never happen.  It means we tried to read a bitmap
        * that has already had overflow pages allocated off it, and we
        * failed to read it from the file.
        */
       if (!freep)
         {
              assert(0);
              return;
         }
#endif
       CLRBIT(freep, free_bit);
#ifdef DEBUG2
       (void)fprintf(stderr, "FREE_OVFLPAGE: ADDR: %d BIT: %d PAGE %d\n",
           obufp->addr, free_bit, free_page);
#endif
       __reclaim_buf(hashp, obufp);
}

Here is the caller graph for this function:

BUFHEAD* __get_buf ( HTAB ,
uint32  ,
BUFHEAD *  ,
int   
)

Definition at line 107 of file hash_buf.c.

{
       register BUFHEAD *bp;
       register uint32 is_disk_mask;
       register int is_disk, segment_ndx = 0;
       SEGMENT segp = 0;

       is_disk = 0;
       is_disk_mask = 0;
       if (prev_bp) {
              bp = prev_bp->ovfl;
              if (!bp || (bp->addr != addr))
                     bp = NULL;
              if (!newpage)
                     is_disk = BUF_DISK;
       } else {
              /* Grab buffer out of directory */
              segment_ndx = addr & (hashp->SGSIZE - 1);

              /* valid segment ensured by __call_hash() */
              segp = hashp->dir[addr >> hashp->SSHIFT];
#ifdef DEBUG
              assert(segp != NULL);
#endif  

              bp = PTROF(segp[segment_ndx]);

              is_disk_mask = ISDISK(segp[segment_ndx]);
              is_disk = is_disk_mask || !hashp->new_file;
       }

       if (!bp) {
              bp = newbuf(hashp, addr, prev_bp);
              if (!bp)
                     return(NULL);
              if(__get_page(hashp, bp->page, addr, !prev_bp, is_disk, 0))
                {
                     /* free bp and its page */
                     if(prev_bp)
                       {
                            /* if prev_bp is set then the new page that
                             * failed is hooked onto prev_bp as an overflow page.
                             * if we don't remove the pointer to the bad page
                             * we may try and access it later and we will die
                             * horribly because it will have already been
                             * free'd and overwritten with bogus data.
                             */
                            prev_bp->ovfl = NULL;
                       }
                     BUF_REMOVE(bp);
                     free(bp->page);
                     free(bp);
                     return (NULL);
                }

              if (!prev_bp)               
                {
#if 0
                     /* 16 bit windows and mac can't handle the
                      * oring of the is disk flag.
                      */                  
                     segp[segment_ndx] =
                         (BUFHEAD *)((ptrdiff_t)bp | is_disk_mask);
#else   
                     /* set the is_disk thing inside the structure
                      */
                     bp->is_disk = is_disk_mask;
                     segp[segment_ndx] = bp;
#endif
                }
       } else {  
              BUF_REMOVE(bp);
              MRU_INSERT(bp);                 
       }
       return (bp);
}

Here is the caller graph for this function:

int __get_page ( HTAB ,
char *  ,
uint32  ,
int  ,
int  ,
int   
)

Definition at line 686 of file h_page.c.

{
       register int fd, page;
       size_t size;
       int rsize;
       uint16 *bp;

       fd = hashp->fp;
       size = hashp->BSIZE;

       if ((fd == -1) || !is_disk) {
              PAGE_INIT(p);
              return (0);
       }
       if (is_bucket)
              page = BUCKET_TO_PAGE(bucket);
       else
              page = OADDR_TO_PAGE(bucket);
       if ((MY_LSEEK(fd, (off_t)page << hashp->BSHIFT, SEEK_SET) == -1) ||
           ((rsize = read(fd, p, size)) == -1))
              return (-1);

       bp = (uint16 *)p;
       if (!rsize)
              bp[0] = 0;    /* We hit the EOF, so initialize a new page */
       else
              if ((unsigned)rsize != size) {
                     errno = EFTYPE;
                     return (-1);
              }

       if (!is_bitmap && !bp[0]) {
              PAGE_INIT(p);
       } else {

#ifdef DEBUG
              if(BYTE_ORDER == LITTLE_ENDIAN)
                {
                     int is_little_endian;
                     is_little_endian = BYTE_ORDER;
                }
              else if(BYTE_ORDER == BIG_ENDIAN)
                {
                     int is_big_endian;
                     is_big_endian = BYTE_ORDER;
                }
              else
                {
                     assert(0);
                }
#endif

              if (hashp->LORDER != BYTE_ORDER) {
                     register int i, max;

                     if (is_bitmap) {
                            max = hashp->BSIZE >> 2; /* divide by 4 */
                            for (i = 0; i < max; i++)
                                   M_32_SWAP(((int *)p)[i]);
                     } else {
                            M_16_SWAP(bp[0]);
                            max = bp[0] + 2;

                     /* bound the size of max by
                      * the maximum number of entries
                      * in the array
                      */
                            if((unsigned)max > (size / sizeof(uint16)))
                                   return(DATABASE_CORRUPTED_ERROR);

                            /* do the byte order swap
                             */
                            for (i = 1; i <= max; i++)
                                   M_16_SWAP(bp[i]);
                     }
              }

              /* check the validity of the page here
               * (after doing byte order swaping if necessary)
               */
              if(!is_bitmap && bp[0] != 0)
                {
                     uint16 num_keys = bp[0];
                     uint16 offset;
                     uint16 i;

                     /* bp[0] is supposed to be the number of
                      * entries currently in the page.  If
                      * bp[0] is too large (larger than the whole
                      * page) then the page is corrupted
                      */
                     if(bp[0] > (size / sizeof(uint16)))
                            return(DATABASE_CORRUPTED_ERROR);
                     
                     /* bound free space */
                     if(FREESPACE(bp) > size)
                            return(DATABASE_CORRUPTED_ERROR);
              
                     /* check each key and data offset to make
                      * sure they are all within bounds they
                      * should all be less than the previous
                      * offset as well.
                      */
                     offset = size;
                     for(i=1 ; i <= num_keys; i+=2)
                       {
                            /* ignore overflow pages etc. */
                            if(bp[i+1] >= REAL_KEY)
                              {
                                          
                                   if(bp[i] > offset || bp[i+1] > bp[i])                   
                                          return(DATABASE_CORRUPTED_ERROR);
                     
                                   offset = bp[i+1];
                              }
                            else
                              {
                                   /* there are no other valid keys after
                                    * seeing a non REAL_KEY
                                    */
                                   break;
                              }
                       }
              }
       }
       return (0);
}

Here is the caller graph for this function:

int __ibitmap ( HTAB ,
int  ,
int  ,
int   
)

Definition at line 918 of file h_page.c.

{
       uint32 *ip;
       size_t clearbytes, clearints;

       if ((ip = (uint32 *)malloc((size_t)hashp->BSIZE)) == NULL)
              return (1);
       hashp->nmaps++;
       clearints = ((nbits - 1) >> INT_BYTE_SHIFT) + 1;
       clearbytes = clearints << INT_TO_BYTE;
       (void)memset((char *)ip, 0, clearbytes);
       (void)memset(((char *)ip) + clearbytes, 0xFF,
           hashp->BSIZE - clearbytes);
       ip[clearints - 1] = ALL_SET << (nbits & BYTE_MASK);
       SETBIT(ip, 0);
       hashp->BITMAPS[ndx] = (uint16)pnum;
       hashp->mapp[ndx] = ip;
       return (0);
}

Here is the caller graph for this function:

Definition at line 47 of file h_log2.c.

{
       register uint32 i, limit;

       limit = 1;
       for (i = 0; limit < num; limit = limit << 1, i++) {}
       return (i);
}

Here is the caller graph for this function:

int __put_page ( HTAB ,
char *  ,
uint32  ,
int  ,
int   
)

Definition at line 827 of file h_page.c.

{
       register int fd, page;
       size_t size;
       int wsize;
       off_t offset;

       size = hashp->BSIZE;
       if ((hashp->fp == -1) && open_temp(hashp))
              return (-1);
       fd = hashp->fp;

       if (hashp->LORDER != BYTE_ORDER) {
              register int i;
              register int max;

              if (is_bitmap) {
                     max = hashp->BSIZE >> 2;    /* divide by 4 */
                     for (i = 0; i < max; i++)
                            M_32_SWAP(((int *)p)[i]);
              } else {
                     max = ((uint16 *)p)[0] + 2;

            /* bound the size of max by
             * the maximum number of entries
             * in the array
             */
            if((unsigned)max > (size / sizeof(uint16)))
                return(DATABASE_CORRUPTED_ERROR);

                     for (i = 0; i <= max; i++)
                            M_16_SWAP(((uint16 *)p)[i]);

              }
       }

       if (is_bucket)
              page = BUCKET_TO_PAGE(bucket);
       else
              page = OADDR_TO_PAGE(bucket);
       offset = (off_t)page << hashp->BSHIFT;
       if ((MY_LSEEK(fd, offset, SEEK_SET) == -1) ||
           ((wsize = write(fd, p, size)) == -1))
              /* Errno is set */
              return (-1);
       if ((unsigned)wsize != size) {
              errno = EFTYPE;
              return (-1);
       }
#if defined(_WIN32) || defined(_WINDOWS) 
       if (offset + size > hashp->file_size) {
              hashp->updateEOF = 1;
       }
#endif
       /* put the page back the way it was so that it isn't byteswapped
        * if it remains in memory - LJM
        */
       if (hashp->LORDER != BYTE_ORDER) {
              register int i;
              register int max;

              if (is_bitmap) {
                     max = hashp->BSIZE >> 2;    /* divide by 4 */
                     for (i = 0; i < max; i++)
                            M_32_SWAP(((int *)p)[i]);
              } else {
              uint16 *bp = (uint16 *)p;

                     M_16_SWAP(bp[0]);
                     max = bp[0] + 2;

                     /* no need to bound the size if max again
                      * since it was done already above
                      */

                     /* do the byte order re-swap
                      */
                     for (i = 1; i <= max; i++)
                            M_16_SWAP(bp[i]);
              }
       }

       return (0);
}

Here is the caller graph for this function:

void __reclaim_buf ( HTAB ,
BUFHEAD *   
)

Definition at line 405 of file hash_buf.c.

{
       bp->ovfl = 0;
       bp->addr = 0;
       bp->flags = 0;
       BUF_REMOVE(bp);
       LRU_INSERT(bp);
}

Here is the caller graph for this function:

int __split_page ( HTAB ,
uint32  ,
uint32   
)

Definition at line 284 of file h_page.c.

{
       register BUFHEAD *new_bufp, *old_bufp;
       register uint16 *ino;
       register uint16 *tmp_uint16_array;
       register char *np;
       DBT key, val;
    uint16 n, ndx;
       int retval;
       uint16 copyto, diff, moved;
       size_t off;
       char *op;

       copyto = (uint16)hashp->BSIZE;
       off = (uint16)hashp->BSIZE;
       old_bufp = __get_buf(hashp, obucket, NULL, 0);
       if (old_bufp == NULL)
              return (-1);
       new_bufp = __get_buf(hashp, nbucket, NULL, 0);
       if (new_bufp == NULL)
              return (-1);

       old_bufp->flags |= (BUF_MOD | BUF_PIN);
       new_bufp->flags |= (BUF_MOD | BUF_PIN);

       ino = (uint16 *)(op = old_bufp->page);
       np = new_bufp->page;

       moved = 0;

       for (n = 1, ndx = 1; n < ino[0]; n += 2) {
              if (ino[n + 1] < REAL_KEY) {
                     retval = ugly_split(hashp, obucket, old_bufp, new_bufp,
                         (int)copyto, (int)moved);
                     old_bufp->flags &= ~BUF_PIN;
                     new_bufp->flags &= ~BUF_PIN;
                     return (retval);

              }
              key.data = (uint8 *)op + ino[n];

              /* check here for ino[n] being greater than
               * off.  If it is then the database has
               * been corrupted.
               */
              if(ino[n] > off)
                     return(DATABASE_CORRUPTED_ERROR);

              key.size = off - ino[n];

#ifdef DEBUG
              /* make sure the size is positive */
              assert(((int)key.size) > -1);
#endif

              if (__call_hash(hashp, (char *)key.data, key.size) == obucket) {
                     /* Don't switch page */
                     diff = copyto - off;
                     if (diff) {
                            copyto = ino[n + 1] + diff;
                            memmove(op + copyto, op + ino[n + 1],
                                off - ino[n + 1]);
                            ino[ndx] = copyto + ino[n] - ino[n + 1];
                            ino[ndx + 1] = copyto;
                     } else
                            copyto = ino[n + 1];
                     ndx += 2;
              } else {
                     /* Switch page */
                     val.data = (uint8 *)op + ino[n + 1];
                     val.size = ino[n] - ino[n + 1];

                     /* if the pair doesn't fit something is horribly
                      * wrong.  LJM
                      */
                     tmp_uint16_array = (uint16*)np;
                     if(!PAIRFITS(tmp_uint16_array, &key, &val))
                            return(DATABASE_CORRUPTED_ERROR);

                     putpair(np, &key, &val);
                     moved += 2;
              }

              off = ino[n + 1];
       }

       /* Now clean up the page */
       ino[0] -= moved;
       FREESPACE(ino) = copyto - sizeof(uint16) * (ino[0] + 3);
       OFFSET(ino) = copyto;

#ifdef DEBUG3
       (void)fprintf(stderr, "split %d/%d\n",
           ((uint16 *)np)[0] / 2,
           ((uint16 *)op)[0] / 2);
#endif
       /* unpin both pages */
       old_bufp->flags &= ~BUF_PIN;
       new_bufp->flags &= ~BUF_PIN;
       return (0);
}

Here is the caller graph for this function:


Variable Documentation