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