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