can't have a global "hashp", pass it around as an argument
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Mon, 18 Jan 1993 08:20:24 +0000 (00:20 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Mon, 18 Jan 1993 08:20:24 +0000 (00:20 -0800)
change default_hash to __default_hash for the same reason

SCCS-vsn: lib/libc/db/hash/extern.h 5.3
SCCS-vsn: lib/libc/db/hash/hash.c 5.30
SCCS-vsn: lib/libc/db/hash/hash_bigkey.c 5.8
SCCS-vsn: lib/libc/db/hash/hash_buf.c 5.11
SCCS-vsn: lib/libc/db/hash/hash_func.c 5.3
SCCS-vsn: lib/libc/db/hash/hash_page.c 5.23

usr/src/lib/libc/db/hash/extern.h
usr/src/lib/libc/db/hash/hash.c
usr/src/lib/libc/db/hash/hash_bigkey.c
usr/src/lib/libc/db/hash/hash_buf.c
usr/src/lib/libc/db/hash/hash_func.c
usr/src/lib/libc/db/hash/hash_page.c

index 7d820f3..c3f6a77 100644 (file)
@@ -4,35 +4,36 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)extern.h    5.2 (Berkeley) %G%
+ *     @(#)extern.h    5.3 (Berkeley) %G%
  */
 
  */
 
-BUFHEAD        *__add_ovflpage __P((BUFHEAD *));
-int     __addel __P((BUFHEAD *, const DBT *, const DBT *));
-int     __big_delete __P((BUFHEAD *));
-int     __big_insert __P((BUFHEAD *, const DBT *, const DBT *));
-int     __big_keydata __P((BUFHEAD *, DBT *, DBT *, int));
-int     __big_return __P((BUFHEAD *, int, DBT *, int));
-int     __big_split __P((BUFHEAD *, BUFHEAD *, BUFHEAD *,
+BUFHEAD        *__add_ovflpage __P((HTAB *, BUFHEAD *));
+int     __addel __P((HTAB *, BUFHEAD *, const DBT *, const DBT *));
+int     __big_delete __P((HTAB *, BUFHEAD *));
+int     __big_insert __P((HTAB *, BUFHEAD *, const DBT *, const DBT *));
+int     __big_keydata __P((HTAB *, BUFHEAD *, DBT *, DBT *, int));
+int     __big_return __P((HTAB *, BUFHEAD *, int, DBT *, int));
+int     __big_split __P((HTAB *, BUFHEAD *, BUFHEAD *, BUFHEAD *,
                int, u_int, SPLIT_RETURN *));
                int, u_int, SPLIT_RETURN *));
-int     __buf_free __P((int, int));
-void    __buf_init __P((int));
-u_int   __call_hash __P((char *, int));
-int     __delpair __P((BUFHEAD *, int));
-int     __expand_table __P((void));
-int     __find_bigpair __P((BUFHEAD *, int, char *, int));
-u_short         __find_last_page __P((BUFHEAD **));
-void    __free_ovflpage __P((BUFHEAD *));
-BUFHEAD        *__get_buf __P((u_int, BUFHEAD *, int));
-int     __get_page __P((char *, u_int, int, int, int));
-int     __init_bitmap __P((int, int, int));
+int     __buf_free __P((HTAB *, int, int));
+void    __buf_init __P((HTAB *, int));
+u_int   __call_hash __P((HTAB *, char *, int));
+int     __delpair __P((HTAB *, BUFHEAD *, int));
+int     __expand_table __P((HTAB *));
+int     __find_bigpair __P((HTAB *, BUFHEAD *, int, char *, int));
+u_short         __find_last_page __P((HTAB *, BUFHEAD **));
+void    __free_ovflpage __P((HTAB *, BUFHEAD *));
+BUFHEAD        *__get_buf __P((HTAB *, u_int, BUFHEAD *, int));
+int     __get_page __P((HTAB *, char *, u_int, int, int, int));
+int     __init_bitmap __P((HTAB *, int, int, int));
 u_int   __log2 __P((u_int));
 u_int   __log2 __P((u_int));
-int     __put_page __P((char *, u_int, int, int));
-void    __reclaim_buf __P((BUFHEAD *));
-int     __split_page __P((u_int, u_int));
+int     __put_page __P((HTAB *, char *, u_int, int, int));
+void    __reclaim_buf __P((HTAB *, BUFHEAD *));
+int     __split_page __P((HTAB *, u_int, u_int));
+
+/* Default hash routine. */
+extern int     (*__default_hash) __P((u_char *, int));
 
 
-extern HTAB *hashp;
 #ifdef HASH_STATISTICS
 extern long hash_accesses, hash_collisions, hash_expansions, hash_overflows;
 #endif
 #ifdef HASH_STATISTICS
 extern long hash_accesses, hash_collisions, hash_expansions, hash_overflows;
 #endif
-extern int (*default_hash) __P((u_char *, int));
index f4e9dbe..b34979b 100644 (file)
@@ -9,29 +9,30 @@
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)hash.c     5.29 (Berkeley) %G%";
+static char sccsid[] = "@(#)hash.c     5.30 (Berkeley) %G%";
 #endif /* LIBC_SCCS and not lint */
 
 #include <sys/param.h>
 #include <sys/stat.h>
 
 #endif /* LIBC_SCCS and not lint */
 
 #include <sys/param.h>
 #include <sys/stat.h>
 
-#include <fcntl.h>
-#include <errno.h>
-#ifdef DEBUG
-#include <assert.h>
-#endif
 #include <db.h>
 #include <db.h>
+#include <errno.h>
+#include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <unistd.h>
 #include <string.h>
 #include <string.h>
+#include <unistd.h>
+#ifdef DEBUG
+#include <assert.h>
+#endif
+
 #include "hash.h"
 #include "page.h"
 #include "extern.h"
 
 #include "hash.h"
 #include "page.h"
 #include "extern.h"
 
-static int   alloc_segs __P((int));
-static int   flush_meta __P((void));
-static int   hash_access __P((ACTION, DBT *, DBT *));
+static int   alloc_segs __P((HTAB *, int));
+static int   flush_meta __P((HTAB *));
+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_get __P((const DB *, const DBT *, DBT *, u_int));
 static int   hash_close __P((DB *));
 static int   hash_delete __P((const DB *, const DBT *, u_int));
 static int   hash_get __P((const DB *, const DBT *, DBT *, u_int));
@@ -39,11 +40,11 @@ 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 *));
 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 *));
-static int   hdestroy __P((void));
-static HTAB *init_hash __P((HASHINFO *));
-static int   init_htab __P((int));
+static int   hdestroy __P((HTAB *));
+static HTAB *init_hash __P((HTAB *, HASHINFO *));
+static int   init_htab __P((HTAB *, int));
 #if BYTE_ORDER == LITTLE_ENDIAN
 #if BYTE_ORDER == LITTLE_ENDIAN
-static void  swap_header __P((void));
+static void  swap_header __P((HTAB *, void));
 static void  swap_header_copy __P((HASHHDR *, HASHHDR *));
 #endif
 
 static void  swap_header_copy __P((HASHHDR *, HASHHDR *));
 #endif
 
@@ -57,9 +58,6 @@ static void  swap_header_copy __P((HASHHDR *, HASHHDR *));
 #define        ERROR   (-1)
 #define        ABNORMAL (1)
 
 #define        ERROR   (-1)
 #define        ABNORMAL (1)
 
-/* Local data */
-HTAB *hashp = NULL;
-
 #ifdef HASH_STATISTICS
 long hash_accesses, hash_collisions, hash_expansions, hash_overflows;
 #endif
 #ifdef HASH_STATISTICS
 long hash_accesses, hash_collisions, hash_expansions, hash_overflows;
 #endif
@@ -73,6 +71,7 @@ __hash_open(file, flags, mode, info)
        int flags, mode;
        const HASHINFO *info;   /* Special directives for create */
 {
        int flags, mode;
        const HASHINFO *info;   /* Special directives for create */
 {
+       HTAB *hashp;
        struct stat statbuf;
        DB *dbp;
        int bpages, hdrsize, new_table, nsegs, save_errno;
        struct stat statbuf;
        DB *dbp;
        int bpages, hdrsize, new_table, nsegs, save_errno;
@@ -106,18 +105,18 @@ __hash_open(file, flags, mode, info)
                (void)fcntl(hashp->fp, F_SETFD, 1);
        }
        if (new_table) {
                (void)fcntl(hashp->fp, F_SETFD, 1);
        }
        if (new_table) {
-               if (!(hashp = init_hash((HASHINFO *)info)))
+               if (!(hashp = init_hash(hashp, (HASHINFO *)info)))
                        RETURN_ERROR(errno, error1);
        } else {
                /* Table already exists */
                if (info && info->hash)
                        hashp->hash = info->hash;
                else
                        RETURN_ERROR(errno, error1);
        } else {
                /* Table already exists */
                if (info && info->hash)
                        hashp->hash = info->hash;
                else
-                       hashp->hash = default_hash;
+                       hashp->hash = __default_hash;
 
                hdrsize = read(hashp->fp, &hashp->hdr, sizeof(HASHHDR));
 #if BYTE_ORDER == LITTLE_ENDIAN
 
                hdrsize = read(hashp->fp, &hashp->hdr, sizeof(HASHHDR));
 #if BYTE_ORDER == LITTLE_ENDIAN
-               swap_header();
+               swap_header(hashp);
 #endif
                if (hdrsize == -1)
                        RETURN_ERROR(errno, error1);
 #endif
                if (hdrsize == -1)
                        RETURN_ERROR(errno, error1);
@@ -138,7 +137,7 @@ __hash_open(file, flags, mode, info)
                nsegs = (hashp->MAX_BUCKET + 1 + hashp->SGSIZE - 1) /
                         hashp->SGSIZE;
                hashp->nsegs = 0;
                nsegs = (hashp->MAX_BUCKET + 1 + hashp->SGSIZE - 1) /
                         hashp->SGSIZE;
                hashp->nsegs = 0;
-               if (alloc_segs(nsegs))
+               if (alloc_segs(hashp, nsegs))
                        /*
                         * If alloc_segs fails, table will have been destroyed
                         * and errno will have been set.
                        /*
                         * If alloc_segs fails, table will have been destroyed
                         * and errno will have been set.
@@ -155,20 +154,20 @@ __hash_open(file, flags, mode, info)
 
        /* Initialize Buffer Manager */
        if (info && info->cachesize)
 
        /* Initialize Buffer Manager */
        if (info && info->cachesize)
-               __buf_init(info->cachesize);
+               __buf_init(hashp, info->cachesize);
        else
        else
-               __buf_init(DEF_BUFSIZE);
+               __buf_init(hashp, DEF_BUFSIZE);
 
        hashp->new_file = new_table;
        hashp->save_file = file && (hashp->flags & O_RDWR);
        hashp->cbucket = -1;
        if (!(dbp = malloc(sizeof(DB)))) {
                save_errno = errno;
 
        hashp->new_file = new_table;
        hashp->save_file = file && (hashp->flags & O_RDWR);
        hashp->cbucket = -1;
        if (!(dbp = malloc(sizeof(DB)))) {
                save_errno = errno;
-               hdestroy();
+               hdestroy(hashp);
                errno = save_errno;
                return (NULL);
        }
                errno = save_errno;
                return (NULL);
        }
-       dbp->internal = (char *)hashp;
+       dbp->internal = hashp;
        dbp->close = hash_close;
        dbp->del = hash_delete;
        dbp->get = hash_get;
        dbp->close = hash_close;
        dbp->del = hash_delete;
        dbp->get = hash_get;
@@ -215,19 +214,22 @@ static int
 hash_close(dbp)
        DB *dbp;
 {
 hash_close(dbp)
        DB *dbp;
 {
+       HTAB *hashp;
        int retval;
 
        if (!dbp)
                return (ERROR);
        int retval;
 
        if (!dbp)
                return (ERROR);
+
        hashp = (HTAB *)dbp->internal;
        hashp = (HTAB *)dbp->internal;
-       retval = hdestroy();
+       retval = hdestroy(hashp);
        free(dbp);
        return (retval);
 }
 
 /************************** LOCAL CREATION ROUTINES **********************/
 static HTAB *
        free(dbp);
        return (retval);
 }
 
 /************************** LOCAL CREATION ROUTINES **********************/
 static HTAB *
-init_hash(info)
+init_hash(hashp, info)
+       HTAB *hashp;
        HASHINFO *info;
 {
        int nelem;
        HASHINFO *info;
 {
        int nelem;
@@ -241,7 +243,7 @@ init_hash(info)
        hashp->SSHIFT = DEF_SEGSIZE_SHIFT;
        hashp->DSIZE = DEF_DIRSIZE;
        hashp->FFACTOR = DEF_FFACTOR;
        hashp->SSHIFT = DEF_SEGSIZE_SHIFT;
        hashp->DSIZE = DEF_DIRSIZE;
        hashp->FFACTOR = DEF_FFACTOR;
-       hashp->hash = default_hash;
+       hashp->hash = __default_hash;
        bzero(hashp->SPARES, sizeof(hashp->SPARES));
        bzero (hashp->BITMAPS, sizeof (hashp->BITMAPS));
 
        bzero(hashp->SPARES, sizeof(hashp->SPARES));
        bzero (hashp->BITMAPS, sizeof (hashp->BITMAPS));
 
@@ -271,7 +273,7 @@ init_hash(info)
                }
        }
        /* init_htab should destroy the table and set errno if it fails */
                }
        }
        /* init_htab should destroy the table and set errno if it fails */
-       if (init_htab(nelem))
+       if (init_htab(hashp, nelem))
                return (NULL);
        else
                return (hashp);
                return (NULL);
        else
                return (hashp);
@@ -283,7 +285,8 @@ init_hash(info)
  * Returns 0 on No Error
  */
 static int
  * Returns 0 on No Error
  */
 static int
-init_htab(nelem)
+init_htab(hashp, nelem)
+       HTAB *hashp;
        int nelem;
 {
        register int nbuckets, nsegs;
        int nelem;
 {
        register int nbuckets, nsegs;
@@ -305,7 +308,7 @@ init_htab(nelem)
        hashp->LAST_FREED = 2;
 
        /* First bitmap page is at: splitpoint l2 page offset 1 */
        hashp->LAST_FREED = 2;
 
        /* First bitmap page is at: splitpoint l2 page offset 1 */
-       if (__init_bitmap(OADDR_OF(l2, 1), l2 + 1, 0))
+       if (__init_bitmap(hashp, OADDR_OF(l2, 1), l2 + 1, 0))
                return (-1);
 
        hashp->MAX_BUCKET = hashp->LOW_MASK = nbuckets - 1;
                return (-1);
 
        hashp->MAX_BUCKET = hashp->LOW_MASK = nbuckets - 1;
@@ -318,7 +321,7 @@ init_htab(nelem)
 
        if (nsegs > hashp->DSIZE)
                hashp->DSIZE = nsegs;
 
        if (nsegs > hashp->DSIZE)
                hashp->DSIZE = nsegs;
-       return (alloc_segs(nsegs));
+       return (alloc_segs(hashp, nsegs));
 }
 
 /********************** DESTROY/CLOSE ROUTINES ************************/
 }
 
 /********************** DESTROY/CLOSE ROUTINES ************************/
@@ -328,52 +331,50 @@ init_htab(nelem)
  * structure, freeing all allocated space.
  */
 static int
  * structure, freeing all allocated space.
  */
 static int
-hdestroy()
+hdestroy(hashp)
+       HTAB *hashp;
 {
        int i, save_errno;
 
        save_errno = 0;
 
 {
        int i, save_errno;
 
        save_errno = 0;
 
-       if (hashp != NULL) {
 #ifdef HASH_STATISTICS
 #ifdef HASH_STATISTICS
-               (void)fprintf(stderr, "hdestroy: accesses %ld collisions %ld\n",
-                   hash_accesses, hash_collisions);
-               (void)fprintf(stderr, "hdestroy: expansions %ld\n",
-                   hash_expansions);
-               (void)fprintf(stderr, "hdestroy: overflows %ld\n",
-                   hash_overflows);
-               (void)fprintf(stderr, "keys %ld maxp %d segmentcount %d\n",
-                   hashp->NKEYS, hashp->MAX_BUCKET, hashp->nsegs);
-
-               for (i = 0; i < NCACHED; i++)
-                       (void)fprintf(stderr,
-                           "spares[%d] = %d\n", i, hashp->SPARES[i]);
+       (void)fprintf(stderr, "hdestroy: accesses %ld collisions %ld\n",
+           hash_accesses, hash_collisions);
+       (void)fprintf(stderr, "hdestroy: expansions %ld\n",
+           hash_expansions);
+       (void)fprintf(stderr, "hdestroy: overflows %ld\n",
+           hash_overflows);
+       (void)fprintf(stderr, "keys %ld maxp %d segmentcount %d\n",
+           hashp->NKEYS, hashp->MAX_BUCKET, hashp->nsegs);
+
+       for (i = 0; i < NCACHED; i++)
+               (void)fprintf(stderr,
+                   "spares[%d] = %d\n", i, hashp->SPARES[i]);
 #endif
 #endif
-               /*
-                * Call on buffer manager to free buffers, and if required,
-                * write them to disk.
-                */
-               if (__buf_free(1, hashp->save_file))
-                       save_errno = errno;
-               if (hashp->dir) {
-                       free(*hashp->dir);      /* Free initial segments */
-                       /* Free extra segments */
-                       while (hashp->exsegs--)
-                               free(hashp->dir[--hashp->nsegs]);
-                       free(hashp->dir);
-               }
-               if (flush_meta() && !save_errno)
-                       save_errno = errno;
-               /* Free Bigmaps */
-               for (i = 0; i < hashp->nmaps; i++)
-                       if (hashp->mapp[i])
-                               free(hashp->mapp[i]);
-
-               if (hashp->fp != -1)
-                       (void)close(hashp->fp);
-               free(hashp);
-               hashp = NULL;
+       /*
+        * Call on buffer manager to free buffers, and if required,
+        * write them to disk.
+        */
+       if (__buf_free(hashp, 1, hashp->save_file))
+               save_errno = errno;
+       if (hashp->dir) {
+               free(*hashp->dir);      /* Free initial segments */
+               /* Free extra segments */
+               while (hashp->exsegs--)
+                       free(hashp->dir[--hashp->nsegs]);
+               free(hashp->dir);
        }
        }
+       if (flush_meta(hashp) && !save_errno)
+               save_errno = errno;
+       /* Free Bigmaps */
+       for (i = 0; i < hashp->nmaps; i++)
+               if (hashp->mapp[i])
+                       free(hashp->mapp[i]);
+
+       if (hashp->fp != -1)
+               (void)close(hashp->fp);
+
        if (save_errno) {
                errno = save_errno;
                return (ERROR);
        if (save_errno) {
                errno = save_errno;
                return (ERROR);
@@ -391,13 +392,15 @@ static int
 hash_sync(dbp)
        const DB *dbp;
 {
 hash_sync(dbp)
        const DB *dbp;
 {
+       HTAB *hashp;
+
        if (!dbp)
                return (ERROR);
        if (!dbp)
                return (ERROR);
-       hashp = (HTAB *)dbp->internal;
 
 
+       hashp = (HTAB *)dbp->internal;
        if (!hashp->save_file)
                return (0);
        if (!hashp->save_file)
                return (0);
-       if (__buf_free(0, 1) || flush_meta())
+       if (__buf_free(hashp, 0, 1) || flush_meta(hashp))
                return (ERROR);
        hashp->new_file = 0;
        return (0);
                return (ERROR);
        hashp->new_file = 0;
        return (0);
@@ -409,7 +412,8 @@ hash_sync(dbp)
  *     -1 indicates that errno should be set
  */
 static int
  *     -1 indicates that errno should be set
  */
 static int
-flush_meta()
+flush_meta(hashp)
+       HTAB *hashp;
 {
        HASHHDR *whdrp;
 #if BYTE_ORDER == LITTLE_ENDIAN
 {
        HASHHDR *whdrp;
 #if BYTE_ORDER == LITTLE_ENDIAN
@@ -440,7 +444,7 @@ flush_meta()
                }
        for (i = 0; i < NCACHED; i++)
                if (hashp->mapp[i])
                }
        for (i = 0; i < NCACHED; i++)
                if (hashp->mapp[i])
-                       if (__put_page((char *)hashp->mapp[i],
+                       if (__put_page(hashp, (char *)hashp->mapp[i],
                                hashp->BITMAPS[i], 0, 1))
                                return (-1);
        return (0);
                                hashp->BITMAPS[i], 0, 1))
                                return (-1);
        return (0);
@@ -462,12 +466,14 @@ hash_get(dbp, key, data, flag)
        DBT *data;
        u_int flag;
 {
        DBT *data;
        u_int flag;
 {
+       HTAB *hashp;
+
+       hashp = (HTAB *)dbp->internal;
        if (flag) {
                hashp->errno = errno = EINVAL;
                return (ERROR);
        }
        if (flag) {
                hashp->errno = errno = EINVAL;
                return (ERROR);
        }
-       hashp = (HTAB *)dbp->internal;
-       return (hash_access(HASH_GET, (DBT *)key, data));
+       return (hash_access(hashp, HASH_GET, (DBT *)key, data));
 }
 
 static int
 }
 
 static int
@@ -477,16 +483,18 @@ hash_put(dbp, key, data, flag)
        const DBT *data;
        u_int flag;
 {
        const DBT *data;
        u_int flag;
 {
+       HTAB *hashp;
+
+       hashp = (HTAB *)dbp->internal;
        if (flag && flag != R_NOOVERWRITE) {
                hashp->errno = errno = EINVAL;
                return (ERROR);
        }
        if (flag && flag != R_NOOVERWRITE) {
                hashp->errno = errno = EINVAL;
                return (ERROR);
        }
-       hashp = (HTAB *)dbp->internal;
        if ((hashp->flags & O_ACCMODE) == O_RDONLY) {
                hashp->errno = errno = EPERM;
                return (ERROR);
        }
        if ((hashp->flags & O_ACCMODE) == O_RDONLY) {
                hashp->errno = errno = EPERM;
                return (ERROR);
        }
-       return (hash_access(flag == R_NOOVERWRITE ?
+       return (hash_access(hashp, flag == R_NOOVERWRITE ?
            HASH_PUTNEW : HASH_PUT, (DBT *)key, (DBT *)data));
 }
 
            HASH_PUTNEW : HASH_PUT, (DBT *)key, (DBT *)data));
 }
 
@@ -496,23 +504,26 @@ hash_delete(dbp, key, flag)
        const DBT *key;
        u_int flag;             /* Ignored */
 {
        const DBT *key;
        u_int flag;             /* Ignored */
 {
+       HTAB *hashp;
+
+       hashp = (HTAB *)dbp->internal;
        if (flag && flag != R_CURSOR) {
                hashp->errno = errno = EINVAL;
                return (ERROR);
        }
        if (flag && flag != R_CURSOR) {
                hashp->errno = errno = EINVAL;
                return (ERROR);
        }
-       hashp = (HTAB *)dbp->internal;
        if ((hashp->flags & O_ACCMODE) == O_RDONLY) {
                hashp->errno = errno = EPERM;
                return (ERROR);
        }
        if ((hashp->flags & O_ACCMODE) == O_RDONLY) {
                hashp->errno = errno = EPERM;
                return (ERROR);
        }
-       return (hash_access(HASH_DELETE, (DBT *)key, NULL));
+       return (hash_access(hashp, HASH_DELETE, (DBT *)key, NULL));
 }
 
 /*
  * Assume that hashp has been set in wrapper routine.
  */
 static int
 }
 
 /*
  * Assume that hashp has been set in wrapper routine.
  */
 static int
-hash_access(action, key, val)
+hash_access(hashp, action, key, val)
+       HTAB *hashp;
        ACTION action;
        DBT *key, *val;
 {
        ACTION action;
        DBT *key, *val;
 {
@@ -530,7 +541,7 @@ hash_access(action, key, val)
        off = hashp->BSIZE;
        size = key->size;
        kp = (char *)key->data;
        off = hashp->BSIZE;
        size = key->size;
        kp = (char *)key->data;
-       rbufp = __get_buf(__call_hash(kp, size), NULL, 0);
+       rbufp = __get_buf(hashp, __call_hash(hashp, kp, size), NULL, 0);
        if (!rbufp)
                return (ERROR);
        save_bufp = rbufp;
        if (!rbufp)
                return (ERROR);
        save_bufp = rbufp;
@@ -550,7 +561,7 @@ hash_access(action, key, val)
                        bp += 2;
                        ndx += 2;
                } else if (bp[1] == OVFLPAGE) {
                        bp += 2;
                        ndx += 2;
                } else if (bp[1] == OVFLPAGE) {
-                       rbufp = __get_buf(*bp, rbufp, 0);
+                       rbufp = __get_buf(hashp, *bp, rbufp, 0);
                        if (!rbufp) {
                                save_bufp->flags &= ~BUF_PIN;
                                return (ERROR);
                        if (!rbufp) {
                                save_bufp->flags &= ~BUF_PIN;
                                return (ERROR);
@@ -561,16 +572,18 @@ hash_access(action, key, val)
                        ndx = 1;
                        off = hashp->BSIZE;
                } else if (bp[1] < REAL_KEY) {
                        ndx = 1;
                        off = hashp->BSIZE;
                } else if (bp[1] < REAL_KEY) {
-                       if ((ndx = __find_bigpair(rbufp, ndx, kp, size)) > 0)
+                       if ((ndx =
+                           __find_bigpair(hashp, rbufp, ndx, kp, size)) > 0)
                                goto found;
                        if (ndx == -2) {
                                bufp = rbufp;
                                goto found;
                        if (ndx == -2) {
                                bufp = rbufp;
-                               if (!(pageno = __find_last_page(&bufp))) {
+                               if (!(pageno =
+                                   __find_last_page(hashp, &bufp))) {
                                        ndx = 0;
                                        rbufp = bufp;
                                        break;  /* FOR */
                                }
                                        ndx = 0;
                                        rbufp = bufp;
                                        break;  /* FOR */
                                }
-                               rbufp = __get_buf(pageno, bufp, 0);
+                               rbufp = __get_buf(hashp, pageno, bufp, 0);
                                if (!rbufp) {
                                        save_bufp->flags &= ~BUF_PIN;
                                        return (ERROR);
                                if (!rbufp) {
                                        save_bufp->flags &= ~BUF_PIN;
                                        return (ERROR);
@@ -590,7 +603,7 @@ hash_access(action, key, val)
        switch (action) {
        case HASH_PUT:
        case HASH_PUTNEW:
        switch (action) {
        case HASH_PUT:
        case HASH_PUTNEW:
-               if (__addel(rbufp, key, val)) {
+               if (__addel(hashp, rbufp, key, val)) {
                        save_bufp->flags &= ~BUF_PIN;
                        return (ERROR);
                } else {
                        save_bufp->flags &= ~BUF_PIN;
                        return (ERROR);
                } else {
@@ -612,7 +625,7 @@ found:
        case HASH_GET:
                bp = (u_short *)rbufp->page;
                if (bp[ndx + 1] < REAL_KEY) {
        case HASH_GET:
                bp = (u_short *)rbufp->page;
                if (bp[ndx + 1] < REAL_KEY) {
-                       if (__big_return(rbufp, ndx, val, 0))
+                       if (__big_return(hashp, rbufp, ndx, val, 0))
                                return (ERROR);
                } else {
                        val->data = (u_char *)rbufp->page + (int)bp[ndx + 1];
                                return (ERROR);
                } else {
                        val->data = (u_char *)rbufp->page + (int)bp[ndx + 1];
@@ -620,15 +633,18 @@ found:
                }
                break;
        case HASH_PUT:
                }
                break;
        case HASH_PUT:
-               if ((__delpair(rbufp, ndx)) || (__addel(rbufp, key, val))) {
+               if ((__delpair(hashp, rbufp, ndx)) ||
+                   (__addel(hashp, rbufp, key, val))) {
                        save_bufp->flags &= ~BUF_PIN;
                        return (ERROR);
                }
                break;
        case HASH_DELETE:
                        save_bufp->flags &= ~BUF_PIN;
                        return (ERROR);
                }
                break;
        case HASH_DELETE:
-               if (__delpair(rbufp, ndx))
+               if (__delpair(hashp, rbufp, ndx))
                        return (ERROR);
                break;
                        return (ERROR);
                break;
+       default:
+               abort();
        }
        save_bufp->flags &= ~BUF_PIN;
        return (SUCCESS);
        }
        save_bufp->flags &= ~BUF_PIN;
        return (SUCCESS);
@@ -642,13 +658,14 @@ hash_seq(dbp, key, data, flag)
 {
        register u_int bucket;
        register BUFHEAD *bufp;
 {
        register u_int bucket;
        register BUFHEAD *bufp;
+       HTAB *hashp;
        u_short *bp, ndx;
 
        u_short *bp, ndx;
 
+       hashp = (HTAB *)dbp->internal;
        if (flag && flag != R_FIRST && flag != R_NEXT) {
                hashp->errno = errno = EINVAL;
                return (ERROR);
        }
        if (flag && flag != R_FIRST && flag != R_NEXT) {
                hashp->errno = errno = EINVAL;
                return (ERROR);
        }
-       hashp = (HTAB *)dbp->internal;
 #ifdef HASH_STATISTICS
        hash_accesses++;
 #endif
 #ifdef HASH_STATISTICS
        hash_accesses++;
 #endif
@@ -663,7 +680,7 @@ hash_seq(dbp, key, data, flag)
                        for (bucket = hashp->cbucket;
                            bucket <= hashp->MAX_BUCKET;
                            bucket++, hashp->cndx = 1) {
                        for (bucket = hashp->cbucket;
                            bucket <= hashp->MAX_BUCKET;
                            bucket++, hashp->cndx = 1) {
-                               bufp = __get_buf(bucket, NULL, 0);
+                               bufp = __get_buf(hashp, bucket, NULL, 0);
                                if (!bufp)
                                        return (ERROR);
                                hashp->cpage = bufp;
                                if (!bufp)
                                        return (ERROR);
                                hashp->cpage = bufp;
@@ -685,7 +702,7 @@ hash_seq(dbp, key, data, flag)
 #endif
                while (bp[hashp->cndx + 1] == OVFLPAGE) {
                        bufp = hashp->cpage =
 #endif
                while (bp[hashp->cndx + 1] == OVFLPAGE) {
                        bufp = hashp->cpage =
-                           __get_buf(bp[hashp->cndx], bufp, 0);
+                           __get_buf(hashp, bp[hashp->cndx], bufp, 0);
                        if (!bufp)
                                return (ERROR);
                        bp = (u_short *)(bufp->page);
                        if (!bufp)
                                return (ERROR);
                        bp = (u_short *)(bufp->page);
@@ -698,7 +715,7 @@ hash_seq(dbp, key, data, flag)
        }
        ndx = hashp->cndx;
        if (bp[ndx + 1] < REAL_KEY) {
        }
        ndx = hashp->cndx;
        if (bp[ndx + 1] < REAL_KEY) {
-               if (__big_keydata(bufp, key, data, 1))
+               if (__big_keydata(hashp, bufp, key, data, 1))
                        return (ERROR);
        } else {
                key->data = (u_char *)hashp->cpage->page + bp[ndx];
                        return (ERROR);
        } else {
                key->data = (u_char *)hashp->cpage->page + bp[ndx];
@@ -724,7 +741,8 @@ hash_seq(dbp, key, data, flag)
  *     -1 ==> Error
  */
 extern int
  *     -1 ==> Error
  */
 extern int
-__expand_table()
+__expand_table(hashp)
+       HTAB *hashp;
 {
        u_int old_bucket, new_bucket;
        int dirsize, new_segnum, spare_ndx;
 {
        u_int old_bucket, new_bucket;
        int dirsize, new_segnum, spare_ndx;
@@ -770,7 +788,7 @@ __expand_table()
                hashp->HIGH_MASK = new_bucket | hashp->LOW_MASK;
        }
        /* Relocate records to the new bucket */
                hashp->HIGH_MASK = new_bucket | hashp->LOW_MASK;
        }
        /* Relocate records to the new bucket */
-       return (__split_page(old_bucket, new_bucket));
+       return (__split_page(hashp, old_bucket, new_bucket));
 }
 
 /*
 }
 
 /*
@@ -794,7 +812,8 @@ hash_realloc(p_ptr, oldsize, newsize)
 }
 
 extern u_int
 }
 
 extern u_int
-__call_hash(k, len)
+__call_hash(hashp, k, len)
+       HTAB *hashp;
        char *k;
        int len;
 {
        char *k;
        int len;
 {
@@ -813,7 +832,8 @@ __call_hash(k, len)
  * Returns 0 on success
  */
 static int
  * Returns 0 on success
  */
 static int
-alloc_segs(nsegs)
+alloc_segs(hashp, nsegs)
+       HTAB *hashp;
        int nsegs;
 {
        register int i;
        int nsegs;
 {
        register int i;
@@ -823,7 +843,7 @@ alloc_segs(nsegs)
 
        if (!(hashp->dir = calloc(hashp->DSIZE, sizeof(SEGMENT *)))) {
                save_errno = errno;
 
        if (!(hashp->dir = calloc(hashp->DSIZE, sizeof(SEGMENT *)))) {
                save_errno = errno;
-               (void)hdestroy();
+               (void)hdestroy(hashp);
                errno = save_errno;
                return (-1);
        }
                errno = save_errno;
                return (-1);
        }
@@ -831,7 +851,7 @@ alloc_segs(nsegs)
        store = calloc(nsegs << hashp->SSHIFT, sizeof(SEGMENT));
        if (!store) {
                save_errno = errno;
        store = calloc(nsegs << hashp->SSHIFT, sizeof(SEGMENT));
        if (!store) {
                save_errno = errno;
-               (void)hdestroy();
+               (void)hdestroy(hashp);
                errno = save_errno;
                return (-1);
        }
                errno = save_errno;
                return (-1);
        }
@@ -874,7 +894,8 @@ swap_header_copy(srcp, destp)
 }
 
 static void
 }
 
 static void
-swap_header()
+swap_header(hashp)
+       HTAB *hashp;
 {
        HASHHDR *hdrp;
        int i;
 {
        HASHHDR *hdrp;
        int i;
index d0a1f4c..a3ac110 100644 (file)
@@ -9,7 +9,7 @@
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)hash_bigkey.c      5.7 (Berkeley) %G%";
+static char sccsid[] = "@(#)hash_bigkey.c      5.8 (Berkeley) %G%";
 #endif /* LIBC_SCCS and not lint */
 
 /*
 #endif /* LIBC_SCCS and not lint */
 
 /*
@@ -31,20 +31,23 @@ static char sccsid[] = "@(#)hash_bigkey.c   5.7 (Berkeley) %G%";
  */
 
 #include <sys/param.h>
  */
 
 #include <sys/param.h>
-#include <errno.h>
+
 #include <db.h>
 #include <db.h>
+#include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+
 #ifdef DEBUG
 #include <assert.h>
 #endif
 #ifdef DEBUG
 #include <assert.h>
 #endif
+
 #include "hash.h"
 #include "page.h"
 #include "extern.h"
 
 #include "hash.h"
 #include "page.h"
 #include "extern.h"
 
-static int collect_key __P((BUFHEAD *, int, DBT *, int));
-static int collect_data __P((BUFHEAD *, int, int));
+static int collect_key __P((HTAB *, BUFHEAD *, int, DBT *, int));
+static int collect_data __P((HTAB *, BUFHEAD *, int, int));
 
 /*
  * Big_insert
 
 /*
  * Big_insert
@@ -56,7 +59,8 @@ static int collect_data __P((BUFHEAD *, int, int));
  *-1 ==> ERROR
  */
 extern int
  *-1 ==> ERROR
  */
 extern int
-__big_insert(bufp, key, val)
+__big_insert(hashp, bufp, key, val)
+       HTAB *hashp;
        BUFHEAD *bufp;
        const DBT *key, *val;
 {
        BUFHEAD *bufp;
        const DBT *key, *val;
 {
@@ -87,7 +91,7 @@ __big_insert(bufp, key, val)
                FREESPACE(p) = off - PAGE_META(n);
                OFFSET(p) = off;
                p[n] = PARTIAL_KEY;
                FREESPACE(p) = off - PAGE_META(n);
                OFFSET(p) = off;
                p[n] = PARTIAL_KEY;
-               bufp = __add_ovflpage(bufp);
+               bufp = __add_ovflpage(hashp, bufp);
                if (!bufp)
                        return (-1);
                n = p[0];
                if (!bufp)
                        return (-1);
                n = p[0];
@@ -130,7 +134,7 @@ __big_insert(bufp, key, val)
                OFFSET(p) = off;
                if (val_size) {
                        p[n] = FULL_KEY;
                OFFSET(p) = off;
                if (val_size) {
                        p[n] = FULL_KEY;
-                       bufp = __add_ovflpage(bufp);
+                       bufp = __add_ovflpage(hashp, bufp);
                        if (!bufp)
                                return (-1);
                        cp = bufp->page;
                        if (!bufp)
                                return (-1);
                        cp = bufp->page;
@@ -154,7 +158,8 @@ __big_insert(bufp, key, val)
  *-1 => ERROR
  */
 extern int
  *-1 => ERROR
  */
 extern int
-__big_delete(bufp)
+__big_delete(hashp, bufp)
+       HTAB *hashp;
        BUFHEAD *bufp;
 {
        register BUFHEAD *last_bfp, *rbufp;
        BUFHEAD *bufp;
 {
        register BUFHEAD *last_bfp, *rbufp;
@@ -180,9 +185,9 @@ __big_delete(bufp)
                        break;
                pageno = bp[bp[0] - 1];
                rbufp->flags |= BUF_MOD;
                        break;
                pageno = bp[bp[0] - 1];
                rbufp->flags |= BUF_MOD;
-               rbufp = __get_buf(pageno, rbufp, 0);
+               rbufp = __get_buf(hashp, pageno, rbufp, 0);
                if (last_bfp)
                if (last_bfp)
-                       __free_ovflpage(last_bfp);
+                       __free_ovflpage(hashp, last_bfp);
                last_bfp = rbufp;
                if (!rbufp)
                        return (-1);            /* Error. */
                last_bfp = rbufp;
                if (!rbufp)
                        return (-1);            /* Error. */
@@ -217,9 +222,9 @@ __big_delete(bufp)
 
        bufp->flags |= BUF_MOD;
        if (rbufp)
 
        bufp->flags |= BUF_MOD;
        if (rbufp)
-               __free_ovflpage(rbufp);
+               __free_ovflpage(hashp, rbufp);
        if (last_bfp != rbufp)
        if (last_bfp != rbufp)
-               __free_ovflpage(last_bfp);
+               __free_ovflpage(hashp, last_bfp);
 
        hashp->NKEYS--;
        return (0);
 
        hashp->NKEYS--;
        return (0);
@@ -232,7 +237,8 @@ __big_delete(bufp)
  * -3 error
  */
 extern int
  * -3 error
  */
 extern int
-__find_bigpair(bufp, ndx, key, size)
+__find_bigpair(hashp, bufp, ndx, key, size)
+       HTAB *hashp;
        BUFHEAD *bufp;
        int ndx;
        char *key;
        BUFHEAD *bufp;
        int ndx;
        char *key;
@@ -256,7 +262,7 @@ __find_bigpair(bufp, ndx, key, size)
                        return (-2);
                kkey += bytes;
                ksize -= bytes;
                        return (-2);
                kkey += bytes;
                ksize -= bytes;
-               bufp = __get_buf(bp[ndx + 2], bufp, 0);
+               bufp = __get_buf(hashp, bp[ndx + 2], bufp, 0);
                if (!bufp)
                        return (-3);
                p = bufp->page;
                if (!bufp)
                        return (-3);
                p = bufp->page;
@@ -283,7 +289,8 @@ __find_bigpair(bufp, ndx, key, size)
  * bucket)
  */
 extern u_short
  * bucket)
  */
 extern u_short
-__find_last_page(bpp)
+__find_last_page(hashp, bpp)
+       HTAB *hashp;
        BUFHEAD **bpp;
 {
        BUFHEAD *bufp;
        BUFHEAD **bpp;
 {
        BUFHEAD *bufp;
@@ -305,7 +312,7 @@ __find_last_page(bpp)
                        break;
 
                pageno = bp[n - 1];
                        break;
 
                pageno = bp[n - 1];
-               bufp = __get_buf(pageno, bufp, 0);
+               bufp = __get_buf(hashp, pageno, bufp, 0);
                if (!bufp)
                        return (0);     /* Need to indicate an error! */
                bp = (u_short *)bufp->page;
                if (!bufp)
                        return (0);     /* Need to indicate an error! */
                bp = (u_short *)bufp->page;
@@ -323,7 +330,8 @@ __find_last_page(bpp)
  * index (index should always be 1).
  */
 extern int
  * index (index should always be 1).
  */
 extern int
-__big_return(bufp, ndx, val, set_current)
+__big_return(hashp, bufp, ndx, val, set_current)
+       HTAB *hashp;
        BUFHEAD *bufp;
        int ndx;
        DBT *val;
        BUFHEAD *bufp;
        int ndx;
        DBT *val;
@@ -335,7 +343,7 @@ __big_return(bufp, ndx, val, set_current)
 
        bp = (u_short *)bufp->page;
        while (bp[ndx + 1] == PARTIAL_KEY) {
 
        bp = (u_short *)bufp->page;
        while (bp[ndx + 1] == PARTIAL_KEY) {
-               bufp = __get_buf(bp[bp[0] - 1], bufp, 0);
+               bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0);
                if (!bufp)
                        return (-1);
                bp = (u_short *)bufp->page;
                if (!bufp)
                        return (-1);
                bp = (u_short *)bufp->page;
@@ -343,7 +351,7 @@ __big_return(bufp, ndx, val, set_current)
        }
 
        if (bp[ndx + 1] == FULL_KEY) {
        }
 
        if (bp[ndx + 1] == FULL_KEY) {
-               bufp = __get_buf(bp[bp[0] - 1], bufp, 0);
+               bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0);
                if (!bufp)
                        return (-1);
                bp = (u_short *)bufp->page;
                if (!bufp)
                        return (-1);
                bp = (u_short *)bufp->page;
@@ -364,7 +372,7 @@ __big_return(bufp, ndx, val, set_current)
                        len = bp[1] - off;
                        save_p = bufp;
                        save_addr = bufp->addr;
                        len = bp[1] - off;
                        save_p = bufp;
                        save_addr = bufp->addr;
-                       bufp = __get_buf(bp[bp[0] - 1], bufp, 0);
+                       bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0);
                        if (!bufp)
                                return (-1);
                        bp = (u_short *)bufp->page;
                        if (!bufp)
                                return (-1);
                        bp = (u_short *)bufp->page;
@@ -381,8 +389,8 @@ __big_return(bufp, ndx, val, set_current)
                                        hashp->cbucket++;
                                        hashp->cndx = 1;
                                } else {
                                        hashp->cbucket++;
                                        hashp->cndx = 1;
                                } else {
-                                       hashp->cpage =
-                                           __get_buf(bp[bp[0] - 1], bufp, 0);
+                                       hashp->cpage = __get_buf(hashp,
+                                           bp[bp[0] - 1], bufp, 0);
                                        if (!hashp->cpage)
                                                return (-1);
                                        hashp->cndx = 1;
                                        if (!hashp->cpage)
                                                return (-1);
                                        hashp->cndx = 1;
@@ -396,7 +404,7 @@ __big_return(bufp, ndx, val, set_current)
                        return (0);
                }
 
                        return (0);
                }
 
-       val->size = collect_data(bufp, (int)len, set_current);
+       val->size = collect_data(hashp, bufp, (int)len, set_current);
        if (val->size == -1)
                return (-1);
        if (save_p->addr != save_addr) {
        if (val->size == -1)
                return (-1);
        if (save_p->addr != save_addr) {
@@ -413,7 +421,8 @@ __big_return(bufp, ndx, val, set_current)
  * allocate a buffer and copy the data as you recurse up.
  */
 static int
  * allocate a buffer and copy the data as you recurse up.
  */
 static int
-collect_data(bufp, len, set)
+collect_data(hashp, bufp, len, set)
+       HTAB *hashp;
        BUFHEAD *bufp;
        int len, set;
 {
        BUFHEAD *bufp;
        int len, set;
 {
@@ -442,7 +451,7 @@ collect_data(bufp, len, set)
                                hashp->cbucket++;
                        } else {
                                hashp->cpage =
                                hashp->cbucket++;
                        } else {
                                hashp->cpage =
-                                   __get_buf(bp[bp[0] - 1], bufp, 0);
+                                   __get_buf(hashp, bp[bp[0] - 1], bufp, 0);
                                if (!hashp->cpage)
                                        return (-1);
                                else if (!((u_short *)hashp->cpage->page)[0]) {
                                if (!hashp->cpage)
                                        return (-1);
                                else if (!((u_short *)hashp->cpage->page)[0]) {
@@ -452,9 +461,9 @@ collect_data(bufp, len, set)
                        }
                }
        } else {
                        }
                }
        } else {
-               xbp = __get_buf(bp[bp[0] - 1], bufp, 0);
-               if (!xbp ||
-                   ((totlen = collect_data(xbp, len + mylen, set)) < 1))
+               xbp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0);
+               if (!xbp || ((totlen =
+                   collect_data(hashp, xbp, len + mylen, set)) < 1))
                        return (-1);
        }
        if (bufp->addr != save_addr) {
                        return (-1);
        }
        if (bufp->addr != save_addr) {
@@ -469,12 +478,13 @@ collect_data(bufp, len, set)
  * Fill in the key and data for this big pair.
  */
 extern int
  * Fill in the key and data for this big pair.
  */
 extern int
-__big_keydata(bufp, key, val, set)
+__big_keydata(hashp, bufp, key, val, set)
+       HTAB *hashp;
        BUFHEAD *bufp;
        DBT *key, *val;
        int set;
 {
        BUFHEAD *bufp;
        DBT *key, *val;
        int set;
 {
-       key->size = collect_key(bufp, 0, val, set);
+       key->size = collect_key(hashp, bufp, 0, val, set);
        if (key->size == -1)
                return (-1);
        key->data = (u_char *)hashp->tmp_key;
        if (key->size == -1)
                return (-1);
        key->data = (u_char *)hashp->tmp_key;
@@ -486,7 +496,8 @@ __big_keydata(bufp, key, val, set)
  * collect the data, allocate a buffer and copy the key as you recurse up.
  */
 static int
  * collect the data, allocate a buffer and copy the key as you recurse up.
  */
 static int
-collect_key(bufp, len, val, set)
+collect_key(hashp, bufp, len, val, set)
+       HTAB *hashp;
        BUFHEAD *bufp;
        int len;
        DBT *val;
        BUFHEAD *bufp;
        int len;
        DBT *val;
@@ -509,12 +520,12 @@ collect_key(bufp, len, val, set)
                hashp->tmp_key = malloc(totlen);
                if (!hashp->tmp_key)
                        return (-1);
                hashp->tmp_key = malloc(totlen);
                if (!hashp->tmp_key)
                        return (-1);
-               if (__big_return(bufp, 1, val, set))
+               if (__big_return(hashp, bufp, 1, val, set))
                        return (-1);
        } else {
                        return (-1);
        } else {
-               xbp = __get_buf(bp[bp[0] - 1], bufp, 0);
-               if (!xbp ||
-                   ((totlen = collect_key(xbp, totlen, val, set)) < 1))
+               xbp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0);
+               if (!xbp || ((totlen =
+                   collect_key(hashp, xbp, totlen, val, set)) < 1))
                        return (-1);
        }
        if (bufp->addr != save_addr) {
                        return (-1);
        }
        if (bufp->addr != save_addr) {
@@ -531,7 +542,8 @@ collect_key(bufp, len, val, set)
  * -1 => error
  */
 extern int
  * -1 => error
  */
 extern int
-__big_split(op, np, big_keyp, addr, obucket, ret)
+__big_split(hashp, op, np, big_keyp, addr, obucket, ret)
+       HTAB *hashp;
        BUFHEAD *op;    /* Pointer to where to put keys that go in old bucket */
        BUFHEAD *np;    /* Pointer to new bucket page */
                        /* Pointer to first page containing the big key/data */
        BUFHEAD *op;    /* Pointer to where to put keys that go in old bucket */
        BUFHEAD *np;    /* Pointer to new bucket page */
                        /* Pointer to first page containing the big key/data */
@@ -550,12 +562,13 @@ __big_split(op, np, big_keyp, addr, obucket, ret)
        bp = big_keyp;
 
        /* Now figure out where the big key/data goes */
        bp = big_keyp;
 
        /* Now figure out where the big key/data goes */
-       if (__big_keydata(big_keyp, &key, &val, 0))
+       if (__big_keydata(hashp, big_keyp, &key, &val, 0))
                return (-1);
                return (-1);
-       change = (__call_hash(key.data, key.size) != obucket);
+       change = (__call_hash(hashp, key.data, key.size) != obucket);
 
 
-       if (ret->next_addr = __find_last_page(&big_keyp)) {
-               if (!(ret->nextp = __get_buf(ret->next_addr, big_keyp, 0)))
+       if (ret->next_addr = __find_last_page(hashp, &big_keyp)) {
+               if (!(ret->nextp =
+                   __get_buf(hashp, ret->next_addr, big_keyp, 0)))
                        return (-1);;
        } else
                ret->nextp = NULL;
                        return (-1);;
        } else
                ret->nextp = NULL;
@@ -615,7 +628,7 @@ __big_split(op, np, big_keyp, addr, obucket, ret)
                tp[0] -= 2;
                FREESPACE(tp) = free_space + OVFLSIZE;
                OFFSET(tp) = off;
                tp[0] -= 2;
                FREESPACE(tp) = free_space + OVFLSIZE;
                OFFSET(tp) = off;
-               tmpp = __add_ovflpage(big_keyp);
+               tmpp = __add_ovflpage(hashp, big_keyp);
                if (!tmpp)
                        return (-1);
                tp[4] = n;
                if (!tmpp)
                        return (-1);
                tp[4] = n;
index af56376..fa3c336 100644 (file)
@@ -9,7 +9,7 @@
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)hash_buf.c 5.10 (Berkeley) %G%";
+static char sccsid[] = "@(#)hash_buf.c 5.11 (Berkeley) %G%";
 #endif /* LIBC_SCCS and not lint */
 
 /*
 #endif /* LIBC_SCCS and not lint */
 
 /*
@@ -29,6 +29,7 @@ static char sccsid[] = "@(#)hash_buf.c        5.10 (Berkeley) %G%";
  */
 
 #include <sys/param.h>
  */
 
 #include <sys/param.h>
+
 #include <db.h>
 #include <errno.h>
 #include <stdio.h>
 #include <db.h>
 #include <errno.h>
 #include <stdio.h>
@@ -36,11 +37,12 @@ static char sccsid[] = "@(#)hash_buf.c      5.10 (Berkeley) %G%";
 #ifdef DEBUG
 #include <assert.h>
 #endif
 #ifdef DEBUG
 #include <assert.h>
 #endif
+
 #include "hash.h"
 #include "page.h"
 #include "extern.h"
 
 #include "hash.h"
 #include "page.h"
 #include "extern.h"
 
-static BUFHEAD *newbuf __P((u_int, BUFHEAD *));
+static BUFHEAD *newbuf __P((HTAB *, u_int, BUFHEAD *));
 
 /* Unlink B from its place in the lru */
 #define BUF_REMOVE(B) { \
 
 /* Unlink B from its place in the lru */
 #define BUF_REMOVE(B) { \
@@ -72,7 +74,8 @@ static BUFHEAD *newbuf __P((u_int, BUFHEAD *));
  * address you are seeking.
  */
 extern BUFHEAD *
  * address you are seeking.
  */
 extern BUFHEAD *
-__get_buf(addr, prev_bp, newpage)
+__get_buf(hashp, addr, prev_bp, newpage)
+       HTAB *hashp;
        u_int addr;
        BUFHEAD *prev_bp;
        int newpage;    /* If prev_bp set, indicates a new overflow page. */
        u_int addr;
        BUFHEAD *prev_bp;
        int newpage;    /* If prev_bp set, indicates a new overflow page. */
@@ -105,8 +108,9 @@ __get_buf(addr, prev_bp, newpage)
        }
 
        if (!bp) {
        }
 
        if (!bp) {
-               bp = newbuf(addr, prev_bp);
-               if (!bp || __get_page(bp->page, addr, !prev_bp, is_disk, 0))
+               bp = newbuf(hashp, addr, prev_bp);
+               if (!bp ||
+                   __get_page(hashp, bp->page, addr, !prev_bp, is_disk, 0))
                        return (NULL);
                if (!prev_bp)
                        segp[segment_ndx] =
                        return (NULL);
                if (!prev_bp)
                        segp[segment_ndx] =
@@ -125,8 +129,9 @@ __get_buf(addr, prev_bp, newpage)
  * If newbuf finds an error (returning NULL), it also sets errno.
  */
 static BUFHEAD *
  * If newbuf finds an error (returning NULL), it also sets errno.
  */
 static BUFHEAD *
-newbuf(addr, prev_bp)
-       u_int   addr;
+newbuf(hashp, addr, prev_bp)
+       HTAB *hashp;
+       u_int addr;
        BUFHEAD *prev_bp;
 {
        register BUFHEAD *bp;           /* The buffer we're going to use */
        BUFHEAD *prev_bp;
 {
        register BUFHEAD *bp;           /* The buffer we're going to use */
@@ -164,7 +169,7 @@ newbuf(addr, prev_bp)
                        shortp = (u_short *)bp->page;
                        if (shortp[0])
                                oaddr = shortp[shortp[0] - 1];
                        shortp = (u_short *)bp->page;
                        if (shortp[0])
                                oaddr = shortp[shortp[0] - 1];
-                       if ((bp->flags & BUF_MOD) && __put_page(bp->page,
+                       if ((bp->flags & BUF_MOD) && __put_page(hashp, bp->page,
                            bp->addr, (int)IS_BUCKET(bp->flags), 0))
                                return (NULL);
                        /*
                            bp->addr, (int)IS_BUCKET(bp->flags), 0))
                                return (NULL);
                        /*
@@ -208,8 +213,8 @@ newbuf(addr, prev_bp)
                                if (shortp[0])
                                        /* set before __put_page */
                                        oaddr = shortp[shortp[0] - 1];
                                if (shortp[0])
                                        /* set before __put_page */
                                        oaddr = shortp[shortp[0] - 1];
-                               if ((xbp->flags & BUF_MOD) &&
-                                   __put_page(xbp->page, xbp->addr, 0, 0))
+                               if ((xbp->flags & BUF_MOD) && __put_page(hashp,
+                                   xbp->page, xbp->addr, 0, 0))
                                        return (NULL);
                                xbp->addr = 0;
                                xbp->flags = 0;
                                        return (NULL);
                                xbp->addr = 0;
                                xbp->flags = 0;
@@ -245,7 +250,8 @@ newbuf(addr, prev_bp)
 }
 
 extern void
 }
 
 extern void
-__buf_init(nbytes)
+__buf_init(hashp, nbytes)
+       HTAB *hashp;
        int nbytes;
 {
        BUFHEAD *bfp;
        int nbytes;
 {
        BUFHEAD *bfp;
@@ -269,7 +275,8 @@ __buf_init(nbytes)
 }
 
 extern int
 }
 
 extern int
-__buf_free(do_free, to_disk)
+__buf_free(hashp, do_free, to_disk)
+       HTAB *hashp;
        int do_free, to_disk;
 {
        BUFHEAD *bp;
        int do_free, to_disk;
 {
        BUFHEAD *bp;
@@ -281,7 +288,7 @@ __buf_free(do_free, to_disk)
                /* Check that the buffer is valid */
                if (bp->addr || IS_BUCKET(bp->flags)) {
                        if (to_disk && (bp->flags & BUF_MOD) &&
                /* Check that the buffer is valid */
                if (bp->addr || IS_BUCKET(bp->flags)) {
                        if (to_disk && (bp->flags & BUF_MOD) &&
-                           __put_page(bp->page,
+                           __put_page(hashp, bp->page,
                            bp->addr, IS_BUCKET(bp->flags), 0))
                                return (-1);
                }
                            bp->addr, IS_BUCKET(bp->flags), 0))
                                return (-1);
                }
@@ -299,7 +306,8 @@ __buf_free(do_free, to_disk)
 }
 
 extern void
 }
 
 extern void
-__reclaim_buf(bp)
+__reclaim_buf(hashp, bp)
+       HTAB *hashp;
        BUFHEAD *bp;
 {
        bp->ovfl = 0;
        BUFHEAD *bp;
 {
        bp->ovfl = 0;
index 6399b8a..5cccc26 100644 (file)
@@ -9,11 +9,13 @@
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)hash_func.c        5.2 (Berkeley) %G%";
+static char sccsid[] = "@(#)hash_func.c        5.3 (Berkeley) %G%";
 #endif /* LIBC_SCCS and not lint */
 
 #include <sys/types.h>
 #endif /* LIBC_SCCS and not lint */
 
 #include <sys/types.h>
+
 #include <db.h>
 #include <db.h>
+
 #include "hash.h"
 #include "page.h"
 #include "extern.h"
 #include "hash.h"
 #include "page.h"
 #include "extern.h"
@@ -24,7 +26,7 @@ static int hash3 __P((u_char *, int));
 static int hash4 __P((u_char *, int));
 
 /* Global default hash function */
 static int hash4 __P((u_char *, int));
 
 /* Global default hash function */
-int (*default_hash) __P((u_char *, int)) = hash4;
+int (*__default_hash) __P((u_char *, int)) = hash4;
 
 /******************************* HASH FUNCTIONS **************************/
 /*
 
 /******************************* HASH FUNCTIONS **************************/
 /*
index 6d58ced..9d1a974 100644 (file)
@@ -9,7 +9,7 @@
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)hash_page.c        5.22 (Berkeley) %G%";
+static char sccsid[] = "@(#)hash_page.c        5.23 (Berkeley) %G%";
 #endif /* LIBC_SCCS and not lint */
 
 /*
 #endif /* LIBC_SCCS and not lint */
 
 /*
@@ -28,11 +28,12 @@ static char sccsid[] = "@(#)hash_page.c     5.22 (Berkeley) %G%";
  *     open_temp
  */
 
  *     open_temp
  */
 
-#include <sys/param.h>
+#include <sys/types.h>
+
+#include <db.h>
+#include <errno.h>
 #include <fcntl.h>
 #include <signal.h>
 #include <fcntl.h>
 #include <signal.h>
-#include <errno.h>
-#include <db.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -40,17 +41,19 @@ static char sccsid[] = "@(#)hash_page.c     5.22 (Berkeley) %G%";
 #ifdef DEBUG
 #include <assert.h>
 #endif
 #ifdef DEBUG
 #include <assert.h>
 #endif
+
 #include "hash.h"
 #include "page.h"
 #include "extern.h"
 
 #include "hash.h"
 #include "page.h"
 #include "extern.h"
 
-static u_long  *fetch_bitmap __P((int));
+static u_long  *fetch_bitmap __P((HTAB *, int));
 static u_long   first_free __P((u_long));
 static u_long   first_free __P((u_long));
-static int      open_temp __P((void));
-static u_short  overflow_page __P((void));
+static int      open_temp __P((HTAB *));
+static u_short  overflow_page __P((HTAB *));
 static void     putpair __P((char *, const DBT *, const DBT *));
 static void     squeeze_key __P((u_short *, const DBT *, const DBT *));
 static void     putpair __P((char *, const DBT *, const DBT *));
 static void     squeeze_key __P((u_short *, const DBT *, const DBT *));
-static int      ugly_split __P((u_int, BUFHEAD *, BUFHEAD *, int, int));
+static int      ugly_split
+                   __P((HTAB *, u_int, BUFHEAD *, BUFHEAD *, int, int));
 
 #define        PAGE_INIT(P) { \
        ((u_short *)(P))[0] = 0; \
 
 #define        PAGE_INIT(P) { \
        ((u_short *)(P))[0] = 0; \
@@ -96,7 +99,8 @@ putpair(p, key, val)
  *     -1 error
  */
 extern int
  *     -1 error
  */
 extern int
-__delpair(bufp, ndx)
+__delpair(hashp, bufp, ndx)
+       HTAB *hashp;
        BUFHEAD *bufp;
        register int ndx;
 {
        BUFHEAD *bufp;
        register int ndx;
 {
@@ -108,7 +112,7 @@ __delpair(bufp, ndx)
        n = bp[0];
 
        if (bp[ndx + 1] < REAL_KEY)
        n = bp[0];
 
        if (bp[ndx + 1] < REAL_KEY)
-               return (__big_delete(bufp));
+               return (__big_delete(hashp, bufp));
        if (ndx != 1)
                newoff = bp[ndx - 1];
        else
        if (ndx != 1)
                newoff = bp[ndx - 1];
        else
@@ -148,7 +152,8 @@ __delpair(bufp, ndx)
  *     -1 ==> Error
  */
 extern int
  *     -1 ==> Error
  */
 extern int
-__split_page(obucket, nbucket)
+__split_page(hashp, obucket, nbucket)
+       HTAB *hashp;
        u_int obucket, nbucket;
 {
        register BUFHEAD *new_bufp, *old_bufp;
        u_int obucket, nbucket;
 {
        register BUFHEAD *new_bufp, *old_bufp;
@@ -161,10 +166,10 @@ __split_page(obucket, nbucket)
 
        copyto = (u_short)hashp->BSIZE;
        off = (u_short)hashp->BSIZE;
 
        copyto = (u_short)hashp->BSIZE;
        off = (u_short)hashp->BSIZE;
-       old_bufp = __get_buf(obucket, NULL, 0);
+       old_bufp = __get_buf(hashp, obucket, NULL, 0);
        if (old_bufp == NULL)
                return (-1);
        if (old_bufp == NULL)
                return (-1);
-       new_bufp = __get_buf(nbucket, NULL, 0);
+       new_bufp = __get_buf(hashp, nbucket, NULL, 0);
        if (new_bufp == NULL)
                return (-1);
 
        if (new_bufp == NULL)
                return (-1);
 
@@ -178,7 +183,7 @@ __split_page(obucket, nbucket)
 
        for (n = 1, ndx = 1; n < ino[0]; n += 2) {
                if (ino[n + 1] < REAL_KEY) {
 
        for (n = 1, ndx = 1; n < ino[0]; n += 2) {
                if (ino[n + 1] < REAL_KEY) {
-                       retval = ugly_split(obucket, old_bufp, new_bufp,
+                       retval = ugly_split(hashp, obucket, old_bufp, new_bufp,
                            (int)copyto, (int)moved);
                        old_bufp->flags &= ~BUF_PIN;
                        new_bufp->flags &= ~BUF_PIN;
                            (int)copyto, (int)moved);
                        old_bufp->flags &= ~BUF_PIN;
                        new_bufp->flags &= ~BUF_PIN;
@@ -188,7 +193,7 @@ __split_page(obucket, nbucket)
                key.data = (u_char *)op + ino[n];
                key.size = off - ino[n];
 
                key.data = (u_char *)op + ino[n];
                key.size = off - ino[n];
 
-               if (__call_hash(key.data, key.size) == obucket) {
+               if (__call_hash(hashp, key.data, key.size) == obucket) {
                        /* Don't switch page */
                        diff = copyto - off;
                        if (diff) {
                        /* Don't switch page */
                        diff = copyto - off;
                        if (diff) {
@@ -243,7 +248,8 @@ __split_page(obucket, nbucket)
  *     -1 ==> failure
  */
 static int
  *     -1 ==> failure
  */
 static int
-ugly_split(obucket, old_bufp, new_bufp, copyto, moved)
+ugly_split(hashp, obucket, old_bufp, new_bufp, copyto, moved)
+       HTAB *hashp;
        u_int obucket;  /* Same as __split_page. */
        BUFHEAD *old_bufp, *new_bufp;
        int copyto;     /* First byte on page which contains key/data values. */
        u_int obucket;  /* Same as __split_page. */
        BUFHEAD *old_bufp, *new_bufp;
        int copyto;     /* First byte on page which contains key/data values. */
@@ -274,7 +280,7 @@ ugly_split(obucket, old_bufp, new_bufp, copyto, moved)
                         * Ov_addr gets set before reaching this point; there's
                         * always an overflow page before a big key/data page.
                         */
                         * Ov_addr gets set before reaching this point; there's
                         * always an overflow page before a big key/data page.
                         */
-                       if (__big_split(old_bufp,
+                       if (__big_split(hashp, old_bufp,
                            new_bufp, bufp, ov_addr, obucket, &ret))
                                return (-1);
                        old_bufp = ret.oldp;
                            new_bufp, bufp, ov_addr, obucket, &ret))
                                return (-1);
                        old_bufp = ret.oldp;
@@ -302,7 +308,7 @@ ugly_split(obucket, old_bufp, new_bufp, copyto, moved)
                            scopyto - sizeof(u_short) * (ino[0] + 3);
                        OFFSET(ino) = scopyto;
 
                            scopyto - sizeof(u_short) * (ino[0] + 3);
                        OFFSET(ino) = scopyto;
 
-                       bufp = __get_buf(ov_addr, bufp, 0);
+                       bufp = __get_buf(hashp, ov_addr, bufp, 0);
                        if (!bufp)
                                return (-1);
 
                        if (!bufp)
                                return (-1);
 
@@ -312,7 +318,7 @@ ugly_split(obucket, old_bufp, new_bufp, copyto, moved)
                        moved = 0;
 
                        if (last_bfp)
                        moved = 0;
 
                        if (last_bfp)
-                               __free_ovflpage(last_bfp);
+                               __free_ovflpage(hashp, last_bfp);
                        last_bfp = bufp;
                }
                /* Move regular sized pairs of there are any */
                        last_bfp = bufp;
                }
                /* Move regular sized pairs of there are any */
@@ -325,12 +331,13 @@ ugly_split(obucket, old_bufp, new_bufp, copyto, moved)
                        val.size = ino[n] - ino[n + 1];
                        off = ino[n + 1];
 
                        val.size = ino[n] - ino[n + 1];
                        off = ino[n + 1];
 
-                       if (__call_hash(key.data, key.size) == obucket) {
+                       if (__call_hash(hashp, key.data, key.size) == obucket) {
                                /* Keep on old page */
                                if (PAIRFITS(op, (&key), (&val)))
                                        putpair((char *)op, &key, &val);
                                else {
                                /* Keep on old page */
                                if (PAIRFITS(op, (&key), (&val)))
                                        putpair((char *)op, &key, &val);
                                else {
-                                       old_bufp = __add_ovflpage(old_bufp);
+                                       old_bufp =
+                                           __add_ovflpage(hashp, old_bufp);
                                        if (!old_bufp)
                                                return (-1);
                                        op = (u_short *)old_bufp->page;
                                        if (!old_bufp)
                                                return (-1);
                                        op = (u_short *)old_bufp->page;
@@ -342,7 +349,8 @@ ugly_split(obucket, old_bufp, new_bufp, copyto, moved)
                                if (PAIRFITS(np, (&key), (&val)))
                                        putpair((char *)np, &key, &val);
                                else {
                                if (PAIRFITS(np, (&key), (&val)))
                                        putpair((char *)np, &key, &val);
                                else {
-                                       new_bufp = __add_ovflpage(new_bufp);
+                                       new_bufp =
+                                           __add_ovflpage(hashp, new_bufp);
                                        if (!new_bufp)
                                                return (-1);
                                        np = (u_short *)new_bufp->page;
                                        if (!new_bufp)
                                                return (-1);
                                        np = (u_short *)new_bufp->page;
@@ -353,7 +361,7 @@ ugly_split(obucket, old_bufp, new_bufp, copyto, moved)
                }
        }
        if (last_bfp)
                }
        }
        if (last_bfp)
-               __free_ovflpage(last_bfp);
+               __free_ovflpage(hashp, last_bfp);
        return (0);
 }
 
        return (0);
 }
 
@@ -365,7 +373,8 @@ ugly_split(obucket, old_bufp, new_bufp, copyto, moved)
  *     1 ==> failure
  */
 extern int
  *     1 ==> failure
  */
 extern int
-__addel(bufp, key, val)
+__addel(hashp, bufp, key, val)
+       HTAB *hashp;
        BUFHEAD *bufp;
        const DBT *key, *val;
 {
        BUFHEAD *bufp;
        const DBT *key, *val;
 {
@@ -378,7 +387,7 @@ __addel(bufp, key, val)
                /* Exception case */
                if (bp[2] < REAL_KEY && bp[bp[0]] != OVFLPAGE) {
                        /* This is a big-keydata pair */
                /* Exception case */
                if (bp[2] < REAL_KEY && bp[bp[0]] != OVFLPAGE) {
                        /* This is a big-keydata pair */
-                       bufp = __add_ovflpage(bufp);
+                       bufp = __add_ovflpage(hashp, bufp);
                        if (!bufp)
                                return (-1);
                        bp = (u_short *)bufp->page;
                        if (!bufp)
                                return (-1);
                        bp = (u_short *)bufp->page;
@@ -388,7 +397,7 @@ __addel(bufp, key, val)
                                squeeze_key(bp, key, val);
                                return (0);
                        } else {
                                squeeze_key(bp, key, val);
                                return (0);
                        } else {
-                               bufp = __get_buf(bp[bp[0] - 1], bufp, 0);
+                               bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0);
                                if (!bufp)
                                        return (-1);
                                bp = (u_short *)bufp->page;
                                if (!bufp)
                                        return (-1);
                                bp = (u_short *)bufp->page;
@@ -398,7 +407,7 @@ __addel(bufp, key, val)
                putpair(bufp->page, key, val);
        else {
                do_expand = 1;
                putpair(bufp->page, key, val);
        else {
                do_expand = 1;
-               bufp = __add_ovflpage(bufp);
+               bufp = __add_ovflpage(hashp, bufp);
                if (!bufp)
                        return (-1);
                sop = (u_short *)bufp->page;
                if (!bufp)
                        return (-1);
                sop = (u_short *)bufp->page;
@@ -406,7 +415,7 @@ __addel(bufp, key, val)
                if (PAIRFITS(sop, key, val))
                        putpair((char *)sop, key, val);
                else
                if (PAIRFITS(sop, key, val))
                        putpair((char *)sop, key, val);
                else
-                       if (__big_insert(bufp, key, val))
+                       if (__big_insert(hashp, bufp, key, val))
                                return (-1);
        }
        bufp->flags |= BUF_MOD;
                                return (-1);
        }
        bufp->flags |= BUF_MOD;
@@ -417,7 +426,7 @@ __addel(bufp, key, val)
        hashp->NKEYS++;
        if (do_expand ||
            (hashp->NKEYS / (hashp->MAX_BUCKET + 1) > hashp->FFACTOR))
        hashp->NKEYS++;
        if (do_expand ||
            (hashp->NKEYS / (hashp->MAX_BUCKET + 1) > hashp->FFACTOR))
-               return (__expand_table());
+               return (__expand_table(hashp));
        return (0);
 }
 
        return (0);
 }
 
@@ -428,7 +437,8 @@ __addel(bufp, key, val)
  *     NULL on error
  */
 extern BUFHEAD *
  *     NULL on error
  */
 extern BUFHEAD *
-__add_ovflpage(bufp)
+__add_ovflpage(hashp, bufp)
+       HTAB *hashp;
        BUFHEAD *bufp;
 {
        register u_short *sp;
        BUFHEAD *bufp;
 {
        register u_short *sp;
@@ -438,12 +448,12 @@ __add_ovflpage(bufp)
 #endif
        sp = (u_short *)bufp->page;
        bufp->flags |= BUF_MOD;
 #endif
        sp = (u_short *)bufp->page;
        bufp->flags |= BUF_MOD;
-       ovfl_num = overflow_page();
+       ovfl_num = overflow_page(hashp);
 #ifdef DEBUG1
        tmp1 = bufp->addr;
        tmp2 = bufp->ovfl ? bufp->ovfl->addr : 0;
 #endif
 #ifdef DEBUG1
        tmp1 = bufp->addr;
        tmp2 = bufp->ovfl ? bufp->ovfl->addr : 0;
 #endif
-       if (!ovfl_num || !(bufp->ovfl = __get_buf(ovfl_num, bufp, 1)))
+       if (!ovfl_num || !(bufp->ovfl = __get_buf(hashp, ovfl_num, bufp, 1)))
                return (NULL);
        bufp->ovfl->flags |= BUF_MOD;
 #ifdef DEBUG1
                return (NULL);
        bufp->ovfl->flags |= BUF_MOD;
 #ifdef DEBUG1
@@ -473,7 +483,8 @@ __add_ovflpage(bufp)
  *     -1 indicates FAILURE
  */
 extern int
  *     -1 indicates FAILURE
  */
 extern int
-__get_page(p, bucket, is_bucket, is_disk, is_bitmap)
+__get_page(hashp, p, bucket, is_bucket, is_disk, is_bitmap)
+       HTAB *hashp;
        char *p;
        u_int bucket;
        int is_bucket, is_disk, is_bitmap;
        char *p;
        u_int bucket;
        int is_bucket, is_disk, is_bitmap;
@@ -532,7 +543,8 @@ __get_page(p, bucket, is_bucket, is_disk, is_bitmap)
  *     -1 ==>failure
  */
 extern int
  *     -1 ==>failure
  */
 extern int
-__put_page(p, bucket, is_bucket, is_bitmap)
+__put_page(hashp, p, bucket, is_bucket, is_bitmap)
+       HTAB *hashp;
        char *p;
        u_int bucket;
        int is_bucket, is_bitmap;
        char *p;
        u_int bucket;
        int is_bucket, is_bitmap;
@@ -541,7 +553,7 @@ __put_page(p, bucket, is_bucket, is_bitmap)
        int wsize;
 
        size = hashp->BSIZE;
        int wsize;
 
        size = hashp->BSIZE;
-       if ((hashp->fp == -1) && open_temp())
+       if ((hashp->fp == -1) && open_temp(hashp))
                return (-1);
        fd = hashp->fp;
 
                return (-1);
        fd = hashp->fp;
 
@@ -580,7 +592,8 @@ __put_page(p, bucket, is_bucket, is_bitmap)
  * once they are read in.
  */
 extern int
  * once they are read in.
  */
 extern int
-__init_bitmap(pnum, nbits, ndx)
+__init_bitmap(hashp, pnum, nbits, ndx)
+       HTAB *hashp;
        int pnum, nbits, ndx;
 {
        u_long *ip;
        int pnum, nbits, ndx;
 {
        u_long *ip;
@@ -616,8 +629,9 @@ first_free(map)
        return (i);
 }
 
        return (i);
 }
 
-static  u_short
-overflow_page()
+static u_short
+overflow_page(hashp)
+       HTAB *hashp;
 {
        register u_long *freep;
        register int max_free, offset, splitnum;
 {
        register u_long *freep;
        register int max_free, offset, splitnum;
@@ -636,7 +650,7 @@ overflow_page()
        first_page = hashp->LAST_FREED >>(hashp->BSHIFT + BYTE_SHIFT);
        for ( i = first_page; i <= free_page; i++ ) {
                if (!(freep = (u_long *)hashp->mapp[i]) &&
        first_page = hashp->LAST_FREED >>(hashp->BSHIFT + BYTE_SHIFT);
        for ( i = first_page; i <= free_page; i++ ) {
                if (!(freep = (u_long *)hashp->mapp[i]) &&
-                   !(freep = fetch_bitmap(i)))
+                   !(freep = fetch_bitmap(hashp, i)))
                        return (NULL);
                if (i == free_page)
                        in_use_bits = free_bit;
                        return (NULL);
                if (i == free_page)
                        in_use_bits = free_bit;
@@ -693,7 +707,7 @@ overflow_page()
                 * don't have to if we tell init_bitmap not to leave it clear
                 * in the first place.
                 */
                 * don't have to if we tell init_bitmap not to leave it clear
                 * in the first place.
                 */
-               if (__init_bitmap((int)OADDR_OF(splitnum, offset),
+               if (__init_bitmap(hashp, (int)OADDR_OF(splitnum, offset),
                    1, free_page))
                        return (NULL);
                hashp->SPARES[splitnum]++;
                    1, free_page))
                        return (NULL);
                hashp->SPARES[splitnum]++;
@@ -764,7 +778,8 @@ found:
  * Mark this overflow page as free.
  */
 extern void
  * Mark this overflow page as free.
  */
 extern void
-__free_ovflpage(obufp)
+__free_ovflpage(hashp, obufp)
+       HTAB *hashp;
        BUFHEAD *obufp;
 {
        register u_short addr;
        BUFHEAD *obufp;
 {
        register u_short addr;
@@ -785,7 +800,7 @@ __free_ovflpage(obufp)
        free_bit = bit_address & ((hashp->BSIZE << BYTE_SHIFT) - 1);
 
        if (!(freep = hashp->mapp[free_page]))
        free_bit = bit_address & ((hashp->BSIZE << BYTE_SHIFT) - 1);
 
        if (!(freep = hashp->mapp[free_page]))
-               freep = fetch_bitmap(free_page);
+               freep = fetch_bitmap(hashp, free_page);
 #ifdef DEBUG
        /*
         * This had better never happen.  It means we tried to read a bitmap
 #ifdef DEBUG
        /*
         * This had better never happen.  It means we tried to read a bitmap
@@ -800,7 +815,7 @@ __free_ovflpage(obufp)
        (void)fprintf(stderr, "FREE_OVFLPAGE: ADDR: %d BIT: %d PAGE %d\n",
            obufp->addr, free_bit, free_page);
 #endif
        (void)fprintf(stderr, "FREE_OVFLPAGE: ADDR: %d BIT: %d PAGE %d\n",
            obufp->addr, free_bit, free_page);
 #endif
-       __reclaim_buf(obufp);
+       __reclaim_buf(hashp, obufp);
 }
 
 /*
 }
 
 /*
@@ -809,7 +824,8 @@ __free_ovflpage(obufp)
  *     -1 failure
  */
 static int
  *     -1 failure
  */
 static int
-open_temp()
+open_temp(hashp)
+       HTAB *hashp;
 {
        sigset_t set, oset;
        static char namestr[] = "_hashXXXXXX";
 {
        sigset_t set, oset;
        static char namestr[] = "_hashXXXXXX";
@@ -857,12 +873,13 @@ squeeze_key(sp, key, val)
 }
 
 static u_long *
 }
 
 static u_long *
-fetch_bitmap(ndx)
+fetch_bitmap(hashp, ndx)
+       HTAB *hashp;
        int ndx;
 {
        if (ndx >= hashp->nmaps ||
            !(hashp->mapp[ndx] = malloc(hashp->BSIZE)) ||
        int ndx;
 {
        if (ndx >= hashp->nmaps ||
            !(hashp->mapp[ndx] = malloc(hashp->BSIZE)) ||
-           __get_page((char *)hashp->mapp[ndx],
+           __get_page(hashp, (char *)hashp->mapp[ndx],
            hashp->BITMAPS[ndx], 0, 1, 1))
                return (NULL);
        return (hashp->mapp[ndx]);
            hashp->BITMAPS[ndx], 0, 1, 1))
                return (NULL);
        return (hashp->mapp[ndx]);
@@ -877,13 +894,13 @@ print_chain(addr)
        short *bp, oaddr;
 
        (void)fprintf(stderr, "%d ", addr);
        short *bp, oaddr;
 
        (void)fprintf(stderr, "%d ", addr);
-       bufp = __get_buf(addr, NULL, 0);
+       bufp = __get_buf(hashp, addr, NULL, 0);
        bp = (short *)bufp->page;
        while (bp[0] && ((bp[bp[0]] == OVFLPAGE) ||
                ((bp[0] > 2) && bp[2] < REAL_KEY))) {
                oaddr = bp[bp[0] - 1];
                (void)fprintf(stderr, "%d ", (int)oaddr);
        bp = (short *)bufp->page;
        while (bp[0] && ((bp[bp[0]] == OVFLPAGE) ||
                ((bp[0] > 2) && bp[2] < REAL_KEY))) {
                oaddr = bp[bp[0] - 1];
                (void)fprintf(stderr, "%d ", (int)oaddr);
-               bufp = __get_buf((int)oaddr, bufp, 0);
+               bufp = __get_buf(hashp, (int)oaddr, bufp, 0);
                bp = (short *)bufp->page;
        }
        (void)fprintf(stderr, "\n");
                bp = (short *)bufp->page;
        }
        (void)fprintf(stderr, "\n");