1*2639ae9bSBen Gras /* $NetBSD: page.h,v 1.8 2008/08/26 21:18:38 joerg Exp $ */ 2*2639ae9bSBen Gras 3*2639ae9bSBen Gras /*- 4*2639ae9bSBen Gras * Copyright (c) 1990, 1993, 1994 5*2639ae9bSBen Gras * The Regents of the University of California. All rights reserved. 6*2639ae9bSBen Gras * 7*2639ae9bSBen Gras * This code is derived from software contributed to Berkeley by 8*2639ae9bSBen Gras * Margo Seltzer. 9*2639ae9bSBen Gras * 10*2639ae9bSBen Gras * Redistribution and use in source and binary forms, with or without 11*2639ae9bSBen Gras * modification, are permitted provided that the following conditions 12*2639ae9bSBen Gras * are met: 13*2639ae9bSBen Gras * 1. Redistributions of source code must retain the above copyright 14*2639ae9bSBen Gras * notice, this list of conditions and the following disclaimer. 15*2639ae9bSBen Gras * 2. Redistributions in binary form must reproduce the above copyright 16*2639ae9bSBen Gras * notice, this list of conditions and the following disclaimer in the 17*2639ae9bSBen Gras * documentation and/or other materials provided with the distribution. 18*2639ae9bSBen Gras * 3. Neither the name of the University nor the names of its contributors 19*2639ae9bSBen Gras * may be used to endorse or promote products derived from this software 20*2639ae9bSBen Gras * without specific prior written permission. 21*2639ae9bSBen Gras * 22*2639ae9bSBen Gras * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23*2639ae9bSBen Gras * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24*2639ae9bSBen Gras * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25*2639ae9bSBen Gras * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26*2639ae9bSBen Gras * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27*2639ae9bSBen Gras * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28*2639ae9bSBen Gras * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29*2639ae9bSBen Gras * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30*2639ae9bSBen Gras * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31*2639ae9bSBen Gras * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32*2639ae9bSBen Gras * SUCH DAMAGE. 33*2639ae9bSBen Gras * 34*2639ae9bSBen Gras * @(#)page.h 8.2 (Berkeley) 5/31/94 35*2639ae9bSBen Gras */ 36*2639ae9bSBen Gras 37*2639ae9bSBen Gras /* 38*2639ae9bSBen Gras * Definitions for hashing page file format. 39*2639ae9bSBen Gras */ 40*2639ae9bSBen Gras 41*2639ae9bSBen Gras /* 42*2639ae9bSBen Gras * routines dealing with a data page 43*2639ae9bSBen Gras * 44*2639ae9bSBen Gras * page format: 45*2639ae9bSBen Gras * +------------------------------+ 46*2639ae9bSBen Gras * p | n | keyoff | datoff | keyoff | 47*2639ae9bSBen Gras * +------------+--------+--------+ 48*2639ae9bSBen Gras * | datoff | free | ptr | --> | 49*2639ae9bSBen Gras * +--------+---------------------+ 50*2639ae9bSBen Gras * | F R E E A R E A | 51*2639ae9bSBen Gras * +--------------+---------------+ 52*2639ae9bSBen Gras * | <---- - - - | data | 53*2639ae9bSBen Gras * +--------+-----+----+----------+ 54*2639ae9bSBen Gras * | key | data | key | 55*2639ae9bSBen Gras * +--------+----------+----------+ 56*2639ae9bSBen Gras * 57*2639ae9bSBen Gras * Pointer to the free space is always: p[p[0] + 2] 58*2639ae9bSBen Gras * Amount of free space on the page is: p[p[0] + 1] 59*2639ae9bSBen Gras */ 60*2639ae9bSBen Gras 61*2639ae9bSBen Gras /* 62*2639ae9bSBen Gras * How many bytes required for this pair? 63*2639ae9bSBen Gras * 2 shorts in the table at the top of the page + room for the 64*2639ae9bSBen Gras * key and room for the data 65*2639ae9bSBen Gras * 66*2639ae9bSBen Gras * We prohibit entering a pair on a page unless there is also room to append 67*2639ae9bSBen Gras * an overflow page. The reason for this it that you can get in a situation 68*2639ae9bSBen Gras * where a single key/data pair fits on a page, but you can't append an 69*2639ae9bSBen Gras * overflow page and later you'd have to split the key/data and handle like 70*2639ae9bSBen Gras * a big pair. 71*2639ae9bSBen Gras * You might as well do this up front. 72*2639ae9bSBen Gras */ 73*2639ae9bSBen Gras 74*2639ae9bSBen Gras #define PAIRSIZE(K,D) (2*sizeof(uint16_t) + (K)->size + (D)->size) 75*2639ae9bSBen Gras #define BIGOVERHEAD (4*sizeof(uint16_t)) 76*2639ae9bSBen Gras #define KEYSIZE(K) (4*sizeof(uint16_t) + (K)->size); 77*2639ae9bSBen Gras #define OVFLSIZE (2*sizeof(uint16_t)) 78*2639ae9bSBen Gras #define FREESPACE(P) ((P)[(P)[0]+1]) 79*2639ae9bSBen Gras #define OFFSET(P) ((P)[(P)[0]+2]) 80*2639ae9bSBen Gras #define PAIRFITS(P,K,D) \ 81*2639ae9bSBen Gras (((P)[2] >= REAL_KEY) && \ 82*2639ae9bSBen Gras (PAIRSIZE((K),(D)) + OVFLSIZE) <= FREESPACE((P))) 83*2639ae9bSBen Gras #define PAGE_META(N) (((N)+3) * sizeof(uint16_t)) 84*2639ae9bSBen Gras 85*2639ae9bSBen Gras typedef struct { 86*2639ae9bSBen Gras BUFHEAD *newp; 87*2639ae9bSBen Gras BUFHEAD *oldp; 88*2639ae9bSBen Gras BUFHEAD *nextp; 89*2639ae9bSBen Gras uint16_t next_addr; 90*2639ae9bSBen Gras } SPLIT_RETURN; 91