1 | /* db.h,v 1.5 2004/09/14 22:27:32 bird Exp */
|
---|
2 | /** @file
|
---|
3 | * FreeBSD 5.1
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*-
|
---|
7 | * Copyright (c) 1990, 1993, 1994
|
---|
8 | * The Regents of the University of California. All rights reserved.
|
---|
9 | *
|
---|
10 | * Redistribution and use in source and binary forms, with or without
|
---|
11 | * modification, are permitted provided that the following conditions
|
---|
12 | * are met:
|
---|
13 | * 1. Redistributions of source code must retain the above copyright
|
---|
14 | * notice, this list of conditions and the following disclaimer.
|
---|
15 | * 2. Redistributions in binary form must reproduce the above copyright
|
---|
16 | * notice, this list of conditions and the following disclaimer in the
|
---|
17 | * documentation and/or other materials provided with the distribution.
|
---|
18 | * 3. All advertising materials mentioning features or use of this software
|
---|
19 | * must display the following acknowledgement:
|
---|
20 | * This product includes software developed by the University of
|
---|
21 | * California, Berkeley and its contributors.
|
---|
22 | * 4. Neither the name of the University nor the names of its contributors
|
---|
23 | * may be used to endorse or promote products derived from this software
|
---|
24 | * without specific prior written permission.
|
---|
25 | *
|
---|
26 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
---|
27 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
---|
28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
---|
29 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
---|
30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
---|
31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
---|
32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
---|
33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
---|
34 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
---|
35 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
---|
36 | * SUCH DAMAGE.
|
---|
37 | *
|
---|
38 | * @(#)db.h 8.7 (Berkeley) 6/16/94
|
---|
39 | * $FreeBSD: src/include/db.h,v 1.5 2002/03/26 01:35:05 bde Exp $
|
---|
40 | */
|
---|
41 |
|
---|
42 | #ifndef _DB_H_
|
---|
43 | #define _DB_H_
|
---|
44 |
|
---|
45 | #include <sys/types.h>
|
---|
46 | #include <sys/cdefs.h>
|
---|
47 |
|
---|
48 | #include <limits.h>
|
---|
49 |
|
---|
50 | #define RET_ERROR -1 /* Return values. */
|
---|
51 | #define RET_SUCCESS 0
|
---|
52 | #define RET_SPECIAL 1
|
---|
53 |
|
---|
54 | #define MAX_PAGE_NUMBER 0xffffffff /* >= # of pages in a file */
|
---|
55 | typedef u_int32_t pgno_t;
|
---|
56 | #define MAX_PAGE_OFFSET 65535 /* >= # of bytes in a page */
|
---|
57 | typedef u_int16_t indx_t;
|
---|
58 | #define MAX_REC_NUMBER 0xffffffff /* >= # of records in a tree */
|
---|
59 | typedef u_int32_t recno_t;
|
---|
60 |
|
---|
61 | /* Key/data structure -- a Data-Base Thang. */
|
---|
62 | typedef struct {
|
---|
63 | void *data; /* data */
|
---|
64 | size_t size; /* data length */
|
---|
65 | } DBT;
|
---|
66 |
|
---|
67 | /* Routine flags. */
|
---|
68 | #define R_CURSOR 1 /* del, put, seq */
|
---|
69 | #define __R_UNUSED 2 /* UNUSED */
|
---|
70 | #define R_FIRST 3 /* seq */
|
---|
71 | #define R_IAFTER 4 /* put (RECNO) */
|
---|
72 | #define R_IBEFORE 5 /* put (RECNO) */
|
---|
73 | #define R_LAST 6 /* seq (BTREE, RECNO) */
|
---|
74 | #define R_NEXT 7 /* seq */
|
---|
75 | #define R_NOOVERWRITE 8 /* put */
|
---|
76 | #define R_PREV 9 /* seq (BTREE, RECNO) */
|
---|
77 | #define R_SETCURSOR 10 /* put (RECNO) */
|
---|
78 | #define R_RECNOSYNC 11 /* sync (RECNO) */
|
---|
79 |
|
---|
80 | typedef enum { DB_BTREE, DB_HASH, DB_RECNO } DBTYPE;
|
---|
81 |
|
---|
82 | /*
|
---|
83 | * !!!
|
---|
84 | * The following flags are included in the dbopen(3) call as part of the
|
---|
85 | * open(2) flags. In order to avoid conflicts with the open flags, start
|
---|
86 | * at the top of the 16 or 32-bit number space and work our way down. If
|
---|
87 | * the open flags were significantly expanded in the future, it could be
|
---|
88 | * a problem. Wish I'd left another flags word in the dbopen call.
|
---|
89 | *
|
---|
90 | * !!!
|
---|
91 | * None of this stuff is implemented yet. The only reason that it's here
|
---|
92 | * is so that the access methods can skip copying the key/data pair when
|
---|
93 | * the DB_LOCK flag isn't set.
|
---|
94 | */
|
---|
95 | #if UINT_MAX > 65535
|
---|
96 | #define DB_LOCK 0x20000000 /* Do locking. */
|
---|
97 | #define DB_SHMEM 0x40000000 /* Use shared memory. */
|
---|
98 | #define DB_TXN 0x80000000 /* Do transactions. */
|
---|
99 | #else
|
---|
100 | #define DB_LOCK 0x2000 /* Do locking. */
|
---|
101 | #define DB_SHMEM 0x4000 /* Use shared memory. */
|
---|
102 | #define DB_TXN 0x8000 /* Do transactions. */
|
---|
103 | #endif
|
---|
104 |
|
---|
105 | /* Access method description structure. */
|
---|
106 | typedef struct __db {
|
---|
107 | DBTYPE type; /* Underlying db type. */
|
---|
108 | int (*close)(struct __db *);
|
---|
109 | int (*del)(const struct __db *, const DBT *, u_int);
|
---|
110 | int (*get)(const struct __db *, const DBT *, DBT *, u_int);
|
---|
111 | int (*put)(const struct __db *, DBT *, const DBT *, u_int);
|
---|
112 | int (*seq)(const struct __db *, DBT *, DBT *, u_int);
|
---|
113 | int (*sync)(const struct __db *, u_int);
|
---|
114 | void *internal; /* Access method private. */
|
---|
115 | int (*fd)(const struct __db *);
|
---|
116 | } DB;
|
---|
117 |
|
---|
118 | #define BTREEMAGIC 0x053162
|
---|
119 | #define BTREEVERSION 3
|
---|
120 |
|
---|
121 | /* Structure used to pass parameters to the btree routines. */
|
---|
122 | typedef struct {
|
---|
123 | #define R_DUP 0x01 /* duplicate keys */
|
---|
124 | u_long flags;
|
---|
125 | u_int cachesize; /* bytes to cache */
|
---|
126 | int maxkeypage; /* maximum keys per page */
|
---|
127 | int minkeypage; /* minimum keys per page */
|
---|
128 | u_int psize; /* page size */
|
---|
129 | int (*compare) /* comparison function */
|
---|
130 | (const DBT *, const DBT *);
|
---|
131 | size_t (*prefix) /* prefix function */
|
---|
132 | (const DBT *, const DBT *);
|
---|
133 | int lorder; /* byte order */
|
---|
134 | } BTREEINFO;
|
---|
135 |
|
---|
136 | #define HASHMAGIC 0x061561
|
---|
137 | #define HASHVERSION 2
|
---|
138 |
|
---|
139 | /* Structure used to pass parameters to the hashing routines. */
|
---|
140 | typedef struct {
|
---|
141 | u_int bsize; /* bucket size */
|
---|
142 | u_int ffactor; /* fill factor */
|
---|
143 | u_int nelem; /* number of elements */
|
---|
144 | u_int cachesize; /* bytes to cache */
|
---|
145 | u_int32_t /* hash function */
|
---|
146 | (*hash)(const void *, size_t);
|
---|
147 | int lorder; /* byte order */
|
---|
148 | } HASHINFO;
|
---|
149 |
|
---|
150 | /* Structure used to pass parameters to the record routines. */
|
---|
151 | typedef struct {
|
---|
152 | #define R_FIXEDLEN 0x01 /* fixed-length records */
|
---|
153 | #define R_NOKEY 0x02 /* key not required */
|
---|
154 | #define R_SNAPSHOT 0x04 /* snapshot the input */
|
---|
155 | u_long flags;
|
---|
156 | u_int cachesize; /* bytes to cache */
|
---|
157 | u_int psize; /* page size */
|
---|
158 | int lorder; /* byte order */
|
---|
159 | size_t reclen; /* record length (fixed-length records) */
|
---|
160 | u_char bval; /* delimiting byte (variable-length records */
|
---|
161 | char *bfname; /* btree file name */
|
---|
162 | } RECNOINFO;
|
---|
163 |
|
---|
164 | #ifdef __DBINTERFACE_PRIVATE
|
---|
165 | /*
|
---|
166 | * Little endian <==> big endian 32-bit swap macros.
|
---|
167 | * M_32_SWAP swap a memory location
|
---|
168 | * P_32_SWAP swap a referenced memory location
|
---|
169 | * P_32_COPY swap from one location to another
|
---|
170 | */
|
---|
171 | #define M_32_SWAP(a) { \
|
---|
172 | u_int32_t _tmp = a; \
|
---|
173 | ((char *)&a)[0] = ((char *)&_tmp)[3]; \
|
---|
174 | ((char *)&a)[1] = ((char *)&_tmp)[2]; \
|
---|
175 | ((char *)&a)[2] = ((char *)&_tmp)[1]; \
|
---|
176 | ((char *)&a)[3] = ((char *)&_tmp)[0]; \
|
---|
177 | }
|
---|
178 | #define P_32_SWAP(a) { \
|
---|
179 | u_int32_t _tmp = *(u_int32_t *)a; \
|
---|
180 | ((char *)a)[0] = ((char *)&_tmp)[3]; \
|
---|
181 | ((char *)a)[1] = ((char *)&_tmp)[2]; \
|
---|
182 | ((char *)a)[2] = ((char *)&_tmp)[1]; \
|
---|
183 | ((char *)a)[3] = ((char *)&_tmp)[0]; \
|
---|
184 | }
|
---|
185 | #define P_32_COPY(a, b) { \
|
---|
186 | ((char *)&(b))[0] = ((char *)&(a))[3]; \
|
---|
187 | ((char *)&(b))[1] = ((char *)&(a))[2]; \
|
---|
188 | ((char *)&(b))[2] = ((char *)&(a))[1]; \
|
---|
189 | ((char *)&(b))[3] = ((char *)&(a))[0]; \
|
---|
190 | }
|
---|
191 |
|
---|
192 | /*
|
---|
193 | * Little endian <==> big endian 16-bit swap macros.
|
---|
194 | * M_16_SWAP swap a memory location
|
---|
195 | * P_16_SWAP swap a referenced memory location
|
---|
196 | * P_16_COPY swap from one location to another
|
---|
197 | */
|
---|
198 | #define M_16_SWAP(a) { \
|
---|
199 | u_int16_t _tmp = a; \
|
---|
200 | ((char *)&a)[0] = ((char *)&_tmp)[1]; \
|
---|
201 | ((char *)&a)[1] = ((char *)&_tmp)[0]; \
|
---|
202 | }
|
---|
203 | #define P_16_SWAP(a) { \
|
---|
204 | u_int16_t _tmp = *(u_int16_t *)a; \
|
---|
205 | ((char *)a)[0] = ((char *)&_tmp)[1]; \
|
---|
206 | ((char *)a)[1] = ((char *)&_tmp)[0]; \
|
---|
207 | }
|
---|
208 | #define P_16_COPY(a, b) { \
|
---|
209 | ((char *)&(b))[0] = ((char *)&(a))[1]; \
|
---|
210 | ((char *)&(b))[1] = ((char *)&(a))[0]; \
|
---|
211 | }
|
---|
212 | #endif
|
---|
213 |
|
---|
214 | __BEGIN_DECLS
|
---|
215 | DB *dbopen(const char *, int, int, DBTYPE, const void *);
|
---|
216 |
|
---|
217 | #ifdef __DBINTERFACE_PRIVATE
|
---|
218 | DB *__bt_open(const char *, int, int, const BTREEINFO *, int);
|
---|
219 | DB *__hash_open(const char *, int, int, const HASHINFO *, int);
|
---|
220 | DB *__rec_open(const char *, int, int, const RECNOINFO *, int);
|
---|
221 | void __dbpanic(DB *dbp);
|
---|
222 | #endif
|
---|
223 | __END_DECLS
|
---|
224 | #endif /* !_DB_H_ */
|
---|