1/*-
2 * See the file LICENSE for redistribution information.
3 *
4 * Copyright (c) 1996,2008 Oracle.  All rights reserved.
5 *
6 * $Id: bt_conv.c,v 12.11 2008/01/30 12:18:21 mjc Exp $
7 */
8
9#include "db_config.h"
10
11#include "db_int.h"
12#include "dbinc/db_page.h"
13#include "dbinc/db_swap.h"
14#include "dbinc/btree.h"
15
16/*
17 * __bam_pgin --
18 *	Convert host-specific page layout from the host-independent format
19 *	stored on disk.
20 *
21 * PUBLIC: int __bam_pgin __P((DB *, db_pgno_t, void *, DBT *));
22 */
23int
24__bam_pgin(dbp, pg, pp, cookie)
25	DB *dbp;
26	db_pgno_t pg;
27	void *pp;
28	DBT *cookie;
29{
30	DB_PGINFO *pginfo;
31	PAGE *h;
32
33	pginfo = (DB_PGINFO *)cookie->data;
34	if (!F_ISSET(pginfo, DB_AM_SWAP))
35		return (0);
36
37	h = pp;
38	return (TYPE(h) == P_BTREEMETA ?  __bam_mswap(dbp->env, pp) :
39	    __db_byteswap(dbp, pg, pp, pginfo->db_pagesize, 1));
40}
41
42/*
43 * __bam_pgout --
44 *	Convert host-specific page layout to the host-independent format
45 *	stored on disk.
46 *
47 * PUBLIC: int __bam_pgout __P((DB *, db_pgno_t, void *, DBT *));
48 */
49int
50__bam_pgout(dbp, pg, pp, cookie)
51	DB *dbp;
52	db_pgno_t pg;
53	void *pp;
54	DBT *cookie;
55{
56	DB_PGINFO *pginfo;
57	PAGE *h;
58
59	pginfo = (DB_PGINFO *)cookie->data;
60	if (!F_ISSET(pginfo, DB_AM_SWAP))
61		return (0);
62
63	h = pp;
64	return (TYPE(h) == P_BTREEMETA ?  __bam_mswap(dbp->env, pp) :
65	    __db_byteswap(dbp, pg, pp, pginfo->db_pagesize, 0));
66}
67
68/*
69 * __bam_mswap --
70 *	Swap the bytes on the btree metadata page.
71 *
72 * PUBLIC: int __bam_mswap __P((ENV *, PAGE *));
73 */
74int
75__bam_mswap(env, pg)
76	ENV *env;
77	PAGE *pg;
78{
79	u_int8_t *p;
80
81	COMPQUIET(env, NULL);
82
83	__db_metaswap(pg);
84	p = (u_int8_t *)pg + sizeof(DBMETA);
85
86	p += sizeof(u_int32_t);	/* unused */
87	SWAP32(p);		/* minkey */
88	SWAP32(p);		/* re_len */
89	SWAP32(p);		/* re_pad */
90	SWAP32(p);		/* root */
91	p += 92 * sizeof(u_int32_t); /* unused */
92	SWAP32(p);		/* crypto_magic */
93
94	return (0);
95}
96