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