filehash/ffdb_page.c
int 
ffdb_get_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 retrieve user information.\n",
	       page);
      return -1;
    }
    if (i == 0) {
      if (*len < USER_DATA_LEN(pagep)) {
	fprintf (stderr, "Error: provided user buffer size %d < stored data length %d.\n", *len, USER_DATA_LEN(pagep));
	return -1;
      }
      *len = USER_DATA_LEN(pagep);
      rlen = *len;

      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 {
      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 (&data[idx], (unsigned char *)pagep + offset, copylen);

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

    rlen -= copylen;

    page++;
  }
  return 0;
}
/**
 * Get user meta information in the 2nd page
 */
Get user meta information in the 2nd page
Get user meta information in the 2nd page
int 
ffdb_get_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 retrieve user information.\n",
	       page);
      return -1;
    }
    if (i == 0) {
      if (*len < USER_DATA_LEN(pagep)) {
	fprintf (stderr, "Error: provided user buffer size %d < stored data length %d.\n", *len, USER_DATA_LEN(pagep));
	return -1;
      }
      *len = USER_DATA_LEN(pagep);
      rlen = *len;
      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 {
      if (rlen > hashp->hdr.bsize - PAGE_OVERHEAD) 
	copylen = hashp->hdr.bsize - PAGE_OVERHEAD;
      else
	copylen = rlen;
      offset = PAGE_OVERHEAD;
    }
    idx = *len - rlen;
    memcpy (&data[idx], (unsigned char *)pagep + offset, copylen);
    ffdb_put_page (hashp, pagep, TYPE(pagep), 0);
    rlen -= copylen;
    page++;
  }
  return 0;
}
int ffdb_get_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 ) { if ( * len < USER_DATA_LEN ( pagep ) ) { fprintf ( stderr , " \n " , * len , USER_DATA_LEN ( pagep ) ) ; return -1 ; } * len = USER_DATA_LEN ( pagep ) ; rlen = * len ; 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 { if ( rlen > hashp -> hdr . bsize - PAGE_OVERHEAD ) copylen = hashp -> hdr . bsize - PAGE_OVERHEAD ; else copylen = rlen ; offset = PAGE_OVERHEAD ; } idx = * len - rlen ; memcpy ( & data [ idx ] , ( unsigned char * ) pagep + offset , copylen ) ; ffdb_put_page ( hashp , pagep , TYPE ( pagep ) , 0 ) ; rlen -= copylen ; page ++ ; } return 0 ; }
Get user meta information in the 2nd page
Get user meta information in the 2nd page
/* where to start copy from data */ /* put page out */