1*54925bf6Swillf /*
2*54925bf6Swillf  * Copyright (c) 1997-2000 by Sun Microsystems, Inc.
3*54925bf6Swillf  * All rights reserved.
4*54925bf6Swillf  */
5*54925bf6Swillf 
6*54925bf6Swillf #ifndef _KRB5_BTREE_H
7*54925bf6Swillf #define	_KRB5_BTREE_H
8*54925bf6Swillf 
9*54925bf6Swillf #ifdef	__cplusplus
10*54925bf6Swillf extern "C" {
11*54925bf6Swillf #endif
12*54925bf6Swillf 
13*54925bf6Swillf 
14*54925bf6Swillf /*-
15*54925bf6Swillf  * Copyright (c) 1991, 1993, 1994
16*54925bf6Swillf  *	The Regents of the University of California.  All rights reserved.
17*54925bf6Swillf  *
18*54925bf6Swillf  * This code is derived from software contributed to Berkeley by
19*54925bf6Swillf  * Mike Olson.
20*54925bf6Swillf  *
21*54925bf6Swillf  * Redistribution and use in source and binary forms, with or without
22*54925bf6Swillf  * modification, are permitted provided that the following conditions
23*54925bf6Swillf  * are met:
24*54925bf6Swillf  * 1. Redistributions of source code must retain the above copyright
25*54925bf6Swillf  *    notice, this list of conditions and the following disclaimer.
26*54925bf6Swillf  * 2. Redistributions in binary form must reproduce the above copyright
27*54925bf6Swillf  *    notice, this list of conditions and the following disclaimer in the
28*54925bf6Swillf  *    documentation and/or other materials provided with the distribution.
29*54925bf6Swillf  * 3. All advertising materials mentioning features or use of this software
30*54925bf6Swillf  *    must display the following acknowledgement:
31*54925bf6Swillf  *	This product includes software developed by the University of
32*54925bf6Swillf  *	California, Berkeley and its contributors.
33*54925bf6Swillf  * 4. Neither the name of the University nor the names of its contributors
34*54925bf6Swillf  *    may be used to endorse or promote products derived from this software
35*54925bf6Swillf  *    without specific prior written permission.
36*54925bf6Swillf  *
37*54925bf6Swillf  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
38*54925bf6Swillf  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
39*54925bf6Swillf  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
40*54925bf6Swillf  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
41*54925bf6Swillf  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
42*54925bf6Swillf  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
43*54925bf6Swillf  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44*54925bf6Swillf  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
45*54925bf6Swillf  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
46*54925bf6Swillf  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47*54925bf6Swillf  * SUCH DAMAGE.
48*54925bf6Swillf  *
49*54925bf6Swillf  *	@(#)btree.h	8.11 (Berkeley) 8/17/94
50*54925bf6Swillf  */
51*54925bf6Swillf 
52*54925bf6Swillf /* Macros to set/clear/test flags. */
53*54925bf6Swillf #define	F_SET(p, f)	(p)->flags |= (f)
54*54925bf6Swillf #define	F_CLR(p, f)	(p)->flags &= ~(f)
55*54925bf6Swillf #define	F_ISSET(p, f)	((p)->flags & (f))
56*54925bf6Swillf 
57*54925bf6Swillf #include "mpool.h"
58*54925bf6Swillf 
59*54925bf6Swillf #define	DEFMINKEYPAGE	(2)		/* Minimum keys per page */
60*54925bf6Swillf #define	MINCACHE	(5)		/* Minimum cached pages */
61*54925bf6Swillf #define	MINPSIZE	(512)		/* Minimum page size */
62*54925bf6Swillf 
63*54925bf6Swillf /*
64*54925bf6Swillf  * Page 0 of a btree file contains a copy of the meta-data.  This page is also
65*54925bf6Swillf  * used as an out-of-band page, i.e. page pointers that point to nowhere point
66*54925bf6Swillf  * to page 0.  Page 1 is the root of the btree.
67*54925bf6Swillf  */
68*54925bf6Swillf #define	P_INVALID	 0		/* Invalid tree page number. */
69*54925bf6Swillf #define	P_META		 0		/* Tree metadata page number. */
70*54925bf6Swillf #define	P_ROOT		 1		/* Tree root page number. */
71*54925bf6Swillf 
72*54925bf6Swillf /*
73*54925bf6Swillf  * There are five page layouts in the btree: btree internal pages (BINTERNAL),
74*54925bf6Swillf  * btree leaf pages (BLEAF), recno internal pages (RINTERNAL), recno leaf pages
75*54925bf6Swillf  * (RLEAF) and overflow pages.  All five page types have a page header (PAGE).
76*54925bf6Swillf  * This implementation requires that values within structures NOT be padded.
77*54925bf6Swillf  * (ANSI C permits random padding.)  If your compiler pads randomly you'll have
78*54925bf6Swillf  * to do some work to get this package to run.
79*54925bf6Swillf  */
80*54925bf6Swillf typedef struct _page {
81*54925bf6Swillf 	db_pgno_t	pgno;			/* this page's page number */
82*54925bf6Swillf 	db_pgno_t	prevpg;			/* left sibling */
83*54925bf6Swillf 	db_pgno_t	nextpg;			/* right sibling */
84*54925bf6Swillf 
85*54925bf6Swillf #define	P_BINTERNAL	0x01		/* btree internal page */
86*54925bf6Swillf #define	P_BLEAF		0x02		/* leaf page */
87*54925bf6Swillf #define	P_OVERFLOW	0x04		/* overflow page */
88*54925bf6Swillf #define	P_RINTERNAL	0x08		/* recno internal page */
89*54925bf6Swillf #define	P_RLEAF		0x10		/* leaf page */
90*54925bf6Swillf #define P_TYPE		0x1f		/* type mask */
91*54925bf6Swillf #define	P_PRESERVE	0x20		/* never delete this chain of pages */
92*54925bf6Swillf 	u_int32_t flags;
93*54925bf6Swillf 
94*54925bf6Swillf 	indx_t	lower;			/* lower bound of free space on page */
95*54925bf6Swillf 	indx_t	upper;			/* upper bound of free space on page */
96*54925bf6Swillf 	indx_t	linp[1];		/* indx_t-aligned VAR. LENGTH DATA */
97*54925bf6Swillf } PAGE;
98*54925bf6Swillf 
99*54925bf6Swillf /* First and next index. */
100*54925bf6Swillf #define	BTDATAOFF							\
101*54925bf6Swillf 	(sizeof(db_pgno_t) + sizeof(db_pgno_t) + sizeof(db_pgno_t) +		\
102*54925bf6Swillf 	    sizeof(u_int32_t) + sizeof(indx_t) + sizeof(indx_t))
103*54925bf6Swillf #define	NEXTINDEX(p)	(((p)->lower - BTDATAOFF) / sizeof(indx_t))
104*54925bf6Swillf 
105*54925bf6Swillf /*
106*54925bf6Swillf  * For pages other than overflow pages, there is an array of offsets into the
107*54925bf6Swillf  * rest of the page immediately following the page header.  Each offset is to
108*54925bf6Swillf  * an item which is unique to the type of page.  The h_lower offset is just
109*54925bf6Swillf  * past the last filled-in index.  The h_upper offset is the first item on the
110*54925bf6Swillf  * page.  Offsets are from the beginning of the page.
111*54925bf6Swillf  *
112*54925bf6Swillf  * If an item is too big to store on a single page, a flag is set and the item
113*54925bf6Swillf  * is a { page, size } pair such that the page is the first page of an overflow
114*54925bf6Swillf  * chain with size bytes of item.  Overflow pages are simply bytes without any
115*54925bf6Swillf  * external structure.
116*54925bf6Swillf  *
117*54925bf6Swillf  * The page number and size fields in the items are db_pgno_t-aligned so they can
118*54925bf6Swillf  * be manipulated without copying.  (This presumes that 32 bit items can be
119*54925bf6Swillf  * manipulated on this system.)
120*54925bf6Swillf  */
121*54925bf6Swillf #define	LALIGN(n)	(((n) + sizeof(db_pgno_t) - 1) & ~(sizeof(db_pgno_t) - 1))
122*54925bf6Swillf #define	NOVFLSIZE	(sizeof(db_pgno_t) + sizeof(u_int32_t))
123*54925bf6Swillf 
124*54925bf6Swillf /*
125*54925bf6Swillf  * For the btree internal pages, the item is a key.  BINTERNALs are {key, pgno}
126*54925bf6Swillf  * pairs, such that the key compares less than or equal to all of the records
127*54925bf6Swillf  * on that page.  For a tree without duplicate keys, an internal page with two
128*54925bf6Swillf  * consecutive keys, a and b, will have all records greater than or equal to a
129*54925bf6Swillf  * and less than b stored on the page associated with a.  Duplicate keys are
130*54925bf6Swillf  * somewhat special and can cause duplicate internal and leaf page records and
131*54925bf6Swillf  * some minor modifications of the above rule.
132*54925bf6Swillf  */
133*54925bf6Swillf typedef struct _binternal {
134*54925bf6Swillf 	u_int32_t ksize;		/* key size */
135*54925bf6Swillf 	db_pgno_t	pgno;			/* page number stored on */
136*54925bf6Swillf #define	P_BIGDATA	0x01		/* overflow data */
137*54925bf6Swillf #define	P_BIGKEY	0x02		/* overflow key */
138*54925bf6Swillf 	u_char	flags;
139*54925bf6Swillf 	char	bytes[1];		/* data */
140*54925bf6Swillf } BINTERNAL;
141*54925bf6Swillf 
142*54925bf6Swillf /* Get the page's BINTERNAL structure at index indx. */
143*54925bf6Swillf #define	GETBINTERNAL(pg, indx)						\
144*54925bf6Swillf 	((BINTERNAL *)((char *)(pg) + (pg)->linp[indx]))
145*54925bf6Swillf 
146*54925bf6Swillf /* Get the number of bytes in the entry. */
147*54925bf6Swillf #define NBINTERNAL(len)							\
148*54925bf6Swillf 	LALIGN(sizeof(u_int32_t) + sizeof(db_pgno_t) + sizeof(u_char) + (len))
149*54925bf6Swillf 
150*54925bf6Swillf /* Copy a BINTERNAL entry to the page. */
151*54925bf6Swillf #define	WR_BINTERNAL(p, size, pgno, flags) {				\
152*54925bf6Swillf 	*(u_int32_t *)p = size;						\
153*54925bf6Swillf 	p += sizeof(u_int32_t);						\
154*54925bf6Swillf 	*(db_pgno_t *)p = pgno;						\
155*54925bf6Swillf 	p += sizeof(db_pgno_t);						\
156*54925bf6Swillf 	*(u_char *)p = flags;						\
157*54925bf6Swillf 	p += sizeof(u_char);						\
158*54925bf6Swillf }
159*54925bf6Swillf 
160*54925bf6Swillf /*
161*54925bf6Swillf  * For the recno internal pages, the item is a page number with the number of
162*54925bf6Swillf  * keys found on that page and below.
163*54925bf6Swillf  */
164*54925bf6Swillf typedef struct _rinternal {
165*54925bf6Swillf 	recno_t	nrecs;			/* number of records */
166*54925bf6Swillf 	db_pgno_t	pgno;			/* page number stored below */
167*54925bf6Swillf } RINTERNAL;
168*54925bf6Swillf 
169*54925bf6Swillf /* Get the page's RINTERNAL structure at index indx. */
170*54925bf6Swillf #define	GETRINTERNAL(pg, indx)						\
171*54925bf6Swillf 	((RINTERNAL *)((char *)(pg) + (pg)->linp[indx]))
172*54925bf6Swillf 
173*54925bf6Swillf /* Get the number of bytes in the entry. */
174*54925bf6Swillf #define NRINTERNAL							\
175*54925bf6Swillf 	LALIGN(sizeof(recno_t) + sizeof(db_pgno_t))
176*54925bf6Swillf 
177*54925bf6Swillf /* Copy a RINTERAL entry to the page. */
178*54925bf6Swillf #define	WR_RINTERNAL(p, nrecs, pgno) {					\
179*54925bf6Swillf 	*(recno_t *)p = nrecs;						\
180*54925bf6Swillf 	p += sizeof(recno_t);						\
181*54925bf6Swillf 	*(db_pgno_t *)p = pgno;						\
182*54925bf6Swillf }
183*54925bf6Swillf 
184*54925bf6Swillf /* For the btree leaf pages, the item is a key and data pair. */
185*54925bf6Swillf typedef struct _bleaf {
186*54925bf6Swillf 	u_int32_t	ksize;		/* size of key */
187*54925bf6Swillf 	u_int32_t	dsize;		/* size of data */
188*54925bf6Swillf 	u_char	flags;			/* P_BIGDATA, P_BIGKEY */
189*54925bf6Swillf 	char	bytes[1];		/* data */
190*54925bf6Swillf } BLEAF;
191*54925bf6Swillf 
192*54925bf6Swillf /* Get the page's BLEAF structure at index indx. */
193*54925bf6Swillf #define	GETBLEAF(pg, indx)						\
194*54925bf6Swillf 	((BLEAF *)((char *)(pg) + (pg)->linp[indx]))
195*54925bf6Swillf 
196*54925bf6Swillf /* Get the number of bytes in the entry. */
197*54925bf6Swillf #define NBLEAF(p)	NBLEAFDBT((p)->ksize, (p)->dsize)
198*54925bf6Swillf 
199*54925bf6Swillf /* Get the number of bytes in the user's key/data pair. */
200*54925bf6Swillf #define NBLEAFDBT(ksize, dsize)						\
201*54925bf6Swillf 	LALIGN(sizeof(u_int32_t) + sizeof(u_int32_t) + sizeof(u_char) +	\
202*54925bf6Swillf 	    (ksize) + (dsize))
203*54925bf6Swillf 
204*54925bf6Swillf /* Copy a BLEAF entry to the page. */
205*54925bf6Swillf #define	WR_BLEAF(p, key, data, flags) {					\
206*54925bf6Swillf 	*(u_int32_t *)p = key->size;					\
207*54925bf6Swillf 	p += sizeof(u_int32_t);						\
208*54925bf6Swillf 	*(u_int32_t *)p = data->size;					\
209*54925bf6Swillf 	p += sizeof(u_int32_t);						\
210*54925bf6Swillf 	*(u_char *)p = flags;						\
211*54925bf6Swillf 	p += sizeof(u_char);						\
212*54925bf6Swillf 	memmove(p, key->data, key->size);				\
213*54925bf6Swillf 	p += key->size;							\
214*54925bf6Swillf 	memmove(p, data->data, data->size);				\
215*54925bf6Swillf }
216*54925bf6Swillf 
217*54925bf6Swillf /* For the recno leaf pages, the item is a data entry. */
218*54925bf6Swillf typedef struct _rleaf {
219*54925bf6Swillf 	u_int32_t	dsize;		/* size of data */
220*54925bf6Swillf 	u_char	flags;			/* P_BIGDATA */
221*54925bf6Swillf 	char	bytes[1];
222*54925bf6Swillf } RLEAF;
223*54925bf6Swillf 
224*54925bf6Swillf /* Get the page's RLEAF structure at index indx. */
225*54925bf6Swillf #define	GETRLEAF(pg, indx)						\
226*54925bf6Swillf 	((RLEAF *)((char *)(pg) + (pg)->linp[indx]))
227*54925bf6Swillf 
228*54925bf6Swillf /* Get the number of bytes in the entry. */
229*54925bf6Swillf #define NRLEAF(p)	NRLEAFDBT((p)->dsize)
230*54925bf6Swillf 
231*54925bf6Swillf /* Get the number of bytes from the user's data. */
232*54925bf6Swillf #define	NRLEAFDBT(dsize)						\
233*54925bf6Swillf 	LALIGN(sizeof(u_int32_t) + sizeof(u_char) + (dsize))
234*54925bf6Swillf 
235*54925bf6Swillf /* Copy a RLEAF entry to the page. */
236*54925bf6Swillf #define	WR_RLEAF(p, data, flags) {					\
237*54925bf6Swillf 	*(u_int32_t *)p = data->size;					\
238*54925bf6Swillf 	p += sizeof(u_int32_t);						\
239*54925bf6Swillf 	*(u_char *)p = flags;						\
240*54925bf6Swillf 	p += sizeof(u_char);						\
241*54925bf6Swillf 	memmove(p, data->data, data->size);				\
242*54925bf6Swillf }
243*54925bf6Swillf 
244*54925bf6Swillf /*
245*54925bf6Swillf  * A record in the tree is either a pointer to a page and an index in the page
246*54925bf6Swillf  * or a page number and an index.  These structures are used as a cursor, stack
247*54925bf6Swillf  * entry and search returns as well as to pass records to other routines.
248*54925bf6Swillf  *
249*54925bf6Swillf  * One comment about searches.  Internal page searches must find the largest
250*54925bf6Swillf  * record less than key in the tree so that descents work.  Leaf page searches
251*54925bf6Swillf  * must find the smallest record greater than key so that the returned index
252*54925bf6Swillf  * is the record's correct position for insertion.
253*54925bf6Swillf  */
254*54925bf6Swillf typedef struct _epgno {
255*54925bf6Swillf 	db_pgno_t	pgno;			/* the page number */
256*54925bf6Swillf 	indx_t	index;			/* the index on the page */
257*54925bf6Swillf } EPGNO;
258*54925bf6Swillf 
259*54925bf6Swillf typedef struct _epg {
260*54925bf6Swillf 	PAGE	*page;			/* the (pinned) page */
261*54925bf6Swillf 	indx_t	 index;			/* the index on the page */
262*54925bf6Swillf } EPG;
263*54925bf6Swillf 
264*54925bf6Swillf /*
265*54925bf6Swillf  * About cursors.  The cursor (and the page that contained the key/data pair
266*54925bf6Swillf  * that it referenced) can be deleted, which makes things a bit tricky.  If
267*54925bf6Swillf  * there are no duplicates of the cursor key in the tree (i.e. B_NODUPS is set
268*54925bf6Swillf  * or there simply aren't any duplicates of the key) we copy the key that it
269*54925bf6Swillf  * referenced when it's deleted, and reacquire a new cursor key if the cursor
270*54925bf6Swillf  * is used again.  If there are duplicates keys, we move to the next/previous
271*54925bf6Swillf  * key, and set a flag so that we know what happened.  NOTE: if duplicate (to
272*54925bf6Swillf  * the cursor) keys are added to the tree during this process, it is undefined
273*54925bf6Swillf  * if they will be returned or not in a cursor scan.
274*54925bf6Swillf  *
275*54925bf6Swillf  * The flags determine the possible states of the cursor:
276*54925bf6Swillf  *
277*54925bf6Swillf  * CURS_INIT	The cursor references *something*.
278*54925bf6Swillf  * CURS_ACQUIRE	The cursor was deleted, and a key has been saved so that
279*54925bf6Swillf  *		we can reacquire the right position in the tree.
280*54925bf6Swillf  * CURS_AFTER, CURS_BEFORE
281*54925bf6Swillf  *		The cursor was deleted, and now references a key/data pair
282*54925bf6Swillf  *		that has not yet been returned, either before or after the
283*54925bf6Swillf  *		deleted key/data pair.
284*54925bf6Swillf  * XXX
285*54925bf6Swillf  * This structure is broken out so that we can eventually offer multiple
286*54925bf6Swillf  * cursors as part of the DB interface.
287*54925bf6Swillf  */
288*54925bf6Swillf typedef struct _cursor {
289*54925bf6Swillf 	EPGNO	 pg;			/* B: Saved tree reference. */
290*54925bf6Swillf 	DBT	 key;			/* B: Saved key, or key.data == NULL. */
291*54925bf6Swillf 	recno_t	 rcursor;		/* R: recno cursor (1-based) */
292*54925bf6Swillf 
293*54925bf6Swillf #define	CURS_ACQUIRE	0x01		/*  B: Cursor needs to be reacquired. */
294*54925bf6Swillf #define	CURS_AFTER	0x02		/*  B: Unreturned cursor after key. */
295*54925bf6Swillf #define	CURS_BEFORE	0x04		/*  B: Unreturned cursor before key. */
296*54925bf6Swillf #define	CURS_INIT	0x08		/* RB: Cursor initialized. */
297*54925bf6Swillf 	u_int8_t flags;
298*54925bf6Swillf } CURSOR;
299*54925bf6Swillf 
300*54925bf6Swillf /*
301*54925bf6Swillf  * The metadata of the tree.  The nrecs field is used only by the RECNO code.
302*54925bf6Swillf  * This is because the btree doesn't really need it and it requires that every
303*54925bf6Swillf  * put or delete call modify the metadata.
304*54925bf6Swillf  */
305*54925bf6Swillf typedef struct _btmeta {
306*54925bf6Swillf 	u_int32_t	magic;		/* magic number */
307*54925bf6Swillf 	u_int32_t	version;	/* version */
308*54925bf6Swillf 	u_int32_t	psize;		/* page size */
309*54925bf6Swillf 	u_int32_t	free;		/* page number of first free page */
310*54925bf6Swillf 	u_int32_t	nrecs;		/* R: number of records */
311*54925bf6Swillf 
312*54925bf6Swillf #define	SAVEMETA	(B_NODUPS | R_RECNO)
313*54925bf6Swillf 	u_int32_t	flags;		/* bt_flags & SAVEMETA */
314*54925bf6Swillf } BTMETA;
315*54925bf6Swillf 
316*54925bf6Swillf /* The in-memory btree/recno data structure. */
317*54925bf6Swillf typedef struct _btree {
318*54925bf6Swillf 	MPOOL	 *bt_mp;		/* memory pool cookie */
319*54925bf6Swillf 
320*54925bf6Swillf 	DB	 *bt_dbp;		/* pointer to enclosing DB */
321*54925bf6Swillf 
322*54925bf6Swillf 	EPG	  bt_cur;		/* current (pinned) page */
323*54925bf6Swillf 	PAGE	 *bt_pinned;		/* page pinned across calls */
324*54925bf6Swillf 
325*54925bf6Swillf 	CURSOR	  bt_cursor;		/* cursor */
326*54925bf6Swillf 
327*54925bf6Swillf #define	BT_PUSH(t, p, i) {						\
328*54925bf6Swillf 	t->bt_sp->pgno = p; 						\
329*54925bf6Swillf 	t->bt_sp->index = i; 						\
330*54925bf6Swillf 	++t->bt_sp;							\
331*54925bf6Swillf }
332*54925bf6Swillf #define	BT_POP(t)	(t->bt_sp == t->bt_stack ? NULL : --t->bt_sp)
333*54925bf6Swillf #define	BT_CLR(t)	(t->bt_sp = t->bt_stack)
334*54925bf6Swillf 	EPGNO	  bt_stack[50];		/* stack of parent pages */
335*54925bf6Swillf 	EPGNO	 *bt_sp;		/* current stack pointer */
336*54925bf6Swillf 
337*54925bf6Swillf 	DBT	  bt_rkey;		/* returned key */
338*54925bf6Swillf 	DBT	  bt_rdata;		/* returned data */
339*54925bf6Swillf 
340*54925bf6Swillf 	int	  bt_fd;		/* tree file descriptor */
341*54925bf6Swillf 
342*54925bf6Swillf 	db_pgno_t	  bt_free;		/* next free page */
343*54925bf6Swillf 	u_int32_t bt_psize;		/* page size */
344*54925bf6Swillf 	indx_t	  bt_ovflsize;		/* cut-off for key/data overflow */
345*54925bf6Swillf 	int	  bt_lorder;		/* byte order */
346*54925bf6Swillf 					/* sorted order */
347*54925bf6Swillf 	enum { NOT, BACK, FORWARD } bt_order;
348*54925bf6Swillf 	EPGNO	  bt_last;		/* last insert */
349*54925bf6Swillf 
350*54925bf6Swillf 					/* B: key comparison function */
351*54925bf6Swillf 	int	(*bt_cmp) __P((const DBT *, const DBT *));
352*54925bf6Swillf 					/* B: prefix comparison function */
353*54925bf6Swillf 	size_t	(*bt_pfx) __P((const DBT *, const DBT *));
354*54925bf6Swillf 					/* R: recno input function */
355*54925bf6Swillf 	int	(*bt_irec) __P((struct _btree *, recno_t));
356*54925bf6Swillf 
357*54925bf6Swillf 	FILE	 *bt_rfp;		/* R: record FILE pointer */
358*54925bf6Swillf 	int	  bt_rfd;		/* R: record file descriptor */
359*54925bf6Swillf 
360*54925bf6Swillf 	caddr_t	  bt_cmap;		/* R: current point in mapped space */
361*54925bf6Swillf 	caddr_t	  bt_smap;		/* R: start of mapped space */
362*54925bf6Swillf 	caddr_t   bt_emap;		/* R: end of mapped space */
363*54925bf6Swillf 	size_t	  bt_msize;		/* R: size of mapped region. */
364*54925bf6Swillf 
365*54925bf6Swillf 	recno_t	  bt_nrecs;		/* R: number of records */
366*54925bf6Swillf 	size_t	  bt_reclen;		/* R: fixed record length */
367*54925bf6Swillf 	u_char	  bt_bval;		/* R: delimiting byte/pad character */
368*54925bf6Swillf 
369*54925bf6Swillf /*
370*54925bf6Swillf  * NB:
371*54925bf6Swillf  * B_NODUPS and R_RECNO are stored on disk, and may not be changed.
372*54925bf6Swillf  */
373*54925bf6Swillf #define	B_INMEM		0x00001		/* in-memory tree */
374*54925bf6Swillf #define	B_METADIRTY	0x00002		/* need to write metadata */
375*54925bf6Swillf #define	B_MODIFIED	0x00004		/* tree modified */
376*54925bf6Swillf #define	B_NEEDSWAP	0x00008		/* if byte order requires swapping */
377*54925bf6Swillf #define	B_RDONLY	0x00010		/* read-only tree */
378*54925bf6Swillf 
379*54925bf6Swillf #define	B_NODUPS	0x00020		/* no duplicate keys permitted */
380*54925bf6Swillf #define	R_RECNO		0x00080		/* record oriented tree */
381*54925bf6Swillf 
382*54925bf6Swillf #define	R_CLOSEFP	0x00040		/* opened a file pointer */
383*54925bf6Swillf #define	R_EOF		0x00100		/* end of input file reached. */
384*54925bf6Swillf #define	R_FIXLEN	0x00200		/* fixed length records */
385*54925bf6Swillf #define	R_MEMMAPPED	0x00400		/* memory mapped file. */
386*54925bf6Swillf #define	R_INMEM		0x00800		/* in-memory file */
387*54925bf6Swillf #define	R_MODIFIED	0x01000		/* modified file */
388*54925bf6Swillf #define	R_RDONLY	0x02000		/* read-only file */
389*54925bf6Swillf 
390*54925bf6Swillf #define	B_DB_LOCK	0x04000		/* DB_LOCK specified. */
391*54925bf6Swillf #define	B_DB_SHMEM	0x08000		/* DB_SHMEM specified. */
392*54925bf6Swillf #define	B_DB_TXN	0x10000		/* DB_TXN specified. */
393*54925bf6Swillf 	u_int32_t flags;
394*54925bf6Swillf } BTREE;
395*54925bf6Swillf 
396*54925bf6Swillf #include "extern.h"
397*54925bf6Swillf 
398*54925bf6Swillf #ifdef	__cplusplus
399*54925bf6Swillf }
400*54925bf6Swillf #endif
401*54925bf6Swillf 
402*54925bf6Swillf #endif	/* !_KRB5_BTREE_H */
403