/*- * Copyright (c) 1990 The Regents of the University of California. * All rights reserved. * * This code is derived from software contributed to Berkeley by * Mike Olson. * * %sccs.include.redist.c% */ #if defined(LIBC_SCCS) && !defined(lint) static char sccsid[] = "@(#)bt_conv.c 5.2 (Berkeley) 09/12/91"; #endif /* LIBC_SCCS and not lint */ #include #include #include #include "btree.h" static void kdswap __P((PAGE *)); /* * __BT_BPGIN, __BT_BPGOUT -- * Convert host-specific number layout to/from the host-independent * format stored on disk. * * Parameters: * t: tree * pg: page number * h: page to convert */ void __bt_pgin(t, pg, p) void *t; pgno_t pg; void *p; { PAGE *h; if (((BTREE *)t)->bt_lorder == BYTE_ORDER) return; h = p; BLSWAP(h->pgno); BLSWAP(h->prevpg); BLSWAP(h->nextpg); BLSWAP(h->flags); BSSWAP(h->lower); BSSWAP(h->upper); kdswap(h); } void __bt_pgout(t, pg, p) void *t; pgno_t pg; void *p; { PAGE *h; if (((BTREE *)t)->bt_lorder == BYTE_ORDER) return; h = p; kdswap(h); BLSWAP(h->pgno); BLSWAP(h->prevpg); BLSWAP(h->nextpg); BLSWAP(h->flags); BSSWAP(h->lower); BSSWAP(h->upper); } /* * KDSWAP -- Actually swap the bytes on the page. * * Parameters: * h: page to convert * * Warnings: * Everywhere else in the code, the pgno_t and index_t types are * opaque. These routines know what they really are. */ static void kdswap(h) PAGE *h; { register int i, top; register void *p; u_char flags; top = NEXTINDEX(h); switch (h->flags & P_TYPE) { case P_BINTERNAL: for (i = 0; i < top; i++) { BSSWAP(h->linp[i]); p = GETBINTERNAL(h, i); BLPSWAP(p); p += sizeof(size_t); BLPSWAP(p); p += sizeof(pgno_t); if (*(u_char *)p & P_BIGKEY) { p += sizeof(u_char); BLPSWAP(p); p += sizeof(pgno_t); BSPSWAP(p); } } break; case P_BLEAF: for (i = 0; i < top; i++) { BSSWAP(h->linp[i]); p = GETBLEAF(h, i); BSPSWAP(p); p += sizeof(size_t); BSPSWAP(p); p += sizeof(size_t); flags = *(u_char *)p; if (flags & (P_BIGKEY | P_BIGDATA)) { p += sizeof(u_char); if (flags & P_BIGKEY) { BLPSWAP(p); p += sizeof(pgno_t); BSPSWAP(p); } if (flags & P_BIGDATA) { p += sizeof(size_t); BLPSWAP(p); p += sizeof(pgno_t); BSPSWAP(p); } } } break; } }