filehash/ffdb_page.c
static pgno_t
_ffdb_reuse_free_ovflpage (ffdb_htab_t* hashp)
{
  pgno_t fpage, tp, num, np, nextp;
  void *fpagep;
  unsigned int clevel = hashp->hdr.ovfl_point;

  /* check current free page number at this level */
  num = 0;
  if ((fpage = hashp->hdr.free_pages[clevel]) != INVALID_PGNO) {
    fpagep = ffdb_get_page (hashp, fpage, HASH_FREE_PAGE, 0, &tp);
    if (!fpagep) {
      fprintf (stderr, "Fatal error: free map page at %d could not be found\n",
	       fpage);
      abort ();
    }

    if ((np = NUM_FREE_PAGES(fpagep)) > 0) {
      num = FREE_PAGE(fpagep, np - 1);
      /* reduce number of free pages by one */
      NUM_FREE_PAGES(fpagep)--;
      ffdb_put_page (hashp, fpagep, HASH_FREE_PAGE, 1);
    }
    else {
      nextp = NEXT_PGNO(fpagep);

      /* There is no page free anymore, so I can free this 
       * page for a normal use
       *
       * No need to clean this page, we will reset this page upon reloading
       */
      ffdb_put_page (hashp, fpagep, HASH_OVFL_PAGE, 1);
#ifdef _FFDB_DEBUG
      fprintf (stderr, "Free page %d is not longer needed, put it back\n",
	       fpage);
#endif
      num = fpage;
      /* nextp could be INVALID_PGNO */
      hashp->hdr.free_pages[clevel] = nextp;
#ifdef _FFDB_DEBUG
      fprintf (stderr, "Free map page %d contains no free pages, reuse it\n",
	       fpage);
#endif
    }
  }
  return num;
}
/**
 * Get a free page from free map page if there is one
 * Return 0 when there is no free page
 */
Get a free page from free map page if there is one
Return 0 when there is no free page
Get a free page from free map page if there is one Return 0 when there is no free page
static pgno_t
_ffdb_reuse_free_ovflpage (ffdb_htab_t* hashp)
{
  pgno_t fpage, tp, num, np, nextp;
  void *fpagep;
  unsigned int clevel = hashp->hdr.ovfl_point;
  num = 0;
  if ((fpage = hashp->hdr.free_pages[clevel]) != INVALID_PGNO) {
    fpagep = ffdb_get_page (hashp, fpage, HASH_FREE_PAGE, 0, &tp);
    if (!fpagep) {
      fprintf (stderr, "Fatal error: free map page at %d could not be found\n",
	       fpage);
      abort ();
    }
    if ((np = NUM_FREE_PAGES(fpagep)) > 0) {
      num = FREE_PAGE(fpagep, np - 1);
      NUM_FREE_PAGES(fpagep)--;
      ffdb_put_page (hashp, fpagep, HASH_FREE_PAGE, 1);
    }
    else {
      nextp = NEXT_PGNO(fpagep);
      ffdb_put_page (hashp, fpagep, HASH_OVFL_PAGE, 1);
#ifdef _FFDB_DEBUG
      fprintf (stderr, "Free page %d is not longer needed, put it back\n",
	       fpage);
#endif
      num = fpage;
      hashp->hdr.free_pages[clevel] = nextp;
#ifdef _FFDB_DEBUG
      fprintf (stderr, "Free map page %d contains no free pages, reuse it\n",
	       fpage);
#endif
    }
  }
  return num;
}
static pgno_t _ffdb_reuse_free_ovflpage ( ffdb_htab_t * hashp ) { pgno_t fpage , tp , num , np , nextp ; void * fpagep ; unsigned int clevel = hashp -> hdr . ovfl_point ; num = 0 ; if ( ( fpage = hashp -> hdr . free_pages [ clevel ] ) != INVALID_PGNO ) { fpagep = ffdb_get_page ( hashp , fpage , HASH_FREE_PAGE , 0 , & tp ) ; if ( ! fpagep ) { fprintf ( stderr , " \n " , fpage ) ; abort ( ) ; } if ( ( np = NUM_FREE_PAGES ( fpagep ) ) > 0 ) { num = FREE_PAGE ( fpagep , np - 1 ) ; NUM_FREE_PAGES ( fpagep ) -- ; ffdb_put_page ( hashp , fpagep , HASH_FREE_PAGE , 1 ) ; } else { nextp = NEXT_PGNO ( fpagep ) ; ffdb_put_page ( hashp , fpagep , HASH_OVFL_PAGE , 1 ) ; #ifdef _FFDB_DEBUG fprintf ( stderr , " \n " , fpage ) ; #endif num = fpage ; hashp -> hdr . free_pages [ clevel ] = nextp ; #ifdef _FFDB_DEBUG fprintf ( stderr , " \n " , fpage ) ; #endif } } return num ; }
Get a free page from free map page if there is one
 Return 0 when there is no free page
Get a free page from free map page if there is one Return 0 when there is no free page
/* check current free page number at this level */ /* reduce number of free pages by one */ /* There is no page free anymore, so I can free this 
       * page for a normal use
       *
       * No need to clean this page, we will reset this page upon reloading
       */ /* nextp could be INVALID_PGNO */