filehash/ffdb_page.c
static int
_ffdb_add_item_on_page (ffdb_htab_t* hashp, void* pagep, pgno_t page,
			FFDB_DBT* key, const FFDB_DBT* val,
			unsigned int data_chksum)
{
  unsigned int n, off, soff;
  ffdb_datap_t datap;
  pgno_t dpage, fpage;
  void* memp;
  int status, reuse;
  
  n = NUM_ENT(pagep);
  /* Find place to put the key */
  off = OFFSET(pagep) - key->size + 1;
  memmove (pagep + off, key->data, key->size);

  /* Set Key Offset Value */
  KEY_OFF(pagep, n) = off;
  KEY_LEN(pagep, n) = key->size;

  /*  Find place to put data pointer value */
  off -= sizeof(ffdb_datap_t);
  soff = off;
  /* I have to align this pointer to 4 byte boundary */
  ALIGN_DATAP_OFFSET_VAL(off);

  /* I will fill 0 to the gap of data and key */
  /* ------off---soff-----000key */
  if (off != soff) 
    memset (pagep + off + sizeof(ffdb_datap_t), 0, soff - off);


  /* Here I have to figure out where to put the data */
  reuse = 0;
  fpage = _ffdb_data_page(hashp, 0, &reuse);

#ifdef _FFDB_DEBUG
  fprintf (stderr, "Get data page %d to store data from hash page %d at level %d\n",
	   fpage, page, hashp->hdr.ovfl_point);
#endif

  /* Now I need check this page: get this page first */
  memp = ffdb_get_page (hashp, fpage, HASH_DATA_PAGE, FFDB_CREATE,
			&dpage);
  if (!memp) {
    fprintf (stderr, "cannot get data page for at page number %d\n",
	     dpage);
    return -1;
  }
  

  /* Now Put data on this page: this data can expand multiple pages */
  datap.first = fpage;
  datap.offset = 0;
  datap.len = val->size;
  datap.chksum = data_chksum;

  /* add data to data page provided key page and key index in the page
   * datap offset and first page is updated in the add_data call 
   */
  status = _ffdb_add_data (hashp, page, n, val, memp, dpage, &datap);
  if (status != 0) {
    fprintf (stderr, "cannot put data into data page at page number %d\n",
	     dpage);
    return -1;
  }
#ifdef _FFDB_DEBUG
  fprintf (stderr, "Data len %d is stored at page %d offset %d checksum 0x%x\n",
	   datap.len, datap.first, datap.offset, datap.chksum);
#endif
  memmove (pagep + off, &datap, sizeof(ffdb_datap_t));
  DATAP_OFF(pagep, n) = off;

  /* Update this page information */
  NUM_ENT(pagep) = n + 1;
  OFFSET(pagep) = off - 1;

  return 0;
}
/**
 * Add a pair of key and data onto a page (hash page) represented by
 * page address and page number
 */
Add a pair of key and data onto a page (hash page) represented by
page address and page number
Add a pair of key and data onto a page ( hash page ) represented by page address and page number
static int
_ffdb_add_item_on_page (ffdb_htab_t* hashp, void* pagep, pgno_t page,
			FFDB_DBT* key, const FFDB_DBT* val,
			unsigned int data_chksum)
{
  unsigned int n, off, soff;
  ffdb_datap_t datap;
  pgno_t dpage, fpage;
  void* memp;
  int status, reuse;
  n = NUM_ENT(pagep);
  off = OFFSET(pagep) - key->size + 1;
  memmove (pagep + off, key->data, key->size);
  KEY_OFF(pagep, n) = off;
  KEY_LEN(pagep, n) = key->size;
  off -= sizeof(ffdb_datap_t);
  soff = off;
  ALIGN_DATAP_OFFSET_VAL(off);
  if (off != soff) 
    memset (pagep + off + sizeof(ffdb_datap_t), 0, soff - off);
  reuse = 0;
  fpage = _ffdb_data_page(hashp, 0, &reuse);
#ifdef _FFDB_DEBUG
  fprintf (stderr, "Get data page %d to store data from hash page %d at level %d\n",
	   fpage, page, hashp->hdr.ovfl_point);
#endif
  memp = ffdb_get_page (hashp, fpage, HASH_DATA_PAGE, FFDB_CREATE,
			&dpage);
  if (!memp) {
    fprintf (stderr, "cannot get data page for at page number %d\n",
	     dpage);
    return -1;
  }
  datap.first = fpage;
  datap.offset = 0;
  datap.len = val->size;
  datap.chksum = data_chksum;
  status = _ffdb_add_data (hashp, page, n, val, memp, dpage, &datap);
  if (status != 0) {
    fprintf (stderr, "cannot put data into data page at page number %d\n",
	     dpage);
    return -1;
  }
#ifdef _FFDB_DEBUG
  fprintf (stderr, "Data len %d is stored at page %d offset %d checksum 0x%x\n",
	   datap.len, datap.first, datap.offset, datap.chksum);
#endif
  memmove (pagep + off, &datap, sizeof(ffdb_datap_t));
  DATAP_OFF(pagep, n) = off;
  NUM_ENT(pagep) = n + 1;
  OFFSET(pagep) = off - 1;
  return 0;
}
static int _ffdb_add_item_on_page ( ffdb_htab_t * hashp , void * pagep , pgno_t page , FFDB_DBT * key , const FFDB_DBT * val , unsigned int data_chksum ) { unsigned int n , off , soff ; ffdb_datap_t datap ; pgno_t dpage , fpage ; void * memp ; int status , reuse ; n = NUM_ENT ( pagep ) ; off = OFFSET ( pagep ) - key -> size + 1 ; memmove ( pagep + off , key -> data , key -> size ) ; KEY_OFF ( pagep , n ) = off ; KEY_LEN ( pagep , n ) = key -> size ; off -= sizeof ( ffdb_datap_t ) ; soff = off ; ALIGN_DATAP_OFFSET_VAL ( off ) ; if ( off != soff ) memset ( pagep + off + sizeof ( ffdb_datap_t ) , 0 , soff - off ) ; reuse = 0 ; fpage = _ffdb_data_page ( hashp , 0 , & reuse ) ; #ifdef _FFDB_DEBUG fprintf ( stderr , " \n " , fpage , page , hashp -> hdr . ovfl_point ) ; #endif memp = ffdb_get_page ( hashp , fpage , HASH_DATA_PAGE , FFDB_CREATE , & dpage ) ; if ( ! memp ) { fprintf ( stderr , " \n " , dpage ) ; return -1 ; } datap . first = fpage ; datap . offset = 0 ; datap . len = val -> size ; datap . chksum = data_chksum ; status = _ffdb_add_data ( hashp , page , n , val , memp , dpage , & datap ) ; if ( status != 0 ) { fprintf ( stderr , " \n " , dpage ) ; return -1 ; } #ifdef _FFDB_DEBUG fprintf ( stderr , " \n " , datap . len , datap . first , datap . offset , datap . chksum ) ; #endif memmove ( pagep + off , & datap , sizeof ( ffdb_datap_t ) ) ; DATAP_OFF ( pagep , n ) = off ; NUM_ENT ( pagep ) = n + 1 ; OFFSET ( pagep ) = off - 1 ; return 0 ; }
Add a pair of key and data onto a page (hash page) represented by
 page address and page number
Add a pair of key and data onto a page ( hash page ) represented by page address and page number
/* Find place to put the key */ /* Set Key Offset Value */ /*  Find place to put data pointer value */ /* I have to align this pointer to 4 byte boundary */ /* I will fill 0 to the gap of data and key */ /* ------off---soff-----000key */ /* Here I have to figure out where to put the data */ /* Now I need check this page: get this page first */ /* Now Put data on this page: this data can expand multiple pages */ /* add data to data page provided key page and key index in the page
   * datap offset and first page is updated in the add_data call 
   */ /* Update this page information */