1*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
2*7c478bd9Sstevel@tonic-gate /*-
3*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1990, 1993, 1994
4*7c478bd9Sstevel@tonic-gate  *	The Regents of the University of California.  All rights reserved.
5*7c478bd9Sstevel@tonic-gate  *
6*7c478bd9Sstevel@tonic-gate  * Redistribution and use in source and binary forms, with or without
7*7c478bd9Sstevel@tonic-gate  * modification, are permitted provided that the following conditions
8*7c478bd9Sstevel@tonic-gate  * are met:
9*7c478bd9Sstevel@tonic-gate  * 1. Redistributions of source code must retain the above copyright
10*7c478bd9Sstevel@tonic-gate  *    notice, this list of conditions and the following disclaimer.
11*7c478bd9Sstevel@tonic-gate  * 2. Redistributions in binary form must reproduce the above copyright
12*7c478bd9Sstevel@tonic-gate  *    notice, this list of conditions and the following disclaimer in the
13*7c478bd9Sstevel@tonic-gate  *    documentation and/or other materials provided with the distribution.
14*7c478bd9Sstevel@tonic-gate  * 3. All advertising materials mentioning features or use of this software
15*7c478bd9Sstevel@tonic-gate  *    must display the following acknowledgement:
16*7c478bd9Sstevel@tonic-gate  *	This product includes software developed by the University of
17*7c478bd9Sstevel@tonic-gate  *	California, Berkeley and its contributors.
18*7c478bd9Sstevel@tonic-gate  * 4. Neither the name of the University nor the names of its contributors
19*7c478bd9Sstevel@tonic-gate  *    may be used to endorse or promote products derived from this software
20*7c478bd9Sstevel@tonic-gate  *    without specific prior written permission.
21*7c478bd9Sstevel@tonic-gate  *
22*7c478bd9Sstevel@tonic-gate  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23*7c478bd9Sstevel@tonic-gate  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24*7c478bd9Sstevel@tonic-gate  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25*7c478bd9Sstevel@tonic-gate  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26*7c478bd9Sstevel@tonic-gate  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27*7c478bd9Sstevel@tonic-gate  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28*7c478bd9Sstevel@tonic-gate  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29*7c478bd9Sstevel@tonic-gate  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30*7c478bd9Sstevel@tonic-gate  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31*7c478bd9Sstevel@tonic-gate  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32*7c478bd9Sstevel@tonic-gate  * SUCH DAMAGE.
33*7c478bd9Sstevel@tonic-gate  *
34*7c478bd9Sstevel@tonic-gate  *	@(#)db.h	8.8 (Berkeley) 11/2/95
35*7c478bd9Sstevel@tonic-gate  */
36*7c478bd9Sstevel@tonic-gate 
37*7c478bd9Sstevel@tonic-gate #ifndef _DB_H_
38*7c478bd9Sstevel@tonic-gate #define	_DB_H_
39*7c478bd9Sstevel@tonic-gate 
40*7c478bd9Sstevel@tonic-gate #include <db-config.h>
41*7c478bd9Sstevel@tonic-gate 
42*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
43*7c478bd9Sstevel@tonic-gate 
44*7c478bd9Sstevel@tonic-gate #define	RET_ERROR	-1		/* Return values. */
45*7c478bd9Sstevel@tonic-gate #define	RET_SUCCESS	 0
46*7c478bd9Sstevel@tonic-gate #define	RET_SPECIAL	 1
47*7c478bd9Sstevel@tonic-gate 
48*7c478bd9Sstevel@tonic-gate /* Key/data structure -- a Data-Base Thang. */
49*7c478bd9Sstevel@tonic-gate typedef struct {
50*7c478bd9Sstevel@tonic-gate 	void	*data;			/* data */
51*7c478bd9Sstevel@tonic-gate 	size_t	 size;			/* data length */
52*7c478bd9Sstevel@tonic-gate } DBT;
53*7c478bd9Sstevel@tonic-gate 
54*7c478bd9Sstevel@tonic-gate /* Routine flags. */
55*7c478bd9Sstevel@tonic-gate #define	R_CURSOR	1		/* del, put, seq */
56*7c478bd9Sstevel@tonic-gate #define	__R_UNUSED	2		/* UNUSED */
57*7c478bd9Sstevel@tonic-gate #define	R_FIRST		3		/* seq */
58*7c478bd9Sstevel@tonic-gate #define	R_IAFTER	4		/* put (RECNO) */
59*7c478bd9Sstevel@tonic-gate #define	R_IBEFORE	5		/* put (RECNO) */
60*7c478bd9Sstevel@tonic-gate #define	R_LAST		6		/* seq (BTREE, RECNO) */
61*7c478bd9Sstevel@tonic-gate #define	R_NEXT		7		/* seq */
62*7c478bd9Sstevel@tonic-gate #define	R_NOOVERWRITE	8		/* put */
63*7c478bd9Sstevel@tonic-gate #define	R_PREV		9		/* seq (BTREE, RECNO) */
64*7c478bd9Sstevel@tonic-gate #define	R_SETCURSOR	10		/* put (RECNO) */
65*7c478bd9Sstevel@tonic-gate #define	R_RECNOSYNC	11		/* sync (RECNO) */
66*7c478bd9Sstevel@tonic-gate 
67*7c478bd9Sstevel@tonic-gate typedef enum { DB_BTREE, DB_HASH, DB_RECNO } DBTYPE;
68*7c478bd9Sstevel@tonic-gate 
69*7c478bd9Sstevel@tonic-gate /*
70*7c478bd9Sstevel@tonic-gate  * !!!
71*7c478bd9Sstevel@tonic-gate  * The following flags are included in the dbopen(3) call as part of the
72*7c478bd9Sstevel@tonic-gate  * open(2) flags.  In order to avoid conflicts with the open flags, start
73*7c478bd9Sstevel@tonic-gate  * at the top of the 16 or 32-bit number space and work our way down.  If
74*7c478bd9Sstevel@tonic-gate  * the open flags were significantly expanded in the future, it could be
75*7c478bd9Sstevel@tonic-gate  * a problem.  Wish I'd left another flags word in the dbopen call.
76*7c478bd9Sstevel@tonic-gate  *
77*7c478bd9Sstevel@tonic-gate  * !!!
78*7c478bd9Sstevel@tonic-gate  * None of this stuff is implemented yet.  The only reason that it's here
79*7c478bd9Sstevel@tonic-gate  * is so that the access methods can skip copying the key/data pair when
80*7c478bd9Sstevel@tonic-gate  * the DB_LOCK flag isn't set.
81*7c478bd9Sstevel@tonic-gate  */
82*7c478bd9Sstevel@tonic-gate #if SIZEOF_INT == 4
83*7c478bd9Sstevel@tonic-gate #define	DB_LOCK		0x20000000	/* Do locking. */
84*7c478bd9Sstevel@tonic-gate #define	DB_SHMEM	0x40000000	/* Use shared memory. */
85*7c478bd9Sstevel@tonic-gate #define	DB_TXN		0x80000000	/* Do transactions. */
86*7c478bd9Sstevel@tonic-gate #else
87*7c478bd9Sstevel@tonic-gate #define	DB_LOCK		    0x2000	/* Do locking. */
88*7c478bd9Sstevel@tonic-gate #define	DB_SHMEM	    0x4000	/* Use shared memory. */
89*7c478bd9Sstevel@tonic-gate #define	DB_TXN		    0x8000	/* Do transactions. */
90*7c478bd9Sstevel@tonic-gate #endif
91*7c478bd9Sstevel@tonic-gate 
92*7c478bd9Sstevel@tonic-gate /* deal with turning prototypes on and off */
93*7c478bd9Sstevel@tonic-gate 
94*7c478bd9Sstevel@tonic-gate #ifndef __P
95*7c478bd9Sstevel@tonic-gate #if defined(__STDC__) || defined(__cplusplus)
96*7c478bd9Sstevel@tonic-gate #define	__P(protos)	protos		/* full-blown ANSI C */
97*7c478bd9Sstevel@tonic-gate #else	/* !(__STDC__ || __cplusplus) */
98*7c478bd9Sstevel@tonic-gate #define	__P(protos)	()		/* traditional C preprocessor */
99*7c478bd9Sstevel@tonic-gate #endif
100*7c478bd9Sstevel@tonic-gate #endif /* no __P from system */
101*7c478bd9Sstevel@tonic-gate 
102*7c478bd9Sstevel@tonic-gate /* Access method description structure. */
103*7c478bd9Sstevel@tonic-gate typedef struct __db {
104*7c478bd9Sstevel@tonic-gate 	DBTYPE type;			/* Underlying db type. */
105*7c478bd9Sstevel@tonic-gate 	int (*close)	__P((struct __db *));
106*7c478bd9Sstevel@tonic-gate 	int (*del)	__P((const struct __db *, const DBT *, u_int));
107*7c478bd9Sstevel@tonic-gate 	int (*get)	__P((const struct __db *, const DBT *, DBT *, u_int));
108*7c478bd9Sstevel@tonic-gate 	int (*put)	__P((const struct __db *, DBT *, const DBT *, u_int));
109*7c478bd9Sstevel@tonic-gate 	int (*seq)	__P((const struct __db *, DBT *, DBT *, u_int));
110*7c478bd9Sstevel@tonic-gate 	int (*sync)	__P((const struct __db *, u_int));
111*7c478bd9Sstevel@tonic-gate 	void *internal;			/* Access method private. */
112*7c478bd9Sstevel@tonic-gate 	int (*fd)	__P((const struct __db *));
113*7c478bd9Sstevel@tonic-gate } DB;
114*7c478bd9Sstevel@tonic-gate 
115*7c478bd9Sstevel@tonic-gate #define	BTREEMAGIC	0x053162
116*7c478bd9Sstevel@tonic-gate #define	BTREEVERSION	3
117*7c478bd9Sstevel@tonic-gate 
118*7c478bd9Sstevel@tonic-gate /* Structure used to pass parameters to the btree routines. */
119*7c478bd9Sstevel@tonic-gate typedef struct {
120*7c478bd9Sstevel@tonic-gate #define	R_DUP		0x01	/* duplicate keys */
121*7c478bd9Sstevel@tonic-gate 	u_long	flags;
122*7c478bd9Sstevel@tonic-gate 	u_int	cachesize;	/* bytes to cache */
123*7c478bd9Sstevel@tonic-gate 	int	maxkeypage;	/* maximum keys per page */
124*7c478bd9Sstevel@tonic-gate 	int	minkeypage;	/* minimum keys per page */
125*7c478bd9Sstevel@tonic-gate 	u_int	psize;		/* page size */
126*7c478bd9Sstevel@tonic-gate 	int	(*compare)	/* comparison function */
127*7c478bd9Sstevel@tonic-gate 	    __P((const DBT *, const DBT *));
128*7c478bd9Sstevel@tonic-gate 	size_t	(*prefix)	/* prefix function */
129*7c478bd9Sstevel@tonic-gate 	    __P((const DBT *, const DBT *));
130*7c478bd9Sstevel@tonic-gate 	int	lorder;		/* byte order */
131*7c478bd9Sstevel@tonic-gate } BTREEINFO;
132*7c478bd9Sstevel@tonic-gate 
133*7c478bd9Sstevel@tonic-gate #define	HASHMAGIC	0x061561
134*7c478bd9Sstevel@tonic-gate #define	HASHVERSION	3
135*7c478bd9Sstevel@tonic-gate 
136*7c478bd9Sstevel@tonic-gate /* Structure used to pass parameters to the hashing routines. */
137*7c478bd9Sstevel@tonic-gate typedef struct {
138*7c478bd9Sstevel@tonic-gate 	u_int	bsize;		/* bucket size */
139*7c478bd9Sstevel@tonic-gate 	u_int	ffactor;	/* fill factor */
140*7c478bd9Sstevel@tonic-gate 	u_int	nelem;		/* number of elements */
141*7c478bd9Sstevel@tonic-gate 	u_int	cachesize;	/* bytes to cache */
142*7c478bd9Sstevel@tonic-gate 	u_int32_t		/* hash function */
143*7c478bd9Sstevel@tonic-gate 		(*hash) __P((const void *, size_t));
144*7c478bd9Sstevel@tonic-gate 	int	lorder;		/* byte order */
145*7c478bd9Sstevel@tonic-gate } HASHINFO;
146*7c478bd9Sstevel@tonic-gate 
147*7c478bd9Sstevel@tonic-gate /* Structure used to pass parameters to the record routines. */
148*7c478bd9Sstevel@tonic-gate typedef struct {
149*7c478bd9Sstevel@tonic-gate #define	R_FIXEDLEN	0x01	/* fixed-length records */
150*7c478bd9Sstevel@tonic-gate #define	R_NOKEY		0x02	/* key not required */
151*7c478bd9Sstevel@tonic-gate #define	R_SNAPSHOT	0x04	/* snapshot the input */
152*7c478bd9Sstevel@tonic-gate 	u_long	flags;
153*7c478bd9Sstevel@tonic-gate 	u_int	cachesize;	/* bytes to cache */
154*7c478bd9Sstevel@tonic-gate 	u_int	psize;		/* page size */
155*7c478bd9Sstevel@tonic-gate 	int	lorder;		/* byte order */
156*7c478bd9Sstevel@tonic-gate 	size_t	reclen;		/* record length (fixed-length records) */
157*7c478bd9Sstevel@tonic-gate 	u_char	bval;		/* delimiting byte (variable-length records */
158*7c478bd9Sstevel@tonic-gate 	char	*bfname;	/* btree file name */
159*7c478bd9Sstevel@tonic-gate } RECNOINFO;
160*7c478bd9Sstevel@tonic-gate 
161*7c478bd9Sstevel@tonic-gate #if defined(__cplusplus)
162*7c478bd9Sstevel@tonic-gate #define	__BEGIN_DECLS	extern "C" {
163*7c478bd9Sstevel@tonic-gate #define	__END_DECLS	};
164*7c478bd9Sstevel@tonic-gate #else
165*7c478bd9Sstevel@tonic-gate #define	__BEGIN_DECLS
166*7c478bd9Sstevel@tonic-gate #define	__END_DECLS
167*7c478bd9Sstevel@tonic-gate #endif
168*7c478bd9Sstevel@tonic-gate 
169*7c478bd9Sstevel@tonic-gate #define dbopen	kdb2_dbopen
170*7c478bd9Sstevel@tonic-gate #define bt_rseq		kdb2_bt_rseq /* XXX kludge */
171*7c478bd9Sstevel@tonic-gate __BEGIN_DECLS
172*7c478bd9Sstevel@tonic-gate DB *dbopen __P((const char *, int, int, DBTYPE, const void *));
173*7c478bd9Sstevel@tonic-gate int	 bt_rseq(const DB*, DBT *, DBT *, void **, u_int); /* XXX kludge */
174*7c478bd9Sstevel@tonic-gate __END_DECLS
175*7c478bd9Sstevel@tonic-gate 
176*7c478bd9Sstevel@tonic-gate #if DEBUG_DB
177*7c478bd9Sstevel@tonic-gate 
178*7c478bd9Sstevel@tonic-gate /* debugging aid used to turn on display of messages */
179*7c478bd9Sstevel@tonic-gate void debugDisplayDB(int onOff);
180*7c478bd9Sstevel@tonic-gate 
181*7c478bd9Sstevel@tonic-gate #endif
182*7c478bd9Sstevel@tonic-gate 
183*7c478bd9Sstevel@tonic-gate #endif /* !_DB_H_ */
184