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