]>
git.saurik.com Git - apple/libc.git/blob - include/db.h
2 * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
24 * Copyright (c) 1990, 1993, 1994
25 * The Regents of the University of California. All rights reserved.
27 * Redistribution and use in source and binary forms, with or without
28 * modification, are permitted provided that the following conditions
30 * 1. Redistributions of source code must retain the above copyright
31 * notice, this list of conditions and the following disclaimer.
32 * 2. Redistributions in binary form must reproduce the above copyright
33 * notice, this list of conditions and the following disclaimer in the
34 * documentation and/or other materials provided with the distribution.
35 * 3. All advertising materials mentioning features or use of this software
36 * must display the following acknowledgement:
37 * This product includes software developed by the University of
38 * California, Berkeley and its contributors.
39 * 4. Neither the name of the University nor the names of its contributors
40 * may be used to endorse or promote products derived from this software
41 * without specific prior written permission.
43 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
44 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
47 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
48 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
49 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
51 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
52 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
55 * @(#)db.h 8.7 (Berkeley) 6/16/94
56 * $FreeBSD: src/include/db.h,v 1.5 2002/03/26 01:35:05 bde Exp $
62 #include <sys/types.h>
63 #include <sys/cdefs.h>
67 #define RET_ERROR -1 /* Return values. */
71 #define MAX_PAGE_NUMBER 0xffffffff /* >= # of pages in a file */
72 typedef u_int32_t pgno_t
;
73 #define MAX_PAGE_OFFSET 65535 /* >= # of bytes in a page */
74 typedef u_int16_t indx_t
;
75 #define MAX_REC_NUMBER 0xffffffff /* >= # of records in a tree */
76 typedef u_int32_t recno_t
;
78 /* Key/data structure -- a Data-Base Thang. */
80 void *data
; /* data */
81 size_t size
; /* data length */
85 #define R_CURSOR 1 /* del, put, seq */
86 #define __R_UNUSED 2 /* UNUSED */
87 #define R_FIRST 3 /* seq */
88 #define R_IAFTER 4 /* put (RECNO) */
89 #define R_IBEFORE 5 /* put (RECNO) */
90 #define R_LAST 6 /* seq (BTREE, RECNO) */
91 #define R_NEXT 7 /* seq */
92 #define R_NOOVERWRITE 8 /* put */
93 #define R_PREV 9 /* seq (BTREE, RECNO) */
94 #define R_SETCURSOR 10 /* put (RECNO) */
95 #define R_RECNOSYNC 11 /* sync (RECNO) */
97 typedef enum { DB_BTREE
, DB_HASH
, DB_RECNO
} DBTYPE
;
101 * The following flags are included in the dbopen(3) call as part of the
102 * open(2) flags. In order to avoid conflicts with the open flags, start
103 * at the top of the 16 or 32-bit number space and work our way down. If
104 * the open flags were significantly expanded in the future, it could be
105 * a problem. Wish I'd left another flags word in the dbopen call.
108 * None of this stuff is implemented yet. The only reason that it's here
109 * is so that the access methods can skip copying the key/data pair when
110 * the DB_LOCK flag isn't set.
113 #define DB_LOCK 0x20000000 /* Do locking. */
114 #define DB_SHMEM 0x40000000 /* Use shared memory. */
115 #define DB_TXN 0x80000000 /* Do transactions. */
117 #define DB_LOCK 0x2000 /* Do locking. */
118 #define DB_SHMEM 0x4000 /* Use shared memory. */
119 #define DB_TXN 0x8000 /* Do transactions. */
122 /* Access method description structure. */
123 typedef struct __db
{
124 DBTYPE type
; /* Underlying db type. */
125 int (*close
)(struct __db
*);
126 int (*del
)(const struct __db
*, const DBT
*, u_int
);
127 int (*get
)(const struct __db
*, const DBT
*, DBT
*, u_int
);
128 int (*put
)(const struct __db
*, DBT
*, const DBT
*, u_int
);
129 int (*seq
)(const struct __db
*, DBT
*, DBT
*, u_int
);
130 int (*sync
)(const struct __db
*, u_int
);
131 void *internal
; /* Access method private. */
132 int (*fd
)(const struct __db
*);
135 #define BTREEMAGIC 0x053162
136 #define BTREEVERSION 3
138 /* Structure used to pass parameters to the btree routines. */
140 #define R_DUP 0x01 /* duplicate keys */
142 u_int cachesize
; /* bytes to cache */
143 int maxkeypage
; /* maximum keys per page */
144 int minkeypage
; /* minimum keys per page */
145 u_int psize
; /* page size */
146 int (*compare
) /* comparison function */
147 (const DBT
*, const DBT
*);
148 size_t (*prefix
) /* prefix function */
149 (const DBT
*, const DBT
*);
150 int lorder
; /* byte order */
153 #define HASHMAGIC 0x061561
154 #define HASHVERSION 2
156 /* Structure used to pass parameters to the hashing routines. */
158 u_int bsize
; /* bucket size */
159 u_int ffactor
; /* fill factor */
160 u_int nelem
; /* number of elements */
161 u_int cachesize
; /* bytes to cache */
162 u_int32_t
/* hash function */
163 (*hash
)(const void *, size_t);
164 int lorder
; /* byte order */
167 /* Structure used to pass parameters to the record routines. */
169 #define R_FIXEDLEN 0x01 /* fixed-length records */
170 #define R_NOKEY 0x02 /* key not required */
171 #define R_SNAPSHOT 0x04 /* snapshot the input */
173 u_int cachesize
; /* bytes to cache */
174 u_int psize
; /* page size */
175 int lorder
; /* byte order */
176 size_t reclen
; /* record length (fixed-length records) */
177 u_char bval
; /* delimiting byte (variable-length records */
178 char *bfname
; /* btree file name */
181 #ifdef __DBINTERFACE_PRIVATE
183 * Little endian <==> big endian 32-bit swap macros.
184 * M_32_SWAP swap a memory location
185 * P_32_SWAP swap a referenced memory location
186 * P_32_COPY swap from one location to another
188 #define M_32_SWAP(a) { \
189 u_int32_t _tmp = a; \
190 ((char *)&a)[0] = ((char *)&_tmp)[3]; \
191 ((char *)&a)[1] = ((char *)&_tmp)[2]; \
192 ((char *)&a)[2] = ((char *)&_tmp)[1]; \
193 ((char *)&a)[3] = ((char *)&_tmp)[0]; \
195 #define P_32_SWAP(a) { \
196 u_int32_t _tmp = *(u_int32_t *)a; \
197 ((char *)a)[0] = ((char *)&_tmp)[3]; \
198 ((char *)a)[1] = ((char *)&_tmp)[2]; \
199 ((char *)a)[2] = ((char *)&_tmp)[1]; \
200 ((char *)a)[3] = ((char *)&_tmp)[0]; \
202 #define P_32_COPY(a, b) { \
203 ((char *)&(b))[0] = ((char *)&(a))[3]; \
204 ((char *)&(b))[1] = ((char *)&(a))[2]; \
205 ((char *)&(b))[2] = ((char *)&(a))[1]; \
206 ((char *)&(b))[3] = ((char *)&(a))[0]; \
210 * Little endian <==> big endian 16-bit swap macros.
211 * M_16_SWAP swap a memory location
212 * P_16_SWAP swap a referenced memory location
213 * P_16_COPY swap from one location to another
215 #define M_16_SWAP(a) { \
216 u_int16_t _tmp = a; \
217 ((char *)&a)[0] = ((char *)&_tmp)[1]; \
218 ((char *)&a)[1] = ((char *)&_tmp)[0]; \
220 #define P_16_SWAP(a) { \
221 u_int16_t _tmp = *(u_int16_t *)a; \
222 ((char *)a)[0] = ((char *)&_tmp)[1]; \
223 ((char *)a)[1] = ((char *)&_tmp)[0]; \
225 #define P_16_COPY(a, b) { \
226 ((char *)&(b))[0] = ((char *)&(a))[1]; \
227 ((char *)&(b))[1] = ((char *)&(a))[0]; \
232 DB
*dbopen(const char *, int, int, DBTYPE
, const void *);
234 #ifdef __DBINTERFACE_PRIVATE
235 DB
*__bt_open(const char *, int, int, const BTREEINFO
*, int);
236 DB
*__hash_open(const char *, int, int, const HASHINFO
*, int);
237 DB
*__rec_open(const char *, int, int, const RECNOINFO
*, int);
238 void __dbpanic(DB
*dbp
);