to init_htab so that if no page size is specified, the page size will default
to the block size of the file system. Initialize fill factor so that it will
dynamically be set during operation.
SCCS-vsn: lib/libc/db/hash/hash.c 5.35
*/
#if defined(LIBC_SCCS) && !defined(lint)
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)hash.c 5.34 (Berkeley) %G%";
+static char sccsid[] = "@(#)hash.c 5.35 (Berkeley) %G%";
#endif /* LIBC_SCCS and not lint */
#include <sys/param.h>
#endif /* LIBC_SCCS and not lint */
#include <sys/param.h>
static int hash_access __P((HTAB *, ACTION, DBT *, DBT *));
static int hash_close __P((DB *));
static int hash_delete __P((const DB *, const DBT *, u_int));
static int hash_access __P((HTAB *, ACTION, DBT *, DBT *));
static int hash_close __P((DB *));
static int hash_delete __P((const DB *, const DBT *, u_int));
+static int hash_fd __P((const DB *));
static int hash_get __P((const DB *, const DBT *, DBT *, u_int));
static int hash_put __P((const DB *, DBT *, const DBT *, u_int));
static void *hash_realloc __P((SEGMENT **, int, int));
static int hash_seq __P((const DB *, DBT *, DBT *, u_int));
static int hash_sync __P((const DB *, u_int));
static int hdestroy __P((HTAB *));
static int hash_get __P((const DB *, const DBT *, DBT *, u_int));
static int hash_put __P((const DB *, DBT *, const DBT *, u_int));
static void *hash_realloc __P((SEGMENT **, int, int));
static int hash_seq __P((const DB *, DBT *, DBT *, u_int));
static int hash_sync __P((const DB *, u_int));
static int hdestroy __P((HTAB *));
-static HTAB *init_hash __P((HTAB *, HASHINFO *));
+static HTAB *init_hash __P((HTAB *, const char *, HASHINFO *));
static int init_htab __P((HTAB *, int));
#if BYTE_ORDER == LITTLE_ENDIAN
static void swap_header __P((HTAB *));
static int init_htab __P((HTAB *, int));
#if BYTE_ORDER == LITTLE_ENDIAN
static void swap_header __P((HTAB *));
(void)fcntl(hashp->fp, F_SETFD, 1);
}
if (new_table) {
(void)fcntl(hashp->fp, F_SETFD, 1);
}
if (new_table) {
- if (!(hashp = init_hash(hashp, (HASHINFO *)info)))
+ if (!(hashp = init_hash(hashp, file, (HASHINFO *)info)))
RETURN_ERROR(errno, error1);
} else {
/* Table already exists */
RETURN_ERROR(errno, error1);
} else {
/* Table already exists */
dbp->internal = hashp;
dbp->close = hash_close;
dbp->del = hash_delete;
dbp->internal = hashp;
dbp->close = hash_close;
dbp->del = hash_delete;
dbp->get = hash_get;
dbp->put = hash_put;
dbp->seq = hash_seq;
dbp->get = hash_get;
dbp->put = hash_put;
dbp->seq = hash_seq;
+static int
+hash_fd(dbp)
+ const DB *dbp;
+{
+ HTAB *hashp;
+
+ if (!dbp)
+ return (ERROR);
+
+ hashp = (HTAB *)dbp->internal;
+ if (hashp->fp == -1) {
+ errno = ENOENT;
+ return (-1);
+ }
+ return (hashp->fp);
+}
+
/************************** LOCAL CREATION ROUTINES **********************/
static HTAB *
/************************** LOCAL CREATION ROUTINES **********************/
static HTAB *
+init_hash(hashp, file, info)
memset(hashp->SPARES, 0, sizeof(hashp->SPARES));
memset(hashp->BITMAPS, 0, sizeof (hashp->BITMAPS));
memset(hashp->SPARES, 0, sizeof(hashp->SPARES));
memset(hashp->BITMAPS, 0, sizeof (hashp->BITMAPS));
+ /* Fix bucket size to be optimal for file system */
+ if (file != NULL) {
+ if (stat(file, &statbuf))
+ return (NULL);
+ hashp->BSIZE = statbuf.st_blksize;
+ hashp->BSHIFT = __log2(hashp->BSIZE);
+ }
+
if (info) {
if (info->bsize) {
/* Round pagesize up to power of 2 */
if (info) {
if (info->bsize) {
/* Round pagesize up to power of 2 */