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