filehash/ffdb_page.c
static int
_ffdb_replace_item_on_page (ffdb_htab_t* hashp,
			    FFDB_DBT* key, const FFDB_DBT* val,
			    ffdb_hent_t* item)
{
  int status;
  ffdb_datap_t* datap;
  pgno_t dpage;
  void* memp;

  /* Get current data pointer information of this key */
  datap = DATAP (item->pagep, item->pgndx);
  
#ifdef _FFDB_DEBUG
  fprintf (stderr, "Replace Key %s information: \n", (char *)key->data);
  fprintf (stderr, "At first page %d\n", datap->first);
  fprintf (stderr, "At offset %d\n", datap->offset);
  fprintf (stderr, "Length of data %d\n", datap->len);
  fprintf (stderr, "Checksum of data is 0x%x\n", datap->chksum);
  fprintf (stderr, "With new data size of %d\n", val->size);
  fprintf (stderr, "new check sum = 0x%x\n", item->data_chksum);
#endif
  if (val->size > datap->len) {
    fprintf (stderr, "Replacement data size %d is larger than the existing data size %d\n", val->size, datap->len);
    return -1;
  }
  
  /* Now I can put data on the page pointed by data pointer */
  memp = ffdb_get_page (hashp, datap->first, HASH_DATA_PAGE, 0,
			&dpage);
  if (!memp) {
    fprintf (stderr, "Cannot get data page %d to replace data at offset %d\n",	     datap->first, datap->offset);
    return -1;
  }

  /* Change data pointer value */
  datap->len = val->size;
  datap->chksum = item->data_chksum;

  status = _ffdb_replace_data (hashp, val, memp, dpage, datap);

  if (status != 0) {
    fprintf (stderr, "Cannot replace data of len %d on page %d at offset %d\n",
	     datap->len, dpage, datap->offset);
    return -1;
  }

  return 0;
}
/**
 * Replace a hash item on the page identified by item structure
 * Data can be only replaced when the new data has size <= the existing
 * data size
 */
Replace a hash item on the page identified by item structure
Data can be only replaced when the new data has size <= the existing
data size
Replace a hash item on the page identified by item structure Data can be only replaced when the new data has size < = the existing data size
static int
_ffdb_replace_item_on_page (ffdb_htab_t* hashp,
			    FFDB_DBT* key, const FFDB_DBT* val,
			    ffdb_hent_t* item)
{
  int status;
  ffdb_datap_t* datap;
  pgno_t dpage;
  void* memp;
  datap = DATAP (item->pagep, item->pgndx);
#ifdef _FFDB_DEBUG
  fprintf (stderr, "Replace Key %s information: \n", (char *)key->data);
  fprintf (stderr, "At first page %d\n", datap->first);
  fprintf (stderr, "At offset %d\n", datap->offset);
  fprintf (stderr, "Length of data %d\n", datap->len);
  fprintf (stderr, "Checksum of data is 0x%x\n", datap->chksum);
  fprintf (stderr, "With new data size of %d\n", val->size);
  fprintf (stderr, "new check sum = 0x%x\n", item->data_chksum);
#endif
  if (val->size > datap->len) {
    fprintf (stderr, "Replacement data size %d is larger than the existing data size %d\n", val->size, datap->len);
    return -1;
  }
  memp = ffdb_get_page (hashp, datap->first, HASH_DATA_PAGE, 0,
			&dpage);
  if (!memp) {
    fprintf (stderr, "Cannot get data page %d to replace data at offset %d\n",	     datap->first, datap->offset);
    return -1;
  }
  datap->len = val->size;
  datap->chksum = item->data_chksum;
  status = _ffdb_replace_data (hashp, val, memp, dpage, datap);
  if (status != 0) {
    fprintf (stderr, "Cannot replace data of len %d on page %d at offset %d\n",
	     datap->len, dpage, datap->offset);
    return -1;
  }
  return 0;
}
static int _ffdb_replace_item_on_page ( ffdb_htab_t * hashp , FFDB_DBT * key , const FFDB_DBT * val , ffdb_hent_t * item ) { int status ; ffdb_datap_t * datap ; pgno_t dpage ; void * memp ; datap = DATAP ( item -> pagep , item -> pgndx ) ; #ifdef _FFDB_DEBUG fprintf ( stderr , " \n " , ( char * ) key -> data ) ; fprintf ( stderr , " \n " , datap -> first ) ; fprintf ( stderr , " \n " , datap -> offset ) ; fprintf ( stderr , " \n " , datap -> len ) ; fprintf ( stderr , " \n " , datap -> chksum ) ; fprintf ( stderr , " \n " , val -> size ) ; fprintf ( stderr , " \n " , item -> data_chksum ) ; #endif if ( val -> size > datap -> len ) { fprintf ( stderr , " \n " , val -> size , datap -> len ) ; return -1 ; } memp = ffdb_get_page ( hashp , datap -> first , HASH_DATA_PAGE , 0 , & dpage ) ; if ( ! memp ) { fprintf ( stderr , " \n " , datap -> first , datap -> offset ) ; return -1 ; } datap -> len = val -> size ; datap -> chksum = item -> data_chksum ; status = _ffdb_replace_data ( hashp , val , memp , dpage , datap ) ; if ( status != 0 ) { fprintf ( stderr , " \n " , datap -> len , dpage , datap -> offset ) ; return -1 ; } return 0 ; }
Replace a hash item on the page identified by item structure
 Data can be only replaced when the new data has size <= the existing
 data size
Replace a hash item on the page identified by item structure Data can be only replaced when the new data has size < = the existing data size
/* Get current data pointer information of this key */ /* Now I can put data on the page pointed by data pointer */ /* Change data pointer value */