filehash/ffdb_page.c
int 
ffdb_set_uinfo (ffdb_htab_t* hashp, unsigned char* data,
		unsigned int len)
{
  unsigned int i, copylen, offset, idx, rlen;
  pgno_t page, tp;
  void* pagep;
  
  idx = 0;
  rlen = len;
  page = hashp->hdr.uinfo_page;
  for (i = 0; i < hashp->hdr.uinfo_npages; i++) {
    pagep = ffdb_get_page (hashp, page, HASH_UINFO_PAGE, 0, &tp);
    if (!pagep) {
      fprintf (stderr, "Cannot get page %d to store user information.\n",
	       page);
      return -1;
    }
    if (i == 0) {
      /* Set number of item to 1 on the first page */
      NUM_ENT(pagep) = 1;
      USER_DATA_LEN(pagep) = rlen;
      if (rlen > hashp->hdr.bsize - PAGE_OVERHEAD - sizeof(unsigned int)) 
	copylen = hashp->hdr.bsize - PAGE_OVERHEAD - sizeof(unsigned int);
      else 
	copylen = rlen;
      offset = PAGE_OVERHEAD + sizeof(unsigned int);
    }
    else {
      /* Set number of item to 0 on the other pages */
      NUM_ENT(pagep) = 0;
      if (rlen > hashp->hdr.bsize - PAGE_OVERHEAD) 
	copylen = hashp->hdr.bsize - PAGE_OVERHEAD;
      else
	copylen = rlen;
      offset = PAGE_OVERHEAD;
    }
    /* where to start copy from data */
    idx = len - rlen;

    memcpy ((unsigned char *)pagep + offset, &data[idx], copylen);

    /* put page out */
    ffdb_put_page (hashp, pagep, TYPE(pagep), 1);

    rlen -= copylen;

    page++;
  }
  return 0;
}
/**
 * Set user meta information in the 2nd page
 */
Set user meta information in the 2nd page
Set user meta information in the 2nd page
int 
ffdb_set_uinfo (ffdb_htab_t* hashp, unsigned char* data,
		unsigned int len)
{
  unsigned int i, copylen, offset, idx, rlen;
  pgno_t page, tp;
  void* pagep;
  idx = 0;
  rlen = len;
  page = hashp->hdr.uinfo_page;
  for (i = 0; i < hashp->hdr.uinfo_npages; i++) {
    pagep = ffdb_get_page (hashp, page, HASH_UINFO_PAGE, 0, &tp);
    if (!pagep) {
      fprintf (stderr, "Cannot get page %d to store user information.\n",
	       page);
      return -1;
    }
    if (i == 0) {
      NUM_ENT(pagep) = 1;
      USER_DATA_LEN(pagep) = rlen;
      if (rlen > hashp->hdr.bsize - PAGE_OVERHEAD - sizeof(unsigned int)) 
	copylen = hashp->hdr.bsize - PAGE_OVERHEAD - sizeof(unsigned int);
      else 
	copylen = rlen;
      offset = PAGE_OVERHEAD + sizeof(unsigned int);
    }
    else {
      NUM_ENT(pagep) = 0;
      if (rlen > hashp->hdr.bsize - PAGE_OVERHEAD) 
	copylen = hashp->hdr.bsize - PAGE_OVERHEAD;
      else
	copylen = rlen;
      offset = PAGE_OVERHEAD;
    }
    idx = len - rlen;
    memcpy ((unsigned char *)pagep + offset, &data[idx], copylen);
    ffdb_put_page (hashp, pagep, TYPE(pagep), 1);
    rlen -= copylen;
    page++;
  }
  return 0;
}
int ffdb_set_uinfo ( ffdb_htab_t * hashp , unsigned char * data , unsigned int len ) { unsigned int i , copylen , offset , idx , rlen ; pgno_t page , tp ; void * pagep ; idx = 0 ; rlen = len ; page = hashp -> hdr . uinfo_page ; for ( i = 0 ; i < hashp -> hdr . uinfo_npages ; i ++ ) { pagep = ffdb_get_page ( hashp , page , HASH_UINFO_PAGE , 0 , & tp ) ; if ( ! pagep ) { fprintf ( stderr , " \n " , page ) ; return -1 ; } if ( i == 0 ) { NUM_ENT ( pagep ) = 1 ; USER_DATA_LEN ( pagep ) = rlen ; if ( rlen > hashp -> hdr . bsize - PAGE_OVERHEAD - sizeof ( unsigned int ) ) copylen = hashp -> hdr . bsize - PAGE_OVERHEAD - sizeof ( unsigned int ) ; else copylen = rlen ; offset = PAGE_OVERHEAD + sizeof ( unsigned int ) ; } else { NUM_ENT ( pagep ) = 0 ; if ( rlen > hashp -> hdr . bsize - PAGE_OVERHEAD ) copylen = hashp -> hdr . bsize - PAGE_OVERHEAD ; else copylen = rlen ; offset = PAGE_OVERHEAD ; } idx = len - rlen ; memcpy ( ( unsigned char * ) pagep + offset , & data [ idx ] , copylen ) ; ffdb_put_page ( hashp , pagep , TYPE ( pagep ) , 1 ) ; rlen -= copylen ; page ++ ; } return 0 ; }
Set user meta information in the 2nd page
Set user meta information in the 2nd page
/* Set number of item to 1 on the first page */ /* Set number of item to 0 on the other pages */ /* where to start copy from data */ /* put page out */