Main Page | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Related Pages

hash_conv.c

00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 1996-2005
00005  *      Sleepycat Software.  All rights reserved.
00006  *
00007  * $Id: hash_conv.c,v 12.1 2005/06/16 20:22:50 bostic Exp $
00008  */
00009 
00010 #include "db_config.h"
00011 
00012 #ifndef NO_SYSTEM_INCLUDES
00013 #include <sys/types.h>
00014 #endif
00015 
00016 #include "db_int.h"
00017 #include "dbinc/db_page.h"
00018 #include "dbinc/db_swap.h"
00019 #include "dbinc/hash.h"
00020 
00021 /*
00022  * __ham_pgin --
00023  *      Convert host-specific page layout from the host-independent format
00024  *      stored on disk.
00025  *
00026  * PUBLIC: int __ham_pgin __P((DB_ENV *, DB *, db_pgno_t, void *, DBT *));
00027  */
00028 int
00029 __ham_pgin(dbenv, dummydbp, pg, pp, cookie)
00030         DB_ENV *dbenv;
00031         DB *dummydbp;
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 (h->type != P_HASHMETA && h->pgno == PGNO_INVALID) {
00048                 P_INIT(pp, (db_indx_t)pginfo->db_pagesize,
00049                     pg, PGNO_INVALID, PGNO_INVALID, 0, P_HASH);
00050                 return (0);
00051         }
00052 
00053         if (!F_ISSET(pginfo, DB_AM_SWAP))
00054                 return (0);
00055 
00056         return (h->type == P_HASHMETA ?  __ham_mswap(pp) :
00057             __db_byteswap(dbenv, dummydbp, pg, pp, pginfo->db_pagesize, 1));
00058 }
00059 
00060 /*
00061  * __ham_pgout --
00062  *      Convert host-specific page layout to the host-independent format
00063  *      stored on disk.
00064  *
00065  * PUBLIC: int __ham_pgout __P((DB_ENV *, DB *, db_pgno_t, void *, DBT *));
00066  */
00067 int
00068 __ham_pgout(dbenv, dummydbp, pg, pp, cookie)
00069         DB_ENV *dbenv;
00070         DB *dummydbp;
00071         db_pgno_t pg;
00072         void *pp;
00073         DBT *cookie;
00074 {
00075         DB_PGINFO *pginfo;
00076         PAGE *h;
00077 
00078         pginfo = (DB_PGINFO *)cookie->data;
00079         if (!F_ISSET(pginfo, DB_AM_SWAP))
00080                 return (0);
00081 
00082         h = pp;
00083         return (h->type == P_HASHMETA ?  __ham_mswap(pp) :
00084             __db_byteswap(dbenv, dummydbp, pg, pp, pginfo->db_pagesize, 0));
00085 }
00086 
00087 /*
00088  * __ham_mswap --
00089  *      Swap the bytes on the hash metadata page.
00090  *
00091  * PUBLIC: int __ham_mswap __P((void *));
00092  */
00093 int
00094 __ham_mswap(pg)
00095         void *pg;
00096 {
00097         u_int8_t *p;
00098         int i;
00099 
00100         __db_metaswap(pg);
00101 
00102         p = (u_int8_t *)pg + sizeof(DBMETA);
00103 
00104         SWAP32(p);              /* max_bucket */
00105         SWAP32(p);              /* high_mask */
00106         SWAP32(p);              /* low_mask */
00107         SWAP32(p);              /* ffactor */
00108         SWAP32(p);              /* nelem */
00109         SWAP32(p);              /* h_charkey */
00110         for (i = 0; i < NCACHED; ++i)
00111                 SWAP32(p);      /* spares */
00112         p += 59 * sizeof(u_int32_t); /* unused */
00113         SWAP32(p);              /* crypto_magic */
00114         return (0);
00115 }

Generated on Sun Dec 25 12:14:29 2005 for Berkeley DB 4.4.16 by  doxygen 1.4.2