1*0Sstevel@tonic-gate /*- 2*0Sstevel@tonic-gate * See the file LICENSE for redistribution information. 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * Copyright (c) 1996, 1997, 1998 5*0Sstevel@tonic-gate * Sleepycat Software. All rights reserved. 6*0Sstevel@tonic-gate */ 7*0Sstevel@tonic-gate 8*0Sstevel@tonic-gate #include "config.h" 9*0Sstevel@tonic-gate 10*0Sstevel@tonic-gate #ifndef lint 11*0Sstevel@tonic-gate static const char sccsid[] = "@(#)bt_conv.c 10.7 (Sleepycat) 9/20/98"; 12*0Sstevel@tonic-gate #endif /* not lint */ 13*0Sstevel@tonic-gate 14*0Sstevel@tonic-gate #ifndef NO_SYSTEM_INCLUDES 15*0Sstevel@tonic-gate #include <sys/types.h> 16*0Sstevel@tonic-gate #endif 17*0Sstevel@tonic-gate 18*0Sstevel@tonic-gate #include "db_int.h" 19*0Sstevel@tonic-gate #include "db_page.h" 20*0Sstevel@tonic-gate #include "db_swap.h" 21*0Sstevel@tonic-gate #include "btree.h" 22*0Sstevel@tonic-gate 23*0Sstevel@tonic-gate /* 24*0Sstevel@tonic-gate * __bam_pgin -- 25*0Sstevel@tonic-gate * Convert host-specific page layout from the host-independent format 26*0Sstevel@tonic-gate * stored on disk. 27*0Sstevel@tonic-gate * 28*0Sstevel@tonic-gate * PUBLIC: int __bam_pgin __P((db_pgno_t, void *, DBT *)); 29*0Sstevel@tonic-gate */ 30*0Sstevel@tonic-gate int 31*0Sstevel@tonic-gate __bam_pgin(pg, pp, cookie) 32*0Sstevel@tonic-gate db_pgno_t pg; 33*0Sstevel@tonic-gate void *pp; 34*0Sstevel@tonic-gate DBT *cookie; 35*0Sstevel@tonic-gate { 36*0Sstevel@tonic-gate DB_PGINFO *pginfo; 37*0Sstevel@tonic-gate 38*0Sstevel@tonic-gate pginfo = (DB_PGINFO *)cookie->data; 39*0Sstevel@tonic-gate if (!pginfo->needswap) 40*0Sstevel@tonic-gate return (0); 41*0Sstevel@tonic-gate return (pg == PGNO_METADATA ? 42*0Sstevel@tonic-gate __bam_mswap(pp) : __db_pgin(pg, pginfo->db_pagesize, pp)); 43*0Sstevel@tonic-gate } 44*0Sstevel@tonic-gate 45*0Sstevel@tonic-gate /* 46*0Sstevel@tonic-gate * __bam_pgout -- 47*0Sstevel@tonic-gate * Convert host-specific page layout to the host-independent format 48*0Sstevel@tonic-gate * stored on disk. 49*0Sstevel@tonic-gate * 50*0Sstevel@tonic-gate * PUBLIC: int __bam_pgout __P((db_pgno_t, void *, DBT *)); 51*0Sstevel@tonic-gate */ 52*0Sstevel@tonic-gate int 53*0Sstevel@tonic-gate __bam_pgout(pg, pp, cookie) 54*0Sstevel@tonic-gate db_pgno_t pg; 55*0Sstevel@tonic-gate void *pp; 56*0Sstevel@tonic-gate DBT *cookie; 57*0Sstevel@tonic-gate { 58*0Sstevel@tonic-gate DB_PGINFO *pginfo; 59*0Sstevel@tonic-gate 60*0Sstevel@tonic-gate pginfo = (DB_PGINFO *)cookie->data; 61*0Sstevel@tonic-gate if (!pginfo->needswap) 62*0Sstevel@tonic-gate return (0); 63*0Sstevel@tonic-gate return (pg == PGNO_METADATA ? 64*0Sstevel@tonic-gate __bam_mswap(pp) : __db_pgout(pg, pginfo->db_pagesize, pp)); 65*0Sstevel@tonic-gate } 66*0Sstevel@tonic-gate 67*0Sstevel@tonic-gate /* 68*0Sstevel@tonic-gate * __bam_mswap -- 69*0Sstevel@tonic-gate * Swap the bytes on the btree metadata page. 70*0Sstevel@tonic-gate * 71*0Sstevel@tonic-gate * PUBLIC: int __bam_mswap __P((PAGE *)); 72*0Sstevel@tonic-gate */ 73*0Sstevel@tonic-gate int 74*0Sstevel@tonic-gate __bam_mswap(pg) 75*0Sstevel@tonic-gate PAGE *pg; 76*0Sstevel@tonic-gate { 77*0Sstevel@tonic-gate u_int8_t *p; 78*0Sstevel@tonic-gate 79*0Sstevel@tonic-gate p = (u_int8_t *)pg; 80*0Sstevel@tonic-gate 81*0Sstevel@tonic-gate /* Swap the meta-data information. */ 82*0Sstevel@tonic-gate SWAP32(p); /* lsn.file */ 83*0Sstevel@tonic-gate SWAP32(p); /* lsn.offset */ 84*0Sstevel@tonic-gate SWAP32(p); /* pgno */ 85*0Sstevel@tonic-gate SWAP32(p); /* magic */ 86*0Sstevel@tonic-gate SWAP32(p); /* version */ 87*0Sstevel@tonic-gate SWAP32(p); /* pagesize */ 88*0Sstevel@tonic-gate SWAP32(p); /* maxkey */ 89*0Sstevel@tonic-gate SWAP32(p); /* minkey */ 90*0Sstevel@tonic-gate SWAP32(p); /* free */ 91*0Sstevel@tonic-gate SWAP32(p); /* flags */ 92*0Sstevel@tonic-gate 93*0Sstevel@tonic-gate return (0); 94*0Sstevel@tonic-gate } 95