comparison nss/lib/dbm/include/mcom_db.h @ 3:150b72113545

Add DBM and legacydb support
author Andre Heinecke <andre.heinecke@intevation.de>
date Tue, 05 Aug 2014 18:32:02 +0200
parents
children
comparison
equal deleted inserted replaced
2:a945361df361 3:150b72113545
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /*-
3 * Copyright (c) 1990, 1993, 1994
4 * The Regents of the University of California. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. ***REMOVED*** - see
15 * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change
16 * 4. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 *
32 * @(#)db.h 8.7 (Berkeley) 6/16/94
33 */
34
35 #ifndef _DB_H_
36 #define _DB_H_
37
38 #ifndef macintosh
39 #include <sys/types.h>
40 #endif
41 #include "prtypes.h"
42
43 #if !defined(XP_BEOS) && !defined(XP_OS2) && !defined(XP_UNIX) || defined(NTO)
44 typedef PRUintn uint;
45 #endif
46 typedef PRUint8 uint8;
47 typedef PRUint16 uint16;
48 /* On AIX 5.2, sys/inttypes.h (which is included by sys/types.h)
49 * defines the types int8, int16, int32, and int64. */
50 #if !defined(AIX)
51 typedef PRInt32 int32;
52 #endif
53 typedef PRUint32 uint32;
54
55 #include <limits.h>
56
57 #ifdef __DBINTERFACE_PRIVATE
58
59 #ifdef HAVE_SYS_CDEFS_H
60 #include <sys/cdefs.h>
61 #else
62 #include "cdefs.h"
63 #endif
64
65 #ifdef HAVE_SYS_BYTEORDER_H
66 #include <sys/byteorder.h>
67 #endif
68
69 #if defined(__linux) || defined(__BEOS__)
70 #include <endian.h>
71 #ifndef BYTE_ORDER
72 #define BYTE_ORDER __BYTE_ORDER
73 #define BIG_ENDIAN __BIG_ENDIAN
74 #define LITTLE_ENDIAN __LITTLE_ENDIAN
75 #endif
76 #endif /* __linux */
77
78 #ifdef __sgi
79 #define BYTE_ORDER BIG_ENDIAN
80 #define BIG_ENDIAN 4321
81 #define LITTLE_ENDIAN 1234 /* LSB first: i386, vax, all NT risc */
82 #endif
83
84 #ifdef __sun
85 #define BIG_ENDIAN 4321
86 #define LITTLE_ENDIAN 1234 /* LSB first: i386, vax, all NT risc */
87
88 #ifndef __SVR4
89 /* compat.h is only in 4.1.3 machines. - dp */
90 #include <compat.h>
91 #endif
92
93 /* XXX - dp
94 * Need to find a general way of defining endian-ness in SunOS 5.3
95 * SunOS 5.4 defines _BIG_ENDIAN and _LITTLE_ENDIAN
96 * SunOS 5.3 does nothing like this.
97 */
98
99 #ifndef BYTE_ORDER
100
101 #if defined(_BIG_ENDIAN)
102 #define BYTE_ORDER BIG_ENDIAN
103 #elif defined(_LITTLE_ENDIAN)
104 #define BYTE_ORDER LITTLE_ENDIAN
105 #elif !defined(__SVR4)
106 /* 4.1.3 is always BIG_ENDIAN as it was released only on sparc platforms. */
107 #define BYTE_ORDER BIG_ENDIAN
108 #elif !defined(vax) && !defined(ntohl) && !defined(lint) && !defined(i386)
109 /* 5.3 big endian. Copied this above line from sys/byteorder.h */
110 /* Now we are in a 5.3 SunOS rather non 5.4 or above SunOS */
111 #define BYTE_ORDER BIG_ENDIAN
112 #else
113 #define BYTE_ORDER LITTLE_ENDIAN
114 #endif
115
116 #endif /* !BYTE_ORDER */
117 #endif /* __sun */
118
119 #if defined(__hpux) || defined(__hppa)
120 #define BYTE_ORDER BIG_ENDIAN
121 #define BIG_ENDIAN 4321
122 #define LITTLE_ENDIAN 1234 /* LSB first: i386, vax, all NT risc */
123 #endif
124
125 #if defined(AIXV3) || defined(AIX)
126 /* BYTE_ORDER, LITTLE_ENDIAN, BIG_ENDIAN are all defined here */
127 #include <sys/machine.h>
128 #endif
129
130 /* Digital Unix */
131 #ifdef __osf__
132 #include <machine/endian.h>
133 #endif
134
135 #ifdef __alpha
136 #ifndef WIN32
137 #else
138 /* Alpha NT */
139 #define BYTE_ORDER LITTLE_ENDIAN
140 #define BIG_ENDIAN 4321
141 #define LITTLE_ENDIAN 1234
142 #endif
143 #endif
144
145 #ifdef NCR
146 #include <sys/endian.h>
147 #endif
148
149 #ifdef __QNX__
150 #ifdef __QNXNTO__
151 #include <sys/param.h>
152 #else
153 #define LITTLE_ENDIAN 1234
154 #define BIG_ENDIAN 4321
155 #define BYTE_ORDER LITTLE_ENDIAN
156 #endif
157 #endif
158
159 #ifdef SNI
160 /* #include <sys/hetero.h> */
161 #define BYTE_ORDER BIG_ENDIAN
162 #define BIG_ENDIAN 4321
163 #define LITTLE_ENDIAN 1234
164 #endif
165
166 #ifdef _WINDOWS
167 #ifdef BYTE_ORDER
168 #undef BYTE_ORDER
169 #endif
170
171 #define BYTE_ORDER LITTLE_ENDIAN
172 #define LITTLE_ENDIAN 1234 /* LSB first: i386, vax, all NT risc */
173 #define BIG_ENDIAN 4321
174 #endif
175
176 #ifdef macintosh
177 #define BIG_ENDIAN 4321
178 #define LITTLE_ENDIAN 1234
179 #define BYTE_ORDER BIG_ENDIAN
180 #endif
181
182 #endif /* __DBINTERFACE_PRIVATE */
183
184 #ifdef SCO
185 #define MAXPATHLEN 1024
186 #endif
187
188 #include <fcntl.h>
189
190 #if defined(_WINDOWS) || defined(XP_OS2)
191 #include <stdio.h>
192 #include <io.h>
193
194 #ifndef XP_OS2
195 #define MAXPATHLEN 1024
196 #endif
197
198 #define EFTYPE EINVAL /* POSIX 1003.1 format errno. */
199
200 #ifndef STDERR_FILENO
201 #define STDIN_FILENO 0 /* ANSI C #defines */
202 #define STDOUT_FILENO 1
203 #define STDERR_FILENO 2
204 #endif
205
206 #ifndef O_ACCMODE /* POSIX 1003.1 access mode mask. */
207 #define O_ACCMODE (O_RDONLY|O_WRONLY|O_RDWR)
208 #endif
209 #endif
210
211 #ifdef macintosh
212 #include <stdio.h>
213 #include "xp_mcom.h"
214 #define O_ACCMODE 3 /* Mask for file access modes */
215 #define EFTYPE 2000
216 PR_BEGIN_EXTERN_C
217 int mkstemp(const char *path);
218 PR_END_EXTERN_C
219 #endif /* MACINTOSH */
220
221 #if !defined(_WINDOWS) && !defined(macintosh)
222 #include <sys/stat.h>
223 #include <errno.h>
224 #endif
225
226 /* define EFTYPE since most don't */
227 #ifndef EFTYPE
228 #define EFTYPE EINVAL /* POSIX 1003.1 format errno. */
229 #endif
230
231 #define RET_ERROR -1 /* Return values. */
232 #define RET_SUCCESS 0
233 #define RET_SPECIAL 1
234
235 #define MAX_PAGE_NUMBER 0xffffffff /* >= # of pages in a file */
236
237 #ifndef __sgi
238 typedef uint32 pgno_t;
239 #endif
240
241 #define MAX_PAGE_OFFSET 65535 /* >= # of bytes in a page */
242 typedef uint16 indx_t;
243 #define MAX_REC_NUMBER 0xffffffff /* >= # of records in a tree */
244 typedef uint32 recno_t;
245
246 /* Key/data structure -- a Data-Base Thang. */
247 typedef struct {
248 void *data; /* data */
249 size_t size; /* data length */
250 } DBT;
251
252 /* Routine flags. */
253 #define R_CURSOR 1 /* del, put, seq */
254 #define __R_UNUSED 2 /* UNUSED */
255 #define R_FIRST 3 /* seq */
256 #define R_IAFTER 4 /* put (RECNO) */
257 #define R_IBEFORE 5 /* put (RECNO) */
258 #define R_LAST 6 /* seq (BTREE, RECNO) */
259 #define R_NEXT 7 /* seq */
260 #define R_NOOVERWRITE 8 /* put */
261 #define R_PREV 9 /* seq (BTREE, RECNO) */
262 #define R_SETCURSOR 10 /* put (RECNO) */
263 #define R_RECNOSYNC 11 /* sync (RECNO) */
264
265 typedef enum { DB_BTREE, DB_HASH, DB_RECNO } DBTYPE;
266
267 typedef enum { LockOutDatabase, UnlockDatabase } DBLockFlagEnum;
268
269 /*
270 * !!!
271 * The following flags are included in the dbopen(3) call as part of the
272 * open(2) flags. In order to avoid conflicts with the open flags, start
273 * at the top of the 16 or 32-bit number space and work our way down. If
274 * the open flags were significantly expanded in the future, it could be
275 * a problem. Wish I'd left another flags word in the dbopen call.
276 *
277 * !!!
278 * None of this stuff is implemented yet. The only reason that it's here
279 * is so that the access methods can skip copying the key/data pair when
280 * the DB_LOCK flag isn't set.
281 */
282 #if UINT_MAX > 65535
283 #define DB_LOCK 0x20000000 /* Do locking. */
284 #define DB_SHMEM 0x40000000 /* Use shared memory. */
285 #define DB_TXN 0x80000000 /* Do transactions. */
286 #else
287 #define DB_LOCK 0x2000 /* Do locking. */
288 #define DB_SHMEM 0x4000 /* Use shared memory. */
289 #define DB_TXN 0x8000 /* Do transactions. */
290 #endif
291
292 /* Access method description structure. */
293 typedef struct __db {
294 DBTYPE type; /* Underlying db type. */
295 int (*close) (struct __db *);
296 int (*del) (const struct __db *, const DBT *, uint);
297 int (*get) (const struct __db *, const DBT *, DBT *, uint);
298 int (*put) (const struct __db *, DBT *, const DBT *, uint);
299 int (*seq) (const struct __db *, DBT *, DBT *, uint);
300 int (*sync) (const struct __db *, uint);
301 void *internal; /* Access method private. */
302 int (*fd) (const struct __db *);
303 } DB;
304
305 #define BTREEMAGIC 0x053162
306 #define BTREEVERSION 3
307
308 /* Structure used to pass parameters to the btree routines. */
309 typedef struct {
310 #define R_DUP 0x01 /* duplicate keys */
311 uint32 flags;
312 uint cachesize; /* bytes to cache */
313 int maxkeypage; /* maximum keys per page */
314 int minkeypage; /* minimum keys per page */
315 uint psize; /* page size */
316 int (*compare) /* comparison function */
317 (const DBT *, const DBT *);
318 size_t (*prefix) /* prefix function */
319 (const DBT *, const DBT *);
320 int lorder; /* byte order */
321 } BTREEINFO;
322
323 #define HASHMAGIC 0x061561
324 #define HASHVERSION 2
325
326 /* Structure used to pass parameters to the hashing routines. */
327 typedef struct {
328 uint bsize; /* bucket size */
329 uint ffactor; /* fill factor */
330 uint nelem; /* number of elements */
331 uint cachesize; /* bytes to cache */
332 uint32 /* hash function */
333 (*hash) (const void *, size_t);
334 int lorder; /* byte order */
335 } HASHINFO;
336
337 /* Structure used to pass parameters to the record routines. */
338 typedef struct {
339 #define R_FIXEDLEN 0x01 /* fixed-length records */
340 #define R_NOKEY 0x02 /* key not required */
341 #define R_SNAPSHOT 0x04 /* snapshot the input */
342 uint32 flags;
343 uint cachesize; /* bytes to cache */
344 uint psize; /* page size */
345 int lorder; /* byte order */
346 size_t reclen; /* record length (fixed-length records) */
347 uint8 bval; /* delimiting byte (variable-length records */
348 char *bfname; /* btree file name */
349 } RECNOINFO;
350
351 #ifdef __DBINTERFACE_PRIVATE
352 /*
353 * Little endian <==> big endian 32-bit swap macros.
354 * M_32_SWAP swap a memory location
355 * P_32_SWAP swap a referenced memory location
356 * P_32_COPY swap from one location to another
357 */
358 #define M_32_SWAP(a) { \
359 uint32 _tmp = a; \
360 ((char *)&a)[0] = ((char *)&_tmp)[3]; \
361 ((char *)&a)[1] = ((char *)&_tmp)[2]; \
362 ((char *)&a)[2] = ((char *)&_tmp)[1]; \
363 ((char *)&a)[3] = ((char *)&_tmp)[0]; \
364 }
365 #define P_32_SWAP(a) { \
366 uint32 _tmp = *(uint32 *)a; \
367 ((char *)a)[0] = ((char *)&_tmp)[3]; \
368 ((char *)a)[1] = ((char *)&_tmp)[2]; \
369 ((char *)a)[2] = ((char *)&_tmp)[1]; \
370 ((char *)a)[3] = ((char *)&_tmp)[0]; \
371 }
372 #define P_32_COPY(a, b) { \
373 ((char *)&(b))[0] = ((char *)&(a))[3]; \
374 ((char *)&(b))[1] = ((char *)&(a))[2]; \
375 ((char *)&(b))[2] = ((char *)&(a))[1]; \
376 ((char *)&(b))[3] = ((char *)&(a))[0]; \
377 }
378
379 /*
380 * Little endian <==> big endian 16-bit swap macros.
381 * M_16_SWAP swap a memory location
382 * P_16_SWAP swap a referenced memory location
383 * P_16_COPY swap from one location to another
384 */
385 #define M_16_SWAP(a) { \
386 uint16 _tmp = a; \
387 ((char *)&a)[0] = ((char *)&_tmp)[1]; \
388 ((char *)&a)[1] = ((char *)&_tmp)[0]; \
389 }
390 #define P_16_SWAP(a) { \
391 uint16 _tmp = *(uint16 *)a; \
392 ((char *)a)[0] = ((char *)&_tmp)[1]; \
393 ((char *)a)[1] = ((char *)&_tmp)[0]; \
394 }
395 #define P_16_COPY(a, b) { \
396 ((char *)&(b))[0] = ((char *)&(a))[1]; \
397 ((char *)&(b))[1] = ((char *)&(a))[0]; \
398 }
399 #endif
400
401 PR_BEGIN_EXTERN_C
402
403 extern DB *
404 dbopen (const char *, int, int, DBTYPE, const void *);
405
406 /* set or unset a global lock flag to disable the
407 * opening of any DBM file
408 */
409 void dbSetOrClearDBLock(DBLockFlagEnum type);
410
411 #ifdef __DBINTERFACE_PRIVATE
412 DB *__bt_open (const char *, int, int, const BTREEINFO *, int);
413 DB *__hash_open (const char *, int, int, const HASHINFO *, int);
414 DB *__rec_open (const char *, int, int, const RECNOINFO *, int);
415 void __dbpanic (DB *dbp);
416 #endif
417
418 PR_END_EXTERN_C
419
420 #endif /* !_DB_H_ */
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)