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 * 4. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 #if defined(LIBC_SCCS) && !defined(lint)
34 static char sccsid[] = "@(#)hash.c 8.9 (Berkeley) 6/16/94";
35 #endif /* LIBC_SCCS and not lint */
36 #include <sys/cdefs.h>
37 __FBSDID("$FreeBSD$");
39 #include "namespace.h"
40 #include <sys/param.h>
52 #include "un-namespace.h"
59 static int alloc_segs(HTAB *, int);
60 static int flush_meta(HTAB *);
61 static int hash_access(HTAB *, ACTION, DBT *, DBT *);
62 static int hash_close(DB *);
63 static int hash_delete(const DB *, const DBT *, u_int32_t);
64 static int hash_fd(const DB *);
65 static int hash_get(const DB *, const DBT *, DBT *, u_int32_t);
66 static int hash_put(const DB *, DBT *, const DBT *, u_int32_t);
67 static void *hash_realloc(SEGMENT **, int, int);
68 static int hash_seq(const DB *, DBT *, DBT *, u_int32_t);
69 static int hash_sync(const DB *, u_int32_t);
70 static int hdestroy(HTAB *);
71 static HTAB *init_hash(HTAB *, const char *, const HASHINFO *);
72 static int init_htab(HTAB *, int);
73 #if BYTE_ORDER == LITTLE_ENDIAN
74 static void swap_header(HTAB *);
75 static void swap_header_copy(HASHHDR *, HASHHDR *);
78 /* Fast arithmetic, relying on powers of 2, */
79 #define MOD(x, y) ((x) & ((y) - 1))
81 #define RETURN_ERROR(ERR, LOC) { save_errno = ERR; goto LOC; }
88 #ifdef HASH_STATISTICS
89 int hash_accesses, hash_collisions, hash_expansions, hash_overflows;
92 /************************** INTERFACE ROUTINES ***************************/
96 __hash_open(file, flags, mode, info, dflags)
98 int flags, mode, dflags;
99 const HASHINFO *info; /* Special directives for create */
104 int bpages, hdrsize, new_table, nsegs, save_errno;
106 if ((flags & O_ACCMODE) == O_WRONLY) {
111 if (!(hashp = (HTAB *)calloc(1, sizeof(HTAB))))
116 * Even if user wants write only, we need to be able to read
117 * the actual file, so we need to open it read/write. But, the
118 * field in the hashp structure needs to be accurate so that
119 * we can check accesses.
121 hashp->flags = flags;
124 if (!file || (flags & O_TRUNC) ||
125 (stat(file, &statbuf) && (errno == ENOENT))) {
127 errno = 0; /* Just in case someone looks at errno */
131 if ((hashp->fp = _open(file, flags, mode)) == -1)
132 RETURN_ERROR(errno, error0);
134 /* if the .db file is empty, and we had permission to create
135 a new .db file, then reinitialize the database */
136 if ((flags & O_CREAT) &&
137 _fstat(hashp->fp, &statbuf) == 0 && statbuf.st_size == 0)
140 (void)_fcntl(hashp->fp, F_SETFD, 1);
143 if (!(hashp = init_hash(hashp, file, info)))
144 RETURN_ERROR(errno, error1);
146 /* Table already exists */
147 if (info && info->hash)
148 hashp->hash = info->hash;
150 hashp->hash = __default_hash;
152 hdrsize = _read(hashp->fp, &hashp->hdr, sizeof(HASHHDR));
153 #if BYTE_ORDER == LITTLE_ENDIAN
157 RETURN_ERROR(errno, error1);
158 if (hdrsize != sizeof(HASHHDR))
159 RETURN_ERROR(EFTYPE, error1);
160 /* Verify file type, versions and hash function */
161 if (hashp->MAGIC != HASHMAGIC)
162 RETURN_ERROR(EFTYPE, error1);
163 #define OLDHASHVERSION 1
164 if (hashp->VERSION != HASHVERSION &&
165 hashp->VERSION != OLDHASHVERSION)
166 RETURN_ERROR(EFTYPE, error1);
167 if (hashp->hash(CHARKEY, sizeof(CHARKEY)) != hashp->H_CHARKEY)
168 RETURN_ERROR(EFTYPE, error1);
170 * Figure out how many segments we need. Max_Bucket is the
171 * maximum bucket number, so the number of buckets is
174 nsegs = (hashp->MAX_BUCKET + 1 + hashp->SGSIZE - 1) /
177 if (alloc_segs(hashp, nsegs))
179 * If alloc_segs fails, table will have been destroyed
180 * and errno will have been set.
183 /* Read in bitmaps */
184 bpages = (hashp->SPARES[hashp->OVFL_POINT] +
185 (hashp->BSIZE << BYTE_SHIFT) - 1) >>
186 (hashp->BSHIFT + BYTE_SHIFT);
188 hashp->nmaps = bpages;
189 (void)memset(&hashp->mapp[0], 0, bpages * sizeof(u_int32_t *));
192 /* Initialize Buffer Manager */
193 if (info && info->cachesize)
194 __buf_init(hashp, info->cachesize);
196 __buf_init(hashp, DEF_BUFSIZE);
198 hashp->new_file = new_table;
199 hashp->save_file = file && (hashp->flags & O_RDWR);
201 if (!(dbp = (DB *)malloc(sizeof(DB)))) {
207 dbp->internal = hashp;
208 dbp->close = hash_close;
209 dbp->del = hash_delete;
214 dbp->sync = hash_sync;
218 (void)fprintf(stderr,
219 "%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",
221 "TABLE POINTER ", hashp,
222 "BUCKET SIZE ", hashp->BSIZE,
223 "BUCKET SHIFT ", hashp->BSHIFT,
224 "DIRECTORY SIZE ", hashp->DSIZE,
225 "SEGMENT SIZE ", hashp->SGSIZE,
226 "SEGMENT SHIFT ", hashp->SSHIFT,
227 "FILL FACTOR ", hashp->FFACTOR,
228 "MAX BUCKET ", hashp->MAX_BUCKET,
229 "OVFL POINT ", hashp->OVFL_POINT,
230 "LAST FREED ", hashp->LAST_FREED,
231 "HIGH MASK ", hashp->HIGH_MASK,
232 "LOW MASK ", hashp->LOW_MASK,
233 "NSEGS ", hashp->nsegs,
234 "NKEYS ", hashp->NKEYS);
236 #ifdef HASH_STATISTICS
237 hash_overflows = hash_accesses = hash_collisions = hash_expansions = 0;
243 (void)_close(hashp->fp);
261 hashp = (HTAB *)dbp->internal;
262 retval = hdestroy(hashp);
276 hashp = (HTAB *)dbp->internal;
277 if (hashp->fp == -1) {
284 /************************** LOCAL CREATION ROUTINES **********************/
286 init_hash(hashp, file, info)
289 const HASHINFO *info;
296 hashp->LORDER = BYTE_ORDER;
297 hashp->BSIZE = DEF_BUCKET_SIZE;
298 hashp->BSHIFT = DEF_BUCKET_SHIFT;
299 hashp->SGSIZE = DEF_SEGSIZE;
300 hashp->SSHIFT = DEF_SEGSIZE_SHIFT;
301 hashp->DSIZE = DEF_DIRSIZE;
302 hashp->FFACTOR = DEF_FFACTOR;
303 hashp->hash = __default_hash;
304 memset(hashp->SPARES, 0, sizeof(hashp->SPARES));
305 memset(hashp->BITMAPS, 0, sizeof (hashp->BITMAPS));
307 /* Fix bucket size to be optimal for file system */
309 if (stat(file, &statbuf))
311 hashp->BSIZE = statbuf.st_blksize;
312 hashp->BSHIFT = __log2(hashp->BSIZE);
317 /* Round pagesize up to power of 2 */
318 hashp->BSHIFT = __log2(info->bsize);
319 hashp->BSIZE = 1 << hashp->BSHIFT;
320 if (hashp->BSIZE > MAX_BSIZE) {
326 hashp->FFACTOR = info->ffactor;
328 hashp->hash = info->hash;
332 if (info->lorder != BIG_ENDIAN &&
333 info->lorder != LITTLE_ENDIAN) {
337 hashp->LORDER = info->lorder;
340 /* init_htab should destroy the table and set errno if it fails */
341 if (init_htab(hashp, nelem))
347 * This calls alloc_segs which may run out of memory. Alloc_segs will destroy
348 * the table and set errno, so we just pass the error information along.
350 * Returns 0 on No Error
353 init_htab(hashp, nelem)
361 * Divide number of elements by the fill factor and determine a
362 * desired number of buckets. Allocate space for the next greater
363 * power of two number of buckets.
365 nelem = (nelem - 1) / hashp->FFACTOR + 1;
367 l2 = __log2(MAX(nelem, 2));
370 hashp->SPARES[l2] = l2 + 1;
371 hashp->SPARES[l2 + 1] = l2 + 1;
372 hashp->OVFL_POINT = l2;
373 hashp->LAST_FREED = 2;
375 /* First bitmap page is at: splitpoint l2 page offset 1 */
376 if (__ibitmap(hashp, OADDR_OF(l2, 1), l2 + 1, 0))
379 hashp->MAX_BUCKET = hashp->LOW_MASK = nbuckets - 1;
380 hashp->HIGH_MASK = (nbuckets << 1) - 1;
381 hashp->HDRPAGES = ((MAX(sizeof(HASHHDR), MINHDRSIZE) - 1) >>
384 nsegs = (nbuckets - 1) / hashp->SGSIZE + 1;
385 nsegs = 1 << __log2(nsegs);
387 if (nsegs > hashp->DSIZE)
388 hashp->DSIZE = nsegs;
389 return (alloc_segs(hashp, nsegs));
392 /********************** DESTROY/CLOSE ROUTINES ************************/
395 * Flushes any changes to the file if necessary and destroys the hashp
396 * structure, freeing all allocated space.
406 #ifdef HASH_STATISTICS
407 (void)fprintf(stderr, "hdestroy: accesses %ld collisions %ld\n",
408 hash_accesses, hash_collisions);
409 (void)fprintf(stderr, "hdestroy: expansions %ld\n",
411 (void)fprintf(stderr, "hdestroy: overflows %ld\n",
413 (void)fprintf(stderr, "keys %ld maxp %d segmentcount %d\n",
414 hashp->NKEYS, hashp->MAX_BUCKET, hashp->nsegs);
416 for (i = 0; i < NCACHED; i++)
417 (void)fprintf(stderr,
418 "spares[%d] = %d\n", i, hashp->SPARES[i]);
421 * Call on buffer manager to free buffers, and if required,
422 * write them to disk.
424 if (__buf_free(hashp, 1, hashp->save_file))
427 free(*hashp->dir); /* Free initial segments */
428 /* Free extra segments */
429 while (hashp->exsegs--)
430 free(hashp->dir[--hashp->nsegs]);
433 if (flush_meta(hashp) && !save_errno)
436 for (i = 0; i < hashp->nmaps; i++)
438 free(hashp->mapp[i]);
441 (void)_close(hashp->fp);
452 * Write modified pages to disk
459 hash_sync(dbp, flags)
473 hashp = (HTAB *)dbp->internal;
474 if (!hashp->save_file)
476 if (__buf_free(hashp, 0, 1) || flush_meta(hashp))
485 * -1 indicates that errno should be set
492 #if BYTE_ORDER == LITTLE_ENDIAN
497 if (!hashp->save_file)
499 hashp->MAGIC = HASHMAGIC;
500 hashp->VERSION = HASHVERSION;
501 hashp->H_CHARKEY = hashp->hash(CHARKEY, sizeof(CHARKEY));
505 #if BYTE_ORDER == LITTLE_ENDIAN
507 swap_header_copy(&hashp->hdr, whdrp);
509 if ((lseek(fp, (off_t)0, SEEK_SET) == -1) ||
510 ((wsize = _write(fp, whdrp, sizeof(HASHHDR))) == -1))
513 if (wsize != sizeof(HASHHDR)) {
515 hashp->error = errno;
518 for (i = 0; i < NCACHED; i++)
520 if (__put_page(hashp, (char *)hashp->mapp[i],
521 hashp->BITMAPS[i], 0, 1))
526 /*******************************SEARCH ROUTINES *****************************/
528 * All the access routines return
532 * 1 to indicate an external ERROR (i.e. key not found, etc)
533 * -1 to indicate an internal ERROR (i.e. out of memory, etc)
536 hash_get(dbp, key, data, flag)
544 hashp = (HTAB *)dbp->internal;
546 hashp->error = errno = EINVAL;
549 return (hash_access(hashp, HASH_GET, (DBT *)key, data));
553 hash_put(dbp, key, data, flag)
561 hashp = (HTAB *)dbp->internal;
562 if (flag && flag != R_NOOVERWRITE) {
563 hashp->error = EINVAL;
567 if ((hashp->flags & O_ACCMODE) == O_RDONLY) {
568 hashp->error = errno = EPERM;
571 return (hash_access(hashp, flag == R_NOOVERWRITE ?
572 HASH_PUTNEW : HASH_PUT, (DBT *)key, (DBT *)data));
576 hash_delete(dbp, key, flag)
579 u_int32_t flag; /* Ignored */
583 hashp = (HTAB *)dbp->internal;
584 if (flag && flag != R_CURSOR) {
585 hashp->error = errno = EINVAL;
588 if ((hashp->flags & O_ACCMODE) == O_RDONLY) {
589 hashp->error = errno = EPERM;
592 return (hash_access(hashp, HASH_DELETE, (DBT *)key, NULL));
596 * Assume that hashp has been set in wrapper routine.
599 hash_access(hashp, action, key, val)
605 BUFHEAD *bufp, *save_bufp;
607 int n, ndx, off, size;
611 #ifdef HASH_STATISTICS
617 kp = (char *)key->data;
618 rbufp = __get_buf(hashp, __call_hash(hashp, kp, size), NULL, 0);
623 /* Pin the bucket chain */
624 rbufp->flags |= BUF_PIN;
625 for (bp = (u_int16_t *)rbufp->page, n = *bp++, ndx = 1; ndx < n;)
626 if (bp[1] >= REAL_KEY) {
627 /* Real key/data pair */
628 if (size == off - *bp &&
629 memcmp(kp, rbufp->page + *bp, size) == 0)
632 #ifdef HASH_STATISTICS
637 } else if (bp[1] == OVFLPAGE) {
638 rbufp = __get_buf(hashp, *bp, rbufp, 0);
640 save_bufp->flags &= ~BUF_PIN;
644 bp = (u_int16_t *)rbufp->page;
648 } else if (bp[1] < REAL_KEY) {
650 __find_bigpair(hashp, rbufp, ndx, kp, size)) > 0)
655 __find_last_page(hashp, &bufp))) {
660 rbufp = __get_buf(hashp, pageno, bufp, 0);
662 save_bufp->flags &= ~BUF_PIN;
666 bp = (u_int16_t *)rbufp->page;
671 save_bufp->flags &= ~BUF_PIN;
680 if (__addel(hashp, rbufp, key, val)) {
681 save_bufp->flags &= ~BUF_PIN;
684 save_bufp->flags &= ~BUF_PIN;
690 save_bufp->flags &= ~BUF_PIN;
697 save_bufp->flags &= ~BUF_PIN;
700 bp = (u_int16_t *)rbufp->page;
701 if (bp[ndx + 1] < REAL_KEY) {
702 if (__big_return(hashp, rbufp, ndx, val, 0))
705 val->data = (u_char *)rbufp->page + (int)bp[ndx + 1];
706 val->size = bp[ndx] - bp[ndx + 1];
710 if ((__delpair(hashp, rbufp, ndx)) ||
711 (__addel(hashp, rbufp, key, val))) {
712 save_bufp->flags &= ~BUF_PIN;
717 if (__delpair(hashp, rbufp, ndx))
723 save_bufp->flags &= ~BUF_PIN;
728 hash_seq(dbp, key, data, flag)
738 hashp = (HTAB *)dbp->internal;
739 if (flag && flag != R_FIRST && flag != R_NEXT) {
740 hashp->error = errno = EINVAL;
743 #ifdef HASH_STATISTICS
746 if ((hashp->cbucket < 0) || (flag == R_FIRST)) {
752 for (bp = NULL; !bp || !bp[0]; ) {
753 if (!(bufp = hashp->cpage)) {
754 for (bucket = hashp->cbucket;
755 bucket <= hashp->MAX_BUCKET;
756 bucket++, hashp->cndx = 1) {
757 bufp = __get_buf(hashp, bucket, NULL, 0);
761 bp = (u_int16_t *)bufp->page;
765 hashp->cbucket = bucket;
766 if (hashp->cbucket > hashp->MAX_BUCKET) {
771 bp = (u_int16_t *)hashp->cpage->page;
777 while (bp[hashp->cndx + 1] == OVFLPAGE) {
778 bufp = hashp->cpage =
779 __get_buf(hashp, bp[hashp->cndx], bufp, 0);
782 bp = (u_int16_t *)(bufp->page);
791 if (bp[ndx + 1] < REAL_KEY) {
792 if (__big_keydata(hashp, bufp, key, data, 1))
795 key->data = (u_char *)hashp->cpage->page + bp[ndx];
796 key->size = (ndx > 1 ? bp[ndx - 1] : hashp->BSIZE) - bp[ndx];
797 data->data = (u_char *)hashp->cpage->page + bp[ndx + 1];
798 data->size = bp[ndx] - bp[ndx + 1];
810 /********************************* UTILITIES ************************/
818 __expand_table(hashp)
821 u_int32_t old_bucket, new_bucket;
822 int dirsize, new_segnum, spare_ndx;
824 #ifdef HASH_STATISTICS
827 new_bucket = ++hashp->MAX_BUCKET;
828 old_bucket = (hashp->MAX_BUCKET & hashp->LOW_MASK);
830 new_segnum = new_bucket >> hashp->SSHIFT;
832 /* Check if we need a new segment */
833 if (new_segnum >= hashp->nsegs) {
834 /* Check if we need to expand directory */
835 if (new_segnum >= hashp->DSIZE) {
836 /* Reallocate directory */
837 dirsize = hashp->DSIZE * sizeof(SEGMENT *);
838 if (!hash_realloc(&hashp->dir, dirsize, dirsize << 1))
840 hashp->DSIZE = dirsize << 1;
842 if ((hashp->dir[new_segnum] =
843 (SEGMENT)calloc(hashp->SGSIZE, sizeof(SEGMENT))) == NULL)
849 * If the split point is increasing (MAX_BUCKET's log base 2
850 * * increases), we need to copy the current contents of the spare
851 * split bucket to the next bucket.
853 spare_ndx = __log2(hashp->MAX_BUCKET + 1);
854 if (spare_ndx > hashp->OVFL_POINT) {
855 hashp->SPARES[spare_ndx] = hashp->SPARES[hashp->OVFL_POINT];
856 hashp->OVFL_POINT = spare_ndx;
859 if (new_bucket > hashp->HIGH_MASK) {
860 /* Starting a new doubling */
861 hashp->LOW_MASK = hashp->HIGH_MASK;
862 hashp->HIGH_MASK = new_bucket | hashp->LOW_MASK;
864 /* Relocate records to the new bucket */
865 return (__split_page(hashp, old_bucket, new_bucket));
869 * If realloc guarantees that the pointer is not destroyed if the realloc
870 * fails, then this routine can go away.
873 hash_realloc(p_ptr, oldsize, newsize)
875 int oldsize, newsize;
879 if ( (p = malloc(newsize)) ) {
880 memmove(p, *p_ptr, oldsize);
881 memset((char *)p + oldsize, 0, newsize - oldsize);
889 __call_hash(hashp, k, len)
896 n = hashp->hash(k, len);
897 bucket = n & hashp->HIGH_MASK;
898 if (bucket > hashp->MAX_BUCKET)
899 bucket = bucket & hashp->LOW_MASK;
904 * Allocate segment table. On error, destroy the table and set errno.
906 * Returns 0 on success
909 alloc_segs(hashp, nsegs)
919 (SEGMENT *)calloc(hashp->DSIZE, sizeof(SEGMENT *))) == NULL) {
921 (void)hdestroy(hashp);
925 /* Allocate segments */
927 (SEGMENT)calloc(nsegs << hashp->SSHIFT, sizeof(SEGMENT))) == NULL) {
929 (void)hdestroy(hashp);
933 for (i = 0; i < nsegs; i++, hashp->nsegs++)
934 hashp->dir[i] = &store[i << hashp->SSHIFT];
938 #if BYTE_ORDER == LITTLE_ENDIAN
940 * Hashp->hdr needs to be byteswapped.
943 swap_header_copy(srcp, destp)
944 HASHHDR *srcp, *destp;
948 P_32_COPY(srcp->magic, destp->magic);
949 P_32_COPY(srcp->version, destp->version);
950 P_32_COPY(srcp->lorder, destp->lorder);
951 P_32_COPY(srcp->bsize, destp->bsize);
952 P_32_COPY(srcp->bshift, destp->bshift);
953 P_32_COPY(srcp->dsize, destp->dsize);
954 P_32_COPY(srcp->ssize, destp->ssize);
955 P_32_COPY(srcp->sshift, destp->sshift);
956 P_32_COPY(srcp->ovfl_point, destp->ovfl_point);
957 P_32_COPY(srcp->last_freed, destp->last_freed);
958 P_32_COPY(srcp->max_bucket, destp->max_bucket);
959 P_32_COPY(srcp->high_mask, destp->high_mask);
960 P_32_COPY(srcp->low_mask, destp->low_mask);
961 P_32_COPY(srcp->ffactor, destp->ffactor);
962 P_32_COPY(srcp->nkeys, destp->nkeys);
963 P_32_COPY(srcp->hdrpages, destp->hdrpages);
964 P_32_COPY(srcp->h_charkey, destp->h_charkey);
965 for (i = 0; i < NCACHED; i++) {
966 P_32_COPY(srcp->spares[i], destp->spares[i]);
967 P_16_COPY(srcp->bitmaps[i], destp->bitmaps[i]);
980 M_32_SWAP(hdrp->magic);
981 M_32_SWAP(hdrp->version);
982 M_32_SWAP(hdrp->lorder);
983 M_32_SWAP(hdrp->bsize);
984 M_32_SWAP(hdrp->bshift);
985 M_32_SWAP(hdrp->dsize);
986 M_32_SWAP(hdrp->ssize);
987 M_32_SWAP(hdrp->sshift);
988 M_32_SWAP(hdrp->ovfl_point);
989 M_32_SWAP(hdrp->last_freed);
990 M_32_SWAP(hdrp->max_bucket);
991 M_32_SWAP(hdrp->high_mask);
992 M_32_SWAP(hdrp->low_mask);
993 M_32_SWAP(hdrp->ffactor);
994 M_32_SWAP(hdrp->nkeys);
995 M_32_SWAP(hdrp->hdrpages);
996 M_32_SWAP(hdrp->h_charkey);
997 for (i = 0; i < NCACHED; i++) {
998 M_32_SWAP(hdrp->spares[i]);
999 M_16_SWAP(hdrp->bitmaps[i]);