(__FDMASK): Cast constant 1 to be shifted correctly.
[glibc/history.git] / db / db.h
blob13c7495d645760560c330e6c38a3c23e24bb403f
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.7 (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 #ifndef __BIT_TYPES_DEFINED__
53 #define __BIT_TYPES_DEFINED__
54 typedef __signed char int8_t;
55 typedef unsigned char u_int8_t;
56 typedef short int16_t;
57 typedef unsigned short u_int16_t;
58 typedef int int32_t;
59 typedef unsigned int u_int32_t;
60 #ifdef WE_DONT_NEED_QUADS
61 typedef long long int64_t;
62 typedef unsigned long long u_int64_t;
63 #endif
64 #endif
66 #define MAX_PAGE_NUMBER 0xffffffff /* >= # of pages in a file */
67 typedef u_int32_t pgno_t;
68 #define MAX_PAGE_OFFSET 65535 /* >= # of bytes in a page */
69 typedef u_int16_t indx_t;
70 #define MAX_REC_NUMBER 0xffffffff /* >= # of records in a tree */
71 typedef u_int32_t recno_t;
73 /* Key/data structure -- a Data-Base Thang. */
74 typedef struct {
75 void *data; /* data */
76 size_t size; /* data length */
77 } DBT;
79 /* Routine flags. */
80 #define R_CURSOR 1 /* del, put, seq */
81 #define __R_UNUSED 2 /* UNUSED */
82 #define R_FIRST 3 /* seq */
83 #define R_IAFTER 4 /* put (RECNO) */
84 #define R_IBEFORE 5 /* put (RECNO) */
85 #define R_LAST 6 /* seq (BTREE, RECNO) */
86 #define R_NEXT 7 /* seq */
87 #define R_NOOVERWRITE 8 /* put */
88 #define R_PREV 9 /* seq (BTREE, RECNO) */
89 #define R_SETCURSOR 10 /* put (RECNO) */
90 #define R_RECNOSYNC 11 /* sync (RECNO) */
92 typedef enum { DB_BTREE, DB_HASH, DB_RECNO } DBTYPE;
95 * !!!
96 * The following flags are included in the dbopen(3) call as part of the
97 * open(2) flags. In order to avoid conflicts with the open flags, start
98 * at the top of the 16 or 32-bit number space and work our way down. If
99 * the open flags were significantly expanded in the future, it could be
100 * a problem. Wish I'd left another flags word in the dbopen call.
102 * !!!
103 * None of this stuff is implemented yet. The only reason that it's here
104 * is so that the access methods can skip copying the key/data pair when
105 * the DB_LOCK flag isn't set.
107 #if UINT_MAX > 65535
108 #define DB_LOCK 0x20000000 /* Do locking. */
109 #define DB_SHMEM 0x40000000 /* Use shared memory. */
110 #define DB_TXN 0x80000000 /* Do transactions. */
111 #else
112 #define DB_LOCK 0x2000 /* Do locking. */
113 #define DB_SHMEM 0x4000 /* Use shared memory. */
114 #define DB_TXN 0x8000 /* Do transactions. */
115 #endif
117 /* Access method description structure. */
118 typedef struct __db {
119 DBTYPE type; /* Underlying db type. */
120 int (*close) __P((struct __db *));
121 int (*del) __P((const struct __db *, const DBT *, u_int));
122 int (*get) __P((const struct __db *, const DBT *, DBT *, u_int));
123 int (*put) __P((const struct __db *, DBT *, const DBT *, u_int));
124 int (*seq) __P((const struct __db *, DBT *, DBT *, u_int));
125 int (*sync) __P((const struct __db *, u_int));
126 void *internal; /* Access method private. */
127 int (*fd) __P((const struct __db *));
128 } DB;
130 #define BTREEMAGIC 0x053162
131 #define BTREEVERSION 3
133 /* Structure used to pass parameters to the btree routines. */
134 typedef struct {
135 #define R_DUP 0x01 /* duplicate keys */
136 u_long flags;
137 u_int cachesize; /* bytes to cache */
138 int maxkeypage; /* maximum keys per page */
139 int minkeypage; /* minimum keys per page */
140 u_int psize; /* page size */
141 int (*compare) /* comparison function */
142 __P((const DBT *, const DBT *));
143 size_t (*prefix) /* prefix function */
144 __P((const DBT *, const DBT *));
145 int lorder; /* byte order */
146 } BTREEINFO;
148 #define HASHMAGIC 0x061561
149 #define HASHVERSION 2
151 /* Structure used to pass parameters to the hashing routines. */
152 typedef struct {
153 u_int bsize; /* bucket size */
154 u_int ffactor; /* fill factor */
155 u_int nelem; /* number of elements */
156 u_int cachesize; /* bytes to cache */
157 u_int32_t /* hash function */
158 (*hash) __P((const void *, size_t));
159 int lorder; /* byte order */
160 } HASHINFO;
162 /* Structure used to pass parameters to the record routines. */
163 typedef struct {
164 #define R_FIXEDLEN 0x01 /* fixed-length records */
165 #define R_NOKEY 0x02 /* key not required */
166 #define R_SNAPSHOT 0x04 /* snapshot the input */
167 u_long flags;
168 u_int cachesize; /* bytes to cache */
169 u_int psize; /* page size */
170 int lorder; /* byte order */
171 size_t reclen; /* record length (fixed-length records) */
172 u_char bval; /* delimiting byte (variable-length records */
173 char *bfname; /* btree file name */
174 } RECNOINFO;
176 #ifdef __DBINTERFACE_PRIVATE
178 * Little endian <==> big endian 32-bit swap macros.
179 * M_32_SWAP swap a memory location
180 * P_32_SWAP swap a referenced memory location
181 * P_32_COPY swap from one location to another
183 #define M_32_SWAP(a) { \
184 u_int32_t _tmp = a; \
185 ((char *)&a)[0] = ((char *)&_tmp)[3]; \
186 ((char *)&a)[1] = ((char *)&_tmp)[2]; \
187 ((char *)&a)[2] = ((char *)&_tmp)[1]; \
188 ((char *)&a)[3] = ((char *)&_tmp)[0]; \
190 #define P_32_SWAP(a) { \
191 u_int32_t _tmp = *(u_int32_t *)a; \
192 ((char *)a)[0] = ((char *)&_tmp)[3]; \
193 ((char *)a)[1] = ((char *)&_tmp)[2]; \
194 ((char *)a)[2] = ((char *)&_tmp)[1]; \
195 ((char *)a)[3] = ((char *)&_tmp)[0]; \
197 #define P_32_COPY(a, b) { \
198 ((char *)&(b))[0] = ((char *)&(a))[3]; \
199 ((char *)&(b))[1] = ((char *)&(a))[2]; \
200 ((char *)&(b))[2] = ((char *)&(a))[1]; \
201 ((char *)&(b))[3] = ((char *)&(a))[0]; \
205 * Little endian <==> big endian 16-bit swap macros.
206 * M_16_SWAP swap a memory location
207 * P_16_SWAP swap a referenced memory location
208 * P_16_COPY swap from one location to another
210 #define M_16_SWAP(a) { \
211 u_int16_t _tmp = a; \
212 ((char *)&a)[0] = ((char *)&_tmp)[1]; \
213 ((char *)&a)[1] = ((char *)&_tmp)[0]; \
215 #define P_16_SWAP(a) { \
216 u_int16_t _tmp = *(u_int16_t *)a; \
217 ((char *)a)[0] = ((char *)&_tmp)[1]; \
218 ((char *)a)[1] = ((char *)&_tmp)[0]; \
220 #define P_16_COPY(a, b) { \
221 ((char *)&(b))[0] = ((char *)&(a))[1]; \
222 ((char *)&(b))[1] = ((char *)&(a))[0]; \
224 #endif
226 __BEGIN_DECLS
227 DB *dbopen __P((const char *, int, int, DBTYPE, const void *));
229 #ifdef __DBINTERFACE_PRIVATE
230 DB *__bt_open __P((const char *, int, int, const BTREEINFO *, int));
231 DB *__hash_open __P((const char *, int, int, const HASHINFO *, int));
232 DB *__rec_open __P((const char *, int, int, const RECNOINFO *, int));
233 void __dbpanic __P((DB *dbp));
234 #endif
235 __END_DECLS
236 #endif /* !_DB_H_ */