add db.1.85
[nvi.git] / db.1.85 / PORT / bsd.4.4 / include / db.h
blobcae13f9ecf58ad5483450f41c075d3e9f6383703
1 /*-
2 * Copyright (c) 1990, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
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.
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.
33 * @(#)db.h 8.6 (Berkeley) 6/16/94
36 #ifndef _DB_H_
37 #define _DB_H_
39 #include <sys/types.h>
40 #include <sys/cdefs.h>
42 #include <limits.h>
44 #ifdef __DBINTERFACE_PRIVATE
45 #include <compat.h>
46 #endif
48 #define RET_ERROR -1 /* Return values. */
49 #define RET_SUCCESS 0
50 #define RET_SPECIAL 1
52 #define MAX_PAGE_NUMBER 0xffffffff /* >= # of pages in a file */
53 typedef u_int32_t pgno_t;
54 #define MAX_PAGE_OFFSET 65535 /* >= # of bytes in a page */
55 typedef u_int16_t indx_t;
56 #define MAX_REC_NUMBER 0xffffffff /* >= # of records in a tree */
57 typedef u_int32_t recno_t;
59 /* Key/data structure -- a Data-Base Thang. */
60 typedef struct {
61 void *data; /* data */
62 size_t size; /* data length */
63 } DBT;
65 /* Routine flags. */
66 #define R_CURSOR 1 /* del, put, seq */
67 #define __R_UNUSED 2 /* UNUSED */
68 #define R_FIRST 3 /* seq */
69 #define R_IAFTER 4 /* put (RECNO) */
70 #define R_IBEFORE 5 /* put (RECNO) */
71 #define R_LAST 6 /* seq (BTREE, RECNO) */
72 #define R_NEXT 7 /* seq */
73 #define R_NOOVERWRITE 8 /* put */
74 #define R_PREV 9 /* seq (BTREE, RECNO) */
75 #define R_SETCURSOR 10 /* put (RECNO) */
76 #define R_RECNOSYNC 11 /* sync (RECNO) */
78 typedef enum { DB_BTREE, DB_HASH, DB_RECNO } DBTYPE;
81 * !!!
82 * The following flags are included in the dbopen(3) call as part of the
83 * open(2) flags. In order to avoid conflicts with the open flags, start
84 * at the top of the 16 or 32-bit number space and work our way down. If
85 * the open flags were significantly expanded in the future, it could be
86 * a problem. Wish I'd left another flags word in the dbopen call.
88 * !!!
89 * None of this stuff is implemented yet. The only reason that it's here
90 * is so that the access methods can skip copying the key/data pair when
91 * the DB_LOCK flag isn't set.
93 #if UINT_MAX > 65535
94 #define DB_LOCK 0x20000000 /* Do locking. */
95 #define DB_SHMEM 0x40000000 /* Use shared memory. */
96 #define DB_TXN 0x80000000 /* Do transactions. */
97 #else
98 #define DB_LOCK 0x2000 /* Do locking. */
99 #define DB_SHMEM 0x4000 /* Use shared memory. */
100 #define DB_TXN 0x8000 /* Do transactions. */
101 #endif
103 /* Access method description structure. */
104 typedef struct __db {
105 DBTYPE type; /* Underlying db type. */
106 int (*close) __P((struct __db *));
107 int (*del) __P((const struct __db *, const DBT *, u_int));
108 int (*get) __P((const struct __db *, const DBT *, DBT *, u_int));
109 int (*put) __P((const struct __db *, DBT *, const DBT *, u_int));
110 int (*seq) __P((const struct __db *, DBT *, DBT *, u_int));
111 int (*sync) __P((const struct __db *, u_int));
112 void *internal; /* Access method private. */
113 int (*fd) __P((const struct __db *));
114 } DB;
116 #define BTREEMAGIC 0x053162
117 #define BTREEVERSION 3
119 /* Structure used to pass parameters to the btree routines. */
120 typedef struct {
121 #define R_DUP 0x01 /* duplicate keys */
122 u_long flags;
123 u_int cachesize; /* bytes to cache */
124 int maxkeypage; /* maximum keys per page */
125 int minkeypage; /* minimum keys per page */
126 u_int psize; /* page size */
127 int (*compare) /* comparison function */
128 __P((const DBT *, const DBT *));
129 size_t (*prefix) /* prefix function */
130 __P((const DBT *, const DBT *));
131 int lorder; /* byte order */
132 } BTREEINFO;
134 #define HASHMAGIC 0x061561
135 #define HASHVERSION 2
137 /* Structure used to pass parameters to the hashing routines. */
138 typedef struct {
139 u_int bsize; /* bucket size */
140 u_int ffactor; /* fill factor */
141 u_int nelem; /* number of elements */
142 u_int cachesize; /* bytes to cache */
143 u_int32_t /* hash function */
144 (*hash) __P((const void *, size_t));
145 int lorder; /* byte order */
146 } HASHINFO;
148 /* Structure used to pass parameters to the record routines. */
149 typedef struct {
150 #define R_FIXEDLEN 0x01 /* fixed-length records */
151 #define R_NOKEY 0x02 /* key not required */
152 #define R_SNAPSHOT 0x04 /* snapshot the input */
153 u_long flags;
154 u_int cachesize; /* bytes to cache */
155 u_int psize; /* page size */
156 int lorder; /* byte order */
157 size_t reclen; /* record length (fixed-length records) */
158 u_char bval; /* delimiting byte (variable-length records */
159 char *bfname; /* btree file name */
160 } RECNOINFO;
162 #ifdef __DBINTERFACE_PRIVATE
164 * Little endian <==> big endian 32-bit swap macros.
165 * M_32_SWAP swap a memory location
166 * P_32_SWAP swap a referenced memory location
167 * P_32_COPY swap from one location to another
169 #define M_32_SWAP(a) { \
170 u_int32_t _tmp = a; \
171 ((char *)&a)[0] = ((char *)&_tmp)[3]; \
172 ((char *)&a)[1] = ((char *)&_tmp)[2]; \
173 ((char *)&a)[2] = ((char *)&_tmp)[1]; \
174 ((char *)&a)[3] = ((char *)&_tmp)[0]; \
176 #define P_32_SWAP(a) { \
177 u_int32_t _tmp = *(u_int32_t *)a; \
178 ((char *)a)[0] = ((char *)&_tmp)[3]; \
179 ((char *)a)[1] = ((char *)&_tmp)[2]; \
180 ((char *)a)[2] = ((char *)&_tmp)[1]; \
181 ((char *)a)[3] = ((char *)&_tmp)[0]; \
183 #define P_32_COPY(a, b) { \
184 ((char *)&(b))[0] = ((char *)&(a))[3]; \
185 ((char *)&(b))[1] = ((char *)&(a))[2]; \
186 ((char *)&(b))[2] = ((char *)&(a))[1]; \
187 ((char *)&(b))[3] = ((char *)&(a))[0]; \
191 * Little endian <==> big endian 16-bit swap macros.
192 * M_16_SWAP swap a memory location
193 * P_16_SWAP swap a referenced memory location
194 * P_16_COPY swap from one location to another
196 #define M_16_SWAP(a) { \
197 u_int16_t _tmp = a; \
198 ((char *)&a)[0] = ((char *)&_tmp)[1]; \
199 ((char *)&a)[1] = ((char *)&_tmp)[0]; \
201 #define P_16_SWAP(a) { \
202 u_int16_t _tmp = *(u_int16_t *)a; \
203 ((char *)a)[0] = ((char *)&_tmp)[1]; \
204 ((char *)a)[1] = ((char *)&_tmp)[0]; \
206 #define P_16_COPY(a, b) { \
207 ((char *)&(b))[0] = ((char *)&(a))[1]; \
208 ((char *)&(b))[1] = ((char *)&(a))[0]; \
210 #endif
212 __BEGIN_DECLS
213 DB *dbopen __P((const char *, int, int, DBTYPE, const void *));
215 #ifdef __DBINTERFACE_PRIVATE
216 DB *__bt_open __P((const char *, int, int, const BTREEINFO *, int));
217 DB *__hash_open __P((const char *, int, int, const HASHINFO *, int));
218 DB *__rec_open __P((const char *, int, int, const RECNOINFO *, int));
219 void __dbpanic __P((DB *dbp));
220 #endif
221 __END_DECLS
222 #endif /* !_DB_H_ */