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