/*-1* SPDX-License-Identifier: BSD-3-Clause2*3* Copyright (c) 1990, 1993, 19944* The Regents of the University of California. All rights reserved.5*6* This code is derived from software contributed to Berkeley by7* Margo Seltzer.8*9* Redistribution and use in source and binary forms, with or without10* modification, are permitted provided that the following conditions11* are met:12* 1. Redistributions of source code must retain the above copyright13* notice, this list of conditions and the following disclaimer.14* 2. Redistributions in binary form must reproduce the above copyright15* notice, this list of conditions and the following disclaimer in the16* documentation and/or other materials provided with the distribution.17* 3. Neither the name of the University nor the names of its contributors18* may be used to endorse or promote products derived from this software19* without specific prior written permission.20*21* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND22* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE23* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE24* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE25* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL26* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS27* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)28* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT29* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY30* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF31* SUCH DAMAGE.32*/3334/*35* Definitions for hashing page file format.36*/3738/*39* routines dealing with a data page40*41* page format:42* +------------------------------+43* p | n | keyoff | datoff | keyoff |44* +------------+--------+--------+45* | datoff | free | ptr | --> |46* +--------+---------------------+47* | F R E E A R E A |48* +--------------+---------------+49* | <---- - - - | data |50* +--------+-----+----+----------+51* | key | data | key |52* +--------+----------+----------+53*54* Pointer to the free space is always: p[p[0] + 2]55* Amount of free space on the page is: p[p[0] + 1]56*/5758/*59* How many bytes required for this pair?60* 2 shorts in the table at the top of the page + room for the61* key and room for the data62*63* We prohibit entering a pair on a page unless there is also room to append64* an overflow page. The reason for this it that you can get in a situation65* where a single key/data pair fits on a page, but you can't append an66* overflow page and later you'd have to split the key/data and handle like67* a big pair.68* You might as well do this up front.69*/7071#define PAIRSIZE(K,D) (2*sizeof(u_int16_t) + (K)->size + (D)->size)72#define BIGOVERHEAD (4*sizeof(u_int16_t))73#define KEYSIZE(K) (4*sizeof(u_int16_t) + (K)->size);74#define OVFLSIZE (2*sizeof(u_int16_t))75#define FREESPACE(P) ((P)[(P)[0]+1])76#define OFFSET(P) ((P)[(P)[0]+2])77#define PAIRFITS(P,K,D) \78(((P)[2] >= REAL_KEY) && \79(PAIRSIZE((K),(D)) + OVFLSIZE) <= FREESPACE((P)))80#define PAGE_META(N) (((N)+3) * sizeof(u_int16_t))8182typedef struct {83BUFHEAD *newp;84BUFHEAD *oldp;85BUFHEAD *nextp;86u_int16_t next_addr;87} SPLIT_RETURN;888990