00001 /*- 00002 * See the file LICENSE for redistribution information. 00003 * 00004 * Copyright (c) 1996, 1997, 1998, 1999, 2000 00005 * Sleepycat Software. All rights reserved. 00006 */ 00007 #include "config.h" 00008 00009 #ifndef lint 00010 static const char revid[] = "$Id: hash__conv_8c-source.html,v 1.1 2008年06月08日 10:19:24 sebdiaz Exp $"; 00011 #endif /* not lint */ 00012 00013 #ifndef NO_SYSTEM_INCLUDES 00014 #include <sys/types.h> 00015 #endif 00016 00017 #include "db_int.h" 00018 #include "db_page.h" 00019 #include "db_swap.h" 00020 #include "hash.h" 00021 00022 /* 00023 * CDB___ham_pgin -- 00024 * Convert host-specific page layout from the host-independent format 00025 * stored on disk. 00026 * 00027 * PUBLIC: int CDB___ham_pgin __P((DB_ENV *, db_pgno_t, void *, DBT *)); 00028 */ 00029 int 00030 CDB___ham_pgin(dbenv, pg, pp, cookie) 00031 DB_ENV *dbenv; 00032 db_pgno_t pg; 00033 void *pp; 00034 DBT *cookie; 00035 { 00036 DB_PGINFO *pginfo; 00037 PAGE *h; 00038 00039 h = pp; 00040 pginfo = (DB_PGINFO *)cookie->data; 00041 00042 /* 00043 * The hash access method does blind reads of pages, causing them 00044 * to be created. If the type field isn't set it's one of them, 00045 * initialize the rest of the page and return. 00046 */ 00047 if (TYPE(h) != P_HASHMETA && h->pgno == PGNO_INVALID) { 00048 P_INIT(pp, pginfo->db_pagesize, 00049 pg, PGNO_INVALID, PGNO_INVALID, 0, P_HASH, 0); 00050 return (0); 00051 } 00052 00053 if (!pginfo->needswap) 00054 return (0); 00055 00056 return (TYPE(h) == P_HASHMETA ? CDB___ham_mswap(pp) : 00057 CDB___db_byteswap(dbenv, pg, pp, pginfo->db_pagesize, 1)); 00058 } 00059 00060 /* 00061 * CDB___ham_pgout -- 00062 * Convert host-specific page layout to the host-independent format 00063 * stored on disk. 00064 * 00065 * PUBLIC: int CDB___ham_pgout __P((DB_ENV *, db_pgno_t, void *, DBT *)); 00066 */ 00067 int 00068 CDB___ham_pgout(dbenv, pg, pp, cookie) 00069 DB_ENV *dbenv; 00070 db_pgno_t pg; 00071 void *pp; 00072 DBT *cookie; 00073 { 00074 DB_PGINFO *pginfo; 00075 PAGE *h; 00076 00077 pginfo = (DB_PGINFO *)cookie->data; 00078 if (!pginfo->needswap) 00079 return (0); 00080 00081 h = pp; 00082 return (TYPE(h) == P_HASHMETA ? CDB___ham_mswap(pp) : 00083 CDB___db_byteswap(dbenv, pg, pp, pginfo->db_pagesize, 0)); 00084 } 00085 00086 /* 00087 * CDB___ham_mswap -- 00088 * Swap the bytes on the hash metadata page. 00089 * 00090 * PUBLIC: int CDB___ham_mswap __P((void *)); 00091 */ 00092 int 00093 CDB___ham_mswap(pg) 00094 void *pg; 00095 { 00096 u_int8_t *p; 00097 int i; 00098 00099 CDB___db_metaswap(pg); 00100 00101 p = (u_int8_t *)pg + sizeof(DBMETA); 00102 00103 SWAP32(p); /* max_bucket */ 00104 SWAP32(p); /* high_mask */ 00105 SWAP32(p); /* low_mask */ 00106 SWAP32(p); /* ffactor */ 00107 SWAP32(p); /* nelem */ 00108 SWAP32(p); /* h_charkey */ 00109 for (i = 0; i < NCACHED; ++i) 00110 SWAP32(p); /* spares */ 00111 return (0); 00112 }