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