filehash/ffdb_hash.c
static int
_ffdb_init_hash(ffdb_htab_t* hashp, const char* file, 
		FFDB_HASHINFO* info)
{
  struct stat statbuf;

  /* This is the machine we are writing the database on
   * and we are using the native format
   */
  hashp->hdr.lorder = _ffdb_test_endian ();
#if 0
  if (hashp->hdr.lorder == LITTLE_ENDIAN) 
    fprintf (stderr, "Info: Data will be stored in little endian format.\n");
  else
    fprintf (stderr, "Info: Data will be stored in big endian format.\n");
#endif

  hashp->hdr.nkeys = 0;
  hashp->hdr.bsize = DEF_BUCKET_SIZE;
  hashp->hdr.bshift = DEF_BUCKET_SHIFT;
  hashp->hdr.ffactor = DEF_FFACTOR;
  hashp->hash = __ffdb_default_hash;
  hashp->h_compare = __ffdb_default_cmp;
  memset(hashp->hdr.spares, 0, sizeof(hashp->hdr.spares));

  /* Fix bucket size to be optimal for file system */
  /* This is not very reliable for NFS based file system */
  if (stat(file, &statbuf) != 0)
    return errno;
  hashp->hdr.bsize = statbuf.st_blksize;
  hashp->hdr.bshift = __ffdb_log2(hashp->hdr.bsize);
	
  if (info) {
    if (info->bsize) {
      /* Round pagesize up to power of 2 */
      hashp->hdr.bshift = __ffdb_log2(info->bsize);
      hashp->hdr.bsize = 1 << hashp->hdr.bshift;
      if (hashp->hdr.bsize > MAX_BSIZE) {
	errno = EINVAL;
	return errno;
      }
      /* the header occupies one page    */
      if (hashp->hdr.bsize < sizeof(ffdb_hashhdr_t)) {
	fprintf (stderr, "Hash page is too small to handle meta info.\n");
	errno = EINVAL;
	return errno;
      }
    }

    /* Set rearrange page flag */
    hashp->rearrange_pages = info->rearrangepages;
    
#if 0
    if (info->hash)
      hashp->hash = info->hash;
    if (info->cmp)
      hashp->h_compare = info->cmp;
#endif
  }

  return 0;
}
/**
 * Initialize hashtable values
 * return 0 on sucess, errno or -1 on failure
 */
Initialize hashtable values
return 0 on sucess, errno or -1 on failure
Initialize hashtable values return 0 on sucess errno or - 1 on failure
static int
_ffdb_init_hash(ffdb_htab_t* hashp, const char* file, 
		FFDB_HASHINFO* info)
{
  struct stat statbuf;
  hashp->hdr.lorder = _ffdb_test_endian ();
#if 0
  if (hashp->hdr.lorder == LITTLE_ENDIAN) 
    fprintf (stderr, "Info: Data will be stored in little endian format.\n");
  else
    fprintf (stderr, "Info: Data will be stored in big endian format.\n");
#endif
  hashp->hdr.nkeys = 0;
  hashp->hdr.bsize = DEF_BUCKET_SIZE;
  hashp->hdr.bshift = DEF_BUCKET_SHIFT;
  hashp->hdr.ffactor = DEF_FFACTOR;
  hashp->hash = __ffdb_default_hash;
  hashp->h_compare = __ffdb_default_cmp;
  memset(hashp->hdr.spares, 0, sizeof(hashp->hdr.spares));
  if (stat(file, &statbuf) != 0)
    return errno;
  hashp->hdr.bsize = statbuf.st_blksize;
  hashp->hdr.bshift = __ffdb_log2(hashp->hdr.bsize);
  if (info) {
    if (info->bsize) {
      hashp->hdr.bshift = __ffdb_log2(info->bsize);
      hashp->hdr.bsize = 1 << hashp->hdr.bshift;
      if (hashp->hdr.bsize > MAX_BSIZE) {
	errno = EINVAL;
	return errno;
      }
      if (hashp->hdr.bsize < sizeof(ffdb_hashhdr_t)) {
	fprintf (stderr, "Hash page is too small to handle meta info.\n");
	errno = EINVAL;
	return errno;
      }
    }
    hashp->rearrange_pages = info->rearrangepages;
#if 0
    if (info->hash)
      hashp->hash = info->hash;
    if (info->cmp)
      hashp->h_compare = info->cmp;
#endif
  }
  return 0;
}
static int _ffdb_init_hash ( ffdb_htab_t * hashp , const char * file , FFDB_HASHINFO * info ) { struct stat statbuf ; hashp -> hdr . lorder = _ffdb_test_endian ( ) ; #if 0 if ( hashp -> hdr . lorder == LITTLE_ENDIAN ) fprintf ( stderr , " \n " ) ; else fprintf ( stderr , " \n " ) ; #endif hashp -> hdr . nkeys = 0 ; hashp -> hdr . bsize = DEF_BUCKET_SIZE ; hashp -> hdr . bshift = DEF_BUCKET_SHIFT ; hashp -> hdr . ffactor = DEF_FFACTOR ; hashp -> hash = __ffdb_default_hash ; hashp -> h_compare = __ffdb_default_cmp ; memset ( hashp -> hdr . spares , 0 , sizeof ( hashp -> hdr . spares ) ) ; if ( stat ( file , & statbuf ) != 0 ) return errno ; hashp -> hdr . bsize = statbuf . st_blksize ; hashp -> hdr . bshift = __ffdb_log2 ( hashp -> hdr . bsize ) ; if ( info ) { if ( info -> bsize ) { hashp -> hdr . bshift = __ffdb_log2 ( info -> bsize ) ; hashp -> hdr . bsize = 1 << hashp -> hdr . bshift ; if ( hashp -> hdr . bsize > MAX_BSIZE ) { errno = EINVAL ; return errno ; } if ( hashp -> hdr . bsize < sizeof ( ffdb_hashhdr_t ) ) { fprintf ( stderr , " \n " ) ; errno = EINVAL ; return errno ; } } hashp -> rearrange_pages = info -> rearrangepages ; #if 0 if ( info -> hash ) hashp -> hash = info -> hash ; if ( info -> cmp ) hashp -> h_compare = info -> cmp ; #endif } return 0 ; }
Initialize hashtable values
 return 0 on sucess, errno or -1 on failure
Initialize hashtable values return 0 on sucess errno or - 1 on failure
/* This is the machine we are writing the database on
   * and we are using the native format
   */ /* Fix bucket size to be optimal for file system */ /* This is not very reliable for NFS based file system */ /* Round pagesize up to power of 2 */ /* the header occupies one page    */ /* Set rearrange page flag */