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