2 * Copyright (c) 1990, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software contributed to Berkeley by
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 #if defined(LIBC_SCCS) && !defined(lint)
38 static char sccsid[] = "@(#)hash.c 8.9 (Berkeley) 6/16/94";
39 #endif /* LIBC_SCCS and not lint */
40 #include <sys/cdefs.h>
41 __FBSDID("$FreeBSD$");
43 #include "namespace.h"
44 #include <sys/param.h>
56 #include "un-namespace.h"
63 static int alloc_segs(HTAB *, int);
64 static int flush_meta(HTAB *);
65 static int hash_access(HTAB *, ACTION, DBT *, DBT *);
66 static int hash_close(DB *);
67 static int hash_delete(const DB *, const DBT *, u_int32_t);
68 static int hash_fd(const DB *);
69 static int hash_get(const DB *, const DBT *, DBT *, u_int32_t);
70 static int hash_put(const DB *, DBT *, const DBT *, u_int32_t);
71 static void *hash_realloc(SEGMENT **, int, int);
72 static int hash_seq(const DB *, DBT *, DBT *, u_int32_t);
73 static int hash_sync(const DB *, u_int32_t);
74 static int hdestroy(HTAB *);
75 static HTAB *init_hash(HTAB *, const char *, HASHINFO *);
76 static int init_htab(HTAB *, int);
77 #if BYTE_ORDER == LITTLE_ENDIAN
78 static void swap_header(HTAB *);
79 static void swap_header_copy(HASHHDR *, HASHHDR *);
82 /* Fast arithmetic, relying on powers of 2, */
83 #define MOD(x, y) ((x) & ((y) - 1))
85 #define RETURN_ERROR(ERR, LOC) { save_errno = ERR; goto LOC; }
92 #ifdef HASH_STATISTICS
93 int hash_accesses, hash_collisions, hash_expansions, hash_overflows;
96 /************************** INTERFACE ROUTINES ***************************/
100 __hash_open(file, flags, mode, info, dflags)
102 int flags, mode, dflags;
103 const HASHINFO *info; /* Special directives for create */
108 int bpages, hdrsize, new_table, nsegs, save_errno;
110 if ((flags & O_ACCMODE) == O_WRONLY) {
115 if (!(hashp = (HTAB *)calloc(1, sizeof(HTAB))))
120 * Even if user wants write only, we need to be able to read
121 * the actual file, so we need to open it read/write. But, the
122 * field in the hashp structure needs to be accurate so that
123 * we can check accesses.
125 hashp->flags = flags;
128 if (!file || (flags & O_TRUNC) ||
129 (stat(file, &statbuf) && (errno == ENOENT))) {
131 errno = 0; /* Just in case someone looks at errno */
135 if ((hashp->fp = _open(file, flags, mode)) == -1)
136 RETURN_ERROR(errno, error0);
138 /* if the .db file is empty, and we had permission to create
139 a new .db file, then reinitialize the database */
140 if ((flags & O_CREAT) &&
141 _fstat(hashp->fp, &statbuf) == 0 && statbuf.st_size == 0)
144 (void)_fcntl(hashp->fp, F_SETFD, 1);
147 if (!(hashp = init_hash(hashp, file, (HASHINFO *)info)))
148 RETURN_ERROR(errno, error1);
150 /* Table already exists */
151 if (info && info->hash)
152 hashp->hash = info->hash;
154 hashp->hash = __default_hash;
156 hdrsize = _read(hashp->fp, &hashp->hdr, sizeof(HASHHDR));
157 #if BYTE_ORDER == LITTLE_ENDIAN
161 RETURN_ERROR(errno, error1);
162 if (hdrsize != sizeof(HASHHDR))
163 RETURN_ERROR(EFTYPE, error1);
164 /* Verify file type, versions and hash function */
165 if (hashp->MAGIC != HASHMAGIC)
166 RETURN_ERROR(EFTYPE, error1);
167 #define OLDHASHVERSION 1
168 if (hashp->VERSION != HASHVERSION &&
169 hashp->VERSION != OLDHASHVERSION)
170 RETURN_ERROR(EFTYPE, error1);
171 if (hashp->hash(CHARKEY, sizeof(CHARKEY)) != hashp->H_CHARKEY)
172 RETURN_ERROR(EFTYPE, error1);
174 * Figure out how many segments we need. Max_Bucket is the
175 * maximum bucket number, so the number of buckets is
178 nsegs = (hashp->MAX_BUCKET + 1 + hashp->SGSIZE - 1) /
181 if (alloc_segs(hashp, nsegs))
183 * If alloc_segs fails, table will have been destroyed
184 * and errno will have been set.
187 /* Read in bitmaps */
188 bpages = (hashp->SPARES[hashp->OVFL_POINT] +
189 (hashp->BSIZE << BYTE_SHIFT) - 1) >>
190 (hashp->BSHIFT + BYTE_SHIFT);
192 hashp->nmaps = bpages;
193 (void)memset(&hashp->mapp[0], 0, bpages * sizeof(u_int32_t *));
196 /* Initialize Buffer Manager */
197 if (info && info->cachesize)
198 __buf_init(hashp, info->cachesize);
200 __buf_init(hashp, DEF_BUFSIZE);
202 hashp->new_file = new_table;
203 hashp->save_file = file && (hashp->flags & O_RDWR);
205 if (!(dbp = (DB *)malloc(sizeof(DB)))) {
211 dbp->internal = hashp;
212 dbp->close = hash_close;
213 dbp->del = hash_delete;
218 dbp->sync = hash_sync;
222 (void)fprintf(stderr,
223 "%s\n%s%p\n%s%d\n%s%d\n%s%d\n%s%d\n%s%d\n%s%d\n%s%d\n%s%d\n%s%d\n%s%x\n%s%x\n%s%d\n%s%d\n",
225 "TABLE POINTER ", hashp,
226 "BUCKET SIZE ", hashp->BSIZE,
227 "BUCKET SHIFT ", hashp->BSHIFT,
228 "DIRECTORY SIZE ", hashp->DSIZE,
229 "SEGMENT SIZE ", hashp->SGSIZE,
230 "SEGMENT SHIFT ", hashp->SSHIFT,
231 "FILL FACTOR ", hashp->FFACTOR,
232 "MAX BUCKET ", hashp->MAX_BUCKET,
233 "OVFL POINT ", hashp->OVFL_POINT,
234 "LAST FREED ", hashp->LAST_FREED,
235 "HIGH MASK ", hashp->HIGH_MASK,
236 "LOW MASK ", hashp->LOW_MASK,
237 "NSEGS ", hashp->nsegs,
238 "NKEYS ", hashp->NKEYS);
240 #ifdef HASH_STATISTICS
241 hash_overflows = hash_accesses = hash_collisions = hash_expansions = 0;
247 (void)_close(hashp->fp);
265 hashp = (HTAB *)dbp->internal;
266 retval = hdestroy(hashp);
280 hashp = (HTAB *)dbp->internal;
281 if (hashp->fp == -1) {
288 /************************** LOCAL CREATION ROUTINES **********************/
290 init_hash(hashp, file, info)
300 hashp->LORDER = BYTE_ORDER;
301 hashp->BSIZE = DEF_BUCKET_SIZE;
302 hashp->BSHIFT = DEF_BUCKET_SHIFT;
303 hashp->SGSIZE = DEF_SEGSIZE;
304 hashp->SSHIFT = DEF_SEGSIZE_SHIFT;
305 hashp->DSIZE = DEF_DIRSIZE;
306 hashp->FFACTOR = DEF_FFACTOR;
307 hashp->hash = __default_hash;
308 memset(hashp->SPARES, 0, sizeof(hashp->SPARES));
309 memset(hashp->BITMAPS, 0, sizeof (hashp->BITMAPS));
311 /* Fix bucket size to be optimal for file system */
313 if (stat(file, &statbuf))
315 hashp->BSIZE = statbuf.st_blksize;
316 hashp->BSHIFT = __log2(hashp->BSIZE);
321 /* Round pagesize up to power of 2 */
322 hashp->BSHIFT = __log2(info->bsize);
323 hashp->BSIZE = 1 << hashp->BSHIFT;
324 if (hashp->BSIZE > MAX_BSIZE) {
330 hashp->FFACTOR = info->ffactor;
332 hashp->hash = info->hash;
336 if (info->lorder != BIG_ENDIAN &&
337 info->lorder != LITTLE_ENDIAN) {
341 hashp->LORDER = info->lorder;
344 /* init_htab should destroy the table and set errno if it fails */
345 if (init_htab(hashp, nelem))
351 * This calls alloc_segs which may run out of memory. Alloc_segs will destroy
352 * the table and set errno, so we just pass the error information along.
354 * Returns 0 on No Error
357 init_htab(hashp, nelem)
365 * Divide number of elements by the fill factor and determine a
366 * desired number of buckets. Allocate space for the next greater
367 * power of two number of buckets.
369 nelem = (nelem - 1) / hashp->FFACTOR + 1;
371 l2 = __log2(MAX(nelem, 2));
374 hashp->SPARES[l2] = l2 + 1;
375 hashp->SPARES[l2 + 1] = l2 + 1;
376 hashp->OVFL_POINT = l2;
377 hashp->LAST_FREED = 2;
379 /* First bitmap page is at: splitpoint l2 page offset 1 */
380 if (__ibitmap(hashp, OADDR_OF(l2, 1), l2 + 1, 0))
383 hashp->MAX_BUCKET = hashp->LOW_MASK = nbuckets - 1;
384 hashp->HIGH_MASK = (nbuckets << 1) - 1;
385 hashp->HDRPAGES = ((MAX(sizeof(HASHHDR), MINHDRSIZE) - 1) >>
388 nsegs = (nbuckets - 1) / hashp->SGSIZE + 1;
389 nsegs = 1 << __log2(nsegs);
391 if (nsegs > hashp->DSIZE)
392 hashp->DSIZE = nsegs;
393 return (alloc_segs(hashp, nsegs));
396 /********************** DESTROY/CLOSE ROUTINES ************************/
399 * Flushes any changes to the file if necessary and destroys the hashp
400 * structure, freeing all allocated space.
410 #ifdef HASH_STATISTICS
411 (void)fprintf(stderr, "hdestroy: accesses %ld collisions %ld\n",
412 hash_accesses, hash_collisions);
413 (void)fprintf(stderr, "hdestroy: expansions %ld\n",
415 (void)fprintf(stderr, "hdestroy: overflows %ld\n",
417 (void)fprintf(stderr, "keys %ld maxp %d segmentcount %d\n",
418 hashp->NKEYS, hashp->MAX_BUCKET, hashp->nsegs);
420 for (i = 0; i < NCACHED; i++)
421 (void)fprintf(stderr,
422 "spares[%d] = %d\n", i, hashp->SPARES[i]);
425 * Call on buffer manager to free buffers, and if required,
426 * write them to disk.
428 if (__buf_free(hashp, 1, hashp->save_file))
431 free(*hashp->dir); /* Free initial segments */
432 /* Free extra segments */
433 while (hashp->exsegs--)
434 free(hashp->dir[--hashp->nsegs]);
437 if (flush_meta(hashp) && !save_errno)
440 for (i = 0; i < hashp->nmaps; i++)
442 free(hashp->mapp[i]);
445 (void)_close(hashp->fp);
456 * Write modified pages to disk
463 hash_sync(dbp, flags)
477 hashp = (HTAB *)dbp->internal;
478 if (!hashp->save_file)
480 if (__buf_free(hashp, 0, 1) || flush_meta(hashp))
489 * -1 indicates that errno should be set
496 #if BYTE_ORDER == LITTLE_ENDIAN
501 if (!hashp->save_file)
503 hashp->MAGIC = HASHMAGIC;
504 hashp->VERSION = HASHVERSION;
505 hashp->H_CHARKEY = hashp->hash(CHARKEY, sizeof(CHARKEY));
509 #if BYTE_ORDER == LITTLE_ENDIAN
511 swap_header_copy(&hashp->hdr, whdrp);
513 if ((lseek(fp, (off_t)0, SEEK_SET) == -1) ||
514 ((wsize = _write(fp, whdrp, sizeof(HASHHDR))) == -1))
517 if (wsize != sizeof(HASHHDR)) {
519 hashp->error = errno;
522 for (i = 0; i < NCACHED; i++)
524 if (__put_page(hashp, (char *)hashp->mapp[i],
525 hashp->BITMAPS[i], 0, 1))
530 /*******************************SEARCH ROUTINES *****************************/
532 * All the access routines return
536 * 1 to indicate an external ERROR (i.e. key not found, etc)
537 * -1 to indicate an internal ERROR (i.e. out of memory, etc)
540 hash_get(dbp, key, data, flag)
548 hashp = (HTAB *)dbp->internal;
550 hashp->error = errno = EINVAL;
553 return (hash_access(hashp, HASH_GET, (DBT *)key, data));
557 hash_put(dbp, key, data, flag)
565 hashp = (HTAB *)dbp->internal;
566 if (flag && flag != R_NOOVERWRITE) {
567 hashp->error = EINVAL;
571 if ((hashp->flags & O_ACCMODE) == O_RDONLY) {
572 hashp->error = errno = EPERM;
575 return (hash_access(hashp, flag == R_NOOVERWRITE ?
576 HASH_PUTNEW : HASH_PUT, (DBT *)key, (DBT *)data));
580 hash_delete(dbp, key, flag)
583 u_int32_t flag; /* Ignored */
587 hashp = (HTAB *)dbp->internal;
588 if (flag && flag != R_CURSOR) {
589 hashp->error = errno = EINVAL;
592 if ((hashp->flags & O_ACCMODE) == O_RDONLY) {
593 hashp->error = errno = EPERM;
596 return (hash_access(hashp, HASH_DELETE, (DBT *)key, NULL));
600 * Assume that hashp has been set in wrapper routine.
603 hash_access(hashp, action, key, val)
609 BUFHEAD *bufp, *save_bufp;
611 int n, ndx, off, size;
615 #ifdef HASH_STATISTICS
621 kp = (char *)key->data;
622 rbufp = __get_buf(hashp, __call_hash(hashp, kp, size), NULL, 0);
627 /* Pin the bucket chain */
628 rbufp->flags |= BUF_PIN;
629 for (bp = (u_int16_t *)rbufp->page, n = *bp++, ndx = 1; ndx < n;)
630 if (bp[1] >= REAL_KEY) {
631 /* Real key/data pair */
632 if (size == off - *bp &&
633 memcmp(kp, rbufp->page + *bp, size) == 0)
636 #ifdef HASH_STATISTICS
641 } else if (bp[1] == OVFLPAGE) {
642 rbufp = __get_buf(hashp, *bp, rbufp, 0);
644 save_bufp->flags &= ~BUF_PIN;
648 bp = (u_int16_t *)rbufp->page;
652 } else if (bp[1] < REAL_KEY) {
654 __find_bigpair(hashp, rbufp, ndx, kp, size)) > 0)
659 __find_last_page(hashp, &bufp))) {
664 rbufp = __get_buf(hashp, pageno, bufp, 0);
666 save_bufp->flags &= ~BUF_PIN;
670 bp = (u_int16_t *)rbufp->page;
675 save_bufp->flags &= ~BUF_PIN;
684 if (__addel(hashp, rbufp, key, val)) {
685 save_bufp->flags &= ~BUF_PIN;
688 save_bufp->flags &= ~BUF_PIN;
694 save_bufp->flags &= ~BUF_PIN;
701 save_bufp->flags &= ~BUF_PIN;
704 bp = (u_int16_t *)rbufp->page;
705 if (bp[ndx + 1] < REAL_KEY) {
706 if (__big_return(hashp, rbufp, ndx, val, 0))
709 val->data = (u_char *)rbufp->page + (int)bp[ndx + 1];
710 val->size = bp[ndx] - bp[ndx + 1];
714 if ((__delpair(hashp, rbufp, ndx)) ||
715 (__addel(hashp, rbufp, key, val))) {
716 save_bufp->flags &= ~BUF_PIN;
721 if (__delpair(hashp, rbufp, ndx))
727 save_bufp->flags &= ~BUF_PIN;
732 hash_seq(dbp, key, data, flag)
742 hashp = (HTAB *)dbp->internal;
743 if (flag && flag != R_FIRST && flag != R_NEXT) {
744 hashp->error = errno = EINVAL;
747 #ifdef HASH_STATISTICS
750 if ((hashp->cbucket < 0) || (flag == R_FIRST)) {
756 for (bp = NULL; !bp || !bp[0]; ) {
757 if (!(bufp = hashp->cpage)) {
758 for (bucket = hashp->cbucket;
759 bucket <= hashp->MAX_BUCKET;
760 bucket++, hashp->cndx = 1) {
761 bufp = __get_buf(hashp, bucket, NULL, 0);
765 bp = (u_int16_t *)bufp->page;
769 hashp->cbucket = bucket;
770 if (hashp->cbucket > hashp->MAX_BUCKET) {
775 bp = (u_int16_t *)hashp->cpage->page;
781 while (bp[hashp->cndx + 1] == OVFLPAGE) {
782 bufp = hashp->cpage =
783 __get_buf(hashp, bp[hashp->cndx], bufp, 0);
786 bp = (u_int16_t *)(bufp->page);
795 if (bp[ndx + 1] < REAL_KEY) {
796 if (__big_keydata(hashp, bufp, key, data, 1))
799 key->data = (u_char *)hashp->cpage->page + bp[ndx];
800 key->size = (ndx > 1 ? bp[ndx - 1] : hashp->BSIZE) - bp[ndx];
801 data->data = (u_char *)hashp->cpage->page + bp[ndx + 1];
802 data->size = bp[ndx] - bp[ndx + 1];
814 /********************************* UTILITIES ************************/
822 __expand_table(hashp)
825 u_int32_t old_bucket, new_bucket;
826 int dirsize, new_segnum, spare_ndx;
828 #ifdef HASH_STATISTICS
831 new_bucket = ++hashp->MAX_BUCKET;
832 old_bucket = (hashp->MAX_BUCKET & hashp->LOW_MASK);
834 new_segnum = new_bucket >> hashp->SSHIFT;
836 /* Check if we need a new segment */
837 if (new_segnum >= hashp->nsegs) {
838 /* Check if we need to expand directory */
839 if (new_segnum >= hashp->DSIZE) {
840 /* Reallocate directory */
841 dirsize = hashp->DSIZE * sizeof(SEGMENT *);
842 if (!hash_realloc(&hashp->dir, dirsize, dirsize << 1))
844 hashp->DSIZE = dirsize << 1;
846 if ((hashp->dir[new_segnum] =
847 (SEGMENT)calloc(hashp->SGSIZE, sizeof(SEGMENT))) == NULL)
853 * If the split point is increasing (MAX_BUCKET's log base 2
854 * * increases), we need to copy the current contents of the spare
855 * split bucket to the next bucket.
857 spare_ndx = __log2(hashp->MAX_BUCKET + 1);
858 if (spare_ndx > hashp->OVFL_POINT) {
859 hashp->SPARES[spare_ndx] = hashp->SPARES[hashp->OVFL_POINT];
860 hashp->OVFL_POINT = spare_ndx;
863 if (new_bucket > hashp->HIGH_MASK) {
864 /* Starting a new doubling */
865 hashp->LOW_MASK = hashp->HIGH_MASK;
866 hashp->HIGH_MASK = new_bucket | hashp->LOW_MASK;
868 /* Relocate records to the new bucket */
869 return (__split_page(hashp, old_bucket, new_bucket));
873 * If realloc guarantees that the pointer is not destroyed if the realloc
874 * fails, then this routine can go away.
877 hash_realloc(p_ptr, oldsize, newsize)
879 int oldsize, newsize;
883 if ( (p = malloc(newsize)) ) {
884 memmove(p, *p_ptr, oldsize);
885 memset((char *)p + oldsize, 0, newsize - oldsize);
893 __call_hash(hashp, k, len)
900 n = hashp->hash(k, len);
901 bucket = n & hashp->HIGH_MASK;
902 if (bucket > hashp->MAX_BUCKET)
903 bucket = bucket & hashp->LOW_MASK;
908 * Allocate segment table. On error, destroy the table and set errno.
910 * Returns 0 on success
913 alloc_segs(hashp, nsegs)
923 (SEGMENT *)calloc(hashp->DSIZE, sizeof(SEGMENT *))) == NULL) {
925 (void)hdestroy(hashp);
929 /* Allocate segments */
931 (SEGMENT)calloc(nsegs << hashp->SSHIFT, sizeof(SEGMENT))) == NULL) {
933 (void)hdestroy(hashp);
937 for (i = 0; i < nsegs; i++, hashp->nsegs++)
938 hashp->dir[i] = &store[i << hashp->SSHIFT];
942 #if BYTE_ORDER == LITTLE_ENDIAN
944 * Hashp->hdr needs to be byteswapped.
947 swap_header_copy(srcp, destp)
948 HASHHDR *srcp, *destp;
952 P_32_COPY(srcp->magic, destp->magic);
953 P_32_COPY(srcp->version, destp->version);
954 P_32_COPY(srcp->lorder, destp->lorder);
955 P_32_COPY(srcp->bsize, destp->bsize);
956 P_32_COPY(srcp->bshift, destp->bshift);
957 P_32_COPY(srcp->dsize, destp->dsize);
958 P_32_COPY(srcp->ssize, destp->ssize);
959 P_32_COPY(srcp->sshift, destp->sshift);
960 P_32_COPY(srcp->ovfl_point, destp->ovfl_point);
961 P_32_COPY(srcp->last_freed, destp->last_freed);
962 P_32_COPY(srcp->max_bucket, destp->max_bucket);
963 P_32_COPY(srcp->high_mask, destp->high_mask);
964 P_32_COPY(srcp->low_mask, destp->low_mask);
965 P_32_COPY(srcp->ffactor, destp->ffactor);
966 P_32_COPY(srcp->nkeys, destp->nkeys);
967 P_32_COPY(srcp->hdrpages, destp->hdrpages);
968 P_32_COPY(srcp->h_charkey, destp->h_charkey);
969 for (i = 0; i < NCACHED; i++) {
970 P_32_COPY(srcp->spares[i], destp->spares[i]);
971 P_16_COPY(srcp->bitmaps[i], destp->bitmaps[i]);
984 M_32_SWAP(hdrp->magic);
985 M_32_SWAP(hdrp->version);
986 M_32_SWAP(hdrp->lorder);
987 M_32_SWAP(hdrp->bsize);
988 M_32_SWAP(hdrp->bshift);
989 M_32_SWAP(hdrp->dsize);
990 M_32_SWAP(hdrp->ssize);
991 M_32_SWAP(hdrp->sshift);
992 M_32_SWAP(hdrp->ovfl_point);
993 M_32_SWAP(hdrp->last_freed);
994 M_32_SWAP(hdrp->max_bucket);
995 M_32_SWAP(hdrp->high_mask);
996 M_32_SWAP(hdrp->low_mask);
997 M_32_SWAP(hdrp->ffactor);
998 M_32_SWAP(hdrp->nkeys);
999 M_32_SWAP(hdrp->hdrpages);
1000 M_32_SWAP(hdrp->h_charkey);
1001 for (i = 0; i < NCACHED; i++) {
1002 M_32_SWAP(hdrp->spares[i]);
1003 M_16_SWAP(hdrp->bitmaps[i]);