1 /*- 2 * See the file LICENSE for redistribution information. 3 * 4 * Copyright (c) 1996, 1997 5 * Sleepycat Software. All rights reserved. 6 */ 7 /* 8 * Copyright (c) 1998 by Sun Microsystems, Inc. 9 * All rights reserved. 10 */ 11 12 #include "config.h" 13 14 #ifndef lint 15 static const char sccsid[] = "@(#)hash_conv.c 10.4 (Sleepycat) 9/15/97"; 16 static const char sccsi2[] = "%W% (Sun) %G%"; 17 #endif /* not lint */ 18 19 #ifndef NO_SYSTEM_INCLUDES 20 #include <sys/types.h> 21 #endif 22 23 #include "db_int.h" 24 #include "db_page.h" 25 #include "db_swap.h" 26 #include "hash.h" 27 28 /* 29 * __ham_pgin -- 30 * Convert host-specific page layout from the host-independent format 31 * stored on disk. 32 * 33 * PUBLIC: int __ham_pgin __P((db_pgno_t, void *, DBT *)); 34 */ 35 int 36 __ham_pgin(pg, pp, cookie) 37 db_pgno_t pg; 38 void *pp; 39 DBT *cookie; 40 { 41 DB_PGINFO *pginfo; 42 u_int32_t tpgno; 43 44 pginfo = (DB_PGINFO *)cookie->data; 45 tpgno = PGNO((PAGE *)pp); 46 if (pginfo->needswap) 47 M_32_SWAP(tpgno); 48 49 if (pg != PGNO_METADATA && pg != tpgno) { 50 P_INIT(pp, pginfo->db_pagesize, 51 pg, PGNO_INVALID, PGNO_INVALID, 0, P_HASH); 52 return (0); 53 } 54 55 if (!pginfo->needswap) 56 return (0); 57 return (pg == PGNO_METADATA ? 58 __ham_mswap(pp) : __db_pgin(pg, pginfo->db_pagesize, pp)); 59 } 60 61 /* 62 * __ham_pgout -- 63 * Convert host-specific page layout to the host-independent format 64 * stored on disk. 65 * 66 * PUBLIC: int __ham_pgout __P((db_pgno_t, void *, DBT *)); 67 */ 68 int 69 __ham_pgout(pg, pp, cookie) 70 db_pgno_t pg; 71 void *pp; 72 DBT *cookie; 73 { 74 DB_PGINFO *pginfo; 75 76 pginfo = (DB_PGINFO *)cookie->data; 77 if (!pginfo->needswap) 78 return (0); 79 return (pg == PGNO_METADATA ? 80 __ham_mswap(pp) : __db_pgout(pg, pginfo->db_pagesize, pp)); 81 } 82 83 /* 84 * __ham_mswap -- 85 * Swap the bytes on the hash metadata page. 86 * 87 * PUBLIC: int __ham_mswap __P((void *)); 88 */ 89 int 90 __ham_mswap(pg) 91 void *pg; 92 { 93 u_int8_t *p; 94 int i; 95 96 p = (u_int8_t *)pg; 97 SWAP32(p); /* lsn part 1 */ 98 SWAP32(p); /* lsn part 2 */ 99 SWAP32(p); /* pgno */ 100 SWAP32(p); /* magic */ 101 SWAP32(p); /* version */ 102 SWAP32(p); /* pagesize */ 103 SWAP32(p); /* ovfl_point */ 104 SWAP32(p); /* last_freed */ 105 SWAP32(p); /* max_bucket */ 106 SWAP32(p); /* high_mask */ 107 SWAP32(p); /* low_mask */ 108 SWAP32(p); /* ffactor */ 109 SWAP32(p); /* nelem */ 110 SWAP32(p); /* h_charkey */ 111 SWAP32(p); /* flags */ 112 for (i = 0; i < NCACHED; ++i) 113 SWAP32(p); /* spares */ 114 return (0); 115 } 116